From ccc30eaedf81944d743491c7601d9f6b11ed8995 Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 26 Jul 2023 01:13:02 +0900 Subject: [PATCH] Respect solid color wallpaper (#672) --- data/greeter.metainfo.xml.in | 1 + src/Cards/UserCard.vala | 72 ++++++++++++++------------ src/PantheonAccountsServicePlugin.vala | 2 + src/Widgets/BackgroundImage.vala | 20 ++++++- src/meson.build | 3 +- 5 files changed, 63 insertions(+), 35 deletions(-) diff --git a/data/greeter.metainfo.xml.in b/data/greeter.metainfo.xml.in index ef24a0e20..f26bc7e22 100644 --- a/data/greeter.metainfo.xml.in +++ b/data/greeter.metainfo.xml.in @@ -45,6 +45,7 @@ + Login screen does not respect solid color background Mask corners User mouse settings aren't applied Clicking in the card but outside of the wallpaper window does not switch the card diff --git a/src/Cards/UserCard.vala b/src/Cards/UserCard.vala index a737d8542..eb05105cb 100644 --- a/src/Cards/UserCard.vala +++ b/src/Cards/UserCard.vala @@ -29,6 +29,8 @@ public class Greeter.UserCard : Greeter.BaseCard { private Gtk.Revealer form_revealer; private Gtk.Stack login_stack; private Greeter.PasswordEntry password_entry; + private Gtk.Box main_box; + private SelectionCheck logged_in; private unowned Gtk.StyleContext logged_in_context; @@ -153,36 +155,12 @@ public class Greeter.UserCard : Greeter.BaseCard { SYNC_CREATE ); - var background_path = lightdm_user.background; - - if (background_path == null) { - string path = Path.build_filename ("/", "var", "lib", "lightdm-data", lightdm_user.name, "wallpaper"); - if (FileUtils.test (path, EXISTS)) { - var background_directory = File.new_for_path (path); - try { - var enumerator = background_directory.enumerate_children (FileAttribute.STANDARD_NAME, NONE); - - FileInfo file_info; - while ((file_info = enumerator.next_file ()) != null) { - if (file_info.get_file_type () == REGULAR) { - background_path = Path.build_filename (path, file_info.get_name ()); - break; - } - } - } catch (Error e) { - critical (e.message); - } - } - } - - var background_image = new Greeter.BackgroundImage (background_path); - - var main_box = new Gtk.Box (VERTICAL, 0) { + main_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { margin_bottom = 48 }; - main_box.add (background_image); - main_box.add (username_label); - main_box.add (form_revealer); + // in reverse order because pack_end is used + main_box.pack_end (form_revealer); + main_box.pack_end (username_label); main_box_style_context = main_box.get_style_context (); main_box_style_context.add_class (Granite.STYLE_CLASS_CARD); @@ -288,17 +266,39 @@ public class Greeter.UserCard : Greeter.BaseCard { }); } - private void update_style () { - var interface_settings = new GLib.Settings ("org.gnome.desktop.interface"); - interface_settings.set_value ("gtk-theme", "io.elementary.stylesheet." + accent_to_string (prefers_accent_color)); - } - private void set_check_style () { // Override check's accent_color so that it *always* uses user's preferred color var style_provider = Gtk.CssProvider.get_named ("io.elementary.stylesheet." + accent_to_string (prefers_accent_color), null); logged_in_context.add_provider (style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); } + private void set_background_image () { + Greeter.BackgroundImage background_image; + + var background_path = lightdm_user.background; + var background_exists = ( + background_path != null && + FileUtils.test (background_path, EXISTS) && + FileUtils.test (background_path, IS_REGULAR) + ); + + if (!background_exists) { + background_path = Path.build_filename ("/", "var", "lib", "lightdm-data", lightdm_user.name, "wallpaper"); + background_exists = FileUtils.test (background_path, EXISTS) && FileUtils.test (background_path, IS_REGULAR); + } + + if (settings_act.picture_options != 0 && background_exists) { + background_image = new Greeter.BackgroundImage.from_path (background_path); + } else if (settings_act.picture_options == 0 && settings_act.primary_color != null) { + background_image = new Greeter.BackgroundImage.from_color (settings_act.primary_color); + } else { + background_image = new Greeter.BackgroundImage.from_path (null); + } + + main_box.pack_start (background_image); + main_box.show_all (); + } + private string accent_to_string (int i) { switch (i) { case 1: @@ -369,6 +369,7 @@ public class Greeter.UserCard : Greeter.BaseCard { } } + set_background_image (); set_check_style (); if (needs_settings_set) { @@ -491,6 +492,11 @@ public class Greeter.UserCard : Greeter.BaseCard { night_light_settings.set_value ("night-light-temperature", settings_act.night_light_temperature); } + private void update_style () { + var interface_settings = new GLib.Settings ("org.gnome.desktop.interface"); + interface_settings.set_value ("gtk-theme", "io.elementary.stylesheet." + accent_to_string (prefers_accent_color)); + } + public override void wrong_credentials () { unowned var entry_style_context = password_entry.get_style_context (); entry_style_context.add_class (Gtk.STYLE_CLASS_ERROR); diff --git a/src/PantheonAccountsServicePlugin.vala b/src/PantheonAccountsServicePlugin.vala index 527552010..c390edbbe 100644 --- a/src/PantheonAccountsServicePlugin.vala +++ b/src/PantheonAccountsServicePlugin.vala @@ -52,6 +52,8 @@ interface Pantheon.SettingsDaemon.AccountsService : Object { public abstract int cursor_size { get; set; } public abstract bool locate_pointer { get; set; } public abstract double text_scaling_factor { get; set; } + public abstract int picture_options { get; set; } + public abstract string primary_color { owned get; set; } public abstract string document_font_name { owned get; set; } public abstract string font_name { owned get; set; } public abstract string monospace_font_name { owned get; set; } diff --git a/src/Widgets/BackgroundImage.vala b/src/Widgets/BackgroundImage.vala index 833272c50..c52274ca0 100644 --- a/src/Widgets/BackgroundImage.vala +++ b/src/Widgets/BackgroundImage.vala @@ -7,7 +7,7 @@ public class Greeter.BackgroundImage : Gtk.EventBox { height_request = 150; } - public BackgroundImage (string? path) { + public BackgroundImage.from_path (string? path) { if (path == null) { path = "/usr/share/backgrounds/elementaryos-default"; } @@ -26,6 +26,24 @@ public class Greeter.BackgroundImage : Gtk.EventBox { } } + public BackgroundImage.from_color (string color) { + full_pixbuf = new Gdk.Pixbuf (Gdk.Colorspace.RGB, false, 8, 1, 1); + + Gdk.RGBA rgba_color = {}; + rgba_color.parse (color); + + uint32 f = 0x0; + f += (uint) Math.round (rgba_color.red * 255); + f <<= 8; + f += (uint) Math.round (rgba_color.green * 255); + f <<= 8; + f += (uint) Math.round (rgba_color.blue * 255); + f <<= 8; + f += 255; + + full_pixbuf.fill (f); + } + public override bool draw (Cairo.Context cr) { var scale = get_scale_factor (); var width = get_allocated_width () * scale; diff --git a/src/meson.build b/src/meson.build index c57dbb71f..29aaef3f8 100644 --- a/src/meson.build +++ b/src/meson.build @@ -5,6 +5,7 @@ gtk_dep = dependency('gtk+-3.0') granite_dep = dependency('granite', version: '>= 5.5.0') hdy_dep = dependency('libhandy-1', version: '>= 1.1.90') lightdm_dep = dependency('liblightdm-gobject-1') +m_dep = meson.get_compiler('c').find_library('m') install_path = join_paths(get_option('prefix'), get_option('sbindir')) @@ -28,7 +29,7 @@ executable( 'Widgets/PasswordEntry.vala', 'Widgets/SessionButton.vala', config_header, - dependencies: [ actservice_dep, gobject_dep, glib_dep, gtk_dep, granite_dep, hdy_dep, lightdm_dep ], + dependencies: [ actservice_dep, gobject_dep, glib_dep, gtk_dep, granite_dep, hdy_dep, lightdm_dep, m_dep ], install : true, install_dir: install_path )