Skip to content
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

feat: theme integration #196

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ libsystemd = { version = "0.6", optional = true }
wayland-backend = "0.3.2"
wayland-scanner = "0.31.0"
cosmic-comp-config = { path = "cosmic-comp-config" }
cosmic-config = { git = "https://github.com/pop-os/libcosmic/", rev = "f91287d", features = ["calloop"] }
cosmic-config = { git = "https://github.com/pop-os/libcosmic/", features = ["calloop", "macro"], branch = "theme-dark-light-switching"}
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", branch = "main", default-features = false, features = ["server"] }
libcosmic = { git = "https://github.com/pop-os/libcosmic/", rev = "f91287d", default-features = false }
iced_tiny_skia = { git = "https://github.com/pop-os/libcosmic/", rev = "f91287d" }
libcosmic = { git = "https://github.com/pop-os/libcosmic/", default-features = false, branch = "theme-dark-light-switching" }
iced_tiny_skia = { git = "https://github.com/pop-os/libcosmic/", branch = "theme-dark-light-switching" }
tiny-skia = "0.10"
ordered-float = "4.0"
glow = "0.12.0"
Expand Down
9 changes: 6 additions & 3 deletions src/backend/kms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[cfg(feature = "debug")]
use crate::backend::render::element::AsGlowRenderer;
use crate::{
backend::render::{workspace_elements, CLEAR_COLOR},
backend::render::workspace_elements,
config::OutputConfig,
shell::Shell,
state::{BackendData, ClientState, Common, Fps, SurfaceDmabufFeedback},
Expand Down Expand Up @@ -1107,8 +1107,11 @@ impl Surface {
})?;
self.fps.elements();

let res =
compositor.render_frame::<_, _, GlesTexture>(&mut renderer, &elements, CLEAR_COLOR);
let res = compositor.render_frame::<_, _, GlesTexture>(
&mut renderer,
&elements,
crate::theme::clear_color(),
);
self.fps.render();

match res {
Expand Down
19 changes: 10 additions & 9 deletions src/backend/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ pub type GlMultiFrame<'a, 'b, 'frame> =
MultiFrame<'a, 'a, 'b, 'frame, GbmGlesBackend<GlowRenderer>, GbmGlesBackend<GlowRenderer>>;
pub type GlMultiError = MultiError<GbmGlesBackend<GlowRenderer>, GbmGlesBackend<GlowRenderer>>;

pub static CLEAR_COLOR: [f32; 4] = [0.153, 0.161, 0.165, 1.0];
pub static GROUP_COLOR: [f32; 3] = [0.788, 0.788, 0.788];
pub static ACTIVE_GROUP_COLOR: [f32; 3] = [0.58, 0.922, 0.922];
pub static FOCUS_INDICATOR_COLOR: [f32; 3] = [0.580, 0.921, 0.921];

pub static OUTLINE_SHADER: &str = include_str!("./shaders/rounded_outline.frag");
pub static RECTANGLE_SHADER: &str = include_str!("./shaders/rounded_rectangle.frag");

Expand Down Expand Up @@ -169,6 +164,7 @@ impl IndicatorShader {
element_geo.loc -= (t, t).into();
element_geo.size += (t * 2, t * 2).into();

let focus_indicator = crate::theme::active_window_hint();
IndicatorShader::element(
renderer,
key,
Expand All @@ -177,7 +173,11 @@ impl IndicatorShader {
thickness * 2,
alpha,
scale,
FOCUS_INDICATOR_COLOR,
[
focus_indicator.red,
focus_indicator.green,
focus_indicator.blue,
],
)
}

Expand Down Expand Up @@ -580,6 +580,7 @@ where
}
});

let active_hint = crate::theme::active_hint();
let (w_elements, p_elements) = workspace
.render_output::<R>(
renderer,
Expand All @@ -589,7 +590,7 @@ where
(!move_active && is_active_space).then_some(&last_active_seat),
overview.clone(),
resize_indicator.clone(),
state.config.static_conf.active_hint,
active_hint,
)
.map_err(|_| OutputNoMode)?;
elements.extend(p_elements.into_iter().map(|p_element| {
Expand Down Expand Up @@ -647,7 +648,7 @@ where
(!move_active && is_active_space).then_some(&last_active_seat),
overview,
resize_indicator,
state.config.static_conf.active_hint,
crate::theme::active_hint(),
)
.map_err(|_| OutputNoMode)?;
elements.extend(p_elements.into_iter().map(|p_element| {
Expand Down Expand Up @@ -919,7 +920,7 @@ where
}

renderer.bind(target).map_err(RenderError::Rendering)?;
let res = damage_tracker.render_output(renderer, age, &elements, CLEAR_COLOR);
let res = damage_tracker.render_output(renderer, age, &elements, crate::theme::clear_color());

if let Some(fps) = fps.as_mut() {
fps.render();
Expand Down
14 changes: 0 additions & 14 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ pub struct StaticConfig {
#[serde(default = "default_workspace_layout")]
pub workspace_layout: WorkspaceLayout,
pub tiling_enabled: bool,
#[serde(default = "default_active_hint")]
pub active_hint: u8,
#[serde(default = "default_gaps")]
pub gaps: (u8, u8),
}

#[derive(Debug, Deserialize, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -100,14 +96,6 @@ fn default_enabled() -> bool {
true
}

fn default_active_hint() -> u8 {
4
}

fn default_gaps() -> (u8, u8) {
(0, 4)
}

fn default_workspace_layout() -> WorkspaceLayout {
WorkspaceLayout::Vertical
}
Expand Down Expand Up @@ -219,8 +207,6 @@ impl Config {
workspace_amount: WorkspaceAmount::Dynamic,
workspace_layout: WorkspaceLayout::Vertical,
tiling_enabled: false,
active_hint: default_active_hint(),
gaps: default_gaps(),
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub mod shell;
pub mod state;
#[cfg(feature = "systemd")]
pub mod systemd;
pub mod theme;
pub mod utils;
pub mod wayland;
pub mod xwayland;
Expand Down Expand Up @@ -55,6 +56,8 @@ fn main() -> Result<()> {
// potentially tell the session we are setup now
session::setup_socket(event_loop.handle(), &state)?;

let _theme_res = theme::watch_theme(event_loop.handle());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let _theme_res = theme::watch_theme(event_loop.handle());
if let Err(err) = theme::watch_theme(event_loop.handle()) {
warn!(?err, "Failed to watch cosmic theme");
}


// run the event loop
event_loop.run(None, &mut state, |state| {
// shall we shut down?
Expand Down
16 changes: 16 additions & 0 deletions src/shell/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,22 @@ impl CosmicMapped {
popup_elements.into_iter().map(C::from).collect(),
)
}

pub(crate) fn set_theme(&self) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this has no parameter, could we maybe rename this to something like reload_theme or update_theme? (Same then for CosmicStack, CosmicWindow, IcedElement..)

match &self.element {
CosmicMappedInternal::Window(w) => w.set_theme(),
CosmicMappedInternal::Stack(s) => s.set_theme(),
CosmicMappedInternal::_GenericCatcher(_) => {}
}
}

pub(crate) fn force_redraw(&self) {
match &self.element {
CosmicMappedInternal::Window(w) => w.force_redraw(),
CosmicMappedInternal::Stack(s) => s.force_redraw(),
CosmicMappedInternal::_GenericCatcher(_) => {}
}
}
}

impl IsAlive for CosmicMapped {
Expand Down
11 changes: 9 additions & 2 deletions src/shell/element/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,14 @@ impl CosmicStack {
popup_elements.into_iter().map(C::from).collect(),
)
}

pub(crate) fn set_theme(&self) {
self.0.set_theme();
}

pub(crate) fn force_redraw(&self) {
self.0.force_redraw();
}
}

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -1059,8 +1067,7 @@ impl PointerTarget<State> for CosmicStack {
));
let elem_geo =
workspace.element_geometry(stack_mapped).unwrap();
let indicator_thickness =
data.common.config.static_conf.active_hint;
let indicator_thickness = crate::theme::active_hint();
let was_tiled = workspace.is_tiled(stack_mapped);

self.remove_idx(dragged_out);
Expand Down
8 changes: 8 additions & 0 deletions src/shell/element/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ impl CosmicWindow {
popup_elements.into_iter().map(C::from).collect(),
)
}

pub(crate) fn set_theme(&self) {
self.0.set_theme();
}

pub(crate) fn force_redraw(&self) {
self.0.force_redraw();
}
}

#[derive(Debug, Clone, Copy)]
Expand Down
Loading