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 22 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
Binary file added data/auto.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions data/icons.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<file alias="64x64/apps/application-default-icon-symbolic.svg" compressed="true" preprocess="xml-stripblanks">application-default-icon/64-symbolic.svg</file>
<file alias="appearance-default.svg" compressed="true" preprocess="xml-stripblanks">appearance-default.svg</file>
<file alias="appearance-dark.svg" compressed="true" preprocess="xml-stripblanks">appearance-dark.svg</file>
<file alias="auto.png" compressed="true">auto.png</file>
<file alias="plug.css" compressed="true">plug.css</file>
</gresource>
</gresources>
9 changes: 8 additions & 1 deletion data/plug.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 elementary LLC. (https://elementary.io)
* Copyright 2018–2021 elementary, Inc. (https://elementary.io)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
Expand Down Expand Up @@ -80,3 +80,10 @@ radiobutton .card {
alpha (@accent_color_500, 0.1)
);
}

.color-button.auto radio {
background-image: url("auto.png");
background-position: -1px -1px;
background-repeat: no-repeat;
background-size: calc(100% + 2px);
}
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
74 changes: 46 additions & 28 deletions src/Views/Appearance.vala
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,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 +313,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 ("blueberry", pantheon_act, Granite.Settings.AccentColor.BLUE);
blueberry_button.tooltip_text = _("Blueberry");

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

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

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

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

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

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

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

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

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

var auto_button = new PrefersAccentColorButton ("auto", pantheon_act, Granite.Settings.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 +358,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,21 +388,29 @@ public class PantheonShell.Appearance : Gtk.Grid {
});
}

private class ColorButton : Gtk.RadioButton {
public string color_name { get; construct; }
private class PrefersAccentColorButton : Gtk.RadioButton {
public string theme { get; construct; }
public Granite.Settings.AccentColor preference { get; construct; }

private Pantheon.AccountsService? pantheon_act = null;
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved

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

public ColorButton (string _color_name, Gtk.RadioButton? group_member = null) {
public PrefersAccentColorButton (string _theme, Pantheon.AccountsService? _pantheon_act, Granite.Settings.AccentColor _preference, Gtk.RadioButton? group_member = null) {
Object (
color_name: _color_name,
theme: _theme,
preference: _preference,
group: group_member
);

pantheon_act = _pantheon_act;
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
}

static construct {
interface_settings = new GLib.Settings (INTERFACE_SCHEMA);
granite_settings = Granite.Settings.get_default ();

var current_stylesheet = interface_settings.get_string (STYLESHEET_KEY);
current_accent = current_stylesheet.replace (STYLESHEET_PREFIX, "");
Expand All @@ -405,16 +419,20 @@ public class PantheonShell.Appearance : Gtk.Grid {
construct {
unowned Gtk.StyleContext context = get_style_context ();
context.add_class ("color-button");
context.add_class (color_name);
context.add_class (theme);

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

toggled.connect (() => {
interface_settings.set_string (
STYLESHEET_KEY,
STYLESHEET_PREFIX + color_name
);
if (preference != Granite.Settings.AccentColor.NO_PREFERENCE) {
interface_settings.set_string (
STYLESHEET_KEY,
STYLESHEET_PREFIX + theme
);
}

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