Guest User

Untitled

a guest
Jul 9th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.83 KB | None | 0 0
  1. -- Standard awesome library
  2. require("awful")
  3. -- Theme handling library
  4. require("beautiful")
  5. -- Notification library
  6. require("naughty")
  7. -- Wicked widgets library
  8. require("wicked")
  9.  
  10. awful.util.spawn("wmname LG3D") -- fool Java apps into working :)
  11.  
  12. ---------------
  13. -- Variables --
  14. ---------------
  15.  
  16. theme_path = "/home/baddog/.config/awesome/themes/default/theme.lua"
  17. icon_dir = "/home/baddog/.config/awesome/icons/"
  18.  
  19. beautiful.init(theme_path)
  20.  
  21. terminal = "urxvt"
  22. editor = os.getenv("EDITOR") or "vim"
  23. editor_cmd = terminal .. " -e " .. editor
  24.  
  25. modkey = "Mod4"
  26.  
  27. layouts =
  28. {
  29. awful.layout.suit.tile,
  30. awful.layout.suit.tile.left,
  31. awful.layout.suit.tile.bottom,
  32. awful.layout.suit.tile.top,
  33. awful.layout.suit.fair,
  34. awful.layout.suit.fair.horizontal,
  35. awful.layout.suit.max,
  36. awful.layout.suit.max.fullscreen,
  37. awful.layout.suit.magnifier,
  38. awful.layout.suit.floating
  39. }
  40.  
  41. floatapps =
  42. {
  43. ["Browser"] = true, -- firefox dialog windows
  44. ["Sonata"]= true,
  45. ["Dragon"] = true,
  46. ["MPlayer"] = true,
  47. ["VLC media player"] = true,
  48. ["gimp"] = true,
  49. ["pidgin"] = true
  50. }
  51.  
  52. apptags =
  53. {
  54. -- ["Firefox"] = { screen = 1, tag = 2 },
  55. -- ["mocp"] = { screen = 2, tag = 4 },
  56. }
  57.  
  58. use_titlebar = true
  59.  
  60. ----------
  61. -- Tags --
  62. ----------
  63.  
  64. tags = {}
  65. for s = 1, screen.count() do
  66. -- Each screen has its own tag table.
  67. tags[s] = {}
  68. -- Create 9 tags per screen.
  69. for tagnumber = 1, 9 do
  70. tags[s][tagnumber] = tag(tagnumber)
  71. -- Add tags to screen one by one
  72. tags[s][tagnumber].screen = s
  73. awful.layout.set(layouts[1], tags[s][tagnumber])
  74. end
  75. -- I'm sure you want to see at least one tag.
  76. tags[s][1].selected = true
  77. end
  78.  
  79. ---------------
  80. -- Functions --
  81. ---------------
  82.  
  83. function title(t)
  84. return '<span color="white"><b>'..t..': </b></span>'
  85. end
  86.  
  87. function alert(a)
  88. return '<span color="orange"><b>'..a..'</b></span>'
  89. end
  90.  
  91. function color(str, color)
  92. return '<span color="'..color..'">'..str..'</span>'
  93. end
  94.  
  95. function dec2hex(s)
  96. s = string.format("%02x", s)
  97. return s
  98. end
  99.  
  100. function gradient(min, max, val)
  101. val = tonumber(val)
  102. if (val > max) then val = max end
  103. if (val < min) then val = min end
  104.  
  105. local v = val - min
  106. local d = (max - min) * 0.45
  107. local r, g
  108.  
  109. if (v <= d) then
  110. r = 255 * math.pow(v / d, 0.7)
  111. g = 255
  112. else
  113. r = 255
  114. g = 255 - (255 * math.pow((v-d) / ((max - min)-d), 0.7))
  115. end
  116.  
  117. return "#"..dec2hex(tostring(r))..dec2hex(tostring(g)).."00"
  118. end
  119.  
  120. function cputemp(core)
  121. local command = "sensors | grep 'Core "..tostring(core).."'"
  122. local cpu = io.popen(command):read("*all")
  123.  
  124. if (cpu == nil) then
  125. return ''
  126. end
  127.  
  128. local pos = cpu:find('+')+1
  129. cpu = string.sub(cpu, pos, pos+3)
  130. return cpu
  131. end
  132.  
  133. function log(var)
  134. local log = io.open("/home/scott/.awesome_log", "a")
  135. log:write(os.date("%c\t")..tostring(var).."\n")
  136. log:close()
  137. end
  138.  
  139. -- For the volume widget/keybindings
  140. cardid = 0
  141. channel = "Master"
  142. function volume (mode, widget)
  143. if mode == "update" then
  144. local fd = io.popen("amixer -c " .. cardid .. " -- sget " .. channel)
  145. local status = fd:read("*all")
  146. fd:close()
  147.  
  148. local volume = string.match(status, "(%d?%d?%d)%%")
  149. volume = string.format("%d", volume)
  150. local val = tonumber(volume)
  151.  
  152. status = string.match(status, "%[(o[^%]]*)%]")
  153.  
  154. if string.find(status, "on", 1, true) then
  155. volume = volume .. "%"
  156. else
  157. volume = volume .. "M"
  158. end
  159. widget.text = title("VOL")..color(string.gsub(volume, ' ', ''), gradient(0, 100, val))
  160.  
  161. elseif mode == "up" then
  162. io.popen("amixer -q -c " .. cardid .. " sset " .. channel .. " 5%+"):read("*all")
  163. volume("update", widget)
  164. elseif mode == "down" then
  165. io.popen("amixer -q -c " .. cardid .. " sset " .. channel .. " 5%-"):read("*all")
  166. volume("update", widget)
  167. else
  168. io.popen("amixer -c " .. cardid .. " sset " .. channel .. " toggle"):read("*all")
  169. volume("update", widget)
  170. end
  171. end
  172.  
  173.  
  174. -- For MPD widget/keybindings
  175. mpd_host = 'localhost' -- unused
  176. mpd_port = 6600 -- unused
  177. function mpd (mode, widget, image_widget)
  178. if mode == "update" then
  179. local fd = io.popen("mpc")
  180. local status = fd:read("*all")
  181. fd:close()
  182.  
  183. if status:find("Connection refused") then
  184. widget.text = "Not running"
  185. image_widget.image = nil
  186. elseif status:find("playing") then
  187. current_song = status:match("[^\n]*") -- gets the first line
  188. widget.text = " "..awful.util.escape(current_song)
  189. image_widget.image = image(icon_dir.."robs/play.png")
  190. elseif status:find("paused") then
  191. current_song = status:match("[^\n]*") -- gets the first line
  192. widget.text = " "..awful.util.escape(current_song)
  193. image_widget.image = image(icon_dir.."robs/pause.png")
  194. else -- stopped
  195. widget.text = "Stopped"
  196. image_widget.image = nil
  197. end
  198. elseif mode == "toggle" then
  199. io.popen("mpc toggle")
  200. mpd("update", widget, image_widget)
  201. elseif mode == "stop" then
  202. io.popen("mpc stop")
  203. mpd("update", widget, image_widget)
  204. elseif mode == "next" then
  205. io.popen("mpc next")
  206. mpd("update", widget, image_widget)
  207. elseif mode == "prev" then
  208. io.popen("mpc prev")
  209. mpd("update", widget, image_widget)
  210. end
  211. end
  212.  
  213.  
  214. function amarok_dbus (method)
  215. return io.popen("qdbus org.kde.amarok /Player " .. method)
  216. end
  217.  
  218. function amarok (mode, widget)
  219. if mode == "toggle" then
  220. amarok_dbus("Pause")
  221. elseif mode == "stop" then
  222. amarok_dbus("Stop")
  223. elseif mode == "next" then
  224. amarok_dbus("Next")
  225. elseif mode == "prev" then
  226. amarok_dbus("Prev")
  227. end
  228.  
  229. local fd = io.popen("ruby /data/Code/Ruby/amarok2-np.rb -- --no-time")
  230. local status = fd:read("*all")
  231. fd:close()
  232.  
  233. if status:match("^$") then
  234. widget.text = "Stopped"
  235. else
  236. widget.text = awful.util.escape(status:match("[^\n]*"))
  237. end
  238. end
  239.  
  240. -------------
  241. -- Widgets --
  242. -------------
  243.  
  244. -- Menu
  245. awesomemenu = {
  246. { "manual", terminal .. " -e man awesome" },
  247. { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
  248. { "restart", awesome.restart },
  249. { "quit", awesome.quit }
  250. }
  251.  
  252. mainmenu = awful.menu.new({ items = {
  253. { "open terminal", terminal },
  254. { "awesome", awesomemenu, beautiful.awesome_icon }
  255. }})
  256.  
  257. menulauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
  258. menu = mainmenu })
  259.  
  260. -- Layout Box
  261. layoutbox = widget({ type = "imagebox", align = "right" })
  262. layoutbox:buttons({ button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  263. button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  264. button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  265. button({ }, 5, function () awful.layout.inc(layouts, -1) end) })
  266.  
  267. -- Tag List
  268. taglist = awful.widget.taglist.new(1, awful.widget.taglist.label.all,
  269. { button({ }, 1, awful.tag.viewonly),
  270. button({ modkey }, 1, awful.client.movetotag),
  271. button({ }, 3, function (tag) tag.selected = not tag.selected end),
  272. button({ modkey }, 3, awful.client.toggletag),
  273. button({ }, 4, awful.tag.viewnext),
  274. button({ }, 5, awful.tag.viewprev) })
  275.  
  276. -- Prompt Box
  277. promptbox = widget({ type = "textbox", align = "left" })
  278.  
  279. -- Status Monitors
  280. -- Volume
  281. tb_volume = widget({ type = "textbox", name = "tb_volume", align = "right" })
  282. tb_volume:buttons({
  283. button({ }, 4, function () volume("up", tb_volume) end),
  284. button({ }, 5, function () volume("down", tb_volume) end),
  285. button({ }, 1, function () volume("mute", tb_volume) end)
  286. })
  287. volume("update", tb_volume)
  288.  
  289. -- RAM Usage
  290. memwidget = widget({
  291. type = 'textbox',
  292. name = 'memwidget',
  293. align = 'right'
  294. })
  295.  
  296. wicked.register(memwidget, wicked.widgets.mem, title("MEM")..'$2MB/$3MB')
  297.  
  298. -- Net Usage
  299. nettitle = widget({ type = "textbox", name = "titlebox", align = "right" })
  300. -- I remove the space from the title because the image after it provides enough space
  301. nettitle.text = string.gsub(title("NET"), ': ', ':')
  302.  
  303. netupiconbox = widget({ type = "imagebox", name = "netupiconbox", align = "right" })
  304. netupiconbox.image = image(icon_dir..'up.png')
  305. netupwidget = widget({
  306. type = 'textbox',
  307. name = 'netupwidget',
  308. align = 'right'
  309. })
  310.  
  311. wicked.register(netupwidget, wicked.widgets.net, '${eth0 up_kb} KB', 1, nil, 3)
  312.  
  313. netdowniconbox = widget({ type = "imagebox", name = "netdowniconbox", align = "right" })
  314. netdowniconbox.image = image(icon_dir..'down.png')
  315. netdownwidget = widget({
  316. type = 'textbox',
  317. name = 'netdownwidget',
  318. align = 'right'
  319. })
  320.  
  321. wicked.register(netdownwidget, wicked.widgets.net, '${eth0 down_kb} KB', 1, nil, 3)
  322.  
  323. -- CPU Usage
  324. cputextwidget = widget({
  325. type = 'textbox',
  326. name = 'cputextwidget',
  327. align = 'right'
  328. })
  329.  
  330. wicked.register(cputextwidget, wicked.widgets.cpu, function(widget, args)
  331. cpuinfo = title("CPU")
  332. cpuinfo = color(cpuinfo..'['..args[2]..'%] ', gradient(0, 100, args[2]))
  333. cpuinfo = color(cpuinfo..'['..args[3]..'%] ', gradient(0, 100, args[3]))
  334. return cpuinfo
  335. end, 1, nil, 2)
  336.  
  337. -- cpu graph
  338. cpugraphwidget = widget({
  339. type = 'graph',
  340. name = 'cpugraphwidget',
  341. align = 'right'
  342. })
  343.  
  344. cpugraphwidget.height = 0.8
  345. cpugraphwidget.width = 60
  346. cpugraphwidget.bg = beautiful.bg_normal
  347. cpugraphwidget.border_color = beautiful.fg_normal
  348. cpugraphwidget.grow = 'left'
  349.  
  350. cpugraphwidget:plot_properties_set('cpu', {
  351. fg = fg_normal,
  352. fg_center = beautiful.border_focus,
  353. fg_end = beautiful.border_normal,
  354. vertical_gradient = false
  355. })
  356.  
  357. wicked.register(cpugraphwidget, wicked.widgets.cpu, '$1', 1, 'cpu')
  358.  
  359.  
  360. -- Load Average
  361. loadwidget = widget({
  362. type = 'textbox',
  363. name = 'loadwidget',
  364. align = 'right'
  365. })
  366.  
  367. wicked.register(loadwidget, 'function', function (widget, args)
  368. -- Use /proc/loadavg to get the average system load on 1, 5 and 15 minute intervals
  369. local f = io.open('/proc/loadavg')
  370. local n = f:read()
  371. f:close()
  372.  
  373. -- Find the third space
  374. local pos = n:find(' ', n:find(' ', n:find(' ')+1)+1)
  375.  
  376. return title('LOAD')..n:sub(1,pos-1)
  377.  
  378. end, 2)
  379.  
  380.  
  381. -- Filesystems
  382. fswidget = widget({
  383. type = 'textbox',
  384. name = 'fswidget',
  385. align = 'right'
  386. })
  387.  
  388. wicked.register(fswidget, wicked.widgets.fs,
  389. title("FS")..color('/ [${/ used}|${/ size}]', "green")..color(' /data [${/data used}|${/data size}]',"yellow"),
  390. 10)
  391.  
  392.  
  393. -- MPD
  394. mpd_title = widget({ type = "textbox", align = "right" })
  395. mpd_title.text = title("MPD")
  396. mpd_image = widget({ type = "imagebox", align = "right" })
  397. mpd_text = widget({ type = "textbox", align = "right" })
  398.  
  399. mpd("update", mpd_text, mpd_image)
  400.  
  401.  
  402. -- Amarok
  403. amarok_title = widget({ type = "textbox", align = "right" })
  404. amarok_title.text = title("MUSIC")
  405. amarok_text = widget({ type = "textbox", align = "right" })
  406.  
  407. -- amarok("update", amarok_text)
  408.  
  409. -- Clock
  410. clock = widget({ type = "textbox", align = "right" })
  411. wicked.register(clock, wicked.widgets.date, '%a %b %d, %H:%M')
  412.  
  413. -- System Tray
  414. systray = widget({ type = "systray", align = "right" })
  415.  
  416. -- Spacer
  417. spacer = widget({ type = "imagebox", name = "spacer", align = "right" })
  418. spacer.image = image(icon_dir..'spacer.png')
  419.  
  420. -- create the wibox and assign widgets - only on screen one, at the bottom
  421. bottom_wibox = wibox({ position = "bottom", fg = beautiful.fg_normal,
  422. bg = beautiful.bg_normal })
  423. bottom_wibox.widgets =
  424. {
  425. menulauncher,
  426. taglist,
  427. promptbox,
  428. ----------
  429. mpd_title, mpd_image, mpd_text, spacer,
  430. -- amarok_title, amarok_text, spacer,
  431. --fswidget, spacer,
  432. nettitle,
  433. netupiconbox, netupwidget,
  434. netdowniconbox, netdownwidget, spacer,
  435. cputextwidget, cpugraphwidget, spacer,
  436. memwidget, spacer,
  437. tb_volume, spacer,
  438. clock, spacer,
  439. systray,
  440. loadaverage,
  441. layoutbox
  442. }
  443. bottom_wibox.screen = 1
  444.  
  445. -- Task Lists - one per screen, at the top
  446. top_wibox = {}
  447. tasklist = {}
  448. for s=1, screen.count() do
  449. tasklist[s] = awful.widget.tasklist.new(
  450. function(c)
  451. return awful.widget.tasklist.label.currenttags(c, s)
  452. end,
  453. { button({ }, s,
  454. function (c)
  455. if not c:isvisible() then
  456. awful.tag.viewonly(c:tags()[s])
  457. end
  458. client.focus = c
  459. c:raise()
  460. end),
  461. button({ }, 3,
  462. function ()
  463. if instance then instance:hide() end
  464. instance = awful.menu.clients({ width=250 })
  465. end),
  466. button({ }, 4,
  467. function ()
  468. awful.client.focus.byidx(1)
  469. if client.focus then client.focus:raise() end
  470. end),
  471. button({ }, 5,
  472. function ()
  473. awful.client.focus.byidx(-1)
  474. if client.focus then client.focus:raise() end
  475. end)
  476. })
  477.  
  478. top_wibox[s] = wibox({ position = "top", fg = beautiful.fg_normal,
  479. bg = beautiful.bg_normal })
  480. top_wibox[s].widgets = { tasklist[s] }
  481. top_wibox[s].screen = s
  482. end
  483.  
  484. --------------------
  485. -- Mouse Bindings --
  486. --------------------
  487.  
  488. root.buttons({
  489. button({ }, 3, function () mainmenu:toggle() end),
  490. button({ }, 4, awful.tag.viewnext),
  491. button({ }, 5, awful.tag.viewprev)
  492. })
  493.  
  494. ------------------
  495. -- Key Bindings --
  496. ------------------
  497.  
  498. globalkeys =
  499. {
  500. key({ modkey, }, "Left", awful.tag.viewprev ),
  501. key({ modkey, }, "Right", awful.tag.viewnext ),
  502. key({ modkey, }, "Escape", awful.tag.history.restore),
  503.  
  504. key({ modkey, }, "j",
  505. function ()
  506. awful.client.focus.byidx( 1)
  507. if client.focus then client.focus:raise() end
  508. end),
  509. key({ modkey, }, "k",
  510. function ()
  511. awful.client.focus.byidx(-1)
  512. if client.focus then client.focus:raise() end
  513. end),
  514.  
  515. -- Layout manipulation
  516. key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
  517. key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
  518. key({ modkey, "Control" }, "j", function () awful.screen.focus( 1) end),
  519. key({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end),
  520. key({ modkey, }, "u", awful.client.urgent.jumpto),
  521. key({ modkey, }, "Tab",
  522. function ()
  523. awful.client.focus.history.previous()
  524. if client.focus then
  525. client.focus:raise()
  526. end
  527. end),
  528.  
  529. -- Standard program
  530. key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
  531. key({ modkey, "Control" }, "r", awesome.restart),
  532. key({ modkey, "Shift" }, "q", awesome.quit),
  533.  
  534. key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  535. key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  536. key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  537. key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  538. key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
  539. key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
  540. key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
  541. key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
  542.  
  543. -- Prompt
  544. key({ modkey }, "F1",
  545. function ()
  546. awful.prompt.run({ prompt = "Run: " },
  547. promptbox,
  548. awful.util.spawn, awful.completion.bash,
  549. awful.util.getdir("cache") .. "/history")
  550. end),
  551.  
  552. key({ modkey }, "F4",
  553. function ()
  554. awful.prompt.run({ prompt = "Run Lua code: " },
  555. promptbox,
  556. awful.util.eval, awful.prompt.bash,
  557. awful.util.getdir("cache") .. "/history_eval")
  558. end),
  559. }
  560.  
  561. -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
  562. clientkeys =
  563. {
  564. key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
  565. key({ modkey, "Shift" }, "c", function (c) c:kill() end),
  566. key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
  567. key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  568. key({ modkey, }, "o", awful.client.movetoscreen ),
  569. key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
  570. key({ modkey }, "t", awful.client.togglemarked),
  571. key({ modkey,}, "m",
  572. function (c)
  573. c.maximized_horizontal = not c.maximized_horizontal
  574. c.maximized_vertical = not c.maximized_vertical
  575. end),
  576. }
  577.  
  578. -- Tag keybindings
  579. -- Compute the maximum number of digit we need, limited to 9
  580. keynumber = 0
  581. for s = 1, screen.count() do
  582. keynumber = math.min(9, math.max(#tags[s], keynumber));
  583. end
  584.  
  585. for i = 1, keynumber do
  586. table.insert(globalkeys,
  587. key({ modkey }, i,
  588. function ()
  589. local screen = mouse.screen
  590. if tags[screen][i] then
  591. awful.tag.viewonly(tags[screen][i])
  592. end
  593. end))
  594. table.insert(globalkeys,
  595. key({ modkey, "Control" }, i,
  596. function ()
  597. local screen = mouse.screen
  598. if tags[screen][i] then
  599. tags[screen][i].selected = not tags[screen][i].selected
  600. end
  601. end))
  602. table.insert(globalkeys,
  603. key({ modkey, "Shift" }, i,
  604. function ()
  605. if client.focus and tags[client.focus.screen][i] then
  606. awful.client.movetotag(tags[client.focus.screen][i])
  607. end
  608. end))
  609. table.insert(globalkeys,
  610. key({ modkey, "Control", "Shift" }, i,
  611. function ()
  612. if client.focus and tags[client.focus.screen][i] then
  613. awful.client.toggletag(tags[client.focus.screen][i])
  614. end
  615. end))
  616. end
  617.  
  618.  
  619. for i = 1, keynumber do
  620. table.insert(globalkeys, key({ modkey, "Shift" }, "F" .. i,
  621. function ()
  622. local screen = mouse.screen
  623. if tags[screen][i] then
  624. for k, c in pairs(awful.client.getmarked()) do
  625. awful.client.movetotag(tags[screen][i], c)
  626. end
  627. end
  628. end))
  629. end
  630.  
  631. -- Volume keybidings
  632. table.insert(globalkeys, key({ }, "XF86AudioRaiseVolume", function () volume("up", tb_volume) end))
  633. table.insert(globalkeys, key({ }, "XF86AudioLowerVolume", function () volume("down", tb_volume) end))
  634. table.insert(globalkeys, key({ }, "XF86AudioMute", function () volume("mute", tb_volume) end))
  635.  
  636.  
  637. -- MPD keybindings
  638. table.insert(globalkeys, key({ }, "XF86AudioPlay", function () mpd("toggle", mpd_text, mpd_image) end))
  639. table.insert(globalkeys, key({ }, "XF86AudioStop", function () mpd("stop", mpd_text, mpd_image) end))
  640. table.insert(globalkeys, key({ }, "XF86AudioNext", function () mpd("next", mpd_text, mpd_image) end))
  641. table.insert(globalkeys, key({ }, "XF86AudioPrev", function () mpd("prev", mpd_text, mpd_image) end))
  642.  
  643.  
  644. -- Amarok keybindings
  645. -- table.insert(globalkeys, key({ }, "XF86AudioPlay", function () amarok("toggle", amarok_text) end))
  646. -- table.insert(globalkeys, key({ }, "XF86AudioStop", function () amarok("stop", amarok_text) end))
  647. -- table.insert(globalkeys, key({ }, "XF86AudioNext", function () amarok("next", amarok_text) end))
  648. -- table.insert(globalkeys, key({ }, "XF86AudioPrev", function () amarok("prev", amarok_text) end))
  649.  
  650. -- Set keys
  651. root.keys(globalkeys)
  652.  
  653. -----------
  654. -- Hooks --
  655. -----------
  656.  
  657. -- Hook function to execute when focusing a client.
  658. awful.hooks.focus.register(function (c)
  659. if not awful.client.ismarked(c) then
  660. c.border_color = beautiful.border_focus
  661. end
  662. end)
  663.  
  664. -- Hook function to execute when unfocusing a client.
  665. awful.hooks.unfocus.register(function (c)
  666. if not awful.client.ismarked(c) then
  667. c.border_color = beautiful.border_normal
  668. end
  669. end)
  670.  
  671. -- Hook function to execute when marking a client
  672. awful.hooks.marked.register(function (c)
  673. c.border_color = beautiful.border_marked
  674. end)
  675.  
  676. -- Hook function to execute when unmarking a client.
  677. awful.hooks.unmarked.register(function (c)
  678. c.border_color = beautiful.border_focus
  679. end)
  680.  
  681. -- Hook function to execute when the mouse enters a client.
  682. awful.hooks.mouse_enter.register(function (c)
  683. -- Sloppy focus, but disabled for magnifier layout
  684. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  685. and awful.client.focus.filter(c) then
  686. client.focus = c
  687. end
  688. end)
  689.  
  690. -- Hook function to execute when a new client appears.
  691. awful.hooks.manage.register(function (c, startup)
  692. -- If we are not managing this application at startup,
  693. -- move it to the screen where the mouse is.
  694. -- We only do it for filtered windows (i.e. no dock, etc).
  695. if not startup and awful.client.focus.filter(c) then
  696. c.screen = mouse.screen
  697. end
  698.  
  699. if use_titlebar then
  700. -- Add a titlebar
  701. awful.titlebar.add(c, { modkey = modkey })
  702. end
  703. -- Add mouse bindings
  704. c:buttons({
  705. button({ }, 1, function (c) client.focus = c; c:raise() end),
  706. button({ modkey }, 1, awful.mouse.client.move),
  707. button({ modkey }, 3, awful.mouse.client.resize)
  708. })
  709. -- New client may not receive focus
  710. -- if they're not focusable, so set border anyway.
  711. c.border_width = beautiful.border_width
  712. c.border_color = beautiful.border_normal
  713.  
  714. -- Check if the application should be floating.
  715. local cls = c.class
  716. local inst = c.instance
  717. if floatapps[cls] then
  718. awful.client.floating.set(c, floatapps[cls])
  719. elseif floatapps[inst] then
  720. awful.client.floating.set(c, floatapps[inst])
  721. end
  722.  
  723. -- Check application->screen/tag mappings.
  724. local target
  725. if apptags[cls] then
  726. target = apptags[cls]
  727. elseif apptags[inst] then
  728. target = apptags[inst]
  729. end
  730. if target then
  731. c.screen = target.screen
  732. awful.client.movetotag(tags[target.screen][target.tag], c)
  733. end
  734.  
  735. -- Do this after tag mapping, so you don't see it on the wrong tag for a split second.
  736. client.focus = c
  737.  
  738. -- Set key bindings
  739. c:keys(clientkeys)
  740.  
  741. -- Set the windows at the slave,
  742. -- i.e. put it at the end of others instead of setting it master.
  743. -- awful.client.setslave(c)
  744.  
  745. -- Honor size hints: if you want to drop the gaps between windows, set this to false.
  746. -- c.size_hints_honor = false
  747. end)
  748.  
  749. -- Hook function to execute when arranging the screen.
  750. -- (tag switch, new client, etc)
  751. awful.hooks.arrange.register(function (screen)
  752. local layout = awful.layout.getname(awful.layout.get(screen))
  753. if layout and beautiful["layout_" ..layout] then
  754. layoutbox.image = image(beautiful["layout_" .. layout])
  755. else
  756. layoutbox.image = nil
  757. end
  758.  
  759. -- Give focus to the latest client in history if no window has focus
  760. -- or if the current window is a desktop or a dock one.
  761. if not client.focus then
  762. local c = awful.client.focus.history.get(screen, 0)
  763. if c then client.focus = c end
  764. end
  765. end)
  766.  
  767. -- Widget Hooks
  768. -- volume widget hook
  769. awful.hooks.timer.register(1, function () volume("update", tb_volume) end)
  770.  
  771. -- MPD widget hook
  772. awful.hooks.timer.register(1, function () mpd("update", mpd_text, mpd_image) end)
  773.  
  774. -- Amarok widget hook
  775. -- awful.hooks.timer.register(1, function () amarok("update", amarok_text) end)
Add Comment
Please, Sign In to add comment