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

112 lines
3.6 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()
local monitors = hl.get_monitors()
local monitor_count = #monitors
2026-06-27 12:51:49 +01:00
2026-06-27 17:04:05 +01:00
-- Move active window to a workspace with SUPER + SHIFT + [1-5]
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-06-27 19:38:20 +01:00
-- local workspace_id = "name:" .. workspace_map[i] .. "_" .. j
local workspace_id = (i - 1) * monitor_count + j
2026-08-16 12:36:11 +01:00
local workspace_name = workspace_map[i] .. '_' .. j
hl.workspace_rule {
2026-06-28 22:53:41 +01:00
-- workspace = (i - 1) * monitor_count + j,
2026-06-28 22:45:03 +01:00
-- default_name = workspace_name,
2026-08-16 12:36:11 +01:00
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-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-08-16 12:36:11 +01:00
hl.bind('SUPER + SHIFT + code:1' .. (i - 1), function()
2026-06-28 22:45:03 +01:00
local active_window = hl.get_active_window()
local active_workspace = active_window.workspace
2026-06-28 20:26:30 +01:00
local active_workspace_name = active_workspace.name
2026-08-16 12:36:11 +01:00
local monitor_suffix = active_workspace_name:match '_(%d+)$' or '1'
local new_workspace = 'name:' .. workspace_map[i] .. '_' .. monitor_suffix
2026-06-28 20:26:30 +01:00
-- local new_workspace = (i - 1) * monitor_count + active_workspace.id
2026-08-16 12:36:11 +01:00
hl.dispatch(hl.dsp.window.move { workspace = new_workspace, window = active_window, follow = false })
end, { description = 'Move window to workspace ' .. workspace_map[i] })
2026-06-28 20:26:30 +01:00
end
-- A hack to move to the Home workspace when Hyprland first loads
2026-06-28 22:45:03 +01:00
for j = monitor_count, 1, -1 do
if hl.get_workspaces()[j].id > 0 and monitor_count == 2 then
2026-08-16 12:36:11 +01:00
hl.dispatch(hl.dsp.focus { workspace = 'name:Home_' .. j })
2026-06-28 20:26:30 +01:00
end
2026-08-16 12:36:11 +01:00
for k, window in pairs(hl.get_windows { workspace = j }) do
hl.dispatch(hl.dsp.window.move { window = window, workspace = 'name:Home_1', follow = true })
2026-06-29 19:13:54 +01:00
end
2026-06-27 12:51:49 +01:00
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)
hl.bind('switch:off:Lid Switch', setup_monitors)
hl.bind('switch:on:Lid Switch', setup_monitors)
hl.bind('switch:off:Lid Switch', function()
hl.monitor {
output = 'desc:BOE NE160QDM-NZ6',
disabled = false,
}
setup_monitors()
end)
hl.bind('switch:on:Lid Switch', function()
hl.monitor {
output = 'desc:BOE NE160QDM-NZ6',
disabled = true,
}
setup_monitors()
end)
2026-08-16 16:42:16 +01:00
hl.on('monitor.focused', function()
local workspace = hl.get_active_workspace()
if hl.get_active_special_workspace() then
workspace = hl.get_active_special_workspace()
end
if not workspace then
return
end
2026-08-17 19:41:51 +01:00
local monitor = hl.get_active_monitor()
if monitor.description == 'BOE NE160QDM-NZ6' then
hl.workspace_rule { workspace = 'name:' .. tostring(workspace.name), layout = 'monocle' }
end
end)
hl.on('config.reloaded', function()
local workspace = hl.get_active_workspace()
if hl.get_active_special_workspace() then
workspace = hl.get_active_special_workspace()
end
if not workspace then
return
end
2026-08-16 16:42:16 +01:00
local monitor = hl.get_active_monitor()
if monitor.description == 'BOE NE160QDM-NZ6' then
hl.workspace_rule { workspace = 'name:' .. tostring(workspace.name), layout = 'monocle' }
end
end)