Fix menu positioning to account for multiple monitors (#24)

* Fix menu positioning to account for multiple monitors

It takes into account the orientation of the panel applet. It also
offsets its right/left positioning to avoid clipping.

Fixes #21

* Take into account possible clipping in the top/bottom of the monitor
This commit is contained in:
Victor Kareh 2017-07-16 06:05:34 -04:00 committed by Clement Lefebvre
parent ce03b1674d
commit 45faa83e52

View File

@ -749,36 +749,56 @@ class MenuWin( object ):
entryWidth, entryHeight = self.applet.get_allocation().width, self.applet.get_allocation().height entryWidth, entryHeight = self.applet.get_allocation().width, self.applet.get_allocation().height
entryHeight = entryHeight + self.mainwin.offset entryHeight = entryHeight + self.mainwin.offset
# Get the screen dimensions # Get the monitor dimensions
screenHeight = Gdk.Screen.height() display = self.applet.get_display()
screenWidth = Gdk.Screen.width() if (Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION) >= (3, 22):
if self.applet.get_orient() == MatePanelApplet.AppletOrient.UP or self.applet.get_orient() == MatePanelApplet.AppletOrient.DOWN: monitor = display.get_monitor_at_window(self.applet.get_window())
if entryX + ourWidth < screenWidth or entryX + entryWidth / 2 < screenWidth / 2: monitorGeometry = monitor.get_geometry()
# Align to the left of the entry else:
screen = display.get_default_screen()
monitor = screen.get_monitor_at_window(self.applet.get_window())
monitorGeometry = screen.get_monitor_geometry(monitor)
applet_orient = self.applet.get_orient()
if applet_orient == MatePanelApplet.AppletOrient.UP:
newX = entryX newX = entryX
else:
# Align to the right of the entry
newX = entryX + entryWidth - ourWidth
if entryY + entryHeight / 2 < screenHeight / 2:
# Align to the bottom of the entry
newY = entryY + entryHeight
else:
newY = entryY - ourHeight newY = entryY - ourHeight
else: elif applet_orient == MatePanelApplet.AppletOrient.DOWN:
if entryX + entryWidth / 2 < screenWidth / 2: newX = entryX
# Align to the left of the entry newY = entryY + entryHeight
elif applet_orient == MatePanelApplet.AppletOrient.RIGHT:
newX = entryX + entryWidth newX = entryX + entryWidth
else:
# Align to the right of the entry
newX = entryX - ourWidth
if entryY + ourHeight < screenHeight or entryY + entryHeight / 2 < screenHeight / 2:
# Align to the bottom of the entry
newY = entryY newY = entryY
else: elif applet_orient == MatePanelApplet.AppletOrient.LEFT:
newY = entryY - ourHeight + entryHeight newX = entryX - ourWidth
# -"Move window" newY = entryY
# Adjust for offset if we reach the end of the screen
# Bind to the right side
if newX + ourWidth > (monitorGeometry.x + monitorGeometry.width):
newX = (monitorGeometry.x + monitorGeometry.width) - ourWidth
if applet_orient == MatePanelApplet.AppletOrient.LEFT:
newX -= entryWidth
# Bind to the left side
if newX < monitorGeometry.x:
newX = monitorGeometry.x
if applet_orient == MatePanelApplet.AppletOrient.RIGHT:
newX -= entryWidth;
# Bind to the bottom
if newY + ourHeight > (monitorGeometry.y + monitorGeometry.height):
newY = (monitorGeometry.y + monitorGeometry.height) - ourHeight
if applet_orient == MatePanelApplet.AppletOrient.UP:
newY -= entryHeight
# Bind to the top
if newY < monitorGeometry.y:
newY = monitorGeometry.y
if applet_orient == MatePanelApplet.AppletOrient.DOWN:
newY -= entryHeight
# Move window
self.mainwin.window.move( newX, newY ) self.mainwin.window.move( newX, newY )
# this callback is to create a context menu # this callback is to create a context menu