Guest User

Untitled

a guest
Jan 22nd, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.14 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. -- Load Debian menu entries
  11. require("debian.menu")
  12.  
  13. -- {{{ Variable definitions
  14. -- Themes define colours, icons, and wallpapers
  15. --beautiful.init("/usr/share/awesome/themes/default/theme.lua")
  16. beautiful.init("/home/tectu/.config/awesome/themes/darkblue/theme.lua")
  17.  
  18. -- This is used later as the default terminal and editor to run.
  19. terminal = "x-terminal-emulator"
  20. editor = os.getenv("EDITOR") or "editor"
  21. editor_cmd = terminal .. " -e " .. editor
  22.  
  23. -- Default modkey.
  24. -- Usually, Mod4 is the key with a logo between Control and Alt.
  25. -- If you do not like this or do not have such a key,
  26. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  27. -- However, you can use another modifier like Mod1, but it may interact with others.
  28. modkey = "Mod4"
  29.  
  30. -- Table of layouts to cover with awful.layout.inc, order matters.
  31. layouts =
  32. {
  33. --awful.layout.suit.floating,
  34. awful.layout.suit.tile,
  35. --awful.layout.suit.tile.left,
  36. awful.layout.suit.tile.bottom,
  37. --awful.layout.suit.tile.top,
  38. awful.layout.suit.fair,
  39. awful.layout.suit.fair.horizontal,
  40. --awful.layout.suit.spiral,
  41. --awful.layout.suit.spiral.dwindle,
  42. --awful.layout.suit.max,
  43. --awful.layout.suit.max.fullscreen,
  44. --awful.layout.suit.magnifier
  45. }
  46. -- }}}
  47.  
  48. -- {{{ Tags
  49. -- Define a tag table which hold all screen tags.
  50. tags = {}
  51. for s = 1, screen.count() do
  52. -- Each screen has its own tag table.
  53. tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
  54. end
  55. -- }}}
  56.  
  57. -- {{{ Menu
  58. -- Create a laucher widget and a main menu
  59. myawesomemenu = {
  60. { "manual", terminal .. " -e man awesome" },
  61. { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
  62. { "restart", awesome.restart },
  63. { "quit", awesome.quit }
  64. }
  65.  
  66. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  67. { "Debian", debian.menu.Debian_menu.Debian },
  68. { "open terminal", terminal }
  69. }
  70. })
  71.  
  72. mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
  73. menu = mymainmenu })
  74. -- }}}
  75.  
  76. -- {{{ Wibox
  77. -- Create a textclock widget
  78. mytextclock = awful.widget.textclock({ align = "right" })
  79.  
  80. -- Create a systray
  81. mysystray = widget({ type = "systray" })
  82.  
  83. -- Create a wibox for each screen and add it
  84. mywibox = {}
  85. mypromptbox = {}
  86. mylayoutbox = {}
  87. mytaglist = {}
  88. mytaglist.buttons = awful.util.table.join(
  89. awful.button({ }, 1, awful.tag.viewonly),
  90. awful.button({ modkey }, 1, awful.client.movetotag),
  91. awful.button({ }, 3, awful.tag.viewtoggle),
  92. awful.button({ modkey }, 3, awful.client.toggletag),
  93. awful.button({ }, 4, awful.tag.viewnext),
  94. awful.button({ }, 5, awful.tag.viewprev)
  95. )
  96. mytasklist = {}
  97. mytasklist.buttons = awful.util.table.join(
  98. awful.button({ }, 1, function (c)
  99. if not c:isvisible() then
  100. awful.tag.viewonly(c:tags()[1])
  101. end
  102. client.focus = c
  103. c:raise()
  104. end),
  105. awful.button({ }, 3, function ()
  106. if instance then
  107. instance:hide()
  108. instance = nil
  109. else
  110. instance = awful.menu.clients({ width=250 })
  111. end
  112. end),
  113. awful.button({ }, 4, function ()
  114. awful.client.focus.byidx(1)
  115. if client.focus then client.focus:raise() end
  116. end),
  117. awful.button({ }, 5, function ()
  118. awful.client.focus.byidx(-1)
  119. if client.focus then client.focus:raise() end
  120. end))
  121. --------- BATTERY ---------
  122. -- Create fraxbat widget
  123. fraxbat = widget({ type = "textbox", name = "fraxbat", align = "right" })
  124. fraxbat.text = 'fraxbat';
  125.  
  126. -- Globals used by fraxbat
  127. fraxbat_st= nil
  128. fraxbat_ts= nil
  129. fraxbat_ch= nil
  130. fraxbat_now = nil
  131. fraxbat_est= nil
  132.  
  133. -- Function for updating fraxbat
  134. function hook_fraxbat (tbw, bat)
  135. -- Battery Present?
  136. local fh= io.open("/sys/class/power_supply/"..bat.."/present", "r")
  137. if fh == nil then
  138. tbw.text="No Bat"
  139. return(nil)
  140. end
  141. local stat= fh:read()
  142. fh:close()
  143. if tonumber(stat) < 1 then
  144. tbw.text="Bat Not Present"
  145. return(nil)
  146. end
  147.  
  148. -- Status (Charging, Full or Discharging)
  149. fh= io.open("/sys/class/power_supply/"..bat.."/status", "r")
  150. if fh == nil then
  151. tbw.text="N/S"
  152. return(nil)
  153. end
  154. stat= fh:read()
  155. fh:close()
  156. if stat == 'Full' then
  157. tbw.text="100%"
  158. return(nil)
  159. end
  160. stat= string.upper(string.sub(stat, 1, 1))
  161. if stat == 'D' then tag= 'i' else tag= 'b' end
  162.  
  163. -- Remaining + Estimated (Dis)Charging Time
  164. local charge=nil
  165. fh= io.open("/sys/class/power_supply/"..bat.."/charge_full_design", "r")
  166. if fh ~= nil then
  167. local full= fh:read()
  168. fh:close()
  169. full= tonumber(full)
  170. if full ~= nil then
  171. fh= io.open("/sys/class/power_supply/"..bat.."/charge_now", "r")
  172. if fh ~= nil then
  173. local now= fh:read()
  174. local est=
  175. fh:close()
  176. if fraxbat_st == stat then
  177. delta= os.difftime(os.time(),fraxbat_ts)
  178. est= math.abs(fraxbat_ch - now)
  179. if delta > 30 and est > 0 then
  180. est= delta/est
  181. if now == fraxbat_now then
  182. est= fraxbat_est
  183. else
  184. fraxbat_est= est
  185. fraxbat_now= now
  186. end
  187. if stat == 'D' then
  188. est= now*est
  189. else
  190. est= (full-now)*est
  191. end
  192. local h= math.floor(est/3600)
  193. est= est - h*3600
  194. est= string.format(',%02d:%02d',h,math.floor(est/60))
  195. else
  196. est=nil
  197. end
  198. else
  199. fraxbat_st= stat
  200. fraxbat_ts= os.time()
  201. fraxbat_ch= now
  202. fraxbat_now= nil
  203. fraxbat_est= nil
  204. end
  205. charge=':<'..tag..'>'..tostring(math.ceil((100*now)/full))..'%</'..tag..'>'..est
  206. end
  207. end
  208. end
  209. tbw.text= stat..charge
  210. end
  211.  
  212. fraxbat.buttons(fraxbat,{ button({ }, 1, function () hook_fraxbat(fraxbat,'BAT0') end),
  213. button({ }, 2, function () hook_fraxbat(fraxbat,'BAT0') end),
  214. button({ }, 3, function () hook_fraxbat(fraxbat,'BAT0') end) })
  215. --------- BATTERY --------
  216.  
  217.  
  218.  
  219. for s = 1, screen.count() do
  220. -- Create a promptbox for each screen
  221. mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  222. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  223. -- We need one layoutbox per screen.
  224. mylayoutbox[s] = awful.widget.layoutbox(s)
  225. mylayoutbox[s]:buttons(awful.util.table.join(
  226. awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  227. awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  228. awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  229. awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  230. -- Create a taglist widget
  231. mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  232.  
  233. -- Create a tasklist widget
  234. mytasklist[s] = awful.widget.tasklist(function(c)
  235. return awful.widget.tasklist.label.currenttags(c, s)
  236. end, mytasklist.buttons)
  237.  
  238. -- Create the wibox
  239. mywibox[s] = awful.wibox({ position = "top", screen = s })
  240. -- Add widgets to the wibox - order matters
  241. mywibox[s].widgets = {
  242. {
  243. mylauncher,
  244. mytaglist[s],
  245. mypromptbox[s],
  246. fraxbat,
  247. layout = awful.widget.layout.horizontal.leftright
  248. },
  249. mylayoutbox[s],
  250. mytextclock,
  251. s == 1 and mysystray or nil,
  252. mytasklist[s],
  253. layout = awful.widget.layout.horizontal.rightleft
  254. }
  255. end
  256. -- }}}
  257.  
  258. -- {{{ Mouse bindings
  259. root.buttons(awful.util.table.join(
  260. awful.button({ }, 3, function () mymainmenu:toggle() end),
  261. awful.button({ }, 4, awful.tag.viewnext),
  262. awful.button({ }, 5, awful.tag.viewprev)
  263. ))
  264. -- }}}
  265.  
  266. -- {{{ Key bindings
  267. globalkeys = awful.util.table.join(
  268. awful.key({ modkey, }, "Left", awful.tag.viewprev ),
  269. awful.key({ modkey, }, "Right", awful.tag.viewnext ),
  270. awful.key({ modkey, }, "Escape", awful.tag.history.restore),
  271.  
  272. awful.key({ modkey, }, "j",
  273. function ()
  274. awful.client.focus.byidx( 1)
  275. if client.focus then client.focus:raise() end
  276. end),
  277. awful.key({ modkey, }, "k",
  278. function ()
  279. awful.client.focus.byidx(-1)
  280. if client.focus then client.focus:raise() end
  281. end),
  282. awful.key({ modkey, }, "w", function () mymainmenu:show({keygrabber=true}) end),
  283.  
  284. -- Layout manipulation
  285. awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
  286. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
  287. awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  288. awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  289. awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
  290. awful.key({ modkey, }, "Tab",
  291. function ()
  292. awful.client.focus.history.previous()
  293. if client.focus then
  294. client.focus:raise()
  295. end
  296. end),
  297.  
  298. -- Standard program
  299. awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
  300. awful.key({ modkey, "Control" }, "r", awesome.restart),
  301. awful.key({ modkey, "Shift" }, "q", awesome.quit),
  302.  
  303. awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  304. awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  305. awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  306. awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  307. awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
  308. awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
  309. awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
  310. awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
  311.  
  312. -- Prompt
  313. awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
  314.  
  315. awful.key({ modkey }, "x",
  316. function ()
  317. awful.prompt.run({ prompt = "Run Lua code: " },
  318. mypromptbox[mouse.screen].widget,
  319. awful.util.eval, nil,
  320. awful.util.getdir("cache") .. "/history_eval")
  321. end)
  322. )
  323.  
  324. clientkeys = awful.util.table.join(
  325. awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
  326. awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
  327. awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
  328. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  329. awful.key({ modkey, }, "o", awful.client.movetoscreen ),
  330. awful.key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
  331. awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
  332. awful.key({ modkey, }, "n", function (c) c.minimized = not c.minimized end),
  333. awful.key({ modkey, }, "m",
  334. function (c)
  335. c.maximized_horizontal = not c.maximized_horizontal
  336. c.maximized_vertical = not c.maximized_vertical
  337. end)
  338. )
  339.  
  340. -- Compute the maximum number of digit we need, limited to 9
  341. keynumber = 0
  342. for s = 1, screen.count() do
  343. keynumber = math.min(9, math.max(#tags[s], keynumber));
  344. end
  345.  
  346. -- Bind all key numbers to tags.
  347. -- Be careful: we use keycodes to make it works on any keyboard layout.
  348. -- This should map on the top row of your keyboard, usually 1 to 9.
  349. for i = 1, keynumber do
  350. globalkeys = awful.util.table.join(globalkeys,
  351. awful.key({ modkey }, "#" .. i + 9,
  352. function ()
  353. local screen = mouse.screen
  354. if tags[screen][i] then
  355. awful.tag.viewonly(tags[screen][i])
  356. end
  357. end),
  358. awful.key({ modkey, "Control" }, "#" .. i + 9,
  359. function ()
  360. local screen = mouse.screen
  361. if tags[screen][i] then
  362. awful.tag.viewtoggle(tags[screen][i])
  363. end
  364. end),
  365. awful.key({ modkey, "Shift" }, "#" .. i + 9,
  366. function ()
  367. if client.focus and tags[client.focus.screen][i] then
  368. awful.client.movetotag(tags[client.focus.screen][i])
  369. end
  370. end),
  371. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  372. function ()
  373. if client.focus and tags[client.focus.screen][i] then
  374. awful.client.toggletag(tags[client.focus.screen][i])
  375. end
  376. end))
  377. end
  378.  
  379. clientbuttons = awful.util.table.join(
  380. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  381. awful.button({ modkey }, 1, awful.mouse.client.move),
  382. awful.button({ modkey }, 3, awful.mouse.client.resize))
  383.  
  384. -- Set keys
  385. root.keys(globalkeys)
  386. -- }}}
  387.  
  388. -- {{{ Rules
  389. awful.rules.rules = {
  390. -- All clients will match this rule.
  391. { rule = { },
  392. properties = { border_width = beautiful.border_width,
  393. border_color = beautiful.border_normal,
  394. focus = true,
  395. keys = clientkeys,
  396. buttons = clientbuttons } },
  397. { rule = { class = "MPlayer" },
  398. properties = { floating = true } },
  399. { rule = { class = "pinentry" },
  400. properties = { floating = true } },
  401. { rule = { class = "gimp" },
  402. properties = { floating = true } },
  403. -- Set Firefox to always map on tags number 2 of screen 1.
  404. -- { rule = { class = "Firefox" },
  405. -- properties = { tag = tags[1][2] } },
  406. }
  407. -- }}}
  408.  
  409. -- {{{ Signals
  410. -- Signal function to execute when a new client appears.
  411. client.add_signal("manage", function (c, startup)
  412. -- Add a titlebar
  413. -- awful.titlebar.add(c, { modkey = modkey })
  414.  
  415. -- Enable sloppy focus
  416. c:add_signal("mouse::enter", function(c)
  417. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  418. and awful.client.focus.filter(c) then
  419. client.focus = c
  420. end
  421. end)
  422.  
  423. if not startup then
  424. -- Set the windows at the slave,
  425. -- i.e. put it at the end of others instead of setting it master.
  426. -- awful.client.setslave(c)
  427.  
  428. -- Put windows in a smart way, only if they does not set an initial position.
  429. if not c.size_hints.user_position and not c.size_hints.program_position then
  430. awful.placement.no_overlap(c)
  431. awful.placement.no_offscreen(c)
  432. end
  433. end
  434. end)
  435.  
  436. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  437. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  438. -- }}}
  439.  
  440. awful.hooks.timer.register(10, function () hook_fraxbat(fraxbat,'BAT0') end)
  441.  
  442. awful.util.spawn_with_shell("gtk-theme-switch2 /usr/share/themes/Aurora-Midnight")
  443. awful.util.spawn_with_shell("nm-applet")
Add Comment
Please, Sign In to add comment