Source

profile.d / awesome / rc.lua

Full commit
  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
require("awful")
require("awful.autofocus")
require("beautiful")
require("shifty")
require("naughty")

-- configuration variables
-- -- default modkey
modkey = "Mod4"

-- -- table of layouts
layouts = {
    awful.layout.suit.tile,
    awful.layout.suit.tile.left,
    awful.layout.suit.tile.bottom,
    awful.layout.suit.tile.top,
    awful.layout.suit.fair,
    awful.layout.suit.fair.horizontal,
    awful.layout.suit.max,
    awful.layout.suit.max.fullscreen,
    awful.layout.suit.magnifier,
    awful.layout.suit.floating
}

-- -- initialize theme
beautiful.init(os.getenv("HOME") .. "/.config/awesome/theme")

-- tags
shifty.config.tags = {
   ["music"] = {
      exclusive = true,
      layout = awful.layout.suit.max,
      position = 1,
      screen = 1,
   },
   ["mail"] = {
      exclusive = true,
      position = 2,
      layout = awful.layout.suit.max,
      screen = 1,
   },
   ["www"] = {
      init = true,
      exclusive = true,
      position = 3,
      layout = awful.layout.suit.max,
      screen = 1,
   },
   ["gimp"] = {
      layout = awful.layout.suit.tile,
      mwfact = 0.18,
      screen = 2,
   },
   ["inkscape"] = {
      exclusive = true,
      layout = awful.layout.suit.max,
      screen = 2,
   },
   ["pdf"] = {
      exclusive = true,
      layout = awful.layout.suit.max,
      screen = 2,
   },
   ["ooffice"] = {
      layout = awful.layout.suit.max,
      screen = 2,
   },
   ["rawtherapee"] = {
      layout = awful.layout.suit.max,
      screen = 2,
   },
   ["wireshark"] = {
      layout = awful.layout.suit.max,
      screen = 2,
   },
   ["remote"] = {
      layout = awful.layout.suit.max,
      screen = 2,
   },
   ["emacs.*"] = {
      layout = awful.layout.suit.tile.bottom,
      mwfact = 0.58,
      nmaster = 2,
      ncol = 1,
      screen = 2,
   },
}

shifty.config.apps = {
   {
      match = { "gajim", "pinentry", "xcalc", "thunar", "MPlayer.*",
                "qemu", "kvm", "StoryEditor.*", "urxvt.vt100" },
      float = true,
      intrusive = true,
   },

   { match = { "Firefox", "Iceweasel.*" },  tag = "www"         },
   { match = { "chromium" },                tag = "www"         },
   { match = { "Claws%-mail" },             tag = "mail"        },
   { match = { "acroread.*" },              tag = "pdf"         },
   { match = { "quodlibet" },               tag = "music"       },
   { match = { "Gimp", "Ufraw" },           tag = "gimp"        },
   { match = { "gimp%-image%-window" },     slave = true        },
   { match = { "Rt" },                      tag = "rawtherapee" },
   { match = { "Inkscape" },                tag = "inkscape"    },
   { match = { "Wireshark" },               tag = "wireshark"   },
   { match = { "OpenOffice.*" },            tag = "ooffice"     },
   { match = { "Remmina" },                 tag = "remote"     },
}

shifty.config.defaults = {
   layout = awful.layout.suit.fair.horizontal,
   persist = false,
}

-- wibox
taskbar = {}
taskbar.wibox = {}
taskbar.promptbox = {}
taskbar.layoutbox = {}

-- -- taglist and label
taskbar.taglist = {}
taskbar.taglistlabel = widget({ type = "textbox", align = "left" })
taskbar.taglistlabel.text = "<small> </small>tags:<small> </small>"

-- -- tasklist and label
taskbar.tasklist = {}
taskbar.tasklistlabel = widget({ type = "textbox", align = "left" })
taskbar.tasklistlabel.text = "<small> </small>/ tasks:<small> </small>"

-- -- clock widget
taskbar.clockbox = awful.widget.textclock(
   { align = "right" },
   "<small> </small>/ date: %a %d %b %H:%M ")

-- -- systray
taskbar.systray = widget({ type = "systray", align = "right" })

for s = 1, screen.count() do
   taskbar.promptbox[s] = awful.widget.prompt(
      { layout = awful.widget.layout.horizontal.rightleft })
   taskbar.layoutbox[s] = widget({ type = "textbox", align = "left" })

   -- taglist widget
   taskbar.taglist[s] = awful.widget.taglist(
      s,
      function(t)
	 local text, bg, bg_image, icon = awful.widget.taglist.label.all(t)
         return text, bg, nil, nil
      end,
      awful.util.table.join(
         awful.button({ }, 1, awful.tag.viewonly) ))

   -- tasklist widget
   taskbar.tasklist[s] = awful.widget.tasklist(
      function(c)
	 local text, bg, bg_image, icon =
	       awful.widget.tasklist.label.currenttags(c, s)
	 if text then
	    text = " " .. text
	 end

	 return text, bg, nil, nil
      end,
      awful.util.table.join(
         awful.button({ }, 3, function (c)
                                 c.minimized = not c.minimized
                              end) ))

   -- wibox
   taskbar.wibox[s] = awful.wibox({ position = "top",
                                    fg = beautiful.fg_normal,
                                    bg = beautiful.bg_normal,
                                    screen = s })

   -- add widgets to the wibox - order matters
   taskbar.wibox[s].widgets = {
      { taskbar.taglistlabel,
        taskbar.taglist[s],
        taskbar.tasklistlabel,
        layout = awful.widget.layout.horizontal.leftright },
      s == 1 and taskbar.systray or nil,
      taskbar.clockbox,
      taskbar.promptbox[s],
      taskbar.layoutbox[s],
      taskbar.tasklist[s],
      layout = awful.widget.layout.horizontal.rightleft }
end

-- init shifty
shifty.taglist = taskbar.taglist
shifty.init()

-- keybindings
rootkeys = awful.util.table.join(
   -- -- left/right tag switching
   awful.key({ modkey }, "Left",
             function ()
                awful.tag.viewprev()
                for _,cl in pairs(awful.tag.selected():clients()) do
                   cl:redraw()
                end
             end),
   awful.key({ modkey }, "Right",
             function ()
                awful.tag.viewnext()
                for _,cl in pairs(awful.tag.selected():clients()) do
                   cl:redraw()
                end
             end),

   -- -- left/right screen switching
   awful.key({ modkey, "Control" }, "Left",
             function () awful.screen.focus_relative(-1) end),
   awful.key({ modkey, "Control" }, "Right",
             function () awful.screen.focus_relative( 1) end),

   -- -- tool shortcuts
   awful.key({ modkey }, "Return",
             function () awful.util.spawn("urxvt") end),

   awful.key({ modkey, "Shift" }, "Return",
             function () awful.util.spawn("urxvt -name urxvt.small") end),

   awful.key({ modkey, "Control" }, "Return",
             function () awful.util.spawn("urxvt -name urxvt.vt100") end),

   awful.key({ modkey }, "e",
             function () awful.util.spawn("urxvt -e emacs") end),

   -- -- restart and quit
   awful.key({ modkey }, "F11", awesome.restart),
   awful.key({ modkey }, "F12", awesome.quit),

   -- -- client switching
   awful.key({ modkey }, "Tab", function ()
                                   awful.client.focus.byidx(1);
                                   if client.focus then
                                      client.focus:raise()
                                   end
                                end),
   awful.key({ modkey }, "q", function ()
                                 awful.client.focus.byidx(-1);
                                 if client.focus then
                                    client.focus:raise()
                                 end
                              end),

   -- -- client swaping
   awful.key({ modkey, "Shift" }, "Tab", function ()
                                            awful.client.swap.byidx(1)
                                         end),

   -- -- tag manipulation
   awful.key({ modkey }, "t", function ()
                                 shifty.add({ nopopup = true })
                              end),
   awful.key({ modkey }, "w", shifty.del),
   awful.key({ modkey }, "r", shifty.rename),

   -- -- layout switching
   awful.key({ modkey }, "space",
             function () awful.layout.inc(layouts, 1) end),
   awful.key({ modkey, "Shift" }, "space",
             function () awful.layout.inc(layouts, -1) end),

   -- -- layout manipulation
   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, "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),

   -- -- prompt
   awful.key({ modkey }, "1",
             function ()
                awful.prompt.run(
                   { prompt = " / run: " },
                   taskbar.promptbox[mouse.screen].widget,
                   function (cmd)
                      if cmd and cmd ~= "" then
                         cmd =  awful.util.shell .. " -l -c \"" .. cmd .. "\""
                         return awesome.spawn(cmd, false, mouse.screen)
                      end
                   end,
                   awful.completion.shell,
                   awful.util.getdir("cache") .. "/history")
             end),

   -- -- moving clients around tags
   awful.key({ modkey }, "s", awful.client.togglemarked),

   awful.key({ modkey, "Shift" }, "s",
             function ()
                local clients = awful.client.getmarked()
                local sel = awful.tag.selected(mouse.screen)

                for k,c in pairs(clients) do
                   awful.client.movetotag(sel, c)
                   client.focus = c
                end
             end),

   -- -- screen stuff
   awful.key({ "Control", "Mod1" }, "Delete",
             function ()
                awful.util.spawn("xscreensaver-command -lock")
             end)
)

clientkeys = awful.util.table.join(
   -- -- client manipulation
   awful.key({ modkey }, "c",
             function (c)
                c:kill()
             end),
   awful.key({ modkey }, "f", awful.client.floating.toggle),
   awful.key({ modkey, "Shift" }, "f",
             function (c)
                c.fullscreen = not c.fullscreen
             end),
   awful.key({ modkey }, "m",
             function (c)
                c.minimized = true
             end),
   awful.key({ modkey, "Shift" }, "r",
             function (c)
                c:redraw()
             end),

   -- -- information about clients
   awful.key({ modkey }, "i",
             function (c)
                local s = mouse.screen
                local items = {}

                for key,item in pairs({"name", "instance", "class", "role"}) do
                   if c[item] then
                      table.insert(items, item .. ": " .. c[item])
                   end
                end

                naughty.notify( { text = table.concat(items, "\n"),
                                  position = "top_right",
                                  width = 500,
                                  padding = 20,
                                  timeout = 5,
                                  screen = 1,
                                  ontop = true } )
             end)
)


-- Signals
-- -- client focused
client.add_signal(
   "focus",
   function (c)
      if not awful.client.ismarked(c) then
	 c.border_color = beautiful.border_focus
      end
   end)

-- -- client unfocused
client.add_signal(
   "unfocus",
   function (c)
      if not awful.client.ismarked(c) then
	 c.border_color = beautiful.border_normal
      end
   end)

-- -- new client appeared
client.add_signal(
   "manage",
   function (c, startup)
      -- signal for mouse entered client
      c:add_signal(
         "mouse::enter",
         function (c)
            -- Sloppy focus, but disabled for magnifier layout
            if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
            and awful.client.focus.filter(c) then
            client.focus = c
         end
      end)

      -- signal for client marked
      c:add_signal(
         "marked",
         function (c)
            c.border_color = beautiful.border_marked
         end)

      -- signal for client unmarked
      c:add_signal(
         "unmarked",
         function (c)
            c.border_color = beautiful.border_focus
         end)

      -- Add mouse bindings
      c:buttons(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)
      ))

      -- New client may not receive focus
      -- if they're not focusable, so set border anyway.
      c.border_width = beautiful.border_width
      c.border_color = beautiful.border_normal

      -- Do this after tag mapping, so you don't see
      -- it on the wrong tag for a split second.
      client.focus = c
      c.border_color = beautiful.border_focus

      -- Set keys on client
      c:keys(clientkeys)

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

      -- Honor size hints: if you want to drop the gaps between
      --- windows, set this to false.
      c.size_hints_honor = false
   end)

-- -- screen arranging (tag switch, new client, etc.)
for s = 1, screen.count() do
   screen[s]:add_signal(
      "arrange",
      function (screen)
         local layout = awful.layout.get(s)
         local layout_name = awful.layout.getname(layout)
         local tiledclients = awful.client.tiled(s)

         if layout_name then
            taskbar.layoutbox[s].text = "/ layout: " .. layout_name
         else
            taskbar.layoutbox[s].text = ""
         end

         -- Give focus to the latest client in history if no window has
         -- focus or if the current window is a desktop or a dock one.
         if not client.focus then
            local c = awful.client.focus.history.get(s, 0)
            if c then
               client.focus = c
            end
         end
      end)
end

-- spawn xscreensaver
awful.util.spawn("xscreensaver -no-splash")

-- load local modifications
dofile(os.getenv("HOME") .. "/.profile.d/awesome/rc.lua.local")

-- set key bindings
root.keys(rootkeys)