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

This commit is contained in:
Robert Ancell 2020-11-03 08:57:13 +13:00 committed by Georges Basile Stavracas Neto
parent 31102bd256
commit 2f4058d7e9
8 changed files with 242 additions and 162 deletions

View file

@ -0,0 +1,83 @@
/*
* 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-blinking-dialog.h"
#define INTERFACE_SETTINGS "org.gnome.desktop.interface"
#define KEY_CURSOR_BLINKING "cursor-blink"
#define KEY_CURSOR_BLINKING_TIME "cursor-blink-time"
struct _CcCursorBlinkingDialog
{
GtkDialog parent;
GtkScale *blink_time_scale;
GtkSwitch *enable_switch;
GSettings *interface_settings;
};
G_DEFINE_TYPE (CcCursorBlinkingDialog, cc_cursor_blinking_dialog, GTK_TYPE_DIALOG);
static void
cc_cursor_blinking_dialog_dispose (GObject *object)
{
CcCursorBlinkingDialog *self = CC_CURSOR_BLINKING_DIALOG (object);
g_clear_object (&self->interface_settings);
G_OBJECT_CLASS (cc_cursor_blinking_dialog_parent_class)->dispose (object);
}
static void
cc_cursor_blinking_dialog_class_init (CcCursorBlinkingDialogClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->dispose = cc_cursor_blinking_dialog_dispose;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/universal-access/cc-cursor-blinking-dialog.ui");
gtk_widget_class_bind_template_child (widget_class, CcCursorBlinkingDialog, blink_time_scale);
gtk_widget_class_bind_template_child (widget_class, CcCursorBlinkingDialog, enable_switch);
}
static void
cc_cursor_blinking_dialog_init (CcCursorBlinkingDialog *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
self->interface_settings = g_settings_new (INTERFACE_SETTINGS);
g_settings_bind (self->interface_settings, KEY_CURSOR_BLINKING,
self->enable_switch, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (self->interface_settings, KEY_CURSOR_BLINKING_TIME,
gtk_range_get_adjustment (GTK_RANGE (self->blink_time_scale)), "value",
G_SETTINGS_BIND_DEFAULT);
}
CcCursorBlinkingDialog *
cc_cursor_blinking_dialog_new (void)
{
return g_object_new (cc_cursor_blinking_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 (CcCursorBlinkingDialog, cc_cursor_blinking_dialog, CC, CURSOR_BLINKING_DIALOG, GtkDialog)
CcCursorBlinkingDialog *cc_cursor_blinking_dialog_new (void);
G_END_DECLS

View file

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<template class="CcCursorBlinkingDialog" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Cursor Blinking</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="type_hint">dialog</property>
<property name="use_header_bar">1</property>
<child internal-child="headerbar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<child>
<object class="GtkSwitch" id="enable_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object>
</child>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Cursor blinks in text fields.</property>
<property name="margin_start">12</property>
<property name="margin_end">6</property>
<property name="margin_top">6</property>
<property name="margin_bottom">12</property>
</object>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">start</property>
<property name="margin_start">12</property>
<property name="margin_end">6</property>
<property name="margin_top">6</property>
<property name="margin_bottom">12</property>
<property name="orientation">vertical</property>
<property name="row_spacing">18</property>
<property name="column_spacing">24</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">start</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Speed</property>
<property name="mnemonic_widget">blink_time_scale</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkScale" id="blink_time_scale">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="adjustment">blink_time_adjustment</property>
<property name="draw_value">False</property>
<property name="width-request">400</property>
<child internal-child="accessible">
<object class="AtkObject">
<property name="AtkObject::accessible-description" translatable="yes">Cursor blinking speed</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</template>
<object class="GtkAdjustment" id="blink_time_adjustment">
<property name="lower">100</property>
<property name="upper">2500</property>
<property name="value">1000</property>
<property name="step_increment">200</property>
<property name="page_increment">200</property>
</object>
</interface>

View file

@ -30,6 +30,7 @@
#include "list-box-helper.h"
#include "cc-ua-panel.h"
#include "cc-ua-resources.h"
#include "cc-cursor-blinking-dialog.h"
#include "cc-cursor-size-dialog.h"
#include "cc-repeat-keys-dialog.h"
#include "cc-sound-keys-dialog.h"
@ -105,9 +106,6 @@ struct _CcUaPanel
{
CcPanel parent_instance;
GtkDialog *cursor_blinking_dialog;
GtkWidget *cursor_blinking_scale;
GtkWidget *cursor_blinking_switch;
GtkWidget *list_hearing;
GtkWidget *list_pointing;
GtkWidget *list_seeing;
@ -230,9 +228,6 @@ cc_ua_panel_class_init (CcUaPanelClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/universal-access/cc-ua-panel.ui");
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, list_hearing);
gtk_widget_class_bind_template_child (widget_class, CcUaPanel, list_pointing);
gtk_widget_class_bind_template_child (widget_class, CcUaPanel, list_seeing);
@ -564,7 +559,7 @@ activate_row (CcUaPanel *self, GtkListBoxRow *row)
}
else if (row == self->row_cursor_blinking)
{
show_dialog (self, self->cursor_blinking_dialog);
run_dialog (self, GTK_DIALOG (cc_cursor_blinking_dialog_new ()));
}
else if (row == self->row_accessx)
{
@ -717,23 +712,8 @@ cc_ua_panel_init_keyboard (CcUaPanel *self)
/* Cursor Blinking */
g_signal_connect_object (self->interface_settings, "changed",
G_CALLBACK (on_cursor_blinking_toggled), self, G_CONNECT_SWAPPED);
self->toplevels = g_slist_prepend (self->toplevels, self->cursor_blinking_dialog);
g_signal_connect (self->cursor_blinking_dialog, "delete-event",
G_CALLBACK (gtk_widget_hide_on_delete), NULL);
sw = self->cursor_blinking_switch;
g_settings_bind (self->interface_settings, KEY_CURSOR_BLINKING,
sw, "active",
G_SETTINGS_BIND_DEFAULT);
on_cursor_blinking_toggled (self);
g_settings_bind (self->interface_settings, KEY_CURSOR_BLINKING_TIME,
gtk_range_get_adjustment (GTK_RANGE (self->cursor_blinking_scale)), "value",
G_SETTINGS_BIND_DEFAULT);
/* accessx */
g_signal_connect_object (self->kb_settings, "changed",
G_CALLBACK (update_accessx_label), self, G_CONNECT_SWAPPED);

View file

@ -9,13 +9,6 @@
<property name="step_increment">100</property>
<property name="page_increment">100</property>
</object>
<object class="GtkAdjustment" id="cursor_blink_time_adjustment">
<property name="lower">100</property>
<property name="upper">2500</property>
<property name="value">1000</property>
<property name="step_increment">200</property>
<property name="page_increment">200</property>
</object>
<!-- interface-requires gtk+ 3.0 -->
<template class="CcUaPanel" parent="CcPanel">
<property name="visible">True</property>
@ -1058,139 +1051,6 @@
<property name="step_increment">10</property>
<property name="page_increment">10</property>
</object>
<object class="GtkDialog" id="cursor_blinking_dialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Cursor Blinking</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="type_hint">dialog</property>
<property name="use_header_bar">1</property>
<child internal-child="headerbar">
<object class="GtkHeaderBar" id="cursor_blinking_headerbar">
<property name="visible">True</property>
<child>
<object class="GtkSwitch" id="cursor_blinking_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object>
</child>
<child internal-child="vbox">
<object class="GtkBox" id="cursor_blinking-vbox5">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="cursor_blinking-description">
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Cursor blinks in text fields.</property>
<property name="margin_start">12</property>
<property name="margin_end">6</property>
<property name="margin_top">6</property>
<property name="margin_bottom">12</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="cursor_blinking-grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">start</property>
<property name="margin_start">12</property>
<property name="margin_end">6</property>
<property name="margin_top">6</property>
<property name="margin_bottom">12</property>
<property name="orientation">vertical</property>
<property name="row_spacing">18</property>
<property name="column_spacing">24</property>
<child>
<object class="GtkBox" id="cursor_blinking-box6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">start</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox" id="cursor_blinking-box7">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="cursor_blinking_label">
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Speed</property>
<property name="mnemonic_widget">cursor_blinking_scale</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkScale" id="cursor_blinking_scale">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="adjustment">cursor_blink_time_adjustment</property>
<property name="draw_value">False</property>
<property name="width-request">400</property>
<child internal-child="accessible">
<object class="AtkObject" id="cursor_blinking_scale-atkobject">
<property name="AtkObject::accessible-description" translatable="yes">Cursor blinking speed</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkDialog" id="typing_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-blinking-dialog.c',
'cc-cursor-size-dialog.c',
'cc-repeat-keys-dialog.c',
'cc-sound-keys-dialog.c',
@ -34,6 +35,7 @@ resource_data = files(
'left_ptr_48px.png',
'left_ptr_64px.png',
'left_ptr_96px.png',
'cc-cursor-blinking-dialog.ui',
'cc-cursor-size-dialog.ui',
'cc-repeat-keys-dialog.ui',
'cc-sound-keys-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-blinking-dialog.ui</file>
<file preprocess="xml-stripblanks">cc-cursor-size-dialog.ui</file>
<file preprocess="xml-stripblanks">cc-repeat-keys-dialog.ui</file>
<file preprocess="xml-stripblanks">cc-sound-keys-dialog.ui</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-blinking-dialog.ui
panels/universal-access/cc-cursor-size-dialog.ui
panels/universal-access/cc-repeat-keys-dialog.ui
panels/universal-access/cc-sound-keys-dialog.ui