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"
|
2017-11-17 12:46:44 +00:00
|
|
|
#include "gdkdisplay.h"
|
2007-12-13 05:16:33 +00:00
|
|
|
#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.
|
2014-02-04 21:57:57 +00:00
|
|
|
*
|
|
|
|
* ## Launching an application
|
|
|
|
*
|
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
|
|
|
*
|
2017-10-31 03:01:34 +00:00
|
|
|
* gdk_app_launch_context_set_display (display);
|
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
|
|
|
*/
|
|
|
|
|
|
|
|
|
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->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->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_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
|
2014-02-03 21:56:15 +00:00
|
|
|
* [Extended Window Manager Hints](http://www.freedesktop.org/Standards/wm-spec).
|
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
|
|
|
}
|
|
|
|
|
2010-12-09 06:08:05 +00:00
|
|
|
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
|
|
|
}
|