Skip to content

Commit b798ba9

Browse files
committed
cinnamon-slideshow.py: Exit when Cinnamon does.
1 parent f8bd99f commit b798ba9

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

files/usr/share/cinnamon/cinnamon-slideshow/cinnamon-slideshow.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,29 @@ def __init__(self):
5656
self.connection = None
5757
self.registration_id = 0
5858

59-
try:
60-
GLibUnix.signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self.end)
61-
except AttributeError:
62-
GLibUnix.signal_add_full(GLib.PRIORITY_DEFAULT, signal.SIGINT, self.end, None)
59+
self.cinnamon_seen = False
60+
self.cinnamon_watch_id = Gio.bus_watch_name(
61+
Gio.BusType.SESSION,
62+
"org.Cinnamon",
63+
Gio.BusNameWatcherFlags.NONE,
64+
self.on_cinnamon_appeared,
65+
self.on_cinnamon_vanished
66+
)
67+
68+
for sig in (signal.SIGINT, signal.SIGTERM):
69+
try:
70+
GLibUnix.signal_add(GLib.PRIORITY_DEFAULT, sig, self.end)
71+
except AttributeError:
72+
GLibUnix.signal_add_full(GLib.PRIORITY_DEFAULT, sig, self.end, None)
73+
74+
def on_cinnamon_appeared(self, connection, name, name_owner):
75+
self.cinnamon_seen = True
76+
77+
def on_cinnamon_vanished(self, connection, name):
78+
# Cinnamon owns org.Cinnamon; if it goes away (logout, crash, replace)
79+
# this orphaned service should exit too, since nothing else will stop it.
80+
if self.cinnamon_seen:
81+
self.end()
6382

6483
def do_startup(self):
6584
Gio.Application.do_startup(self)
@@ -128,6 +147,10 @@ def end(self):
128147
GLib.source_remove(self.update_id)
129148
self.update_id = 0
130149

150+
if self.cinnamon_watch_id > 0:
151+
Gio.bus_unwatch_name(self.cinnamon_watch_id)
152+
self.cinnamon_watch_id = 0
153+
131154
self.disconnect_folder_monitor()
132155
self.quit()
133156

0 commit comments

Comments
 (0)