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