Hi people,

after being inspired by Knirch on #awesome, I wrote a patch to
awful.client which implemented client annotations. These are little
strings stored in a table with clients as the keys. Once a client gets
focused, naughty is used to display the string associated with that
client. I added a prompt to the default rc.lua which can be used to
change the annotation of the focused client. The relevant functions are:

    awful.client.annotation.get(c)
        Returns the annotation of client c or the focused client if c is
        nil. Returns nil if no annotation is set.

    awful.client.annotation.set(msg, c)
        Sets the annotation of client c or the focused client to msg

    awful.client.annotation.display(c)
        A convenience function which uses naughty to display the
        annotation of client c or the focused client. Is a No-Op if
        the client doesn't have an annotation.

-- 
GCS/IT/M d- s+:- a-- C++ UL+++ US UB++ P+++ L+++ E--- W+ N+ o--
K- w--- ?O M-- ?V PS++ PE- Y++ PGP+++ t+ 5 X+ R tv b+++ DI+++
D+++ G+ e h! r y+

    Gregor Best
From 449d27d541db5b6c81b7d5486a60ab12652cfe4a Mon Sep 17 00:00:00 2001
From: Gregor Best <[email protected]>
Date: Tue, 18 Aug 2009 15:51:53 +0200
Subject: [PATCH] awful.client: add client annotation support

Signed-off-by: Gregor Best <[email protected]>
---
 awesomerc.lua.in        |   22 ++++++++++++++++------
 lib/awful/client.lua.in |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/awesomerc.lua.in b/awesomerc.lua.in
index 459f50b..b0c1a74 100644
--- a/awesomerc.lua.in
+++ b/awesomerc.lua.in
@@ -251,17 +251,27 @@ globalkeys = awful.util.table.join(
                   mypromptbox[mouse.screen].widget,
                   awful.util.eval, nil,
                   awful.util.getdir("cache") .. "/history_eval")
+              end),
+
+    -- Client annotation prompt
+    awful.key({ modkey }, "n",
+              function ()
+                  awful.prompt.run({ prompt = "Annotate current client: " },
+                  mypromptbox[mouse.screen].widget,
+                  awful.client.annotation.set, nil,
+                  awful.util.getdir("cache") .. "/history_annotate")
               end)
 )
 
 -- Client awful tagging: this is useful to tag some clients and then do stuff 
like move to tag on them
 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),
-    awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle    
                 ),
-    awful.key({ modkey, "Control" }, "Return", function (c) 
c:swap(awful.client.getmaster()) end),
-    awful.key({ modkey,           }, "o",      awful.client.movetoscreen       
                 ),
-    awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()         
              end),
+    awful.key({ modkey, "Shift"   }, "n",      function (c) 
awful.client.annotation.display(c) end),
+    awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not 
c.fullscreen    end),
+    awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()           
                end),
+    awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle    
                   ),
+    awful.key({ modkey, "Control" }, "Return", function (c) 
c:swap(awful.client.getmaster())   end),
+    awful.key({ modkey,           }, "o",      awful.client.movetoscreen       
                   ),
+    awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()         
                end),
     awful.key({ modkey,}, "m",
         function (c)
             c.maximized_horizontal = not c.maximized_horizontal
diff --git a/lib/awful/client.lua.in b/lib/awful/client.lua.in
index 4f97f9e..c1aab7b 100644
--- a/lib/awful/client.lua.in
+++ b/lib/awful/client.lua.in
@@ -7,6 +7,7 @@
 -- Grab environment we need
 local util = require("awful.util")
 local tag = require("awful.tag")
+local naughty = require("naughty")
 local pairs = pairs
 local type = type
 local ipairs = ipairs
@@ -31,6 +32,7 @@ data = {}
 data.focus = {}
 data.urgent = {}
 data.marked = {}
+data.annotation = setmetatable({}, { __mode = 'k' })
 data.properties = setmetatable({}, { __mode = 'k' })
 
 -- Functions
@@ -41,6 +43,7 @@ swap = {}
 floating = {}
 dockable = {}
 property = {}
+annotation = {}
 
 -- User hooks
 hooks.user.create('marked')
@@ -829,6 +832,33 @@ function property.set(c, prop, value)
     hooks.user.call("property", c, prop)
 end
 
+--- Get a clients annotation
+-- This function returns a clients annotation, or nil if the client is not
+-- annotated
+-- @param c The client. If ommitted, client.focus is assumed
+-- @return The annotation
+function annotation.get(c)
+    c = c or capi.client.focus
+    return data.annotation[c]
+end
+
+--- Set a clients annotation
+-- This function sets the annotation for a given client
+-- @param msg The annotation to set
+-- @param c The client to be annotated, or client.focus if ommitted
+function annotation.set(msg, c)
+    data.annotation[c or capi.client.focus] = msg
+end
+
+--- Print a clients annotation using naughty
+-- This function uses naughty to print the clients annotation
+-- @param c The client, or client.focus if ommitted
+function annotation.display(c)
+    c = c or capi.client.focus
+    if not data.annotation[c] then return end
+    naughty.notify({ text = data.annotation[c], screen = c.screen })
+end
+
 -- Register standards hooks
 hooks.focus.register(focus.history.add)
 hooks.unmanage.register(focus.history.delete)
@@ -839,4 +869,6 @@ hooks.unmanage.register(urgent.delete)
 
 hooks.unmanage.register(floating.delete)
 
+hooks.focus.register(annotation.display)
+
 -- vim: 
filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
-- 
1.6.4

Attachment: pgpNGHUy1tGib.pgp
Description: PGP signature

Reply via email to