Guest User

Untitled

a guest
Oct 17th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.61 KB | None | 0 0
  1. require('awful')
  2. require('awful.rules')
  3. require('awful.autofocus')
  4. require('beautiful')
  5. require('eminent')
  6. require('naughty')
  7.  
  8. -- Constants
  9. terminal = 'gnome-terminal'
  10. editor = 'gvim'
  11. modkey = 'Mod4'
  12. dmenu = 'dmenu_run -p "command:" -nb "#222222" -nf "#808080" -sb "#256fb4" -sf "#ffffff" -l 10 -fn "-misc-fixed-medium-*-normal-*-14-*-*-*-*-*-*-*"'
  13.  
  14. system_tray_screen = 1
  15. widgets_screen = 1
  16. cursor_name = 'left_ptr'
  17.  
  18. if screen.count() > 1 then
  19.     widgets_screen = 2
  20. end
  21.  
  22. -- Set root cursor
  23. root.cursor(cursor_name)
  24.  
  25. -- Function used to focus clients on workspace change
  26. function focus_screen(screen_index)
  27.     if screen_index ~= mouse.screen then
  28.         local pos_x = math.floor(screen[screen_index].workarea.width / 2)
  29.         local pos_y = math.floor(screen[screen_index].workarea.height / 2)
  30.  
  31.         pos_x = pos_x + screen[screen_index].geometry.x
  32.         pos_y = pos_y + screen[screen_index].geometry.y
  33.  
  34.         awful.screen.focus(screen_index)
  35.         mouse.coords({x = pos_x, y = pos_y}, false)
  36.     end
  37. end
  38.  
  39. -- Initialize default theme
  40. theme_path = '/usr/share/awesome/themes/default/theme.lua'
  41. theme_path = '/home/meaneye/.config/awesome/wave/theme.lua'
  42. beautiful.init(theme_path)
  43.  
  44. awesome.font = 'Ubuntu 9'
  45. theme.font = awesome.font
  46. theme.taglist_font = awesome.font
  47.  
  48. -- Table of layouts to cover with awful.layout.inc, order matters.
  49. layouts = {
  50.     awful.layout.suit.tile,
  51.     awful.layout.suit.tile.left,
  52.     awful.layout.suit.tile.bottom,
  53.     awful.layout.suit.tile.top,
  54.     awful.layout.suit.fair,
  55.     awful.layout.suit.fair.horizontal,
  56.     awful.layout.suit.max
  57. }
  58.  
  59. -- Configure tags for each screen
  60. tags = {}
  61. tags_by_name = {}
  62.  
  63. if screen.count() == 2 then
  64.     -- Create tags for each screen individually
  65.     tags[1] = awful.tag({'Web', 'FM', 6, 7, 8, 9}, 1, layouts[1])
  66.     tags[2] = awful.tag({'Chat', 'Code', 'Misc', 6, 7, 8, 9}, 2, layouts[1])
  67.  
  68.     tags_by_name.chat = tags[2][1]
  69.     tags_by_name.web = tags[1][1]
  70.     tags_by_name.code = tags[2][2]
  71.     tags_by_name.misc = tags[2][3]
  72.     tags_by_name.fm = tags[1][2]
  73.  
  74. elseif screen.count() == 3 then
  75.     -- Create tags for each screen individually
  76.     tags[1] = awful.tag({'Web', 'FM', 6, 7, 8, 9}, 1, layouts[1])
  77.     tags[2] = awful.tag({'Chat', 'Code', 'Misc', 6, 7, 8, 9}, 2, layouts[1])
  78.     tags[3] = awful.tag({'TV'}, 3, layouts[1])
  79.  
  80.     tags_by_name.chat = tags[2][1]
  81.     tags_by_name.web = tags[1][1]
  82.     tags_by_name.code = tags[2][2]
  83.     tags_by_name.misc = tags[2][3]
  84.     tags_by_name.fm = tags[1][2]
  85.  
  86. else
  87.     -- We are operating on a single screen
  88.     tags[1] = awful.tag({'Chat', 'Web', 'Code', 'Misc', 'FM', 6, 7, 8, 9}, 1, layouts[1])
  89.  
  90.     tags_by_name.chat = tags[1][1]
  91.     tags_by_name.web = tags[1][2]
  92.     tags_by_name.code = tags[1][3]
  93.     tags_by_name.misc = tags[1][4]
  94.     tags_by_name.fm = tags[1][5]
  95. end
  96.  
  97. -- Create widgets
  98. items_main_menu = {
  99.     {'Terminal', terminal},
  100.     {'Sunflower', 'sunflower'},
  101.     {'Restart', awesome.restart},
  102.     {'Logout', awesome.quit}
  103. }
  104.  
  105. main_menu = awful.menu({items = items_main_menu})
  106. launcher_main_menu = awful.widget.launcher({image = image(beautiful.awesome_icon), menu = main_menu})
  107.  
  108. -- Create system tray
  109. system_tray = widget({type ='systray'})
  110.  
  111. -- Create tag lists
  112. tag_list = {}
  113. tag_list.buttons = awful.util.table.join(
  114.                     awful.button({}, 1, awful.tag.viewonly),
  115.                     awful.button({modkey}, 1, awful.client.movetotag),
  116.                     awful.button({}, 3, awful.tag.viewtoggle),
  117.                     awful.button({modkey}, 3, awful.client.toggletag),
  118.                     awful.button({}, 4, awful.tag.viewprev),
  119.                     awful.button({}, 5, awful.tag.viewnext)
  120.                 )
  121.  
  122. -- Create toolbar for each screen
  123. toolbars = {}
  124. layout_box = {}
  125.  
  126. for screen_index = 1, screen.count() do
  127.     options = {
  128.         position = 'top',
  129.         screen = screen_index,
  130.         height = beautiful.bar_height,
  131.         cursor = cursor_name
  132.     }
  133.  
  134.     -- Create new toolbar (wibox)
  135.     toolbars[screen_index] = awful.wibox(options)
  136.  
  137.     -- Create tag list for each screen
  138.     tag_list[screen_index] = awful.widget.taglist(
  139.                                             screen_index,
  140.                                             awful.widget.taglist.label.all,
  141.                                             tag_list.buttons
  142.                                         )
  143.  
  144.     -- Create layout box which displays current layout of windows
  145.     layout_box[screen_index] = awful.widget.layoutbox(screen_index)
  146.     layout_box[screen_index]:buttons(awful.util.table.join(
  147.                             awful.button({}, 1, function() awful.layout.inc(layouts, 1) end),
  148.                             awful.button({}, 3, function() awful.layout.inc(layouts, -1) end),
  149.                             awful.button({}, 4, function() awful.layout.inc(layouts, 1) end),
  150.                             awful.button({}, 5, function() awful.layout.inc(layouts, -1) end))
  151.                         )
  152.  
  153.     toolbars[screen_index].widgets = {
  154.         {
  155.             launcher_main_menu,
  156.             tag_list[screen_index],
  157.             layout = awful.widget.layout.horizontal.leftright
  158.         },
  159.         layout_box[screen_index],
  160.         screen_index == system_tray_screen and system_tray or nil,
  161.         screen_index == widgets_screen and theme.widgets or nil,
  162.         layout = awful.widget.layout.horizontal.rightleft
  163.     }
  164. end
  165.  
  166. -- Set key and mouse handlers
  167. container_buttons = awful.util.table.join(
  168.     awful.button({}, 1, function(container) client.focus = container; container:raise() end),
  169.     awful.button({modkey}, 1, awful.mouse.client.move),
  170.     awful.button({modkey}, 3, awful.mouse.client.resize)
  171. )
  172.  
  173. container_keys = awful.util.table.join(
  174.     awful.key({'Mod1'}, 'F4', function(container) container:kill() end),
  175.     awful.key({modkey, 'Shift'}, 'space', awful.client.floating.toggle),
  176.     awful.key({modkey}, 'f', function(container) container.fullscreen = not container.fullscreen end),
  177.     awful.key({modkey}, 'm', function(container)
  178.         container.maximized_horizontal = not container.maximized_horizontal
  179.         container.maximized_vertical = not container.maximized_vertical
  180.     end)
  181. )
  182.  
  183. global_keys = awful.util.table.join(
  184.     awful.key({modkey}, 'F1', function() awful.util.spawn(terminal) end),
  185.     awful.key({modkey}, 'F2', function() awful.util.spawn(editor) end),
  186.     awful.key({'Mod1'}, 'F2', function() awful.util.spawn(dmenu) end),
  187.     awful.key({modkey, 'Shift'}, 'r', awesome.restart),
  188.     awful.key({modkey}, 'Return', function() awful.layout.inc(layouts, 1) end),
  189.     awful.key({modkey, 'Shift'}, 'Return', function() awful.layout.inc(layouts, -1) end),
  190.     awful.key({'Mod1'}, 'Tab', function()
  191.         awful.client.focus.history.previous()
  192.         if client.focus then
  193.             client.focus:raise()
  194.         end
  195.     end),
  196.     awful.key({modkey}, 'Right', function()
  197.         awful.client.focus.bydirection('right')
  198.         if client.focus then client.focus:raise() end
  199.     end),
  200.     awful.key({modkey}, 'Left', function()
  201.         awful.client.focus.bydirection('left')
  202.         if client.focus then client.focus:raise() end
  203.     end),
  204.     awful.key({modkey}, 'Up', function()
  205.         awful.client.focus.bydirection('up')
  206.         if client.focus then client.focus:raise() end
  207.     end),
  208.     awful.key({modkey}, 'Down', function()
  209.         awful.client.focus.bydirection('down')
  210.         if client.focus then client.focus:raise() end
  211.     end),
  212.     awful.key({modkey, 'Shift'}, 'Right', function()
  213.         awful.client.swap.bydirection('right')
  214.         if client.focus then client.focus:raise() end
  215.     end),
  216.     awful.key({modkey, 'Shift'}, 'Left', function()
  217.         awful.client.swap.bydirection('left')
  218.         if client.focus then client.focus:raise() end
  219.     end),
  220.     awful.key({modkey, 'Shift'}, 'Up', function()
  221.         awful.client.swap.bydirection('up')
  222.         if client.focus then client.focus:raise() end
  223.     end),
  224.     awful.key({modkey, 'Shift'}, 'Down', function()
  225.         awful.client.swap.bydirection('down')
  226.         if client.focus then client.focus:raise() end
  227.     end),
  228.     awful.key({modkey}, '1', function()
  229.         awful.tag.viewonly(tags_by_name.chat)
  230.         focus_screen(tags_by_name.chat.screen)
  231.     end),
  232.     awful.key({modkey}, '2', function()
  233.         awful.tag.viewonly(tags_by_name.web)
  234.         focus_screen(tags_by_name.web.screen)
  235.     end),
  236.     awful.key({modkey}, '3', function()
  237.         awful.tag.viewonly(tags_by_name.code)
  238.         focus_screen(tags_by_name.code.screen)
  239.     end),
  240.     awful.key({modkey}, '4', function()
  241.         awful.tag.viewonly(tags_by_name.misc)
  242.         focus_screen(tags_by_name.misc.screen)
  243.     end),
  244.     awful.key({modkey}, '5', function()
  245.         awful.tag.viewonly(tags_by_name.fm)
  246.         focus_screen(tags_by_name.fm.screen)
  247.     end),
  248.     awful.key({modkey, 'Shift'}, '1', function() awful.tag.movetotag(tags_by_name.chat) end),
  249.     awful.key({modkey, 'Shift'}, '2', function() awful.tag.movetotag(tags_by_name.web) end),
  250.     awful.key({modkey, 'Shift'}, '3', function() awful.tag.movetotag(tags_by_name.code) end),
  251.     awful.key({modkey, 'Shift'}, '4', function() awful.tag.movetotag(tags_by_name.misc) end),
  252.     awful.key({modkey, 'Shift'}, '5', function() awful.tag.movetotag(tags_by_name.fm) end)
  253. )
  254.  
  255. -- Bind the rest of the numbers
  256. for index = 6, 9 do
  257.     global_keys = awful.util.table.join(global_keys,
  258.         awful.key({modkey}, index, function()
  259.             local screen_count = screen.count()
  260.             local screen = mouse.screen
  261.             local tag_index = index
  262.  
  263.             if screen_count > 1 then
  264.                 tag_index = screen == 1 and index - 3 or index - 2
  265.             end
  266.  
  267.             awful.tag.viewonly(tags[screen][tag_index])
  268.             grab_focus()
  269.         end))
  270. end
  271.  
  272. -- Connect root keys and buttons
  273. root.buttons(awful.util.table.join(
  274.     awful.button({}, 3, function () main_menu:toggle() end),
  275.     awful.button({}, 4, awful.tag.viewnext),
  276.     awful.button({}, 5, awful.tag.viewprev)
  277. ))
  278.  
  279. root.keys(global_keys)
  280.  
  281. -- Set general rules
  282. awful.rules.rules = {
  283.     {
  284.         rule = {},
  285.         properties = {
  286.             border_width = beautiful.border_width,
  287.             border_color = beautiful.border_color,
  288.             focus = true,
  289.             keys = container_keys,
  290.             buttons = container_buttons,
  291.             size_hints_honor = false
  292.         }
  293.     },
  294.     {
  295.         rule = {class = "Pidgin"},
  296.         properties = {
  297.             tag = tags_by_name.chat
  298.         }
  299.     },
  300.     {
  301.         rule = {class = "Pidgin", role = "buddy_list"},
  302.         properties = {
  303.             floating = true
  304.         },
  305.         callback = function(container)
  306.             local work_area = screen[container.screen].workarea
  307.             local window_width = 250
  308.  
  309.             container:struts({right = window_width})
  310.             container:geometry({
  311.                 x = work_area.width - window_width,
  312.                 width = window_width,
  313.                 y = work_area.y,
  314.                 height = work_area.height
  315.             })
  316.         end
  317.     },
  318.     {
  319.         rule = {role = "irc_chat"},
  320.         properties = {
  321.             tag = tags_by_name.chat
  322.         }
  323.     },
  324.     {
  325.         rule = {role = "music_player"},
  326.         properties = {
  327.             tag = tags_by_name.chat
  328.         }
  329.     },
  330.     {
  331.         rule = {class = "Google-chrome"},
  332.         properties = {
  333.             tag = tags_by_name.web
  334.         }
  335.     },
  336.     {
  337.         rule = {class = "Gimp"},
  338.         properties = {
  339.             tag = tags_by_name.misc
  340.         }
  341.     },
  342.     {
  343.         rule = {class = "Bcompare"},
  344.         properties = {
  345.             tag = tags_by_name.misc
  346.         }
  347.     },
  348.     {
  349.         rule = {class = "Sunflower"},
  350.         properties = {
  351.             tag = tags_by_name.fm
  352.         }
  353.     }
  354. }
  355.  
  356. -- Handle signals
  357. client.add_signal('manage', function (container, startup)
  358.     -- Add a titlebar
  359.     options = {
  360.         modkey = modkey,
  361.         height = 16
  362.     }
  363.  
  364.     -- awful.titlebar.add(container, options)
  365.  
  366.     if not startup then
  367.         -- Set the windows at the slave,
  368.         -- i.e. put it at the end of others instead of setting it master.
  369.         -- awful.client.setslave(c)
  370.  
  371.         -- Put windows in a smart way, only if they does not set an initial position.
  372.         if not container.size_hints.user_position and not container.size_hints.program_position then
  373.             awful.placement.no_overlap(container)
  374.             awful.placement.no_offscreen(container)
  375.         end
  376.     end
  377. end)
  378.  
  379. client.add_signal('focus', function(container) container.border_color = beautiful.border_focus end)
  380. client.add_signal('unfocus', function(container) container.border_color = beautiful.border_normal end)
  381.  
  382. -- Execute required programs
  383. awful.util.spawn_with_shell('gnome-settings-daemon')
  384. awful.util.spawn_with_shell('bluetooth-applet')
  385. awful.util.spawn_with_shell('nm-applet')
  386. awful.util.spawn_with_shell('~/.mouse.sh')
  387. awful.util.spawn_with_shell('gnome-terminal -e irssi --role "irc_chat"')
  388. awful.util.spawn_with_shell('gnome-terminal -e cmus --role "music_player"')
  389. awful.util.spawn_with_shell('pidgin')
  390. awful.util.spawn_with_shell('sleep 2; google-chrome')
Add Comment
Please, Sign In to add comment