]> Pileus Git - ~andy/gtk/blob - gdk/gdkapplaunchcontext.c
aa37ca7fc6cb9cf474e363b193e2d5e8532a0f8b
[~andy/gtk] / gdk / gdkapplaunchcontext.c
1 /* gdkapplaunchcontext.c - Gtk+ implementation for GAppLaunchContext
2
3    Copyright (C) 2007 Red Hat, Inc.
4
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.
9
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.
14
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.
19
20    Author: Alexander Larsson <alexl@redhat.com>
21 */
22
23 #include "config.h"
24
25 #include "gdkapplaunchcontext.h"
26 #include "gdkinternals.h"
27 #include "gdkscreen.h"
28 #include "gdkintl.h"
29
30
31 static void    gdk_app_launch_context_finalize    (GObject           *object);
32 static gchar * gdk_app_launch_context_get_display (GAppLaunchContext *context,
33                                                    GAppInfo          *info,
34                                                    GList             *files);
35
36
37 G_DEFINE_TYPE (GdkAppLaunchContext, gdk_app_launch_context,
38                G_TYPE_APP_LAUNCH_CONTEXT)
39
40 static void
41 gdk_app_launch_context_class_init (GdkAppLaunchContextClass *klass)
42 {
43   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
44   GAppLaunchContextClass *context_class = G_APP_LAUNCH_CONTEXT_CLASS (klass);
45
46   gobject_class->finalize = gdk_app_launch_context_finalize;
47
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;
51
52   g_type_class_add_private (klass, sizeof (GdkAppLaunchContextPrivate));
53 }
54
55 static void
56 gdk_app_launch_context_init (GdkAppLaunchContext *context)
57 {
58   context->priv = G_TYPE_INSTANCE_GET_PRIVATE (context,
59                                                GDK_TYPE_APP_LAUNCH_CONTEXT,
60                                                GdkAppLaunchContextPrivate);
61   context->priv->workspace = -1;
62 }
63
64 static void
65 gdk_app_launch_context_finalize (GObject *object)
66 {
67   GdkAppLaunchContext *context;
68   GdkAppLaunchContextPrivate *priv;
69
70   context = GDK_APP_LAUNCH_CONTEXT (object);
71
72   priv = context->priv;
73
74   if (priv->display)
75     g_object_unref (priv->display);
76
77   if (priv->screen)
78     g_object_unref (priv->screen);
79
80   if (priv->icon)
81     g_object_unref (priv->icon);
82
83   g_free (priv->icon_name);
84
85   G_OBJECT_CLASS (gdk_app_launch_context_parent_class)->finalize (object);
86 }
87
88 static gchar *
89 gdk_app_launch_context_get_display (GAppLaunchContext *context,
90                                     GAppInfo          *info,
91                                     GList             *files)
92 {
93   GdkDisplay *display;
94   GdkAppLaunchContextPrivate *priv;
95
96   priv = GDK_APP_LAUNCH_CONTEXT (context)->priv;
97
98   if (priv->screen)
99     return gdk_screen_make_display_name (priv->screen);
100
101   if (priv->display)
102     display = priv->display;
103   else
104     display = gdk_display_get_default ();
105
106   return g_strdup (gdk_display_get_name (display));
107 }
108
109 /**
110  * gdk_app_launch_context_set_display:
111  * @context: a #GdkAppLaunchContext
112  * @display: a #GdkDisplay
113  *
114  * Sets the display on which applications will be launched when
115  * using this context. See also gdk_app_launch_context_set_screen().
116  *
117  * Since: 2.14
118  */
119 void
120 gdk_app_launch_context_set_display (GdkAppLaunchContext *context,
121                                     GdkDisplay          *display)
122 {
123   g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
124   g_return_if_fail (display == NULL || GDK_IS_DISPLAY (display));
125
126   if (context->priv->display)
127     {
128       g_object_unref (context->priv->display);
129       context->priv->display = NULL;
130     }
131
132   if (display)
133     context->priv->display = g_object_ref (display);
134 }
135
136 /**
137  * gdk_app_launch_context_set_screen:
138  * @context: a #GdkAppLaunchContext
139  * @screen: a #GdkScreen
140  *
141  * Sets the screen on which applications will be launched when
142  * using this context. See also gdk_app_launch_context_set_display().
143  *
144  * If both @screen and @display are set, the @screen takes priority.
145  * If neither @screen or @display are set, the default screen and
146  * display are used.
147  *
148  * Since: 2.14
149  */
150 void
151 gdk_app_launch_context_set_screen (GdkAppLaunchContext *context,
152                                    GdkScreen           *screen)
153 {
154   g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
155   g_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen));
156
157   if (context->priv->screen)
158     {
159       g_object_unref (context->priv->screen);
160       context->priv->screen = NULL;
161     }
162
163   if (screen)
164     context->priv->screen = g_object_ref (screen);
165 }
166
167 /**
168  * gdk_app_launch_context_set_desktop:
169  * @context: a #GdkAppLaunchContext
170  * @desktop: the number of a workspace, or -1
171  *
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>. 
177  *
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.
181  *
182  * Since: 2.14
183  */
184 void
185 gdk_app_launch_context_set_desktop (GdkAppLaunchContext *context,
186                                     gint                 desktop)
187 {
188   g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
189
190   context->priv->workspace = desktop;
191 }
192
193 /**
194  * gdk_app_launch_context_set_timestamp:
195  * @context: a #GdkAppLaunchContext
196  * @timestamp: a timestamp
197  *
198  * Sets the timestamp of @context. The timestamp should ideally
199  * be taken from the event that triggered the launch. 
200  *
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
204  * prevention'.
205  *
206  * Since: 2.14
207  */
208 void
209 gdk_app_launch_context_set_timestamp (GdkAppLaunchContext *context,
210                                       guint32              timestamp)
211 {
212   g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
213
214   context->priv->timestamp = timestamp;
215 }
216
217 /**
218  * gdk_app_launch_context_set_icon:
219  * @context: a #GdkAppLaunchContext
220  * @icon: (allow-none): a #GIcon, or %NULL
221  *
222  * Sets the icon for applications that are launched with this
223  * context.
224  *
225  * Window Managers can use this information when displaying startup
226  * notification.
227  *
228  * See also gdk_app_launch_context_set_icon_name().
229  *
230  * Since: 2.14
231  */
232 void
233 gdk_app_launch_context_set_icon (GdkAppLaunchContext *context,
234                                  GIcon               *icon)
235 {
236   g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
237   g_return_if_fail (icon == NULL || G_IS_ICON (icon));
238
239   if (context->priv->icon)
240     {
241       g_object_unref (context->priv->icon);
242       context->priv->icon = NULL;
243     }
244
245   if (icon)
246     context->priv->icon = g_object_ref (icon);
247 }
248
249 /**
250  * gdk_app_launch_context_set_icon_name:
251  * @context: a #GdkAppLaunchContext
252  * @icon_name: (allow-none): an icon name, or %NULL
253  *
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(). 
257  *
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.
262  * 
263  * Since: 2.14
264  */
265 void
266 gdk_app_launch_context_set_icon_name (GdkAppLaunchContext *context,
267                                       const char          *icon_name)
268 {
269   g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
270
271   g_free (context->priv->icon_name);
272   context->priv->icon_name = g_strdup (icon_name);
273 }
274
275 /**
276  * gdk_app_launch_context_new:
277  *
278  * Creates a new #GdkAppLaunchContext.
279  *
280  * Returns: a new #GdkAppLaunchContext
281  *
282  * Since: 2.14
283  */
284 GdkAppLaunchContext *
285 gdk_app_launch_context_new (void)
286 {
287   return g_object_new (GDK_TYPE_APP_LAUNCH_CONTEXT, NULL);
288 }