Advertisement
mrneilypops

awesome copycat rainbow rc.lua config

Aug 2nd, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.80 KB | None | 0 0
  1. --[[ ]]--
  2. -- -
  3. -- Rainbow Awesome WM 3.5.+ config --
  4. -- github.com/copycat-killer --
  5. -- -
  6. --[[ ]]--
  7.  
  8.  
  9. -- {{{ Required Libraries
  10.  
  11. local gears = require("gears")
  12. local awful = require("awful")
  13. awful.rules = require("awful.rules")
  14. awful.autofocus = require("awful.autofocus")
  15. local wibox = require("wibox")
  16. local beautiful = require("beautiful")
  17. local naughty = require("naughty")
  18. local vicious = require("vicious")
  19. local scratch = require("scratch")
  20. local yawn = require("yawn")
  21. local layouts = require("layouts")
  22.  
  23. -- }}}
  24.  
  25. -- {{{ Autostart applications
  26.  
  27. function run_once(cmd)
  28. findme = cmd
  29. firstspace = cmd:find(" ")
  30. if firstspace then
  31. findme = cmd:sub(0, firstspace-1)
  32. end
  33. awful.util.spawn_with_shell("pgrep -u $USER -x " .. findme .. " > /dev/null || (" .. cmd .. ")")
  34. end
  35.  
  36. run_once("urxvtd")
  37. run_once("unclutter -idle 10")
  38. run_once("compton")
  39.  
  40. -- }}}
  41.  
  42. -- {{{ Localization
  43.  
  44. os.setlocale(os.getenv("LANG"))
  45.  
  46. -- }}}
  47.  
  48. -- {{{ Error Handling
  49.  
  50. -- Check if awesome encountered an error during startup and fell back to
  51. -- another config (This code will only ever execute for the fallback config)
  52. if awesome.startup_errors then
  53. naughty.notify({ preset = naughty.config.presets.critical,
  54. title = "Oops, there were errors during startup!",
  55. text = awesome.startup_errors })
  56. end
  57.  
  58. -- Handle runtime errors after startup
  59. do
  60. local in_error = false
  61. awesome.connect_signal("debug::error", function (err)
  62. -- Make sure we don't go into an endless error loop
  63. if in_error then return end
  64. in_error = true
  65.  
  66. naughty.notify({ preset = naughty.config.presets.critical,
  67. title = "Oops, an error happened!",
  68. text = err })
  69. local in_error = false
  70. end)
  71. end
  72.  
  73. -- }}}
  74.  
  75. -- {{{ Global variables
  76.  
  77. home = os.getenv("HOME")
  78. confdir = home .. "/.config/awesome"
  79. scriptdir = confdir .. "/scripts/"
  80. themes = confdir .. "/themes"
  81. active_theme = themes .. "/rainbow"
  82. language = string.gsub(os.getenv("LANG"), ".utf8", "")
  83.  
  84. beautiful.init(active_theme .. "/theme.lua")
  85.  
  86. terminal = "urxvtc"
  87. editor = os.getenv("EDITOR")
  88. --editor_cmd = terminal .. " -e " .. editor
  89. gui_editor = "gvim"
  90. browser = "dwb"
  91. graphics = "gimp"
  92. mail = terminal .. " -e mutt "
  93. wifi = terminal .. " -e sudo wifi-menu "
  94. musicplr = terminal .. " -g 130x34-320+16 -e ncmpcpp "
  95.  
  96. modkey = "Mod1"
  97. altkey = "Mod1"
  98.  
  99. layouts =
  100. {
  101. awful.layout.suit.floating, -- 1
  102. awful.layout.suit.tile, -- 2
  103. awful.layout.suit.fair, -- 3
  104. awful.layout.suit.tile.bottom, -- 4
  105. awful.layout.suit.fair.horizontal, -- 5
  106. layouts.tilegaps, -- 6
  107. }
  108.  
  109. -- }}}
  110.  
  111. -- {{{ Wallpaper
  112.  
  113. if beautiful.wallpaper then
  114. for s = 1, screen.count() do
  115. gears.wallpaper.maximized(beautiful.wallpaper, s, true)
  116. end
  117. end
  118.  
  119. -- }}}
  120.  
  121. -- {{{ Tags
  122.  
  123. tags = {
  124. names = { "www", "dev", "docs", "media" },
  125. layout = { layouts[1], layouts[2], layouts[4], layouts[3] }
  126. }
  127. for s = 1, screen.count() do
  128. tags[s] = awful.tag(tags.names, s, tags.layout)
  129. end
  130.  
  131.  
  132. -- }}}
  133.  
  134. -- {{{ Menu
  135.  
  136. -- applications menu
  137. require('freedesktop.utils')
  138. freedesktop.utils.terminal = terminal -- default: "xterm"
  139. freedesktop.utils.icon_theme = 'AwOkenDark' -- look inside /usr/share/icons/, default: nil (don't use icon theme)
  140. require('freedesktop.menu')
  141. require("debian.menu")
  142.  
  143. menu_items = freedesktop.menu.new()
  144. myawesomemenu = {
  145. { "manual", terminal .. " -e man awesome", freedesktop.utils.lookup_icon({ icon = 'help' }) },
  146. -- { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua", freedesktop.utils.lookup_icon({ icon = 'package_settings' }) },
  147. { "restart", awesome.restart, freedesktop.utils.lookup_icon({ icon = 'gtk-refresh' }) },
  148. { "quit", awesome.quit, freedesktop.utils.lookup_icon({ icon = 'gtk-quit' }) }
  149. }
  150. table.insert(menu_items, { "awesome", myawesomemenu, beautiful.awesome_icon })
  151. table.insert(menu_items, { "open terminal", terminal, freedesktop.utils.lookup_icon({icon = 'terminal'}) })
  152. table.insert(menu_items, { "Debian", debian.menu.Debian_menu.Debian, freedesktop.utils.lookup_icon({ icon = 'debian-logo' }) })
  153.  
  154. mymainmenu = awful.menu.new({ items = menu_items, width = 150 })
  155.  
  156. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  157. menu = mymainmenu })
  158.  
  159. -- }}}
  160.  
  161. -- {{{ Wibox
  162.  
  163. -- awful.util
  164. local util = awful.util
  165.  
  166. -- Colours
  167. coldef = "</span>"
  168. white = "<span color='#ebebff'>"
  169. gray = "<span color='#9e9e9e'>"
  170.  
  171. -- Textclock widget
  172. mytextclock = awful.widget.textclock(white .. "%H:%M" .. coldef)
  173.  
  174. -- Calendar notification
  175. local tonumber = tonumber
  176. local calendar = nil
  177. local offset = 0
  178.  
  179. function remove_calendar()
  180. if calendar ~= nil then
  181. naughty.destroy(calendar)
  182. calendar = nil
  183. end
  184. end
  185.  
  186. function show_calendar(inc_offset, t_out)
  187. remove_calendar()
  188. local f, c_text
  189. local today = tonumber(os.date('%d'))
  190.  
  191. if inc_offset == 0 then
  192. if today < 10 then
  193. f = io.popen('/usr/bin/cal | sed -r -e "s/(^| )( ' .. today .. ')($| )/\\1<b><span foreground=\\"#242424\\" background=\\"#D4D4D4\\">\\2<\\/span><\\/b>\\3/"',"r")
  194. else
  195. f = io.popen('/usr/bin/cal | sed -r -e "s/(^| )(' .. today .. ')($| )/\\1<b><span foreground=\\"#242424\\" background=\\"#D4D4D4\\">\\2<\\/span><\\/b>\\3/"',"r")
  196. end
  197. c_text = "<tt><span font='Tamsyn 12'><b>" .. f:read() .. "</b>\n\n" .. f:read() .. "\n" .. f:read("*all") .. "</span></tt>"
  198. f:close()
  199. offset = 0
  200. else
  201. local month = tonumber(os.date('%m'))
  202. local year = tonumber(os.date('%Y'))
  203.  
  204. offset = offset + inc_offset
  205. month = month + offset
  206.  
  207. if month > 12 then
  208. month = 12
  209. offset = 12 - tonumber(os.date('%m'))
  210. elseif month < 1 then
  211. month = 1
  212. offset = 1 - tonumber(os.date('%m'))
  213. end
  214.  
  215. f = io.popen('/usr/bin/cal ' .. month .. ' ' .. year ,"r")
  216. c_text = "<tt><span font='Tamsyn 12'><b>" .. f:read() .. "</b>\n\n" .. f:read() .. "\n" .. f:read("*all") .. "</span></tt>"
  217. f:close()
  218. end
  219.  
  220. calendar = naughty.notify({ text = c_text,
  221. fg = "#D4D4D4",
  222. bg = "#242424",
  223. timeout = t_out
  224. })
  225. end
  226.  
  227. mytextclock:connect_signal("mouse::enter", function() show_calendar(0, 0) end)
  228. mytextclock:connect_signal("mouse::leave", function() remove_calendar() end)
  229. mytextclock:buttons(util.table.join( awful.button({ }, 1, function() show_calendar(-1, 0) end),
  230. awful.button({ }, 3, function() show_calendar(1, 0) end)))
  231.  
  232. -- GMail widget
  233. mygmail = wibox.widget.textbox()
  234. gmail_t = awful.tooltip({ objects = { mygmail },})
  235. notify_shown = false
  236. mailcount = 0
  237. vicious.register(mygmail, vicious.widgets.gmail,
  238. function (widget, args)
  239. gmail_t:set_text(args["{subject}"])
  240. gmail_t:add_to_object(mygmail)
  241. notify_title = ""
  242. notify_text = ""
  243. mailcount = args["{count}"]
  244. if (args["{count}"] > 0 ) then
  245. if (notify_shown == false) then
  246. -- Italian localization
  247. -- can be a stub for your own localization
  248. if (args["{count}"] == 1) then
  249. if language:find("it_IT") ~= nil
  250. then
  251. notify_title = "Hai un nuovo messaggio"
  252. else
  253. notify_title = "You got a new mail"
  254. end
  255. notify_text = '"' .. args["{subject}"] .. '"'
  256. else
  257. if language:find("it_IT") ~= nil
  258. then
  259. notify_title = "Hai " .. args["{count}"] .. " nuovi messaggi"
  260. notify_text = 'Ultimo: "' .. args["{subject}"] .. '"'
  261. else
  262. notify_title = "You got " .. args["{count}"] .. " new mails"
  263. notify_text = 'Last one: "' .. args["{subject}"] .. '"'
  264. end
  265. end
  266. naughty.notify({
  267. title = notify_title,
  268. text = notify_text,
  269. timeout = 7,
  270. position = "top_left",
  271. icon = beautiful.widget_mail_notify,
  272. fg = "#D0D0D0",
  273. bg = "#242424"
  274. })
  275. notify_shown = true
  276. end
  277. return gray .. " Mail " .. coldef .. white .. args["{count}"] .. " " .. coldef
  278. else
  279. notify_shown = false
  280. return ''
  281. end
  282. end, 60)
  283. mygmail:buttons(awful.util.table.join(awful.button({ }, 1, function () awful.util.spawn(mail, false) end)))
  284.  
  285. -- Mpd widget
  286. mpdwidget = wibox.widget.textbox()
  287. mpdwidget:buttons(awful.util.table.join(awful.button({ }, 1, function () awful.util.spawn_with_shell(musicplr) end)))
  288. curr_track = nil
  289. vicious.register(mpdwidget, vicious.widgets.mpd,
  290. function(widget, args)
  291. if args["{state}"] == "Play" then
  292. if args["{Title}"] ~= curr_track
  293. then
  294. curr_track = args["{Title}"]
  295. os.execute(scriptdir .. "mpdinfo")
  296. old_id = naughty.notify({
  297. title = "Now playing",
  298. text = args["{Artist}"] .. " (" .. args["{Album}"] .. ")\n" .. args["{Title}"],
  299. icon = "/tmp/mpdnotify_cover.png",
  300. fg = "#D0D0D0",
  301. bg = "#242424",
  302. timeout = 5,
  303. replaces_id = old_id
  304. }).id
  305. end
  306. return gray .. args["{Artist}"] .. coldef .. white .. " " .. args["{Title}"] .. " " .. coldef
  307. elseif args["{state}"] == "Pause" then
  308. -- 'in pausa' means 'paused'
  309. return gray .. "mpd " .. coldef .. white .. "in pausa " .. coldef
  310. else
  311. curr_track = nil
  312. return ''
  313. end
  314. end, 1)
  315.  
  316. -- /home fs widget
  317. fshwidget = wibox.widget.textbox()
  318. too_much = false
  319. vicious.register(fshwidget, vicious.widgets.fs,
  320. function (widget, args)
  321. if ( args["{/home used_p}"] >= 90 ) then
  322. if ( args["{/home used_p}"] >= 99 and too_much == false ) then
  323. naughty.notify({ title = "Attenzione", text = "Partizione /home esaurita!\nFa' un po' di spazio.",
  324. timeout = 7,
  325. position = "top_right",
  326. fg = beautiful.fg_urgent,
  327. bg = beautiful.bg_urgent })
  328. too_much = true
  329. end
  330. return gray .. " Hdd " .. coldef .. white .. args["{/home used_p}"] .. coldef .. " "
  331. else
  332. return ""
  333. end
  334. end, 600)
  335.  
  336. -- hhd status notification
  337. local infos = nil
  338.  
  339. function remove_info()
  340. if infos ~= nil then
  341. naughty.destroy(infos)
  342. infos = nil
  343. end
  344. end
  345.  
  346. function show_info(t_out)
  347. remove_info()
  348. local capi = {
  349. mouse = mouse,
  350. screen = screen
  351. }
  352. local hdd = awful.util.pread(scriptdir .. "dfs")
  353. hdd = string.gsub(hdd, " ^%s*(.-)%s*$", "%1")
  354.  
  355. -- Italian localization
  356. -- can be a stub for your own localization
  357. if language:find("it_IT") ~= nil
  358. then
  359. hdd = string.gsub(hdd, "Used ", "Usato")
  360. hdd = string.gsub(hdd, "Free ", "Libero")
  361. hdd = string.gsub(hdd, "Total ", "Totale")
  362. end
  363.  
  364. infos = naughty.notify({
  365. text = hdd,
  366. timeout = t_out,
  367. position = "top_right",
  368. margin = 10,
  369. height = 210,
  370. width = 680,
  371. fg = "#D4D4D4",
  372. bg = "#242424",
  373. screen = capi.mouse.screen
  374. })
  375. end
  376.  
  377. fshwidget:connect_signal('mouse::enter', function () show_info(0) end)
  378. fshwidget:connect_signal('mouse::leave', function () remove_info() end)
  379.  
  380. -- Battery widget
  381. batwidget = wibox.widget.textbox()
  382. function batstate()
  383.  
  384. local file = io.open("/sys/class/power_supply/BAT0/status", "r")
  385.  
  386. if (file == nil) then
  387. return "Cable plugged"
  388. end
  389.  
  390. local batstate = file:read("*line")
  391. file:close()
  392.  
  393. if (batstate == 'Discharging' or batstate == 'Charging') then
  394. return batstate
  395. else
  396. return "Fully charged"
  397. end
  398. end
  399. vicious.register(batwidget, vicious.widgets.bat,
  400. function (widget, args)
  401. -- plugged
  402. if (batstate() == 'Cable plugged' or batstate() == 'Unknown') then
  403. return ''
  404. -- critical
  405. elseif (args[2] <= 5 and batstate() == 'Discharging') then
  406. naughty.notify{
  407. -- Italian localization
  408. -- can be a stub for your own localization
  409. text = "sto per spegnermi...",
  410. title = "Carica quasi esaurita!",
  411. position = "top_right",
  412. timeout = 0,
  413. fg="#000000",
  414. bg="#ffffff",
  415. screen = 1,
  416. ontop = true,
  417. }
  418. -- low
  419. elseif (args[2] <= 10 and batstate() == 'Discharging') then
  420. naughty.notify({
  421. -- Italian localization
  422. -- can be a stub for your own localization
  423. text = "attacca il cavo!",
  424. title = "Carica bassa",
  425. position = "top_right",
  426. timeout = 0,
  427. fg="#ffffff",
  428. bg="#262729",
  429. screen = 1,
  430. ontop = true,
  431. })
  432. end
  433. return gray .. "Bat " .. coldef .. white .. args[2] .. " " .. coldef
  434. end, 1, 'BAT0')
  435.  
  436. -- {{{ Volume widget
  437. --
  438. -- original version: http://awesome.naquadah.org/wiki/Rman%27s_Simple_Volume_Widget
  439.  
  440. local alsawidget =
  441. {
  442. channel = "Master",
  443. step = "5%",
  444. colors =
  445. {
  446. unmute = "#a4ce8a",
  447. mute = "#eb8f8f"
  448. },
  449. mixer = terminal .. " -e alsamixer", -- or whatever your preferred sound mixer is
  450. notifications =
  451. {
  452. font = "Tamsyn 11",
  453. bar_size = 18
  454. }
  455. }
  456.  
  457. alsawidget.bar = awful.widget.progressbar ()
  458. alsawidget.bar:set_width (60)
  459. alsawidget.bar:set_height (10)
  460. awful.widget.progressbar.set_ticks (alsawidget.bar, true)
  461. alsamargin = wibox.layout.margin (alsawidget.bar, 5, 8, 80)
  462. wibox.layout.margin.set_top (alsamargin, 5)
  463. wibox.layout.margin.set_bottom (alsamargin, 5)
  464.  
  465. alsawidget.bar:set_background_color ("#7e7e7e")
  466. alsawidget.bar:set_color (alsawidget.colors.unmute)
  467. alsawidget.bar:buttons (awful.util.table.join (
  468. awful.button ({}, 1, function()
  469. awful.util.spawn (alsawidget.mixer)
  470. end),
  471. awful.button ({}, 3, function()
  472. awful.util.spawn ("amixer sset " .. alsawidget.channel .. " toggle")
  473. vicious.force ({ alsawidget.bar })
  474. end),
  475. awful.button ({}, 4, function()
  476. awful.util.spawn ("amixer sset " .. alsawidget.channel .. " " .. alsawidget.step .. "+")
  477. vicious.force ({ alsawidget.bar })
  478. end),
  479. awful.button ({}, 5, function()
  480. awful.util.spawn ("amixer sset " .. alsawidget.channel .. " " .. alsawidget.step .. "-")
  481. vicious.force ({ alsawidget.bar })
  482. end)
  483. ))
  484.  
  485. -- tooltip
  486. alsawidget.tooltip = awful.tooltip ({ objects = { alsawidget.bar } })
  487.  
  488. -- naughty notifications
  489. alsawidget._current_level = 0
  490. alsawidget._muted = false
  491.  
  492. function alsawidget:notify ()
  493. local preset =
  494. {
  495. -- title = "", text = "",
  496. timeout = 3,
  497. height = 40,
  498. width = 170,
  499. font = alsawidget.notifications.font,
  500. fg = "#D4D4D4"
  501. }
  502.  
  503. if alsawidget._muted
  504. then
  505. preset.title = alsawidget.channel .. " - Muted"
  506. else
  507. preset.title = alsawidget.channel .. " - " .. alsawidget._current_level .. "%"
  508. end
  509.  
  510. local int = math.modf (alsawidget._current_level / 100 * alsawidget.notifications.bar_size)
  511. preset.text = "[" .. string.rep ("|", int) .. string.rep (" ", alsawidget.notifications.bar_size - int) .. "]"
  512.  
  513. if alsawidget._notify ~= nil
  514. then
  515. alsawidget._notify = naughty.notify (
  516. {
  517. replaces_id = alsawidget._notify.id,
  518. preset = preset
  519. })
  520. else
  521. alsawidget._notify = naughty.notify ({ preset = preset })
  522. end
  523. end
  524.  
  525. -- register the widget through vicious
  526. vicious.register (alsawidget.bar, vicious.widgets.volume, function (widget, args)
  527. alsawidget._current_level = args[1]
  528. if args[2] ~= "♩"
  529. then
  530. alsawidget._muted = false
  531. alsawidget.tooltip:set_text (" " .. alsawidget.channel .. ": " .. args[1] .. "% ")
  532. widget:set_color (alsawidget.colors.unmute)
  533. else
  534. alsawidget._muted = true
  535. alsawidget.tooltip:set_text (" [Muted] ")
  536. widget:set_color (alsawidget.colors.mute)
  537. end
  538. return args[1]
  539. end, 5, alsawidget.channel) -- relatively high update time, use of keys/mouse will force update
  540.  
  541. -- }}}
  542.  
  543. -- Net checker widget
  544. no_net_shown = true
  545. netwidget = wibox.widget.textbox()
  546. vicious.register(netwidget, vicious.widgets.net,
  547. function (widget, args)
  548. if args["{wlan0 carrier}"] == 0 then
  549. if no_net_shown == true then
  550. naughty.notify({ title = "wlan0", text = "No carrier",
  551. timeout = 7,
  552. position = "top_left",
  553. icon = beautiful.widget_no_net_notify,
  554. fg = "#ff5e5e",
  555. bg = "#242424" })
  556. no_net_shown = false
  557. end
  558. return gray .. " Net " .. coldef .. "<span color='#eb8f8f'>Off " .. coldef
  559. else
  560. no_net_shown = true
  561. return ''
  562. end
  563. end, 10)
  564. netwidget:buttons(awful.util.table.join(awful.button({ }, 1, function () awful.util.spawn_with_shell(wifi) end)))
  565.  
  566. -- Weather widget
  567. yawn.register(123456) -- https//github.com/copycat-killer/yawn
  568.  
  569. -- Separators
  570. spr = wibox.widget.textbox(' ')
  571. small_spr = wibox.widget.textbox('<span font="Tamsyn 4"> </span>')
  572.  
  573. -- }}}
  574.  
  575. -- {{{ Layout
  576.  
  577. -- Create a wibox for each screen and add it
  578. mywibox = {}
  579. mypromptbox = {}
  580. txtlayoutbox = {}
  581. mytaglist = {}
  582. mytaglist.buttons = awful.util.table.join(
  583. awful.button({ }, 1, awful.tag.viewonly),
  584. awful.button({ modkey }, 1, awful.client.movetotag),
  585. awful.button({ }, 3, awful.tag.viewtoggle),
  586. awful.button({ modkey }, 3, awful.client.toggletag),
  587. awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
  588. awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
  589. )
  590. mytasklist = {}
  591. mytasklist.buttons = awful.util.table.join(
  592. awful.button({ }, 1, function (c)
  593. if c == client.focus then
  594. c.minimized = true
  595. else
  596. -- Without this, the following
  597. -- :isvisible() makes no sense
  598. c.minimized = false
  599. if not c:isvisible() then
  600. awful.tag.viewonly(c:tags()[1])
  601. end
  602. -- This will also un-minimize
  603. -- the client, if needed
  604. client.focus = c
  605. c:raise()
  606. end
  607. end),
  608. awful.button({ }, 3, function ()
  609. if instance then
  610. instance:hide()
  611. instance = nil
  612. else
  613. instance = awful.menu.clients({ width=250 })
  614. end
  615. end),
  616. awful.button({ }, 4, function ()
  617. awful.client.focus.byidx(1)
  618. if client.focus then client.focus:raise() end
  619. end),
  620. awful.button({ }, 5, function ()
  621. awful.client.focus.byidx(-1)
  622. if client.focus then client.focus:raise() end
  623. end))
  624.  
  625. -- Writes a string representation of the current layout in a textbox widget
  626. function updatelayoutbox(layout, s)
  627. local screen = s or 1
  628. layout:set_text(beautiful["layout_txt_" .. awful.layout.getname(awful.layout.get(screen))])
  629. end
  630.  
  631. for s = 1, screen.count() do
  632. -- Create a promptbox for each screen
  633. mypromptbox[s] = awful.widget.prompt()
  634.  
  635. -- Create a textbox widget which will contains a short string representing the
  636. -- layout we're using. We need one layoutbox per screen.
  637. txtlayoutbox[s] = wibox.widget.textbox(beautiful["layout_txt_" .. awful.layout.getname(awful.layout.get(s))])
  638. awful.tag.attached_connect_signal(s, "property::selected", function ()
  639. updatelayoutbox(txtlayoutbox[s], s)
  640. end)
  641. awful.tag.attached_connect_signal(s, "property::layout", function ()
  642. updatelayoutbox(txtlayoutbox[s], s)
  643. end)
  644. txtlayoutbox[s]:buttons(awful.util.table.join(
  645. awful.button({}, 1, function() awful.layout.inc(layouts, 1) end),
  646. awful.button({}, 3, function() awful.layout.inc(layouts, -1) end),
  647. awful.button({}, 4, function() awful.layout.inc(layouts, 1) end),
  648. awful.button({}, 5, function() awful.layout.inc(layouts, -1) end)))
  649.  
  650. -- Create a taglist widget
  651. mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  652.  
  653. -- Create a tasklist widget
  654. mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  655.  
  656. -- Create the wibox
  657. mywibox[s] = awful.wibox({ position = "top", screen = s, height = 18 })
  658.  
  659. -- Widgets that are aligned to the upper left
  660. local left_layout = wibox.layout.fixed.horizontal()
  661. left_layout:add(small_spr)
  662. left_layout:add(mytaglist[s])
  663. left_layout:add(spr)
  664. left_layout:add(txtlayoutbox[s])
  665. left_layout:add(spr)
  666. left_layout:add(mypromptbox[s])
  667.  
  668. -- Widgets that are aligned to the upper right
  669. local right_layout = wibox.layout.fixed.horizontal()
  670. if s == 1 then right_layout:add(wibox.widget.systray()) end
  671. right_layout:add(small_spr)
  672. right_layout:add(mpdwidget)
  673. right_layout:add(mygmail)
  674. right_layout:add(fshwidget)
  675. right_layout:add(batwidget)
  676. right_layout:add(netwidget)
  677. right_layout:add(small_spr)
  678. right_layout:add(alsamargin)
  679. right_layout:add(spr)
  680. right_layout:add(mytextclock)
  681. right_layout:add(spr)
  682.  
  683. -- Now bring it all together (with the tasklist in the middle)
  684. local layout = wibox.layout.align.horizontal()
  685. layout:set_left(left_layout)
  686. layout:set_middle(mytasklist[s])
  687. layout:set_right(right_layout)
  688.  
  689. mywibox[s]:set_widget(layout)
  690.  
  691. end
  692.  
  693. -- }}}
  694.  
  695. -- {{{ Mouse Bindings
  696.  
  697. root.buttons(awful.util.table.join(
  698. awful.button({ }, 3, function () mymainmenu:toggle() end),
  699. awful.button({ }, 4, awful.tag.viewnext),
  700. awful.button({ }, 5, awful.tag.viewprev)
  701. ))
  702.  
  703. -- }}}
  704.  
  705. -- {{{ Key bindings
  706.  
  707. globalkeys = awful.util.table.join(
  708.  
  709. -- Take a screenshot
  710. awful.key({ altkey }, "p", function() awful.util.spawn("screenshot",false) end),
  711.  
  712. awful.key({ modkey, }, "Left", awful.tag.viewprev ),
  713. awful.key({ altkey, "Control" }, "j", awful.tag.viewprev ),
  714. awful.key({ modkey, }, "Right", awful.tag.viewnext ),
  715. awful.key({ altkey, "Control" }, "k", awful.tag.viewnext ),
  716. awful.key({ modkey, }, "Escape", awful.tag.history.restore),
  717. awful.key({ modkey, }, "k",
  718. function ()
  719. awful.client.focus.byidx( 1)
  720. if client.focus then client.focus:raise() end
  721. end),
  722. awful.key({ modkey, }, "j",
  723. function ()
  724. awful.client.focus.byidx(-1)
  725. if client.focus then client.focus:raise() end
  726. end),
  727. awful.key({ modkey, }, "w", function () mymainmenu:show({keygrabber=true}) end),
  728.  
  729. -- Show/Hide Wibox
  730. awful.key({ modkey }, "b", function ()
  731. mywibox[mouse.screen].visible = not mywibox[mouse.screen].visible
  732. end),
  733.  
  734. -- Layout manipulation
  735. awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
  736. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
  737. awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  738. awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  739. awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
  740. awful.key({ modkey, }, "Tab",
  741. function ()
  742. awful.client.focus.history.previous()
  743. if client.focus then
  744. client.focus:raise()
  745. end
  746. end),
  747.  
  748. -- Standard program
  749. awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
  750. awful.key({ modkey, "Control" }, "r", awesome.restart),
  751. awful.key({ modkey, "Shift" }, "q", awesome.quit),
  752. awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  753. awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  754. awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  755. awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  756. awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
  757. awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
  758. awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
  759. awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
  760. awful.key({ modkey, "Control" }, "n", awful.client.restore),
  761.  
  762. -- Dropdown terminal
  763. awful.key({ modkey, }, "z", function () scratch.drop(terminal) end),
  764.  
  765. -- Widgets popups
  766. awful.key({ altkey, }, "c", function () show_calendar(0, 7) end),
  767. awful.key({ altkey, }, "h", function ()
  768. vicious.force({ fshwidget })
  769. show_info(7)
  770. end),
  771. awful.key({ altkey, }, "w", function () yawn.show_weather(7) end),
  772.  
  773. -- Volume control
  774. awful.key({ altkey }, "Up", function ()
  775. awful.util.spawn("amixer sset " .. alsawidget.channel .. " " .. alsawidget.step .. "+")
  776. vicious.force({ alsawidget.bar })
  777. alsawidget.notify()
  778. end),
  779. awful.key({ altkey }, "Down", function ()
  780. awful.util.spawn("amixer sset " .. alsawidget.channel .. " " .. alsawidget.step .. "-")
  781. vicious.force({ alsawidget.bar })
  782. alsawidget.notify()
  783. end),
  784. awful.key({ altkey }, "m", function ()
  785. awful.util.spawn("amixer set Master playback toggle")
  786. vicious.force({ alsawidget.bar })
  787. --alsawidget._muted = not alsawidget._muted
  788. alsawidget.notify()
  789. end),
  790. awful.key({ altkey, "Control" }, "m", function ()
  791. awful.util.spawn("amixer set Master playback 100%", false )
  792. vicious.force({ alsawidget.bar })
  793. alsawidget.notify()
  794. end),
  795.  
  796. -- Music control
  797. awful.key({ altkey, "Control" }, "Up", function ()
  798. awful.util.spawn( "mpc toggle", false )
  799. vicious.force({ mpdwidget } )
  800. end),
  801. awful.key({ altkey, "Control" }, "Down", function ()
  802. awful.util.spawn( "mpc stop", false )
  803. vicious.force({ mpdwidget } )
  804. end ),
  805. awful.key({ altkey, "Control" }, "Left", function ()
  806. awful.util.spawn( "mpc prev", false )
  807. vicious.force({ mpdwidget } )
  808. end ),
  809. awful.key({ altkey, "Control" }, "Right", function ()
  810. awful.util.spawn( "mpc next", false )
  811. vicious.force({ mpdwidget } )
  812. end ),
  813.  
  814. -- Copy to clipboard
  815. awful.key({ modkey }, "c", function () os.execute("xsel -p -o | xsel -i -b") end),
  816.  
  817. -- User programs
  818. awful.key({ modkey }, "q", function () awful.util.spawn(browser) end),
  819. awful.key({ modkey }, "s", function () awful.util.spawn(gui_editor) end),
  820. awful.key({ modkey }, "g", function () awful.util.spawn(graphics) end),
  821.  
  822. -- Prompt
  823. awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
  824. awful.key({ modkey }, "x",
  825. function ()
  826. awful.prompt.run({ prompt = "Run Lua code: " },
  827. mypromptbox[mouse.screen].widget,
  828. awful.util.eval, nil,
  829. awful.util.getdir("cache") .. "/history_eval")
  830. end)
  831. )
  832.  
  833. clientkeys = awful.util.table.join(
  834. awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
  835. awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
  836. awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
  837. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  838. awful.key({ modkey, }, "o", awful.client.movetoscreen ),
  839. awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
  840. awful.key({ modkey, }, "n",
  841. function (c)
  842. -- The client currently has the input focus, so it cannot be
  843. -- minimized, since minimized clients can't have the focus.
  844. c.minimized = true
  845. end),
  846. awful.key({ modkey, }, "m",
  847. function (c)
  848. c.maximized_horizontal = not c.maximized_horizontal
  849. c.maximized_vertical = not c.maximized_vertical
  850. end)
  851. )
  852.  
  853.  
  854. -- Compute the maximum number of digit we need, limited to 9
  855. keynumber = 0
  856. for s = 1, screen.count() do
  857. keynumber = math.min(9, math.max(#tags[s], keynumber));
  858. end
  859.  
  860. -- Bind all key numbers to tags.
  861. -- Be careful: we use keycodes to make it works on any keyboard layout.
  862. -- This should map on the top row of your keyboard, usually 1 to 9.
  863. for i = 1, keynumber do
  864. globalkeys = awful.util.table.join(globalkeys,
  865. awful.key({ modkey }, "#" .. i + 9,
  866. function ()
  867. screen = mouse.screen
  868. if tags[screen][i] then
  869. awful.tag.viewonly(tags[screen][i])
  870. end
  871. end),
  872. awful.key({ modkey, "Control" }, "#" .. i + 9,
  873. function ()
  874. screen = mouse.screen
  875. if tags[screen][i] then
  876. awful.tag.viewtoggle(tags[screen][i])
  877. end
  878. end),
  879. awful.key({ modkey, "Shift" }, "#" .. i + 9,
  880. function ()
  881. if client.focus and tags[client.focus.screen][i] then
  882. awful.client.movetotag(tags[client.focus.screen][i])
  883. end
  884. end),
  885. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  886. function ()
  887. if client.focus and tags[client.focus.screen][i] then
  888. awful.client.toggletag(tags[client.focus.screen][i])
  889. end
  890. end))
  891. end
  892.  
  893. clientbuttons = awful.util.table.join(
  894. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  895. awful.button({ modkey }, 1, awful.mouse.client.move),
  896. awful.button({ modkey }, 3, awful.mouse.client.resize))
  897.  
  898. -- Set keys
  899. root.keys(globalkeys)
  900.  
  901. -- }}}
  902.  
  903. -- {{{ Rules
  904.  
  905. awful.rules.rules = {
  906. -- All clients will match this rule.
  907. { rule = { },
  908. properties = { border_width = beautiful.border_width,
  909. border_color = beautiful.border_normal,
  910. focus = awful.client.focus.filter,
  911. keys = clientkeys,
  912. buttons = clientbuttons,
  913. size_hints_honor = false
  914. }
  915. },
  916.  
  917. { rule = { class = "URxvt" },
  918. properties = { opacity = 0.99 } },
  919.  
  920. { rule = { class = "MPlayer" },
  921. properties = { floating = true } },
  922.  
  923. { rule = { class = "Dwb" },
  924. properties = { tag = tags[1][1] } },
  925.  
  926. { rule = { instance = "plugin-container" },
  927. properties = { tag = tags[1][1] } },
  928.  
  929. { rule = { class = "Gimp" },
  930. properties = { tag = tags[1][4] } },
  931.  
  932. { rule = { class = "Gimp", role = "gimp-image-window" },
  933. properties = { maximized_horizontal = true,
  934. maximized_vertical = true } },
  935.  
  936. { rule = { class = "Transmission-gtk" },
  937. properties = { tag = tags[1][4] } },
  938.  
  939. { rule = { class = "Torrent-search" },
  940. properties = { tag = tags[1][4] } },
  941. }
  942.  
  943. -- }}}
  944.  
  945. -- {{{ Signals
  946.  
  947. -- Signal function to execute when a new client appears.
  948. client.connect_signal("manage", function (c, startup)
  949. -- Enable sloppy focus
  950. c:connect_signal("mouse::enter", function(c)
  951. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  952. and awful.client.focus.filter(c) then
  953. client.focus = c
  954. end
  955. end)
  956.  
  957. if not startup then
  958. -- Set the windows at the slave,
  959. -- i.e. put it at the end of others instead of setting it master.
  960. awful.client.setslave(c)
  961.  
  962. -- Put windows in a smart way, only if they does not set an initial position.
  963. if not c.size_hints.user_position and not c.size_hints.program_position then
  964. awful.placement.no_overlap(c) awful.placement.no_offscreen(c)
  965. end
  966. end
  967. end)
  968.  
  969. -- No border for maximized clients
  970. client.connect_signal("focus",
  971. function(c)
  972. if c.maximized_horizontal == true and c.maximized_vertical == true then
  973. c.border_width = "0"
  974. c.border_color = beautiful.border_normal
  975. else
  976. c.border_width = beautiful.border_width
  977. c.border_color = beautiful.border_focus
  978. end
  979. end)
  980. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  981.  
  982. -- }}}
  983.  
  984. -- {{{ Arrange signal handler
  985.  
  986. for s = 1, screen.count() do screen[s]:connect_signal("arrange", function ()
  987. local clients = awful.client.visible(s)
  988. local layout = awful.layout.getname(awful.layout.get(s))
  989.  
  990. if #clients > 0 then -- Fine grained borders and floaters control
  991. for _, c in pairs(clients) do -- Floaters always have borders
  992. if awful.client.floating.get(c) or layout == "floating" then
  993. c.border_width = beautiful.border_width
  994.  
  995. -- No borders with only one visible client
  996. elseif #clients == 1 or layout == "max" then
  997. clients[1].border_width = 0
  998. awful.client.moveresize(0, 0, 2, 2, clients[1])
  999. else
  1000. c.border_width = beautiful.border_width
  1001. end
  1002. end
  1003. end
  1004. end)
  1005. end
  1006.  
  1007. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement