def setup_clock(self): self.clock_widget = ClockWidget(self.screen, self.away_message, utils.get_mouse_monitor()) self.add_child_widget(self.clock_widget) if not settings.should_show_plugin() and settings.get_show_clock(): self.put_on_top(self.clock_widget) self.clock_widget.start_positioning()
def maybe_update_layout(self): current_focus_monitor = utils.get_mouse_monitor() if self.last_focus_monitor == -1: self.last_focus_monitor = current_focus_monitor return if self.unlock_dialog and current_focus_monitor != self.last_focus_monitor: self.last_focus_monitor = current_focus_monitor self.overlay.queue_resize()
def maybe_update_layout(self): """ Called on all user events, moves widgets to the currently focused monitor if it changes (whichever monitor the mouse is in) """ current_focus_monitor = utils.get_mouse_monitor() if self.last_focus_monitor == -1: self.last_focus_monitor = current_focus_monitor return if self.unlock_dialog and current_focus_monitor != self.last_focus_monitor: self.last_focus_monitor = current_focus_monitor self.overlay.queue_resize()
def setup_albumart(self): """ Construct the AlbumArt widget and add it to the overlay, but only actually show it if we're a) Not running a plug-in, and b) The user wants it via preferences. Initially invisible, regardless - its visibility is controlled via its own positioning timer. """ self.albumart_widget = AlbumArt(self.screen, self.away_message, utils.get_mouse_monitor()) self.add_child_widget(self.albumart_widget) self.floaters.append(self.clock_widget) if not settings.should_show_plugin() and settings.get_show_albumart(): self.albumart_widget.start_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 = utils.get_mouse_monitor() monitor_rect = self.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) - (nat_rect.width / 2) allocation.y = monitor_rect.y + (monitor_rect.height / 2) - (nat_rect.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() current_monitor = child.current_monitor 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. """ if isinstance(child, ClockWidget): child.set_halign(Gtk.Align.START) else: child.set_halign(Gtk.Align.END) child.set_valign(Gtk.Align.CENTER) current_monitor = utils.get_mouse_monitor() else: 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) monitor_rect = self.screen.get_monitor_geometry(current_monitor) allocation.width = nat_rect.width allocation.height = nat_rect.height halign = child.get_halign() valign = child.get_valign() if halign == Gtk.Align.START: allocation.x = monitor_rect.x elif halign == Gtk.Align.CENTER: allocation.x = monitor_rect.x + (monitor_rect.width / 2) - (nat_rect.width / 2) elif halign == Gtk.Align.END: allocation.x = monitor_rect.x + monitor_rect.width - nat_rect.width if valign == Gtk.Align.START: allocation.y = monitor_rect.y elif valign == Gtk.Align.CENTER: allocation.y = monitor_rect.y + (monitor_rect.height / 2) - (nat_rect.height / 2) elif valign == Gtk.Align.END: allocation.y = monitor_rect.y + monitor_rect.height - nat_rect.height 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 = utils.get_mouse_monitor() monitor_rect = self.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 = utils.get_mouse_monitor() monitor_rect = self.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 = utils.get_mouse_monitor() monitor_rect = self.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) - (nat_rect.width / 2) allocation.y = monitor_rect.y + (monitor_rect.height / 2) - (nat_rect.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() current_monitor = child.current_monitor 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. """ if isinstance(child, ClockWidget): child.set_halign(Gtk.Align.START) else: child.set_halign(Gtk.Align.END) child.set_valign(Gtk.Align.CENTER) current_monitor = utils.get_mouse_monitor() else: 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) monitor_rect = self.screen.get_monitor_geometry(current_monitor) allocation.width = nat_rect.width allocation.height = nat_rect.height halign = child.get_halign() valign = child.get_valign() if halign == Gtk.Align.START: allocation.x = monitor_rect.x elif halign == Gtk.Align.CENTER: allocation.x = monitor_rect.x + (monitor_rect.width / 2) - (nat_rect.width / 2) elif halign == Gtk.Align.END: allocation.x = monitor_rect.x + monitor_rect.width - nat_rect.width if valign == Gtk.Align.START: allocation.y = monitor_rect.y elif valign == Gtk.Align.CENTER: allocation.y = monitor_rect.y + (monitor_rect.height / 2) - (nat_rect.height / 2) elif valign == Gtk.Align.END: allocation.y = monitor_rect.y + monitor_rect.height - nat_rect.height # Earlier gtk versions don't appear to include css padding in their preferred-size calculation # This is true at least in 3.14 (Betsy/Jessir - is 3.16 relevant anywhere?) if not utils.have_gtk_version("3.18.0"): padding = child.get_style_context().get_padding( Gtk.StateFlags.NORMAL) if halign == Gtk.Align.START: allocation.x += padding.left elif halign == Gtk.Align.END: allocation.x -= padding.right if valign == Gtk.Align.START: allocation.y += padding.top elif valign == Gtk.Align.END: allocation.y -= 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 = utils.get_mouse_monitor() monitor_rect = self.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 = utils.get_mouse_monitor() monitor_rect = self.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): if isinstance(child, MonitorView): 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): monitor = utils.get_mouse_monitor() monitor_rect = self.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) - (nat_rect.width / 2) allocation.y = monitor_rect.y + (monitor_rect.height / 2) - (nat_rect.height / 2) return True if isinstance(child, ClockWidget): min_rect, nat_rect = child.get_preferred_size() current_monitor = child.current_monitor if status.Awake: child.set_halign(Gtk.Align.START) child.set_valign(Gtk.Align.CENTER) current_monitor = utils.get_mouse_monitor() monitor_rect = self.screen.get_monitor_geometry(current_monitor) allocation.width = nat_rect.width allocation.height = nat_rect.height halign = child.get_halign() valign = child.get_valign() if halign == Gtk.Align.START: allocation.x = monitor_rect.x elif halign == Gtk.Align.CENTER: allocation.x = monitor_rect.x + (monitor_rect.width / 2) - (nat_rect.width / 2) elif halign == Gtk.Align.END: allocation.x = monitor_rect.x + monitor_rect.width - nat_rect.width if valign == Gtk.Align.START: allocation.y = monitor_rect.y elif valign == Gtk.Align.CENTER: allocation.y = monitor_rect.y + (monitor_rect.height / 2) - (nat_rect.height / 2) elif valign == Gtk.Align.END: allocation.y = monitor_rect.y + monitor_rect.height - nat_rect.height return True if isinstance(child, AudioPanel): min_rect, nat_rect = child.get_preferred_size() if status.Awake: current_monitor = utils.get_mouse_monitor() monitor_rect = self.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): min_rect, nat_rect = child.get_preferred_size() if status.Awake: current_monitor = utils.get_mouse_monitor() monitor_rect = self.screen.get_monitor_geometry(current_monitor) allocation.x = monitor_rect.x + monitor_rect.width - nat_rect.width allocation.y = monitor_rect.y allocation.width = monitor_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