mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-06-25 03:08:34 +02:00
bindings: enhance the way the Pidgin conversation window is selected
There is now some cycle stuff. This is still not perfect since it will bring some random window. It would be better to be able to choose the appropriate one.
This commit is contained in:
parent
8bce8a5528
commit
b6f1ee8646
1 changed files with 42 additions and 29 deletions
|
@ -80,36 +80,49 @@ end
|
||||||
|
|
||||||
-- Toggle pidgin conversation window
|
-- Toggle pidgin conversation window
|
||||||
local toggle_pidgin = toggle_window(
|
local toggle_pidgin = toggle_window(
|
||||||
function ()
|
(function ()
|
||||||
local cls = client.get()
|
local adding = true
|
||||||
local focus = client.focus
|
local choose = function()
|
||||||
local rule = { class = "Pidgin",
|
local cls = client.get()
|
||||||
role = "conversation" }
|
local focus = client.focus
|
||||||
-- Score. We want a Pidgin window. Then:
|
local rule = { class = "Pidgin",
|
||||||
-- 1. Urgent, visible, not focused
|
role = "conversation" }
|
||||||
-- 2. Urgent, not visible, not focused.
|
-- Score. We want a Pidgin window. Then:
|
||||||
-- 3. Not urgent, not visible, not focused
|
-- 1. Urgent, visible, not focused
|
||||||
-- 4. Focused
|
-- 2. Urgent, not visible, not focused.
|
||||||
-- 5. Visible, not focused
|
-- 3. Not urgent, not visible, not focused
|
||||||
local function score(cl)
|
-- 4. Focused
|
||||||
if not awful.rules.match(cl, rule) then return -10 end
|
-- 5. Visible, not focused
|
||||||
|
local function score(cl)
|
||||||
|
if not awful.rules.match(cl, rule) then return -10 end
|
||||||
|
|
||||||
local urgent = cl.urgent
|
local urgent = cl.urgent
|
||||||
local focused = (focus == cl)
|
local focused = (focus == cl)
|
||||||
local visible = cl:isvisible()
|
local visible = cl:isvisible()
|
||||||
if urgent and visible and not focused then return 100 end
|
if urgent and visible and not focused then return 100 end
|
||||||
if urgent and not visible and not focused then return 90 end
|
if urgent and not visible and not focused then return 90 end
|
||||||
if not urgent and not visible then return 80 end
|
if not adding and focused then return 80 end
|
||||||
if focused then return 50 end
|
if adding and not urgent and not visible then return 70 end
|
||||||
return 10
|
if focused then return 50 end
|
||||||
end
|
if not urgent and not visible then return 40 end
|
||||||
table.sort(cls, function(c1, c2)
|
return 10
|
||||||
local s1 = score(c1)
|
end
|
||||||
local s2 = score(c2)
|
table.sort(cls, function(c1, c2)
|
||||||
return s1 > s2
|
local s1 = score(c1)
|
||||||
end)
|
local s2 = score(c2)
|
||||||
if awful.rules.match(cls[1], rule) then return cls[1] end
|
return s1 > s2
|
||||||
end)
|
end)
|
||||||
|
local candidate = cls[1]
|
||||||
|
if candidate == nil or not awful.rules.match(candidate, rule) then return nil end
|
||||||
|
|
||||||
|
-- Maybe we need to switch direction
|
||||||
|
if candidate == focus and adding then adding = false
|
||||||
|
elseif candidate ~= focus and not adding then adding = true end
|
||||||
|
|
||||||
|
return candidate
|
||||||
|
end
|
||||||
|
return choose
|
||||||
|
end)())
|
||||||
|
|
||||||
-- Toggle urgent window
|
-- Toggle urgent window
|
||||||
local toggle_urgent = toggle_window(awful.client.urgent.get)
|
local toggle_urgent = toggle_window(awful.client.urgent.get)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue