vladkomarr

rc.lua

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