1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
/*
* Copyright (C) 2021 Alberts Muktupāvels
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include "config.h"
#include "meta-request-csd.h"
#include <dlfcn.h>
typedef GType (* RegisterStaticSimple) (GType parent_type,
const gchar *type_name,
guint class_size,
GClassInitFunc class_init,
guint instance_size,
GInstanceInitFunc instance_init,
GTypeFlags flags);
typedef gint (* AddInstancePrivateFunc) (GType class_type,
gsize private_size);
typedef struct _GtkMnemnonicHash GtkMnemonicHash;
typedef struct _GtkCssNode GtkCssNode;
struct _GtkWindowPrivate
{
GtkMnemonicHash *mnemonic_hash;
GtkWidget *attach_widget;
GtkWidget *default_widget;
GtkWidget *initial_focus;
GtkWidget *focus_widget;
GtkWindow *transient_parent;
GtkWindowGeometryInfo *geometry_info;
GtkWindowGroup *group;
GdkScreen *screen;
GdkDisplay *display;
GtkApplication *application;
GList *popovers;
GdkModifierType mnemonic_modifier;
gchar *startup_id;
gchar *title;
gchar *wmclass_class;
gchar *wmclass_name;
gchar *wm_role;
guint keys_changed_handler;
guint delete_event_handler;
guint32 initial_timestamp;
guint16 configure_request_count;
guint mnemonics_display_timeout_id;
gint scale;
gint title_height;
GtkWidget *title_box;
GtkWidget *titlebar;
GtkWidget *popup_menu;
GdkWindow *border_window[8];
gint initial_fullscreen_monitor;
guint edge_constraints;
guint need_default_position : 1;
guint need_default_size : 1;
guint above_initially : 1;
guint accept_focus : 1;
guint below_initially : 1;
guint builder_visible : 1;
guint configure_notify_received : 1;
guint decorated : 1;
guint deletable : 1;
guint destroy_with_parent : 1;
guint focus_on_map : 1;
guint fullscreen_initially : 1;
guint has_focus : 1;
guint has_user_ref_count : 1;
guint has_toplevel_focus : 1;
guint hide_titlebar_when_maximized : 1;
guint iconify_initially : 1;
guint is_active : 1;
guint maximize_initially : 1;
guint mnemonics_visible : 1;
guint mnemonics_visible_set : 1;
guint focus_visible : 1;
guint modal : 1;
guint position : 3;
guint resizable : 1;
guint skips_pager : 1;
guint skips_taskbar : 1;
guint stick_initially : 1;
guint transient_parent_group : 1;
guint type : 4;
guint urgent : 1;
guint gravity : 5;
guint csd_requested : 1;
guint client_decorated : 1;
guint use_client_shadow : 1;
guint maximized : 1;
guint fullscreen : 1;
guint tiled : 1;
guint unlimited_guessed_size_x : 1;
guint unlimited_guessed_size_y : 1;
guint force_resize : 1;
guint fixate_size : 1;
guint use_subsurface : 1;
GdkWindowTypeHint type_hint;
GtkGesture *multipress_gesture;
GtkGesture *drag_gesture;
GdkWindow *hardcoded_window;
GtkCssNode *decoration_node;
};
static RegisterStaticSimple register_static_simple_orig_func = NULL;
static RegisterStaticSimple register_static_simple_func = NULL;
static GType gtk_window_type = 0;
static AddInstancePrivateFunc add_instance_private_orig_func = NULL;
static AddInstancePrivateFunc add_instance_private_func = NULL;
static gsize gtk_window_private_size = 0;
static GType
find_gtk_window_type (GType parent_type,
const gchar *type_name,
guint class_size,
GClassInitFunc class_init,
guint instance_size,
GInstanceInitFunc instance_init,
GTypeFlags flags)
{
GType type_id;
type_id = register_static_simple_orig_func (parent_type,
type_name,
class_size,
class_init,
instance_size,
instance_init,
flags);
if (g_strcmp0 (type_name, "GtkWindow") == 0)
{
register_static_simple_func = register_static_simple_orig_func;
gtk_window_type = type_id;
}
return type_id;
}
static gint
find_gtk_window_private_size (GType class_type,
gsize private_size)
{
if (class_type == gtk_window_type)
{
add_instance_private_func = add_instance_private_orig_func;
gtk_window_private_size = private_size;
}
return add_instance_private_orig_func (class_type, private_size);
}
__attribute__((constructor))
static void
add_instance_private_init (void)
{
void *func;
func = dlsym (RTLD_NEXT, "g_type_register_static_simple");
register_static_simple_orig_func = func;
register_static_simple_func = find_gtk_window_type;
func = dlsym (RTLD_NEXT, "g_type_add_instance_private");
add_instance_private_orig_func = func;
add_instance_private_func = find_gtk_window_private_size;
}
GType
g_type_register_static_simple (GType parent_type,
const gchar *type_name,
guint class_size,
GClassInitFunc class_init,
guint instance_size,
GInstanceInitFunc instance_init,
GTypeFlags flags)
{
return register_static_simple_func (parent_type,
type_name,
class_size,
class_init,
instance_size,
instance_init,
flags);
}
gint
g_type_add_instance_private (GType class_type,
gsize private_size)
{
return add_instance_private_func (class_type, private_size);
}
static gboolean
check_gtk_window_private (void)
{
static gboolean ret = FALSE;
static gboolean checked = FALSE;
if (!checked)
{
GtkWindow *window;
if (gtk_window_private_size < sizeof (GtkWindowPrivate))
{
checked = TRUE;
return FALSE;
}
window = g_object_new (GTK_TYPE_WINDOW,
"type", GTK_WINDOW_POPUP,
"type-hint", GDK_WINDOW_TYPE_HINT_TOOLTIP,
NULL);
while (TRUE)
{
GtkWindowPrivate *priv;
GtkWidget *titlebar;
priv = window->priv;
if (priv->type != GTK_WINDOW_POPUP ||
priv->type_hint != GDK_WINDOW_TYPE_HINT_TOOLTIP)
break;
gtk_window_set_gravity (window, GDK_GRAVITY_STATIC);
if (priv->gravity != GDK_GRAVITY_STATIC)
break;
titlebar = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_window_set_titlebar (window, titlebar);
if (priv->title_box != titlebar ||
!priv->client_decorated)
break;
if (priv->csd_requested)
break;
ret = TRUE;
break;
}
gtk_widget_destroy (GTK_WIDGET (window));
checked = TRUE;
}
return ret;
}
void
meta_request_csd (GtkWindow *window)
{
if (!check_gtk_window_private ())
return;
window->priv->csd_requested = TRUE;
}
|