def update_location(self): """ Makes sure the window is always fully visible """ workarea = Gdk.Rectangle() workarea.x = workarea.y = 0 workarea.width, workarea.height = get_workarea_size() parent_alloc = self.parent_widget.get_allocation() toplevel_position = self.parent_widget.get_toplevel().get_window( ).get_position() # Use absolute screen position parent_alloc.x += toplevel_position[0] parent_alloc.y += toplevel_position[1] alloc = self.get_allocation() if workarea.width - parent_alloc.x < alloc.width: # Parent rightmost x = parent_alloc.x + parent_alloc.width - alloc.width else: # Parent leftmost x = parent_alloc.x if workarea.height - parent_alloc.y < alloc.height: # Parent at bottom y = parent_alloc.y - alloc.height else: # Parent at top y = parent_alloc.y + parent_alloc.height self.move(x, y)
def update_location(self): """ Makes sure the window is always fully visible """ workarea = gtk.gdk.Rectangle(0, 0, *get_workarea_size()) parent = self.parent_widget.allocation toplevel_position = self.parent_widget.get_toplevel().get_position() # Use absolute screen position parent.x += toplevel_position[0] parent.y += toplevel_position[1] if workarea.width - parent.x < self.allocation.width: # Parent rightmost x = parent.x + parent.width - self.allocation.width else: # Parent leftmost x = parent.x if workarea.height - parent.y < self.allocation.height: # Parent at bottom y = parent.y - self.allocation.height else: # Parent at top y = parent.y + parent.height self.move(x, y)
def update_location(self): """ Makes sure the window is always fully visible """ workarea = Gdk.Rectangle() workarea.x = workarea.y = 0 workarea.width, workarea.height = get_workarea_size() parent_alloc = self.parent_widget.get_allocation() toplevel_position = self.parent_widget.get_toplevel().get_window().get_position() # Use absolute screen position parent_alloc.x += toplevel_position[0] parent_alloc.y += toplevel_position[1] alloc = self.get_allocation() if workarea.width - parent_alloc.x < alloc.width: # Parent rightmost x = parent_alloc.x + parent_alloc.width - alloc.width else: # Parent leftmost x = parent_alloc.x if workarea.height - parent_alloc.y < alloc.height: # Parent at bottom y = parent_alloc.y - alloc.height else: # Parent at top y = parent_alloc.y + parent_alloc.height self.move(x, y)
def get_menu_position(self, menu, icon): """ Returns coordinates for the best menu position """ workarea_width, workarea_height = get_workarea_size() icon_x, icon_y, icon_width, icon_height = icon.get_allocation() icon_x, icon_y = icon.get_window().get_origin() menu_x, menu_y, menu_width, menu_height = menu.get_allocation() x = icon_x + icon_width y = icon_y + icon_height if workarea_width - icon_x < menu_width: # Tray icon on the right: insufficient space x -= menu_width if workarea_height - icon_y < menu_height: # Tray icon on the bottom: insufficient space y -= menu_height return (x, y, False)
def update_drop_target_window_location(self): """ Makes sure the drop target is always fully visible """ workarea_width, workarea_height = get_workarea_size() icon_x, icon_y, icon_width, icon_height = self.get_allocation() icon_x, icon_y = self.get_window().get_origin() target_width, target_height = self.drop_target_window.size_request() # TODO: Align drop targets vertically if required # Tray icon on the left if icon_x < target_width / 2: # Insufficient space: leftmost x = icon_width # Tray icon on the right elif workarea_width - icon_x < target_width / 2: # Insufficient space: rightmost x = workarea_width - target_width # Tray icon in between else: x = icon_x + icon_width / 2 - target_width / 2 # Tray icon on the top if icon_y < target_height / 2: # Insufficient space: topmost y = icon_height # Tray icon on the bottom elif workarea_height - icon_y < target_height / 2: # Insufficient space: bottommost y = workarea_height - target_height # Tray icon in between else: y = icon_y + icon_height / 2 - target_height / 2 self.drop_target_window.move(x, y)