#include "config.h"
-#include <glib.h>
-
-#include "gdkapplaunchcontext.h"
-#include "gdkinternals.h"
+#include "gdkapplaunchcontextprivate.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;
+/**
+ * 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>
+ * <programlisting>
+ * GdkAppLaunchContext *context;
+ *
+ * context = gdk_display_get_app_launch_context (display);
+ *
+ * gdk_app_launch_context_set_screen (screen);
+ * 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);
+ * </programlisting>
+ * </example>
+ */
- context = GDK_APP_LAUNCH_CONTEXT (object);
- priv = context->priv;
+static void gdk_app_launch_context_finalize (GObject *object);
+static gchar * gdk_app_launch_context_get_display (GAppLaunchContext *context,
+ GAppInfo *info,
+ GList *files);
+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);
- if (priv->display)
- g_object_unref (priv->display);
- if (priv->screen)
- g_object_unref (priv->screen);
+enum
+{
+ PROP_0,
+ PROP_DISPLAY
+};
- if (priv->icon)
- g_object_unref (priv->icon);
+G_DEFINE_TYPE (GdkAppLaunchContext, gdk_app_launch_context, G_TYPE_APP_LAUNCH_CONTEXT)
- g_free (priv->icon_name);
+static void
+gdk_app_launch_context_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GdkAppLaunchContext *context = GDK_APP_LAUNCH_CONTEXT (object);
- (*G_OBJECT_CLASS (gdk_app_launch_context_parent_class)->finalize) (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 char *
-get_display (GAppLaunchContext *context,
- GAppInfo *info,
- GList *files)
+static void
+gdk_app_launch_context_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- 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 ();
+ GdkAppLaunchContext *context = GDK_APP_LAUNCH_CONTEXT (object);
- return g_strdup (gdk_display_get_name (display));
+ 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);
+ }
}
static void
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GAppLaunchContextClass *context_class = G_APP_LAUNCH_CONTEXT_CLASS (klass);
+ gobject_class->set_property = gdk_app_launch_context_set_property,
+ gobject_class->get_property = gdk_app_launch_context_get_property;
+
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;
+ context_class->get_display = gdk_app_launch_context_get_display;
+ context_class->get_startup_notify_id = gdk_app_launch_context_get_startup_notify_id;
+ context_class->launch_failed = gdk_app_launch_context_launch_failed;
- g_type_class_add_private (klass, sizeof (GdkAppLaunchContextPrivate));
+ 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));
}
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;
+ context->workspace = -1;
+}
+
+static void
+gdk_app_launch_context_finalize (GObject *object)
+{
+ GdkAppLaunchContext *context = GDK_APP_LAUNCH_CONTEXT (object);
+
+ if (context->display)
+ g_object_unref (context->display);
+
+ if (context->screen)
+ g_object_unref (context->screen);
+
+ if (context->icon)
+ g_object_unref (context->icon);
+
+ g_free (context->icon_name);
+
+ G_OBJECT_CLASS (gdk_app_launch_context_parent_class)->finalize (object);
+}
+
+static gchar *
+gdk_app_launch_context_get_display (GAppLaunchContext *context,
+ GAppInfo *info,
+ GList *files)
+{
+ GdkAppLaunchContext *ctx = GDK_APP_LAUNCH_CONTEXT (context);
+ GdkDisplay *display;
+
+ if (ctx->screen)
+ return gdk_screen_make_display_name (ctx->screen);
+
+ if (ctx->display)
+ display = ctx->display;
+ else
+ display = gdk_display_get_default ();
+
+ return g_strdup (gdk_display_get_name (display));
}
/**
* using this context. See also gdk_app_launch_context_set_screen().
*
* Since: 2.14
+ *
+ * Deprecated: 3.0: Use gdk_display_get_app_launch_context() instead
*/
void
gdk_app_launch_context_set_display (GdkAppLaunchContext *context,
- GdkDisplay *display)
+ GdkDisplay *display)
{
- if (context->priv->display)
- {
- g_object_unref (context->priv->display);
- context->priv->display = NULL;
- }
+ g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
+ g_return_if_fail (display == NULL || GDK_IS_DISPLAY (display));
- if (display)
- context->priv->display = g_object_ref (display);
+ g_warn_if_fail (display == NULL || display == context->display);
}
/**
*
* 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.
+ * If neither @screen or @display are set, the default screen and
+ * display are used.
*
* Since: 2.14
*/
void
gdk_app_launch_context_set_screen (GdkAppLaunchContext *context,
- GdkScreen *screen)
+ GdkScreen *screen)
{
- if (context->priv->screen)
+ g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
+ g_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen));
+
+ g_return_if_fail (screen == NULL || gdk_screen_get_display (screen) == context->display);
+
+ if (context->screen)
{
- g_object_unref (context->priv->screen);
- context->priv->screen = NULL;
+ g_object_unref (context->screen);
+ context->screen = NULL;
}
if (screen)
- context->priv->screen = g_object_ref (screen);
+ context->screen = g_object_ref (screen);
}
/**
* @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>.
+ * 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>.
+ *
+ * When the workspace is not specified or @desktop is set to -1,
+ * it is up to the window manager to pick one, typically it will
+ * be the current workspace.
*
* Since: 2.14
*/
void
gdk_app_launch_context_set_desktop (GdkAppLaunchContext *context,
- gint desktop)
+ gint desktop)
{
- context->priv->workspace = desktop;
+ g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
+
+ context->workspace = desktop;
}
/**
* Sets the timestamp of @context. The timestamp should ideally
* be taken from the event that triggered the launch.
*
+ * 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'.
+ *
* Since: 2.14
*/
void
gdk_app_launch_context_set_timestamp (GdkAppLaunchContext *context,
- guint32 timestamp)
+ guint32 timestamp)
{
- context->priv->timestamp = timestamp;
+ g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
+
+ context->timestamp = timestamp;
}
/**
* gdk_app_launch_context_set_icon:
* @context: a #GdkAppLaunchContext
- * @icon: a #GIcon, or %NULL
+ * @icon: (allow-none): a #GIcon, or %NULL
*
* Sets the icon for applications that are launched with this
- * context. See also gdk_app_launch_context_set_icon_name().
+ * context.
+ *
+ * Window Managers can use this information when displaying startup
+ * notification.
+ *
+ * See also gdk_app_launch_context_set_icon_name().
*
* Since: 2.14
*/
void
-gdk_app_launch_context_set_icon (GdkAppLaunchContext *context,
+gdk_app_launch_context_set_icon (GdkAppLaunchContext *context,
GIcon *icon)
{
- if (context->priv->icon)
+ g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
+ g_return_if_fail (icon == NULL || G_IS_ICON (icon));
+
+ if (context->icon)
{
- g_object_unref (context->priv->icon);
- context->priv->icon = NULL;
+ g_object_unref (context->icon);
+ context->icon = NULL;
}
if (icon)
- context->priv->icon = g_object_ref (icon);
+ context->icon = g_object_ref (icon);
}
/**
* gdk_app_launch_context_set_icon_name:
* @context: a #GdkAppLaunchContext
- * @icon_name: an icon name, or %NULL
+ * @icon_name: (allow-none): 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.
+ * 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
+ * for the launched application itself.
*
- * 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.14
*/
void
gdk_app_launch_context_set_icon_name (GdkAppLaunchContext *context,
- const char *icon_name)
+ const char *icon_name)
{
- g_free (context->priv->icon_name);
- context->priv->icon_name = g_strdup (icon_name);
+ g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
+
+ g_free (context->icon_name);
+ context->icon_name = g_strdup (icon_name);
}
/**
* Returns: a new #GdkAppLaunchContext
*
* Since: 2.14
+ *
+ * Deprecated: 3.0: Use gdk_display_get_app_launch_context() instead
*/
GdkAppLaunchContext *
gdk_app_launch_context_new (void)
{
- GdkAppLaunchContext *context;
-
- context = g_object_new (gdk_app_launch_context_get_type (), NULL);
-
- return context;
+ 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;
+}
-#define __GDK_APP_LAUNCH_CONTEXT_C__
-#include "gdkaliasdef.c"
+static void
+gdk_app_launch_context_launch_failed (GAppLaunchContext *context,
+ const gchar *startup_notify_id)
+{
+}