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

Benjamin Mako Hill || Want to submit a patch?