| 1 |
/* |
| 2 |
* Copyright © 2010 Intel Corporation |
| 3 |
* |
| 4 |
* This library is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU Lesser General Public License |
| 6 |
* as published by the Free Software Foundation; either version 2 of |
| 7 |
* the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This library is distributed in the hope that it will be useful, but |
| 10 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* Lesser General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU Lesser General Public |
| 15 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include "config.h" |
| 19 |
|
| 20 |
#include <string.h> |
| 21 |
#include <unistd.h> |
| 22 |
|
| 23 |
#include <glib.h> |
| 24 |
#include <gio/gdesktopappinfo.h> |
| 25 |
|
| 26 |
#include "gdkwayland.h" |
| 27 |
#include "gdkprivate-wayland.h" |
| 28 |
#include "gdkapplaunchcontextprivate.h" |
| 29 |
#include "gdkscreen.h" |
| 30 |
#include "gdkinternals.h" |
| 31 |
#include "gdkintl.h" |
| 32 |
|
| 33 |
#ifdef HAVE_XDG_ACTIVATION |
| 34 |
typedef struct { |
| 35 |
gchar *token; |
| 36 |
} AppLaunchData; |
| 37 |
|
| 38 |
static void |
| 39 |
token_done (gpointer data, |
| 40 |
struct xdg_activation_token_v1 *provider, |
| 41 |
const char *token) |
| 42 |
{ |
| 43 |
AppLaunchData *app_launch_data = data; |
| 44 |
|
| 45 |
app_launch_data->token = g_strdup (token); |
| 46 |
} |
| 47 |
|
| 48 |
static const struct xdg_activation_token_v1_listener token_listener = { |
| 49 |
token_done, |
| 50 |
}; |
| 51 |
#endif |
| 52 |
|
| 53 |
static char * |
| 54 |
gdk_wayland_app_launch_context_get_startup_notify_id (GAppLaunchContext *context, |
| 55 |
GAppInfo *info, |
| 56 |
GList *files) |
| 57 |
{ |
| 58 |
GdkWaylandDisplay *display; |
| 59 |
gchar *id = NULL; |
| 60 |
|
| 61 |
g_object_get (context, "display", &display, NULL); |
| 62 |
|
| 63 |
#ifdef HAVE_XDG_ACTIVATION |
| 64 |
if (display->xdg_activation) |
| 65 |
{ |
| 66 |
struct xdg_activation_token_v1 *token; |
| 67 |
struct wl_event_queue *event_queue; |
| 68 |
struct wl_surface *wl_surface = NULL; |
| 69 |
GdkSeat *seat; |
| 70 |
GdkWindow *focus_window; |
| 71 |
AppLaunchData app_launch_data = { 0 }; |
| 72 |
|
| 73 |
event_queue = wl_display_create_queue (display->wl_display); |
| 74 |
|
| 75 |
seat = gdk_display_get_default_seat (GDK_DISPLAY (display)); |
| 76 |
token = xdg_activation_v1_get_activation_token (display->xdg_activation); |
| 77 |
wl_proxy_set_queue ((struct wl_proxy *) token, event_queue); |
| 78 |
|
| 79 |
xdg_activation_token_v1_add_listener (token, |
| 80 |
&token_listener, |
| 81 |
&app_launch_data); |
| 82 |
xdg_activation_token_v1_set_serial (token, |
| 83 |
_gdk_wayland_seat_get_last_implicit_grab_serial (seat, NULL), |
| 84 |
gdk_wayland_seat_get_wl_seat (seat)); |
| 85 |
|
| 86 |
focus_window = gdk_wayland_device_get_focus (gdk_seat_get_keyboard (seat)); |
| 87 |
if (focus_window) |
| 88 |
wl_surface = gdk_wayland_window_get_wl_surface (focus_window); |
| 89 |
if (wl_surface) |
| 90 |
xdg_activation_token_v1_set_surface (token, wl_surface); |
| 91 |
|
| 92 |
xdg_activation_token_v1_commit (token); |
| 93 |
|
| 94 |
while (app_launch_data.token == NULL) |
| 95 |
wl_display_dispatch_queue (display->wl_display, event_queue); |
| 96 |
|
| 97 |
xdg_activation_token_v1_destroy (token); |
| 98 |
id = app_launch_data.token; |
| 99 |
wl_event_queue_destroy (event_queue); |
| 100 |
} |
| 101 |
else |
| 102 |
#endif |
| 103 |
if (display->gtk_shell_version >= 3) |
| 104 |
{ |
| 105 |
id = g_uuid_string_random (); |
| 106 |
gtk_shell1_notify_launch (display->gtk_shell, id); |
| 107 |
} |
| 108 |
|
| 109 |
g_object_unref (display); |
| 110 |
|
| 111 |
return id; |
| 112 |
} |
| 113 |
|
| 114 |
static void |
| 115 |
gdk_wayland_app_launch_context_launch_failed (GAppLaunchContext *context, |
| 116 |
const char *startup_notify_id) |
| 117 |
{ |
| 118 |
} |
| 119 |
|
| 120 |
typedef struct _GdkWaylandAppLaunchContext GdkWaylandAppLaunchContext; |
| 121 |
typedef struct _GdkWaylandAppLaunchContextClass GdkWaylandAppLaunchContextClass; |
| 122 |
|
| 123 |
struct _GdkWaylandAppLaunchContext |
| 124 |
{ |
| 125 |
GdkAppLaunchContext base; |
| 126 |
gchar *name; |
| 127 |
guint serial; |
| 128 |
}; |
| 129 |
|
| 130 |
struct _GdkWaylandAppLaunchContextClass |
| 131 |
{ |
| 132 |
GdkAppLaunchContextClass base_class; |
| 133 |
}; |
| 134 |
|
| 135 |
GType gdk_wayland_app_launch_context_get_type (void); |
| 136 |
|
| 137 |
G_DEFINE_TYPE (GdkWaylandAppLaunchContext, gdk_wayland_app_launch_context, GDK_TYPE_APP_LAUNCH_CONTEXT) |
| 138 |
|
| 139 |
static void |
| 140 |
gdk_wayland_app_launch_context_class_init (GdkWaylandAppLaunchContextClass *klass) |
| 141 |
{ |
| 142 |
GAppLaunchContextClass *ctx_class = G_APP_LAUNCH_CONTEXT_CLASS (klass); |
| 143 |
|
| 144 |
ctx_class->get_startup_notify_id = gdk_wayland_app_launch_context_get_startup_notify_id; |
| 145 |
ctx_class->launch_failed = gdk_wayland_app_launch_context_launch_failed; |
| 146 |
} |
| 147 |
|
| 148 |
static void |
| 149 |
gdk_wayland_app_launch_context_init (GdkWaylandAppLaunchContext *ctx) |
| 150 |
{ |
| 151 |
} |
| 152 |
|
| 153 |
GdkAppLaunchContext * |
| 154 |
_gdk_wayland_display_get_app_launch_context (GdkDisplay *display) |
| 155 |
{ |
| 156 |
GdkAppLaunchContext *ctx; |
| 157 |
|
| 158 |
ctx = g_object_new (gdk_wayland_app_launch_context_get_type (), |
| 159 |
"display", display, |
| 160 |
NULL); |
| 161 |
|
| 162 |
return ctx; |
| 163 |
} |