Advertisement
Guest User

Untitled

a guest
Oct 19th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 30.60 KB | None | 0 0
  1.    
  2.  
  3.     --[[
  4.                                                  
  5.          Powerarrow Darker Awesome WM config 2.0
  6.          github.com/copycat-killer              
  7.                                                  
  8.     --]]
  9.      
  10.     -- {{{ Required libraries
  11.     local gears     = require("gears")
  12.     local awful     = require("awful")
  13.     awful.rules     = require("awful.rules")
  14.                       require("awful.autofocus")
  15.     local wibox     = require("wibox")
  16.     local beautiful = require("beautiful")
  17.     local naughty   = require("naughty")
  18.     local drop      = require("scratchdrop")
  19.     local lain      = require("lain")
  20.     -- }}}
  21.      
  22.     -- {{{ Error handling
  23.     if awesome.startup_errors then
  24.         naughty.notify({ preset = naughty.config.presets.critical,
  25.                          title = "Oops, there were errors during startup! You Retard.",
  26.                          text = awesome.startup_errors })
  27.     end
  28.      
  29.     do
  30.         local in_error = false
  31.         awesome.connect_signal("debug::error", function (err)
  32.             if in_error then return end
  33.             in_error = true
  34.      
  35.             naughty.notify({ preset = naughty.config.presets.critical,
  36.                              title = "Oops, an error happened!",
  37.                              text = err })
  38.             in_error = false
  39.         end)
  40.     end
  41.     -- }}}
  42.      
  43.     -- {{{ Autostart applications
  44.     function run_once(cmd)
  45.       findme = cmd
  46.       firstspace = cmd:find(" ")
  47.       if firstspace then
  48.          findme = cmd:sub(0, firstspace-1)
  49.       end
  50.       awful.util.spawn_with_shell("pgrep -u $USER -x " .. findme .. " > /dev/null || (" .. cmd .. ")")
  51.     end
  52.      
  53.     run_once("urxvtd")
  54.     run_once("unclutter")
  55.     -- }}}
  56.      
  57.     -- {{{ Variable definitions
  58.     -- localization
  59.     os.setlocale(os.getenv("LANG"))
  60.      
  61.     -- beautiful init
  62.     beautiful.init(os.getenv("HOME") .. "/.config/awesome/themes/powerarrow-darker/theme.lua")
  63.      
  64.     -- common
  65.     modkey     = "Mod4"
  66.     altkey     = "Mod1"
  67.     terminal   = "urxvtc" or "xterm"
  68.     editor     = os.getenv("EDITOR") or "nano" or "vi"
  69.     editor_cmd = terminal .. " -e " .. editor
  70.      
  71.     -- user defined
  72.     browser    = "dwb"
  73.     browser2   = "iron"
  74.     gui_editor = "gvim"
  75.     graphics   = "gimp"
  76.     mail       = terminal .. " -e mutt "
  77.     iptraf     = terminal .. " -g 180x54-20+34 -e sudo iptraf-ng -i all "
  78.     musicplr   = terminal .. " -g 130x34-320+16 -e ncmpcpp "
  79.      
  80.     local layouts = {
  81.         awful.layout.suit.floating,
  82.         awful.layout.suit.tile,
  83.         awful.layout.suit.tile.bottom,
  84.         awful.layout.suit.fair,
  85.         awful.layout.suit.fair.horizontal,
  86.     }
  87.     -- }}}
  88.      
  89.     -- {{{ Tags
  90.     tags = {
  91.        names = { "1", "2", "3", "4", "5"},
  92.        layout = { layouts[1], layouts[2], layouts[3], layouts[1], layouts[4] }
  93.     }
  94.      
  95.     for s = 1, screen.count() do
  96.        tags[s] = awful.tag(tags.names, s, tags.layout)
  97.     end
  98.     -- }}}
  99.      
  100.     -- {{{ Wallpaper
  101.     if beautiful.wallpaper then
  102.         for s = 1, screen.count() do
  103.             gears.wallpaper.maximized(beautiful.wallpaper, s, true)
  104.         end
  105.     end
  106.     -- }}}
  107.      
  108.     -- {{{ Menu
  109.     mymainmenu = awful.menu.new({ items = require("menugen").build_menu(),
  110.                                   theme = { height = 16, width = 130 }})
  111.     -- }}}
  112.      
  113.     -- {{{ Wibox
  114.     markup = lain.util.markup
  115.      
  116.     -- Textclock
  117.     clockicon = wibox.widget.imagebox(beautiful.widget_clock)
  118.     mytextclock = awful.widget.textclock(" %a %d %b  %H:%M")
  119.      
  120.     -- calendar
  121.     lain.widgets.calendar:attach(mytextclock, { font_size = 10 })
  122.      
  123.     -- Mail IMAP check
  124.     mailicon = wibox.widget.imagebox(beautiful.widget_mail)
  125.     mailicon:buttons(awful.util.table.join(awful.button({ }, 1, function () awful.util.spawn(mail) end)))
  126.     --[[ commented because it needs to be set before use
  127.     mailwidget = wibox.widget.background(lain.widgets.imap({
  128.         timeout  = 180,
  129.         server   = "server",
  130.         mail     = "mail",
  131.         password = "keyring get mail",
  132.         settings = function()
  133.             if mailcount > 0 then
  134.                 widget:set_text(" " .. mailcount .. " ")
  135.                 mailicon:set_image(beautiful.widget_mail_on)
  136.             else
  137.                 widget:set_text("")
  138.                 mailicon:set_image(beautiful.widget_mail)
  139.             end
  140.         end
  141.     }), "#313131")
  142.     ]]
  143.      
  144.     -- MPD
  145.     mpdicon = wibox.widget.imagebox(beautiful.widget_music)
  146.     mpdicon:buttons(awful.util.table.join(awful.button({ }, 1, function () awful.util.spawn_with_shell(musicplr) end)))
  147.     mpdwidget = lain.widgets.mpd({
  148.         settings = function()
  149.             if mpd_now.state == "play" then
  150.                 artist = " " .. mpd_now.artist .. " "
  151.                 title  = mpd_now.title  .. " "
  152.                 mpdicon:set_image(beautiful.widget_music_on)
  153.             elseif mpd_now.state == "pause" then
  154.                 artist = " mpd "
  155.                 title  = "paused "
  156.             else
  157.                 artist = ""
  158.                 title  = ""
  159.                 mpdicon:set_image(beautiful.widget_music)
  160.             end
  161.      
  162.             widget:set_markup(markup("#EA6F81", artist) .. title)
  163.         end
  164.     })
  165.     mpdwidgetbg = wibox.widget.background(mpdwidget, "#313131")
  166.      
  167.     -- MEM
  168.     memicon = wibox.widget.imagebox(beautiful.widget_mem)
  169.     memwidget = lain.widgets.mem({
  170.         settings = function()
  171.             widget:set_text(" " .. mem_now.used .. "MB ")
  172.         end
  173.     })
  174.      
  175.     -- CPU
  176.     cpuicon = wibox.widget.imagebox(beautiful.widget_cpu)
  177.     cpuwidget = wibox.widget.background(lain.widgets.cpu({
  178.         settings = function()
  179.             widget:set_text(" " .. cpu_now.usage .. "% ")
  180.         end
  181.     }), "#313131")
  182.      
  183.     -- Coretemp
  184.     tempicon = wibox.widget.imagebox(beautiful.widget_temp)
  185.     tempwidget = lain.widgets.temp({
  186.         settings = function()
  187.             widget:set_text(" " .. coretemp_now .. "°C ")
  188.         end
  189.     })
  190.      
  191.     -- / fs
  192.     fsicon = wibox.widget.imagebox(beautiful.widget_hdd)
  193.     fswidget = lain.widgets.fs({
  194.         settings  = function()
  195.             widget:set_text(" " .. fs_now.used .. "% ")
  196.         end
  197.     })
  198.     fswidgetbg = wibox.widget.background(fswidget, "#313131")
  199.      
  200.     -- Battery
  201.     baticon = wibox.widget.imagebox(beautiful.widget_battery)
  202.     batwidget = lain.widgets.bat({
  203.         settings = function()
  204.             if bat_now.perc == "N/A" then
  205.                 widget:set_markup(" AC ")
  206.                 baticon:set_image(beautiful.widget_ac)
  207.                 return
  208.             elseif tonumber(bat_now.perc) <= 5 then
  209.                 baticon:set_image(beautiful.widget_battery_empty)
  210.             elseif tonumber(bat_now.perc) <= 15 then
  211.                 baticon:set_image(beautiful.widget_battery_low)
  212.             else
  213.                 baticon:set_image(beautiful.widget_battery)
  214.             end
  215.             widget:set_markup(" " .. bat_now.perc .. "% ")
  216.         end
  217.     })
  218.      
  219.     -- ALSA volume
  220.     volicon = wibox.widget.imagebox(beautiful.widget_vol)
  221.     volumewidget = lain.widgets.alsa({
  222.         settings = function()
  223.             if volume_now.status == "off" then
  224.                 volicon:set_image(beautiful.widget_vol_mute)
  225.             elseif tonumber(volume_now.level) == 0 then
  226.                 volicon:set_image(beautiful.widget_vol_no)
  227.             elseif tonumber(volume_now.level) <= 50 then
  228.                 volicon:set_image(beautiful.widget_vol_low)
  229.             else
  230.                 volicon:set_image(beautiful.widget_vol)
  231.             end
  232.      
  233.             widget:set_text(" " .. volume_now.level .. "% ")
  234.         end
  235.     })
  236.      
  237.     -- Net
  238.     neticon = wibox.widget.imagebox(beautiful.widget_net)
  239.     neticon:buttons(awful.util.table.join(awful.button({ }, 1, function () awful.util.spawn_with_shell(iptraf) end)))
  240.     netwidget = wibox.widget.background(lain.widgets.net({
  241.         settings = function()
  242.             widget:set_markup(markup("#7AC82E", " " .. net_now.received)
  243.                               .. " " ..
  244.                               markup("#46A8C3", " " .. net_now.sent .. " "))
  245.         end
  246.     }), "#313131")
  247.      
  248.     -- Separators
  249.     spr = wibox.widget.textbox(' ')
  250.     arrl = wibox.widget.imagebox()
  251.     arrl:set_image(beautiful.arrl)
  252.     arrl_dl = wibox.widget.imagebox()
  253.     arrl_dl:set_image(beautiful.arrl_dl)
  254.     arrl_ld = wibox.widget.imagebox()
  255.     arrl_ld:set_image(beautiful.arrl_ld)
  256.      
  257.     -- Create a wibox for each screen and add it
  258.     mywibox = {}
  259.     mypromptbox = {}
  260.     mylayoutbox = {}
  261.     mytaglist = {}
  262.     mytaglist.buttons = awful.util.table.join(
  263.                         awful.button({ }, 1, awful.tag.viewonly),
  264.                         awful.button({ modkey }, 1, awful.client.movetotag),
  265.                         awful.button({ }, 3, awful.tag.viewtoggle),
  266.                         awful.button({ modkey }, 3, awful.client.toggletag),
  267.                         awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
  268.                         awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
  269.                         )
  270.     mytasklist = {}
  271.     mytasklist.buttons = awful.util.table.join(
  272.                          awful.button({ }, 1, function (c)
  273.                                                   if c == client.focus then
  274.                                                       c.minimized = true
  275.                                                   else
  276.                                                       -- Without this, the following
  277.                                                       -- :isvisible() makes no sense
  278.                                                       c.minimized = false
  279.                                                       if not c:isvisible() then
  280.                                                           awful.tag.viewonly(c:tags()[1])
  281.                                                       end
  282.                                                       -- This will also un-minimize
  283.                                                       -- the client, if needed
  284.                                                       client.focus = c
  285.                                                       c:raise()
  286.                                                   end
  287.                                               end),
  288.                          awful.button({ }, 3, function ()
  289.                                                   if instance then
  290.                                                       instance:hide()
  291.                                                       instance = nil
  292.                                                   else
  293.                                                       instance = awful.menu.clients({ width=250 })
  294.                                                   end
  295.                                               end),
  296.                          awful.button({ }, 4, function ()
  297.                                                   awful.client.focus.byidx(1)
  298.                                                   if client.focus then client.focus:raise() end
  299.                                               end),
  300.                          awful.button({ }, 5, function ()
  301.                                                   awful.client.focus.byidx(-1)
  302.                                                   if client.focus then client.focus:raise() end
  303.                                               end))
  304.      
  305.     for s = 1, screen.count() do
  306.      
  307.         -- Create a promptbox for each screen
  308.         mypromptbox[s] = awful.widget.prompt()
  309.      
  310.         -- We need one layoutbox per screen.
  311.         mylayoutbox[s] = awful.widget.layoutbox(s)
  312.         mylayoutbox[s]:buttons(awful.util.table.join(
  313.                                 awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  314.                                 awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  315.                                 awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  316.                                 awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  317.      
  318.         -- Create a taglist widget
  319.         mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  320.      
  321.         -- Create a tasklist widget
  322.         mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  323.      
  324.         -- Create the wibox
  325.         mywibox[s] = awful.wibox({ position = "top", screen = s, height = 18 })
  326.      
  327.         -- Widgets that are aligned to the upper left
  328.         local left_layout = wibox.layout.fixed.horizontal()
  329.         left_layout:add(spr)
  330.         left_layout:add(mytaglist[s])
  331.         left_layout:add(mypromptbox[s])
  332.         left_layout:add(spr)
  333.      
  334.         -- Widgets that are aligned to the upper right
  335.         -- If you are moving widgets from a section with light grey background to dark grey or vice versa,
  336.         -- use a replacement icon as appropriate from themes/powerarrow-darker/alticons so your icons match the bg.
  337.         local right_layout = wibox.layout.fixed.horizontal()
  338.         if s == 1 then right_layout:add(wibox.widget.systray()) end
  339.         right_layout:add(spr)
  340.         right_layout:add(arrl)
  341.         right_layout:add(arrl_ld)
  342.         right_layout:add(mpdicon)
  343.         right_layout:add(mpdwidgetbg)
  344.         right_layout:add(arrl_dl)
  345.         right_layout:add(volicon)
  346.         right_layout:add(volumewidget)
  347.         right_layout:add(arrl_ld)
  348.         right_layout:add(mailicon)
  349.         --right_layout:add(mailwidget)
  350.         right_layout:add(arrl_dl)
  351.         right_layout:add(memicon)
  352.         right_layout:add(memwidget)
  353.         right_layout:add(arrl_ld)
  354.         right_layout:add(cpuicon)
  355.         right_layout:add(cpuwidget)
  356.         right_layout:add(arrl_dl)
  357.         right_layout:add(tempicon)
  358.         right_layout:add(tempwidget)
  359.         right_layout:add(arrl_ld)
  360.         right_layout:add(fsicon)
  361.         right_layout:add(fswidgetbg)
  362.         right_layout:add(arrl_dl)
  363.         right_layout:add(baticon)
  364.         right_layout:add(batwidget)
  365.         right_layout:add(arrl_ld)
  366.         right_layout:add(neticon)
  367.         right_layout:add(netwidget)
  368.         right_layout:add(arrl_dl)
  369.         right_layout:add(mytextclock)
  370.         right_layout:add(spr)
  371.         right_layout:add(arrl_ld)
  372.         right_layout:add(mylayoutbox[s])
  373.      
  374.         -- Now bring it all together (with the tasklist in the middle)
  375.         local layout = wibox.layout.align.horizontal()
  376.         layout:set_left(left_layout)
  377.         layout:set_middle(mytasklist[s])
  378.         layout:set_right(right_layout)
  379.         mywibox[s]:set_widget(layout)
  380.      
  381.     end
  382.     -- }}}
  383.      
  384.     -- {{{ Mouse Bindings
  385.     root.buttons(awful.util.table.join(
  386.         awful.button({ }, 3, function () mymainmenu:toggle() end),
  387.         awful.button({ }, 4, awful.tag.viewnext),
  388.         awful.button({ }, 5, awful.tag.viewprev)
  389.     ))
  390.     -- }}}
  391.      
  392.     -- {{{ Key bindings
  393.     globalkeys = awful.util.table.join(
  394.        
  395.         -- Awesome Resize (inward)
  396.         awful.key({ modkey }, "[",  function ()
  397.                     beautiful.global_border_width = beautiful.global_border_width - 5
  398.                     awful.layout.arrange(1)
  399.         end),
  400.        
  401.         -- Awesome Resize (outward)
  402.         awful.key({ modkey }, "]",  function ()
  403.                     beautiful.global_border_width = beautiful.global_border_width + 5
  404.                     awful.layout.arrange(1)
  405.         end),
  406.        
  407.         -- Take a screenshot
  408.         -- https://github.com/copycat-killer/dots/blob/master/bin/screenshot
  409.         awful.key({ altkey }, "p", function() os.execute("screenshot") end),
  410.      
  411.         -- Tag browsing
  412.         awful.key({ modkey }, "Left",   awful.tag.viewprev       ),
  413.         awful.key({ modkey }, "Right",  awful.tag.viewnext       ),
  414.         awful.key({ modkey }, "Escape", awful.tag.history.restore),
  415.      
  416.         -- Non-empty tag browsing
  417.         awful.key({ altkey }, "Left", function () lain.util.tag_view_nonempty(-1) end),
  418.         awful.key({ altkey }, "Right", function () lain.util.tag_view_nonempty(1) end),
  419.      
  420.         -- Default client focus
  421.         awful.key({ altkey }, "k",
  422.             function ()
  423.                 awful.client.focus.byidx( 1)
  424.                 if client.focus then client.focus:raise() end
  425.             end),
  426.         awful.key({ altkey }, "j",
  427.             function ()
  428.                 awful.client.focus.byidx(-1)
  429.                 if client.focus then client.focus:raise() end
  430.             end),
  431.      
  432.         -- By direction client focus
  433.         awful.key({ modkey }, "j",
  434.             function()
  435.                 awful.client.focus.bydirection("down")
  436.                 if client.focus then client.focus:raise() end
  437.             end),
  438.         awful.key({ modkey }, "k",
  439.             function()
  440.                 awful.client.focus.bydirection("up")
  441.                 if client.focus then client.focus:raise() end
  442.             end),
  443.         awful.key({ modkey }, "h",
  444.             function()
  445.                 awful.client.focus.bydirection("left")
  446.                 if client.focus then client.focus:raise() end
  447.             end),
  448.         awful.key({ modkey }, "l",
  449.             function()
  450.                 awful.client.focus.bydirection("right")
  451.                 if client.focus then client.focus:raise() end
  452.             end),
  453.      
  454.         -- Show Menu
  455.         awful.key({ modkey }, "w",
  456.             function ()
  457.                 mymainmenu:show({ keygrabber = true })
  458.             end),
  459.      
  460.         -- Show/Hide Wibox
  461.         awful.key({ modkey }, "b", function ()
  462.             mywibox[mouse.screen].visible = not mywibox[mouse.screen].visible
  463.         end),
  464.      
  465.         -- Layout manipulation
  466.         awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  467.         awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  468.         awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  469.         awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  470.         awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  471.         awful.key({ modkey,           }, "Tab",
  472.             function ()
  473.                 awful.client.focus.history.previous()
  474.                 if client.focus then
  475.                     client.focus:raise()
  476.                 end
  477.             end),
  478.         awful.key({ altkey, "Shift"   }, "l",      function () awful.tag.incmwfact( 0.05)     end),
  479.         awful.key({ altkey, "Shift"   }, "h",      function () awful.tag.incmwfact(-0.05)     end),
  480.         awful.key({ modkey, "Shift"   }, "l",      function () awful.tag.incnmaster(-1)       end),
  481.         awful.key({ modkey, "Shift"   }, "h",      function () awful.tag.incnmaster( 1)       end),
  482.         awful.key({ modkey, "Control" }, "l",      function () awful.tag.incncol(-1)          end),
  483.         awful.key({ modkey, "Control" }, "h",      function () awful.tag.incncol( 1)          end),
  484.         awful.key({ modkey,           }, "space",  function () awful.layout.inc(layouts,  1)  end),
  485.         awful.key({ modkey, "Shift"   }, "space",  function () awful.layout.inc(layouts, -1)  end),
  486.         awful.key({ modkey, "Control" }, "n",      awful.client.restore),
  487.      
  488.         -- Standard program
  489.         awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
  490.         awful.key({ modkey, "Control" }, "r",      awesome.restart),
  491.         awful.key({ modkey, "Shift"   }, "q",      awesome.quit),
  492.      
  493.         -- Dropdown terminal
  494.         awful.key({ modkey,           }, "z",      function () drop(terminal) end),
  495.      
  496.         -- Widgets popups
  497.         awful.key({ altkey,           }, "c",      function () lain.widgets.calendar:show(7) end),
  498.         awful.key({ altkey,           }, "h",      function () fswidget.show(7) end),
  499.      
  500.         -- ALSA volume control
  501.         awful.key({ altkey }, "Up",
  502.             function ()
  503.                 awful.util.spawn("amixer -q set Master 1%+")
  504.                 volumewidget.update()
  505.             end),
  506.         awful.key({ altkey }, "Down",
  507.             function ()
  508.                 awful.util.spawn("amixer -q set Master 1%-")
  509.                 volumewidget.update()
  510.             end),
  511.         awful.key({ altkey }, "m",
  512.             function ()
  513.                 awful.util.spawn("amixer -q set Master playback toggle")
  514.                 volumewidget.update()
  515.             end),
  516.         awful.key({ altkey, "Control" }, "m",
  517.             function ()
  518.                 awful.util.spawn("amixer -q set Master playback 100%")
  519.                 volumewidget.update()
  520.             end),
  521.      
  522.         -- MPD control
  523.         awful.key({ altkey, "Control" }, "Up",
  524.             function ()
  525.                 awful.util.spawn_with_shell("mpc toggle || ncmpc toggle || pms toggle")
  526.                 mpdwidget.update()
  527.             end),
  528.         awful.key({ altkey, "Control" }, "Down",
  529.             function ()
  530.                 awful.util.spawn_with_shell("mpc stop || ncmpc stop || pms stop")
  531.                 mpdwidget.update()
  532.             end),
  533.         awful.key({ altkey, "Control" }, "Left",
  534.             function ()
  535.                 awful.util.spawn_with_shell("mpc prev || ncmpc prev || pms prev")
  536.                 mpdwidget.update()
  537.             end),
  538.         awful.key({ altkey, "Control" }, "Right",
  539.             function ()
  540.                 awful.util.spawn_with_shell("mpc next || ncmpc next || pms next")
  541.                 mpdwidget.update()
  542.             end),
  543.      
  544.         -- Copy to clipboard
  545.         awful.key({ modkey }, "c", function () os.execute("xsel -p -o | xsel -i -b") end),
  546.      
  547.         -- User programs
  548.         awful.key({ modkey }, "q", function () awful.util.spawn(browser) end),
  549.         awful.key({ modkey }, "i", function () awful.util.spawn(browser2) end),
  550.         awful.key({ modkey }, "s", function () awful.util.spawn(gui_editor) end),
  551.         awful.key({ modkey }, "g", function () awful.util.spawn(graphics) end),
  552.      
  553.         -- Prompt
  554.         awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
  555.         awful.key({ modkey }, "x",
  556.                   function ()
  557.                       awful.prompt.run({ prompt = "Run Lua code: " },
  558.                       mypromptbox[mouse.screen].widget,
  559.                       awful.util.eval, nil,
  560.                       awful.util.getdir("cache") .. "/history_eval")
  561.                   end)
  562.     )
  563.      
  564.     clientkeys = awful.util.table.join(
  565.         awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  566.         awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  567.         awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  568.         awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  569.         awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  570.         awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  571.         awful.key({ modkey,           }, "n",
  572.             function (c)
  573.                 -- The client currently has the input focus, so it cannot be
  574.                 -- minimized, since minimized clients can't have the focus.
  575.                 c.minimized = true
  576.             end),
  577.         awful.key({ modkey,           }, "m",
  578.             function (c)
  579.                 c.maximized_horizontal = not c.maximized_horizontal
  580.                 c.maximized_vertical   = not c.maximized_vertical
  581.             end)
  582.     )
  583.      
  584.     -- Bind all key numbers to tags.
  585.     -- Be careful: we use keycodes to make it works on any keyboard layout.
  586.     -- This should map on the top row of your keyboard, usually 1 to 9.
  587.     for i = 1, 9 do
  588.         globalkeys = awful.util.table.join(globalkeys,
  589.             awful.key({ modkey }, "#" .. i + 9,
  590.                       function ()
  591.                             local screen = mouse.screen
  592.                             local tag = awful.tag.gettags(screen)[i]
  593.                             if tag then
  594.                                awful.tag.viewonly(tag)
  595.                             end
  596.                       end),
  597.             awful.key({ modkey, "Control" }, "#" .. i + 9,
  598.                       function ()
  599.                           local screen = mouse.screen
  600.                           local tag = awful.tag.gettags(screen)[i]
  601.                           if tag then
  602.                              awful.tag.viewtoggle(tag)
  603.                           end
  604.                       end),
  605.             awful.key({ modkey, "Shift" }, "#" .. i + 9,
  606.                       function ()
  607.                           local tag = awful.tag.gettags(client.focus.screen)[i]
  608.                           if client.focus and tag then
  609.                               awful.client.movetotag(tag)
  610.                          end
  611.                       end),
  612.             awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  613.                       function ()
  614.                           local tag = awful.tag.gettags(client.focus.screen)[i]
  615.                           if client.focus and tag then
  616.                               awful.client.toggletag(tag)
  617.                           end
  618.                       end))
  619.     end
  620.      
  621.     clientbuttons = awful.util.table.join(
  622.         awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  623.         awful.button({ modkey }, 1, awful.mouse.client.move),
  624.         awful.button({ modkey }, 3, awful.mouse.client.resize))
  625.      
  626.     -- Set keys
  627.     root.keys(globalkeys)
  628.     -- }}}
  629.      
  630.     -- {{{ Rules
  631.     awful.rules.rules = {
  632.         -- All clients will match this rule.
  633.         { rule = { },
  634.           properties = { border_width = beautiful.border_width,
  635.                          border_color = beautiful.border_normal,
  636.                          focus = awful.client.focus.filter,
  637.                          keys = clientkeys,
  638.                          buttons = clientbuttons,
  639.                                size_hints_honor = false } },
  640.         { rule = { class = "URxvt" },
  641.               properties = { opacity = 0.99 } },
  642.      
  643.         { rule = { class = "MPlayer" },
  644.               properties = { floating = true } },
  645.      
  646.         { rule = { class = "Dwb" },
  647.               properties = { tag = tags[1][1] } },
  648.      
  649.         { rule = { class = "Iron" },
  650.               properties = { tag = tags[1][1] } },
  651.      
  652.         { rule = { instance = "plugin-container" },
  653.               properties = { tag = tags[1][1] } },
  654.      
  655.               { rule = { class = "Gimp" },
  656.                 properties = { tag = tags[1][4] } },
  657.      
  658.         { rule = { class = "Gimp", role = "gimp-image-window" },
  659.               properties = { maximized_horizontal = true,
  660.                              maximized_vertical = true } },
  661.     }
  662.     -- }}}
  663.      
  664.     -- {{{ Signals
  665.     -- signal function to execute when a new client appears.
  666.     client.connect_signal("manage", function (c, startup)
  667.         -- enable sloppy focus
  668.         c:connect_signal("mouse::enter", function(c)
  669.             if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  670.                 and awful.client.focus.filter(c) then
  671.                 client.focus = c
  672.             end
  673.         end)
  674.      
  675.         if not startup and not c.size_hints.user_position
  676.            and not c.size_hints.program_position then
  677.             awful.placement.no_overlap(c)
  678.             awful.placement.no_offscreen(c)
  679.         end
  680.      
  681.         local titlebars_enabled = false
  682.         if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  683.             -- buttons for the titlebar
  684.             local buttons = awful.util.table.join(
  685.                     awful.button({ }, 1, function()
  686.                         client.focus = c
  687.                         c:raise()
  688.                         awful.mouse.client.move(c)
  689.                     end),
  690.                     awful.button({ }, 3, function()
  691.                         client.focus = c
  692.                         c:raise()
  693.                         awful.mouse.client.resize(c)
  694.                     end)
  695.                     )
  696.      
  697.             -- widgets that are aligned to the right
  698.             local right_layout = wibox.layout.fixed.horizontal()
  699.             right_layout:add(awful.titlebar.widget.floatingbutton(c))
  700.             right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  701.             right_layout:add(awful.titlebar.widget.stickybutton(c))
  702.             right_layout:add(awful.titlebar.widget.ontopbutton(c))
  703.             right_layout:add(awful.titlebar.widget.closebutton(c))
  704.      
  705.             -- the title goes in the middle
  706.             local middle_layout = wibox.layout.flex.horizontal()
  707.             local title = awful.titlebar.widget.titlewidget(c)
  708.             title:set_align("center")
  709.             middle_layout:add(title)
  710.             middle_layout:buttons(buttons)
  711.      
  712.             -- now bring it all together
  713.             local layout = wibox.layout.align.horizontal()
  714.             layout:set_right(right_layout)
  715.             layout:set_middle(middle_layout)
  716.      
  717.             awful.titlebar(c,{size=16}):set_widget(layout)
  718.         end
  719.     end)
  720.      
  721.     -- No border for maximized clients
  722.     client.connect_signal("focus",
  723.         function(c)
  724.             if c.maximized_horizontal == true and c.maximized_vertical == true then
  725.                 c.border_color = beautiful.border_normal
  726.             else
  727.                 c.border_color = beautiful.border_focus
  728.             end
  729.         end)
  730.     client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  731.     -- }}}
  732.      
  733.     -- {{{ Arrange signal handler
  734.     for s = 1, screen.count() do screen[s]:connect_signal("arrange", function ()
  735.             local clients = awful.client.visible(s)
  736.             local layout  = awful.layout.getname(awful.layout.get(s))
  737.      
  738.             if #clients > 0 then -- Fine grained borders and floaters control
  739.                 for _, c in pairs(clients) do -- Floaters always have borders
  740.                     if awful.client.floating.get(c) or layout == "floating" then
  741.                         c.border_width = beautiful.border_width
  742.      
  743.                     -- No borders with only one visible client
  744.                     elseif #clients == 1 or layout == "max" then
  745.                         clients[1].border_width = 0
  746.                     else
  747.                         c.border_width = beautiful.border_width
  748.                     end
  749.                 end
  750.             end
  751.           end)
  752.     end
  753.     -- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement