def update_position(self): """ Updates the position based on gravity and offsets """ gravity = self.gravity_map[settings.get_option( 'plugin/desktopcover/anchor', 'topleft')] cover_offset_x = settings.get_option('plugin/desktopcover/x', 0) cover_offset_y = settings.get_option('plugin/desktopcover/y', 0) allocation = self.get_allocation() workarea = get_workarea_dimensions() x, y = workarea.offset_x, workarea.offset_y if gravity in (gtk.gdk.GRAVITY_NORTH_WEST, gtk.gdk.GRAVITY_SOUTH_WEST): x += cover_offset_x else: x += workarea.width - allocation.width - cover_offset_x if gravity in (gtk.gdk.GRAVITY_NORTH_WEST, gtk.gdk.GRAVITY_NORTH_EAST): y += cover_offset_y else: y += workarea.height - allocation.height - cover_offset_y self.set_gravity(gravity) self.move(int(x), int(y))
def update_position(self): """ Updates the position based on gravity and offsets """ gravity = self.gravity_map[settings.get_option( 'plugin/desktopcover/anchor', 'topleft')] cover_offset_x = settings.get_option('plugin/desktopcover/x', 0) cover_offset_y = settings.get_option('plugin/desktopcover/y', 0) allocation = self.get_allocation() workarea = get_workarea_dimensions() x, y = workarea.x, workarea.y if gravity in (Gdk.Gravity.NORTH_WEST, Gdk.Gravity.SOUTH_WEST): x += cover_offset_x else: x += workarea.width - allocation.width - cover_offset_x if gravity in (Gdk.Gravity.NORTH_WEST, Gdk.Gravity.NORTH_EAST): y += cover_offset_y else: y += workarea.height - allocation.height - cover_offset_y self.set_gravity(gravity) self.move(int(x), int(y))
def _sanitize_window_geometry(window, current_allocation, padding, width_fill, height_fill): """ Sanitizes (x-offset, y-offset, width, height) of the given window, to make the window show on the screen. :param width_fill, height_fill: specifies the maximum width or height of a monitor to fill. 1.0 means "fill the whole monitor" :param padding: specifies the padding (from workarea border) to leave empty """ work_area = guiutil.get_workarea_dimensions(window) cural = current_allocation newal = Gdk.Rectangle() newal.x = max(padding, cural.x) newal.y = max(padding, cural.y) newal.width = min(work_area.width // width_fill, cural.width) newal.height = min(work_area.height // height_fill, cural.height) newal.x = min(newal.x, work_area.x + work_area.width - newal.width - padding) newal.y = min(newal.y, work_area.y + work_area.height - newal.height - padding) if newal == cural: return None if cural.x != newal.x or cural.y != newal.y: if cural.width != newal.width or cural.height != newal.height: window.get_window().move_resize( newal.x, newal.y, newal.width, newal.height) else: window.move(newal.x, newal.y) else: if cural.width != newal.width or cural.height != newal.height: window.resize(newal.width, newal.height) return newal