misaka

[Awesome WM] rc.lua

Mar 30th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.06 KB | None | 0 0
  1. -- Standard awesome library
  2. local gears = require("gears")
  3. local awful = require("awful")
  4. awful.rules = require("awful.rules")
  5. require("awful.autofocus")
  6. -- Widget and layout library
  7. local wibox = require("wibox")
  8. -- Theme handling library
  9. local beautiful = require("beautiful")
  10. -- Notification library
  11. local naughty = require("naughty")
  12. local menubar = require("menubar")
  13.  
  14. -- {{{ Error handling
  15. -- Check if awesome encountered an error during startup and fell back to
  16. -- another config (This code will only ever execute for the fallback config)
  17. if awesome.startup_errors then
  18.     naughty.notify({ preset = naughty.config.presets.critical,
  19.                      title = "Oops, there were errors during startup!",
  20.                      text = awesome.startup_errors })
  21. end
  22.  
  23. -- Handle runtime errors after startup
  24. do
  25.     local in_error = false
  26.     awesome.connect_signal("debug::error", function (err)
  27.         -- Make sure we don't go into an endless error loop
  28.         if in_error then return end
  29.         in_error = true
  30.  
  31.         naughty.notify({ preset = naughty.config.presets.critical,
  32.                          title = "Oops, an error happened!",
  33.                          text = err })
  34.         in_error = false
  35.     end)
  36. end
  37. -- }}}
  38.  
  39. -- {{{ Variable definitions
  40. -- Themes define colours, icons, and wallpapers
  41. beautiful.init("/usr/share/awesome/themes/default/theme.lua")
  42.  
  43. -- This is used later as the default terminal and editor to run.
  44. terminal = "xterm"
  45. editor = os.getenv("EDITOR") or "vim"
  46. editor_cmd = terminal .. " -e " .. editor
  47.  
  48. -- Default modkey.
  49. -- Usually, Mod4 is the key with a logo between Control and Alt.
  50. -- If you do not like this or do not have such a key,
  51. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  52. -- However, you can use another modifier like Mod1, but it may interact with others.
  53. modkey = "Mod4"
  54.  
  55. -- Table of layouts to cover with awful.layout.inc, order matters.
  56. local layouts =
  57. {
  58.     awful.layout.suit.floating,
  59.     awful.layout.suit.tile,
  60.     awful.layout.suit.tile.left,
  61.     awful.layout.suit.tile.bottom,
  62.     awful.layout.suit.tile.top,
  63.     awful.layout.suit.fair,
  64.     awful.layout.suit.fair.horizontal,
  65.     awful.layout.suit.spiral,
  66.     awful.layout.suit.spiral.dwindle,
  67.     awful.layout.suit.max,
  68.     awful.layout.suit.max.fullscreen,
  69.     awful.layout.suit.magnifier
  70. }
  71. -- }}}
  72.  
  73. -- {{{ Wallpaper
  74.  
  75. if beautiful.wallpaper then
  76.     for s = 1, screen.count() do
  77.         -- gears.wallpaper.maximized(beautiful.wallpaper, s, true)
  78.         awful.util.spawn("feh --bg-scale /home/mikoto/.config/awesome/01.png")
  79.     end
  80. end
  81. -- }}}
  82.  
  83. -- {{{ Tags
  84. -- Define a tag table which hold all screen tags.
  85. tags = {}
  86. for s = 1, screen.count() do
  87.     -- Each screen has its own tag table.
  88.     tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
  89. end
  90. -- }}}
  91.  
  92. -- {{{ Menu
  93. -- Create a laucher widget and a main menu
  94. myawesomemenu = {
  95.    { "manual", terminal .. " -e man awesome" },
  96.    { "edit config", editor_cmd .. " " .. awesome.conffile },
  97.    { "restart", awesome.restart },
  98.    { "quit", awesome.quit }
  99. }
  100.  
  101. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  102.                                     { "open terminal", terminal }
  103.                                   }
  104.                         })
  105.  
  106. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  107.                                      menu = mymainmenu })
  108.  
  109. -- Menubar configuration
  110. menubar.utils.terminal = terminal -- Set the terminal for applications that require it
  111. -- }}}
  112.  
  113. -- Create a textclock widget
  114. mytextclock = awful.widget.textclock()
  115. -- Keyboard map indicator and changer
  116. kbdcfg = {}
  117. kbdcfg.cmd = "setxkbmap"
  118. kbdcfg.layout = { "us", "ru" }
  119. kbdcfg.current =  1 -- default layout
  120. kbdcfg.widget = wibox.widget.textbox()
  121. kbdcfg.widget:set_text(" " .. kbdcfg.layout[kbdcfg.current] .. " ")
  122. kbdcfg.switch = function()
  123.     kbdcfg.current = kbdcfg.current % #(kbdcfg.layout) + 1
  124.     local layout = kbdcfg.layout[kbdcfg.current]
  125.     kbdcfg.widget:set_text(" " .. layout .. " ")
  126.     os.execute(kbdcfg.cmd .. " " .. layout .. ",us" )
  127. end
  128.  
  129. kbdcfg.widget:buttons(
  130.     awful.util.table.join(awful.button({ }, 1, function () kbdcfg.switch() end)))
  131. -- Separator
  132. separator = wibox.widget.textbox()
  133. separator:set_text(" ")
  134. -- Volume Widget
  135. volume = {}
  136. volume.cmd = "amixer -q sset Master "
  137. volume.current = io.popen("alsaget volume"):read()
  138. volume.muted = false
  139. volume.widget = awful.widget.progressbar()
  140. volume.widget:set_width(19)
  141. volume.widget:set_background_color("#222222")
  142. volume.widget:set_color("#858585")
  143. volume.widget:set_vertical(true)
  144. volume.widget:set_value(volume.current/100)
  145. volume.change = function (op)
  146.     if(op == "-") then
  147.         if(volume.muted) then
  148.             volume.change("m")
  149.         end
  150.         os.execute(volume.cmd .. "5%-")
  151.         volume.current = io.popen("alsaget volume"):read()
  152.         volume.widget:set_value(volume.current/100)
  153.     elseif(op == "+") then
  154.         if(volume.muted) then
  155.             volume.change("m")
  156.         end
  157.         os.execute(volume.cmd .. "5%+")
  158.         volume.current = io.popen("alsaget volume"):read()
  159.         volume.widget:set_value(volume.current/100)
  160.     elseif(op == "m") then
  161.         if(volume.muted) then
  162.             os.execute(volume.cmd .. "unmute")
  163.             volume.widget:set_background_color("#222222")
  164.             volume.muted = false
  165.         else
  166.             os.execute(volume.cmd .. "mute")
  167.             volume.widget:set_background_color("#FF3D77")
  168.             volume.muted = true
  169.         end
  170.     end
  171. end
  172.  
  173.  
  174. -- Create a wibox for each screen and add it
  175. mywibox = {}
  176. mypromptbox = {}
  177. mylayoutbox = {}
  178. mytaglist = {}
  179. mytaglist.buttons = awful.util.table.join(
  180.                     awful.button({ }, 1, awful.tag.viewonly),
  181.                     awful.button({ modkey }, 1, awful.client.movetotag),
  182.                     awful.button({ }, 3, awful.tag.viewtoggle),
  183.                     awful.button({ modkey }, 3, awful.client.toggletag),
  184.                     awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
  185.                     awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
  186.                     )
  187. mytasklist = {}
  188. mytasklist.buttons = awful.util.table.join(
  189.                      awful.button({ }, 1, function (c)
  190.                                               if c == client.focus then
  191.                                                   c.minimized = true
  192.                                               else
  193.                                                   -- Without this, the following
  194.                                                   -- :isvisible() makes no sense
  195.                                                   c.minimized = false
  196.                                                   if not c:isvisible() then
  197.                                                       awful.tag.viewonly(c:tags()[1])
  198.                                                   end
  199.                                                   -- This will also un-minimize
  200.                                                   -- the client, if needed
  201.                                                   client.focus = c
  202.                                                   c:raise()
  203.                                               end
  204.                                           end),
  205.                      awful.button({ }, 3, function ()
  206.                                               if instance then
  207.                                                   instance:hide()
  208.                                                   instance = nil
  209.                                               else
  210.                                                   instance = awful.menu.clients({ width=250 })
  211.                                               end
  212.                                           end),
  213.                      awful.button({ }, 4, function ()
  214.                                               awful.client.focus.byidx(1)
  215.                                               if client.focus then client.focus:raise() end
  216.                                           end),
  217.                      awful.button({ }, 5, function ()
  218.                                               awful.client.focus.byidx(-1)
  219.                                               if client.focus then client.focus:raise() end
  220.                                           end))
  221.  
  222. for s = 1, screen.count() do
  223.     -- Create a promptbox for each screen
  224.     mypromptbox[s] = awful.widget.prompt()
  225.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  226.     -- We need one layoutbox per screen.
  227.     mylayoutbox[s] = awful.widget.layoutbox(s)
  228.     mylayoutbox[s]:buttons(awful.util.table.join(
  229.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  230.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  231.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  232.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  233.     -- Create a taglist widget
  234.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  235.  
  236.     -- Create a tasklist widget
  237.     mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  238.  
  239.     -- Create the wibox
  240.     mywibox[s] = awful.wibox({ position = "top", screen = s })
  241.  
  242.     -- Widgets that are aligned to the left
  243.     local left_layout = wibox.layout.fixed.horizontal()
  244.     left_layout:add(mylauncher)
  245.     left_layout:add(mytaglist[s])
  246.     left_layout:add(mypromptbox[s])
  247.  
  248.     -- Widgets that are aligned to the right
  249.     local right_layout = wibox.layout.fixed.horizontal()
  250.     if s == 1 then right_layout:add(wibox.widget.systray()) end
  251.     -- right_layout:add(kbdcfg.widget)
  252.     right_layout:add(separator)
  253.     right_layout:add(volume.widget)
  254.     right_layout:add(kbdcfg.widget)
  255.     right_layout:add(mytextclock)
  256.     right_layout:add(mylayoutbox[s])
  257.  
  258.     -- Now bring it all together (with the tasklist in the middle)
  259.     local layout = wibox.layout.align.horizontal()
  260.     layout:set_left(left_layout)
  261.     layout:set_middle(mytasklist[s])
  262.     layout:set_right(right_layout)
  263.  
  264.     mywibox[s]:set_widget(layout)
  265. end
  266. -- }}}
  267.  
  268. -- {{{ Mouse bindings
  269. root.buttons(awful.util.table.join(
  270.     awful.button({ }, 3, function () mymainmenu:toggle() end),
  271.     awful.button({ }, 4, awful.tag.viewnext),
  272.     awful.button({ }, 5, awful.tag.viewprev)
  273. ))
  274. -- }}}
  275.  
  276. -- {{{ Key bindings
  277. globalkeys = awful.util.table.join(
  278.     --- Keyboard laoyt
  279.     awful.key({ "Mod1",           }, "Shift_L",function () kbdcfg.switch() end),
  280.     awful.key({ "Shift_L",        }, "Mod1", function () kbdcfg.switch() end),
  281.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  282.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  283.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  284.  
  285.     awful.key({ modkey,           }, "j",
  286.         function ()
  287.             awful.client.focus.byidx( 1)
  288.             if client.focus then client.focus:raise() end
  289.         end),
  290.     awful.key({ modkey,           }, "k",
  291.         function ()
  292.             awful.client.focus.byidx(-1)
  293.             if client.focus then client.focus:raise() end
  294.         end),
  295.     awful.key({ modkey,           }, "w", function () mymainmenu:show() end),
  296.  
  297.     -- Layout manipulation
  298.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  299.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  300.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  301.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  302.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  303.     awful.key({ modkey,           }, "Tab",
  304.         function ()
  305.             awful.client.focus.history.previous()
  306.             if client.focus then
  307.                 client.focus:raise()
  308.             end
  309.         end),
  310.  
  311.     -- Standard program
  312.     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
  313.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  314.     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  315.  
  316.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  317.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  318.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  319.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  320.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  321.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  322.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  323.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  324.  
  325.     awful.key({ modkey, "Control" }, "n", awful.client.restore),
  326.     awful.key({ modkey,           }, "=",   function () volume.change("+") end),
  327.     awful.key({ modkey,           }, "-", function () volume.change("-") end),
  328.     awful.key({ modkey,           }, "\\", function () volume.change("m") end),
  329.  
  330.     -- Prompt
  331.     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
  332.  
  333.     awful.key({ modkey }, "x",
  334.               function ()
  335.                   awful.prompt.run({ prompt = "Run Lua code: " },
  336.                   mypromptbox[mouse.screen].widget,
  337.                   awful.util.eval, nil,
  338.                   awful.util.getdir("cache") .. "/history_eval")
  339.               end),
  340.     -- Menubar
  341.     awful.key({ modkey }, "p", function() menubar.show() end)
  342. )
  343.  
  344. clientkeys = awful.util.table.join(
  345.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  346.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  347.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  348.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  349.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  350.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  351.     awful.key({ modkey,           }, "n",
  352.         function (c)
  353.             -- The client currently has the input focus, so it cannot be
  354.             -- minimized, since minimized clients can't have the focus.
  355.             c.minimized = true
  356.         end),
  357.     awful.key({ modkey,           }, "m",
  358.         function (c)
  359.             c.maximized_horizontal = not c.maximized_horizontal
  360.             c.maximized_vertical   = not c.maximized_vertical
  361.         end)
  362. )
  363.  
  364. -- Compute the maximum number of digit we need, limited to 9
  365. keynumber = 0
  366. for s = 1, screen.count() do
  367.    keynumber = math.min(9, math.max(#tags[s], keynumber))
  368. end
  369.  
  370. -- Bind all key numbers to tags.
  371. -- Be careful: we use keycodes to make it works on any keyboard layout.
  372. -- This should map on the top row of your keyboard, usually 1 to 9.
  373. for i = 1, keynumber do
  374.     globalkeys = awful.util.table.join(globalkeys,
  375.         awful.key({ modkey }, "#" .. i + 9,
  376.                   function ()
  377.                         local screen = mouse.screen
  378.                         if tags[screen][i] then
  379.                             awful.tag.viewonly(tags[screen][i])
  380.                         end
  381.                   end),
  382.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  383.                   function ()
  384.                       local screen = mouse.screen
  385.                       if tags[screen][i] then
  386.                           awful.tag.viewtoggle(tags[screen][i])
  387.                       end
  388.                   end),
  389.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  390.                   function ()
  391.                       if client.focus and tags[client.focus.screen][i] then
  392.                           awful.client.movetotag(tags[client.focus.screen][i])
  393.                       end
  394.                   end),
  395.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  396.                   function ()
  397.                       if client.focus and tags[client.focus.screen][i] then
  398.                           awful.client.toggletag(tags[client.focus.screen][i])
  399.                       end
  400.                   end))
  401. end
  402.  
  403. clientbuttons = awful.util.table.join(
  404.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  405.     awful.button({ modkey }, 1, awful.mouse.client.move),
  406.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  407.  
  408. -- Set keys
  409. root.keys(globalkeys)
  410. -- }}}
  411.  
  412. -- {{{ Rules
  413. awful.rules.rules = {
  414.     -- All clients will match this rule.
  415.     { rule = { },
  416.       properties = { border_width = beautiful.border_width,
  417.                      border_color = beautiful.border_normal,
  418.                      focus = awful.client.focus.filter,
  419.                      keys = clientkeys,
  420.                      size_hints_honor = false,
  421.                      buttons = clientbuttons } },
  422.     { rule = { class = "MPlayer" },
  423.       properties = { floating = true } },
  424.     { rule = { class = "pinentry" },
  425.       properties = { floating = true } },
  426.     { rule = { class = "gimp" },
  427.       properties = { floating = true } },
  428.     { rule = { class = "Skype" },
  429.       properties = { tag = tags[1][9] } },
  430.     { rule = { class = "Steam" },
  431.       properties = { tag = tags[1][9] } },
  432.     -- Set Firefox to always map on tags number 2 of screen 1.
  433.     -- { rule = { class = "Firefox" },
  434.     --   properties = { tag = tags[1][2] } },
  435. }
  436. -- }}}
  437.  
  438. -- {{{ Signals
  439. -- Signal function to execute when a new client appears.
  440. client.connect_signal("manage", function (c, startup)
  441.     -- Enable sloppy focus
  442.     c:connect_signal("mouse::enter", function(c)
  443.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  444.             and awful.client.focus.filter(c) then
  445.             client.focus = c
  446.         end
  447.     end)
  448.  
  449.     if not startup then
  450.         -- Set the windows at the slave,
  451.         -- i.e. put it at the end of others instead of setting it master.
  452.         -- awful.client.setslave(c)
  453.  
  454.         -- Put windows in a smart way, only if they does not set an initial position.
  455.         if not c.size_hints.user_position and not c.size_hints.program_position then
  456.             awful.placement.no_overlap(c)
  457.             awful.placement.no_offscreen(c)
  458.         end
  459.     end
  460.  
  461.     local titlebars_enabled = false
  462.     if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  463.         -- Widgets that are aligned to the left
  464.         local left_layout = wibox.layout.fixed.horizontal()
  465.         left_layout:add(awful.titlebar.widget.iconwidget(c))
  466.  
  467.         -- Widgets that are aligned to the right
  468.         local right_layout = wibox.layout.fixed.horizontal()
  469.         right_layout:add(awful.titlebar.widget.floatingbutton(c))
  470.         right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  471.         right_layout:add(awful.titlebar.widget.stickybutton(c))
  472.         right_layout:add(awful.titlebar.widget.ontopbutton(c))
  473.         right_layout:add(awful.titlebar.widget.closebutton(c))
  474.  
  475.         -- The title goes in the middle
  476.         local title = awful.titlebar.widget.titlewidget(c)
  477.         title: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.         -- Now bring it all together
  491.         local layout = wibox.layout.align.horizontal()
  492.         layout:set_left(left_layout)
  493.         layout:set_right(right_layout)
  494.         layout:set_middle(title)
  495.  
  496.         awful.titlebar(c):set_widget(layout)
  497.     end
  498. end)
  499.  
  500. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  501. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  502. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment