1 /* gdkapplaunchcontext.c - Gtk+ implementation for GAppLaunchContext
3 Copyright (C) 2007 Red Hat, Inc.
5 The Gnome Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The Gnome Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the Gnome Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
20 Author: Alexander Larsson <alexl@redhat.com>
25 #include "gdkapplaunchcontextprivate.h"
26 #include "gdkscreen.h"
31 * SECTION:gdkapplaunchcontext
32 * @Short_description: Startup notification for applications
33 * @Title: Application launching
35 * GdkAppLaunchContext is an implementation of #GAppLaunchContext that
36 * handles launching an application in a graphical context. It provides
37 * startup notification and allows to launch applications on a specific
38 * screen or workspace.
40 * <title>Launching an application</title>
43 * GdkAppLaunchContext *context;
45 * context = gdk_display_get_app_launch_context (display);
47 * gdk_app_launch_context_set_screen (screen);
48 * gdk_app_launch_context_set_timestamp (event->time);
50 * if (!g_app_info_launch_default_for_uri ("http://www.gtk.org", context, &error))
51 * g_warning ("Launching failed: %s\n", error->message);
53 * g_object_unref (context);
60 static void gdk_app_launch_context_finalize (GObject *object);
61 static gchar * gdk_app_launch_context_get_display (GAppLaunchContext *context,
64 static gchar * gdk_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
67 static void gdk_app_launch_context_launch_failed (GAppLaunchContext *context,
68 const gchar *startup_notify_id);
77 G_DEFINE_TYPE (GdkAppLaunchContext, gdk_app_launch_context, G_TYPE_APP_LAUNCH_CONTEXT)
80 gdk_app_launch_context_get_property (GObject *object,
85 GdkAppLaunchContext *context = GDK_APP_LAUNCH_CONTEXT (object);
90 g_value_set_object (value, context->display);
93 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
98 gdk_app_launch_context_set_property (GObject *object,
103 GdkAppLaunchContext *context = GDK_APP_LAUNCH_CONTEXT (object);
108 context->display = g_value_dup_object (value);
111 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
116 gdk_app_launch_context_class_init (GdkAppLaunchContextClass *klass)
118 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
119 GAppLaunchContextClass *context_class = G_APP_LAUNCH_CONTEXT_CLASS (klass);
121 gobject_class->set_property = gdk_app_launch_context_set_property,
122 gobject_class->get_property = gdk_app_launch_context_get_property;
124 gobject_class->finalize = gdk_app_launch_context_finalize;
126 context_class->get_display = gdk_app_launch_context_get_display;
127 context_class->get_startup_notify_id = gdk_app_launch_context_get_startup_notify_id;
128 context_class->launch_failed = gdk_app_launch_context_launch_failed;
130 g_object_class_install_property (gobject_class, PROP_DISPLAY,
131 g_param_spec_object ("display", P_("Display"), P_("Display"),
133 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
137 gdk_app_launch_context_init (GdkAppLaunchContext *context)
139 context->workspace = -1;
143 gdk_app_launch_context_finalize (GObject *object)
145 GdkAppLaunchContext *context = GDK_APP_LAUNCH_CONTEXT (object);
147 if (context->display)
148 g_object_unref (context->display);
151 g_object_unref (context->screen);
154 g_object_unref (context->icon);
156 g_free (context->icon_name);
158 G_OBJECT_CLASS (gdk_app_launch_context_parent_class)->finalize (object);
162 gdk_app_launch_context_get_display (GAppLaunchContext *context,
166 GdkAppLaunchContext *ctx = GDK_APP_LAUNCH_CONTEXT (context);
170 return gdk_screen_make_display_name (ctx->screen);
173 display = ctx->display;
175 display = gdk_display_get_default ();
177 return g_strdup (gdk_display_get_name (display));
181 * gdk_app_launch_context_set_display:
182 * @context: a #GdkAppLaunchContext
183 * @display: a #GdkDisplay
185 * Sets the display on which applications will be launched when
186 * using this context. See also gdk_app_launch_context_set_screen().
190 * Deprecated: 3.0: Use gdk_display_get_app_launch_context() instead
193 gdk_app_launch_context_set_display (GdkAppLaunchContext *context,
196 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
197 g_return_if_fail (display == NULL || GDK_IS_DISPLAY (display));
199 g_warn_if_fail (display == NULL || display == context->display);
203 * gdk_app_launch_context_set_screen:
204 * @context: a #GdkAppLaunchContext
205 * @screen: a #GdkScreen
207 * Sets the screen on which applications will be launched when
208 * using this context. See also gdk_app_launch_context_set_display().
210 * If both @screen and @display are set, the @screen takes priority.
211 * If neither @screen or @display are set, the default screen and
217 gdk_app_launch_context_set_screen (GdkAppLaunchContext *context,
220 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
221 g_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen));
223 g_return_if_fail (screen == NULL || gdk_screen_get_display (screen) == context->display);
227 g_object_unref (context->screen);
228 context->screen = NULL;
232 context->screen = g_object_ref (screen);
236 * gdk_app_launch_context_set_desktop:
237 * @context: a #GdkAppLaunchContext
238 * @desktop: the number of a workspace, or -1
240 * Sets the workspace on which applications will be launched when
241 * using this context when running under a window manager that
242 * supports multiple workspaces, as described in the
243 * <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
244 * Window Manager Hints</ulink>.
246 * When the workspace is not specified or @desktop is set to -1,
247 * it is up to the window manager to pick one, typically it will
248 * be the current workspace.
253 gdk_app_launch_context_set_desktop (GdkAppLaunchContext *context,
256 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
258 context->workspace = desktop;
262 * gdk_app_launch_context_set_timestamp:
263 * @context: a #GdkAppLaunchContext
264 * @timestamp: a timestamp
266 * Sets the timestamp of @context. The timestamp should ideally
267 * be taken from the event that triggered the launch.
269 * Window managers can use this information to avoid moving the
270 * focus to the newly launched application when the user is busy
271 * typing in another window. This is also known as 'focus stealing
277 gdk_app_launch_context_set_timestamp (GdkAppLaunchContext *context,
280 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
282 context->timestamp = timestamp;
286 * gdk_app_launch_context_set_icon:
287 * @context: a #GdkAppLaunchContext
288 * @icon: (allow-none): a #GIcon, or %NULL
290 * Sets the icon for applications that are launched with this
293 * Window Managers can use this information when displaying startup
296 * See also gdk_app_launch_context_set_icon_name().
301 gdk_app_launch_context_set_icon (GdkAppLaunchContext *context,
304 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
305 g_return_if_fail (icon == NULL || G_IS_ICON (icon));
309 g_object_unref (context->icon);
310 context->icon = NULL;
314 context->icon = g_object_ref (icon);
318 * gdk_app_launch_context_set_icon_name:
319 * @context: a #GdkAppLaunchContext
320 * @icon_name: (allow-none): an icon name, or %NULL
322 * Sets the icon for applications that are launched with this context.
323 * The @icon_name will be interpreted in the same way as the Icon field
324 * in desktop files. See also gdk_app_launch_context_set_icon().
326 * If both @icon and @icon_name are set, the @icon_name takes priority.
327 * If neither @icon or @icon_name is set, the icon is taken from either
328 * the file that is passed to launched application or from the #GAppInfo
329 * for the launched application itself.
334 gdk_app_launch_context_set_icon_name (GdkAppLaunchContext *context,
335 const char *icon_name)
337 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
339 g_free (context->icon_name);
340 context->icon_name = g_strdup (icon_name);
344 * gdk_app_launch_context_new:
346 * Creates a new #GdkAppLaunchContext.
348 * Returns: a new #GdkAppLaunchContext
352 * Deprecated: 3.0: Use gdk_display_get_app_launch_context() instead
354 GdkAppLaunchContext *
355 gdk_app_launch_context_new (void)
357 return gdk_display_get_app_launch_context (gdk_display_get_default ());
361 gdk_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
369 gdk_app_launch_context_launch_failed (GAppLaunchContext *context,
370 const gchar *startup_notify_id)