Line |
Branch |
Exec |
Source |
1 |
|
|
/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2008 William Jon McCann <jmccann@redhat.com> |
4 |
|
|
* Copyright (C) 2010 Intel, Inc |
5 |
|
|
* Copyright 2022 Mohammed Sadiq <sadiq@sadiqpk.org> |
6 |
|
|
* Copyright 2022 Purism SPC |
7 |
|
|
* |
8 |
|
|
* Licensed under the GNU General Public License Version 2 |
9 |
|
|
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* (at your option) any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program; if not, write to the Free Software |
22 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
23 |
|
|
* |
24 |
|
|
* Author(s): |
25 |
|
|
* Thomas Wood <thomas.wood@intel.com> |
26 |
|
|
* Rodrigo Moya <rodrigo@gnome.org> |
27 |
|
|
* Mohammed Sadiq <sadiq@sadiqpk.org> |
28 |
|
|
* |
29 |
|
|
* SPDX-License-Identifier: GPL-2.0-or-later |
30 |
|
|
*/ |
31 |
|
|
|
32 |
|
|
#undef G_LOG_DOMAIN |
33 |
|
|
#define G_LOG_DOMAIN "cc-ua-seeing-page" |
34 |
|
|
|
35 |
|
|
#ifdef HAVE_CONFIG_H |
36 |
|
|
# include "config.h" |
37 |
|
|
#endif |
38 |
|
|
|
39 |
|
|
#include <glib/gi18n-lib.h> |
40 |
|
|
|
41 |
|
|
#include "cc-list-row.h" |
42 |
|
|
#include "cc-cursor-size-dialog.h" |
43 |
|
|
#include "cc-ua-macros.h" |
44 |
|
|
#include "cc-ua-seeing-page.h" |
45 |
|
|
|
46 |
|
|
struct _CcUaSeeingPage |
47 |
|
|
{ |
48 |
|
|
AdwNavigationPage parent_instance; |
49 |
|
|
|
50 |
|
|
AdwSwitchRow *high_contrast_row; |
51 |
|
|
AdwSwitchRow *status_shapes_row; |
52 |
|
|
AdwSwitchRow *animations_row; |
53 |
|
|
AdwSwitchRow *large_text_row; |
54 |
|
|
CcListRow *cursor_size_row; |
55 |
|
|
AdwSwitchRow *sound_keys_row; |
56 |
|
|
AdwSwitchRow *show_scrollbars_row; |
57 |
|
|
|
58 |
|
|
AdwSwitchRow *screen_reader_row; |
59 |
|
|
|
60 |
|
|
GSettings *kb_settings; |
61 |
|
|
GSettings *interface_settings; |
62 |
|
|
GSettings *application_settings; |
63 |
|
|
GSettings *a11y_interface_settings; |
64 |
|
|
}; |
65 |
|
|
|
66 |
|
✗ |
G_DEFINE_TYPE (CcUaSeeingPage, cc_ua_seeing_page, ADW_TYPE_NAVIGATION_PAGE) |
67 |
|
|
|
68 |
|
|
static gboolean |
69 |
|
✗ |
get_large_text_mapping (GValue *value, |
70 |
|
|
GVariant *variant, |
71 |
|
|
gpointer user_data) |
72 |
|
|
{ |
73 |
|
|
gdouble factor; |
74 |
|
|
|
75 |
|
✗ |
factor = g_variant_get_double (variant); |
76 |
|
✗ |
g_value_set_boolean (value, factor > DPI_FACTOR_NORMAL); |
77 |
|
|
|
78 |
|
✗ |
return TRUE; |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
static GVariant * |
82 |
|
✗ |
set_large_text_mapping (const GValue *value, |
83 |
|
|
const GVariantType *expected_type, |
84 |
|
|
gpointer user_data) |
85 |
|
|
{ |
86 |
|
✗ |
GSettings *settings = user_data; |
87 |
|
|
|
88 |
|
✗ |
if (g_value_get_boolean (value)) |
89 |
|
✗ |
return g_variant_new_double (DPI_FACTOR_LARGE); |
90 |
|
|
|
91 |
|
✗ |
g_settings_reset (settings, KEY_TEXT_SCALING_FACTOR); |
92 |
|
|
|
93 |
|
✗ |
return NULL; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
static void |
97 |
|
✗ |
ua_seeing_interface_cursor_size_changed_cb (CcUaSeeingPage *self) |
98 |
|
|
{ |
99 |
|
✗ |
g_autofree char *label = NULL; |
100 |
|
|
int cursor_size; |
101 |
|
|
|
102 |
|
✗ |
g_assert (CC_IS_UA_SEEING_PAGE (self)); |
103 |
|
|
|
104 |
|
✗ |
cursor_size = g_settings_get_int (self->interface_settings, KEY_MOUSE_CURSOR_SIZE); |
105 |
|
|
|
106 |
|
✗ |
switch (cursor_size) |
107 |
|
|
{ |
108 |
|
✗ |
case 24: |
109 |
|
|
/* translators: the labels will read: |
110 |
|
|
* Cursor Size: Default */ |
111 |
|
✗ |
label = g_strdup (C_("cursor size", "Default")); |
112 |
|
✗ |
break; |
113 |
|
✗ |
case 32: |
114 |
|
✗ |
label = g_strdup (C_("cursor size", "Medium")); |
115 |
|
✗ |
break; |
116 |
|
✗ |
case 48: |
117 |
|
✗ |
label = g_strdup (C_("cursor size", "Large")); |
118 |
|
✗ |
break; |
119 |
|
✗ |
case 64: |
120 |
|
✗ |
label = g_strdup (C_("cursor size", "Larger")); |
121 |
|
✗ |
break; |
122 |
|
✗ |
case 96: |
123 |
|
✗ |
label = g_strdup (C_("cursor size", "Largest")); |
124 |
|
✗ |
break; |
125 |
|
✗ |
default: |
126 |
|
✗ |
label = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, |
127 |
|
|
"%d pixel", |
128 |
|
|
"%d pixels", |
129 |
|
|
cursor_size), |
130 |
|
|
cursor_size); |
131 |
|
✗ |
break; |
132 |
|
|
} |
133 |
|
|
|
134 |
|
✗ |
cc_list_row_set_secondary_label (self->cursor_size_row, label); |
135 |
|
✗ |
} |
136 |
|
|
|
137 |
|
|
static void |
138 |
|
✗ |
ua_cursor_row_activated_cb (CcUaSeeingPage *self) |
139 |
|
|
{ |
140 |
|
|
GtkWindow *dialog; |
141 |
|
|
GtkNative *native; |
142 |
|
|
|
143 |
|
✗ |
g_assert (CC_IS_UA_SEEING_PAGE (self)); |
144 |
|
|
|
145 |
|
✗ |
dialog = GTK_WINDOW (cc_cursor_size_dialog_new ()); |
146 |
|
✗ |
native = gtk_widget_get_native (GTK_WIDGET (self)); |
147 |
|
|
|
148 |
|
✗ |
gtk_window_set_transient_for (dialog, GTK_WINDOW (native)); |
149 |
|
✗ |
gtk_window_present (dialog); |
150 |
|
✗ |
} |
151 |
|
|
|
152 |
|
|
static void |
153 |
|
✗ |
cc_ua_seeing_page_dispose (GObject *object) |
154 |
|
|
{ |
155 |
|
✗ |
CcUaSeeingPage *self = (CcUaSeeingPage *)object; |
156 |
|
|
|
157 |
|
✗ |
g_clear_object (&self->kb_settings); |
158 |
|
✗ |
g_clear_object (&self->interface_settings); |
159 |
|
✗ |
g_clear_object (&self->application_settings); |
160 |
|
✗ |
g_clear_object (&self->a11y_interface_settings); |
161 |
|
|
|
162 |
|
✗ |
G_OBJECT_CLASS (cc_ua_seeing_page_parent_class)->dispose (object); |
163 |
|
✗ |
} |
164 |
|
|
|
165 |
|
|
static void |
166 |
|
✗ |
cc_ua_seeing_page_class_init (CcUaSeeingPageClass *klass) |
167 |
|
|
{ |
168 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
169 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
170 |
|
|
|
171 |
|
✗ |
object_class->dispose = cc_ua_seeing_page_dispose; |
172 |
|
|
|
173 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, |
174 |
|
|
"/org/gnome/control-center/" |
175 |
|
|
"universal-access/cc-ua-seeing-page.ui"); |
176 |
|
|
|
177 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcUaSeeingPage, high_contrast_row); |
178 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcUaSeeingPage, status_shapes_row); |
179 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcUaSeeingPage, animations_row); |
180 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcUaSeeingPage, large_text_row); |
181 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcUaSeeingPage, cursor_size_row); |
182 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcUaSeeingPage, sound_keys_row); |
183 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcUaSeeingPage, show_scrollbars_row); |
184 |
|
|
|
185 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcUaSeeingPage, screen_reader_row); |
186 |
|
|
|
187 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, ua_cursor_row_activated_cb); |
188 |
|
✗ |
} |
189 |
|
|
|
190 |
|
|
static void |
191 |
|
✗ |
cc_ua_seeing_page_init (CcUaSeeingPage *self) |
192 |
|
|
{ |
193 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
194 |
|
|
|
195 |
|
✗ |
self->kb_settings = g_settings_new (KEYBOARD_SETTINGS); |
196 |
|
✗ |
self->interface_settings = g_settings_new (INTERFACE_SETTINGS); |
197 |
|
✗ |
self->application_settings = g_settings_new (APPLICATION_SETTINGS); |
198 |
|
✗ |
self->a11y_interface_settings = g_settings_new (A11Y_INTERFACE_SETTINGS); |
199 |
|
|
|
200 |
|
|
/* High contrast */ |
201 |
|
✗ |
g_settings_bind (self->a11y_interface_settings, KEY_HIGH_CONTRAST, |
202 |
|
✗ |
self->high_contrast_row, "active", |
203 |
|
|
G_SETTINGS_BIND_DEFAULT); |
204 |
|
|
|
205 |
|
|
/* Switch shapes */ |
206 |
|
✗ |
g_settings_bind (self->a11y_interface_settings, KEY_STATUS_SHAPES, |
207 |
|
✗ |
self->status_shapes_row, "active", |
208 |
|
|
G_SETTINGS_BIND_DEFAULT); |
209 |
|
|
|
210 |
|
|
/* Enable Animations */ |
211 |
|
✗ |
g_settings_bind (self->interface_settings, KEY_ENABLE_ANIMATIONS, |
212 |
|
✗ |
self->animations_row, "active", |
213 |
|
|
G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_INVERT_BOOLEAN); |
214 |
|
|
|
215 |
|
|
/* Large Text */ |
216 |
|
✗ |
g_settings_bind_with_mapping (self->interface_settings, KEY_TEXT_SCALING_FACTOR, |
217 |
|
✗ |
self->large_text_row, |
218 |
|
|
"active", G_SETTINGS_BIND_DEFAULT, |
219 |
|
|
get_large_text_mapping, |
220 |
|
|
set_large_text_mapping, |
221 |
|
✗ |
self->interface_settings, |
222 |
|
|
NULL); |
223 |
|
|
|
224 |
|
|
/* Sound Keys */ |
225 |
|
✗ |
g_settings_bind (self->kb_settings, KEY_TOGGLEKEYS_ENABLED, |
226 |
|
✗ |
self->sound_keys_row, "active", |
227 |
|
|
G_SETTINGS_BIND_DEFAULT); |
228 |
|
|
|
229 |
|
|
/* Overlay Scrollbars */ |
230 |
|
✗ |
g_settings_bind (self->interface_settings, KEY_OVERLAY_SCROLLING, |
231 |
|
✗ |
self->show_scrollbars_row, "active", |
232 |
|
|
G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_INVERT_BOOLEAN); |
233 |
|
|
|
234 |
|
|
/* Screen Reader */ |
235 |
|
✗ |
g_settings_bind (self->application_settings, KEY_SCREEN_READER_ENABLED, |
236 |
|
✗ |
self->screen_reader_row, "active", |
237 |
|
|
G_SETTINGS_BIND_DEFAULT); |
238 |
|
|
|
239 |
|
✗ |
g_signal_connect_object (self->interface_settings, "changed::" KEY_MOUSE_CURSOR_SIZE, |
240 |
|
|
G_CALLBACK (ua_seeing_interface_cursor_size_changed_cb), |
241 |
|
|
self, G_CONNECT_SWAPPED | G_CONNECT_AFTER); |
242 |
|
|
|
243 |
|
✗ |
ua_seeing_interface_cursor_size_changed_cb (self); |
244 |
|
✗ |
} |
245 |
|
|
|
246 |
|
|
GtkWidget * |
247 |
|
✗ |
cc_ua_seeing_page_new (void) |
248 |
|
|
{ |
249 |
|
✗ |
return g_object_new (CC_TYPE_UA_SEEING_PAGE, NULL); |
250 |
|
|
} |
251 |
|
|
|