[kupfer: 2/51] Track current GdkScreen and launch applications there



commit b4c6b3918bc95cf8297706a1477fc3258af2d44b
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Mon Mar 28 16:51:40 2011 +0200

    Track current GdkScreen and launch applications there

 kupfer/desktop_launch.py |   13 ++++++++++---
 kupfer/launch.py         |    5 +++--
 kupfer/obj/objects.py    |   12 ++++++++----
 3 files changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/kupfer/desktop_launch.py b/kupfer/desktop_launch.py
index 965a7d9..c7bb52a 100644
--- a/kupfer/desktop_launch.py
+++ b/kupfer/desktop_launch.py
@@ -252,7 +252,7 @@ def _info_for_desktop_file(desktop_file):
 	return desktop_info
 
 def launch_app_info(app_info, gfiles=[], in_terminal=None, timestamp=None,
-	                desktop_file=None, launch_cb=None):
+	                desktop_file=None, launch_cb=None, screen=None):
 	"""
 	Launch @app_info, opening @gfiles
 
@@ -315,7 +315,8 @@ def launch_app_info(app_info, gfiles=[], in_terminal=None, timestamp=None,
 				targv.append(term["exearg"])
 			argv = targv + argv
 		ret = spawn_app(app_info, argv, gfiles, workdir, notify,
-		                timestamp=timestamp, launch_cb=launch_cb)
+		                timestamp=timestamp, launch_cb=launch_cb,
+		                screen=screen)
 		if not ret:
 			return False
 	return True
@@ -332,7 +333,7 @@ def spawn_app_id(app_id, argv, workdir=None, startup_notify=True):
 	return spawn_app(app_info, argv, [], workdir, startup_notify)
 
 def spawn_app(app_info, argv, filelist, workdir=None, startup_notify=True,
-	          timestamp=None, launch_cb=None):
+	          timestamp=None, launch_cb=None, screen=None):
 	"""
 	Spawn app.
 
@@ -344,6 +345,7 @@ def spawn_app(app_info, argv, filelist, workdir=None, startup_notify=True,
 	@timestamp: Event timestamp
 	@launch_cb: Called if successful with
 	            (argv, pid, notify_id, filelist, timestamp)
+	@screen: GdkScreen on which to put the application
 
 	return pid if successful
 	raise SpawnError on error
@@ -352,12 +354,17 @@ def spawn_app(app_info, argv, filelist, workdir=None, startup_notify=True,
 	if startup_notify:
 		ctx = gtk.gdk.AppLaunchContext()
 		ctx.set_timestamp(timestamp or gtk.get_current_event_time())
+		if screen:
+			ctx.set_screen(screen)
 		# This not only returns the string ID but
 		# it actually starts the startup notification!
 		notify_id = ctx.get_startup_notify_id(app_info, filelist)
 		child_env_add = {STARTUP_ENV: notify_id}
 	else:
 		child_env_add = {}
+	if screen:
+		child_env_add["DISPLAY"]=screen.get_display().get_name()
+	debug_log(child_env_add)
 
 	if not workdir or not os.path.exists(workdir):
 		workdir = "."
diff --git a/kupfer/launch.py b/kupfer/launch.py
index 26eff41..bec99b3 100644
--- a/kupfer/launch.py
+++ b/kupfer/launch.py
@@ -42,7 +42,7 @@ def application_id(app_info, desktop_file=None):
 	return app_id
 
 def launch_application(app_info, files=(), uris=(), paths=(), track=True,
-	                   activate=True, desktop_file=None):
+	                   activate=True, desktop_file=None, screen=None):
 	"""
 	Launch @app_rec correctly, using a startup notification
 
@@ -90,7 +90,8 @@ def launch_application(app_info, files=(), uris=(), paths=(), track=True,
 		desktop_launch.launch_app_info(app_info, files,
 			   timestamp=uievents.current_event_time(),
 			   desktop_file=desktop_file,
-			   launch_cb=launch_callback)
+			   launch_cb=launch_callback,
+			   screen=screen)
 	except SpawnError:
 		raise
 	return True
diff --git a/kupfer/obj/objects.py b/kupfer/obj/objects.py
index 36ecda8..e01beb1 100644
--- a/kupfer/obj/objects.py
+++ b/kupfer/obj/objects.py
@@ -219,7 +219,7 @@ class AppLeaf (Leaf):
 	def _get_package_name(self):
 		return gobject.filename_display_basename(self.get_id())
 
-	def launch(self, files=(), paths=(), activate=False):
+	def launch(self, files=(), paths=(), activate=False, ctx=None):
 		"""
 		Launch the represented applications
 
@@ -230,7 +230,8 @@ class AppLeaf (Leaf):
 		try:
 			return launch.launch_application(self.object, files=files,
 			                                 paths=paths, activate=activate,
-			                                 desktop_file=self.init_path)
+			                                 desktop_file=self.init_path,
+			                                 screen=ctx and ctx.environment.get_screen())
 		except launch.SpawnError as exc:
 			raise OperationError(exc)
 
@@ -300,8 +301,11 @@ class Launch (Action):
 		self.is_running = is_running
 		self.open_new = open_new
 	
-	def activate(self, leaf):
-		leaf.launch(activate=not self.open_new)
+	def wants_context(self):
+		return True
+
+	def activate(self, leaf, ctx):
+		leaf.launch(activate=not self.open_new, ctx=ctx)
 
 	def get_description(self):
 		if self.is_running:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]