Advertisement
Guest User

rc.lua

a guest
Sep 4th, 2010
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.57 KB | None | 0 0
  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. --Wiget Library
  10. require("vicious")
  11.  
  12. -- {{{ Variable definitions
  13. -- Themes define colours, icons, and wallpapers
  14. beautiful.init("/home/him/.config/awesome/default/theme.lua")
  15.  
  16. -- This is used later as the default terminal and editor to run.
  17. terminal = "urxvt"
  18. editor = os.getenv("EDITOR") or "nano"
  19. editor_cmd = terminal .. " -e " .. editor
  20.  
  21. -- Default modkey.
  22. -- Usually, Mod4 is the key with a logo between Control and Alt.
  23. -- If you do not like this or do not have such a key,
  24. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  25. -- However, you can use another modifier like Mod1, but it may interact with others.
  26. modkey = "Mod4"
  27.  
  28. -- Table of layouts to cover with awful.layout.inc, order matters.
  29. layouts =
  30. {
  31. awful.layout.suit.tile,
  32. awful.layout.suit.tile.left,
  33. awful.layout.suit.tile.bottom,
  34. awful.layout.suit.tile.top,
  35. awful.layout.suit.fair,
  36. awful.layout.suit.fair.horizontal,
  37. awful.layout.suit.magnifier,
  38. awful.layout.suit.floating
  39. }
  40. -- }}}
  41.  
  42. -- {{{ Tags
  43. -- Define a tag table which will hold all screen tags.
  44. tags = {
  45. names = { "Term", "Web", "Dev", "Var"},
  46. layout = { layouts[1], layouts[1], layouts[1], layouts[1]
  47. }}
  48. for s = 1, screen.count() do
  49. tags[s] = awful.tag(tags.names, s, tags.layout)
  50. end
  51. -- }}}
  52.  
  53. -- {{{ Menu
  54. -- Create a laucher widget and a main menu
  55. myawesomemenu = {
  56. { "manual", terminal .. " -e man awesome" },
  57. { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
  58. { "restart", awesome.restart },
  59. { "quit", awesome.quit }
  60. }
  61.  
  62. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  63. { "open terminal", terminal }
  64. }
  65. })
  66.  
  67. mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
  68. menu = mymainmenu })
  69. -- }}}
  70.  
  71. -- Separators
  72.  
  73. spacer = widget({ type = "textbox" })
  74. seperator = widget({ type = "textbox" })
  75. dash = widget({ type = "textbox" })
  76. spacer.text = " "
  77. seperator.text = "|"
  78. dash.text = "-"
  79.  
  80. -- {{{ Wibox
  81.  
  82. --Create a Volume Widget
  83. volicon = widget({ type = "imagebox" })
  84. volicon.image = image("/home/him/images/icons/awesome/vol.png")
  85. --Initialize widget
  86. volbar = awful.widget.progressbar()
  87. --Progressbar settings
  88. volbar:set_width(8)
  89. volbar:set_height(18)
  90. volbar:set_vertical(true)
  91. volbar:set_ticks(true)
  92. volbar:set_ticks_gap(1)
  93. volbar:set_ticks_size(2)
  94. volbar:set_background_color("#000000")
  95. volbar:set_border_color("#000000")
  96. volbar:set_color("#D9D9D9")
  97. volbar:set_gradient_colors({ "#D9D9D9", "#D9D9D9", "#D9D9D9" })
  98. --Register widget
  99. vicious.register(volbar, vicious.widgets.volume, "$1", 2, "Master")
  100.  
  101. -- MPD Widget
  102. mpdicon = widget({ type = "imagebox" })
  103. mpdicon.image = image("/home/him/images/icons/awesome/mpd.png")
  104. -- Initialize widget
  105. mpdwidget = widget({ type = "textbox" })
  106. -- Register Widget
  107. vicious.register(mpdwidget, vicious.widgets.mpd, "${Title}, ${Artist}", 13)
  108.  
  109. -- Wifiwidget
  110. wifiwidget = widget({ type = "textbox" })
  111. -- Register Widget
  112. vicious.register(wifiwidget, vicious.widgets.wifi, "~ ${link}%", 5, "eth1")
  113.  
  114. --Seperator
  115. spicon = widget({ type = "imagebox" })
  116. spicon.image = image("/home/him/images/icons/awesome/separator.png")
  117.  
  118. -- Create a netwidget (usage)
  119. dnicon = widget({ type = "imagebox" })
  120. upicon = widget({ type = "imagebox" })
  121. dnicon.image = image("/home/him/images/icons/awesome/down.png")
  122. upicon.image = image("/home/him/images/icons/awesome/up.png")
  123. -- Initialize widget
  124. netwidget = widget({ type = "textbox" })
  125. -- Register widget
  126. vicious.register(netwidget, vicious.widgets.net, "${eth1 down_kb}kb/s / ${eth1 up_kb}kb/s", 1)
  127.  
  128. -- Create a battery widget
  129. baticon = widget({ type = "imagebox" })
  130. baticon.image = image("/home/him/images/icons/awesome/bat.png")
  131. --Initialize widget
  132. batwidget = widget({ type = "textbox" })
  133. --Register widget
  134. vicious.register(batwidget, vicious.widgets.bat, "$1$2%", 31, "BAT1")
  135.  
  136. --Create a cpuwidget
  137. cpuicon = widget({ type = "imagebox" })
  138. cpuicon.image = image("/home/him/images/icons/awesome/cpuinfo.png")
  139. --Initialize widget
  140. cpuwidget = widget({ type = "textbox" })
  141. --Register widget
  142. vicious.register(cpuwidget, vicious.widgets.cpu, "$1%", 2)
  143. -- Create a textclock widget
  144. mytextclock = awful.widget.textclock({ align = "right" })
  145.  
  146. -- Create a systray
  147. mysystray = widget({ type = "systray" })
  148.  
  149. -- Create a wibox for each screen and add it
  150. mywibox = {}
  151. mypromptbox = {}
  152. mylayoutbox = {}
  153. mytaglist = {}
  154. mytaglist.buttons = awful.util.table.join(
  155. awful.button({ }, 1, awful.tag.viewonly),
  156. awful.button({ modkey }, 1, awful.client.movetotag),
  157. awful.button({ }, 3, awful.tag.viewtoggle),
  158. awful.button({ modkey }, 3, awful.client.toggletag),
  159. awful.button({ }, 4, awful.tag.viewnext),
  160. awful.button({ }, 5, awful.tag.viewprev)
  161. )
  162. mytasklist = {}
  163. mytasklist.buttons = awful.util.table.join(
  164. awful.button({ }, 1, function (c)
  165. if not c:isvisible() then
  166. awful.tag.viewonly(c:tags()[1])
  167. end
  168. client.focus = c
  169. c:raise()
  170. end),
  171. awful.button({ }, 3, function ()
  172. if instance then
  173. instance:hide()
  174. instance = nil
  175. else
  176. instance = awful.menu.clients({ width=250 })
  177. end
  178. end),
  179. awful.button({ }, 4, function ()
  180. awful.client.focus.byidx(1)
  181. if client.focus then client.focus:raise() end
  182. end),
  183. awful.button({ }, 5, function ()
  184. awful.client.focus.byidx(-1)
  185. if client.focus then client.focus:raise() end
  186. end))
  187.  
  188. for s = 1, screen.count() do
  189. -- Create a promptbox for each screen
  190. mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  191. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  192. -- We need one layoutbox per screen.
  193. mylayoutbox[s] = awful.widget.layoutbox(s)
  194. mylayoutbox[s]:buttons(awful.util.table.join(
  195. awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  196. awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  197. awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  198. awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  199. -- Create a taglist widget
  200. mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  201.  
  202. -- Create a tasklist widget
  203. mytasklist[s] = awful.widget.tasklist(function(c)
  204. return awful.widget.tasklist.label.currenttags(c, s)
  205. end, mytasklist.buttons)
  206.  
  207. -- Create the wibox
  208. mywibox[s] = awful.wibox({ position = "top", screen = s })
  209. -- Add widgets to the wibox - order matters
  210. mywibox[s].widgets = {
  211. {
  212. mytaglist[s], spacer, mpdicon, mpdwidget, spacer,
  213. -- mytaglist[s], spacer,
  214. mypromptbox[s],
  215. layout = awful.widget.layout.horizontal.leftright
  216. },
  217. --mylayoutbox[s],
  218. s == 1 and mysystray or nil, mytextclock,
  219. seperator, spacer, cpuwidget, spacer, cpuicon, spacer, seperator, upicon, netwidget, dnicon, seperator, spacer, wifiwidget, spacer, seperator, spacer,
  220. batwidget, spacer, baticon, seperator, spacer, volbar.widget, volicon,
  221. layout = awful.widget.layout.horizontal.rightleft
  222. }
  223. end
  224. -- }}}
  225.  
  226. -- {{{ Mouse bindings
  227. root.buttons(awful.util.table.join(
  228. awful.button({ }, 3, function () mymainmenu:toggle() end),
  229. awful.button({ }, 4, awful.tag.viewnext),
  230. awful.button({ }, 5, awful.tag.viewprev)
  231. ))
  232. -- }}}
  233.  
  234. -- {{{ Key bindings
  235. globalkeys = awful.util.table.join(
  236. awful.key({ modkey, }, "Left", awful.tag.viewprev ),
  237. awful.key({ modkey, }, "Right", awful.tag.viewnext ),
  238. awful.key({ modkey, }, "Escape", awful.tag.history.restore),
  239.  
  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.  
  252. --Volume manipulation
  253. awful.key({ }, "XF86AudioRaiseVolume", function () awful.util.spawn("amixer set Master 5+") end),
  254. awful.key({ }, "XF86AudioLowerVolume", function () awful.util.spawn("amixer set Master 5-") end),
  255.  
  256. -- Layout manipulation
  257. awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
  258. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
  259. awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  260. awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  261. awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
  262. awful.key({ modkey, }, "Tab",
  263. function ()
  264. awful.client.focus.history.previous()
  265. if client.focus then
  266. client.focus:raise()
  267. end
  268. end),
  269.  
  270. -- Standard program
  271. awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
  272. awful.key({ modkey, "Control" }, "r", awesome.restart),
  273. awful.key({ modkey, "Shift" }, "q", awesome.quit),
  274.  
  275. awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  276. awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  277. awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  278. awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  279. awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
  280. awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
  281. awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
  282. awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
  283.  
  284. -- Prompt
  285. awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
  286.  
  287. awful.key({ modkey }, "x",
  288. function ()
  289. awful.prompt.run({ prompt = "Run Lua code: " },
  290. mypromptbox[mouse.screen].widget,
  291. awful.util.eval, nil,
  292. awful.util.getdir("cache") .. "/history_eval")
  293. end)
  294. )
  295.  
  296. clientkeys = awful.util.table.join(
  297. awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
  298. awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
  299. awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
  300. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  301. awful.key({ modkey, }, "o", awful.client.movetoscreen ),
  302. awful.key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
  303. awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
  304. awful.key({ modkey, }, "n", function (c) c.minimized = not c.minimized end),
  305. awful.key({ modkey, }, "m",
  306. function (c)
  307. c.maximized_horizontal = not c.maximized_horizontal
  308. c.maximized_vertical = not c.maximized_vertical
  309. end)
  310. )
  311.  
  312. -- Compute the maximum number of digit we need, limited to 9
  313. keynumber = 0
  314. for s = 1, screen.count() do
  315. keynumber = math.min(9, math.max(#tags[s], keynumber));
  316. end
  317.  
  318. -- Bind all key numbers to tags.
  319. -- Be careful: we use keycodes to make it works on any keyboard layout.
  320. -- This should map on the top row of your keyboard, usually 1 to 9.
  321. for i = 1, keynumber do
  322. globalkeys = awful.util.table.join(globalkeys,
  323. awful.key({ modkey }, "#" .. i + 9,
  324. function ()
  325. local screen = mouse.screen
  326. if tags[screen][i] then
  327. awful.tag.viewonly(tags[screen][i])
  328. end
  329. end),
  330. awful.key({ modkey, "Control" }, "#" .. i + 9,
  331. function ()
  332. local screen = mouse.screen
  333. if tags[screen][i] then
  334. awful.tag.viewtoggle(tags[screen][i])
  335. end
  336. end),
  337. awful.key({ modkey, "Shift" }, "#" .. i + 9,
  338. function ()
  339. if client.focus and tags[client.focus.screen][i] then
  340. awful.client.movetotag(tags[client.focus.screen][i])
  341. end
  342. end),
  343. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  344. function ()
  345. if client.focus and tags[client.focus.screen][i] then
  346. awful.client.toggletag(tags[client.focus.screen][i])
  347. end
  348. end))
  349. end
  350.  
  351. clientbuttons = awful.util.table.join(
  352. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  353. awful.button({ modkey }, 1, awful.mouse.client.move),
  354. awful.button({ modkey }, 3, awful.mouse.client.resize))
  355.  
  356. -- Set keys
  357. root.keys(globalkeys)
  358. -- }}}
  359.  
  360. -- {{{ Rules
  361. awful.rules.rules = {
  362. -- All clients will match this rule.
  363. { rule = { },
  364. properties = { border_width = beautiful.border_width,
  365. border_color = beautiful.border_normal,
  366. focus = true,
  367. keys = clientkeys,
  368. buttons = clientbuttons } },
  369. { rule = { class = "MPlayer" },
  370. properties = { floating = true } },
  371. { rule = { class = "pinentry" },
  372. properties = { floating = true } },
  373. { rule = { class = "gimp" },
  374. properties = { floating = true } },
  375. -- Set Firefox to always map on tags number 2 of screen 1.
  376. -- { rule = { class = "Firefox" },
  377. -- properties = { tag = tags[1][2] } },
  378. }
  379. -- }}}
  380.  
  381. -- {{{ Signals
  382. -- Signal function to execute when a new client appears.
  383. client.add_signal("manage", function (c, startup)
  384. -- Add a titlebar
  385. -- awful.titlebar.add(c, { modkey = modkey })
  386.  
  387. -- Enable sloppy focus
  388. c:add_signal("mouse::enter", function(c)
  389. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  390. and awful.client.focus.filter(c) then
  391. client.focus = c
  392. end
  393. end)
  394.  
  395. if not startup then
  396. -- Set the windows at the slave,
  397. -- i.e. put it at the end of others instead of setting it master.
  398. -- awful.client.setslave(c)
  399.  
  400. -- Put windows in a smart way, only if they does not set an initial position.
  401. if not c.size_hints.user_position and not c.size_hints.program_position then
  402. awful.placement.no_overlap(c)
  403. awful.placement.no_offscreen(c)
  404. end
  405. end
  406. end)
  407.  
  408. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  409. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  410. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement