]> Pileus Git - ~andy/gtk/blob - gdk/gdkapplaunchcontext.c
examples/gtkdial/gtkdial.c gdk/gdkapplaunchcontext.c gdk/gdkpango.c
[~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 <glib.h>
26
27 #include "gdkapplaunchcontext.h"
28 #include "gdkinternals.h"
29 #include "gdkscreen.h"
30 #include "gdkintl.h"
31 #include "gdkalias.h"
32
33
34 G_DEFINE_TYPE (GdkAppLaunchContext, gdk_app_launch_context,
35                G_TYPE_APP_LAUNCH_CONTEXT);
36
37 static void
38 gdk_app_launch_context_finalize (GObject *object)
39 {
40   GdkAppLaunchContext *context;
41   GdkAppLaunchContextPrivate *priv;
42
43   context = GDK_APP_LAUNCH_CONTEXT (object);
44
45   priv = context->priv;
46
47   if (priv->display)
48     g_object_unref (priv->display);
49
50   if (priv->screen)
51     g_object_unref (priv->screen);
52
53   if (priv->icon)
54     g_object_unref (priv->icon);
55
56   g_free (priv->icon_name);
57
58   G_OBJECT_CLASS (gdk_app_launch_context_parent_class)->finalize (object);
59 }
60
61 static char *
62 get_display (GAppLaunchContext *context, 
63              GAppInfo          *info, 
64              GList             *files)
65 {
66   GdkDisplay *display;
67   GdkAppLaunchContextPrivate *priv;
68
69   priv = GDK_APP_LAUNCH_CONTEXT (context)->priv;
70
71   if (priv->screen)
72     return gdk_screen_make_display_name (priv->screen);
73
74   if (priv->display)
75     display = priv->display;
76   else
77     display = gdk_display_get_default ();
78
79   return g_strdup (gdk_display_get_name (display));
80 }
81
82 static void
83 gdk_app_launch_context_class_init (GdkAppLaunchContextClass *klass)
84 {
85   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
86   GAppLaunchContextClass *context_class = G_APP_LAUNCH_CONTEXT_CLASS (klass);
87
88   gobject_class->finalize = gdk_app_launch_context_finalize;
89
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;
93
94   g_type_class_add_private (klass, sizeof (GdkAppLaunchContextPrivate));
95 }
96
97 static void
98 gdk_app_launch_context_init (GdkAppLaunchContext *context)
99 {
100   context->priv = G_TYPE_INSTANCE_GET_PRIVATE (context,
101                                                GDK_TYPE_APP_LAUNCH_CONTEXT,
102                                                GdkAppLaunchContextPrivate);
103   context->priv->workspace = -1;
104 }
105
106 /**
107  * gdk_app_launch_context_set_display:
108  * @context: a #GdkAppLaunchContext
109  * @display: a #GdkDisplay
110  *
111  * Sets the display on which applications will be launched when
112  * using this context. See also gdk_app_launch_context_set_screen().
113  *
114  * Since: 2.14
115  */
116 void
117 gdk_app_launch_context_set_display (GdkAppLaunchContext *context,
118                                     GdkDisplay          *display)
119 {
120   if (context->priv->display)
121     {
122       g_object_unref (context->priv->display);
123       context->priv->display = NULL;
124     }
125
126   if (display)
127     context->priv->display = g_object_ref (display);
128 }
129
130 /**
131  * gdk_app_launch_context_set_screen:
132  * @context: a #GdkAppLaunchContext
133  * @screen: a #GdkScreen
134  *
135  * Sets the screen on which applications will be launched when
136  * using this context. See also gdk_app_launch_context_set_display().
137  *
138  * If both @screen and @display are set, the @screen takes priority.
139  * If neither @screen or @display are set, the default screen and
140  * display are used.
141  *
142  * Since: 2.14
143  */
144 void
145 gdk_app_launch_context_set_screen (GdkAppLaunchContext *context,
146                                    GdkScreen           *screen)
147 {
148   if (context->priv->screen)
149     {
150       g_object_unref (context->priv->screen);
151       context->priv->screen = NULL;
152     }
153
154   if (screen)
155     context->priv->screen = g_object_ref (screen);
156 }
157
158 /**
159  * gdk_app_launch_context_set_desktop:
160  * @context: a #GdkAppLaunchContext
161  * @desktop: the number of a workspace, or -1
162  *
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>. 
168  *
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.
172  *
173  * Since: 2.14
174  */
175 void
176 gdk_app_launch_context_set_desktop (GdkAppLaunchContext *context,
177                                     gint                 desktop)
178 {
179   context->priv->workspace = desktop;
180 }
181
182 /**
183  * gdk_app_launch_context_set_timestamp:
184  * @context: a #GdkAppLaunchContext
185  * @timestamp: a timestamp
186  *
187  * Sets the timestamp of @context. The timestamp should ideally
188  * be taken from the event that triggered the launch. 
189  *
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
193  * prevention'.
194  *
195  * Since: 2.14
196  */
197 void
198 gdk_app_launch_context_set_timestamp (GdkAppLaunchContext *context,
199                                       guint32              timestamp)
200 {
201   context->priv->timestamp = timestamp;
202 }
203
204 /**
205  * gdk_app_launch_context_set_icon:
206  * @context: a #GdkAppLaunchContext
207  * @icon: a #GIcon, or %NULL
208  *
209  * Sets the icon for applications that are launched with this
210  * context. See also gdk_app_launch_context_set_icon_name().
211  *
212  * Since: 2.14
213  */
214 void
215 gdk_app_launch_context_set_icon (GdkAppLaunchContext *context, 
216                                  GIcon               *icon)
217 {
218   if (context->priv->icon)
219     {
220       g_object_unref (context->priv->icon);
221       context->priv->icon = NULL;
222     }
223
224   if (icon)
225     context->priv->icon = g_object_ref (icon);
226 }
227
228 /**
229  * gdk_app_launch_context_set_icon_name:
230  * @context: a #GdkAppLaunchContext
231  * @icon_name: an icon name, or %NULL
232  *
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(). 
236  *
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.
241  * 
242  * Since: 2.14
243  */
244 void
245 gdk_app_launch_context_set_icon_name (GdkAppLaunchContext *context,
246                                       const char          *icon_name)
247 {
248   g_free (context->priv->icon_name);
249   context->priv->icon_name = g_strdup (icon_name);
250 }
251
252 /**
253  * gdk_app_launch_context_new:
254  *
255  * Creates a new #GdkAppLaunchContext.
256  *
257  * Returns: a new #GdkAppLaunchContext
258  *
259  * Since: 2.14
260  */
261 GdkAppLaunchContext *
262 gdk_app_launch_context_new (void)
263 {
264   GdkAppLaunchContext *context;
265
266   context = g_object_new (gdk_app_launch_context_get_type (), NULL);
267
268   return context;
269 }
270
271
272 #define __GDK_APP_LAUNCH_CONTEXT_C__
273 #include "gdkaliasdef.c"