rc.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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. local simple_seperator = wibox.widget.textbox()
  190. simple_seperator:set_text(' ')
  191. right_layout:add(simple_seperator)
  192. right_layout:add(wibox.widget.systray())
  193. right_layout:add(textclock)
  194. right_layout:add(seperator)
  195. right_layout:add(obvious.volume_alsa(1, "Master"))
  196. right_layout:add(seperator)
  197. right_layout:add(obvious.battery())
  198. right_layout:add(simple_seperator)
  199. right_layout:add(layoutbox[s])
  200. -- Now bring it all together (with the tasklist in the middle)
  201. local layout = wibox.layout.align.horizontal()
  202. layout:set_left(left_layout)
  203. layout:set_middle(tasklist[s])
  204. layout:set_right(right_layout)
  205. widgetbox[s]:set_widget(layout)
  206. end
  207. -- }}}
  208. -- {{{ Mouse bindings
  209. root.buttons(awful.util.table.join(
  210. awful.button({ }, 3, function() mainmenu:toggle() end),
  211. awful.button({ }, 4, awful.tag.viewnext),
  212. awful.button({ }, 5, awful.tag.viewprev)
  213. ))
  214. -- }}}
  215. -- {{{ Key bindings
  216. globalkeys = awful.util.table.join(
  217. awful.key({ s_mod, }, "Left", awful.tag.viewprev ),
  218. awful.key({ s_mod, }, "Right", awful.tag.viewnext ),
  219. awful.key({ s_mod, }, "Escape", awful.tag.history.restore),
  220. awful.key({ s_mod, }, "j", function()
  221. awful.client.focus.byidx( 1)
  222. if client.focus then client.focus:raise() end
  223. end),
  224. awful.key({ s_mod, }, "k", function()
  225. awful.client.focus.byidx(-1)
  226. if client.focus then client.focus:raise() end
  227. end),
  228. awful.key({ s_mod, }, "Space", function() mainmenu:show() end),
  229. -- Layout manipulation
  230. awful.key({ s_mod, "Shift" }, "j", function() awful.client.swap.byidx( 1) end),
  231. awful.key({ s_mod, "Shift" }, "k", function() awful.client.swap.byidx( -1) end),
  232. awful.key({ s_mod, "Control" }, "j", function() awful.screen.focus_relative( 1) end),
  233. awful.key({ s_mod, "Control" }, "k", function() awful.screen.focus_relative(-1) end),
  234. awful.key({ s_mod, }, "u", awful.client.urgent.jumpto),
  235. awful.key({ alt_mod, }, "Tab", function()
  236. awful.client.focus.history.previous()
  237. if client.focus then
  238. client.focus:raise()
  239. end
  240. end),
  241. -- Standard program
  242. awful.key({ s_mod, "Control" }, "r", awesome.restart),
  243. awful.key({ s_mod, "Shift" }, "q", awesome.quit),
  244. awful.key({ s_mod, }, "l", function() awful.tag.incmwfact( 0.05) end),
  245. awful.key({ s_mod, }, "h", function() awful.tag.incmwfact(-0.05) end),
  246. awful.key({ s_mod, "Shift" }, "h", function() awful.tag.incnmaster( 1) end),
  247. awful.key({ s_mod, "Shift" }, "l", function() awful.tag.incnmaster(-1) end),
  248. awful.key({ s_mod, "Control" }, "h", function() awful.tag.incncol( 1) end),
  249. awful.key({ s_mod, "Control" }, "l", function() awful.tag.incncol(-1) end),
  250. awful.key({ s_mod, }, "space", function() awful.layout.inc(layouts, 1) end),
  251. awful.key({ s_mod, "Shift" }, "space", function() awful.layout.inc(layouts, -1) end),
  252. awful.key({ s_mod, "Control" }, "n", awful.client.restore),
  253. -- Prompt
  254. awful.key({ s_mod }, "r", function() promptbox[mouse.screen]:run() end),
  255. awful.key({ s_mod }, "x", function()
  256. awful.prompt.run({ prompt = "Run Lua code: " },
  257. mypromptbox[mouse.screen].widget,
  258. awful.util.eval, nil,
  259. awful.util.getdir("cache") .. "/history_eval")
  260. end),
  261. -- Menubar
  262. awful.key({ s_mod }, "p", function() menubar.show() end)
  263. )
  264. clientkeys = awful.util.table.join(
  265. awful.key({ s_mod, }, "f", function(c) c.fullscreen = not c.fullscreen end),
  266. awful.key({ s_mod, "Shift" }, "c", function(c) c:kill() end),
  267. awful.key({ s_mod, "Control" }, "space", awful.client.floating.toggle ),
  268. awful.key({ s_mod, "Control" }, "Return", function(c) c:swap(awful.client.getmaster()) end),
  269. awful.key({ s_mod, }, "o", awful.client.movetoscreen ),
  270. awful.key({ s_mod, }, "t", function(c) c.ontop = not c.ontop end),
  271. awful.key({ s_mod, }, "n", function(c)
  272. -- The client currently has the input focus, so it cannot be
  273. -- minimized, since minimized clients can't have the focus.
  274. c.minimized = true
  275. end),
  276. awful.key({ s_mod, }, "m", function(c)
  277. c.maximized_horizontal = not c.maximized_horizontal
  278. c.maximized_vertical = not c.maximized_vertical
  279. end)
  280. )
  281. -- Bind all key numbers to tags.
  282. -- Be careful: we use keycodes to make it works on any keyboard layout.
  283. -- This should map on the top row of your keyboard, usually 1 to 9.
  284. for i = 1, 9 do
  285. globalkeys = awful.util.table.join(globalkeys,
  286. -- View tag only.
  287. awful.key({ s_mod }, "#" .. i + 9, function()
  288. local screen = mouse.screen
  289. local tag = awful.tag.gettags(screen)[i]
  290. if tag then
  291. awful.tag.viewonly(tag)
  292. end
  293. end),
  294. -- Toggle tag.
  295. awful.key({ s_mod, "Control" }, "#" .. i + 9, function()
  296. local screen = mouse.screen
  297. local tag = awful.tag.gettags(screen)[i]
  298. if tag then
  299. awful.tag.viewtoggle(tag)
  300. end
  301. end),
  302. -- Move client to tag.
  303. awful.key({ s_mod, "Shift" }, "#" .. i + 9, function()
  304. if client.focus then
  305. local tag = awful.tag.gettags(client.focus.screen)[i]
  306. if tag then
  307. awful.client.movetotag(tag)
  308. end
  309. end
  310. end),
  311. -- Toggle tag.
  312. awful.key({ s_mod, "Control", "Shift" }, "#" .. i + 9, function()
  313. if client.focus then
  314. local tag = awful.tag.gettags(client.focus.screen)[i]
  315. if tag then
  316. awful.client.toggletag(tag)
  317. end
  318. end
  319. end))
  320. end
  321. clientbuttons = awful.util.table.join(
  322. awful.button({ }, 1, function(c) client.focus = c; c:raise() end),
  323. awful.button({ s_mod }, 1, awful.mouse.client.move),
  324. awful.button({ s_mod }, 3, awful.mouse.client.resize))
  325. -- Set keys
  326. root.keys(globalkeys)
  327. -- }}}
  328. -- {{{ Rules
  329. -- Rules to apply to new clients (through the "manage" signal).
  330. awful.rules.rules = {
  331. -- All clients will match this rule.
  332. { rule = { },
  333. properties = {
  334. border_width = beautiful.border_width,
  335. border_color = beautiful.border_normal,
  336. focus = awful.client.focus.filter,
  337. raise = true,
  338. keys = clientkeys,
  339. buttons = clientbuttons,
  340. size_hints_honor = false
  341. } },
  342. { rule = { class = "Pidgin", role = "buddy_list" },
  343. properties = { floating = true, width = 235, height = 450 } },
  344. { rule = { class = "Skype" },
  345. properties = { floating = true} },
  346. { rule = { class = "gimp" },
  347. properties = { floating = true } },
  348. { rule = { class = 'urxvt' },
  349. properties = { border = 0 } },
  350. { rule = { class = "Conky" },
  351. properties = {
  352. floating = true,
  353. sticky = true,
  354. ontop = false,
  355. focusable = false,
  356. size_hints = {"program_position", "program_size"}
  357. } }
  358. }
  359. -- }}}
  360. -- {{{ Signals
  361. -- Signal functionto execute when a new client appears.
  362. client.connect_signal("manage", function(c, startup)
  363. -- Enable sloppy focus
  364. c:connect_signal("mouse::enter", function(c)
  365. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  366. and awful.client.focus.filter(c) then
  367. client.focus = c
  368. end
  369. end)
  370. if not startup then
  371. -- Set the windows at the slave,
  372. -- i.e. put it at the end of others instead of setting it master.
  373. -- awful.client.setslave(c)
  374. -- Put windows in a smart way, only if they does not set an initial position.
  375. if not c.size_hints.user_position and not c.size_hints.program_position then
  376. awful.placement.no_overlap(c)
  377. awful.placement.no_offscreen(c)
  378. end
  379. end
  380. local titlebars_enabled = false
  381. if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  382. -- buttons for the titlebar
  383. local buttons = awful.util.table.join(
  384. awful.button({ }, 1, function()
  385. client.focus = c
  386. c:raise()
  387. awful.mouse.client.move(c)
  388. end),
  389. awful.button({ }, 3, function()
  390. client.focus = c
  391. c:raise()
  392. awful.mouse.client.resize(c)
  393. end)
  394. )
  395. -- Widgets that are aligned to the left
  396. local left_layout = wibox.layout.fixed.horizontal()
  397. left_layout:add(awful.titlebar.widget.iconwidget(c))
  398. left_layout:buttons(buttons)
  399. -- Widgets that are aligned to the right
  400. local right_layout = wibox.layout.fixed.horizontal()
  401. right_layout:add(awful.titlebar.widget.floatingbutton(c))
  402. right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  403. right_layout:add(awful.titlebar.widget.stickybutton(c))
  404. right_layout:add(awful.titlebar.widget.ontopbutton(c))
  405. right_layout:add(awful.titlebar.widget.closebutton(c))
  406. -- The title goes in the middle
  407. local middle_layout = wibox.layout.flex.horizontal()
  408. local title = awful.titlebar.widget.titlewidget(c)
  409. title:set_align("center")
  410. middle_layout:add(title)
  411. middle_layout:buttons(buttons)
  412. -- Now bring it all together
  413. local layout = wibox.layout.align.horizontal()
  414. layout:set_left(left_layout)
  415. layout:set_right(right_layout)
  416. layout:set_middle(middle_layout)
  417. awful.titlebar(c):set_widget(layout)
  418. end
  419. end)
  420. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  421. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  422. -- }}}