Skip to content

Commit 912d39b

Browse files
committed
fix(notes): ensure widget is fully shown on one screen
This fix prevents the widget from being split between monitors if the widget button is on the edge between two adjacent monitors.
1 parent 9e11469 commit 912d39b

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/core/utils/utilities.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import platform
22
import re
3-
from typing import Any
3+
from typing import Any, cast
44
from PyQt6.QtWidgets import QApplication, QWidget, QFrame, QMenu, QGraphicsDropShadowEffect
5-
from PyQt6.QtCore import QEvent, QObject, QPoint, Qt
6-
from PyQt6.QtGui import QScreen, QColor
5+
from PyQt6.QtCore import QEvent, QPoint, Qt
6+
from PyQt6.QtGui import QScreen, QColor
77
from core.utils.win32.blurWindow import Blur
88

99
def is_windows_10() -> bool:
@@ -99,7 +99,7 @@ def setPosition(self, alignment='left', direction='down', offset_left=0, offset_
9999
offset_left (int): Horizontal offset in pixels
100100
offset_top (int): Vertical offset in pixels
101101
"""
102-
parent = self.parent()
102+
parent = cast(QWidget, self.parent()) # parent should be a QWidget
103103
if not parent:
104104
return
105105

@@ -124,6 +124,15 @@ def setPosition(self, alignment='left', direction='down', offset_left=0, offset_
124124
else:
125125
global_position = widget_global_pos
126126

127+
# Determine screen where the parent is
128+
screen = QApplication.screenAt(parent.mapToGlobal(parent.rect().center()))
129+
if screen:
130+
available_geometry = screen.availableGeometry()
131+
# Ensure the popup fits horizontally
132+
x = max(available_geometry.left(), min(global_position.x(), available_geometry.right() - self.width()))
133+
# Ensure the popup fits vertically
134+
y = max(available_geometry.top(), min(global_position.y(), available_geometry.bottom() - self.height()))
135+
global_position = QPoint(x, y)
127136
self.move(global_position)
128137

129138
def showEvent(self, event):

0 commit comments

Comments
 (0)