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
=== modified file 'spectlib/main.py'
--- spectlib/main.py 2009-12-16 18:47:16 +0000
+++ spectlib/main.py 2009-12-26 20:16:12 +0000
@@ -29,6 +29,7 @@
2929
30import os30import os
31import sys31import sys
32import signal
32import gobject33import gobject
33import gettext34import gettext
3435
@@ -136,7 +137,24 @@
136 if self.GTK:137 if self.GTK:
137 for watch in self.watch_db:138 for watch in self.watch_db:
138 self.notifier.add_notifier_entry(watch.id)139 self.notifier.add_notifier_entry(watch.id)
139140
141 # Listen for USR1. If received, answer and show the window
142 def listen_for_USR1(signum, frame):
143 f = open(self.SPECTO_DIR + "/" + "specto.pid.boot")
144 pid = int(f.readline())
145 f.close()
146 os.kill(pid, signal.SIGUSR1)
147 # If window was not shown, make it appear
148 if not self.notifier.get_state():
149 self.logger.log("Showing window, the user ran another instance of specto", "debug", "specto")
150 self.toggle_notifier()
151 else:
152 # Based on http://www.pygtk.org/docs/pygtk/class-gtkwindow.html#method-gtkwindow--present
153 self.logger.log("Window is already visible! Raising it to the front.", "debug", "specto")
154 self.notifier.notifier.present()
155
156 signal.signal(signal.SIGUSR1, listen_for_USR1)
157
140 self.notifier.refresh_all_watches()158 self.notifier.refresh_all_watches()
141 else:159 else:
142 self.console.start_watches()160 self.console.start_watches()
@@ -213,7 +231,34 @@
213 p_name = os.popen("ps -f --pid " + pid).read()231 p_name = os.popen("ps -f --pid " + pid).read()
214 if p == 0 and "specto" in p_name:232 if p == 0 and "specto" in p_name:
215 if self.GTK:233 if self.GTK:
216 self.already_running_dialog()234 # Save our pid and prepare a 'pong' system
235 f = open(pidfile + ".boot", "w")
236 f.write(str(os.getpid()))
237 f.close()
238
239 def not_responding(signum, frame):
240 """ Launch the already running dialog if the
241 other instance doesn't respond """
242 os.unlink(pidfile + ".boot")
243 self.already_running_dialog()
244
245 def response_received(signum, frame):
246 """ Kill this specto if the other one answers """
247 signal.alarm(0)
248 os.unlink(pidfile + ".boot")
249 self.logger.log("Specto is already running! The old instance will be brought to front.", "debug", "specto")
250 sys.exit(0)
251
252 signal.signal(signal.SIGALRM, not_responding)
253 signal.signal(signal.SIGUSR1, response_received)
254 signal.alarm(5)
255
256 # Send signal to raise window
257 os.kill(int(pid), signal.SIGUSR1)
258
259 # Wait for signals
260 signal.pause()
261
217 return True262 return True
218 elif DEBUG:263 elif DEBUG:
219 self.logger.log(_("Specto is already running!"), "critical", "specto")264 self.logger.log(_("Specto is already running!"), "critical", "specto")

Subscribers

People subscribed via source and target branches