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 "gdkapplaunchcontext.h"
26 #include "gdkinternals.h"
27 #include "gdkscreen.h"
32 static void gdk_app_launch_context_finalize (GObject *object);
33 static gchar * gdk_app_launch_context_get_display (GAppLaunchContext *context,
38 G_DEFINE_TYPE (GdkAppLaunchContext, gdk_app_launch_context,
39 G_TYPE_APP_LAUNCH_CONTEXT)
42 gdk_app_launch_context_class_init (GdkAppLaunchContextClass *klass)
44 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
45 GAppLaunchContextClass *context_class = G_APP_LAUNCH_CONTEXT_CLASS (klass);
47 gobject_class->finalize = gdk_app_launch_context_finalize;
49 context_class->get_display = gdk_app_launch_context_get_display;
50 context_class->get_startup_notify_id = _gdk_windowing_get_startup_notify_id;
51 context_class->launch_failed = _gdk_windowing_launch_failed;
53 g_type_class_add_private (klass, sizeof (GdkAppLaunchContextPrivate));
57 gdk_app_launch_context_init (GdkAppLaunchContext *context)
59 context->priv = G_TYPE_INSTANCE_GET_PRIVATE (context,
60 GDK_TYPE_APP_LAUNCH_CONTEXT,
61 GdkAppLaunchContextPrivate);
62 context->priv->workspace = -1;
66 gdk_app_launch_context_finalize (GObject *object)
68 GdkAppLaunchContext *context;
69 GdkAppLaunchContextPrivate *priv;
71 context = GDK_APP_LAUNCH_CONTEXT (object);
76 g_object_unref (priv->display);
79 g_object_unref (priv->screen);
82 g_object_unref (priv->icon);
84 g_free (priv->icon_name);
86 G_OBJECT_CLASS (gdk_app_launch_context_parent_class)->finalize (object);
90 gdk_app_launch_context_get_display (GAppLaunchContext *context,
95 GdkAppLaunchContextPrivate *priv;
97 priv = GDK_APP_LAUNCH_CONTEXT (context)->priv;
100 return gdk_screen_make_display_name (priv->screen);
103 display = priv->display;
105 display = gdk_display_get_default ();
107 return g_strdup (gdk_display_get_name (display));
111 * gdk_app_launch_context_set_display:
112 * @context: a #GdkAppLaunchContext
113 * @display: a #GdkDisplay
115 * Sets the display on which applications will be launched when
116 * using this context. See also gdk_app_launch_context_set_screen().
121 gdk_app_launch_context_set_display (GdkAppLaunchContext *context,
124 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
125 g_return_if_fail (display == NULL || GDK_IS_DISPLAY (display));
127 if (context->priv->display)
129 g_object_unref (context->priv->display);
130 context->priv->display = NULL;
134 context->priv->display = g_object_ref (display);
138 * gdk_app_launch_context_set_screen:
139 * @context: a #GdkAppLaunchContext
140 * @screen: a #GdkScreen
142 * Sets the screen on which applications will be launched when
143 * using this context. See also gdk_app_launch_context_set_display().
145 * If both @screen and @display are set, the @screen takes priority.
146 * If neither @screen or @display are set, the default screen and
152 gdk_app_launch_context_set_screen (GdkAppLaunchContext *context,
155 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
156 g_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen));
158 if (context->priv->screen)
160 g_object_unref (context->priv->screen);
161 context->priv->screen = NULL;
165 context->priv->screen = g_object_ref (screen);
169 * gdk_app_launch_context_set_desktop:
170 * @context: a #GdkAppLaunchContext
171 * @desktop: the number of a workspace, or -1
173 * Sets the workspace on which applications will be launched when
174 * using this context when running under a window manager that
175 * supports multiple workspaces, as described in the
176 * <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
177 * Window Manager Hints</ulink>.
179 * When the workspace is not specified or @desktop is set to -1,
180 * it is up to the window manager to pick one, typically it will
181 * be the current workspace.
186 gdk_app_launch_context_set_desktop (GdkAppLaunchContext *context,
189 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
191 context->priv->workspace = desktop;
195 * gdk_app_launch_context_set_timestamp:
196 * @context: a #GdkAppLaunchContext
197 * @timestamp: a timestamp
199 * Sets the timestamp of @context. The timestamp should ideally
200 * be taken from the event that triggered the launch.
202 * Window managers can use this information to avoid moving the
203 * focus to the newly launched application when the user is busy
204 * typing in another window. This is also known as 'focus stealing
210 gdk_app_launch_context_set_timestamp (GdkAppLaunchContext *context,
213 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
215 context->priv->timestamp = timestamp;
219 * gdk_app_launch_context_set_icon:
220 * @context: a #GdkAppLaunchContext
221 * @icon: a #GIcon, or %NULL
223 * Sets the icon for applications that are launched with this
226 * Window Managers can use this information when displaying startup
229 * See also gdk_app_launch_context_set_icon_name().
234 gdk_app_launch_context_set_icon (GdkAppLaunchContext *context,
237 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
238 g_return_if_fail (icon == NULL || G_IS_ICON (icon));
240 if (context->priv->icon)
242 g_object_unref (context->priv->icon);
243 context->priv->icon = NULL;
247 context->priv->icon = g_object_ref (icon);
251 * gdk_app_launch_context_set_icon_name:
252 * @context: a #GdkAppLaunchContext
253 * @icon_name: an icon name, or %NULL
255 * Sets the icon for applications that are launched with this context.
256 * The @icon_name will be interpreted in the same way as the Icon field
257 * in desktop files. See also gdk_app_launch_context_set_icon().
259 * If both @icon and @icon_name are set, the @icon_name takes priority.
260 * If neither @icon or @icon_name is set, the icon is taken from either
261 * the file that is passed to launched application or from the #GAppInfo
262 * for the launched application itself.
267 gdk_app_launch_context_set_icon_name (GdkAppLaunchContext *context,
268 const char *icon_name)
270 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
272 g_free (context->priv->icon_name);
273 context->priv->icon_name = g_strdup (icon_name);
277 * gdk_app_launch_context_new:
279 * Creates a new #GdkAppLaunchContext.
281 * Returns: a new #GdkAppLaunchContext
285 GdkAppLaunchContext *
286 gdk_app_launch_context_new (void)
288 return g_object_new (GDK_TYPE_APP_LAUNCH_CONTEXT, NULL);
291 #define __GDK_APP_LAUNCH_CONTEXT_C__
292 #include "gdkaliasdef.c"