rc.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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('killall conky 2>/dev/null 1>&2; conky -c ' .. os.getenv('HOME') .. '/.config/conky/conkyrc')
  44. awful.util.spawn('pidgin')
  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: www', '3: im', '4: misc', '5: media', 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. awful.tag.setncol(columns-1, tags[s][i])
  92. awful.tag.setmwfact(1/columns, tags[s][i])
  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 = awful.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 wibox
  187. widgetbox[s] = awful.wibox({ 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(textclock)
  202. right_layout:add(seperator)
  203. right_layout:add(obvious.volume_alsa(1, "Master"))
  204. right_layout:add(seperator)
  205. right_layout:add(obvious.battery())
  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, }, "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]:run() end),
  262. awful.key({ s_mod }, "x", function()
  263. awful.prompt.run({ prompt = "Run Lua code: " },
  264. promptbox[mouse.screen].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) c.fullscreen = not c.fullscreen end),
  273. awful.key({ s_mod, "Shift" }, "c", function(c) c:kill() end),
  274. awful.key({ s_mod, "Control" }, "space", awful.client.floating.toggle ),
  275. awful.key({ s_mod, "Control" }, "Return", function(c) c:swap(awful.client.getmaster()) end),
  276. awful.key({ s_mod, }, "i", function(c) awful.client.movetoscreen(c, c.screen-1) end ),
  277. awful.key({ s_mod, }, "o", function(c) awful.client.movetoscreen(c, c.screen+1) end ),
  278. awful.key({ s_mod, }, "t", function(c) c.ontop = not c.ontop end),
  279. awful.key({ s_mod, }, "n", function(c)
  280. -- The client currently has the input focus, so it cannot be
  281. -- minimized, since minimized clients can't have the focus.
  282. c.minimized = true
  283. end),
  284. awful.key({ s_mod, }, "m", function(c)
  285. c.maximized_horizontal = not c.maximized_horizontal
  286. c.maximized_vertical = not c.maximized_vertical
  287. end)
  288. )
  289. -- Bind all key numbers to tags.
  290. -- Be careful: we use keycodes to make it works on any keyboard layout.
  291. -- This should map on the top row of your keyboard, usually 1 to 9.
  292. for i = 1, 9 do
  293. globalkeys = awful.util.table.join(globalkeys,
  294. -- View tag only.
  295. awful.key({ s_mod }, "#" .. i + 9, function()
  296. local screen = mouse.screen
  297. local tag = awful.tag.gettags(screen)[i]
  298. if tag then
  299. awful.tag.viewonly(tag)
  300. end
  301. end),
  302. -- Toggle tag.
  303. awful.key({ s_mod, "Control" }, "#" .. i + 9, function()
  304. local screen = mouse.screen
  305. local tag = awful.tag.gettags(screen)[i]
  306. if tag then
  307. awful.tag.viewtoggle(tag)
  308. end
  309. end),
  310. -- Move client to tag.
  311. awful.key({ s_mod, "Shift" }, "#" .. i + 9, function()
  312. if client.focus then
  313. local tag = awful.tag.gettags(client.focus.screen)[i]
  314. if tag then
  315. awful.client.movetotag(tag)
  316. end
  317. end
  318. end),
  319. -- Toggle tag.
  320. awful.key({ s_mod, "Control", "Shift" }, "#" .. i + 9, function()
  321. if client.focus then
  322. local tag = awful.tag.gettags(client.focus.screen)[i]
  323. if tag then
  324. awful.client.toggletag(tag)
  325. end
  326. end
  327. end)
  328. )
  329. end
  330. clientbuttons = awful.util.table.join(
  331. awful.button({ }, 1, function(c) client.focus = c; c:raise() end),
  332. awful.button({ s_mod }, 1, awful.mouse.client.move),
  333. awful.button({ s_mod }, 3, awful.mouse.client.resize)
  334. )
  335. -- Set keys
  336. root.keys(globalkeys)
  337. -- }}}
  338. -- {{{ Rules
  339. -- Rules to apply to new clients (through the "manage" signal).
  340. awful.rules.rules = {
  341. -- All clients will match this rule.
  342. { rule = { },
  343. properties = {
  344. border_width = beautiful.border_width,
  345. border_color = beautiful.border_normal,
  346. focus = awful.client.focus.filter,
  347. raise = true,
  348. keys = clientkeys,
  349. buttons = clientbuttons,
  350. size_hints_honor = false
  351. }},
  352. { rule = { class = "Pidgin", role = "buddy_list" },
  353. properties = { floating = true, width = 235, height = 450 } },
  354. { rule = { class = "Skype" },
  355. properties = { floating = true} },
  356. { rule = { class = "gimp" },
  357. properties = { floating = true } },
  358. { rule = { class = 'urxvt' },
  359. properties = { border = 0 } },
  360. { rule = { class = "Conky" },
  361. properties = {
  362. floating = true,
  363. sticky = true,
  364. ontop = false,
  365. focusable = false,
  366. size_hints = {"program_position", "program_size"}
  367. }}
  368. }
  369. -- }}}
  370. -- {{{ Signals
  371. -- Signal functionto execute when a new client appears.
  372. client.connect_signal("manage", function(c, startup)
  373. -- Enable sloppy focus
  374. c:connect_signal("mouse::enter", function(c)
  375. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  376. and awful.client.focus.filter(c) then
  377. client.focus = c
  378. end
  379. end)
  380. if not startup then
  381. -- Set the windows at the slave,
  382. -- i.e. put it at the end of others instead of setting it master.
  383. -- awful.client.setslave(c)
  384. -- Put windows in a smart way, only if they does not set an initial position.
  385. if not c.size_hints.user_position and not c.size_hints.program_position then
  386. awful.placement.no_overlap(c)
  387. awful.placement.no_offscreen(c)
  388. end
  389. end
  390. local titlebars_enabled = false
  391. if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  392. -- buttons for the titlebar
  393. local buttons = awful.util.table.join(
  394. awful.button({ }, 1, function()
  395. client.focus = c
  396. c:raise()
  397. awful.mouse.client.move(c)
  398. end),
  399. awful.button({ }, 3, function()
  400. client.focus = c
  401. c:raise()
  402. awful.mouse.client.resize(c)
  403. end)
  404. )
  405. -- Widgets that are aligned to the left
  406. local left_layout = wibox.layout.fixed.horizontal()
  407. left_layout:add(awful.titlebar.widget.iconwidget(c))
  408. left_layout:buttons(buttons)
  409. -- Widgets that are aligned to the right
  410. local right_layout = wibox.layout.fixed.horizontal()
  411. right_layout:add(awful.titlebar.widget.floatingbutton(c))
  412. right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  413. right_layout:add(awful.titlebar.widget.stickybutton(c))
  414. right_layout:add(awful.titlebar.widget.ontopbutton(c))
  415. right_layout:add(awful.titlebar.widget.closebutton(c))
  416. -- The title goes in the middle
  417. local middle_layout = wibox.layout.flex.horizontal()
  418. local title = awful.titlebar.widget.titlewidget(c)
  419. title:set_align("center")
  420. middle_layout:add(title)
  421. middle_layout:buttons(buttons)
  422. -- Now bring it all together
  423. local layout = wibox.layout.align.horizontal()
  424. layout:set_left(left_layout)
  425. layout:set_right(right_layout)
  426. layout:set_middle(middle_layout)
  427. awful.titlebar(c):set_widget(layout)
  428. end
  429. end)
  430. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  431. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  432. -- }}}