diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:45:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:45:20 +0000 |
commit | ae1c76ff830d146d41e88d6fba724c0a54bce868 (patch) | |
tree | 3c354bec95af07be35fc71a4b738268496f1a1c4 /panels/universal-access/cc-visual-alerts-dialog.c | |
parent | Initial commit. (diff) | |
download | gnome-control-center-5a27cd97b79ff6970e90a7f09df8564651c207c6.tar.xz gnome-control-center-5a27cd97b79ff6970e90a7f09df8564651c207c6.zip |
Adding upstream version 1:43.6.upstream/1%43.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | panels/universal-access/cc-visual-alerts-dialog.c | 144 |
1 files changed, 144 insertions, 0 deletions
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 0000000..398753d --- /dev/null +++ b/panels/universal-access/cc-visual-alerts-dialog.c @@ -0,0 +1,144 @@ +/* + * 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 <gdesktop-enums.h> + +#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; + GtkCheckButton *screen_radio; + GtkButton *test_button; + GtkCheckButton *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) +{ + GtkCheckButton *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_check_button_set_active (widget, TRUE); +} + +static void +visual_bell_type_toggle_cb (CcVisualAlertsDialog *self) +{ + gboolean frame_flash; + GDesktopVisualBellType type; + + frame_flash = gtk_check_button_get_active (GTK_CHECK_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) +{ + GtkNative *native = gtk_widget_get_native (GTK_WIDGET (self)); + GdkSurface *surface = gtk_native_get_surface (native); + + gdk_surface_beep (surface); +} + +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); +} |