Advertisement
atm-irbis

My Awesome config

Apr 9th, 2013
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.66 KB | None | 0 0
  1. -- Для работы нужны:
  2. --
  3. --     скрипт calendar2  
  4. --     тема dust
  5. --     программа slock
  6. --     программа kbdd
  7. --     библиотека vicious
  8. --     библиотека blingbling (из оверлея stuff)
  9.  
  10. -- Стандартные библиотеки awesome
  11. require("awful")
  12. require("awful.autofocus")
  13. require("awful.rules")
  14. require("beautiful")
  15. require("naughty")
  16.  
  17. -- Сторонние библиотеки и вложения
  18. require("calendar2")
  19. require("vicious")
  20. require("blingbling")
  21.  
  22.  
  23. -- Ошибка запуска awesome
  24. if awesome.startup_errors then
  25.     naughty.notify({ preset = naughty.config.presets.critical,
  26.                      title = "Oops, there were errors during startup!",
  27.                      text = awesome.startup_errors })
  28. end
  29.  
  30. -- Захват ошибок после запуска
  31. do
  32.     local in_error = false
  33.     awesome.add_signal("debug::error", function (err)
  34.         if in_error then return end
  35.         in_error = true
  36.  
  37.         naughty.notify({ preset = naughty.config.presets.critical,
  38.                          title = "Oops, an error happened!",
  39.                          text = err })
  40.         in_error = false
  41.     end)
  42. end
  43.  
  44.  
  45. -- Тема, используемая в awesome
  46. beautiful.init("/usr/share/awesome/themes/dust/theme.lua")
  47.  
  48.  
  49. -- Редактор/терминал по умолчанию
  50. terminal = "konsole"
  51. editor_cmd = "kwrite"
  52.  
  53.  
  54. -- Клавиша-модификатор
  55. modkey = "Mod4"
  56.  
  57. -- Раскладки для окон
  58. layouts =
  59. {
  60.     awful.layout.suit.floating,
  61.     awful.layout.suit.tile,
  62.     awful.layout.suit.tile.left,
  63.     awful.layout.suit.tile.bottom,
  64.     awful.layout.suit.tile.top,
  65.     awful.layout.suit.fair,
  66.     awful.layout.suit.fair.horizontal,
  67.     awful.layout.suit.spiral,
  68.     awful.layout.suit.spiral.dwindle,
  69.     awful.layout.suit.max,
  70.     awful.layout.suit.max.fullscreen,
  71.     awful.layout.suit.magnifier
  72. }
  73. -- }}}
  74.  
  75. -- Привязки тэгов.
  76. --
  77. tags = {
  78.    names  = { "1:main", "2:devel", "3:editor", "4:files", "5:media", "6:office", "7:term", "8:www","9:misc"},
  79.    layout = { layouts[1], layouts[1], layouts[1], layouts[2], layouts[2],
  80.               layouts[1], layouts[2], layouts[1], layouts[2]
  81.  }}
  82.  for s = 1, screen.count() do
  83. -- Each screen has its own tag table.
  84.      tags[s] = awful.tag(tags.names, s, tags.layout)
  85.  end
  86.  -- }}}
  87.  
  88. -- Меню и его виджет
  89. myawesomemenu = {
  90.    { "manual", terminal .. " -e man awesome" },        
  91.    { "edit config", editor_cmd .. " " .. awesome.conffile },
  92.    { "restart", awesome.restart },
  93.    { "quit", awesome.quit }
  94. }
  95.  
  96. -- Меню отключения
  97. poweroffmenu = {
  98.    { "reboot", "sudo reboot" },
  99.    { "shutdown", "sudo poweroff" },    
  100. }
  101.  
  102. -- Основное меню  
  103. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  104.                                     { "Terminal", terminal },
  105.                     { "Exit", poweroffmenu }
  106.                                   }
  107.                         })
  108.  
  109. mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
  110.                                      menu = mymainmenu })
  111.  
  112. -- Виджет простых текстовых часов
  113. mytextclock = awful.widget.textclock({ align = "right" }, "<span color='cyan'>%a %d %b, %H:%M</span>")
  114. calendar2.addCalendarToWidget(mytextclock, "<span color='green'>%s</span>")
  115.  
  116. -- Системный трей
  117. mysystray = widget({ type = "systray" })
  118.  
  119. -- Wibox для каждого рабочего стола
  120. mywibox = {}
  121. mypromptbox = {}
  122. mylayoutbox = {}
  123. mytaglist = {}
  124. mytaglist.buttons = awful.util.table.join(
  125.                     awful.button({ }, 1, awful.tag.viewonly),
  126.                     awful.button({ modkey }, 1, awful.client.movetotag),
  127.                     awful.button({ }, 3, awful.tag.viewtoggle),
  128.                     awful.button({ modkey }, 3, awful.client.toggletag),
  129.                     awful.button({ }, 4, awful.tag.viewnext),
  130.                     awful.button({ }, 5, awful.tag.viewprev)
  131.                     )
  132. mytasklist = {}
  133. mytasklist.buttons = awful.util.table.join(
  134.                      awful.button({ }, 1, function (c)
  135.                                               if c == client.focus then
  136.                                                   c.minimized = true
  137.                                               else
  138.                                                   if not c:isvisible() then
  139.                                                       awful.tag.viewonly(c:tags()[1])
  140.                                                   end
  141.                                                   -- This will also un-minimize
  142.                                                   -- the client, if needed
  143.                                                   client.focus = c
  144.                                                   c:raise()
  145.                                               end
  146.                                           end),
  147.                      awful.button({ }, 3, function ()
  148.                                               if instance then
  149.                                                   instance:hide()
  150.                                                   instance = nil
  151.                                               else
  152.                                                   instance = awful.menu.clients({ width=250 })
  153.                                               end
  154.                                           end),
  155.                      awful.button({ }, 4, function ()
  156.                                               awful.client.focus.byidx(1)
  157.                                               if client.focus then client.focus:raise() end
  158.                                           end),
  159.                      awful.button({ }, 5, function ()
  160.                                               awful.client.focus.byidx(-1)
  161.                                               if client.focus then client.focus:raise() end
  162.                                           end))
  163.  
  164.  
  165.                      
  166.            
  167. for s = 1, screen.count() do
  168.     -- Create a promptbox for each screen
  169.     mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  170.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  171.     -- We need one layoutbox per screen.
  172.     mylayoutbox[s] = awful.widget.layoutbox(s)
  173.     mylayoutbox[s]:buttons(awful.util.table.join(
  174.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  175.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  176.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  177.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  178.     -- Создание списка тэгов
  179.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  180.  
  181.     -- Создание списка задач
  182.     mytasklist[s] = awful.widget.tasklist(function(c)
  183.                                               return awful.widget.tasklist.label.currenttags(c, s)
  184.                                           end, mytasklist.buttons)
  185.  
  186.     -- Создаем наш wibox
  187.     mywibox[s] = awful.wibox({ position = "top", screen = s })
  188.    
  189.     -- Настроенные виджеты
  190.     -- Индикатор раскладки клавиатуры
  191.     kbdwidget = widget({type = "textbox", name = "kbdwidget"})
  192.     kbdwidget.border_color = beautiful.fg_normal
  193.     kbdwidget.text = " Eng "
  194.  
  195.     dbus.request_name("session", "ru.gentoo.kbdd")
  196.     dbus.add_match("session", "interface='ru.gentoo.kbdd',member='layoutChanged'")
  197.     dbus.add_signal("ru.gentoo.kbdd", function(...)
  198.           local data = {...}
  199.           local layout = data[2]
  200.     lts = {[0] = "<span color='lightgreen'>Eng</span>", [1] = "Rus"}
  201.     kbdwidget.text = " "..lts[layout].." "
  202.     end
  203.    )
  204.    
  205.    -- Регулировка звука
  206.    volume_label = widget ({ type = "textbox" })
  207.    volume_label.text = "♫"
  208.    my_volume=blingbling.volume.new()
  209.    my_volume:set_height(18)
  210.    my_volume:set_v_margin(4)
  211.    my_volume:set_width(20)
  212.    my_volume:update_master()
  213.    my_volume:set_master_control()
  214.    my_volume:set_bar(true)
  215.    my_volume:set_background_graph_color("#444444")--beautiful.bg_focus)
  216.    my_volume:set_graph_color(beautiful.motive)--beautiful.fg_normal)
  217.  
  218.     -- Индикаторы сети
  219.    netwidget = widget({ type = "textbox" })
  220.    vicious.register(netwidget, vicious.widgets.net, "<span color='green'>up: ${usb0 up_kb}</span> <span color='red'>down: ${usb0 down_kb}</span>", 3)
  221.    
  222.     -- Загрузка процессора
  223.    cpuwidget = widget({ type = "textbox" })
  224.    vicious.register(cpuwidget, vicious.widgets.cpu, "cpu: $2%")
  225.    
  226.     -- Разделитель
  227.     sep = widget ({ type = "textbox" })
  228.     sep.text = " "
  229.    
  230.     -- Добавляем виджеты на wibox
  231.     mywibox[s].widgets = {
  232.         {
  233.             mylauncher,
  234.             mytaglist[s],
  235.             mypromptbox[s],
  236.             layout = awful.widget.layout.horizontal.leftright
  237.         },
  238.         mylayoutbox[s],sep,
  239.         netwidget,sep,
  240.         cpuwidget,sep,
  241.         my_volume.widget,sep,
  242.         volume_label,sep,
  243.         kbdwidget,sep,
  244.         mytextclock,sep,
  245.         s == 1 and mysystray or nil,
  246.         mytasklist[s],
  247.         layout = awful.widget.layout.horizontal.rightleft
  248.     }
  249. end
  250. -- }}}
  251.  
  252. -- {{{ Привязка клавиш мыши
  253. root.buttons(awful.util.table.join(
  254.     awful.button({ }, 3, function () mymainmenu:toggle() end),
  255.     awful.button({ }, 4, awful.tag.viewnext),
  256.     awful.button({ }, 5, awful.tag.viewprev)
  257. ))
  258. -- }}}
  259.  
  260. -- {{{ Клавиатурные сочетания
  261. globalkeys = awful.util.table.join(
  262.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  263.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  264.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  265.  
  266.     awful.key({ modkey,           }, "j",
  267.         function ()
  268.             awful.client.focus.byidx( 1)
  269.             if client.focus then client.focus:raise() end
  270.         end),
  271.     awful.key({ modkey,           }, "k",
  272.         function ()
  273.             awful.client.focus.byidx(-1)
  274.             if client.focus then client.focus:raise() end
  275.         end),
  276.     awful.key({ modkey,           }, "w", function () mymainmenu:show({keygrabber=true}) end),
  277.  
  278.     -- Манипуляции с раскладкой окон
  279.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  280.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  281.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  282.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  283.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  284.     awful.key({ modkey,           }, "Tab",
  285.         function ()
  286.             awful.client.focus.history.previous()
  287.             if client.focus then
  288.                 client.focus:raise()
  289.             end
  290.         end),
  291.  
  292.     -- Standard program
  293.     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
  294.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  295.     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  296.  
  297.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  298.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  299.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  300.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  301.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  302.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  303.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  304.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  305.  
  306.     awful.key({ modkey, "Control" }, "n", awful.client.restore),
  307.  
  308.     -- Строка запуска приложений
  309.     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
  310.  
  311.     awful.key({ modkey }, "x",
  312.               function ()
  313.                   awful.prompt.run({ prompt = "Run Lua code: " },
  314.                   mypromptbox[mouse.screen].widget,
  315.                   awful.util.eval, nil,
  316.                   awful.util.getdir("cache") .. "/history_eval")
  317.               end),
  318.                  
  319.     -- Скрыть панель по Mod + b            
  320.     awful.key({ modkey }, "b",
  321.        function ()
  322.            if mywibox[mouse.screen].screen == nil then
  323.                mywibox[mouse.screen].screen = mouse.screen
  324.            else
  325.                mywibox[mouse.screen].screen = nil
  326.            end
  327.        end),
  328.        
  329.      -- Блокировка экрана с помощью slock по Mod + y             
  330.     awful.key({ modkey }, "y",
  331.        function()
  332.            awful.util.spawn("slock")
  333.        end)
  334.  
  335. )
  336.  
  337. clientkeys = awful.util.table.join(
  338.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  339.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  340.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  341.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  342.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  343.     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
  344.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  345.     awful.key({ modkey,           }, "n",
  346.         function (c)
  347.             -- The client currently has the input focus, so it cannot be
  348.             -- minimized, since minimized clients can't have the focus.
  349.             c.minimized = true
  350.         end),
  351.     awful.key({ modkey,           }, "m",
  352.         function (c)
  353.             c.maximized_horizontal = not c.maximized_horizontal
  354.             c.maximized_vertical   = not c.maximized_vertical
  355.         end),
  356.    
  357.     -- Информация о клиенте Mod + Ctrl + i
  358.     awful.key({ modkey, "Control" }, "i",
  359.        function (c)
  360.            naughty.notify({ text =
  361.                "Class: " .. c.class ..
  362.                "\nInstance: " .. c.instance ..
  363.                "\nName: " .. c.name .. "\n",
  364.                width = 400 })
  365.        end)
  366. )
  367.  
  368. -- Compute the maximum number of digit we need, limited to 9
  369. keynumber = 0
  370. for s = 1, screen.count() do
  371.    keynumber = math.min(9, math.max(#tags[s], keynumber));
  372. end
  373.  
  374. -- Bind all key numbers to tags.
  375. -- Be careful: we use keycodes to make it works on any keyboard layout.
  376. -- This should map on the top row of your keyboard, usually 1 to 9.
  377. for i = 1, keynumber do
  378.     globalkeys = awful.util.table.join(globalkeys,
  379.         awful.key({ modkey }, "#" .. i + 9,
  380.                   function ()
  381.                         local screen = mouse.screen
  382.                         if tags[screen][i] then
  383.                             awful.tag.viewonly(tags[screen][i])
  384.                         end
  385.                   end),
  386.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  387.                   function ()
  388.                       local screen = mouse.screen
  389.                       if tags[screen][i] then
  390.                           awful.tag.viewtoggle(tags[screen][i])
  391.                       end
  392.                   end),
  393.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  394.                   function ()
  395.                       if client.focus and tags[client.focus.screen][i] then
  396.                           awful.client.movetotag(tags[client.focus.screen][i])
  397.                       end
  398.                   end),
  399.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  400.                   function ()
  401.                       if client.focus and tags[client.focus.screen][i] then
  402.                           awful.client.toggletag(tags[client.focus.screen][i])
  403.                       end
  404.                   end))
  405. end
  406.  
  407. clientbuttons = awful.util.table.join(
  408.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  409.     awful.button({ modkey }, 1, awful.mouse.client.move),
  410.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  411.  
  412. -- Set keys
  413. root.keys(globalkeys)
  414. -- }}}
  415.  
  416. -- Растановка приложений по тэгам
  417. awful.rules.rules = {
  418.     -- All clients will match this rule.
  419.     { rule = { },
  420.       properties = { border_width = beautiful.border_width,
  421.                      border_color = beautiful.border_normal,
  422.                      focus = true,
  423.                      keys = clientkeys,
  424.                      buttons = clientbuttons } },
  425.     { rule = { class = "SMPlayer" },
  426.       properties = { floating = true } },
  427.     { rule = { class = "Gimp" },
  428.       properties = { floating = true } },
  429.     { rule = { class = "Konsole" },
  430.       properties = { floating = false } },
  431.     { rule = { class = "Dolphin" },
  432.       properties = { floating = false } },
  433.     { rule = { class = "Chromium" },
  434.       properties = { floating = false } },  
  435.     { rule = { class = "jEdit" },
  436.       properties = { floating = false } },
  437.     { rule = { class = "Lxterminal" },
  438.       properties = { floating = false } },
  439.     { rule = { class = "jEdit" },
  440.        properties = { tag = tags[1][2] } },
  441.     { rule = { class = "Dolphin" },
  442.        properties = { tag = tags[1][4] } },
  443.     { rule = { class = "Konsole" },
  444.        properties = { tag = tags[1][7] } },
  445.     { rule = { class = "Chromium" },
  446.        properties = { tag = tags[1][8] } },
  447.     { rule = { class = "Smplayer" },
  448.        properties = { tag = tags[1][5] } },
  449.     { rule = { class = "LibreOffice" },
  450.        properties = { tag = tags[1][6] } },
  451.     { rule = { class = "VLC" },
  452.        properties = { tag = tags[1][5] } },
  453.     { rule = { class = "Kwrite" },
  454.        properties = { tag = tags[1][3] } },
  455.     { rule = { class = "Amarok" },
  456.        properties = { tag = tags[1][5] } },
  457.     { rule = { class = "lxmusic" },
  458.        properties = { tag = tags[1][5] } },
  459.     { rule = { class = "SMPlayer" },
  460.        properties = { tag = tags[1][5] } },
  461.     { rule = { class = "VirtualBox" },
  462.        properties = { tag = tags[1][2] } },
  463.     { rule = { class = "lxterminal" },
  464.        properties = { tag = tags[1][2] } },
  465.     { rule = { class = "Vim" },
  466.        properties = { tag = tags[1][2] } },
  467.     { rule = { class = "FileZilla" },
  468.        properties = { tag = tags[1][8] } },
  469.     { rule = { class = "Gwenview" },
  470.        properties = { tag = tags[1][5] } },
  471.     { rule = { class = "Ark" },
  472.        properties = { tag = tags[1][4] } },  
  473.        
  474.     -- Set Firefox to always map on tags number 2 of screen 1.
  475.     -- { rule = { class = "Firefox" },
  476.     --   properties = { tag = tags[1][2] } },
  477. }
  478. -- }}}
  479.  
  480. -- {{{ Signals
  481. -- Signal function to execute when a new client appears.
  482. client.add_signal("manage", function (c, startup)
  483.     -- Add a titlebar
  484.     -- awful.titlebar.add(c, { modkey = modkey })
  485.  
  486.     -- Enable sloppy focus
  487.     c:add_signal("mouse::enter", function(c)
  488.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  489.             and awful.client.focus.filter(c) then
  490.             client.focus = c
  491.         end
  492.     end)
  493.  
  494.     if not startup then
  495.         -- Set the windows at the slave,
  496.         -- i.e. put it at the end of others instead of setting it master.
  497.         -- awful.client.setslave(c)
  498.  
  499.         -- Put windows in a smart way, only if they does not set an initial position.
  500.         if not c.size_hints.user_position and not c.size_hints.program_position then
  501.             awful.placement.no_overlap(c)
  502.             awful.placement.no_offscreen(c)
  503.         end
  504.     end
  505. end)
  506.  
  507. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  508. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  509. -- }}}
  510.  
  511.  
  512. -- Секция автозапуска
  513.  
  514. function run_once(prg)
  515.     if not prg then
  516.         do return nil end
  517.     end
  518.     awful.util.spawn_with_shell("x=" .. prg .. "; pgrep -u $USERNAME -x " .. prg .. " || (" .. prg .. ")")
  519. end
  520.  
  521. run_once("kbdd") -- Клавиатурный демон
  522. run_once(terminal) -- Терминал
  523.  
  524. naughty.notify({
  525.     text = "Awesome запущен !!!",
  526.     title = "Уведомление: ",
  527.     fg="#ffggcc",
  528.     bg="#bbggcc",
  529.     screen = 1,
  530.     ontop = false
  531. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement