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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
* Copyright (C) 2017 Red Hat
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#include "config.h"
#include "backends/meta-settings-private.h"
#include <gio/gio.h>
#include "backends/meta-backend-private.h"
#include "backends/meta-logical-monitor.h"
#include "backends/meta-monitor-manager-private.h"
#ifndef XWAYLAND_GRAB_DEFAULT_ACCESS_RULES
# warning "XWAYLAND_GRAB_DEFAULT_ACCESS_RULES is not set"
# define XWAYLAND_GRAB_DEFAULT_ACCESS_RULES ""
#endif
enum
{
UI_SCALING_FACTOR_CHANGED,
GLOBAL_SCALING_FACTOR_CHANGED,
FONT_DPI_CHANGED,
EXPERIMENTAL_FEATURES_CHANGED,
PRIVACY_SCREEN_CHANGED,
N_SIGNALS
};
static guint signals[N_SIGNALS];
struct _MetaSettings
{
GObject parent;
MetaBackend *backend;
GSettings *interface_settings;
GSettings *mutter_settings;
GSettings *privacy_settings;
GSettings *wayland_settings;
int ui_scaling_factor;
int global_scaling_factor;
int font_dpi;
gboolean privacy_screen;
MetaExperimentalFeature experimental_features;
gboolean experimental_features_overridden;
gboolean xwayland_allow_grabs;
GPtrArray *xwayland_grab_allow_list_patterns;
GPtrArray *xwayland_grab_deny_list_patterns;
/* A bitmask of MetaXwaylandExtension enum */
int xwayland_disable_extensions;
/* Whether Xwayland should allow X11 clients from different endianness */
gboolean xwayland_allow_byte_swapped_clients;
};
G_DEFINE_TYPE (MetaSettings, meta_settings, G_TYPE_OBJECT)
static int
calculate_ui_scaling_factor (MetaSettings *settings)
{
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (settings->backend);
MetaLogicalMonitor *primary_logical_monitor;
primary_logical_monitor =
meta_monitor_manager_get_primary_logical_monitor (monitor_manager);
if (!primary_logical_monitor)
return 1;
return (int) meta_logical_monitor_get_scale (primary_logical_monitor);
}
static gboolean
update_ui_scaling_factor (MetaSettings *settings)
{
int ui_scaling_factor;
if (meta_backend_is_stage_views_scaled (settings->backend))
ui_scaling_factor = 1;
else
ui_scaling_factor = calculate_ui_scaling_factor (settings);
if (settings->ui_scaling_factor != ui_scaling_factor)
{
settings->ui_scaling_factor = ui_scaling_factor;
return TRUE;
}
else
{
return FALSE;
}
}
void
meta_settings_update_ui_scaling_factor (MetaSettings *settings)
{
if (update_ui_scaling_factor (settings))
g_signal_emit (settings, signals[UI_SCALING_FACTOR_CHANGED], 0);
}
int
meta_settings_get_ui_scaling_factor (MetaSettings *settings)
{
g_assert (settings->ui_scaling_factor != 0);
return settings->ui_scaling_factor;
}
static gboolean
update_global_scaling_factor (MetaSettings *settings)
{
int global_scaling_factor;
global_scaling_factor =
(int) g_settings_get_uint (settings->interface_settings,
"scaling-factor");
if (settings->global_scaling_factor != global_scaling_factor)
{
settings->global_scaling_factor = global_scaling_factor;
return TRUE;
}
else
{
return FALSE;
}
}
gboolean
meta_settings_get_global_scaling_factor (MetaSettings *settings,
int *out_scaling_factor)
{
if (settings->global_scaling_factor == 0)
return FALSE;
*out_scaling_factor = settings->global_scaling_factor;
return TRUE;
}
static gboolean
update_font_dpi (MetaSettings *settings)
{
double text_scaling_factor;
/* Number of logical pixels on an inch when unscaled */
const double dots_per_inch = 96;
/* Being based on Xft, API users expect the DPI to be 1/1024th of an inch. */
const double xft_factor = 1024;
int font_dpi;
text_scaling_factor = g_settings_get_double (settings->interface_settings,
"text-scaling-factor");
font_dpi = (int) (text_scaling_factor *
dots_per_inch *
xft_factor *
settings->ui_scaling_factor);
if (font_dpi != settings->font_dpi)
{
settings->font_dpi = font_dpi;
g_object_set (clutter_settings_get_default (),
"font-dpi", font_dpi,
NULL);
return TRUE;
}
else
{
return FALSE;
}
}
static void
meta_settings_update_font_dpi (MetaSettings *settings)
{
if (update_font_dpi (settings))
g_signal_emit (settings, signals[FONT_DPI_CHANGED], 0);
}
int
meta_settings_get_font_dpi (MetaSettings *settings)
{
g_assert (settings->font_dpi != 0);
return settings->font_dpi;
}
static void
interface_settings_changed (GSettings *interface_settings,
const char *key,
MetaSettings *settings)
{
if (g_str_equal (key, "scaling-factor"))
{
if (update_global_scaling_factor (settings))
g_signal_emit (settings, signals[GLOBAL_SCALING_FACTOR_CHANGED], 0);
}
else if (g_str_equal (key, "text-scaling-factor"))
{
meta_settings_update_font_dpi (settings);
}
}
static void
privacy_settings_changed (GSettings *privacy_settings,
const char *key,
MetaSettings *settings)
{
if (g_str_equal (key, "privacy-screen"))
{
gboolean privacy_screen;
privacy_screen = g_settings_get_boolean (privacy_settings, key);
if (settings->privacy_screen != privacy_screen)
{
settings->privacy_screen = privacy_screen;
g_signal_emit (settings, signals[PRIVACY_SCREEN_CHANGED], 0);
}
}
}
gboolean
meta_settings_is_experimental_feature_enabled (MetaSettings *settings,
MetaExperimentalFeature feature)
{
return !!(settings->experimental_features & feature);
}
void
meta_settings_override_experimental_features (MetaSettings *settings)
{
settings->experimental_features = META_EXPERIMENTAL_FEATURE_NONE;
settings->experimental_features_overridden = TRUE;
}
void
meta_settings_enable_experimental_feature (MetaSettings *settings,
MetaExperimentalFeature feature)
{
g_assert (settings->experimental_features_overridden);
settings->experimental_features |= feature;
}
static gboolean
experimental_features_handler (GVariant *features_variant,
gpointer *result,
gpointer data)
{
MetaSettings *settings = data;
GVariantIter features_iter;
char *feature_str;
MetaExperimentalFeature features = META_EXPERIMENTAL_FEATURE_NONE;
if (settings->experimental_features_overridden)
{
*result = GINT_TO_POINTER (FALSE);
return TRUE;
}
g_variant_iter_init (&features_iter, features_variant);
while (g_variant_iter_loop (&features_iter, "s", &feature_str))
{
MetaExperimentalFeature feature = META_EXPERIMENTAL_FEATURE_NONE;
if (g_str_equal (feature_str, "scale-monitor-framebuffer"))
feature = META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER;
else if (g_str_equal (feature_str, "kms-modifiers"))
feature = META_EXPERIMENTAL_FEATURE_KMS_MODIFIERS;
else if (g_str_equal (feature_str, "rt-scheduler"))
feature = META_EXPERIMENTAL_FEATURE_RT_SCHEDULER;
else if (g_str_equal (feature_str, "autoclose-xwayland"))
feature = META_EXPERIMENTAL_FEATURE_AUTOCLOSE_XWAYLAND;
if (feature)
g_message ("Enabling experimental feature '%s'", feature_str);
else
g_warning ("Unknown experimental feature '%s'", feature_str);
features |= feature;
}
if (features != settings->experimental_features)
{
settings->experimental_features = features;
*result = GINT_TO_POINTER (TRUE);
}
else
{
*result = GINT_TO_POINTER (FALSE);
}
return TRUE;
}
static gboolean
update_experimental_features (MetaSettings *settings)
{
return GPOINTER_TO_INT (g_settings_get_mapped (settings->mutter_settings,
"experimental-features",
experimental_features_handler,
settings));
}
static void
mutter_settings_changed (GSettings *mutter_settings,
gchar *key,
MetaSettings *settings)
{
MetaExperimentalFeature old_experimental_features;
if (!g_str_equal (key, "experimental-features"))
return;
old_experimental_features = settings->experimental_features;
if (update_experimental_features (settings))
g_signal_emit (settings, signals[EXPERIMENTAL_FEATURES_CHANGED], 0,
(unsigned int) old_experimental_features);
}
static void
xwayland_grab_list_add_item (MetaSettings *settings,
char *item)
{
/* If first character is '!', it's a denied value */
if (item[0] != '!')
g_ptr_array_add (settings->xwayland_grab_allow_list_patterns,
g_pattern_spec_new (item));
else if (item[1] != 0)
g_ptr_array_add (settings->xwayland_grab_deny_list_patterns,
g_pattern_spec_new (&item[1]));
}
static gboolean
xwayland_grab_access_rules_handler (GVariant *variant,
gpointer *result,
gpointer data)
{
MetaSettings *settings = data;
GVariantIter iter;
char *item;
/* Create a GPatternSpec for each element */
g_variant_iter_init (&iter, variant);
while (g_variant_iter_loop (&iter, "s", &item))
xwayland_grab_list_add_item (settings, item);
*result = GINT_TO_POINTER (TRUE);
return TRUE;
}
static void
update_xwayland_grab_access_rules (MetaSettings *settings)
{
gchar **system_defaults;
int i;
/* Free previous patterns and create new arrays */
g_clear_pointer (&settings->xwayland_grab_allow_list_patterns,
g_ptr_array_unref);
settings->xwayland_grab_allow_list_patterns =
g_ptr_array_new_with_free_func ((GDestroyNotify) g_pattern_spec_free);
g_clear_pointer (&settings->xwayland_grab_deny_list_patterns,
g_ptr_array_unref);
settings->xwayland_grab_deny_list_patterns =
g_ptr_array_new_with_free_func ((GDestroyNotify) g_pattern_spec_free);
/* Add system defaults values */
system_defaults = g_strsplit (XWAYLAND_GRAB_DEFAULT_ACCESS_RULES, ",", -1);
for (i = 0; system_defaults[i]; i++)
xwayland_grab_list_add_item (settings, system_defaults[i]);
g_strfreev (system_defaults);
/* Then add gsettings values */
g_settings_get_mapped (settings->wayland_settings,
"xwayland-grab-access-rules",
xwayland_grab_access_rules_handler,
settings);
}
static void
update_xwayland_allow_grabs (MetaSettings *settings)
{
settings->xwayland_allow_grabs =
g_settings_get_boolean (settings->wayland_settings,
"xwayland-allow-grabs");
}
static void
update_xwayland_disable_extensions (MetaSettings *settings)
{
settings->xwayland_disable_extensions =
g_settings_get_flags (settings->wayland_settings,
"xwayland-disable-extension");
}
static void
update_privacy_settings (MetaSettings *settings)
{
privacy_settings_changed (settings->privacy_settings,
"privacy-screen",
settings);
}
static void
update_xwayland_allow_byte_swapped_clients (MetaSettings *settings)
{
settings->xwayland_allow_byte_swapped_clients =
g_settings_get_flags (settings->wayland_settings,
"xwayland-allow-byte-swapped-clients");
}
static void
wayland_settings_changed (GSettings *wayland_settings,
gchar *key,
MetaSettings *settings)
{
if (g_str_equal (key, "xwayland-allow-grabs"))
{
update_xwayland_allow_grabs (settings);
}
else if (g_str_equal (key, "xwayland-grab-access-rules"))
{
update_xwayland_grab_access_rules (settings);
}
else if (g_str_equal (key, "xwayland-disable-extension"))
{
update_xwayland_disable_extensions (settings);
}
else if (g_str_equal (key, "xwayland-allow-byte-swapped-clients"))
{
update_xwayland_allow_byte_swapped_clients (settings);
}
}
void
meta_settings_get_xwayland_grab_patterns (MetaSettings *settings,
GPtrArray **allow_list_patterns,
GPtrArray **deny_list_patterns)
{
*allow_list_patterns = settings->xwayland_grab_allow_list_patterns;
*deny_list_patterns = settings->xwayland_grab_deny_list_patterns;
}
gboolean
meta_settings_are_xwayland_grabs_allowed (MetaSettings *settings)
{
return (settings->xwayland_allow_grabs);
}
int
meta_settings_get_xwayland_disable_extensions (MetaSettings *settings)
{
return (settings->xwayland_disable_extensions);
}
gboolean
meta_settings_are_xwayland_byte_swapped_clients_allowed (MetaSettings *settings)
{
return settings->xwayland_allow_byte_swapped_clients;
}
gboolean
meta_settings_is_privacy_screen_enabled (MetaSettings *settings)
{
return settings->privacy_screen;
}
void
meta_settings_set_privacy_screen_enabled (MetaSettings *settings,
gboolean enabled)
{
if (settings->privacy_screen == enabled)
return;
settings->privacy_screen = enabled;
g_settings_set_boolean (settings->privacy_settings, "privacy-screen",
enabled);
}
MetaSettings *
meta_settings_new (MetaBackend *backend)
{
MetaSettings *settings;
settings = g_object_new (META_TYPE_SETTINGS, NULL);
settings->backend = backend;
return settings;
}
static void
meta_settings_dispose (GObject *object)
{
MetaSettings *settings = META_SETTINGS (object);
g_clear_object (&settings->mutter_settings);
g_clear_object (&settings->interface_settings);
g_clear_object (&settings->privacy_settings);
g_clear_object (&settings->wayland_settings);
g_clear_pointer (&settings->xwayland_grab_allow_list_patterns,
g_ptr_array_unref);
g_clear_pointer (&settings->xwayland_grab_deny_list_patterns,
g_ptr_array_unref);
G_OBJECT_CLASS (meta_settings_parent_class)->dispose (object);
}
static void
meta_settings_init (MetaSettings *settings)
{
settings->interface_settings = g_settings_new ("org.gnome.desktop.interface");
g_signal_connect (settings->interface_settings, "changed",
G_CALLBACK (interface_settings_changed),
settings);
settings->privacy_settings = g_settings_new ("org.gnome.desktop.privacy");
g_signal_connect (settings->privacy_settings, "changed",
G_CALLBACK (privacy_settings_changed),
settings);
settings->mutter_settings = g_settings_new ("org.gnome.mutter");
g_signal_connect (settings->mutter_settings, "changed",
G_CALLBACK (mutter_settings_changed),
settings);
settings->wayland_settings = g_settings_new ("org.gnome.mutter.wayland");
g_signal_connect (settings->wayland_settings, "changed",
G_CALLBACK (wayland_settings_changed),
settings);
/* Chain up inter-dependent settings. */
g_signal_connect (settings, "global-scaling-factor-changed",
G_CALLBACK (meta_settings_update_ui_scaling_factor), NULL);
g_signal_connect (settings, "ui-scaling-factor-changed",
G_CALLBACK (meta_settings_update_font_dpi), NULL);
update_global_scaling_factor (settings);
update_experimental_features (settings);
update_xwayland_grab_access_rules (settings);
update_xwayland_allow_grabs (settings);
update_xwayland_disable_extensions (settings);
update_privacy_settings (settings);
}
static void
on_monitors_changed (MetaMonitorManager *monitor_manager,
MetaSettings *settings)
{
meta_settings_update_ui_scaling_factor (settings);
}
void
meta_settings_post_init (MetaSettings *settings)
{
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (settings->backend);
update_ui_scaling_factor (settings);
update_font_dpi (settings);
g_signal_connect_object (monitor_manager, "monitors-changed-internal",
G_CALLBACK (on_monitors_changed),
settings, G_CONNECT_AFTER);
}
static void
meta_settings_class_init (MetaSettingsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = meta_settings_dispose;
signals[UI_SCALING_FACTOR_CHANGED] =
g_signal_new ("ui-scaling-factor-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
signals[GLOBAL_SCALING_FACTOR_CHANGED] =
g_signal_new ("global-scaling-factor-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
signals[FONT_DPI_CHANGED] =
g_signal_new ("font-dpi-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
signals[EXPERIMENTAL_FEATURES_CHANGED] =
g_signal_new ("experimental-features-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_UINT);
signals[PRIVACY_SCREEN_CHANGED] =
g_signal_new ("privacy-screen-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
}
|