mirror of
https://github.com/elementary/gala.git
synced 2024-12-25 10:13:04 +03:00
Move AccentColorManager to settings-daemon (#1842)
This commit is contained in:
parent
3a042e273c
commit
6e50184ead
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@ -31,7 +31,7 @@ jobs:
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
apt update
|
||||
apt install -y gettext gnome-settings-daemon-dev gsettings-desktop-schemas-dev libbamf3-dev libcanberra-dev libcanberra-gtk3-dev libclutter-1.0-dev libgee-0.8-dev libglib2.0-dev libgnome-desktop-3-dev libgranite-dev libgtk-3-dev ${{ matrix.mutter_pkg }} libplank-dev libxml2-utils libgexiv2-dev libsqlite3-dev meson valac valadoc
|
||||
apt install -y gettext gnome-settings-daemon-dev gsettings-desktop-schemas-dev libbamf3-dev libcanberra-dev libcanberra-gtk3-dev libclutter-1.0-dev libgee-0.8-dev libglib2.0-dev libgnome-desktop-3-dev libgranite-dev libgtk-3-dev ${{ matrix.mutter_pkg }} libplank-dev libxml2-utils libsqlite3-dev meson valac valadoc
|
||||
- name: Build
|
||||
env:
|
||||
DESTDIR: out
|
||||
|
@ -14,7 +14,6 @@ You'll need the following dependencies:
|
||||
* libcanberra-gtk3-dev
|
||||
* libclutter-1.0-dev (>= 1.12.0)
|
||||
* libgee-0.8-dev
|
||||
* libgexiv2-dev
|
||||
* libglib2.0-dev (>= 2.44)
|
||||
* libgnome-desktop-3-dev
|
||||
* libgranite-dev (>= 5.4.0)
|
||||
|
@ -96,7 +96,6 @@ gnome_desktop_dep = dependency('gnome-desktop-3.0')
|
||||
gsd_dep = dependency('gnome-settings-daemon', version: '>= @0@'.format(gsd_version_required))
|
||||
m_dep = cc.find_library('m', required: false)
|
||||
posix_dep = vala.find_library('posix', required: false)
|
||||
gexiv2_dep = dependency('gexiv2')
|
||||
sqlite3_dep = dependency('sqlite3')
|
||||
if get_option('systemd')
|
||||
systemd_dep = dependency('libsystemd')
|
||||
@ -175,7 +174,7 @@ endif
|
||||
add_project_arguments(vala_flags, language: 'vala')
|
||||
add_project_link_arguments(['-Wl,-rpath,@0@'.format(mutter_typelib_dir)], language: 'c')
|
||||
|
||||
gala_base_dep = [canberra_dep, glib_dep, gobject_dep, gio_dep, gio_unix_dep, gmodule_dep, gee_dep, gtk_dep, mutter_dep, granite_dep, gnome_desktop_dep, m_dep, posix_dep, gexiv2_dep, sqlite3_dep, config_dep]
|
||||
gala_base_dep = [canberra_dep, glib_dep, gobject_dep, gio_dep, gio_unix_dep, gmodule_dep, gee_dep, gtk_dep, mutter_dep, granite_dep, gnome_desktop_dep, m_dep, posix_dep, sqlite3_dep, config_dep]
|
||||
|
||||
if get_option('systemd')
|
||||
gala_base_dep += systemd_dep
|
||||
|
@ -1,173 +0,0 @@
|
||||
/*
|
||||
* Copyright 2021-2023 elementary, Inc. <https://elementary.io>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Authored by: Marius Meisenzahl <mariusmeisenzahl@gmail.com>
|
||||
*/
|
||||
|
||||
public class Gala.AccentColorManager : Object {
|
||||
private const string INTERFACE_SCHEMA = "org.gnome.desktop.interface";
|
||||
private const string STYLESHEET_KEY = "gtk-theme";
|
||||
private const string TAG_ACCENT_COLOR = "Xmp.xmp.io.elementary.AccentColor";
|
||||
|
||||
private const string THEME_BLUE = "io.elementary.stylesheet.blueberry";
|
||||
private const string THEME_MINT = "io.elementary.stylesheet.mint";
|
||||
private const string THEME_GREEN = "io.elementary.stylesheet.lime";
|
||||
private const string THEME_YELLOW = "io.elementary.stylesheet.banana";
|
||||
private const string THEME_ORANGE = "io.elementary.stylesheet.orange";
|
||||
private const string THEME_RED = "io.elementary.stylesheet.strawberry";
|
||||
private const string THEME_PINK = "io.elementary.stylesheet.bubblegum";
|
||||
private const string THEME_PURPLE = "io.elementary.stylesheet.grape";
|
||||
private const string THEME_BROWN = "io.elementary.stylesheet.cocoa";
|
||||
private const string THEME_GRAY = "io.elementary.stylesheet.slate";
|
||||
|
||||
private Gala.AccountsService? gala_accounts_service = null;
|
||||
|
||||
private Settings background_settings;
|
||||
private Settings interface_settings;
|
||||
|
||||
private NamedColor[] theme_colors = {
|
||||
new NamedColor ("Blue", THEME_BLUE, new Drawing.Color.from_int (0x3689e6)),
|
||||
new NamedColor ("Mint", THEME_MINT, new Drawing.Color.from_int (0x28bca3)),
|
||||
new NamedColor ("Green", THEME_GREEN, new Drawing.Color.from_int (0x68b723)),
|
||||
new NamedColor ("Yellow", THEME_YELLOW, new Drawing.Color.from_int (0xf9c440)),
|
||||
new NamedColor ("Orange", THEME_ORANGE, new Drawing.Color.from_int (0xffa154)),
|
||||
new NamedColor ("Red", THEME_RED, new Drawing.Color.from_int (0xed5353)),
|
||||
new NamedColor ("Pink", THEME_PINK, new Drawing.Color.from_int (0xde3e80)),
|
||||
new NamedColor ("Purple", THEME_PURPLE, new Drawing.Color.from_int (0xa56de2)),
|
||||
new NamedColor ("Brown", THEME_BROWN, new Drawing.Color.from_int (0x8a715e)),
|
||||
new NamedColor ("Gray", THEME_GRAY, new Drawing.Color.from_int (0x667885))
|
||||
};
|
||||
|
||||
construct {
|
||||
background_settings = new Settings ("org.gnome.desktop.background");
|
||||
interface_settings = new Settings (INTERFACE_SCHEMA);
|
||||
|
||||
string? user_path = null;
|
||||
try {
|
||||
FDO.Accounts? accounts_service = GLib.Bus.get_proxy_sync (
|
||||
GLib.BusType.SYSTEM,
|
||||
"org.freedesktop.Accounts",
|
||||
"/org/freedesktop/Accounts"
|
||||
);
|
||||
|
||||
user_path = accounts_service.find_user_by_name (GLib.Environment.get_user_name ());
|
||||
} catch (Error e) {
|
||||
critical (e.message);
|
||||
}
|
||||
|
||||
if (user_path != null) {
|
||||
try {
|
||||
gala_accounts_service = GLib.Bus.get_proxy_sync (
|
||||
GLib.BusType.SYSTEM,
|
||||
"org.freedesktop.Accounts",
|
||||
user_path
|
||||
);
|
||||
|
||||
((DBusProxy)gala_accounts_service).g_properties_changed.connect (() => {
|
||||
update_accent_color ();
|
||||
});
|
||||
} catch (Error e) {
|
||||
warning ("Unable to get AccountsService proxy, accent color preference may be incorrect");
|
||||
}
|
||||
}
|
||||
|
||||
background_settings.changed["picture-options"].connect (update_accent_color);
|
||||
background_settings.changed["picture-uri"].connect (update_accent_color);
|
||||
background_settings.changed["primary-color"].connect (update_accent_color);
|
||||
|
||||
update_accent_color ();
|
||||
}
|
||||
|
||||
private void update_accent_color () {
|
||||
bool set_accent_color_auto = gala_accounts_service.prefers_accent_color == 0;
|
||||
|
||||
if (!set_accent_color_auto) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool set_accent_color_based_on_primary_color = background_settings.get_enum ("picture-options") == 0;
|
||||
|
||||
var current_stylesheet = interface_settings.get_string (STYLESHEET_KEY);
|
||||
|
||||
debug ("Current stylesheet: %s", current_stylesheet);
|
||||
|
||||
NamedColor? new_color = null;
|
||||
if (set_accent_color_based_on_primary_color) {
|
||||
var primary_color = background_settings.get_string ("primary-color");
|
||||
debug ("Current primary color: %s", primary_color);
|
||||
|
||||
new_color = get_accent_color_based_on_primary_color (primary_color);
|
||||
} else {
|
||||
var picture_uri = background_settings.get_string ("picture-uri");
|
||||
debug ("Current wallpaper: %s", picture_uri);
|
||||
|
||||
var accent_color_name = read_accent_color_name_from_exif (picture_uri);
|
||||
if (accent_color_name != null) {
|
||||
for (int i = 0; i < theme_colors.length; i++) {
|
||||
if (theme_colors[i].name == accent_color_name) {
|
||||
new_color = theme_colors[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
new_color = get_accent_color_of_picture_simple (picture_uri);
|
||||
}
|
||||
}
|
||||
|
||||
if (new_color != null && new_color.theme != current_stylesheet) {
|
||||
debug ("New stylesheet: %s", new_color.theme);
|
||||
|
||||
interface_settings.set_string (
|
||||
STYLESHEET_KEY,
|
||||
new_color.theme
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private string? read_accent_color_name_from_exif (string picture_uri) {
|
||||
string path = "";
|
||||
GExiv2.Metadata metadata;
|
||||
try {
|
||||
path = Filename.from_uri (picture_uri);
|
||||
metadata = new GExiv2.Metadata ();
|
||||
metadata.open_path (path);
|
||||
|
||||
return metadata.try_get_tag_string (TAG_ACCENT_COLOR);
|
||||
} catch (Error e) {
|
||||
warning ("Error parsing exif metadata of \"%s\": %s", path, e.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private NamedColor? get_accent_color (ColorExtractor color_extractor) {
|
||||
var palette = new Gee.ArrayList<Drawing.Color> ();
|
||||
for (int i = 0; i < theme_colors.length; i++) {
|
||||
palette.add (theme_colors[i].color);
|
||||
}
|
||||
|
||||
var index = color_extractor.get_dominant_color_index (palette);
|
||||
return theme_colors[index];
|
||||
}
|
||||
|
||||
private NamedColor? get_accent_color_of_picture_simple (string picture_uri) {
|
||||
var file = File.new_for_uri (picture_uri);
|
||||
|
||||
try {
|
||||
var pixbuf = new Gdk.Pixbuf.from_file (file.get_path ());
|
||||
var color_extractor = new ColorExtractor.from_pixbuf (pixbuf);
|
||||
|
||||
return get_accent_color (color_extractor);
|
||||
} catch (Error e) {
|
||||
warning (e.message);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private NamedColor? get_accent_color_based_on_primary_color (string primary_color) {
|
||||
var granite_primary_color = new Drawing.Color.from_string (primary_color);
|
||||
var color_extractor = new ColorExtractor.from_primary_color (granite_primary_color);
|
||||
|
||||
return get_accent_color (color_extractor);
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright 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
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
* Authored by: Marius Meisenzahl <mariusmeisenzahl@gmail.com>
|
||||
*/
|
||||
|
||||
public class Gala.ColorExtractor : Object {
|
||||
private const double PERCENTAGE_SAMPLE_PIXELS = 0.01;
|
||||
|
||||
public Gdk.Pixbuf? pixbuf { get; construct set; }
|
||||
public Drawing.Color? primary_color { get; construct set; }
|
||||
|
||||
private Gee.List<Drawing.Color> pixels;
|
||||
|
||||
public ColorExtractor.from_pixbuf (Gdk.Pixbuf pixbuf) {
|
||||
Object (pixbuf: pixbuf);
|
||||
|
||||
pixels = convert_pixels_to_rgb (pixbuf.get_pixels_with_length (), pixbuf.has_alpha);
|
||||
}
|
||||
|
||||
public ColorExtractor.from_primary_color (Drawing.Color primary_color) {
|
||||
Object (primary_color: primary_color);
|
||||
|
||||
pixels = new Gee.ArrayList<Drawing.Color> ();
|
||||
pixels.add (primary_color);
|
||||
}
|
||||
|
||||
public int get_dominant_color_index (Gee.List<Drawing.Color> palette) {
|
||||
int index = 0;
|
||||
var matches = new double[palette.size];
|
||||
|
||||
pixels.foreach ((pixel) => {
|
||||
for (int i = 0; i < palette.size; i++) {
|
||||
var color = palette.get (i);
|
||||
|
||||
var distance = Math.sqrt (
|
||||
Math.pow ((pixel.R - color.R), 2) +
|
||||
Math.pow ((pixel.G - color.G), 2) +
|
||||
Math.pow ((pixel.B - color.B), 2)
|
||||
);
|
||||
|
||||
if (distance > 0.25) {
|
||||
continue;
|
||||
}
|
||||
|
||||
matches[i] += 1.0 - distance;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
double best_match = double.MIN;
|
||||
for (int i = 0; i < matches.length; i++) {
|
||||
if (matches[i] > best_match) {
|
||||
best_match = matches[i];
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
private Gee.ArrayList<Drawing.Color> convert_pixels_to_rgb (uint8[] pixels, bool has_alpha) {
|
||||
var list = new Gee.ArrayList<Drawing.Color> ();
|
||||
|
||||
int factor = 3 + (int) has_alpha;
|
||||
int step_size = (int) (pixels.length / factor * PERCENTAGE_SAMPLE_PIXELS);
|
||||
|
||||
for (int i = 0; i < pixels.length / factor; i += step_size) {
|
||||
int offset = i * factor;
|
||||
double red = pixels[offset] / 255.0;
|
||||
double green = pixels[offset + 1] / 255.0;
|
||||
double blue = pixels[offset + 2] / 255.0;
|
||||
|
||||
list.add (new Drawing.Color (red, green, blue, 0.0));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright 2021-2023 elementary, Inc. <https://elementary.io>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Authored by: Marius Meisenzahl <mariusmeisenzahl@gmail.com>
|
||||
*/
|
||||
|
||||
public class Gala.NamedColor : Object {
|
||||
public string name { get; construct set; }
|
||||
public string theme { get; construct set; }
|
||||
public Drawing.Color color { get; construct set; }
|
||||
|
||||
public NamedColor (string name, string theme, Drawing.Color color) {
|
||||
Object (
|
||||
name: name,
|
||||
theme: theme,
|
||||
color: color
|
||||
);
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
[DBus (name = "io.elementary.pantheon.AccountsService")]
|
||||
interface Gala.AccountsService : Object {
|
||||
public abstract int prefers_accent_color { get; }
|
||||
}
|
||||
|
||||
[DBus (name = "org.freedesktop.Accounts")]
|
||||
interface Gala.FDO.Accounts : Object {
|
||||
public abstract string find_user_by_name (string username) throws GLib.Error;
|
||||
}
|
@ -86,8 +86,6 @@ namespace Gala {
|
||||
*/
|
||||
private Zoom? zoom = null;
|
||||
|
||||
private AccentColorManager accent_color_manager;
|
||||
|
||||
private Clutter.Actor? tile_preview;
|
||||
|
||||
private Meta.Window? moving; //place for the window that is being moved over
|
||||
@ -314,8 +312,6 @@ namespace Gala {
|
||||
Gtk.init (ref _args);
|
||||
}
|
||||
|
||||
accent_color_manager = new AccentColorManager ();
|
||||
|
||||
// initialize plugins and add default components if no plugin overrides them
|
||||
unowned var plugin_manager = PluginManager.get_default ();
|
||||
plugin_manager.initialize (this);
|
||||
|
@ -3,7 +3,6 @@ gala_bin_sources = files(
|
||||
'DBusAccelerator.vala',
|
||||
'DesktopIntegration.vala',
|
||||
'Dialogs.vala',
|
||||
'GalaAccountsServicePlugin.vala',
|
||||
'InternalUtils.vala',
|
||||
'KeyboardManager.vala',
|
||||
'Main.vala',
|
||||
@ -19,9 +18,6 @@ gala_bin_sources = files(
|
||||
'WindowTracker.vala',
|
||||
'WorkspaceManager.vala',
|
||||
'Zoom.vala',
|
||||
'AccentColor/AccentColorManager.vala',
|
||||
'AccentColor/ColorExtractor.vala',
|
||||
'AccentColor/NamedColor.vala',
|
||||
'Background/Animation.vala',
|
||||
'Background/Background.vala',
|
||||
'Background/BackgroundCache.vala',
|
||||
|
Loading…
Reference in New Issue
Block a user