]> git.madduck.net Git - etc/awesome.git/blobdiff - .config/awesome/rc.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

move battery widget to better context
[etc/awesome.git] / .config / awesome / rc.lua
index 60c913358f82d8f397e63e50bbdb721545d9dc0f..5a4db6934974182ac822b3522d3658825278ab76 100644 (file)
@@ -12,12 +12,18 @@ local xrdb = beautiful.xresources
 local naughty = require("naughty")
 local menubar = require("menubar")
 local hotkeys_popup = require("awful.hotkeys_popup").widget
+-- Enable hotkeys help widget for VIM and other apps
+-- when client with a matching name is opened:
+require("awful.hotkeys_popup.keys")
+
+-- Load Debian menu entries
+local debian = require("debian.menu")
+local has_fdo, freedesktop = pcall(require, "freedesktop")
+-- Other libraries
 local tblutils = require("tblutils")
 local lain = require("lain")
-local dkjson = require("lain.util").dkjson
-local math = require("math")
-local freedesktop = require("freedesktop")
-local luatz = require("luatz")
+local ccwidgets = require("cryptocoin_widgets")
+local clocksarray = require("clocksarray")
 -- }}}
 
 -- {{{ Error handling
@@ -49,13 +55,13 @@ end
 --xrdb.set_dpi(95, screen[1])
 --xrdb.set_dpi(120, screen[2])
 
--- Themes define colours, icons, and wallpapers
-beautiful.init(awful.util.get_themes_dir() .. "default/theme.lua")
+-- Themes define colours, icons, font and wallpapers.
+beautiful.init(gears.filesystem.get_themes_dir() .. "default/theme.lua")
 beautiful.font = 'Sans 10'
 
 -- This is used later as the default terminal and editor to run.
 terminal = "x-terminal-emulator"
-editor = "sensible-editor"
+editor = os.getenv("EDITOR") or "editor"
 editor_cmd = terminal .. " -e " .. editor
 
 -- Default modkey.
@@ -68,27 +74,28 @@ cmdkey = "Mod3"
 
 -- Table of layouts to cover with awful.layout.inc, order matters.
 awful.layout.layouts = {
-    awful.layout.suit.fair,
+    awful.layout.suit.floating,
     awful.layout.suit.tile,
-    -- awful.layout.suit.tile.left,
-    -- awful.layout.suit.tile.bottom,
+    awful.layout.suit.tile.left,
+    awful.layout.suit.tile.bottom,
     awful.layout.suit.tile.top,
-    -- awful.layout.suit.spiral,
-    -- awful.layout.suit.spiral.dwindle,
+    awful.layout.suit.fair,
+    awful.layout.suit.fair.horizontal,
+    awful.layout.suit.spiral,
+    awful.layout.suit.spiral.dwindle,
     awful.layout.suit.max,
-    -- awful.layout.suit.max.fullscreen,
-    -- awful.layout.suit.magnifier,
-    -- awful.layout.suit.corner.nw,
+    awful.layout.suit.max.fullscreen,
+    awful.layout.suit.magnifier,
+    awful.layout.suit.corner.nw,
     -- awful.layout.suit.corner.ne,
     -- awful.layout.suit.corner.sw,
     -- awful.layout.suit.corner.se,
-    awful.layout.suit.floating,
 }
 
-layout_default = awful.layout.layouts[1]
+layout_default = awful.layout.layouts[6]
 layout_tiled = awful.layout.layouts[2]
-layout_maximised = awful.layout.layouts[4]
-layout_floating = awful.layout.layouts[5]
+layout_maximised = awful.layout.layouts[10]
+layout_floating = awful.layout.layouts[1]
 -- }}}
 
 -- {{{ Helper functions
@@ -105,48 +112,17 @@ local function client_menu_toggle_fn()
     end
 end
 
-local lain_bat = lain.widget.bat({
-    batteries = {"BAT0", "BAT1"},
-    settings = function()
-        local delim = "↓"
-        if bat_now.status == "Charging" then delim = "↑"
-        elseif bat_now.status == "Unknown" then delim = "٭" end
-        widget:set_text(bat_now.perc .. "% " .. delim .. " " .. bat_now.time)
-    end,
-})
-
-local function poloniex_price(output, pair, prec)
-    local xc, pos, err = dkjson.decode(output, 1, nil)
-    if not prec then prec = 4 end
-    val = (xc and xc[pair]["last"]) or 0
-    val = math.floor(val*10^prec+0.5)/10^prec
-    return (not err and val) or "n/a"
-end
-
-local eth_widget = lain.widget.watch({
-    cmd = "curl -m5 -s 'https://poloniex.com/public?command=returnTicker'",
-    timeout = 600,
-    settings = function()
-        widget:set_text(poloniex_price(output, 'BTC_ETH') .. " Ƀ/Ξ")
+local function set_wallpaper(s)
+    -- Wallpaper
+    if beautiful.wallpaper then
+        local wallpaper = beautiful.wallpaper
+        -- If wallpaper is a function, call it with the screen
+        if type(wallpaper) == "function" then
+            wallpaper = wallpaper(s)
+        end
+        gears.wallpaper.maximized(wallpaper, s, true)
     end
-})
-
-local function coindesk_price(output, base, prec)
-    local xc, pos, err = dkjson.decode(output, 1, nil)
-    if not prec then prec = 4 end
-    val = (xc and xc["bpi"][base]["rate_float"]) or 0
-    val = math.floor(val*10^prec+0.5)/10^prec
-    return (not err and val) or "n/a"
 end
-
-local btc_widget = lain.widget.watch({
-    cmd = "curl -m5 -Ls 'https://api.coindesk.com/v1/bpi/currentprice/EUR.json'",
-    timeout = 600,
-    settings = function()
-        widget:set_text(coindesk_price(output, "EUR", 2) .. " €/Ƀ")
-    end
-})
-
 -- }}}
 
 -- {{{ Menu
@@ -156,52 +132,60 @@ myawesomemenu = {
    { "manual", terminal .. " -e man awesome" },
    { "edit config", editor_cmd .. " " .. awesome.conffile },
    { "restart", awesome.restart },
-   { "quit", awesome.quit }
+   { "quit", function() awesome.quit() end}
 }
 
-mymainmenu = freedesktop.menu.build({
-    before = {
-        { "awesome", myawesomemenu, beautiful.awesome_icon },
-        { "terminal", terminal },
-    },
-    after = {
-    }
-})
+local menu_awesome = { "awesome", myawesomemenu, beautiful.awesome_icon }
+local menu_terminal = { "open terminal", terminal }
+
+if has_fdo then
+    mymainmenu = freedesktop.menu.build({
+        before = { menu_awesome },
+        after =  { menu_terminal }
+    })
+else
+    mymainmenu = awful.menu({
+        items = {
+                  menu_awesome,
+                  { "Debian", debian.menu.Debian_menu.Debian },
+                  menu_terminal,
+                }
+    })
+end
+
 
 mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
                                      menu = mymainmenu })
--- }}}
 
--- {{{ Menubar configuration
+-- Menubar configuration
 menubar.utils.terminal = terminal -- Set the terminal for applications that require it
 -- }}}
 
--- {{{ Wibox
+-- {{{ Wibar
 local spacer = wibox.widget.textbox()
 spacer:set_text(' │ ')
--- Create a textclock widget
-clocks = { wibox.widget.textclock("%a %d %b %H:%M:%S %Z", 1) }
 
-ZONES = {
-  ["NZ"] = "Pacific/Auckland",
-  ["DE"] = "Europe/Berlin"
-}
-local now = luatz.time_in(nil)
-for c, tz in tblutils.sorted_pairs(ZONES) do
-    local t = luatz.time_in(tz)
-    if math.abs(os.difftime(t, now)) > 10 then
-        local widget = wibox.widget.textclock(c .. ": %H:%M (%a)", 60, tz)
-        table.insert(clocks, 1, spacer)
-        table.insert(clocks, 1, widget)
-    end
-end
+-- Keyboard map indicator and switcher
+mykeyboardlayout = awful.widget.keyboardlayout()
+
+local lain_bat = lain.widget.bat({
+    batteries = {"BAT0", "BAT1"},
+    settings = function()
+        local delim = "↓"
+        if bat_now.status == "Charging" then delim = "↑"
+        elseif bat_now.status == "Unknown" then delim = "٭" end
+        widget:set_text(bat_now.perc .. "% " .. delim .. " " .. bat_now.time)
+    end,
+})
+
+-- Create a textclock widget
+clocksarray = clocksarray.get_clocksarray("%a %d %b %H:%M:%S %Z", {
+        ["NZ"] = "Pacific/Auckland",
+        ["DE"] = "Europe/Berlin"
+    }, spacer)
 
 -- Create a wibox for each screen and add it
-mywibox = {}
-mypromptbox = {}
-mylayoutbox = {}
-mytaglist = {}
-mytaglist.buttons = awful.util.table.join(
+local taglist_buttons = gears.table.join(
                     awful.button({ }, 1, function(t) t:view_only() end),
                     awful.button({ modkey }, 1, function(t)
                                               if client.focus then
@@ -218,8 +202,7 @@ mytaglist.buttons = awful.util.table.join(
                     awful.button({ }, 5, function(t) awful.tag.viewprev(t.screen) end)
                 )
 
-mytasklist = {}
-mytasklist.buttons = awful.util.table.join(
+local tasklist_buttons = gears.table.join(
                      awful.button({ }, 1, function (c)
                                               if c == client.focus then
                                                   -- I don't like click-minimising
@@ -246,6 +229,9 @@ mytasklist.buttons = awful.util.table.join(
                                           end))
 -- }}}
 
+-- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
+screen.connect_signal("property::geometry", set_wallpaper)
+
 -- {{{ Tags
 tags = {}
 tags.config = {}
@@ -284,15 +270,6 @@ end
 awful.screen.connect_for_each_screen(function(s)
     -- local fontsize = math.floor(250 * xrdb.get_dpi(s)/s.geometry.width)
     -- beautiful.font = "Sans " .. tostring(fontsize)
-    -- Wallpaper
-    --DISABLED--if beautiful.wallpaper then
-    --DISABLED--    local wallpaper = beautiful.wallpaper
-    --DISABLED--    -- If wallpaper is a function, call it with the screen
-    --DISABLED--    if type(wallpaper) == "function" then
-    --DISABLED--        wallpaper = wallpaper(s)
-    --DISABLED--    end
-    --DISABLED--    gears.wallpaper.maximized(wallpaper, s, true)
-    --DISABLED--end
 
     if not tags[s.index] then
         tags[s.index] = {}
@@ -337,12 +314,14 @@ awful.screen.connect_for_each_screen(function(s)
                 layout = wibox.layout.fixed.horizontal,
                 mykeyboardlayout,
                 wibox.widget.systray(),
-                btc_widget,
+                ccwidgets.btc_widget,
+                spacer,
+                ccwidgets.eth_widget,
                 spacer,
                 lain_bat.widget,
                 spacer,
             },
-            clocks,
+            clocksarray,
             {
                 mylayoutbox[s],
             }
@@ -352,7 +331,7 @@ end)
 -- }}}
 
 -- {{{ Mouse bindings
-root.buttons(awful.util.table.join(
+root.buttons(gears.table.join(
     awful.button({ }, 3, function () mymainmenu:toggle() end),
     awful.button({ }, 4, awful.tag.viewnext),
     awful.button({ }, 5, awful.tag.viewprev)
@@ -360,7 +339,7 @@ root.buttons(awful.util.table.join(
 -- }}}
 
 -- {{{ Key bindings
-globalkeys = awful.util.table.join(
+globalkeys = gears.table.join(
     awful.key({ modkey,           }, "s",      hotkeys_popup.show_help,
               {description="show help", group="awesome"}),
     awful.key({ modkey,           }, "Left",   awful.tag.viewprev,
@@ -442,15 +421,17 @@ globalkeys = awful.util.table.join(
               {description = "restore minimized", group = "client"}),
 
     -- Prompt
-    awful.key({ modkey },            "r",     function () mypromptbox[awful.screen.focused()]:run() end,
+    awful.key({ modkey },            "r",     function () awful.screen.focused().mypromptbox:run() end,
               {description = "run prompt", group = "launcher"}),
 
     awful.key({ modkey }, "x",
               function ()
-                  awful.prompt.run({ prompt = "Run Lua code: " },
-                  mypromptbox[awful.screen.focused()].widget,
-                  awful.util.eval, nil,
-                  awful.util.get_cache_dir() .. "/history_eval")
+                  awful.prompt.run {
+                    prompt       = "Run Lua code: ",
+                    textbox      = awful.screen.focused().mypromptbox.widget,
+                    exe_callback = awful.util.eval,
+                    history_path = awful.util.get_cache_dir() .. "/history_eval"
+                  }
               end,
               {description = "lua execute prompt", group = "awesome"}),
     -- Menubar
@@ -458,7 +439,7 @@ globalkeys = awful.util.table.join(
               {description = "show the menubar", group = "launcher"})
 )
 
-clientkeys = awful.util.table.join(
+clientkeys = gears.table.join(
     awful.key({ modkey,           }, "f",
         function (c)
             c.fullscreen = not c.fullscreen
@@ -489,14 +470,26 @@ clientkeys = awful.util.table.join(
             c.maximized_vertical = false
             c:raise()
         end ,
-        {description = "maximize", group = "client"})
+        {description = "(un)maximize", group = "client"}),
+    awful.key({ modkey, "Control" }, "m",
+        function (c)
+            c.maximized_vertical = not c.maximized_vertical
+            c:raise()
+        end ,
+        {description = "(un)maximize vertically", group = "client"}),
+    awful.key({ modkey, "Shift"   }, "m",
+        function (c)
+            c.maximized_horizontal = not c.maximized_horizontal
+            c:raise()
+        end ,
+        {description = "(un)maximize horizontally", group = "client"})
 )
 
 -- Bind all key numbers to tags.
--- Be careful: we use keycodes to make it works on any keyboard layout.
+-- Be careful: we use keycodes to make it work on any keyboard layout.
 -- This should map on the top row of your keyboard, usually 1 to 9.
 for i = 1, 9 do
-    globalkeys = awful.util.table.join(globalkeys,
+    globalkeys = gears.table.join(globalkeys,
         -- View tag only.
         awful.key({ modkey }, "#" .. i + 9,
                   function ()
@@ -507,7 +500,7 @@ for i = 1, 9 do
                         end
                   end,
                   {description = "view tag #"..i, group = "tag"}),
-        -- Toggle tag.
+        -- Toggle tag display.
         awful.key({ modkey, "Control" }, "#" .. i + 9,
                   function ()
                       local screen = awful.screen.focused()
@@ -542,7 +535,7 @@ for i = 1, 9 do
     )
 end
 
-clientbuttons = awful.util.table.join(
+clientbuttons = gears.table.join(
     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
     awful.button({ modkey }, 1, awful.mouse.client.move),
     awful.button({ modkey }, 3, awful.mouse.client.resize))
@@ -711,7 +704,7 @@ end)
 -- Add a titlebar if titlebars_enabled is set to true in the rules.
 client.connect_signal("request::titlebars", function(c)
     -- buttons for the titlebar
-    local buttons = awful.util.table.join(
+    local buttons = gears.table.join(
         awful.button({ }, 1, function()
             client.focus = c
             c:raise()
@@ -750,7 +743,7 @@ client.connect_signal("request::titlebars", function(c)
     }
 end)
 
--- Enable sloppy focus
+-- Enable sloppy focus, so that focus follows mouse.
 client.connect_signal("mouse::enter", function(c)
     if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
         and awful.client.focus.filter(c) then