diff --git a/panels/universal-access/cc-ua-panel.c b/panels/universal-access/cc-ua-panel.c index 6dc6ed299..49dfa1e4b 100644 --- a/panels/universal-access/cc-ua-panel.c +++ b/panels/universal-access/cc-ua-panel.c @@ -33,6 +33,7 @@ #include "cc-cursor-size-dialog.h" #include "cc-sound-keys-dialog.h" #include "cc-screen-reader-dialog.h" +#include "cc-visual-alerts-dialog.h" #include "cc-zoom-options-dialog.h" #define DPI_FACTOR_LARGE 1.25 @@ -62,7 +63,6 @@ /* wm settings */ #define WM_SETTINGS "org.gnome.desktop.wm.preferences" #define KEY_VISUAL_BELL_ENABLED "visual-bell" -#define KEY_VISUAL_BELL_TYPE "visual-bell-type" #define KEY_WM_THEME "theme" /* keyboard settings */ @@ -173,11 +173,6 @@ struct _CcUaPanel GtkWidget *value_sound_keys; GtkWidget *value_visual_alerts; GtkWidget *value_zoom; - GtkDialog *visual_alerts_dialog; - GtkWidget *visual_alerts_screen_radio; - GtkWidget *visual_alerts_switch; - GtkWidget *visual_alerts_test_button; - GtkWidget *visual_alerts_window_radio; GSettings *wm_settings; GSettings *a11y_settings; @@ -305,11 +300,6 @@ cc_ua_panel_class_init (CcUaPanelClass *klass) gtk_widget_class_bind_template_child (widget_class, CcUaPanel, value_sound_keys); gtk_widget_class_bind_template_child (widget_class, CcUaPanel, value_visual_alerts); gtk_widget_class_bind_template_child (widget_class, CcUaPanel, value_zoom); - gtk_widget_class_bind_template_child (widget_class, CcUaPanel, visual_alerts_dialog); - gtk_widget_class_bind_template_child (widget_class, CcUaPanel, visual_alerts_screen_radio); - gtk_widget_class_bind_template_child (widget_class, CcUaPanel, visual_alerts_switch); - gtk_widget_class_bind_template_child (widget_class, CcUaPanel, visual_alerts_test_button); - gtk_widget_class_bind_template_child (widget_class, CcUaPanel, visual_alerts_window_radio); } /* seeing section */ @@ -577,7 +567,7 @@ activate_row (CcUaPanel *self, GtkListBoxRow *row) } else if (row == self->row_visual_alerts) { - show_dialog (self, self->visual_alerts_dialog); + run_dialog (self, GTK_DIALOG (cc_visual_alerts_dialog_new ())); } else if (row == self->row_repeat_keys) { @@ -659,44 +649,6 @@ cc_ua_panel_init_seeing (CcUaPanel *self) } /* hearing/sound section */ -static void -visual_bell_type_notify_cb (CcUaPanel *self) -{ - GtkWidget *widget; - GDesktopVisualBellType type; - - type = g_settings_get_enum (self->wm_settings, KEY_VISUAL_BELL_TYPE); - - if (type == G_DESKTOP_VISUAL_BELL_FRAME_FLASH) - widget = self->visual_alerts_window_radio; - else - widget = self->visual_alerts_screen_radio; - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE); -} - -static void -visual_bell_type_toggle_cb (CcUaPanel *self) -{ - gboolean frame_flash; - GDesktopVisualBellType type; - - frame_flash = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->visual_alerts_window_radio)); - - if (frame_flash) - type = G_DESKTOP_VISUAL_BELL_FRAME_FLASH; - else - type = G_DESKTOP_VISUAL_BELL_FULLSCREEN_FLASH; - g_settings_set_enum (self->wm_settings, KEY_VISUAL_BELL_TYPE, type); -} - -static void -test_flash (GtkButton *button, - gpointer data) -{ - GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button)); - gdk_window_beep (gtk_widget_get_window (toplevel)); -} static void cc_ua_panel_init_hearing (CcUaPanel *self) @@ -708,39 +660,11 @@ cc_ua_panel_init_hearing (CcUaPanel *self) g_signal_connect_object (self->list_hearing, "row-activated", G_CALLBACK (activate_row), self, G_CONNECT_SWAPPED); - /* set the initial visual bell values */ - visual_bell_type_notify_cb (self); - - /* and listen */ - g_settings_bind (self->wm_settings, KEY_VISUAL_BELL_ENABLED, - self->visual_alerts_switch, "active", - G_SETTINGS_BIND_DEFAULT); - g_settings_bind_with_mapping (self->wm_settings, KEY_VISUAL_BELL_ENABLED, self->value_visual_alerts, "label", G_SETTINGS_BIND_GET, on_off_label_mapping_get, NULL, NULL, NULL); - - g_object_bind_property (self->visual_alerts_switch, "active", - self->visual_alerts_window_radio, "sensitive", - G_BINDING_SYNC_CREATE); - g_object_bind_property (self->visual_alerts_switch, "active", - self->visual_alerts_screen_radio, "sensitive", - G_BINDING_SYNC_CREATE); - - g_signal_connect_object (self->wm_settings, "changed::" KEY_VISUAL_BELL_TYPE, - G_CALLBACK (visual_bell_type_notify_cb), self, G_CONNECT_SWAPPED); - g_signal_connect_object (self->visual_alerts_window_radio, - "toggled", G_CALLBACK (visual_bell_type_toggle_cb), self, G_CONNECT_SWAPPED); - - self->toplevels = g_slist_prepend (self->toplevels, self->visual_alerts_dialog); - - g_signal_connect (self->visual_alerts_dialog, "delete-event", - G_CALLBACK (gtk_widget_hide_on_delete), NULL); - - g_signal_connect (self->visual_alerts_test_button, - "clicked", G_CALLBACK (test_flash), NULL); } /* typing/keyboard section */ diff --git a/panels/universal-access/cc-ua-panel.ui b/panels/universal-access/cc-ua-panel.ui index 72e332606..bf5cdd79e 100644 --- a/panels/universal-access/cc-ua-panel.ui +++ b/panels/universal-access/cc-ua-panel.ui @@ -1060,149 +1060,6 @@ - - False - 5 - False - True - dialog - 1 - - - True - False - Visual Alerts - True - - - _Test flash - True - True - False - True - center - - - - start - - - - - - - False - vertical - 2 - - - True - False - 12 - 6 - 6 - 0 - Use a visual indication when an alert sound occurs. - True - - - False - True - 0 - - - - - True - False - 12 - 6 - 12 - 12 - 12 - 6 - - - True - False - True - 0 - _Visual Alerts - True - visual_alerts_switch - - - 0 - 0 - 1 - 1 - - - - - True - True - end - - - 1 - 0 - 1 - 1 - - - - - Flash the entire _window - True - True - False - 0 - True - True - True - - - 0 - 1 - 2 - 1 - - - - - Flash the entire _screen - True - True - False - 0 - True - True - visual_alerts_window_radio - True - - - 0 - 2 - 2 - 1 - - - - - False - True - 2 - - - - - - visual_alerts_test_button - - 900 0.5 diff --git a/panels/universal-access/cc-visual-alerts-dialog.c b/panels/universal-access/cc-visual-alerts-dialog.c new file mode 100644 index 000000000..d49bac58b --- /dev/null +++ b/panels/universal-access/cc-visual-alerts-dialog.c @@ -0,0 +1,142 @@ +/* + * 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 + +#include "cc-visual-alerts-dialog.h" + +#define WM_SETTINGS "org.gnome.desktop.wm.preferences" +#define KEY_VISUAL_BELL_ENABLED "visual-bell" +#define KEY_VISUAL_BELL_TYPE "visual-bell-type" + +struct _CcVisualAlertsDialog +{ + GtkDialog parent; + + GtkSwitch *enable_switch; + GtkRadioButton *screen_radio; + GtkButton *test_button; + GtkRadioButton *window_radio; + + GSettings *wm_settings; +}; + +G_DEFINE_TYPE (CcVisualAlertsDialog, cc_visual_alerts_dialog, GTK_TYPE_DIALOG); + +static void +visual_bell_type_notify_cb (CcVisualAlertsDialog *self) +{ + GtkRadioButton *widget; + GDesktopVisualBellType type; + + type = g_settings_get_enum (self->wm_settings, KEY_VISUAL_BELL_TYPE); + + if (type == G_DESKTOP_VISUAL_BELL_FRAME_FLASH) + widget = self->window_radio; + else + widget = self->screen_radio; + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE); +} + +static void +visual_bell_type_toggle_cb (CcVisualAlertsDialog *self) +{ + gboolean frame_flash; + GDesktopVisualBellType type; + + frame_flash = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->window_radio)); + + if (frame_flash) + type = G_DESKTOP_VISUAL_BELL_FRAME_FLASH; + else + type = G_DESKTOP_VISUAL_BELL_FULLSCREEN_FLASH; + g_settings_set_enum (self->wm_settings, KEY_VISUAL_BELL_TYPE, type); +} + +static void +test_flash (CcVisualAlertsDialog *self) +{ + GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self)); + gdk_window_beep (gtk_widget_get_window (toplevel)); +} + +static void +cc_visual_alerts_dialog_dispose (GObject *object) +{ + CcVisualAlertsDialog *self = CC_VISUAL_ALERTS_DIALOG (object); + + g_clear_object (&self->wm_settings); + + G_OBJECT_CLASS (cc_visual_alerts_dialog_parent_class)->dispose (object); +} + +static void +cc_visual_alerts_dialog_class_init (CcVisualAlertsDialogClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->dispose = cc_visual_alerts_dialog_dispose; + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/universal-access/cc-visual-alerts-dialog.ui"); + + gtk_widget_class_bind_template_child (widget_class, CcVisualAlertsDialog, enable_switch); + gtk_widget_class_bind_template_child (widget_class, CcVisualAlertsDialog, screen_radio); + gtk_widget_class_bind_template_child (widget_class, CcVisualAlertsDialog, test_button); + gtk_widget_class_bind_template_child (widget_class, CcVisualAlertsDialog, window_radio); +} + +static void +cc_visual_alerts_dialog_init (CcVisualAlertsDialog *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); + + self->wm_settings = g_settings_new (WM_SETTINGS); + + /* set the initial visual bell values */ + visual_bell_type_notify_cb (self); + + /* and listen */ + g_settings_bind (self->wm_settings, KEY_VISUAL_BELL_ENABLED, + self->enable_switch, "active", + G_SETTINGS_BIND_DEFAULT); + + g_object_bind_property (self->enable_switch, "active", + self->window_radio, "sensitive", + G_BINDING_SYNC_CREATE); + + g_object_bind_property (self->enable_switch, "active", + self->screen_radio, "sensitive", + G_BINDING_SYNC_CREATE); + g_signal_connect_object (self->wm_settings, "changed::" KEY_VISUAL_BELL_TYPE, + G_CALLBACK (visual_bell_type_notify_cb), self, G_CONNECT_SWAPPED); + g_signal_connect_object (self->window_radio, + "toggled", G_CALLBACK (visual_bell_type_toggle_cb), self, G_CONNECT_SWAPPED); + + g_signal_connect_object (self->test_button, + "clicked", G_CALLBACK (test_flash), self, G_CONNECT_SWAPPED); +} + +CcVisualAlertsDialog * +cc_visual_alerts_dialog_new (void) +{ + return g_object_new (cc_visual_alerts_dialog_get_type (), + "use-header-bar", TRUE, + NULL); +} diff --git a/panels/universal-access/cc-visual-alerts-dialog.h b/panels/universal-access/cc-visual-alerts-dialog.h new file mode 100644 index 000000000..49add84b1 --- /dev/null +++ b/panels/universal-access/cc-visual-alerts-dialog.h @@ -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 + +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (CcVisualAlertsDialog, cc_visual_alerts_dialog, CC, VISUAL_ALERTS_DIALOG, GtkDialog) + +CcVisualAlertsDialog *cc_visual_alerts_dialog_new (void); + +G_END_DECLS diff --git a/panels/universal-access/cc-visual-alerts-dialog.ui b/panels/universal-access/cc-visual-alerts-dialog.ui new file mode 100644 index 000000000..ebb3dd89a --- /dev/null +++ b/panels/universal-access/cc-visual-alerts-dialog.ui @@ -0,0 +1,134 @@ + + + + + diff --git a/panels/universal-access/meson.build b/panels/universal-access/meson.build index fd97ad3aa..f2df85b08 100644 --- a/panels/universal-access/meson.build +++ b/panels/universal-access/meson.build @@ -22,6 +22,7 @@ sources = files( 'cc-sound-keys-dialog.c', 'cc-screen-reader-dialog.c', 'cc-ua-panel.c', + 'cc-visual-alerts-dialog.c', 'cc-zoom-options-dialog.c' ) @@ -35,6 +36,7 @@ resource_data = files( 'cc-cursor-size-dialog.ui', 'cc-sound-keys-dialog.ui', 'cc-screen-reader-dialog.ui', + 'cc-visual-alerts-dialog.ui', 'cc-zoom-options-dialog.ui' ) diff --git a/panels/universal-access/universal-access.gresource.xml b/panels/universal-access/universal-access.gresource.xml index c06079a03..9558627d2 100644 --- a/panels/universal-access/universal-access.gresource.xml +++ b/panels/universal-access/universal-access.gresource.xml @@ -5,6 +5,7 @@ cc-sound-keys-dialog.ui cc-screen-reader-dialog.ui cc-ua-panel.ui + cc-visual-alerts-dialog.ui cc-zoom-options-dialog.ui left_ptr_24px.png left_ptr_32px.png diff --git a/po/POTFILES.in b/po/POTFILES.in index 5bffeef8b..4eff4fef1 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -220,6 +220,7 @@ panels/universal-access/cc-sound-keys-dialog.ui panels/universal-access/cc-screen-reader-dialog.ui panels/universal-access/cc-ua-panel.c panels/universal-access/cc-ua-panel.ui +panels/universal-access/cc-visual-alerts-dialog.ui panels/universal-access/cc-zoom-options-dialog.c panels/universal-access/cc-zoom-options-dialog.ui panels/universal-access/gnome-universal-access-panel.desktop.in.in