Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.97 KB | None | 0 0
  1. -- Standard awesome library
  2. require("awful")
  3. require("awful.autofocus")
  4. require("awful.rules")
  5. -- Theme handling library
  6. require("beautiful")
  7. -- Notification library
  8. require("naughty")
  9.  
  10. -- Sound Widget
  11. cardid = 0
  12. channel = "Master"
  13. function volume (mode, widget)
  14. if mode == "update" then
  15. local fd = io.popen("amixer -c " .. cardid .. " -- sget " .. channel)
  16. local status = fd:read("*all")
  17. fd:close()
  18.  
  19. local volume = string.match(status, "(%d?%d?%d)%%")
  20. volume = string.format("% 3d", volume)
  21.  
  22. status = string.match(status, "%[(o[^%]]*)%]")
  23.  
  24. if string.find(status, "on", 1, true) then
  25. volume = "| Vol:<span color='green'>" .. volume .. "</span>% "
  26. else
  27. volume = "| Vol:<span color='red'>" .. volume .. "</span>M "
  28. end
  29. widget.text = volume
  30. elseif mode == "up" then
  31. io.popen("amixer -q -c " .. cardid .. " sset " .. channel .. " 5%+"):read("*all")
  32. volume("update", widget)
  33. elseif mode == "down" then
  34. io.popen("amixer -q -c " .. cardid .. " sset " .. channel .. " 5%-"):read("*all")
  35. volume("update", widget)
  36. else
  37. io.popen("amixer -c " .. cardid .. " sset " .. channel .. " toggle"):read("*all")
  38. volume("update", widget)
  39. end
  40. end
  41.  
  42.  
  43. -- {{{ Variable definitions
  44. -- Themes define colours, icons, and wallpapers
  45. beautiful.init("/usr/share/awesome/themes/default/theme.lua")
  46.  
  47. -- This is used later as the default terminal and editor to run.
  48. --terminal = "xterm"
  49. terminal = "terminator"
  50. editor = os.getenv("EDITOR") or "vim"
  51. editor_cmd = terminal .. " -e " .. editor
  52.  
  53. -- Default modkey.
  54. -- Usually, Mod4 is the key with a logo between Control and Alt.
  55. -- If you do not like this or do not have such a key,
  56. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  57. -- However, you can use another modifier like Mod1, but it may interact with others.
  58. modkey = "Mod4"
  59.  
  60. -- Table of layouts to cover with awful.layout.inc, order matters.
  61. layouts =
  62. {
  63. awful.layout.suit.floating,
  64. awful.layout.suit.tile,
  65. awful.layout.suit.tile.left,
  66. awful.layout.suit.tile.bottom,
  67. awful.layout.suit.tile.top,
  68. awful.layout.suit.fair,
  69. awful.layout.suit.fair.horizontal,
  70. awful.layout.suit.spiral,
  71. awful.layout.suit.spiral.dwindle,
  72. awful.layout.suit.max,
  73. awful.layout.suit.max.fullscreen,
  74. awful.layout.suit.magnifier
  75. }
  76. -- }}}
  77.  
  78. -- {{{ Tags
  79. -- Define a tag table which hold all screen tags.
  80. tags = {
  81. names = { "term", "web", "dev", "bla", "mus","vid", "expl","trucs" },
  82. layout = { layouts[2], layouts[1], layouts[2], layouts[8], layouts[2],layouts[11],layouts[2],layouts[1]}
  83. }
  84.  
  85. for s = 1, screen.count() do
  86. tags[s] = awful.tag(tags.names, s, tags.layout)
  87. end
  88.  
  89. -- }}}
  90.  
  91. -- {{{ Menu
  92. -- Create a laucher widget and a main menu
  93. myawesomemenu = {
  94. { "doc", terminal .. " -e man awesome" },
  95. { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
  96. { "restart", awesome.restart },
  97. { "deco", awesome.quit },
  98. { "bye", function () awesome.spawn("gdm-control --shutdown"); awesome.quit() end}
  99. }
  100.  
  101. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  102. { "open terminal", terminal },
  103. }
  104. })
  105.  
  106. mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
  107. menu = mymainmenu })
  108. -- }}}
  109.  
  110. -- {{{ Wibox
  111.  
  112. -- Create Volume Control Widget
  113. tb_volume = widget({ type = "textbox", name = "tb_volume", align = "right" })
  114. tb_volume:buttons(awful.util.table.join(
  115. awful.button({ }, 4, function () volume("up", tb_volume) end),
  116. awful.button({ }, 5, function () volume("down", tb_volume) end),
  117. awful.button({ }, 1, function () volume("mute", tb_volume) end)
  118. ))
  119. volume("update", tb_volume)
  120.  
  121. -- refresh the Volume Control Widget
  122. tb_volume_timer = timer({ timeout = 10 })
  123. tb_volume_timer:add_signal("timeout", function () volume("update", tb_volume) end)
  124. tb_volume_timer:start()
  125.  
  126.  
  127.  
  128. -- Create CPU Temp Widget
  129. function activecputemp()
  130. local temp
  131.  
  132. io.input("/sys/bus/acpi/devices/LNXTHERM\:00/thermal_zone/temp")
  133. temp = io.read("*number")/1000
  134.  
  135. if temp < 46 then
  136. temp = '<span color="turquoise">' .. temp .. '</span>'
  137. elseif temp < 61 then
  138. temp = '<span color="yellow">' .. temp .. '</span>'
  139. elseif temp < 76 then
  140. temp = '<span color="orange">' .. temp .. '</span>'
  141. else
  142. temp = '<span color="red">' .. temp .. '</span>'
  143. end
  144.  
  145. return temp
  146. end
  147.  
  148. cputemp = widget({ type = "textbox" , name = "cputemp" })
  149.  
  150. -- Assign a hook to update temperature
  151. -- awful.hooks.timer.register(1, function() cputemp.text = "@ " .. activecputemp() .. "°C | RAM: " end)
  152. cputemp_timer = timer({timeout = 1})
  153. cputemp_timer:add_signal("timeout", function() cputemp.text = "@ " .. activecputemp() .. "°C | RAM: " end)
  154. cputemp_timer:start()
  155.  
  156. -- Create a textclock widget
  157. mytextclock = awful.widget.textclock({ align = "right" })
  158.  
  159. -- Create a systray
  160. mysystray = widget({ type = "systray" })
  161.  
  162. -- Create a wibox for each screen and add it
  163. mywibox = {}
  164. mypromptbox = {}
  165. mylayoutbox = {}
  166. mytaglist = {}
  167. mytaglist.buttons = awful.util.table.join(
  168. awful.button({ }, 1, awful.tag.viewonly),
  169. awful.button({ modkey }, 1, awful.client.movetotag),
  170. awful.button({ }, 3, awful.tag.viewtoggle),
  171. awful.button({ modkey }, 3, awful.client.toggletag),
  172. awful.button({ }, 4, awful.tag.viewnext),
  173. awful.button({ }, 5, awful.tag.viewprev)
  174. )
  175. mytasklist = {}
  176. mytasklist.buttons = awful.util.table.join(
  177. awful.button({ }, 1, function (c)
  178. if not c:isvisible() then
  179. awful.tag.viewonly(c:tags()[1])
  180. end
  181. client.focus = c
  182. c:raise()
  183. end),
  184. awful.button({ }, 3, function ()
  185. if instance then
  186. instance:hide()
  187. instance = nil
  188. else
  189. instance = awful.menu.clients({ width=250 })
  190. end
  191. end),
  192. awful.button({ }, 4, function ()
  193. awful.client.focus.byidx(1)
  194. if client.focus then client.focus:raise() end
  195. end),
  196. awful.button({ }, 5, function ()
  197. awful.client.focus.byidx(-1)
  198. if client.focus then client.focus:raise() end
  199. end))
  200.  
  201. for s = 1, screen.count() do
  202. -- Create a promptbox for each screen
  203. mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  204. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  205. -- We need one layoutbox per screen.
  206. mylayoutbox[s] = awful.widget.layoutbox(s)
  207. mylayoutbox[s]:buttons(awful.util.table.join(
  208. awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  209. awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  210. awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  211. awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  212. -- Create a taglist widget
  213. mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  214.  
  215. -- Create a tasklist widget
  216. mytasklist[s] = awful.widget.tasklist(function(c)
  217. return awful.widget.tasklist.label.currenttags(c, s)
  218. end, mytasklist.buttons)
  219.  
  220. -- Create the wibox
  221. mywibox[s] = awful.wibox({ position = "top", screen = s })
  222. -- Add widgets to the wibox - order matters
  223. mywibox[s].widgets = {
  224. {
  225. mylauncher,
  226. mytaglist[s],
  227. mypromptbox[s],
  228. layout = awful.widget.layout.horizontal.leftright
  229. },
  230. mylayoutbox[s],
  231. mymail,
  232. s == 1 and mysystray or nil,
  233. tb_volume,
  234. mytextclock,
  235.  
  236.  
  237. cputemp,
  238.  
  239.  
  240. mytasklist[s],
  241. layout = awful.widget.layout.horizontal.rightleft
  242. }
  243. end
  244. -- }}}
  245.  
  246. -- {{{ Mouse bindings
  247. root.buttons(awful.util.table.join(
  248. awful.button({ }, 3, function () mymainmenu:toggle() end),
  249. awful.button({ }, 4, awful.tag.viewnext),
  250. awful.button({ }, 5, awful.tag.viewprev)
  251. ))
  252. -- }}}
  253.  
  254. -- {{{ Key bindings
  255. globalkeys = awful.util.table.join(
  256. awful.key({ modkey, }, "Left", awful.tag.viewprev ),
  257. awful.key({ modkey, }, "Right", awful.tag.viewnext ),
  258. awful.key({ modkey, }, "Escape", awful.tag.history.restore),
  259.  
  260. awful.key({ modkey, }, "j",
  261. function ()
  262. awful.client.focus.byidx( 1)
  263. if client.focus then client.focus:raise() end
  264. end),
  265. awful.key({ modkey, }, "k",
  266. function ()
  267. awful.client.focus.byidx(-1)
  268. if client.focus then client.focus:raise() end
  269. end),
  270. awful.key({ modkey, }, "w", function () mymainmenu:show(true) end),
  271.  
  272. awful.key({modkey }, "p", function()
  273. awful.util.spawn_with_shell( "exe=`dmenu_path | dmenu -nf '#888888' -nb '#222222' -sf '#ffffff' -sb '#285577'` && exec $exe")
  274. end),
  275.  
  276. -- Multimedia keys
  277. awful.key({ }, "XF86AudioRaiseVolume", function () volume("up", tb_volume) end),
  278. awful.key({ }, "XF86AudioLowerVolume", function () volume("down", tb_volume) end),
  279. awful.key({ }, "XF86AudioMute", function () volume("mute", tb_volume) end),
  280.  
  281.  
  282. -- Layout manipulation
  283. awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
  284. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
  285. awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  286. awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  287. awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
  288. awful.key({ modkey, }, "Tab",
  289. function ()
  290. awful.client.focus.history.previous()
  291. if client.focus then
  292. client.focus:raise()
  293. end
  294. end),
  295.  
  296. -- Standard program
  297. awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
  298. awful.key({ modkey, "Control" }, "r", awesome.restart),
  299. awful.key({ modkey, "Shift" }, "q", awesome.quit),
  300.  
  301. awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  302. awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  303. awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  304. awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  305. awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
  306. awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
  307. awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
  308. awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
  309.  
  310. -- Prompt
  311. awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
  312.  
  313. awful.key({ modkey }, "x",
  314. function ()
  315. awful.prompt.run({ prompt = "Run Lua code: " },
  316. mypromptbox[mouse.screen].widget,
  317. awful.util.eval, nil,
  318. awful.util.getdir("cache") .. "/history_eval")
  319. end)
  320. )
  321.  
  322. clientkeys = awful.util.table.join(
  323. awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
  324. awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
  325. awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
  326. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  327. awful.key({ modkey, }, "o", awful.client.movetoscreen ),
  328. awful.key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
  329. awful.key({ modkey, }, "n", function (c) c.minimized = not c.minimized end),
  330. awful.key({ modkey, }, "m",
  331. function (c)
  332. c.maximized_horizontal = not c.maximized_horizontal
  333. c.maximized_vertical = not c.maximized_vertical
  334. end)
  335. )
  336.  
  337.  
  338. -- Compute the maximum number of digit we need, limited to 9
  339. keynumber = 0
  340. for s = 1, screen.count() do
  341. keynumber = math.min(9, math.max(#tags[s], keynumber));
  342. end
  343.  
  344. -- Bind all key numbers to tags.
  345. -- Be careful: we use keycodes to make it works on any keyboard layout.
  346. -- This should map on the top row of your keyboard, usually 1 to 9.
  347. for i = 1, keynumber do
  348. globalkeys = awful.util.table.join(globalkeys,
  349. awful.key({ modkey }, "#" .. i + 9,
  350. function ()
  351. local screen = mouse.screen
  352. if tags[screen][i] then
  353. awful.tag.viewonly(tags[screen][i])
  354. end
  355. end),
  356. awful.key({ modkey, "Control" }, "#" .. i + 9,
  357. function ()
  358. local screen = mouse.screen
  359. if tags[screen][i] then
  360. awful.tag.viewtoggle(tags[screen][i])
  361. end
  362. end),
  363. awful.key({ modkey, "Shift" }, "#" .. i + 9,
  364. function ()
  365. if client.focus and tags[client.focus.screen][i] then
  366. awful.client.movetotag(tags[client.focus.screen][i])
  367. end
  368. end),
  369. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  370. function ()
  371. if client.focus and tags[client.focus.screen][i] then
  372. awful.client.toggletag(tags[client.focus.screen][i])
  373. end
  374. end))
  375. end
  376.  
  377. clientbuttons = awful.util.table.join(
  378. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  379. awful.button({ modkey }, 1, awful.mouse.client.move),
  380. awful.button({ modkey }, 3, awful.mouse.client.resize))
  381.  
  382. -- Set keys
  383. root.keys(globalkeys)
  384. -- }}}
  385.  
  386. -- {{{ Rules
  387. awful.rules.rules = {
  388. -- All clients will match this rule.
  389. { rule = { },
  390. properties = { border_width = beautiful.border_width,
  391. border_color = beautiful.border_normal,
  392. focus = true,
  393. keys = clientkeysl,
  394. floating = false,
  395. buttons = clientbuttons
  396. } },
  397.  
  398. { rule = { class = "Chromium-browser" },
  399. properties = { tag = tags[1][2],floating = true, switchtotag = true } },
  400. { rule = { class = "Terminator" },
  401. properties = { tag = tags[1][1], switchtotag = true } },
  402. { rule = { class = "Nautilus" },
  403. properties = { tag = tags[1][7], switchtotag = true } },
  404. { rule = { class = "Thunar" },
  405. properties = { tag = tags[1][7], switchtotag = true } },
  406. { rule = { class = "Tomboy" },
  407. properties = { tag = tags[1][8],floating = true, switchtotag = true } },
  408.  
  409. { rule = { class = "Vlc" },
  410. properties = { tag = tags[1][6],floating = true, switchtotag = true } },
  411. { rule = { class = "Thevibeii" },
  412. properties = { tag = tags[1][8],floating = true, switchtotag = true } },
  413. { rule = { class = "Qtcreator" },
  414. properties = { tag = tags[1][3], switchtotag = true } },
  415. { rule = { class = "Xchat" },
  416. properties = { tag = tags[1][4], switchtotag = true } },
  417. { rule = { class = "Empathy" },
  418. properties = { tag = tags[1][4], switchtotag = true } },
  419. { rule = { class = "Pidgin" },
  420. properties = { tag = tags[1][4], switchtotag = true } },
  421. { rule = { class = "Spotify" },
  422. properties = { tag = tags[1][5],floating = true, switchtotag = true } }
  423. }
  424. -- }}}
  425.  
  426. -- {{{ Signals
  427. -- Signal function to execute when a new client appears.
  428. client.add_signal("manage", function (c, startup)
  429. -- Add a titlebar
  430. -- awful.titlebar.add(c, { modkey = modkey })
  431.  
  432. -- Enable sloppy focus
  433. c:add_signal("mouse::enter", function(c)
  434. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  435. and awful.client.focus.filter(c) then
  436. client.focus = c
  437. end
  438. end)
  439.  
  440. if not startup then
  441. -- Set the windows at the slave,
  442. -- i.e. put it at the end of others instead of setting it master.
  443. -- awful.client.setslave(c)
  444.  
  445. -- Put windows in a smart way, only if they does not set an initial position.
  446. if not c.size_hints.user_position and not c.size_hints.program_position then
  447. awful.placement.no_overlap(c)
  448. awful.placement.no_offscreen(c)
  449. end
  450. end
  451. end)
  452.  
  453. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_focus end)
  454. client.add_signal("focus", function(c) c.border_color = beautiful.border_normal end)
  455. -- }}}
  456.  
  457. -- Launch the network-manager applet
  458. awful.util.spawn('nm-applet')
  459. awful.util.spawn('nitrogen --restore')
  460. --awful.util.spawn('conky')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement