def start_positioning(self): self.show() if settings.get_allow_floating(): trackers.timer_tracker_get().cancel(str(self) + "positioning") trackers.timer_tracker_get().start_seconds(str(self) + "positioning", POSITIONING_TIMEOUT, self.positioning_callback)
def start_positioning(self): self.show() if settings.get_allow_floating(): trackers.timer_tracker_get().cancel(str(self) + "positioning") trackers.timer_tracker_get().start_seconds( str(self) + "positioning", POSITIONING_TIMEOUT, self.positioning_callback)
def stop_positioning(self): if settings.get_allow_floating(): trackers.timer_tracker_get().cancel(str(self) + "positioning")
def position_overlay_child(self, overlay, child, allocation): """ Callback for our GtkOverlay, think of this as a mini- window manager for our Stage. Depending on what type child is, we position it differently. We always call child.get_preferred_size() whether we plan to use it or not - this prevents allocation warning spew, particularly in Gtk >= 3.20. Returning True says, yes draw it. Returning False tells it to skip drawing. If a new widget type is introduced that spawns directly on the stage, it must have its own handling code here. """ if isinstance(child, MonitorView): """ MonitorView is always the size and position of its assigned monitor. This is calculated and stored by the child in child.rect) """ w, h = child.get_preferred_size() allocation.x = child.rect.x allocation.y = child.rect.y allocation.width = child.rect.width allocation.height = child.rect.height return True if isinstance(child, UnlockDialog): """ UnlockDialog always shows on the currently focused monitor (the one the mouse is currently in), and is kept centered. """ monitor = status.screen.get_mouse_monitor() monitor_rect = status.screen.get_monitor_geometry(monitor) min_rect, nat_rect = child.get_preferred_size() allocation.width = nat_rect.width allocation.height = nat_rect.height allocation.x = monitor_rect.x + (monitor_rect.width / 2) - (allocation.width / 2) allocation.y = monitor_rect.y + (monitor_rect.height / 2) - (allocation.height / 2) return True if isinstance(child, ClockWidget) or isinstance(child, AlbumArt): """ ClockWidget and AlbumArt behave differently depending on if status.Awake is True or not. The widgets' halign and valign properties are used to store their gross position on the monitor. This limits the number of possible positions to (3 * 3 * n_monitors) when our screensaver is not Awake, and the widgets have an internal timer that randomizes halign, valign, and current monitor every so many seconds, calling a queue_resize on itself after each timer tick (which forces this function to run). """ min_rect, nat_rect = child.get_preferred_size() if status.Awake: current_monitor = status.screen.get_mouse_monitor() else: current_monitor = child.current_monitor monitor_rect = status.screen.get_monitor_geometry(current_monitor) region_w = monitor_rect.width / 3 region_h = monitor_rect.height / 3 if status.Awake: """ If we're Awake, force the clock to track to the active monitor, and be aligned to the left-center. The albumart widget aligns right-center. """ unlock_mw, unlock_nw = self.unlock_dialog.get_preferred_width() """ If, for whatever reason, we need more than 1/3 of the screen to fully display the unlock dialog, reduce our available region width to accomodate it, reducing the allocation for the floating widgets as required. """ if (unlock_nw > region_w): region_w = (monitor_rect.width - unlock_nw) / 2 if isinstance(child, ClockWidget): child.set_halign(Gtk.Align.START) else: child.set_halign(Gtk.Align.END) child.set_valign(Gtk.Align.CENTER) else: if settings.get_allow_floating(): for floater in self.floaters: """ Don't let our floating widgets end up in the same spot. """ if floater is child: continue if floater.get_halign() != child.get_halign() and floater.get_valign() != child.get_valign(): continue fa = floater.get_halign() ca = child.get_halign() while fa == ca: ca = ALIGNMENTS[random.randint(0, 2)] child.set_halign(ca) fa = floater.get_valign() ca = child.get_valign() while fa == ca: ca = ALIGNMENTS[random.randint(0, 2)] child.set_valign(ca) # Restrict the widget size to the allowable region sizes if necessary. allocation.width = min(nat_rect.width, region_w) allocation.height = min(nat_rect.height, region_h) # Calculate padding required to center widgets within their particular 1/9th of the monitor padding_left = padding_right = (region_w - allocation.width) / 2 padding_top = padding_bottom = (region_h - allocation.height) / 2 halign = child.get_halign() valign = child.get_valign() if halign == Gtk.Align.START: allocation.x = monitor_rect.x + padding_left elif halign == Gtk.Align.CENTER: allocation.x = monitor_rect.x + (monitor_rect.width / 2) - (allocation.width / 2) elif halign == Gtk.Align.END: allocation.x = monitor_rect.x + monitor_rect.width - allocation.width - padding_right if valign == Gtk.Align.START: allocation.y = monitor_rect.y + padding_top elif valign == Gtk.Align.CENTER: allocation.y = monitor_rect.y + (monitor_rect.height / 2) - (allocation.height / 2) elif valign == Gtk.Align.END: allocation.y = monitor_rect.y + monitor_rect.height - allocation.height - padding_bottom return True if isinstance(child, AudioPanel): """ The AudioPanel is only shown when Awake, and attaches itself to the upper-left corner of the active monitor. """ min_rect, nat_rect = child.get_preferred_size() if status.Awake: current_monitor = status.screen.get_mouse_monitor() monitor_rect = status.screen.get_monitor_geometry(current_monitor) allocation.x = monitor_rect.x allocation.y = monitor_rect.y allocation.width = nat_rect.width allocation.height = nat_rect.height else: allocation.x = child.rect.x allocation.y = child.rect.y allocation.width = nat_rect.width allocation.height = nat_rect.height return True if isinstance(child, InfoPanel): """ The InfoPanel can be shown while not Awake, but only if we're not running a screensaver plugin. In any case, it will only appear if a) We have received notifications while the screensaver is running, or b) we're either on battery or plugged in but with a non-full battery. It attaches itself to the upper-right corner of the monitor. """ min_rect, nat_rect = child.get_preferred_size() if status.Awake: current_monitor = status.screen.get_mouse_monitor() monitor_rect = status.screen.get_monitor_geometry(current_monitor) allocation.x = monitor_rect.x + monitor_rect.width - nat_rect.width allocation.y = monitor_rect.y allocation.width = nat_rect.width allocation.height = nat_rect.height else: allocation.x = child.rect.x + child.rect.width - nat_rect.width allocation.y = child.rect.y allocation.width = nat_rect.width allocation.height = nat_rect.height return True return False
def position_overlay_child(self, overlay, child, allocation): """ Callback for our GtkOverlay, think of this as a mini- window manager for our Stage. Depending on what type child is, we position it differently. We always call child.get_preferred_size() whether we plan to use it or not - this prevents allocation warning spew, particularly in Gtk >= 3.20. Returning True says, yes draw it. Returning False tells it to skip drawing. If a new widget type is introduced that spawns directly on the stage, it must have its own handling code here. """ if isinstance(child, MonitorView): """ MonitorView is always the size and position of its assigned monitor. This is calculated and stored by the child in child.rect) """ w, h = child.get_preferred_size() allocation.x = child.rect.x allocation.y = child.rect.y allocation.width = child.rect.width allocation.height = child.rect.height return True if isinstance(child, UnlockDialog): """ UnlockDialog always shows on the currently focused monitor (the one the mouse is currently in), and is kept centered. """ monitor = status.screen.get_mouse_monitor() monitor_rect = status.screen.get_monitor_geometry(monitor) min_rect, nat_rect = child.get_preferred_size() allocation.width = nat_rect.width allocation.height = nat_rect.height allocation.x = monitor_rect.x + (monitor_rect.width / 2) - (allocation.width / 2) allocation.y = monitor_rect.y + (monitor_rect.height / 2) - (allocation.height / 2) return True if isinstance(child, ClockWidget) or isinstance(child, AlbumArt): """ ClockWidget and AlbumArt behave differently depending on if status.Awake is True or not. The widgets' halign and valign properties are used to store their gross position on the monitor. This limits the number of possible positions to (3 * 3 * n_monitors) when our screensaver is not Awake, and the widgets have an internal timer that randomizes halign, valign, and current monitor every so many seconds, calling a queue_resize on itself after each timer tick (which forces this function to run). """ min_rect, nat_rect = child.get_preferred_size() if status.Awake: current_monitor = status.screen.get_mouse_monitor() else: current_monitor = child.current_monitor monitor_rect = status.screen.get_monitor_geometry(current_monitor) region_w = monitor_rect.width / 3 region_h = monitor_rect.height if status.Awake: """ If we're Awake, force the clock to track to the active monitor, and be aligned to the left-center. The albumart widget aligns right-center. """ unlock_mw, unlock_nw = self.unlock_dialog.get_preferred_width() """ If, for whatever reason, we need more than 1/3 of the screen to fully display the unlock dialog, reduce our available region width to accomodate it, reducing the allocation for the floating widgets as required. """ if (unlock_nw > region_w): region_w = (monitor_rect.width - unlock_nw) / 2 region_h = monitor_rect.height if isinstance(child, ClockWidget): child.set_halign(Gtk.Align.START) else: child.set_halign(Gtk.Align.END) child.set_valign(Gtk.Align.CENTER) else: if settings.get_allow_floating(): for floater in self.floaters: """ Don't let our floating widgets end up in the same spot. """ if floater is child: continue if floater.get_halign() != child.get_halign( ) and floater.get_valign() != child.get_valign(): continue region_h = monitor_rect.height / 3 fa = floater.get_halign() ca = child.get_halign() while fa == ca: ca = ALIGNMENTS[random.randint(0, 2)] child.set_halign(ca) fa = floater.get_valign() ca = child.get_valign() while fa == ca: ca = ALIGNMENTS[random.randint(0, 2)] child.set_valign(ca) # Restrict the widget size to the allowable region sizes if necessary. allocation.width = min(nat_rect.width, region_w) allocation.height = min(nat_rect.height, region_h) # Calculate padding required to center widgets within their particular 1/9th of the monitor padding_left = padding_right = (region_w - allocation.width) / 2 padding_top = padding_bottom = (region_h - allocation.height) / 2 halign = child.get_halign() valign = child.get_valign() if halign == Gtk.Align.START: allocation.x = monitor_rect.x + padding_left elif halign == Gtk.Align.CENTER: allocation.x = monitor_rect.x + (monitor_rect.width / 2) - (allocation.width / 2) elif halign == Gtk.Align.END: allocation.x = monitor_rect.x + monitor_rect.width - allocation.width - padding_right if valign == Gtk.Align.START: allocation.y = monitor_rect.y + padding_top elif valign == Gtk.Align.CENTER: allocation.y = monitor_rect.y + (monitor_rect.height / 2) - (allocation.height / 2) elif valign == Gtk.Align.END: allocation.y = monitor_rect.y + monitor_rect.height - allocation.height - padding_bottom return True if isinstance(child, AudioPanel): """ The AudioPanel is only shown when Awake, and attaches itself to the upper-left corner of the active monitor. """ min_rect, nat_rect = child.get_preferred_size() if status.Awake: current_monitor = status.screen.get_mouse_monitor() monitor_rect = status.screen.get_monitor_geometry( current_monitor) allocation.x = monitor_rect.x allocation.y = monitor_rect.y allocation.width = nat_rect.width allocation.height = nat_rect.height else: allocation.x = child.rect.x allocation.y = child.rect.y allocation.width = nat_rect.width allocation.height = nat_rect.height return True if isinstance(child, InfoPanel): """ The InfoPanel can be shown while not Awake, but will only appear if a) We have received notifications while the screensaver is running, or b) we're either on battery or plugged in but with a non-full battery. It attaches itself to the upper-right corner of the monitor. """ min_rect, nat_rect = child.get_preferred_size() if status.Awake: current_monitor = status.screen.get_mouse_monitor() monitor_rect = status.screen.get_monitor_geometry( current_monitor) allocation.x = monitor_rect.x + monitor_rect.width - nat_rect.width allocation.y = monitor_rect.y allocation.width = nat_rect.width allocation.height = nat_rect.height else: allocation.x = child.rect.x + child.rect.width - nat_rect.width allocation.y = child.rect.y allocation.width = nat_rect.width allocation.height = nat_rect.height return True if isinstance(child, OnScreenKeyboard): """ The InfoPanel can be shown while not Awake, but will only appear if a) We have received notifications while the screensaver is running, or b) we're either on battery or plugged in but with a non-full battery. It attaches itself to the upper-right corner of the monitor. """ min_rect, nat_rect = child.get_preferred_size() current_monitor = status.screen.get_mouse_monitor() monitor_rect = status.screen.get_monitor_geometry(current_monitor) allocation.x = monitor_rect.x allocation.y = monitor_rect.y + monitor_rect.height - ( monitor_rect.height / 3) allocation.width = monitor_rect.width allocation.height = monitor_rect.height / 3 return True return False