rc.lua 15 KB

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