Make GdkAppLaunchContext display-dependent

Add a GdkDisplay::get_app_launch_context vfunc, and a
gdk_display_get_app_launch_context that for X11 returns a subclass.
For win32 and quartz, the implementations were trivial, so we
just return a new GdkAppLaunchContext without subclassing. Since
the type of the context now depends on the display,
gdk_app_launch_context_set_display is deprecated.
This commit is contained in:
Matthias Clasen 2010-12-09 01:08:05 -05:00
parent de84a7b14f
commit 06f75b3727
13 changed files with 133 additions and 151 deletions

View File

@ -85,6 +85,7 @@ gdk_display_beep
gdk_display_close
gdk_display_device_is_grabbed
gdk_display_flush
gdk_display_get_app_launch_context
gdk_display_get_default
gdk_display_get_default_cursor_size
gdk_display_get_default_group

View File

@ -61,10 +61,14 @@ 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);
G_DEFINE_TYPE (GdkAppLaunchContext, gdk_app_launch_context,
G_TYPE_APP_LAUNCH_CONTEXT)
G_DEFINE_TYPE (GdkAppLaunchContext, gdk_app_launch_context, G_TYPE_APP_LAUNCH_CONTEXT)
static void
gdk_app_launch_context_class_init (GdkAppLaunchContextClass *klass)
@ -75,8 +79,8 @@ gdk_app_launch_context_class_init (GdkAppLaunchContextClass *klass)
gobject_class->finalize = gdk_app_launch_context_finalize;
context_class->get_display = gdk_app_launch_context_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_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));
}
@ -85,8 +89,8 @@ static void
gdk_app_launch_context_init (GdkAppLaunchContext *context)
{
context->priv = G_TYPE_INSTANCE_GET_PRIVATE (context,
GDK_TYPE_APP_LAUNCH_CONTEXT,
GdkAppLaunchContextPrivate);
GDK_TYPE_APP_LAUNCH_CONTEXT,
GdkAppLaunchContextPrivate);
context->priv->workspace = -1;
}
@ -144,22 +148,17 @@ gdk_app_launch_context_get_display (GAppLaunchContext *context,
* 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)
{
g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
g_return_if_fail (display == NULL || GDK_IS_DISPLAY (display));
if (context->priv->display)
{
g_object_unref (context->priv->display);
context->priv->display = NULL;
}
if (display)
context->priv->display = g_object_ref (display);
g_warn_if_fail (display == NULL || display == context->priv->display);
}
/**
@ -178,11 +177,13 @@ gdk_app_launch_context_set_display (GdkAppLaunchContext *context,
*/
void
gdk_app_launch_context_set_screen (GdkAppLaunchContext *context,
GdkScreen *screen)
GdkScreen *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->priv->display);
if (context->priv->screen)
{
g_object_unref (context->priv->screen);
@ -199,12 +200,12 @@ gdk_app_launch_context_set_screen (GdkAppLaunchContext *context,
* @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,
* 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.
*
@ -212,7 +213,7 @@ gdk_app_launch_context_set_screen (GdkAppLaunchContext *context,
*/
void
gdk_app_launch_context_set_desktop (GdkAppLaunchContext *context,
gint desktop)
gint desktop)
{
g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
@ -225,7 +226,7 @@ gdk_app_launch_context_set_desktop (GdkAppLaunchContext *context,
* @timestamp: a timestamp
*
* Sets the timestamp of @context. The timestamp should ideally
* be taken from the event that triggered the launch.
* 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
@ -236,7 +237,7 @@ gdk_app_launch_context_set_desktop (GdkAppLaunchContext *context,
*/
void
gdk_app_launch_context_set_timestamp (GdkAppLaunchContext *context,
guint32 timestamp)
guint32 timestamp)
{
g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
@ -280,20 +281,20 @@ gdk_app_launch_context_set_icon (GdkAppLaunchContext *context,
* @context: a #GdkAppLaunchContext
* @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().
* 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
* 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.
*
*
* Since: 2.14
*/
void
gdk_app_launch_context_set_icon_name (GdkAppLaunchContext *context,
const char *icon_name)
const char *icon_name)
{
g_return_if_fail (GDK_IS_APP_LAUNCH_CONTEXT (context));
@ -309,9 +310,25 @@ gdk_app_launch_context_set_icon_name (GdkAppLaunchContext *context,
* 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)
{
return g_object_new (GDK_TYPE_APP_LAUNCH_CONTEXT, NULL);
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)
{
}

View File

@ -28,6 +28,7 @@
#define __GDK_APP_LAUNCH_CONTEXT_H__
#include <gio/gio.h>
#include <gdk/gdktypes.h>
#include <gdk/gdkscreen.h>
G_BEGIN_DECLS
@ -39,7 +40,6 @@ G_BEGIN_DECLS
#define GDK_IS_APP_LAUNCH_CONTEXT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GDK_TYPE_APP_LAUNCH_CONTEXT))
#define GDK_APP_LAUNCH_CONTEXT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GDK_TYPE_APP_LAUNCH_CONTEXT, GdkAppLaunchContextClass))
typedef struct GdkAppLaunchContext GdkAppLaunchContext;
typedef struct GdkAppLaunchContextClass GdkAppLaunchContextClass;
typedef struct GdkAppLaunchContextPrivate GdkAppLaunchContextPrivate;

View File

@ -121,8 +121,7 @@ static GdkWindow* singlehead_default_window_get_pointer (GdkWindow *window
GdkModifierType *mask);
static GdkWindow* singlehead_default_window_at_pointer (GdkScreen *screen,
gint *win_x,
gint *win_y);
static GdkWindow *gdk_window_real_window_get_device_position (GdkDisplay *display,
gint *win_y);static GdkWindow *gdk_window_real_window_get_device_position (GdkDisplay *display,
GdkDevice *device,
GdkWindow *window,
gint *x,
@ -132,6 +131,7 @@ static GdkWindow *gdk_display_real_get_window_at_device_position (GdkDisplay
GdkDevice *device,
gint *win_x,
gint *win_y);
static GdkAppLaunchContext *gdk_display_real_get_app_launch_context (GdkDisplay *display);
static guint signals[LAST_SIGNAL] = { 0 };
@ -179,6 +179,8 @@ gdk_display_class_init (GdkDisplayClass *class)
object_class->finalize = gdk_display_finalize;
object_class->dispose = gdk_display_dispose;
class->get_app_launch_context = gdk_display_real_get_app_launch_context;
/**
* GdkDisplay::opened:
* @display: the object on which the signal is emitted
@ -2211,3 +2213,32 @@ gdk_add_client_message_filter (GdkAtom message_type,
gdk_display_add_client_message_filter (gdk_display_get_default (),
message_type, func, data);
}
static GdkAppLaunchContext *
gdk_display_real_get_app_launch_context (GdkDisplay *display)
{
GdkAppLaunchContext *ctx;
ctx = gdk_app_launch_context_new ();
gdk_app_launch_context_set_display (ctx, display);
return ctx;
}
/**
* gdk_display_get_app_launch_context:
* @display: a #GdkDisplay
*
* Returns a #GdkAppLaunchContext suitable for launching
* applications on the given display.
*
* Returns: a new #GdkAppLaunchContext for @display.
* Free with g_object_unref() when done
*
* Since: 3.0
*/
GdkAppLaunchContext *
gdk_display_get_app_launch_context (GdkDisplay *display)
{
return GDK_DISPLAY_GET_CLASS(display)->get_app_launch_context (display);
}

View File

@ -309,6 +309,8 @@ gboolean gdk_display_supports_composite (GdkDisplay *display);
GdkDeviceManager * gdk_display_get_device_manager (GdkDisplay *display);
GdkAppLaunchContext *gdk_display_get_app_launch_context (GdkDisplay *display);
G_END_DECLS

View File

@ -304,6 +304,7 @@ struct _GdkDisplayClass
GdkAtom message_type,
GdkFilterFunc func,
gpointer data);
GdkAppLaunchContext * (*get_app_launch_context) (GdkDisplay *display);
/* Signals */
@ -575,12 +576,6 @@ struct GdkAppLaunchContextPrivate
char *icon_name;
};
char *_gdk_windowing_get_startup_notify_id (GAppLaunchContext *context,
GAppInfo *info,
GList *files);
void _gdk_windowing_launch_failed (GAppLaunchContext *context,
const char *startup_notify_id);
void _gdk_display_device_grab_update (GdkDisplay *display,
GdkDevice *device,
GdkDevice *source_device,

View File

@ -147,6 +147,7 @@ typedef struct _GdkVisual GdkVisual;
typedef struct _GdkWindow GdkWindow;
typedef struct _GdkDisplay GdkDisplay;
typedef struct _GdkScreen GdkScreen;
typedef struct GdkAppLaunchContext GdkAppLaunchContext;
/**
* GdkByteOrder:

View File

@ -21,7 +21,6 @@ libgdk_quartz_la_SOURCES = \
GdkQuartzView.h \
GdkQuartzWindow.c \
GdkQuartzWindow.h \
gdkapplaunchcontext-quartz.c \
gdkcursor-quartz.c \
gdkdevice-core.c \
gdkdevicemanager-core.c \

View File

@ -1,42 +0,0 @@
/* gdkapplaunchcontext-quartz.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
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Matthias Clasen <mclasen@redhat.com>
*/
#include "config.h"
#include "gdkapplaunchcontext.h"
char *
_gdk_windowing_get_startup_notify_id (GAppLaunchContext *context,
GAppInfo *info,
GList *files)
{
return NULL;
}
void
_gdk_windowing_launch_failed (GAppLaunchContext *context,
const char *startup_notify_id)
{
}

View File

@ -26,7 +26,6 @@ EXTRA_DIST += \
libgdk_win32_la_SOURCES = \
xcursors.h \
gdkapplaunchcontext-win32.c \
gdkcursor-win32.c \
gdkdevicemanager-win32.c \
gdkdevicemanager-win32.h \

View File

@ -1,42 +0,0 @@
/* gdkapplaunchcontext-win32.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
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Matthias Clasen <mclasen@redhat.com>
*/
#include "config.h"
#include "gdkapplaunchcontext.h"
char *
_gdk_windowing_get_startup_notify_id (GAppLaunchContext *context,
GAppInfo *info,
GList *files)
{
return NULL;
}
void
_gdk_windowing_launch_failed (GAppLaunchContext *context,
const char *startup_notify_id)
{
}

View File

@ -23,10 +23,10 @@
#include "config.h"
#include "gdkapplaunchcontext.h"
#include "gdkinternals.h"
#include "gdkx.h"
#include "gdkscreen.h"
#include "gdkinternals.h"
#include "gdkintl.h"
#include <glib.h>
@ -258,10 +258,10 @@ add_startup_timeout (GdkScreen *screen,
}
char *
_gdk_windowing_get_startup_notify_id (GAppLaunchContext *context,
GAppInfo *info,
GList *files)
static char *
gdk_app_launch_context_x11_get_startup_notify_id (GAppLaunchContext *context,
GAppInfo *info,
GList *files)
{
static int sequence = 0;
GdkAppLaunchContextPrivate *priv;
@ -281,21 +281,11 @@ _gdk_windowing_get_startup_notify_id (GAppLaunchContext *context,
priv = GDK_APP_LAUNCH_CONTEXT (context)->priv;
display = priv->display;
if (priv->screen)
{
screen = priv->screen;
display = gdk_screen_get_display (priv->screen);
}
else if (priv->display)
{
display = priv->display;
screen = gdk_display_get_default_screen (display);
}
screen = priv->screen;
else
{
display = gdk_display_get_default ();
screen = gdk_display_get_default_screen (display);
}
screen = gdk_display_get_default_screen (priv->display);
fileinfo = NULL;
@ -398,9 +388,9 @@ _gdk_windowing_get_startup_notify_id (GAppLaunchContext *context,
}
void
_gdk_windowing_launch_failed (GAppLaunchContext *context,
const char *startup_notify_id)
static void
gdk_app_launch_context_x11_launch_failed (GAppLaunchContext *context,
const char *startup_notify_id)
{
GdkAppLaunchContextPrivate *priv;
GdkScreen *screen;
@ -412,10 +402,8 @@ _gdk_windowing_launch_failed (GAppLaunchContext *context,
if (priv->screen)
screen = priv->screen;
else if (priv->display)
screen = gdk_display_get_default_screen (priv->display);
else
screen = gdk_display_get_default_screen (gdk_display_get_default ());
screen = gdk_display_get_default_screen (priv->display);
data = g_object_get_data (G_OBJECT (screen), "appinfo-startup-data");
@ -441,3 +429,33 @@ _gdk_windowing_launch_failed (GAppLaunchContext *context,
}
}
}
typedef struct GdkAppLaunchContext GdkAppLaunchContextX11;
typedef struct GdkAppLaunchContextClass GdkAppLaunchContextX11Class;
G_DEFINE_TYPE (GdkAppLaunchContextX11, _gdk_app_launch_context_x11, GDK_TYPE_APP_LAUNCH_CONTEXT)
static void
_gdk_app_launch_context_x11_class_init (GdkAppLaunchContextX11Class *klass)
{
GAppLaunchContextClass *ctx_class = G_APP_LAUNCH_CONTEXT_CLASS (klass);
ctx_class->get_startup_notify_id = gdk_app_launch_context_x11_get_startup_notify_id;
ctx_class->launch_failed = gdk_app_launch_context_x11_launch_failed;
}
static void
_gdk_app_launch_context_x11_init (GdkAppLaunchContextX11 *ctx)
{
}
GdkAppLaunchContext *
_gdk_x11_display_get_app_launch_context (GdkDisplay *display)
{
GdkAppLaunchContext *ctx;
ctx = g_object_new (_gdk_app_launch_context_x11_get_type (), NULL);
gdk_app_launch_context_set_display (ctx, display);
return ctx;
}

View File

@ -2703,6 +2703,8 @@ gdk_x11_display_error_trap_pop_ignored (GdkDisplay *display)
gdk_x11_display_error_trap_pop_internal (display, FALSE);
}
extern GdkAppLaunchContext *_gdk_x11_display_get_app_launch_context (GdkDisplay *display);
static void
_gdk_display_x11_class_init (GdkDisplayX11Class * class)
{
@ -2730,5 +2732,6 @@ _gdk_display_x11_class_init (GdkDisplayX11Class * class)
display_class->list_devices = gdk_x11_display_list_devices;
display_class->send_client_message = gdk_x11_display_send_client_message;
display_class->add_client_message_filter = gdk_x11_display_add_client_message_filter;
display_class->get_app_launch_context = _gdk_x11_display_get_app_launch_context;
}