Advertisement
Guest User

Untitled

a guest
Feb 14th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.20 KB | None | 0 0
  1. -- Standard awesome library
  2. local gears = require("gears")
  3. local awful = require("awful")
  4. awful.rules = require("awful.rules")
  5. require("awful.autofocus")
  6. -- Widget and layout library
  7. local wibox = require("wibox")
  8. -- Theme handling library
  9. local beautiful = require("beautiful")
  10. -- Notification library
  11. local naughty = require("naughty")
  12. local menubar = require("menubar")
  13.  
  14. -- {{{ Error handling
  15. -- Check if awesome encountered an error during startup and fell back to
  16. -- another config (This code will only ever execute for the fallback config)
  17. if awesome.startup_errors then
  18. naughty.notify({ preset = naughty.config.presets.critical,
  19. title = "Oops, there were errors during startup!",
  20. text = awesome.startup_errors })
  21. end
  22.  
  23. -- Handle runtime errors after startup
  24. do
  25. local in_error = false
  26. awesome.connect_signal("debug::error", function (err)
  27. -- Make sure we don't go into an endless error loop
  28. if in_error then return end
  29. in_error = true
  30.  
  31. naughty.notify({ preset = naughty.config.presets.critical,
  32. title = "Oops, an error happened!",
  33. text = err })
  34. in_error = false
  35. end)
  36. end
  37. -- }}}
  38.  
  39. -- {{{ Variable definitions
  40. -- Themes define colours, icons, font and wallpapers.
  41. beautiful.init("/usr/share/awesome/themes/default/theme.lua")
  42.  
  43. -- This is used later as the default terminal and editor to run.
  44. terminal = "terminator"
  45. editor = os.getenv("EDITOR") or "nano"
  46. editor_cmd = terminal .. " -e " .. editor
  47.  
  48. -- Default modkey.
  49. -- Usually, Mod4 is the key with a logo between Control and Alt.
  50. -- If you do not like this or do not have such a key,
  51. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  52. -- However, you can use another modifier like Mod1, but it may interact with others.
  53. modkey = "Mod4"
  54.  
  55. -- Table of layouts to cover with awful.layout.inc, order matters.
  56. local layouts =
  57. {
  58. awful.layout.suit.floating,
  59. awful.layout.suit.tile,
  60. awful.layout.suit.tile.left,
  61. awful.layout.suit.tile.bottom,
  62. awful.layout.suit.tile.top,
  63. awful.layout.suit.fair,
  64. awful.layout.suit.fair.horizontal,
  65. awful.layout.suit.spiral,
  66. awful.layout.suit.spiral.dwindle,
  67. awful.layout.suit.max,
  68. awful.layout.suit.max.fullscreen,
  69. awful.layout.suit.magnifier
  70. }
  71. -- }}}
  72.  
  73. -- {{{ Wallpaper
  74. if beautiful.wallpaper then
  75. for s = 1, screen.count() do
  76. gears.wallpaper.maximized(beautiful.wallpaper, s, true)
  77. end
  78. end
  79. -- }}}
  80.  
  81. -- {{{ Tags
  82. -- Define a tag table which hold all screen tags.
  83. tags = {}
  84. for s = 1, screen.count() do
  85. -- Each screen has its own tag table.
  86. tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
  87. end
  88. -- }}}
  89.  
  90. -- {{{ Menu
  91. -- Create a laucher widget and a main menu
  92. myawesomemenu = {
  93. { "manual", terminal .. " -e man awesome" },
  94. { "edit config", editor_cmd .. " " .. awesome.conffile },
  95. { "restart", awesome.restart },
  96. { "quit", awesome.quit }
  97. }
  98.  
  99. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  100. { "open terminal", terminal }
  101. }
  102. })
  103.  
  104. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  105. menu = mymainmenu })
  106.  
  107. -- Menubar configuration
  108. menubar.utils.terminal = terminal -- Set the terminal for applications that require it
  109. -- }}}
  110.  
  111. -- {{{ Wibox
  112. -- Create a textclock widget
  113. mytextclock = awful.widget.textclock()
  114.  
  115. -- Create a wibox for each screen and add it
  116. mywibox = {}
  117. mypromptbox = {}
  118. mylayoutbox = {}
  119. mytaglist = {}
  120. mytaglist.buttons = awful.util.table.join(
  121. awful.button({ }, 1, awful.tag.viewonly),
  122. awful.button({ modkey }, 1, awful.client.movetotag),
  123. awful.button({ }, 3, awful.tag.viewtoggle),
  124. awful.button({ modkey }, 3, awful.client.toggletag),
  125. awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
  126. awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
  127. )
  128. mytasklist = {}
  129. mytasklist.buttons = awful.util.table.join(
  130. awful.button({ }, 1, function (c)
  131. if c == client.focus then
  132. c.minimized = true
  133. else
  134. -- Without this, the following
  135. -- :isvisible() makes no sense
  136. c.minimized = false
  137. if not c:isvisible() then
  138. awful.tag.viewonly(c:tags()[1])
  139. end
  140. -- This will also un-minimize
  141. -- the client, if needed
  142. client.focus = c
  143. c:raise()
  144. end
  145. end),
  146. awful.button({ }, 3, function ()
  147. if instance then
  148. instance:hide()
  149. instance = nil
  150. else
  151. instance = awful.menu.clients({
  152. theme = { width = 250 }
  153. })
  154. end
  155. end),
  156. awful.button({ }, 4, function ()
  157. awful.client.focus.byidx(1)
  158. if client.focus then client.focus:raise() end
  159. end),
  160. awful.button({ }, 5, function ()
  161. awful.client.focus.byidx(-1)
  162. if client.focus then client.focus:raise() end
  163. end))
  164.  
  165. for s = 1, screen.count() do
  166. -- Create a promptbox for each screen
  167. mypromptbox[s] = awful.widget.prompt()
  168. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  169. -- We need one layoutbox per screen.
  170. mylayoutbox[s] = awful.widget.layoutbox(s)
  171. mylayoutbox[s]:buttons(awful.util.table.join(
  172. awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  173. awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  174. awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  175. awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  176. -- Create a taglist widget
  177. mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  178.  
  179. -- Create a tasklist widget
  180. mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  181.  
  182. -- Create the wibox
  183. mywibox[s] = awful.wibox({ position = "top", screen = s })
  184.  
  185. -- Widgets that are aligned to the left
  186. local left_layout = wibox.layout.fixed.horizontal()
  187. left_layout:add(mylauncher)
  188. left_layout:add(mytaglist[s])
  189. left_layout:add(mypromptbox[s])
  190.  
  191. -- Widgets that are aligned to the right
  192. local right_layout = wibox.layout.fixed.horizontal()
  193. if s == 1 then right_layout:add(wibox.widget.systray()) end
  194. right_layout:add(mytextclock)
  195. right_layout:add(mylayoutbox[s])
  196.  
  197. -- Now bring it all together (with the tasklist in the middle)
  198. local layout = wibox.layout.align.horizontal()
  199. layout:set_left(left_layout)
  200. layout:set_middle(mytasklist[s])
  201. layout:set_right(right_layout)
  202.  
  203. mywibox[s]:set_widget(layout)
  204. end
  205. -- }}}
  206.  
  207. -- {{{ Mouse bindings
  208. root.buttons(awful.util.table.join(
  209. awful.button({ }, 3, function () mymainmenu:toggle() end),
  210. awful.button({ }, 4, awful.tag.viewnext),
  211. awful.button({ }, 5, awful.tag.viewprev)
  212. ))
  213. -- }}}
  214.  
  215. -- {{{ Key bindings
  216. globalkeys = awful.util.table.join(
  217. awful.key({ modkey, }, "Left", awful.tag.viewprev ),
  218. awful.key({ modkey, }, "Right", awful.tag.viewnext ),
  219. awful.key({ modkey, }, "Escape", awful.tag.history.restore),
  220.  
  221. awful.key({ modkey, }, "j",
  222. function ()
  223. awful.client.focus.byidx( 1)
  224. if client.focus then client.focus:raise() end
  225. end),
  226. awful.key({ modkey, }, "k",
  227. function ()
  228. awful.client.focus.byidx(-1)
  229. if client.focus then client.focus:raise() end
  230. end),
  231. awful.key({ modkey, }, "w", function () mymainmenu:show() end),
  232.  
  233. -- Layout manipulation
  234. awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
  235. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
  236. awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  237. awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  238. awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
  239. awful.key({ modkey, }, "Tab",
  240. function ()
  241. awful.client.focus.history.previous()
  242. if client.focus then
  243. client.focus:raise()
  244. end
  245. end),
  246.  
  247. -- Standard program
  248. awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
  249. awful.key({ modkey, "Control" }, "r", awesome.restart),
  250. awful.key({ modkey, "Shift" }, "q", awesome.quit),
  251.  
  252. awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  253. awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  254. awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  255. awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  256. awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
  257. awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
  258. awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
  259. awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
  260.  
  261. awful.key({ modkey, "Control" }, "n", awful.client.restore),
  262.  
  263. -- Prompt
  264. awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
  265.  
  266. awful.key({ modkey }, "x",
  267. function ()
  268. awful.prompt.run({ prompt = "Run Lua code: " },
  269. mypromptbox[mouse.screen].widget,
  270. awful.util.eval, nil,
  271. awful.util.getdir("cache") .. "/history_eval")
  272. end),
  273. -- Menubar
  274. awful.key({ modkey }, "p", function() menubar.show() end)
  275. )
  276.  
  277. clientkeys = awful.util.table.join(
  278. awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
  279. awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
  280. awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
  281. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  282. awful.key({ modkey, }, "o", awful.client.movetoscreen ),
  283. awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
  284. awful.key({ modkey, }, "n",
  285. function (c)
  286. -- The client currently has the input focus, so it cannot be
  287. -- minimized, since minimized clients can't have the focus.
  288. c.minimized = true
  289. end),
  290. awful.key({ modkey, }, "m",
  291. function (c)
  292. c.maximized_horizontal = not c.maximized_horizontal
  293. c.maximized_vertical = not c.maximized_vertical
  294. end)
  295. )
  296.  
  297. -- Bind all key numbers to tags.
  298. -- Be careful: we use keycodes to make it works on any keyboard layout.
  299. -- This should map on the top row of your keyboard, usually 1 to 9.
  300. for i = 1, 9 do
  301. globalkeys = awful.util.table.join(globalkeys,
  302. -- View tag only.
  303. awful.key({ modkey }, "#" .. i + 9,
  304. function ()
  305. local screen = mouse.screen
  306. local tag = awful.tag.gettags(screen)[i]
  307. if tag then
  308. awful.tag.viewonly(tag)
  309. end
  310. end),
  311. -- Toggle tag.
  312. awful.key({ modkey, "Control" }, "#" .. i + 9,
  313. function ()
  314. local screen = mouse.screen
  315. local tag = awful.tag.gettags(screen)[i]
  316. if tag then
  317. awful.tag.viewtoggle(tag)
  318. end
  319. end),
  320. -- Move client to tag.
  321. awful.key({ modkey, "Shift" }, "#" .. i + 9,
  322. function ()
  323. if client.focus then
  324. local tag = awful.tag.gettags(client.focus.screen)[i]
  325. if tag then
  326. awful.client.movetotag(tag)
  327. end
  328. end
  329. end),
  330. -- Toggle tag.
  331. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  332. function ()
  333. if client.focus then
  334. local tag = awful.tag.gettags(client.focus.screen)[i]
  335. if tag then
  336. awful.client.toggletag(tag)
  337. end
  338. end
  339. end))
  340. end
  341.  
  342. clientbuttons = awful.util.table.join(
  343. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  344. awful.button({ modkey }, 1, awful.mouse.client.move),
  345. awful.button({ modkey }, 3, awful.mouse.client.resize))
  346.  
  347. -- Set keys
  348. root.keys(globalkeys)
  349. -- }}}
  350.  
  351. -- {{{ Rules
  352. -- Rules to apply to new clients (through the "manage" signal).
  353. awful.rules.rules = {
  354. -- All clients will match this rule.
  355. { rule = { },
  356. properties = { border_width = beautiful.border_width,
  357. border_color = beautiful.border_normal,
  358. focus = awful.client.focus.filter,
  359. raise = true,
  360. keys = clientkeys,
  361. buttons = clientbuttons } },
  362. { rule = { class = "MPlayer" },
  363. properties = { floating = true } },
  364. { rule = { class = "pinentry" },
  365. properties = { floating = true } },
  366. { rule = { class = "gimp" },
  367. properties = { floating = true } },
  368. -- Set Firefox to always map on tags number 2 of screen 1.
  369. -- { rule = { class = "Firefox" },
  370. -- properties = { tag = tags[1][2] } },
  371. }
  372. -- }}}
  373.  
  374. -- {{{ Signals
  375. -- Signal function to execute when a new client appears.
  376. client.connect_signal("manage", function (c, startup)
  377. -- Enable sloppy focus
  378. c:connect_signal("mouse::enter", function(c)
  379. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  380. and awful.client.focus.filter(c) then
  381. client.focus = c
  382. end
  383. end)
  384.  
  385. if not startup then
  386. -- Set the windows at the slave,
  387. -- i.e. put it at the end of others instead of setting it master.
  388. -- awful.client.setslave(c)
  389.  
  390. -- Put windows in a smart way, only if they does not set an initial position.
  391. if not c.size_hints.user_position and not c.size_hints.program_position then
  392. awful.placement.no_overlap(c)
  393. awful.placement.no_offscreen(c)
  394. end
  395. end
  396.  
  397. local titlebars_enabled = false
  398. if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  399. -- buttons for the titlebar
  400. local buttons = awful.util.table.join(
  401. awful.button({ }, 1, function()
  402. client.focus = c
  403. c:raise()
  404. awful.mouse.client.move(c)
  405. end),
  406. awful.button({ }, 3, function()
  407. client.focus = c
  408. c:raise()
  409. awful.mouse.client.resize(c)
  410. end)
  411. )
  412.  
  413. -- Widgets that are aligned to the left
  414. local left_layout = wibox.layout.fixed.horizontal()
  415. left_layout:add(awful.titlebar.widget.iconwidget(c))
  416. left_layout:buttons(buttons)
  417.  
  418. -- Widgets that are aligned to the right
  419. local right_layout = wibox.layout.fixed.horizontal()
  420. right_layout:add(awful.titlebar.widget.floatingbutton(c))
  421. right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  422. right_layout:add(awful.titlebar.widget.stickybutton(c))
  423. right_layout:add(awful.titlebar.widget.ontopbutton(c))
  424. right_layout:add(awful.titlebar.widget.closebutton(c))
  425.  
  426. -- The title goes in the middle
  427. local middle_layout = wibox.layout.flex.horizontal()
  428. local title = awful.titlebar.widget.titlewidget(c)
  429. title:set_align("center")
  430. middle_layout:add(title)
  431. middle_layout:buttons(buttons)
  432.  
  433. -- Now bring it all together
  434. local layout = wibox.layout.align.horizontal()
  435. layout:set_left(left_layout)
  436. layout:set_right(right_layout)
  437. layout:set_middle(middle_layout)
  438.  
  439. awful.titlebar(c):set_widget(layout)
  440. end
  441. end)
  442.  
  443. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  444. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  445. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement