wip: use toplevel protocols
This commit is contained in:
parent
647a402206
commit
560ebc0bf5
20 changed files with 1073 additions and 623 deletions
|
|
@ -27,9 +27,9 @@ use wayland_client::{Connection, Dispatch, QueueHandle};
|
|||
use calloop::channel::*;
|
||||
|
||||
pub fn spawn_workspaces(tx: glib::Sender<State>) -> SyncSender<WorkspaceEvent> {
|
||||
let (workspaces_tx, mut workspaces_rx) = calloop::channel::sync_channel(100);
|
||||
let (workspaces_tx, workspaces_rx) = calloop::channel::sync_channel(100);
|
||||
|
||||
if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY")
|
||||
if let Ok(Ok(conn)) = std::env::var("WAYLAND_DISPLAY")
|
||||
.map_err(anyhow::Error::msg)
|
||||
.map(|display_str| {
|
||||
let mut socket_path = env::var_os("XDG_RUNTIME_DIR")
|
||||
|
|
@ -130,7 +130,7 @@ pub fn spawn_workspaces(tx: glib::Sender<State>) -> SyncSender<WorkspaceEvent> {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
eprintln!("ENV variable HOST_WAYLAND_DISPLAY is missing. Exiting...");
|
||||
eprintln!("ENV variable WAYLAND_DISPLAY is missing. Exiting...");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
|
|
@ -185,7 +185,7 @@ struct Workspace {
|
|||
|
||||
impl Dispatch<wl_registry::WlRegistry, ()> for State {
|
||||
fn event(
|
||||
&mut self,
|
||||
state: &mut Self,
|
||||
registry: &wl_registry::WlRegistry,
|
||||
event: wl_registry::Event,
|
||||
_: &(),
|
||||
|
|
@ -208,7 +208,7 @@ impl Dispatch<wl_registry::WlRegistry, ()> for State {
|
|||
(),
|
||||
)
|
||||
.unwrap();
|
||||
self.workspace_manager = Some(workspace_manager);
|
||||
state.workspace_manager = Some(workspace_manager);
|
||||
}
|
||||
"wl_output" => {
|
||||
registry.bind::<WlOutput, _, _>(name, 1, qh, ()).unwrap();
|
||||
|
|
@ -221,7 +221,7 @@ impl Dispatch<wl_registry::WlRegistry, ()> for State {
|
|||
|
||||
impl Dispatch<ZcosmicWorkspaceManagerV1, ()> for State {
|
||||
fn event(
|
||||
&mut self,
|
||||
state: &mut Self,
|
||||
_: &ZcosmicWorkspaceManagerV1,
|
||||
event: zcosmic_workspace_manager_v1::Event,
|
||||
_: &(),
|
||||
|
|
@ -230,14 +230,14 @@ impl Dispatch<ZcosmicWorkspaceManagerV1, ()> for State {
|
|||
) {
|
||||
match event {
|
||||
zcosmic_workspace_manager_v1::Event::WorkspaceGroup { workspace_group } => {
|
||||
self.workspace_groups.push(WorkspaceGroup {
|
||||
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 self.workspace_groups {
|
||||
for group in &mut state.workspace_groups {
|
||||
group.workspaces.sort_by(|w1, w2| {
|
||||
w1.coordinates.iter().zip(w2.coordinates.iter())
|
||||
.skip_while(|(coord1, coord2)| coord1 == coord2)
|
||||
|
|
@ -246,10 +246,10 @@ impl Dispatch<ZcosmicWorkspaceManagerV1, ()> for State {
|
|||
.unwrap_or(std::cmp::Ordering::Equal)
|
||||
});
|
||||
}
|
||||
let _ = self.tx.send(self.clone());
|
||||
let _ = state.tx.send(state.clone());
|
||||
}
|
||||
zcosmic_workspace_manager_v1::Event::Finished => {
|
||||
self.workspace_manager.take();
|
||||
state.workspace_manager.take();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -262,7 +262,7 @@ impl Dispatch<ZcosmicWorkspaceManagerV1, ()> for State {
|
|||
|
||||
impl Dispatch<ZcosmicWorkspaceGroupHandleV1, ()> for State {
|
||||
fn event(
|
||||
&mut self,
|
||||
state: &mut Self,
|
||||
group: &ZcosmicWorkspaceGroupHandleV1,
|
||||
event: zcosmic_workspace_group_handle_v1::Event,
|
||||
_: &(),
|
||||
|
|
@ -271,7 +271,7 @@ impl Dispatch<ZcosmicWorkspaceGroupHandleV1, ()> for State {
|
|||
) {
|
||||
match event {
|
||||
zcosmic_workspace_group_handle_v1::Event::OutputEnter { output } => {
|
||||
if let Some(group) = self
|
||||
if let Some(group) = state
|
||||
.workspace_groups
|
||||
.iter_mut()
|
||||
.find(|g| &g.workspace_group_handle == group)
|
||||
|
|
@ -280,14 +280,14 @@ impl Dispatch<ZcosmicWorkspaceGroupHandleV1, ()> for State {
|
|||
}
|
||||
}
|
||||
zcosmic_workspace_group_handle_v1::Event::OutputLeave { output } => {
|
||||
if let Some(group) = self.workspace_groups.iter_mut().find(|g| {
|
||||
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) = self
|
||||
if let Some(group) = state
|
||||
.workspace_groups
|
||||
.iter_mut()
|
||||
.find(|g| &g.workspace_group_handle == group)
|
||||
|
|
@ -301,12 +301,12 @@ impl Dispatch<ZcosmicWorkspaceGroupHandleV1, ()> for State {
|
|||
}
|
||||
}
|
||||
zcosmic_workspace_group_handle_v1::Event::Remove => {
|
||||
if let Some(group) = self
|
||||
if let Some(group) = state
|
||||
.workspace_groups
|
||||
.iter()
|
||||
.position(|g| &g.workspace_group_handle == group)
|
||||
{
|
||||
self.workspace_groups.remove(group);
|
||||
state.workspace_groups.remove(group);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
|
@ -320,7 +320,7 @@ impl Dispatch<ZcosmicWorkspaceGroupHandleV1, ()> for State {
|
|||
|
||||
impl Dispatch<ZcosmicWorkspaceHandleV1, ()> for State {
|
||||
fn event(
|
||||
&mut self,
|
||||
state: &mut Self,
|
||||
workspace: &ZcosmicWorkspaceHandleV1,
|
||||
event: zcosmic_workspace_handle_v1::Event,
|
||||
_: &(),
|
||||
|
|
@ -329,7 +329,7 @@ impl Dispatch<ZcosmicWorkspaceHandleV1, ()> for State {
|
|||
) {
|
||||
match event {
|
||||
zcosmic_workspace_handle_v1::Event::Name { name } => {
|
||||
if let Some(w) = self.workspace_groups.iter_mut().find_map(|g| {
|
||||
if let Some(w) = state.workspace_groups.iter_mut().find_map(|g| {
|
||||
g.workspaces
|
||||
.iter_mut()
|
||||
.find(|w| &w.workspace_handle == workspace)
|
||||
|
|
@ -338,7 +338,7 @@ impl Dispatch<ZcosmicWorkspaceHandleV1, ()> for State {
|
|||
}
|
||||
}
|
||||
zcosmic_workspace_handle_v1::Event::Coordinates { coordinates } => {
|
||||
if let Some(w) = self.workspace_groups.iter_mut().find_map(|g| {
|
||||
if let Some(w) = state.workspace_groups.iter_mut().find_map(|g| {
|
||||
g.workspaces
|
||||
.iter_mut()
|
||||
.find(|w| &w.workspace_handle == workspace)
|
||||
|
|
@ -347,18 +347,18 @@ impl Dispatch<ZcosmicWorkspaceHandleV1, ()> for State {
|
|||
w.coordinates = coordinates.chunks(4).map(|chunk| u32::from_ne_bytes(chunk.try_into().unwrap())).collect();
|
||||
}
|
||||
}
|
||||
zcosmic_workspace_handle_v1::Event::State { state } => {
|
||||
if let Some(w) = self.workspace_groups.iter_mut().find_map(|g| {
|
||||
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 = state.chunks(4).map(|chunk| zcosmic_workspace_handle_v1::State::try_from(u32::from_ne_bytes(chunk.try_into().unwrap())).unwrap()).collect();
|
||||
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)) = self.workspace_groups.iter_mut().find_map(|g| {
|
||||
if let Some((g, w_i)) = state.workspace_groups.iter_mut().find_map(|g| {
|
||||
g.workspaces
|
||||
.iter_mut()
|
||||
.position(|w| &w.workspace_handle == workspace)
|
||||
|
|
@ -374,7 +374,7 @@ impl Dispatch<ZcosmicWorkspaceHandleV1, ()> for State {
|
|||
|
||||
impl Dispatch<WlOutput, ()> for State {
|
||||
fn event(
|
||||
&mut self,
|
||||
state: &mut Self,
|
||||
o: &WlOutput,
|
||||
e: wl_output::Event,
|
||||
_: &(),
|
||||
|
|
@ -382,8 +382,8 @@ impl Dispatch<WlOutput, ()> for State {
|
|||
_: &QueueHandle<Self>,
|
||||
) {
|
||||
match e {
|
||||
wl_output::Event::Name { name } if name == self.configured_output => {
|
||||
self.expected_output.replace(o.clone());
|
||||
wl_output::Event::Name { name } if name == state.configured_output => {
|
||||
state.expected_output.replace(o.clone());
|
||||
}
|
||||
_ => {} // ignored
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue