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:
parent
ce03b1674d
commit
45faa83e52
@ -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
|
|
||||||
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
|
|
||||||
else:
|
else:
|
||||||
if entryX + entryWidth / 2 < screenWidth / 2:
|
screen = display.get_default_screen()
|
||||||
# Align to the left of the entry
|
monitor = screen.get_monitor_at_window(self.applet.get_window())
|
||||||
newX = entryX + entryWidth
|
monitorGeometry = screen.get_monitor_geometry(monitor)
|
||||||
else:
|
|
||||||
# Align to the right of the entry
|
|
||||||
newX = entryX - ourWidth
|
|
||||||
|
|
||||||
if entryY + ourHeight < screenHeight or entryY + entryHeight / 2 < screenHeight / 2:
|
applet_orient = self.applet.get_orient()
|
||||||
# Align to the bottom of the entry
|
if applet_orient == MatePanelApplet.AppletOrient.UP:
|
||||||
newY = entryY
|
newX = entryX
|
||||||
else:
|
newY = entryY - ourHeight
|
||||||
newY = entryY - ourHeight + entryHeight
|
elif applet_orient == MatePanelApplet.AppletOrient.DOWN:
|
||||||
# -"Move window"
|
newX = entryX
|
||||||
|
newY = entryY + entryHeight
|
||||||
|
elif applet_orient == MatePanelApplet.AppletOrient.RIGHT:
|
||||||
|
newX = entryX + entryWidth
|
||||||
|
newY = entryY
|
||||||
|
elif applet_orient == MatePanelApplet.AppletOrient.LEFT:
|
||||||
|
newX = entryX - ourWidth
|
||||||
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user