Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to dim wallpapers when dark style is active #343

Merged
merged 6 commits into from
Apr 11, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 34 additions & 15 deletions src/Views/Wallpaper.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ public class PantheonShell.Wallpaper : Gtk.Grid {
};

public Switchboard.Plug plug { get; construct set; }
private GLib.Settings settings;

private static GLib.Settings gnome_background_settings;
private static GLib.Settings gala_background_settings;

//Instance of the AccountsServices-Interface for this user
private AccountsServiceUser? accountsservice = null;

private Gtk.ScrolledWindow wallpaper_scrolled_window;
private Gtk.FlowBox wallpaper_view;
private Gtk.Overlay view_overlay;
private Gtk.Switch dim_switch;
private Gtk.ComboBoxText combo;
private Gtk.ColorButton color_button;

Expand All @@ -65,9 +68,12 @@ public class PantheonShell.Wallpaper : Gtk.Grid {
Object (plug: _plug);
}

construct {
settings = new GLib.Settings ("org.gnome.desktop.background");
static construct {
gnome_background_settings = new GLib.Settings ("org.gnome.desktop.background");
gala_background_settings = new GLib.Settings ("io.elementary.desktop.background");
}

construct {
// DBus connection needed in update_wallpaper for
// passing the wallpaper-information to accountsservice.
try {
Expand All @@ -89,7 +95,7 @@ public class PantheonShell.Wallpaper : Gtk.Grid {
wallpaper_view.child_activated.connect (update_checked_wallpaper);
wallpaper_view.set_sort_func (wallpapers_sort_function);

var color = settings.get_string ("primary-color");
var color = gnome_background_settings.get_string ("primary-color");
create_solid_color_container (color);

Gtk.TargetEntry e = {"text/uri-list", 0, 0};
Expand All @@ -106,6 +112,15 @@ public class PantheonShell.Wallpaper : Gtk.Grid {
var add_wallpaper_button = new Gtk.Button.with_label (_("Import Photo…"));
add_wallpaper_button.margin = 12;

var dim_label = new Gtk.Label ("Dim wallpaper in dark style:") {
lenemter marked this conversation as resolved.
Show resolved Hide resolved
margin_end = 12
};

dim_switch = new Gtk.Switch () {
vexpand = false,
valign = Gtk.Align.CENTER
};

combo = new Gtk.ComboBoxText ();
combo.valign = Gtk.Align.CENTER;
combo.append ("centered", _("Centered"));
Expand Down Expand Up @@ -134,6 +149,8 @@ public class PantheonShell.Wallpaper : Gtk.Grid {
var actionbar = new Gtk.ActionBar ();
actionbar.get_style_context ().add_class (Gtk.STYLE_CLASS_INLINE_TOOLBAR);
actionbar.pack_start (add_wallpaper_button);
actionbar.pack_start (dim_label);
actionbar.pack_start (dim_switch);
actionbar.pack_end (color_button);
actionbar.pack_end (combo);

Expand Down Expand Up @@ -191,10 +208,12 @@ public class PantheonShell.Wallpaper : Gtk.Grid {
}

private void load_settings () {
gala_background_settings.bind ("dim-wallpaper-in-dark-style", dim_switch, "active", SettingsBindFlags.DEFAULT);

// TODO: need to store the previous state, before changing to none
// when a solid color is selected, because the combobox doesn't know
// about it anymore. The previous state should be loaded instead here.
string picture_options = settings.get_string ("picture-options");
string picture_options = gnome_background_settings.get_string ("picture-options");
if (picture_options == "none") {
combo.set_sensitive (false);
picture_options = "zoom";
Expand All @@ -203,7 +222,7 @@ public class PantheonShell.Wallpaper : Gtk.Grid {
prevent_update_mode = true;
combo.set_active_id (picture_options);

current_wallpaper_path = settings.get_string ("picture-uri");
current_wallpaper_path = gnome_background_settings.get_string ("picture-uri");
}

/*
Expand Down Expand Up @@ -234,7 +253,7 @@ public class PantheonShell.Wallpaper : Gtk.Grid {
path = greeter_file.get_path ();
}

settings.set_string ("picture-uri", uri);
gnome_background_settings.set_string ("picture-uri", uri);
accountsservice.background_file = path;
}

Expand All @@ -247,16 +266,16 @@ public class PantheonShell.Wallpaper : Gtk.Grid {

if (active_wallpaper == solid_color) {
combo.set_sensitive (true);
settings.set_string ("picture-options", combo.get_active_id ());
gnome_background_settings.set_string ("picture-options", combo.get_active_id ());
}

} else {
set_combo_disabled_if_necessary ();
settings.set_string ("primary-color", solid_color.color);
gnome_background_settings.set_string ("primary-color", solid_color.color);
}

// We don't do gradient backgrounds, reset the key that might interfere
settings.reset ("color-shading-type");
gnome_background_settings.reset ("color-shading-type");

children.checked = true;

Expand All @@ -280,13 +299,13 @@ public class PantheonShell.Wallpaper : Gtk.Grid {

active_wallpaper = solid_color;
active_wallpaper.checked = true;
settings.set_string ("primary-color", solid_color.color);
gnome_background_settings.set_string ("primary-color", solid_color.color);
}
}

private void update_mode () {
if (!prevent_update_mode) {
settings.set_string ("picture-options", combo.get_active_id ());
gnome_background_settings.set_string ("picture-options", combo.get_active_id ());

// Changing the mode, while a solid color is selected, change focus to the
// wallpaper tile.
Expand All @@ -311,7 +330,7 @@ public class PantheonShell.Wallpaper : Gtk.Grid {
private void set_combo_disabled_if_necessary () {
if (active_wallpaper != solid_color) {
combo.set_sensitive (false);
settings.set_string ("picture-options", "none");
gnome_background_settings.set_string ("picture-options", "none");
}
}

Expand Down Expand Up @@ -375,7 +394,7 @@ public class PantheonShell.Wallpaper : Gtk.Grid {
wallpaper_view.add (solid_color);
finished = true;

if (settings.get_string ("picture-options") == "none") {
if (gnome_background_settings.get_string ("picture-options") == "none") {
wallpaper_view.select_child (solid_color);
solid_color.checked = true;
active_wallpaper = solid_color;
Expand Down Expand Up @@ -556,7 +575,7 @@ public class PantheonShell.Wallpaper : Gtk.Grid {
});

// Select the wallpaper if it is the current wallpaper
if (current_wallpaper_path.has_suffix (uri) && settings.get_string ("picture-options") != "none") {
if (current_wallpaper_path.has_suffix (uri) && gnome_background_settings.get_string ("picture-options") != "none") {
this.wallpaper_view.select_child (wallpaper);
// Set the widget activated without activating it
wallpaper.checked = true;
Expand Down