Files
dotfiles/.config/hypr/workspaces.lua
T

134 lines
4.1 KiB
Lua
Raw Normal View History

2026-06-08 18:28:10 +01:00
local workspace_map = {
2026-08-16 12:36:11 +01:00
'Home',
'Dev',
'Art',
'Gaming',
'Writing',
2026-06-08 18:28:10 +01:00
}
2026-06-07 19:03:11 +01:00
2026-06-27 17:04:05 +01:00
local function setup_monitors()
2026-09-02 14:30:16 +01:00
toggle_laptop_monitor()
2026-06-27 17:04:05 +01:00
local monitors = hl.get_monitors()
local monitor_count = #monitors
2026-06-27 12:51:49 +01:00
2026-06-28 22:45:03 +01:00
for i = 1, #workspace_map do
2026-06-27 17:04:05 +01:00
for j = monitor_count, 1, -1 do
local monitor = monitors[j]
2026-08-16 12:36:11 +01:00
local workspace_name = workspace_map[i] .. '_' .. j
hl.workspace_rule {
workspace = 'name:' .. workspace_name,
2026-06-27 17:04:05 +01:00
monitor = monitor.name,
2026-06-27 19:38:20 +01:00
default = i == 1,
2026-08-16 12:36:11 +01:00
}
2026-06-27 17:04:05 +01:00
2026-09-29 17:15:31 +01:00
-- Move to a workspace with SUPER + [1-5]
2026-06-28 20:26:30 +01:00
hl.bind(
2026-08-16 12:36:11 +01:00
'SUPER + code:1' .. (i - 1),
hl.dsp.focus { workspace = 'name:' .. workspace_name },
{ description = 'Switch to workspace ' .. workspace_map[i] }
2026-06-27 17:04:05 +01:00
)
end
2026-09-29 17:15:31 +01:00
-- Move active window to a workspace with SUPER + SHIFT + [1-5]
2026-08-16 12:36:11 +01:00
hl.bind('SUPER + SHIFT + code:1' .. (i - 1), function()
2026-09-27 17:06:16 +01:00
notify('Moving', 2000)
2026-06-28 22:45:03 +01:00
local active_window = hl.get_active_window()
2026-09-27 17:06:16 +01:00
if active_window then
local active_workspace = active_window.workspace
if active_workspace then
local active_workspace_name = active_workspace.name
local monitor_suffix = active_workspace_name:match '_(%d+)$'
or '1'
local new_workspace = 'name:'
.. workspace_map[i]
.. '_'
.. monitor_suffix
hl.dispatch(hl.dsp.window.move {
workspace = new_workspace,
window = active_window,
follow = false,
})
end
end
end, {
description = 'Move window to workspace ' .. workspace_map[i],
})
2026-06-28 20:26:30 +01:00
end
2026-09-29 17:15:31 +01:00
-- When removing a monitor move all windows to existing monitors
local windows = hl.get_windows()
for i = 1, #windows do
local window = windows[i]
if window and window.workspace then
local workspace_name = window.workspace.name
local monitor_suffix = workspace_name:match '_(%d+)$' or '0'
if tonumber(monitor_suffix) > monitor_count then
local new_workspace = 'name:'
.. workspace_name:match '^%w+'
.. '_1'
hl.dispatch(hl.dsp.window.move {
workspace = new_workspace,
window = window,
follow = false,
})
end
end
end
2026-06-07 19:32:56 +01:00
end
2026-06-27 17:04:05 +01:00
2026-08-16 12:36:11 +01:00
hl.on('monitor.added', setup_monitors)
hl.on('monitor.removed', setup_monitors)
hl.on('config.reloaded', setup_monitors)
2026-09-02 14:30:16 +01:00
hl.bind('switch:off:Lid Switch', setup_monitors)
hl.bind('switch:on:Lid Switch', setup_monitors)
2026-08-16 12:36:11 +01:00
2026-09-30 17:03:12 +01:00
local function set_laptop_workspaces_to_monocle()
local workspaces = hl.get_workspaces()
2026-08-16 12:36:11 +01:00
2026-09-30 17:03:12 +01:00
for i = 1, #workspaces do
local workspace = workspaces[i]
if
2026-09-30 17:25:03 +01:00
not workspace.special
and workspace.monitor
2026-09-30 17:03:12 +01:00
and workspace.monitor.description == LAPTOP_MONITOR_NAME
then
hl.workspace_rule {
workspace = 'name:' .. tostring(workspace.name),
layout = 'monocle',
}
end
2026-08-17 19:41:51 +01:00
end
2026-09-02 14:30:16 +01:00
end
2026-08-17 19:41:51 +01:00
2026-09-30 17:03:12 +01:00
hl.on('monitor.focused', set_laptop_workspaces_to_monocle)
2026-08-16 16:42:16 +01:00
2026-09-30 17:03:12 +01:00
hl.on('config.reloaded', set_laptop_workspaces_to_monocle)
2026-08-16 16:42:16 +01:00
2026-09-07 17:54:40 +01:00
hl.on('window.open', function()
local windows = hl.get_windows()
for i = 1, #windows do
local win = windows[i]
if win.workspace.id > 0 then
hl.dispatch(hl.dsp.window.move { workspace = 'name:Home_1' })
end
end
end)
hl.on('workspace.active', function()
local monitors = hl.get_monitors()
local monitor_count = #monitors
local workspace = get_active_workspace()
if workspace and workspace.id > 0 then
for j = monitor_count, 1, -1 do
local monitor = monitors[j]
hl.dsp.focus { workspace = 'name:Home_' .. j }
end
end
end)