Use cosmic-client-toolkit helpers in workspace applet
This commit is contained in:
parent
442e59073f
commit
27e19828fd
3 changed files with 129 additions and 299 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -624,6 +624,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"calloop",
|
"calloop",
|
||||||
|
"cosmic-client-toolkit",
|
||||||
"cosmic-protocols",
|
"cosmic-protocols",
|
||||||
"futures",
|
"futures",
|
||||||
"i18n-embed",
|
"i18n-embed",
|
||||||
|
|
@ -634,7 +635,6 @@ dependencies = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"pretty_env_logger",
|
"pretty_env_logger",
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
"smithay-client-toolkit",
|
|
||||||
"wayland-backend",
|
"wayland-backend",
|
||||||
"wayland-client",
|
"wayland-client",
|
||||||
"xdg",
|
"xdg",
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet"] }
|
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet"] }
|
||||||
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", rev = "3776d4a" }
|
cosmic-client-toolkit = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false }
|
||||||
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false, features = ["client"] }
|
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false, features = ["client"] }
|
||||||
wayland-backend = {version = "0.1.0-beta.14", features = ["client_system"]}
|
wayland-backend = {version = "0.1.0-beta.14", features = ["client_system"]}
|
||||||
wayland-client = {version = "0.30.0-beta.14"}
|
wayland-client = {version = "0.30.0-beta.14"}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,24 @@
|
||||||
use calloop::channel::*;
|
use calloop::channel::*;
|
||||||
use cosmic::applet::cosmic_panel_config::CosmicPanelOuput;
|
use cosmic::applet::cosmic_panel_config::CosmicPanelOuput;
|
||||||
use cosmic_protocols::workspace::v1::client::{
|
use cosmic_client_toolkit::{
|
||||||
zcosmic_workspace_group_handle_v1::{self, ZcosmicWorkspaceGroupHandleV1},
|
sctk::{
|
||||||
zcosmic_workspace_handle_v1::{self, ZcosmicWorkspaceHandleV1},
|
self,
|
||||||
zcosmic_workspace_manager_v1::{self, ZcosmicWorkspaceManagerV1},
|
event_loop::WaylandSource,
|
||||||
|
output::{OutputHandler, OutputState},
|
||||||
|
registry::{ProvidesRegistryState, RegistryState},
|
||||||
|
},
|
||||||
|
workspace::{WorkspaceHandler, WorkspaceState},
|
||||||
};
|
};
|
||||||
|
use cosmic_protocols::workspace::v1::client::zcosmic_workspace_handle_v1;
|
||||||
use futures::{channel::mpsc, executor::block_on, SinkExt};
|
use futures::{channel::mpsc, executor::block_on, SinkExt};
|
||||||
use sctk::event_loop::WaylandSource;
|
|
||||||
use std::{env, os::unix::net::UnixStream, path::PathBuf, str::FromStr, time::Duration};
|
use std::{env, os::unix::net::UnixStream, path::PathBuf, str::FromStr, time::Duration};
|
||||||
use wayland_backend::client::ObjectId;
|
use wayland_backend::client::ObjectId;
|
||||||
use wayland_client::{
|
use wayland_client::{
|
||||||
event_created_child,
|
globals::registry_queue_init,
|
||||||
protocol::{
|
protocol::wl_output::{self, WlOutput},
|
||||||
wl_output::{self, WlOutput},
|
|
||||||
wl_registry::{self, WlRegistry},
|
|
||||||
},
|
|
||||||
ConnectError, Proxy,
|
ConnectError, Proxy,
|
||||||
};
|
};
|
||||||
use wayland_client::{Connection, Dispatch, QueueHandle};
|
use wayland_client::{Connection, QueueHandle, WEnum};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum WorkspaceEvent {
|
pub enum WorkspaceEvent {
|
||||||
|
|
@ -42,7 +43,7 @@ pub fn spawn_workspaces(tx: mpsc::Sender<WorkspaceList>) -> SyncSender<Workspace
|
||||||
.and_then(|s| s.map(|s| Connection::from_socket(s).map_err(anyhow::Error::msg)))
|
.and_then(|s| s.map(|s| Connection::from_socket(s).map_err(anyhow::Error::msg)))
|
||||||
{
|
{
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let output = std::env::var("COSMIC_PANEL_OUTPUT")
|
let configured_output = std::env::var("COSMIC_PANEL_OUTPUT")
|
||||||
.ok()
|
.ok()
|
||||||
.map(|output_str| match CosmicPanelOuput::from_str(&output_str) {
|
.map(|output_str| match CosmicPanelOuput::from_str(&output_str) {
|
||||||
Ok(CosmicPanelOuput::Name(name)) => name,
|
Ok(CosmicPanelOuput::Name(name)) => name,
|
||||||
|
|
@ -51,7 +52,7 @@ pub fn spawn_workspaces(tx: mpsc::Sender<WorkspaceList>) -> SyncSender<Workspace
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let mut event_loop = calloop::EventLoop::<State>::try_new().unwrap();
|
let mut event_loop = calloop::EventLoop::<State>::try_new().unwrap();
|
||||||
let loop_handle = event_loop.handle();
|
let loop_handle = event_loop.handle();
|
||||||
let event_queue = conn.new_event_queue::<State>();
|
let (globals, event_queue) = registry_queue_init(&conn).unwrap();
|
||||||
let qhandle = event_queue.handle();
|
let qhandle = event_queue.handle();
|
||||||
|
|
||||||
WaylandSource::new(event_queue)
|
WaylandSource::new(event_queue)
|
||||||
|
|
@ -59,43 +60,56 @@ pub fn spawn_workspaces(tx: mpsc::Sender<WorkspaceList>) -> SyncSender<Workspace
|
||||||
.insert(loop_handle)
|
.insert(loop_handle)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let display = conn.display();
|
let registry_state = RegistryState::new(&globals);
|
||||||
display.get_registry(&qhandle, ());
|
|
||||||
|
|
||||||
let mut state = State {
|
let mut state = State {
|
||||||
outputs_to_handle: Default::default(),
|
// Must be before `WorkspaceState`
|
||||||
wm_name: None,
|
output_state: OutputState::new(&globals, &qhandle),
|
||||||
workspace_manager: None,
|
configured_output,
|
||||||
workspace_groups: Vec::new(),
|
workspace_state: WorkspaceState::new(®istry_state, &qhandle),
|
||||||
configured_output: output,
|
registry_state,
|
||||||
expected_output: None,
|
expected_output: None,
|
||||||
tx,
|
tx,
|
||||||
running: true,
|
running: true,
|
||||||
|
have_workspaces: false,
|
||||||
};
|
};
|
||||||
let loop_handle = event_loop.handle();
|
let loop_handle = event_loop.handle();
|
||||||
loop_handle
|
loop_handle
|
||||||
.insert_source(workspaces_rx, |e, _, state| match e {
|
.insert_source(workspaces_rx, |e, _, state| match e {
|
||||||
Event::Msg(WorkspaceEvent::Activate(id)) => {
|
Event::Msg(WorkspaceEvent::Activate(id)) => {
|
||||||
if let Some(w) = state.workspace_groups.iter().find_map(|g| {
|
if let Some(w) = state
|
||||||
g.workspaces.iter().find(|w| w.workspace_handle.id() == id)
|
.workspace_state
|
||||||
}) {
|
.workspace_groups()
|
||||||
w.workspace_handle.activate();
|
.iter()
|
||||||
state.workspace_manager.as_ref().unwrap().commit();
|
.find_map(|g| g.workspaces.iter().find(|w| w.handle.id() == id))
|
||||||
|
{
|
||||||
|
w.handle.activate();
|
||||||
|
state
|
||||||
|
.workspace_state
|
||||||
|
.workspace_manager()
|
||||||
|
.get()
|
||||||
|
.unwrap()
|
||||||
|
.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Msg(WorkspaceEvent::Scroll(v)) => {
|
Event::Msg(WorkspaceEvent::Scroll(v)) => {
|
||||||
if let Some((w_g, w_i)) = state.workspace_groups.iter().find_map(|g| {
|
if let Some((w_g, w_i)) = state
|
||||||
if g.output != state.expected_output {
|
.workspace_state
|
||||||
return None;
|
.workspace_groups()
|
||||||
}
|
.iter()
|
||||||
g.workspaces
|
.find_map(|g| {
|
||||||
.iter()
|
if g.output != state.expected_output {
|
||||||
.position(|w| {
|
return None;
|
||||||
w.states
|
}
|
||||||
.contains(&zcosmic_workspace_handle_v1::State::Active)
|
g.workspaces
|
||||||
})
|
.iter()
|
||||||
.map(|w_i| (g, w_i))
|
.position(|w| {
|
||||||
}) {
|
w.state.contains(&WEnum::Value(
|
||||||
|
zcosmic_workspace_handle_v1::State::Active,
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.map(|w_i| (g, w_i))
|
||||||
|
})
|
||||||
|
{
|
||||||
let max_w = w_g.workspaces.len().wrapping_sub(1);
|
let max_w = w_g.workspaces.len().wrapping_sub(1);
|
||||||
let d_i = if v > 0.0 {
|
let d_i = if v > 0.0 {
|
||||||
if w_i == max_w {
|
if w_i == max_w {
|
||||||
|
|
@ -111,15 +125,22 @@ pub fn spawn_workspaces(tx: mpsc::Sender<WorkspaceList>) -> SyncSender<Workspace
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Some(w) = w_g.workspaces.get(d_i) {
|
if let Some(w) = w_g.workspaces.get(d_i) {
|
||||||
w.workspace_handle.activate();
|
w.handle.activate();
|
||||||
state.workspace_manager.as_ref().unwrap().commit();
|
state
|
||||||
|
.workspace_state
|
||||||
|
.workspace_manager()
|
||||||
|
.get()
|
||||||
|
.unwrap()
|
||||||
|
.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Closed => {
|
Event::Closed => {
|
||||||
if let Some(workspace_manager) = &mut state.workspace_manager {
|
if let Ok(workspace_manager) =
|
||||||
for g in &mut state.workspace_groups {
|
state.workspace_state.workspace_manager().get()
|
||||||
g.workspace_group_handle.destroy();
|
{
|
||||||
|
for g in state.workspace_state.workspace_groups() {
|
||||||
|
g.handle.destroy();
|
||||||
}
|
}
|
||||||
workspace_manager.stop();
|
workspace_manager.stop();
|
||||||
}
|
}
|
||||||
|
|
@ -140,44 +161,52 @@ pub fn spawn_workspaces(tx: mpsc::Sender<WorkspaceList>) -> SyncSender<Workspace
|
||||||
workspaces_tx
|
workspaces_tx
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug)]
|
||||||
pub struct State {
|
pub struct State {
|
||||||
outputs_to_handle: Option<Vec<WlOutput>>,
|
|
||||||
wm_name: Option<(u32, WlRegistry)>,
|
|
||||||
running: bool,
|
running: bool,
|
||||||
tx: mpsc::Sender<WorkspaceList>,
|
tx: mpsc::Sender<WorkspaceList>,
|
||||||
configured_output: String,
|
configured_output: String,
|
||||||
expected_output: Option<WlOutput>,
|
expected_output: Option<WlOutput>,
|
||||||
workspace_manager: Option<ZcosmicWorkspaceManagerV1>,
|
output_state: OutputState,
|
||||||
workspace_groups: Vec<WorkspaceGroup>,
|
registry_state: RegistryState,
|
||||||
|
workspace_state: WorkspaceState,
|
||||||
|
have_workspaces: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
// XXX
|
|
||||||
pub fn workspace_list(
|
pub fn workspace_list(
|
||||||
&self,
|
&self,
|
||||||
) -> Vec<(String, Option<zcosmic_workspace_handle_v1::State>, ObjectId)> {
|
) -> Vec<(String, Option<zcosmic_workspace_handle_v1::State>, ObjectId)> {
|
||||||
self.workspace_groups
|
self.workspace_state
|
||||||
|
.workspace_groups()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|g| {
|
.filter_map(|g| {
|
||||||
// TODO remove none check when workspace groups receive output event
|
if g.output == self.expected_output {
|
||||||
if g.output.is_none() || g.output == self.expected_output {
|
|
||||||
Some(g.workspaces.iter().map(|w| {
|
Some(g.workspaces.iter().map(|w| {
|
||||||
(
|
(
|
||||||
w.name.clone(),
|
w.name.clone(),
|
||||||
match &w.states {
|
match &w.state {
|
||||||
x if x.contains(&zcosmic_workspace_handle_v1::State::Active) => {
|
x if x.contains(&WEnum::Value(
|
||||||
|
zcosmic_workspace_handle_v1::State::Active,
|
||||||
|
)) =>
|
||||||
|
{
|
||||||
Some(zcosmic_workspace_handle_v1::State::Active)
|
Some(zcosmic_workspace_handle_v1::State::Active)
|
||||||
}
|
}
|
||||||
x if x.contains(&zcosmic_workspace_handle_v1::State::Urgent) => {
|
x if x.contains(&WEnum::Value(
|
||||||
|
zcosmic_workspace_handle_v1::State::Urgent,
|
||||||
|
)) =>
|
||||||
|
{
|
||||||
Some(zcosmic_workspace_handle_v1::State::Urgent)
|
Some(zcosmic_workspace_handle_v1::State::Urgent)
|
||||||
}
|
}
|
||||||
x if x.contains(&zcosmic_workspace_handle_v1::State::Hidden) => {
|
x if x.contains(&WEnum::Value(
|
||||||
|
zcosmic_workspace_handle_v1::State::Hidden,
|
||||||
|
)) =>
|
||||||
|
{
|
||||||
Some(zcosmic_workspace_handle_v1::State::Hidden)
|
Some(zcosmic_workspace_handle_v1::State::Hidden)
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
w.workspace_handle.id(),
|
w.handle.id(),
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -189,260 +218,61 @@ impl State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
impl ProvidesRegistryState for State {
|
||||||
struct WorkspaceGroup {
|
fn registry(&mut self) -> &mut RegistryState {
|
||||||
workspace_group_handle: ZcosmicWorkspaceGroupHandleV1,
|
&mut self.registry_state
|
||||||
output: Option<WlOutput>,
|
}
|
||||||
workspaces: Vec<Workspace>,
|
sctk::registry_handlers![OutputState,];
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
impl OutputHandler for State {
|
||||||
pub struct Workspace {
|
fn output_state(&mut self) -> &mut OutputState {
|
||||||
workspace_handle: ZcosmicWorkspaceHandleV1,
|
&mut self.output_state
|
||||||
name: String,
|
}
|
||||||
coordinates: Vec<u32>,
|
|
||||||
states: Vec<zcosmic_workspace_handle_v1::State>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Dispatch<wl_registry::WlRegistry, ()> for State {
|
fn new_output(
|
||||||
fn event(
|
&mut self,
|
||||||
state: &mut Self,
|
_conn: &Connection,
|
||||||
registry: &wl_registry::WlRegistry,
|
_qh: &QueueHandle<Self>,
|
||||||
event: wl_registry::Event,
|
output: wl_output::WlOutput,
|
||||||
_: &(),
|
|
||||||
_: &Connection,
|
|
||||||
qh: &QueueHandle<Self>,
|
|
||||||
) {
|
) {
|
||||||
if let wl_registry::Event::Global {
|
let info = self.output_state.info(&output).unwrap();
|
||||||
name,
|
if info.name.as_deref() == Some(&self.configured_output) {
|
||||||
interface,
|
self.expected_output = Some(output);
|
||||||
version: _version,
|
if self.have_workspaces {
|
||||||
} = event
|
let _ = block_on(self.tx.send(self.workspace_list()));
|
||||||
{
|
|
||||||
match &interface[..] {
|
|
||||||
"zcosmic_workspace_manager_v1" => {
|
|
||||||
if let Some(outputs_to_handle) = state.outputs_to_handle.as_ref() {
|
|
||||||
if outputs_to_handle.is_empty() {
|
|
||||||
let workspace_manager =
|
|
||||||
registry.bind::<ZcosmicWorkspaceManagerV1, _, _>(name, 1, qh, ());
|
|
||||||
state.workspace_manager = Some(workspace_manager);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// will be handled when outputs are done...
|
|
||||||
state.wm_name.replace((name, registry.clone()));
|
|
||||||
}
|
|
||||||
"wl_output" => {
|
|
||||||
let _output = registry.bind::<WlOutput, _, _>(name, 4, qh, ());
|
|
||||||
match state.outputs_to_handle.as_mut() {
|
|
||||||
Some(outputs_to_handle) => outputs_to_handle.push(_output),
|
|
||||||
None => {
|
|
||||||
state.outputs_to_handle.replace(vec![_output]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Dispatch<ZcosmicWorkspaceManagerV1, ()> for State {
|
fn update_output(
|
||||||
fn event(
|
&mut self,
|
||||||
state: &mut Self,
|
_conn: &Connection,
|
||||||
_: &ZcosmicWorkspaceManagerV1,
|
_qh: &QueueHandle<Self>,
|
||||||
event: zcosmic_workspace_manager_v1::Event,
|
_output: wl_output::WlOutput,
|
||||||
_: &(),
|
|
||||||
_: &Connection,
|
|
||||||
_: &QueueHandle<Self>,
|
|
||||||
) {
|
) {
|
||||||
match event {
|
|
||||||
zcosmic_workspace_manager_v1::Event::WorkspaceGroup { workspace_group } => {
|
|
||||||
state.workspace_groups.push(WorkspaceGroup {
|
|
||||||
workspace_group_handle: workspace_group,
|
|
||||||
output: None,
|
|
||||||
workspaces: Vec::new(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
zcosmic_workspace_manager_v1::Event::Done => {
|
|
||||||
for group in &mut state.workspace_groups {
|
|
||||||
group.workspaces.sort_by(|w1, w2| {
|
|
||||||
w1.coordinates
|
|
||||||
.iter()
|
|
||||||
.zip(w2.coordinates.iter())
|
|
||||||
.rev()
|
|
||||||
.skip_while(|(coord1, coord2)| coord1 == coord2)
|
|
||||||
.next()
|
|
||||||
.map(|(coord1, coord2)| coord1.cmp(coord2))
|
|
||||||
.unwrap_or(std::cmp::Ordering::Equal)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
let _ = block_on(state.tx.send(state.workspace_list()));
|
|
||||||
}
|
|
||||||
zcosmic_workspace_manager_v1::Event::Finished => {
|
|
||||||
state.workspace_manager.take();
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
event_created_child!(State, ZcosmicWorkspaceManagerV1, [
|
fn output_destroyed(
|
||||||
0 => (ZcosmicWorkspaceGroupHandleV1, ())
|
&mut self,
|
||||||
]);
|
_conn: &Connection,
|
||||||
}
|
_qh: &QueueHandle<Self>,
|
||||||
|
_output: wl_output::WlOutput,
|
||||||
impl Dispatch<ZcosmicWorkspaceGroupHandleV1, ()> for State {
|
|
||||||
fn event(
|
|
||||||
state: &mut Self,
|
|
||||||
group: &ZcosmicWorkspaceGroupHandleV1,
|
|
||||||
event: zcosmic_workspace_group_handle_v1::Event,
|
|
||||||
_: &(),
|
|
||||||
_: &Connection,
|
|
||||||
_: &QueueHandle<Self>,
|
|
||||||
) {
|
) {
|
||||||
match event {
|
|
||||||
zcosmic_workspace_group_handle_v1::Event::OutputEnter { output } => {
|
|
||||||
if let Some(group) = state
|
|
||||||
.workspace_groups
|
|
||||||
.iter_mut()
|
|
||||||
.find(|g| &g.workspace_group_handle == group)
|
|
||||||
{
|
|
||||||
group.output = Some(output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
zcosmic_workspace_group_handle_v1::Event::OutputLeave { output } => {
|
|
||||||
if let Some(group) = state.workspace_groups.iter_mut().find(|g| {
|
|
||||||
&g.workspace_group_handle == group && g.output.as_ref() == Some(&output)
|
|
||||||
}) {
|
|
||||||
group.output = None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
zcosmic_workspace_group_handle_v1::Event::Workspace { workspace } => {
|
|
||||||
if let Some(group) = state
|
|
||||||
.workspace_groups
|
|
||||||
.iter_mut()
|
|
||||||
.find(|g| &g.workspace_group_handle == group)
|
|
||||||
{
|
|
||||||
group.workspaces.push(Workspace {
|
|
||||||
workspace_handle: workspace,
|
|
||||||
name: String::new(),
|
|
||||||
coordinates: Vec::new(),
|
|
||||||
states: Vec::new(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
zcosmic_workspace_group_handle_v1::Event::Remove => {
|
|
||||||
if let Some(group) = state
|
|
||||||
.workspace_groups
|
|
||||||
.iter()
|
|
||||||
.position(|g| &g.workspace_group_handle == group)
|
|
||||||
{
|
|
||||||
state.workspace_groups.remove(group);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
event_created_child!(State, ZcosmicWorkspaceGroupHandleV1, [
|
|
||||||
3 => (ZcosmicWorkspaceHandleV1, ())
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Dispatch<ZcosmicWorkspaceHandleV1, ()> for State {
|
|
||||||
fn event(
|
|
||||||
state: &mut Self,
|
|
||||||
workspace: &ZcosmicWorkspaceHandleV1,
|
|
||||||
event: zcosmic_workspace_handle_v1::Event,
|
|
||||||
_: &(),
|
|
||||||
_: &Connection,
|
|
||||||
_: &QueueHandle<Self>,
|
|
||||||
) {
|
|
||||||
match event {
|
|
||||||
zcosmic_workspace_handle_v1::Event::Name { name } => {
|
|
||||||
if let Some(w) = state.workspace_groups.iter_mut().find_map(|g| {
|
|
||||||
g.workspaces
|
|
||||||
.iter_mut()
|
|
||||||
.find(|w| &w.workspace_handle == workspace)
|
|
||||||
}) {
|
|
||||||
w.name = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
zcosmic_workspace_handle_v1::Event::Coordinates { coordinates } => {
|
|
||||||
if let Some(w) = state.workspace_groups.iter_mut().find_map(|g| {
|
|
||||||
g.workspaces
|
|
||||||
.iter_mut()
|
|
||||||
.find(|w| &w.workspace_handle == workspace)
|
|
||||||
}) {
|
|
||||||
// wayland is host byte order
|
|
||||||
w.coordinates = coordinates
|
|
||||||
.chunks(4)
|
|
||||||
.map(|chunk| u32::from_ne_bytes(chunk.try_into().unwrap()))
|
|
||||||
.collect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
zcosmic_workspace_handle_v1::Event::State {
|
|
||||||
state: workspace_state,
|
|
||||||
} => {
|
|
||||||
if let Some(w) = state.workspace_groups.iter_mut().find_map(|g| {
|
|
||||||
g.workspaces
|
|
||||||
.iter_mut()
|
|
||||||
.find(|w| &w.workspace_handle == workspace)
|
|
||||||
}) {
|
|
||||||
// wayland is host byte order
|
|
||||||
w.states = workspace_state
|
|
||||||
.chunks(4)
|
|
||||||
.map(|chunk| {
|
|
||||||
zcosmic_workspace_handle_v1::State::try_from(u32::from_ne_bytes(
|
|
||||||
chunk.try_into().unwrap(),
|
|
||||||
))
|
|
||||||
.unwrap()
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
zcosmic_workspace_handle_v1::Event::Remove => {
|
|
||||||
if let Some((g, w_i)) = state.workspace_groups.iter_mut().find_map(|g| {
|
|
||||||
g.workspaces
|
|
||||||
.iter_mut()
|
|
||||||
.position(|w| &w.workspace_handle == workspace)
|
|
||||||
.map(|p| (g, p))
|
|
||||||
}) {
|
|
||||||
g.workspaces.remove(w_i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dispatch<WlOutput, ()> for State {
|
impl WorkspaceHandler for State {
|
||||||
fn event(
|
fn workspace_state(&mut self) -> &mut WorkspaceState {
|
||||||
state: &mut Self,
|
&mut self.workspace_state
|
||||||
o: &WlOutput,
|
}
|
||||||
e: wl_output::Event,
|
|
||||||
_: &(),
|
fn done(&mut self) {
|
||||||
_: &Connection,
|
self.have_workspaces = true;
|
||||||
qh: &QueueHandle<Self>,
|
let _ = block_on(self.tx.send(self.workspace_list()));
|
||||||
) {
|
|
||||||
match e {
|
|
||||||
wl_output::Event::Name { name } if name == state.configured_output => {
|
|
||||||
state.expected_output.replace(o.clone());
|
|
||||||
// Necessary bc often the output is handled after the workspaces
|
|
||||||
let _ = block_on(state.tx.send(state.workspace_list()));
|
|
||||||
}
|
|
||||||
wl_output::Event::Done => {
|
|
||||||
let outputs_to_handle = state.outputs_to_handle.as_mut().unwrap();
|
|
||||||
outputs_to_handle.retain(|o_to_handle| o != o_to_handle);
|
|
||||||
if outputs_to_handle.is_empty() {
|
|
||||||
if let Some((wm_name, registry)) = state.wm_name.as_ref() {
|
|
||||||
let workspace_manager =
|
|
||||||
registry.bind::<ZcosmicWorkspaceManagerV1, _, _>(*wm_name, 1, qh, ());
|
|
||||||
state.workspace_manager = Some(workspace_manager);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {} // ignored
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cosmic_client_toolkit::delegate_workspace!(State);
|
||||||
|
sctk::delegate_output!(State);
|
||||||
|
sctk::delegate_registry!(State);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue