Description: Fix budgie-panel hang when USB inserted Occasionally popover for dropby sticks in the open position. Author: David Mohammed Bug-Ubuntu: https://bugs.launchpad.net/bugs/1771606 Origin: upstream commits 2907237e2ca5a7292de38f67ad12ed7aa1a18ad9 f24ac719c569df23f7559d5ee5e67a507438ec3d Last-Update: 2018-05-16 Reviewed-By: David Mohammed --- budgie-extras-0.4.4.orig/budgie-dropby/budgie_dropby.py +++ budgie-extras-0.4.4/budgie-dropby/budgie_dropby.py @@ -7,6 +7,7 @@ import os import dropby_tools as db import subprocess import psutil +from threading import Thread """ @@ -95,25 +96,31 @@ class BudgieDropByApplet(Budgie.Applet): self.popover = Budgie.Popover.new(self.box) # grid to contain all the stuff self.maingrid = Gtk.Grid() - # setup bindings + # throw it in popover + self.popover.add(self.maingrid) + self.popover.get_child().show_all() + self.box.show_all() + self.show_all() + self.box.connect("button-press-event", self.on_press) + # thread + GObject.threads_init() + self.update = Thread(target=self.setup_watching) + # daemonize the thread to make the indicator stopable + self.update.setDaemon(True) + self.update.start() + self.refresh_from_idle() + + def setup_watching(self): self.watchdrives = Gio.VolumeMonitor.get() self.triggers = [ "volume_added", "volume_removed", "mount_added", "mount_removed", ] for t in self.triggers: - self.watchdrives.connect(t, self.refresh) + self.watchdrives.connect(t, self.refresh_from_idle) # workaround to only open nautilus on our own action self.act_onmount = False # make the applet pop up on the event of a new volume self.watchdrives.connect("volume_added", self.on_event, self.box) - # initial situation - self.refresh() - # throw it in popover - self.popover.add(self.maingrid) - self.popover.get_child().show_all() - self.box.show_all() - self.show_all() - self.box.connect("button-press-event", self.on_press) def do_get_settings_ui(self): """Return the applet settings with given uuid""" @@ -194,6 +201,12 @@ class BudgieDropByApplet(Budgie.Applet): ) self.set_spacers() + def refresh_from_idle(self, subject=None, newvol=None): + GObject.idle_add( + self.refresh, subject, newvol, + priority=GObject.PRIORITY_DEFAULT, + ) + def refresh(self, subject=None, newvol=None): # empty grid for c in self.maingrid.get_children(): @@ -247,12 +260,22 @@ class BudgieDropByApplet(Budgie.Applet): except psutil.NoSuchProcess: return False + def scrs_active_check(self): + return "screensaver is inactive" in subprocess.check_output([ + "gnome-screensaver-command", "-q" + ]).decode("utf-8") + def on_event(self, box, *args): - if not self.lockscreen_check(): - self.manager.show_popover(self.box) + if all([ + not self.lockscreen_check(), self.scrs_active_check() + ]): + GObject.idle_add( + self.manager.show_popover, self.box, + priority=GObject.PRIORITY_DEFAULT, + ) def on_press(self, box, arg): - self.refresh() + self.refresh_from_idle() self.manager.show_popover(self.box) def do_update_popovers(self, manager):