平铺式窗口管理器Awesome配置文件
备份 Linux窗口管理器
Awesome
的配置文件
配置文件路径:~/.config/awesome/rc.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449-- 说明:Screen 指屏幕,awesome支持多屏幕。 Tag 指标签,一个标签对应一个虚拟桌面。 Client 指程序窗口。
-- {{{ 运行所需的库
-- 标准awesome库
local gears = require("gears")
local awful = require("awful")
awful.rules = require("awful.rules")
require("awful.autofocus")
-- 窗口和布局库
local wibox = require("wibox")
-- 主题控制库
local beautiful = require("beautiful")
-- 通知库
local naughty = require("naughty")
local menubar = require("menubar")
-- 导入右键程序菜单模块
require("debian.menu")
-- }}}
-- {{{ 错误处理
-- 检查awesome启动过程中是否发生错误
-- 如果发生错误则启用最近的正确配置,并通知用户
if awesome.startup_errors then
naughty.notify({ preset = naughty.config.presets.critical,
title = "Oops, there were errors during startup!",
text = awesome.startup_errors })
end
-- 处理awesome启动后的运行时错误
do
local in_error = false
awesome.connect_signal("debug::error", function (err)
-- Make sure we don't go into an endless error loop
if in_error then return end
in_error = true
naughty.notify({ preset = naughty.config.presets.critical,
title = "Oops, an error happened!",
text = err })
in_error = false
end)
end
-- }}}
-- {{{ 变量定义
-- 主题定义:颜色、图标、字体、壁纸
beautiful.init("/usr/share/awesome/themes/default/theme.lua") -- 默认主题配置文件所在路径
-- 设置默认的终端和文本编辑器
terminal = "mate-terminal"
editor = "pluma"
editor_cmd = terminal .. " -e " .. editor
-- 默认的modkey设置,用于快捷键。默认是Mod4,也就是Win键
-- 通常,Mod4键位于键盘左侧的Ctrl和Alt键之间
-- 如果你不喜欢这样的设置或者没有这个按键,
-- 建议你使用xmodmap或者别的工具把Mod4键映射到别的按键
modkey = "Mod4"
-- 默认的布局方式和顺序
-- 可以手动调整顺序,可以删除不需要的布局方式(建议注释掉即可,以免以后再想使用)
local layouts =
{
awful.layout.suit.tile, -- 平铺
awful.layout.suit.floating, -- 浮动
awful.layout.suit.tile.left,
awful.layout.suit.tile.bottom,
awful.layout.suit.tile.top,
awful.layout.suit.fair, -- 平铺,每个窗口大小一致
awful.layout.suit.max, -- 最大化
-- awful.layout.suit.fair.horizontal,
-- awful.layout.suit.max.fullscreen, -- 全屏
-- awful.layout.suit.spiral, -- 螺旋式
awful.layout.suit.magnifier -- 放大
}
-- }}}
-- {{{ 壁纸设置
if beautiful.wallpaper then
for s = 1, screen.count() do
gears.wallpaper.maximized("/home/td/Pictures/background.jpg", s, true) -- 替代引号中图片路径即可
end
end
-- }}}
-- {{{ 桌面标签
-- 定义一个包含所有虚拟桌面的标签列表
tags = {
names = {"Internet","Term","Code","Music",5,6}, -- 桌面标签的名称
layout = {layouts[1],layouts[1],layouts[7],layouts[1],layouts[2],layouts[1]} -- 标签默认布局,用索引表示,按照上面设置的layouts顺序
}
for s = 1, screen.count() do
tags[s] = awful.tag(tags.names, s, tags.layout)
end
-- }}}
-- {{{ 菜单
-- myawesomemenu是mymainmenu主菜单的一项,这里包含3个子菜单,可以手动修改子菜单
-- 还可以仿照myawesomemenu向主菜单添加新项,添加后务必加入下面的mymainmenu中
myawesomemenu = {
{ "edit config", "pluma /home/td/.config/awesome/rc.lua" }, -- 这个子菜单用于修改awesome配置文件,pluma是一个简单的文本编辑器
{ "restart", awesome.restart },
{ "quit", awesome.quit }
}
-- mymainmenu主菜单
mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon }, -- 这里的awesome项添加上面的myawesomemenu
{ "应用程序", debian.menu.Debian_menu.Debian }, -- 这是debian.menu模块自动生成的应用程序子菜单
{ "文件管理器", "caja /home/td/" }, -- 手动添加的项
{ "网络浏览器", "chromium-browser %u" }, -- 手动添加的项
{ "open terminal", terminal },
{ "重启电脑", "gksu reboot now" }, -- 手动添加的项
{ "关闭系统", "gksu 'shutdown -h now'" }, -- 手动添加的项
}
})
mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
menu = mymainmenu })
menubar.utils.terminal = terminal -- 应用终端,见上文默认终端设置
-- }}}
-- {{{ 窗口和布局
-- 创建一个时钟部件
mytextclock = awful.widget.textclock("%X",1)
-- 为每个屏幕创建一个wibox
mywibox = {}
mypromptbox = {}
mylayoutbox = {}
mytaglist = {}
mytaglist.buttons = awful.util.table.join(
awful.button({ }, 1, awful.tag.viewonly),
awful.button({ modkey }, 1, awful.client.movetotag),
awful.button({ }, 3, awful.tag.viewtoggle),
awful.button({ modkey }, 3, awful.client.toggletag),
awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
)
mytasklist = {}
mytasklist.buttons = awful.util.table.join(
awful.button({ }, 1, function (c)
if c == client.focus then
c.minimized = true
else
-- Without this, the following
-- :isvisible() makes no sense
c.minimized = false
if not c:isvisible() then
awful.tag.viewonly(c:tags()[1])
end
-- This will also un-minimize
-- the client, if needed
client.focus = c
c:raise()
end
end),
awful.button({ }, 3, function ()
if instance then
instance:hide()
instance = nil
else
instance = awful.menu.clients({
theme = { width = 250 }
})
end
end),
awful.button({ }, 4, function ()
awful.client.focus.byidx(1)
if client.focus then client.focus:raise() end
end),
awful.button({ }, 5, function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end))
for s = 1, screen.count() do
-- 为每个屏幕创建一个信息框
mypromptbox[s] = awful.widget.prompt()
-- 在屏幕右上角显示目前正在使用的布局样式
mylayoutbox[s] = awful.widget.layoutbox(s)
mylayoutbox[s]:buttons(awful.util.table.join(
awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
-- 创建屏幕左上方的tag列表
mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
-- Create a tasklist widget
mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
-- Create the wibox
mywibox[s] = awful.wibox({ position = "top", screen = s })
-- 左对齐的部件
local left_layout = wibox.layout.fixed.horizontal()
left_layout:add(mylauncher)
left_layout:add(mytaglist[s])
left_layout:add(mypromptbox[s])
-- 右对齐的部件
local right_layout = wibox.layout.fixed.horizontal()
if s == 1 then right_layout:add(wibox.widget.systray()) end
right_layout:add(mytextclock)
right_layout:add(mylayoutbox[s])
--
local layout = wibox.layout.align.horizontal()
layout:set_left(left_layout)
layout:set_middle(mytasklist[s])
layout:set_right(right_layout)
mywibox[s]:set_widget(layout)
end
-- }}}
-- {{{ 鼠标绑定
root.buttons(awful.util.table.join(
awful.button({ }, 3, function () mymainmenu:toggle() end),
awful.button({ }, 4, awful.tag.viewnext),
awful.button({ }, 5, awful.tag.viewprev)
))
-- }}}
-- {{{ 快捷键
globalkeys = awful.util.table.join(
awful.key({ modkey, }, "Left", awful.tag.viewprev ), -- 向左一个标签
awful.key({ modkey, }, "Right", awful.tag.viewnext ), -- 向右一个标签
awful.key({ modkey, }, "Escape", awful.tag.history.restore), -- 之前使用的标签
awful.key({ modkey, }, "j", -- 切换下一个窗口
function ()
awful.client.focus.byidx( 1)
if client.focus then client.focus:raise() end
end),
awful.key({ modkey, }, "k", -- 切换上一个窗口
function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end),
awful.key({ modkey, }, "w", function () mymainmenu:show() end), -- 显示主菜单,鼠标右键关闭
-- Layout manipulation
awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end), -- 当前窗口和前一个窗口互换位置
awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end), -- 当前窗口和后一个窗口互换位置
awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end), -- 切换到下一个屏幕
awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end), -- 切换到上一个屏幕
-- awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
awful.key({ modkey, }, "Tab", -- 切换到之前使用的窗口
function ()
awful.client.focus.history.previous()
if client.focus then
client.focus:raise()
end
end),
-- 标准程序
awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
awful.key({ modkey, "Control" }, "r", awesome.restart), -- 重启awesome
awful.key({ modkey, "Shift" }, "q", awesome.quit), -- 退出awesome
awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end), -- 增加主区域宽度
awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end), -- 减少主区域宽度
awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end), -- 增加主区域窗口数目
awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end), -- 减少主区域窗口数目
awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end), -- 按顺序切换布局样式
awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end), -- 反向切换布局样式
awful.key({ modkey, "Control" }, "n", awful.client.restore),
-- 启动器
awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end), -- 默认,程序启动器
-- awful.key({ modkey }, "r", function () awful.util.spawn( "dmenu_run" ) end), -- dmenu,程序启动器,需额外安装
-- 包含显式选项的启动器
awful.key({ modkey }, "p", function() menubar.show() end)
)
clientkeys = awful.util.table.join(
awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end), -- 切换全屏/非全屏
awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
awful.key({ modkey, }, "o", awful.client.movetoscreen ),
awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end), -- 标记当前窗口
awful.key({ modkey, }, "n", -- 最小化窗口
function (c)
-- The client currently has the input focus, so it cannot be
-- minimized, since minimized clients can't have the focus.
c.minimized = true
end),
awful.key({ modkey, }, "m", -- 最大化窗口
function (c)
c.maximized_horizontal = not c.maximized_horizontal
c.maximized_vertical = not c.maximized_vertical
end)
)
-- 把数字键1到9绑定到对应的标签
for i = 1, 9 do
globalkeys = awful.util.table.join(globalkeys,
-- 转到指定窗口
awful.key({ modkey }, "#" .. i + 9,
function ()
local screen = mouse.screen
local tag = awful.tag.gettags(screen)[i]
if tag then
awful.tag.viewonly(tag)
end
end),
awful.key({ modkey, "Control" }, "#" .. i + 9,
function ()
local screen = mouse.screen
local tag = awful.tag.gettags(screen)[i]
if tag then
awful.tag.viewtoggle(tag)
end
end),
-- 把窗口移动到指定标签
awful.key({ modkey, "Shift" }, "#" .. i + 9, -- 快捷键,注意需要先用 Mod4 + t 标记当前窗口
function ()
if client.focus then
local tag = awful.tag.gettags(client.focus.screen)[i]
if tag then
awful.client.movetotag(tag)
end
end
end),
awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
function ()
if client.focus then
local tag = awful.tag.gettags(client.focus.screen)[i]
if tag then
awful.client.toggletag(tag)
end
end
end))
end
clientbuttons = awful.util.table.join(
awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
awful.button({ modkey }, 1, awful.mouse.client.move),
awful.button({ modkey }, 3, awful.mouse.client.resize))
-- 应用快捷键
root.keys(globalkeys)
-- }}}
-- {{{ 规则
-- 设置部分程序启动时默认所在的屏幕和虚拟桌面,以及是否浮动(支持多屏幕,默认为屏幕1)
awful.rules.rules = {
{ rule = { },
properties = { border_width = beautiful.border_width,
border_color = beautiful.border_normal,
focus = awful.client.focus.filter,
raise = true,
keys = clientkeys,
buttons = clientbuttons } },
{ rule = { class = "MPlayer" },
properties = { floating = true } }, -- 设置mplayer启动时默认为浮动状态
{ rule = { class = "pinentry" },
properties = { floating = true } },
{ rule = { class = "gimp" },
properties = { floating = true } },
-- 设置chromium浏览器启动时默认位于第一个屏幕的第一个标签
{ rule = { class = "Chromium-browser" },
properties = { tag = tags[1][1] } },
-- { rule = { class = "Firefox" },
-- properties = { tag = tags[1][1] } },
}
-- }}}
-- {{{ Signals
-- 以下功能仅在新窗口出现时生效
client.connect_signal("manage", function (c, startup)
-- Enable sloppy focus
c:connect_signal("mouse::enter", function(c)
if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
and awful.client.focus.filter(c) then
client.focus = c
end
end)
if not startup then
-- Set the windows at the slave,
-- i.e. put it at the end of others instead of setting it master.
-- awful.client.setslave(c)
-- Put windows in a smart way, only if they does not set an initial position.
if not c.size_hints.user_position and not c.size_hints.program_position then
awful.placement.no_overlap(c)
awful.placement.no_offscreen(c)
end
elseif not c.size_hints.user_position and not c.size_hints.program_position then
-- Prevent clients from being unreachable after screen count change
awful.placement.no_offscreen(c)
end
local titlebars_enabled = false
if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
-- 标题栏的按钮
local buttons = awful.util.table.join(
awful.button({ }, 1, function()
client.focus = c
c:raise()
awful.mouse.client.move(c)
end),
awful.button({ }, 3, function()
client.focus = c
c:raise()
awful.mouse.client.resize(c)
end)
)
-- 左对齐的部件
local left_layout = wibox.layout.fixed.horizontal()
left_layout:add(awful.titlebar.widget.iconwidget(c))
left_layout:buttons(buttons)
-- 右对齐的部件
local right_layout = wibox.layout.fixed.horizontal()
right_layout:add(awful.titlebar.widget.floatingbutton(c))
right_layout:add(awful.titlebar.widget.maximizedbutton(c))
right_layout:add(awful.titlebar.widget.stickybutton(c))
right_layout:add(awful.titlebar.widget.ontopbutton(c))
right_layout:add(awful.titlebar.widget.closebutton(c))
--
local middle_layout = wibox.layout.flex.horizontal()
local title = awful.titlebar.widget.titlewidget(c)
title:set_align("center")
middle_layout:add(title)
middle_layout:buttons(buttons)
-- Now bring it all together
local layout = wibox.layout.align.horizontal()
layout:set_left(left_layout)
layout:set_right(right_layout)
layout:set_middle(middle_layout)
awful.titlebar(c):set_widget(layout)
end
end)
client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
-- }}}