mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-07-09 17:54:22 +02:00
bindings: switch "jump to urgent" to "toggle pidgin conversation"
Moreover, we define a more generic function to toggle a window that can be used for windows with urgency hint or for any group of windows. The undo stack will skip windows that cannnot be restored yet (not visible) and will be cleaned up if it becomes too large.
This commit is contained in:
parent
3669b73aaa
commit
a2a3a19e54
1 changed files with 65 additions and 45 deletions
|
@ -16,29 +16,31 @@ local function screenshot(client)
|
||||||
awful.util.spawn("import -window " .. client .. " " .. path, false)
|
awful.util.spawn("import -window " .. client .. " " .. path, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Pull the first window with urgent flag in the current workspace if
|
|
||||||
-- not displayed. If displayed, just raise it. If no urgent window,
|
-- Function to toggle a given window to the currently selected and
|
||||||
-- push back the previous urgent window to its original tag
|
-- focused tag. We need a filter. This function can be used to focus a
|
||||||
local urgent_undo_stack = {}
|
-- particular window. When the filter is unable to select something,
|
||||||
local function pull_urgent()
|
-- we undo previous actions (hence "toggle"). This function returns a
|
||||||
local cl = awful.client.urgent.get()
|
-- function that will effectively toggle things.
|
||||||
|
local function toggle_window(filter)
|
||||||
|
local undo = {} -- undo stack
|
||||||
|
local toggle = function()
|
||||||
|
-- "Current" screen
|
||||||
local s = client.focus and client.focus.screen or mouse.screen
|
local s = client.focus and client.focus.screen or mouse.screen
|
||||||
if cl then
|
local cl = filter() -- Client to toggle
|
||||||
|
if cl and client.focus ~= cl then
|
||||||
-- So, we have a client.
|
-- So, we have a client.
|
||||||
if not cl:isvisible() then
|
if not cl:isvisible() then
|
||||||
-- But it is not visible. So we will add it to the current
|
-- But it is not visible. So we will add it to the current
|
||||||
-- tag of the current screen.
|
-- tag of the current screen.
|
||||||
local t = awful.tag.selected(s)
|
local t = assert(awful.tag.selected(s))
|
||||||
if not t then
|
|
||||||
return awful.client.urgent.jumpto()
|
|
||||||
end
|
|
||||||
-- Before adding the tag to the client, we should ensure it
|
-- Before adding the tag to the client, we should ensure it
|
||||||
-- is on the same screen.
|
-- is on the same screen.
|
||||||
if s ~= cl.screen then
|
if s ~= cl.screen then
|
||||||
sharetags.tag_move(cl:tags()[1], s)
|
sharetags.tag_move(cl:tags()[1], s)
|
||||||
end
|
end
|
||||||
-- Add our tag to the client
|
-- Add our tag to the client
|
||||||
urgent_undo_stack[#urgent_undo_stack + 1] = { cl, t }
|
undo[#undo + 1] = { cl, t }
|
||||||
awful.client.toggletag(t, cl)
|
awful.client.toggletag(t, cl)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -51,21 +53,39 @@ local function pull_urgent()
|
||||||
else
|
else
|
||||||
-- OK, we need to restore the previously pushed window to its
|
-- OK, we need to restore the previously pushed window to its
|
||||||
-- original state.
|
-- original state.
|
||||||
while #urgent_undo_stack > 0 do
|
local i = #undo
|
||||||
local cl, t = unpack(table.remove(urgent_undo_stack,
|
while i > 0 do
|
||||||
#urgent_undo_stack))
|
local cl, t = unpack(undo[i])
|
||||||
-- We only handle visible clients that are attached to the
|
-- We only handle visible clients that are attached to the
|
||||||
-- appropriate tag. Otherwise, the client is discarded (and
|
-- appropriate tag. Otherwise, we try the next one.
|
||||||
-- won't be restored later).
|
|
||||||
if cl and cl:isvisible() and
|
if cl and cl:isvisible() and
|
||||||
awful.util.table.hasitem(cl:tags(), t) then
|
awful.util.table.hasitem(cl:tags(), t) then
|
||||||
awful.client.toggletag(t, cl)
|
awful.client.toggletag(t, cl)
|
||||||
|
table.remove(undo, i)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
-- Clean up...
|
||||||
|
while #undo > 10 do
|
||||||
|
table.remove(undo, 1)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return toggle
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Toggle pidgin conversation window
|
||||||
|
local toggle_pidgin = toggle_window(
|
||||||
|
function ()
|
||||||
|
return awful.client.cycle(function(c)
|
||||||
|
return awful.rules.match(c, { class = "Pidgin",
|
||||||
|
role = "conversation" })
|
||||||
|
end)()
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Toggle urgent window
|
||||||
|
local toggle_urgent = toggle_window(awful.client.urgent.get)
|
||||||
|
|
||||||
config.keys.global = awful.util.table.join(
|
config.keys.global = awful.util.table.join(
|
||||||
keydoc.group("Focus"),
|
keydoc.group("Focus"),
|
||||||
awful.key({ modkey, }, "j",
|
awful.key({ modkey, }, "j",
|
||||||
|
@ -88,8 +108,8 @@ config.keys.global = awful.util.table.join(
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
"Focus previously focused window"),
|
"Focus previously focused window"),
|
||||||
awful.key({ modkey, }, "u", pull_urgent,
|
awful.key({ modkey, }, "u", toggle_pidgin,
|
||||||
"Jump to urgent-flagged window"),
|
"Toggle Pidgin conversation window"),
|
||||||
awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end,
|
awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end,
|
||||||
"Jump to next screen"),
|
"Jump to next screen"),
|
||||||
awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
|
awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue