gdkapplaunchcontext.c 8.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/* gdkapplaunchcontext.c - Gtk+ implementation for GAppLaunchContext

   Copyright (C) 2007 Red Hat, Inc.

   The Gnome Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The Gnome Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Author: Alexander Larsson <alexl@redhat.com>
*/

23
#include "config.h"
24 25 26 27 28 29 30 31

#include "gdkapplaunchcontext.h"
#include "gdkinternals.h"
#include "gdkscreen.h"
#include "gdkintl.h"
#include "gdkalias.h"


32 33 34 35 36 37
static void    gdk_app_launch_context_finalize    (GObject           *object);
static gchar * gdk_app_launch_context_get_display (GAppLaunchContext *context,
                                                   GAppInfo          *info,
                                                   GList             *files);


38
G_DEFINE_TYPE (GdkAppLaunchContext, gdk_app_launch_context,
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
	       G_TYPE_APP_LAUNCH_CONTEXT)

static void
gdk_app_launch_context_class_init (GdkAppLaunchContextClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  GAppLaunchContextClass *context_class = G_APP_LAUNCH_CONTEXT_CLASS (klass);

  gobject_class->finalize = gdk_app_launch_context_finalize;

  context_class->get_display = gdk_app_launch_context_get_display;
  context_class->get_startup_notify_id = _gdk_windowing_get_startup_notify_id;
  context_class->launch_failed = _gdk_windowing_launch_failed;

  g_type_class_add_private (klass, sizeof (GdkAppLaunchContextPrivate));
}

static void
gdk_app_launch_context_init (GdkAppLaunchContext *context)
{
  context->priv = G_TYPE_INSTANCE_GET_PRIVATE (context,
					       GDK_TYPE_APP_LAUNCH_CONTEXT,
					       GdkAppLaunchContextPrivate);
  context->priv->workspace = -1;
}
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

static void
gdk_app_launch_context_finalize (GObject *object)
{
  GdkAppLaunchContext *context;
  GdkAppLaunchContextPrivate *priv;

  context = GDK_APP_LAUNCH_CONTEXT (object);

  priv = context->priv;

  if (priv->display)
    g_object_unref (priv->display);

  if (priv->screen)
    g_object_unref (priv->screen);

  if (priv->icon)
    g_object_unref (priv->icon);

  g_free (priv->icon_name);

86
  G_OBJECT_CLASS (gdk_app_launch_context_parent_class)->finalize (object);
87 88
}

89 90 91 92
static gchar *
gdk_app_launch_context_get_display (GAppLaunchContext *context,
                                    GAppInfo          *info,
                                    GList             *files)
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
{
  GdkDisplay *display;
  GdkAppLaunchContextPrivate *priv;

  priv = GDK_APP_LAUNCH_CONTEXT (context)->priv;

  if (priv->screen)
    return gdk_screen_make_display_name (priv->screen);

  if (priv->display)
    display = priv->display;
  else
    display = gdk_display_get_default ();

  return g_strdup (gdk_display_get_name (display));
}

Matthias Clasen's avatar
Matthias Clasen committed
110 111 112 113 114 115 116 117
/**
 * gdk_app_launch_context_set_display:
 * @context: a #GdkAppLaunchContext
 * @display: a #GdkDisplay
 *
 * Sets the display on which applications will be launched when
 * using this context. See also gdk_app_launch_context_set_screen().
 *
118
 * Since: 2.14
Matthias Clasen's avatar
Matthias Clasen committed
119
 */
120 121 122 123
void
gdk_app_launch_context_set_display (GdkAppLaunchContext *context,
				    GdkDisplay          *display)
{
124 125 126
  g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
  g_return_if_fail (display == NULL || GDK_IS_DISPLAY (display));

127 128 129 130 131 132 133 134 135
  if (context->priv->display)
    {
      g_object_unref (context->priv->display);
      context->priv->display = NULL;
    }

  if (display)
    context->priv->display = g_object_ref (display);
}
Matthias Clasen's avatar
Matthias Clasen committed
136 137 138 139 140 141 142 143

/**
 * gdk_app_launch_context_set_screen:
 * @context: a #GdkAppLaunchContext
 * @screen: a #GdkScreen
 *
 * Sets the screen on which applications will be launched when
 * using this context. See also gdk_app_launch_context_set_display().
Matthias Clasen's avatar
Matthias Clasen committed
144
 *
Matthias Clasen's avatar
Matthias Clasen committed
145
 * If both @screen and @display are set, the @screen takes priority.
Matthias Clasen's avatar
Matthias Clasen committed
146 147
 * If neither @screen or @display are set, the default screen and
 * display are used.
Matthias Clasen's avatar
Matthias Clasen committed
148
 *
149
 * Since: 2.14
Matthias Clasen's avatar
Matthias Clasen committed
150
 */
151 152 153 154
void
gdk_app_launch_context_set_screen (GdkAppLaunchContext *context,
				   GdkScreen           *screen)
{
155 156 157
  g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
  g_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen));

158 159 160 161 162 163 164 165 166 167
  if (context->priv->screen)
    {
      g_object_unref (context->priv->screen);
      context->priv->screen = NULL;
    }

  if (screen)
    context->priv->screen = g_object_ref (screen);
}

Matthias Clasen's avatar
Matthias Clasen committed
168 169 170 171 172 173 174 175 176 177 178
/**
 * gdk_app_launch_context_set_desktop:
 * @context: a #GdkAppLaunchContext
 * @desktop: the number of a workspace, or -1
 *
 * Sets the workspace on which applications will be launched when
 * using this context when running under a window manager that 
 * supports multiple workspaces, as described in the 
 * <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended 
 * Window Manager Hints</ulink>. 
 *
Matthias Clasen's avatar
Matthias Clasen committed
179 180 181 182
 * When the workspace is not specified or @desktop is set to -1, 
 * it is up to the window manager to pick one, typically it will
 * be the current workspace.
 *
183
 * Since: 2.14
Matthias Clasen's avatar
Matthias Clasen committed
184
 */
185 186 187 188
void
gdk_app_launch_context_set_desktop (GdkAppLaunchContext *context,
				    gint                 desktop)
{
189 190
  g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));

191 192 193
  context->priv->workspace = desktop;
}

Matthias Clasen's avatar
Matthias Clasen committed
194 195 196 197 198 199
/**
 * gdk_app_launch_context_set_timestamp:
 * @context: a #GdkAppLaunchContext
 * @timestamp: a timestamp
 *
 * Sets the timestamp of @context. The timestamp should ideally
Matthias Clasen's avatar
Matthias Clasen committed
200 201 202 203 204 205
 * be taken from the event that triggered the launch. 
 *
 * Window managers can use this information to avoid moving the
 * focus to the newly launched application when the user is busy
 * typing in another window. This is also known as 'focus stealing
 * prevention'.
Matthias Clasen's avatar
Matthias Clasen committed
206
 *
207
 * Since: 2.14
Matthias Clasen's avatar
Matthias Clasen committed
208
 */
209 210 211 212
void
gdk_app_launch_context_set_timestamp (GdkAppLaunchContext *context,
				      guint32              timestamp)
{
213 214
  g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));

215 216 217
  context->priv->timestamp = timestamp;
}

Matthias Clasen's avatar
Matthias Clasen committed
218 219 220
/**
 * gdk_app_launch_context_set_icon:
 * @context: a #GdkAppLaunchContext
Johan Dahlin's avatar
Johan Dahlin committed
221
 * @icon: (allow-none): a #GIcon, or %NULL
Matthias Clasen's avatar
Matthias Clasen committed
222 223
 *
 * Sets the icon for applications that are launched with this
224 225 226 227 228 229
 * context.
 *
 * Window Managers can use this information when displaying startup
 * notification.
 *
 * See also gdk_app_launch_context_set_icon_name().
Matthias Clasen's avatar
Matthias Clasen committed
230
 *
231
 * Since: 2.14
Matthias Clasen's avatar
Matthias Clasen committed
232
 */
233
void
234
gdk_app_launch_context_set_icon (GdkAppLaunchContext *context,
235 236
                                 GIcon               *icon)
{
237 238 239
  g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
  g_return_if_fail (icon == NULL || G_IS_ICON (icon));

240 241 242 243 244 245 246 247 248 249
  if (context->priv->icon)
    {
      g_object_unref (context->priv->icon);
      context->priv->icon = NULL;
    }

  if (icon)
    context->priv->icon = g_object_ref (icon);
}

Matthias Clasen's avatar
Matthias Clasen committed
250 251 252
/**
 * gdk_app_launch_context_set_icon_name:
 * @context: a #GdkAppLaunchContext
Johan Dahlin's avatar
Johan Dahlin committed
253
 * @icon_name: (allow-none): an icon name, or %NULL
Matthias Clasen's avatar
Matthias Clasen committed
254
 *
Matthias Clasen's avatar
Matthias Clasen committed
255 256 257 258 259 260 261 262
 * Sets the icon for applications that are launched with this context. 
 * The @icon_name will be interpreted in the same way as the Icon field 
 * in desktop files. See also gdk_app_launch_context_set_icon(). 
 *
 * If both @icon and @icon_name are set, the @icon_name takes priority.
 * If neither @icon or @icon_name is set, the icon is taken from either 
 * the file that is passed to launched application or from the #GAppInfo 
 * for the launched application itself.
Matthias Clasen's avatar
Matthias Clasen committed
263
 * 
264
 * Since: 2.14
Matthias Clasen's avatar
Matthias Clasen committed
265
 */
266 267 268 269
void
gdk_app_launch_context_set_icon_name (GdkAppLaunchContext *context,
				      const char          *icon_name)
{
270 271
  g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));

272 273 274 275
  g_free (context->priv->icon_name);
  context->priv->icon_name = g_strdup (icon_name);
}

Matthias Clasen's avatar
Matthias Clasen committed
276 277 278 279 280 281 282
/**
 * gdk_app_launch_context_new:
 *
 * Creates a new #GdkAppLaunchContext.
 *
 * Returns: a new #GdkAppLaunchContext
 *
283
 * Since: 2.14
Matthias Clasen's avatar
Matthias Clasen committed
284
 */
285 286 287
GdkAppLaunchContext *
gdk_app_launch_context_new (void)
{
288
  return g_object_new (GDK_TYPE_APP_LAUNCH_CONTEXT, NULL);
289 290 291 292
}

#define __GDK_APP_LAUNCH_CONTEXT_C__
#include "gdkaliasdef.c"