From 33d2f8d0461314c5eeaab2c74b10b545906e1491 Mon Sep 17 00:00:00 2001 From: Mihai Moldovan Date: Tue, 6 Dec 2022 05:10:29 +0100 Subject: misc src/: completely rework high contrast mode, add stub for big font mode. This is a work-in-progress. The reworked high contrast mode adds support for a configurable high contrast GTK theme and changes a lot of widgets to change their color. The big font mode is a stub currently. --- .../org.ArcticaProject.arctica-greeter.gschema.xml | 12 ++ src/arctica-greeter.vala | 110 ++++++++++++ src/dash-box.vala | 19 ++- src/main-window.vala | 5 +- src/menubar.vala | 182 +++++++++++++++++--- src/prompt-box.vala | 188 ++++++++++++++++++++- src/settings.vala | 60 +++++++ src/toggle-box.vala | 39 ++++- src/user-list.vala | 6 +- tests/menubar.vala | 1 - 10 files changed, 586 insertions(+), 36 deletions(-) diff --git a/data/org.ArcticaProject.arctica-greeter.gschema.xml b/data/org.ArcticaProject.arctica-greeter.gschema.xml index 9efc200..b0069c2 100644 --- a/data/org.ArcticaProject.arctica-greeter.gschema.xml +++ b/data/org.ArcticaProject.arctica-greeter.gschema.xml @@ -37,6 +37,10 @@ 'Blue-Submarine' GTK+ theme to use + + 'HighContrastInverse' + GTK+ theme to use in high contrast mode + 'Adwaita' Icon theme to use @@ -82,6 +86,10 @@ false Whether to use a high contrast theme + + false + Whether to use big fonts throughout the application + false Whether to enable the screen reader @@ -115,6 +123,10 @@ 'auto' Whether to enable HiDPI support + + 0.5 + Alpha value for menubar, multiplied with the theme-provided transparency value. Not used in high contrast mode. + '' Default FQDN for host offering Remote Logon Service diff --git a/src/arctica-greeter.vala b/src/arctica-greeter.vala index 013739c..6d31a9b 100644 --- a/src/arctica-greeter.vala +++ b/src/arctica-greeter.vala @@ -306,6 +306,47 @@ public class ArcticaGreeter : Object Canberra.PROP_EVENT_ID, "system-ready"); + /* Synchronize properties in AGSettings once. */ + var agsettings = new AGSettings (); + agsettings.high_contrast = !(!(agsettings.high_contrast)); + agsettings.big_font = !(!(agsettings.big_font)); + + /* + * Add timeouts to process the full node hierarchy to handle a11y + * changes. + * + * That's the easiest way to handle a changing node hierarchy. + * + * Alternatives would involve connecting a function for every a11y + * change to the GtkWidget::parent-set event to *every widget* we + * create, but that would make the code incredibly messy. + * + * The value has been determined by a fair dice roll and should make + * sure that changes are visible almost instantaneously to users. + */ + Timeout.add_full (GLib.Priority.HIGH_IDLE, 302, () => { + var agsettings_intimer = new AGSettings (); + /* + if (0 == GLib.Random.int_range (0, 10)) { + debug ("Syncing up high contrast value via timer: %s", agsettings_intimer.high_contrast.to_string ()); + } + */ + switch_contrast (agsettings_intimer.high_contrast); + + return true; + }); + Timeout.add_full (GLib.Priority.HIGH_IDLE, 302, () => { + var agsettings_intimer = new AGSettings (); + /* + if (0 == GLib.Random.int_range (0, 10)) { + debug ("Syncing up big font value via timer: %s", agsettings_intimer.big_font.to_string ()); + } + */ + switch_font (agsettings_intimer.big_font); + + return true; + }); + return false; } @@ -419,6 +460,75 @@ public class ArcticaGreeter : Object return greeter.has_guest_account_hint; } + private delegate void SwitchClassType (Gtk.Widget widget, string classname, bool enable); + + private delegate void IterateChildrenType (Gtk.Widget widget); + + private void switch_generic (Gtk.Widget widget, string classname, bool enable) + { + var style_ctx = widget.get_style_context (); + if (enable) + { + style_ctx.add_class (classname); + } + else + { + style_ctx.remove_class (classname); + } + } + + private void iterate_children_generic (Gtk.Widget widget, SwitchClassType switch_func, string classname, bool enable) + { + /* + * GTK 4 changed its API quite dramatically, got rid of GtkContainer + * and made each GtkWidget accept children, while also defining a new + * way to access those. + */ + IterateChildrenType rec_func = null; + rec_func = (widget) => { +#if HAVE_GTK_4_0 + Gtk.Widget child = widget.get_first_child (); + while (null != child) + { + rec_func (child); + child = child.get_next_sibling (); + } +#else + if (gtk_is_container (widget)) + { + ((Gtk.Container)(widget)).@foreach (rec_func); + } +#endif + + /* Common code to add or remove the CSS class. */ + switch_func (widget, classname, enable); + }; + + /* + * Actually recursively iterate through this item and all of its + * children. + */ + rec_func (widget); + } + + public void switch_contrast (bool high) + { + var time_pre = GLib.get_monotonic_time (); + iterate_children_generic (main_window, switch_generic, "high_contrast", high); + var time_post = GLib.get_monotonic_time (); + var time_diff = time_post - time_pre; + assert (0 <= time_diff); + var time_diff_sec = time_diff / 1000000; + var time_diff_msec = time_diff / 1000; + var time_diff_usec = time_diff % 1000000; + // debug ("Time passed: %" + int64.FORMAT + " s, %" + int64.FORMAT + " ms, %" + int64.FORMAT + " us", time_diff_sec, time_diff_msec, time_diff_usec); + } + + public void switch_font (bool big) + { + iterate_children_generic (main_window, switch_generic, "big_font", big); + } + private Gdk.FilterReturn focus_upon_map (Gdk.XEvent gxevent, Gdk.Event event) { var xevent = (X.Event*)gxevent; diff --git a/src/dash-box.vala b/src/dash-box.vala index d8fe6fd..1073aa5 100644 --- a/src/dash-box.vala +++ b/src/dash-box.vala @@ -221,10 +221,25 @@ public class DashBox : Gtk.Box CairoUtils.rounded_rectangle (c, 0, box_y, box_w, box_h, box_r); - c.set_source_rgba (0.1, 0.1, 0.1, 0.4); + var agsettings = new AGSettings (); + if (agsettings.high_contrast) + { + c.set_source_rgba (1.0, 1.0, 1.0, 1.0); + } + else + { + c.set_source_rgba (0.1, 0.1, 0.1, 0.4); + } c.fill_preserve (); - c.set_source_rgba (0.4, 0.4, 0.4, 0.4); + if (agsettings.high_contrast) + { + c.set_source_rgba (0.0, 0.0, 0.0, 1.0); + } + else + { + c.set_source_rgba (0.4, 0.4, 0.4, 0.4); + } c.set_line_width (1); c.stroke (); diff --git a/src/main-window.vala b/src/main-window.vala index 172c6f4..d7fe6f0 100644 --- a/src/main-window.vala +++ b/src/main-window.vala @@ -40,7 +40,7 @@ public class MainWindow : Gtk.Window public ListStack stack; // Menubar is smaller, but with shadow, we reserve more space - public const int MENUBAR_HEIGHT = 32; + public const int MENUBAR_HEIGHT = 40; construct { @@ -75,6 +75,8 @@ public class MainWindow : Gtk.Window shadow_style = "background-image: url('%s'); background-repeat: repeat;".printf(shadow_path); } + /* Disable the shadow image, we will use CSS instead. */ + /* try { var style = new Gtk.CssProvider (); @@ -89,6 +91,7 @@ public class MainWindow : Gtk.Window { debug ("Internal error loading menubox style: %s", e.message); } + */ menubox.set_size_request (-1, MENUBAR_HEIGHT); menubox.show (); menualign.show (); diff --git a/src/menubar.vala b/src/menubar.vala index 3f9f72c..8915530 100644 --- a/src/menubar.vala +++ b/src/menubar.vala @@ -68,7 +68,6 @@ private class IndicatorMenuItem : Gtk.MenuItem public class MenuBar : Gtk.MenuBar { public Background? background { get; construct; default = null; } - public bool high_contrast { get; private set; default = false; } public Gtk.Window? keyboard_window { get; private set; default = null; } public Gtk.AccelGroup? accel_group { get; construct; } @@ -83,16 +82,57 @@ public class MenuBar : Gtk.MenuBar { if (background != null) { + /* Disable background drawing to see how it changes the visuals. */ + /* int x, y; background.translate_coordinates (this, 0, 0, out x, out y); c.save (); c.translate (x, y); background.draw_full (c, Background.DrawFlags.NONE); c.restore (); + */ } - c.set_source_rgb (0.1, 0.1, 0.1); - c.paint_with_alpha (0.4); + /* Get the style and dimensions. */ + var style_ctx = this.get_style_context (); + + var w = this.get_allocated_width (); + var h = this.get_allocated_height (); + + /* Add a group. */ + c.push_group (); + + /* Draw the background normally. */ + style_ctx.render_background (c, 0, 0, w, h); + + /* Draw the frame normally. */ + style_ctx.render_frame (c, 0, 0, w, h); + + /* Go back to the original widget. */ + c.pop_group_to_source (); + + var agsettings = new AGSettings (); + if (agsettings.high_contrast) { + /* + * In case the high contrast mode is enabled, do not add any + * transparency. While the GTK theme might define one (even though + * it better should not, given that we are also switching to a + * high contrast theme), we certainly do not want to make the look + * fuzzy. + */ + c.paint (); + } + else { + /* + * And finally repaint it with additional transparency. + * Note that most GTK styles already define a transparency for OSD + * menus. We want to have something more transparent, but also + * make sure that it is not too transparent, so do not choose a + * value that is too low here - certainly not your desired final + * alpha value. + */ + c.paint_with_alpha (AGSettings.get_double (AGSettings.KEY_MENUBAR_ALPHA)); + } foreach (var child in get_children ()) { @@ -102,6 +142,16 @@ public class MenuBar : Gtk.MenuBar return false; } + public static void add_style_class (Gtk.Widget widget) + { + /* + * Add style context class osd, which makes the widget respect the GTK + * style definitions for this type of elements. + */ + var ctx = widget.get_style_context (); + ctx.add_class ("osd"); + } + /* Due to LP #973922 the keyboard has to be loaded after the main window * is shown and given focus. Therefore we don't enable the active state * until now. @@ -113,33 +163,110 @@ public class MenuBar : Gtk.MenuBar onscreen_keyboard_item.set_active (AGSettings.get_boolean (AGSettings.KEY_ONSCREEN_KEYBOARD)); } - private string default_theme_name; private List indicator_objects; private Gtk.CheckMenuItem high_contrast_item; + private Gtk.CheckMenuItem big_font_item; private Pid keyboard_pid = 0; private Pid reader_pid = 0; private Gtk.CheckMenuItem onscreen_keyboard_item; construct { - Gtk.Settings.get_default ().get ("gtk-theme-name", out default_theme_name); + add_style_class (this); + + /* Add shadow. */ + var shadow_style = new Gtk.CssProvider (); + shadow_style.load_from_data ("* { box-shadow: 0px 0px 5px 5px #000000; }", -1); + this.get_style_context ().add_provider (shadow_style, + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); pack_direction = Gtk.PackDirection.RTL; if (AGSettings.get_boolean (AGSettings.KEY_SHOW_HOSTNAME)) { - var label = new Gtk.Label (Posix.utsname ().nodename); - label.show (); - var hostname_item = new Gtk.MenuItem (); - hostname_item.add (label); - hostname_item.sensitive = false; - hostname_item.right_justified = true; - hostname_item.show (); + var hostname_item = new Gtk.MenuItem.with_label (Posix.utsname ().nodename); append (hostname_item); + hostname_item.show (); + + /* + * Even though this (menu) item is insensitive, we want its label + * text to have the sensitive color as to not look out of place + * and difficult to read. + * + * There's a really weird bug that leads to always fetch the + * sensitive color after the widget (menuitem in this case) has + * been set to insensitive once - at least in this constructor. + * + * I haven't found a way to fix that, or, for that matter, what is + * actually causing the issue. Even waiting on the main event loop + * until all events are processed didn't help. + * + * We'll work around this issue by fetching the color before + * setting the widget to insensitive and call it proper. + */ + var insensitive_override_style = new Gtk.CssProvider (); + + /* + * First, fetch the associated GtkStyleContext and save the state, + * we'll override the state later on. + */ + var hostname_item_ctx = hostname_item.get_style_context (); + hostname_item_ctx.save (); + + try { + /* Get the actual color. */ + var sensitive_color = hostname_item_ctx.get_color (Gtk.StateFlags.NORMAL); + debug ("Directly fetched sensitive color: %s", sensitive_color.to_string ()); + + insensitive_override_style.load_from_data ("*:disabled { color: %s; }".printf(sensitive_color.to_string ()), -1); + } + catch (Error e) + { + debug ("Internal error loading hostname menu item text color: %s", e.message); + } + finally { + /* + * Restore the context, which we might have changed through the + * previous get_color () call. + */ + hostname_item_ctx.restore (); + } + + try { + /* And finally override the insensitive color. */ + hostname_item_ctx.add_provider (insensitive_override_style, + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + + /* + * Just overriding the color for the Gtk.MenuItem widget + * doesn't help, we'll also apply it to the children. + * + * In theory, we could just use the get_child () method to + * fetch the only child we should ever have on that widget, + * namely a GtkAccelLabel, but that isn't future-proof enough, + * especially if that is ever extended into having a submenu. + * + * Thus, iterate over all children and override the style for + * all of them. + */ + if (gtk_is_container (hostname_item)) { + var children = hostname_item.get_children (); + foreach (Gtk.Widget element in children) { + var child_ctx = element.get_style_context (); + debug ("Adding override style provider to child widget %s", element.name); + child_ctx.add_provider (insensitive_override_style, + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } + } + } + catch (Error e) + { + debug ("Internal error overriding hostname menu item text color: %s", e.message); + } - /* Hack to get a label showing on the menubar */ - var fg = label.get_style_context ().get_color (Gtk.StateFlags.NORMAL); - label.override_color (Gtk.StateFlags.INSENSITIVE, fg); + hostname_item.set_sensitive (false); + + hostname_item.set_right_justified (true); } /* Prevent dragging the window by the menubar */ @@ -235,7 +362,15 @@ public class MenuBar : Gtk.MenuBar high_contrast_item.add_accelerator ("activate", accel_group, Gdk.Key.h, Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE); high_contrast_item.show (); submenu.append (high_contrast_item); - high_contrast_item.set_active (AGSettings.get_boolean (AGSettings.KEY_HIGH_CONTRAST)); + var agsettings = new AGSettings (); + debug ("Initializing high contrast menu item to state %s", agsettings.high_contrast.to_string ()); + high_contrast_item.set_active (agsettings.high_contrast); + big_font_item = new Gtk.CheckMenuItem.with_label (_("Big Font")); + big_font_item.toggled.connect (big_font_toggled_cb); + big_font_item.add_accelerator ("activate", accel_group, Gdk.Key.b, Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE); + big_font_item.show (); + submenu.append (big_font_item); + big_font_item.set_active (agsettings.big_font); var item = new Gtk.CheckMenuItem.with_label (_("Screen Reader")); item.toggled.connect (screen_reader_toggled_cb); item.add_accelerator ("activate", accel_group, Gdk.Key.s, Gdk.ModifierType.SUPER_MASK | Gdk.ModifierType.MOD1_MASK, Gtk.AccelFlags.VISIBLE); @@ -443,13 +578,14 @@ public class MenuBar : Gtk.MenuBar private void high_contrast_toggled_cb (Gtk.CheckMenuItem item) { - var settings = Gtk.Settings.get_default (); - if (item.active) - settings.set ("gtk-theme-name", "HighContrastInverse"); - else - settings.set ("gtk-theme-name", default_theme_name); - high_contrast = item.active; - AGSettings.set_boolean (AGSettings.KEY_HIGH_CONTRAST, high_contrast); + var agsettings = new AGSettings (); + agsettings.high_contrast = item.active; + } + + private void big_font_toggled_cb (Gtk.CheckMenuItem item) + { + var agsettings = new AGSettings (); + agsettings.big_font = item.active; } private void screen_reader_toggled_cb (Gtk.CheckMenuItem item) diff --git a/src/prompt-box.vala b/src/prompt-box.vala index 1a0007f..2180c70 100644 --- a/src/prompt-box.vala +++ b/src/prompt-box.vala @@ -208,7 +208,21 @@ public class PromptBox : FadableBox debug ("Internal error loading font style (%s, %dpt): %s", font_family, font_size+2, e.message); } - name_label.override_color (Gtk.StateFlags.NORMAL, { 1.0f, 1.0f, 1.0f, 1.0f }); + var agsettings = new AGSettings (); + try + { + var color_provider = new Gtk.CssProvider (); + var css = "* { color: rgba(255, 255, 255, 1.0); }\n" + + ".high_contrast { color: rgba (0, 0, 0, 1.0); }"; + color_provider.load_from_data (css, -1); + style_ctx.add_provider (color_provider, + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } + catch (Error e) + { + debug ("Internal error setting color on name label: %s", e.message); + } + name_label.valign = Gtk.Align.START; name_label.vexpand = true; name_label.yalign = 0.5f; @@ -236,7 +250,40 @@ public class PromptBox : FadableBox name_grid.attach (align, COL_NAME_MESSAGE, ROW_NAME, 1, 1); option_button = new FlatButton (); - option_button.get_style_context ().add_class ("option-button"); + var option_button_ctx = option_button.get_style_context (); + option_button_ctx.add_class ("option-button"); + + try { + /* + * Override background for both high-contrast and normal modes. + * Note that we have to use CSS selectors here, since this code + * is only executed once. + */ + var background_style = new Gtk.CssProvider (); + background_style.load_from_data ("button.flat.option-button.high_contrast {\n" + + " background-color: %s;\n".printf("rgba(0,0,0,1.0)") + + " background-image: none;\n" + + "}\n" + + "button.flat.option-button:hover:not(.high_contrast), " + + "button.flat.option-button:active:not(.high_contrast), " + + "button.flat.option-button:hover:active:not(.high_contrast) {\n"+ + " background-color: %s;\n".printf("rgba(255,255,255,0.5)")+ + " background-image: none;"+ + "}\n" + + "button.flat.option-button:hover.high_contrast," + + "button.flat.option-button:active.high_contrast," + + "button.flat.option-button:hover:active.high_contrast {\n" + + " background-color:%s;\n".printf("rgba(70, 70, 70, 1.0)") + + " background-image: none;" + + "}\n", -1); + option_button_ctx.add_provider (background_style, + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } + catch (Error e) + { + debug ("Internal error loading option button background style: %s", e.message); + } + option_button.hexpand = true; option_button.halign = Gtk.Align.END; option_button.valign = Gtk.Align.START; @@ -388,6 +435,7 @@ public class PromptBox : FadableBox public void clear () { prompt_visibility = PromptVisibility.HIDDEN; + active_indicator.expanded = false; /* Hold a ref while removing the prompt widgets - * if we just do w.destroy() we get this warning: @@ -452,6 +500,7 @@ public class PromptBox : FadableBox { case PromptVisibility.HIDDEN: w.hide (); + active_indicator.expanded = false; break; case PromptVisibility.FADING: var f = w as Fadable; @@ -460,10 +509,12 @@ public class PromptBox : FadableBox f.fade_in (); else w.show (); + active_indicator.expanded = true; break; case PromptVisibility.SHOWN: w.show (); w.sensitive = true; + active_indicator.expanded = true; break; } } @@ -473,6 +524,7 @@ public class PromptBox : FadableBox prompt_visibility = PromptVisibility.FADING; show (); foreach_prompt_widget ((w) => { update_prompt_visibility (w); }); + active_indicator.expanded = true; } public void show_prompts () @@ -480,6 +532,7 @@ public class PromptBox : FadableBox prompt_visibility = PromptVisibility.SHOWN; show (); foreach_prompt_widget ((w) => { update_prompt_visibility (w); }); + active_indicator.expanded = true; } protected void attach_item (Gtk.Widget w, bool add_style_class = true) @@ -713,6 +766,7 @@ public class PromptBox : FadableBox private class ActiveIndicator : Gtk.Image { public bool active { get; set; } + public bool expanded { get; set; } public const int WIDTH = 8; public const int HEIGHT = 7; @@ -722,12 +776,16 @@ private class ActiveIndicator : Gtk.Image try { pixbuf = new Gdk.Pixbuf.from_file (filename); + pixbuf_changed_helper (); } catch (Error e) { debug ("Could not load active image: %s", e.message); } notify["active"].connect (() => { queue_draw (); }); + notify["expanded"].connect (() => { notify_expanded (); }); + notify["pixbuf"].connect ((s, p) => { notify_pixbuf_changed (s, p); }); + this.style_updated.connect ((w) => { handle_style_updated (w); }); xalign = 0.0f; } @@ -747,6 +805,132 @@ private class ActiveIndicator : Gtk.Image { if (!active) return false; + return base.draw (c); } + + private void notify_pixbuf_changed (Object src, ParamSpec prop) { + assert ("pixbuf" == prop.name); + + if (!(this.swapping_)) { + pixbuf_changed_helper (); + } + } + + private void pixbuf_changed_helper () { + /* Copy the new pixbuf. */ + this.pixbuf_orig_ = this.pixbuf.copy (); + this.pixbuf.copy_options (this.pixbuf_orig_); + this.pixbuf_inverted_ = this.pixbuf.copy (); + this.pixbuf.copy_options (this.pixbuf_inverted_); + + /* Invert the new pixbuf. */ + invert_pixbuf (); + + if (this.inverted_) { + this.swapping_ = true; + this.pixbuf = this.pixbuf_inverted_; + this.swapping_ = false; + } + } + + private void handle_style_updated (Gtk.Widget widget) { + var style_ctx = this.get_style_context (); + if (style_ctx.has_class ("high_contrast")) { + if ((!(this.inverted_)) && (this.expanded)) { + this.swapping_ = true; + this.pixbuf = this.pixbuf_inverted_; + this.inverted_ = true; + this.swapping_ = false; + } + } + else { + if (this.inverted_) { + this.swapping_ = true; + this.pixbuf = this.pixbuf_orig_; + this.inverted_ = false; + this.swapping_ = false; + } + } + } + + private void invert_pixbuf () { + assert (Gdk.Colorspace.RGB == this.pixbuf_inverted_.get_colorspace ()); + var sample_size = this.pixbuf_inverted_.get_bits_per_sample (); + var alpha = this.pixbuf_inverted_.get_has_alpha (); + var channels = this.pixbuf_inverted_.get_n_channels (); + + assert (((4 == channels) && (alpha)) || + (3 == channels)); + + /* + * Fun fact: we don't need to decompose the actual colors. Since + * the inversion is just a simple XOR operation, we can just + * invert all the bits minus the alpha value. + */ + assert (1 <= sample_size); + + var rowstride = this.pixbuf_inverted_.get_rowstride (); + var col_bytes = (((channels * sample_size) + 7) / 8); + var row_bytes = (this.pixbuf_inverted_.width * col_bytes); + unowned var pixels = this.pixbuf_inverted_.get_pixels (); + assert (pixels != null); + size_t color_bits = channels; + if (alpha) { + --color_bits; + } + color_bits *= sample_size; + for (size_t i = 0; i < this.pixbuf_inverted_.height; (++i)) { + for (size_t y = 0; y < this.pixbuf_inverted_.width; (++y)) { + /* Invert full bytes first. */ + for (size_t x = 0; x < (color_bits / 8); (++(x))) { + pixels[(i * rowstride) + (y * col_bytes) + (x)] ^= (~(0)); + } + + /* + * And now, invert the last actual color bits minus alpha + * and padding. + */ + uint8 rest = (uint8) (color_bits % 8); + if (0 < rest) { + uint8 mask = (~(0)); + mask <<= (8 - rest); + pixels[(i * rowstride) + (y * col_bytes) + (color_bits / 8)] ^= mask; + } + } + } + } + + private void notify_expanded () { + if (!(this.expanded)) { + /* + * In non-expanded form, we always want to have the original + * look. + */ + if (this.inverted_) { + this.swapping_ = true; + this.pixbuf = this.pixbuf_orig_; + this.inverted_ = false; + this.swapping_ = false; + } + } + else { + /* + * In expanded form, we want to restore the inverted form iff the + * high contrast mode is enabled. + */ + var agsettings = new AGSettings (); + if ((!(this.inverted_)) && (agsettings.high_contrast)) { + this.swapping_ = true; + this.pixbuf = this.pixbuf_inverted_; + this.inverted_ = true; + this.swapping_ = false; + } + } + } + + private bool inverted_ = false; + private bool swapping_ = false; + private Gdk.Pixbuf? pixbuf_orig_ = null; + private Gdk.Pixbuf? pixbuf_inverted_ = null; } diff --git a/src/settings.vala b/src/settings.vala index 3c50bbc..af753ce 100644 --- a/src/settings.vala +++ b/src/settings.vala @@ -31,6 +31,7 @@ public class AGSettings : Object public const string KEY_SHOW_HOSTNAME = "show-hostname"; public const string KEY_LOGO = "logo"; public const string KEY_THEME_NAME = "theme-name"; + public const string KEY_HIGH_CONTRAST_THEME_NAME = "high-contrast-theme-name"; public const string KEY_ICON_THEME_NAME = "icon-theme-name"; public const string KEY_FONT_NAME = "font-name"; public const string KEY_XFT_ANTIALIAS = "xft-antialias"; @@ -39,6 +40,7 @@ public class AGSettings : Object public const string KEY_XFT_RGBA = "xft-rgba"; public const string KEY_ONSCREEN_KEYBOARD = "onscreen-keyboard"; public const string KEY_HIGH_CONTRAST = "high-contrast"; + public const string KEY_BIG_FONT = "big-font"; public const string KEY_SCREEN_READER = "screen-reader"; public const string KEY_PLAY_READY_SOUND = "play-ready-sound"; public const string KEY_INDICATORS = "indicators"; @@ -51,6 +53,8 @@ public class AGSettings : Object public const string KEY_TOGGLEBOX_FONT_FGCOLOR = "togglebox-font-fgcolor"; public const string KEY_TOGGLEBOX_BUTTON_BGCOLOR = "togglebox-button-bgcolor"; public const string KEY_ENABLE_HIDPI = "enable-hidpi"; + public const string KEY_MENUBAR_ALPHA = "menubar-alpha"; + public static bool get_boolean (string key) { @@ -112,7 +116,63 @@ public class AGSettings : Object } construct { + Gtk.Settings.get_default ().get ("gtk-theme-name", out this.default_theme_name_); + /* + debug ("Fetched default theme name in construct: %s", this.default_theme_name_); + */ + } + + public bool high_contrast { + get { + return this.high_contrast_; + } + + set { + debug ("Called high contrast setter with value %s", value.to_string ()); + this.high_contrast_ = value; + + /* Also sync back to dconf, so that this state is persistent. */ + set_boolean (AGSettings.KEY_HIGH_CONTRAST, value); + + var greeter = new ArcticaGreeter (); + greeter.switch_contrast (value); + + var settings = Gtk.Settings.get_default (); + if (value) + { + /* + debug ("Switching GTK Theme to high contrast theme \"%s\"", AGSettings.get_string (AGSettings.KEY_HIGH_CONTRAST_THEME_NAME)); + */ + settings.set ("gtk-theme-name", AGSettings.get_string (AGSettings.KEY_HIGH_CONTRAST_THEME_NAME)); + } + else + { + /* + debug ("Switching GTK Theme to default theme \"%s\"", this.default_theme_name_); + */ + settings.set ("gtk-theme-name", this.default_theme_name_); + } + } + } + + public bool big_font { + get { + return this.big_font_; + } + + set { + this.big_font_ = value; + + /* Also sync back to dconf, so that this state is persistent. */ + set_boolean (AGSettings.KEY_BIG_FONT, value); + + var greeter = new ArcticaGreeter (); + greeter.switch_font (value); + } } private const string SCHEMA = "org.ArcticaProject.arctica-greeter"; + private bool high_contrast_ = AGSettings.get_boolean (AGSettings.KEY_HIGH_CONTRAST); + private bool big_font_ = AGSettings.get_boolean (AGSettings.KEY_BIG_FONT); + private string default_theme_name_; } diff --git a/src/toggle-box.vala b/src/toggle-box.vala index c157f60..518275f 100644 --- a/src/toggle-box.vala +++ b/src/toggle-box.vala @@ -70,8 +70,21 @@ public class ToggleBox : Gtk.Box " background-image: none;"+ "}\n"+ "button:hover,\n"+ - "button:hover:active {\n"+ + "button:active,\n" + + "button:hover:active,\n" + + "button.selected {\n"+ " background-color: %s;\n".printf(AGSettings.get_string (AGSettings.KEY_TOGGLEBOX_BUTTON_BGCOLOR))+ + "}\n" + + "button.high_contrast {\n" + + " background-color: %s;\n".printf ("rgba(70, 70, 70, 1.0)") + + " background-image: none;\n" + + " border-color: %s\n;".printf ("rgba(0, 0, 0, 1.0)") + + "}\n" + + "button.high_contrast:hover,\n" + + "button.high_contrast:active,\n" + + "button.high_contrast:hover:active,\n" + + "button.high_contrast.selected {\n" + + " background-color: %s;\n".printf ("rgba(0, 0, 0, 1.0)") + "}\n", -1); button.get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); } @@ -113,9 +126,8 @@ public class ToggleBox : Gtk.Box selected_button = button; selected_key = selected_button.get_data ("toggle-list-key"); - var bg_color = Gdk.RGBA (); - bg_color.parse (AGSettings.get_string (AGSettings.KEY_TOGGLEBOX_BUTTON_BGCOLOR)); - selected_button.override_background_color(Gtk.StateFlags.NORMAL, bg_color); + /* Handle color via CSS. */ + selected_button.get_style_context ().add_class ("selected"); } private Gtk.Button make_button (string key, string name_in, Gdk.Pixbuf? icon) @@ -140,7 +152,24 @@ public class ToggleBox : Gtk.Box } var label = new Gtk.Label (null); - label.set_markup ("%s".printf (font_family, font_size+2, AGSettings.get_string (AGSettings.KEY_TOGGLEBOX_FONT_FGCOLOR), name)); + /* Font and other properties are being handled via CSS. */ + label.set_text (name); + try { + var style = new Gtk.CssProvider (); + style.load_from_data ("label {\n" + + " font-family: \"%s\", sans-serif;\n".printf (font_family) + + " font-size: %d;\n".printf (font_size + 2) + + " color: %s;\n".printf (AGSettings.get_string (AGSettings.KEY_TOGGLEBOX_FONT_FGCOLOR)) + + "}\n" + + "label.high_contrast {\n" + + " color: %s;\n".printf ("rgba(255, 255, 255, 1.0)") + + "}\n", -1); + label.get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } + catch (Error e) + { + debug ("Internal error loading session chooser label style: %s", e.message); + } label.halign = Gtk.Align.START; hbox.pack_start (label, true, true, 0); diff --git a/src/user-list.vala b/src/user-list.vala index 3012c7d..9f4b265 100644 --- a/src/user-list.vala +++ b/src/user-list.vala @@ -148,7 +148,8 @@ public class UserList : GreeterList construct { - menubar.notify["high-contrast"].connect (() => { change_background (); }); + var agsettings = new AGSettings (); + agsettings.notify["high-contrast"].connect (() => { change_background (); }); entry_displayed_start.connect (() => { change_background (); }); entry_displayed_done.connect (() => { change_background (); }); @@ -593,7 +594,8 @@ public class UserList : GreeterList private bool change_background_timeout_cb () { string? new_background_file = null; - if (menubar.high_contrast || !AGSettings.get_boolean (AGSettings.KEY_DRAW_USER_BACKGROUNDS)) + var agsettings = new AGSettings (); + if (agsettings.high_contrast || !AGSettings.get_boolean (AGSettings.KEY_DRAW_USER_BACKGROUNDS)) new_background_file = null; else if (selected_entry is UserPromptBox) new_background_file = (selected_entry as UserPromptBox).background; diff --git a/tests/menubar.vala b/tests/menubar.vala index f222957..4162dc0 100644 --- a/tests/menubar.vala +++ b/tests/menubar.vala @@ -19,7 +19,6 @@ public class MenuBar : Gtk.MenuBar { public const int HEIGHT = 32; - public bool high_contrast { get; private set; default = false; } public MenuBar (Background bg, Gtk.AccelGroup ag) { -- cgit v1.2.3