]> git.rmz.io Git - dotfiles.git/blob - awesome/rc.lua
move bindings to separate file
[dotfiles.git] / awesome / rc.lua
1 -- Standard awesome library
2 gears = require("gears")
3 awful = require("awful")
4 awful.rules = require("awful.rules")
5 require("awful.autofocus")
6 -- Widget and layout library
7 wibox = require("wibox")
8 -- Theme handling library
9 beautiful = require("beautiful")
10 -- Notification library
11 naughty = require("naughty")
12 menubar = require("menubar")
13 -- Pulseaudio widget
14 --local APW = require("apw/widget")
15
16 -- {{{ Error handling
17 -- Check if awesome encountered an error during startup and fell back to
18 -- another config (This code will only ever execute for the fallback config)
19 if awesome.startup_errors then
20 naughty.notify({ preset = naughty.config.presets.critical,
21 title = "Oops, there were errors during startup!",
22 text = awesome.startup_errors })
23 end
24
25 -- Handle runtime errors after startup
26 do
27 local in_error = false
28 awesome.connect_signal("debug::error", function (err)
29 -- Make sure we don't go into an endless error loop
30 if in_error then return end
31 in_error = true
32
33 naughty.notify({ preset = naughty.config.presets.critical,
34 title = "Oops, an error happened!",
35 text = err })
36 in_error = false
37 end)
38 end
39 -- }}}
40
41 -- {{{ Variable definitions
42 -- Themes define colours, icons, and wallpapers
43 beautiful.init("/usr/share/awesome/themes/default/theme.lua")
44
45 -- This is used later as the default terminal and editor to run.
46 terminal = "konsole"
47 editor = os.getenv("EDITOR") or "vim"
48 editor_cmd = terminal .. " -e " .. editor
49
50 -- Default modkey.
51 -- Usually, Mod4 is the key with a logo between Control and Alt.
52 -- If you do not like this or do not have such a key,
53 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
54 -- However, you can use another modifier like Mod1, but it may interact with others.
55 modkey = "Mod4"
56
57 -- Tags
58 require("tags")
59 -- }}}
60
61 -- {{{ Wallpaper
62 if beautiful.wallpaper then
63 for s = 1, screen.count() do
64 gears.wallpaper.maximized(beautiful.wallpaper, s, true)
65 end
66 end
67 -- }}}
68
69 -- {{{ Menu
70 -- Create a laucher widget and a main menu
71 myawesomemenu = {
72 { "manual", terminal .. " -e man awesome" },
73 { "edit config", editor_cmd .. " " .. awesome.conffile },
74 { "restart", awesome.restart },
75 { "quit", awesome.quit }
76 }
77
78 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
79 { "open terminal", terminal }
80 }
81 })
82
83 mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
84 menu = mymainmenu })
85
86 -- Menubar configuration
87 menubar.utils.terminal = terminal -- Set the terminal for applications that require it
88 -- }}}
89
90 -- {{{ Wibox
91 -- Create a textclock widget
92 mytextclock = awful.widget.textclock()
93
94 -- Create a wibox for each screen and add it
95 mywibox = {}
96 mypromptbox = {}
97 mylayoutbox = {}
98 mytaglist = {}
99 mytaglist.buttons = awful.util.table.join(
100 awful.button({ }, 1, awful.tag.viewonly),
101 awful.button({ modkey }, 1, awful.client.movetotag),
102 awful.button({ }, 3, awful.tag.viewtoggle),
103 awful.button({ modkey }, 3, awful.client.toggletag),
104 awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
105 awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
106 )
107 mytasklist = {}
108 mytasklist.buttons = awful.util.table.join(
109 awful.button({ }, 1, function (c)
110 if c == client.focus then
111 c.minimized = true
112 else
113 -- Without this, the following
114 -- :isvisible() makes no sense
115 c.minimized = false
116 if not c:isvisible() then
117 awful.tag.viewonly(c:tags()[1])
118 end
119 -- This will also un-minimize
120 -- the client, if needed
121 client.focus = c
122 c:raise()
123 end
124 end),
125 awful.button({ }, 3, function ()
126 if instance then
127 instance:hide()
128 instance = nil
129 else
130 instance = awful.menu.clients({ width=250 })
131 end
132 end),
133 awful.button({ }, 4, function ()
134 awful.client.focus.byidx(1)
135 if client.focus then client.focus:raise() end
136 end),
137 awful.button({ }, 5, function ()
138 awful.client.focus.byidx(-1)
139 if client.focus then client.focus:raise() end
140 end))
141
142 for s = 1, screen.count() do
143 -- Create a promptbox for each screen
144 mypromptbox[s] = awful.widget.prompt()
145 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
146 -- We need one layoutbox per screen.
147 mylayoutbox[s] = awful.widget.layoutbox(s)
148 mylayoutbox[s]:buttons(awful.util.table.join(
149 awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
150 awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
151 awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
152 awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
153 -- Create a taglist widget
154 mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
155
156 -- Create a tasklist widget
157 mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
158
159 -- Create the wibox
160 mywibox[s] = awful.wibox({ position = "top", screen = s })
161
162 -- Widgets that are aligned to the left
163 local left_layout = wibox.layout.fixed.horizontal()
164 left_layout:add(mylauncher)
165 left_layout:add(mytaglist[s])
166 left_layout:add(mypromptbox[s])
167
168 -- Widgets that are aligned to the right
169 local right_layout = wibox.layout.fixed.horizontal()
170 if s == 1 then right_layout:add(wibox.widget.systray()) end
171 --right_layout:add(APW)
172 right_layout:add(mytextclock)
173 right_layout:add(mylayoutbox[s])
174
175 -- Now bring it all together (with the tasklist in the middle)
176 local layout = wibox.layout.align.horizontal()
177 layout:set_left(left_layout)
178 layout:set_middle(mytasklist[s])
179 layout:set_right(right_layout)
180
181 mywibox[s]:set_widget(layout)
182 end
183 -- }}}
184
185 -- Mouse/Key Bindings
186 require("bindings")
187
188 -- {{{ Rules
189 awful.rules.rules = {
190 -- All clients will match this rule.
191 { rule = { },
192 properties = { border_width = beautiful.border_width,
193 border_color = beautiful.border_normal,
194 focus = awful.client.focus.filter,
195 keys = clientkeys,
196 buttons = clientbuttons } },
197 { rule = { class = "MPlayer" },
198 properties = { floating = true } },
199 { rule = { class = "pinentry" },
200 properties = { floating = true } },
201 { rule = { class = "gimp" },
202 properties = { floating = true } },
203 -- Set Firefox to always map on tags number 2 of screen 1.
204 -- { rule = { class = "Firefox" },
205 -- properties = { tag = tags[1][2] } },
206 }
207 -- }}}
208
209 -- {{{ Signals
210 -- Signal function to execute when a new client appears.
211 client.connect_signal("manage", function (c, startup)
212 -- Enable sloppy focus
213 c:connect_signal("mouse::enter", function(c)
214 if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
215 and awful.client.focus.filter(c) then
216 client.focus = c
217 end
218 end)
219
220 if not startup then
221 -- Set the windows at the slave,
222 -- i.e. put it at the end of others instead of setting it master.
223 -- awful.client.setslave(c)
224
225 -- Put windows in a smart way, only if they does not set an initial position.
226 if not c.size_hints.user_position and not c.size_hints.program_position then
227 awful.placement.no_overlap(c)
228 awful.placement.no_offscreen(c)
229 end
230 end
231
232 local titlebars_enabled = false
233 if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
234 -- buttons for the titlebar
235 local buttons = awful.util.table.join(
236 awful.button({ }, 1, function()
237 client.focus = c
238 c:raise()
239 awful.mouse.client.move(c)
240 end),
241 awful.button({ }, 3, function()
242 client.focus = c
243 c:raise()
244 awful.mouse.client.resize(c)
245 end)
246 )
247
248 -- Widgets that are aligned to the left
249 local left_layout = wibox.layout.fixed.horizontal()
250 left_layout:add(awful.titlebar.widget.iconwidget(c))
251 left_layout:buttons(buttons)
252
253 -- Widgets that are aligned to the right
254 local right_layout = wibox.layout.fixed.horizontal()
255 right_layout:add(awful.titlebar.widget.floatingbutton(c))
256 right_layout:add(awful.titlebar.widget.maximizedbutton(c))
257 right_layout:add(awful.titlebar.widget.stickybutton(c))
258 right_layout:add(awful.titlebar.widget.ontopbutton(c))
259 right_layout:add(awful.titlebar.widget.closebutton(c))
260
261 -- The title goes in the middle
262 local middle_layout = wibox.layout.flex.horizontal()
263 local title = awful.titlebar.widget.titlewidget(c)
264 title:set_align("center")
265 middle_layout:add(title)
266 middle_layout:buttons(buttons)
267
268 -- Now bring it all together
269 local layout = wibox.layout.align.horizontal()
270 layout:set_left(left_layout)
271 layout:set_right(right_layout)
272 layout:set_middle(middle_layout)
273
274 awful.titlebar(c):set_widget(layout)
275 end
276 end)
277
278 client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
279 client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
280 -- }}}
281
282 -- {{{ Autostart applications
283 require("autostart")
284 -- }}}