Advertisement
Guest User

Untitled

a guest
Oct 11th, 2010
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.72 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. require("vicious")
  10.  
  11. -- Functions
  12.  
  13. -- Amixer Widget
  14.  
  15. cardid = 0
  16. channel = "Master"
  17. function volume (mode, widget)
  18. if mode == "update" then
  19. local fd = io.popen("amixer -c " .. cardid .. " -- sget " .. channel)
  20. local status = fd:read("*all")
  21. fd:close()
  22.  
  23. local volume = string.match(status, "(%d?%d?%d)%%")
  24. volume = string.format("% 3d", volume)
  25.  
  26. status = string.match(status, "%[(o[^%]]*)%]")
  27.  
  28. if string.find(status, "on", 1, true) then
  29. volume = volume .. "%"
  30. else
  31. volume = volume .. "M"
  32. end
  33. widget.text = " vol" .. volume
  34. elseif mode == "up" then
  35. io.popen("amixer -q -c " .. cardid .. " sset " .. channel .. " 5%+"):read("*all")
  36. volume("update", widget)
  37. elseif mode == "down" then
  38. io.popen("amixer -q -c " .. cardid .. " sset " .. channel .. " 5%-"):read("*all")
  39. volume("update", widget)
  40. else
  41. io.popen("amixer -c " .. cardid .. " sset " .. channel .. " toggle"):read("*all")
  42. volume("update", widget)
  43. end
  44. end
  45.  
  46.  
  47. -- moc player
  48.  
  49. function hook_moc()
  50. moc_info = io.popen("mocp -i"):read("*all")
  51. moc_state = string.gsub(string.match(moc_info, "State: %a*"),"State: ","")
  52. if moc_state == "PLAY" or moc_state == "PAUSE" then
  53. moc_artist = string.gsub(string.match(moc_info, "Artist: %C*"), "Artist: ","")
  54. moc_title = string.gsub(string.match(moc_info, "SongTitle: %C*"), "SongTitle: ","")
  55. moc_curtime = string.gsub(string.match(moc_info, "CurrentTime: %d*:%d*"), "CurrentTime: ","")
  56. moc_totaltime = string.gsub(string.match(moc_info, "TotalTime: %d*:%d*"), "TotalTime: ","")
  57. if moc_artist == "" then
  58. moc_artist = "unknown artist"
  59. end
  60. if moc_title == "" then
  61. moc_title = "unknown title"
  62. end
  63. moc_string = "MOC: " .. moc_artist .. " - " .. moc_title .. "(" .. moc_curtime .. "/" .. moc_totaltime .. ")"
  64. if moc_state == "PAUSE" then
  65. moc_string = " [[ " .. moc_string .. " ]]"
  66. end
  67. else
  68. moc_string = "-- MOC not playing --"
  69. end
  70. tb_moc.text = moc_string
  71. end
  72.  
  73. function pause_moc()
  74. moc_info = io.popen("mocp -i"):read("*all")
  75. moc_state = string.gsub(string.match(moc_info, "State: %a*"),"State: ","")
  76. if moc_state == "PLAY" then
  77. io.popen("mocp -P")
  78. elseif moc_state == "PAUSE" then
  79. io.popen("mocp -U")
  80. end
  81. end
  82.  
  83.  
  84.  
  85.  
  86. -- {{{ Variable definitions
  87. -- Themes define colours, icons, and wallpapers
  88. beautiful.init("/home/garrik/.config/awesome/theme/floating.lua")
  89.  
  90. -- This is used later as the default terminal and editor to run.
  91. terminal = "urxvt -g 80x28"
  92. editor = os.getenv("EDITOR") or "vim"
  93. editor_cmd = terminal .. " -e " .. editor
  94.  
  95. -- Default modkey.
  96. -- Usually, Mod4 is the key with a logo between Control and Alt.
  97. -- If you do not like this or do not have such a key,
  98. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  99. -- However, you can use another modifier like Mod1, but it may interact with others.
  100. modkey = "Mod4"
  101.  
  102. -- Table of layouts to cover with awful.layout.inc, order matters.
  103. layouts =
  104. {
  105. awful.layout.suit.floating,
  106. awful.layout.suit.tile,
  107. awful.layout.suit.tile.left,
  108. awful.layout.suit.tile.bottom,
  109. awful.layout.suit.tile.top,
  110. awful.layout.suit.fair,
  111. awful.layout.suit.fair.horizontal,
  112. awful.layout.suit.spiral,
  113. awful.layout.suit.spiral.dwindle,
  114. awful.layout.suit.max.fullscreen,
  115. awful.layout.suit.magnifier,
  116. awful.layout.suit.max
  117. }
  118. -- }}}
  119.  
  120. -- {{{ Tags
  121. -- Define a tag table which hold all screen tags.
  122. tags = {}
  123. for s = 1, screen.count() do
  124. -- Each screen has its own tag table.
  125. tags[s] = awful.tag({ "1 main", "2 mail", "3 www", "4 chat", "5 xfe", "6 off", "7 adm", "8 dev", "9 misc" }, s, layouts[1])
  126. end
  127. -- }}}
  128.  
  129. -- {{{ Menu
  130. -- Create a laucher widget and a main menu
  131. myawesomemenu = {
  132. { "manual", terminal .. " -e man awesome" },
  133. { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
  134. { "restart", awesome.restart },
  135. { "quit", awesome.quit }
  136. }
  137.  
  138. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  139. { "open terminal", terminal }
  140. }
  141. })
  142.  
  143. mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
  144. menu = mymainmenu })
  145. -- }}}
  146.  
  147. -- {{{ Wibox
  148. -- Create a textclock widget
  149. mytextclock = awful.widget.textclock({ align = "right" })
  150.  
  151. -- Create a systray
  152. mysystray = widget({ type = "systray" })
  153.  
  154. -- Create a wibox for each screen and add it
  155. mywibox = {}
  156. mywibox2 = {}
  157. mypromptbox = {}
  158. mylayoutbox = {}
  159. mytaglist = {}
  160. mytaglist.buttons = awful.util.table.join(
  161. awful.button({ }, 1, awful.tag.viewonly),
  162. awful.button({ modkey }, 1, awful.client.movetotag),
  163. awful.button({ }, 3, awful.tag.viewtoggle),
  164. awful.button({ modkey }, 3, awful.client.toggletag),
  165. awful.button({ }, 4, awful.tag.viewnext),
  166. awful.button({ }, 5, awful.tag.viewprev)
  167. )
  168. mytasklist = {}
  169. mytasklist.buttons = awful.util.table.join(
  170. awful.button({ }, 1, function (c)
  171. if not c:isvisible() then
  172. awful.tag.viewonly(c:tags()[1])
  173. end
  174. client.focus = c
  175. c:raise()
  176. end),
  177. awful.button({ }, 3, function ()
  178. if instance then
  179. instance:hide()
  180. instance = nil
  181. else
  182. instance = awful.menu.clients({ width=250 })
  183. end
  184. end),
  185. awful.button({ }, 4, function ()
  186. awful.client.focus.byidx(1)
  187. if client.focus then client.focus:raise() end
  188. end),
  189. awful.button({ }, 5, function ()
  190. awful.client.focus.byidx(-1)
  191. if client.focus then client.focus:raise() end
  192. end))
  193.  
  194. for s = 1, screen.count() do
  195. -- Create a promptbox for each screen
  196. mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  197. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  198. -- We need one layoutbox per screen.
  199. mylayoutbox[s] = awful.widget.layoutbox(s)
  200. mylayoutbox[s]:buttons(awful.util.table.join(
  201. awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  202. awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  203. awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  204. awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  205. -- Create a taglist widget
  206. mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  207.  
  208. -- Create a tasklist widget
  209. mytasklist[s] = awful.widget.tasklist(function(c)
  210. return awful.widget.tasklist.label.currenttags(c, s)
  211. end, mytasklist.buttons)
  212.  
  213. -- amixer widget
  214.  
  215. tb_volume = widget({ type = "textbox", name = "tb_volume", align = "right" })
  216. tb_volume:buttons(awful.util.table.join(
  217. awful.button({ }, 4, function () volume("up", tb_volume) end),
  218. awful.button({ }, 5, function () volume("down", tb_volume) end),
  219. awful.button({ }, 1, function () volume("mute", tb_volume) end)))
  220. volume("update", tb_volume)
  221.  
  222. -- moc widget
  223. tb_moc = widget({ type = "textbox", name = "tb_moc", align = "right" })
  224. tb_moc:buttons(awful.util.table.join(awful.button({ }, 1, function () pause_moc() end)))
  225.  
  226. -- cpu widget
  227. cpuwidget = widget({ type = "textbox" })
  228. -- Register widget
  229. vicious.register(cpuwidget, vicious.widgets.cpu, "CPU0 $2% CPU1 $3% ", 3)
  230.  
  231. -- mem text
  232. memtext = widget({ type = "textbox" })
  233. -- Register widget
  234. vicious.register(memtext, vicious.widgets.mem, " MEM : $1% ($2MB/$3MB)", 20)
  235.  
  236. -- fs text
  237. fswidget = widget({type = "textbox" })
  238. vicious.register(fswidget, vicious.widgets.fs, " FS: / : ${/ used_gb}/${/ size_gb} /donnees : ${/donnees used_gb}/${/donnees size_gb} ",30)
  239.  
  240. --blank widget
  241. blankwg = widget({type = "textbox" })
  242. blankwg.text = " "
  243.  
  244. -- Create the top wibox
  245. mywibox[s] = awful.wibox({ position = "top", screen = s })
  246. -- Add widgets to the wibox
  247. mywibox[s].widgets = {
  248. {
  249. mylauncher,
  250. mytaglist[s],
  251. mypromptbox[s],
  252. layout = awful.widget.layout.horizontal.leftright
  253. },
  254. mylayoutbox[s],
  255. s == 1 and mysystray or nil,
  256. mytasklist[s],
  257. layout = awful.widget.layout.horizontal.rightleft
  258. }
  259.  
  260. -- Create the bottom wibox
  261. mywibox2[s] = awful.wibox({ position = "bottom", screen = s })
  262. -- Add widgets to the wibox
  263. mywibox2[s].widgets = {
  264. {
  265. tb_volume,
  266. memtext,
  267. fswidget,
  268. layout = awful.widget.layout.horizontal.leftright
  269. },
  270. mytextclock,
  271. blankwg,
  272. tb_moc,
  273. cpuwidget,
  274. layout = awful.widget.layout.horizontal.rightleft
  275. }
  276. end
  277. -- }}}
  278.  
  279. -- {{{ Mouse bindings
  280. root.buttons(awful.util.table.join(
  281. awful.button({ }, 3, function () mymainmenu:toggle() end),
  282. awful.button({ }, 4, awful.tag.viewnext),
  283. awful.button({ }, 5, awful.tag.viewprev)
  284. ))
  285. -- }}}
  286.  
  287. -- {{{ Key bindings
  288. globalkeys = awful.util.table.join(
  289. awful.key({ modkey, }, "Left", awful.tag.viewprev ),
  290. awful.key({ modkey, }, "Right", awful.tag.viewnext ),
  291. awful.key({ modkey, }, "Escape", awful.tag.history.restore),
  292.  
  293. awful.key({ modkey, }, "Tab",
  294. function ()
  295. awful.client.focus.byidx( 1)
  296. if client.focus then client.focus:raise() end
  297. end),
  298. awful.key({ modkey, }, "k",
  299. function ()
  300. awful.client.focus.byidx(-1)
  301. if client.focus then client.focus:raise() end
  302. end),
  303. awful.key({ modkey, }, "w", function () mymainmenu:show({keygrabber=true}) end),
  304.  
  305. -- Layout manipulation
  306. awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
  307. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
  308. awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  309. awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  310. awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
  311. awful.key({ modkey, }, "j",
  312. function ()
  313. awful.client.focus.history.previous()
  314. if client.focus then
  315. client.focus:raise()
  316. end
  317. end),
  318.  
  319. -- Standard program
  320. awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
  321. awful.key({ modkey, "Control" }, "r", awesome.restart),
  322. awful.key({ modkey, "Shift" }, "q", awesome.quit),
  323.  
  324. awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  325. awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  326. awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  327. awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  328. awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
  329. awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
  330. awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
  331. awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
  332.  
  333. -- Prompt
  334. awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
  335.  
  336. awful.key({ modkey }, "x",
  337. function ()
  338. awful.prompt.run({ prompt = "Run Lua code: " },
  339. mypromptbox[mouse.screen].widget,
  340. awful.util.eval, nil,
  341. awful.util.getdir("cache") .. "/history_eval")
  342. end),
  343.  
  344. awful.key({modkey}, "F1", function () awful.util.spawn("claws-mail") awful.util.spawn("liferea") awful.util.spawn("chromium") awful.util.spawn("kvirc") awful.util.spawn("xfe") end),
  345. awful.key({modkey}, "F2", function () awful.util.spawn("claws-mail") end),
  346. awful.key({modkey}, "F6", function () awful.util.spawn("emesene") end),
  347. awful.key({modkey}, "F8", function () awful.util.spawn("liferea") end),
  348. awful.key({modkey}, "F3", function () awful.util.spawn("chromium") end),
  349. awful.key({modkey}, "F4", function () awful.util.spawn("kvirc") end),
  350. awful.key({modkey}, "F5", function () awful.util.spawn("xfe") end),
  351. awful.key({modkey}, "F7", function () awful.util.spawn("soffice") end)
  352.  
  353. )
  354.  
  355.  
  356. clientkeys = awful.util.table.join(
  357. awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
  358. awful.key({ modkey, }, "c", function (c) c:kill() end),
  359. awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
  360. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  361. awful.key({ modkey, }, "o", awful.client.movetoscreen ),
  362. awful.key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
  363. awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
  364. awful.key({ modkey, }, "n", function (c) c.minimized = not c.minimized end),
  365. awful.key({ modkey, }, "m",
  366. function (c)
  367. c.maximized_horizontal = not c.maximized_horizontal
  368. c.maximized_vertical = not c.maximized_vertical
  369. end)
  370. )
  371.  
  372. -- Compute the maximum number of digit we need, limited to 9
  373. keynumber = 0
  374. for s = 1, screen.count() do
  375. keynumber = math.min(9, math.max(#tags[s], keynumber));
  376. end
  377.  
  378. -- Bind all key numbers to tags.
  379. -- Be careful: we use keycodes to make it works on any keyboard layout.
  380. -- This should map on the top row of your keyboard, usually 1 to 9.
  381. for i = 1, keynumber do
  382. globalkeys = awful.util.table.join(globalkeys,
  383. awful.key({ modkey }, "#" .. i + 9,
  384. function ()
  385. local screen = mouse.screen
  386. if tags[screen][i] then
  387. awful.tag.viewonly(tags[screen][i])
  388. end
  389. end),
  390. awful.key({ modkey, "Control" }, "#" .. i + 9,
  391. function ()
  392. local screen = mouse.screen
  393. if tags[screen][i] then
  394. awful.tag.viewtoggle(tags[screen][i])
  395. end
  396. end),
  397. awful.key({ modkey, "Shift" }, "#" .. i + 9,
  398. function ()
  399. if client.focus and tags[client.focus.screen][i] then
  400. awful.client.movetotag(tags[client.focus.screen][i])
  401. end
  402. end),
  403. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  404. function ()
  405. if client.focus and tags[client.focus.screen][i] then
  406. awful.client.toggletag(tags[client.focus.screen][i])
  407. end
  408. end))
  409. end
  410.  
  411. clientbuttons = awful.util.table.join(
  412. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  413. awful.button({ modkey }, 1, awful.mouse.client.move),
  414. awful.button({ modkey }, 3, awful.mouse.client.resize))
  415.  
  416. -- Set keys
  417. root.keys(globalkeys)
  418. -- }}}
  419.  
  420. -- {{{ Rules
  421. awful.rules.rules = {
  422. -- All clients will match this rule.
  423. { rule = { },
  424. properties = { border_width = beautiful.border_width,
  425. border_color = beautiful.border_normal,
  426. focus = true,
  427. keys = clientkeys,
  428. buttons = clientbuttons,
  429. size_hints_honor = false } },
  430. { rule = { class = "MPlayer" },
  431. properties = { floating = true } },
  432. { rule = { class = "pinentry" },
  433. properties = { floating = true } },
  434. { rule = { class = "gimp" },
  435. properties = { floating = true } },
  436. { rule = { class = "wesnoth" },
  437. properties = { floating = true } },
  438. { rule = { class = "Pidgin" },
  439. properties = { floating = true, tag=tags[1][2] } },
  440. { rule = { class = "Chromium" },
  441. properties = { floating = true, tag=tags[1][3] } },
  442. { rule = { class = "Namoroka" },
  443. properties = { floating = true } },
  444. { rule = { class = "Kvirc" },
  445. properties = { tag=tags[1][4] } },
  446. { rule = { class = "Claws-mail" },
  447. properties = { tag=tags[1][2] } },
  448. { rule = { class = "Xfe" },
  449. properties = { tag=tags[1][5] } },
  450. { rule = { class = "Liferea" },
  451. properties = { tag=tags[1][3] } },
  452.  
  453. }
  454. -- }}}
  455.  
  456. -- {{{ Signals
  457. -- Signal function to execute when a new client appears.
  458. client.add_signal("manage", function (c, startup)
  459. -- Add a titlebar
  460. -- awful.titlebar.add(c, { modkey = modkey })
  461.  
  462. -- Enable sloppy focus
  463. c:add_signal("mouse::enter", function(c)
  464. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  465. and awful.client.focus.filter(c) then
  466. client.focus = c
  467. end
  468. end)
  469.  
  470. if not startup then
  471. -- Set the windows at the slave,
  472. -- i.e. put it at the end of others instead of setting it master.
  473. -- awful.client.setslave(c)
  474.  
  475. -- Put windows in a smart way, only if they does not set an initial position.
  476. if not c.size_hints.user_position and not c.size_hints.program_position then
  477. awful.placement.no_overlap(c)
  478. awful.placement.no_offscreen(c)
  479. end
  480. end
  481. end)
  482.  
  483. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  484. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  485.  
  486. -- Moc widget timer
  487.  
  488. mytimermoc = timer { timeout = 1 }
  489. mytimermoc:add_signal("timeout", function() hook_moc() end)
  490. mytimermoc:start()
  491.  
  492. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement