Skip to content

Commit c592e2a

Browse files
committed
improve force_monitor behavior #113
1 parent a209d82 commit c592e2a

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

pyprland/plugins/scratchpads/__init__.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ async def _configure_windowrules(self, scratch: Scratch) -> None:
121121
defined_class: str = scratch.conf.get("class", "")
122122
skipped_windowrules = scratch.conf.get("skip_windowrules", [])
123123
if defined_class:
124-
monitor = await self.get_focused_monitor_props(name=scratch.conf.get("force_monitor"))
124+
forced_monitor = scratch.conf.get("force_monitor")
125+
if forced_monitor and forced_monitor not in state.monitors:
126+
self.log.error("forced monitor %s doesn't exist", forced_monitor)
127+
await self.notify_error(f"Monitor '{forced_monitor}' doesn't exist, check {scratch.uid}'s scratch configuration")
128+
forced_monitor = None
129+
monitor = await self.get_focused_monitor_props(name=forced_monitor)
125130
width, height = convert_coords(scratch.conf.get("size", "80% 80%"), monitor)
126131

127132
ipc_commands = []
@@ -435,7 +440,7 @@ async def run_toggle(self, uid_or_uids: str) -> None:
435440
) # visible on the currently focused monitor
436441

437442
is_visible = first_scratch.visible and (
438-
first_scratch.conf.get("force_monitor") or extra_visibility_check
443+
first_scratch.forced_monitor or extra_visibility_check
439444
) # always showing on the same monitor
440445
tasks = []
441446

@@ -455,7 +460,7 @@ async def get_offsets(self, scratch: Scratch, monitor: MonitorInfo | None = None
455460
"""Return offset from config or use margin as a ref."""
456461
offset = scratch.conf.get("offset")
457462
if monitor is None:
458-
monitor = await get_focused_monitor_props(self.log, name=scratch.conf.get("force_monitor"))
463+
monitor = await get_focused_monitor_props(self.log, name=scratch.forced_monitor)
459464
rotated = is_rotated(monitor)
460465
aspect = reversed(scratch.client_info["size"]) if rotated else scratch.client_info["size"]
461466

@@ -540,7 +545,7 @@ async def run_show(self, uid: str) -> None:
540545

541546
scratch.visible = True
542547
scratch.meta.space_identifier = get_active_space_identifier()
543-
monitor = await self.get_focused_monitor_props(name=scratch.conf.get("force_monitor"))
548+
monitor = await self.get_focused_monitor_props(name=scratch.forced_monitor)
544549

545550
assert monitor
546551
assert scratch.full_address, "No address !"

pyprland/plugins/scratchpads/objects.py

+8
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ def __init__(self, uid: str, opts: dict[str, Any]) -> None:
5656
self.meta = MetaInfo()
5757
self.extra_addr: set[str] = set() # additional client addresses
5858

59+
@property
60+
def forced_monitor(self) -> str | None:
61+
"""Returns forced monitor if available, else None."""
62+
forced_monitor = self.conf.get("force_monitor")
63+
if forced_monitor in state.monitors:
64+
return forced_monitor
65+
return None
66+
5967
def set_config(self, opts: dict[str, Any]) -> None:
6068
"""Apply constraints to the configuration."""
6169
if "class_match" in opts: # NOTE: legacy, to be removed

pyprland/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Package version."""
22

3-
VERSION = "2.3.8-1"
3+
VERSION = "2.3.8-2"

0 commit comments

Comments
 (0)