summaryrefslogtreecommitdiff
path: root/rc.lua
blob: 71be25397768fe100eeba01ad356fca8f48bf33e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
-- Standard awesome library
local gears = require("gears")
local awful = require("awful")
require("awful.autofocus")
-- Widget and layout library
local wibox = require("wibox")
-- Theme handling library
local beautiful = require("beautiful")
-- Notification library
local naughty = require("naughty")
local vicious = require("vicious")
local menubar = require("menubar")
local lfs = require('lfs')
local uselessfair = require("lib.uselessfair")


awful.screen = require("awful.screen")
local hotkeys = require("awful.hotkeys_popup")
local hotkeys_popup = require("awful.hotkeys_popup").widget

-- Lain
local lain = require("lain")
local awmodoro = require("awmodoro")

local io = require("io")


-- {{{ Error handling
-- Check if awesome encountered an error during startup and fell back to
-- another config (This code will only ever execute for the fallback config)
if awesome.startup_errors then
    naughty.notify({ preset = naughty.config.presets.critical,
                     title = "Oops, there were errors during startup!",
                     text = awesome.startup_errors })
end

-- Kill supervise before quiting
_awesome_quit = awesome.quit
awesome.quit = function()
    os.execute("loginctl terminate-session $(loginctl session-status | head -n 1 | awk '{print $1}')")
    _awesome_quit()
end

function guess_wifi(d)
   for file in lfs.dir(d) do
       if lfs.attributes(d .. file,"mode") == "directory"  then
           local ok = ""
           for l in lfs.dir("/sys/class/net/" .. file) do
                if l == "wireless" then
                  return file
                end
           end
       end
   end
end



-- Handle runtime errors after startup
do
    local in_error = false
    awesome.connect_signal("debug::error", function (err)
        -- Make sure we don't go into an endless error loop
        if in_error then return end
        in_error = true

        naughty.notify({ preset = naughty.config.presets.critical,
                         title = "Oops, an error happened!",
                         text = err })
        in_error = false
    end)
end
-- }}}

-- {{{ Variable definitions
-- Themes define colours, icons, and wallpapers
beautiful.init(os.getenv("HOME") .. "/.config/awesome/" ..
               "themes/customII/theme.lua")

-- This is used later as the default terminal and editor to run.
terminal = "kitty"
editor = os.getenv("EDITOR") or "vim"
editor_cmd = terminal .. " -e " .. editor

-- Default modkey.
-- Usually, Mod4 is the key with a logo between Control and Alt.
-- If you do not like this or do not have such a key,
-- I suggest you to remap Mod4 to another key using xmodmap or other tools.
-- However, you can use another modifier like Mod1, but it may interact with others.
modkey = "Mod4"

lain.layout.cascade.offset_x = 64
lain.layout.cascade.offset_y = 20

-- Table of layouts to cover with awful.layout.inc, order matters.
awful.layout.layouts = {
    -- uselessfairnogap,       --3
    uselessfair,       --3
    lain.layout.cascade,       --3
    lain.layout.cascade.tile,       --3
    awful.layout.suit.tile,             --1
    awful.layout.suit.floating,             --1
    awful.layout.suit.fair,             --1
}
-- }}}

-- {{{ Wallpaper
if beautiful.wallpaper then
    for s = 1, screen.count() do
        gears.wallpaper.maximized(beautiful.wallpaper, s, true)
    end
end
-- }}}


awful.screen.connect_for_each_screen(function(s)
    awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9", " " }, s, awful.layout.layouts[1])

    s.mylayoutbox = awful.widget.layoutbox(s)
    s.mylayoutbox:buttons(awful.util.table.join(
                           awful.button({ }, 1, function () awful.layout.inc( 1) end),
                           awful.button({ }, 3, function () awful.layout.inc(-1) end),
                           awful.button({ }, 4, function () awful.layout.inc( 1) end),
                           awful.button({ }, 5, function () awful.layout.inc(-1) end)))
end)

-- {{{ Menu
-- Create a laucher widget and a main menu
myawesomemenu = {
   { "manual", terminal .. " -e man awesome" },
   { "edit config", editor_cmd .. " " .. awesome.conffile },
   { "restart", awesome.restart },
   { "quit", awesome.quit }
}

mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
                                    { "firefox", function () awful.util.spawn("firefox") end},
                                    { "open terminal", terminal }
                                  }
                        })

mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
                                     menu = mymainmenu })

pomowibox = awful.wibox({ position = "top", screen = 1, height=4})
qPomowibox = awful.wibox({ position = "top", screen = 1, height=4})
pomowibox.visible = false
qPomowibox.visible = false

local pomodoro = awmodoro.new({
	minutes 			= 25,
	do_notify 			= false,
	active_bg_color 	= '#313131',
	paused_bg_color 	= '#7746D7',
	fg_color			= {type = "linear", from = {0,0}, to = {pomowibox.width, 0}, stops = {{0, "#AECF96"},{0.5, "#88A175"},{1, "#FF5656"}}},
	width 				= pomowibox.width,
	height 				= pomowibox.height,

	begin_callback = function()
		for s = 1, screen.count() do
			mywibox[s].visible = false
		end
		pomowibox.visible = true
	end,

	finish_callback = function()
		for s = 1, screen.count() do
			mywibox[s].visible = true
		end
		pomowibox.visible = false
	end})
 pomowibox:set_widget(pomodoro)
local quickPomodoro = awmodoro.new({
	minutes 			= 1,
	do_notify 			= false,
	active_bg_color 	= '#313131',
	paused_bg_color 	= '#7746D7',
	fg_color			= {type = "linear", from = {0,0}, to = {qPomowibox.width, 0}, stops = {{0, "#AECF96"},{0.5, "#88A175"},{1, "#FF5656"}}},
	width 				= qPomowibox.width,
	height 				= qPomowibox.height,

	begin_callback = function()
		for s = 1, screen.count() do
			mywibox[s].visible = false
		end
		qPomowibox.visible = true
	end,

	finish_callback = function()
		for s = 1, screen.count() do
			mywibox[s].visible = true
		end
		qPomowibox.visible = false
	end})
  qPomowibox:set_widget(quickPomodoro)


-- Menubar configuration
menubar.utils.terminal = terminal -- Set the terminal for applications that require it
-- }}}

-- {{{ Wibox
-- Create a textclock widget
mytextclock = awful.widget.textclock("<span color='#cbcbcb'> %H:%M</span>")
markup = lain.util.markup

-- Calendar
lain.widget.cal {
  attach_to = {mytextclock},
}


-- CPU
cpuwidget = lain.widget.cpu({
    settings = function()
        int_cpu_usage = tonumber(cpu_now.usage)
        widget:set_text("⚙️ ".. cpu_now.usage .. "%")
      end, timeout=10})

-- MPD
-- mpdwidget = lain.widget.mpd()

gputemp = wibox.widget.textbox()
vicious.register(gputemp, vicious.widgets.thermal, {"sys"}, 5)

mpdwidget = wibox.widget.textbox()
-- Register widget
vicious.register(mpdwidget, vicious.widgets.mpd,
    function (mpdwidget, args)
        if args["{state}"] == "Stop" then
            return ""
        else
          if not (args["{Artist}"] == 'N/A') then
            if not (args["{Title}"] == 'N/A') then
                return markup.bold(args["{Artist}"]..' - '.. args["{Title}"]) .. " / "
            else
                return markup.bold(args["{Artist}"] ) .. " / "
            end
          else
            if not (args["{Title}"] == 'N/A') then
                return markup.bold(args["{Title}"]) .. " / "
            end
            return ''
          end
        end
      end, 5
)

-- MEM
memwidget = lain.widget.mem({
    settings = function()
        int_mem_now_used = tonumber(mem_now.used)
        local perc_total = math.floor((mem_now.used + mem_now.swapused) / (mem_now.total + mem_now.swap) * 100)
        widget:set_markup(markup.fg.color("#dda", "🐏 " .. mem_now.used .. "M (" .. perc_total .. "%)"))

        if notify_ram and mem_now.perc_total >= 85 then
          naughty.notify({ preset = naughty.config.presets.critical,
          title = "Niveau de RM",
          text = "L'utilisation de la RAM dépasse 85%",
          bg="#EEAA55"})
        end
      end, timeout=5
})


-- ALSA volume
volumewidget = lain.widget.alsa({
    settings = function()
        header = " "

        int_volume_level = tonumber(volume_now.level)

        if int_volume_level == 100 then
            vlevel = "100"
        elseif int_volume_level == 0 then
            vlevel = "0"
        else
            vlevel = volume_now.level
        end

        volume_emoji = "📢 "
        if int_volume_level == 0 then
          volume_emoji = "🔇 "
        elseif int_volume_level < 30 then
          volume_emoji = "🔈 "
        elseif int_volume_level < 50 then
          volume_emoji = "🔉 "
        elseif int_volume_level < 90 then
          volume_emoji = "🔊 "
        end

        if volume_now.status == "off" then
            vlevel = vlevel .. "#"
            volume_emoji = "🔇"
        else
            vlevel = vlevel .. "%"
        end

        widget:set_markup(markup.fg.color("#ccaacc", volume_emoji .. vlevel))

    end , timeout=3})

-- Separators
first = wibox.widget.textbox(markup.font("Terminus 4", " "))
spr = wibox.widget.textbox(' ⌁ ')


myemailwidget = wibox.widget.textbox()
mybatwidget = wibox.widget.textbox ('')
mysysctlwidget = wibox.widget.textbox ('')
mynetworkwidget = wibox.widget.textbox ('')

notify_bat = true
notify_ram = true
notify_email = true

local lastIp = ''
local lastInt = ''
local lastEssid = ''

function fuckingAct()

    local list=client.get()
    for k, c in pairs(list) do
      awful.client.shape.update.all(c)
      awful.client.shape.update.bounding(c)
      awful.client.shape.update.clip(c)
    end

  awful.tag.viewnext()
  awful.tag.viewnext()
  gears.timer.delayed_call(awful.tag.viewnext)
  act()
  gears.timer.start_new (0.05, awful.tag.viewprev)
  gears.timer.start_new (0.05, awful.tag.viewprev)
end


function act()
    -- vicious.force(mpdwidget)
    --{{ Batterie notification
    awful.spawn.easy_async("bash -c \"acpi | cut -d' ' -f3 \"",
        function(stdout, stderr, reason, exit_code)
            if stdout == "Discharging,\n" then
              awful.spawn.easy_async("bash -c \"acpi | cut -d',' -f2 \"",
              function(percent, stderr, reason, exit_code)
                  a,b = string.find( percent, "%%")
                  nPercent = tonumber(string.sub(percent,2,a-1))

                  if nPercent > 30 then
                    color = "#19DF1D"
                  elseif nPercent > 10 then
                    color = "#E28126"
                  else
                    color = "#FF8080"
                  end

                  mybatwidget:set_markup_silently( markup(color, "🔋 " .. nPercent) .. "%")

                  if notify_bat then
                      if nPercent < 22 and nPercent >= 18 then
                        naughty.notify({ preset = naughty.config.presets.normal,
                        title = "Niveau de batterie",
                        text = "Niveau de batterie inquiétant."
                            .. "Pensez à trouver une prise" })
                      end
                      if nPercent < 12 and nPercent >= 7 then
                        naughty.notify({ preset = naughty.config.presets.critical,
                        title = "Alerte niveau de batterie",
                        text = "Niveau de batterie faible,"
                            .. "pensez à charger le portable" })
                      end
                      if nPercent < 4 then
                        naughty.notify({ preset = naughty.config.presets.critical,
                        title = "Attention niveau batterie critique !",
                        text = "Plus que quelque minutes avant un manque d'energie."
                            .. "Pensez à sauvegarder." })
                      end
                  end
              end)
            else
                awful.spawn.easy_async("bash -c \"acpi | cut -d',' -f2 \"",
                    function(percent, stderr, reason, exit_code)
                        a, b = string.find( percent, "%%")
                        if a then
                            nPercent = tonumber(string.sub(percent,2,a-1))
                            mybatwidget:set_text ("🔌 " .. nPercent .. "%")
                        end
                end)
            end
        end)

    textStat = " / "
    --{{ systemctl status
    awful.spawn.easy_async("pidof wpa_supplicant", function(out, a, reason, exit_code)
      textStat = ""
      if exit_code == 0 then
        textStat = textStat .. "📡 | "
      end
      mysysctlwidget:set_text ( textStat )
    end
    )
    awful.spawn.easy_async("systemctl status bluetooth", function(out, _, reason, exit_code)
      if exit_code == 0 then
        textStat = textStat .. "💎 | "
      end
      mysysctlwidget:set_text ( textStat )
    end
    )
    awful.spawn.easy_async("systemctl status sshd", function(out, _, reason, exit_code)
      if exit_code == 0 then
        textStat = textStat .. "🐚 | "
      end
      mysysctlwidget:set_text ( textStat )
    end
    )
    --{{ Network
    awful.spawn.easy_async("bash -c \"ip r | grep default | head -n 1 | sed s/.*dev/sed/ | cut -d' ' -f 2\"",
        function(interface_default, stderr, reason, exit_code)
            if not ( interface_default == "" or interface_default == "\n") then
                interface_default = string.gsub(interface_default, "\n", "")
                if not (interface_default == lastInt) then
                    if not lastInt == "" then
                      naughty.notify({ preset = naughty.config.presets.normal,
                          title = "ip change",
                          text = "Changement d'interface par defaut " .. lastInt .. " par "
                                  .. interface_default,
                          timeout=20})
                    else
                       naughty.notify({ preset = naughty.config.presets.normal,
                          title = "new ip",
                          text = "Connection à " .. interface_default,
                          timeout=20})
                    end
                    lastInt = interface_default
                end

                awful.spawn.easy_async("bash -c \"ip r | grep 'dev " .. interface_default .. "' | grep src | head -n 1 | sed 's/.*src/src/' | cut -d' ' -f 2 | cut -z -f1\"",

                    function(ip, stderr2, reason3, exit_code3)

                        toShow = ""
                        if not ( ip == "" or ip == "\n") then
                            ip = string.gsub(ip, "\n", "")
                            toShow = ip .. "@"
                            if not (ip == lastIp) then
                                if not lastIp == "" then
                                  naughty.notify({ preset = naughty.config.presets.normal,
                                      title = "ip route",
                                      text = "Changement de route " .. lastIp ..
                                             " vers " .. ip,
                                      timeout=20})
                                else
                                  naughty.notify({ preset = naughty.config.presets.normal,
                                      title = "ip route",
                                      text = "Initialisation de la route par defaut vers " .. ip,
                                      timeout=20})
                                end
                                lastIp = ip
                            end
                        end

                        toShow = toShow .. interface_default



                        interface_wifi = guess_wifi("/sys/class/net/")


                        if interface_wifi ~= "" then
                          awful.spawn.easy_async("bash -c \"printf '%b' $(iwconfig " .. interface_wifi .." 2>&1 | grep -v 'no wireless' | grep ESSID | grep -v 'off/any' | tail -n 1 | cut -d'\\\"' -f 2)\"",
                          function(essid, stderr2, reason2, exit_code2)
                            if essid ~= "" then
                                essid = string.gsub(essid, "\n", "")
                                if interface_wifi ~= interface_default then
                                  toShow = toShow .. " ⏸️"
                                else
                                  toShow = toShow .. " ▶️"
                                end
                                toShow = toShow .. "[" .. essid  .. "]"
                                mynetworkwidget:set_text ( toShow )

                                if essid ~= lastEssid then
                                  naughty.notify({ preset = naughty.config.presets.normal,
                                  title = "Connection Wifi",
                                  text = "Connecté à " .. essid .. " !",
                                  timeout=20})
                                  lastEssid = essid
                                end

                                awful.spawn.easy_async("bash -c \"iwconfig wlan0 2>&1 | grep -i quality | grep -v 'no wireless' | cut -d'=' -f 2 | cut -d' ' -f1\"",
                                    function(signal, stderr3, reason3, exit_code3)
                                      if signal ~= "" then
                                        signal = string.gsub(signal, "\n", "")
                                        toShow = toShow .. "(📶" .. signal .. ")"
                                        mynetworkwidget:set_text ( toShow )
                                      end
                                    end
                                )
                            end
                          end
                          )
                        end
                        mynetworkwidget:set_text ( toShow )
                    end
                )
            else
                mynetworkwidget:set_markup("")
            end
        end
    )

    --{{ E-mail notification
    awful.spawn.easy_async(
      "bash -c \"which hasMail > /dev/null 2>&1 && hasMail\"",
      function(res, stderr, reason, exit_code)
        if res == "0\n" or notify_email == false then
            myemailwidget:set_text ( "" )
        elseif res == "" then
            myemailwidget:set_text ( "☠" )
        else
            myemailwidget:set_text ( "📧" .. res)
            naughty.notify({ preset = naughty.config.presets.normal,
            title = "T'as un email",
            text = string.gsub(res, "\n", "") .. " new mails !" })
        end
      end
    )

end

act()

mytimer = timer { timeout = 60 }
mytimer:connect_signal("timeout", act)

-- Create a wibox for each screen and add it
mywibox = {}
mypromptbox = {}
mytaglist = {}
mytaglist.buttons = awful.util.table.join(
                    awful.button({ }, 1, awful.tag.viewonly),
                    awful.button({ modkey }, 1, awful.client.movetotag),
                    awful.button({ }, 3, awful.tag.viewtoggle),
                    awful.button({ modkey }, 3, awful.client.toggletag),
                    awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
                    awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
                    )
mytasklist = {}
mytasklist.buttons = awful.util.table.join(
                     awful.button({ }, 1, function (c)
                                              if c == client.focus then
                                                  c.minimized = true
                                              else
                                                  -- Without this, the following
                                                  -- :isvisible() makes no sense
                                                  c.minimized = false
                                                  if not c:isvisible() then
                                                      awful.tag.viewonly(c:tags()[1])
                                                  end
                                                  -- This will also un-minimize
                                                  -- the client, if needed
                                                  client.focus = c
                                                  c:raise()
                                              end
                                          end),
                     awful.button({ }, 3, function ()
                                              if instance then
                                                  instance:hide()
                                                  instance = nil
                                              else
                                                  instance = awful.menu.clients({ width=250 })
                                              end
                                          end),
                     awful.button({ }, 4, function ()
                                              awful.client.focus.byidx(1)
                                              if client.focus then client.focus:raise() end
                                          end),
                     awful.button({ }, 5, function ()
                                              awful.client.focus.byidx(-1)
                                              if client.focus then client.focus:raise() end
                                          end))

for s = 1, screen.count() do
    -- Create a promptbox for each screen
    mypromptbox[s] = awful.widget.prompt()
    screen[s].mypromptbox = mypromptbox[s]

    -- Create a taglist widget
    mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)

    -- Create a tasklist widget
    mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)

    -- Create the wibox
    mywibox[s] = awful.wibox({ position = "top", screen = s })
    mywibox[s].visible = true
    -- Widgets that are aligned to the left
    local left_layout = wibox.layout.fixed.horizontal()
    left_layout:add(mylauncher)
    left_layout:add(mytaglist[s])
    left_layout:add(mypromptbox[s])

    -- Widgets that are aligned to the right
    local right_layout = wibox.layout.fixed.horizontal()
    if s == 1 then right_layout:add(wibox.widget.systray()) end
    right_layout:add(spr)
    right_layout:add(mpdwidget)
    right_layout:add(mysysctlwidget)
    right_layout:add(mynetworkwidget)
    right_layout:add(spr)
    right_layout:add(cpuwidget.widget)
    right_layout:add(spr)
    right_layout:add(memwidget.widget)
    right_layout:add(spr)
    right_layout:add(volumewidget.widget)
    right_layout:add(spr)
    right_layout:add(mybatwidget)
    right_layout:add(spr)
    right_layout:add(myemailwidget)
    right_layout:add(mytextclock)
mytimer:start()

    -- Now bring it all together (with the tasklist in the middle)
    local layout = wibox.layout.align.horizontal()
    layout:set_left(left_layout)
    layout:set_middle(mytasklist[s])
    layout:set_right(right_layout)

    mywibox[s]:set_widget(layout)
end
-- }}}


wp_timer = timer { timeout = 15 }
wp_timer:connect_signal("timeout", function() showHideWibox() end)

blockWibox = true

function showHideWibox()
 if not blockWibox then
   for s = 1, screen.count() do
       mywibox[s].visible = not mywibox[s].visible
   end
   if mywibox[1].visible then
     wp_timer:start()
   else
     wp_timer:stop()
   end
 end
end

function showHide()

end

function hideNotification()
end

local rule_any2 = {class={"Weechat", "weechat"}}
for group_name, group_data in pairs({
        ["Weechat"] = { color="#659FdF", rule_any=urxvt_rule_any},
        ["Vim"] = { color="#C59FdF", rule_any=urxvt_rule_any}
}) do
    hotkeys_popup.group_rules[group_name] = group_data
end

local own_rule_any = {
    ["Weechat"] = {
        {
            modifiers = { "Alt" },
            keys = {
                Left = "Tampon précédent"
            }
        },
        {
            modifiers = {"Alt"},
            keys = {
                Right = "Tampon suivant"
            }
        },
        {
            modifiers = {"F7"},
            keys = { v = "Fenêtre précédente" }
        },
        {
            modifiers = {"F8"},
            keys = { v = "Fenêtre suivante" }
        },
        {
            modifiers = {"F11"},
            keys = { v = "Pseudo précédente" }
        },
        {
            modifiers = {"F12"},
            keys = { v = "Pseudo suivant" }
        },
        {
            modifiers = {"Alt"},
            keys = {
                a = "Sauter au "
            }
        }
    },
    ["Vim"] = {
        {
            modifiers = {"z"},
            keys = {
                R = "Open every",
                M = "Fold every",
                a = "Toogle fold",
                A = "Toogle recursively"
            }
        }
    }
}
hotkeys_popup.add_hotkeys(own_rule_any)

layoutKkb = 1

-- {{{ Key bindings
globalkeys = awful.util.table.join(



awful.key({ modkey, "Mod1"      }, "#43",    hotkeys_popup.show_help, {description="Show help", group="awesome"}),
    awful.key({ modkey,           }, "#9", awful.tag.history.restore --[[, {description = "go back", group = "tag"} --]]),



    -- Layout manipulation
    awful.key({ modkey, "Shift"   }, "#44", function () awful.client.swap.byidx(  1)    end,
              {description = "Swap with next client by index", group = "client"}),
    awful.key({ modkey, "Shift"   }, "#45", function () awful.client.swap.byidx( -1)    end,
              {description = "Swap with previous client by index", group = "client"}),
    awful.key({ modkey,           }, "#30", awful.client.urgent.jumpto,
              {description = "Jump to urgent client", group = "client"}),


 -- Raccourcis perso
    awful.key({ }, "#123", function ()
      awful.util.spawn("pamixer -i 2") end),
    awful.key({ }, "#122", function ()
      awful.util.spawn("pamixer -d 2") end),
    awful.key({ }, "#121", function ()
      awful.util.spawn("pamixer -t") end),
    awful.key({ }, "#96", function ()
      awful.util.spawn("pamixer -i 2") end),
    awful.key({ }, "#76", function ()
      awful.util.spawn("pamixer -d 2") end),
    awful.key({ }, "#95", function ()
      awful.util.spawn("pamixer -t") end),

    awful.key({ }, "#172", function ()
      awful.util.spawn("mpc toggle") end),
    awful.key({ }, "#171", function ()
      awful.util.spawn("mpc next") end),
    awful.key({ }, "#173", function ()
      awful.util.spawn("mpc prev") end),
    awful.key({ "Control" }, "#95", function ()
      awful.util.spawn("mpc toggle") end),
    awful.key({ "Control" }, "#96", function ()
      awful.util.spawn("mpc next") end),
    awful.key({ "Control" }, "#76", function ()
      awful.util.spawn("mpc prev") end),
    awful.key({ modkey }, "#95", function ()
      awful.util.spawn("pavucontrol") end),


    awful.key({ modkey}, "#67", function ()
        awful.util.spawn("kitty -e ncmpcpp") end,
        {description = "MPD", group = "awesome"}),
    awful.key({ modkey, "Mod1" }, "#68", function ()
        awful.util.spawn("kitty -e mutt") end,
        {description = "mutt", group = "awesome"}),
    awful.key({ modkey, "Control" }, "#69", function ()
      naughty.destroy_all_notifications(nil,naughty.notificationClosedReason.dismissedByUser)
    end),

    awful.key({ modkey, "Mod1"}, "#41", function () awful.util.spawn("firefox") end,
        {description = "Firefox", group = "awesome"}),
--    awful.key({ modkey,       }, "b", function () awful.util.spawn("vimb -c /usr/share/vimb/.vimbrc") end),
    awful.key({ modkey, "Mod1"}, "#27", function () awful.util.spawn_with_shell("kitty -e 'ranger'") end,
              {description = "Ranger", group = "awesome"}),
    awful.key({ modkey, "Control"}, "#27", function () awful.util.spawn("caja") end),
    awful.key({ modkey,  }, "#39", function ()
      awful.util.spawn("bash -c \"maim -u | xclip -selection clipboard -t image/png\"")
      naughty.notify({ title = 'Maim', text = 'New screenshot taken', timeout = 3 })
    end,
              {description = "Screenshot", group = "awesome"}),
    awful.key({ modkey, "Shift" }, "#54", function ()
      awful.util.spawn("xsel -x")
      naughty.notify({ title = 'Maim', text = 'New screenshot taken', timeout = 3 })
    end,
              {description = "Switch PRIMARY and SECONDARY clipboard", group = "awesome"}),
    awful.key({ modkey, "Control" }, "#54", function ()
      awful.spawn.easy_async("clip2file",
        function(res, stderr, reason, exit_code)
          if exit_code == 0 then
            naughty.notify({title='Maim', text='Clipboard saved !', timeout=3})
          else
            naughty.notify({preset=naughty.config.presets.critical, title='Maim', text=stderr, timeout=3 })
          end
        end
      )
    end,
              {description = "Save clipboard to file", group = "awesome"}),
    awful.key({ modkey,  "Shift"}, "#39", function ()
      awful.util.spawn("bash -c \"maim -u -s | xclip -selection clipboard -t image/png\"")
      naughty.notify({ title = 'Maim', text = 'New screenshot taken', timeout = 3 })
    end,
              {description = "Screenshot of selectionned area", group = "awesome"}),
    awful.key({ modkey, "Control" }, "#39", function ()
      awful.util.spawn("bash -c \"maim -u -i $(xdotool getactivewindow) | xclip -selection clipboard -t image/png\"")
      naughty.notify({ title = 'Maim', text = 'Screenshot of focused windows', timeout = 2 })
    end,
              {description = "Screenshot of focused windows", group = "awesome"}),
    awful.key({ modkey,           }, "#113",
      function ()
          local screen = awful.screen.focused()
          local tag = screen.tags[1]
          local lastTag = screen.tags[9]

          if tag == awful.tag.selected(1) then
             lastTag:view_only()
          else
            awful.tag.viewprev()
          end
      end,
              {description = "Previous", group = "tag"}),
    awful.key({ modkey,           }, "#114",
      function ()
          local screen = awful.screen.focused()
          local tag = screen.tags[9]
          local firstTag = screen.tags[1]

          if tag == awful.tag.selected(1) then
             firstTag:view_only()
          else
            awful.tag.viewnext()
          end
      end,
              {description = "Next", group = "tag"}),
    awful.key({ modkey, "Control" }, "#113",  function() awful.screen.focus_relative(-1) end,
              {description = "Next screen", group = "awesome"}),
    awful.key({ modkey, "Control" }, "#114", function() awful.screen.focus_relative( 1) end,
              {description = "Previous screen", group = "awesome"}),
    awful.key({ modkey,           }, "#9", fuckingAct),
    awful.key({ modkey,           }, "#23",
        function ()
            awful.client.focus.byidx( 1)
            if client.focus then client.focus:raise() end
        end, {description = "Next client", group = "client"}),
     awful.key({ modkey,  "Shift"  }, "#23",
        function ()
            awful.client.focus.byidx(-1)
            if client.focus then client.focus:raise() end
        end,{description = "Previous client", group = "client"}),

    awful.key({ modkey,           }, "#52", function () awful.util.spawn("autoWall") end,
              {description = "Switch wallpaper", group = "awesome"}),
    awful.key({ modkey, "Control" }, "#52", function () act() end,
              {description = "Actualise Wibox", group = "awesome"}),
    awful.key({ modkey, "Shift"   }, "#52", function () awful.util.spawn("passmenu --type -matching fuzzy -theme gruvbox-dark-hard") end,
              {description = "🔑 Passwd promt", group = "awesome"}),
    awful.key({ modkey, "Mod1"   }, "#52", function () awful.util.spawn("passmenu --type") end,
              {description = "🔑 Passwd promt alt", group = "awesome"}),
    awful.key({ modkey, "Control" }, "#53", function () awful.util.spawn("locker") end,
              {description = "Lock screen", group = "awesome"}),

    -- Layout manipulation
    awful.key({ modkey, "Mod1"   }, "#45", function () awful.util.spawn("xkill") end,
              {description = "xkill", group = "awesome"}),
    awful.key({ modkey, "Control" }, "#44", function () awful.screen.focus_relative( 1) end),
    awful.key({ modkey, "Control" }, "#45", function () awful.screen.focus_relative(-1) end),
    awful.key({ modkey,           }, "#30", awful.client.urgent.jumpto),

    -- Standard program
    awful.key({ modkey,           }, "#36", function () awful.util.spawn(terminal) end,
              {description = "new term", group = "awesome"}),
    awful.key({ modkey, "Shift"   }, "#27", awesome.restart, {description = "restart", group = "awesome"}),
    awful.key({ modkey, "Shift"   }, "#38", awesome.quit,{description = "quit", group = "awesome"}),

    awful.key({ modkey,           }, "#46",     function () awful.tag.incmwfact( 0.05)    end),
    awful.key({ modkey,           }, "#43",     function () awful.tag.incmwfact(-0.05)    end),
    awful.key({ modkey,           }, "#44",     function () awful.client.incwfact( 0.05)  end),
    awful.key({ modkey,           }, "#45",     function () awful.client.incwfact(-0.05)  end),
    awful.key({ modkey, "Shift"   }, "#43",     function () awful.tag.incnmaster( 1)      end),
    awful.key({ modkey, "Shift"   }, "#46",     function () awful.tag.incnmaster(-1)      end),
    awful.key({ modkey, "Control" }, "#43",     function () awful.tag.incncol( 1)         end),
    awful.key({ modkey, "Control" }, "#46",     function () awful.tag.incncol(-1)         end),
    awful.key({ modkey,           }, "#65", function () awful.layout.inc(1)
							 naughty.notify({ title = 'Layout', text = awful.layout.getname(), timeout = 1 }) end, {description = "Next layout", group = "client"}),
    awful.key({ modkey, "Shift"   }, "#65", function () awful.layout.inc(-1)
							 naughty.notify({ title = 'Layout', text = awful.layout.getname(), timeout = 1 }) end, {description = "Previous layout", group = "client"}),

-- ## TODO : Add a description for it
    awful.key({ modkey, "Mod1"    }, "#114", function () awful.tag.incmwfact( 0.01)    end),
    awful.key({ modkey, "Mod1"    }, "#113",  function () awful.tag.incmwfact(-0.01)    end),
    awful.key({ modkey, "Mod1"    }, "#116",  function () awful.client.incwfact( 0.01)    end),
    awful.key({ modkey, "Mod1"    }, "#111",    function () awful.client.incwfact(-0.01)    end),


    awful.key({ modkey, "Control" }, "#57", awful.client.restore),
    awful.key({ modkey,             }, "#28", showHideWibox,
              {description = "Toogle Wibox", group = "awesome"}),
    awful.key({ modkey, "Shift"     }, "#28", function () blockWibox = not blockWibox end,
              {description = "Lock Wibox", group = "awesome"}),
    awful.key({ modkey, "Shift"     }, "#56", function ()
        notify_bat = not notify_bat
        naughty.notify({ preset = naughty.config.presets.normal, timeout=1,
                        text = "Notification d'énergie : " .. ( notify_bat and "activée" or "désactivée" )})

        end,
              {description = "Toggle battery warning 🚨", group = "awesome"}),
    awful.key({ modkey, "Control"     }, "#56", function ()
        notify_ram = not notify_ram
        naughty.notify({ preset = naughty.config.presets.normal, timeout=1,
                        text = "Notification de ressource RAM: " .. ( notify_ram and "activée" or "désactivée" )})

        end,
              {description = "Toggle RAM limite warning 🚨", group = "awesome"}),
 
    awful.key({ modkey, "Shift"     }, "#26", function ()
        notify_email = not notify_email
        naughty.notify({ preset = naughty.config.presets.normal, timeout=1,
                        text = "Notification d'email : " .. ( notify_email and "activée" or "désactivée" )})

        end,
              {description = "Toggle email warning 🚨", group = "awesome"}),
    awful.key({ modkey, "Control"   }, "#28", showHideWibox),


    -- Prompt
--    awful.key({ modkey },            "r",     function () awful.screen.focused().mypromptbox:run() end,
--              {description = "run prompt", group = "launcher"}),
    awful.key({ modkey }, "#53",
              function ()
                  --[[
                  awful.prompt.run {
                    prompt       = "Run Lua code: ",
                    textbox      = awful.screen.focused().mypromptbox.widget,
                    exe_callback = awful.util.eval,
                    history_path = awful.util.get_cache_dir() .. "/history_eval"
                }
                ]]
                awful.util.spawn("rofi -show run -modi run -matching fuzzy")
              end,{description = "Run rofi prompt", group = "awesome"}),
    awful.key({ modkey }, "#51",
              function ()
                  awful.prompt.run {
                    prompt       = "Run Lua code: ",
                    textbox      = awful.screen.focused().mypromptbox.widget,
                    exe_callback = awful.util.eval,
                    history_path = awful.util.get_cache_dir() .. "/history_eval"
                }
              end,{description = "Run Lua code", group = "awesome"}),
    awful.key({ modkey, "Shift" }, "#61",
              function ()
                awful.util.spawn("xset s off")
                awful.util.spawn("xset s 0 0 0")
                awful.util.spawn("xset -dpms")
              end,{description = "🔐 lock screen", group = "awesome"}),
    awful.key({ modkey }, "#61",
              function ()
                awful.util.spawn("loginctl lock-session")
              end,{description = "🔐 lock screen", group = "awesome"}),
    awful.key({ modkey }, "#60",
              function ()
                awful.util.spawn("splatmoji type /home/ache/.config/splatmoji/perso_emoji_list.tsv /home/ache/.config/splatmoji/kaomoji.tsv")
              end,{description = "emoji picker", group = "awesome"}),

    -- Menubar
    awful.key({ modkey }, "#33", function()
          local list=client.get()
          for k, c in pairs(list) do
              -- Without this, the following
              -- :isvisible() makes no sense
              c.minimized = false
              if not c:isvisible() and ok  then
                awful.tag.viewonly(c:tags()[1])
              end
              -- This will also un-minimize
              -- the client, if needed
              client.focus = c
              c:raise()
            end
    end)
)


-- Simple function to move the mouse to the coordinates set above.
 local function moveMouse(x_co, y_co)
     mouse.coords({ x=x_co, y=y_co })
     end
clientkeys = awful.util.table.join(
awful.key({ modkey,           }, "#41",      function (c) c.fullscreen = not c.fullscreen  end,
                    {description = "Set active client fullscreen", group = "client"}),
awful.key({ modkey, "Mod1"    }, "#28",      function (c) c.ontop = not c.ontop  end,
                    {description = "Set active client on top", group = "client"}),
    awful.key({ modkey,           }, "#54",      function (c)
        c:kill()
    end),
    awful.key({ modkey,           }, "#55",      function (c)
      awful.util.spawn("xdotool click 2")
    end),
    awful.key({ modkey, "Control" }, "#65",  awful.client.floating.toggle,
              {description = "Set floating layout", group = "client"}),
    awful.key({ modkey, "Control" }, "#36", function (c) c:swap(awful.client.getmaster()) end),
    awful.key({ modkey,           }, "#32",      awful.client.movetoscreen                        ),
    awful.key({ modkey,           }, "#57",
        function (c)
            -- The client currently has the input focus, so it cannot be
            -- minimized, since minimized clients can't have the focus.
            local A, B
            A=mouse.coords()["x"]
            B=mouse.coords()["y"]
            mouse.coords({ x=0, y=0 })
            c.minimized=true
            mouse.coords({ x=A, y=B })
        end, {description = "Set minimized", group = "client"}),
    awful.key({ modkey, "Control" }, "#33", function () menubar.show() end,
              {description = "Maximize all clients", group = "awesome"}),
   -- all minimized clients are restored
    awful.key({ modkey,  }, "#56",
        function(c)
         --[[
        for c in awful.client.iterate(function (x) x:raise()
                                                   return true
                                                 end) do
            c.minimized=false
        end
        --]]
            local A, B
            A=mouse.coords()["x"]
            B=mouse.coords()["y"]
            mouse.coords({ x=0, y=0 })
            c.minimized=true
            mouse.coords({ x=A, y=B })
        end),
    awful.key({ modkey,           }, "#40",
        function (c)
            c.floating = not c.floating
        end, {description = "Set floating", group = "client"}),
    awful.key({ modkey,           }, "#47",
        function (c)
              c.maximized = not c.maximized
-- Alternative : 
--            c.maximized_horizontal = not c.maximized_horizontal
--            c.maximized_vertical   = not c.maximized_vertical
        end, {description = "Set maximized", group = "client"}),
    awful.key({ modkey, "Control" }, "#47", function (c)
            if c == client.focus then
              c.minimized = true
            else
              -- Without this, the following
              -- :isvisible() makes no sense
              c.minimized = false
            end
          end)
          --[[,
          awful.key({ modkey, "Control" }, "Menu",
          function (c)
            if layoutKbd == 1 then
              layoutKbd = 2
              awful.util.spawn_with_shell("setxkbmap us")
            else if layoutKbd == 2 then
              layoutKbd = 3
              awful.util.spawn_with_shell("setxkbmap dvorak")
            else if layoutKbd == 3 then
              awful.util.spawn_with_shell("setxkbmap fr bepo")
              layoutKbd = 4
       --     else if layoutKbd == 4 then
       --       layoutKbd = 5
       --       awful.util.spawn_with_shell("setxkbmap dvorak fr")
            else
              layoutKbd = 1
              awful.util.spawn_with_shell("setxkbmap fr")
            end end end
          end,{description = "Switch keboard layout", group = "awesome"})
          --]]

)



-- {{{ Signals
-- Signal function to execute when a new client appears.
client.connect_signal("manage", function (c, startup)
    -- Enable sloppy focus
    c:connect_signal("mouse::enter", function(c)
        if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
            and awful.client.focus.filter(c) then
            client.focus = c
        end
    end)

    if not startup then
        -- Set the windows at the slave,
        -- i.e. put it at the end of others instead of setting it master.
        awful.client.setslave(c)

        -- Put windows in a smart way, only if they does not set an initial position.
        if not c.size_hints.user_position and not c.size_hints.program_position then
            awful.placement.no_overlap(c)
            awful.placement.no_offscreen(c)
        end
    end

    local titlebars_enabled = false
    if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
        -- buttons for the titlebar
        local buttons = awful.util.table.join(
                awful.button({ }, 1, function()
                    client.focus = c
                    c:raise()
                    awful.mouse.client.move(c)
                end),
                awful.button({ }, 3, function()
                    client.focus = c
                    c:raise()
                    awful.mouse.client.resize(c)
                end)
                )

        -- Widgets that are aligned to the left
        local left_layout = wibox.layout.fixed.horizontal()
        left_layout:add(awful.titlebar.widget.iconwidget(c))
        left_layout:buttons(buttons)

        -- Widgets that are aligned to the right
        local right_layout = wibox.layout.fixed.horizontal()
        right_layout:add(awful.titlebar.widget.floatingbutton(c))
        right_layout:add(awful.titlebar.widget.maximizedbutton(c))
        right_layout:add(awful.titlebar.widget.stickybutton(c))
        right_layout:add(awful.titlebar.widget.ontopbutton(c))
        right_layout:add(awful.titlebar.widget.closebutton(c))

        -- The title goes in the middle
        local middle_layout = wibox.layout.flex.horizontal()
        local title = awful.titlebar.widget.titlewidget(c)
        title:set_align("center")
        middle_layout:add(title)
        middle_layout:buttons(buttons)

        -- Now bring it all together
        local layout = wibox.layout.align.horizontal()
        layout:set_left(left_layout)
        layout:set_right(right_layout)
        layout:set_middle(middle_layout)

        awful.titlebar(c):set_widget(layout)
    end
end)

-- }}}
for i = 1, 9 do
    globalkeys = awful.util.table.join(globalkeys,
        -- View tag only.
        awful.key({ modkey }, "#" .. i + 9,
                  function ()
                        local screen = awful.screen.focused()
                        local tag = screen.tags[i]
                        if tag then
                           tag:view_only()
                        end
                  end --[[,
                  {description = "view tag #"..i, group = "tag"}--]]),
        -- Toggle tag display.
        awful.key({ modkey, "Control" }, "#" .. i + 9,
                  function ()
                      local screen = awful.screen.focused()
                      local tag = screen.tags[i]
                      if tag then
                         awful.tag.viewtoggle(tag)
                      end
                  end --[[,
                  {description = "toggle tag #" .. i, group = "tag"}--]]),
        -- Move client to tag.
        awful.key({ modkey, "Shift" }, "#" .. i + 9,
                  function ()
                      if client.focus then
                          local tag = client.focus.screen.tags[i]
                          if tag then
                              client.focus:move_to_tag(tag)
                          end
                     end
                  end --[[,
                  {description = "move focused client to tag #"..i, group = "tag"}--]]),
        -- Toggle tag on focused client.
        awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
                  function ()
                      if client.focus then
                          local tag = client.focus.screen.tags[i]
                          if tag then
                              client.focus:toggle_tag(tag)
                          end
                      end
                  end --[[, {description = "toggle focused client on tag #" .. i, group = "tag"}--]]),


        awful.key({	modkey, "Mod1"}, "p", function () if not pomowibox.visible then pomodoro:toggle() end end),
        awful.key({	modkey, "Ctrl"}, "p", function () if not pomowibox.visible then quickPomodoro:toggle() end end),
        awful.key({	modkey, "Shift"	}, "p", function () pomodoro:finish(); quickPomodoro:finish() end)
  )
end

globalkeys = awful.util.table.join(globalkeys,
  -- Move only last tag.
  awful.key({ modkey }, "Delete",
    function ()
          local screen = awful.screen.focused()
          local tag = screen.tags[10]
          if tag then
             tag:view_only()
          end
    end
  ),
  -- Move client to tag.
  awful.key({ modkey, "Shift" }, "Delete",
    function ()
        if client.focus then
            local tag = client.focus.screen.tags[10]
            if tag then
                client.focus:move_to_tag(tag)
            end
       end
    end
  )
)





clientbuttons = awful.util.table.join(
    awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
    awful.button({ modkey }, 1, awful.mouse.client.move),
    awful.button({ modkey }, 3, awful.mouse.client.resize))

-- Set keys
root.keys(globalkeys)
-- }}}

-- {{{ Rules
-- Rules to apply to new clients (through the "manage" signal).
awful.rules.rules = {
    -- All clients will match this rule.
    { rule = { },
      properties = { border_width = beautiful.border_width,
                     border_color = beautiful.border_normal,
                     focus = awful.client.focus.filter,
                     raise = true,
                     keys = clientkeys,
                     buttons = clientbuttons,
                     screen = awful.screen.preferred,
                     placement = awful.placement.no_overlap+awful.placement.no_offscreen
     }
    },

    -- Floating clients.
    { rule_any = {
        instance = {
          "DTA",  -- Firefox addon DownThemAll.
          "copyq",  -- Includes session name in class.
        },
        class = {
          "Arandr",
          "Gpick",
          "Kruler",
          "MessageWin",  -- kalarm.
          "Sxiv",
          "Wpa_gui",
          "pinentry",
          "veromix",
          "xtightvncviewer"},

        name = {
          "Event Tester",  -- xev.
        },
        role = {
          "AlarmWindow",  -- Thunderbird's calendar.
          "pop-up",       -- e.g. Google Chrome's (detached) Developer Tools.
        }
      }, properties = { floating = true }},

    -- Add titlebars to normal clients and dialogs
    { rule_any = {type = { "normal", "dialog" }
      }, properties = { titlebars_enabled = true }
    },
}




 awful.util.spawn_with_shell("autoWall") -- Have to be here, to write other the fucking wallpaper of awesome.

 -- awful.util.spawn_with_shell("xbindkeys")
 -- awful.util.spawn_with_shell("setxkbmap -option grab:break_actions")
 -- awful.util.spawn_with_shell("xss-lock -n /usr/lib/xsecurelock/dimmer -l -- /usr/bin/xsecurelock")
 -- -- All moved to .xinitrc.

client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)