summaryrefslogtreecommitdiff
path: root/rc.lua
blob: fa5fb087711a3d7ce5488f503ebe29abeabfb502 (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
-- 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")

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


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




-- {{{ 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

-- 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 = "roxterm"
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"

-- Table of layouts to cover with awful.layout.inc, order matters.
awful.layout.layouts = {
    awful.layout.suit.tile,             --1
    lain.layout.uselesspiral,           --2
    lain.layout.uselessfairnogap,       --3
}
-- }}}

-- {{{ 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 })

-- 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.widgets.calendar:attach(mytextclock)


-- CPU
cpuwidget = lain.widgets.cpu({
    settings = function()
        int_cpu_usage = tonumber(cpu_now.usage)
        widget:set_markup(markup("#cb66cb", "") .. cpu_now.usage .. "%")
    end
})

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

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, 10)

-- MEM
memwidget = lain.widgets.mem({
    settings = function()
        int_mem_now_used = tonumber(mem_now.used)
        widget:set_markup(markup.fg.color("#dda", mem_now.used .. "M"))
    end
})


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

        int_volume_level = tonumber(volume_now.level)

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

        if volume_now.status == "off" then
            vlevel = vlevel .. "#"
        else
            vlevel = vlevel .. "%"
        end
        widget:set_markup(markup.fg.color("#ccaacc", vlevel))
    end
})


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


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


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
                      mybatwidget:set_markup_silently( markup("#19DF1D", "🔋") .. string.sub(percent, 1, a+1))
                  elseif nPercent > 10 then
                      mybatwidget:set_markup_silently( markup("#E28126", "🔋") .. string.sub(percent, 1, a+1))
                  else
                      mybatwidget:set_markup_silently( markup("#E61E1E", "🔋") .. string.sub(percent, 1, a+1))
                  end
                  -- str = awful.util.shell("acpi | cut -d',' -f2")
                  if percent == " 21%\n" or percent == " 20%\n" then
                    naughty.notify({ preset = naughty.config.presets.critical,
                    title = "Niveau de batterie",
                    text = "Niveau de batterie inquiétant."
                        .. "Pensez à trouver une prise" })
                  end
                  if percent == " 8%\n" or percent == " 9%\n" or
                                           percent == " 10%\n" then
                    naughty.notify({ preset = naughty.config.presets.critical,
                    title = "Alerte niveau de batterie",
                    text = "Niveau de batterie faible,"
                        .. "pensez à charger le portable" })
                  end
                  if percent == " 4%\n" or percent == " 5%\n" 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)
          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
                          mybatwidget:set_text ("🔌" .. string.sub(percent, 1, a+1))
                      end
              end)
          end
        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, stderr, reason, exit_code)
            if not ( interface == "" or interface == "\n") then
                interface = string.gsub(interface, "\n", "")
                awful.spawn.easy_async("bash -c \"ip r | grep 'dev " .. interface .. "' | 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 .. "@"
                        end
                        awful.spawn.easy_async("bash -c \"iwconfig wlp3s0 2>1 | grep -v 'no wireless' | grep wlp3s0 | cut -d'\\\"' -f 2 \"",
                        function(essid, stderr2, reason2, exit_code2)
                            if not (essid == "" ) then
                                essid = string.gsub(essid, "\n", "")
                                awful.spawn.easy_async("bash -c \"iwconfig " .. interface .. " 2>1 | grep -v 'no wireless' | grep Signal | cut -d'=' -f 3 | cut -d' ' -f 1\"",
                                    function(signal, stderr3, reason3, exit_code3)
                                        signal = string.gsub(signal, "\n", "")
                                        mynetworkwidget:set_text ( ip .. "@" .. essid .. "#" .. signal)
                                    end
                                )
                            else
                                mynetworkwidget:set_text ( toShow .. interface )
                            end
                        end
                        )
                    end
                )
            else
                mynetworkwidget:set_markup( "<s>ip</s>" )
            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" then
            myemailwidget:set_text ( "" )
        elseif res == "" then
            myemailwidget:set_text ( "☠" )
        else
            myemailwidget:set_text ( "📧" )
            naughty.notify({ preset = naughty.config.presets.normal,
            title = "T'as un email",
            text = "Hey mec ! e-mail !" })
        end
      end)

  end 

act()

mytimer = timer { timeout = 60 }
mytimer:connect_signal("timeout", function() act() end)
  
-- 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(mynetworkwidget)
    right_layout:add(spr)
    right_layout:add(cpuwidget)
    right_layout:add(spr)
    right_layout:add(memwidget)
    right_layout:add(spr)
    right_layout:add(volumewidget)
    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

local rule_any2 = {class={"Weechat", "weechat"}}
for group_name, group_data in pairs({
        ["Weechat"] = { color="#659FdF", 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 "
            }
        }
    }
}
hotkeys_popup.add_hotkeys(own_rule_any)






layoutKkb = 1



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

awful.key({ modkey, "Shift"      }, "s",    hotkeys_popup.show_help, {description="Show help", group="awesome"}),
    awful.key({ modkey,           }, "Escape", awful.tag.history.restore --[[, {description = "go back", group = "tag"} --]]),



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




 -- Raccourcis perso
    awful.key({ }, "XF86AudioRaiseVolume", function ()
      awful.util.spawn("amixer set Master 9%+") end),
    awful.key({ }, "XF86AudioLowerVolume", function ()
      awful.util.spawn("amixer set Master 9%-") end),
    awful.key({ }, "XF86AudioMute", function ()
      awful.util.spawn("amixer sset Master toggle") end),
    awful.key({ }, "XF86AudioPlay", function ()
      awful.util.spawn("mpc toggle") end),
    awful.key({ }, "XF86AudioNext", function ()
      awful.util.spawn("mpc next") end),
    awful.key({ }, "XF86AudioPrev", function ()
      awful.util.spawn("mpc prev") end),
    awful.key({ modkey}, "F1", function ()
        awful.util.spawn("roxterm -e bash -c \"mpd;mpc random on;mpc repeat on;ncmpcpp\"") end,
        {description = "MPD", group = "awesome"}),
    awful.key({ modkey}, "F2", function ()
        awful.util.spawn("roxterm -e mutt") end,
        {description = "mutt", group = "awesome"}),

    awful.key({ modkey, "Mod1"}, "f", function () awful.util.spawn("firefox") end,
        {description = "Firefox", group = "awesome"}),
    awful.key({ modkey,       }, "t", function () awful.util.spawn("uzbl-browser") end),
--    awful.key({ modkey,       }, "b", function () awful.util.spawn("vimb -c /usr/share/vimb/.vimbrc") end),
    awful.key({ modkey, "Mod1"}, "t", function () awful.util.spawn("proxychains uzbl-browser") end),
    awful.key({ modkey, "Mod1"}, "b", function () awful.util.spawn("proxychains vimb -c /usr/share/vimb/.vimbrc http://duckduckgo.com") end),
    awful.key({ modkey, "Mod1"}, "q", function () awful.util.spawn("uzbl-browser http://duckduckgo.com > /dev/null") end), 
    awful.key({ modkey, "Mod1"}, "r", function () awful.util.spawn_with_shell("xterm -e 'ranger'") end,
              {description = "Ranger", group = "awesome"}),
    awful.key({ modkey, "Control"}, "r", function () awful.util.spawn("pcmanfm") end),
    awful.key({ modkey, "Mod1"}, "v", function () awful.util.spawn("gvim") end),
    awful.key({ modkey,  }, "s", function () awful.util.spawn("scrot") end,
              {description = "Screenshot", group = "awesome"}),
    awful.key({ modkey, "Control" }, "s", function () awful.util.spawn("scrot -u") end,
              {description = "Screenshot selection", group = "awesome"}),


    awful.key({ modkey,           }, "Left",   awful.tag.viewprev,
              {description = "Previous", group = "tag"}),
    awful.key({ modkey,           }, "Right",  awful.tag.viewnext,
              {description = "Next", group = "tag"}),
    awful.key({ modkey, "Control" }, "Left",  function() awful.screen.focus_relative(-1) end,
              {description = "Next screen", group = "awesome"}),
    awful.key({ modkey, "Control" }, "Right", function() awful.screen.focus_relative( 1) end,
              {description = "Previous screen", group = "awesome"}),
    awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
    

    awful.key({ modkey,           }, "Tab",
        function ()
            awful.client.focus.byidx( 1)
            if client.focus then client.focus:raise() end
        end, {description = "Next client", group = "client"}),
     awful.key({ modkey,  "Shift"  }, "Tab",
        function ()
            awful.client.focus.byidx(-1)
            if client.focus then client.focus:raise() end
        end,{description = "Previous client", group = "client"}),
--        


    awful.key({ modkey,           }, "w", function () awful.util.spawn("autoWall") end,
              {description = "Switch wallpaper", group = "awesome"}),
    awful.key({ modkey, "Control" }, "w", function () act() end,
              {description = "Actualise Wibox", group = "awesome"}),
    awful.key({ modkey, "Shift"   }, "w", function () awful.util.spawn("passmenu") end,
              {description = "Passwd promt", group = "awesome"}),
    awful.key({ modkey, "Control" }, "x", function () awful.util.spawn("xscreensaver-command --lock") end,
              {description = "Lock screen", group = "awesome"}),

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

    -- Standard program
    awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end,
              {description = "new term", group = "awesome"}),
    awful.key({ modkey, "Shift"   }, "r", awesome.restart, {description = "restart", group = "awesome"}),
    awful.key({ modkey, "Shift"   }, "q", awesome.quit,{description = "quit", group = "awesome"}),

    awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
    awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
    awful.key({ modkey,           }, "j",     function () awful.client.incwfact( 0.05)  end),
    awful.key({ modkey,           }, "k",     function () awful.client.incwfact(-0.05)  end),
    awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
    awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
    awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
    awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
    awful.key({ modkey,           }, "space", 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"   }, "space", 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"    }, "Right", function () awful.tag.incmwfact( 0.01)    end),
    awful.key({ modkey, "Mod1"    }, "Left",  function () awful.tag.incmwfact(-0.01)    end),
    awful.key({ modkey, "Mod1"    }, "Down",  function () awful.client.incwfact( 0.01)    end),
    awful.key({ modkey, "Mod1"    }, "Up",    function () awful.client.incwfact(-0.01)    end),


    --~ awful.key({ modkey, "Control" }, "n", awful.client.restore),
    awful.key({ modkey,             }, "t", function () showHideWibox() end,
              {description = "Toogle Wibox", group = "awesome"}),
    awful.key({ modkey, "Shift"     }, "t", function () blockWibox = not blockWibox end,
              {description = "Lock Wibox", group = "awesome"}),
    awful.key({ modkey, "Control"   }, "t", function () showHideWibox() end),
	

    -- Prompt
--    awful.key({ modkey },            "r",     function () awful.screen.focused().mypromptbox:run() end,
--              {description = "run prompt", group = "launcher"}),
    awful.key({ modkey }, "x",
              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")
              end,{description = "Run rofi prompt", group = "awesome"}),
    -- Menubar
    awful.key({ modkey }, "p", 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,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end,
                    {description = "Set active client fullscreen", group = "client"}),
    awful.key({ modkey,           }, "c",      function (c)
      if c.name == "Lecteur multimédia VLC" then
        awful.util.spawn_with_shell('sleep 0.3;xte "keydown Control_L" "keydown v" "keyup v" "keyup Control_L"')
      else
        c:kill()
      end
    
    
    end),
    awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle,
              {description = "Set floating layout", group = "client"}),
    awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
    awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
    awful.key({ modkey,           }, "n",
        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" }, "p", function () menubar.show() end,
              {description = "Maximize all clients", group = "awesome"}),
   -- all minimized clients are restored 
    awful.key({ modkey,  }, "b", 
        function()
        for c in awful.client.iterate(function (x) x:raise()
                                                   return true
                                                 end) do
            c.minimized=false
        end
        end),
    awful.key({ modkey,           }, "d",
        function (c)
            c.floating = not c.floating
        end, {description = "Set floating", group = "client"}),
    awful.key({ modkey,           }, "m",
        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" }, "m", 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"}--]])
    )
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("xbindkeys")
awful.util.spawn_with_shell("autoWall")
awful.util.spawn_with_shell("setxkbmap -option grab:break_actions")

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)