rc.lua 17 KB

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