Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.91 KB | None | 0 0
  1. -- Modules
  2. gears = require("gears")
  3. awful = require("awful")
  4. awful.rules = require("awful.rules")
  5. awful.autofocus = require("awful.autofocus")
  6. wibox = require("wibox") -- Widget box
  7. naughty = require("naughty") -- Notification
  8. beautiful = require("beautiful") -- Theming
  9. lain = require("lain") -- Additional widgets and layouts
  10. vicious = require("vicious") -- Widget library
  11. menubar = require("menubar") -- Menubar: dmenu-like launcher
  12. volume = require("volume") -- Widget displaying volume information
  13.  
  14.  
  15. -- Variables
  16. home_path = os.getenv('HOME') .. '/'
  17. terminal = "x-terminal-emulator"
  18. menubar.utils.terminal = terminal -- Set terminal for applications which require it
  19. editor = "geany"
  20. modkey = "Mod4" -- Meta/Win
  21. modkey_alt = "Mod1" -- Alt
  22.  
  23. -- Appearance
  24. beautiful.init(awful.util.getdir("config") .. "/themes/default/theme.lua")
  25. if beautiful.wallpaper then
  26.     for s = 1, screen.count() do
  27.         gears.wallpaper.maximized(beautiful.wallpaper, s, true)
  28.     end
  29. end
  30.  
  31. -- Returns true if all pairs in table1 are present in table2 (for use by "Run of raise")
  32. function match (table1, table2)
  33.    for k, v in pairs(table1) do
  34.       if table2[k] ~= v and not table2[k]:find(v) then
  35.          return false
  36.       end
  37.    end
  38.    return true
  39. end
  40.  
  41. -- "Run or raise" function
  42. function run_or_raise(cmd, properties)
  43.    local clients = client.get()
  44.    local focused = awful.client.next(0)
  45.    local findex = 0
  46.    local matched_clients = {}
  47.    local n = 0
  48.    for i, c in pairs(clients) do
  49.       -- make an array of matched clients
  50.       if match(properties, c) then
  51.          n = n + 1
  52.          matched_clients[n] = c
  53.          if c == focused then
  54.             findex = n
  55.          end
  56.       end
  57.    end
  58.    if n > 0 then
  59.       local c = matched_clients[1]
  60.       -- if the focused window matched switch focus to next in list
  61.       if 0 < findex and findex < n then
  62.          c = matched_clients[findex+1]
  63.       end
  64.       local ctags = c:tags()
  65.       if #ctags == 0 then
  66.          -- ctags is empty, show client on current tag
  67.          local curtag = awful.tag.selected()
  68.          awful.client.movetotag(curtag, c)
  69.       else
  70.          -- Otherwise, pop to first tag client is visible on
  71.          awful.tag.viewonly(ctags[1])
  72.       end
  73.       -- And then focus the client
  74.       client.focus = c
  75.       c:raise()
  76.       return
  77.    end
  78.    awful.util.spawn(cmd)
  79. end
  80.  
  81. -- "Run once" function
  82. function run_once(prg,arg_string,pname,screen) -- Run PRG once with command-line ARGuments, expecting PNAME as process name on SCREEN
  83.     if not prg then
  84.         do return nil end
  85.     end
  86.  
  87.     if not pname then
  88.        pname = prg
  89.     end
  90.  
  91.     if not arg_string then
  92.         awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. "' || (" .. prg .. ")",screen)
  93.     else
  94.         awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. " ".. arg_string .."' || (" .. prg .. " " .. arg_string .. ")",screen)
  95.     end
  96. end
  97.  
  98. -- Handle runtime errors after startup
  99. do
  100.     local in_error = false
  101.     awesome.connect_signal("debug::error", function (err)
  102.         -- Make sure we don't go into an endless error loop
  103.         if in_error then return end
  104.         in_error = true
  105.  
  106.         naughty.notify({ preset = naughty.config.presets.critical,
  107.                          title = "Oops, an error happened!",
  108.                          text = err })
  109.         in_error = false
  110.    end)
  111. end
  112.  
  113. -- Autostart
  114. awful.util.spawn_with_shell('setxkbmap -layout "us,ru" setxkbmap -option "grp:caps_toggle,grp_led:scroll,compose:ralt"')
  115. run_once("kbdd")
  116. run_once("xsettingsd")
  117. run_once("mpd")
  118. run_once("nm-applet")
  119. run_once("clipit")
  120. run_once("transmission-gtk","-m")
  121. run_once("/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1")
  122.  
  123. -- Key bindings
  124. -- Global
  125. globalkeys = awful.util.table.join(
  126.     -- Manipulating layouts
  127.     awful.key({ modkey, }, "Left",   awful.tag.viewprev),
  128.     awful.key({ modkey, }, "Right",  awful.tag.viewnext),
  129.     awful.key({ modkey, }, "j",
  130.         function ()
  131.             awful.client.focus.byidx(1)
  132.             if client.focus then client.focus:raise() end
  133.         end),
  134.     awful.key({ modkey, }, "k",
  135.         function ()
  136.             awful.client.focus.byidx(-1)
  137.             if client.focus then client.focus:raise() end
  138.         end),
  139.     awful.key({ modkey_alt, }, "Tab",
  140.         function ()
  141.             awful.client.focus.byidx(1)
  142.             if client.focus then client.focus:raise() end
  143.         end),
  144.     awful.key({ modkey, "Shift"     }, "j", function () awful.client.swap.byidx(1) end),
  145.     awful.key({ modkey, "Shift"     }, "k", function () awful.client.swap.byidx(-1) end),
  146.     awful.key({ modkey_alt, "Shift" }, "Tab", function () awful.client.swap.byidx(1) end),
  147.     awful.key({ modkey,             }, "`", function () awful.client.urgent.jumpto() end),
  148.     awful.key({ modkey,             }, "Tab",
  149.         function ()
  150.             awful.client.focus.history.previous()
  151.             if client.focus then
  152.                 client.focus:raise()
  153.             end
  154.         end),
  155.  
  156.     -- Standard program
  157.     awful.key({ modkey, "Shift"   }, "r",      awesome.restart),
  158.     awful.key({ modkey,           }, "l",      function () awful.tag.incmwfact( 0.05) end),
  159.     awful.key({ modkey,           }, "h",      function () awful.tag.incmwfact(-0.05) end),
  160.     awful.key({ modkey, "Shift"   }, "h",      function () awful.tag.incnmaster( 1) end),
  161.     awful.key({ modkey, "Shift"   }, "l",      function () awful.tag.incnmaster(-1) end),
  162.     awful.key({ modkey,           }, "space",  function () awful.layout.inc( 1) end),
  163.     awful.key({ modkey, "Shift"   }, "space",  function () awful.layout.inc(-1) end),
  164.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  165.  
  166.     -- Launchers
  167.     awful.key({ modkey, }, "p",      function() menubar.show() end),
  168.     awful.key({ modkey,           }, "x",
  169.         function ()
  170.             awful.prompt.run({ prompt = "Run Lua code: " },
  171.             mypromptbox[mouse.screen].widget,
  172.             awful.util.eval, nil,
  173.             awful.util.getdir("cache") .. "/history_eval")
  174.     end),
  175.     awful.key({ modkey, }, "w",      function () run_or_raise("x-www-browser", { class = "Iceweasel" }) end),
  176.     awful.key({ modkey, }, "e",      function () run_or_raise("icedove", { class = "Icedove" }) end),
  177.     awful.key({ modkey, }, "o",      function () awful.util.spawn("dm-tool lock") end),
  178.     awful.key({ modkey, }, "Return", function () awful.util.spawn("x-terminal-emulator") end),
  179.     awful.key({ modkey, }, "F1", function () awful.util.spawn("x-terminal-emulator") end),
  180.     awful.key({ modkey, }, "f",      function () awful.util.spawn("thunar") end),
  181.     awful.key({ modkey, }, "q",      function () awful.util.spawn("tkscreen") end),
  182.     awful.key({ modkey, }, "a",      function () run_or_raise("x-terminal-emulator -T ncmpcpp -e ncmpcpp", { name = "ncmpcpp" }) end),
  183.     awful.key({ modkey, }, "F2",     function () run_or_raise("x-terminal-emulator -T htop -e sudo htop", { name = "htop" }) end),
  184.  
  185.     -- Multimedia
  186.     awful.key({}, "XF86Calculator",       function () awful.util.spawn ("qalculate") end),
  187.     awful.key({}, "XF86AudioPlay",        function () awful.util.spawn("mpc toggle") end),
  188.     awful.key({}, "XF86AudioNext",        function () awful.util.spawn("mpc next") end),
  189.     awful.key({}, "XF86AudioPrev",        function () awful.util.spawn("mpc prev") end),
  190.     awful.key({}, "XF86AudioStop",        function () awful.util.spawn("mpc stop") end),
  191.     awful.key({}, "XF86AudioRaiseVolume", function () awful.util.spawn("amixer set Master 4%+ on") end),
  192.     awful.key({}, "XF86AudioLowerVolume", function () awful.util.spawn("amixer set Master 4%- on") end),
  193.     awful.key({}, "XF86AudioMute",        function () awful.util.spawn("amixer set Master toggle") end)
  194. )
  195.  
  196. clientkeys = awful.util.table.join(
  197.     awful.key({ modkey_alt, }, "F1", function (c) c.fullscreen = not c.fullscreen end),
  198.     awful.key({ modkey_alt, }, "F2",
  199.         function (c)
  200.             c:raise()
  201.             c.maximized_horizontal = not c.maximized_horizontal
  202.             c.maximized_vertical   = not c.maximized_vertical
  203.     end),
  204.     awful.key({ modkey_alt, }, "F3", awful.client.floating.toggle),
  205.     awful.key({ modkey_alt, }, "F4", function (c) c:kill() end),
  206.     awful.key({ modkey_alt, }, "F5", function (c) c:swap(awful.client.getmaster()) end),
  207.     awful.key({ modkey_alt, }, "F6", function (c) c.ontop = not c.ontop end)
  208. )
  209.  
  210. -- Mouse bindings
  211. root.buttons(awful.util.table.join(
  212.     awful.button({ }, 3, function () mymainmenu:toggle() end),
  213.     awful.button({ }, 4, awful.tag.viewnext),
  214.     awful.button({ }, 5, awful.tag.viewprev)
  215. ))
  216. clientbuttons = awful.util.table.join(
  217.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  218.     awful.button({ modkey }, 1, awful.mouse.client.move),
  219.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  220.  
  221. -- Table of layouts
  222. awful.layout.layouts = {
  223.     awful.layout.suit.floating,
  224.     lain.layout.uselesstilecenter, -- будет использоваться для тегов, где обычно то, чему не нужен фуллскрин
  225.     awful.layout.suit.fair, -- будет использоваться для всех остальных тегов
  226.     awful.layout.suit.tile -- будет использоваться для тегов, где нужен фуллскрин и есть одно главное окно
  227. --    awful.layout.suit.tile.left
  228. --    awful.layout.suit.tile.bottom,
  229. --    awful.layout.suit.tile.top,
  230. --    awful.layout.suit.fair,
  231. --    awful.layout.suit.fair.horizontal,
  232. --    awful.layout.suit.spiral
  233. --    awful.layout.suit.spiral.dwindle,
  234. --    awful.layout.suit.max,
  235. --    awful.layout.suit.max.fullscreen,
  236. --    awful.layout.suit.magnifier
  237. }
  238.  
  239. -- Tags
  240. tags = {
  241.    names  = { "www", "music", "mail", 4, 5, 6, 7, 8, 9 },
  242.    layout = { awful.layout.layouts[4], awful.layout.layouts[4], awful.layout.layouts[4], awful.layout.layouts[2], awful.layout.layouts[2],
  243.               awful.layout.layouts[2], awful.layout.layouts[3], awful.layout.layouts[3], awful.layout.layouts[3]
  244. }}
  245. for s = 1, screen.count() do
  246.     tags[s] = awful.tag(tags.names, s, tags.layout)
  247. end
  248.  
  249. -- Rules
  250. awful.rules.rules = {
  251. { rule = { },
  252. properties = { border_width = beautiful.border_width,
  253.               border_color = beautiful.border_normal,
  254.               focus = awful.client.focus.filter,
  255.               keys = clientkeys,
  256.               size_hints_honor = false,
  257.               buttons = clientbuttons } },
  258. { rule = { instance = "pidgin" },
  259. properties = { floating = true }
  260. },
  261. { rule = { instance = "Pidgin" },
  262. properties = { floating = true }
  263. },
  264. { rule = { class = "qemu-system-x86_64" },
  265. properties = { floating = true }
  266. },
  267. { rule = { name = "File Operation Progress" },
  268. properties = { floating = true }
  269. },
  270. { rule = { instance = "qalculate" },
  271. properties = { floating = true }
  272. }
  273. }
  274.  
  275. -- Launcher widget and main menu
  276. myawesomemenu = {
  277.    { "edit config", editor .. " " .. awesome.conffile },
  278.    { "restart", awesome.restart },
  279. }
  280.  
  281. mysessionmenu = {
  282.    { "lock session", "dm-tool lock" },
  283.    { "quit session", awesome.quit },
  284.    { "switch user", "dm-tool switch-to-greeter" },
  285.    { "suspend", "systemctl suspend" },
  286.    { "reboot", "systemctl reboot" },
  287.    { "shutdown", "systemctl poweroff" }
  288.  
  289. }
  290.  
  291. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon }, { "session", mysessionmenu } }
  292.                         })
  293.  
  294. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  295.                                      menu = mymainmenu })
  296.  
  297. -- Wibox
  298.  
  299. -- Keyboard layout widget
  300. kbdwidget = wibox.widget.textbox(" Eng ")
  301. kbdwidget:set_font("Liberation Mono 9")
  302. kbdwidget.border_width = 1
  303. kbdwidget.border_color = beautiful.fg_normal
  304. kbdwidget:set_text(" Eng ")
  305.  
  306. kbdstrings = {[0] = " Eng ",
  307.               [1] = " Рус ", -- Хрен его знает, dbus-monitor за подробностями
  308.               [2] = " Eng ",
  309.               [3] = " Рус "}
  310.  
  311. dbus.request_name("session", "ru.gentoo.kbdd")
  312. dbus.add_match("session", "interface='ru.gentoo.kbdd',member='layoutChanged'")
  313. dbus.connect_signal("ru.gentoo.kbdd", function(...)
  314.     local data = {...}
  315.     local layout = data[2]
  316.     kbdwidget:set_text(kbdstrings[layout])
  317.     end
  318. )
  319.  
  320. -- Create a textclock widget
  321. mytextclock = awful.widget.textclock.new(" %A %d.%m.%y, %H:%M")
  322. -- Append calendar from Lain to clock widget
  323. lain.widgets.calendar:attach(mytextclock, {font_size = 9, font = "DejaVu Sans Mono"})
  324.  
  325. -- Create a wibox for each screen and add it
  326. mywibox = {}
  327. mypromptbox = {}
  328. mylayoutbox = {}
  329. mytaglist = {}
  330. mytaglist.buttons = awful.util.table.join(
  331.                     awful.button({ }, 1, awful.tag.viewonly), -- Go to tag
  332.                     awful.button({ modkey }, 1, awful.client.movetotag), -- Move focused window to tag
  333.                     awful.button({ }, 3, awful.tag.viewtoggle), -- Append tag's windows to current tag
  334.                     awful.button({ modkey }, 3, awful.client.toggletag), -- Display focused window on tag
  335.                     awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end), -- Scroll through tags
  336.                     awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end) -- Scroll through tags
  337.                     )
  338. mytasklist = {}
  339. mytasklist.buttons = awful.util.table.join(
  340.                      awful.button({ }, 1, function (c)
  341.                                               if c == client.focus then -- If in focus, then minimize
  342.                                                   c.minimized = true
  343.                                               else
  344.                                                   c.minimized = false -- Else, go to window's tag, unminize and give focus
  345.                                                   if not c:isvisible() then
  346.                                                       awful.tag.viewonly(c:tags()[1])
  347.                                                   end
  348.                                                   client.focus = c
  349.                                                   c:raise()
  350.                                               end
  351.                                           end),
  352.                      awful.button({ }, 3, function () -- Show list of windows
  353.                                               if instance then
  354.                                                   instance:hide()
  355.                                                   instance = nil
  356.                                               else
  357.                                                   instance = awful.menu.clients({
  358.                                                       theme = { width = 250 }
  359.                                                   })
  360.                                               end
  361.                                           end),
  362.                      awful.button({ }, 4, function () -- Scroll focus through windows
  363.                                               awful.client.focus.byidx(1)
  364.                                               if client.focus then client.focus:raise() end
  365.                                           end),
  366.                      awful.button({ }, 5, function () -- Scroll focus through windows
  367.                                               awful.client.focus.byidx(-1)
  368.                                               if client.focus then client.focus:raise() end
  369.                                           end))
  370.  
  371. for s = 1, screen.count() do
  372.     -- Create a promptbox for each screen
  373.     mypromptbox[s] = awful.widget.prompt()
  374.     -- Create an imagebox widget which will contain an icon indicating which layout we're using.
  375.     -- We need one layoutbox per screen.
  376.     mylayoutbox[s] = awful.widget.layoutbox(s)
  377.     mylayoutbox[s]:buttons(awful.util.table.join(
  378.                            awful.button({ }, 1, function () awful.layout.inc( 1) end), -- Scroll through layouts
  379.                            awful.button({ }, 3, function () awful.layout.inc(-1) end),
  380.                            awful.button({ }, 4, function () awful.layout.inc( 1) end),
  381.                            awful.button({ }, 5, function () awful.layout.inc(-1) end)))
  382.     -- Create a taglist widget
  383.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  384.  
  385.     -- Create a tasklist widget
  386.     mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  387.  
  388.     -- Create the wibox
  389.     mywibox[s] = awful.wibox({ position = "top", screen = s })
  390.  
  391.     -- Widgets that are aligned to the left
  392.     local left_layout = wibox.layout.fixed.horizontal()
  393.     left_layout:add(mylauncher)
  394.     left_layout:add(mytaglist[s])
  395.     left_layout:add(mypromptbox[s])
  396.  
  397.  
  398.     -- Widgets that are aligned to the right
  399.     local right_layout = wibox.layout.fixed.horizontal()
  400.     if s == 1 then right_layout:add(wibox.widget.systray()) end -- Tray should only be on one screen
  401.     right_layout:add(volume_widget)
  402.     right_layout:add(mytextclock)
  403.     right_layout:add(kbdwidget)
  404.     right_layout:add(mylayoutbox[s])
  405.     -- Now bring it all together (with the tasklist in the middle)
  406.     local layout = wibox.layout.align.horizontal()
  407.     layout:set_left(left_layout)
  408.     layout:set_middle(mytasklist[s])
  409.     layout:set_right(right_layout)
  410.  
  411.     mywibox[s]:set_widget(layout)
  412. end
  413.  
  414. -- Key bindings for tags manipulating
  415. for i = 1, 9 do
  416.     globalkeys = awful.util.table.join(globalkeys,
  417.     awful.key({ modkey }, "#" .. i + 9,
  418.         function ()
  419.             local screen = mouse.screen
  420.                 local tag = awful.tag.gettags(screen)[i]
  421.                     if tag then
  422.                         awful.tag.viewonly(tag)
  423.                     end
  424.     end),
  425.     awful.key({ modkey, "Control" }, "#" .. i + 9,
  426.         function ()
  427.             local screen = mouse.screen
  428.                 local tag = awful.tag.gettags(screen)[i]
  429.                     if tag then
  430.                         awful.tag.viewtoggle(tag)
  431.                     end
  432.     end),
  433.     awful.key({ modkey, "Shift" }, "#" .. i + 9,
  434.         function ()
  435.             if client.focus then
  436.                 local tag = awful.tag.gettags(client.focus.screen)[i]
  437.                     if tag then
  438.                         awful.client.movetotag(tag)
  439.                     end
  440.             end
  441.     end),
  442.     awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  443.         function ()
  444.             if client.focus then
  445.                 local tag = awful.tag.gettags(client.focus.screen)[i]
  446.                     if tag then
  447.                         awful.client.toggletag(tag)
  448.                     end
  449.             end
  450.     end))
  451. end
  452.  
  453. -- Set keys
  454. root.keys(globalkeys)
  455.  
  456. -- Signals
  457. -- Signal function to execute when a new client appears.
  458. client.connect_signal("manage", function (c)
  459.     if not awesome.startup then
  460.         -- Set the windows at the slave,
  461.         -- i.e. put it at the end of others instead of setting it master.
  462.         awful.client.setslave(c)
  463.  
  464.         -- Put windows in a smart way, only if they does not set an initial position.
  465.         if not c.size_hints.user_position and not c.size_hints.program_position then
  466.             awful.placement.no_overlap(c)
  467.             awful.placement.no_offscreen(c)
  468.         end
  469.     elseif not c.size_hints.user_position and not c.size_hints.program_position then
  470.         -- Prevent clients from being unreachable after screen count change
  471.         awful.placement.no_offscreen(c)
  472.     end
  473.  
  474.     local titlebars_enabled = false
  475.     if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  476.         -- buttons for the titlebar
  477.         local buttons = awful.util.table.join(
  478.                 awful.button({ }, 1, function()
  479.                     client.focus = c
  480.                     c:raise()
  481.                     awful.mouse.client.move(c)
  482.                 end),
  483.                 awful.button({ }, 3, function()
  484.                     client.focus = c
  485.                     c:raise()
  486.                     awful.mouse.client.resize(c)
  487.                 end)
  488.                 )
  489.  
  490.         -- Widgets that are aligned to the left
  491.         local left_layout = wibox.layout.fixed.horizontal()
  492.         left_layout:add(awful.titlebar.widget.iconwidget(c))
  493.         left_layout:buttons(buttons)
  494.  
  495.         -- Widgets that are aligned to the right
  496.         local right_layout = wibox.layout.fixed.horizontal()
  497.         right_layout:add(awful.titlebar.widget.floatingbutton(c))
  498.         right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  499.         right_layout:add(awful.titlebar.widget.stickybutton(c))
  500.         right_layout:add(awful.titlebar.widget.ontopbutton(c))
  501.         right_layout:add(awful.titlebar.widget.closebutton(c))
  502.  
  503.         -- The title goes in the middle
  504.         local middle_layout = wibox.layout.flex.horizontal()
  505.         local title = awful.titlebar.widget.titlewidget(c)
  506.         title:set_align("center")
  507.         middle_layout:add(title)
  508.         middle_layout:buttons(buttons)
  509.  
  510.         -- Now bring it all together
  511.         local layout = wibox.layout.align.horizontal()
  512.         layout:set_left(left_layout)
  513.         layout:set_right(right_layout)
  514.         layout:set_middle(middle_layout)
  515.  
  516.         awful.titlebar(c):set_widget(layout)
  517.     end
  518. end)
  519.  
  520. -- Enable sloppy focus
  521. client.connect_signal("mouse::enter", function(c)
  522.     if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  523.         and awful.client.focus.filter(c) then
  524.         client.focus = c
  525.     end
  526. end)
  527.  
  528. client.connect_signal("focus", function(c)
  529.   c.border_color = beautiful.border_focus
  530.   if not c:isvisible() then
  531.     awful.client.jumpto(c)
  532.   end
  533. end)
  534. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement