Skip to content
Open
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
974 changes: 657 additions & 317 deletions Cargo.lock

Large diffs are not rendered by default.

268 changes: 177 additions & 91 deletions cosmic-panel-bin/src/space/layout.rs

Large diffs are not rendered by default.

57 changes: 56 additions & 1 deletion cosmic-panel-bin/src/space/panel_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ use smithay::{
compositor::with_states,
fractional_scale::with_fractional_scale,
seat::WaylandFocus,
shell::xdg::{PopupSurface, PositionerState},
shell::xdg::{PopupSurface, PositionerState, ToplevelSurface},
},
};
use tokio::sync::{mpsc, oneshot};
Expand Down Expand Up @@ -138,6 +138,7 @@ pub struct PanelClient {
pub is_notification_applet: Option<bool>,
pub shrink_priority: Option<u32>,
pub shrink_min_size: Option<ClientShrinkSize>,
pub padding_shrinkable: bool,
/// If there is an existing popup, this applet with be pressed when hovered.
pub auto_popup_hover_press: Option<AppletAutoClickAnchor>,
}
Expand Down Expand Up @@ -206,6 +207,7 @@ impl PanelClient {
requests_wayland_display: None,
is_notification_applet: None,
auto_popup_hover_press: None,
padding_shrinkable: false,
shrink_priority: None,
shrink_min_size: None,
}
Expand Down Expand Up @@ -311,6 +313,7 @@ pub struct PanelSpace {
pub c_display: Option<WlDisplay>,
pub config: CosmicPanelConfig,
pub space: Space<CosmicMappedInternal>,
pub unmapped_windows: Vec<CosmicMappedInternal>,
pub damage_tracked_renderer: Option<OutputDamageTracker>,
pub clients_left: Clients,
pub clients_center: Clients,
Expand Down Expand Up @@ -394,6 +397,7 @@ impl PanelSpace {
config,
shared: shared.clone(),
space: Space::default(),
unmapped_windows: Vec::new(),
overflow_left: Space::default(),
overflow_center: Space::default(),
overflow_right: Space::default(),
Expand Down Expand Up @@ -600,6 +604,7 @@ impl PanelSpace {
is_notification_applet: None,
shrink_priority: None,
shrink_min_size: None,
padding_shrinkable: false,
auto_popup_hover_press: None,
};

Expand Down Expand Up @@ -653,6 +658,7 @@ impl PanelSpace {
is_notification_applet: None,
shrink_priority: None,
shrink_min_size: None,
padding_shrinkable: false,
auto_popup_hover_press: None,
};
// add to list if not already there
Expand Down Expand Up @@ -1936,6 +1942,55 @@ impl PanelSpace {
});
}
}

pub fn minimize_window(&mut self, surface: ToplevelSurface) -> bool {
let w = self
.space
.elements()
.find(|e| {
if let CosmicMappedInternal::Window(w) = e {
if let Some(t) = w.toplevel() {
return *t == surface;
}
}
false
})
.cloned();

if let Some(window) = w {
self.space.unmap_elem(&window);
self.unmapped_windows.push(window);
true
} else {
false
}
}

pub fn unminimize_window(&mut self, surface: ToplevelSurface) -> bool {
let pos = self.unmapped_windows.iter().position(|e| {
if let CosmicMappedInternal::Window(w) = e {
if let Some(t) = w.toplevel() {
return *t == surface;
}
}
false
});

if let Some(idx) = pos {
let window = self.unmapped_windows.remove(idx);
if let Some(wl_surface) = window.wl_surface() {
with_states(&wl_surface, |states| {
with_fractional_scale(states, |fractional_scale| {
fractional_scale.set_preferred_scale(self.scale);
});
});
}
self.space.map_element(window, (0, 0), false);
true
} else {
false
}
}
}

impl Drop for PanelSpace {
Expand Down
1 change: 0 additions & 1 deletion cosmic-panel-bin/src/space/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ impl PanelSpace {
let hovered_clients: HashSet<_> = self
.s_hovered_surface
.iter()
.chain(self.s_hovered_surface.iter())
.filter_map(|c| c.surface.wl_surface().map(|s| s.id()))
.collect();
tracing::trace!("Rendering space");
Expand Down
7 changes: 7 additions & 0 deletions cosmic-panel-bin/src/space/wrapper_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,16 @@ impl WrapperSpace for PanelSpace {
let config_anchor = ron::ser::to_string(&self.config.anchor).unwrap_or_default();
let config_bg = ron::ser::to_string(&self.config.background).unwrap_or_default();
let config_spacing = ron::ser::to_string(&self.config.spacing).unwrap_or_default();
let config_padding_overlap =
ron::ser::to_string(&self.config.padding_overlap()).unwrap_or_default();
let config_name = self.config.name.clone();
let env_vars = vec![
("COSMIC_PANEL_NAME".to_string(), config_name),
("COSMIC_PANEL_OUTPUT".to_string(), active_output),
("COSMIC_PANEL_SPACING".to_string(), config_spacing),
("COSMIC_PANEL_ANCHOR".to_string(), config_anchor),
("COSMIC_PANEL_BACKGROUND".to_string(), config_bg),
("COSMIC_PANEL_PADDING_OVERLAP".to_string(), config_padding_overlap),
];
info!("{:?}", &desktop_ids);

Expand Down Expand Up @@ -492,6 +495,10 @@ impl WrapperSpace for PanelSpace {
panel_client.shrink_priority = entry
.desktop_entry("X-OverflowPriority")
.and_then(|x| x.parse::<u32>().ok());
panel_client.padding_shrinkable = entry
.desktop_entry("X-CosmicShrinkable")
.map(|x| x == "true")
.unwrap_or_default();

panel_client.minimize_priority = if let Some(x_minimize_entry) =
entry.desktop_entry("X-MinimizeApplet")
Expand Down
19 changes: 19 additions & 0 deletions cosmic-panel-bin/src/space_container/space_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use smithay::{
backend::renderer::gles::GlesRenderer,
output::Output,
reexports::wayland_server::{self, backend::ClientId},
wayland::shell::xdg::ToplevelSurface,
};
use tokio::sync::mpsc;
use tracing::{error, info};
Expand Down Expand Up @@ -295,6 +296,8 @@ impl SpaceContainer {
|| self.config.config_list.iter().any(|c| {
// size changed
c.name == entry.name && c.size != entry.size
// spacing changed
|| (c.name == entry.name && c.spacing != entry.spacing)
// size overrides changed
|| (c.name == entry.name && (c.size_center != entry.size_center || c.size_wings != entry.size_wings))
// output changed
Expand Down Expand Up @@ -567,4 +570,20 @@ impl SpaceContainer {
);
}
}

pub(crate) fn minimize_window(&mut self, surface: ToplevelSurface) {
for space in &mut self.space_list {
if space.minimize_window(surface.clone()) {
break;
}
}
}

pub(crate) fn maximize_window(&mut self, surface: ToplevelSurface) {
for space in &mut self.space_list {
if space.unminimize_window(surface.clone()) {
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ impl XdgShellHandler for GlobalState {
fn popup_destroyed(&mut self, surface: PopupSurface) {
self.server_state.popup_manager.commit(surface.wl_surface());
}

fn minimize_request(&mut self, surface: ToplevelSurface) {
self.space.minimize_window(surface.clone());
}

fn maximize_request(&mut self, surface: ToplevelSurface) {
self.space.maximize_window(surface.clone());
}
}

// Xdg Shell
Expand Down
10 changes: 6 additions & 4 deletions cosmic-panel-config/src/container_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,14 @@ impl Default for CosmicPanelContainerConfig {
size_center: None,
expand_to_edges: true,
padding: 0,
spacing: 2,
spacing: 0,
border_radius: 0,
exclusive_zone: true,
autohide: None,
margin: 0,
opacity: 1.0,
autohover_delay_ms: Some(500),
padding_overlap: 0.5,
},
CosmicPanelConfig {
name: "Dock".to_string(),
Expand All @@ -186,9 +187,9 @@ impl Default for CosmicPanelContainerConfig {
size_wings: None,
size_center: None,
expand_to_edges: false,
padding: 0,
spacing: 4,
border_radius: 160,
padding: 4,
spacing: 0,
border_radius: 12,
exclusive_zone: false,
autohide: Some(crate::AutoHide {
wait_time: 500,
Expand All @@ -199,6 +200,7 @@ impl Default for CosmicPanelContainerConfig {
margin: 0,
opacity: 1.0,
autohover_delay_ms: Some(500),
padding_overlap: 0.5,
},
],
}
Expand Down
37 changes: 36 additions & 1 deletion cosmic-panel-config/src/panel_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,34 @@ impl PanelSize {
}
}

pub fn get_applet_shrinkable_padding(&self, is_symbolic: bool) -> u16 {
if is_symbolic {
match self {
PanelSize::XS => 12,
PanelSize::S => 14,
PanelSize::M => 18,
PanelSize::L => 20,
PanelSize::XL => 20,
PanelSize::Custom(s) => {
let s = (*s).max(16) / 4 * 4;
4 + (s / 4) as u16
},
}
} else {
match self {
PanelSize::XS => 8,
PanelSize::S => 8,
PanelSize::M => 12,
PanelSize::L => 12,
PanelSize::XL => 16,
PanelSize::Custom(s) => {
let s = (*s).max(16) / 4 * 4;
4 + (s * 3 / 20) as u16
},
}
}
}

pub fn get_applet_icon_size_with_padding(&self, is_symbolic: bool) -> u32 {
self.get_applet_icon_size(is_symbolic) + self.get_applet_padding(is_symbolic) as u32 * 2
}
Expand Down Expand Up @@ -382,6 +410,8 @@ pub struct CosmicPanelConfig {
/// autohover popup delay duration in milliseconds
/// If None, then it is disabled
pub autohover_delay_ms: Option<u32>,
/// padding overlap ratio
pub padding_overlap: f32,
}

impl PartialEq for CosmicPanelConfig {
Expand Down Expand Up @@ -429,13 +459,14 @@ impl Default for CosmicPanelConfig {
size_center: Default::default(),
expand_to_edges: true,
padding: 4,
spacing: 4,
spacing: 0,
exclusive_zone: true,
autohide: Some(AutoHide::default()),
border_radius: 8,
margin: 4,
opacity: 0.8,
autohover_delay_ms: Some(500),
padding_overlap: 0.5,
}
}
}
Expand All @@ -449,6 +480,10 @@ pub enum Side {

#[cfg(feature = "wayland-rs")]
impl CosmicPanelConfig {
pub fn padding_overlap(&self) -> f32 {
self.padding_overlap.clamp(0., 1.)
}

/// get the applet size given its side
pub fn get_effective_applet_size(&self, side: Side) -> PanelSize {
match side {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
160
12
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0
4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4
0
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2
0