WIP way to activate workspace
This commit is contained in:
parent
347f2a7060
commit
65233e1a28
3 changed files with 63 additions and 29 deletions
12
Cargo.toml
12
Cargo.toml
|
|
@ -6,12 +6,8 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cctk = { package = "cosmic-client-toolkit", git = "https://github.com/pop-os/cosmic-protocols" }
|
cctk = { package = "cosmic-client-toolkit", git = "https://github.com/pop-os/cosmic-protocols" }
|
||||||
futures-channel = "0.3.25"
|
futures-channel = "0.3.25"
|
||||||
# iced = { git = "https://github.com/pop-os/libcosmic", features = ["tokio"] }
|
iced = { git = "https://github.com/pop-os/libcosmic", features = ["tokio", "wayland"] }
|
||||||
# iced_native = { git = "https://github.com/pop-os/libcosmic" }
|
iced_native = { git = "https://github.com/pop-os/libcosmic" }
|
||||||
# iced_sctk = { git = "https://github.com/pop-os/libcosmic" }
|
iced_sctk = { git = "https://github.com/pop-os/libcosmic" }
|
||||||
# libcosmic = { git = "https://github.com/pop-os/libcosmic" }
|
libcosmic = { git = "https://github.com/pop-os/libcosmic" }
|
||||||
iced = { path = "/home/ian/src/pop/libcosmic/iced", features = ["tokio"] }
|
|
||||||
iced_native = { path = "/home/ian/src/pop/libcosmic/iced/native" }
|
|
||||||
iced_sctk = { path = "/home/ian/src/pop/libcosmic/iced/sctk" }
|
|
||||||
libcosmic = { path = "/home/ian/src/pop/libcosmic" }
|
|
||||||
tokio = "1.23.0"
|
tokio = "1.23.0"
|
||||||
|
|
|
||||||
67
src/main.rs
67
src/main.rs
|
|
@ -1,16 +1,15 @@
|
||||||
use cctk::{
|
use cctk::{
|
||||||
cosmic_protocols::{
|
cosmic_protocols::{
|
||||||
toplevel_info::v1::client::zcosmic_toplevel_handle_v1,
|
toplevel_info::v1::client::zcosmic_toplevel_handle_v1,
|
||||||
workspace::v1::client::zcosmic_workspace_handle_v1,
|
workspace::v1::client::{zcosmic_workspace_handle_v1, zcosmic_workspace_manager_v1},
|
||||||
},
|
},
|
||||||
sctk::shell::layer::{Anchor, KeyboardInteractivity, Layer},
|
sctk::shell::layer::{Anchor, KeyboardInteractivity, Layer},
|
||||||
toplevel_info::ToplevelInfo,
|
toplevel_info::ToplevelInfo,
|
||||||
wayland_client::protocol::wl_output,
|
wayland_client::{protocol::wl_output, Connection, QueueHandle, WEnum},
|
||||||
};
|
};
|
||||||
use iced::{
|
use iced::{
|
||||||
event::wayland::{Event as WaylandEvent, OutputEvent},
|
event::wayland::{Event as WaylandEvent, OutputEvent},
|
||||||
keyboard::KeyCode,
|
keyboard::KeyCode,
|
||||||
sctk_settings::InitialSurface,
|
|
||||||
widget, Application, Command, Element, Subscription,
|
widget, Application, Command, Element, Subscription,
|
||||||
};
|
};
|
||||||
use iced_native::{
|
use iced_native::{
|
||||||
|
|
@ -20,8 +19,9 @@ use iced_native::{
|
||||||
use iced_sctk::{
|
use iced_sctk::{
|
||||||
application::SurfaceIdWrapper,
|
application::SurfaceIdWrapper,
|
||||||
commands::layer_surface::{destroy_layer_surface, get_layer_surface},
|
commands::layer_surface::{destroy_layer_surface, get_layer_surface},
|
||||||
|
settings::InitialSurface,
|
||||||
};
|
};
|
||||||
use std::{collections::HashMap, process};
|
use std::{collections::HashMap, mem, process};
|
||||||
|
|
||||||
mod wayland;
|
mod wayland;
|
||||||
|
|
||||||
|
|
@ -63,6 +63,10 @@ struct App {
|
||||||
layer_surfaces: HashMap<SurfaceId, LayerSurface>,
|
layer_surfaces: HashMap<SurfaceId, LayerSurface>,
|
||||||
workspaces: Vec<Workspace>,
|
workspaces: Vec<Workspace>,
|
||||||
toplevels: Vec<Toplevel>,
|
toplevels: Vec<Toplevel>,
|
||||||
|
workspace_manager: Option<(
|
||||||
|
Connection,
|
||||||
|
zcosmic_workspace_manager_v1::ZcosmicWorkspaceManagerV1,
|
||||||
|
)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
|
|
@ -84,6 +88,18 @@ impl App {
|
||||||
) -> Option<&mut Toplevel> {
|
) -> Option<&mut Toplevel> {
|
||||||
self.toplevels.iter_mut().find(|i| &i.handle == handle)
|
self.toplevels.iter_mut().find(|i| &i.handle == handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn layer_surface_for_output_name(
|
||||||
|
&mut self,
|
||||||
|
output_name: Option<&str>,
|
||||||
|
) -> Option<&mut LayerSurface> {
|
||||||
|
for surface in self.layer_surfaces.values_mut() {
|
||||||
|
if surface.output_name.as_deref() == output_name {
|
||||||
|
return Some(surface);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application for App {
|
impl Application for App {
|
||||||
|
|
@ -148,16 +164,36 @@ impl Application for App {
|
||||||
},
|
},
|
||||||
Msg::Wayland(evt) => {
|
Msg::Wayland(evt) => {
|
||||||
match evt {
|
match evt {
|
||||||
|
wayland::Event::WorkspaceManager(conn, manager) => {
|
||||||
|
self.workspace_manager = Some((conn, manager));
|
||||||
|
}
|
||||||
wayland::Event::Workspaces(workspaces) => {
|
wayland::Event::Workspaces(workspaces) => {
|
||||||
// XXX efficiency
|
let old_workspaces = mem::take(&mut self.workspaces);
|
||||||
// XXX removal
|
|
||||||
self.workspaces = Vec::new();
|
self.workspaces = Vec::new();
|
||||||
for (output_name, workspace) in workspaces {
|
for (output_name, workspace) in workspaces {
|
||||||
|
let is_active = workspace.state.contains(&WEnum::Value(
|
||||||
|
zcosmic_workspace_handle_v1::State::Active,
|
||||||
|
));
|
||||||
|
if is_active {
|
||||||
|
// XXX
|
||||||
|
if let Some(surface) =
|
||||||
|
self.layer_surface_for_output_name(output_name.as_deref())
|
||||||
|
{
|
||||||
|
surface.active_workspace = Some(workspace.handle.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX efficiency
|
||||||
|
let img = old_workspaces
|
||||||
|
.iter()
|
||||||
|
.find(|i| &i.handle == &workspace.handle)
|
||||||
|
.and_then(|i| i.img.clone());
|
||||||
|
|
||||||
self.workspaces.push(Workspace {
|
self.workspaces.push(Workspace {
|
||||||
name: workspace.name,
|
name: workspace.name,
|
||||||
handle: workspace.handle,
|
handle: workspace.handle,
|
||||||
output_name,
|
output_name,
|
||||||
img: None,
|
img,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -187,18 +223,11 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
Msg::Closed(_) => {}
|
Msg::Closed(_) => {}
|
||||||
Msg::ActivateWorkspace(workspace_handle) => {
|
Msg::ActivateWorkspace(workspace_handle) => {
|
||||||
// XXX
|
println!("Activate: {:?}", workspace_handle);
|
||||||
for workspace in &self.workspaces {
|
let (conn, workspace_manager) = self.workspace_manager.as_ref().unwrap();
|
||||||
if &workspace.handle == &workspace_handle {
|
workspace_handle.activate();
|
||||||
for surface in self.layer_surfaces.values_mut() {
|
workspace_manager.commit();
|
||||||
if &surface.output_name == &workspace.output_name {
|
conn.flush();
|
||||||
surface.active_workspace = Some(workspace_handle);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use cctk::{
|
||||||
cosmic_protocols::{
|
cosmic_protocols::{
|
||||||
screencopy::v1::client::{zcosmic_screencopy_manager_v1, zcosmic_screencopy_session_v1},
|
screencopy::v1::client::{zcosmic_screencopy_manager_v1, zcosmic_screencopy_session_v1},
|
||||||
toplevel_info::v1::client::zcosmic_toplevel_handle_v1,
|
toplevel_info::v1::client::zcosmic_toplevel_handle_v1,
|
||||||
workspace::v1::client::zcosmic_workspace_handle_v1,
|
workspace::v1::client::{zcosmic_workspace_handle_v1, zcosmic_workspace_manager_v1},
|
||||||
},
|
},
|
||||||
screencopy::{BufferInfo, ScreencopyHandler, ScreencopyState},
|
screencopy::{BufferInfo, ScreencopyHandler, ScreencopyState},
|
||||||
sctk::{
|
sctk::{
|
||||||
|
|
@ -39,6 +39,10 @@ use std::{collections::HashMap, thread};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
|
WorkspaceManager(
|
||||||
|
Connection,
|
||||||
|
zcosmic_workspace_manager_v1::ZcosmicWorkspaceManagerV1,
|
||||||
|
),
|
||||||
// XXX Output name rather than `WlOutput`
|
// XXX Output name rather than `WlOutput`
|
||||||
Workspaces(Vec<(Option<String>, cctk::workspace::Workspace)>),
|
Workspaces(Vec<(Option<String>, cctk::workspace::Workspace)>),
|
||||||
WorkspaceCapture(
|
WorkspaceCapture(
|
||||||
|
|
@ -70,7 +74,7 @@ struct Frame {
|
||||||
first_frame: bool,
|
first_frame: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AppData {
|
pub struct AppData {
|
||||||
qh: QueueHandle<Self>,
|
qh: QueueHandle<Self>,
|
||||||
output_state: OutputState,
|
output_state: OutputState,
|
||||||
registry_state: RegistryState,
|
registry_state: RegistryState,
|
||||||
|
|
@ -265,6 +269,7 @@ impl ScreencopyHandler for AppData {
|
||||||
session.commit(zcosmic_screencopy_session_v1::Options::empty());
|
session.commit(zcosmic_screencopy_session_v1::Options::empty());
|
||||||
} else {
|
} else {
|
||||||
session.commit(zcosmic_screencopy_session_v1::Options::OnDamage);
|
session.commit(zcosmic_screencopy_session_v1::Options::OnDamage);
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
conn.flush().unwrap();
|
conn.flush().unwrap();
|
||||||
|
|
||||||
|
|
@ -336,6 +341,10 @@ fn start() -> mpsc::Receiver<Event> {
|
||||||
output_names: HashMap::new(),
|
output_names: HashMap::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if let Ok(manager) = app_data.workspace_state.workspace_manager().get() {
|
||||||
|
app_data.send_event(Event::WorkspaceManager(conn, manager.clone()));
|
||||||
|
}
|
||||||
|
|
||||||
thread::spawn(move || loop {
|
thread::spawn(move || loop {
|
||||||
event_queue.blocking_dispatch(&mut app_data).unwrap();
|
event_queue.blocking_dispatch(&mut app_data).unwrap();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue