From 61726ad3ccb5489948d38fd6764fbba479893ad1 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Wed, 4 Jan 2023 15:41:19 -0800 Subject: [PATCH] Try to support selecting toplevel --- src/main.rs | 21 +++++++++++++++------ src/wayland.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7dabcd2..9b151a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,10 @@ use cctk::{ }, sctk::shell::layer::{Anchor, KeyboardInteractivity, Layer}, toplevel_info::ToplevelInfo, - wayland_client::{protocol::wl_output, Connection, QueueHandle, WEnum}, + wayland_client::{ + protocol::{wl_output, wl_seat}, + Connection, QueueHandle, WEnum, + }, }; use iced::{ event::wayland::{Event as WaylandEvent, OutputEvent}, @@ -68,6 +71,7 @@ struct App { conn: Option, workspace_manager: Option, toplevel_manager: Option, + seats: Vec, } impl App { @@ -223,6 +227,9 @@ impl Application for App { toplevel.img = Some(image.clone()); } } + wayland::Event::Seats(seats) => { + self.seats = seats; + } } } Msg::Close => { @@ -236,13 +243,15 @@ impl Application for App { self.conn.as_ref().unwrap().flush(); } Msg::ActivateToplevel(toplevel_handle) => { - /* if let Some(toplevel_manager) = self.toplevel_manager.as_ref() { - toplevel_manager.activate(&toplevel_handle, todo!()); - self.conn.as_ref().unwrap().flush(); - std::process::exit(0); // Can we assume flush is suficient to ensure this takes effect? + if !self.seats.is_empty() { + for seat in &self.seats { + toplevel_manager.activate(&toplevel_handle, todo!()); + self.conn.as_ref().unwrap().flush(); + } + std::process::exit(0); // Can we assume flush is suficient to ensure this takes effect? + } } - */ } } diff --git a/src/wayland.rs b/src/wayland.rs index 950fa78..61b6a91 100644 --- a/src/wayland.rs +++ b/src/wayland.rs @@ -18,6 +18,7 @@ use cctk::{ self, output::{OutputHandler, OutputState}, registry::{ProvidesRegistryState, RegistryState}, + seat::{SeatHandler, SeatState}, shm::{raw::RawPool, ShmHandler, ShmState}, }, toplevel_info::{ToplevelInfo, ToplevelInfoHandler, ToplevelInfoState}, @@ -25,7 +26,7 @@ use cctk::{ wayland_client::{ backend::ObjectId, globals::registry_queue_init, - protocol::{wl_buffer, wl_output, wl_shm}, + protocol::{wl_buffer, wl_output, wl_seat, wl_shm}, Connection, Dispatch, Proxy, QueueHandle, WEnum, }, workspace::{WorkspaceHandler, WorkspaceState}, @@ -58,6 +59,7 @@ pub enum Event { zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1, image::Handle, ), + Seats(Vec), } pub fn subscription() -> iced::Subscription { @@ -82,11 +84,13 @@ pub struct AppData { toplevel_info_state: ToplevelInfoState, workspace_state: WorkspaceState, screencopy_state: ScreencopyState, + seat_state: SeatState, shm_state: ShmState, toplevel_manager_state: ToplevelManagerState, sender: mpsc::Sender, frames: HashMap, output_names: HashMap>, + seats: Vec, } impl AppData { @@ -100,7 +104,42 @@ impl ProvidesRegistryState for AppData { &mut self.registry_state } - sctk::registry_handlers!(OutputState,); + sctk::registry_handlers!(OutputState, SeatState); +} + +impl SeatHandler for AppData { + fn seat_state(&mut self) -> &mut SeatState { + &mut self.seat_state + } + + fn new_seat(&mut self, _: &Connection, _: &QueueHandle, seat: wl_seat::WlSeat) { + self.seats.push(seat); + self.send_event(Event::Seats(self.seats.clone())); + } + + fn remove_seat(&mut self, _: &Connection, _: &QueueHandle, seat: wl_seat::WlSeat) { + if let Some(idx) = self.seats.iter().position(|i| i == &seat) { + self.seats.remove(idx); + } + self.send_event(Event::Seats(self.seats.clone())); + } + + fn new_capability( + &mut self, + _: &Connection, + _: &QueueHandle, + _: wl_seat::WlSeat, + _: sctk::seat::Capability, + ) { + } + fn remove_capability( + &mut self, + _: &Connection, + _: &QueueHandle, + _: wl_seat::WlSeat, + _: sctk::seat::Capability, + ) { + } } impl ShmHandler for AppData { @@ -354,10 +393,12 @@ fn start() -> mpsc::Receiver { toplevel_manager_state: ToplevelManagerState::new(®istry_state, &qh), screencopy_state: ScreencopyState::new(&globals, &qh), registry_state, + seat_state: SeatState::new(&globals, &qh), shm_state: ShmState::bind(&globals, &qh).unwrap(), sender, frames: HashMap::new(), output_names: HashMap::new(), + seats: Vec::new(), }; app_data.send_event(Event::Connection(conn)); @@ -377,6 +418,7 @@ fn start() -> mpsc::Receiver { sctk::delegate_output!(AppData); sctk::delegate_registry!(AppData); +sctk::delegate_seat!(AppData); sctk::delegate_shm!(AppData); cctk::delegate_toplevel_info!(AppData); cctk::delegate_toplevel_manager!(AppData);