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