Merge lp:~turl/specto/raise-window-if-running into lp:specto

Proposed by Emilio
Status: Merged
Merged at revision: not available
Proposed branch: lp:~turl/specto/raise-window-if-running
Merge into: lp:specto
Diff against target: 73 lines (+47/-2)
1 file modified
spectlib/main.py (+47/-2)
To merge this branch: bzr merge lp:~turl/specto/raise-window-if-running
Reviewer Review Type Date Requested Status
Jeff Fortin Tam Needs Fixing
Specto development Pending
Review via email: mp+16302@code.launchpad.net
To post a comment you must log in.
142. By Emilio

Some cosmetic fixes.

Revision history for this message
Jeff Fortin Tam (kiddo) wrote :

Sadly, it doesn't work. My test method:
1) ./launch.sh in specto's main branch, or the PPA version, or any branch
2) ./launch.sh in the raise-window-if-running branch

Results:
- it never raises the window (even if it's on the same workspace). At least not with Compiz, haven't tested with Mutter or Metacity.
- it seems to "think" for a few seconds, and then ends up showing the "already running" dialog
- it sometimes exists/kills the existing window!

So, needs further testing and fixing before this can be merged!

review: Needs Fixing
143. By Emilio

Really raise the window if it was already opened but hidden by another window when launching another instance of specto.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'spectlib/main.py'
2--- spectlib/main.py 2009-12-16 18:47:16 +0000
3+++ spectlib/main.py 2009-12-26 20:16:12 +0000
4@@ -29,6 +29,7 @@
5
6 import os
7 import sys
8+import signal
9 import gobject
10 import gettext
11
12@@ -136,7 +137,24 @@
13 if self.GTK:
14 for watch in self.watch_db:
15 self.notifier.add_notifier_entry(watch.id)
16-
17+
18+ # Listen for USR1. If received, answer and show the window
19+ def listen_for_USR1(signum, frame):
20+ f = open(self.SPECTO_DIR + "/" + "specto.pid.boot")
21+ pid = int(f.readline())
22+ f.close()
23+ os.kill(pid, signal.SIGUSR1)
24+ # If window was not shown, make it appear
25+ if not self.notifier.get_state():
26+ self.logger.log("Showing window, the user ran another instance of specto", "debug", "specto")
27+ self.toggle_notifier()
28+ else:
29+ # Based on http://www.pygtk.org/docs/pygtk/class-gtkwindow.html#method-gtkwindow--present
30+ self.logger.log("Window is already visible! Raising it to the front.", "debug", "specto")
31+ self.notifier.notifier.present()
32+
33+ signal.signal(signal.SIGUSR1, listen_for_USR1)
34+
35 self.notifier.refresh_all_watches()
36 else:
37 self.console.start_watches()
38@@ -213,7 +231,34 @@
39 p_name = os.popen("ps -f --pid " + pid).read()
40 if p == 0 and "specto" in p_name:
41 if self.GTK:
42- self.already_running_dialog()
43+ # Save our pid and prepare a 'pong' system
44+ f = open(pidfile + ".boot", "w")
45+ f.write(str(os.getpid()))
46+ f.close()
47+
48+ def not_responding(signum, frame):
49+ """ Launch the already running dialog if the
50+ other instance doesn't respond """
51+ os.unlink(pidfile + ".boot")
52+ self.already_running_dialog()
53+
54+ def response_received(signum, frame):
55+ """ Kill this specto if the other one answers """
56+ signal.alarm(0)
57+ os.unlink(pidfile + ".boot")
58+ self.logger.log("Specto is already running! The old instance will be brought to front.", "debug", "specto")
59+ sys.exit(0)
60+
61+ signal.signal(signal.SIGALRM, not_responding)
62+ signal.signal(signal.SIGUSR1, response_received)
63+ signal.alarm(5)
64+
65+ # Send signal to raise window
66+ os.kill(int(pid), signal.SIGUSR1)
67+
68+ # Wait for signals
69+ signal.pause()
70+
71 return True
72 elif DEBUG:
73 self.logger.log(_("Specto is already running!"), "critical", "specto")

Subscribers

People subscribed via source and target branches