rc.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. -- Standard awesome library
  2. require("awful")
  3. require("awful.autofocus")
  4. require("awful.rules")
  5. -- Theme handling library
  6. require("beautiful")
  7. -- Notification library
  8. require("naughty")
  9. -- Load Debian menu entries
  10. require("debian.menu")
  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({ preset = naughty.config.presets.critical,
  16. title = "Oops, there were errors during startup!",
  17. text = awesome.startup_errors })
  18. end
  19. -- Handle runtime errors after startup
  20. do
  21. local in_error = false
  22. awesome.add_signal("debug::error", function (err)
  23. -- Make sure we don't go into an endless error loop
  24. if in_error then return end
  25. in_error = true
  26. naughty.notify({ preset = naughty.config.presets.critical,
  27. title = "Oops, an error happened!",
  28. text = err })
  29. in_error = false
  30. end)
  31. end
  32. -- }}}
  33. -- {{{ Variable definitions
  34. -- Themes define colours, icons, and wallpapers
  35. beautiful.init("/usr/share/awesome/themes/zenburn/theme.lua")
  36. -- This is used later as the default terminal and editor to run.
  37. terminal = "terminator"
  38. editor = os.getenv("EDITOR") or "editor"
  39. editor_cmd = terminal .. " -e " .. editor
  40. -- Default modkey.
  41. -- Usually, Mod4 is the key with a logo between Control and Alt.
  42. -- If you do not like this or do not have such a key,
  43. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  44. -- However, you can use another modifier like Mod1, but it may interact with others.
  45. modkey = "Mod4"
  46. -- Table of layouts to cover with awful.layout.inc, order matters.
  47. layouts =
  48. {
  49. awful.layout.suit.floating,
  50. awful.layout.suit.tile,
  51. awful.layout.suit.tile.left,
  52. awful.layout.suit.tile.bottom,
  53. awful.layout.suit.tile.top,
  54. awful.layout.suit.fair,
  55. awful.layout.suit.fair.horizontal,
  56. awful.layout.suit.spiral,
  57. awful.layout.suit.spiral.dwindle,
  58. awful.layout.suit.max,
  59. awful.layout.suit.max.fullscreen,
  60. awful.layout.suit.magnifier
  61. }
  62. -- }}}
  63. -- {{{ Tags
  64. -- Define a tag table which hold all screen tags.
  65. tags = {}
  66. for s = 1, screen.count() do
  67. -- Each screen has its own tag table.
  68. tags[s] = awful.tag({ "www", "term", "irc", "games", "music" }, s, layouts[1])
  69. end
  70. -- }}}
  71. -- {{{ Menu
  72. -- Create a laucher widget and a main menu
  73. myawesomemenu = {
  74. { "manual", terminal .. " -e man awesome" },
  75. { "edit config", editor_cmd .. " " .. awesome.conffile },
  76. { "restart", awesome.restart },
  77. { "quit", awesome.quit }
  78. }
  79. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  80. { "Debian", debian.menu.Debian_menu.Debian },
  81. { "open terminal", terminal }
  82. }
  83. })
  84. mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
  85. menu = mymainmenu })
  86. -- }}}
  87. -- {{{ Wibox
  88. -- Create a textclock widget
  89. mytextclock = awful.widget.textclock({ align = "right" })
  90. -- Create a systray
  91. mysystray = widget({ type = "systray" })
  92. -- Create a wibox for each screen and add it
  93. mystatusbar = awful.wibox({ position = "bottom", screen = 1, ontop = false, width = 1, height = 16 })
  94. mywibox = {}
  95. mypromptbox = {}
  96. mylayoutbox = {}
  97. mytaglist = {}
  98. mytaglist.buttons = awful.util.table.join(
  99. awful.button({ }, 1, awful.tag.viewonly),
  100. awful.button({ modkey }, 1, awful.client.movetotag),
  101. awful.button({ }, 3, awful.tag.viewtoggle),
  102. awful.button({ modkey }, 3, awful.client.toggletag),
  103. awful.button({ }, 4, awful.tag.viewnext),
  104. awful.button({ }, 5, awful.tag.viewprev)
  105. )
  106. mytasklist = {}
  107. mytasklist.buttons = awful.util.table.join(
  108. awful.button({ }, 1, function (c)
  109. if c == client.focus then
  110. c.minimized = true
  111. else
  112. if not c:isvisible() then
  113. awful.tag.viewonly(c:tags()[1])
  114. end
  115. -- This will also un-minimize
  116. -- the client, if needed
  117. client.focus = c
  118. c:raise()
  119. end
  120. end),
  121. awful.button({ }, 3, function ()
  122. if instance then
  123. instance:hide()
  124. instance = nil
  125. else
  126. instance = awful.menu.clients({ width=250 })
  127. end
  128. end),
  129. awful.button({ }, 4, function ()
  130. awful.client.focus.byidx(1)
  131. if client.focus then client.focus:raise() end
  132. end),
  133. awful.button({ }, 5, function ()
  134. awful.client.focus.byidx(-1)
  135. if client.focus then client.focus:raise() end
  136. end))
  137. for s = 1, screen.count() do
  138. -- Create a promptbox for each screen
  139. mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  140. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  141. -- We need one layoutbox per screen.
  142. mylayoutbox[s] = awful.widget.layoutbox(s)
  143. mylayoutbox[s]:buttons(awful.util.table.join(
  144. awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  145. awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  146. awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  147. awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  148. -- Create a taglist widget
  149. mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  150. -- Create a tasklist widget
  151. mytasklist[s] = awful.widget.tasklist(function(c)
  152. return awful.widget.tasklist.label.currenttags(c, s)
  153. end, mytasklist.buttons)
  154. -- Create the wibox
  155. mywibox[s] = awful.wibox({ position = "top", screen = s })
  156. -- Add widgets to the wibox - order matters
  157. mywibox[s].widgets = {
  158. {
  159. mylauncher,
  160. mytaglist[s],
  161. mypromptbox[s],
  162. layout = awful.widget.layout.horizontal.leftright
  163. },
  164. mylayoutbox[s],
  165. mytextclock,
  166. s == 1 and mysystray or nil,
  167. mytasklist[s],
  168. layout = awful.widget.layout.horizontal.rightleft
  169. }
  170. end
  171. -- }}}
  172. -- {{{ Mouse bindings
  173. root.buttons(awful.util.table.join(
  174. awful.button({ }, 3, function () mymainmenu:toggle() end),
  175. awful.button({ }, 4, awful.tag.viewnext),
  176. awful.button({ }, 5, awful.tag.viewprev)
  177. ))
  178. -- }}}
  179. -- {{{ Key bindings
  180. globalkeys = awful.util.table.join(
  181. awful.key({ modkey, }, "Left", awful.tag.viewprev ),
  182. awful.key({ modkey, }, "Right", awful.tag.viewnext ),
  183. awful.key({ modkey, }, "Escape", awful.tag.history.restore),
  184. awful.key({ modkey, }, "j",
  185. function ()
  186. awful.client.focus.byidx( 1)
  187. if client.focus then client.focus:raise() end
  188. end),
  189. awful.key({ modkey, }, "k",
  190. function ()
  191. awful.client.focus.byidx(-1)
  192. if client.focus then client.focus:raise() end
  193. end),
  194. awful.key({ modkey, }, "w", function () mymainmenu:show({keygrabber=true}) end),
  195. -- Layout manipulation
  196. awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
  197. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
  198. awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  199. awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  200. awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
  201. awful.key({ modkey, }, "Tab",
  202. function ()
  203. awful.client.focus.history.previous()
  204. if client.focus then
  205. client.focus:raise()
  206. end
  207. end),
  208. -- Standard program
  209. awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
  210. awful.key({ modkey, "Control" }, "r", awesome.restart),
  211. awful.key({ modkey, "Shift" }, "q", awesome.quit),
  212. awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  213. awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  214. awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  215. awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  216. awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
  217. awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
  218. awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
  219. awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
  220. awful.key({ modkey, "Control" }, "n", awful.client.restore),
  221. -- Prompt
  222. awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
  223. awful.key({ modkey }, "x",
  224. function ()
  225. awful.prompt.run({ prompt = "Run Lua code: " },
  226. mypromptbox[mouse.screen].widget,
  227. awful.util.eval, nil,
  228. awful.util.getdir("cache") .. "/history_eval")
  229. end)
  230. )
  231. clientkeys = awful.util.table.join(
  232. awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
  233. awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
  234. awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
  235. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  236. awful.key({ modkey, }, "o", awful.client.movetoscreen ),
  237. awful.key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
  238. awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
  239. awful.key({ modkey, }, "n",
  240. function (c)
  241. -- The client currently has the input focus, so it cannot be
  242. -- minimized, since minimized clients can't have the focus.
  243. c.minimized = true
  244. end),
  245. awful.key({ modkey, }, "m",
  246. function (c)
  247. c.maximized_horizontal = not c.maximized_horizontal
  248. c.maximized_vertical = not c.maximized_vertical
  249. end)
  250. )
  251. -- Compute the maximum number of digit we need, limited to 9
  252. keynumber = 0
  253. for s = 1, screen.count() do
  254. keynumber = math.min(9, math.max(#tags[s], keynumber));
  255. end
  256. -- Bind all key numbers to tags.
  257. -- Be careful: we use keycodes to make it works on any keyboard layout.
  258. -- This should map on the top row of your keyboard, usually 1 to 9.
  259. for i = 1, keynumber do
  260. globalkeys = awful.util.table.join(globalkeys,
  261. awful.key({ modkey }, "#" .. i + 9,
  262. function ()
  263. local screen = mouse.screen
  264. if tags[screen][i] then
  265. awful.tag.viewonly(tags[screen][i])
  266. end
  267. end),
  268. awful.key({ modkey, "Control" }, "#" .. i + 9,
  269. function ()
  270. local screen = mouse.screen
  271. if tags[screen][i] then
  272. awful.tag.viewtoggle(tags[screen][i])
  273. end
  274. end),
  275. awful.key({ modkey, "Shift" }, "#" .. i + 9,
  276. function ()
  277. if client.focus and tags[client.focus.screen][i] then
  278. awful.client.movetotag(tags[client.focus.screen][i])
  279. end
  280. end),
  281. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  282. function ()
  283. if client.focus and tags[client.focus.screen][i] then
  284. awful.client.toggletag(tags[client.focus.screen][i])
  285. end
  286. end))
  287. end
  288. clientbuttons = awful.util.table.join(
  289. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  290. awful.button({ modkey }, 1, awful.mouse.client.move),
  291. awful.button({ modkey }, 3, awful.mouse.client.resize))
  292. -- Set keys
  293. root.keys(globalkeys)
  294. -- }}}
  295. -- {{{ Rules
  296. awful.rules.rules = {
  297. -- All clients will match this rule.
  298. { rule = { },
  299. properties = { border_width = beautiful.border_width,
  300. border_color = beautiful.border_normal,
  301. focus = true,
  302. keys = clientkeys,
  303. buttons = clientbuttons } },
  304. { rule = { class = "MPlayer" },
  305. properties = { floating = true } },
  306. { rule = { class = "pinentry" },
  307. properties = { floating = true } },
  308. { rule = { class = "gimp" },
  309. properties = { floating = true } },
  310. -- Set Firefox to always map on tags number 2 of screen 1.
  311. -- { rule = { class = "Firefox" },
  312. -- properties = { tag = tags[1][2] } },
  313. }
  314. -- }}}
  315. -- {{{ Signals
  316. -- Signal function to execute when a new client appears.
  317. client.add_signal("manage", function (c, startup)
  318. -- Add a titlebar
  319. -- awful.titlebar.add(c, { modkey = modkey })
  320. -- Enable sloppy focus
  321. c:add_signal("mouse::enter", function(c)
  322. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  323. and awful.client.focus.filter(c) then
  324. client.focus = c
  325. end
  326. end)
  327. if not startup then
  328. -- Set the windows at the slave,
  329. -- i.e. put it at the end of others instead of setting it master.
  330. -- awful.client.setslave(c)
  331. -- Put windows in a smart way, only if they does not set an initial position.
  332. if not c.size_hints.user_position and not c.size_hints.program_position then
  333. awful.placement.no_overlap(c)
  334. awful.placement.no_offscreen(c)
  335. end
  336. end
  337. end)
  338. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  339. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  340. -- }}}