Skip to content

Commit

Permalink
Merge pull request #500 from frmdstryr/x11-popup-layout
Browse files Browse the repository at this point in the history
Workaround multi-display issues on X11 with popups
  • Loading branch information
MatthieuDartiailh committed Aug 12, 2022
2 parents 8fc7f7f + 47485b3 commit db8d918
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions enaml/qt/q_popup_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from atom.api import Atom, Bool, Typed, Float, Int

from .QtCore import (
Qt, QPoint, QPointF, QSize, QRect,QMargins, QPropertyAnimation, QTimer,
Qt, QPoint, QPointF, QSize, QRect, QMargins, QPropertyAnimation, QTimer,
QEvent, Signal
)
from .QtGui import (
Expand All @@ -21,6 +21,9 @@
from .q_single_widget_layout import QSingleWidgetLayout


IS_X11 = QApplication.platformName() == "xcb"


class AnchorMode(IntEnum):
""" An IntEnum defining the various popup anchor modes.
Expand Down Expand Up @@ -218,6 +221,7 @@ def edge_margins(arrow_size, arrow_edge):
margins.setTop(arrow_size)
return margins


# XXX check on multiple screen setup
def is_fully_on_screen(screen, rect):
""" Get whether or not a rect is fully contained on the screen.
Expand Down Expand Up @@ -829,11 +833,21 @@ def _get_screen(self):
""" Access the screen on which this popup is displayed.
"""
window = self.windowHandle()
if window is None:
window = QApplication.primaryScreen()
screen = None
parent = self.parent()
if parent:
if parent.isWindow():
screen = parent.screen()
else:
screen = parent.window().screen()
else:
window = self.windowHandle()
if window:
screen = window.screen()
if screen is None:
screen = QApplication.primaryScreen()

return window.screen()
return screen

def _refreshGeometry(self, force=False):
""" Refresh the geometry for the popup using the current state.
Expand Down Expand Up @@ -863,7 +877,12 @@ def _layoutPlainRect(self):
offset = self._state.offset
trial_pos = target_pos + offset - anchor_pos
trial_geo = QRect(trial_pos, self.size())
geo = ensure_on_screen(self._get_screen(), trial_geo)
if IS_X11:
# X11 handles geometry as an absolute position in the desktop
# when there are multiple screens
geo = trial_geo
else:
geo = ensure_on_screen(self._get_screen(), trial_geo)
self.setGeometry(geo)

def _layoutArrowRect(self):
Expand Down Expand Up @@ -897,7 +916,7 @@ def _layoutArrowRect(self):
pos = target_pos + state.offset - QPoint(ax, ay)
rect = QRect(pos, size)
screen = self._get_screen()
if not is_fully_on_screen(screen, rect):
if not is_fully_on_screen(screen, rect) and not IS_X11:
rect, new_edge, d_ax, d_ay = adjust_arrow_rect(
screen, rect, arrow_edge, target_pos, state.offset
)
Expand Down

0 comments on commit db8d918

Please sign in to comment.