You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

590 line
23 KiB

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