rc.lua 16 KB

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