Skip to content

Commit 4fdd2a2

Browse files
committed
multi-monitor progress
1 parent f156815 commit 4fdd2a2

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

modules/notch.py

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,21 +474,71 @@ def close_notch(self):
474474
self.notch_revealer.set_reveal_child(False)
475475

476476
def open_notch(self, widget_name: str):
477-
# Handle monitor focus switching
477+
# Debug info for troubleshooting
478+
if hasattr(self, '_debug_monitor_focus') and self._debug_monitor_focus:
479+
print(f"DEBUG: open_notch called on monitor {self.monitor_id} for widget '{widget_name}'")
480+
481+
# Handle monitor focus switching - always check real focused monitor from Hyprland
478482
if self.monitor_manager:
483+
# Get real focused monitor directly from Hyprland to ensure accuracy
484+
real_focused_monitor_id = self._get_real_focused_monitor_id()
485+
486+
# Update monitor manager if we got a valid result
487+
if real_focused_monitor_id is not None:
488+
# Update the monitor manager's focused monitor
489+
self.monitor_manager._focused_monitor_id = real_focused_monitor_id
490+
if hasattr(self, '_debug_monitor_focus') and self._debug_monitor_focus:
491+
print(f"DEBUG: Real focused monitor from Hyprland: {real_focused_monitor_id}")
492+
479493
focused_monitor_id = self.monitor_manager.get_focused_monitor_id()
494+
480495
if focused_monitor_id != self.monitor_id:
481496
# Close this notch and open on focused monitor
497+
if hasattr(self, '_debug_monitor_focus') and self._debug_monitor_focus:
498+
print(f"DEBUG: Redirecting from monitor {self.monitor_id} to focused monitor {focused_monitor_id}")
499+
482500
self.close_notch()
483-
focused_notch = self.monitor_manager.get_focused_instance('notch')
501+
focused_notch = self.monitor_manager.get_instance(focused_monitor_id, 'notch')
484502
if focused_notch and hasattr(focused_notch, 'open_notch'):
485-
focused_notch.open_notch(widget_name)
503+
# Recursively call open_notch on the correct monitor instance
504+
focused_notch._open_notch_internal(widget_name)
486505
return
487506

488507
# Close notches on other monitors
489508
self.monitor_manager.close_all_notches_except(self.monitor_id)
490509
self.monitor_manager.set_notch_state(self.monitor_id, True, widget_name)
491510

511+
# Call internal open_notch implementation
512+
self._open_notch_internal(widget_name)
513+
514+
def _get_real_focused_monitor_id(self):
515+
"""Get the real focused monitor ID directly from Hyprland."""
516+
try:
517+
import json
518+
import subprocess
519+
520+
# Get focused monitor from Hyprland
521+
result = subprocess.run(
522+
["hyprctl", "monitors", "-j"],
523+
capture_output=True,
524+
text=True,
525+
check=True,
526+
timeout=2.0
527+
)
528+
529+
monitors = json.loads(result.stdout)
530+
for i, monitor in enumerate(monitors):
531+
if monitor.get('focused', False):
532+
return i
533+
534+
except (subprocess.CalledProcessError, json.JSONDecodeError,
535+
FileNotFoundError, subprocess.TimeoutExpired) as e:
536+
print(f"Warning: Could not get focused monitor from Hyprland: {e}")
537+
538+
return None
539+
540+
def _open_notch_internal(self, widget_name: str):
541+
492542
self.notch_revealer.set_reveal_child(True)
493543
self.notch_box.add_style_class("open")
494544
self.stack.add_style_class("open")

0 commit comments

Comments
 (0)