rc.lua 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. -- {{{ License
  2. -- Awesome main config file
  3. -- 2012, Emmanuel Bouthenot <kolter@openics.org>
  4. --
  5. -- This file is distributed in the hope that it will be useful,
  6. -- but WITHOUT ANY WARRANTY
  7. --
  8. -- }}}
  9. -- {{{ Libraries
  10. -- Standard awesome library
  11. require("awful")
  12. require("awful.autofocus")
  13. require("awful.rules")
  14. -- Theme handling library
  15. require("beautiful")
  16. -- Notification library
  17. require("naughty")
  18. -- Load Debian menu entries
  19. require("debian.menu")
  20. -- Misc tools
  21. require("wicked")
  22. require("vicious")
  23. -- User libraries
  24. require("helpers")
  25. -- }}}
  26. -- {{{ Error handling
  27. -- Check if awesome encountered an error during startup and fell back to
  28. -- another config (This code will only ever execute for the fallback config)
  29. if awesome.startup_errors then
  30. naughty.notify({ preset = naughty.config.presets.critical,
  31. title = "Oops, there were errors during startup!",
  32. text = awesome.startup_errors })
  33. end
  34. -- Handle runtime errors after startup
  35. do
  36. local in_error = false
  37. awesome.add_signal("debug::error", function (err)
  38. -- Make sure we don't go into an endless error loop
  39. if in_error then return end
  40. in_error = true
  41. naughty.notify({ preset = naughty.config.presets.critical,
  42. title = "Oops, an error happened!",
  43. text = err })
  44. in_error = false
  45. end)
  46. end
  47. -- }}}
  48. -- {{{ Variable definitions
  49. -- Themes define colours, icons, and wallpapers
  50. beautiful.init("/usr/share/awesome/themes/default/theme.lua")
  51. -- This is used later as the default terminal and editor to run.
  52. terminal = whereis('xterm') or 'x-terminal-emulator'
  53. editor = os.getenv('EDITOR') or 'sensible-editor'
  54. editor_cmd = terminal .. ' -e ' .. editor
  55. -- Default modkey.
  56. -- Usually, Mod4 is the key with a logo between Control and Alt.
  57. -- If you do not like this or do not have such a key,
  58. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  59. -- However, you can use another modifier like Mod1, but it may interact with others.
  60. -- modkey = "Mod4"
  61. modkey = "Mod1"
  62. -- Table of layouts to cover with awful.layout.inc, order matters.
  63. layouts =
  64. {
  65. awful.layout.suit.floating,
  66. awful.layout.suit.tile,
  67. awful.layout.suit.tile.left,
  68. awful.layout.suit.tile.bottom,
  69. awful.layout.suit.tile.top,
  70. awful.layout.suit.fair,
  71. awful.layout.suit.fair.horizontal,
  72. awful.layout.suit.spiral,
  73. awful.layout.suit.spiral.dwindle,
  74. awful.layout.suit.max,
  75. awful.layout.suit.max.fullscreen,
  76. awful.layout.suit.magnifier
  77. }
  78. -- Store the current tag
  79. mycurrenttag = 1
  80. -- }}}
  81. -- {{{ Tags
  82. -- Define a tag table which hold all screen tags.
  83. tags = {}
  84. for s = 1, screen.count() do
  85. -- Each screen has its own tag table.
  86. tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
  87. end
  88. -- }}}
  89. -- {{{ Menu
  90. -- Create a laucher widget and a main menu
  91. myawesomemenu = {
  92. { "manual", terminal .. " -e man awesome" },
  93. { "edit config", editor_cmd .. " " .. awesome.conffile },
  94. { "restart", awesome.restart },
  95. { "quit", awesome.quit }
  96. }
  97. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  98. { "Debian", debian.menu.Debian_menu.Debian },
  99. { "open terminal", terminal }
  100. }
  101. })
  102. mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
  103. menu = mymainmenu })
  104. -- }}}
  105. -- {{{ Widgets
  106. -- {{{ CPU widget
  107. -- cpuwidget = awful.widget.graph({ layout = awful.widget.layout.horizontal.rightleft })
  108. -- cpuwidget:set_width(30)
  109. -- cpuwidget:set_height(19)
  110. -- cpuwidget:set_max_value(1)
  111. -- cpuwidget:set_background_color("#333333")
  112. -- cpuwidget:set_border_color("#0a0a0a")
  113. -- cpuwidget:set_color("#FF5656")
  114. -- cpuwidget:set_gradient_angle(50)
  115. -- cpuwidget:set_gradient_colors({ "#AEC6D8", "#285577", "#285577" })
  116. -- vicious.register(cpuwidget, vicious.widgets.cpu, "$1")
  117. -- }}}
  118. -- {{{ MEM widget
  119. -- memwidget = awful.widget.progressbar({ layout = awful.widget.layout.horizontal.rightleft })
  120. -- memwidget:set_width(15)
  121. -- memwidget:set_height(19)
  122. -- memwidget:set_vertical(true)
  123. -- memwidget:set_background_color("#333333")
  124. -- memwidget:set_border_color("#0a0a0a")
  125. -- memwidget:set_color("#FF5656")
  126. -- memwidget:set_gradient_colors({ "#AEC6D8", "#285577", "#285577" })
  127. -- vicious.register(memwidget, vicious.widgets.mem, "$1", 19)
  128. -- }}}
  129. -- {{{ VOL widget
  130. volwidget = widget({
  131. align = right,
  132. type = "textbox"
  133. })
  134. vicious.register(volwidget, vicious.widgets.volume, ' ♬:$1٪', 5, 'Master')
  135. -- }}}
  136. -- }}}
  137. -- {{{ Wibox
  138. -- Create a textclock widget
  139. mytextclock = awful.widget.textclock(
  140. { align = "right" },
  141. "%a %d, %H:%M",
  142. 60
  143. )
  144. -- Create a systray
  145. mysystray = widget({ type = "systray" })
  146. -- Create a wibox for each screen and add it
  147. mywibox = {}
  148. mypromptbox = {}
  149. mylayoutbox = {}
  150. mytaglist = {}
  151. mytaglist.buttons = awful.util.table.join(
  152. awful.button({ }, 1, awful.tag.viewonly),
  153. awful.button({ modkey }, 1, awful.client.movetotag),
  154. awful.button({ }, 3, awful.tag.viewtoggle),
  155. awful.button({ modkey }, 3, awful.client.toggletag),
  156. awful.button({ }, 4, awful.tag.viewnext),
  157. awful.button({ }, 5, awful.tag.viewprev)
  158. )
  159. mytasklist = {}
  160. mytasklist.buttons = awful.util.table.join(
  161. awful.button({ }, 1, function (c)
  162. if c == client.focus then
  163. c.minimized = true
  164. else
  165. if not c:isvisible() then
  166. awful.tag.viewonly(c:tags()[1])
  167. end
  168. -- This will also un-minimize
  169. -- the client, if needed
  170. client.focus = c
  171. c:raise()
  172. end
  173. end),
  174. awful.button({ }, 3, function ()
  175. if instance then
  176. instance:hide()
  177. instance = nil
  178. else
  179. instance = awful.menu.clients({ width=250 })
  180. end
  181. end),
  182. awful.button({ }, 4, function ()
  183. awful.client.focus.byidx(1)
  184. if client.focus then client.focus:raise() end
  185. end),
  186. awful.button({ }, 5, function ()
  187. awful.client.focus.byidx(-1)
  188. if client.focus then client.focus:raise() end
  189. end)
  190. )
  191. for s = 1, screen.count() do
  192. -- Create a promptbox for each screen
  193. mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  194. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  195. -- We need one layoutbox per screen.
  196. mylayoutbox[s] = awful.widget.layoutbox(s)
  197. mylayoutbox[s]:buttons(awful.util.table.join(
  198. awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  199. awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  200. awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  201. awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)
  202. ))
  203. -- Create a taglist widget
  204. mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  205. -- Create a tasklist widget
  206. mytasklist[s] = awful.widget.tasklist(function(c)
  207. return awful.widget.tasklist.label.currenttags(c, s)
  208. end, mytasklist.buttons)
  209. -- Create the wibox
  210. mywibox[s] = awful.wibox({ position = "top", screen = s })
  211. -- Add widgets to the wibox - order matters
  212. mywibox[s].widgets = {
  213. {
  214. mylauncher,
  215. mytaglist[s],
  216. mypromptbox[s],
  217. layout = awful.widget.layout.horizontal.leftright
  218. },
  219. mylayoutbox[s],
  220. volwidget,
  221. mytextclock,
  222. s == 1 and mysystray or nil,
  223. mytasklist[s],
  224. layout = awful.widget.layout.horizontal.rightleft
  225. }
  226. end
  227. -- }}}
  228. -- {{{ Mouse bindings
  229. root.buttons(awful.util.table.join(
  230. awful.button({ }, 3, function () mymainmenu:toggle() end),
  231. awful.button({ }, 4, awful.tag.viewnext),
  232. awful.button({ }, 5, awful.tag.viewprev)
  233. ))
  234. -- }}}
  235. -- {{{ Key bindings
  236. globalkeys = awful.util.table.join(
  237. awful.key({ modkey, }, "Left", awful.tag.viewprev ),
  238. awful.key({ modkey, }, "Right", awful.tag.viewnext ),
  239. awful.key({ modkey, }, "Escape", awful.tag.history.restore),
  240. awful.key({ modkey, }, "j",
  241. function ()
  242. awful.client.focus.byidx( 1)
  243. if client.focus then client.focus:raise() end
  244. end),
  245. awful.key({ modkey, }, "k",
  246. function ()
  247. awful.client.focus.byidx(-1)
  248. if client.focus then client.focus:raise() end
  249. end),
  250. -- awful.key({ modkey, }, "w", function () mymainmenu:show({keygrabber=true}) end),
  251. -- Layout manipulation
  252. awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
  253. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
  254. awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  255. awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  256. awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
  257. awful.key({ modkey, }, "Tab",
  258. function ()
  259. awful.client.focus.history.previous()
  260. if client.focus then
  261. client.focus:raise()
  262. end
  263. end),
  264. -- Standard program
  265. awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
  266. awful.key({ modkey, "Control" }, "r", awesome.restart),
  267. awful.key({ modkey, "Shift" }, "q", awesome.quit),
  268. -- awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  269. -- awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  270. -- awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  271. -- awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  272. -- awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
  273. -- awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
  274. -- awful.key({ "Shift" }, "Right", function () awful.layout.inc(layouts, 1) end),
  275. -- awful.key({ "Shift" }, "Left", function () awful.layout.inc(layouts, -1) end),
  276. -- awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
  277. -- awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
  278. awful.key({ modkey, "Control" }, "n", awful.client.restore),
  279. -- Prompt
  280. awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
  281. awful.key({ modkey }, "x",
  282. function ()
  283. awful.prompt.run({ prompt = "Run Lua code: " },
  284. mypromptbox[mouse.screen].widget,
  285. awful.util.eval, nil,
  286. awful.util.getdir("cache") .. "/history_eval")
  287. end),
  288. -- Screensaver
  289. awful.key({ modkey, "Control"}, "l", function() awful.util.spawn("xscreensaver-command -lock") end),
  290. -- Dropdown terminal
  291. awful.key({ modkey }, "space", function()
  292. local curtag = awful.tag.getidx(awful.tag.selected(mouse.screen))
  293. local lasttag = table.getn(tags[mouse.screen])
  294. if not (curtag == lasttag) then
  295. mycurrenttag = curtag
  296. awful.tag.viewonly(tags[mouse.screen][lasttag])
  297. else
  298. awful.tag.viewonly(tags[mouse.screen][mycurrenttag])
  299. end
  300. end)
  301. )
  302. -- Extend globalkeys
  303. for i = 1, table.getn(tags[mouse.screen]) do
  304. globalkeys = awful.util.table.join(
  305. globalkeys,
  306. -- Ctrl Fx keys shows (goes to) tag X
  307. awful.key({ "Control"}, 'F' .. i, function()
  308. awful.tag.viewonly(tags[mouse.screen][i])
  309. mycurrenttag = i
  310. end),
  311. -- Shift Fx move focused application to tag X
  312. awful.key({ "Control", "Shift" }, 'F' .. i,
  313. function ()
  314. if client.focus and tags[client.focus.screen][i] then
  315. awful.client.movetotag(tags[client.focus.screen][i])
  316. end
  317. end)
  318. )
  319. end
  320. clientkeys = awful.util.table.join(
  321. awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
  322. awful.key({ modkey, }, "c", function (c) c:kill() end),
  323. awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
  324. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  325. awful.key({ modkey, }, "o", awful.client.movetoscreen ),
  326. awful.key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
  327. awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
  328. awful.key({ modkey, }, "n",
  329. function (c)
  330. -- The client currently has the input focus, so it cannot be
  331. -- minimized, since minimized clients can't have the focus.
  332. c.minimized = true
  333. end),
  334. awful.key({ modkey, }, "m",
  335. function (c)
  336. c.maximized_horizontal = not c.maximized_horizontal
  337. c.maximized_vertical = not c.maximized_vertical
  338. end)
  339. )
  340. -- Compute the maximum number of digit we need, limited to 9
  341. keynumber = 0
  342. for s = 1, screen.count() do
  343. keynumber = math.min(9, math.max(#tags[s], keynumber));
  344. end
  345. -- Bind all key numbers to tags.
  346. -- Be careful: we use keycodes to make it works on any keyboard layout.
  347. -- This should map on the top row of your keyboard, usually 1 to 9.
  348. for i = 1, keynumber do
  349. globalkeys = awful.util.table.join(globalkeys,
  350. awful.key({ modkey }, "#" .. i + 9,
  351. function ()
  352. local screen = mouse.screen
  353. if tags[screen][i] then
  354. awful.tag.viewonly(tags[screen][i])
  355. end
  356. end),
  357. awful.key({ modkey, "Control" }, "#" .. i + 9,
  358. function ()
  359. local screen = mouse.screen
  360. if tags[screen][i] then
  361. awful.tag.viewtoggle(tags[screen][i])
  362. end
  363. end),
  364. awful.key({ modkey, "Shift" }, "#" .. i + 9,
  365. function ()
  366. if client.focus and tags[client.focus.screen][i] then
  367. awful.client.movetotag(tags[client.focus.screen][i])
  368. end
  369. end),
  370. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  371. function ()
  372. if client.focus and tags[client.focus.screen][i] then
  373. awful.client.toggletag(tags[client.focus.screen][i])
  374. end
  375. end))
  376. end
  377. clientbuttons = awful.util.table.join(
  378. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  379. awful.button({ modkey }, 1, awful.mouse.client.move),
  380. awful.button({ modkey }, 3, awful.mouse.client.resize))
  381. -- Set keys
  382. root.keys(globalkeys)
  383. -- }}}
  384. -- {{{ Rules
  385. awful.rules.rules = {
  386. -- All clients will match this rule.
  387. { rule = { },
  388. properties = { border_width = beautiful.border_width,
  389. border_color = beautiful.border_normal,
  390. focus = true,
  391. keys = clientkeys,
  392. buttons = clientbuttons } },
  393. { rule = { class = "MPlayer" }, properties = { floating = true } },
  394. { rule = { class = "pinentry" }, properties = { floating = true } },
  395. { rule = { class = "gimp" }, properties = { floating = true } },
  396. { rule = { class = "pidgin" }, properties = { floating = true } },
  397. -- Set Firefox to always map on tags number 2 of screen 1.
  398. -- { rule = { class = "Firefox" },
  399. -- properties = { tag = tags[1][2] } },
  400. }
  401. -- }}}
  402. -- {{{ Signals
  403. -- Signal function to execute when a new client appears.
  404. client.add_signal("manage", function (c, startup)
  405. -- Add a titlebar
  406. -- awful.titlebar.add(c, { modkey = modkey })
  407. -- Enable sloppy focus
  408. c:add_signal("mouse::enter", function(c)
  409. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  410. and awful.client.focus.filter(c) then
  411. client.focus = c
  412. end
  413. end)
  414. if not startup then
  415. -- Set the windows at the slave,
  416. -- i.e. put it at the end of others instead of setting it master.
  417. -- awful.client.setslave(c)
  418. -- Put windows in a smart way, only if they does not set an initial position.
  419. if not c.size_hints.user_position and not c.size_hints.program_position then
  420. awful.placement.no_overlap(c)
  421. awful.placement.no_offscreen(c)
  422. end
  423. end
  424. end)
  425. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  426. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  427. -- }}}
  428. -- {{{ Startup programs
  429. runonce('xscreensaver -no-splash')
  430. runonce('clipit')
  431. runonce('roxterm --disable-sm')
  432. runonce('pidgin')
  433. runonce('setxkbmap -option compose:menu')
  434. -- }}}
  435. -- vim: foldmethod=marker