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