dc8e13e6bfa984fbfeb539ab97340a4947844666
[awesome-config] / rc.lua
1 -- Standard awesome library
2 require("awful")
3 require("awful.autofocus")
4 require("awful.rules")
5 -- Theme handling library
6 require("beautiful")
7 -- Notification library
8 require("naughty")
9
10 -- require vicious widgets
11 require("vicious")
12
13 -- Load Debian menu entries
14 require("debian.menu")
15
16 -- {{{ Error handling
17 -- Check if awesome encountered an error during startup and fell back to
18 -- another config (This code will only ever execute for the fallback config)
19 if awesome.startup_errors then
20     naughty.notify({ preset = naughty.config.presets.critical,
21                      title = "Oops, there were errors during startup!",
22                      text = awesome.startup_errors })
23 end
24
25 -- Handle runtime errors after startup
26 do
27     local in_error = false
28     awesome.add_signal("debug::error", function (err)
29         -- Make sure we don't go into an endless error loop
30         if in_error then return end
31         in_error = true
32
33         naughty.notify({ preset = naughty.config.presets.critical,
34                          title = "Oops, an error happened!",
35                          text = err })
36         in_error = false
37     end)
38 end
39 -- }}}
40
41
42 -- {{{ Variable definitions
43 -- Themes define colours, icons, and wallpapers
44 -- beautiful.init("/usr/share/awesome/themes/default/theme.lua")
45 beautiful.init("/usr/share/awesome/themes/sky/theme.lua")
46 -- beautiful.init(os.getenv("HOME") .. "/.config/awesome/theme.lua")
47
48 -- This is used later as the default terminal and editor to run.
49 terminal = "x-terminal-emulator"
50 editor = os.getenv("EDITOR") or "editor"
51 editor_cmd = terminal .. " -e " .. editor
52
53 -- Default modkey.
54 -- Usually, Mod4 is the key with a logo between Control and Alt.
55 -- If you do not like this or do not have such a key,
56 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
57 -- However, you can use another modifier like Mod1, but it may interact with others.
58 modkey = "Mod1"
59
60 -- Table of layouts to cover with awful.layout.inc, order matters.
61 layouts =
62 {
63     awful.layout.suit.tile,
64 --    awful.layout.suit.tile.left,
65 --    awful.layout.suit.tile.bottom,
66 --    awful.layout.suit.tile.top,
67 --    awful.layout.suit.fair,
68 --    awful.layout.suit.fair.horizontal,
69 --    awful.layout.suit.spiral,
70 --    awful.layout.suit.spiral.dwindle,
71     awful.layout.suit.max,
72 --    awful.layout.suit.max.fullscreen,
73 --    awful.layout.suit.magnifier,
74     awful.layout.suit.floating,
75 }
76 -- }}}
77
78 -- {{{ Tags
79 -- Define a tag table which hold all screen tags.
80 tags = {}
81 for s = 1, screen.count() do
82     -- Each screen has its own tag table.
83     tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
84 end
85 -- }}}
86
87 -- {{{ Menu
88 -- Create a laucher widget and a main menu
89 myawesomemenu = {
90    { "manual", terminal .. " -e man awesome" },
91    { "edit config", editor_cmd .. " " .. awesome.conffile },
92    { "restart", awesome.restart },
93    { "quit", awesome.quit }
94 }
95
96 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
97                                     { "Debian", debian.menu.Debian_menu.Debian },
98                                     { "open terminal", terminal }
99                                   }
100                         })
101
102 mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
103                                      menu = mymainmenu })
104 -- }}}
105
106 -- {{{ Wibox
107 -- Create a textclock widget
108 mytextclock = awful.widget.textclock({ align = "right" })
109
110 -- Create a systray
111 mysystray = widget({ type = "systray" })
112
113 -- Initialize widget
114 mycpuwidget = widget({ type = "textbox" })
115 -- Register widget
116 vicious.register(mycpuwidget, vicious.widgets.cpu, "CPU:$1%")
117
118 mynetwidget = widget({ type = "textbox" })
119  vicious.register(mynetwidget, vicious.widgets.net, "${wlan23 up_kb}(OUT) ${wlan23 down_kb}(IN)", 1)
120 -- vicious.register(mynetwidget, vicious.widgets.net, "${wlan26 up_kb}(OUT) ${wlan26 down_kb}(IN)", 1)
121
122 spacer = widget({ type = "textbox"})
123 spacer.text = " "
124
125 sep = widget({ type = "textbox"})
126 sep.text = "|"
127
128 -- Create a wibox for each screen and add it
129 mywibox = {}
130 mypromptbox = {}
131 mylayoutbox = {}
132 mytaglist = {}
133 mytaglist.buttons = awful.util.table.join(
134                     awful.button({ }, 1, awful.tag.viewonly),
135                     awful.button({ modkey }, 1, awful.client.movetotag),
136                     awful.button({ }, 3, awful.tag.viewtoggle),
137                     awful.button({ modkey }, 3, awful.client.toggletag),
138                     awful.button({ }, 4, awful.tag.viewnext),
139                     awful.button({ }, 5, awful.tag.viewprev)
140                     )
141 mytasklist = {}
142 mytasklist.buttons = awful.util.table.join(
143                      awful.button({ }, 1, function (c)
144                                               if c == client.focus then
145                                                   c.minimized = true
146                                               else
147                                                   if not c:isvisible() then
148                                                       awful.tag.viewonly(c:tags()[1])
149                                                   end
150                                                   -- This will also un-minimize
151                                                   -- the client, if needed
152                                                   client.focus = c
153                                                   c:raise()
154                                               end
155                                           end),
156                      awful.button({ }, 3, function ()
157                                               if instance then
158                                                   instance:hide()
159                                                   instance = nil
160                                               else
161                                                   instance = awful.menu.clients({ width=250 })
162                                               end
163                                           end),
164                      awful.button({ }, 4, function ()
165                                               awful.client.focus.byidx(1)
166                                               if client.focus then client.focus:raise() end
167                                           end),
168                      awful.button({ }, 5, function ()
169                                               awful.client.focus.byidx(-1)
170                                               if client.focus then client.focus:raise() end
171                                           end))
172
173 for s = 1, screen.count() do
174     -- Create a promptbox for each screen
175     mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
176     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
177     -- We need one layoutbox per screen.
178     mylayoutbox[s] = awful.widget.layoutbox(s)
179     mylayoutbox[s]:buttons(awful.util.table.join(
180                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
181                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
182                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
183                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
184     -- Create a taglist widget
185     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
186
187     -- Create a tasklist widget
188     mytasklist[s] = awful.widget.tasklist(function(c)
189                                               return awful.widget.tasklist.label.currenttags(c, s)
190                                           end, mytasklist.buttons)
191
192     -- Create the wibox
193     mywibox[s] = awful.wibox({ position = "top", screen = s })
194     -- Add widgets to the wibox - order matters
195     mywibox[s].widgets = {
196         {
197             mylauncher,
198             mytaglist[s],
199             mypromptbox[s],
200             layout = awful.widget.layout.horizontal.leftright
201         },
202         mylayoutbox[s],
203         mytextclock,
204         s == 1 and mysystray or nil,
205         mycpuwidget,
206         mynetwidget,
207         mytasklist[s],
208         layout = awful.widget.layout.horizontal.rightleft
209     }
210 end
211 -- }}}
212
213 -- {{{ Mouse bindings
214 root.buttons(awful.util.table.join(
215     awful.button({ }, 3, function () mymainmenu:toggle() end),
216     awful.button({ }, 4, awful.tag.viewnext),
217     awful.button({ }, 5, awful.tag.viewprev)
218 ))
219 -- }}}
220
221 -- {{{ Key bindings
222 globalkeys = awful.util.table.join(
223     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
224     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
225     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
226
227     awful.key({ modkey,           }, "j",
228         function ()
229             awful.client.focus.byidx( 1)
230             if client.focus then client.focus:raise() end
231         end),
232     awful.key({ modkey,           }, "k",
233         function ()
234             awful.client.focus.byidx(-1)
235             if client.focus then client.focus:raise() end
236         end),
237     awful.key({ modkey,           }, "w", function () mymainmenu:show({keygrabber=true}) end),
238
239     -- Layout manipulation
240     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
241     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
242     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
243     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
244     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
245     awful.key({ modkey,           }, "Tab",
246         function ()
247             awful.client.focus.history.previous()
248             if client.focus then
249                 client.focus:raise()
250             end
251         end),
252
253     -- Standard program
254     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
255     awful.key({ modkey, "Control" }, "r", awesome.restart),
256     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
257
258     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
259     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
260     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
261     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
262     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
263     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
264     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
265     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
266
267     awful.key({ modkey, "Control" }, "n", awful.client.restore),
268
269     -- Prompt
270     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
271
272     awful.key({ modkey }, "x",    
273                function () 
274                   awful.prompt.run({ prompt = "Run in Terminal: " },
275                   mypromptbox[mouse.screen].widget,
276                   function (prog) awful.util.spawn_with_shell(terminal .. " -title " .. prog .. " -e " .. prog) end) end),
277
278     awful.key({ modkey, "Shift"}, "x",
279               function ()
280                   awful.prompt.run({ prompt = "Run Lua code: " },
281                   mypromptbox[mouse.screen].widget,
282                   awful.util.eval, nil,
283                   awful.util.getdir("cache") .. "/history_eval")
284               end),
285
286     -- key to make the 4 column setup for the big screen
287     awful.key({ modkey }, "q",
288               function ()
289                   awful.tag.incnmaster(-1)
290                   awful.tag.incncol(3)
291               end)
292                                     
293 )
294
295 clientkeys = awful.util.table.join(
296     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
297     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
298     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
299     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
300     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
301     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
302     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
303     awful.key({ modkey,           }, "n",
304         function (c)
305             -- The client currently has the input focus, so it cannot be
306             -- minimized, since minimized clients can't have the focus.
307             c.minimized = true
308         end),
309     awful.key({ modkey,           }, "m",
310         function (c)
311             c.maximized_horizontal = not c.maximized_horizontal
312             c.maximized_vertical   = not c.maximized_vertical
313         end)
314 )
315
316 -- Compute the maximum number of digit we need, limited to 9
317 keynumber = 0
318 for s = 1, screen.count() do
319    keynumber = math.min(9, math.max(#tags[s], keynumber));
320 end
321
322 -- Bind all key numbers to tags.
323 -- Be careful: we use keycodes to make it works on any keyboard layout.
324 -- This should map on the top row of your keyboard, usually 1 to 9.
325 for i = 1, keynumber do
326     globalkeys = awful.util.table.join(globalkeys,
327         awful.key({ modkey }, "#" .. i + 9,
328                   function ()
329                         local screen = mouse.screen
330                         if tags[screen][i] then
331                             awful.tag.viewonly(tags[screen][i])
332                         end
333                   end),
334         awful.key({ modkey, "Control" }, "#" .. i + 9,
335                   function ()
336                       local screen = mouse.screen
337                       if tags[screen][i] then
338                           awful.tag.viewtoggle(tags[screen][i])
339                       end
340                   end),
341         awful.key({ modkey, "Shift" }, "#" .. i + 9,
342                   function ()
343                       if client.focus and tags[client.focus.screen][i] then
344                           awful.client.movetotag(tags[client.focus.screen][i])
345                       end
346                   end),
347         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
348                   function ()
349                       if client.focus and tags[client.focus.screen][i] then
350                           awful.client.toggletag(tags[client.focus.screen][i])
351                       end
352                   end))
353 end
354
355 clientbuttons = awful.util.table.join(
356     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
357     awful.button({ modkey }, 1, awful.mouse.client.move),
358     awful.button({ modkey }, 3, awful.mouse.client.resize))
359
360 -- Set keys
361 root.keys(globalkeys)
362 -- }}}
363
364 -- {{{ Rules
365 awful.rules.rules = {
366     -- All clients will match this rule.
367     { rule = { },
368       properties = { border_width = beautiful.border_width,
369                      border_color = beautiful.border_normal,
370                      focus = true,
371                      keys = clientkeys,
372                      buttons = clientbuttons } },
373     { rule = { class = "MPlayer" },
374       properties = { floating = true } },
375     { rule = { class = "pinentry" },
376       properties = { floating = true } },
377     { rule = { class = "gimp" },
378       properties = { floating = true } },
379     -- Set Firefox to always map on tags number 2 of screen 1.
380     -- { rule = { class = "Iceweasel" },
381     --   properties = { tag = tags[1][3] } },
382     { rule = { name = "oli" },
383       properties = { tag = tags[1][9] } },
384     -- { rule = { name = "emacs" },
385     --  properties = { tag = tags[1][2] } },
386     { rule = { name = "tunnel" },
387       properties = { tag = tags[1][9] } },
388 }
389 -- }}}
390
391 -- {{{ Signals
392 -- Signal function to execute when a new client appears.
393 client.add_signal("manage", function (c, startup)
394     -- Add a titlebar
395     -- awful.titlebar.add(c, { modkey = modkey })
396
397     -- Enable sloppy focus
398     c:add_signal("mouse::enter", function(c)
399         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
400             and awful.client.focus.filter(c) then
401             client.focus = c
402         end
403     end)
404
405     if not startup then
406         -- Set the windows at the slave,
407         -- i.e. put it at the end of others instead of setting it master.
408         -- awful.client.setslave(c)
409
410         -- Put windows in a smart way, only if they does not set an initial position.
411         if not c.size_hints.user_position and not c.size_hints.program_position then
412             awful.placement.no_overlap(c)
413             awful.placement.no_offscreen(c)
414         end
415     end
416 end)
417
418 client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
419 client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
420 -- }}}

Benjamin Mako Hill || Want to submit a patch?