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
|
|
|
/**
|
2021-02-21 05:13:57 +00:00
|
|
|
* GdkAppLaunchContext:
|
|
|
|
*
|
|
|
|
* `GdkAppLaunchContext` handles launching an application in a graphical context.
|
2010-11-15 02:18:45 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* It is an implementation of `GAppLaunchContext` that provides startup
|
2022-02-01 18:55:54 +00:00
|
|
|
* notification and allows to launch applications on a specific workspace.
|
2014-02-04 21:57:57 +00:00
|
|
|
*
|
|
|
|
* ## Launching an application
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* ```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
|
|
|
*
|
2020-02-18 03:11:56 +00:00
|
|
|
* gdk_app_launch_context_set_timestamp (gdk_event_get_time (event));
|
2010-11-15 02:18:45 +00:00
|
|
|
*
|
|
|
|
* 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);
|
2021-02-21 05:13:57 +00:00
|
|
|
* ```
|
2017-12-26 16:34:18 +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);
|
2020-07-24 18:40:36 +00:00
|
|
|
static char * gdk_app_launch_context_get_display_name (GAppLaunchContext *context,
|
2020-02-24 12:39:20 +00:00
|
|
|
GAppInfo *info,
|
|
|
|
GList *files);
|
2020-07-24 18:40:36 +00:00
|
|
|
static char * gdk_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
|
2010-12-09 06:08:05 +00:00
|
|
|
GAppInfo *info,
|
|
|
|
GList *files);
|
|
|
|
static void gdk_app_launch_context_launch_failed (GAppLaunchContext *context,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *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;
|
|
|
|
|
2020-02-24 12:39:20 +00:00
|
|
|
context_class->get_display = gdk_app_launch_context_get_display_name;
|
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
|
|
|
|
2021-02-24 14:09:57 +00:00
|
|
|
/**
|
|
|
|
* GdkAppLaunchContext:display: (attributes org.gtk.Property.get=gdk_app_launch_context_get_display)
|
|
|
|
*
|
|
|
|
* The display that the `GdkAppLaunchContext` is on.
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
static char *
|
2020-02-24 12:39:20 +00:00
|
|
|
gdk_app_launch_context_get_display_name (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));
|
|
|
|
}
|
|
|
|
|
2020-02-24 12:39:20 +00:00
|
|
|
/**
|
2021-02-24 14:09:57 +00:00
|
|
|
* gdk_app_launch_context_get_display: (attributes org.gtk.Method.get_property=display)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @context: a `GdkAppLaunchContext`
|
2020-02-24 12:39:20 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Gets the `GdkDisplay` that @context is for.
|
2020-02-24 12:39:20 +00:00
|
|
|
*
|
2020-02-26 10:23:01 +00:00
|
|
|
* Returns: (transfer none): the display of @context
|
2020-02-24 12:39:20 +00:00
|
|
|
*/
|
|
|
|
GdkDisplay *
|
|
|
|
gdk_app_launch_context_get_display (GdkAppLaunchContext *context)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context), NULL);
|
|
|
|
|
|
|
|
return context->display;
|
|
|
|
}
|
|
|
|
|
2007-12-13 05:49:11 +00:00
|
|
|
/**
|
|
|
|
* gdk_app_launch_context_set_desktop:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @context: a `GdkAppLaunchContext`
|
2007-12-13 05:49:11 +00:00
|
|
|
* @desktop: the number of a workspace, or -1
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Sets the workspace on which applications will be launched.
|
|
|
|
*
|
|
|
|
* This only works when running under a window manager that
|
2010-12-09 06:08:05 +00:00
|
|
|
* 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).
|
2022-02-01 18:55:54 +00:00
|
|
|
* Specifically this sets the `_NET_WM_DESKTOP` property described
|
|
|
|
* in that spec.
|
|
|
|
*
|
|
|
|
* This only works when using the X11 backend.
|
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.
|
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,
|
2020-07-24 13:54:49 +00:00
|
|
|
int 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:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @context: a `GdkAppLaunchContext`
|
2007-12-13 05:49:11 +00:00
|
|
|
* @timestamp: a timestamp
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Sets the timestamp of @context.
|
|
|
|
*
|
|
|
|
* The timestamp should ideally 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
|
|
|
*/
|
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:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @context: a `GdkAppLaunchContext`
|
2021-05-20 03:39:18 +00:00
|
|
|
* @icon: (nullable): a `GIcon`
|
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.
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* See also [method@Gdk.AppLaunchContext.set_icon_name].
|
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:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @context: a `GdkAppLaunchContext`
|
2021-05-21 00:45:06 +00:00
|
|
|
* @icon_name: (nullable): an icon name
|
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.
|
2021-02-21 05:13:57 +00:00
|
|
|
*
|
2010-12-09 06:08:05 +00:00
|
|
|
* The @icon_name will be interpreted in the same way as the Icon field
|
2021-05-27 00:18:23 +00:00
|
|
|
* in desktop files. See also [method@Gdk.AppLaunchContext.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
|
2021-02-21 05:13:57 +00:00
|
|
|
* 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.
|
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,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *startup_notify_id)
|
2010-12-09 06:08:05 +00:00
|
|
|
{
|
2007-12-13 05:16:33 +00:00
|
|
|
}
|