Skip to content

Commit

Permalink
Remove eframe-specific system theme sync
Browse files Browse the repository at this point in the history
  • Loading branch information
bash committed Jul 3, 2024
1 parent 61cca8b commit 7a4a87f
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 69 deletions.
5 changes: 0 additions & 5 deletions crates/eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,11 +769,6 @@ pub struct IntegrationInfo {
#[cfg(target_arch = "wasm32")]
pub web_info: WebInfo,

/// Does the OS use dark or light mode?
///
/// `None` means "don't know".
pub system_theme: Option<Theme>,

/// Seconds of cpu usage (in seconds) on the previous frame.
///
/// This includes [`App::update`] as well as rendering (except for vsync waiting).
Expand Down
22 changes: 2 additions & 20 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use winit::event_loop::EventLoopWindowTarget;

use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _};

use egui::{DeferredViewportUiCallback, NumExt as _, Theme, ViewportBuilder, ViewportId, Visuals};
use egui::{DeferredViewportUiCallback, NumExt as _, ViewportBuilder, ViewportId};
use egui_winit::{EventResponse, WindowSettings};

use crate::epi;
Expand Down Expand Up @@ -162,7 +162,6 @@ pub struct EpiIntegration {
close: bool,

can_drag_window: bool,
follow_system_theme: bool,
#[cfg(feature = "persistence")]
persist_window: bool,
app_icon_setter: super::app_icon::AppTitleIconSetter,
Expand All @@ -173,7 +172,6 @@ impl EpiIntegration {
pub fn new(
egui_ctx: egui::Context,
window: &winit::window::Window,
system_theme: Option<Theme>,
app_name: &str,
native_options: &crate::NativeOptions,
storage: Option<Box<dyn epi::Storage>>,
Expand All @@ -184,10 +182,7 @@ impl EpiIntegration {
#[cfg(feature = "wgpu")] wgpu_render_state: Option<egui_wgpu::RenderState>,
) -> Self {
let frame = epi::Frame {
info: epi::IntegrationInfo {
system_theme,
cpu_usage: None,
},
info: epi::IntegrationInfo { cpu_usage: None },
storage,
#[cfg(feature = "glow")]
gl,
Expand Down Expand Up @@ -221,7 +216,6 @@ impl EpiIntegration {
pending_full_output: Default::default(),
close: false,
can_drag_window: false,
follow_system_theme: native_options.follow_system_theme,
#[cfg(feature = "persistence")]
persist_window: native_options.persist_window,
app_icon_setter,
Expand Down Expand Up @@ -277,11 +271,6 @@ impl EpiIntegration {
state: ElementState::Pressed,
..
} => self.can_drag_window = true,
WindowEvent::ThemeChanged(winit_theme) if self.follow_system_theme => {
let theme = theme_from_winit_theme(*winit_theme);
self.frame.info.system_theme = Some(theme);
self.egui_ctx.set_visuals(Visuals::theme(theme));
}
_ => {}
}

Expand Down Expand Up @@ -424,10 +413,3 @@ pub fn load_egui_memory(_storage: Option<&dyn epi::Storage>) -> Option<egui::Mem
#[cfg(not(feature = "persistence"))]
None
}

pub(crate) fn theme_from_winit_theme(theme: winit::window::Theme) -> Theme {
match theme {
winit::window::Theme::Dark => Theme::Dark,
winit::window::Theme::Light => Theme::Light,
}
}
8 changes: 1 addition & 7 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use winit::{
use ahash::{HashMap, HashSet};
use egui::{
DeferredViewportUiCallback, ImmediateViewport, ViewportBuilder, ViewportClass, ViewportId,
ViewportIdMap, ViewportIdPair, ViewportInfo, ViewportOutput, Visuals,
ViewportIdMap, ViewportIdPair, ViewportInfo, ViewportOutput,
};
#[cfg(feature = "accesskit")]
use egui_winit::accesskit_winit;
Expand Down Expand Up @@ -228,14 +228,11 @@ impl GlowWinitApp {
}
}

let system_theme =
winit_integration::system_theme(&glutin.window(ViewportId::ROOT), &self.native_options);
let painter = Rc::new(RefCell::new(painter));

let integration = EpiIntegration::new(
egui_ctx,
&glutin.window(ViewportId::ROOT),
system_theme,
&self.app_name,
&self.native_options,
storage,
Expand Down Expand Up @@ -281,9 +278,6 @@ impl GlowWinitApp {
}
}

let theme = system_theme.unwrap_or(self.native_options.default_theme);
integration.egui_ctx.set_visuals(Visuals::theme(theme));

if self
.native_options
.viewport
Expand Down
6 changes: 0 additions & 6 deletions crates/eframe/src/native/wgpu_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use ahash::{HashMap, HashSet, HashSetExt};
use egui::{
DeferredViewportUiCallback, FullOutput, ImmediateViewport, ViewportBuilder, ViewportClass,
ViewportId, ViewportIdMap, ViewportIdPair, ViewportIdSet, ViewportInfo, ViewportOutput,
Visuals,
};
#[cfg(feature = "accesskit")]
use egui_winit::accesskit_winit;
Expand Down Expand Up @@ -206,11 +205,9 @@ impl WgpuWinitApp {

let wgpu_render_state = painter.render_state();

let system_theme = winit_integration::system_theme(&window, &self.native_options);
let integration = EpiIntegration::new(
egui_ctx.clone(),
&window,
system_theme,
&self.app_name,
&self.native_options,
storage,
Expand Down Expand Up @@ -256,9 +253,6 @@ impl WgpuWinitApp {
}
egui_winit.init_system_theme(&window);

let theme = system_theme.unwrap_or(self.native_options.default_theme);
egui_ctx.set_visuals(Visuals::theme(theme));

let app_creator = std::mem::take(&mut self.app_creator)
.expect("Single-use AppCreator has unexpectedly already been taken");
let cc = CreationContext {
Expand Down
12 changes: 1 addition & 11 deletions crates/eframe/src/native/winit_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use winit::{
window::{Window, WindowId},
};

use egui::{Theme, ViewportId};
use egui::ViewportId;
#[cfg(feature = "accesskit")]
use egui_winit::accesskit_winit;

Expand Down Expand Up @@ -103,16 +103,6 @@ pub enum EventResult {
Exit,
}

pub fn system_theme(window: &Window, options: &crate::NativeOptions) -> Option<Theme> {
if options.follow_system_theme {
window
.theme()
.map(super::epi_integration::theme_from_winit_theme)
} else {
None
}
}

/// Short and fast description of an event.
/// Useful for logging and profiling.
pub fn short_event_description(event: &winit::event::Event<UserEvent>) -> &'static str {
Expand Down
12 changes: 1 addition & 11 deletions crates/eframe/src/web/app_runner.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use egui::{TexturesDelta, Visuals};
use egui::TexturesDelta;

use crate::{epi, App};

Expand Down Expand Up @@ -38,18 +38,11 @@ impl AppRunner {
) -> Result<Self, String> {
let painter = super::ActiveWebPainter::new(canvas_id, &web_options).await?;

let system_theme = if web_options.follow_system_theme {
super::system_theme()
} else {
None
};

let info = epi::IntegrationInfo {
web_info: epi::WebInfo {
user_agent: super::user_agent().unwrap_or_default(),
location: super::web_location(),
},
system_theme,
cpu_usage: None,
};
let storage = LocalStorage::default();
Expand All @@ -68,9 +61,6 @@ impl AppRunner {
o.zoom_factor = 1.0;
});

let theme = system_theme.unwrap_or(web_options.default_theme);
egui_ctx.set_visuals(Visuals::theme(theme));

let cc = epi::CreationContext {
egui_ctx: egui_ctx.clone(),
integration_info: info.clone(),
Expand Down
3 changes: 0 additions & 3 deletions crates/eframe/src/web/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use egui::Visuals;
use web_sys::EventTarget;

use super::*;
Expand Down Expand Up @@ -368,8 +367,6 @@ pub(crate) fn install_color_scheme_change_event(runner_ref: &WebRunner) -> Resul
"change",
|event, runner| {
let theme = theme_from_dark_mode(event.matches());
runner.frame.info.system_theme = Some(theme);
runner.egui_ctx().set_visuals(Visuals::theme(theme));
runner.input.raw.system_theme = Some(theme);
runner.needs_repaint.repaint_asap();
},
Expand Down
7 changes: 1 addition & 6 deletions crates/eframe/src/web/web_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ impl WebRunner {
) -> Result<(), JsValue> {
self.destroy();

let follow_system_theme = web_options.follow_system_theme;

let text_agent = TextAgent::attach(self)?;

let runner = AppRunner::new(canvas_id, web_options, app_creator, text_agent).await?;
Expand All @@ -82,10 +80,7 @@ impl WebRunner {

{
events::install_event_handlers(self)?;

if follow_system_theme {
events::install_color_scheme_change_event(self)?;
}
events::install_color_scheme_change_event(self)?;

// The resize observer handles calling `request_animation_frame` to start the render loop.
events::install_resize_observer(self)?;
Expand Down

0 comments on commit 7a4a87f

Please sign in to comment.