Browse Source

Improvements in awesome configuration

Emmanuel Bouthenot 13 years ago
parent
commit
f135f7c407
4 changed files with 379 additions and 48 deletions
  1. 168 0
      .config/awesome/awqterm.lua
  2. 34 0
      .config/awesome/helpers.lua
  3. 130 48
      .config/awesome/rc.lua
  4. 47 0
      .config/awesome/utils.lua

+ 168 - 0
.config/awesome/awqterm.lua

@@ -0,0 +1,168 @@
+-- {{{ License
+-- Awesome dropdown Quake like console
+-- 2012, Emmanuel Bouthenot <kolter@openics.org>
+--
+-- (very) partially inspired from http://awesome.naquadah.org/wiki/Drop-down_terminal
+--
+-- This file is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY
+--
+-- }}}
+
+-- {{{ Libraries
+require('utils')
+-- }}}
+
+-- {{{ Variables
+awq = {}
+awq_tag = nil
+awq_name = ''
+awq_scr = nil
+awq_idx = 0
+awqterm_prog = 'xterm'
+-- }}}
+
+-- {{{ Keys
+awqkeys = awful.util.table.join(
+    awful.key({ "Control" }, "Prior", function(c) awq_client_show_next() end),
+    awful.key({ "Control" }, "Next" , function(c) awq_client_show_prev()  end),
+    awful.key({ "Mod1" }   , "Up"   , function(c) awq_client_new()  end)
+)
+-- }}}
+
+-- {{{ Functions (“private”)
+function awq_client_show_pos(reverse)
+    local keys = awful.util.table.keys(awq)
+    if reverse then
+        keys = awful.util.table.reverse(keys)
+    end
+    local pos = table.pos(keys, awq_name)
+    if not (pos == nil) then
+        local pos = pos+1
+        local newname = table.keypos(keys, pos)
+        if newname == nil then
+            newname = table.keyfirst(keys)
+        end
+        if not (awq_name == newname) then
+            awq_client_hide(awq_name)
+            awq_name = newname
+            awq_client_show(awq_name)
+        end
+    end
+end
+
+function awq_client_show_next()
+    awq_client_show_pos(true)
+end
+
+function awq_client_show_prev()
+    awq_client_show_pos(false)
+end
+
+function awq_client_new()
+    awq_idx = awq_idx+1
+    awq_name = 'awq_' .. awq_idx
+    local name = awq_name
+    if not awq[name] then
+        -- Create table
+        awq[name] = {}
+        -- Add unmanage hook for awq programs
+        client.add_signal("unmanage", function (c, startup)
+            awq_client_show_prev()
+            for name,data in pairs(awq) do
+                for s, cl in pairs(data) do
+                    if cl == c then
+                        awq[name] = nil
+                    end
+                end
+            end
+        end)
+    end
+    -- Get workarea
+    local workarea = screen[awq_scr].workarea
+    spawnw = function (c)
+        -- Store client
+        awq[name][awq_scr] = c
+        -- Float client
+        awful.client.floating.set(c, true)
+        -- Resize client
+        c:geometry({
+            x = workarea.x,
+            y = workarea.y-19,
+            width = workarea.width,
+            height = workarea.height+20
+        })
+        -- Set keys
+        c:keys(awful.util.table.join(
+            c:keys(),
+            awqkeys
+        ))
+        -- Focus and raise client
+        c:raise()
+        client.focus = c
+        -- Remove hook
+        client.remove_signal("manage", spawnw)
+    end
+    -- Add hook
+    client.add_signal("manage", spawnw)
+    -- Spawn program
+    awful.util.spawn(awqterm_prog)
+    awq_tag = awful.tag.selected(awq_scr)
+end
+
+function awq_client_show(name)
+    -- Get client
+    local c = awq[name][awq_scr]
+    awful.client.movetotag(awful.tag.selected(awq_scr), c)
+    c.hidden = false
+    c:raise()
+    client.focus = c
+end
+
+function awq_client_hide(name)
+    -- Get client
+    local c = awq[name][awq_scr]
+    if awful.tag.selected(awq_scr) == awq_tag then
+        c.hidden = true
+        local ctags = c:tags()
+        for i, t in pairs(ctags) do
+            ctags[i] = nil
+        end
+        c:tags(ctags)
+    else
+        awful.client.movetotag(awful.tag.selected(awq_scr), c)
+        c:raise()
+        client.focus = c
+    end
+end
+
+function awq_client_toggle()
+    -- Get client
+    if awq[awq_name] then
+        c = awq[awq_name][awq_scr]
+    end
+    if c == nil then
+        awq_client_new()
+    else
+        if c.hidden then
+            awq_client_show(awq_name)
+        else
+            awq_client_hide(awq_name)
+        end
+        awq_tag = awful.tag.selected(awq_scr)
+    end
+end
+-- }}}
+
+-- {{{ Functions (“public”)
+function awqterm_toggle()
+    awq_scr = mouse.screen
+    if next(awq) == nil then
+        awq_client_new()
+    else
+        awq_client_toggle()
+    end
+end
+-- }}}
+
+-- vim: foldmethod=marker

+ 34 - 0
.config/awesome/helpers.lua

@@ -0,0 +1,34 @@
+-- {{{ License
+-- Awesome helpers
+-- 2012, Emmanuel Bouthenot <kolter@openics.org>
+--
+-- This file is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY
+--
+-- }}}
+
+-- {{{ Libraries
+-- Notification library
+require('naughty')
+-- User libraries
+require('utils')
+-- }}}
+
+-- {{{ Functions
+function whereis(program)
+    local fh = io.popen('which ' .. program)
+    path = string.trim(fh:read('*a'))
+    fh:close()
+    if path == "" then
+        path = nil
+    end
+    return path
+end
+
+function debug(message)
+    naughty.notify({ preset = naughty.config.presets.critical,
+        title = "Debug message", text = message})
+end
+-- }}}
+
+-- vim: foldmethod=marker

+ 130 - 48
.config/awesome/rc.lua

@@ -1,3 +1,13 @@
+-- {{{ License
+-- Awesome main config file
+-- 2012, Emmanuel Bouthenot <kolter@openics.org>
+--
+-- This file is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY
+--
+-- }}}
+
+-- {{{ Libraries
 -- Standard awesome library
 require("awful")
 require("awful.autofocus")
@@ -6,9 +16,15 @@ require("awful.rules")
 require("beautiful")
 -- Notification library
 require("naughty")
-
 -- Load Debian menu entries
 require("debian.menu")
+-- Misc tools
+require("wicked")
+require("vicious")
+-- User libraries
+require("helpers")
+require("awqterm")
+-- }}}
 
 -- {{{ Error handling
 -- Check if awesome encountered an error during startup and fell back to
@@ -40,9 +56,9 @@ end
 beautiful.init("/usr/share/awesome/themes/default/theme.lua")
 
 -- This is used later as the default terminal and editor to run.
-terminal = "x-terminal-emulator"
-editor = os.getenv("EDITOR") or "editor"
-editor_cmd = terminal .. " -e " .. editor
+terminal = whereis('xterm') or 'x-terminal-emulator'
+editor = os.getenv('EDITOR') or 'sensible-editor'
+editor_cmd = terminal .. ' -e ' .. editor
 
 -- Default modkey.
 -- Usually, Mod4 is the key with a logo between Control and Alt.
@@ -50,6 +66,7 @@ editor_cmd = terminal .. " -e " .. editor
 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
 -- However, you can use another modifier like Mod1, but it may interact with others.
 modkey = "Mod4"
+altkey = "Mod1"
 
 -- Table of layouts to cover with awful.layout.inc, order matters.
 layouts =
@@ -97,9 +114,50 @@ mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
                                      menu = mymainmenu })
 -- }}}
 
+-- {{{ Widgets
+
+-- {{{ CPU widget
+-- cpuwidget = awful.widget.graph({ layout = awful.widget.layout.horizontal.rightleft })
+-- cpuwidget:set_width(30)
+-- cpuwidget:set_height(19)
+-- cpuwidget:set_max_value(1)
+-- cpuwidget:set_background_color("#333333")
+-- cpuwidget:set_border_color("#0a0a0a")
+-- cpuwidget:set_color("#FF5656")
+-- cpuwidget:set_gradient_angle(50)
+-- cpuwidget:set_gradient_colors({ "#AEC6D8", "#285577", "#285577" })
+-- vicious.register(cpuwidget, vicious.widgets.cpu, "$1")
+-- }}}
+
+-- {{{ MEM widget
+-- memwidget = awful.widget.progressbar({ layout = awful.widget.layout.horizontal.rightleft })
+-- memwidget:set_width(15)
+-- memwidget:set_height(19)
+-- memwidget:set_vertical(true)
+-- memwidget:set_background_color("#333333")
+-- memwidget:set_border_color("#0a0a0a")
+-- memwidget:set_color("#FF5656")
+-- memwidget:set_gradient_colors({ "#AEC6D8", "#285577", "#285577" })
+-- vicious.register(memwidget, vicious.widgets.mem, "$1", 19)
+-- }}}
+
+-- {{{ VOL widget
+volwidget = widget({
+    align = right,
+    type = "textbox"
+})
+vicious.register(volwidget, vicious.widgets.volume, ' ♬:$1٪',  5, 'Master')
+-- }}}
+
+-- }}}
+
 -- {{{ Wibox
 -- Create a textclock widget
-mytextclock = awful.widget.textclock({ align = "right" })
+mytextclock = awful.widget.textclock(
+    { align = "right" },
+    "%a %d, %H:%M",
+    60
+)
 
 -- Create a systray
 mysystray = widget({ type = "systray" })
@@ -119,35 +177,36 @@ mytaglist.buttons = awful.util.table.join(
                     )
 mytasklist = {}
 mytasklist.buttons = awful.util.table.join(
-                     awful.button({ }, 1, function (c)
-                                              if c == client.focus then
-                                                  c.minimized = true
-                                              else
-                                                  if not c:isvisible() then
-                                                      awful.tag.viewonly(c:tags()[1])
-                                                  end
-                                                  -- This will also un-minimize
-                                                  -- the client, if needed
-                                                  client.focus = c
-                                                  c:raise()
-                                              end
-                                          end),
-                     awful.button({ }, 3, function ()
-                                              if instance then
-                                                  instance:hide()
-                                                  instance = nil
-                                              else
-                                                  instance = awful.menu.clients({ width=250 })
-                                              end
-                                          end),
-                     awful.button({ }, 4, function ()
-                                              awful.client.focus.byidx(1)
-                                              if client.focus then client.focus:raise() end
-                                          end),
-                     awful.button({ }, 5, function ()
-                                              awful.client.focus.byidx(-1)
-                                              if client.focus then client.focus:raise() end
-                                          end))
+    awful.button({ }, 1, function (c)
+        if c == client.focus then
+            c.minimized = true
+        else
+            if not c:isvisible() then
+                awful.tag.viewonly(c:tags()[1])
+            end
+            -- This will also un-minimize
+            -- the client, if needed
+            client.focus = c
+            c:raise()
+        end
+    end),
+    awful.button({ }, 3, function ()
+        if instance then
+            instance:hide()
+            instance = nil
+        else
+            instance = awful.menu.clients({ width=250 })
+        end
+    end),
+    awful.button({ }, 4, function ()
+        awful.client.focus.byidx(1)
+        if client.focus then client.focus:raise() end
+    end),
+    awful.button({ }, 5, function ()
+        awful.client.focus.byidx(-1)
+        if client.focus then client.focus:raise() end
+    end)
+)
 
 for s = 1, screen.count() do
     -- Create a promptbox for each screen
@@ -156,17 +215,18 @@ for s = 1, screen.count() do
     -- We need one layoutbox per screen.
     mylayoutbox[s] = awful.widget.layoutbox(s)
     mylayoutbox[s]:buttons(awful.util.table.join(
-                           awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
-                           awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
-                           awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
-                           awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
+        awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
+        awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
+        awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
+        awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)
+    ))
     -- Create a taglist widget
     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
 
     -- Create a tasklist widget
     mytasklist[s] = awful.widget.tasklist(function(c)
-                                              return awful.widget.tasklist.label.currenttags(c, s)
-                                          end, mytasklist.buttons)
+        return awful.widget.tasklist.label.currenttags(c, s)
+    end, mytasklist.buttons)
 
     -- Create the wibox
     mywibox[s] = awful.wibox({ position = "top", screen = s })
@@ -179,6 +239,7 @@ for s = 1, screen.count() do
             layout = awful.widget.layout.horizontal.leftright
         },
         mylayoutbox[s],
+        volwidget,
         mytextclock,
         s == 1 and mysystray or nil,
         mytasklist[s],
@@ -219,7 +280,7 @@ globalkeys = awful.util.table.join(
     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
-    awful.key({ modkey,           }, "Tab",
+    awful.key({ altkey,           }, "Tab",
         function ()
             awful.client.focus.history.previous()
             if client.focus then
@@ -252,9 +313,30 @@ globalkeys = awful.util.table.join(
                   mypromptbox[mouse.screen].widget,
                   awful.util.eval, nil,
                   awful.util.getdir("cache") .. "/history_eval")
-              end)
+              end),
+
+    -- Screensaver
+    awful.key({ altkey, "Control"}, "l", function () awful.util.spawn("xscreensaver-command -lock") end),
+    -- Dropdown terminal
+    awful.key({ altkey }, "space", function () awqterm_toggle() end)
 )
 
+-- Extend globalkeys
+for i = 1, table.getn(tags[mouse.screen]) do
+    globalkeys = awful.util.table.join(
+        globalkeys,
+        -- Ctrl Fx keys shows (goes to) tag X
+        awful.key({ "Control"}, 'F' .. i, function() awful.tag.viewonly(tags[mouse.screen][i]) end),
+        -- Shift Fx move focused application to tag X
+        awful.key({ "Control", "Shift" },  'F' .. i,
+            function ()
+                if client.focus and tags[client.focus.screen][i] then
+                    awful.client.movetotag(tags[client.focus.screen][i])
+                end
+         end)
+    )
+end
+
 clientkeys = awful.util.table.join(
     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
@@ -333,12 +415,10 @@ awful.rules.rules = {
                      focus = true,
                      keys = clientkeys,
                      buttons = clientbuttons } },
-    { rule = { class = "MPlayer" },
-      properties = { floating = true } },
-    { rule = { class = "pinentry" },
-      properties = { floating = true } },
-    { rule = { class = "gimp" },
-      properties = { floating = true } },
+    { rule = { class = "MPlayer" },  properties = { floating = true } },
+    { rule = { class = "pinentry" }, properties = { floating = true } },
+    { rule = { class = "gimp" },     properties = { floating = true } },
+    { rule = { class = "pidgin" },     properties = { floating = true } },
     -- Set Firefox to always map on tags number 2 of screen 1.
     -- { rule = { class = "Firefox" },
     --   properties = { tag = tags[1][2] } },
@@ -376,3 +456,5 @@ client.add_signal("focus", function(c) c.border_color = beautiful.border_focus e
 client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
 -- }}}
 
+
+-- vim: foldmethod=marker

+ 47 - 0
.config/awesome/utils.lua

@@ -0,0 +1,47 @@
+-- {{{ License
+-- Awesome utils functions
+-- 2012, Emmanuel Bouthenot <kolter@openics.org>
+--
+-- This file is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY
+--
+-- }}}
+
+-- {{{ Functions
+function table.pos(t, k)
+    local ret = nil
+    for i,n in ipairs(t) do
+        if n == k then
+            ret = i
+            break
+        end
+    end
+    return ret
+end
+
+function table.keypos(t, p)
+    local ret
+    for i,n in ipairs(t) do
+        if i == p then
+            ret = n
+            break
+        end
+    end
+    return ret
+end
+
+function table.keyfirst(t)
+    return table.keypos(t, 1)
+end
+
+function table.keylast(t)
+    return table.keypos(t, table.getn(t))
+end
+
+function string.trim(s)
+    -- from http://lua-users.org/wiki/StringTrim
+    return (s:gsub("^%s*(.-)%s*$", "%1"))
+end
+-- }}}
+
+-- vim: foldmethod=marker