Guest User

Untitled

a guest
Jul 31st, 2013
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.19 KB | None | 0 0
  1. -- Standard awesome library
  2. gears = require("gears")
  3. awful = require("awful")
  4. awful.rules = require("awful.rules")
  5. awful.autofocus = require("awful.autofocus")
  6. wibox = require("wibox")
  7. beautiful = require("beautiful")
  8. naughty = require("naughty")
  9. menubar = require("menubar")
  10. vicious = require("vicious")
  11.  
  12. -- {{{ Autostart
  13. awful.util.spawn_with_shell("wicd-gtk --daemon")
  14. awful.util.spawn_with_shell("wicd-client --tray")
  15. awful.util.spawn_with_shell("compton -bfzcCG --backend glx --vsync opengl-swc --paint-on-overlay -D6 -r7 -l-11 -t-8")
  16. awful.util.spawn_with_shell("urxvtd -q -o -f")
  17. --- }}}
  18.  
  19. -- {{{ Error handling
  20. -- Check if awesome encountered an error during startup and fell back to
  21. -- another config (This code will only ever execute for the fallback config)
  22. if awesome.startup_errors then
  23. naughty.notify({ preset = naughty.config.presets.critical,
  24. title = "Oops, there were errors during startup!",
  25. text = awesome.startup_errors })
  26. end
  27.  
  28. -- Handle runtime errors after startup
  29. do
  30. local in_error = false
  31. awesome.connect_signal("debug::error", function (err)
  32. -- Make sure we don't go into an endless error loop
  33. if in_error then return end
  34. in_error = true
  35.  
  36. naughty.notify({ preset = naughty.config.presets.critical,
  37. title = "Oops, an error happened!",
  38. text = err })
  39. in_error = false
  40. end)
  41. end
  42. -- }}}
  43.  
  44. -- {{{ Variable definitions
  45. -- Themes define colours, icons, and wallpapers
  46. beautiful.init("/usr/share/awesome/themes/default/theme.lua")
  47.  
  48. -- This is used later as the default terminal and editor to run.
  49. terminal = "urxvtc"
  50. manager = "thunar"
  51. web = "google-chrome"
  52. exec = awful.util.spawn
  53. modkey = "Mod4"
  54. editor = os.getenv("EDITOR") or "nano"
  55. editor_cmd = terminal .. " -e " .. editor
  56.  
  57. -- Table of layouts to cover with awful.layout.inc, order matters.
  58. local layouts =
  59. {
  60. awful.layout.suit.floating,
  61. awful.layout.suit.tile,
  62. awful.layout.suit.tile.left,
  63. awful.layout.suit.tile.bottom,
  64. awful.layout.suit.tile.top,
  65. awful.layout.suit.fair,
  66. awful.layout.suit.fair.horizontal,
  67. awful.layout.suit.spiral,
  68. awful.layout.suit.spiral.dwindle,
  69. awful.layout.suit.max,
  70. awful.layout.suit.max.fullscreen,
  71. awful.layout.suit.magnifier
  72. }
  73. -- }}}
  74.  
  75. -- {{{ Wallpaper
  76. if beautiful.wallpaper then
  77. for s = 1, screen.count() do
  78. gears.wallpaper.maximized("/home/gybtm/Pictures/the-social-network.png", s, true)
  79. end
  80. end
  81. -- }}}
  82.  
  83. -- {{{ Tags
  84. -- Define a tag table which hold all screen tags.
  85. tags = {}
  86. for s = 1, screen.count() do
  87. -- Each screen has its own tag table.
  88. tags[s] = awful.tag({ "www", "term", "code", "etc" }, s, layouts[1])
  89. end
  90. -- }}}
  91.  
  92. -- {{{ Menu
  93. -- Create a laucher widget and a main menu
  94. myawesomemenu = {
  95. { "manual", terminal .. " -e man awesome" },
  96. { "edit config", editor_cmd .. " " .. awesome.conffile },
  97. { "restart", awesome.restart },
  98. { "quit", awesome.quit }
  99. }
  100.  
  101. --myinternet = {}
  102. --mysecurity = {}
  103. --mydeveloptools = {}
  104.  
  105. mymainmenu = awful.menu({ items = {
  106. { "awesome", myawesomemenu, beautiful.awesome_icon },
  107. { "file manager", manager },
  108. { "web", web },
  109. { "open terminal", terminal }
  110. }
  111. })
  112.  
  113. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon, menu = mymainmenu })
  114.  
  115. -- Menubar configuration
  116. menubar.utils.terminal = terminal -- Set the terminal for applications that require it
  117. -- }}}
  118.  
  119. -- {{{ Widget
  120. -- Colours
  121. coldef = "</span>"
  122. colwhi = "<span color='#b2b2b2'>"
  123. red = "<span color='#e54c62'>"
  124.  
  125. -- Net widget
  126. netwidget = wibox.widget.textbox()
  127. vicious.register(netwidget, vicious.widgets.net, '<span background="#313131" font="Terminus 13" rise="2000"> <span font="Terminus 9" color="#7AC82E">${wlan0 down_kb}</span> <span font="Terminus 7" color="#EEDDDD">??</span> <span font="Terminus 9" color="#46A8C3">${wlan0 up_kb} </span></span>', 3)
  128. neticon = wibox.widget.imagebox()
  129. neticon:set_image(beautiful.widget_net)
  130. netwidget:buttons(awful.util.table.join(awful.button({ }, 1, function () awful.util.spawn_with_shell(iptraf) end)))
  131.  
  132. -- Battery widget
  133. baticon = wibox.widget.imagebox()
  134. baticon:set_image(beautiful.widget_battery)
  135.  
  136. function batstate()
  137.  
  138. local file = io.open("/sys/class/power_supply/BAT0/status", "r")
  139.  
  140. if (file == nil) then
  141. return "Cable plugged"
  142. end
  143.  
  144. local batstate = file:read("*line")
  145. file:close()
  146.  
  147. if (batstate == 'Discharging' or batstate == 'Charging') then
  148. return batstate
  149. else
  150. return "Fully charged"
  151. end
  152. end
  153.  
  154. batwidget = wibox.widget.textbox()
  155. vicious.register(batwidget, vicious.widgets.bat,
  156. function (widget, args)
  157. -- plugged
  158. if (batstate() == 'Cable plugged' or batstate() == 'Unknown') then
  159. baticon:set_image(beautiful.widget_ac)
  160. return '<span font="Terminus 12"> <span font="Terminus 9">AC </span></span>'
  161. -- critical
  162. elseif (args[2] <= 5 and batstate() == 'Discharging') then
  163. baticon:set_image(beautiful.widget_battery_empty)
  164. naughty.notify({
  165. text = "sto per spegnermi...",
  166. title = "Carica quasi esaurita!",
  167. position = "top_right",
  168. timeout = 1,
  169. fg="#000000",
  170. bg="#ffffff",
  171. screen = 1,
  172. ontop = true,
  173. })
  174. -- low
  175. elseif (args[2] <= 10 and batstate() == 'Discharging') then
  176. baticon:set_image(beautiful.widget_battery_low)
  177. naughty.notify({
  178. text = "attacca il cavo!",
  179. title = "Carica bassa",
  180. position = "top_right",
  181. timeout = 1,
  182. fg="#ffffff",
  183. bg="#262729",
  184. screen = 1,
  185. ontop = true,
  186. })
  187. else baticon:set_image(beautiful.widget_battery)
  188. end
  189. return '<span font="Terminus 12"> <span font="Terminus 9">' .. args[2] .. '% </span></span>'
  190. end, 1, 'BAT0')
  191.  
  192. -- Volume widget
  193. volicon = wibox.widget.imagebox()
  194. volicon:set_image(beautiful.widget_vol)
  195. volumewidget = wibox.widget.textbox()
  196. vicious.register(volumewidget, vicious.widgets.volume,
  197. function (widget, args)
  198. if (args[2] ~= "?" ) then
  199. if (args[1] == 0) then volicon:set_image(beautiful.widget_vol_no)
  200. elseif (args[1] <= 50) then volicon:set_image(beautiful.widget_vol_low)
  201. else volicon:set_image(beautiful.widget_vol)
  202. end
  203. else volicon:set_image(beautiful.widget_vol_mute)
  204. end
  205. return '<span font="Terminus 12"> <span font="Terminus 9">' .. args[1] .. '% </span></span>'
  206. end, 1, "Master")
  207.  
  208. -- Spacer
  209. spacer = wibox.widget.textbox(" ")
  210. --- }}}
  211. --- }}}
  212.  
  213. -- {{{ Wibox
  214. -- Create a textclock widget
  215. mytextclock = awful.widget.textclock()
  216.  
  217. -- Create a wibox for each screen and add it
  218. mywibox = {}
  219. mypromptbox = {}
  220. mylayoutbox = {}
  221. mytaglist = {}
  222. mytaglist.buttons = awful.util.table.join(
  223. awful.button({ }, 1, awful.tag.viewonly),
  224. awful.button({ modkey }, 1, awful.client.movetotag),
  225. awful.button({ }, 3, awful.tag.viewtoggle),
  226. awful.button({ modkey }, 3, awful.client.toggletag),
  227. awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
  228. awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
  229. )
  230. mytasklist = {}
  231. mytasklist.buttons = awful.util.table.join(
  232. awful.button({ }, 1, function (c)
  233. if c == client.focus then
  234. c.minimized = true
  235. else
  236. -- Without this, the following
  237. -- :isvisible() makes no sense
  238. c.minimized = false
  239. if not c:isvisible() then
  240. awful.tag.viewonly(c:tags()[1])
  241. end
  242. -- This will also un-minimize
  243. -- the client, if needed
  244. client.focus = c
  245. c:raise()
  246. end
  247. end),
  248. awful.button({ }, 3, function ()
  249. if instance then
  250. instance:hide()
  251. instance = nil
  252. else
  253. instance = awful.menu.clients({ width=250 })
  254. end
  255. end),
  256. awful.button({ }, 4, function ()
  257. awful.client.focus.byidx(1)
  258. if client.focus then client.focus:raise() end
  259. end),
  260. awful.button({ }, 5, function ()
  261. awful.client.focus.byidx(-1)
  262. if client.focus then client.focus:raise() end
  263. end))
  264.  
  265. for s = 1, screen.count() do
  266. -- Create a promptbox for each screen
  267. mypromptbox[s] = awful.widget.prompt()
  268. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  269. -- We need one layoutbox per screen.
  270. mylayoutbox[s] = awful.widget.layoutbox(s)
  271. mylayoutbox[s]:buttons(awful.util.table.join(
  272. awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  273. awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  274. awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  275. awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  276. -- Create a taglist widget
  277. mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  278.  
  279. -- Create a tasklist widget
  280. mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  281.  
  282. -- Create the wibox
  283. mywibox[s] = awful.wibox({ position = "top", screen = s })
  284.  
  285. -- Widgets that are aligned to the left
  286. local left_layout = wibox.layout.fixed.horizontal()
  287. left_layout:add(mylauncher)
  288. left_layout:add(mytaglist[s])
  289. left_layout:add(mypromptbox[s])
  290.  
  291. -- Widgets that are aligned to the right
  292. local right_layout = wibox.layout.fixed.horizontal()
  293. if s == 1 then right_layout:add(wibox.widget.systray()) end
  294. right_layout:add(neticon)
  295. right_layout:add(netwidget)
  296. right_layout:add(spacer)
  297. right_layout:add(baticon)
  298. right_layout:add(batwidget)
  299. right_layout:add(mytextclock)
  300. right_layout:add(mylayoutbox[s])
  301.  
  302. -- Now bring it all together (with the tasklist in the middle)
  303. local layout = wibox.layout.align.horizontal()
  304. layout:set_left(left_layout)
  305. layout:set_middle(mytasklist[s])
  306. layout:set_right(right_layout)
  307.  
  308. mywibox[s]:set_widget(layout)
  309. end
  310. -- }}}
  311.  
  312. -- {{{ Mouse bindings
  313. root.buttons(awful.util.table.join(
  314. awful.button({ }, 3, function () mymainmenu:toggle() end),
  315. awful.button({ }, 4, awful.tag.viewnext),
  316. awful.button({ }, 5, awful.tag.viewprev)
  317. ))
  318. -- }}}
  319.  
  320. -- {{{ Key bindings
  321. globalkeys = awful.util.table.join(
  322. awful.key({ modkey, }, "Left", awful.tag.viewprev ),
  323. awful.key({ modkey, }, "Right", awful.tag.viewnext ),
  324. awful.key({ modkey, }, "Escape", awful.tag.history.restore),
  325.  
  326. awful.key({ modkey, }, "j",
  327. function ()
  328. awful.client.focus.byidx( 1)
  329. if client.focus then client.focus:raise() end
  330. end),
  331. awful.key({ modkey, }, "k",
  332. function ()
  333. awful.client.focus.byidx(-1)
  334. if client.focus then client.focus:raise() end
  335. end),
  336. awful.key({ modkey, }, "w", function () mymainmenu:show() end),
  337.  
  338. -- Layout manipulation
  339. awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
  340. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
  341. awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  342. awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  343. awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
  344. awful.key({ modkey, }, "Tab",
  345. function ()
  346. awful.client.focus.history.previous()
  347. if client.focus then
  348. client.focus:raise()
  349. end
  350. end),
  351.  
  352. -- Standard program
  353. awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
  354. awful.key({ modkey, "Control" }, "r", awesome.restart),
  355. awful.key({ modkey, "Shift" }, "q", awesome.quit),
  356. awful.key({ modkey }, "e", function () exec("thunar") end),
  357. awful.key({ modkey }, "t", function () exec("urxvtc") end),
  358. awful.key({ modkey }, "f", function () exec("firefox") end),
  359. awful.key({ modkey }, "g", function () exec("google-chrome") end),
  360.  
  361. awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  362. awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  363. awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  364. awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  365. awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
  366. awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
  367. awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
  368. awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
  369.  
  370. awful.key({ modkey, "Control" }, "n", awful.client.restore),
  371.  
  372. -- Prompt
  373. awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
  374.  
  375. awful.key({ modkey }, "x",
  376. function ()
  377. awful.prompt.run({ prompt = "Run Lua code: " },
  378. mypromptbox[mouse.screen].widget,
  379. awful.util.eval, nil,
  380. awful.util.getdir("cache") .. "/history_eval")
  381. end),
  382. -- Menubar
  383. awful.key({ modkey }, "p", function() menubar.show() end)
  384. )
  385.  
  386. clientkeys = awful.util.table.join(
  387. awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
  388. awful.key({ "Mod1", }, "F4", function (c) c:kill() end),
  389. awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
  390. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  391. awful.key({ modkey, }, "o", awful.client.movetoscreen ),
  392. awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
  393. awful.key({ modkey, }, "n",
  394. function (c)
  395. -- The client currently has the input focus, so it cannot be
  396. -- minimized, since minimized clients can't have the focus.
  397. c.minimized = true
  398. end),
  399. awful.key({ modkey, }, "m",
  400. function (c)
  401. c.maximized_horizontal = not c.maximized_horizontal
  402. c.maximized_vertical = not c.maximized_vertical
  403. end)
  404. )
  405.  
  406. -- Bind all key numbers to tags.
  407. -- Be careful: we use keycodes to make it works on any keyboard layout.
  408. -- This should map on the top row of your keyboard, usually 1 to 9.
  409. for i = 1, 9 do
  410. globalkeys = awful.util.table.join(globalkeys,
  411. awful.key({ modkey }, "#" .. i + 9,
  412. function ()
  413. local screen = mouse.screen
  414. local tag = awful.tag.gettags(screen)[i]
  415. if tag then
  416. awful.tag.viewonly(tag)
  417. end
  418. end),
  419. awful.key({ modkey, "Control" }, "#" .. i + 9,
  420. function ()
  421. local screen = mouse.screen
  422. local tag = awful.tag.gettags(screen)[i]
  423. if tag then
  424. awful.tag.viewtoggle(tag)
  425. end
  426. end),
  427. awful.key({ modkey, "Shift" }, "#" .. i + 9,
  428. function ()
  429. local tag = awful.tag.gettags(client.focus.screen)[i]
  430. if client.focus and tag then
  431. awful.client.movetotag(tag)
  432. end
  433. end),
  434. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  435. function ()
  436. local tag = awful.tag.gettags(client.focus.screen)[i]
  437. if client.focus and tag then
  438. awful.client.toggletag(tag)
  439. end
  440. end))
  441. end
  442.  
  443. clientbuttons = awful.util.table.join(
  444. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  445. awful.button({ modkey }, 1, awful.mouse.client.move),
  446. awful.button({ modkey }, 3, awful.mouse.client.resize))
  447.  
  448. -- Set keys
  449. root.keys(globalkeys)
  450. -- }}}
  451.  
  452. -- {{{ Rules
  453. awful.rules.rules = {
  454. -- All clients will match this rule.
  455. { rule = { },
  456. properties = { border_width = beautiful.border_width,
  457. border_color = beautiful.border_normal,
  458. focus = awful.client.focus.filter,
  459. keys = clientkeys,
  460. buttons = clientbuttons } },
  461. { rule = { class = "MPlayer" },
  462. properties = { floating = true } },
  463. { rule = { class = "pinentry" },
  464. properties = { floating = true } },
  465. { rule = { class = "gimp" },
  466. properties = { floating = true } },
  467. -- Set Firefox to always map on tags number 2 of screen 1.
  468. -- { rule = { class = "Firefox" },
  469. -- properties = { tag = tags[1][2] } },
  470. }
  471. -- }}}
  472.  
  473. -- {{{ Signals
  474. -- Signal function to execute when a new client appears.
  475. client.connect_signal("manage", function (c, startup)
  476. -- Enable sloppy focus
  477. c:connect_signal("mouse::enter", function(c)
  478. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  479. and awful.client.focus.filter(c) then
  480. client.focus = c
  481. end
  482. end)
  483.  
  484. if not startup then
  485. -- Set the windows at the slave,
  486. -- i.e. put it at the end of others instead of setting it master.
  487. -- awful.client.setslave(c)
  488.  
  489. -- Put windows in a smart way, only if they does not set an initial position.
  490. if not c.size_hints.user_position and not c.size_hints.program_position then
  491. awful.placement.no_overlap(c)
  492. awful.placement.no_offscreen(c)
  493. end
  494. end
  495.  
  496. local titlebars_enabled = false
  497. if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  498. -- buttons for the titlebar
  499. local buttons = awful.util.table.join(
  500. awful.button({ }, 1, function()
  501. client.focus = c
  502. c:raise()
  503. awful.mouse.client.move(c)
  504. end),
  505. awful.button({ }, 3, function()
  506. client.focus = c
  507. c:raise()
  508. awful.mouse.client.resize(c)
  509. end)
  510. )
  511.  
  512. -- Widgets that are aligned to the left
  513. local left_layout = wibox.layout.fixed.horizontal()
  514. left_layout:add(awful.titlebar.widget.iconwidget(c))
  515. left_layout:buttons(buttons)
  516.  
  517. -- Widgets that are aligned to the right
  518. local right_layout = wibox.layout.fixed.horizontal()
  519. right_layout:add(awful.titlebar.widget.floatingbutton(c))
  520. right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  521. right_layout:add(awful.titlebar.widget.stickybutton(c))
  522. right_layout:add(awful.titlebar.widget.ontopbutton(c))
  523. right_layout:add(awful.titlebar.widget.closebutton(c))
  524.  
  525. -- The title goes in the middle
  526. local middle_layout = wibox.layout.flex.horizontal()
  527. local title = awful.titlebar.widget.titlewidget(c)
  528. title:set_align("center")
  529. middle_layout:add(title)
  530. middle_layout:buttons(buttons)
  531.  
  532. -- Now bring it all together
  533. local layout = wibox.layout.align.horizontal()
  534. layout:set_left(left_layout)
  535. layout:set_right(right_layout)
  536. layout:set_middle(middle_layout)
  537.  
  538. awful.titlebar(c):set_widget(layout)
  539. end
  540. end)
  541.  
  542. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  543. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  544. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment