Guest User

Untitled

a guest
Dec 18th, 2013
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.42 KB | None | 0 0
  1. local gears = require("gears")
  2. local awful = require("awful")
  3. awful.rules = require("awful.rules")
  4. require("awful.autofocus")
  5. local wibox = require("wibox")
  6. local beautiful = require("beautiful")
  7. local naughty = require("naughty")
  8. local vicious = require("vicious")
  9.  
  10. -- Цвета виджетов
  11. main_color = "#afdd00"
  12. sub_color =  "#E6AD04"
  13.  
  14. -- Кое-какие бинды
  15. terminal = "urxvtc"
  16. editor = "vim"
  17. editor_cmd = terminal .. " -x " .. editor
  18. awesome_dir = "/home/ilya/.config/awesome/"
  19. modkey = "Mod1"
  20.  
  21. -- Включаем тему
  22. beautiful.init(awesome_dir .. "/themes/inspgreen/theme.lua")
  23.  
  24. -- Отключил для dmenu
  25. --local menubar = require("menubar")
  26. --menubar.utils.terminal = terminal
  27.  
  28. dmenu_run = "dmenu_run -b -nb '"..beautiful.bg_normal.."' -sb '"..beautiful.bg_normal.."' -sf '"..beautiful.fg_focus.."'"
  29.  
  30. -- Стол
  31.  
  32. if awesome.startup_errors then
  33.     naughty.notify({ preset = naughty.config.presets.critical,
  34.                      title = "Oops, there were errors during startup!",
  35.                      text = awesome.startup_errors })
  36. end
  37.  
  38. do
  39.     local in_error = false
  40.     awesome.connect_signal("debug::error", function (err)
  41.         if in_error then return end
  42.         in_error = true
  43.  
  44.         naughty.notify({ preset = naughty.config.presets.critical,
  45.                          title = "Oops, an error happened!",
  46.                          text = err })
  47.         in_error = false
  48.     end)
  49. end
  50.  
  51. local layouts =
  52. {
  53.     awful.layout.suit.floating,
  54.     awful.layout.suit.tile,
  55.     awful.layout.suit.tile.left,
  56.     awful.layout.suit.tile.top,
  57.     awful.layout.suit.max,
  58.     awful.layout.suit.max.fullscreen,
  59. }
  60.  
  61. if beautiful.wallpaper then
  62.     for s = 1, screen.count() do
  63.         gears.wallpaper.maximized(beautiful.wallpaper, s, true)
  64.     end
  65. end
  66.  
  67. tags = {
  68.   names  = { "α", "β", "γ", "δ", "ε" },
  69. layout = { layouts[5], layouts[5], layouts[5], layouts[5], layouts[5], } }
  70. for s = 1, screen.count() do
  71.     tags[s] = awful.tag(tags.names, s, tags.layout)    
  72. end
  73.  
  74.  
  75. -- Мои виджеты
  76. --- Пробел
  77. space = wibox.widget.textbox()
  78. space:set_text(" ")
  79.  
  80. -- Спойлер
  81. spoiler = wibox.widget.textbox()
  82. spoiler:set_markup('<span color="'.. sub_color ..'"> | </span>')
  83.  
  84. -- Дата
  85. datewidget = wibox.widget.textbox()
  86. vicious.register(datewidget, vicious.widgets.date, '<span color="'.. main_color .. '">%R </span>', 60)
  87.  
  88. -- Батарея
  89. batwidget = wibox.widget.textbox()
  90. vicious.register(batwidget, vicious.widgets.bat, '<span color="'..main_color..'">'..'$2%</span> <span color="'..sub_color..'">'..'$1</span>', 120, "BAT0")
  91.  
  92. -- mpd
  93. mpdwidget = wibox.widget.textbox()
  94. vicious.register(mpdwidget, vicious.widgets.mpd,
  95.     function (widget, args)
  96.         if args["{state}"] == "Stop" then
  97.             return " - "
  98.         else
  99.             return '<span color="'.. sub_color ..'"> ♫</span> <span color="'.. main_color .. '">' .. args['{Artist}'] .. ' - ' .. args['{Title}'] .. '</span> <span color="'.. sub_color ..'">♫</span>'
  100.         end
  101.     end, 25)
  102.    
  103. -- Календарь
  104.  
  105.     local calendar = nil
  106.     local offset = 0
  107.  
  108.     function remove_calendar()
  109.         if calendar ~= nil then
  110.             naughty.destroy(calendar)
  111.             calendar = nil
  112.             offset = 0
  113.         end
  114.     end
  115.    
  116.     function add_calendar(inc_offset)
  117.         local save_offset = offset
  118.         remove_calendar()
  119.         offset = save_offset + inc_offset
  120.         local datespec = os.date("*t")
  121.         datespec = datespec.year * 12 + datespec.month - 1 + offset
  122.         datespec = (datespec % 12 + 1) .. " " .. math.floor(datespec / 12)
  123.         local cal = awful.util.pread("cal -m " .. datespec)
  124.         cal = string.gsub(cal, "^%s*(.-)%s*$", "%1")
  125.         calendar = naughty.notify({
  126.             text = string.format('<span font_desc="%s">%s</span>', "Terminus 8", os.date("%a, %d %B %Y") .. "\n" .. cal),
  127.             timeout = 0, hover_timeout = 0.5,
  128.             width = 160,
  129.         })
  130.     end
  131.  
  132. -- Добавляем сигнал
  133. datewidget:connect_signal("mouse::enter", function()
  134.       add_calendar(0)
  135.     end)
  136. datewidget:connect_signal("mouse::leave", remove_calendar)
  137.  
  138. -- coverart
  139. local coverart_nf
  140. function coverart_show()
  141.     coverart_hide()
  142.     local img = awful.util.pread(awesome_dir .. "/scripts/coverart/coverart.sh")
  143.     local txt = awful.util.pread(awesome_dir .. "/scripts/coverart/musicinfo.sh")
  144.     coverart_nf = naughty.notify({icon = img, icon_size = 100, text = txt, position = "top_right"})
  145. end
  146.  
  147. function coverart_hide()
  148.     if coverart_nf ~= nil then
  149.         naughty.destroy(coverart_nf)
  150.     end
  151. end
  152.  
  153. -- coverart и лирика
  154. mpdwidget:connect_signal("mouse::enter", function()
  155.     coverart_show()
  156. end)
  157.  
  158. mpdwidget:connect_signal("mouse::leave", function()
  159.     coverart_hide()
  160. end)
  161. mywibox = {}
  162. mypromptbox = {}
  163. mytaglist = {}
  164. mytaglist.buttons = awful.util.table.join(
  165.                     awful.button({ }, 1, awful.tag.viewonly),
  166.                     awful.button({ modkey }, 1, awful.client.movetotag),
  167.                     awful.button({ }, 3, awful.tag.viewtoggle),
  168.                     awful.button({ modkey }, 3, awful.client.toggletag),
  169.                     awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
  170.                     awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
  171.                     )
  172. mytasklist = {}
  173. mytasklist.buttons = awful.util.table.join(
  174.                      awful.button({ }, 1, function (c)
  175.                                               if c == client.focus then
  176.                                                   c.minimized = true
  177.                                               else
  178.                                                   -- Without this, the following
  179.                                                   -- :isvisible() makes no sense
  180.                                                   c.minimized = false
  181.                                                   if not c:isvisible() then
  182.                                                       awful.tag.viewonly(c:tags()[1])
  183.                                                   end
  184.                                                   -- This will also un-minimize
  185.                                                   -- the client, if needed
  186.                                                   client.focus = c
  187.                                                   c:raise()
  188.                                               end
  189.                                           end),
  190.                      awful.button({ }, 3, function ()
  191.                                               if instance then
  192.                                                   instance:hide()
  193.                                                   instance = nil
  194.                                               else
  195.                                                   instance = awful.menu.clients({ width=250 })
  196.                                               end
  197.                                           end),
  198.                      awful.button({ }, 4, function ()
  199.                                               awful.client.focus.byidx(1)
  200.                                               if client.focus then client.focus:raise() end
  201.                                           end),
  202.                      awful.button({ }, 5, function ()
  203.                                               awful.client.focus.byidx(-1)
  204.                                               if client.focus then client.focus:raise() end
  205.                                           end))
  206.  
  207. for s = 1, screen.count() do
  208.     -- Create a promptbox for each screen
  209.     mypromptbox[s] = awful.widget.prompt()
  210.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  211.  
  212.     -- Create a tasklist widget
  213.     mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  214.  
  215.     -- Create the wibox
  216.     mywibox[s] = awful.wibox({ position = "top", screen = s })
  217.  
  218.     -- Widgets that are aligned to the left
  219.     local left_layout = wibox.layout.fixed.horizontal()
  220.     left_layout:add(mytaglist[s])
  221.     left_layout:add(mypromptbox[s])
  222.    
  223.     -- !!!
  224.     left_layout:add(spoiler)
  225.     left_layout:add(batwidget)
  226.     left_layout:add(spoiler)
  227.  
  228.     -- Widgets that are aligned to the right
  229.     local right_layout = wibox.layout.fixed.horizontal()
  230.     right_layout:add(mpdwidget)
  231.     right_layout:add(spoiler)
  232.     if s == 1 then right_layout:add(wibox.widget.systray()) end
  233.     right_layout:add(spoiler)
  234.     right_layout:add(datewidget)
  235.  
  236.     -- Now bring it all together (with the tasklist in the middle)
  237.     local layout = wibox.layout.align.horizontal()
  238.     layout:set_left(left_layout)
  239.     layout:set_middle(mytasklist[s])
  240.     layout:set_right(right_layout)
  241.     mywibox[s]:set_widget(layout)
  242. end
  243. -- }}}
  244.  
  245. -- {{{ Mouse bindings
  246. root.buttons(awful.util.table.join(
  247. --    awful.button({ }, 3, function () mymainmenu:toggle() end),
  248.     awful.button({ }, 4, awful.tag.viewnext),
  249.     awful.button({ }, 5, awful.tag.viewprev)
  250. ))
  251. -- }}}
  252.  
  253. -- {{{ Key bindings
  254. globalkeys = awful.util.table.join(
  255.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  256.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  257.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  258.  
  259.     awful.key({ modkey,           }, "j",
  260.         function ()
  261.             awful.client.focus.byidx( 1)
  262.             if client.focus then client.focus:raise() end
  263.         end),
  264.     awful.key({ modkey,           }, "k",
  265.         function ()
  266.             awful.client.focus.byidx(-1)
  267.             if client.focus then client.focus:raise() end
  268.         end),
  269.     awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx(  1)    end),
  270.     awful.key({ modkey, "Shift"}, "k", function () awful.client.swap.byidx( -1)    end),
  271.     awful.key({ modkey}, "j", function () awful.screen.focus_relative( 1) end),
  272.     awful.key({ modkey}, "k", function () awful.screen.focus_relative(-1) end),
  273.     awful.key({ modkey}, "u", awful.client.urgent.jumpto),
  274.     awful.key({ modkey}, "Tab",
  275.         function ()
  276.             awful.client.focus.history.previous()
  277.             if client.focus then
  278.                 client.focus:raise()
  279.             end
  280.         end),
  281.  
  282.     awful.key({ modkey, "Control" }, "Return", function () awful.util.spawn(terminal) end),
  283.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  284.  
  285. -- Перезагрузка и выключение
  286.     awful.key({ "Shift", "Control" }, "h", function () awful.util.spawn("user-halt") end),
  287.     awful.key({ "Shift", "Control" }, "r", function () awful.util.spawn("user-reboot") end),
  288.        
  289. -- Хоткеи на приложения
  290.     awful.key({ modkey, "Control" }, "o", function () awful.util.spawn("firefox-bin") end),
  291.     awful.key({ modkey, "Control" }, "j", function () awful.util.spawn("gajim") end),
  292.     awful.key({ modkey, "Control" }, "t", function () awful.util.spawn("transmission-gtk") end),
  293.     awful.key({ modkey, "Control" }, "k", function () awful.util.spawn("thunar") end),
  294.     awful.key({ modkey, "Control" }, "p", function () awful.util.spawn("slimlock") end),
  295.     awful.key({ modkey, "Control" }, "s", function () awful.util.spawn("skype") end),
  296.     awful.key({ modkey, "Control" }, "m", function () awful.util.spawn("urxvtc -e ncmpcpp") end),
  297.     awful.key({ modkey, "Control" }, "b", function () awful.util.spawn("fbreader") end),
  298.     awful.key({ modkey, "Control" }, "v", function () awful.util.spawn("smplayer") end),
  299.     awful.key({ modkey, "Control" }, "e", function () awful.util.spawn("geany") end),
  300.     awful.key({ modkey, "Control" }, "l", function () awful.util.spawn("libreoffice") end),
  301.     awful.key({ modkey, "Control" }, "g", function () awful.util.spawn("gimp") end),
  302.  
  303. -- Спец. Кнопки
  304.     awful.key({ }, "XF86AudioMute", function () awful.util.spawn("amixer -c 2 set Speaker toggle") end),
  305.     awful.key({ }, "XF86AudioRaiseVolume", function () awful.util.spawn("amixer -c 2 set Speaker 2+ unmute") end),
  306.     awful.key({ }, "XF86AudioLowerVolume", function () awful.util.spawn("amixer -c 2 set Speaker 2-") end),
  307.  
  308. -- Управление mpd
  309.     awful.key({ modkey, }, "b", function () awful.util.spawn("mpc prev") end),
  310.     awful.key({ modkey, }, "p", function () awful.util.spawn("mpc toggle") end),
  311.     awful.key({ modkey, }, "n", function () awful.util.spawn("mpc next") end),
  312.    
  313.        
  314.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  315.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  316.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  317.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  318.     awful.key({ modkey, }, "l",     function () awful.tag.incncol(-1)         end),
  319.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  320.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  321.  
  322. -- Больно тормозной, переключу на dmenu
  323. --  awful.key({ modkey }, "r", function() menubar.show() end)
  324.     awful.key({ modkey }, "r", function() awful.util.spawn(dmenu_run) end)
  325.  
  326. )
  327.  
  328. clientkeys = awful.util.table.join(
  329.     awful.key({ "Control"     }, "f",      function (c) c.max = not c.fullscreen  end),
  330.     awful.key({ modkey, "Control"   }, "q",      function (c) c:kill()                         end),
  331.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  332.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  333.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  334.     awful.key({ modkey,           }, "m",
  335.         function (c)
  336.             c.maximized_horizontal = not c.maximized_horizontal
  337.             c.maximized_vertical   = not c.maximized_vertical
  338.         end)
  339. )
  340.  
  341. -- Compute the maximum number of digit we need, limited to 9
  342. keynumber = 0
  343. for s = 1, screen.count() do
  344.    keynumber = math.min(9, math.max(#tags[s], keynumber))
  345. end
  346.  
  347. -- Bind all key numbers to tags.
  348. -- Be careful: we use keycodes to make it works on any keyboard layout.
  349. -- This should map on the top row of your keyboard, usually 1 to 9.
  350. for i = 1, keynumber do
  351.     globalkeys = awful.util.table.join(globalkeys,
  352.         awful.key({ modkey }, "#" .. i + 9,
  353.                   function ()
  354.                         local screen = mouse.screen
  355.                         if tags[screen][i] then
  356.                             awful.tag.viewonly(tags[screen][i])
  357.                         end
  358.                   end),
  359.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  360.                   function ()
  361.                       local screen = mouse.screen
  362.                       if tags[screen][i] then
  363.                           awful.tag.viewtoggle(tags[screen][i])
  364.                       end
  365.                   end),
  366.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  367.                   function ()
  368.                       if client.focus and tags[client.focus.screen][i] then
  369.                           awful.client.movetotag(tags[client.focus.screen][i])
  370.                       end
  371.                   end),
  372.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  373.                   function ()
  374.                       if client.focus and tags[client.focus.screen][i] then
  375.                           awful.client.toggletag(tags[client.focus.screen][i])
  376.                       end
  377.                   end))
  378. end
  379.  
  380. clientbuttons = awful.util.table.join(
  381.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  382.     awful.button({ modkey }, 1, awful.mouse.client.move),
  383.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  384.  
  385. -- Set keys
  386. root.keys(globalkeys)
  387. -- }}}
  388.  
  389. -- {{{ Rules
  390. awful.rules.rules = {
  391.     -- All clients will match this rule.
  392.     { rule = { },
  393.       properties = { border_width = beautiful.border_width,
  394.                      border_color = beautiful.border_normal,
  395.                      focus = awful.client.focus.filter,
  396.                      -- Без отступов
  397.                      size_hints_honor = false,
  398.                      keys = clientkeys,
  399.                      buttons = clientbuttons } },
  400.  { rule = { class = "Firefox" },
  401.        properties = { tag = tags[1][1] } },
  402.    
  403.     { rule = { class = "Skype" },
  404.        properties = { tag = tags[1][3] } },
  405.      
  406.  { rule = { class = "Xfdesktop" }, callback = function(c) c:tags({
  407.  tags[1][1], tags[1][2],tags[1][3],tags[1][4],tags[1][5]}) end},
  408.        
  409. }
  410. -- {{{ Signals
  411. -- Signal function to execute when a new client appears.
  412. client.connect_signal("manage", function (c, startup)
  413.     -- Enable sloppy focus
  414.     c:connect_signal("mouse::enter", function(c)
  415.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  416.             and awful.client.focus.filter(c) then
  417.             client.focus = c
  418.         end
  419.     end)
  420.  
  421.     if not startup then
  422.         -- Set the windows at the slave,
  423.         -- i.e. put it at the end of others instead of setting it master.
  424.         -- awful.client.setslave(c)
  425.  
  426.         -- Put windows in a smart way, only if they does not set an initial position.
  427.         if not c.size_hints.user_position and not c.size_hints.program_position then
  428.             awful.placement.no_overlap(c)
  429.             awful.placement.no_offscreen(c)
  430.         end
  431.     end
  432.  
  433.     local titlebars_enabled = false
  434.     if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  435.         local left_layout = wibox.layout.fixed.horizontal()
  436.         left_layout:add(awful.titlebar.widget.iconwidget(c))
  437.  
  438.         local right_layout = wibox.layout.fixed.horizontal()
  439.         right_layout:add(awful.titlebar.widget.floatingbutton(c))
  440.         right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  441.         right_layout:add(awful.titlebar.widget.stickybutton(c))
  442.         right_layout:add(awful.titlebar.widget.ontopbutton(c))
  443.         right_layout:add(awful.titlebar.widget.closebutton(c))
  444.  
  445.         local title = awful.titlebar.widget.titlewidget(c)
  446.         title:buttons(awful.util.table.join(
  447.                 awful.button({ }, 1, function()
  448.                     client.focus = c
  449.                     c:raise()
  450.                     awful.mouse.client.move(c)
  451.                 end),
  452.                 awful.button({ }, 3, function()
  453.                     client.focus = c
  454.                     c:raise()
  455.                     awful.mouse.client.resize(c)
  456.                 end)
  457.                 ))
  458.  
  459.         local layout = wibox.layout.align.horizontal()
  460.         layout:set_left(left_layout)
  461.         layout:set_right(right_layout)
  462.         layout:set_middle(title)
  463.  
  464.         awful.titlebar(c):set_widget(layout)
  465.     end
  466. end)
  467.  
  468. -- Без рамок для полноэкранных окон
  469. client.connect_signal("focus",
  470.         function(c)
  471.                 if c.maximized_horizontal == true and c.maximized_vertical == true then
  472.                         c.border_width = "0"
  473.                         c.border_color = beautiful.border_focus
  474.                 else
  475.                         c.border_width = beautiful.border_width
  476.                         c.border_color = beautiful.border_focus
  477.                 end
  478.         end)
  479.  
  480.  
  481. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  482.  
  483. -- Скрипт для автостарта приложений
  484. awful.util.spawn_with_shell(awesome_dir .. "/scripts/autostart.sh")
Advertisement
Add Comment
Please, Sign In to add comment