it works!
This commit is contained in:
parent
fb094e9e5d
commit
9338671070
2 changed files with 79 additions and 19 deletions
|
|
@ -11,22 +11,18 @@ pub struct Workspace {
|
|||
|
||||
pub fn listen_workspaces(sink: StreamSink<Vec<Workspace>>) -> Result<()> {
|
||||
std::thread::spawn(move || {
|
||||
// Connect to Wayland
|
||||
let conn = Connection::connect_to_env().expect("Failed to connect to Wayland");
|
||||
|
||||
let mut event_queue: EventQueue<AppState> = conn.new_event_queue();
|
||||
let qh = event_queue.handle();
|
||||
|
||||
// Initialize state
|
||||
let mut state = AppState {
|
||||
workspaces: HashMap::new(),
|
||||
sink,
|
||||
};
|
||||
|
||||
// Get registry (this triggers wl_registry events → binds manager)
|
||||
conn.display().get_registry(&qh, ());
|
||||
|
||||
// Main event loop
|
||||
loop {
|
||||
event_queue
|
||||
.blocking_dispatch(&mut state)
|
||||
|
|
|
|||
|
|
@ -1,21 +1,39 @@
|
|||
use crate::{frb_generated::StreamSink, workspace_api::Workspace};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use wayland_protocols::ext::workspace::v1::client::{
|
||||
ext_workspace_manager_v1,
|
||||
ext_workspace_handle_v1,
|
||||
use wayland_client::{
|
||||
self, Connection, Dispatch, QueueHandle, backend::ObjectId, event_created_child, protocol::wl_registry
|
||||
};
|
||||
use wayland_protocols::ext::workspace::v1::client::{
|
||||
ext_workspace_group_handle_v1, ext_workspace_handle_v1, ext_workspace_manager_v1,
|
||||
};
|
||||
use wayland_client::{self, Connection, Dispatch, QueueHandle, event_created_child, protocol::wl_registry};
|
||||
|
||||
pub struct AppState {
|
||||
pub workspaces: HashMap<u32, Workspace>,
|
||||
pub workspaces: HashMap<ObjectId, Workspace>,
|
||||
pub sink: StreamSink<Vec<Workspace>>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
// fn emit(&self) {
|
||||
// let _ = self.sink.add(self.workspaces.values().cloned().collect());
|
||||
// }
|
||||
fn emit(&self) {
|
||||
let mut entries: Vec<(&ObjectId, &Workspace)> = self.workspaces.iter().collect();
|
||||
|
||||
entries.sort_by_key(
|
||||
|entry: &(&ObjectId, &Workspace)| -> u32 {
|
||||
entry.0.protocol_id()
|
||||
},
|
||||
);
|
||||
|
||||
let sorted: Vec<Workspace> = entries
|
||||
.into_iter()
|
||||
.map(
|
||||
|entry: (&ObjectId, &Workspace)| -> Workspace {
|
||||
entry.1.clone()
|
||||
},
|
||||
)
|
||||
.collect();
|
||||
|
||||
let _ = self.sink.add(sorted);
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<wl_registry::WlRegistry, ()> for AppState {
|
||||
|
|
@ -27,7 +45,7 @@ impl Dispatch<wl_registry::WlRegistry, ()> for AppState {
|
|||
_conn: &Connection,
|
||||
qh: &QueueHandle<Self>,
|
||||
) {
|
||||
if let wl_registry::Event::Global {
|
||||
if let wl_registry::Event::Global {
|
||||
name,
|
||||
interface,
|
||||
version,
|
||||
|
|
@ -56,11 +74,15 @@ impl Dispatch<ext_workspace_manager_v1::ExtWorkspaceManagerV1, ()> for AppState
|
|||
) {
|
||||
}
|
||||
|
||||
event_created_child!(
|
||||
event_created_child!(
|
||||
AppState,
|
||||
ext_workspace_manager_v1::ExtWorkspaceManagerV1,
|
||||
[
|
||||
_workspace => (
|
||||
wayland_protocols::ext::workspace::v1::client::ext_workspace_manager_v1::EVT_WORKSPACE_GROUP_OPCODE => (
|
||||
ext_workspace_group_handle_v1::ExtWorkspaceGroupHandleV1,
|
||||
()
|
||||
),
|
||||
wayland_protocols::ext::workspace::v1::client::ext_workspace_manager_v1::EVT_WORKSPACE_OPCODE => (
|
||||
ext_workspace_handle_v1::ExtWorkspaceHandleV1,
|
||||
()
|
||||
)
|
||||
|
|
@ -68,17 +90,59 @@ impl Dispatch<ext_workspace_manager_v1::ExtWorkspaceManagerV1, ()> for AppState
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
use wayland_client::Proxy;
|
||||
impl Dispatch<ext_workspace_handle_v1::ExtWorkspaceHandleV1, ()> for AppState {
|
||||
fn event(
|
||||
state: &mut Self,
|
||||
_proxy: &ext_workspace_handle_v1::ExtWorkspaceHandleV1,
|
||||
proxy: &ext_workspace_handle_v1::ExtWorkspaceHandleV1,
|
||||
event: ext_workspace_handle_v1::Event,
|
||||
_data: &(),
|
||||
_conn: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
) {
|
||||
println!("workspace event: {:?}", event);
|
||||
|
||||
match event {
|
||||
ext_workspace_handle_v1::Event::Id { id: _ } => {
|
||||
|
||||
state
|
||||
.workspaces
|
||||
.insert(proxy.id(), Workspace { activated: false });
|
||||
state.emit();
|
||||
}
|
||||
|
||||
ext_workspace_handle_v1::Event::State { state: flags } => {
|
||||
let active = matches!(
|
||||
flags,
|
||||
wayland_client::WEnum::Value(ext_workspace_handle_v1::State::Active)
|
||||
);
|
||||
|
||||
let id = proxy.id();
|
||||
|
||||
if let Some(ws) = state.workspaces.get_mut(&id) {
|
||||
ws.activated = active;
|
||||
}
|
||||
|
||||
state.emit();
|
||||
}
|
||||
|
||||
ext_workspace_handle_v1::Event::Removed => {
|
||||
state.workspaces.remove(&proxy.id());
|
||||
state.emit();
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<ext_workspace_group_handle_v1::ExtWorkspaceGroupHandleV1, ()> for AppState {
|
||||
fn event(
|
||||
_state: &mut Self,
|
||||
_proxy: &ext_workspace_group_handle_v1::ExtWorkspaceGroupHandleV1,
|
||||
_event: ext_workspace_group_handle_v1::Event,
|
||||
_data: &(),
|
||||
_conn: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
) {
|
||||
// println!("workspace GROUP event: {:?}", event);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue