rc.lua_original 23 KB

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