1 | /* |
2 | * Copyright © 2010 Codethink Limited |
3 | * Copyright © 2013 Canonical Limited |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Lesser General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the licence, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Lesser General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Lesser General Public |
16 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
17 | * |
18 | * Author: Ryan Lortie <desrt@desrt.ca> |
19 | */ |
20 | |
21 | #include "config.h" |
22 | |
23 | #include "gtkapplicationprivate.h" |
24 | #include "gtknative.h" |
25 | |
26 | #include <gdk/x11/gdkx.h> |
27 | |
28 | typedef GtkApplicationImplDBusClass GtkApplicationImplX11Class; |
29 | |
30 | typedef struct |
31 | { |
32 | GtkApplicationImplDBus dbus; |
33 | |
34 | } GtkApplicationImplX11; |
35 | |
36 | G_DEFINE_TYPE (GtkApplicationImplX11, gtk_application_impl_x11, GTK_TYPE_APPLICATION_IMPL_DBUS) |
37 | |
38 | static void |
39 | gtk_application_impl_x11_handle_window_realize (GtkApplicationImpl *impl, |
40 | GtkWindow *window) |
41 | { |
42 | GtkApplicationImplDBus *dbus = (GtkApplicationImplDBus *) impl; |
43 | GdkSurface *gdk_surface; |
44 | char *window_path; |
45 | |
46 | gdk_surface = gtk_native_get_surface (self: GTK_NATIVE (ptr: window)); |
47 | |
48 | if (!GDK_IS_X11_SURFACE (gdk_surface)) |
49 | return; |
50 | |
51 | window_path = gtk_application_impl_dbus_get_window_path (dbus, window); |
52 | |
53 | gdk_x11_surface_set_utf8_property (surface: gdk_surface, name: "_GTK_APPLICATION_ID" , value: dbus->application_id); |
54 | gdk_x11_surface_set_utf8_property (surface: gdk_surface, name: "_GTK_UNIQUE_BUS_NAME" , value: dbus->unique_name); |
55 | gdk_x11_surface_set_utf8_property (surface: gdk_surface, name: "_GTK_APPLICATION_OBJECT_PATH" , value: dbus->object_path); |
56 | gdk_x11_surface_set_utf8_property (surface: gdk_surface, name: "_GTK_WINDOW_OBJECT_PATH" , value: window_path); |
57 | gdk_x11_surface_set_utf8_property (surface: gdk_surface, name: "_GTK_APP_MENU_OBJECT_PATH" , value: dbus->app_menu_path); |
58 | gdk_x11_surface_set_utf8_property (surface: gdk_surface, name: "_GTK_MENUBAR_OBJECT_PATH" , value: dbus->menubar_path); |
59 | |
60 | g_free (mem: window_path); |
61 | } |
62 | |
63 | static GVariant * |
64 | gtk_application_impl_x11_get_window_system_id (GtkApplicationImplDBus *dbus, |
65 | GtkWindow *window) |
66 | { |
67 | GdkSurface *gdk_surface; |
68 | |
69 | gdk_surface = gtk_native_get_surface (self: GTK_NATIVE (ptr: window)); |
70 | |
71 | if (GDK_IS_X11_SURFACE (gdk_surface)) |
72 | return g_variant_new_uint32 (GDK_SURFACE_XID (gdk_surface)); |
73 | |
74 | return GTK_APPLICATION_IMPL_DBUS_CLASS (gtk_application_impl_x11_parent_class)->get_window_system_id (dbus, window); |
75 | } |
76 | |
77 | static void |
78 | gtk_application_impl_x11_init (GtkApplicationImplX11 *x11) |
79 | { |
80 | } |
81 | |
82 | static void |
83 | gtk_application_impl_x11_before_emit (GtkApplicationImpl *impl, |
84 | GVariant *platform_data) |
85 | { |
86 | const char *startup_notification_id = NULL; |
87 | |
88 | g_variant_lookup (dictionary: platform_data, key: "desktop-startup-id" , format_string: "&s" , &startup_notification_id); |
89 | |
90 | gdk_x11_display_set_startup_notification_id (display: gdk_display_get_default (), startup_id: startup_notification_id); |
91 | } |
92 | |
93 | static void |
94 | gtk_application_impl_x11_class_init (GtkApplicationImplX11Class *class) |
95 | { |
96 | GtkApplicationImplDBusClass *dbus_class = GTK_APPLICATION_IMPL_DBUS_CLASS (class); |
97 | GtkApplicationImplClass *impl_class = GTK_APPLICATION_IMPL_CLASS (class); |
98 | |
99 | impl_class->handle_window_realize = gtk_application_impl_x11_handle_window_realize; |
100 | dbus_class->get_window_system_id = gtk_application_impl_x11_get_window_system_id; |
101 | impl_class->before_emit = gtk_application_impl_x11_before_emit; |
102 | } |
103 | |