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 "gdkintl.h"
30
31typedef struct {
32 gchar *token;
33} AppLaunchData;
34
35static void
36token_done (gpointer data,
37 struct xdg_activation_token_v1 *provider,
38 const char *token)
39{
40 AppLaunchData *app_launch_data = data;
41
42 app_launch_data->token = g_strdup (str: token);
43}
44
45static const struct xdg_activation_token_v1_listener token_listener = {
46 token_done,
47};
48
49static char *
50gdk_wayland_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
51 GAppInfo *info,
52 GList *files)
53{
54 GdkWaylandDisplay *display;
55 gchar *id = NULL;
56
57 g_object_get (object: context, first_property_name: "display", &display, NULL);
58
59 if (display->xdg_activation)
60 {
61 struct xdg_activation_token_v1 *token;
62 struct wl_event_queue *event_queue;
63 struct wl_surface *wl_surface = NULL;
64 GdkWaylandSeat *seat;
65 GdkSurface *focus_surface;
66 AppLaunchData app_launch_data = { 0 };
67
68 event_queue = wl_display_create_queue (display: display->wl_display);
69
70 seat = GDK_WAYLAND_SEAT (gdk_display_get_default_seat (GDK_DISPLAY (display)));
71 token = xdg_activation_v1_get_activation_token (display->xdg_activation);
72 wl_proxy_set_queue (proxy: (struct wl_proxy *) token, queue: event_queue);
73
74 xdg_activation_token_v1_add_listener (token,
75 &token_listener,
76 &app_launch_data);
77 xdg_activation_token_v1_set_serial (token,
78 _gdk_wayland_seat_get_last_implicit_grab_serial (seat, NULL),
79 gdk_wayland_seat_get_wl_seat (GDK_SEAT (seat)));
80
81 focus_surface = gdk_wayland_device_get_focus (device: gdk_seat_get_keyboard (GDK_SEAT (seat)));
82 if (focus_surface)
83 wl_surface = gdk_wayland_surface_get_wl_surface (surface: focus_surface);
84 if (wl_surface)
85 xdg_activation_token_v1_set_surface (token, wl_surface);
86
87 xdg_activation_token_v1_commit (token);
88
89 while (app_launch_data.token == NULL)
90 wl_display_dispatch_queue (display: display->wl_display, queue: event_queue);
91
92 xdg_activation_token_v1_destroy (token);
93 id = app_launch_data.token;
94 wl_event_queue_destroy (queue: event_queue);
95 }
96 else if (display->gtk_shell_version >= 3)
97 {
98 id = g_uuid_string_random ();
99 gtk_shell1_notify_launch (display->gtk_shell, id);
100 }
101
102 g_object_unref (object: display);
103
104 return id;
105}
106
107static void
108gdk_wayland_app_launch_context_launch_failed (GAppLaunchContext *context,
109 const char *startup_notify_id)
110{
111}
112
113typedef struct _GdkWaylandAppLaunchContext GdkWaylandAppLaunchContext;
114typedef struct _GdkWaylandAppLaunchContextClass GdkWaylandAppLaunchContextClass;
115
116struct _GdkWaylandAppLaunchContext
117{
118 GdkAppLaunchContext base;
119 char *name;
120 guint serial;
121};
122
123struct _GdkWaylandAppLaunchContextClass
124{
125 GdkAppLaunchContextClass base_class;
126};
127
128GType gdk_wayland_app_launch_context_get_type (void);
129
130G_DEFINE_TYPE (GdkWaylandAppLaunchContext, gdk_wayland_app_launch_context, GDK_TYPE_APP_LAUNCH_CONTEXT)
131
132static void
133gdk_wayland_app_launch_context_class_init (GdkWaylandAppLaunchContextClass *klass)
134{
135 GAppLaunchContextClass *ctx_class = G_APP_LAUNCH_CONTEXT_CLASS (klass);
136
137 ctx_class->get_startup_notify_id = gdk_wayland_app_launch_context_get_startup_notify_id;
138 ctx_class->launch_failed = gdk_wayland_app_launch_context_launch_failed;
139}
140
141static void
142gdk_wayland_app_launch_context_init (GdkWaylandAppLaunchContext *ctx)
143{
144}
145
146GdkAppLaunchContext *
147_gdk_wayland_display_get_app_launch_context (GdkDisplay *display)
148{
149 GdkAppLaunchContext *ctx;
150
151 ctx = g_object_new (object_type: gdk_wayland_app_launch_context_get_type (),
152 first_property_name: "display", display,
153 NULL);
154
155 return ctx;
156}
157

source code of gtk/gdk/wayland/gdkapplaunchcontext-wayland.c