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

Benjamin Mako Hill || Want to submit a patch?