Преглед на файлове

~/.config/awesome/rc.lua: a little config for awesome wm.

I don't know if I'll keep using it, but it provides a few nice features
such as better EWMH compatibility and urgency highlighting.
Still, it would be interesting to read the XMonad source code.
Lucas Stadler преди 14 години
родител
ревизия
1807418664
променени са 1 файла, в които са добавени 378 реда и са изтрити 0 реда
  1. 378 0
      .config/awesome/rc.lua

+ 378 - 0
.config/awesome/rc.lua

@ -0,0 +1,378 @@
1
-- Standard awesome library
2
require("awful")
3
require("awful.autofocus")
4
require("awful.rules")
5
-- Widget and layout library
6
require("wibox")
7
require("vicious")
8
-- Theme handling library
9
require("beautiful")
10
-- Notification library
11
require("naughty")
12
13
-- {{{ Error handling
14
-- Check if awesome encountered an error during startup and fell back to
15
-- another config (This code will only ever execute for the fallback config)
16
if awesome.startup_errors then
17
    naughty.notify({ preset = naughty.config.presets.critical,
18
                     title = "Oops, there were errors during startup!",
19
                     text = awesome.startup_errors })
20
end
21
22
-- Handle runtime errors after startup
23
do
24
    local in_error = false
25
    awesome.connect_signal("debug::error", function (err)
26
        -- Make sure we don't go into an endless error loop
27
        if in_error then return end
28
        in_error = true
29
30
        naughty.notify({ preset = naughty.config.presets.critical,
31
                         title = "Oops, an error happened!",
32
                         text = err })
33
        in_error = false
34
    end)
35
end
36
-- }}}
37
38
-- {{{ Variable definitions
39
-- Themes define colours, icons, and wallpapers
40
beautiful.init("/usr/share/awesome/themes/zenburn/theme.lua")
41
42
-- This is used later as the default terminal and editor to run.
43
terminal = "urxvt"
44
editor = os.getenv("EDITOR") or "vim"
45
editor_cmd = terminal .. " -e " .. editor
46
47
-- Default modkey.
48
-- Usually, Mod4 is the key with a logo between Control and Alt.
49
-- If you do not like this or do not have such a key,
50
-- I suggest you to remap Mod4 to another key using xmodmap or other tools.
51
-- However, you can use another modifier like Mod1, but it may interact with others.
52
modkey = "Mod4"
53
54
-- Table of layouts to cover with awful.layout.inc, order matters.
55
layouts =
56
{
57
    awful.layout.suit.spiral,
58
    awful.layout.suit.tile,
59
    awful.layout.suit.fair,
60
    awful.layout.suit.max,
61
    awful.layout.suit.floating
62
}
63
-- }}}
64
65
-- {{{ Tags
66
-- Define a tag table which hold all screen tags.
67
tags = {}
68
for s = 1, screen.count() do
69
    -- Each screen has its own tag table.
70
    tags[s] = awful.tag({ "term", "web", "irssi", 4, 5, 6, 7 }, s, layouts[1])
71
end
72
-- }}}
73
74
space = wibox.widget.textbox()
75
space:set_text(" ")
76
77
batterywidget = wibox.widget.textbox()
78
vicious.register(batterywidget, vicious.widgets.bat, "Bat: $2%", 61, "BAT0")
79
80
memorywidget = wibox.widget.textbox()
81
vicious.register(memorywidget, vicious.widgets.mem, "Mem: $1%", 2)
82
83
mailwidget = wibox.widget.textbox()
84
mdirs = {
85
	"/home/lu/.mails/lu/INBOX",
86
	"/home/lu/.mails/htwk.imn/INBOX",
87
	"/home/lu/.mails/htwk/INBOX"
88
}
89
vicious.register(mailwidget, vicious.widgets.mdir, "New mails: $1", 59, mdirs)
90
91
-- {{{ Wibox
92
-- Create a textclock widget
93
mytextclock = awful.widget.textclock()
94
95
-- Create a wibox for each screen and add it
96
mywibox = {}
97
mypromptbox = {}
98
mylayoutbox = {}
99
mytaglist = {}
100
mytaglist.buttons = awful.util.table.join(
101
                    awful.button({ }, 1, awful.tag.viewonly),
102
                    awful.button({ modkey }, 1, awful.client.movetotag),
103
                    awful.button({ }, 3, awful.tag.viewtoggle),
104
                    awful.button({ modkey }, 3, awful.client.toggletag),
105
                    awful.button({ }, 4, awful.tag.viewnext),
106
                    awful.button({ }, 5, awful.tag.viewprev)
107
                    )
108
mytasklist = {}
109
mytasklist.buttons = awful.util.table.join(
110
                     awful.button({ }, 1, function (c)
111
                                              if c == client.focus then
112
                                                  c.minimized = true
113
                                              else
114
                                                  if not c:isvisible() then
115
                                                      awful.tag.viewonly(c:tags()[1])
116
                                                  end
117
                                                  -- This will also un-minimize
118
                                                  -- the client, if needed
119
                                                  client.focus = c
120
                                                  c:raise()
121
                                              end
122
                                          end),
123
                     awful.button({ }, 3, function ()
124
                                              if instance then
125
                                                  instance:hide()
126
                                                  instance = nil
127
                                              else
128
                                                  instance = awful.menu.clients({ width=250 })
129
                                              end
130
                                          end),
131
                     awful.button({ }, 4, function ()
132
                                              awful.client.focus.byidx(1)
133
                                              if client.focus then client.focus:raise() end
134
                                          end),
135
                     awful.button({ }, 5, function ()
136
                                              awful.client.focus.byidx(-1)
137
                                              if client.focus then client.focus:raise() end
138
                                          end))
139
140
for s = 1, screen.count() do
141
    -- Create a promptbox for each screen
142
    mypromptbox[s] = awful.widget.prompt()
143
    -- Create an imagebox widget which will contains an icon indicating which layout we're using.
144
    -- We need one layoutbox per screen.
145
    mylayoutbox[s] = awful.widget.layoutbox(s)
146
    mylayoutbox[s]:buttons(awful.util.table.join(
147
                           awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
148
                           awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
149
                           awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
150
                           awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
151
    -- Create a taglist widget
152
    mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
153
154
    -- Create a tasklist widget
155
    mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
156
157
    -- Create the wibox
158
    mywibox[s] = awful.wibox({ position = "top", screen = s })
159
160
    -- Widgets that are aligned to the left
161
    local left_layout = wibox.layout.fixed.horizontal()
162
    left_layout:add(mytaglist[s])
163
    left_layout:add(mypromptbox[s])
164
165
    -- Widgets that are aligned to the right
166
    local right_layout = wibox.layout.fixed.horizontal()
167
    if s == 1 then right_layout:add(wibox.widget.systray()) end
168
    right_layout:add(mailwidget)
169
    right_layout:add(space)
170
    right_layout:add(memorywidget)
171
    right_layout:add(space)
172
    right_layout:add(batterywidget)
173
    right_layout:add(space)
174
    right_layout:add(mytextclock)
175
    right_layout:add(mylayoutbox[s])
176
177
    -- Now bring it all together (with the tasklist in the middle)
178
    local layout = wibox.layout.align.horizontal()
179
    layout:set_left(left_layout)
180
    layout:set_middle(mytasklist[s])
181
    layout:set_right(right_layout)
182
183
    mywibox[s]:set_widget(layout)
184
end
185
-- }}}
186
187
-- {{{ Mouse bindings
188
root.buttons(awful.util.table.join(
189
    awful.button({ }, 4, awful.tag.viewnext),
190
    awful.button({ }, 5, awful.tag.viewprev)
191
))
192
-- }}}
193
194
-- {{{ Key bindings
195
globalkeys = awful.util.table.join(
196
    awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
197
    awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
198
    awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
199
200
    awful.key({ modkey,           }, "j",
201
        function ()
202
            awful.client.focus.byidx( 1)
203
            if client.focus then client.focus:raise() end
204
        end),
205
    awful.key({ modkey,           }, "k",
206
        function ()
207
            awful.client.focus.byidx(-1)
208
            if client.focus then client.focus:raise() end
209
        end),
210
211
    -- Layout manipulation
212
    awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
213
    awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
214
    awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
215
    awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
216
    awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
217
    awful.key({ modkey,           }, "Tab",
218
        function ()
219
            awful.client.focus.history.previous()
220
            if client.focus then
221
                client.focus:raise()
222
            end
223
        end),
224
225
    -- Standard program
226
    awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
227
    awful.key({ modkey, "Control" }, "r", awesome.restart),
228
    awful.key({ modkey, "Shift"   }, "q", awesome.quit),
229
230
--    awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
231
    awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
232
    awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
233
--    awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
234
    awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
235
    awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
236
    awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
237
    awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
238
239
    awful.key({ modkey, "Control" }, "n", awful.client.restore),
240
241
    -- Prompt
242
    awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
243
244
    awful.key({ modkey }, "x",
245
              function ()
246
                  awful.prompt.run({ prompt = "Run Lua code: " },
247
                  mypromptbox[mouse.screen].widget,
248
                  awful.util.eval, nil,
249
                  awful.util.getdir("cache") .. "/history_eval")
250
              end),
251
252
    awful.key({ modkey }, "l", function() os.execute("xkbswap") end),
253
    awful.key({ modkey }, "b", function() os.execute("chromium") end),
254
    awful.key({ modkey, "Shift" }, "b", function() os.execute("chromium --incognito") end)
255
)
256
257
clientkeys = awful.util.table.join(
258
    awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
259
    awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
260
    awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
261
    awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
262
    awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
263
    awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
264
    awful.key({ modkey,           }, "n",
265
        function (c)
266
            -- The client currently has the input focus, so it cannot be
267
            -- minimized, since minimized clients can't have the focus.
268
            c.minimized = true
269
        end),
270
    awful.key({ modkey,           }, "m",
271
        function (c)
272
            c.maximized_horizontal = not c.maximized_horizontal
273
            c.maximized_vertical   = not c.maximized_vertical
274
        end)
275
)
276
277
-- Compute the maximum number of digit we need, limited to 9
278
keynumber = 0
279
for s = 1, screen.count() do
280
   keynumber = math.min(9, math.max(#tags[s], keynumber));
281
end
282
283
-- Bind all key numbers to tags.
284
-- Be careful: we use keycodes to make it works on any keyboard layout.
285
-- This should map on the top row of your keyboard, usually 1 to 9.
286
for i = 1, keynumber do
287
    globalkeys = awful.util.table.join(globalkeys,
288
        awful.key({ modkey }, "#" .. i + 9,
289
                  function ()
290
                        local screen = mouse.screen
291
                        if tags[screen][i] then
292
                            awful.tag.viewonly(tags[screen][i])
293
                        end
294
                  end),
295
        awful.key({ modkey, "Control" }, "#" .. i + 9,
296
                  function ()
297
                      local screen = mouse.screen
298
                      if tags[screen][i] then
299
                          awful.tag.viewtoggle(tags[screen][i])
300
                      end
301
                  end),
302
        awful.key({ modkey, "Shift" }, "#" .. i + 9,
303
                  function ()
304
                      if client.focus and tags[client.focus.screen][i] then
305
                          awful.client.movetotag(tags[client.focus.screen][i])
306
                      end
307
                  end),
308
        awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
309
                  function ()
310
                      if client.focus and tags[client.focus.screen][i] then
311
                          awful.client.toggletag(tags[client.focus.screen][i])
312
                      end
313
                  end))
314
end
315
316
clientbuttons = awful.util.table.join(
317
    awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
318
    awful.button({ modkey }, 1, awful.mouse.client.move),
319
    awful.button({ modkey }, 3, awful.mouse.client.resize))
320
321
-- Set keys
322
root.keys(globalkeys)
323
-- }}}
324
325
-- {{{ Rules
326
awful.rules.rules = {
327
    -- All clients will match this rule.
328
    { rule = { },
329
      properties = { border_width = beautiful.border_width,
330
                     border_color = beautiful.border_normal,
331
                     focus = true,
332
                     keys = clientkeys,
333
                     buttons = clientbuttons } },
334
    { rule = { class = "MPlayer" },
335
      properties = { floating = true } },
336
    { rule = { class = "pinentry" },
337
      properties = { floating = true } },
338
    { rule = { class = "gimp" },
339
      properties = { floating = true } },
340
    -- Set Firefox to always map on tags number 2 of screen 1.
341
    -- { rule = { class = "Firefox" },
342
    --   properties = { tag = tags[1][2] } },
343
}
344
-- }}}
345
346
-- {{{ Signals
347
-- Signal function to execute when a new client appears.
348
client.connect_signal("manage", function (c, startup)
349
    -- Enable sloppy focus
350
    c:connect_signal("mouse::enter", function(c)
351
        if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
352
            and awful.client.focus.filter(c) then
353
            client.focus = c
354
        end
355
    end)
356
357
    if not startup then
358
        -- Set the windows at the slave,
359
        -- i.e. put it at the end of others instead of setting it master.
360
        -- awful.client.setslave(c)
361
362
        -- Put windows in a smart way, only if they does not set an initial position.
363
        if not c.size_hints.user_position and not c.size_hints.program_position then
364
            awful.placement.no_overlap(c)
365
            awful.placement.no_offscreen(c)
366
        end
367
    end
368
end)
369
370
client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
371
client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
372
-- }}}
373
374
-- My own stuff
375
376
client.connect_signal("focus", function(c)
377
	os.execute("/home/lu/.bin/events focus '" .. c.name .. "'")
378
end)