Guest User

myawesomewmconfig

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