From 2e2b6a3112c2aaecbab8d42ed07f0fa5423e4430 Mon Sep 17 00:00:00 2001 From: Leon Winter Date: Mon, 18 Aug 2008 10:39:34 +0200 Subject: [PATCH] awful: add urgent client fast switching Signed-off-by: Julien Danjou --- awesome.1.txt | 2 ++ awesomerc.lua.in | 1 + lib/awful.lua.in | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/awesome.1.txt b/awesome.1.txt index 59c853c75..1d247951a 100644 --- a/awesome.1.txt +++ b/awesome.1.txt @@ -96,6 +96,8 @@ Navigation. Focus next client. *Mod4 \+ k*:: Focus previous client. +*Mod4 \+ u*:: + Focus first urgent client. *Mod4 \+ Left*:: View previous tag. *Mod4 \+ Right*:: diff --git a/awesomerc.lua.in b/awesomerc.lua.in index 2b7554f78..ca0fb8efd 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -224,6 +224,7 @@ keybinding({ modkey, "Control" }, "space", awful.client.togglefloating):add() keybinding({ modkey, "Control" }, "Return", function () client.focus:swap(awful.client.master()) end):add() keybinding({ modkey }, "o", awful.client.movetoscreen):add() keybinding({ modkey }, "Tab", awful.client.focus.history.previous):add() +keybinding({ modkey }, "u", awful.client.urgent.jumpto):add() -- Layout manipulation keybinding({ modkey }, "l", function () awful.tag.incmwfact(0.05) end):add() diff --git a/lib/awful.lua.in b/lib/awful.lua.in index 9ac188a36..99d8e8dbb 100644 --- a/lib/awful.lua.in +++ b/lib/awful.lua.in @@ -62,6 +62,9 @@ widget.taglist = {} widget.taglist.label = {} widget.tasklist = {} widget.tasklist.label = {} +client.urgent = {} +client.urgent.stack = {} +client.urgent.stack.data = {} --- Make i cycle. -- @param t A length. @@ -73,6 +76,56 @@ local function cycle(t, i) return i end +--- Get the first client that got the urgent hint. +-- @return The first urgent client. +function client.urgent.get() + if #client.urgent.stack.data > 0 then + return client.urgent.stack.data[1] + else + -- fallback behaviour: iterate through clients and get the first urgent + local clients = capi.client.get() + for k, cl in pairs(clients) do + if cl.urgent then + return cl + end + end + end +end + +--- Jump to the client that received the urgent hint first. +function client.urgent.jumpto() + local c = client.urgent.get() + if c then + local s = capi.client.focus and capi.client.focus.screen or capi.mouse.screen + -- focus the screen + if s ~= c.screen then + capi.mouse.screen = c.screen + end + -- focus the tag + tag.viewonly(c:tags()[1]) + -- focus the client + capi.client.focus = c + c:raise() + end +end + +--- Adds client to urgent stack. +-- @param The client object. +function client.urgent.stack.add(c) + table.insert(client.urgent.stack.data, c) +end + +--- Remove client from urgent stack. +-- @param The client object. +function client.urgent.stack.delete(c) + for k, cl in ipairs(client.urgent.stack.data) do + if c == cl then + table.remove(client.urgent.stack.data, k) + break + end + end +end + --- Remove a client from the focus history -- @param c The client that must be removed. function client.focus.history.delete(c) @@ -1421,4 +1474,8 @@ hooks.unfocus.register(titlebar.update) hooks.titleupdate.register(titlebar.update) hooks.unmanage.register(titlebar.remove) +hooks.urgent.register(client.urgent.stack.add) +hooks.focus.register(client.urgent.stack.delete) +hooks.unmanage.register(client.urgent.stack.delete) + -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80