Skip to content

Commit

Permalink
Respect solid color wallpaper (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenemter authored Jul 25, 2023
1 parent 8a66725 commit ccc30ea
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 35 deletions.
1 change: 1 addition & 0 deletions data/greeter.metainfo.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
</ul>
</description>
<issues>
<issue url="https://github.com/elementary/greeter/issues/3">Login screen does not respect solid color background</issue>
<issue url="https://github.com/elementary/greeter/issues/25">Mask corners</issue>
<issue url="https://github.com/elementary/greeter/issues/70">User mouse settings aren't applied</issue>
<issue url="https://github.com/elementary/greeter/issues/295">Clicking in the card but outside of the wallpaper window does not switch the card</issue>
Expand Down
72 changes: 39 additions & 33 deletions src/Cards/UserCard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -369,6 +369,7 @@ public class Greeter.UserCard : Greeter.BaseCard {
}
}

set_background_image ();
set_check_style ();

if (needs_settings_set) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/PantheonAccountsServicePlugin.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
20 changes: 19 additions & 1 deletion src/Widgets/BackgroundImage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand All @@ -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
)

0 comments on commit ccc30ea

Please sign in to comment.