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
|
#include <gtk/gtk.h>
#include <glib.h>
enum
{
/*
* In GTK+ 3.24.9 and later, the "overlay-scrolling" property is assigned
* a property number of 85. We might as well follow that convention here
* and avoid any property number collisions.
*/
PROP_OVERLAY_SCROLLING = 85
};
static gboolean overlay_scrolling_enabled = TRUE;
static GParamSpec * gtk_overlay_scrolling_pspec;
static void (*original_gtk_settings_set_property) (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void (*original_gtk_settings_get_property) (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void overridden_gtk_settings_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void overridden_gtk_settings_get_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
G_MODULE_EXPORT const char *
g_module_check_init (GModule *module)
{
/*
* Exit immediately on GTK+ versions prior to 3.15.0, since overlay
* scrolling hadn't been introduced yet!
*/
if (gtk_check_version (3,15,0) != NULL)
{
return "Your version of GTK+ is too old to support overlay scrolling.\n"
"This module is thus unnecessary and you should remove it.";
}
/*
* Similarly, a property was introduced in GTK+ 3.24.9 to disable overlay
* scrolling globally, making this module redundant.
*/
else if (gtk_check_version (3,24,9) == NULL)
{
return "Your version of GTK+ already supports globally disabling overlay scrolling.\n"
"This module is thus redundant and you should remove it.";
}
/*
* Otherwise, this module is useful for the current version of GTK+, so
* proceed with loading it.
*/
else
{
g_module_make_resident (module);
return NULL;
}
}
G_MODULE_EXPORT int
gtk_module_init (gint * argc, char *** argv)
{
GtkSettingsClass *gtk_settings_class;
GtkScrolledWindowClass *gtk_scrolled_window_class;
(void) argc;
(void) argv;
gtk_settings_class = g_type_class_ref (GTK_TYPE_SETTINGS);
gtk_overlay_scrolling_pspec = g_param_spec_boolean ("gtk-overlay-scrolling",
"Overlay Scrolling",
"Whether to enable overlay scrolling mode globally",
overlay_scrolling_enabled,
G_PARAM_READWRITE);
g_object_class_install_property (gtk_settings_class,
PROP_OVERLAY_SCROLLING,
gtk_overlay_scrolling_pspec);
original_gtk_settings_set_property = G_OBJECT_CLASS (gtk_settings_class)->set_property;
G_OBJECT_CLASS (gtk_settings_class)->set_property = overridden_gtk_settings_class_set_property;
original_gtk_settings_get_property = G_OBJECT_CLASS (gtk_settings_class)->get_property;
G_OBJECT_CLASS (gtk_settings_class)->get_property = overridden_gtk_settings_class_get_property;
g_type_class_unref (gtk_settings_class);
return 0;
}
static void overridden_gtk_settings_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id)
{
case PROP_OVERLAY_SCROLLING:
overlay_scrolling_enabled = g_value_get_boolean (value);
break;
default:
original_gtk_settings_set_property (object, property_id, value, pspec);
}
}
static void overridden_gtk_settings_get_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id)
{
case PROP_OVERLAY_SCROLLING:
g_value_set_boolean (value, overlay_scrolling_enabled);
break;
default:
original_gtk_settings_get_property (object, property_id, value, pspec);
}
}
|