Blame gdk/gdkapplaunchcontext.c

Packit 98cdb6
/* gdkapplaunchcontext.c - Gtk+ implementation for GAppLaunchContext
Packit 98cdb6
Packit 98cdb6
   Copyright (C) 2007 Red Hat, Inc.
Packit 98cdb6
Packit 98cdb6
   The Gnome Library is free software; you can redistribute it and/or
Packit 98cdb6
   modify it under the terms of the GNU Library General Public License as
Packit 98cdb6
   published by the Free Software Foundation; either version 2 of the
Packit 98cdb6
   License, or (at your option) any later version.
Packit 98cdb6
Packit 98cdb6
   The Gnome Library is distributed in the hope that it will be useful,
Packit 98cdb6
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 98cdb6
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 98cdb6
   Library General Public License for more details.
Packit 98cdb6
Packit 98cdb6
   You should have received a copy of the GNU Library General Public
Packit 98cdb6
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
Packit 98cdb6
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 98cdb6
   Boston, MA 02111-1307, USA.
Packit 98cdb6
Packit 98cdb6
   Author: Alexander Larsson <alexl@redhat.com>
Packit 98cdb6
*/
Packit 98cdb6
Packit 98cdb6
#include "config.h"
Packit 98cdb6
Packit 98cdb6
#include "gdkapplaunchcontext.h"
Packit 98cdb6
#include "gdkinternals.h"
Packit 98cdb6
#include "gdkscreen.h"
Packit 98cdb6
#include "gdkintl.h"
Packit 98cdb6
#include "gdkalias.h"
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
static void    gdk_app_launch_context_finalize    (GObject           *object);
Packit 98cdb6
static gchar * gdk_app_launch_context_get_display (GAppLaunchContext *context,
Packit 98cdb6
                                                   GAppInfo          *info,
Packit 98cdb6
                                                   GList             *files);
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
G_DEFINE_TYPE (GdkAppLaunchContext, gdk_app_launch_context,
Packit 98cdb6
	       G_TYPE_APP_LAUNCH_CONTEXT)
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gdk_app_launch_context_class_init (GdkAppLaunchContextClass *klass)
Packit 98cdb6
{
Packit 98cdb6
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
Packit 98cdb6
  GAppLaunchContextClass *context_class = G_APP_LAUNCH_CONTEXT_CLASS (klass);
Packit 98cdb6
Packit 98cdb6
  gobject_class->finalize = gdk_app_launch_context_finalize;
Packit 98cdb6
Packit 98cdb6
  context_class->get_display = gdk_app_launch_context_get_display;
Packit 98cdb6
  context_class->get_startup_notify_id = _gdk_windowing_get_startup_notify_id;
Packit 98cdb6
  context_class->launch_failed = _gdk_windowing_launch_failed;
Packit 98cdb6
Packit 98cdb6
  g_type_class_add_private (klass, sizeof (GdkAppLaunchContextPrivate));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gdk_app_launch_context_init (GdkAppLaunchContext *context)
Packit 98cdb6
{
Packit 98cdb6
  context->priv = G_TYPE_INSTANCE_GET_PRIVATE (context,
Packit 98cdb6
					       GDK_TYPE_APP_LAUNCH_CONTEXT,
Packit 98cdb6
					       GdkAppLaunchContextPrivate);
Packit 98cdb6
  context->priv->workspace = -1;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gdk_app_launch_context_finalize (GObject *object)
Packit 98cdb6
{
Packit 98cdb6
  GdkAppLaunchContext *context;
Packit 98cdb6
  GdkAppLaunchContextPrivate *priv;
Packit 98cdb6
Packit 98cdb6
  context = GDK_APP_LAUNCH_CONTEXT (object);
Packit 98cdb6
Packit 98cdb6
  priv = context->priv;
Packit 98cdb6
Packit 98cdb6
  if (priv->display)
Packit 98cdb6
    g_object_unref (priv->display);
Packit 98cdb6
Packit 98cdb6
  if (priv->screen)
Packit 98cdb6
    g_object_unref (priv->screen);
Packit 98cdb6
Packit 98cdb6
  if (priv->icon)
Packit 98cdb6
    g_object_unref (priv->icon);
Packit 98cdb6
Packit 98cdb6
  g_free (priv->icon_name);
Packit 98cdb6
Packit 98cdb6
  G_OBJECT_CLASS (gdk_app_launch_context_parent_class)->finalize (object);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gchar *
Packit 98cdb6
gdk_app_launch_context_get_display (GAppLaunchContext *context,
Packit 98cdb6
                                    GAppInfo          *info,
Packit 98cdb6
                                    GList             *files)
Packit 98cdb6
{
Packit 98cdb6
  GdkDisplay *display;
Packit 98cdb6
  GdkAppLaunchContextPrivate *priv;
Packit 98cdb6
Packit 98cdb6
  priv = GDK_APP_LAUNCH_CONTEXT (context)->priv;
Packit 98cdb6
Packit 98cdb6
  if (priv->screen)
Packit 98cdb6
    return gdk_screen_make_display_name (priv->screen);
Packit 98cdb6
Packit 98cdb6
  if (priv->display)
Packit 98cdb6
    display = priv->display;
Packit 98cdb6
  else
Packit 98cdb6
    display = gdk_display_get_default ();
Packit 98cdb6
Packit 98cdb6
  return g_strdup (gdk_display_get_name (display));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_app_launch_context_set_display:
Packit 98cdb6
 * @context: a #GdkAppLaunchContext
Packit 98cdb6
 * @display: a #GdkDisplay
Packit 98cdb6
 *
Packit 98cdb6
 * Sets the display on which applications will be launched when
Packit 98cdb6
 * using this context. See also gdk_app_launch_context_set_screen().
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.14
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gdk_app_launch_context_set_display (GdkAppLaunchContext *context,
Packit 98cdb6
				    GdkDisplay          *display)
Packit 98cdb6
{
Packit 98cdb6
  g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
Packit 98cdb6
  g_return_if_fail (display == NULL || GDK_IS_DISPLAY (display));
Packit 98cdb6
Packit 98cdb6
  if (context->priv->display)
Packit 98cdb6
    {
Packit 98cdb6
      g_object_unref (context->priv->display);
Packit 98cdb6
      context->priv->display = NULL;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (display)
Packit 98cdb6
    context->priv->display = g_object_ref (display);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_app_launch_context_set_screen:
Packit 98cdb6
 * @context: a #GdkAppLaunchContext
Packit 98cdb6
 * @screen: a #GdkScreen
Packit 98cdb6
 *
Packit 98cdb6
 * Sets the screen on which applications will be launched when
Packit 98cdb6
 * using this context. See also gdk_app_launch_context_set_display().
Packit 98cdb6
 *
Packit 98cdb6
 * If both @screen and @display are set, the @screen takes priority.
Packit 98cdb6
 * If neither @screen or @display are set, the default screen and
Packit 98cdb6
 * display are used.
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.14
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gdk_app_launch_context_set_screen (GdkAppLaunchContext *context,
Packit 98cdb6
				   GdkScreen           *screen)
Packit 98cdb6
{
Packit 98cdb6
  g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
Packit 98cdb6
  g_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen));
Packit 98cdb6
Packit 98cdb6
  if (context->priv->screen)
Packit 98cdb6
    {
Packit 98cdb6
      g_object_unref (context->priv->screen);
Packit 98cdb6
      context->priv->screen = NULL;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (screen)
Packit 98cdb6
    context->priv->screen = g_object_ref (screen);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_app_launch_context_set_desktop:
Packit 98cdb6
 * @context: a #GdkAppLaunchContext
Packit 98cdb6
 * @desktop: the number of a workspace, or -1
Packit 98cdb6
 *
Packit 98cdb6
 * Sets the workspace on which applications will be launched when
Packit 98cdb6
 * using this context when running under a window manager that 
Packit 98cdb6
 * supports multiple workspaces, as described in the 
Packit 98cdb6
 * <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended 
Packit 98cdb6
 * Window Manager Hints</ulink>. 
Packit 98cdb6
 *
Packit 98cdb6
 * When the workspace is not specified or @desktop is set to -1, 
Packit 98cdb6
 * it is up to the window manager to pick one, typically it will
Packit 98cdb6
 * be the current workspace.
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.14
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gdk_app_launch_context_set_desktop (GdkAppLaunchContext *context,
Packit 98cdb6
				    gint                 desktop)
Packit 98cdb6
{
Packit 98cdb6
  g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
Packit 98cdb6
Packit 98cdb6
  context->priv->workspace = desktop;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_app_launch_context_set_timestamp:
Packit 98cdb6
 * @context: a #GdkAppLaunchContext
Packit 98cdb6
 * @timestamp: a timestamp
Packit 98cdb6
 *
Packit 98cdb6
 * Sets the timestamp of @context. The timestamp should ideally
Packit 98cdb6
 * be taken from the event that triggered the launch. 
Packit 98cdb6
 *
Packit 98cdb6
 * Window managers can use this information to avoid moving the
Packit 98cdb6
 * focus to the newly launched application when the user is busy
Packit 98cdb6
 * typing in another window. This is also known as 'focus stealing
Packit 98cdb6
 * prevention'.
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.14
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gdk_app_launch_context_set_timestamp (GdkAppLaunchContext *context,
Packit 98cdb6
				      guint32              timestamp)
Packit 98cdb6
{
Packit 98cdb6
  g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
Packit 98cdb6
Packit 98cdb6
  context->priv->timestamp = timestamp;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_app_launch_context_set_icon:
Packit 98cdb6
 * @context: a #GdkAppLaunchContext
Packit 98cdb6
 * @icon: (allow-none): a #GIcon, or %NULL
Packit 98cdb6
 *
Packit 98cdb6
 * Sets the icon for applications that are launched with this
Packit 98cdb6
 * context.
Packit 98cdb6
 *
Packit 98cdb6
 * Window Managers can use this information when displaying startup
Packit 98cdb6
 * notification.
Packit 98cdb6
 *
Packit 98cdb6
 * See also gdk_app_launch_context_set_icon_name().
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.14
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gdk_app_launch_context_set_icon (GdkAppLaunchContext *context,
Packit 98cdb6
                                 GIcon               *icon)
Packit 98cdb6
{
Packit 98cdb6
  g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
Packit 98cdb6
  g_return_if_fail (icon == NULL || G_IS_ICON (icon));
Packit 98cdb6
Packit 98cdb6
  if (context->priv->icon)
Packit 98cdb6
    {
Packit 98cdb6
      g_object_unref (context->priv->icon);
Packit 98cdb6
      context->priv->icon = NULL;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (icon)
Packit 98cdb6
    context->priv->icon = g_object_ref (icon);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_app_launch_context_set_icon_name:
Packit 98cdb6
 * @context: a #GdkAppLaunchContext
Packit 98cdb6
 * @icon_name: (allow-none): an icon name, or %NULL
Packit 98cdb6
 *
Packit 98cdb6
 * Sets the icon for applications that are launched with this context. 
Packit 98cdb6
 * The @icon_name will be interpreted in the same way as the Icon field 
Packit 98cdb6
 * in desktop files. See also gdk_app_launch_context_set_icon(). 
Packit 98cdb6
 *
Packit 98cdb6
 * If both @icon and @icon_name are set, the @icon_name takes priority.
Packit 98cdb6
 * If neither @icon or @icon_name is set, the icon is taken from either 
Packit 98cdb6
 * the file that is passed to launched application or from the #GAppInfo 
Packit 98cdb6
 * for the launched application itself.
Packit 98cdb6
 * 
Packit 98cdb6
 * Since: 2.14
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gdk_app_launch_context_set_icon_name (GdkAppLaunchContext *context,
Packit 98cdb6
				      const char          *icon_name)
Packit 98cdb6
{
Packit 98cdb6
  g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
Packit 98cdb6
Packit 98cdb6
  g_free (context->priv->icon_name);
Packit 98cdb6
  context->priv->icon_name = g_strdup (icon_name);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_app_launch_context_new:
Packit 98cdb6
 *
Packit 98cdb6
 * Creates a new #GdkAppLaunchContext.
Packit 98cdb6
 *
Packit 98cdb6
 * Returns: a new #GdkAppLaunchContext
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.14
Packit 98cdb6
 */
Packit 98cdb6
GdkAppLaunchContext *
Packit 98cdb6
gdk_app_launch_context_new (void)
Packit 98cdb6
{
Packit 98cdb6
  return g_object_new (GDK_TYPE_APP_LAUNCH_CONTEXT, NULL);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
#define __GDK_APP_LAUNCH_CONTEXT_C__
Packit 98cdb6
#include "gdkaliasdef.c"