From 320ac68fb76d680f472ae53cd2700e74b3355dc3 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 8 Sep 2008 00:09:50 +0200 Subject: [PATCH] awful: filter focus by type Signed-off-by: Julien Danjou --- awesomerc.lua.in | 6 ++++-- lib/awful.lua.in | 32 +++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/awesomerc.lua.in b/awesomerc.lua.in index 268d77e4..57514657 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -359,7 +359,8 @@ end) -- Hook function to execute when the mouse is over a client. awful.hooks.mouse_over.register(function (c) -- Sloppy focus, but disabled for magnifier layout - if awful.layout.get(c.screen) ~= "magnifier" then + if awful.layout.get(c.screen) ~= "magnifier" + and awful.client.focus.filter(c) then client.focus = c end end) @@ -422,7 +423,8 @@ awful.hooks.arrange.register(function (screen) mylayoutbox[screen].text = "No layout." end - -- If no window has focus, give focus to the latest in history + -- Give focus to the latest client in history if no window has focus + -- or if the current window is a desktop or a dock one. if not client.focus then local c = awful.client.focus.history.get(screen, 0) if c then client.focus = c end diff --git a/lib/awful.lua.in b/lib/awful.lua.in index eae7b633..2bcff936 100644 --- a/lib/awful.lua.in +++ b/lib/awful.lua.in @@ -161,13 +161,29 @@ function client.focus.history.delete(c) end end +--- Filter out window that we do not want handled by focus. +-- This usually means that desktop, dock and splash windows are +-- not registered and cannot get focus. +-- @param c A client. +-- @return The same client if it's ok, nil otherwise. +function client.focus.filter(c) + if c.type == "desktop" + or c.type == "dock" + or c.type == "splash" then + return nil + end + return c +end + --- Update client focus history. -- @param c The client that has been focused. function client.focus.history.add(c) - -- Remove the client if its in stack - client.focus.history.delete(c) - -- Record the client has latest focused - table.insert(client.focus.history.data, 1, c) + if client.focus.filter(c) then + -- Remove the client if its in stack + client.focus.history.delete(c) + -- Record the client has latest focused + table.insert(client.focus.history.data, 1, c) + end end --- Get the latest focused client for a screen in history. @@ -223,11 +239,17 @@ function client.next(i, c) if sel then -- Get all visible clients local cls = capi.client.visible_get(sel.screen) + -- Remove all no-normal clients + for idx, c in ipairs(cls) do + if not client.focus.filter(c) then + table.remove(cls, idx) + end + end -- Loop upon each client for idx, c in ipairs(cls) do if c == sel then -- Cycle - return cls[cycle(#cls, idx +i)] + return cls[cycle(#cls, idx + i)] end end end