2007-12-13 05:16:33 +00:00
|
|
|
/* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2007-12-13 05:16:33 +00:00
|
|
|
|
|
|
|
Author: Alexander Larsson <alexl@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2007-12-13 05:16:33 +00:00
|
|
|
|
2010-12-11 05:14:53 +00:00
|
|
|
#include "gdkapplaunchcontextprivate.h"
|
2007-12-13 05:16:33 +00:00
|
|
|
#include "gdkscreen.h"
|
|
|
|
#include "gdkintl.h"
|
|
|
|
|
|
|
|
|
2010-11-15 02:18:45 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gdkapplaunchcontext
|
|
|
|
* @Short_description: Startup notification for applications
|
|
|
|
* @Title: Application launching
|
|
|
|
*
|
|
|
|
* GdkAppLaunchContext is an implementation of #GAppLaunchContext that
|
|
|
|
* handles launching an application in a graphical context. It provides
|
|
|
|
* startup notification and allows to launch applications on a specific
|
|
|
|
* screen or workspace.
|
|
|
|
* <example>
|
|
|
|
* <title>Launching an application</title>
|
2014-01-27 19:55:18 +00:00
|
|
|
* |[<!-- language="C" -->
|
2010-11-15 02:18:45 +00:00
|
|
|
* GdkAppLaunchContext *context;
|
|
|
|
*
|
2010-12-24 22:37:00 +00:00
|
|
|
* context = gdk_display_get_app_launch_context (display);
|
2010-11-15 02:18:45 +00:00
|
|
|
*
|
2010-12-24 22:37:00 +00:00
|
|
|
* gdk_app_launch_context_set_screen (screen);
|
2010-11-15 02:18:45 +00:00
|
|
|
* gdk_app_launch_context_set_timestamp (event->time);
|
|
|
|
*
|
|
|
|
* if (!g_app_info_launch_default_for_uri ("http://www.gtk.org", context, &error))
|
|
|
|
* g_warning ("Launching failed: %s\n", error->message);
|
|
|
|
*
|
|
|
|
* g_object_unref (context);
|
2014-01-27 17:12:55 +00:00
|
|
|
* ]|
|
2010-11-15 02:18:45 +00:00
|
|
|
* </example>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2008-10-21 20:20:50 +00:00
|
|
|
static void gdk_app_launch_context_finalize (GObject *object);
|
|
|
|
static gchar * gdk_app_launch_context_get_display (GAppLaunchContext *context,
|
|
|
|
GAppInfo *info,
|
|
|
|
GList *files);
|
2010-12-09 06:08:05 +00:00
|
|
|
static gchar * gdk_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
|
|
|
|
GAppInfo *info,
|
|
|
|
GList *files);
|
|
|
|
static void gdk_app_launch_context_launch_failed (GAppLaunchContext *context,
|
|
|
|
const gchar *startup_notify_id);
|
2008-10-21 20:20:50 +00:00
|
|
|
|
|
|
|
|
2010-12-15 07:37:03 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_DISPLAY
|
|
|
|
};
|
|
|
|
|
2010-12-09 06:08:05 +00:00
|
|
|
G_DEFINE_TYPE (GdkAppLaunchContext, gdk_app_launch_context, G_TYPE_APP_LAUNCH_CONTEXT)
|
2008-10-21 20:20:50 +00:00
|
|
|
|
2010-12-15 07:37:03 +00:00
|
|
|
static void
|
|
|
|
gdk_app_launch_context_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GdkAppLaunchContext *context = GDK_APP_LAUNCH_CONTEXT (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_DISPLAY:
|
|
|
|
g_value_set_object (value, context->display);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_app_launch_context_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GdkAppLaunchContext *context = GDK_APP_LAUNCH_CONTEXT (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_DISPLAY:
|
|
|
|
context->display = g_value_dup_object (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-21 20:20:50 +00:00
|
|
|
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);
|
|
|
|
|
2010-12-15 07:37:03 +00:00
|
|
|
gobject_class->set_property = gdk_app_launch_context_set_property,
|
|
|
|
gobject_class->get_property = gdk_app_launch_context_get_property;
|
|
|
|
|
2008-10-21 20:20:50 +00:00
|
|
|
gobject_class->finalize = gdk_app_launch_context_finalize;
|
|
|
|
|
|
|
|
context_class->get_display = gdk_app_launch_context_get_display;
|
2010-12-09 06:08:05 +00:00
|
|
|
context_class->get_startup_notify_id = gdk_app_launch_context_get_startup_notify_id;
|
|
|
|
context_class->launch_failed = gdk_app_launch_context_launch_failed;
|
2010-12-15 07:37:03 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_DISPLAY,
|
|
|
|
g_param_spec_object ("display", P_("Display"), P_("Display"),
|
|
|
|
GDK_TYPE_DISPLAY,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
2008-10-21 20:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_app_launch_context_init (GdkAppLaunchContext *context)
|
|
|
|
{
|
2010-12-11 05:14:53 +00:00
|
|
|
context->workspace = -1;
|
2008-10-21 20:20:50 +00:00
|
|
|
}
|
2007-12-13 05:16:33 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_app_launch_context_finalize (GObject *object)
|
|
|
|
{
|
2010-12-11 05:14:53 +00:00
|
|
|
GdkAppLaunchContext *context = GDK_APP_LAUNCH_CONTEXT (object);
|
2007-12-13 05:16:33 +00:00
|
|
|
|
2010-12-11 05:14:53 +00:00
|
|
|
if (context->display)
|
|
|
|
g_object_unref (context->display);
|
2007-12-13 05:16:33 +00:00
|
|
|
|
2010-12-11 05:14:53 +00:00
|
|
|
if (context->screen)
|
|
|
|
g_object_unref (context->screen);
|
2007-12-13 05:16:33 +00:00
|
|
|
|
2010-12-11 05:14:53 +00:00
|
|
|
if (context->icon)
|
|
|
|
g_object_unref (context->icon);
|
2007-12-13 05:16:33 +00:00
|
|
|
|
2010-12-11 05:14:53 +00:00
|
|
|
g_free (context->icon_name);
|
2007-12-13 05:16:33 +00:00
|
|
|
|
2008-08-12 09:51:16 +00:00
|
|
|
G_OBJECT_CLASS (gdk_app_launch_context_parent_class)->finalize (object);
|
2007-12-13 05:16:33 +00:00
|
|
|
}
|
|
|
|
|
2008-10-21 20:20:50 +00:00
|
|
|
static gchar *
|
|
|
|
gdk_app_launch_context_get_display (GAppLaunchContext *context,
|
|
|
|
GAppInfo *info,
|
|
|
|
GList *files)
|
2007-12-13 05:16:33 +00:00
|
|
|
{
|
2010-12-11 05:14:53 +00:00
|
|
|
GdkAppLaunchContext *ctx = GDK_APP_LAUNCH_CONTEXT (context);
|
2007-12-13 05:16:33 +00:00
|
|
|
GdkDisplay *display;
|
|
|
|
|
2010-12-11 05:14:53 +00:00
|
|
|
if (ctx->screen)
|
|
|
|
return gdk_screen_make_display_name (ctx->screen);
|
2007-12-13 05:16:33 +00:00
|
|
|
|
2010-12-11 05:14:53 +00:00
|
|
|
if (ctx->display)
|
|
|
|
display = ctx->display;
|
2007-12-13 05:16:33 +00:00
|
|
|
else
|
|
|
|
display = gdk_display_get_default ();
|
|
|
|
|
|
|
|
return g_strdup (gdk_display_get_name (display));
|
|
|
|
}
|
|
|
|
|
2007-12-13 05:49:11 +00:00
|
|
|
/**
|
|
|
|
* 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().
|
|
|
|
*
|
2008-02-15 23:42:42 +00:00
|
|
|
* Since: 2.14
|
2010-12-09 06:08:05 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.0: Use gdk_display_get_app_launch_context() instead
|
2007-12-13 05:49:11 +00:00
|
|
|
*/
|
2007-12-13 05:16:33 +00:00
|
|
|
void
|
|
|
|
gdk_app_launch_context_set_display (GdkAppLaunchContext *context,
|
2010-12-09 06:08:05 +00:00
|
|
|
GdkDisplay *display)
|
2007-12-13 05:16:33 +00:00
|
|
|
{
|
2008-10-21 20:20:50 +00:00
|
|
|
g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
|
|
|
|
g_return_if_fail (display == NULL || GDK_IS_DISPLAY (display));
|
|
|
|
|
2010-12-11 05:14:53 +00:00
|
|
|
g_warn_if_fail (display == NULL || display == context->display);
|
2007-12-13 05:16:33 +00:00
|
|
|
}
|
2007-12-13 05:49:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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().
|
2008-08-02 04:12:55 +00:00
|
|
|
*
|
2007-12-13 05:49:11 +00:00
|
|
|
* If both @screen and @display are set, the @screen takes priority.
|
2008-08-02 04:12:55 +00:00
|
|
|
* If neither @screen or @display are set, the default screen and
|
|
|
|
* display are used.
|
2007-12-13 05:49:11 +00:00
|
|
|
*
|
2008-02-15 23:42:42 +00:00
|
|
|
* Since: 2.14
|
2007-12-13 05:49:11 +00:00
|
|
|
*/
|
2007-12-13 05:16:33 +00:00
|
|
|
void
|
|
|
|
gdk_app_launch_context_set_screen (GdkAppLaunchContext *context,
|
2010-12-09 06:08:05 +00:00
|
|
|
GdkScreen *screen)
|
2007-12-13 05:16:33 +00:00
|
|
|
{
|
2008-10-21 20:20:50 +00:00
|
|
|
g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
|
|
|
|
g_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen));
|
|
|
|
|
2010-12-11 05:14:53 +00:00
|
|
|
g_return_if_fail (screen == NULL || gdk_screen_get_display (screen) == context->display);
|
2010-12-09 06:08:05 +00:00
|
|
|
|
2010-12-11 05:14:53 +00:00
|
|
|
if (context->screen)
|
2007-12-13 05:16:33 +00:00
|
|
|
{
|
2010-12-11 05:14:53 +00:00
|
|
|
g_object_unref (context->screen);
|
|
|
|
context->screen = NULL;
|
2007-12-13 05:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (screen)
|
2010-12-11 05:14:53 +00:00
|
|
|
context->screen = g_object_ref (screen);
|
2007-12-13 05:16:33 +00:00
|
|
|
}
|
|
|
|
|
2007-12-13 05:49:11 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2010-12-09 06:08:05 +00:00
|
|
|
* 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>.
|
2007-12-13 05:49:11 +00:00
|
|
|
*
|
2010-12-09 06:08:05 +00:00
|
|
|
* When the workspace is not specified or @desktop is set to -1,
|
2008-08-02 04:12:55 +00:00
|
|
|
* it is up to the window manager to pick one, typically it will
|
|
|
|
* be the current workspace.
|
|
|
|
*
|
2008-02-15 23:42:42 +00:00
|
|
|
* Since: 2.14
|
2007-12-13 05:49:11 +00:00
|
|
|
*/
|
2007-12-13 05:16:33 +00:00
|
|
|
void
|
|
|
|
gdk_app_launch_context_set_desktop (GdkAppLaunchContext *context,
|
2010-12-09 06:08:05 +00:00
|
|
|
gint desktop)
|
2007-12-13 05:16:33 +00:00
|
|
|
{
|
2008-10-21 20:20:50 +00:00
|
|
|
g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
|
|
|
|
|
2010-12-11 05:14:53 +00:00
|
|
|
context->workspace = desktop;
|
2007-12-13 05:16:33 +00:00
|
|
|
}
|
|
|
|
|
2007-12-13 05:49:11 +00:00
|
|
|
/**
|
|
|
|
* gdk_app_launch_context_set_timestamp:
|
|
|
|
* @context: a #GdkAppLaunchContext
|
|
|
|
* @timestamp: a timestamp
|
|
|
|
*
|
|
|
|
* Sets the timestamp of @context. The timestamp should ideally
|
2010-12-09 06:08:05 +00:00
|
|
|
* be taken from the event that triggered the launch.
|
2008-08-02 04:12:55 +00:00
|
|
|
*
|
|
|
|
* 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'.
|
2007-12-13 05:49:11 +00:00
|
|
|
*
|
2008-02-15 23:42:42 +00:00
|
|
|
* Since: 2.14
|
2007-12-13 05:49:11 +00:00
|
|
|
*/
|
2007-12-13 05:16:33 +00:00
|
|
|
void
|
|
|
|
gdk_app_launch_context_set_timestamp (GdkAppLaunchContext *context,
|
2010-12-09 06:08:05 +00:00
|
|
|
guint32 timestamp)
|
2007-12-13 05:16:33 +00:00
|
|
|
{
|
2008-10-21 20:20:50 +00:00
|
|
|
g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
|
|
|
|
|
2010-12-11 05:14:53 +00:00
|
|
|
context->timestamp = timestamp;
|
2007-12-13 05:16:33 +00:00
|
|
|
}
|
|
|
|
|
2007-12-13 05:49:11 +00:00
|
|
|
/**
|
|
|
|
* gdk_app_launch_context_set_icon:
|
|
|
|
* @context: a #GdkAppLaunchContext
|
2010-02-19 16:53:17 +00:00
|
|
|
* @icon: (allow-none): a #GIcon, or %NULL
|
2007-12-13 05:49:11 +00:00
|
|
|
*
|
|
|
|
* Sets the icon for applications that are launched with this
|
2008-12-26 04:20:28 +00:00
|
|
|
* context.
|
|
|
|
*
|
|
|
|
* Window Managers can use this information when displaying startup
|
|
|
|
* notification.
|
|
|
|
*
|
|
|
|
* See also gdk_app_launch_context_set_icon_name().
|
2007-12-13 05:49:11 +00:00
|
|
|
*
|
2008-02-15 23:42:42 +00:00
|
|
|
* Since: 2.14
|
2007-12-13 05:49:11 +00:00
|
|
|
*/
|
2007-12-13 05:16:33 +00:00
|
|
|
void
|
2008-10-21 20:20:50 +00:00
|
|
|
gdk_app_launch_context_set_icon (GdkAppLaunchContext *context,
|
2007-12-13 05:16:33 +00:00
|
|
|
GIcon *icon)
|
|
|
|
{
|
2008-10-21 20:20:50 +00:00
|
|
|
g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
|
|
|
|
g_return_if_fail (icon == NULL || G_IS_ICON (icon));
|
|
|
|
|
2010-12-11 05:14:53 +00:00
|
|
|
if (context->icon)
|
2007-12-13 05:16:33 +00:00
|
|
|
{
|
2010-12-11 05:14:53 +00:00
|
|
|
g_object_unref (context->icon);
|
|
|
|
context->icon = NULL;
|
2007-12-13 05:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (icon)
|
2010-12-11 05:14:53 +00:00
|
|
|
context->icon = g_object_ref (icon);
|
2007-12-13 05:16:33 +00:00
|
|
|
}
|
|
|
|
|
2007-12-13 05:49:11 +00:00
|
|
|
/**
|
|
|
|
* gdk_app_launch_context_set_icon_name:
|
|
|
|
* @context: a #GdkAppLaunchContext
|
2010-02-19 16:53:17 +00:00
|
|
|
* @icon_name: (allow-none): an icon name, or %NULL
|
2007-12-13 05:49:11 +00:00
|
|
|
*
|
2010-12-09 06:08:05 +00:00
|
|
|
* 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().
|
2008-08-02 04:12:55 +00:00
|
|
|
*
|
|
|
|
* If both @icon and @icon_name are set, the @icon_name takes priority.
|
2010-12-09 06:08:05 +00:00
|
|
|
* 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
|
2008-08-02 04:12:55 +00:00
|
|
|
* for the launched application itself.
|
2010-12-09 06:08:05 +00:00
|
|
|
*
|
2008-02-15 23:42:42 +00:00
|
|
|
* Since: 2.14
|
2007-12-13 05:49:11 +00:00
|
|
|
*/
|
2007-12-13 05:16:33 +00:00
|
|
|
void
|
|
|
|
gdk_app_launch_context_set_icon_name (GdkAppLaunchContext *context,
|
2010-12-09 06:08:05 +00:00
|
|
|
const char *icon_name)
|
2007-12-13 05:16:33 +00:00
|
|
|
{
|
2008-10-21 20:20:50 +00:00
|
|
|
g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
|
|
|
|
|
2010-12-11 05:14:53 +00:00
|
|
|
g_free (context->icon_name);
|
|
|
|
context->icon_name = g_strdup (icon_name);
|
2007-12-13 05:16:33 +00:00
|
|
|
}
|
|
|
|
|
2007-12-13 05:49:11 +00:00
|
|
|
/**
|
|
|
|
* gdk_app_launch_context_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GdkAppLaunchContext.
|
|
|
|
*
|
|
|
|
* Returns: a new #GdkAppLaunchContext
|
|
|
|
*
|
2008-02-15 23:42:42 +00:00
|
|
|
* Since: 2.14
|
2010-12-09 06:08:05 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.0: Use gdk_display_get_app_launch_context() instead
|
2007-12-13 05:49:11 +00:00
|
|
|
*/
|
2007-12-13 05:16:33 +00:00
|
|
|
GdkAppLaunchContext *
|
|
|
|
gdk_app_launch_context_new (void)
|
|
|
|
{
|
2010-12-09 06:08:05 +00:00
|
|
|
return gdk_display_get_app_launch_context (gdk_display_get_default ());
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
gdk_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
|
|
|
|
GAppInfo *info,
|
|
|
|
GList *files)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_app_launch_context_launch_failed (GAppLaunchContext *context,
|
|
|
|
const gchar *startup_notify_id)
|
|
|
|
{
|
2007-12-13 05:16:33 +00:00
|
|
|
}
|