diff --git a/Cargo.lock b/Cargo.lock index 3958b60..e4b0a06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1122,7 +1122,7 @@ dependencies = [ [[package]] name = "cosmic-config" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#e83e43bf1e38476e79383b299668afa525bad3e9" +source = "git+https://github.com/pop-os/libcosmic#6439507aa2d8d7e6a89c0fc016895dc0ab9252d4" dependencies = [ "atomicwrites", "cosmic-config-derive", @@ -1143,7 +1143,7 @@ dependencies = [ [[package]] name = "cosmic-config-derive" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#e83e43bf1e38476e79383b299668afa525bad3e9" +source = "git+https://github.com/pop-os/libcosmic#6439507aa2d8d7e6a89c0fc016895dc0ab9252d4" dependencies = [ "quote", "syn 2.0.106", @@ -1162,6 +1162,20 @@ dependencies = [ "xdg 2.5.2", ] +[[package]] +name = "cosmic-panel-config" +version = "0.1.0" +source = "git+https://github.com/pop-os/cosmic-panel?branch=workspaces-panel#b6031b084477a961370b6a3c6aefc364c483636e" +dependencies = [ + "anyhow", + "cosmic-config", + "serde", + "smithay-client-toolkit 0.20.0", + "tracing", + "wayland-protocols-wlr", + "xdg-shell-wrapper-config", +] + [[package]] name = "cosmic-protocols" version = "0.1.0" @@ -1193,7 +1207,7 @@ dependencies = [ [[package]] name = "cosmic-settings-daemon" version = "0.1.0" -source = "git+https://github.com/pop-os/dbus-settings-bindings#3b86984332be2c930a3536ab714b843c851fa8ca" +source = "git+https://github.com/pop-os/dbus-settings-bindings#b2337437d70b3db7a56211a43aa1632306711b2d" dependencies = [ "zbus 5.11.0", ] @@ -1251,6 +1265,7 @@ dependencies = [ "cosmic-comp-config", "cosmic-config", "cosmic-freedesktop-icons", + "cosmic-panel-config", "delegate", "env_logger", "futures-channel", @@ -1494,7 +1509,7 @@ dependencies = [ "libc", "option-ext", "redox_users 0.5.2", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -1715,7 +1730,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.60.2", ] [[package]] @@ -2547,7 +2562,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic#e83e43bf1e38476e79383b299668afa525bad3e9" +source = "git+https://github.com/pop-os/libcosmic#6439507aa2d8d7e6a89c0fc016895dc0ab9252d4" dependencies = [ "bitflags 2.9.4", "bytes", @@ -2571,7 +2586,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic#e83e43bf1e38476e79383b299668afa525bad3e9" +source = "git+https://github.com/pop-os/libcosmic#6439507aa2d8d7e6a89c0fc016895dc0ab9252d4" dependencies = [ "futures", "iced_core", @@ -3240,7 +3255,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.53.3", ] [[package]] @@ -3662,7 +3677,7 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" dependencies = [ - "proc-macro-crate 3.3.0", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 2.0.106", @@ -4782,7 +4797,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.11.0", - "windows-sys 0.52.0", + "windows-sys 0.60.2", ] [[package]] @@ -5309,7 +5324,7 @@ dependencies = [ "getrandom 0.3.3", "once_cell", "rustix 1.1.2", - "windows-sys 0.52.0", + "windows-sys 0.60.2", ] [[package]] @@ -6226,7 +6241,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.60.2", ] [[package]] @@ -6817,6 +6832,15 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "xdg-shell-wrapper-config" +version = "0.1.0" +source = "git+https://github.com/pop-os/cosmic-panel?branch=workspaces-panel#b6031b084477a961370b6a3c6aefc364c483636e" +dependencies = [ + "serde", + "wayland-protocols-wlr", +] + [[package]] name = "xkbcommon" version = "0.7.0" diff --git a/Cargo.toml b/Cargo.toml index 25b4ec3..f08fe0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,8 @@ zbus = "5.9.0" tokio-stream = { version = "0.1.17", features = ["sync"] } ash = { version = "0.38.0", features = ["loaded"] } bytemuck = "1.23.2" +# cosmic-panel-config = { git = "https://github.com/pop-os/cosmic-panel" } +cosmic-panel-config = { git = "https://github.com/pop-os/cosmic-panel", branch = "workspaces-panel", features = ["wayland-rs"] } [dependencies.i18n-embed] version = "0.16" diff --git a/src/main.rs b/src/main.rs index e58c446..1628552 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,9 @@ use cosmic::{ }; use cosmic_comp_config::CosmicCompConfig; use cosmic_config::{CosmicConfigEntry, cosmic_config_derive::CosmicConfigEntry}; +use cosmic_panel_config::{ + CosmicPanelConfig, CosmicPanelContainerConfig, CosmicPanelContainerConfigEntry, +}; use i18n_embed::DesktopLanguageRequester; use std::{ collections::{HashMap, HashSet}, @@ -196,6 +199,7 @@ struct App { drop_target: Option, scroll: Option<(f32, Instant)>, dbus_interface: Option, + panel_config: CosmicPanelContainerConfig, } #[derive(Debug, Default)] @@ -271,6 +275,8 @@ impl App { fn show(&mut self) -> Task> { if !self.visible { + //dbg!(&self.panel_regions()); + self.visible = true; let outputs = self.outputs.clone(); let cmd = Task::batch( @@ -348,6 +354,80 @@ impl App { self.capture_filter = capture_filter.clone(); self.send_wayland_cmd(backend::Cmd::CaptureFilter(capture_filter)); } + + // TODO: iinput region when it doesn't extend to edge? + fn panel_regions(&self, output_handle: &wl_output::WlOutput) -> PanelRegions { + let Some(output) = self.outputs.iter().find(|o| o.handle == *output_handle) else { + return PanelRegions::default(); + }; + + use cosmic_panel_config::PanelAnchor; + let mut regions = PanelRegions::default(); + // TODO: also use overlap notify if present? + for config in &self.panel_config.config_list { + /* + &config.exclusive_zone; + &config.autohide; + &config.size; + &config.anchor; + */ + if config.autohide.is_some() && !config.exclusive_zone { + /* + let output_dims = self + .output + .as_ref() + .and_then(|(_, _, info)| { + info.modes.iter().find_map(|m| if m.current { Some(m.dimensions) } else { None }) + }) + .map(|(w, h)| (w as u32, h as u32)); + */ + + // XXX right way to get size in px of pane? + let dimention_constraints = config.get_dimensions( + Some((output.width as u32, output.height as u32)), + None, + Some(config.get_effective_anchor_gap()), + ); + let size = + config.size.get_applet_icon_size_with_padding(true) + u32::from(config.margin); + match config.anchor { + PanelAnchor::Left => { + let size = dimention_constraints.0.map_or(size, |constraints| { + size.clamp(constraints.start, constraints.end) + }); + regions.left += size; + } + PanelAnchor::Right => { + let size = dimention_constraints.0.map_or(size, |constraints| { + size.clamp(constraints.start, constraints.end) + }); + regions.right += size; + } + PanelAnchor::Top => { + let size = dimention_constraints.1.map_or(size, |constraints| { + size.clamp(constraints.start, constraints.end) + }); + regions.top += size; + } + PanelAnchor::Bottom => { + let size = dimention_constraints.1.map_or(size, |constraints| { + size.clamp(constraints.start, constraints.end) + }); + regions.bottom += size; + } + } + } + } + regions + } +} + +#[derive(Debug, Default)] +struct PanelRegions { + top: u32, + bottom: u32, + left: u32, + right: u32, } impl Application for App { @@ -360,6 +440,7 @@ impl Application for App { ( Self { core, + panel_config: CosmicPanelContainerConfig::load().unwrap(), // TODO watch for changes ..Default::default() }, Task::none(), @@ -870,3 +951,24 @@ pub fn main() -> iced::Result { Args::parse(), ) } + +fn f() -> Subscription { + let mut subscriptions = vec![ + cosmic_config::config_subscription::<_, CosmicPanelContainerConfigEntry>( + "panel-config-subscription", + "com.system76.CosmicPanel".into(), + 1, + ) + .map(|update| { + // update.errors; + dbg!(update.config); + todo!() + }), + ]; + cosmic_config::config_subscription::<_, CosmicPanelConfig>( + "panel-config-subscription-Panel", + "com.system76.CosmicPanel.Panel".into(), + 1, + ); + iced::Subscription::batch(subscriptions) +} diff --git a/src/view/mod.rs b/src/view/mod.rs index af280d9..a10fd00 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -150,6 +150,15 @@ pub(crate) fn layer_surface<'a>( .width(Length::Fill), ), }; + + let panel_regions = app.panel_regions(&surface.output); + let container = widget::container(container).padding(iced::Padding { + bottom: panel_regions.bottom as f32, + top: panel_regions.top as f32, + left: panel_regions.left as f32, + right: panel_regions.right as f32, + }); + let output = surface.output.clone(); widget::mouse_area(container) .on_scroll(move |delta| Msg::OnScroll(output.clone(), delta))