refactor(hypr): fix float toggle sizing, improve window cycling, update terminal-pi rule
- Fix toggle_float_with_limit to use correct property names (width/height vs size.width) - Add notification on float toggle showing scale factor - Resize to max bounds instead of scaling - Move function definition after keybinds for better organization - Add cycle_next_window wrapper to bring floating windows to top on cycle - Update terminal-pi window rule to float/center/special workspace
This commit is contained in:
+56
-34
@@ -319,36 +319,6 @@ function toggle_master()
|
|||||||
hl.dispatch(hl.dsp.layout("mfact exact " .. mfact))
|
hl.dispatch(hl.dsp.layout("mfact exact " .. mfact))
|
||||||
end
|
end
|
||||||
|
|
||||||
function toggle_float_with_limit()
|
|
||||||
local win = hl.get_active_window()
|
|
||||||
if win == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local was_floating = win.floating
|
|
||||||
hl.dispatch(hl.dsp.window.float({ action = "toggle" }))
|
|
||||||
if was_floating then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
win = hl.get_active_window()
|
|
||||||
local mon = win and win.monitor and hl.get_monitor(win.monitor) or hl.get_active_monitor()
|
|
||||||
if mon == nil or mon.size == nil or win == nil or win.size == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local max_width = math.floor(mon.size.width * 0.8)
|
|
||||||
local max_height = math.floor(mon.size.height * 0.8)
|
|
||||||
local scale = math.min(1, max_width / win.size.width, max_height / win.size.height)
|
|
||||||
if scale < 1 then
|
|
||||||
hl.dispatch(hl.dsp.window.resize({
|
|
||||||
x = math.floor(win.size.width * scale),
|
|
||||||
y = math.floor(win.size.height * scale),
|
|
||||||
relative = false,
|
|
||||||
}))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
hl.bind(LEADER .. "SHIFT + return", hl.dsp.exec_cmd("gtk-launch herdr.desktop"), { description = "Open herdr terminal" })
|
hl.bind(LEADER .. "SHIFT + return", hl.dsp.exec_cmd("gtk-launch herdr.desktop"), { description = "Open herdr terminal" })
|
||||||
hl.bind(LEADER .. "return", hl.dsp.exec_cmd("gtk-launch tmux.desktop"), { description = "Open tmux terminal" })
|
hl.bind(LEADER .. "return", hl.dsp.exec_cmd("gtk-launch tmux.desktop"), { description = "Open tmux terminal" })
|
||||||
hl.bind(LEADER .. "N", hl.dsp.exec_cmd(terminal .. " -a quicknotes -e nvim +'Obsidian today'"),
|
hl.bind(LEADER .. "N", hl.dsp.exec_cmd(terminal .. " -a quicknotes -e nvim +'Obsidian today'"),
|
||||||
@@ -464,6 +434,43 @@ hl.bind(LEADER .. "CTRL + F", hl.dsp.window.fullscreen_state({ internal = 2, cli
|
|||||||
hl.bind(LEADER .. "ALT + F", hl.dsp.window.fullscreen_state({ internal = 0, client = 2, action = "toggle" }),
|
hl.bind(LEADER .. "ALT + F", hl.dsp.window.fullscreen_state({ internal = 0, client = 2, action = "toggle" }),
|
||||||
{ description = "Window: Toggle fullscreen state 2" })
|
{ description = "Window: Toggle fullscreen state 2" })
|
||||||
|
|
||||||
|
function toggle_float_with_limit()
|
||||||
|
local win = hl.get_active_window()
|
||||||
|
if win == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local was_floating = win.floating
|
||||||
|
hl.dispatch(hl.dsp.window.float({ action = "toggle" }))
|
||||||
|
if was_floating then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local mon = win.monitor and hl.get_monitor(win.monitor) or hl.get_active_monitor()
|
||||||
|
if mon == nil or mon.size == nil or win == nil or win.size == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local max_width = math.floor(mon.width * 0.8)
|
||||||
|
local max_height = math.floor(mon.height * 0.8)
|
||||||
|
local scale = math.max(1, win.size.x / max_width, win.size.y / max_height)
|
||||||
|
hl.notification.create({
|
||||||
|
text = "Scale " ..
|
||||||
|
scale .. " Max float size: " .. win.size.x / max_width .. "x" .. win.size.y / max_height,
|
||||||
|
duration = 2000,
|
||||||
|
icon =
|
||||||
|
"hint"
|
||||||
|
})
|
||||||
|
if scale > 1 then
|
||||||
|
hl.dispatch(hl.dsp.window.resize({
|
||||||
|
x = math.floor(max_width),
|
||||||
|
y = math.floor(max_height),
|
||||||
|
relative = false,
|
||||||
|
window = win
|
||||||
|
}))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
hl.bind(LEADER .. "T", toggle_float_with_limit,
|
hl.bind(LEADER .. "T", toggle_float_with_limit,
|
||||||
{ description = "Window: Toggle floating/tiling (max 80%)" })
|
{ description = "Window: Toggle floating/tiling (max 80%)" })
|
||||||
|
|
||||||
@@ -491,8 +498,20 @@ hl.bind(LEADER .. "ALT + comma", function()
|
|||||||
hl.dispatch(hl.dsp.layout("cyclenext"))
|
hl.dispatch(hl.dsp.layout("cyclenext"))
|
||||||
end, { description = "Window: Swap with prev" })
|
end, { description = "Window: Swap with prev" })
|
||||||
|
|
||||||
hl.bind("ALT + Tab", hl.dsp.window.cycle_next(), { description = "Window: Cycle next" })
|
function cycle_next_window(opts)
|
||||||
hl.bind("ALT + SHIFT + Tab", hl.dsp.window.cycle_next({ next = false }), { description = "Window: Cycle prev" })
|
return function()
|
||||||
|
hl.dispatch(hl.dsp.window.cycle_next(opts))
|
||||||
|
|
||||||
|
local win = hl.get_active_window()
|
||||||
|
if win and win.floating then
|
||||||
|
hl.dispatch(hl.dsp.window.alter_zorder({ mode = "top" }))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
hl.bind("ALT + Tab", cycle_next_window({ next = true }), { description = "Window: Cycle next" })
|
||||||
|
hl.bind("ALT + SHIFT + Tab", cycle_next_window({ next = false }), { description = "Window: Cycle prev" })
|
||||||
|
|
||||||
hl.bind(LEADER .. "ALT + Tab", hl.dsp.focus({ workspace = "previous", on_current_monitor = true }),
|
hl.bind(LEADER .. "ALT + Tab", hl.dsp.focus({ workspace = "previous", on_current_monitor = true }),
|
||||||
{ description = "Window: Focus previous in workspace" })
|
{ description = "Window: Focus previous in workspace" })
|
||||||
|
|
||||||
@@ -685,8 +704,11 @@ hl.window_rule({
|
|||||||
})
|
})
|
||||||
|
|
||||||
hl.window_rule({
|
hl.window_rule({
|
||||||
match = { class = "terminal-pi" },
|
match = { class = "terminal-pi" },
|
||||||
tag = "+floating-window"
|
float = true,
|
||||||
|
center = true,
|
||||||
|
workspace = "special:special",
|
||||||
|
size = { "monitor_w/2", "monitor_h/2" }
|
||||||
})
|
})
|
||||||
|
|
||||||
hl.window_rule({
|
hl.window_rule({
|
||||||
|
|||||||
Reference in New Issue
Block a user