Advertisement
Guest User

rc.lua by intrntbrn

a guest
Mar 30th, 2012
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.35 KB | None | 0 0
  1. -- rc.lua by intrntbrn
  2.  
  3. require("awful")
  4. require("awful.autofocus")
  5. require("awful.rules")
  6. require("beautiful")
  7. require("naughty")
  8. require("vicious")
  9. require("blingbling")
  10.  
  11. -- startup error
  12. do
  13. local in_error = false
  14. awesome.add_signal("debug::error", function (err)
  15. -- Make sure we don't go into an endless error loop
  16. if in_error then return end
  17. in_error = true
  18.  
  19. naughty.notify({ preset = naughty.config.presets.critical,
  20. title = "time to debug",
  21. text = err,
  22. timeout = 1 })
  23. in_error = false
  24. end)
  25. end
  26.  
  27.  
  28. -- error handling
  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.  
  35.  
  36. -- theme
  37. beautiful.init("/usr/share/awesome/themes/redhalo/theme.lua")
  38. barheight = 16
  39. borderwidth = 0
  40.  
  41. -- path
  42. config = awful.util.getdir("config")
  43. icons = "/usr/share/awesome/icons/my/"
  44.  
  45. -- std programs
  46. terminal = "urxvt"
  47. browser = "dwb"
  48. editor = os.getenv("EDITOR") or "vim"
  49. editor_cmd = terminal .. " -e " .. editor
  50. guieditor = terminal .. " -e gvim "
  51. fm = "spacefm "
  52.  
  53. -- alias
  54. exec = awful.util.spawn
  55. sexec = awful.util.spawn_with_shell
  56. modkey = "Mod4"
  57. winkey = "Mod4"
  58. altkey = "Mod1"
  59.  
  60. -- mixed
  61. space = 40
  62. widthMpd = 450
  63. useMpd = true
  64.  
  65.  
  66. -- layouts
  67. layouts =
  68. {
  69. awful.layout.suit.floating,
  70. awful.layout.suit.tile,
  71. awful.layout.suit.tile.left,
  72. awful.layout.suit.tile.bottom,
  73. awful.layout.suit.tile.top,
  74. awful.layout.suit.fair,
  75. awful.layout.suit.fair.horizontal,
  76. awful.layout.suit.spiral,
  77. awful.layout.suit.spiral.dwindle,
  78. awful.layout.suit.max,
  79. awful.layout.suit.max.fullscreen,
  80. awful.layout.suit.magnifier
  81. }
  82.  
  83.  
  84. -- tags
  85. tags = {
  86. names = { "sys", "web", "doc", "dev", "irc", "foo"},
  87. layout = { layouts[1], layouts[10], layouts[8], layouts[8], layouts[2], layouts[1]
  88. }}
  89.  
  90. for s = 1, screen.count() do
  91. tags[s] = awful.tag(tags.names, s, tags.layout)
  92. end
  93.  
  94.  
  95. -- menu
  96. myawesomemenu = {
  97. { "edit rc.lua", function () sexec(guieditor .. "rc.lua") end},
  98. { "edit theme", function () sexec(guieditor .. "/usr/share/awesome/themes/redhalo/theme.lua") end },
  99. { "testmode", function () sexec("bash ~/bin/awsm.sh") end},
  100. { "restart", awesome.restart },
  101. { "quit", awesome.quit }
  102. }
  103.  
  104. mysystemmenu = {
  105. { "shutdown", function () sexec("sudo shutdown -h 0") end},
  106. { "reboot", function () sexec("sudo reboot") end},
  107. { "lock", function () sexec("slimlock") end},
  108. { "suspend", function () sexec("sudo pm-suspend") end},
  109. { "hibernate", function () sexec("sudo pm-hibernate") end}
  110. }
  111.  
  112. myfoldermenu = {
  113. { "Downloads", function () exec(fm .. " ~/Downloads") end},
  114. { "Movies", function () exec(fm .. " ~/HDD/Film") end},
  115. { "Music", function () exec(fm .. " ~/HDD/Musik") end},
  116. { "Downloads JD", function () exec(fm .. " ~/HDD/Downloads_JD") end},
  117. { "Workspace", function () exec(fm .. " ~/Workspace") end},
  118. { "Dropbox W", function () exec(fm .. " ~/Dropbox/WORKSPACE") end},
  119. { "Netbeans", function () exec(fm .. " ~/Workspace/NetBeansProjects") end},
  120. { "SE", function () exec(fm .. " ~/Dropbox/SS2011/SS2012/SE") end},
  121. { "DB", function () exec(fm .. " ~/Dropbox/SS2011/SS2012/Datenbanken") end},
  122. { "MPS", function () exec(fm .. " ~/Dropbox/SS2011/SS2012/MPS-ARM") end},
  123. { "OS", function () exec(fm .. " ~/Dropbox/SS2011/SS2012/Betriebssysteme") end},
  124. }
  125.  
  126. myappmenu = {
  127. { "mp3", terminal .. " -e ncmpcpp"},
  128. { "jabber", terminal .. " -e mcabber" },
  129. { "irc", terminal .. " -e weechat-curses" },
  130. { "watch tv", "vlc Downloads/stream.m3u" },
  131. { "eclipse", "eclipse" },
  132. { "netbeans", function () sexec("netbeans --laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel") end},
  133. { "arm insight", function () sexec("~/toolchain/insight/bin/arm-none-eabi-insight") end},
  134. { "mplayer", function () exec("gnome-mplayer") end},
  135. { "vlc", function () exec("vlc") end},
  136. { "gimp", function () exec("gimp") end},
  137. { "jdownloader", function () exec("jdownloader") end},
  138. { "pidgin", function () exec("pidgin") end},
  139. { "dwb", function () exec("dwb") end},
  140. { "firefox", function () exec("firefox") end},
  141. { "calculator", function () exec("gnome-calculator") end}
  142. }
  143.  
  144.  
  145. mymainmenu = awful.menu({ items = { { "folder", myfoldermenu, icons .."ontop_focus_inactive.png" },
  146. { "system", mysystemmenu, icons .. "arch-red.png" },
  147. { "awesome", myawesomemenu, icons .."awesome-blue.png" },
  148. { "applications", myappmenu, icons .. "arch-green.png" },
  149. { "terminal", terminal },
  150. { "browser", function () exec(browser) end},
  151. { "filemanager", function () exec(fm) end},
  152. { "editor", function () sexec(guieditor) end}
  153. }
  154. })
  155.  
  156. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  157. menu = mymainmenu })
  158.  
  159.  
  160. -- systray
  161. mysystray = widget({ type = "systray" })
  162.  
  163.  
  164. -- wiboxes
  165. mywibox = {}
  166. mywib = {}
  167. mypromptbox = {}
  168. mylayoutbox = {}
  169. mytaglist = {}
  170. mytaglist.buttons = awful.util.table.join(
  171. awful.button({ }, 1, awful.tag.viewonly),
  172. awful.button({ modkey }, 1, awful.client.movetotag),
  173. awful.button({ }, 3, awful.tag.viewtoggle),
  174. awful.button({ modkey }, 3, awful.client.toggletag),
  175. awful.button({ }, 4, awful.tag.viewnext),
  176. awful.button({ }, 5, awful.tag.viewprev)
  177. )
  178. mytasklist = {}
  179. mytasklist.buttons = awful.util.table.join(
  180. awful.button({ }, 1, function (c)
  181. -- swap to master mod
  182. if c == client.focus then
  183. -- c.minimized = true
  184. client.focus = c
  185. c:swap(awful.client.getmaster())
  186. else
  187. if not c:isvisible() then
  188. awful.tag.viewonly(c:tags()[1])
  189. client.focus = c
  190. c:swap(awful.client.getmaster())
  191. end
  192. -- This will also un-minimize
  193. -- the client, if needed
  194. client.focus = c
  195. c:raise()
  196. c:swap(awful.client.getmaster())
  197. end
  198. end),
  199. awful.button({ }, 3, function ()
  200. if instance then
  201. instance:hide()
  202. instance = nil
  203. else
  204. instance = awful.menu.clients({ width=250 })
  205. end
  206. end),
  207. awful.button({ }, 4, function ()
  208. awful.client.focus.byidx(1)
  209. if client.focus then client.focus:raise() end
  210. end),
  211. awful.button({ }, 5, function ()
  212. awful.client.focus.byidx(-1)
  213. if client.focus then client.focus:raise() end
  214. end),
  215. -- middle mouse
  216. awful.button({ }, 0, function (c)
  217. if c == client.focus then
  218. c.minimized = true
  219. else
  220. client.focus = c
  221. c:raise()
  222. end
  223. end))
  224.  
  225. for s = 1, screen.count() do
  226. -- Create a promptbox for each screen
  227. mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  228. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  229. -- We need one layoutbox per screen.
  230. mylayoutbox[s] = awful.widget.layoutbox(s)
  231. mylayoutbox[s]:buttons(awful.util.table.join(
  232. awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  233. awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  234. awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  235. awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  236. -- Create a taglist widget
  237. mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  238.  
  239. -- Create a tasklist widget
  240. mytasklist[s] = awful.widget.tasklist(function(c)
  241. return awful.widget.tasklist.label.currenttags(c, s)
  242. end, mytasklist.buttons)
  243.  
  244.  
  245.  
  246. -- widgets
  247.  
  248. ---------- spacer
  249. spacer = widget({ type = "textbox" })
  250. spacer.text = " "
  251.  
  252.  
  253. ---------- textclock
  254.  
  255. mytextclock = awful.widget.textclock({ align = "right",}, "%H:%M", 60)
  256. mytextclock.width = space
  257.  
  258.  
  259.  
  260. ---------- calendar
  261. my_cal =blingbling.calendar.new({type = "imagebox", image = icons .. "clock_blue.png"})
  262. my_cal:set_cell_padding(2)
  263. my_cal:set_title_font_size(8)
  264. my_cal:set_font_size(8)
  265. my_cal:set_inter_margin(1)
  266. my_cal:set_columns_lines_titles_font_size(8)
  267. my_cal:set_columns_lines_titles_text_color("#1692d0ff")
  268. my_cal:set_link_to_external_calendar(true)
  269.  
  270.  
  271.  
  272. ---------- wlan widget
  273. wlanwidget = widget({ type = "textbox" })
  274. vicious.register(wlanwidget, vicious.widgets.wifi,
  275. function (widget, args)
  276. if ((args["{link}"] == 0) or (args["{link}"] == nil)) then
  277. netwidget.width = 0
  278. netwidget.visible = false
  279. neticon.visible = false
  280. return "off"
  281. else
  282. netwidget.width = space
  283. netwidget.visible = true
  284. neticon.visible = true
  285. return round(((args["{link}"] *100) / 70), 0) .. "%"
  286.  
  287. end
  288. end, 10, "wlan0")
  289.  
  290. wlanwidget.width = space
  291.  
  292. wlanicon = widget({ type = "imagebox" })
  293. wlanicon.image = image(icons .. "wifi_blue.png")
  294.  
  295. ---------- wlan downstream
  296. netwidget = widget({ type = "textbox" })
  297. vicious.register(netwidget, vicious.widgets.net,
  298. function (widget, args)
  299. if (args["{wlan0 down_kb}"] ~= nil) then
  300. return round(args["{wlan0 down_kb}"], 0) .. "kb"
  301.  
  302. else
  303. return ""
  304. end
  305. end)
  306. netwidget.width = space
  307.  
  308. neticon = widget({ type = "imagebox" })
  309. neticon.image = image(icons .. "netdown_blue.png")
  310.  
  311.  
  312. ---------- mem load
  313. mymem = widget({ type = "textbox" })
  314. vicious.register(mymem, vicious.widgets.mem, "$1%", 30)
  315. mymem.width = space
  316.  
  317. mymemicon = widget({ type = "imagebox" })
  318. mymemicon.image = image(icons .. "mem_blue.png")
  319.  
  320. ---------- cpu load
  321. mycpuload = widget({ type = "textbox" })
  322. vicious.register(mycpuload, vicious.widgets.cpu, "$1%", 1)
  323. mycpuload.width = space
  324.  
  325. mycpuloadicon = widget({ type = "imagebox" })
  326. mycpuloadicon.image = image(icons .. "cpu_blue.png")
  327.  
  328. ---------- fan()
  329. function fan()
  330. local file = io.open("/sys/devices/platform/thinkpad_hwmon/fan1_input", "r")
  331. local fan = file:read("*n")
  332. file:close()
  333.  
  334. return fan
  335. end
  336.  
  337. ---------- cputmp()
  338. function cputemp()
  339. local file = io.open("/sys/class/thermal/thermal_zone0/temp", "r")
  340. local tmp = file:read("*n")
  341. file:close()
  342. output = tmp / 1000
  343.  
  344. return output
  345. end
  346.  
  347. ---------- cpu popup
  348. mycpuloadicon:add_signal("mouse::enter", function() batnotify = naughty.notify({
  349. text = "Fan: " .. fan() .. " RPM\n" .. "Temp: " .. cputemp() .. " °C",
  350. title = "CPU Info",
  351. timeout = 0
  352. })
  353. end)
  354.  
  355. mycpuloadicon:add_signal("mouse::leave",
  356. function ()
  357. if batnotify then
  358. naughty.destroy(batnotify)
  359. batnotify = nil
  360. end
  361. end)
  362.  
  363.  
  364. ---------- volume
  365. myvolicon = widget({ type = "imagebox" })
  366. myvolicon.image = image(icons .. "volume_blue.png")
  367.  
  368. myvol = widget({ type = "textbox" })
  369. vicious.register(myvol, vicious.widgets.volume,
  370. function (widget, args)
  371. if args[1] < 1 then
  372. myvolicon.image = image(icons .. "volume_low_blue.png")
  373. return "mute"
  374. else
  375. myvolicon.image = image(icons .. "volume_blue.png")
  376. return args[1] .. "%"
  377. end
  378. end, 2, "Master")
  379.  
  380. myvol.width = space
  381.  
  382.  
  383. ---------- battery
  384. mybaticon = widget({ type = "imagebox" })
  385. mybaticon.image = image(icons .. "battery_full_blue.png")
  386.  
  387. -- batstate()
  388. function batstate()
  389. local fileee = io.open("/sys/class/power_supply/BAT0/status", "r")
  390. local batstate = fileee:read("*line")
  391. if ((batstate == 'Discharging') or (batstate == 'Charging')) then
  392. return batstate
  393. else
  394. return "Fully charged"
  395. end
  396. end
  397.  
  398.  
  399. -- round()
  400. function round(num, idp)
  401. if ((num ~= nil) and (num ~= 0)) then
  402. local mult = 10^(idp or 0)
  403. return math.floor(num * mult + 0.5) / mult
  404. else
  405. return 0
  406. end
  407. end
  408.  
  409. -- shutdown()
  410. function shdown()
  411. sexec("sudo pm-suspend")
  412. end
  413.  
  414.  
  415. -- watt()
  416. function watt()
  417.  
  418. if (batstate() == 'Discharging') then
  419.  
  420. if(assert(io.open("/sys/devices/platform/smapi/BAT0/power_avg", "r"))) then
  421.  
  422. local file = io.open("/sys/devices/platform/smapi/BAT0/power_avg", "r")
  423. local avg = file:read("*n")
  424. file:close()
  425.  
  426. wattavg = ((avg * -1) / 1000)
  427.  
  428. return "\nUsage: ".. round(wattavg, 2) .. "W"
  429. else
  430. return "\nUsage: Error"
  431. end
  432. else
  433. return ""
  434. end
  435. end
  436.  
  437.  
  438. -- remaining()
  439. function remaining()
  440.  
  441. if (batstate() == 'Fully charged') then
  442. return ""
  443. end
  444.  
  445. if (batstate() == 'Discharging') then
  446.  
  447. if (assert(io.open("/sys/devices/platform/smapi/BAT0/remaining_running_time", "r"))) then
  448. local file = (io.open("/sys/devices/platform/smapi/BAT0/remaining_running_time", "r"))
  449. local remain = file:read("*n")
  450. file:close()
  451.  
  452. return "\nRemaining: " .. remain .. " min"
  453.  
  454. else return "\nRemaining: Error"
  455. end
  456. else
  457.  
  458. if (assert(io.open("/sys/devices/platform/smapi/BAT0/remaining_charging_time", "r"))) then
  459. local filee = io.open("/sys/devices/platform/smapi/BAT0/remaining_charging_time", "r")
  460. local charge = filee:read("*n")
  461. filee:close()
  462. return "\nRemaining: " .. charge .. " min"
  463. else
  464. return "\nRemaining: Error"
  465. end
  466. end
  467. end
  468.  
  469.  
  470.  
  471.  
  472. -- batterypopup
  473. mybaticon:add_signal("mouse::enter", function() batnotify = naughty.notify({
  474. text = "Status: " .. batstate() .. watt() .. remaining(),
  475. title = "Battery Info",
  476. timeout = 0
  477. })
  478. end)
  479.  
  480.  
  481. mybaticon:add_signal("mouse::leave",
  482. function ()
  483. if batnotify then
  484. naughty.destroy(batnotify)
  485. batnotify = nil
  486. end
  487. end)
  488.  
  489.  
  490. mybat = widget({ type = "textbox" })
  491. vicious.register(mybat, vicious.widgets.bat,
  492. function (widget, args)
  493.  
  494. batnofiy = nil
  495.  
  496. -- critical ( < 4)
  497. if (args[2] < 4 and batstate() == 'Discharging') then
  498. naughty.notify({
  499. text = "hybernating to disk now",
  500. title = "Critical Battery",
  501. position = "top_right",
  502. timeout = 30,
  503. fg="#262729",
  504. bg="#f92671",
  505. screen = 1,
  506. ontop = true,
  507. run = function () sexec("sudo pm-suspend") end
  508. })
  509. shdown()
  510. mybaticon.image = image(icons .. "battery_low_blue.png")
  511. return args[2] .. "%"
  512.  
  513. -- low ( < 10)
  514. elseif (args[2] < 10 and batstate() == 'Discharging') then
  515. naughty.notify({
  516. text = "charge now",
  517. title = "Low Battery",
  518. position = "top_right",
  519. timeout = 1,
  520. fg="#262729",
  521. bg="#f92671",
  522. screen = 1,
  523. ontop = true,
  524. })
  525.  
  526. mybaticon.image = image(icons .. "battery_low_blue.png")
  527. return args[2] .. "%"
  528.  
  529. -- normal discharging
  530. elseif (batstate() == 'Discharging') then
  531. mybaticon.image = image(icons .."battery_full_blue.png")
  532. return args[2] .. "%"
  533. -- charging
  534. else
  535. mybaticon.image = image(icons .. "ac_blue.png")
  536. return args[2] .. "%"
  537. end
  538. end, 61, 'BAT0')
  539. mybat.width = space
  540.  
  541.  
  542.  
  543. ---------- gmail
  544. awful.widget.gmail = require('awful.widget.gmail')
  545. gmailwidget = awful.widget.gmail.new()
  546.  
  547.  
  548.  
  549. ---------- MPD
  550. if useMpd == true then
  551.  
  552. music_play = awful.widget.launcher({
  553. image = image(icons .. "play_blue.png"),
  554. command = "ncmpcpp toggle && echo -e 'vicious.force({ mpdwidget, })' | awesome-client"
  555. })
  556.  
  557. music_pause = awful.widget.launcher({
  558. image = image(icons .. "pause_blue.png"),
  559. command = "ncmpcpp toggle && echo -e 'vicious.force({ mpdwidget, })' | awesome-client"
  560. })
  561. music_pause.visible = false
  562.  
  563. music_stop = awful.widget.launcher({
  564. image = image(icons .. "stop_blue.png"),
  565. command = "ncmpcpp stop && echo -e 'vicious.force({ mpdwidget, })' | awesome-client"
  566. })
  567.  
  568. music_prev = awful.widget.launcher({
  569. image = image(icons .. "prev_blue.png"),
  570. command = "ncmpcpp prev && echo -e 'vicious.force({ mpdwidget, })' | awesome-client"
  571. })
  572.  
  573. music_next = awful.widget.launcher({
  574. image = image(icons .. "next_blue.png"),
  575. command = "ncmpcpp next && echo -e 'vicious.force({ mpdwidget, })' | awesome-client"
  576. })
  577. maxlength = 15
  578.  
  579. mpdicon = awful.widget.launcher({
  580. image = image(icons .. "note_blue.png"),
  581. command = "ncmpcpp toggle && echo -e 'vicious.force({ mpdwidget, })' | awesome-client"
  582. })
  583.  
  584. mpdwidget = widget({ type = "textbox" })
  585. mpdwidget.width = widthMpd
  586. vicious.register(mpdwidget, vicious.widgets.mpd,
  587. function(widget, args)
  588.  
  589. local string = args["{Artist}"] .. " - " .. args["{Title}"]
  590.  
  591. -- play
  592. if (args["{state}"] == "Play") then
  593. music_play.visible = false
  594. music_pause.visible = true
  595. music_next.visible = true
  596. music_prev.visible = true
  597. music_stop.visible = true
  598. mpdwidget.visible = true
  599. mpdicon.visible = false
  600. return string
  601.  
  602. -- pause
  603. elseif (args["{state}"] == "Pause") then
  604.  
  605. music_play.visible = true
  606. music_pause.visible = false
  607. music_next.visible = true
  608. music_prev.visible = true
  609. music_stop.visible = true
  610. mpdwidget.visible = true
  611. mpdicon.visible = false
  612. return string
  613.  
  614. -- stop
  615. else
  616. mpdicon.visible = true
  617. music_play.visible = false
  618. music_pause.visible = false
  619. music_next.visible = false
  620. music_prev.visible = false
  621. music_stop.visible = false
  622. mpdwidget.visible = false
  623. return string
  624.  
  625. end
  626.  
  627. end, 2)
  628. end
  629.  
  630.  
  631. -- wibox
  632.  
  633. -- top
  634. mywibox[s] = awful.wibox({ position = "top", screen = s })
  635.  
  636. mywibox[s].widgets = {
  637. {
  638. mylauncher,
  639. mytaglist[s],
  640. spacer,
  641. gmailwidget,
  642. spacer,
  643. mpdicon,
  644. music_play,
  645. music_pause,
  646. music_stop,
  647. music_prev,
  648. music_next,
  649. spacer,
  650. spacer,
  651. spacer,
  652. spacer,
  653. mpdwidget,
  654. spacer,
  655. mypromptbox[s],
  656. layout = awful.widget.layout.horizontal.leftright,
  657. },
  658. mylayoutbox[s],
  659. mytextclock,
  660. my_cal.widget,
  661. netwidget,
  662. neticon,
  663. mymem,
  664. mymemicon,
  665. mycpuload,
  666. mycpuloadicon,
  667. wlanwidget,
  668. wlanicon,
  669. mybat,
  670. mybaticon,
  671. myvol,
  672. myvolicon,
  673.  
  674. s == 1 or nil,
  675. layout = awful.widget.layout.horizontal.rightleft
  676. }
  677.  
  678.  
  679. -- bottom
  680. mywib[s] = awful.wibox({ position = "bottom", screen = s})
  681.  
  682.  
  683. mywib[s].widgets = {
  684. -- s == 1 and mysystray or nil,
  685. mysystray,
  686. mytasklist[s],
  687.  
  688. layout = awful.widget.layout.horizontal.rightleft
  689.  
  690. }
  691. end
  692.  
  693.  
  694. -- mouse binds
  695. root.buttons(awful.util.table.join(
  696. awful.button({ }, 3, function () mymainmenu:toggle() end),
  697. awful.button({ }, 4, awful.tag.viewnext),
  698. awful.button({ }, 5, awful.tag.viewprev)
  699. ))
  700.  
  701.  
  702. -- key binds
  703. globalkeys = awful.util.table.join(
  704. awful.key({ "Control" }, "Left", awful.tag.viewprev ),
  705. awful.key({ "Control" }, "Right", awful.tag.viewnext ),
  706. awful.key({ "Control" }, "Escape", awful.tag.history.restore),
  707. awful.key({}, "#122", function () sexec("sh ~/bin/vol.sh down" ) end),
  708. awful.key({}, "#123", function () sexec("sh ~/bin/vol.sh up") end),
  709. awful.key({}, "#121", function () sexec("sh ~/bin/vol.sh mute") end),
  710. awful.key({}, "#233", function () sexec("sh ~/bin/bright.sh") end),
  711. awful.key({}, "#232", function () sexec("sh ~/bin/bright.sh") end),
  712. awful.key({ altkey, }, "Tab",
  713. function ()
  714. awful.client.focus.byidx( 1)
  715. if client.focus then client.focus:raise() end
  716. end),
  717. awful.key({ altkey, }, "k",
  718. function ()
  719. awful.client.focus.byidx(-1)
  720. if client.focus then client.focus:raise() end
  721. end),
  722. awful.key({ modkey, }, "w", function () mymainmenu:show({keygrabber=true}) end),
  723.  
  724. -- Layout manipulation
  725. awful.key({ modkey }, "Tab", function () awful.client.swap.byidx( 1) end),
  726. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
  727. awful.key({ altkey }, "j", function () awful.screen.focus_relative( 1) end),
  728. awful.key({ altkey }, "k", function () awful.screen.focus_relative(-1) end),
  729. awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
  730. awful.key({ modkey, }, "Tab",
  731. function ()
  732. awful.client.focus.history.previous()
  733. if client.focus then
  734. client.focus:raise()
  735. end
  736. end),
  737.  
  738. -- Standard program
  739. awful.key({ "Control" }, "y", function () awful.util.spawn(terminal) end),
  740. awful.key({ modkey, "Control" }, "r", awesome.restart),
  741. -- awful.key({ modkey, "Shift" }, "q", awesome.quit),
  742. awful.key({ }, "F1", function () exec("dwb") end),
  743. -- awful.key({ }, "F1", function () run_or_raise("dwb", { class = "Dwb" }) end),
  744. awful.key({ }, "F8", function () run_or_raise("firefox", { class = "Firefox" }) end),
  745. awful.key({}, "#160", function () exec("slimlock") end),
  746. awful.key({}, "#150", function () sexec("sudo pm-suspend") end),
  747.  
  748. awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  749. awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  750. awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  751. awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  752. awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
  753. awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
  754. awful.key({ "Control", }, "space", function () awful.layout.inc(layouts, 1) end),
  755. awful.key({ modkey }, "space", function () awful.layout.inc(layouts, -1) end),
  756.  
  757. awful.key({ modkey, "Control" }, "n", awful.client.restore),
  758.  
  759. -- Prompt
  760. awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
  761.  
  762. awful.key({ modkey }, "x",
  763. function ()
  764. awful.prompt.run({ prompt = "Run Lua code: " },
  765. mypromptbox[mouse.screen].widget,
  766. awful.util.eval, nil,
  767. awful.util.getdir("cache") .. "/history_eval")
  768. end)
  769. )
  770.  
  771. clientkeys = awful.util.table.join(
  772. awful.key({ altkey }, "m", function (c) c.fullscreen = not c.fullscreen end),
  773. awful.key({ "Control" }, "q", function (c) c:kill() end),
  774. awful.key({ altkey }, "d", awful.client.floating.toggle ),
  775. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  776. awful.key({ modkey, }, "o", awful.client.movetoscreen ),
  777. awful.key({ altkey, }, "t", function (c) c.ontop = not c.ontop end),
  778. awful.key({ altkey }, "n",
  779. function (c)
  780. -- The client currently has the input focus, so it cannot be
  781. -- minimized, since minimized clients can't have the focus.
  782. c.minimized = true
  783. end),
  784. awful.key({ altkey }, "f",
  785. function (c)
  786. c.maximized_horizontal = not c.maximized_horizontal
  787. c.maximized_vertical = not c.maximized_vertical
  788. end)
  789. )
  790.  
  791. -- Compute the maximum number of digit we need, limited to 9
  792. keynumber = 0
  793. for s = 1, screen.count() do
  794. keynumber = math.min(9, math.max(#tags[s], keynumber));
  795. end
  796.  
  797. -- Bind all key numbers to tags.
  798. -- Be careful: we use keycodes to make it works on any keyboard layout.
  799. -- This should map on the top row of your keyboard, usually 1 to 9.
  800. for i = 1, keynumber do
  801. globalkeys = awful.util.table.join(globalkeys,
  802. awful.key({ "Control" }, "#" .. i + 9,
  803. function ()
  804. local screen = mouse.screen
  805. if tags[screen][i] then
  806. awful.tag.viewonly(tags[screen][i])
  807. end
  808. end),
  809. awful.key({ modkey, "Control" }, "#" .. i + 9,
  810. function ()
  811. local screen = mouse.screen
  812. if tags[screen][i] then
  813. awful.tag.viewtoggle(tags[screen][i])
  814. end
  815. end),
  816. awful.key({ altkey }, "#" .. i + 9,
  817. function ()
  818. if client.focus and tags[client.focus.screen][i] then
  819. awful.client.movetotag(tags[client.focus.screen][i])
  820. end
  821. end),
  822. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  823. function ()
  824. if client.focus and tags[client.focus.screen][i] then
  825. awful.client.toggletag(tags[client.focus.screen][i])
  826. end
  827. end))
  828. end
  829.  
  830. clientbuttons = awful.util.table.join(
  831. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  832. awful.button({ altkey }, 1, awful.mouse.client.move),
  833. awful.button({ altkey }, 3, awful.mouse.client.resize))
  834.  
  835. root.keys(globalkeys)
  836.  
  837.  
  838.  
  839. -- rules
  840.  
  841. awful.rules.rules = {
  842. -- All clients will match this rule.
  843. { rule = { },
  844. properties = { border_width = beautiful.border_width,
  845. border_color = beautiful.border_normal,
  846. focus = true,
  847. keys = clientkeys,
  848. buttons = clientbuttons } },
  849.  
  850.  
  851. { rule = { class = "gimp" },
  852. properties = { floating = true } },
  853. -- Set Firefox to always map on tags number 2 of screen 1.
  854. { rule = { class = "Firefox" },
  855. properties = { tag = tags[1][2] } },
  856.  
  857.  
  858. -- 1: sys
  859.  
  860.  
  861.  
  862. -- 2: web
  863.  
  864. { rule = { class = "Firefox" },
  865. except = { instance = "Navigator" },
  866. properties = { tag = tags[1][2], floating = true, switchtotag = true },
  867. -- callback = awful.placement.centered
  868.  
  869.  
  870. },
  871. { rule = { class = "Firefox", instance = "Navigator" },
  872. properties = { tag = tags[1][2], switchtotag = true }
  873. },
  874.  
  875. { rule = { class = "Firefox", instance = "Dialog" },
  876. properties = { tag = tags[1][2], switchtotag = true }
  877. },
  878. { rule = { class = "Midori" },
  879. properties = { tag = tags[1][2], switchtotag = true }
  880. },
  881. { rule = { class = "Dwb" },
  882. properties = { tag = tags[1][2], switchtotag = true }
  883. },
  884.  
  885.  
  886.  
  887. -- 3: doc
  888. { rule = { class = ".*[Mm]edit.*", name = ".*[Mm]edit.*", instance = ".*[Mm]edit.*" },
  889. except = { name = "Find" },
  890. properties = { tag = tags[1][3], switchtotag = true }
  891. },
  892. { rule = { class = "medit" },
  893. except = { name = "Find" },
  894. properties = { tag = tags[1][3], switchtotag = true }
  895. },
  896. { rule = { instance = "medit" },
  897. except = { name = "Find" },
  898. properties = { tag = tags[1][3], switchtotag = true }
  899. },
  900. { rule = { instance = "medit.*" },
  901. except = { name = "Find" },
  902. properties = { tag = tags[1][3], switchtotag = true }
  903. },
  904. { rule = { name = "^medit\ %-.*" },
  905. except = { name = "Find" },
  906. properties = { tag = tags[1][3], switchtotag = true }
  907. },
  908. { rule = { name = "medit.*" },
  909. except = { name = "Find" },
  910. properties = { tag = tags[1][3], switchtotag = true }
  911. },
  912.  
  913. { rule = { class = "epdfview" },
  914. properties = { tag = tags[1][3], switchtotag = true }
  915. },
  916. { rule = { class = "Epdfview" },
  917. properties = { tag = tags[1][3], switchtotag = true }
  918. },
  919. { rule = { class = "zathura" },
  920. properties = { tag = tags[1][3], switchtotag = true }
  921. },
  922. { rule = { class = "Zathura" },
  923. properties = { tag = tags[1][3], switchtotag = true }
  924. },
  925.  
  926.  
  927.  
  928. -- 4: dev
  929.  
  930. { rule = { class = "NetBeans" },
  931. properties = { tag = tags[1][4], switchtotag = true }
  932. },
  933. { rule = { class = "netbeans" },
  934. properties = { tag = tags[1][4], switchtotag = true }
  935. },
  936.  
  937. { rule = { class = "sun-awt-X11-XFramePeer" },
  938. properties = { tag = tags[1][4], switchtotag = true }
  939. },
  940. { rule = { class = "java-lang-Thread" },
  941. properties = { tag = tags[1][4], switchtotag = true }
  942. },
  943. { rule = { class = "Eclipse" },
  944. properties = { tag = tags[1][4], switchtotag = true }
  945. },
  946.  
  947.  
  948.  
  949. -- 5: irc
  950.  
  951. -- 6: foo
  952.  
  953. { rule = { class = "Mplayer" },
  954. properties = { tag = tags[1][6], switchtotag = true }
  955. },
  956. { rule = { class = "mplayer" },
  957. properties = { tag = tags[1][6], switchtotag = true }
  958. },
  959.  
  960.  
  961.  
  962. }
  963. -- }}}
  964.  
  965. -- {{{ Signals
  966. -- Signal function to execute when a new client appears.
  967. client.add_signal("manage", function (c, startup)
  968. -- Add a titlebar
  969. -- awful.titlebar.add(c, { modkey = modkey })
  970.  
  971. -- Enable sloppy focus
  972. c:add_signal("mouse::enter", function(c)
  973. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  974. and awful.client.focus.filter(c) then
  975. client.focus = c
  976. end
  977. end)
  978.  
  979. if not startup then
  980. -- Set the windows at the slave,
  981. -- i.e. put it at the end of others instead of setting it master.
  982. -- awful.client.setslave(c)
  983.  
  984. -- Put windows in a smart way, only if they does not set an initial position.
  985. if not c.size_hints.user_position and not c.size_hints.program_position then
  986. awful.placement.no_overlap(c)
  987. awful.placement.no_offscreen(c)
  988. end
  989. end
  990. end)
  991.  
  992. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  993. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  994. -- }}}
  995.  
  996.  
  997. -- mcabber notifcation wrapper (gettin jabber msgs & statusupdates via naughty)
  998.  
  999. naughty.config.presets.online = {
  1000. bg = "#1f880e80",
  1001. fg = "#ffffff",
  1002. }
  1003. naughty.config.presets.chat = naughty.config.presets.online
  1004. naughty.config.presets.away = {
  1005. bg = "#eb4b1380",
  1006. fg = "#ffffff",
  1007. }
  1008. naughty.config.presets.xa = {
  1009. bg = "#65000080",
  1010. fg = "#ffffff",
  1011. }
  1012. naughty.config.presets.dnd = {
  1013. bg = "#65340080",
  1014. fg = "#ffffff",
  1015. }
  1016. naughty.config.presets.invisible = {
  1017. bg = "#ffffff80",
  1018. fg = "#000000",
  1019. }
  1020. naughty.config.presets.offline = {
  1021. bg = "#64636380",
  1022. fg = "#ffffff",
  1023. }
  1024. naughty.config.presets.requested = naughty.config.presets.offline
  1025. naughty.config.presets.error = {
  1026. bg = "#ff000080",
  1027. fg = "#ffffff",
  1028. }
  1029.  
  1030. muc_nick = "intrntbrn"
  1031.  
  1032. function mcabber_event_hook(kind, direction, jid, msg)
  1033. if kind == "MSG" then
  1034. if direction == "IN" or direction == "MUC" then
  1035. local filehandle = io.open(msg)
  1036. local txt = filehandle:read("*all")
  1037. filehandle:close()
  1038. awful.util.spawn("rm "..msg)
  1039. if direction == "MUC" and txt:match("^<" .. muc_nick .. ">") then
  1040. return
  1041. end
  1042. naughty.notify{
  1043. -- icon = "chat_msg_recv",
  1044. text = awful.util.escape(txt),
  1045. title = jid
  1046. }
  1047. end
  1048. elseif kind == "STATUS" then
  1049. local mapping = {
  1050. [ "O" ] = "online",
  1051. [ "F" ] = "chat",
  1052. [ "A" ] = "away",
  1053. [ "N" ] = "xa",
  1054. [ "D" ] = "dnd",
  1055. [ "I" ] = "invisible",
  1056. [ "_" ] = "offline",
  1057. [ "?" ] = "error",
  1058. [ "X" ] = "requested"
  1059. }
  1060. local status = mapping[direction]
  1061. local iconstatus = status
  1062. if not status then
  1063. status = "error"
  1064. end
  1065. if jid:match("icq") then
  1066. iconstatus = "icq/" .. status
  1067. end
  1068. naughty.notify{
  1069. preset = naughty.config.presets[status],
  1070. text = jid,
  1071. -- icon = iconstatus
  1072. }
  1073. end
  1074. end
  1075.  
  1076. -- RUN OR RAISE
  1077.  
  1078. --- Spawns cmd if no client can be found matching properties
  1079. -- If such a client can be found, pop to first tag where it is visible, and give it focus
  1080. -- @param cmd the command to execute
  1081. -- @param properties a table of properties to match against clients. Possible entries: any properties of the client object
  1082. function run_or_raise(cmd, properties)
  1083. local clients = client.get()
  1084. local focused = awful.client.next(0)
  1085. local findex = 0
  1086. local matched_clients = {}
  1087. local n = 0
  1088. for i, c in pairs(clients) do
  1089. --make an array of matched clients
  1090. if match(properties, c) then
  1091. n = n + 1
  1092. matched_clients[n] = c
  1093. if c == focused then
  1094. findex = n
  1095. end
  1096. end
  1097. end
  1098. if n > 0 then
  1099. local c = matched_clients[1]
  1100. -- if the focused window matched switch focus to next in list
  1101. if 0 < findex and findex < n then
  1102. c = matched_clients[findex+1]
  1103. end
  1104. local ctags = c:tags()
  1105. if table.getn(ctags) == 0 then
  1106. -- ctags is empty, show client on current tag
  1107. local curtag = awful.tag.selected()
  1108. awful.client.movetotag(curtag, c)
  1109. else
  1110. -- Otherwise, pop to first tag client is visible on
  1111. awful.tag.viewonly(ctags[1])
  1112. end
  1113. -- And then focus the client
  1114. client.focus = c
  1115. c:raise()
  1116. return
  1117. end
  1118. awful.util.spawn(cmd)
  1119. end
  1120.  
  1121. -- Returns true if all pairs in table1 are present in table2
  1122. function match (table1, table2)
  1123. for k, v in pairs(table1) do
  1124. if table2[k] ~= v and not table2[k]:find(v) then
  1125. return false
  1126. end
  1127. end
  1128. return true
  1129. end
  1130.  
  1131.  
  1132. -- disable startup-notification globally
  1133. local oldspawn = awful.util.spawn
  1134. awful.util.spawn = function (s)
  1135. oldspawn(s, false)
  1136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement