Skip to content
Draft
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
58 changes: 57 additions & 1 deletion cosmic-panel-bin/src/space/panel_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::{
};
use cctk::{
cosmic_protocols::overlap_notify::v1::client::zcosmic_overlap_notification_v1::ZcosmicOverlapNotificationV1,
wayland_client::Connection,
sctk::shell::wlr_layer::Layer, wayland_client::Connection,
};

use cosmic::iced::id;
Expand Down Expand Up @@ -89,6 +89,7 @@ use wayland_protocols::{
},
xdg::shell::client::xdg_positioner::ConstraintAdjustment,
};
use wayland_protocols_wlr::layer_shell::v1::client::zwlr_layer_shell_v1;

use cosmic_panel_config::{CosmicPanelBackground, CosmicPanelConfig, PanelAnchor};

Expand Down Expand Up @@ -301,6 +302,7 @@ pub struct PanelSharedState {
pub cosmic_workspaces: Option<CosmicWorkspaces>,
pub panel_tx: calloop::channel::Sender<PanelCalloopMsg>,
pub loop_handle: calloop::LoopHandle<'static, GlobalState>,
pub workspaces_shown: Cell<bool>,
}

// space for the cosmic panel
Expand Down Expand Up @@ -777,6 +779,10 @@ impl PanelSpace {

let intellihide = self.overlap_notify.is_some();

if self.shared.workspaces_shown.get() {
return;
}

let cur_hover = {
let c_focused_surface = self.shared.c_focused_surface.borrow();
let c_hovered_surface = self.shared.c_hovered_surface.borrow();
Expand Down Expand Up @@ -1015,6 +1021,56 @@ impl PanelSpace {
}
}

pub fn update_workspaces_shown(&mut self) {
let (layer_surface, _) = if let Some(layer_surface) = self.layer.as_ref() {
(layer_surface, layer_surface.wl_surface())
} else {
return;
};

// XXX only change if autohide?
if self.config.autohide.is_none() {
return;
}

if self.shared.workspaces_shown.get() {
self.transitioning = true;
self.is_dirty = true;
let panel_size =
if self.config().is_horizontal() { self.dimensions.h } else { self.dimensions.w };

/*
if self.config.exclusive_zone() {
layer_surface.set_exclusive_zone(panel_size);
}
*/

self.anchor_gap = 0;
self.visibility = Visibility::Visible;
Self::set_margin(
self.config.anchor,
self.config.get_margin() as i32,
self.additional_gap,
layer_surface,
);

layer_surface.set_layer(Layer::Overlay);
} else {
eprintln!("hidden");
let layer = match self.config().layer() {
zwlr_layer_shell_v1::Layer::Background => Layer::Background,
zwlr_layer_shell_v1::Layer::Bottom => Layer::Bottom,
zwlr_layer_shell_v1::Layer::Top => Layer::Top,
zwlr_layer_shell_v1::Layer::Overlay => Layer::Overlay,
_ => {
return;
},
};
layer_surface.set_layer(layer);
self.handle_focus();
}
}

fn set_margin(
anchor: PanelAnchor,
margin: i32,
Expand Down
27 changes: 26 additions & 1 deletion cosmic-panel-bin/src/space_container/space_container.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use std::{cell::RefCell, collections::HashMap, rc::Rc, sync::Arc};
use std::{
cell::{Cell, RefCell},
collections::HashMap,
rc::Rc,
sync::Arc,
};

use crate::{
PanelCalloopMsg,
Expand Down Expand Up @@ -92,6 +97,17 @@ impl SpaceContainer {
},
};

if let Some(cosmic_workspaces) = &cosmic_workspaces {
loop_handle.insert_source(
cosmic_workspaces.is_shown_event_source(),
move |event, (), state| {
if let calloop::channel::Event::Msg(value) = event {
state.space.update_workspaces_shown(value);
}
},
);
}

Self {
connection: None,
config,
Expand All @@ -117,6 +133,7 @@ impl SpaceContainer {
security_context_manager: RefCell::new(None),
loop_handle,
cosmic_workspaces,
workspaces_shown: Cell::new(false),
}),
}
}
Expand Down Expand Up @@ -567,4 +584,12 @@ impl SpaceContainer {
);
}
}

fn update_workspaces_shown(&mut self, shown: bool) {
dbg!(shown);
self.shared.workspaces_shown.set(shown);
for i in &mut self.space_list {
i.update_workspaces_shown();
}
}
}
13 changes: 13 additions & 0 deletions cosmic-panel-bin/src/workspaces_dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ impl CosmicWorkspaces {
.into_stream())
}

pub fn is_shown_event_source(&self) -> calloop::channel::Channel<bool> {
let (sender, channel) = calloop::channel::channel();
let workspaces = self.clone();
self.runtime.spawn(async move {
use futures::StreamExt;
let mut stream = workspaces.is_shown_stream().await.unwrap();
while let Some(value) = stream.next().await {
sender.send(value);
}
});
channel
}

pub fn hide(&self) {
let proxy = self.proxy.clone();
self.runtime.spawn(async move {
Expand Down