Use WlOutput instead of output names for matching

With a shared wayland connection between the code here and iced, if we
don't bind outputs outselves, we can have `WlOutput`s that match.

This simplifies things.
This commit is contained in:
Ian Douglas Scott 2023-11-08 13:59:53 -08:00
parent 96cd334b81
commit 9598a9f8e4
6 changed files with 53 additions and 142 deletions

View file

@ -41,7 +41,7 @@ impl std::hash::Hash for CaptureSource {
#[derive(Clone, Debug, Default)]
pub struct CaptureFilter {
// TODO: Use `WlOutput` when one Wayland connection is used
pub workspaces_on_outputs: Vec<String>,
pub workspaces_on_outputs: Vec<wl_output::WlOutput>,
pub toplevels_on_workspaces: Vec<zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1>,
}

View file

@ -15,7 +15,6 @@ use cctk::{
screencopy::ScreencopyState,
sctk::{
self,
output::{OutputHandler, OutputState},
reexports::calloop_wayland_source::WaylandSource,
registry::{ProvidesRegistryState, RegistryState},
seat::{SeatHandler, SeatState},
@ -24,10 +23,9 @@ use cctk::{
toplevel_info::{ToplevelInfo, ToplevelInfoState},
toplevel_management::ToplevelManagerState,
wayland_client::{
backend::ObjectId,
globals::registry_queue_init,
protocol::{wl_output, wl_seat},
Connection, Proxy, QueueHandle,
Connection, QueueHandle,
},
workspace::WorkspaceState,
};
@ -61,21 +59,18 @@ pub enum Event {
CmdSender(calloop::channel::Sender<Cmd>),
ToplevelManager(zcosmic_toplevel_manager_v1::ZcosmicToplevelManagerV1),
WorkspaceManager(zcosmic_workspace_manager_v1::ZcosmicWorkspaceManagerV1),
// XXX Output name rather than `WlOutput`
Workspaces(Vec<(Vec<String>, cctk::workspace::Workspace)>),
Workspaces(Vec<(HashSet<wl_output::WlOutput>, cctk::workspace::Workspace)>),
WorkspaceCapture(
zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1,
String,
wl_output::WlOutput,
image::Handle,
),
NewToplevel(
zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
HashSet<String>,
ToplevelInfo,
),
UpdateToplevel(
zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
HashSet<String>,
ToplevelInfo,
),
CloseToplevel(zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1),
@ -97,7 +92,6 @@ pub enum Cmd {
pub struct AppData {
qh: QueueHandle<Self>,
output_state: OutputState,
registry_state: RegistryState,
toplevel_info_state: ToplevelInfoState,
workspace_state: WorkspaceState,
@ -106,7 +100,6 @@ pub struct AppData {
shm_state: Shm,
toplevel_manager_state: ToplevelManagerState,
sender: mpsc::Sender<Event>,
output_names: HashMap<ObjectId, Option<String>>,
seats: Vec<wl_seat::WlSeat>,
capture_filter: CaptureFilter,
captures: RefCell<HashMap<CaptureSource, Arc<Capture>>>,
@ -138,11 +131,7 @@ impl AppData {
})
}
CaptureSource::Workspace(_, output) => {
if let Some(name) = &self.output_state.info(&output).and_then(|x| x.name) {
self.capture_filter.workspaces_on_outputs.contains(name)
} else {
false
}
self.capture_filter.workspaces_on_outputs.contains(output)
}
}
}
@ -185,7 +174,7 @@ impl ProvidesRegistryState for AppData {
&mut self.registry_state
}
sctk::registry_handlers!(OutputState, SeatState);
sctk::registry_handlers!(SeatState);
}
impl SeatHandler for AppData {
@ -229,40 +218,6 @@ impl ShmHandler for AppData {
}
}
// TODO: don't need this if we use same connection with same IDs? Or?
impl OutputHandler for AppData {
fn output_state(&mut self) -> &mut OutputState {
&mut self.output_state
}
fn new_output(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
output: wl_output::WlOutput,
) {
let name = self.output_state.info(&output).unwrap().name;
self.output_names.insert(output.id(), name);
}
fn update_output(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_output: wl_output::WlOutput,
) {
}
fn output_destroyed(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
output: wl_output::WlOutput,
) {
self.output_names.remove(&output.id());
}
}
fn start(conn: Connection) -> mpsc::Receiver<Event> {
let (sender, receiver) = mpsc::channel(20);
@ -272,7 +227,6 @@ fn start(conn: Connection) -> mpsc::Receiver<Event> {
let registry_state = RegistryState::new(&globals);
let mut app_data = AppData {
qh: qh.clone(),
output_state: OutputState::new(&globals, &qh),
workspace_state: WorkspaceState::new(&registry_state, &qh), // Create before toplevel info state
toplevel_info_state: ToplevelInfoState::new(&registry_state, &qh),
toplevel_manager_state: ToplevelManagerState::new(&registry_state, &qh),
@ -281,7 +235,6 @@ fn start(conn: Connection) -> mpsc::Receiver<Event> {
seat_state: SeatState::new(&globals, &qh),
shm_state: Shm::bind(&globals, &qh).unwrap(),
sender,
output_names: HashMap::new(),
seats: Vec::new(),
capture_filter: CaptureFilter::default(),
captures: RefCell::new(HashMap::new()),
@ -323,7 +276,7 @@ fn start(conn: Connection) -> mpsc::Receiver<Event> {
receiver
}
sctk::delegate_output!(AppData);
// Don't bind outputs; use `WlOutput` instances from iced-sctk
sctk::delegate_registry!(AppData);
sctk::delegate_seat!(AppData);
sctk::delegate_shm!(AppData);

View file

@ -1,7 +1,7 @@
use cctk::{
cosmic_protocols::screencopy::v1::client::zcosmic_screencopy_session_v1,
screencopy::{BufferInfo, ScreencopyHandler, ScreencopyState},
wayland_client::{protocol::wl_shm, Connection, Proxy, QueueHandle, WEnum},
wayland_client::{protocol::wl_shm, Connection, QueueHandle, WEnum},
};
use super::{AppData, Buffer, Capture, CaptureSource, Event};
@ -76,13 +76,11 @@ impl ScreencopyHandler for AppData {
self.send_event(Event::ToplevelCapture(toplevel.clone(), image))
}
CaptureSource::Workspace(workspace, output) => {
if let Some(Some(output_name)) = self.output_names.get(&output.id()) {
self.send_event(Event::WorkspaceCapture(
workspace.clone(),
output_name.clone(),
image,
));
}
self.send_event(Event::WorkspaceCapture(
workspace.clone(),
output.clone(),
image,
));
}
};
session.destroy();

View file

@ -5,7 +5,7 @@ use cctk::{
},
toplevel_info::{ToplevelInfoHandler, ToplevelInfoState},
toplevel_management::{ToplevelManagerHandler, ToplevelManagerState},
wayland_client::{Connection, Proxy, QueueHandle, WEnum},
wayland_client::{Connection, QueueHandle, WEnum},
};
use super::{AppData, CaptureSource, Event};
@ -23,16 +23,7 @@ impl ToplevelInfoHandler for AppData {
toplevel: &zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
) {
let info = self.toplevel_info_state.info(toplevel).unwrap();
let output_names = info
.output
.iter()
.filter_map(|o| self.output_names.get(&o.id()).cloned()?)
.collect();
self.send_event(Event::NewToplevel(
toplevel.clone(),
output_names,
info.clone(),
));
self.send_event(Event::NewToplevel(toplevel.clone(), info.clone()));
self.add_capture_source(CaptureSource::Toplevel(toplevel.clone()));
}
@ -44,16 +35,7 @@ impl ToplevelInfoHandler for AppData {
toplevel: &zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
) {
let info = self.toplevel_info_state.info(toplevel).unwrap();
let output_names = info
.output
.iter()
.filter_map(|o| self.output_names.get(&o.id()).cloned()?)
.collect();
self.send_event(Event::UpdateToplevel(
toplevel.clone(),
output_names,
info.clone(),
));
self.send_event(Event::UpdateToplevel(toplevel.clone(), info.clone()));
}
fn toplevel_closed(

View file

@ -1,7 +1,4 @@
use cctk::{
wayland_client::Proxy,
workspace::{WorkspaceHandler, WorkspaceState},
};
use cctk::workspace::{WorkspaceHandler, WorkspaceState};
use super::{AppData, CaptureSource, Event};
@ -18,20 +15,13 @@ impl WorkspaceHandler for AppData {
for group in self.workspace_state.workspace_groups() {
for workspace in &group.workspaces {
let output_names: Vec<_> = group
.outputs
.iter()
.filter_map(|output| self.output_names.get(&output.id()).cloned()?)
.collect();
if !output_names.is_empty() {
workspaces.push((output_names, workspace.clone()));
workspaces.push((group.outputs.iter().cloned().collect(), workspace.clone()));
for output in &group.outputs {
self.add_capture_source(CaptureSource::Workspace(
workspace.handle.clone(),
output.clone(),
));
}
for output in &group.outputs {
self.add_capture_source(CaptureSource::Workspace(
workspace.handle.clone(),
output.clone(),
));
}
}
}