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