-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
Init: set accent color from portal #704
base: main
Are you sure you want to change the base?
Changes from all commits
95c75c8
ba364a8
cb4ec6e
4e728fd
b26c9cd
a8fe480
c1576ac
8ee30d8
feaad3f
c447791
8d0a33f
a42d5cc
3be33e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// These are defined as GtkCSS variables, so are accessible and overridable | ||
// inside of apps. While internal sass variables are considered private API, | ||
// these exported GtkCSS variables should be considered public API. | ||
|
||
@define-color base_color #{"" + bg_color(1)}; | ||
@define-color bg_color #{"" + bg_color(2)}; | ||
@define-color fg_color #{"" + $fg-color}; | ||
@define-color highlight_color #{"" + $highlight_color}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
.accent { | ||
color: #{'mix(@accent_color, @fg_color, 0.27)'}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this will produce very good results for e.g. yellow. In libadwaita I had much better results with oklch colorspace (tho that would require you to update gtk once 4.16 is out) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, that or calculate it programmatically ofc, then you don't need to wait. |
||
|
||
&:backdrop { | ||
color: inherit; | ||
} | ||
} | ||
|
||
.title-1 { | ||
font-size: 24pt; | ||
font-weight: 700; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,25 @@ namespace Granite { | |
LIGHT | ||
} | ||
|
||
private Gdk.RGBA? _accent_color = null; | ||
|
||
/** | ||
* The theme accent color chosen by the user | ||
* @since 7.6.0 | ||
*/ | ||
[Version (since = "7.6.0")] | ||
public Gdk.RGBA accent_color { | ||
get { | ||
if (_accent_color == null) { | ||
setup_accent_color (); | ||
} | ||
return (_accent_color); | ||
} | ||
private set { | ||
_accent_color = value; | ||
} | ||
} | ||
|
||
private ColorScheme? _prefers_color_scheme = null; | ||
|
||
/** | ||
|
@@ -96,6 +115,39 @@ namespace Granite { | |
} | ||
} | ||
|
||
private void setup_accent_color () { | ||
try { | ||
portal = Portal.Settings.get (); | ||
|
||
var variant = portal.read ( | ||
"org.freedesktop.appearance", | ||
"accent-color" | ||
).get_variant (); | ||
|
||
accent_color = parse_color (variant); | ||
|
||
portal.setting_changed.connect ((scheme, key, value) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alice-mkh maybe it's because I'm on an older version of some library but I'm not getting anything at all here when I change the color in system settings so I can't really test further because it's broken for me all the way at the beginning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh okay. It did work for me, but only until I open inspector due to the global provider issue I mentioned. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I can't even test that 😅 |
||
if (scheme == "org.freedesktop.appearance" && key == "accent-color") { | ||
accent_color = parse_color (value); | ||
} | ||
}); | ||
} catch (Error e) { | ||
warning (e.message); | ||
|
||
// Set a default in case we can't get from system | ||
accent_color.parse ("#3689e6"); | ||
} | ||
} | ||
|
||
private Gdk.RGBA parse_color (GLib.Variant color) { | ||
double red, green, blue; | ||
color.get ("(ddd)", out red, out green, out blue); | ||
|
||
Gdk.RGBA rgba = {(float) red, (float) green, (float) blue, 1}; | ||
|
||
return rgba; | ||
} | ||
|
||
private void setup_prefers_color_scheme () { | ||
try { | ||
portal = Portal.Settings.get (); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use THEME + 1 instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried THEME + 1 but it didn't work for some reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh. THat is strange.