[polari] chatView: Stop piggy-backing on LINK state
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] chatView: Stop piggy-backing on LINK state
- Date: Fri, 3 Sep 2021 09:45:12 +0000 (UTC)
commit e447349538cfcbcbfe1f438cf6756dee7fc9fb72
Author: Florian Müllner <fmuellner gnome org>
Date: Sat Oct 10 04:24:24 2020 +0200
chatView: Stop piggy-backing on LINK state
The GTK4 default theme is a lot more selective on where it applies
a dedicated link style. Prepare for that by defining custom colors
in the application stylesheet instead, and use those consistently
for any elements that represent a nick or link.
Part-of: <https://gitlab.gnome.org/GNOME/polari/-/merge_requests/225>
data/resources/application.css | 12 ++++++++
src/chatView.js | 68 ++++++++++++------------------------------
src/entryArea.js | 17 ++++-------
src/userList.js | 11 +++++--
4 files changed, 44 insertions(+), 64 deletions(-)
---
diff --git a/data/resources/application.css b/data/resources/application.css
index c1f39bbc..8f43bdeb 100644
--- a/data/resources/application.css
+++ b/data/resources/application.css
@@ -1,7 +1,19 @@
@define-color polari_dark_bg_color shade(@theme_bg_color, 0.95);
+@define-color active_nick_color @theme_selected_bg_color;
+@define-color active_nick_hover_color lighter(@active_nick_color);
+
+@define-color inactive_nick_color alpha(@theme_text_color, 0.55);
+@define-color inactive_nick_hover_color lighter(@inactive_nick_color);
+
.info { margin-bottom: 1px; }
+.polari-active-nick { color: @active_nick_color; }
+.polari-active-nick:hover { color: @active_nick_hover_color; }
+
+.polari-inactive-nick { color: @inactive_nick_color; }
+.polari-inactive-nick:hover { color: @inactive_nick_hover_color; }
+
.polari-user-list row.expanded {
background-color: @content_view_bg;
}
diff --git a/src/chatView.js b/src/chatView.js
index 17d6d9fa..bab50fcb 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -44,12 +44,6 @@ const NICK_SPACING = 14;
const NICKTAG_PREFIX = 'nick';
-function _getColor(context) {
- let color = context.get_color(context.get_state());
- color.alpha *= context.get_property('opacity', context.get_state());
- return color;
-}
-
// Workaround for GtkTextView growing horizontally over time when
// added to a GtkScrolledWindow with horizontal scrolling disabled
const TextView = GObject.registerClass(
@@ -66,12 +60,8 @@ class TextView extends Gtk.TextView {
}
vfunc_style_updated() {
- let context = this.get_style_context();
- context.save();
- context.add_class('dim-label');
- context.set_state(Gtk.StateFlags.NORMAL);
- this._dimColor = _getColor(context);
- context.restore();
+ const context = this.get_style_context();
+ [, this._dimColor] = context.lookup_color('inactive_nick_color');
super.vfunc_style_updated();
}
@@ -469,52 +459,32 @@ export default GObject.registerClass({
}
_onStyleUpdated() {
- let context = this.get_style_context();
- context.save();
- context.add_class('dim-label');
- context.set_state(Gtk.StateFlags.NORMAL);
- let dimColor = _getColor(context);
- context.restore();
-
- context.save();
- context.set_state(Gtk.StateFlags.LINK);
- let linkColor = _getColor(context);
- this._activeNickColor = _getColor(context);
-
- context.set_state(Gtk.StateFlags.LINK | Gtk.StateFlags.PRELIGHT);
- this._hoveredLinkColor = _getColor(context);
- context.restore();
-
- let desaturatedNickColor = (
- this._activeNickColor.red +
- this._activeNickColor.blue +
- this._activeNickColor.green) / 3;
- this._inactiveNickColor = new Gdk.RGBA({
- red: desaturatedNickColor,
- green: desaturatedNickColor,
- blue: desaturatedNickColor,
- alpha: 1.0,
- });
- if (this._activeNickColor.equal(this._inactiveNickColor))
- this._inactiveNickColor.alpha = 0.5;
-
- context.save();
- context.add_class('view');
- context.set_state(Gtk.StateFlags.NORMAL);
- this._statusHeaderHoverColor = _getColor(context);
- context.restore();
+ const context = this.get_style_context();
+ const [, activeColor] =
+ context.lookup_color('active_nick_color');
+ const [, activeHoverColor] =
+ context.lookup_color('active_nick_hover_color');
+ const [, inactiveColor] =
+ context.lookup_color('inactive_nick_color');
+ const [, inactiveHoverColor] =
+ context.lookup_color('inactive_nick_hover_color');
+
+ this._activeNickColor = activeColor;
+ this._inactiveNickColor = inactiveColor;
+ this._hoveredLinkColor = activeHoverColor;
+ this._statusHeaderHoverColor = inactiveHoverColor;
let buffer = this._view.get_buffer();
let tagTable = buffer.get_tag_table();
let tags = [{
name: 'status',
- foreground_rgba: dimColor,
+ foreground_rgba: inactiveColor,
}, {
name: 'timestamp',
- foreground_rgba: dimColor,
+ foreground_rgba: inactiveColor,
}, {
name: 'url',
- foreground_rgba: linkColor,
+ foreground_rgba: activeColor,
}];
tags.forEach(tagProps => {
let tag = tagTable.lookup(tagProps.name);
diff --git a/src/entryArea.js b/src/entryArea.js
index 45948b8d..5c126628 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -222,20 +222,8 @@ export default GObject.registerClass({
this._nickChangedId = 0;
});
- this._nickLabel.set_state_flags(Gtk.StateFlags.LINK, false);
this._nickLabel.width_chars = this._maxNickChars;
- /* HACK: We don't want the button to look different when the toplevel
- is unfocused, so filter out the BACKDROP state */
- this._nickButton.connect('state-flags-changed', w => {
- let state = w.get_state_flags();
- if (!(state & Gtk.StateFlags.BACKDROP))
- return; // avoid indefinite recursion
-
- state &= ~Gtk.StateFlags.BACKDROP;
- w.set_state_flags(state, true);
- });
-
this._chatEntry.connect('text-pasted', (entry, text, nLines) => {
this.pasteText(text, nLines);
});
@@ -448,6 +436,11 @@ export default GObject.registerClass({
_onSensitiveChanged() {
if (this._canFocusChatEntry())
this._chatEntry.grab_focus();
+
+ if (this.sensitive)
+ this._nickLabel.get_style_context().add_class('polari-active-nick');
+ else
+ this._nickLabel.get_style_context().remove_class('polari-active-nick');
}
_onChannelChanged(room) {
diff --git a/src/userList.js b/src/userList.js
index cdb79651..7c867104 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -335,8 +335,6 @@ export const UserPopover = GObject.registerClass({
super._init(params);
- this._nickLabel.set_state_flags(Gtk.StateFlags.LINK, false);
-
this._app = Gio.Application.get_default();
this._roomStatusChangedId = 0;
@@ -415,7 +413,14 @@ export const UserPopover = GObject.registerClass({
label = _('Offline');
this._statusLabel.label = label;
- this._nickLabel.sensitive = status === Tp.ConnectionPresenceType.AVAILABLE;
+ const context = this._nickLabel.get_style_context();
+ if (status === Tp.ConnectionPresenceType.AVAILABLE) {
+ context.remove_class('polari-inactive-nick');
+ context.add_class('polari-active-nick');
+ } else {
+ context.remove_class('polari-active-nick');
+ context.add_class('polari-inactive-nick');
+ }
}
_updateDetailsContact() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]