gdkapplaunchcontext.c 6.68 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 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
/* 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>
*/

#include <config.h>

#include <string.h>
#include <unistd.h>

#include <glib.h>
#include <gio/gfileicon.h>
#include <gio/gthemedicon.h>

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


G_DEFINE_TYPE (GdkAppLaunchContext, gdk_app_launch_context,
	       G_TYPE_APP_LAUNCH_CONTEXT);

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);

  (*G_OBJECT_CLASS (gdk_app_launch_context_parent_class)->finalize) (object);
}

static char *
get_display (GAppLaunchContext *context, 
             GAppInfo          *info, 
             GList             *files)
{
  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));
}

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 = 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;
}

Matthias Clasen's avatar
Matthias Clasen committed
111 112 113 114 115 116 117 118 119 120
/**
 * 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().
 *
 * Since: 2.16
 */
121 122 123 124 125 126 127 128 129 130 131 132 133
void
gdk_app_launch_context_set_display (GdkAppLaunchContext *context,
				    GdkDisplay          *display)
{
  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
134 135 136 137 138 139 140 141 142 143 144 145

/**
 * 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().
 * If both @screen and @display are set, the @screen takes priority.
 *
 * Since: 2.16
 */
146 147 148 149 150 151 152 153 154 155 156 157 158 159
void
gdk_app_launch_context_set_screen (GdkAppLaunchContext *context,
				   GdkScreen           *screen)
{
  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
160 161 162 163 164 165 166 167 168 169 170 171 172
/**
 * 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>. 
 *
 * Since: 2.16
 */
173 174 175 176 177 178 179
void
gdk_app_launch_context_set_desktop (GdkAppLaunchContext *context,
				    gint                 desktop)
{
  context->priv->workspace = desktop;
}

Matthias Clasen's avatar
Matthias Clasen committed
180 181 182 183 184 185 186 187 188 189
/**
 * gdk_app_launch_context_set_timestamp:
 * @context: a #GdkAppLaunchContext
 * @timestamp: a timestamp
 *
 * Sets the timestamp of @context. The timestamp should ideally
 * be taken from the event that triggered the launch.
 *
 * Since: 2.16
 */
190 191 192 193 194 195 196
void
gdk_app_launch_context_set_timestamp (GdkAppLaunchContext *context,
				      guint32              timestamp)
{
  context->priv->timestamp = timestamp;
}

Matthias Clasen's avatar
Matthias Clasen committed
197 198 199 200 201 202 203 204 205 206
/**
 * gdk_app_launch_context_set_icon:
 * @context: a #GdkAppLaunchContext
 * @icon: a #GIcon, or %NULL
 *
 * Sets the icon for applications that are launched with this
 * context. See also gdk_app_launch_context_set_icon_name().
 *
 * Since: 2.16
 */
207 208 209 210 211 212 213 214 215 216 217 218 219 220
void
gdk_app_launch_context_set_icon (GdkAppLaunchContext *context, 
                                 GIcon               *icon)
{
  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
221 222 223 224 225 226 227 228 229 230 231 232 233
/**
 * gdk_app_launch_context_set_icon_name:
 * @context: a #GdkAppLaunchContext
 * @icon_name: an icon name, or %NULL
 *
 * 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.
 * 
 * Since: 2.16
 */
234 235 236 237 238 239 240 241
void
gdk_app_launch_context_set_icon_name (GdkAppLaunchContext *context,
				      const char          *icon_name)
{
  g_free (context->priv->icon_name);
  context->priv->icon_name = g_strdup (icon_name);
}

Matthias Clasen's avatar
Matthias Clasen committed
242 243 244 245 246 247 248 249 250
/**
 * gdk_app_launch_context_new:
 *
 * Creates a new #GdkAppLaunchContext.
 *
 * Returns: a new #GdkAppLaunchContext
 *
 * Since: 2.16
 */
251 252 253 254 255 256
GdkAppLaunchContext *
gdk_app_launch_context_new (void)
{
  GdkAppLaunchContext *context;

  context = g_object_new (gdk_app_launch_context_get_type (), NULL);
Matthias Clasen's avatar
Matthias Clasen committed
257

258 259 260 261 262 263
  return context;
}


#define __GDK_APP_LAUNCH_CONTEXT_C__
#include "gdkaliasdef.c"