rc.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. local gears = require("gears")
  2. awful = require("awful")
  3. awful.rules = require("awful.rules")
  4. require("awful.autofocus")
  5. local wibox = require("wibox")
  6. local beautiful = require("beautiful")
  7. naughty = require("naughty")
  8. local battery = require("obvious.battery")
  9. battery.preferred_backend = 'acpi'
  10. require("obvious.volume_alsa") -- FIXME: breaks with pulseaudio
  11. local menubar = require("menubar")
  12. -- {{{ Error handling
  13. -- Check if awesome encountered an error during startup and fell back to
  14. -- another config (This code will only ever execute for the fallback config)
  15. if awesome.startup_errors then
  16. naughty.notify({
  17. preset = naughty.config.presets.critical,
  18. title = "Oops, there were errors during startup!",
  19. text = awesome.startup_errors
  20. })
  21. end
  22. tagone = tag({ name = 'one' })
  23. tagone.screen = 1
  24. tagone.selected = true
  25. -- Handle runtime errors after startup
  26. do
  27. local in_error = false
  28. awesome.connect_signal("debug::error", function(err)
  29. -- Make sure we don't go into an endless error loop
  30. if in_error then return end
  31. in_error = true
  32. naughty.notify(
  33. {
  34. preset = naughty.config.presets.critical,
  35. title = "Oops, an error happened!",
  36. text = err
  37. }
  38. )
  39. in_error = false
  40. end)
  41. end
  42. -- }}}
  43. awful.spawn('compton')
  44. --awful.spawn_with_shell(os.getenv('HOME') .. '/.conkyinit --restart >/dev/null 2>&1')
  45. -- {{{ Variable definitions
  46. -- Themes define colours, icons, font and wallpapers.
  47. beautiful.init(awful.util.getdir("config") .. "/theme.lua")
  48. -- This is used later as the default terminal and editor to run.
  49. terminal = "urxvtc"
  50. editor = os.getenv("EDITOR") or "vim"
  51. editor_cmd = terminal .. " -e " .. editor
  52. s_mod = "Mod4"
  53. alt_mod = "Mod1"
  54. -- Table of layouts to cover with awful.layout.inc, order matters.
  55. local layouts =
  56. {
  57. awful.layout.suit.tile.left,
  58. awful.layout.suit.tile,
  59. --awful.layout.suit.tile.bottom,
  60. --awful.layout.suit.tile.top,
  61. awful.layout.suit.fair,
  62. --awful.layout.suit.fair.horizontal,
  63. --awful.layout.suit.spiral,
  64. --awful.layout.suit.spiral.dwindle,
  65. --awful.layout.suit.max,
  66. --awful.layout.suit.max.fullscreen,
  67. --awful.layout.suit.magnifier,
  68. awful.layout.suit.floating,
  69. }
  70. -- }}}
  71. -- {{{ Wallpaper
  72. if beautiful.wallpaper then
  73. for s = 1, screen.count() do
  74. gears.wallpaper.maximized(beautiful.wallpaper, s, true)
  75. end
  76. end
  77. -- }}}
  78. -- {{{ Tags
  79. tags = {}
  80. for s = 1, screen.count() do
  81. tags[s] = awful.tag({ '1: main', '2: aux', '3: im', '4: misc', 5, 6, 7, 8, 9 }, s,
  82. {
  83. layouts[1], layouts[1], layouts[4],
  84. layouts[4], layouts[2], layouts[1],
  85. layouts[1], layouts[1], layouts[1]
  86. }
  87. )
  88. -- 21:9 is really wide, so 3 columns makes sense. 16:9 is not, so 2 columns makes sense
  89. columns = math.ceil(screen[s].geometry.width / screen[s].geometry.height)
  90. for i,v in ipairs(tags[s]) do
  91. tags[s][i].column_count = columns-1
  92. tags[s][i].master_width_factor = 1/columns
  93. end
  94. end
  95. -- }}}
  96. -- {{{ Menu
  97. -- Create a laucher widget and a main menu
  98. awesomemenu = {
  99. { "manual", terminal .. " -e man awesome" },
  100. { "edit config", editor_cmd .. " " .. awesome.conffile },
  101. { "restart", awesome.restart },
  102. { "quit", awesome.quit }
  103. }
  104. mainmenu = awful.menu({ items = {
  105. { "awesome", awesomemenu, beautiful.awesome_icon },
  106. { "open terminal", terminal }
  107. }})
  108. launcher = awful.widget.launcher(
  109. {
  110. image = beautiful.awesome_icon,
  111. menu = mainmenu
  112. }
  113. )
  114. -- Menubar configuration
  115. menubar.utils.terminal = terminal -- Set the terminal for applications that require it
  116. -- }}}
  117. -- {{{ Wibox
  118. -- Create a textclock widget
  119. textclock = wibox.widget.textclock()
  120. -- Create a wibox for each screen and add it
  121. widgetbox = {}
  122. promptbox = {}
  123. layoutbox = {}
  124. taglist = {}
  125. taglist.buttons = awful.util.table.join(
  126. awful.button({ }, 1, awful.tag.viewonly),
  127. awful.button({ s_mod }, 1, awful.client.movetotag),
  128. awful.button({ }, 3, awful.tag.viewtoggle),
  129. awful.button({ s_mod }, 3, awful.client.toggletag),
  130. awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
  131. awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
  132. )
  133. tasklist = {}
  134. tasklist.buttons = awful.util.table.join(
  135. awful.button({ }, 1, function(c)
  136. if c == client.focus then
  137. c.minimized = true
  138. else
  139. -- Without this, the following
  140. -- :isvisible() makes no sense
  141. c.minimized = false
  142. if not c:isvisible() then
  143. awful.tag.viewonly(c:tags()[1])
  144. end
  145. -- This will also un-minimize
  146. -- the client, if needed
  147. client.focus = c
  148. c:raise()
  149. end
  150. end),
  151. awful.button({ }, 3, function()
  152. if instance then
  153. instance:hide()
  154. instance = nil
  155. else
  156. instance = awful.menu.clients({
  157. theme = { width = 250 }
  158. })
  159. end
  160. end),
  161. awful.button({ }, 4, function()
  162. awful.client.focus.byidx(1)
  163. if client.focus then client.focus:raise() end
  164. end),
  165. awful.button({ }, 5, function()
  166. awful.client.focus.byidx(-1)
  167. if client.focus then client.focus:raise() end
  168. end)
  169. )
  170. for s = 1, screen.count() do
  171. -- Create a promptbox for each screen
  172. promptbox[s] = awful.widget.prompt()
  173. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  174. -- We need one layoutbox per screen.
  175. layoutbox[s] = awful.widget.layoutbox(s)
  176. layoutbox[s]:buttons(awful.util.table.join(
  177. awful.button({ }, 1, function() awful.layout.inc(layouts, 1) end),
  178. awful.button({ }, 3, function() awful.layout.inc(layouts, -1) end),
  179. awful.button({ }, 4, function() awful.layout.inc(layouts, 1) end),
  180. awful.button({ }, 5, function() awful.layout.inc(layouts, -1) end))
  181. )
  182. -- Create a taglist widget
  183. taglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, taglist.buttons)
  184. -- Create a tasklist widget
  185. tasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, tasklist.buttons)
  186. -- Create the wibar
  187. widgetbox[s] = awful.wibar({ position = "top", screen = s })
  188. -- Widgets that are aligned to the left
  189. local left_layout = wibox.layout.fixed.horizontal()
  190. left_layout:add(launcher)
  191. left_layout:add(taglist[s])
  192. left_layout:add(promptbox[s])
  193. -- Widgets that are aligned to the right
  194. local right_layout = wibox.layout.fixed.horizontal()
  195. local seperator = wibox.widget.textbox()
  196. seperator:set_text(' | ')
  197. local simple_seperator = wibox.widget.textbox()
  198. simple_seperator:set_text(' ')
  199. right_layout:add(simple_seperator)
  200. if s == 1 then right_layout:add(wibox.widget.systray()) end
  201. right_layout:add(battery())
  202. right_layout:add(seperator)
  203. right_layout:add(obvious.volume_alsa(1, "Master"))
  204. right_layout:add(seperator)
  205. right_layout:add(textclock)
  206. right_layout:add(simple_seperator)
  207. right_layout:add(layoutbox[s])
  208. -- Now bring it all together (with the tasklist in the middle)
  209. local layout = wibox.layout.align.horizontal()
  210. layout:set_left(left_layout)
  211. layout:set_middle(tasklist[s])
  212. layout:set_right(right_layout)
  213. widgetbox[s]:set_widget(layout)
  214. end
  215. -- }}}
  216. -- {{{ Mouse bindings
  217. root.buttons(awful.util.table.join(
  218. awful.button({ }, 3, function() mainmenu:toggle() end),
  219. awful.button({ }, 4, awful.tag.viewnext),
  220. awful.button({ }, 5, awful.tag.viewprev)
  221. ))
  222. -- }}}
  223. -- {{{ Key bindings
  224. globalkeys = awful.util.table.join(
  225. awful.key({ s_mod, "Control" }, "r", awesome.restart),
  226. awful.key({ s_mod, "Shift" }, "q", awesome.quit),
  227. awful.key({ s_mod, }, "Left", awful.tag.viewprev ),
  228. awful.key({ s_mod, }, "Right", awful.tag.viewnext ),
  229. awful.key({ s_mod, }, "Escape", awful.tag.history.restore),
  230. awful.key({ s_mod, }, "j", function()
  231. awful.client.focus.byidx( 1)
  232. if client.focus then client.focus:raise() end
  233. end),
  234. awful.key({ s_mod, }, "k", function()
  235. awful.client.focus.byidx(-1)
  236. if client.focus then client.focus:raise() end
  237. end),
  238. awful.key({ s_mod, alt_mod }, "space", function() mainmenu:show() end),
  239. -- Layout manipulation
  240. awful.key({ s_mod, "Shift" }, "j", function() awful.client.swap.byidx( 1) end),
  241. awful.key({ s_mod, "Shift" }, "k", function() awful.client.swap.byidx( -1) end),
  242. awful.key({ s_mod, "Control" }, "j", function() awful.screen.focus_relative( 1) end),
  243. awful.key({ s_mod, "Control" }, "k", function() awful.screen.focus_relative(-1) end),
  244. awful.key({ s_mod, }, "u", awful.client.urgent.jumpto),
  245. awful.key({ alt_mod, }, "Tab", function()
  246. awful.client.focus.history.previous()
  247. if client.focus then
  248. client.focus:raise()
  249. end
  250. end),
  251. awful.key({ s_mod, }, "l", function() awful.tag.incmwfact( 0.05) end),
  252. awful.key({ s_mod, }, "h", function() awful.tag.incmwfact(-0.05) end),
  253. awful.key({ s_mod, "Shift" }, "h", function() awful.tag.incnmaster( 1) end),
  254. awful.key({ s_mod, "Shift" }, "l", function() awful.tag.incnmaster(-1) end),
  255. awful.key({ s_mod, "Control" }, "h", function() awful.tag.incncol( 1) end),
  256. awful.key({ s_mod, "Control" }, "l", function() awful.tag.incncol(-1) end),
  257. awful.key({ s_mod, }, "space", function() awful.layout.inc(layouts, 1) end),
  258. awful.key({ s_mod, "Shift" }, "space", function() awful.layout.inc(layouts, -1) end),
  259. awful.key({ s_mod, "Control" }, "n", awful.client.restore),
  260. -- Prompt
  261. awful.key({ s_mod }, "r", function() promptbox[mouse.screen.index]:run() end),
  262. awful.key({ s_mod }, "x", function()
  263. awful.prompt.run({ prompt = "Run Lua code: " },
  264. promptbox[mouse.screen.index].widget,
  265. awful.util.eval, nil,
  266. awful.util.getdir("cache") .. "/history_eval")
  267. end),
  268. -- Menubar
  269. awful.key({ s_mod }, "p", function() menubar.show() end)
  270. )
  271. clientkeys = awful.util.table.join(
  272. awful.key({ s_mod, }, "f", function(c)
  273. if c.wasontop == nil then
  274. c.wasontop = false
  275. end
  276. if not c.fullscreen then
  277. c.wasontop = c.ontop
  278. end
  279. c.fullscreen = not c.fullscreen
  280. if not c.fullscreen then
  281. c.ontop = c.wasontop
  282. end
  283. end),
  284. awful.key({ s_mod, "Shift" }, "c", function(c) c:kill() end),
  285. awful.key({ s_mod, "Control" }, "space", awful.client.floating.toggle ),
  286. awful.key({ s_mod, "Control" }, "Return", function(c) c:swap(awful.client.getmaster()) end),
  287. awful.key({ s_mod, }, "i", function(c) awful.client.movetoscreen(c, c.screen.index-1) end ),
  288. awful.key({ s_mod, }, "o", function(c) awful.client.movetoscreen(c, c.screen.index+1) end ),
  289. awful.key({ s_mod, }, "t", function(c) c.ontop = not c.ontop end),
  290. awful.key({ s_mod, }, "n", function(c)
  291. -- The client currently has the input focus, so it cannot be
  292. -- minimized, since minimized clients can't have the focus.
  293. c.minimized = true
  294. end),
  295. awful.key({ s_mod, }, "m", function(c)
  296. c.maximized_horizontal = not c.maximized_horizontal
  297. c.maximized_vertical = not c.maximized_vertical
  298. end),
  299. awful.key({ s_mod, "Shift" }, "m", function(c)
  300. c.maximized = not c.maximized
  301. end)
  302. )
  303. -- Bind all key numbers to tags.
  304. -- Be careful: we use keycodes to make it works on any keyboard layout.
  305. -- This should map on the top row of your keyboard, usually 1 to 9.
  306. for i = 1, 9 do
  307. globalkeys = awful.util.table.join(globalkeys,
  308. -- View tag only.
  309. awful.key({ alt_mod }, "#" .. i + 9, function()
  310. local screen = mouse.screen
  311. local tag = screen.tags[i]
  312. if tag then
  313. tag:view_only()
  314. end
  315. end),
  316. -- Toggle tag.
  317. awful.key({ alt_mod, "Control" }, "#" .. i + 9, function()
  318. local screen = mouse.screen
  319. local tag = screen.tags[i]
  320. if tag then
  321. awful.tag.viewtoggle(tag)
  322. end
  323. end),
  324. -- Move client to tag.
  325. awful.key({ alt_mod, "Shift" }, "#" .. i + 9, function()
  326. if client.focus then
  327. local tag = client.focus.screen.tags[i]
  328. if tag then
  329. client.focus:move_to_tag(tag)
  330. end
  331. end
  332. end),
  333. -- Toggle tag.
  334. awful.key({ s_mod, "Control", "Shift" }, "#" .. i + 9, function()
  335. if client.focus then
  336. local tag = client.focus.screen.tags[i]
  337. if tag then
  338. client.focus:toggle_tag(tag)
  339. end
  340. end
  341. end)
  342. )
  343. end
  344. clientbuttons = awful.util.table.join(
  345. awful.button({ }, 1, function(c) client.focus = c; c:raise() end),
  346. awful.button({ s_mod }, 1, awful.mouse.client.move),
  347. awful.button({ alt_mod }, 1, awful.mouse.client.resize)
  348. )
  349. -- Set keys
  350. root.keys(globalkeys)
  351. -- }}}
  352. -- {{{ Rules
  353. -- Rules to apply to new clients (through the "manage" signal).
  354. awful.rules.rules = {
  355. -- All clients will match this rule.
  356. { rule = { },
  357. properties = {
  358. border_width = beautiful.border_width,
  359. border_color = beautiful.border_normal,
  360. focus = awful.client.focus.filter,
  361. raise = true,
  362. keys = clientkeys,
  363. buttons = clientbuttons,
  364. screen = awful.screen.focused,
  365. size_hints_honor = false
  366. }},
  367. { rule = { class = "Pidgin", role = "buddy_list" },
  368. properties = { floating = true, width = 235, height = 450 } },
  369. { rule = { class = "Slack", role = "browser-window" },
  370. properties = { modkey = a_mod } },
  371. { rule = { instance = "crx_nckgahadagoaajjgafhacjanaoiihapd" },
  372. properties = { floating = true, ontop = true, width = 280, height = 420 } },
  373. { rule = { class = "Skype" },
  374. properties = { floating = true} },
  375. { rule = { class = "gimp" },
  376. properties = { floating = true } },
  377. { rule = { class = 'urxvt' },
  378. properties = { border = 0 } },
  379. { rule = { class = "Conky" },
  380. properties = {
  381. border_with = 0,
  382. floating = true,
  383. sticky = true,
  384. ontop = false,
  385. focusable = false,
  386. size_hints = {"program_position", "program_size"}
  387. }}
  388. }
  389. -- }}}
  390. -- {{{ Signals
  391. -- Signal functionto execute when a new client appears.
  392. client.connect_signal("manage", function(c, startup)
  393. -- Enable sloppy focus
  394. c:move_to_screen(mouse.screen)
  395. c:connect_signal("mouse::enter", function(c)
  396. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  397. and awful.client.focus.filter(c) then
  398. client.focus = c
  399. end
  400. end)
  401. if not startup then
  402. -- Set the windows at the slave,
  403. -- i.e. put it at the end of others instead of setting it master.
  404. -- awful.client.setslave(c)
  405. -- Put windows in a smart way, only if they does not set an initial position.
  406. if not c.size_hints.user_position and not c.size_hints.program_position then
  407. awful.placement.no_overlap(c)
  408. awful.placement.no_offscreen(c)
  409. end
  410. end
  411. local titlebars_enabled = false
  412. if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  413. -- buttons for the titlebar
  414. local buttons = awful.util.table.join(
  415. awful.button({ }, 1, function()
  416. client.focus = c
  417. c:raise()
  418. awful.mouse.client.move(c)
  419. end),
  420. awful.button({ }, 3, function()
  421. client.focus = c
  422. c:raise()
  423. awful.mouse.client.resize(c)
  424. end)
  425. )
  426. -- Widgets that are aligned to the left
  427. local left_layout = wibox.layout.fixed.horizontal()
  428. left_layout:add(awful.titlebar.widget.iconwidget(c))
  429. left_layout:buttons(buttons)
  430. -- Widgets that are aligned to the right
  431. local right_layout = wibox.layout.fixed.horizontal()
  432. right_layout:add(awful.titlebar.widget.floatingbutton(c))
  433. right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  434. right_layout:add(awful.titlebar.widget.stickybutton(c))
  435. right_layout:add(awful.titlebar.widget.ontopbutton(c))
  436. right_layout:add(awful.titlebar.widget.closebutton(c))
  437. -- The title goes in the middle
  438. local middle_layout = wibox.layout.flex.horizontal()
  439. local title = awful.titlebar.widget.titlewidget(c)
  440. title:set_align("center")
  441. middle_layout:add(title)
  442. middle_layout:buttons(buttons)
  443. -- Now bring it all together
  444. local layout = wibox.layout.align.horizontal()
  445. layout:set_left(left_layout)
  446. layout:set_right(right_layout)
  447. layout:set_middle(middle_layout)
  448. awful.titlebar(c):set_widget(layout)
  449. end
  450. end)
  451. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  452. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  453. -- }}}