]> git.donarmstrong.com Git - x_base.git/blob - .config/awesome/rc.lua
update rc.lua for awesome3
[x_base.git] / .config / awesome / rc.lua
1 -- Standard awesome library
2 require("awful")
3 -- Theme handling library
4 require("beautiful")
5 -- Notification library
6 require("naughty")
7
8 -- Load Debian menu entries
9 require("debian.menu")
10
11 -- {{{ Variable definitions
12 -- Themes define colours, icons, and wallpapers
13 -- The default is a dark theme
14 theme_path = "/usr/share/awesome/themes/default/theme"
15 -- Uncommment this for a lighter theme
16 -- theme_path = "/usr/share/awesome/themes/sky/theme"
17
18 -- Actually load theme
19 beautiful.init(theme_path)
20
21 -- This is used later as the default terminal and editor to run.
22 terminal = "x-terminal-emulator"
23 editor = os.getenv("EDITOR") or "editor"
24 editor_cmd = terminal .. " -e " .. editor
25
26 -- Default modkey.
27 -- Usually, Mod4 is the key with a logo between Control and Alt.
28 -- If you do not like this or do not have such a key,
29 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
30 -- However, you can use another modifier like Mod1, but it may interact with others.
31 modkey = "Mod4"
32
33 -- Table of layouts to cover with awful.layout.inc, order matters.
34 layouts =
35 {
36     awful.layout.suit.tile,
37     awful.layout.suit.tile.left,
38     awful.layout.suit.tile.bottom,
39     awful.layout.suit.tile.top,
40     awful.layout.suit.fair,
41     awful.layout.suit.fair.horizontal,
42     awful.layout.suit.max,
43     awful.layout.suit.max.fullscreen,
44     awful.layout.suit.magnifier,
45     awful.layout.suit.floating
46 }
47
48 -- Table of clients that should be set floating. The index may be either
49 -- the application class or instance. The instance is useful when running
50 -- a console app in a terminal like (Music on Console)
51 --    x-terminal-emulator -name mocp -e mocp
52 floatapps =
53 {
54     -- by class
55     ["MPlayer"] = true,
56     ["pinentry"] = true,
57     ["gimp"] = true,
58     -- by instance
59     ["mocp"] = true
60 }
61
62 -- Applications to be moved to a pre-defined tag by class or instance.
63 -- Use the screen and tags indices.
64 apptags =
65 {
66     -- ["Firefox"] = { screen = 1, tag = 2 },
67     -- ["mocp"] = { screen = 2, tag = 4 },
68 }
69
70 -- Define if we want to use titlebar on all applications.
71 use_titlebar = false
72 -- }}}
73
74 -- {{{ Tags
75 -- Define tags table.
76 tags = {}
77 for s = 1, screen.count() do
78     -- Each screen has its own tag table.
79     tags[s] = {}
80     -- Create 9 tags per screen.
81     for tagnumber = 1, 9 do
82         tags[s][tagnumber] = tag(tagnumber)
83         -- Add tags to screen one by one
84         tags[s][tagnumber].screen = s
85         awful.layout.set(layouts[1], tags[s][tagnumber])
86     end
87     -- I'm sure you want to see at least one tag.
88     tags[s][1].selected = true
89 end
90 -- }}}
91
92 -- {{{ Wibox
93 -- Create a textbox widget
94 mytextbox = widget({ type = "textbox", align = "right" })
95 -- Set the default text in textbox
96 mytextbox.text = "<b><small> " .. AWESOME_RELEASE .. " </small></b>"
97
98 -- Create a laucher widget and a main menu
99 myawesomemenu = {
100    { "manual", terminal .. " -e man awesome" },
101    { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
102    { "restart", awesome.restart },
103    { "quit", awesome.quit }
104 }
105
106 mymainmenu = awful.menu.new({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
107                                         { "open terminal", terminal },
108                                         { "Debian", debian.menu.Debian_menu.Debian }
109                                       }
110                             })
111
112 mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
113                                      menu = mymainmenu })
114
115 -- Create a systray
116 mysystray = widget({ type = "systray", align = "right" })
117
118 -- Create a wibox for each screen and add it
119 mywibox = {}
120 mypromptbox = {}
121 mylayoutbox = {}
122 mytaglist = {}
123 mytaglist.buttons = { button({ }, 1, awful.tag.viewonly),
124                       button({ modkey }, 1, awful.client.movetotag),
125                       button({ }, 3, function (tag) tag.selected = not tag.selected end),
126                       button({ modkey }, 3, awful.client.toggletag),
127                       button({ }, 4, awful.tag.viewnext),
128                       button({ }, 5, awful.tag.viewprev) }
129 mytasklist = {}
130 mytasklist.buttons = { button({ }, 1, function (c)
131                                           if not c:isvisible() then
132                                               awful.tag.viewonly(c:tags()[1])
133                                           end
134                                           client.focus = c
135                                           c:raise()
136                                       end),
137                        button({ }, 3, function () if instance then instance:hide() end instance = awful.menu.clients({ width=250 }) end),
138                        button({ }, 4, function () awful.client.focus.byidx(1) end),
139                        button({ }, 5, function () awful.client.focus.byidx(-1) end) }
140
141 for s = 1, screen.count() do
142     -- Create a promptbox for each screen
143     mypromptbox[s] = widget({ type = "textbox", align = "left" })
144     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
145     -- We need one layoutbox per screen.
146     mylayoutbox[s] = widget({ type = "imagebox", align = "right" })
147     mylayoutbox[s]:buttons({ button({ }, 1, function () awful.layout.inc(layouts, 1) end),
148                              button({ }, 3, function () awful.layout.inc(layouts, -1) end),
149                              button({ }, 4, function () awful.layout.inc(layouts, 1) end),
150                              button({ }, 5, function () awful.layout.inc(layouts, -1) end) })
151     -- Create a taglist widget
152     mytaglist[s] = awful.widget.taglist.new(s, awful.widget.taglist.label.all, mytaglist.buttons)
153
154     -- Create a tasklist widget
155     mytasklist[s] = awful.widget.tasklist.new(function(c)
156                                                   return awful.widget.tasklist.label.currenttags(c, s)
157                                               end, mytasklist.buttons)
158
159     -- Create the wibox
160     mywibox[s] = wibox({ position = "top", fg = beautiful.fg_normal, bg = beautiful.bg_normal })
161     -- Add widgets to the wibox - order matters
162     mywibox[s].widgets = { mylauncher,
163                            mytaglist[s],
164                            mytasklist[s],
165                            mypromptbox[s],
166                            mytextbox,
167                            mylayoutbox[s],
168                            s == 1 and mysystray or nil }
169     mywibox[s].screen = s
170 end
171 -- }}}
172
173 -- {{{ Mouse bindings
174 root.buttons({
175     button({ }, 3, function () mymainmenu:toggle() end),
176     button({ }, 4, awful.tag.viewnext),
177     button({ }, 5, awful.tag.viewprev)
178 })
179 -- }}}
180
181 -- {{{ Key bindings
182 globalkeys =
183 {
184     -- key({ modkey,           }, "Left",   awful.tag.viewprev       ),
185     -- key({ modkey,           }, "Right",  awful.tag.viewnext       ),
186     key({ modkey,           }, "Escape", awful.tag.history.restore),
187
188     key({ modkey,           }, "j",
189         function ()
190             awful.client.focus.byidx( 1)
191             if client.focus then client.focus:raise() end
192         end),
193     key({ modkey,           }, "k",
194         function ()
195             awful.client.focus.byidx(-1)
196             if client.focus then client.focus:raise() end
197         end),
198
199     -- Layout manipulation
200     key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1) end),
201     key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1) end),
202     key({ modkey,           }, "Left", function () awful.screen.focus( 1)       end),
203     key({ modkey,           }, "Right", function () awful.screen.focus(-1)       end),
204     key({ modkey,           }, "u", awful.client.urgent.jumpto),
205     key({ modkey,           }, "Tab",
206         function ()
207             awful.client.focus.history.previous()
208             if client.focus then
209                 client.focus:raise()
210             end
211         end),
212
213     -- Standard program
214     key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
215     key({ modkey, "Control","Shift" }, "r", awesome.restart),
216     key({ modkey, "Control","Shift" }, "q", awesome.quit),
217
218     key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
219     key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
220     key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
221     key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
222     key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
223     key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
224     key({ modkey,           }, "n", function () awful.layout.inc(layouts,  1) end),
225     key({ modkey, "Shift"   }, "n", function () awful.layout.inc(layouts, -1) end),
226
227     -- Prompt
228     key({ modkey }, "F1",
229         function ()
230             awful.prompt.run({ prompt = "Run: " },
231             mypromptbox[mouse.screen],
232             awful.util.spawn, awful.completion.bash,
233             awful.util.getdir("cache") .. "/history")
234         end),
235
236     key({ modkey }, "F4",
237         function ()
238             awful.prompt.run({ prompt = "Run Lua code: " },
239             mypromptbox[mouse.screen],
240             awful.util.eval, awful.prompt.bash,
241             awful.util.getdir("cache") .. "/history_eval")
242         end),
243 }
244
245 -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
246 clientkeys =
247 {
248     key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
249     key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
250     key({ modkey,           }, "space",  awful.client.floating.toggle                     ),
251     key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
252     key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
253     key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
254     key({ modkey }, "t", awful.client.togglemarked),
255     key({ modkey,}, "m",
256         function (c)
257             c.maximized_horizontal = not c.maximized_horizontal
258             c.maximized_vertical   = not c.maximized_vertical
259         end),
260 }
261
262 -- Compute the maximum number of digit we need, limited to 9
263 keynumber = 0
264 for s = 1, screen.count() do
265    keynumber = math.min(9, math.max(#tags[s], keynumber));
266 end
267
268 for i = 1, keynumber do
269     table.insert(globalkeys,
270         key({ modkey }, i,
271             function ()
272                 local screen = mouse.screen
273                 if tags[screen][i] then
274                     awful.tag.viewonly(tags[screen][i])
275                 end
276             end))
277     table.insert(globalkeys,
278         key({ modkey, "Control" }, i,
279             function ()
280                 local screen = mouse.screen
281                 if tags[screen][i] then
282                     tags[screen][i].selected = not tags[screen][i].selected
283                 end
284             end))
285     table.insert(globalkeys,
286         key({ modkey, "Shift" }, i,
287             function ()
288                 if client.focus and tags[client.focus.screen][i] then
289                     awful.client.movetotag(tags[client.focus.screen][i])
290                 end
291             end))
292     table.insert(globalkeys,
293         key({ modkey, "Control", "Shift" }, i,
294             function ()
295                 if client.focus and tags[client.focus.screen][i] then
296                     awful.client.toggletag(tags[client.focus.screen][i])
297                 end
298             end))
299 end
300
301
302 for i = 1, keynumber do
303     table.insert(globalkeys, key({ modkey, "Shift" }, "F" .. i,
304                  function ()
305                      local screen = mouse.screen
306                      if tags[screen][i] then
307                          for k, c in pairs(awful.client.getmarked()) do
308                              awful.client.movetotag(tags[screen][i], c)
309                          end
310                      end
311                  end))
312 end
313
314 -- Set keys
315 root.keys(globalkeys)
316 -- }}}
317
318 -- {{{ Hooks
319 -- Hook function to execute when focusing a client.
320 awful.hooks.focus.register(function (c)
321     if not awful.client.ismarked(c) then
322         c.border_color = beautiful.border_focus
323     end
324 end)
325
326 -- Hook function to execute when unfocusing a client.
327 awful.hooks.unfocus.register(function (c)
328     if not awful.client.ismarked(c) then
329         c.border_color = beautiful.border_normal
330     end
331 end)
332
333 -- Hook function to execute when marking a client
334 awful.hooks.marked.register(function (c)
335     c.border_color = beautiful.border_marked
336 end)
337
338 -- Hook function to execute when unmarking a client.
339 awful.hooks.unmarked.register(function (c)
340     c.border_color = beautiful.border_focus
341 end)
342
343 -- Hook function to execute when the mouse enters a client.
344 awful.hooks.mouse_enter.register(function (c)
345     -- Sloppy focus, but disabled for magnifier layout
346     if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
347         and awful.client.focus.filter(c) then
348         client.focus = c
349     end
350 end)
351
352 -- Hook function to execute when a new client appears.
353 awful.hooks.manage.register(function (c, startup)
354     -- If we are not managing this application at startup,
355     -- move it to the screen where the mouse is.
356     -- We only do it for filtered windows (i.e. no dock, etc).
357     if not startup and awful.client.focus.filter(c) then
358         c.screen = mouse.screen
359     end
360
361     if use_titlebar then
362         -- Add a titlebar
363         awful.titlebar.add(c, { modkey = modkey })
364     end
365     -- Add mouse bindings
366     c:buttons({
367         button({ }, 1, function (c) client.focus = c; c:raise() end),
368         button({ modkey }, 1, awful.mouse.client.move),
369         button({ modkey }, 3, awful.mouse.client.resize)
370     })
371     -- New client may not receive focus
372     -- if they're not focusable, so set border anyway.
373     c.border_width = beautiful.border_width
374     c.border_color = beautiful.border_normal
375
376     -- Check if the application should be floating.
377     local cls = c.class
378     local inst = c.instance
379     if floatapps[cls] then
380         awful.client.floating.set(c, floatapps[cls])
381     elseif floatapps[inst] then
382         awful.client.floating.set(c, floatapps[inst])
383     end
384
385     -- Check application->screen/tag mappings.
386     local target
387     if apptags[cls] then
388         target = apptags[cls]
389     elseif apptags[inst] then
390         target = apptags[inst]
391     end
392     if target then
393         c.screen = target.screen
394         awful.client.movetotag(tags[target.screen][target.tag], c)
395     end
396
397     -- Do this after tag mapping, so you don't see it on the wrong tag for a split second.
398     client.focus = c
399
400     -- Set key bindings
401     c:keys(clientkeys)
402
403     -- Set the windows at the slave,
404     -- i.e. put it at the end of others instead of setting it master.
405     -- awful.client.setslave(c)
406
407     -- Honor size hints: if you want to drop the gaps between windows, set this to false.
408     -- c.size_hints_honor = false
409 end)
410
411 -- Hook function to execute when arranging the screen.
412 -- (tag switch, new client, etc)
413 awful.hooks.arrange.register(function (screen)
414     local layout = awful.layout.getname(awful.layout.get(screen))
415     if layout and beautiful["layout_" ..layout] then
416         mylayoutbox[screen].image = image(beautiful["layout_" .. layout])
417     else
418         mylayoutbox[screen].image = nil
419     end
420
421     -- Give focus to the latest client in history if no window has focus
422     -- or if the current window is a desktop or a dock one.
423     if not client.focus then
424         local c = awful.client.focus.history.get(screen, 0)
425         if c then client.focus = c end
426     end
427 end)
428
429 -- Hook called every second
430 awful.hooks.timer.register(1, function ()
431     -- For unix time_t lovers
432     mytextbox.text = " " .. os.time() .. " time_t "
433     -- Otherwise use:
434     -- mytextbox.text = " " .. os.date() .. " "
435 end)
436 -- }}}