From b9a2b7a6a741d0aaabdb76d4beab84395e6b90c9 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 24 Feb 2020 16:31:51 +0000 Subject: [PATCH] =?UTF-8?q?user-controls:=20Add=20CSS=20to=20support=20sty?= =?UTF-8?q?ling=20switches=20as=20=E2=80=98restrictive=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will be used in upcoming commits to mark switches as restricting something when they’re active, rather than allowing something. Their background will be red, rather than blue. Signed-off-by: Philip Withnall Helps: #11 --- libmalcontent-ui/malcontent-ui.gresource.xml | 1 + libmalcontent-ui/restricts-switch.css | 18 ++++++++++++++++++ libmalcontent-ui/user-controls.c | 8 ++++++++ 3 files changed, 27 insertions(+) create mode 100644 libmalcontent-ui/restricts-switch.css diff --git a/libmalcontent-ui/malcontent-ui.gresource.xml b/libmalcontent-ui/malcontent-ui.gresource.xml index cbdaa9f..089d8a5 100644 --- a/libmalcontent-ui/malcontent-ui.gresource.xml +++ b/libmalcontent-ui/malcontent-ui.gresource.xml @@ -4,6 +4,7 @@ restrict-applications-dialog.ui restrict-applications-selector.ui + restricts-switch.css user-controls.ui diff --git a/libmalcontent-ui/restricts-switch.css b/libmalcontent-ui/restricts-switch.css new file mode 100644 index 0000000..c44debe --- /dev/null +++ b/libmalcontent-ui/restricts-switch.css @@ -0,0 +1,18 @@ +/* FIXME: This ‘negative’ variant of a GtkSwitch should probably be + * upstreamed to GTK. See https://gitlab.gnome.org/GNOME/gtk/issues/2470 */ +switch:checked.restricts { + background-color: @error_color; +} + +switch:checked.restricts, switch:checked.restricts slider { + border-color: #8b0000; +} + +switch:disabled.restricts { + border-color: @borders; + background-color: @insensitive_bg_color; +} + +switch:disabled.restricts slider { + border-color: #bfb8b1; +} diff --git a/libmalcontent-ui/user-controls.c b/libmalcontent-ui/user-controls.c index 080eb95..5326df4 100644 --- a/libmalcontent-ui/user-controls.c +++ b/libmalcontent-ui/user-controls.c @@ -949,12 +949,20 @@ mct_user_controls_init (MctUserControls *self) { g_autoptr(GDBusConnection) system_bus = NULL; g_autoptr(GError) error = NULL; + g_autoptr(GtkCssProvider) provider = NULL; /* Ensure the types used in the UI are registered. */ g_type_ensure (MCT_TYPE_RESTRICT_APPLICATIONS_DIALOG); gtk_widget_init_template (GTK_WIDGET (self)); + provider = gtk_css_provider_new (); + gtk_css_provider_load_from_resource (provider, + "/org/freedesktop/MalcontentUi/ui/restricts-switch.css"); + gtk_style_context_add_provider_for_screen (gdk_screen_get_default (), + GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION - 1); + self->selected_age = (guint) -1; self->cancellable = g_cancellable_new ();