awful.widget.taglist: use attached_add_signal
[awesome.git] / awesomerc.lua.in
blob18860e5c8a6ed930ed8a36769bc09d7bf4dc239d
1 -- Standard awesome library
2 require("awful")
3 -- Theme handling library
4 require("beautiful")
5 -- Notification library
6 require("naughty")
8 -- {{{ Variable definitions
9 -- Themes define colours, icons, and wallpapers
10 -- The default is a dark theme
11 theme_path = "@AWESOME_THEMES_PATH@/default/theme.lua"
12 -- Uncommment this for a lighter theme
13 -- theme_path = "@AWESOME_THEMES_PATH@/sky/theme.lua"
15 -- Actually load theme
16 beautiful.init(theme_path)
18 -- This is used later as the default terminal and editor to run.
19 terminal = "xterm"
20 editor = os.getenv("EDITOR") or "nano"
21 editor_cmd = terminal .. " -e " .. editor
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 = "Mod4"
30 -- Table of layouts to cover with awful.layout.inc, order matters.
31 layouts =
33 awful.layout.suit.tile,
34 awful.layout.suit.tile.left,
35 awful.layout.suit.tile.bottom,
36 awful.layout.suit.tile.top,
37 awful.layout.suit.fair,
38 awful.layout.suit.fair.horizontal,
39 awful.layout.suit.spiral,
40 awful.layout.suit.spiral.dwindle,
41 awful.layout.suit.max,
42 awful.layout.suit.max.fullscreen,
43 awful.layout.suit.magnifier,
44 awful.layout.suit.floating
47 -- Table of clients that should be set floating. The index may be either
48 -- the application class or instance. The instance is useful when running
49 -- a console app in a terminal like (Music on Console)
50 -- xterm -name mocp -e mocp
51 floatapps =
53 -- by class
54 ["MPlayer"] = true,
55 ["pinentry"] = true,
56 ["gimp"] = true,
57 -- by instance
58 ["mocp"] = true
61 -- Applications to be moved to a pre-defined tag by class or instance.
62 -- Use the screen and tags indices.
63 apptags =
65 -- ["Firefox"] = { screen = 1, tag = 2 },
66 -- ["mocp"] = { screen = 2, tag = 4 },
69 -- Define if we want to use titlebar on all applications.
70 use_titlebar = false
71 -- }}}
73 -- {{{ Tags
74 -- Define tags table.
75 tags = {}
76 for s = 1, screen.count() do
77 -- Each screen has its own tag table.
78 tags[s] = {}
79 -- Create 9 tags per screen.
80 for tagnumber = 1, 9 do
81 tags[s][tagnumber] = tag { name = tagnumber }
82 -- Add tags to screen one by one
83 tags[s][tagnumber].screen = s
84 awful.layout.set(layouts[1], tags[s][tagnumber])
85 end
86 -- I'm sure you want to see at least one tag.
87 tags[s][1].selected = true
88 end
89 -- }}}
91 -- {{{ Wibox
92 -- Create a textclock widget
93 mytextclock = awful.widget.textclock({ align = "right" })
95 -- Create a laucher widget and a main menu
96 myawesomemenu = {
97 { "manual", terminal .. " -e man awesome" },
98 { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
99 { "restart", awesome.restart },
100 { "quit", awesome.quit }
103 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
104 { "open terminal", terminal }
108 mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
109 menu = mymainmenu })
111 -- Create a systray
112 mysystray = widget({ type = "systray" })
114 -- Create a wibox for each screen and add it
115 mywibox = {}
116 mypromptbox = {}
117 mylayoutbox = {}
118 mytaglist = {}
119 mytaglist.buttons = awful.util.table.join(
120 awful.button({ }, 1, awful.tag.viewonly),
121 awful.button({ modkey }, 1, awful.client.movetotag),
122 awful.button({ }, 3, function (tag) tag.selected = not tag.selected end),
123 awful.button({ modkey }, 3, awful.client.toggletag),
124 awful.button({ }, 4, awful.tag.viewnext),
125 awful.button({ }, 5, awful.tag.viewprev)
127 mytasklist = {}
128 mytasklist.buttons = awful.util.table.join(
129 awful.button({ }, 1, function (c)
130 if not c:isvisible() then
131 awful.tag.viewonly(c:tags()[1])
133 client.focus = c
134 c:raise()
135 end),
136 awful.button({ }, 3, function ()
137 if instance then
138 instance:hide()
139 instance = nil
140 else
141 instance = awful.menu.clients({ width=250 })
143 end),
144 awful.button({ }, 4, function ()
145 awful.client.focus.byidx(1)
146 if client.focus then client.focus:raise() end
147 end),
148 awful.button({ }, 5, function ()
149 awful.client.focus.byidx(-1)
150 if client.focus then client.focus:raise() end
151 end))
153 for s = 1, screen.count() do
154 -- Create a promptbox for each screen
155 mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.leftright })
156 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
157 -- We need one layoutbox per screen.
158 mylayoutbox[s] = awful.widget.layoutbox(s)
159 mylayoutbox[s]:buttons(awful.util.table.join(
160 awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
161 awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
162 awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
163 awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
164 -- Create a taglist widget
165 mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
167 -- Create a tasklist widget
168 mytasklist[s] = awful.widget.tasklist(function(c)
169 return awful.widget.tasklist.label.currenttags(c, s)
170 end, mytasklist.buttons)
172 -- Create the wibox
173 mywibox[s] = awful.wibox({ position = "top", screen = s })
174 -- Add widgets to the wibox - order matters
175 mywibox[s].widgets = {
177 mylauncher,
178 mytaglist[s],
179 mypromptbox[s],
180 layout = awful.widget.layout.horizontal.leftright
182 mylayoutbox[s],
183 mytextclock,
184 s == 1 and mysystray or nil,
185 mytasklist[s],
186 layout = awful.widget.layout.horizontal.rightleft
189 -- }}}
191 -- {{{ Mouse bindings
192 root.buttons(awful.util.table.join(
193 awful.button({ }, 3, function () mymainmenu:toggle() end),
194 awful.button({ }, 4, awful.tag.viewnext),
195 awful.button({ }, 5, awful.tag.viewprev)
197 -- }}}
199 -- {{{ Key bindings
200 globalkeys = awful.util.table.join(
201 awful.key({ modkey, }, "Left", awful.tag.viewprev ),
202 awful.key({ modkey, }, "Right", awful.tag.viewnext ),
203 awful.key({ modkey, }, "Escape", awful.tag.history.restore),
205 awful.key({ modkey, }, "j",
206 function ()
207 awful.client.focus.byidx( 1)
208 if client.focus then client.focus:raise() end
209 end),
210 awful.key({ modkey, }, "k",
211 function ()
212 awful.client.focus.byidx(-1)
213 if client.focus then client.focus:raise() end
214 end),
215 awful.key({ modkey, }, "w", function () mymainmenu:show(true) end),
217 -- Layout manipulation
218 awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
219 awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
220 awful.key({ modkey, "Control" }, "j", function () awful.screen.focus( 1) end),
221 awful.key({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end),
222 awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
223 awful.key({ modkey, }, "Tab",
224 function ()
225 awful.client.focus.history.previous()
226 if client.focus then
227 client.focus:raise()
229 end),
231 -- Standard program
232 awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
233 awful.key({ modkey, "Control" }, "r", awesome.restart),
234 awful.key({ modkey, "Shift" }, "q", awesome.quit),
236 awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
237 awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
238 awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
239 awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
240 awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
241 awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
242 awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
243 awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
245 -- Prompt
246 awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
248 awful.key({ modkey }, "x",
249 function ()
250 awful.prompt.run({ prompt = "Run Lua code: " },
251 mypromptbox[mouse.screen].widget,
252 awful.util.eval, nil,
253 awful.util.getdir("cache") .. "/history_eval")
254 end)
257 -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
258 clientkeys = awful.util.table.join(
259 awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
260 awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
261 awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
262 awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
263 awful.key({ modkey, }, "o", awful.client.movetoscreen ),
264 awful.key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
265 awful.key({ modkey,}, "m",
266 function (c)
267 c.maximized_horizontal = not c.maximized_horizontal
268 c.maximized_vertical = not c.maximized_vertical
269 end)
272 -- Compute the maximum number of digit we need, limited to 9
273 keynumber = 0
274 for s = 1, screen.count() do
275 keynumber = math.min(9, math.max(#tags[s], keynumber));
278 for i = 1, keynumber do
279 globalkeys = awful.util.table.join(globalkeys,
280 awful.key({ modkey }, i,
281 function ()
282 local screen = mouse.screen
283 if tags[screen][i] then
284 awful.tag.viewonly(tags[screen][i])
286 end),
287 awful.key({ modkey, "Control" }, i,
288 function ()
289 local screen = mouse.screen
290 if tags[screen][i] then
291 tags[screen][i].selected = not tags[screen][i].selected
293 end),
294 awful.key({ modkey, "Shift" }, i,
295 function ()
296 if client.focus and tags[client.focus.screen][i] then
297 awful.client.movetotag(tags[client.focus.screen][i])
299 end),
300 awful.key({ modkey, "Control", "Shift" }, i,
301 function ()
302 if client.focus and tags[client.focus.screen][i] then
303 awful.client.toggletag(tags[client.focus.screen][i])
305 end))
308 -- Set keys
309 root.keys(globalkeys)
310 -- }}}
312 -- {{{ Hooks
313 -- Hook function to execute when the mouse enters a client.
314 awful.hooks.mouse_enter.register(function (c)
315 -- Sloppy focus, but disabled for magnifier layout
316 if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
317 and awful.client.focus.filter(c) then
318 client.focus = c
320 end)
322 -- Hook function to execute when a new client appears.
323 client.add_signal("manage", function (c, startup)
324 -- If we are not managing this application at startup,
325 -- move it to the screen where the mouse is.
326 -- We only do it for filtered windows (i.e. no dock, etc).
327 if not startup and awful.client.focus.filter(c) then
328 c.screen = mouse.screen
331 if use_titlebar then
332 -- Add a titlebar
333 awful.titlebar.add(c, { modkey = modkey })
335 -- Add mouse bindings
336 c:buttons(awful.util.table.join(
337 awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
338 awful.button({ modkey }, 1, awful.mouse.client.move),
339 awful.button({ modkey }, 3, awful.mouse.client.resize)
341 -- New client may not receive focus
342 -- if they're not focusable, so set border anyway.
343 c.border_width = beautiful.border_width
344 c.border_color = beautiful.border_normal
346 -- Check if the application should be floating.
347 local cls = c.class
348 local inst = c.instance
349 if floatapps[cls] ~= nil then
350 awful.client.floating.set(c, floatapps[cls])
351 elseif floatapps[inst] ~= nil then
352 awful.client.floating.set(c, floatapps[inst])
355 -- Check application->screen/tag mappings.
356 local target
357 if apptags[cls] then
358 target = apptags[cls]
359 elseif apptags[inst] then
360 target = apptags[inst]
362 if target then
363 c.screen = target.screen
364 awful.client.movetotag(tags[target.screen][target.tag], c)
367 -- Do this after tag mapping, so you don't see it on the wrong tag for a split second.
368 client.focus = c
370 -- Set key bindings
371 c:keys(clientkeys)
373 -- Set the windows at the slave,
374 -- i.e. put it at the end of others instead of setting it master.
375 -- awful.client.setslave(c)
377 -- Honor size hints: if you want to drop the gaps between windows, set this to false.
378 -- c.size_hints_honor = false
379 end)
381 -- Hook function to execute when switching tag selection.
382 awful.hooks.tags.register(function (screen, tag, view)
383 -- Give focus to the latest client in history if no window has focus
384 -- or if the current window is a desktop or a dock one.
385 if not client.focus or not client.focus:isvisible() then
386 local c = awful.client.focus.history.get(screen, 0)
387 if c then client.focus = c end
389 end)
391 -- }}}