GCC Code Coverage Report


Directory: ./
File: panels/universal-access/cc-cursor-size-dialog.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 43 0.0%
Functions: 0 8 0.0%
Branches: 0 15 0.0%

Line Branch Exec Source
1 /*
2 * Copyright 2020 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2.1 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "cc-cursor-size-dialog.h"
20
21 #define INTERFACE_SETTINGS "org.gnome.desktop.interface"
22 #define KEY_MOUSE_CURSOR_SIZE "cursor-size"
23
24 struct _CcCursorSizeDialog
25 {
26 AdwWindow parent;
27
28 GtkBox *cursor_box;
29
30 GSettings *interface_settings;
31 };
32
33 G_DEFINE_TYPE (CcCursorSizeDialog, cc_cursor_size_dialog, ADW_TYPE_WINDOW);
34
35 static void
36 cursor_size_toggled (CcCursorSizeDialog *self, GtkWidget *button)
37 {
38 guint cursor_size;
39
40 if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
41 return;
42
43 cursor_size = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (button), "cursor-size"));
44 g_settings_set_int (self->interface_settings, KEY_MOUSE_CURSOR_SIZE, cursor_size);
45 g_debug ("Setting cursor size to %d", cursor_size);
46 }
47
48 static void
49 cc_cursor_size_dialog_dispose (GObject *object)
50 {
51 CcCursorSizeDialog *self = CC_CURSOR_SIZE_DIALOG (object);
52
53 g_clear_object (&self->interface_settings);
54
55 G_OBJECT_CLASS (cc_cursor_size_dialog_parent_class)->dispose (object);
56 }
57
58 static void
59 cc_cursor_size_dialog_class_init (CcCursorSizeDialogClass *klass)
60 {
61 GObjectClass *object_class = G_OBJECT_CLASS (klass);
62 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
63
64 object_class->dispose = cc_cursor_size_dialog_dispose;
65
66 gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Escape, 0, "window.close", NULL);
67
68 gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/universal-access/cc-cursor-size-dialog.ui");
69
70 gtk_widget_class_bind_template_child (widget_class, CcCursorSizeDialog, cursor_box);
71 }
72
73 static void
74 cc_cursor_size_dialog_init (CcCursorSizeDialog *self)
75 {
76 guint cursor_sizes[] = { 24, 32, 48, 64, 96 };
77 guint current_cursor_size, i;
78 GtkWidget *last_radio_button = NULL;
79
80 gtk_widget_init_template (GTK_WIDGET (self));
81
82 self->interface_settings = g_settings_new (INTERFACE_SETTINGS);
83
84 current_cursor_size = g_settings_get_int (self->interface_settings,
85 KEY_MOUSE_CURSOR_SIZE);
86
87 for (i = 0; i < G_N_ELEMENTS(cursor_sizes); i++)
88 {
89 GtkWidget *image, *button;
90 g_autofree gchar *cursor_image_name = NULL;
91
92 cursor_image_name = g_strdup_printf ("/org/gnome/control-center/universal-access/left_ptr_%dpx.png", cursor_sizes[i]);
93 image = gtk_picture_new_for_resource (cursor_image_name);
94 gtk_picture_set_content_fit (GTK_PICTURE (image), GTK_CONTENT_FIT_SCALE_DOWN);
95
96 button = gtk_toggle_button_new ();
97 gtk_toggle_button_set_group (GTK_TOGGLE_BUTTON (button), GTK_TOGGLE_BUTTON (last_radio_button));
98 last_radio_button = button;
99 g_object_set_data (G_OBJECT (button), "cursor-size", GUINT_TO_POINTER (cursor_sizes[i]));
100
101 gtk_button_set_child (GTK_BUTTON (button), image);
102 gtk_box_append (self->cursor_box, button);
103
104 g_signal_connect_object (button, "toggled",
105 G_CALLBACK (cursor_size_toggled), self, G_CONNECT_SWAPPED);
106
107 if (current_cursor_size == cursor_sizes[i])
108 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
109 }
110 }
111
112 CcCursorSizeDialog *
113 cc_cursor_size_dialog_new (void)
114 {
115 return g_object_new (cc_cursor_size_dialog_get_type (), NULL);
116 }
117