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

Set accent color based on wallpaper #263

Merged
merged 29 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d4e814b
Add no preference button
meisenzahl Apr 8, 2021
66f277e
Fix no preference button
meisenzahl Apr 8, 2021
62e9d50
Add property PrefersAcccentColor
meisenzahl Apr 8, 2021
c8c2825
Set accent color preference to AccountsService
meisenzahl Apr 8, 2021
00dc5a0
Update type
meisenzahl Apr 8, 2021
ef70adf
Merge branch 'master' into set-accent-color-based-on-wallpaper
meisenzahl Apr 9, 2021
4cc47ac
Use Granite.Settings
meisenzahl Apr 10, 2021
f5a0dbb
Merge branch 'set-accent-color-based-on-wallpaper' of github.com:elem…
meisenzahl Apr 10, 2021
96ad623
Merge branch 'master' into set-accent-color-based-on-wallpaper
meisenzahl Apr 11, 2021
768c684
Fix on change detection
meisenzahl Apr 11, 2021
b7905eb
Fix accent colors
meisenzahl Apr 11, 2021
37d10c1
Merge branch 'master' into set-accent-color-based-on-wallpaper
cassidyjames Apr 12, 2021
4f10839
Merge branch 'master' into set-accent-color-based-on-wallpaper
meisenzahl Apr 13, 2021
845924d
Merge branch 'master' into set-accent-color-based-on-wallpaper
meisenzahl Apr 13, 2021
1b298e9
Merge branch 'master' into set-accent-color-based-on-wallpaper
meisenzahl Apr 19, 2021
4cd04b9
Merge branch 'master' into set-accent-color-based-on-wallpaper
cassidyjames Apr 22, 2021
4306112
Refactor wording to auto
meisenzahl Apr 24, 2021
9666372
Merge branch 'set-accent-color-based-on-wallpaper' of github.com:elem…
meisenzahl Apr 24, 2021
97bc845
Merge branch 'master' into set-accent-color-based-on-wallpaper
meisenzahl Apr 24, 2021
2ff92db
Merge branch 'master' into set-accent-color-based-on-wallpaper
meisenzahl Apr 26, 2021
9cc8672
Merge branch 'master' into set-accent-color-based-on-wallpaper
meisenzahl Apr 29, 2021
c94f475
Give auto button a background (#270)
cassidyjames Apr 29, 2021
e521333
Revert "Give auto button a background (#270)"
meisenzahl Apr 30, 2021
bd0b6ef
Merge branch 'master' into set-accent-color-based-on-wallpaper
meisenzahl May 2, 2021
a0c09cd
Set active state
meisenzahl May 2, 2021
f89fcaf
Merge branch 'master' into set-accent-color-based-on-wallpaper
danirabbit May 3, 2021
7818688
Do not use Granite.Settings
meisenzahl May 4, 2021
8971dfb
Merge branch 'master' into set-accent-color-based-on-wallpaper
cassidyjames May 4, 2021
1e2b86e
Reduce number of arguments passed to color button with enum.to_string
meisenzahl May 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/PantheonAccountsServicePlugin.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[DBus (name = "io.elementary.pantheon.AccountsService")]
private interface PantheonShell.Pantheon.AccountsService : Object {
public abstract int prefers_accent_color { get; set; }
public abstract int prefers_color_scheme { get; set; }
}

Expand Down
113 changes: 83 additions & 30 deletions src/Views/Appearance.vala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,47 @@ public class PantheonShell.Appearance : Gtk.Grid {

private Granite.Widgets.ModeButton text_size_modebutton;

private enum AccentColor {
NO_PREFERENCE,
RED,
ORANGE,
YELLOW,
GREEN,
MINT,
BLUE,
PURPLE,
PINK,
BROWN,
GRAY;

public string to_string () {
switch (this) {
case RED:
return "strawberry";
case ORANGE:
return "orange";
case YELLOW:
return "banana";
case GREEN:
return "lime";
case MINT:
return "mint";
case BLUE:
return "blueberry";
case PURPLE:
return "grape";
case PINK:
return "bubblegum";
case BROWN:
return "cocoa";
case GRAY:
return "slate";
}

return "auto";
}
}

construct {
column_spacing = 12;
halign = Gtk.Align.CENTER;
Expand Down Expand Up @@ -248,13 +289,15 @@ public class PantheonShell.Appearance : Gtk.Grid {

((GLib.DBusProxy) pantheon_act).g_properties_changed.connect ((changed, invalid) => {
var color_scheme = changed.lookup_value ("PrefersColorScheme", new VariantType ("i"));
switch ((Granite.Settings.ColorScheme) color_scheme.get_int32 ()) {
case Granite.Settings.ColorScheme.DARK:
prefer_dark_radio.active = true;
break;
default:
prefer_default_radio.active = true;
break;
if (color_scheme != null) {
switch ((Granite.Settings.ColorScheme) color_scheme.get_int32 ()) {
case Granite.Settings.ColorScheme.DARK:
prefer_dark_radio.active = true;
break;
default:
prefer_default_radio.active = true;
break;
}
}
});

Expand Down Expand Up @@ -311,36 +354,39 @@ public class PantheonShell.Appearance : Gtk.Grid {
var accent_label = new Gtk.Label (_("Accent:"));
accent_label.halign = Gtk.Align.END;

var blueberry_button = new ColorButton ("blueberry");
var blueberry_button = new PrefersAccentColorButton (pantheon_act, AccentColor.BLUE);
blueberry_button.tooltip_text = _("Blueberry");

var mint_button = new ColorButton ("mint", blueberry_button);
var mint_button = new PrefersAccentColorButton (pantheon_act, AccentColor.MINT, blueberry_button);
mint_button.tooltip_text = _("Mint");

var lime_button = new ColorButton ("lime", blueberry_button);
var lime_button = new PrefersAccentColorButton (pantheon_act, AccentColor.GREEN, blueberry_button);
lime_button.tooltip_text = _("Lime");

var banana_button = new ColorButton ("banana", blueberry_button);
var banana_button = new PrefersAccentColorButton (pantheon_act, AccentColor.YELLOW, blueberry_button);
banana_button.tooltip_text = _("Banana");

var orange_button = new ColorButton ("orange", blueberry_button);
var orange_button = new PrefersAccentColorButton (pantheon_act, AccentColor.ORANGE, blueberry_button);
orange_button.tooltip_text = _("Orange");

var strawberry_button = new ColorButton ("strawberry", blueberry_button);
var strawberry_button = new PrefersAccentColorButton (pantheon_act, AccentColor.RED, blueberry_button);
strawberry_button.tooltip_text = _("Strawberry");

var bubblegum_button = new ColorButton ("bubblegum", blueberry_button);
var bubblegum_button = new PrefersAccentColorButton (pantheon_act, AccentColor.PINK, blueberry_button);
bubblegum_button.tooltip_text = _("Bubblegum");

var grape_button = new ColorButton ("grape", blueberry_button);
var grape_button = new PrefersAccentColorButton (pantheon_act, AccentColor.PURPLE, blueberry_button);
grape_button.tooltip_text = _("Grape");

var cocoa_button = new ColorButton ("cocoa", blueberry_button);
var cocoa_button = new PrefersAccentColorButton (pantheon_act, AccentColor.BROWN, blueberry_button);
cocoa_button.tooltip_text = _("Cocoa");

var slate_button = new ColorButton ("slate", blueberry_button);
var slate_button = new PrefersAccentColorButton (pantheon_act, AccentColor.GRAY, blueberry_button);
slate_button.tooltip_text = _("Slate");

var auto_button = new PrefersAccentColorButton (pantheon_act, AccentColor.NO_PREFERENCE, blueberry_button);
auto_button.tooltip_text = _("Automatic based on wallpaper");

var accent_grid = new Gtk.Grid ();
accent_grid.column_spacing = 6;
accent_grid.add (blueberry_button);
Expand All @@ -353,6 +399,7 @@ public class PantheonShell.Appearance : Gtk.Grid {
accent_grid.add (grape_button);
accent_grid.add (cocoa_button);
accent_grid.add (slate_button);
accent_grid.add (auto_button);

var accent_info = new Gtk.Label (_("Used across the system by default. Apps can always use their own accent color.")) {
margin_bottom = 18,
Expand Down Expand Up @@ -382,15 +429,16 @@ public class PantheonShell.Appearance : Gtk.Grid {
});
}

private class ColorButton : Gtk.RadioButton {
public string color_name { get; construct; }
private class PrefersAccentColorButton : Gtk.RadioButton {
public AccentColor color { get; construct; }
public Pantheon.AccountsService? pantheon_act { get; construct; default = null; }

private static GLib.Settings interface_settings;
private static string current_accent;

public ColorButton (string _color_name, Gtk.RadioButton? group_member = null) {
public PrefersAccentColorButton (Pantheon.AccountsService? pantheon_act, AccentColor color, Gtk.RadioButton? group_member = null) {
Object (
color_name: _color_name,
pantheon_act: pantheon_act,
color: color,
group: group_member
);
}
Expand All @@ -399,22 +447,27 @@ public class PantheonShell.Appearance : Gtk.Grid {
interface_settings = new GLib.Settings (INTERFACE_SCHEMA);

var current_stylesheet = interface_settings.get_string (STYLESHEET_KEY);
current_accent = current_stylesheet.replace (STYLESHEET_PREFIX, "");
}

construct {
unowned Gtk.StyleContext context = get_style_context ();
context.add_class ("color-button");
context.add_class (color_name);
context.add_class (Granite.STYLE_CLASS_COLOR_BUTTON);
context.add_class (color.to_string ());

realize.connect (() => {
active = current_accent == color_name;
active = color == pantheon_act.prefers_accent_color;

toggled.connect (() => {
interface_settings.set_string (
STYLESHEET_KEY,
STYLESHEET_PREFIX + color_name
);
if (color != AccentColor.NO_PREFERENCE) {
interface_settings.set_string (
STYLESHEET_KEY,
STYLESHEET_PREFIX + color.to_string ()
);
}

if (((GLib.DBusProxy) pantheon_act).get_cached_property ("PrefersAccentColor") != null) {
pantheon_act.prefers_accent_color = color;
}
});
});
}
Expand Down