[fractal/fractal-next] Support dark mode
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] Support dark mode
- Date: Tue, 14 Dec 2021 12:08:30 +0000 (UTC)
commit 872601b13a108aeb26369f0119095d36d9edbe27
Author: Maximiliano Sandoval R <msandova gnome org>
Date: Mon Oct 4 22:10:45 2021 +0200
Support dark mode
data/resources/resources.gresource.xml | 1 +
data/resources/style-dark.css | 12 +++++++++++
data/resources/style.css | 7 +++----
data/resources/ui/login.ui | 8 ++++----
src/application.rs | 1 +
.../content/room_history/message_row/text.rs | 1 +
src/session/content/room_history/mod.rs | 1 +
src/session/event_source_dialog.rs | 1 +
src/utils.rs | 23 ++++++++++++++++++++++
9 files changed, 47 insertions(+), 8 deletions(-)
---
diff --git a/data/resources/resources.gresource.xml b/data/resources/resources.gresource.xml
index ee70046e..4841e5be 100644
--- a/data/resources/resources.gresource.xml
+++ b/data/resources/resources.gresource.xml
@@ -58,6 +58,7 @@
<file compressed="true" preprocess="xml-stripblanks"
alias="qr-code-scanner.ui">ui/qr-code-scanner.ui</file>
<file compressed="true" preprocess="xml-stripblanks"
alias="components-video-player.ui">ui/components-video-player.ui</file>
<file compressed="true">style.css</file>
+ <file compressed="true">style-dark.css</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/send-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/status/welcome.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/status/empty-page.svg</file>
diff --git a/data/resources/style-dark.css b/data/resources/style-dark.css
new file mode 100644
index 00000000..0b141bbe
--- /dev/null
+++ b/data/resources/style-dark.css
@@ -0,0 +1,12 @@
+#new-login-icon {
+ background-color: alpha(black, 0.8);
+}
+
+.devnotice {
+ background: @warning_bg_color;
+ color: @warning_fg_color;
+}
+
+button.cutout {
+ color: alpha(black, 0.8);
+}
diff --git a/data/resources/style.css b/data/resources/style.css
index a62eefb3..160d75c9 100644
--- a/data/resources/style.css
+++ b/data/resources/style.css
@@ -94,11 +94,10 @@
min-width: 200px;
}
-#devnotice {
- background-color: lighter(alpha(@warning_color, 0.3));
- color: shade(@warning_color, 0.5);
+.devnotice {
+ background: @warning_bg_color;
+ color: @warning_fg_color;
padding: 12px 24px;
- border-radius: 9px;
}
/* Session */
diff --git a/data/resources/ui/login.ui b/data/resources/ui/login.ui
index 7bacd558..b3fb74cc 100644
--- a/data/resources/ui/login.ui
+++ b/data/resources/ui/login.ui
@@ -66,7 +66,6 @@
<property name="spacing">18</property>
<child>
<object class="GtkBox">
- <property name="name">devnotice</property>
<property name="spacing">12</property>
<child>
<object class="GtkImage" id="development_icon">
@@ -78,11 +77,12 @@
<object class="GtkLabel" id="development_notice">
<property name="label" translatable="yes">You are running an early stage
development version. Be aware it is a work in progress and far from complete yet.</property>
<property name="wrap">True</property>
- <style>
- <class name="warning"/>
- </style>
</object>
</child>
+ <style>
+ <class name="card"/>
+ <class name="devnotice"/>
+ </style>
</object>
</child>
<child>
diff --git a/src/application.rs b/src/application.rs
index 440c7003..b6e81dd0 100644
--- a/src/application.rs
+++ b/src/application.rs
@@ -12,6 +12,7 @@ use log::{debug, info};
mod imp {
use super::*;
+ use adw::subclass::prelude::AdwApplicationImpl;
use once_cell::unsync::OnceCell;
#[derive(Debug)]
diff --git a/src/session/content/room_history/message_row/text.rs
b/src/session/content/room_history/message_row/text.rs
index 245913b4..e3f58ebe 100644
--- a/src/session/content/room_history/message_row/text.rs
+++ b/src/session/content/room_history/message_row/text.rs
@@ -380,6 +380,7 @@ fn create_widget_for_html_block(block: &HtmlBlock) -> gtk::Widget {
let buffer = sourceview::Buffer::new(None);
buffer.set_highlight_matching_brackets(false);
buffer.set_text(s);
+ crate::utils::setup_style_scheme(&buffer);
let view = sourceview::View::with_buffer(&buffer);
view.set_editable(false);
view.add_css_class("codeview");
diff --git a/src/session/content/room_history/mod.rs b/src/session/content/room_history/mod.rs
index dec58d4e..c38f481f 100644
--- a/src/session/content/room_history/mod.rs
+++ b/src/session/content/room_history/mod.rs
@@ -259,6 +259,7 @@ mod imp {
let (start_iter, end_iter) = buffer.bounds();
obj.action_set_enabled("room-history.send-text-message", start_iter != end_iter);
}));
+ crate::utils::setup_style_scheme(&buffer);
let (start_iter, end_iter) = buffer.bounds();
obj.action_set_enabled("room-history.send-text-message", start_iter != end_iter);
diff --git a/src/session/event_source_dialog.rs b/src/session/event_source_dialog.rs
index fe7d5f1f..5006abd6 100644
--- a/src/session/event_source_dialog.rs
+++ b/src/session/event_source_dialog.rs
@@ -82,6 +82,7 @@ mod imp {
let md_lang = sourceview::LanguageManager::default().and_then(|lm| lm.language("json"));
buffer.set_language(md_lang.as_ref());
+ crate::utils::setup_style_scheme(&buffer);
self.parent_constructed(obj);
}
diff --git a/src/utils.rs b/src/utils.rs
index 447a0d25..dad489e6 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,3 +1,5 @@
+use sourceview::prelude::BufferExt;
+
/// FIXME: This should be addressed in ruma directly
#[macro_export]
macro_rules! fn_event {
@@ -138,3 +140,24 @@ pub fn uint_to_i32(u: Option<UInt>) -> i32 {
})
.unwrap_or(-1)
}
+
+pub fn setup_style_scheme(buffer: &sourceview::Buffer) {
+ let manager = adw::StyleManager::default().unwrap();
+
+ buffer.set_style_scheme(style_scheme().as_ref());
+
+ manager.connect_dark_notify(glib::clone!(@weak buffer => move |_| {
+ buffer.set_style_scheme(style_scheme().as_ref());
+ }));
+}
+
+pub fn style_scheme() -> Option<sourceview::StyleScheme> {
+ let manager = adw::StyleManager::default().unwrap();
+ let scheme_name = if manager.is_dark() {
+ "Adwaita-dark"
+ } else {
+ "Adwaita"
+ };
+
+ sourceview::StyleSchemeManager::default().and_then(|scm| scm.scheme(scheme_name))
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]