Skip to content

Commit

Permalink
Merge pull request #198 from pop-os/theme-integration-2_jammy
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix authored Oct 18, 2023
2 parents d74b371 + 996c821 commit cff4340
Show file tree
Hide file tree
Showing 24 changed files with 396 additions and 136 deletions.
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"] }
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 }
iced_tiny_skia = { git = "https://github.com/pop-os/libcosmic/" }
tiny-skia = "0.10"
ordered-float = "4.0"
glow = "0.12.0"
Expand Down
7 changes: 5 additions & 2 deletions src/backend/kms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,8 +1241,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,
CLEAR_COLOR, // TODO use a theme neutral color
);
self.fps.render();

match res {
Expand Down
25 changes: 16 additions & 9 deletions src/backend/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ pub type GlMultiFrame<'a, 'b, 'frame> =
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 @@ -164,6 +160,7 @@ impl IndicatorShader {
thickness: u8,
scale: f64,
alpha: f32,
active_window_hint: [f32; 3],
) -> PixelShaderElement {
let t = thickness as i32;
element_geo.loc -= (t, t).into();
Expand All @@ -177,7 +174,7 @@ impl IndicatorShader {
thickness * 2,
alpha,
scale,
FOCUS_INDICATOR_COLOR,
active_window_hint,
)
}

Expand Down Expand Up @@ -413,13 +410,14 @@ where
);
}

let theme = state.theme.cosmic();
if let Some(grab_elements) = seat
.user_data()
.get::<SeatMoveGrabState>()
.unwrap()
.borrow()
.as_ref()
.map(|state| state.render::<E, R>(renderer, seat, output))
.map(|state| state.render::<E, R>(renderer, seat, output, theme))
{
elements.extend(grab_elements);
}
Expand Down Expand Up @@ -449,6 +447,7 @@ where
#[cfg(feature = "debug")]
puffin::profile_function!();

let theme = state.theme.cosmic();
let mut elements = cursor_elements(renderer, state, output, cursor_mode);

#[cfg(feature = "debug")]
Expand Down Expand Up @@ -544,6 +543,7 @@ where
} else {
Vec::new()
};
let active_hint = theme.active_hint as u8;

let offset = match previous.as_ref() {
Some((previous, previous_idx, start)) => {
Expand Down Expand Up @@ -584,7 +584,8 @@ where
(!move_active && is_active_space).then_some(&last_active_seat),
overview.clone(),
resize_indicator.clone(),
state.config.static_conf.active_hint,
active_hint,
theme,
)
.map_err(|_| OutputNoMode)?;
elements.extend(p_elements.into_iter().map(|p_element| {
Expand Down Expand Up @@ -641,7 +642,8 @@ where
(!move_active && is_active_space).then_some(&last_active_seat),
overview,
resize_indicator,
state.config.static_conf.active_hint,
active_hint,
theme,
)
.map_err(|_| OutputNoMode)?;
elements.extend(p_elements.into_iter().map(|p_element| {
Expand Down Expand Up @@ -913,7 +915,12 @@ 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,
CLEAR_COLOR, // TODO use a theme neutral 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
1 change: 0 additions & 1 deletion src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ impl State {
<B as InputBackend>::PointerAxisEvent: 'static,
{
use smithay::backend::input::Event;

match event {
InputEvent::DeviceAdded { device } => {
let seat = &mut self.common.last_active_seat();
Expand Down
5 changes: 5 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,10 @@ fn main() -> Result<()> {
// potentially tell the session we are setup now
session::setup_socket(event_loop.handle(), &state)?;

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

// run the event loop
event_loop.run(None, &mut state, |state| {
// shall we shut down?
Expand Down
22 changes: 20 additions & 2 deletions src/shell/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,14 +501,15 @@ impl CosmicMapped {
pub fn convert_to_stack<'a>(
&mut self,
(output, overlap): (&'a Output, Rectangle<i32, Logical>),
theme: cosmic::Theme,
) {
match &self.element {
CosmicMappedInternal::Window(window) => {
let surface = window.surface();
let activated = surface.is_activated(true);
let handle = window.loop_handle();

let stack = CosmicStack::new(std::iter::once(surface), handle);
let stack = CosmicStack::new(std::iter::once(surface), handle, theme);
if let Some(geo) = self.last_geometry.lock().unwrap().clone() {
stack.set_geometry(geo.to_global(&output));
}
Expand All @@ -527,11 +528,12 @@ impl CosmicMapped {
&mut self,
surface: CosmicSurface,
(output, overlap): (&'a Output, Rectangle<i32, Logical>),
theme: cosmic::Theme,
) {
let handle = self.loop_handle();
surface.try_force_undecorated(false);
surface.set_tiled(false);
let window = CosmicWindow::new(surface, handle);
let window = CosmicWindow::new(surface, handle, theme);

if let Some(geo) = self.last_geometry.lock().unwrap().clone() {
window.set_geometry(geo.to_global(&output));
Expand Down Expand Up @@ -764,6 +766,22 @@ impl CosmicMapped {
popup_elements.into_iter().map(C::from).collect(),
)
}

pub(crate) fn update_theme(&self, theme: cosmic::Theme) {
match &self.element {
CosmicMappedInternal::Window(w) => w.set_theme(theme),
CosmicMappedInternal::Stack(s) => s.set_theme(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
2 changes: 2 additions & 0 deletions src/shell/element/resize_indicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub fn resize_indicator(
direction: ResizeDirection,
config: &Config,
evlh: LoopHandle<'static, crate::state::State>,
theme: cosmic::Theme,
) -> ResizeIndicator {
ResizeIndicator::new(
ResizeIndicatorInternal {
Expand All @@ -49,6 +50,7 @@ pub fn resize_indicator(
},
Size::from((1, 1)),
evlh,
theme,
)
}

Expand Down
Loading

0 comments on commit cff4340

Please sign in to comment.