stack: Ability to modify a stacks windows
This commit is contained in:
parent
a9e06741d4
commit
1d51da4ed3
1 changed files with 34 additions and 8 deletions
|
|
@ -95,15 +95,16 @@ pub enum Focus {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CosmicStack {
|
impl CosmicStack {
|
||||||
pub fn new(
|
pub fn new<I: Into<CosmicSurface>>(
|
||||||
window: impl Into<CosmicSurface>,
|
windows: impl Iterator<Item = I>,
|
||||||
handle: LoopHandle<'static, crate::state::Data>,
|
handle: LoopHandle<'static, crate::state::Data>,
|
||||||
) -> CosmicStack {
|
) -> CosmicStack {
|
||||||
let window = window.into();
|
let windows = windows.map(Into::into).collect::<Vec<_>>();
|
||||||
let width = window.geometry().size.w;
|
assert!(!windows.is_empty());
|
||||||
|
let width = windows[0].geometry().size.w;
|
||||||
CosmicStack(IcedElement::new(
|
CosmicStack(IcedElement::new(
|
||||||
CosmicStackInternal {
|
CosmicStackInternal {
|
||||||
windows: Arc::new(Mutex::new(vec![window])),
|
windows: Arc::new(Mutex::new(windows)),
|
||||||
active: Arc::new(AtomicUsize::new(0)),
|
active: Arc::new(AtomicUsize::new(0)),
|
||||||
previous_keyboard: Arc::new(AtomicUsize::new(0)),
|
previous_keyboard: Arc::new(AtomicUsize::new(0)),
|
||||||
pointer_entered: None,
|
pointer_entered: None,
|
||||||
|
|
@ -115,9 +116,34 @@ impl CosmicStack {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub fn add_window()
|
pub fn add_window(&self, window: CosmicSurface) {
|
||||||
//pub fn remove_window()
|
self.0
|
||||||
//pub fn len
|
.with_program(|p| p.windows.lock().unwrap().push(window));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_window(&self, window: &CosmicSurface) {
|
||||||
|
self.0.with_program(|p| {
|
||||||
|
let mut windows = p.windows.lock().unwrap();
|
||||||
|
let Some(idx) = windows.iter().position(|w| w == window) else { return };
|
||||||
|
windows.remove(idx);
|
||||||
|
p.active.fetch_min(windows.len() - 1, Ordering::SeqCst);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_idx(&self, idx: usize) {
|
||||||
|
self.0.with_program(|p| {
|
||||||
|
let mut windows = p.windows.lock().unwrap();
|
||||||
|
if windows.len() >= idx {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
windows.remove(idx);
|
||||||
|
p.active.fetch_min(windows.len(), Ordering::SeqCst);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.0.with_program(|p| p.windows.lock().unwrap().len())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn active(&self) -> CosmicSurface {
|
pub fn active(&self) -> CosmicSurface {
|
||||||
self.0
|
self.0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue