universal-access: Split cursor size dialog into its own widget

This commit is contained in:
Robert Ancell 2020-11-02 16:00:11 +13:00 committed by Georges Basile Stavracas Neto
parent accf1b82a0
commit 12a19878a6
8 changed files with 203 additions and 133 deletions

View file

@ -0,0 +1,120 @@
/*
* Copyright 2020 Canonical Ltd.
*
* 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.1 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 Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "cc-cursor-size-dialog.h"
#define INTERFACE_SETTINGS "org.gnome.desktop.interface"
#define KEY_MOUSE_CURSOR_SIZE "cursor-size"
struct _CcCursorSizeDialog
{
GtkDialog parent;
GtkGrid *size_grid;
GSettings *interface_settings;
};
G_DEFINE_TYPE (CcCursorSizeDialog, cc_cursor_size_dialog, GTK_TYPE_DIALOG);
static void
cursor_size_toggled (CcCursorSizeDialog *self, GtkWidget *button)
{
guint cursor_size;
if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
return;
cursor_size = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (button), "cursor-size"));
g_settings_set_int (self->interface_settings, KEY_MOUSE_CURSOR_SIZE, cursor_size);
g_debug ("Setting cursor size to %d", cursor_size);
}
static void
cc_cursor_size_dialog_dispose (GObject *object)
{
CcCursorSizeDialog *self = CC_CURSOR_SIZE_DIALOG (object);
g_clear_object (&self->interface_settings);
G_OBJECT_CLASS (cc_cursor_size_dialog_parent_class)->dispose (object);
}
static void
cc_cursor_size_dialog_class_init (CcCursorSizeDialogClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->dispose = cc_cursor_size_dialog_dispose;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/universal-access/cc-cursor-size-dialog.ui");
gtk_widget_class_bind_template_child (widget_class, CcCursorSizeDialog, size_grid);
}
static void
cc_cursor_size_dialog_init (CcCursorSizeDialog *self)
{
guint cursor_sizes[] = { 24, 32, 48, 64, 96 };
guint current_cursor_size, i;
GtkSizeGroup *size_group;
GtkWidget *last_radio_button = NULL;
gtk_widget_init_template (GTK_WIDGET (self));
self->interface_settings = g_settings_new (INTERFACE_SETTINGS);
current_cursor_size = g_settings_get_int (self->interface_settings,
KEY_MOUSE_CURSOR_SIZE);
size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
for (i = 0; i < G_N_ELEMENTS(cursor_sizes); i++)
{
GtkWidget *image, *button;
g_autofree gchar *cursor_image_name = NULL;
cursor_image_name = g_strdup_printf ("/org/gnome/control-center/universal-access/left_ptr_%dpx.png", cursor_sizes[i]);
image = gtk_image_new_from_resource (cursor_image_name);
gtk_widget_show (image);
button = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON (last_radio_button));
gtk_widget_show (button);
last_radio_button = button;
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
g_object_set_data (G_OBJECT (button), "cursor-size", GUINT_TO_POINTER (cursor_sizes[i]));
gtk_container_add (GTK_CONTAINER (button), image);
gtk_grid_attach (GTK_GRID (self->size_grid), button, i, 0, 1, 1);
gtk_size_group_add_widget (size_group, button);
g_signal_connect_object (button, "toggled",
G_CALLBACK (cursor_size_toggled), self, G_CONNECT_SWAPPED);
if (current_cursor_size == cursor_sizes[i])
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
}
}
CcCursorSizeDialog *
cc_cursor_size_dialog_new (void)
{
return g_object_new (cc_cursor_size_dialog_get_type (),
"use-header-bar", TRUE,
NULL);
}

View file

@ -0,0 +1,29 @@
/*
* Copyright 2020 Canonical Ltd.
*
* 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.1 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 Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include <gtk/gtk.h>
G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (CcCursorSizeDialog, cc_cursor_size_dialog, CC, CURSOR_SIZE_DIALOG, GtkDialog)
CcCursorSizeDialog *cc_cursor_size_dialog_new (void);
G_END_DECLS

View file

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<template class="CcCursorSizeDialog" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Cursor Size</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can_focus">False</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">12</property>
<property name="margin_end">6</property>
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
<property name="label" translatable="yes">Cursor size can be combined with zoom to make it easier to see the cursor.</property>
<property name="wrap">True</property>
<property name="max_width_chars">45</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkGrid" id="size_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<style>
<class name="linked"/>
</style>
</object>
</child>
</object>
</child>
</template>
</interface>

View file

@ -30,7 +30,7 @@
#include "list-box-helper.h"
#include "cc-ua-panel.h"
#include "cc-ua-resources.h"
#include "cc-cursor-size-dialog.h"
#include "cc-zoom-options-dialog.h"
#define DPI_FACTOR_LARGE 1.25
@ -105,8 +105,6 @@ struct _CcUaPanel
GtkDialog *cursor_blinking_dialog;
GtkWidget *cursor_blinking_scale;
GtkWidget *cursor_blinking_switch;
GtkDialog *cursor_size_dialog;
GtkWidget *cursor_size_grid;
GtkWidget *list_hearing;
GtkWidget *list_pointing;
GtkWidget *list_seeing;
@ -247,8 +245,6 @@ cc_ua_panel_class_init (CcUaPanelClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcUaPanel, cursor_blinking_dialog);
gtk_widget_class_bind_template_child (widget_class, CcUaPanel, cursor_blinking_scale);
gtk_widget_class_bind_template_child (widget_class, CcUaPanel, cursor_blinking_switch);
gtk_widget_class_bind_template_child (widget_class, CcUaPanel, cursor_size_dialog);
gtk_widget_class_bind_template_child (widget_class, CcUaPanel, cursor_size_grid);
gtk_widget_class_bind_template_child (widget_class, CcUaPanel, list_hearing);
gtk_widget_class_bind_template_child (widget_class, CcUaPanel, list_pointing);
gtk_widget_class_bind_template_child (widget_class, CcUaPanel, list_seeing);
@ -322,62 +318,6 @@ cc_ua_panel_class_init (CcUaPanelClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcUaPanel, visual_alerts_window_radio);
}
/* cursor size dialog */
static void
cursor_size_toggled (CcUaPanel *self,
GtkWidget *button)
{
guint cursor_size;
if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
return;
cursor_size = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (button), "cursor-size"));
g_settings_set_int (self->interface_settings, KEY_MOUSE_CURSOR_SIZE, cursor_size);
g_debug ("Setting cursor size to %d", cursor_size);
}
static void
cursor_size_setup (CcUaPanel *self)
{
guint cursor_sizes[] = { 24, 32, 48, 64, 96 };
guint current_cursor_size, i;
GtkSizeGroup *size_group;
GtkWidget *last_radio_button = NULL;
gtk_style_context_add_class (gtk_widget_get_style_context (self->cursor_size_grid), "linked");
current_cursor_size = g_settings_get_int (self->interface_settings,
KEY_MOUSE_CURSOR_SIZE);
size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
for (i = 0; i < G_N_ELEMENTS(cursor_sizes); i++)
{
GtkWidget *image, *button;
g_autofree gchar *cursor_image_name = NULL;
cursor_image_name = g_strdup_printf ("/org/gnome/control-center/universal-access/left_ptr_%dpx.png", cursor_sizes[i]);
image = gtk_image_new_from_resource (cursor_image_name);
gtk_widget_show (image);
button = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON (last_radio_button));
gtk_widget_show (button);
last_radio_button = button;
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
g_object_set_data (G_OBJECT (button), "cursor-size", GUINT_TO_POINTER (cursor_sizes[i]));
gtk_container_add (GTK_CONTAINER (button), image);
gtk_grid_attach (GTK_GRID (self->cursor_size_grid), button, i, 0, 1, 1);
gtk_size_group_add_widget (size_group, button);
g_signal_connect_object (button, "toggled",
G_CALLBACK (cursor_size_toggled), self, G_CONNECT_SWAPPED);
if (current_cursor_size == cursor_sizes[i])
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
}
}
/* seeing section */
static gboolean
@ -631,7 +571,7 @@ activate_row (CcUaPanel *self, GtkListBoxRow *row)
}
else if (row == self->row_cursor_size)
{
show_dialog (self, self->cursor_size_dialog);
run_dialog (self, GTK_DIALOG (cc_cursor_size_dialog_new ()));
}
else if (row == self->row_screen_reader)
{
@ -693,19 +633,12 @@ cc_ua_panel_init_seeing (CcUaPanel *self)
/* cursor size */
cursor_size_setup (self);
g_settings_bind_with_mapping (self->interface_settings, KEY_MOUSE_CURSOR_SIZE,
g_settings_bind_with_mapping (self->interface_settings, KEY_MOUSE_CURSOR_SIZE, // FIXME
self->value_cursor_size,
"label", G_SETTINGS_BIND_GET,
cursor_size_label_mapping_get,
NULL, NULL, NULL);
self->toplevels = g_slist_prepend (self->toplevels, self->cursor_size_dialog);
g_signal_connect (self->cursor_size_dialog, "delete-event",
G_CALLBACK (gtk_widget_hide_on_delete), NULL);
/* zoom */
g_settings_bind_with_mapping (self->application_settings, "screen-magnifier-enabled",

View file

@ -1060,69 +1060,6 @@
<widget name="row_click_assist"/>
</widgets>
</object>
<object class="GtkDialog" id="cursor_size_dialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Cursor Size</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox7">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="cursor_size_blurb">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">12</property>
<property name="margin_end">6</property>
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
<property name="label" translatable="yes">Cursor size can be combined with zoom to make it easier to see the cursor.</property>
<property name="wrap">True</property>
<property name="max_width_chars">45</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="cursor_size_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<child>
<placeholder/>
</child>
<child internal-child="headerbar">
<object class="GtkHeaderBar">
<property name="can_focus">False</property>
</object>
</child>
</object>
<object class="GtkDialog" id="screen_reader_dialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>

View file

@ -18,6 +18,7 @@ i18n.merge_file(
)
sources = files(
'cc-cursor-size-dialog.c',
'cc-ua-panel.c',
'cc-zoom-options-dialog.c'
)
@ -29,6 +30,7 @@ resource_data = files(
'left_ptr_48px.png',
'left_ptr_64px.png',
'left_ptr_96px.png',
'cc-cursor-size-dialog.ui',
'cc-zoom-options-dialog.ui'
)

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/control-center/universal-access">
<file preprocess="xml-stripblanks">cc-cursor-size-dialog.ui</file>
<file preprocess="xml-stripblanks">cc-ua-panel.ui</file>
<file preprocess="xml-stripblanks">cc-zoom-options-dialog.ui</file>
<file>left_ptr_24px.png</file>

View file

@ -215,6 +215,7 @@ panels/thunderbolt/cc-bolt-device-entry.c
panels/thunderbolt/cc-bolt-panel.c
panels/thunderbolt/cc-bolt-panel.ui
panels/thunderbolt/gnome-thunderbolt-panel.desktop.in.in
panels/universal-access/cc-cursor-size-dialog.ui
panels/universal-access/cc-ua-panel.c
panels/universal-access/cc-ua-panel.ui
panels/universal-access/cc-zoom-options-dialog.c