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 this library. If not, see <http://www.gnu.org/licenses/>.
18 Author: Alexander Larsson <alexl@redhat.com>
23 #include "gdkapplaunchcontextprivate.h"
24 #include "gdkscreen.h"
29 * SECTION:gdkapplaunchcontext
30 * @Short_description: Startup notification for applications
31 * @Title: Application launching
33 * GdkAppLaunchContext is an implementation of #GAppLaunchContext that
34 * handles launching an application in a graphical context. It provides
35 * startup notification and allows to launch applications on a specific
36 * screen or workspace.
38 * <title>Launching an application</title>
41 * GdkAppLaunchContext *context;
43 * context = gdk_display_get_app_launch_context (display);
45 * gdk_app_launch_context_set_screen (screen);
46 * gdk_app_launch_context_set_timestamp (event->time);
48 * if (!g_app_info_launch_default_for_uri ("http://www.gtk.org", context, &error))
49 * g_warning ("Launching failed: %s\n", error->message);
51 * g_object_unref (context);
58 static void gdk_app_launch_context_finalize (GObject *object);
59 static gchar * gdk_app_launch_context_get_display (GAppLaunchContext *context,
62 static gchar * gdk_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
65 static void gdk_app_launch_context_launch_failed (GAppLaunchContext *context,
66 const gchar *startup_notify_id);
75 G_DEFINE_TYPE (GdkAppLaunchContext, gdk_app_launch_context, G_TYPE_APP_LAUNCH_CONTEXT)
78 gdk_app_launch_context_get_property (GObject *object,
83 GdkAppLaunchContext *context = GDK_APP_LAUNCH_CONTEXT (object);
88 g_value_set_object (value, context->display);
91 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
96 gdk_app_launch_context_set_property (GObject *object,
101 GdkAppLaunchContext *context = GDK_APP_LAUNCH_CONTEXT (object);
106 context->display = g_value_dup_object (value);
109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
114 gdk_app_launch_context_class_init (GdkAppLaunchContextClass *klass)
116 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
117 GAppLaunchContextClass *context_class = G_APP_LAUNCH_CONTEXT_CLASS (klass);
119 gobject_class->set_property = gdk_app_launch_context_set_property,
120 gobject_class->get_property = gdk_app_launch_context_get_property;
122 gobject_class->finalize = gdk_app_launch_context_finalize;
124 context_class->get_display = gdk_app_launch_context_get_display;
125 context_class->get_startup_notify_id = gdk_app_launch_context_get_startup_notify_id;
126 context_class->launch_failed = gdk_app_launch_context_launch_failed;
128 g_object_class_install_property (gobject_class, PROP_DISPLAY,
129 g_param_spec_object ("display", P_("Display"), P_("Display"),
131 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
135 gdk_app_launch_context_init (GdkAppLaunchContext *context)
137 context->workspace = -1;
141 gdk_app_launch_context_finalize (GObject *object)
143 GdkAppLaunchContext *context = GDK_APP_LAUNCH_CONTEXT (object);
145 if (context->display)
146 g_object_unref (context->display);
149 g_object_unref (context->screen);
152 g_object_unref (context->icon);
154 g_free (context->icon_name);
156 G_OBJECT_CLASS (gdk_app_launch_context_parent_class)->finalize (object);
160 gdk_app_launch_context_get_display (GAppLaunchContext *context,
164 GdkAppLaunchContext *ctx = GDK_APP_LAUNCH_CONTEXT (context);
168 return gdk_screen_make_display_name (ctx->screen);
171 display = ctx->display;
173 display = gdk_display_get_default ();
175 return g_strdup (gdk_display_get_name (display));
179 * gdk_app_launch_context_set_display:
180 * @context: a #GdkAppLaunchContext
181 * @display: a #GdkDisplay
183 * Sets the display on which applications will be launched when
184 * using this context. See also gdk_app_launch_context_set_screen().
188 * Deprecated: 3.0: Use gdk_display_get_app_launch_context() instead
191 gdk_app_launch_context_set_display (GdkAppLaunchContext *context,
194 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
195 g_return_if_fail (display == NULL || GDK_IS_DISPLAY (display));
197 g_warn_if_fail (display == NULL || display == context->display);
201 * gdk_app_launch_context_set_screen:
202 * @context: a #GdkAppLaunchContext
203 * @screen: a #GdkScreen
205 * Sets the screen on which applications will be launched when
206 * using this context. See also gdk_app_launch_context_set_display().
208 * If both @screen and @display are set, the @screen takes priority.
209 * If neither @screen or @display are set, the default screen and
215 gdk_app_launch_context_set_screen (GdkAppLaunchContext *context,
218 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
219 g_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen));
221 g_return_if_fail (screen == NULL || gdk_screen_get_display (screen) == context->display);
225 g_object_unref (context->screen);
226 context->screen = NULL;
230 context->screen = g_object_ref (screen);
234 * gdk_app_launch_context_set_desktop:
235 * @context: a #GdkAppLaunchContext
236 * @desktop: the number of a workspace, or -1
238 * Sets the workspace on which applications will be launched when
239 * using this context when running under a window manager that
240 * supports multiple workspaces, as described in the
241 * <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
242 * Window Manager Hints</ulink>.
244 * When the workspace is not specified or @desktop is set to -1,
245 * it is up to the window manager to pick one, typically it will
246 * be the current workspace.
251 gdk_app_launch_context_set_desktop (GdkAppLaunchContext *context,
254 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
256 context->workspace = desktop;
260 * gdk_app_launch_context_set_timestamp:
261 * @context: a #GdkAppLaunchContext
262 * @timestamp: a timestamp
264 * Sets the timestamp of @context. The timestamp should ideally
265 * be taken from the event that triggered the launch.
267 * Window managers can use this information to avoid moving the
268 * focus to the newly launched application when the user is busy
269 * typing in another window. This is also known as 'focus stealing
275 gdk_app_launch_context_set_timestamp (GdkAppLaunchContext *context,
278 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
280 context->timestamp = timestamp;
284 * gdk_app_launch_context_set_icon:
285 * @context: a #GdkAppLaunchContext
286 * @icon: (allow-none): a #GIcon, or %NULL
288 * Sets the icon for applications that are launched with this
291 * Window Managers can use this information when displaying startup
294 * See also gdk_app_launch_context_set_icon_name().
299 gdk_app_launch_context_set_icon (GdkAppLaunchContext *context,
302 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
303 g_return_if_fail (icon == NULL || G_IS_ICON (icon));
307 g_object_unref (context->icon);
308 context->icon = NULL;
312 context->icon = g_object_ref (icon);
316 * gdk_app_launch_context_set_icon_name:
317 * @context: a #GdkAppLaunchContext
318 * @icon_name: (allow-none): an icon name, or %NULL
320 * Sets the icon for applications that are launched with this context.
321 * The @icon_name will be interpreted in the same way as the Icon field
322 * in desktop files. See also gdk_app_launch_context_set_icon().
324 * If both @icon and @icon_name are set, the @icon_name takes priority.
325 * If neither @icon or @icon_name is set, the icon is taken from either
326 * the file that is passed to launched application or from the #GAppInfo
327 * for the launched application itself.
332 gdk_app_launch_context_set_icon_name (GdkAppLaunchContext *context,
333 const char *icon_name)
335 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
337 g_free (context->icon_name);
338 context->icon_name = g_strdup (icon_name);
342 * gdk_app_launch_context_new:
344 * Creates a new #GdkAppLaunchContext.
346 * Returns: a new #GdkAppLaunchContext
350 * Deprecated: 3.0: Use gdk_display_get_app_launch_context() instead
352 GdkAppLaunchContext *
353 gdk_app_launch_context_new (void)
355 return gdk_display_get_app_launch_context (gdk_display_get_default ());
359 gdk_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
367 gdk_app_launch_context_launch_failed (GAppLaunchContext *context,
368 const gchar *startup_notify_id)