From d088acd62d128c803ebcfd44717fd8302d415edb Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 7 Dec 2022 12:46:54 -0500 Subject: [PATCH] fix: fix update dep & fix window size --- applets/cosmic-applet-battery/Cargo.lock | 2 +- applets/cosmic-applet-battery/src/app.rs | 19 +++++------------ applets/cosmic-applet-graphics/Cargo.lock | 2 +- applets/cosmic-applet-graphics/src/main.rs | 21 ++++++------------- applets/cosmic-applet-workspaces/Cargo.lock | 6 +++--- applets/cosmic-applet-workspaces/Cargo.toml | 4 ++-- .../src/components/app.rs | 18 ++++++++-------- 7 files changed, 27 insertions(+), 45 deletions(-) diff --git a/applets/cosmic-applet-battery/Cargo.lock b/applets/cosmic-applet-battery/Cargo.lock index bf5a4e6e..bd00afa4 100644 --- a/applets/cosmic-applet-battery/Cargo.lock +++ b/applets/cosmic-applet-battery/Cargo.lock @@ -1730,7 +1730,7 @@ checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=fix/applets#0760008f54428ef44968df8db465dfceb7ee837d" +source = "git+https://github.com/pop-os/libcosmic/?branch=fix/applets#244569d42d94a8be3a5aa3c3af8bedff047d780e" dependencies = [ "apply", "cosmic-panel-config", diff --git a/applets/cosmic-applet-battery/src/app.rs b/applets/cosmic-applet-battery/src/app.rs index 14d34c58..8648bacc 100644 --- a/applets/cosmic-applet-battery/src/app.rs +++ b/applets/cosmic-applet-battery/src/app.rs @@ -47,22 +47,13 @@ fn format_duration(duration: Duration) -> String { pub fn run() -> cosmic::iced::Result { let mut settings = settings(); - let pixels = std::env::var("COSMIC_PANEL_SIZE") - .ok() - .and_then(|size| match size.parse::() { - Ok(PanelSize::XL) => Some(64), - Ok(PanelSize::L) => Some(48), - Ok(PanelSize::M) => Some(36), - Ok(PanelSize::S) => Some(24), - Ok(PanelSize::XS) => Some(18), - Err(_) => Some(36), - }) - .unwrap_or(36); + let helper = CosmicAppletHelper::default(); + let pixels = helper.suggested_icon_size() as u32; settings.initial_surface = InitialSurface::XdgWindow(SctkWindowSettings { iced_settings: Settings { - size: (pixels + 32, pixels + 16), - min_size: Some((pixels + 32, pixels + 16)), - max_size: Some((pixels + 32, pixels + 16)), + size: (pixels + 16, pixels + 16), + min_size: Some((pixels + 16, pixels + 16)), + max_size: Some((pixels + 16, pixels + 16)), ..Default::default() }, ..Default::default() diff --git a/applets/cosmic-applet-graphics/Cargo.lock b/applets/cosmic-applet-graphics/Cargo.lock index 2b8c9bb7..88e68772 100644 --- a/applets/cosmic-applet-graphics/Cargo.lock +++ b/applets/cosmic-applet-graphics/Cargo.lock @@ -1531,7 +1531,7 @@ checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=fix/applets#9d75dc8830f7ed8a21af790e2b11c93b90629b1f" +source = "git+https://github.com/pop-os/libcosmic/?branch=fix/applets#244569d42d94a8be3a5aa3c3af8bedff047d780e" dependencies = [ "apply", "cosmic-panel-config", diff --git a/applets/cosmic-applet-graphics/src/main.rs b/applets/cosmic-applet-graphics/src/main.rs index 192a5017..072fa278 100644 --- a/applets/cosmic-applet-graphics/src/main.rs +++ b/applets/cosmic-applet-graphics/src/main.rs @@ -6,29 +6,20 @@ use cosmic::{ iced::{sctk_settings::InitialSurface, Application}, iced_native::command::platform_specific::wayland::window::SctkWindowSettings, iced_native::window::Settings, - settings, + settings, applet::CosmicAppletHelper, }; use cosmic_panel_config::PanelSize; use window::*; pub fn main() -> cosmic::iced::Result { let mut settings = settings(); - let pixels = std::env::var("COSMIC_PANEL_SIZE") - .ok() - .and_then(|size| match size.parse::() { - Ok(PanelSize::XL) => Some(64), - Ok(PanelSize::L) => Some(48), - Ok(PanelSize::M) => Some(36), - Ok(PanelSize::S) => Some(24), - Ok(PanelSize::XS) => Some(18), - Err(_) => Some(36), - }) - .unwrap_or(36); + let helper = CosmicAppletHelper::default(); + let pixels = helper.suggested_icon_size() as u32; settings.initial_surface = InitialSurface::XdgWindow(SctkWindowSettings { iced_settings: Settings { - size: (pixels + 32, pixels + 16), - min_size: Some((pixels + 32, pixels + 16)), - max_size: Some((pixels + 32, pixels + 16)), + size: (pixels + 16, pixels + 16), + min_size: Some((pixels + 16, pixels + 16)), + max_size: Some((pixels + 16, pixels + 16)), ..Default::default() }, ..Default::default() diff --git a/applets/cosmic-applet-workspaces/Cargo.lock b/applets/cosmic-applet-workspaces/Cargo.lock index 0dd2eeac..9a333ef5 100644 --- a/applets/cosmic-applet-workspaces/Cargo.lock +++ b/applets/cosmic-applet-workspaces/Cargo.lock @@ -371,7 +371,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel#a452fc323b574c28aef832951edd413a1d87bc3d" +source = "git+https://github.com/pop-os/cosmic-panel#35d61a3a617b2ef552931645ec35c545a3a688f6" dependencies = [ "anyhow", "ron", @@ -1375,7 +1375,7 @@ dependencies = [ [[package]] name = "iced_sctk" version = "0.1.0" -source = "git+https://github.com/pop-os/iced-sctk#a2c24d95ebc795245495677b99b631a4322ef876" +source = "git+https://github.com/pop-os/iced-sctk#d126b62ef1001b22dc946db91928395890ff8d9f" dependencies = [ "enum-repr", "futures", @@ -1574,7 +1574,7 @@ checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=sctk-cosmic-design-system#e87fe7056d09530c35e2c39d470205c6a7a920c6" +source = "git+https://github.com/pop-os/libcosmic/?branch=fix/applets#244569d42d94a8be3a5aa3c3af8bedff047d780e" dependencies = [ "apply", "cosmic-panel-config", diff --git a/applets/cosmic-applet-workspaces/Cargo.toml b/applets/cosmic-applet-workspaces/Cargo.toml index 9cf16590..b392cea6 100644 --- a/applets/cosmic-applet-workspaces/Cargo.toml +++ b/applets/cosmic-applet-workspaces/Cargo.toml @@ -5,10 +5,10 @@ authors = ["Ashley Wulber "] edition = "2021" [dependencies] -libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "sctk-cosmic-design-system", default-features = false, features = ["wayland", "applet"] } +libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "fix/applets", default-features = false, features = ["wayland", "applet"] } cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", default-features = false } iced_sctk = { git = "https://github.com/pop-os/iced-sctk" } -sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", ersion = "0.1.0-beta.13" } +sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", version = "0.16" } cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false, features = ["client"] } wayland-backend = {version = "0.1.0-beta.13", features = ["client_system"]} wayland-client = {version = "0.30.0-beta.13"} diff --git a/applets/cosmic-applet-workspaces/src/components/app.rs b/applets/cosmic-applet-workspaces/src/components/app.rs index 35f9f914..e695db30 100644 --- a/applets/cosmic-applet-workspaces/src/components/app.rs +++ b/applets/cosmic-applet-workspaces/src/components/app.rs @@ -1,6 +1,6 @@ -use std::{cmp::Ordering, env}; - +use std::cmp::Ordering; use calloop::channel::SyncSender; +use cosmic::applet::CosmicAppletHelper; use cosmic::iced::alignment::{Horizontal, Vertical}; use cosmic::iced::mouse::{self, ScrollDelta}; use cosmic::iced::widget::{column, container, row, text}; @@ -63,13 +63,10 @@ impl Application for IcedWorkspacesApplet { type Flags = (); fn new(_flags: ()) -> (Self, Command) { + let applet_helper = CosmicAppletHelper::default(); ( IcedWorkspacesApplet { - layout: match env::var("COSMIC_PANEL_ANCHOR") - .ok() - .and_then(|anchor| anchor.parse::().ok()) - .unwrap_or_default() - { + layout: match &applet_helper.anchor { PanelAnchor::Left | PanelAnchor::Right => Layout::Column, PanelAnchor::Top | PanelAnchor::Bottom => Layout::Row, }, @@ -100,8 +97,8 @@ impl Application for IcedWorkspacesApplet { self.workspaces = list; let unit = 32; let (w, h) = match self.layout { - Layout::Row => (unit * self.workspaces.len() as u32, unit), - Layout::Column => (unit, unit * self.workspaces.len() as u32), + Layout::Row => (unit * self.workspaces.len().max(1) as u32, unit), + Layout::Column => (unit, unit * self.workspaces.len().max(1) as u32), }; return commands::window::resize_window(window::Id::new(0), w, h); } @@ -132,6 +129,9 @@ impl Application for IcedWorkspacesApplet { } fn view(&self, _id: SurfaceIdWrapper) -> Element { + if self.workspaces.is_empty() { + return row![].padding(8).into(); + } let buttons = self .workspaces .iter()