ActiveWindow selector or something similar for the send_shortcut dispatcher #14381
-
|
I'm facing issues when trying to make a shortcut that only works for the current active application if it is a specific window. I have a keypad that I want to use as undo/redo buttons for xournalpp. But only when it is the current active window, in every other case I want it to behave as the original button, in particular I want to use the keypad buttons as binds for a game(osu!). I don't want to use non_consuming since this will cause diff. issues. FYI the buttons are mapped to f13 and f14. I already tried to use a lua function with varying degrees of success. Well, now I tried multiple things and couldn't get it to work in a satisfactory manner. As the auto_consuming preserves the state of the button presses normally if the dispatcher "fails", I would like to ask if we could get an activewindow regex that allows us to check if the window is currently active, and if not, fails so that auto_consuming will pass the key presses. Trying to use an arbitrary class name that does not exist, the auto_consuming behavior would work as expected. Is it possible to return a dispatch failure manually with a lua function? These are the code segments of some of my tries: hl.bind("F13",
hl.dsp.send_shortcut({
mods = "CTRL",
key = "Z",
window = "class:^(arbitrary-non-existing-class)$",
}),
{ auto_consuming = true } -- send_shortcut fails and triggers normal key-presses
)This was my lua function try hl.bind("F13",
function()
local activeWindow = hl.get_active_window()
if activeWindow ~= nil then
if activeWindow.class == "com.github.xournalpp.xournalpp" then
hl.dispatch(hl.dsp.send_shortcut(
{
mods = "CTRL",
key = "Z",
window = "class:^(com.github.xournalpp.xournalpp)$",
})
)
else
hl.dispatch(hl.dsp.pass({ window = string.format("class:^(%s)$", activeWindow.class) }))
-- return -1 / return nil / return false
end
else
return
end
end,
{ auto_consuming = true }
)Would having a "activewindow:^(class.name)$" and failing the dispatch if it is not the curr active window be a good idea? I would appreciate any feedback or direction, and hey, maybe there is already some way to achieve that, which I did not consider. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
This method create the keybind when the window is active and removes when its not local xournal_binds_active = false
local function apply_xournal_binds()
if not xournal_binds_active then
hl.bind("F13", hl.dsp.send_shortcut({
mods = "CTRL",
key = "Z",
window = "class:^(com.github.xournalpp.xournalpp)$"
}))
hl.bind("F14", hl.dsp.send_shortcut({
mods = "CTRL",
key = "Y",
window = "class:^(com.github.xournalpp.xournalpp)$"
}))
xournal_binds_active = true
end
end
local function remove_xournal_binds()
if xournal_binds_active then
hl.exec_cmd("hyprctl keyword unbind , F13")
hl.exec_cmd("hyprctl keyword unbind , F14")
xournal_binds_active = false
end
end
-- Listen for window focus changes
hl.on("window.active", function(w)
if w ~= nil and w.class == "com.github.xournalpp.xournalpp" then
apply_xournal_binds()
else
remove_xournal_binds()
end
end) |
Beta Was this translation helpful? Give feedback.
This method create the keybind when the window is active and removes when its not