Skip to content
Merged
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
10 changes: 5 additions & 5 deletions cosmic-panel-bin/src/space/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ impl PanelSpace {
self.minimize_applet_rect = new_rect;
self.last_minimize_update = Instant::now();
let output = self.output.as_ref().map(|o| o.1.name()).unwrap_or_default();
_ = self.panel_tx.send(crate::PanelCalloopMsg::MinimizeRect {
_ = self.shared.panel_tx.send(crate::PanelCalloopMsg::MinimizeRect {
output,
applet_info: MinimizeApplet {
priority: if is_dock { 1 } else { 0 },
Expand Down Expand Up @@ -781,7 +781,7 @@ impl PanelSpace {
w,
h,
radius,
self.loop_handle.clone(),
self.shared.loop_handle.clone(),
self.colors.theme.clone(),
self.space.id(),
loc,
Expand Down Expand Up @@ -997,7 +997,7 @@ impl PanelSpace {
},
popup_major,
popup_cross,
self.loop_handle.clone(),
self.shared.loop_handle.clone(),
self.colors.theme.clone(),
self.space.id(),
actual,
Expand Down Expand Up @@ -1304,7 +1304,7 @@ impl PanelSpace {
},
popup_major,
popup_cross,
self.loop_handle.clone(),
self.shared.loop_handle.clone(),
self.colors.theme.clone(),
self.space.id(),
count,
Expand Down Expand Up @@ -1351,7 +1351,7 @@ impl PanelSpace {
(padding as f32).into(),
Arc::new(AtomicBool::new(false)),
icon.into(),
self.loop_handle.clone(),
self.shared.loop_handle.clone(),
self.colors.theme.clone(),
self.space.id(),
);
Expand Down
2 changes: 1 addition & 1 deletion cosmic-panel-bin/src/space/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod render;
pub mod spacer;
mod wrapper_space;

pub(crate) use panel_space::{AppletMsg, PanelColors, PanelSpace};
pub(crate) use panel_space::{AppletMsg, PanelColors, PanelSharedState, PanelSpace};
pub(crate) use spacer::Spacer;

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion cosmic-panel-bin/src/space/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl PanelSpace {
return Ok(());
}

if let Some(cosmic_workspaces) = &self.cosmic_workspaces {
if let Some(cosmic_workspaces) = &self.shared.cosmic_workspaces {
cosmic_workspaces.hide();
}

Expand Down
55 changes: 27 additions & 28 deletions cosmic-panel-bin/src/space/panel_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,17 @@ pub enum HoverId {
Overflow(id::Id),
}

#[derive(Debug)]
pub struct PanelSharedState {
pub c_focused_surface: Rc<RefCell<ClientFocus>>,
pub c_hovered_surface: Rc<RefCell<ClientFocus>>,
pub applet_tx: mpsc::Sender<AppletMsg>,
pub security_context_manager: RefCell<Option<SecurityContextManager>>,
pub cosmic_workspaces: Option<CosmicWorkspaces>,
pub panel_tx: calloop::channel::Sender<PanelCalloopMsg>,
pub loop_handle: calloop::LoopHandle<'static, GlobalState>,
}

// space for the cosmic panel
#[derive(Debug)]
pub struct PanelSpace {
Expand Down Expand Up @@ -321,8 +332,6 @@ pub struct PanelSpace {
pub container_length: i32,
pub is_dirty: bool,
pub space_event: Rc<Cell<Option<SpaceEvent>>>,
pub c_focused_surface: Rc<RefCell<ClientFocus>>,
pub c_hovered_surface: Rc<RefCell<ClientFocus>>,
pub s_focused_surface: ServerFocus,
pub s_hovered_surface: ServerPtrFocus,
pub visibility: Visibility,
Expand All @@ -336,22 +345,17 @@ pub struct PanelSpace {
pub subsurfaces: Vec<WrapperSubsurface>,
pub start_instant: Instant,
pub colors: PanelColors,
pub applet_tx: mpsc::Sender<AppletMsg>,
pub input_region: Option<Region>,
pub has_frame: bool,
pub scale: f64,
pub security_context_manager: Option<SecurityContextManager>,
pub cosmic_workspaces: Option<CosmicWorkspaces>,
pub animate_state: Option<AnimateState>,
pub maximized: bool,
pub panel_tx: calloop::channel::Sender<PanelCalloopMsg>,
pub minimize_applet_rect: Rectangle<i32, Logical>,
pub scale_change_retries: u32,
/// Extra gap for stacked panels. Logical coordinate space.
pub additional_gap: i32,
/// Target gap for the panel on its anchored edge. Logical coordinate space.
pub anchor_gap: i32,
pub loop_handle: calloop::LoopHandle<'static, GlobalState>,
pub left_overflow_button_id: id::Id,
pub center_overflow_button_id: id::Id,
pub right_overflow_button_id: id::Id,
Expand All @@ -371,28 +375,24 @@ pub struct PanelSpace {
pub(crate) overlap_notify: Option<OverlapNotifyV1>,
pub(crate) hover_track: HoverTrack,
pub(crate) start_show_instant: Rc<RefCell<Option<Instant>>>,
pub shared: Rc<PanelSharedState>,
}

impl PanelSpace {
/// create a new space for the cosmic panel
pub fn new(
config: CosmicPanelConfig,
c_focused_surface: Rc<RefCell<ClientFocus>>,
c_hovered_surface: Rc<RefCell<ClientFocus>>,
applet_tx: mpsc::Sender<AppletMsg>,
shared: &Rc<PanelSharedState>,
theme: cosmic::Theme,
s_display: DisplayHandle,
security_context_manager: Option<SecurityContextManager>,
cosmic_workspaces: Option<CosmicWorkspaces>,
conn: &Connection,
panel_tx: calloop::channel::Sender<PanelCalloopMsg>,
loop_handle: calloop::LoopHandle<'static, GlobalState>,
) -> Self {
let name = format!("{}-{}", config.name, config.output);
let visibility =
if config.autohide.is_some() { Visibility::Hidden } else { Visibility::Visible };
Self {
config,
shared: shared.clone(),
space: Space::default(),
overflow_left: Space::default(),
overflow_center: Space::default(),
Expand All @@ -416,28 +416,21 @@ impl PanelSpace {
subsurfaces: Default::default(),
visibility,
start_instant: Instant::now(),
c_focused_surface,
c_hovered_surface,
s_focused_surface: Default::default(),
s_hovered_surface: Default::default(),
colors: PanelColors::new(theme),
applet_tx,
actual_size: (0, 0).into(),
input_region: None,
damage_tracked_renderer: None,
is_dirty: false,
has_frame: true,
scale: 1.0,
security_context_manager,
cosmic_workspaces,
animate_state: None,
maximized: false,
panel_tx,
minimize_applet_rect: Default::default(),
container_length: 0,
scale_change_retries: 0,
additional_gap: 0,
loop_handle,
left_overflow_button_id: id::Id::new(format!("{}-left-overflow-button", name)),
center_overflow_button_id: id::Id::new(format!("{}-center-overflow-button", name)),
right_overflow_button_id: id::Id::new(format!("{}-right-overflow-button", name)),
Expand Down Expand Up @@ -782,9 +775,11 @@ impl PanelSpace {
return;
};

let intellihide = self.overlap_notify.is_some();

let cur_hover = {
let c_focused_surface = self.c_focused_surface.borrow();
let c_hovered_surface = self.c_hovered_surface.borrow();
let c_focused_surface = self.shared.c_focused_surface.borrow();
let c_hovered_surface = self.shared.c_hovered_surface.borrow();
// no transition if not configured for autohide
let no_hover_focus =
c_focused_surface.iter().all(|f| matches!(f.2, FocusStatus::LastFocused(_)))
Expand All @@ -799,7 +794,7 @@ impl PanelSpace {
};

let f = c_hovered_surface.iter().fold(
if self.animate_state.is_some() || !self.has_toplevel_overlap() {
if self.animate_state.is_some() || (intellihide && !self.has_toplevel_overlap()) {
FocusStatus::Focused
} else {
FocusStatus::LastFocused(self.start_instant)
Expand Down Expand Up @@ -1126,7 +1121,9 @@ impl PanelSpace {
}
self.is_dirty = true;
self.additional_gap = gap;
if (!self.has_toplevel_overlap() || matches!(self.visibility, Visibility::Visible))
let intellihide = self.overlap_notify.is_some();
if ((intellihide && !self.has_toplevel_overlap())
|| matches!(self.visibility, Visibility::Visible))
&& !matches!(
self.space_event.as_ref().get(),
Some(SpaceEvent::WaitConfigure { first, .. }) if first
Expand Down Expand Up @@ -1233,10 +1230,12 @@ impl PanelSpace {
if let Some(w) = p.popup.viewport.as_ref() {
w.destroy();
}
self.c_focused_surface
self.shared
.c_focused_surface
.borrow_mut()
.retain(|s| s.0 != *p.popup.c_popup.wl_surface());
self.c_hovered_surface
self.shared
.c_hovered_surface
.borrow_mut()
.retain(|s| s.0 != *p.popup.c_popup.wl_surface());
self.s_focused_surface.retain(|s| {
Expand Down Expand Up @@ -1942,7 +1941,7 @@ impl PanelSpace {
impl Drop for PanelSpace {
fn drop(&mut self) {
// request processes to stop
let _ = self.applet_tx.try_send(AppletMsg::Cleanup(self.id()));
let _ = self.shared.applet_tx.try_send(AppletMsg::Cleanup(self.id()));
self.clients_center.lock().unwrap().clear();
self.clients_left.lock().unwrap().clear();
self.clients_right.lock().unwrap().clear();
Expand Down
4 changes: 2 additions & 2 deletions cosmic-panel-bin/src/space/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ impl PanelSpace {
}

for (popup, surface, s_surface) in to_destroy {
self.c_focused_surface.borrow_mut().retain(|s| s.0 != surface);
self.c_hovered_surface.borrow_mut().retain(|s| s.0 != surface);
self.shared.c_focused_surface.borrow_mut().retain(|s| s.0 != surface);
self.shared.c_hovered_surface.borrow_mut().retain(|s| s.0 != surface);

if let Some(s_surface) = s_surface {
self.s_focused_surface
Expand Down
35 changes: 17 additions & 18 deletions cosmic-panel-bin/src/space/wrapper_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ impl WrapperSpace for PanelSpace {

/// get the client hovered surface of the space
fn get_client_hovered_surface(&self) -> Rc<RefCell<ClientFocus>> {
self.c_hovered_surface.clone()
self.shared.c_hovered_surface.clone()
}

/// get the client focused surface of the space
fn get_client_focused_surface(&self) -> Rc<RefCell<ClientFocus>> {
self.c_focused_surface.clone()
self.shared.c_focused_surface.clone()
}

fn add_window(&mut self, w: Window) {
Expand Down Expand Up @@ -602,7 +602,7 @@ impl WrapperSpace for PanelSpace {

fds.push(socket.into());
let display_handle = display.clone();
let applet_tx_clone = self.applet_tx.clone();
let applet_tx_clone = self.shared.applet_tx.clone();
let id_clone = panel_client.name.clone();
let id_clone_info = panel_client.name.clone();
let id_clone_err = panel_client.name.clone();
Expand Down Expand Up @@ -792,7 +792,7 @@ impl WrapperSpace for PanelSpace {

AppletMsg::NewProcess(self.id(), process.with_env(applet_env))
};
match self.applet_tx.try_send(msg) {
match self.shared.applet_tx.try_send(msg) {
Ok(_) => {},
Err(e) => error!("{e}"),
};
Expand Down Expand Up @@ -884,7 +884,7 @@ impl WrapperSpace for PanelSpace {
/// returns false to forward the button press, and true to intercept
fn handle_button(&mut self, seat_name: &str, press: bool) -> Option<SpaceTarget> {
if let Some(prev_foc) = {
let c_hovered_surface: &ClientFocus = &self.c_hovered_surface.borrow();
let c_hovered_surface: &ClientFocus = &self.shared.c_hovered_surface.borrow();

c_hovered_surface
.iter()
Expand Down Expand Up @@ -1150,12 +1150,12 @@ impl WrapperSpace for PanelSpace {
calloop::timer::TimeoutAction::Drop
};
if auto_hover_dur.as_millis() > 0 {
_ = self.loop_handle.insert_source(
_ = self.shared.loop_handle.insert_source(
Timer::from_duration(auto_hover_dur),
move |_, _, data| on_autohover(data),
);
} else {
_ = self.loop_handle.insert_idle(move |data| {
_ = self.shared.loop_handle.insert_idle(move |data| {
_ = on_autohover(data);
});
}
Expand Down Expand Up @@ -1308,13 +1308,13 @@ impl WrapperSpace for PanelSpace {
calloop::timer::TimeoutAction::Drop
};
if auto_hover_dur.as_millis() > 0 {
_ = self
.loop_handle
.insert_source(Timer::from_duration(auto_hover_dur), move |_, _, data| {
on_autohover(data)
});
_ =
self.shared.loop_handle.insert_source(
Timer::from_duration(auto_hover_dur),
move |_, _, data| on_autohover(data),
);
} else {
_ = self.loop_handle.insert_idle(move |data| {
_ = self.shared.loop_handle.insert_idle(move |data| {
_ = on_autohover(data);
});
}
Expand Down Expand Up @@ -1585,11 +1585,10 @@ impl WrapperSpace for PanelSpace {
self.right_overflow_popup_id = id::Id::new(format!("right_overflow_popup_{}", self.id()));
self.center_overflow_popup_id = id::Id::new(format!("center_overflow_popup_{}", self.id()));

if let Err(err) = self.spawn_clients(
self.s_display.clone().unwrap(),
qh,
self.security_context_manager.clone(),
) {
let security_context_manager = self.shared.security_context_manager.borrow().clone();
if let Err(err) =
self.spawn_clients(self.s_display.clone().unwrap(), qh, security_context_manager)
{
error!(?err, "Failed to spawn clients");
}
Ok(())
Expand Down
Loading