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>
27 #include "gdkapplaunchcontext.h"
28 #include "gdkinternals.h"
29 #include "gdkscreen.h"
34 G_DEFINE_TYPE (GdkAppLaunchContext, gdk_app_launch_context,
35 G_TYPE_APP_LAUNCH_CONTEXT);
38 gdk_app_launch_context_finalize (GObject *object)
40 GdkAppLaunchContext *context;
41 GdkAppLaunchContextPrivate *priv;
43 context = GDK_APP_LAUNCH_CONTEXT (object);
48 g_object_unref (priv->display);
51 g_object_unref (priv->screen);
54 g_object_unref (priv->icon);
56 g_free (priv->icon_name);
58 G_OBJECT_CLASS (gdk_app_launch_context_parent_class)->finalize (object);
62 get_display (GAppLaunchContext *context,
67 GdkAppLaunchContextPrivate *priv;
69 priv = GDK_APP_LAUNCH_CONTEXT (context)->priv;
72 return gdk_screen_make_display_name (priv->screen);
75 display = priv->display;
77 display = gdk_display_get_default ();
79 return g_strdup (gdk_display_get_name (display));
83 gdk_app_launch_context_class_init (GdkAppLaunchContextClass *klass)
85 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
86 GAppLaunchContextClass *context_class = G_APP_LAUNCH_CONTEXT_CLASS (klass);
88 gobject_class->finalize = gdk_app_launch_context_finalize;
90 context_class->get_display = get_display;
91 context_class->get_startup_notify_id = _gdk_windowing_get_startup_notify_id;
92 context_class->launch_failed = _gdk_windowing_launch_failed;
94 g_type_class_add_private (klass, sizeof (GdkAppLaunchContextPrivate));
98 gdk_app_launch_context_init (GdkAppLaunchContext *context)
100 context->priv = G_TYPE_INSTANCE_GET_PRIVATE (context,
101 GDK_TYPE_APP_LAUNCH_CONTEXT,
102 GdkAppLaunchContextPrivate);
103 context->priv->workspace = -1;
107 * gdk_app_launch_context_set_display:
108 * @context: a #GdkAppLaunchContext
109 * @display: a #GdkDisplay
111 * Sets the display on which applications will be launched when
112 * using this context. See also gdk_app_launch_context_set_screen().
117 gdk_app_launch_context_set_display (GdkAppLaunchContext *context,
120 if (context->priv->display)
122 g_object_unref (context->priv->display);
123 context->priv->display = NULL;
127 context->priv->display = g_object_ref (display);
131 * gdk_app_launch_context_set_screen:
132 * @context: a #GdkAppLaunchContext
133 * @screen: a #GdkScreen
135 * Sets the screen on which applications will be launched when
136 * using this context. See also gdk_app_launch_context_set_display().
138 * If both @screen and @display are set, the @screen takes priority.
139 * If neither @screen or @display are set, the default screen and
145 gdk_app_launch_context_set_screen (GdkAppLaunchContext *context,
148 if (context->priv->screen)
150 g_object_unref (context->priv->screen);
151 context->priv->screen = NULL;
155 context->priv->screen = g_object_ref (screen);
159 * gdk_app_launch_context_set_desktop:
160 * @context: a #GdkAppLaunchContext
161 * @desktop: the number of a workspace, or -1
163 * Sets the workspace on which applications will be launched when
164 * using this context when running under a window manager that
165 * supports multiple workspaces, as described in the
166 * <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
167 * Window Manager Hints</ulink>.
169 * When the workspace is not specified or @desktop is set to -1,
170 * it is up to the window manager to pick one, typically it will
171 * be the current workspace.
176 gdk_app_launch_context_set_desktop (GdkAppLaunchContext *context,
179 context->priv->workspace = desktop;
183 * gdk_app_launch_context_set_timestamp:
184 * @context: a #GdkAppLaunchContext
185 * @timestamp: a timestamp
187 * Sets the timestamp of @context. The timestamp should ideally
188 * be taken from the event that triggered the launch.
190 * Window managers can use this information to avoid moving the
191 * focus to the newly launched application when the user is busy
192 * typing in another window. This is also known as 'focus stealing
198 gdk_app_launch_context_set_timestamp (GdkAppLaunchContext *context,
201 context->priv->timestamp = timestamp;
205 * gdk_app_launch_context_set_icon:
206 * @context: a #GdkAppLaunchContext
207 * @icon: a #GIcon, or %NULL
209 * Sets the icon for applications that are launched with this
210 * context. See also gdk_app_launch_context_set_icon_name().
215 gdk_app_launch_context_set_icon (GdkAppLaunchContext *context,
218 if (context->priv->icon)
220 g_object_unref (context->priv->icon);
221 context->priv->icon = NULL;
225 context->priv->icon = g_object_ref (icon);
229 * gdk_app_launch_context_set_icon_name:
230 * @context: a #GdkAppLaunchContext
231 * @icon_name: an icon name, or %NULL
233 * Sets the icon for applications that are launched with this context.
234 * The @icon_name will be interpreted in the same way as the Icon field
235 * in desktop files. See also gdk_app_launch_context_set_icon().
237 * If both @icon and @icon_name are set, the @icon_name takes priority.
238 * If neither @icon or @icon_name is set, the icon is taken from either
239 * the file that is passed to launched application or from the #GAppInfo
240 * for the launched application itself.
245 gdk_app_launch_context_set_icon_name (GdkAppLaunchContext *context,
246 const char *icon_name)
248 g_free (context->priv->icon_name);
249 context->priv->icon_name = g_strdup (icon_name);
253 * gdk_app_launch_context_new:
255 * Creates a new #GdkAppLaunchContext.
257 * Returns: a new #GdkAppLaunchContext
261 GdkAppLaunchContext *
262 gdk_app_launch_context_new (void)
264 GdkAppLaunchContext *context;
266 context = g_object_new (gdk_app_launch_context_get_type (), NULL);
272 #define __GDK_APP_LAUNCH_CONTEXT_C__
273 #include "gdkaliasdef.c"