Guest User

Untitled

a guest
Jun 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.82 KB | None | 0 0
  1. -- Configuration for Awesome 3.4
  2. -- Copyright (C) 2011 Tuomas Jormola <tj@solitudo.net>
  3. --
  4. -- Licensed under the terms of GNU General Public License Version 2.0.
  5. --
  6. -- Features (see README for more detailed descriptions):
  7. --
  8. -- - awesome-freedesktop based menus
  9. -- - Symlink based autostarting of applications
  10. -- - Additional host specific configuration
  11. -- - Wibox with Delightful support
  12. -- - Almost default key bindings
  13. -- - Floating mode rules for many applications
  14.  
  15. require('posix')
  16. require('awful')
  17. require('awful.autofocus')
  18. require('awful.rules')
  19.  
  20. require('freedesktop.utils')
  21. require('freedesktop.menu')
  22.  
  23. require('debian.menu')
  24.  
  25. -- Variable definitions
  26.  
  27. -- This is used later as the default terminal and editor to run.
  28. terminal = 'gnome-terminal'
  29. freedesktop.utils.terminal = terminal
  30. editor = os.getenv('EDITOR') or 'editor'
  31. editor_cmd = string.format('%s -e %s', terminal, editor)
  32. mailer = 'mutt'
  33. mailer_cmd = string.format('%s -e %s', terminal, mailer)
  34. mixer = 'gnome-volume-control'
  35. mixer_cmd = mixer
  36.  
  37. -- Default modkey.
  38. -- Usually, Mod4 is the key with a logo between Control and Alt.
  39. -- If you do not like this or do not have such a key,
  40. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  41. -- However, you can use another modifier like Mod1, but it may interact with others.
  42. modkey = 'Mod4'
  43.  
  44. wibox_position = 'top'
  45. tagnum = 4
  46.  
  47. -- Autostart
  48. local autostart_dir = string.format('%s/autostart', awful.util.getdir('config'))
  49. local autostart_stat = posix.stat(autostart_dir)
  50. if autostart_stat and autostart_stat.type == 'directory' then
  51. local files = posix.dir(autostart_dir)
  52. if files then
  53. for _, file in pairs(files) do
  54. local full_file = string.format('%s/%s', autostart_dir, file)
  55. local file_stat = posix.stat(full_file)
  56. if file_stat and (file_stat.type == 'regular' or file_stat.type == 'link') then
  57. local command = full_file
  58. if file_stat.type == 'link' then
  59. local readlink_output = awful.util.pread(string.format('readlink %s', full_file))
  60. command = readlink_output:gsub('%s*$', '')
  61. end
  62. local basename = command:gsub('^.*/', '')
  63. if command then
  64. awful.util.spawn_with_shell(string.format('pgrep -u $USER -f "%s$" >/dev/null || ("%s" &)', basename, command))
  65. end
  66. end
  67. end
  68. end
  69. end
  70.  
  71. -- Themes
  72. -- Create a symlink from the given theme to ~/.config/awesome/current_theme
  73. function choose_theme(theme)
  74. local config = awful.util.getdir('config')
  75. awful.util.spawn(string.format('ln -sfn %s/themes/%s %s/current_theme', config, theme, config))
  76. awesome.restart()
  77. end
  78. -- Load current configured theme or default theme
  79. local check_themes = {
  80. string.format('%s/current_theme/theme.lua', awful.util.getdir('config')),
  81. '/usr/share/awesome/themes/default/theme.lua'
  82. }
  83. for i, v in pairs(check_themes) do
  84. if awful.util.file_readable(v) then
  85. beautiful.init(v)
  86. break
  87. end
  88. end
  89.  
  90. -- Menus
  91. function build_theme_menu()
  92. local menu = {}
  93. local themes_dir = string.format('%s/themes', awful.util.getdir('config'))
  94. local themes_stat = posix.stat(themes_dir)
  95. if themes_stat and themes_stat.type == 'directory' then
  96. local theme_dirs = posix.dir(themes_dir)
  97. for _, theme_name in pairs(theme_dirs) do
  98. local theme_dir = string.format('%s/%s', themes_dir, theme_name)
  99. local theme_stat = posix.stat(theme_dir)
  100. if theme_stat and (theme_stat.type == 'directory' or theme_stat.type == 'link') and not theme_name:find('^\.\.?$') then
  101. local item = { theme_name, function() choose_theme(theme_name) end }
  102. table.insert(menu, item)
  103. end
  104. end
  105. end
  106.  
  107. return menu
  108. end
  109.  
  110. local theme_menu = build_theme_menu()
  111.  
  112. local system_menu = {
  113. { 'Lock Screen', 'xscreensaver-command -lock', freedesktop.utils.lookup_icon({ icon = 'system-lock-screen' }) },
  114. { 'Logout', awesome.quit, freedesktop.utils.lookup_icon({ icon = 'system-log-out' }) },
  115. { 'Reboot System', 'gksudo "shutdown -r now"', freedesktop.utils.lookup_icon({ icon = 'reboot-notifier' }) },
  116. { 'Shutdown System', 'gksudo "shutdown -h now"', freedesktop.utils.lookup_icon({ icon = 'system-shutdown' }) }
  117. }
  118.  
  119. local awesome_menu = {
  120. { 'Themes', theme_menu, freedesktop.utils.lookup_icon({ icon = 'preferences-desktop-theme' }) },
  121. { 'Restart Awesome', awesome.restart, freedesktop.utils.lookup_icon({ icon = 'gtk-refresh' }) },
  122. }
  123.  
  124. top_menu = {
  125. { 'Applications', freedesktop.menu.new(), freedesktop.utils.lookup_icon({ icon = 'start-here' }) },
  126. { 'Debian', debian.menu.Debian_menu.Debian, freedesktop.utils.lookup_icon({ icon = 'debian-logo' }) },
  127. { 'Awesome', awesome_menu, beautiful.awesome_icon },
  128. { 'System', system_menu, freedesktop.utils.lookup_icon({ icon = 'system' }) },
  129. { 'Terminal', freedesktop.utils.terminal, freedesktop.utils.lookup_icon({ icon = 'terminal' }) }
  130. }
  131.  
  132. -- Tags
  133. -- Table of layouts to cover with awful.layout.inc, order matters.
  134. layouts = {
  135. awful.layout.suit.floating,
  136. awful.layout.suit.tile,
  137. awful.layout.suit.tile.left,
  138. awful.layout.suit.tile.bottom,
  139. awful.layout.suit.tile.top,
  140. awful.layout.suit.fair,
  141. awful.layout.suit.fair.horizontal,
  142. awful.layout.suit.spiral,
  143. awful.layout.suit.spiral.dwindle,
  144. awful.layout.suit.max,
  145. awful.layout.suit.max.fullscreen,
  146. awful.layout.suit.magnifier
  147. }
  148.  
  149. tags = {}
  150. local tagtable = {}
  151. for i = 1, tagnum do
  152. table.insert(tagtable, i)
  153. end
  154. -- Define a tag table which hold all screen tags.
  155. for s = 1, screen.count() do
  156. -- Each screen has its own tag table.
  157. tags[s] = awful.tag(tagtable, s, layouts[4])
  158. end
  159.  
  160. -- Local local config file
  161. local hostname = awful.util.pread('hostname -s'):gsub('\n', '')
  162. local host_config_file = awful.util.getdir('config') .. '/rc.' .. hostname .. '.lua'
  163. if awful.util.file_readable(host_config_file) then
  164. local host_config_function, host_config_load_error
  165. host_config_function, host_config_load_error = loadfile(host_config_file)
  166. if not host_config_load_error then
  167. host_config_function()
  168. else
  169. print(string.format('[awesome] Failed to load %s: %s', host_config_file, host_config_load_error))
  170. end
  171. end
  172.  
  173. -- Wibox
  174. local delightful_container = { widgets = {}, icons = {} }
  175. if install_delightful then
  176. for _, widget in pairs(awful.util.table.reverse(install_delightful)) do
  177. local config = delightful_config and delightful_config[widget]
  178. local widgets, icons = widget:load(config)
  179. if not icons then
  180. icons = {}
  181. end
  182. table.insert(delightful_container.widgets, awful.util.table.reverse(widgets))
  183. table.insert(delightful_container.icons, awful.util.table.reverse(icons))
  184. end
  185. end
  186.  
  187. local taglist = {}
  188. taglist.buttons = awful.util.table.join(
  189. awful.button({ }, 1, awful.tag.viewonly ),
  190. awful.button({ modkey }, 1, awful.client.movetotag),
  191. awful.button({ }, 3, awful.tag.viewtoggle ),
  192. awful.button({ modkey }, 3, awful.client.toggletag),
  193. awful.button({ }, 4, awful.tag.viewnext ),
  194. awful.button({ }, 5, awful.tag.viewprev )
  195. )
  196.  
  197. local tasklist = {}
  198. tasklist.buttons = awful.util.table.join(
  199. awful.button({ }, 1,
  200. function(c)
  201. if not c:isvisible() then
  202. awful.tag.viewonly(c:tags()[1])
  203. end
  204. client.focus = c
  205. c:raise()
  206. end),
  207. awful.button({ }, 3,
  208. function()
  209. if instance then
  210. instance:hide()
  211. instance = nil
  212. else
  213. instance = awful.menu.clients({ width = 250 })
  214. end
  215. end),
  216. awful.button({ }, 4,
  217. function()
  218. awful.client.focus.byidx(1)
  219. if client.focus then
  220. client.focus:raise()
  221. end
  222. end),
  223. awful.button({ }, 5,
  224. function()
  225. awful.client.focus.byidx(-1)
  226. if client.focus then
  227. client.focus:raise()
  228. end
  229. end)
  230. )
  231.  
  232. local main_menu = awful.menu.new({ items = top_menu, width = 150 })
  233. local wibox = {}
  234. local layoutbox = {}
  235. local promptbox = {}
  236. local launcher = awful.widget.launcher({ image = image(beautiful.awesome_icon), menu = main_menu })
  237. local systray = widget({ type = 'systray' })
  238. local spacer = widget({ type = 'textbox', name = 'spacer' })
  239. local separator = widget({ type = 'textbox', name = 'separator' })
  240. spacer.text = ' '
  241. separator.text = '|'
  242.  
  243. for s = 1, screen.count() do
  244. promptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  245.  
  246. layoutbox[s] = awful.widget.layoutbox(s)
  247. layoutbox[s]:buttons(awful.util.table.join(
  248. awful.button({ }, 1, function() awful.layout.inc(layouts, 1) end),
  249. awful.button({ }, 3, function() awful.layout.inc(layouts, -1) end),
  250. awful.button({ }, 4, function() awful.layout.inc(layouts, 1) end),
  251. awful.button({ }, 5, function() awful.layout.inc(layouts, -1) end)
  252. ))
  253.  
  254. taglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, taglist.buttons)
  255.  
  256. tasklist[s] = awful.widget.tasklist(
  257. function(c)
  258. return awful.widget.tasklist.label.currenttags(c, s)
  259. end,
  260. tasklist.buttons
  261. )
  262.  
  263. wibox[s] = awful.wibox({ position = wibox_position, screen = s })
  264. local widgets_front = {
  265. {
  266. launcher,
  267. taglist[s],
  268. promptbox[s],
  269. spacer,
  270. layout = awful.widget.layout.horizontal.leftright
  271. },
  272. layoutbox[s],
  273. spacer,
  274. }
  275. local widgets_middle = {}
  276. for delightful_container_index, delightful_container_data in pairs(delightful_container.widgets) do
  277. table.insert(widgets_middle, separator)
  278. for widget_index, widget_data in pairs(delightful_container_data) do
  279. if delightful_container_index > 1 then
  280. table.insert(widgets_middle, spacer)
  281. end
  282. table.insert(widgets_middle, widget_data)
  283. if delightful_container.icons[delightful_container_index] and delightful_container.icons[delightful_container_index][widget_index] then
  284. table.insert(widgets_middle, delightful_container.icons[delightful_container_index][widget_index])
  285. end
  286. if delightful_container_index > 1 and widget_index == #delightful_container_data then
  287. table.insert(widgets_middle, spacer)
  288. end
  289. end
  290. end
  291. local widgets_end = {
  292. (s == 1 and #delightful_container.widgets > 0) and separator or nil,
  293. s == 1 and systray or nil,
  294. tasklist[s],
  295. layout = awful.widget.layout.horizontal.rightleft,
  296. }
  297. wibox[s].widgets = awful.util.table.join(widgets_front, widgets_middle, widgets_end)
  298. end
  299.  
  300. -- Mouse bindings
  301. root.buttons(awful.util.table.join(
  302. awful.button({ }, 3, function() main_menu:toggle() end),
  303. awful.button({ }, 4, awful.tag.viewnext ),
  304. awful.button({ }, 5, awful.tag.viewprev )
  305. ))
  306.  
  307. -- Key bindings
  308. local globalkeys = awful.util.table.join(
  309. awful.key({ modkey, }, 'Left', awful.tag.viewprev ),
  310. awful.key({ modkey, }, 'Right', awful.tag.viewnext ),
  311. awful.key({ modkey, }, 'Escape', awful.tag.history.restore ),
  312.  
  313. awful.key({ modkey, }, "j",
  314. function ()
  315. awful.client.focus.byidx( 1)
  316. if client.focus then client.focus:raise() end
  317. end),
  318. awful.key({ modkey, }, "k",
  319. function ()
  320. awful.client.focus.byidx(-1)
  321. if client.focus then client.focus:raise() end
  322. end),
  323. awful.key({ modkey, }, 'w', function() main_menu:show(true) end),
  324. awful.key({ modkey, }, 'q', function() awful.menu.clients({width=245}) end),
  325.  
  326. -- Layout manipulation
  327. awful.key({ modkey, 'Shift' }, 'j', function() awful.client.swap.byidx( 1) end),
  328. awful.key({ modkey, 'Shift' }, 'k', function() awful.client.swap.byidx( -1) end),
  329. awful.key({ modkey, 'Control' }, 'j', function() awful.screen.focus_relative( 1) end),
  330. awful.key({ modkey, 'Control' }, 'k', function() awful.screen.focus_relative(-1) end),
  331. awful.key({ modkey, }, 'u', awful.client.urgent.jumpto ),
  332. awful.key({ modkey, }, 'Tab',
  333. function()
  334. awful.client.focus.byidx( 1)
  335. if client.focus then
  336. client.focus:raise()
  337. end
  338. end),
  339. awful.key({ modkey, 'Shift' }, 'Tab',
  340. function()
  341. awful.client.focus.byidx(-1)
  342. if client.focus then
  343. client.focus:raise()
  344. end
  345. end),
  346.  
  347. -- Standard program
  348. awful.key({ modkey, }, 'Return', function() awful.util.spawn(terminal) end),
  349. awful.key({ modkey, 'Control' }, 'r', awesome.restart ),
  350. awful.key({ modkey, 'Shift' }, 'q', awesome.quit ),
  351.  
  352. awful.key({ modkey, }, 'l', function() awful.tag.incmwfact( 0.05) end),
  353. awful.key({ modkey, }, 'h', function() awful.tag.incmwfact(-0.05) end),
  354. awful.key({ modkey, 'Shift' }, 'h', function() awful.tag.incnmaster( 1) end),
  355. awful.key({ modkey, 'Shift' }, 'l', function() awful.tag.incnmaster(-1) end),
  356. awful.key({ modkey, 'Control' }, 'h', function() awful.tag.incncol( 1) end),
  357. awful.key({ modkey, 'Control' }, 'l', function() awful.tag.incncol(-1) end),
  358. awful.key({ modkey, }, 'space', function() awful.layout.inc(layouts, 1) end),
  359. awful.key({ modkey, 'Shift' }, 'space', function() awful.layout.inc(layouts, -1) end),
  360.  
  361. -- Prompt
  362. awful.key({ modkey }, 'r', function() promptbox[mouse.screen]:run() end)
  363. )
  364.  
  365. local clientkeys = awful.util.table.join(
  366. awful.key({ modkey }, 'Next', function() awful.client.moveresize( 20, 20, -40, -40) end),
  367. awful.key({ modkey }, 'Prior', function() awful.client.moveresize(-20, -20, 40, 40) end),
  368. awful.key({ modkey }, 'Home', function() awful.client.moveresize( 0, 20, 0, 0) end),
  369. awful.key({ modkey }, 'Insert', function() awful.client.moveresize( 0, -20, 0, 0) end),
  370. awful.key({ modkey }, 'Delete', function() awful.client.moveresize(-20, 0, 0, 0) end),
  371. awful.key({ modkey }, 'End', function() awful.client.moveresize( 20, 0, 0, 0) end),
  372. awful.key({ modkey, }, 'f', function(c) c.fullscreen = not c.fullscreen end),
  373. awful.key({ modkey, 'Shift' }, 'c', function(c) c:kill() end),
  374. awful.key({ modkey, 'Control' }, 'space', awful.client.floating.toggle ),
  375. awful.key({ modkey, 'Control' }, 'Return', function(c) c:swap(awful.client.getmaster()) end),
  376. awful.key({ modkey, }, 'o', awful.client.movetoscreen ),
  377. awful.key({ modkey, 'Shift' }, 'r', function(c) c:redraw() end),
  378. awful.key({ modkey, }, 'n', function(c) c.minimized = not c.minimized end),
  379. awful.key({ modkey, }, 'm',
  380. function(c)
  381. c.maximized_horizontal = not c.maximized_horizontal
  382. c.maximized_vertical = not c.maximized_vertical
  383. end),
  384. awful.key({ modkey, }, 't',
  385. function(c)
  386. local t = awful.client.property.get(c, 'titlebar') or false
  387. awful.client.property.set(c, 'titlebar', not t)
  388. if t then
  389. awful.titlebar.remove(c)
  390. else
  391. awful.titlebar.add(c, { modkey = modkey })
  392. end
  393. end)
  394. )
  395.  
  396. -- Add host client key bindings
  397. if host_clientkeys then
  398. clientkeys = awful.util.table.join(clientkeys, host_clientkeys)
  399. end
  400.  
  401. -- Compute the maximum number of digit we need, limited to 9
  402. local keynumber = 0
  403. for s = 1, screen.count() do
  404. keynumber = math.min(9, math.max(#tags[s], keynumber));
  405. end
  406.  
  407. -- Bind all key numbers to tags.
  408. -- Be careful: we use keycodes to make it works on any keyboard layout.
  409. -- This should map on the top row of your keyboard, usually 1 to 9.
  410. for i = 1, keynumber do
  411. globalkeys = awful.util.table.join(globalkeys,
  412. awful.key({ modkey }, '#' .. i + 9,
  413. function()
  414. local screen = mouse.screen
  415. if tags[screen][i] then
  416. awful.tag.viewonly(tags[screen][i])
  417. end
  418. end),
  419. awful.key({ modkey, 'Control' }, '#' .. i + 9,
  420. function()
  421. local screen = mouse.screen
  422. if tags[screen][i] then
  423. awful.tag.viewtoggle(tags[screen][i])
  424. end
  425. end),
  426. awful.key({ modkey, 'Shift' }, '#' .. i + 9,
  427. function()
  428. if client.focus and tags[client.focus.screen][i] then
  429. awful.client.movetotag(tags[client.focus.screen][i])
  430. end
  431. end),
  432. awful.key({ modkey, 'Control', 'Shift' }, '#' .. i + 9,
  433. function()
  434. if client.focus and tags[client.focus.screen][i] then
  435. awful.client.toggletag(tags[client.focus.screen][i])
  436. end
  437. end)
  438. )
  439. end
  440.  
  441. -- Add host global key bindings
  442. if host_globalkeys then
  443. globalkeys = awful.util.table.join(globalkeys, host_globalkeys)
  444. end
  445.  
  446. local clientbuttons = awful.util.table.join(
  447. awful.button({ }, 1, function(c) client.focus = c; c:raise() end),
  448. awful.button({ modkey }, 1, awful.mouse.client.move ),
  449. awful.button({ modkey }, 3, awful.mouse.client.resize )
  450. )
  451.  
  452. root.keys(globalkeys)
  453.  
  454. -- Rules
  455. awful.rules.rules = {
  456. -- All clients will match this rule.
  457. {
  458. rule = { },
  459. properties = {
  460. border_width = beautiful.border_width,
  461. border_color = beautiful.border_normal,
  462. focus = true,
  463. keys = clientkeys,
  464. buttons = clientbuttons
  465. }
  466. },
  467. {
  468. rule = { class = 'MPlayer' },
  469. properties = { floating = true }
  470. },
  471. {
  472. rule = { class = 'Vlc' },
  473. properties = { floating = true }
  474. },
  475. {
  476. rule = { class = 'jive' },
  477. properties = { floating = true }
  478. },
  479. {
  480. rule = { class = 'Rhythmbox' },
  481. properties = { floating = true }
  482. },
  483. {
  484. rule = { class = 'Nautilus' },
  485. properties = { floating = true }
  486. },
  487. {
  488. rule = { class = 'pinentry' },
  489. properties = { floating = true }
  490. },
  491. {
  492. rule = { class = 'Gimp' },
  493. properties = { floating = true }
  494. },
  495. {
  496. rule = { class = 'Firefox' },
  497. properties = { floating = true }
  498. },
  499. {
  500. rule = { class = 'Vmware' },
  501. properties = { floating = true }
  502. },
  503. {
  504. rule = { class = 'Vncviewer' },
  505. properties = { floating = true }
  506. },
  507. }
  508. -- Add host rules
  509. if host_rules then
  510. awful.rules.rules = awful.util.table.join(awful.rules.rules, host_rules)
  511. end
  512.  
  513. -- Signals
  514. -- Signal function to execute when a new client appears.
  515. client.add_signal('manage',
  516. function(c, startup)
  517. -- Enable sloppy focus
  518. c:add_signal('mouse::enter',
  519. function(c)
  520. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  521. and awful.client.focus.filter(c) then
  522. client.focus = c
  523. end
  524. end
  525. )
  526.  
  527. if not startup then
  528. -- Set the windows at the slave,
  529. -- i.e. put it at the end of others instead of setting it master.
  530. awful.client.setslave(c)
  531.  
  532. -- Put windows in a smart way, only if they does not set an initial position.
  533. if not c.size_hints.user_position and not c.size_hints.program_position then
  534. awful.placement.no_overlap(c)
  535. awful.placement.no_offscreen(c)
  536. end
  537. end
  538. end
  539. )
  540.  
  541. client.add_signal('focus', function(c) c.border_color = beautiful.border_focus end)
  542. client.add_signal('unfocus', function(c) c.border_color = beautiful.border_normal end)
Add Comment
Please, Sign In to add comment