awful.mouse/widget: enable drag'n'dropping clients on tags
[awesome.git] / awesomerc.lua.in
blob4af90573b6100c420fcfadda8e92063883175b5c
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"
12 -- Uncommment this for a lighter theme
13 -- theme_path = "@AWESOME_THEMES_PATH@/sky/theme"
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.max,
40 awful.layout.suit.max.fullscreen,
41 awful.layout.suit.magnifier,
42 awful.layout.suit.floating
45 -- Table of clients that should be set floating. The index may be either
46 -- the application class or instance. The instance is useful when running
47 -- a console app in a terminal like (Music on Console)
48 -- xterm -name mocp -e mocp
49 floatapps =
51 -- by class
52 ["MPlayer"] = true,
53 ["pinentry"] = true,
54 ["gimp"] = true,
55 -- by instance
56 ["mocp"] = true
59 -- Applications to be moved to a pre-defined tag by class or instance.
60 -- Use the screen and tags indices.
61 apptags =
63 -- ["Firefox"] = { screen = 1, tag = 2 },
64 -- ["mocp"] = { screen = 2, tag = 4 },
67 -- Define if we want to use titlebar on all applications.
68 use_titlebar = false
69 -- }}}
71 -- {{{ Tags
72 -- Define tags table.
73 tags = {}
74 for s = 1, screen.count() do
75 -- Each screen has its own tag table.
76 tags[s] = {}
77 -- Create 9 tags per screen.
78 for tagnumber = 1, 9 do
79 tags[s][tagnumber] = tag(tagnumber)
80 -- Add tags to screen one by one
81 tags[s][tagnumber].screen = s
82 end
83 -- I'm sure you want to see at least one tag.
84 tags[s][1].selected = true
85 end
86 -- }}}
88 -- {{{ Wibox
89 -- Create a textbox widget
90 mytextbox = widget({ type = "textbox", align = "right" })
91 -- Set the default text in textbox
92 mytextbox.text = "<b><small> " .. AWESOME_RELEASE .. " </small></b>"
94 -- Create a laucher widget and a main menu
95 myawesomemenu = {
96 { "manual", terminal .. " -e man awesome" },
97 { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
98 { "restart", awesome.restart },
99 { "quit", awesome.quit }
102 mymainmenu = awful.menu.new({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
103 { "open terminal", terminal }
107 mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
108 menu = mymainmenu })
110 -- Create a systray
111 mysystray = widget({ type = "systray", align = "right" })
113 -- Create a wibox for each screen and add it
114 mywibox = {}
115 mypromptbox = {}
116 mylayoutbox = {}
117 mytaglist = {}
118 mytaglist.buttons = { button({ }, 1, awful.tag.viewonly),
119 button({ modkey }, 1, awful.client.movetotag),
120 button({ }, 3, function (tag) tag.selected = not tag.selected end),
121 button({ modkey }, 3, awful.client.toggletag),
122 button({ }, 4, awful.tag.viewnext),
123 button({ }, 5, awful.tag.viewprev) }
124 mytasklist = {}
125 mytasklist.buttons = { button({ }, 1, function (c) client.focus = c; c:raise() end),
126 button({ }, 3, function () awful.menu.clients({ width=250 }) end),
127 button({ }, 4, function () awful.client.focus.byidx(1) end),
128 button({ }, 5, function () awful.client.focus.byidx(-1) end) }
130 for s = 1, screen.count() do
131 -- Create a promptbox for each screen
132 mypromptbox[s] = widget({ type = "textbox", align = "left" })
133 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
134 -- We need one layoutbox per screen.
135 mylayoutbox[s] = widget({ type = "imagebox", align = "right" })
136 mylayoutbox[s]:buttons({ button({ }, 1, function () awful.layout.inc(layouts, 1) end),
137 button({ }, 3, function () awful.layout.inc(layouts, -1) end),
138 button({ }, 4, function () awful.layout.inc(layouts, 1) end),
139 button({ }, 5, function () awful.layout.inc(layouts, -1) end) })
140 -- Create a taglist widget
141 mytaglist[s] = awful.widget.taglist.new(s, awful.widget.taglist.label.all, mytaglist.buttons)
143 -- Create a tasklist widget
144 mytasklist[s] = awful.widget.tasklist.new(function(c)
145 return awful.widget.tasklist.label.currenttags(c, s)
146 end, mytasklist.buttons)
148 -- Create the wibox
149 mywibox[s] = wibox({ position = "top", fg = beautiful.fg_normal, bg = beautiful.bg_normal })
150 -- Add widgets to the wibox - order matters
151 mywibox[s].widgets = { mylauncher,
152 mytaglist[s],
153 mytasklist[s],
154 mypromptbox[s],
155 mytextbox,
156 mylayoutbox[s],
157 s == 1 and mysystray or nil }
158 mywibox[s].screen = s
160 -- }}}
162 -- {{{ Mouse bindings
163 awesome.buttons({
164 button({ }, 3, function () mymainmenu:toggle() end),
165 button({ }, 4, awful.tag.viewnext),
166 button({ }, 5, awful.tag.viewprev)
168 -- }}}
170 -- {{{ Key bindings
172 -- Bind keyboard digits
173 -- Compute the maximum number of digit we need, limited to 9
174 keynumber = 0
175 for s = 1, screen.count() do
176 keynumber = math.min(9, math.max(#tags[s], keynumber));
179 for i = 1, keynumber do
180 keybinding({ modkey }, i,
181 function ()
182 local screen = mouse.screen
183 if tags[screen][i] then
184 awful.tag.viewonly(tags[screen][i])
186 end):add()
187 keybinding({ modkey, "Control" }, i,
188 function ()
189 local screen = mouse.screen
190 if tags[screen][i] then
191 tags[screen][i].selected = not tags[screen][i].selected
193 end):add()
194 keybinding({ modkey, "Shift" }, i,
195 function ()
196 if client.focus and tags[client.focus.screen][i] then
197 awful.client.movetotag(tags[client.focus.screen][i])
199 end):add()
200 keybinding({ modkey, "Control", "Shift" }, i,
201 function ()
202 if client.focus and tags[client.focus.screen][i] then
203 awful.client.toggletag(tags[client.focus.screen][i])
205 end):add()
208 keybinding({ modkey }, "Left", awful.tag.viewprev):add()
209 keybinding({ modkey }, "Right", awful.tag.viewnext):add()
210 keybinding({ modkey }, "Escape", awful.tag.history.restore):add()
212 -- Standard program
213 keybinding({ modkey }, "Return", function () awful.util.spawn(terminal) end):add()
215 keybinding({ modkey, "Control" }, "r", function ()
216 mypromptbox[mouse.screen].text =
217 awful.util.escape(awful.util.restart())
218 end):add()
219 keybinding({ modkey, "Shift" }, "q", awesome.quit):add()
221 -- Client manipulation
222 keybinding({ modkey }, "m", function () if client.focus then client.focus.maximized_horizontal = not client.focus.maximized_horizontal
223 client.focus.maximized_vertical = not client.focus.maximized_vertical end end):add()
224 keybinding({ modkey }, "f", function () if client.focus then client.focus.fullscreen = not client.focus.fullscreen end end):add()
225 keybinding({ modkey, "Shift" }, "c", function () if client.focus then client.focus:kill() end end):add()
226 keybinding({ modkey }, "j", function () awful.client.focus.byidx(1); if client.focus then client.focus:raise() end end):add()
227 keybinding({ modkey }, "k", function () awful.client.focus.byidx(-1); if client.focus then client.focus:raise() end end):add()
228 keybinding({ modkey, "Shift" }, "j", function () awful.client.swap.byidx(1) end):add()
229 keybinding({ modkey, "Shift" }, "k", function () awful.client.swap.byidx(-1) end):add()
230 keybinding({ modkey, "Control" }, "j", function () awful.screen.focus(1) end):add()
231 keybinding({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end):add()
232 keybinding({ modkey, "Control" }, "space", awful.client.floating.toggle):add()
233 keybinding({ modkey, "Control" }, "Return", function () if client.focus then client.focus:swap(awful.client.getmaster()) end end):add()
234 keybinding({ modkey }, "o", awful.client.movetoscreen):add()
235 keybinding({ modkey }, "Tab", awful.client.focus.history.previous):add()
236 keybinding({ modkey }, "u", awful.client.urgent.jumpto):add()
237 keybinding({ modkey, "Shift" }, "r", function () if client.focus then client.focus:redraw() end end):add()
239 -- Layout manipulation
240 keybinding({ modkey }, "l", function () awful.tag.incmwfact(0.05) end):add()
241 keybinding({ modkey }, "h", function () awful.tag.incmwfact(-0.05) end):add()
242 keybinding({ modkey, "Shift" }, "h", function () awful.tag.incnmaster(1) end):add()
243 keybinding({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end):add()
244 keybinding({ modkey, "Control" }, "h", function () awful.tag.incncol(1) end):add()
245 keybinding({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end):add()
246 keybinding({ modkey }, "space", function () awful.layout.inc(layouts, 1) end):add()
247 keybinding({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end):add()
249 -- Prompt
250 keybinding({ modkey }, "F1", function ()
251 awful.prompt.run({ prompt = "Run: " }, mypromptbox[mouse.screen], awful.util.spawn, awful.completion.bash,
252 awful.util.getdir("cache") .. "/history")
253 end):add()
254 keybinding({ modkey }, "F4", function ()
255 awful.prompt.run({ prompt = "Run Lua code: " }, mypromptbox[mouse.screen], awful.util.eval, awful.prompt.bash,
256 awful.util.getdir("cache") .. "/history_eval")
257 end):add()
259 keybinding({ modkey, "Ctrl" }, "i", function ()
260 local s = mouse.screen
261 if mypromptbox[s].text then
262 mypromptbox[s].text = nil
263 elseif client.focus then
264 mypromptbox[s].text = nil
265 if client.focus.class then
266 mypromptbox[s].text = "Class: " .. client.focus.class .. " "
268 if client.focus.instance then
269 mypromptbox[s].text = mypromptbox[s].text .. "Instance: ".. client.focus.instance .. " "
271 if client.focus.role then
272 mypromptbox[s].text = mypromptbox[s].text .. "Role: ".. client.focus.role
275 end):add()
277 -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
278 keybinding({ modkey }, "t", awful.client.togglemarked):add()
280 for i = 1, keynumber do
281 keybinding({ modkey, "Shift" }, "F" .. i,
282 function ()
283 local screen = mouse.screen
284 if tags[screen][i] then
285 for k, c in pairs(awful.client.getmarked()) do
286 awful.client.movetotag(tags[screen][i], c)
289 end):add()
291 -- }}}
293 -- {{{ Hooks
294 -- Hook function to execute when focusing a client.
295 awful.hooks.focus.register(function (c)
296 if not awful.client.ismarked(c) then
297 c.border_color = beautiful.border_focus
299 end)
301 -- Hook function to execute when unfocusing a client.
302 awful.hooks.unfocus.register(function (c)
303 if not awful.client.ismarked(c) then
304 c.border_color = beautiful.border_normal
306 end)
308 -- Hook function to execute when marking a client
309 awful.hooks.marked.register(function (c)
310 c.border_color = beautiful.border_marked
311 end)
313 -- Hook function to execute when unmarking a client.
314 awful.hooks.unmarked.register(function (c)
315 c.border_color = beautiful.border_focus
316 end)
318 -- Hook function to execute when the mouse enters a client.
319 awful.hooks.mouse_enter.register(function (c)
320 -- Sloppy focus, but disabled for magnifier layout
321 if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
322 and awful.client.focus.filter(c) then
323 client.focus = c
325 end)
327 -- Hook function to execute when a new client appears.
328 awful.hooks.manage.register(function (c)
329 if use_titlebar then
330 -- Add a titlebar
331 awful.titlebar.add(c, { modkey = modkey })
333 -- Add mouse bindings
334 c:buttons({
335 button({ }, 1, function (c) client.focus = c; c:raise() end),
336 button({ modkey }, 1, awful.mouse.client.move),
337 button({ modkey }, 3, awful.mouse.client.resize)
339 -- New client may not receive focus
340 -- if they're not focusable, so set border anyway.
341 c.border_width = beautiful.border_width
342 c.border_color = beautiful.border_normal
344 -- Check if the application should be floating.
345 local cls = c.class
346 local inst = c.instance
347 if floatapps[cls] then
348 awful.client.floating.set(cls, floatapps[cls])
349 elseif floatapps[inst] then
350 awful.client.floating.set(cls, floatapps[inst])
353 -- Check application->screen/tag mappings.
354 local target
355 if apptags[cls] then
356 target = apptags[cls]
357 elseif apptags[inst] then
358 target = apptags[inst]
360 if target then
361 c.screen = target.screen
362 awful.client.movetotag(tags[target.screen][target.tag], c)
365 -- Do this after tag mapping, so you don't see it on the wrong tag for a split second.
366 client.focus = c
368 -- Set the windows at the slave,
369 -- i.e. put it at the end of others instead of setting it master.
370 -- awful.client.setslave(c)
372 -- Honor size hints: if you want to drop the gaps between windows, set this to false.
373 -- c.honorsizehints = false
374 end)
376 -- Hook function to execute when arranging the screen.
377 -- (tag switch, new client, etc)
378 awful.hooks.arrange.register(function (screen)
379 local layout = awful.layout.getname(awful.layout.get(screen))
380 if layout and beautiful["layout_" ..layout] then
381 mylayoutbox[screen].image = image(beautiful["layout_" .. layout])
382 else
383 mylayoutbox[screen].image = nil
386 -- Give focus to the latest client in history if no window has focus
387 -- or if the current window is a desktop or a dock one.
388 if not client.focus then
389 local c = awful.client.focus.history.get(screen, 0)
390 if c then client.focus = c end
393 -- Uncomment if you want mouse warping
394 --[[
395 if client.focus then
396 local c_c = client.focus:fullgeometry()
397 local m_c = mouse.coords()
399 if m_c.x < c_c.x or m_c.x >= c_c.x + c_c.width or
400 m_c.y < c_c.y or m_c.y >= c_c.y + c_c.height then
401 if table.maxn(m_c.buttons) == 0 then
402 mouse.coords({ x = c_c.x + 5, y = c_c.y + 5})
407 end)
409 -- Hook called every second
410 awful.hooks.timer.register(1, function ()
411 -- For unix time_t lovers
412 mytextbox.text = " " .. os.time() .. " time_t "
413 -- Otherwise use:
414 -- mytextbox.text = " " .. os.date() .. " "
415 end)
416 -- }}}