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