key: move grabbing code to window
[awesome.git] / awesomerc.lua.in
blob407191e4d1089ae5a6f49b4e1127cb298942ba51
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")
10 -- {{{ Variable definitions
11 -- This is used later as the default terminal and editor to run.
12 terminal = "xterm"
13 editor = os.getenv("EDITOR") or "nano"
14 editor_cmd = terminal .. " -e " .. editor
16 -- Default modkey.
17 -- Usually, Mod4 is the key with a logo between Control and Alt.
18 -- If you do not like this or do not have such a key,
19 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
20 -- However, you can use another modifier like Mod1, but it may interact with others.
21 modkey = "Mod4"
23 -- Table of layouts to cover with awful.layout.inc, order matters.
24 layouts =
26 awful.layout.suit.tile,
27 awful.layout.suit.tile.left,
28 awful.layout.suit.tile.bottom,
29 awful.layout.suit.tile.top,
30 awful.layout.suit.fair,
31 awful.layout.suit.fair.horizontal,
32 awful.layout.suit.spiral,
33 awful.layout.suit.spiral.dwindle,
34 awful.layout.suit.max,
35 awful.layout.suit.max.fullscreen,
36 awful.layout.suit.magnifier,
37 awful.layout.suit.floating
39 -- }}}
41 -- {{{ Tags
42 -- Define a tag table which hold all screen tags.
43 tags = {}
44 for s = 1, screen.count() do
45 -- Each screen has its own tag table.
46 tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s)
47 end
48 -- }}}
50 -- {{{ Menu
51 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
52 { "open terminal", terminal }
56 mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
57 menu = mymainmenu })
58 -- }}}
60 -- {{{ Wibox
61 -- Create a textclock widget
62 mytextclock = awful.widget.textclock({ align = "right" })
64 -- Create a laucher widget and a main menu
65 myawesomemenu = {
66 { "manual", terminal .. " -e man awesome" },
67 { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
68 { "restart", awesome.restart },
69 { "quit", awesome.quit }
72 -- Create a systray
73 mysystray = widget({ type = "systray" })
75 -- Create a wibox for each screen and add it
76 mywibox = {}
77 mypromptbox = {}
78 mylayoutbox = {}
79 mytaglist = {}
80 mytaglist.buttons = awful.util.table.join(
81 awful.button({ }, 1, awful.tag.viewonly),
82 awful.button({ modkey }, 1, awful.client.movetotag),
83 awful.button({ }, 3, awful.tag.viewtoggle),
84 awful.button({ modkey }, 3, awful.client.toggletag),
85 awful.button({ }, 4, awful.tag.viewnext),
86 awful.button({ }, 5, awful.tag.viewprev)
88 mytasklist = {}
89 mytasklist.buttons = awful.util.table.join(
90 awful.button({ }, 1, function (c)
91 if not c:isvisible() then
92 awful.tag.viewonly(c:tags()[1])
93 end
94 client.focus = c
95 c:raise()
96 end),
97 awful.button({ }, 3, function ()
98 if instance then
99 instance:hide()
100 instance = nil
101 else
102 instance = awful.menu.clients({ width=250 })
104 end),
105 awful.button({ }, 4, function ()
106 awful.client.focus.byidx(1)
107 if client.focus then client.focus:raise() end
108 end),
109 awful.button({ }, 5, function ()
110 awful.client.focus.byidx(-1)
111 if client.focus then client.focus:raise() end
112 end))
114 for s = 1, screen.count() do
115 -- Create a promptbox for each screen
116 mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
117 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
118 -- We need one layoutbox per screen.
119 mylayoutbox[s] = awful.widget.layoutbox(s)
120 mylayoutbox[s]:buttons(awful.util.table.join(
121 awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
122 awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
123 awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
124 awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
125 -- Create a taglist widget
126 mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
128 -- Create a tasklist widget
129 mytasklist[s] = awful.widget.tasklist(function(c)
130 return awful.widget.tasklist.label.currenttags(c, s)
131 end, mytasklist.buttons)
133 -- Create the wibox
134 mywibox[s] = awful.wibox({ position = "top", screen = s })
135 -- Add widgets to the wibox - order matters
136 mywibox[s].widgets = {
138 mylauncher,
139 mytaglist[s],
140 mypromptbox[s],
141 layout = awful.widget.layout.horizontal.leftright
143 mylayoutbox[s],
144 mytextclock,
145 s == 1 and mysystray or nil,
146 mytasklist[s],
147 layout = awful.widget.layout.horizontal.rightleft
150 -- }}}
152 -- {{{ Mouse bindings
153 root.buttons(awful.util.table.join(
154 awful.button({ }, 3, function () mymainmenu:toggle() end),
155 awful.button({ }, 4, awful.tag.viewnext),
156 awful.button({ }, 5, awful.tag.viewprev)
158 -- }}}
160 -- {{{ Key bindings
161 globalkeys = awful.util.table.join(
162 awful.key({ modkey, }, "Left", awful.tag.viewprev ),
163 awful.key({ modkey, }, "Right", awful.tag.viewnext ),
164 awful.key({ modkey, }, "Escape", awful.tag.history.restore),
166 awful.key({ modkey, }, "j",
167 function ()
168 awful.client.focus.byidx( 1)
169 if client.focus then client.focus:raise() end
170 end),
171 awful.key({ modkey, }, "k",
172 function ()
173 awful.client.focus.byidx(-1)
174 if client.focus then client.focus:raise() end
175 end),
176 awful.key({ modkey, }, "w", function () mymainmenu:show(true) end),
178 -- Layout manipulation
179 awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
180 awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
181 awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
182 awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
183 awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
184 awful.key({ modkey, }, "Tab",
185 function ()
186 awful.client.focus.history.previous()
187 if client.focus then
188 client.focus:raise()
190 end),
192 -- Standard program
193 awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
194 awful.key({ modkey, "Control" }, "r", awesome.restart),
195 awful.key({ modkey, "Shift" }, "q", awesome.quit),
197 awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
198 awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
199 awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
200 awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
201 awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
202 awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
203 awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
204 awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
206 -- Prompt
207 awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
209 awful.key({ modkey }, "x",
210 function ()
211 awful.prompt.run({ prompt = "Run Lua code: " },
212 mypromptbox[mouse.screen].widget,
213 awful.util.eval, nil,
214 awful.util.getdir("cache") .. "/history_eval")
215 end)
218 clientkeys = awful.util.table.join(
219 awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
220 awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
221 awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
222 awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
223 awful.key({ modkey, }, "o", awful.client.movetoscreen ),
224 awful.key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
225 awful.key({ modkey, }, "n", function (c) c.minimized = not c.minimized end),
226 awful.key({ modkey, }, "m",
227 function (c)
228 c.maximized_horizontal = not c.maximized_horizontal
229 c.maximized_vertical = not c.maximized_vertical
230 end)
233 -- Compute the maximum number of digit we need, limited to 9
234 keynumber = 0
235 for s = 1, screen.count() do
236 keynumber = math.min(9, math.max(#tags[s], keynumber));
239 for i = 1, keynumber do
240 globalkeys = awful.util.table.join(globalkeys,
241 awful.key({ modkey }, i,
242 function ()
243 local screen = mouse.screen
244 if tags[screen][i] then
245 awful.tag.viewonly(tags[screen][i])
247 end),
248 awful.key({ modkey, "Control" }, i,
249 function ()
250 local screen = mouse.screen
251 if tags[screen][i] then
252 awful.tag.viewtoggle(tags[screen][i])
254 end),
255 awful.key({ modkey, "Shift" }, i,
256 function ()
257 if client.focus and tags[client.focus.screen][i] then
258 awful.client.movetotag(tags[client.focus.screen][i])
260 end),
261 awful.key({ modkey, "Control", "Shift" }, i,
262 function ()
263 if client.focus and tags[client.focus.screen][i] then
264 awful.client.toggletag(tags[client.focus.screen][i])
266 end))
269 clientbuttons = awful.util.table.join(
270 awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
271 awful.button({ modkey }, 1, awful.mouse.client.move),
272 awful.button({ modkey }, 3, awful.mouse.client.resize))
274 -- Set keys
275 root.keys(globalkeys)
276 -- }}}
278 -- {{{ Rules
279 awful.rules.rules = {
280 -- All clients will match this rule.
281 { rule = { },
282 properties = { border_width = beautiful.border_width,
283 border_color = beautiful.border_normal,
284 focus = true,
285 keys = clientkeys,
286 buttons = clientbuttons } },
287 { rule = { class = "MPlayer" },
288 properties = { floating = true } },
289 { rule = { class = "pinentry" },
290 properties = { floating = true } },
291 { rule = { class = "gimp" },
292 properties = { floating = true } },
293 -- Set Firefox to always map on tags number 2 of screen 1.
294 -- { rule = { class = "Firefox" },
295 -- properties = { tag = tags[1][2] } },
297 -- }}}
299 -- {{{ Signals
300 -- Signal function to execute when a new client appears.
301 client.add_signal("manage", function (c, startup)
302 -- If we are not managing this application at startup,
303 -- move it to the screen where the mouse is.
304 -- We only do it for filtered windows (i.e. no dock, etc).
305 if not startup and awful.client.focus.filter(c) then
306 c.screen = mouse.screen
309 -- Add a titlebar
310 -- awful.titlebar.add(c, { modkey = modkey })
312 -- Enable sloppy focus
313 c:add_signal("mouse::enter", function(c)
314 if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
315 and awful.client.focus.filter(c) then
316 client.focus = c
318 end)
320 -- Set the windows at the slave,
321 -- i.e. put it at the end of others instead of setting it master.
322 -- awful.client.setslave(c)
323 end)
325 client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
326 client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
327 -- }}}