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"
31 static void gdk_app_launch_context_finalize (GObject *object);
32 static gchar * gdk_app_launch_context_get_display (GAppLaunchContext *context,
37 G_DEFINE_TYPE (GdkAppLaunchContext, gdk_app_launch_context,
38 G_TYPE_APP_LAUNCH_CONTEXT)
41 gdk_app_launch_context_class_init (GdkAppLaunchContextClass *klass)
43 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
44 GAppLaunchContextClass *context_class = G_APP_LAUNCH_CONTEXT_CLASS (klass);
46 gobject_class->finalize = gdk_app_launch_context_finalize;
48 context_class->get_display = gdk_app_launch_context_get_display;
49 context_class->get_startup_notify_id = _gdk_windowing_get_startup_notify_id;
50 context_class->launch_failed = _gdk_windowing_launch_failed;
52 g_type_class_add_private (klass, sizeof (GdkAppLaunchContextPrivate));
56 gdk_app_launch_context_init (GdkAppLaunchContext *context)
58 context->priv = G_TYPE_INSTANCE_GET_PRIVATE (context,
59 GDK_TYPE_APP_LAUNCH_CONTEXT,
60 GdkAppLaunchContextPrivate);
61 context->priv->workspace = -1;
65 gdk_app_launch_context_finalize (GObject *object)
67 GdkAppLaunchContext *context;
68 GdkAppLaunchContextPrivate *priv;
70 context = GDK_APP_LAUNCH_CONTEXT (object);
75 g_object_unref (priv->display);
78 g_object_unref (priv->screen);
81 g_object_unref (priv->icon);
83 g_free (priv->icon_name);
85 G_OBJECT_CLASS (gdk_app_launch_context_parent_class)->finalize (object);
89 gdk_app_launch_context_get_display (GAppLaunchContext *context,
94 GdkAppLaunchContextPrivate *priv;
96 priv = GDK_APP_LAUNCH_CONTEXT (context)->priv;
99 return gdk_screen_make_display_name (priv->screen);
102 display = priv->display;
104 display = gdk_display_get_default ();
106 return g_strdup (gdk_display_get_name (display));
110 * gdk_app_launch_context_set_display:
111 * @context: a #GdkAppLaunchContext
112 * @display: a #GdkDisplay
114 * Sets the display on which applications will be launched when
115 * using this context. See also gdk_app_launch_context_set_screen().
120 gdk_app_launch_context_set_display (GdkAppLaunchContext *context,
123 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
124 g_return_if_fail (display == NULL || GDK_IS_DISPLAY (display));
126 if (context->priv->display)
128 g_object_unref (context->priv->display);
129 context->priv->display = NULL;
133 context->priv->display = g_object_ref (display);
137 * gdk_app_launch_context_set_screen:
138 * @context: a #GdkAppLaunchContext
139 * @screen: a #GdkScreen
141 * Sets the screen on which applications will be launched when
142 * using this context. See also gdk_app_launch_context_set_display().
144 * If both @screen and @display are set, the @screen takes priority.
145 * If neither @screen or @display are set, the default screen and
151 gdk_app_launch_context_set_screen (GdkAppLaunchContext *context,
154 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
155 g_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen));
157 if (context->priv->screen)
159 g_object_unref (context->priv->screen);
160 context->priv->screen = NULL;
164 context->priv->screen = g_object_ref (screen);
168 * gdk_app_launch_context_set_desktop:
169 * @context: a #GdkAppLaunchContext
170 * @desktop: the number of a workspace, or -1
172 * Sets the workspace on which applications will be launched when
173 * using this context when running under a window manager that
174 * supports multiple workspaces, as described in the
175 * <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
176 * Window Manager Hints</ulink>.
178 * When the workspace is not specified or @desktop is set to -1,
179 * it is up to the window manager to pick one, typically it will
180 * be the current workspace.
185 gdk_app_launch_context_set_desktop (GdkAppLaunchContext *context,
188 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
190 context->priv->workspace = desktop;
194 * gdk_app_launch_context_set_timestamp:
195 * @context: a #GdkAppLaunchContext
196 * @timestamp: a timestamp
198 * Sets the timestamp of @context. The timestamp should ideally
199 * be taken from the event that triggered the launch.
201 * Window managers can use this information to avoid moving the
202 * focus to the newly launched application when the user is busy
203 * typing in another window. This is also known as 'focus stealing
209 gdk_app_launch_context_set_timestamp (GdkAppLaunchContext *context,
212 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
214 context->priv->timestamp = timestamp;
218 * gdk_app_launch_context_set_icon:
219 * @context: a #GdkAppLaunchContext
220 * @icon: (allow-none): a #GIcon, or %NULL
222 * Sets the icon for applications that are launched with this
225 * Window Managers can use this information when displaying startup
228 * See also gdk_app_launch_context_set_icon_name().
233 gdk_app_launch_context_set_icon (GdkAppLaunchContext *context,
236 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
237 g_return_if_fail (icon == NULL || G_IS_ICON (icon));
239 if (context->priv->icon)
241 g_object_unref (context->priv->icon);
242 context->priv->icon = NULL;
246 context->priv->icon = g_object_ref (icon);
250 * gdk_app_launch_context_set_icon_name:
251 * @context: a #GdkAppLaunchContext
252 * @icon_name: (allow-none): an icon name, or %NULL
254 * Sets the icon for applications that are launched with this context.
255 * The @icon_name will be interpreted in the same way as the Icon field
256 * in desktop files. See also gdk_app_launch_context_set_icon().
258 * If both @icon and @icon_name are set, the @icon_name takes priority.
259 * If neither @icon or @icon_name is set, the icon is taken from either
260 * the file that is passed to launched application or from the #GAppInfo
261 * for the launched application itself.
266 gdk_app_launch_context_set_icon_name (GdkAppLaunchContext *context,
267 const char *icon_name)
269 g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
271 g_free (context->priv->icon_name);
272 context->priv->icon_name = g_strdup (icon_name);
276 * gdk_app_launch_context_new:
278 * Creates a new #GdkAppLaunchContext.
280 * Returns: a new #GdkAppLaunchContext
284 GdkAppLaunchContext *
285 gdk_app_launch_context_new (void)
287 return g_object_new (GDK_TYPE_APP_LAUNCH_CONTEXT, NULL);