rc.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. -- If LuaRocks is installed, make sure that packages installed through it are
  2. -- found (e.g. lgi). If LuaRocks is not installed, do nothing.
  3. pcall(require, "luarocks.loader")
  4. -- Standard awesome library
  5. local gears = require("gears")
  6. local awful = require("awful")
  7. require("awful.autofocus")
  8. -- Widget and layout library
  9. local wibox = require("wibox")
  10. -- Theme handling library
  11. local beautiful = require("beautiful")
  12. -- Notification library
  13. local naughty = require("naughty")
  14. local menubar = require("menubar")
  15. local hotkeys_popup = require("awful.hotkeys_popup")
  16. -- Enable hotkeys help widget for VIM and other apps
  17. -- when client with a matching name is opened:
  18. require("awful.hotkeys_popup.keys")
  19. -- {{{ Error handling
  20. -- Check if awesome encountered an error during startup and fell back to
  21. -- another config (This code will only ever execute for the fallback config)
  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. -- Handle runtime errors after startup
  28. do
  29. local in_error = false
  30. awesome.connect_signal("debug::error", function (err)
  31. -- Make sure we don't go into an endless error loop
  32. if in_error then return end
  33. in_error = true
  34. naughty.notify({ preset = naughty.config.presets.critical,
  35. title = "Oops, an error happened!",
  36. text = tostring(err) })
  37. in_error = false
  38. end)
  39. end
  40. -- }}}
  41. -- {{{ Variable definitions
  42. -- Themes define colours, icons, font and wallpapers.
  43. beautiful.init(gears.filesystem.get_themes_dir() .. "default/theme.lua")
  44. -- Default modkey.
  45. -- Usually, Mod4 is the key with a logo between Control and Alt.
  46. -- If you do not like this or do not have such a key,
  47. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  48. -- However, you can use another modifier like Mod1, but it may interact with others.
  49. modkey = "Mod4"
  50. -- Table of layouts to cover with awful.layout.inc, order matters.
  51. awful.layout.layouts = {
  52. awful.layout.suit.floating,
  53. awful.layout.suit.tile,
  54. awful.layout.suit.tile.left,
  55. awful.layout.suit.tile.bottom,
  56. awful.layout.suit.tile.top,
  57. awful.layout.suit.fair,
  58. awful.layout.suit.fair.horizontal,
  59. awful.layout.suit.spiral,
  60. awful.layout.suit.spiral.dwindle,
  61. awful.layout.suit.max,
  62. awful.layout.suit.max.fullscreen,
  63. awful.layout.suit.magnifier,
  64. awful.layout.suit.corner.nw,
  65. -- awful.layout.suit.corner.ne,
  66. -- awful.layout.suit.corner.sw,
  67. -- awful.layout.suit.corner.se,
  68. }
  69. -- }}}
  70. -- {{{ Menu
  71. -- Create a launcher widget and a main menu
  72. myawesomemenu = {
  73. { "hotkeys", function() hotkeys_popup.show_help(nil, awful.screen.focused()) end },
  74. { "restart", awesome.restart },
  75. { "quit", function() awesome.quit() end },
  76. }
  77. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  78. }
  79. })
  80. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  81. menu = mymainmenu })
  82. -- Keyboard map indicator and switcher
  83. mykeyboardlayout = awful.widget.keyboardlayout()
  84. -- {{{ Wibar
  85. -- Create a textclock widget
  86. mytextclock = wibox.widget.textclock()
  87. -- Create a wibox for each screen and add it
  88. local taglist_buttons = gears.table.join(
  89. awful.button({ }, 1, function(t) t:view_only() end),
  90. awful.button({ modkey }, 1, function(t)
  91. if client.focus then
  92. client.focus:move_to_tag(t)
  93. end
  94. end),
  95. awful.button({ }, 3, awful.tag.viewtoggle),
  96. awful.button({ modkey }, 3, function(t)
  97. if client.focus then
  98. client.focus:toggle_tag(t)
  99. end
  100. end),
  101. awful.button({ }, 4, function(t) awful.tag.viewnext(t.screen) end),
  102. awful.button({ }, 5, function(t) awful.tag.viewprev(t.screen) end)
  103. )
  104. local tasklist_buttons = gears.table.join(
  105. awful.button({ }, 1, function (c)
  106. if c == client.focus then
  107. c.minimized = true
  108. else
  109. c:emit_signal(
  110. "request::activate",
  111. "tasklist",
  112. {raise = true}
  113. )
  114. end
  115. end),
  116. awful.button({ }, 3, function()
  117. awful.menu.client_list({ theme = { width = 250 } })
  118. end),
  119. awful.button({ }, 4, function ()
  120. awful.client.focus.byidx(1)
  121. end),
  122. awful.button({ }, 5, function ()
  123. awful.client.focus.byidx(-1)
  124. end))
  125. local function set_wallpaper(s)
  126. -- Wallpaper
  127. if beautiful.wallpaper then
  128. local wallpaper = beautiful.wallpaper
  129. -- If wallpaper is a function, call it with the screen
  130. if type(wallpaper) == "function" then
  131. wallpaper = wallpaper(s)
  132. end
  133. gears.wallpaper.maximized(wallpaper, s, true)
  134. end
  135. end
  136. -- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
  137. screen.connect_signal("property::geometry", set_wallpaper)
  138. awful.screen.connect_for_each_screen(function(s)
  139. -- Wallpaper
  140. set_wallpaper(s)
  141. -- Each screen has its own tag table.
  142. awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1])
  143. -- Create a promptbox for each screen
  144. s.mypromptbox = awful.widget.prompt()
  145. -- Create an imagebox widget which will contain an icon indicating which layout we're using.
  146. -- We need one layoutbox per screen.
  147. s.mylayoutbox = awful.widget.layoutbox(s)
  148. s.mylayoutbox:buttons(gears.table.join(
  149. awful.button({ }, 1, function () awful.layout.inc( 1) end),
  150. awful.button({ }, 3, function () awful.layout.inc(-1) end),
  151. awful.button({ }, 4, function () awful.layout.inc( 1) end),
  152. awful.button({ }, 5, function () awful.layout.inc(-1) end)))
  153. -- Create a taglist widget
  154. s.mytaglist = awful.widget.taglist {
  155. screen = s,
  156. filter = awful.widget.taglist.filter.all,
  157. buttons = taglist_buttons
  158. }
  159. -- Create a tasklist widget
  160. s.mytasklist = awful.widget.tasklist {
  161. screen = s,
  162. filter = awful.widget.tasklist.filter.currenttags,
  163. buttons = tasklist_buttons
  164. }
  165. -- Create the wibox
  166. s.mywibox = awful.wibar({ position = "top", screen = s })
  167. -- Add widgets to the wibox
  168. s.mywibox:setup {
  169. layout = wibox.layout.align.horizontal,
  170. { -- Left widgets
  171. layout = wibox.layout.fixed.horizontal,
  172. mylauncher,
  173. s.mytaglist,
  174. s.mypromptbox,
  175. },
  176. s.mytasklist, -- Middle widget
  177. { -- Right widgets
  178. layout = wibox.layout.fixed.horizontal,
  179. mykeyboardlayout,
  180. wibox.widget.systray(),
  181. mytextclock,
  182. s.mylayoutbox,
  183. },
  184. }
  185. end)
  186. -- }}}
  187. -- {{{ Mouse bindings
  188. root.buttons(gears.table.join(
  189. awful.button({ }, 3, function () mymainmenu:toggle() end),
  190. awful.button({ }, 4, awful.tag.viewnext),
  191. awful.button({ }, 5, awful.tag.viewprev)
  192. ))
  193. -- }}}
  194. -- {{{ Key bindings
  195. globalkeys = gears.table.join(
  196. awful.key({ modkey, }, "s", hotkeys_popup.show_help,
  197. {description="show help", group="awesome"}),
  198. awful.key({ modkey, }, "Left", awful.tag.viewprev,
  199. {description = "view previous", group = "tag"}),
  200. awful.key({ modkey, }, "Right", awful.tag.viewnext,
  201. {description = "view next", group = "tag"}),
  202. awful.key({ modkey, }, "Escape", awful.tag.history.restore,
  203. {description = "go back", group = "tag"}),
  204. awful.key({ modkey, }, "j",
  205. function ()
  206. awful.client.focus.byidx( 1)
  207. end,
  208. {description = "focus next by index", group = "client"}
  209. ),
  210. awful.key({ modkey, }, "k",
  211. function ()
  212. awful.client.focus.byidx(-1)
  213. end,
  214. {description = "focus previous by index", group = "client"}
  215. ),
  216. awful.key({ modkey, }, "w", function () mymainmenu:show() end,
  217. {description = "show main menu", group = "awesome"}),
  218. -- Layout manipulation
  219. awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end,
  220. {description = "swap with next client by index", group = "client"}),
  221. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end,
  222. {description = "swap with previous client by index", group = "client"}),
  223. awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end,
  224. {description = "focus the next screen", group = "screen"}),
  225. awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end,
  226. {description = "focus the previous screen", group = "screen"}),
  227. awful.key({ modkey, }, "u", awful.client.urgent.jumpto,
  228. {description = "jump to urgent client", group = "client"}),
  229. awful.key({ modkey, }, "Tab",
  230. function ()
  231. awful.client.focus.history.previous()
  232. if client.focus then
  233. client.focus:raise()
  234. end
  235. end,
  236. {description = "go back", group = "client"}),
  237. -- Standard program
  238. awful.key({ modkey, "Control" }, "r", awesome.restart,
  239. {description = "reload awesome", group = "awesome"}),
  240. awful.key({ modkey, "Shift" }, "q", awesome.quit,
  241. {description = "quit awesome", group = "awesome"}),
  242. awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end,
  243. {description = "increase master width factor", group = "layout"}),
  244. awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end,
  245. {description = "decrease master width factor", group = "layout"}),
  246. awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1, nil, true) end,
  247. {description = "increase the number of master clients", group = "layout"}),
  248. awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1, nil, true) end,
  249. {description = "decrease the number of master clients", group = "layout"}),
  250. awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1, nil, true) end,
  251. {description = "increase the number of columns", group = "layout"}),
  252. awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1, nil, true) end,
  253. {description = "decrease the number of columns", group = "layout"}),
  254. awful.key({ modkey, }, "space", function () awful.layout.inc( 1) end,
  255. {description = "select next", group = "layout"}),
  256. awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(-1) end,
  257. {description = "select previous", group = "layout"}),
  258. awful.key({ modkey, "Control" }, "n",
  259. function ()
  260. local c = awful.client.restore()
  261. -- Focus restored client
  262. if c then
  263. c:emit_signal(
  264. "request::activate", "key.unminimize", {raise = true}
  265. )
  266. end
  267. end,
  268. {description = "restore minimized", group = "client"}),
  269. -- Prompt
  270. awful.key({ modkey }, "r", function () awful.screen.focused().mypromptbox:run() end,
  271. {description = "run prompt", group = "launcher"}),
  272. awful.key({ modkey }, "x",
  273. function ()
  274. awful.prompt.run {
  275. prompt = "Run Lua code: ",
  276. textbox = awful.screen.focused().mypromptbox.widget,
  277. exe_callback = awful.util.eval,
  278. history_path = awful.util.get_cache_dir() .. "/history_eval"
  279. }
  280. end,
  281. {description = "lua execute prompt", group = "awesome"})
  282. -- Menubar
  283. -- awful.key({ modkey }, "p", function() menubar.show() end,
  284. -- {description = "show the menubar", group = "launcher"})
  285. )
  286. clientkeys = gears.table.join(
  287. awful.key({ modkey, }, "f",
  288. function (c)
  289. c.fullscreen = not c.fullscreen
  290. c:raise()
  291. end,
  292. {description = "toggle fullscreen", group = "client"}),
  293. awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end,
  294. {description = "close", group = "client"}),
  295. awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ,
  296. {description = "toggle floating", group = "client"}),
  297. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end,
  298. {description = "move to master", group = "client"}),
  299. awful.key({ modkey, }, "o", function (c) c:move_to_screen() end,
  300. {description = "move to screen", group = "client"}),
  301. awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end,
  302. {description = "toggle keep on top", group = "client"}),
  303. awful.key({ modkey, }, "n",
  304. function (c)
  305. -- The client currently has the input focus, so it cannot be
  306. -- minimized, since minimized clients can't have the focus.
  307. c.minimized = true
  308. end ,
  309. {description = "minimize", group = "client"}),
  310. awful.key({ modkey, }, "m",
  311. function (c)
  312. c.maximized = not c.maximized
  313. c:raise()
  314. end ,
  315. {description = "(un)maximize", group = "client"}),
  316. awful.key({ modkey, "Control" }, "m",
  317. function (c)
  318. c.maximized_vertical = not c.maximized_vertical
  319. c:raise()
  320. end ,
  321. {description = "(un)maximize vertically", group = "client"}),
  322. awful.key({ modkey, "Shift" }, "m",
  323. function (c)
  324. c.maximized_horizontal = not c.maximized_horizontal
  325. c:raise()
  326. end ,
  327. {description = "(un)maximize horizontally", group = "client"})
  328. )
  329. -- Bind all key numbers to tags.
  330. -- Be careful: we use keycodes to make it work on any keyboard layout.
  331. -- This should map on the top row of your keyboard, usually 1 to 9.
  332. for i = 1, 9 do
  333. globalkeys = gears.table.join(globalkeys,
  334. -- View tag only.
  335. awful.key({ modkey }, "#" .. i + 9,
  336. function ()
  337. local screen = awful.screen.focused()
  338. local tag = screen.tags[i]
  339. if tag then
  340. tag:view_only()
  341. end
  342. end,
  343. {description = "view tag #"..i, group = "tag"}),
  344. -- Toggle tag display.
  345. awful.key({ modkey, "Control" }, "#" .. i + 9,
  346. function ()
  347. local screen = awful.screen.focused()
  348. local tag = screen.tags[i]
  349. if tag then
  350. awful.tag.viewtoggle(tag)
  351. end
  352. end,
  353. {description = "toggle tag #" .. i, group = "tag"}),
  354. -- Move client to tag.
  355. awful.key({ modkey, "Shift" }, "#" .. i + 9,
  356. function ()
  357. if client.focus then
  358. local tag = client.focus.screen.tags[i]
  359. if tag then
  360. client.focus:move_to_tag(tag)
  361. end
  362. end
  363. end,
  364. {description = "move focused client to tag #"..i, group = "tag"}),
  365. -- Toggle tag on focused client.
  366. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  367. function ()
  368. if client.focus then
  369. local tag = client.focus.screen.tags[i]
  370. if tag then
  371. client.focus:toggle_tag(tag)
  372. end
  373. end
  374. end,
  375. {description = "toggle focused client on tag #" .. i, group = "tag"})
  376. )
  377. end
  378. clientbuttons = gears.table.join(
  379. awful.button({ }, 1, function (c)
  380. c:emit_signal("request::activate", "mouse_click", {raise = true})
  381. end),
  382. awful.button({ modkey }, 1, function (c)
  383. c:emit_signal("request::activate", "mouse_click", {raise = true})
  384. awful.mouse.client.move(c)
  385. end),
  386. awful.button({ modkey }, 3, function (c)
  387. c:emit_signal("request::activate", "mouse_click", {raise = true})
  388. awful.mouse.client.resize(c)
  389. end)
  390. )
  391. -- Set keys
  392. root.keys(globalkeys)
  393. -- }}}
  394. -- {{{ Rules
  395. -- Rules to apply to new clients (through the "manage" signal).
  396. awful.rules.rules = {
  397. -- All clients will match this rule.
  398. { rule = { },
  399. properties = { border_width = beautiful.border_width,
  400. border_color = beautiful.border_normal,
  401. focus = awful.client.focus.filter,
  402. raise = true,
  403. keys = clientkeys,
  404. buttons = clientbuttons,
  405. screen = awful.screen.preferred,
  406. placement = awful.placement.no_overlap+awful.placement.no_offscreen
  407. }
  408. },
  409. -- Floating clients.
  410. { rule_any = {
  411. instance = {
  412. "DTA", -- Firefox addon DownThemAll.
  413. "copyq", -- Includes session name in class.
  414. "pinentry",
  415. },
  416. class = {
  417. "Arandr",
  418. "Blueman-manager",
  419. "Gpick",
  420. "Kruler",
  421. "MessageWin", -- kalarm.
  422. "Sxiv",
  423. "Tor Browser", -- Needs a fixed window size to avoid fingerprinting by screen size.
  424. "Wpa_gui",
  425. "veromix",
  426. "xtightvncviewer"},
  427. -- Note that the name property shown in xprop might be set slightly after creation of the client
  428. -- and the name shown there might not match defined rules here.
  429. name = {
  430. "Event Tester", -- xev.
  431. },
  432. role = {
  433. "AlarmWindow", -- Thunderbird's calendar.
  434. "ConfigManager", -- Thunderbird's about:config.
  435. "pop-up", -- e.g. Google Chrome's (detached) Developer Tools.
  436. }
  437. }, properties = { floating = true }},
  438. -- Add titlebars to normal clients and dialogs
  439. { rule_any = {type = { "normal", "dialog" }
  440. }, properties = { titlebars_enabled = true }
  441. },
  442. -- Set Firefox to always map on the tag named "2" on screen 1.
  443. -- { rule = { class = "Firefox" },
  444. -- properties = { screen = 1, tag = "2" } },
  445. }
  446. -- }}}
  447. -- {{{ Signals
  448. -- Signal function to execute when a new client appears.
  449. client.connect_signal("manage", function (c)
  450. -- Set the windows at the slave,
  451. -- i.e. put it at the end of others instead of setting it master.
  452. -- if not awesome.startup then awful.client.setslave(c) end
  453. if awesome.startup
  454. and not c.size_hints.user_position
  455. and not c.size_hints.program_position then
  456. -- Prevent clients from being unreachable after screen count changes.
  457. awful.placement.no_offscreen(c)
  458. end
  459. end)
  460. -- Add a titlebar if titlebars_enabled is set to true in the rules.
  461. client.connect_signal("request::titlebars", function(c)
  462. -- buttons for the titlebar
  463. local buttons = gears.table.join(
  464. awful.button({ }, 1, function()
  465. c:emit_signal("request::activate", "titlebar", {raise = true})
  466. awful.mouse.client.move(c)
  467. end),
  468. awful.button({ }, 3, function()
  469. c:emit_signal("request::activate", "titlebar", {raise = true})
  470. awful.mouse.client.resize(c)
  471. end)
  472. )
  473. awful.titlebar(c) : setup {
  474. { -- Left
  475. awful.titlebar.widget.iconwidget(c),
  476. buttons = buttons,
  477. layout = wibox.layout.fixed.horizontal
  478. },
  479. { -- Middle
  480. { -- Title
  481. align = "center",
  482. widget = awful.titlebar.widget.titlewidget(c)
  483. },
  484. buttons = buttons,
  485. layout = wibox.layout.flex.horizontal
  486. },
  487. { -- Right
  488. awful.titlebar.widget.floatingbutton (c),
  489. awful.titlebar.widget.maximizedbutton(c),
  490. awful.titlebar.widget.stickybutton (c),
  491. awful.titlebar.widget.ontopbutton (c),
  492. awful.titlebar.widget.closebutton (c),
  493. layout = wibox.layout.fixed.horizontal()
  494. },
  495. layout = wibox.layout.align.horizontal
  496. }
  497. end)
  498. -- Enable sloppy focus, so that focus follows mouse.
  499. client.connect_signal("mouse::enter", function(c)
  500. c:emit_signal("request::activate", "mouse_enter", {raise = false})
  501. end)
  502. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  503. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  504. -- }}}