Skip to content

Commit fc293e0

Browse files
committed
Update Hyprland scratchpad workarea cache
1 parent d3912fc commit fc293e0

1 file changed

Lines changed: 41 additions & 21 deletions

File tree

dotfiles/config/hypr/hyprland.lua

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,41 @@ local function split_tsv(line)
12691269
return fields
12701270
end
12711271

1272+
local function monitor_from_reserved_fields(monitor, fields)
1273+
if not monitor or not monitor.name or fields[1] ~= monitor.name or #fields < 10 then
1274+
return nil
1275+
end
1276+
1277+
return {
1278+
name = monitor.name,
1279+
x = tonumber(fields[2]),
1280+
y = tonumber(fields[3]),
1281+
width = tonumber(fields[4]),
1282+
height = tonumber(fields[5]),
1283+
scale = tonumber(fields[6]),
1284+
reserved = {
1285+
tonumber(fields[7]),
1286+
tonumber(fields[8]),
1287+
tonumber(fields[9]),
1288+
tonumber(fields[10]),
1289+
},
1290+
}
1291+
end
1292+
1293+
local function monitor_from_reserved_lines(monitor, lines)
1294+
if not monitor or not monitor.name then
1295+
return nil
1296+
end
1297+
1298+
for line in lines do
1299+
local cached = monitor_from_reserved_fields(monitor, split_tsv(line))
1300+
if cached then
1301+
return cached
1302+
end
1303+
end
1304+
return nil
1305+
end
1306+
12721307
local function monitor_from_reserved_cache(monitor)
12731308
if verify_config or not monitor or not monitor.name then
12741309
return nil
@@ -1279,27 +1314,7 @@ local function monitor_from_reserved_cache(monitor)
12791314
return nil
12801315
end
12811316

1282-
local cached = nil
1283-
for line in file:lines() do
1284-
local fields = split_tsv(line)
1285-
if fields[1] == monitor.name and #fields >= 10 then
1286-
cached = {
1287-
name = monitor.name,
1288-
x = tonumber(fields[2]),
1289-
y = tonumber(fields[3]),
1290-
width = tonumber(fields[4]),
1291-
height = tonumber(fields[5]),
1292-
scale = tonumber(fields[6]),
1293-
reserved = {
1294-
tonumber(fields[7]),
1295-
tonumber(fields[8]),
1296-
tonumber(fields[9]),
1297-
tonumber(fields[10]),
1298-
},
1299-
}
1300-
break
1301-
end
1302-
end
1317+
local cached = monitor_from_reserved_lines(monitor, file:lines())
13031318
file:close()
13041319
return cached
13051320
end
@@ -2272,6 +2287,11 @@ hl.on("config.reloaded", apply_hyprexpo_config)
22722287
hl.on("config.reloaded", apply_hyprwinview_config)
22732288
hl.on("config.reloaded", apply_rules)
22742289
hl.on("config.reloaded", refresh_shell_workarea_and_scratchpads)
2290+
hl.on("layer.opened", refresh_shell_workarea_and_scratchpads)
2291+
hl.on("layer.closed", refresh_shell_workarea_and_scratchpads)
2292+
hl.on("monitor.added", refresh_shell_workarea_and_scratchpads)
2293+
hl.on("monitor.removed", refresh_shell_workarea_and_scratchpads)
2294+
hl.on("monitor.layout_changed", refresh_shell_workarea_and_scratchpads)
22752295

22762296
hl.on("window.open", schedule_nstack_count_update)
22772297
hl.on("window.destroy", schedule_nstack_count_update)

0 commit comments

Comments
 (0)