From 39de286d51300cc3c2c301ca6e26a4323f16635b Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Mon, 4 Jul 2022 16:00:29 +0200 Subject: [PATCH] cargo fmt --- src/backend/kms/mod.rs | 197 +++++--- src/backend/kms/socket.rs | 70 ++- src/backend/mod.rs | 5 +- src/backend/render/cursor.rs | 19 +- src/backend/render/mod.rs | 51 +- src/backend/winit.rs | 54 ++- src/backend/x11.rs | 42 +- src/debug.rs | 21 +- src/input/mod.rs | 117 +++-- src/main.rs | 31 +- src/shell/focus.rs | 45 +- src/shell/layout/floating/grabs.rs | 39 +- src/shell/layout/floating/mod.rs | 18 +- src/shell/layout/mod.rs | 13 +- src/shell/layout/tiling/grabs.rs | 22 +- src/shell/layout/tiling/mod.rs | 21 +- src/shell/mod.rs | 357 ++++++++++---- src/shell/workspace.rs | 33 +- src/state.rs | 8 +- src/utils/prelude.rs | 37 +- src/wayland/handlers/buffer.rs | 7 +- src/wayland/handlers/compositor.rs | 95 ++-- src/wayland/handlers/data_device.rs | 24 +- src/wayland/handlers/dmabuf.rs | 22 +- src/wayland/handlers/layer_shell.rs | 26 +- src/wayland/handlers/mod.rs | 10 +- src/wayland/handlers/output.rs | 2 +- src/wayland/handlers/output_configuration.rs | 45 +- src/wayland/handlers/seat.rs | 8 +- src/wayland/handlers/shm.rs | 8 +- src/wayland/handlers/toplevel_info.rs | 4 +- src/wayland/handlers/viewporter.rs | 2 +- src/wayland/handlers/wl_drm.rs | 5 +- src/wayland/handlers/workspace.rs | 28 +- src/wayland/handlers/xdg_shell.rs | 143 +++--- src/wayland/mod.rs | 2 +- src/wayland/protocols/drm.rs | 89 ++-- src/wayland/protocols/output_configuration.rs | 246 +++++----- src/wayland/protocols/toplevel_info.rs | 223 ++++++--- src/wayland/protocols/workspace.rs | 448 ++++++++++++------ 40 files changed, 1557 insertions(+), 1080 deletions(-) diff --git a/src/backend/kms/mod.rs b/src/backend/kms/mod.rs index 20da98f9..34e9a409 100644 --- a/src/backend/kms/mod.rs +++ b/src/backend/kms/mod.rs @@ -14,18 +14,14 @@ use crate::{ use anyhow::{Context, Result}; use smithay::{ backend::{ - allocator::{ - dmabuf::Dmabuf, - gbm::GbmDevice, - Format, - }, + allocator::{dmabuf::Dmabuf, gbm::GbmDevice, Format}, drm::{DrmDevice, DrmEvent, DrmEventTime, DrmNode, GbmBufferedSurface, NodeType}, egl::{EGLContext, EGLDevice, EGLDisplay}, input::InputEvent, libinput::{LibinputInputBackend, LibinputSessionInterface}, renderer::{ - multigpu::{egl::EglGlesBackend, GpuManager}, gles2::Gles2Renderbuffer, + multigpu::{egl::EglGlesBackend, GpuManager}, Bind, }, session::{auto::AutoSession, Session, Signal}, @@ -40,8 +36,8 @@ use smithay::{ input::Libinput, nix::{fcntl::OFlag, sys::stat::dev_t}, wayland_server::{ - DisplayHandle, Resource, protocol::{wl_output, wl_surface::WlSurface}, + DisplayHandle, Resource, }, }, utils::signaling::{Linkable, SignalToken, Signaler}, @@ -99,7 +95,11 @@ pub struct Surface { fps: Fps, } -pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<'static, Data>, state: &mut State) -> Result<()> { +pub fn init_backend( + dh: &DisplayHandle, + event_loop: &mut EventLoop<'static, Data>, + state: &mut State, +) -> Result<()> { let (session, notifier) = AutoSession::new(None).context("Failed to acquire session")?; let signaler = notifier.signaler(); @@ -118,14 +118,20 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<'static, Data if let &mut InputEvent::DeviceAdded { ref mut device } = &mut event { data.state.common.config.read_device(device); } - data.state.process_input_event(&data.display.handle(), event); + data.state + .process_input_event(&data.display.handle(), event); for output in data.state.common.shell.outputs() { - if let Err(err) = data.state + if let Err(err) = data + .state .backend .kms() .schedule_render(&data.state.common.event_loop_handle, output) { - slog_scope::crit!("Error scheduling event loop for output {}: {:?}", output.name(), err); + slog_scope::crit!( + "Error scheduling event loop for output {}: {:?}", + output.name(), + err + ); } } }) @@ -167,13 +173,16 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<'static, Data let udev_dispatcher = Dispatcher::new(udev_backend, move |event, _, data: &mut Data| { match match event { - UdevEvent::Added { device_id, path } => data.state + UdevEvent::Added { device_id, path } => data + .state .device_added(device_id, path, &data.display.handle()) .with_context(|| format!("Failed to add drm device: {}", device_id)), - UdevEvent::Changed { device_id } => data.state + UdevEvent::Changed { device_id } => data + .state .device_changed(device_id) .with_context(|| format!("Failed to update drm device: {}", device_id)), - UdevEvent::Removed { device_id } => data.state + UdevEvent::Removed { device_id } => data + .state .device_removed(device_id, &data.display.handle()) .with_context(|| format!("Failed to remove drm device: {}", device_id)), } { @@ -218,7 +227,10 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<'static, Data ); } } else { - if let Err(err) = data.state.device_added(dev, path.into(), &data.display.handle()) { + if let Err(err) = + data.state + .device_added(dev, path.into(), &data.display.handle()) + { slog_scope::error!( "Failed to add drm device {}: {}", path.display(), @@ -227,10 +239,7 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<'static, Data } } } - data.state - .common - .output_configuration_state - .update(); + data.state.common.output_configuration_state.update(); data.state.common.config.read_outputs( data.state.common.output_configuration_state.outputs(), @@ -244,7 +253,8 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<'static, Data .config .write_outputs(data.state.common.output_configuration_state.outputs()); - for surface in data.state + for surface in data + .state .backend .kms() .devices @@ -254,12 +264,17 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop<'static, Data surface.pending = false; } for output in data.state.common.shell.outputs() { - if let Err(err) = data.state + if let Err(err) = data + .state .backend .kms() .schedule_render(&data.state.common.event_loop_handle, output) { - slog_scope::crit!("Error scheduling event loop for output {}: {:?}", output.name(), err); + slog_scope::crit!( + "Error scheduling event loop for output {}: {:?}", + output.name(), + err + ); } } }); @@ -358,7 +373,8 @@ impl State { .active_space_mut(&surface.output) .space .send_frames( - data.state.common.start_time.elapsed().as_millis() as u32 + data.state.common.start_time.elapsed().as_millis() + as u32, ); } Some(Err(err)) => { @@ -422,10 +438,10 @@ impl State { } self.backend.kms().devices.insert(drm_node, device); - self.common.output_configuration_state.add_heads(wl_outputs.iter()); self.common .output_configuration_state - .update(); + .add_heads(wl_outputs.iter()); + self.common.output_configuration_state.update(); for output in wl_outputs { if let Err(err) = self.backend.kms().apply_config_for_output( &output, @@ -487,8 +503,12 @@ impl State { } } - self.common.output_configuration_state.remove_heads(outputs_removed.iter()); - self.common.output_configuration_state.add_heads(outputs_added.iter()); + self.common + .output_configuration_state + .remove_heads(outputs_removed.iter()); + self.common + .output_configuration_state + .add_heads(outputs_added.iter()); for output in outputs_added { if let Err(err) = self.backend.kms().apply_config_for_output( &output, @@ -499,9 +519,7 @@ impl State { slog_scope::warn!("Failed to initialize output: {}", err); } } - self.common - .output_configuration_state - .update(); + self.common.output_configuration_state.update(); self.common.config.read_outputs( self.common.output_configuration_state.outputs(), &mut self.backend, @@ -531,14 +549,16 @@ impl State { } if let Some(socket) = device.socket.take() { self.common.event_loop_handle.remove(socket.token); - self.common.dmabuf_state.destroy_global::(dh, socket.dmabuf_global); + self.common + .dmabuf_state + .destroy_global::(dh, socket.dmabuf_global); dh.remove_global(socket.drm_global); } } - self.common.output_configuration_state.remove_heads(outputs_removed.iter()); self.common .output_configuration_state - .update(); + .remove_heads(outputs_removed.iter()); + self.common.output_configuration_state.update(); if self.backend.kms().session.is_active() { self.common.config.read_outputs( @@ -672,35 +692,42 @@ impl Device { const MAX_CPU_COPIES: usize = 3; -fn render_node_for_output(dh: &DisplayHandle, output: &Output, target_node: DrmNode, shell: &Shell) -> DrmNode { +fn render_node_for_output( + dh: &DisplayHandle, + output: &Output, + target_node: DrmNode, + shell: &Shell, +) -> DrmNode { let workspace = shell.active_space(output); - let nodes = workspace - .get_fullscreen(output) - .map(|w| vec![w]) - .unwrap_or_else(|| workspace.space.windows().collect::>()) - .into_iter() - .flat_map(|w| { - dh.get_client(w.toplevel().wl_surface().id()).ok()? - .get_data::().unwrap() - .drm_node - .clone() + let nodes = workspace + .get_fullscreen(output) + .map(|w| vec![w]) + .unwrap_or_else(|| workspace.space.windows().collect::>()) + .into_iter() + .flat_map(|w| { + dh.get_client(w.toplevel().wl_surface().id()) + .ok()? + .get_data::() + .unwrap() + .drm_node + .clone() + }) + .collect::>(); + if nodes.contains(&target_node) || nodes.len() < MAX_CPU_COPIES { + target_node + } else { + nodes + .iter() + .fold(HashMap::new(), |mut count_map, node| { + let count = count_map.entry(node).or_insert(0); + *count += 1; + count_map }) - .collect::>(); - if nodes.contains(&target_node) || nodes.len() < MAX_CPU_COPIES { - target_node - } else { - nodes - .iter() - .fold(HashMap::new(), |mut count_map, node| { - let count = count_map.entry(node).or_insert(0); - *count += 1; - count_map - }) - .into_iter() - .reduce(|a, b| if a.1 > b.1 { a } else { b }) - .map(|(node, _)| *node) - .unwrap_or(target_node) - } + .into_iter() + .reduce(|a, b| if a.1 > b.1 { a } else { b }) + .map(|(node, _)| *node) + .unwrap_or(target_node) + } } impl Surface { @@ -851,19 +878,36 @@ impl KmsState { shell.refresh_outputs(); if recreated { if let Err(err) = self.schedule_render(loop_handle, output) { - slog_scope::crit!("Error scheduling event loop for output {}: {:?}", output.name(), err); + slog_scope::crit!( + "Error scheduling event loop for output {}: {:?}", + output.name(), + err + ); } } Ok(()) } pub fn target_node_for_output(&self, output: &Output) -> Option { - self.devices.iter().find(|(_, dev)| dev.surfaces.values().any(|s| s.output == *output)).map(|(target, _)| target).copied() + self.devices + .iter() + .find(|(_, dev)| dev.surfaces.values().any(|s| s.output == *output)) + .map(|(target, _)| target) + .copied() } - pub fn try_early_import(&mut self, dh: &DisplayHandle, surface: &WlSurface, output: &Output, target: DrmNode, shell: &Shell) { + pub fn try_early_import( + &mut self, + dh: &DisplayHandle, + surface: &WlSurface, + output: &Output, + target: DrmNode, + shell: &Shell, + ) { let render = render_node_for_output(dh, &output, target, &shell); if let Err(err) = self.api.early_import( - dh.get_client(surface.id()).ok().and_then(|c| c.get_data::().unwrap().drm_node.clone()), + dh.get_client(surface.id()) + .ok() + .and_then(|c| c.get_data::().unwrap().drm_node.clone()), render, surface, ) { @@ -871,12 +915,24 @@ impl KmsState { } } - pub fn dmabuf_imported(&mut self, _dh: &DisplayHandle, global: &DmabufGlobal, dmabuf: Dmabuf) -> Result<()> { + pub fn dmabuf_imported( + &mut self, + _dh: &DisplayHandle, + global: &DmabufGlobal, + dmabuf: Dmabuf, + ) -> Result<()> { use smithay::backend::renderer::ImportDma; for device in self.devices.values() { - if device.socket.as_ref().map(|s| &s.dmabuf_global == global).unwrap_or(false) { - return self.api.renderer::(&device.render_node, &device.render_node)? + if device + .socket + .as_ref() + .map(|s| &s.dmabuf_global == global) + .unwrap_or(false) + { + return self + .api + .renderer::(&device.render_node, &device.render_node)? .import_dmabuf(&dmabuf, None) .map(|_| ()) .map_err(Into::into); @@ -919,10 +975,9 @@ impl KmsState { let crtc = *crtc; surface.render_timer_token = Some(loop_handle.insert_source( //if surface.vrr || instant.is_none() { - Timer::immediate() - /*} else { - Timer::from_deadline(instant.unwrap()) - }*/, + Timer::immediate(), /*} else { + Timer::from_deadline(instant.unwrap()) + }*/ move |_time, _, data| { let backend = data.state.backend.kms(); if let Some(device) = backend.devices.get_mut(&device) { diff --git a/src/backend/kms/socket.rs b/src/backend/kms/socket.rs index 96854190..158d477c 100644 --- a/src/backend/kms/socket.rs +++ b/src/backend/kms/socket.rs @@ -8,12 +8,9 @@ use smithay::{ }, reexports::{ calloop::RegistrationToken, - wayland_server::{Client, DisplayHandle, backend::GlobalId}, - }, - wayland::{ - dmabuf::DmabufGlobal, - socket::ListeningSocketSource, + wayland_server::{backend::GlobalId, Client, DisplayHandle}, }, + wayland::{dmabuf::DmabufGlobal, socket::ListeningSocketSource}, }; use std::sync::Arc; @@ -53,50 +50,45 @@ impl State { dev_id == render_node }; - let dmabuf_global = self.common.dmabuf_state.create_global_with_filter::( - dh, - formats.clone(), - filter, - None, - ); + let dmabuf_global = self + .common + .dmabuf_state + .create_global_with_filter::(dh, formats.clone(), filter, None); + + let drm_global_id = self + .common + .wl_drm_state + .create_global_with_filter::( + dh, + render_node + .dev_path_with_type(NodeType::Render) + .or_else(|| render_node.dev_path()) + .ok_or(anyhow!( + "Could not determine path for gpu node: {}", + render_node + ))?, + formats, + &dmabuf_global, + filter, + ); - let drm_global_id = self.common.wl_drm_state.create_global_with_filter::( - dh, - render_node - .dev_path_with_type(NodeType::Render) - .or_else(|| render_node.dev_path()) - .ok_or(anyhow!("Could not determine path for gpu node: {}", render_node))?, - formats, - &dmabuf_global, - filter, - ); - // add a special socket for the gpu let listener = ListeningSocketSource::with_name(&socket_name, None) .with_context(|| format!("Failed to bind socket to {}", socket_name))?; let token = self .common .event_loop_handle - .insert_source( - listener, - move |client_stream, _, data: &mut Data| { - if let Err(err) = data - .display - .handle() - .insert_client(client_stream, Arc::new(data.state.new_client_state_with_node(render_node))) - { - slog_scope::warn!("Error adding wayland client ({}): {}", render_node, err); - } + .insert_source(listener, move |client_stream, _, data: &mut Data| { + if let Err(err) = data.display.handle().insert_client( + client_stream, + Arc::new(data.state.new_client_state_with_node(render_node)), + ) { + slog_scope::warn!("Error adding wayland client ({}): {}", render_node, err); } - ) + }) .context("Failed to add gpu-wayland socket to the event loop")?; - - slog_scope::info!( - "Added socket at {} for gpu {}", - socket_name, - render_node, - ); + slog_scope::info!("Added socket at {} for gpu {}", socket_name, render_node,); Ok(Socket { token, diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 684845da..6a7b62ff 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -2,10 +2,7 @@ use crate::state::{Data, State}; use anyhow::Result; -use smithay::reexports::{ - calloop::EventLoop, - wayland_server::DisplayHandle, -}; +use smithay::reexports::{calloop::EventLoop, wayland_server::DisplayHandle}; pub mod render; diff --git a/src/backend/render/cursor.rs b/src/backend/render/cursor.rs index fdfb3b2b..6266837f 100644 --- a/src/backend/render/cursor.rs +++ b/src/backend/render/cursor.rs @@ -1,14 +1,11 @@ // SPDX-License-Identifier: GPL-3.0-only -use crate::{ - wayland::handlers::data_device::get_dnd_icon, - utils::prelude::*, -}; +use crate::{utils::prelude::*, wayland::handlers::data_device::get_dnd_icon}; use smithay::{ backend::renderer::{Frame, ImportAll, ImportMem, Renderer, Texture}, desktop::space::{RenderElement, SpaceOutputTuple, SurfaceTree}, reexports::wayland_server::protocol::wl_surface, - utils::{IsAlive, Logical, Physical, Point, Rectangle, Size, Scale, Transform}, + utils::{IsAlive, Logical, Physical, Point, Rectangle, Scale, Size, Transform}, wayland::{ compositor::{get_role, with_states}, seat::{CursorImageAttributes, CursorImageStatus, Seat}, @@ -198,7 +195,9 @@ where } fn geometry(&self, scale: impl Into>) -> Rectangle { - Rectangle::from_loc_and_size(self.position, self.size.to_f64()).to_physical(scale).to_i32_round() + Rectangle::from_loc_and_size(self.position, self.size.to_f64()) + .to_physical(scale) + .to_i32_round() } fn accumulated_damage( @@ -207,7 +206,10 @@ where _: Option>, ) -> Vec> { if self.new_frame { - vec![Rectangle::from_loc_and_size((0, 0), self.size.to_physical_precise_round(scale))] + vec![Rectangle::from_loc_and_size( + (0, 0), + self.size.to_physical_precise_round(scale), + )] } else { vec![] } @@ -323,7 +325,8 @@ where pointer_images.push((frame.clone(), Box::new(texture.clone()))); texture }); - let hotspot = Point::::from((frame.xhot as i32, frame.yhot as i32)).to_f64(); + let hotspot = + Point::::from((frame.xhot as i32, frame.yhot as i32)).to_f64(); *state.current_image.borrow_mut() = Some(frame); Some(PointerElement::new(pointer_image.clone(), location - hotspot, new_frame).into()) diff --git a/src/backend/render/mod.rs b/src/backend/render/mod.rs index ac821c5d..c9b5a4a2 100644 --- a/src/backend/render/mod.rs +++ b/src/backend/render/mod.rs @@ -6,7 +6,7 @@ use crate::{ debug::{debug_ui, fps_ui, log_ui, EguiFrame}, state::Fps, utils::prelude::*, -}; +}; use slog::Logger; use smithay::{ @@ -19,7 +19,8 @@ use smithay::{ }, }, desktop::{ - draw_layer_surface, draw_layer_popups, draw_window, draw_window_popups, layer_map_for_output, + draw_layer_popups, draw_layer_surface, draw_window, draw_window_popups, + layer_map_for_output, space::{RenderElement, RenderError, SpaceOutputTuple, SurfaceTree}, utils::damage_from_surface_tree, Window, @@ -201,13 +202,22 @@ where .unwrap_or(Rectangle::from_loc_and_size((0, 0), (0, 0))); let scale = output.current_scale().fractional_scale(); - let fps_overlay = fps_ui(_gpu, state, fps, output_geo.to_f64().to_physical(scale), scale); + let fps_overlay = fps_ui( + _gpu, + state, + fps, + output_geo.to_f64().to_physical(scale), + scale, + ); custom_elements.push(fps_overlay.into()); let area = Rectangle::::from_loc_and_size( - state.shell.space_relative_output_geometry((0.0f64, 0.0f64), output), + state + .shell + .space_relative_output_geometry((0.0f64, 0.0f64), output), state.shell.global_space().to_f64().size, - ).to_physical(scale); + ) + .to_physical(scale); if let Some(log_ui) = log_ui(state, area, scale, output_geo.size.w as f32 * 0.6) { custom_elements.push(log_ui.into()); } @@ -272,7 +282,9 @@ where _gpu, state, fps, - Rectangle::from_loc_and_size((0, 0), output_geo.size).to_f64().to_physical(scale), + Rectangle::from_loc_and_size((0, 0), output_geo.size) + .to_f64() + .to_physical(scale), scale, ); custom_elements.push(fps_overlay.into()); @@ -311,10 +323,7 @@ where &window, scale, (0.0, 0.0), - &[Rectangle::from_loc_and_size( - (0, 0), - mode.size, - )], + &[Rectangle::from_loc_and_size((0, 0), mode.size)], &slog_scope::logger(), )?; draw_window_popups( @@ -323,10 +332,7 @@ where &window, scale, (0.0, 0.0), - &[Rectangle::from_loc_and_size( - (0, 0), - mode.size, - )], + &[Rectangle::from_loc_and_size((0, 0), mode.size)], &slog_scope::logger(), )?; let layer_map = layer_map_for_output(output); @@ -338,7 +344,10 @@ where layer_surface, scale, geo.loc.to_f64().to_physical(scale), - &[Rectangle::from_loc_and_size((0, 0), geo.size.to_physical_precise_round(scale))], + &[Rectangle::from_loc_and_size( + (0, 0), + geo.size.to_physical_precise_round(scale), + )], &slog_scope::logger(), )?; draw_layer_popups( @@ -347,10 +356,18 @@ where layer_surface, scale, geo.loc.to_f64().to_physical(scale), - &[Rectangle::from_loc_and_size((0, 0), geo.size.to_physical_precise_round(scale))], + &[Rectangle::from_loc_and_size( + (0, 0), + geo.size.to_physical_precise_round(scale), + )], &slog_scope::logger(), )?; - damage.extend(damage_from_surface_tree(layer_surface.wl_surface(), geo.loc.to_f64().to_physical(scale), scale, None)); + damage.extend(damage_from_surface_tree( + layer_surface.wl_surface(), + geo.loc.to_f64().to_physical(scale), + scale, + None, + )); } for elem in custom_elements { let loc = elem.location(scale); diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 01f60fc8..d811c08c 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -43,7 +43,9 @@ impl WinitState { self.reset_buffers(); } - self.backend.bind().with_context(|| "Failed to bind buffer")?; + self.backend + .bind() + .with_context(|| "Failed to bind buffer")?; let age = if self.age_reset > 0 { self.age_reset -= 1; 0 @@ -110,7 +112,11 @@ impl WinitState { } } -pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop, state: &mut State) -> Result<()> { +pub fn init_backend( + dh: &DisplayHandle, + event_loop: &mut EventLoop, + state: &mut State, +) -> Result<()> { let (mut backend, mut input) = winit::init(None).map_err(|_| anyhow!("Failed to initilize winit backend"))?; @@ -158,9 +164,12 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop, state: event_loop .handle() .insert_source(render_source, move |_, _, data| { - if let Err(err) = data.state.backend.winit().render_output( - &mut data.state.common - ) { + if let Err(err) = data + .state + .backend + .winit() + .render_output(&mut data.state.common) + { slog_scope::error!("Failed to render frame: {}", err); render_ping.ping(); } @@ -171,13 +180,10 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop, state: event_loop .handle() .insert_source(event_source, move |_, _, data| { - match input - .dispatch_new_events(|event| data.state.process_winit_event( - &data.display.handle(), - event, - &render_ping_handle - )) - { + match input.dispatch_new_events(|event| { + data.state + .process_winit_event(&data.display.handle(), event, &render_ping_handle) + }) { Ok(_) => { event_ping_handle.ping(); render_ping_handle.ping(); @@ -201,11 +207,11 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop, state: fps: Fps::default(), age_reset: 0, }); - state.common.output_configuration_state.add_heads(std::iter::once(&output)); state .common .output_configuration_state - .update(); + .add_heads(std::iter::once(&output)); + state.common.output_configuration_state.update(); state.common.shell.add_output(&output); state.common.config.read_outputs( std::iter::once(&output), @@ -233,11 +239,10 @@ fn init_egl_client_side( .dmabuf_formats() .cloned() .collect::>(); - state.common.dmabuf_state.create_global::( - dh, - dmabuf_formats, - None, - ); + state + .common + .dmabuf_state + .create_global::(dh, dmabuf_formats, None); } Err(err) => slog_scope::warn!("Unable to initialize bind display to EGL: {}", err), }; @@ -246,7 +251,12 @@ fn init_egl_client_side( } impl State { - pub fn process_winit_event(&mut self, dh: &DisplayHandle, event: WinitEvent, render_ping: &ping::Ping) { + pub fn process_winit_event( + &mut self, + dh: &DisplayHandle, + event: WinitEvent, + render_ping: &ping::Ping, + ) { // here we can handle special cases for winit inputs match event { WinitEvent::Focus(true) => { @@ -278,9 +288,7 @@ impl State { output.set_preferred(mode); output.change_current_state(Some(mode), None, None, None); layer_map_for_output(output).arrange(dh); - self.common - .output_configuration_state - .update(); + self.common.output_configuration_state.update(); self.common.shell.refresh_outputs(); render_ping.ping(); } diff --git a/src/backend/x11.rs b/src/backend/x11.rs index 59b49893..0e3c14bf 100644 --- a/src/backend/x11.rs +++ b/src/backend/x11.rs @@ -93,8 +93,8 @@ impl X11State { .iter_mut() .find(|s| s.output == output_ref) { - if let Err(err) = surface - .render_output(&mut x11_state.renderer, &mut data.state.common) + if let Err(err) = + surface.render_output(&mut x11_state.renderer, &mut data.state.common) { slog_scope::error!("Error rendering: {}", err); } @@ -218,7 +218,11 @@ impl Surface { } } -pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop, state: &mut State) -> Result<()> { +pub fn init_backend( + dh: &DisplayHandle, + event_loop: &mut EventLoop, + state: &mut State, +) -> Result<()> { let backend = X11Backend::new(None).with_context(|| "Failed to initilize X11 backend")?; let handle = backend.handle(); @@ -253,11 +257,11 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop, state: .x11() .add_window(event_loop.handle()) .with_context(|| "Failed to create wl_output")?; - state.common.output_configuration_state.add_heads(std::iter::once(&output)); state .common .output_configuration_state - .update(); + .add_heads(std::iter::once(&output)); + state.common.output_configuration_state.update(); state.common.shell.add_output(&output); state.common.config.read_outputs( std::iter::once(&output), @@ -303,7 +307,8 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop, state: size, refresh: 60_000, }; - if let Some(surface) = data.state + if let Some(surface) = data + .state .backend .x11() .surfaces @@ -324,10 +329,7 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop, state: output.change_current_state(Some(mode), None, None, None); output.set_preferred(mode); layer_map_for_output(output).arrange(&data.display.handle()); - data.state - .common - .output_configuration_state - .update(); + data.state.common.output_configuration_state.update(); data.state.common.shell.refresh_outputs(); surface.dirty = true; if !surface.pending { @@ -358,20 +360,20 @@ pub fn init_backend(dh: &DisplayHandle, event_loop: &mut EventLoop, state: Ok(()) } -fn init_egl_client_side(dh: &DisplayHandle, state: &mut State, renderer: &mut Gles2Renderer) -> Result<()> { +fn init_egl_client_side( + dh: &DisplayHandle, + state: &mut State, + renderer: &mut Gles2Renderer, +) -> Result<()> { let bind_result = renderer.bind_wl_display(dh); match bind_result { Ok(_) => { slog_scope::info!("EGL hardware-acceleration enabled"); - let dmabuf_formats = renderer - .dmabuf_formats() - .cloned() - .collect::>(); - state.common.dmabuf_state.create_global::( - dh, - dmabuf_formats, - None, - ); + let dmabuf_formats = renderer.dmabuf_formats().cloned().collect::>(); + state + .common + .dmabuf_state + .create_global::(dh, dmabuf_formats, None); } Err(err) => slog_scope::warn!("Unable to initialize bind display to EGL: {}", err), }; diff --git a/src/debug.rs b/src/debug.rs index ab869ec6..c24cc77e 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -80,7 +80,9 @@ pub fn fps_ui( .show(ui, |plot_ui| { plot_ui.bar_chart(fps_chart); plot_ui.hline( - HLine::new(avg).highlight(true).color(egui::Color32::LIGHT_BLUE), + HLine::new(avg) + .highlight(true) + .color(egui::Color32::LIGHT_BLUE), ); }); } @@ -131,8 +133,10 @@ pub fn debug_ui( state.shell.set_mode(mode); let mode = match &state.shell.workspace_mode { - WorkspaceMode::OutputBound => (ConfigMode::OutputBound, None), - WorkspaceMode::Global { ref active, .. } => (ConfigMode::Global, Some(*active)), + WorkspaceMode::OutputBound => (ConfigMode::OutputBound, None), + WorkspaceMode::Global { ref active, .. } => { + (ConfigMode::Global, Some(*active)) + } }; match mode { (ConfigMode::OutputBound, _) => { @@ -180,7 +184,7 @@ pub fn debug_ui( ); } }); - }, + } _ => unreachable!(), } @@ -225,10 +229,7 @@ pub fn debug_ui( ui.separator(); ui.collapsing(output.name(), |ui| { ui.label(format!("Output: {:#?}", output)); - ui.label(format!( - "Geometry: {:?}", - output.geometry() - )); + ui.label(format!("Geometry: {:?}", output.geometry())); ui.label(format!( "Local Geometry: {:?}", state @@ -239,7 +240,9 @@ pub fn debug_ui( )); ui.label(format!( "Relative Geometry: {:?}", - state.shell.space_relative_output_geometry((0i32, 0i32), &output) + state + .shell + .space_relative_output_geometry((0i32, 0i32), &output) )); }); } diff --git a/src/input/mod.rs b/src/input/mod.rs index 289e390a..4c5cd27e 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1,10 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only -use crate::{ - config::Action, - shell::Workspace, - utils::prelude::*, -}; +use crate::{config::Action, shell::Workspace, utils::prelude::*}; use smithay::{ backend::input::{Device, DeviceCapability, InputBackend, InputEvent, KeyState}, desktop::{layer_map_for_output, Kind, WindowSurfaceType}, @@ -13,7 +9,10 @@ use smithay::{ wayland::{ data_device::set_data_device_focus, output::Output, - seat::{keysyms, CursorImageStatus, FilterResult, KeysymHandle, Seat, XkbConfig, MotionEvent, ButtonEvent}, + seat::{ + keysyms, ButtonEvent, CursorImageStatus, FilterResult, KeysymHandle, MotionEvent, Seat, + XkbConfig, + }, shell::wlr_layer::Layer as WlrLayer, SERIAL_COUNTER, }, @@ -92,7 +91,11 @@ pub fn add_seat(dh: &DisplayHandle, name: String) -> Seat { } impl State { - pub fn process_input_event(&mut self, dh: &DisplayHandle, event: InputEvent) { + pub fn process_input_event( + &mut self, + dh: &DisplayHandle, + event: InputEvent, + ) { use smithay::backend::input::Event; match event { @@ -104,16 +107,18 @@ impl State { match cap { DeviceCapability::Keyboard => { let dh_clone = dh.clone(); - let _ = - seat.add_keyboard(XkbConfig::default(), 200, 25, move |seat, focus| { - if let Some(client) = focus.and_then(|s| dh_clone.get_client(s.id()).ok()) { - set_data_device_focus( - &dh_clone, - seat, - Some(client), - ) + let _ = seat.add_keyboard( + XkbConfig::default(), + 200, + 25, + move |seat, focus| { + if let Some(client) = + focus.and_then(|s| dh_clone.get_client(s.id()).ok()) + { + set_data_device_focus(&dh_clone, seat, Some(client)) } - }); + }, + ); } DeviceCapability::Pointer => { let output = self @@ -302,15 +307,21 @@ impl State { } Action::Focus(focus) => { let current_output = active_output(seat, &self.common); - let workspace = self.common.shell.active_space_mut(¤t_output); + let workspace = + self.common.shell.active_space_mut(¤t_output); let focus_stack = workspace.focus_stack(seat); if let Some(window) = workspace.tiling_layer.move_focus( *focus, seat, &mut workspace.space, - focus_stack.iter() + focus_stack.iter(), ) { - self.common.set_focus(dh, Some(window.toplevel().wl_surface()), seat, None); + self.common.set_focus( + dh, + Some(window.toplevel().wl_surface()), + seat, + None, + ); } } Action::Fullscreen => { @@ -324,11 +335,14 @@ impl State { } Action::Orientation(orientation) => { let output = active_output(seat, &self.common); - let workspace = self.common - .shell - .active_space_mut(&output); + let workspace = self.common.shell.active_space_mut(&output); let focus_stack = workspace.focus_stack(seat); - workspace.tiling_layer.update_orientation(*orientation, &seat, &mut workspace.space, focus_stack.iter()); + workspace.tiling_layer.update_orientation( + *orientation, + &seat, + &mut workspace.space, + focus_stack.iter(), + ); } Action::Spawn(command) => { if let Err(err) = std::process::Command::new("/bin/sh") @@ -363,11 +377,7 @@ impl State { .common .shell .outputs() - .find(|output| { - output.geometry() - .to_f64() - .contains(position) - }) + .find(|output| output.geometry().to_f64().contains(position)) .cloned() .unwrap_or(current_output.clone()); if output != current_output { @@ -395,14 +405,16 @@ impl State { output_geometry, &workspace, ); - seat.get_pointer() - .unwrap() - .motion(self, dh, &MotionEvent { + seat.get_pointer().unwrap().motion( + self, + dh, + &MotionEvent { location: position, focus: under, serial, - time: event.time() - }); + time: event.time(), + }, + ); #[cfg(feature = "debug")] if self.common.seats.iter().position(|x| x == seat).unwrap() == 0 { @@ -444,14 +456,16 @@ impl State { geometry, &workspace, ); - seat.get_pointer() - .unwrap() - .motion(self, dh, &MotionEvent { + seat.get_pointer().unwrap().motion( + self, + dh, + &MotionEvent { location: position, focus: under, serial, - time: event.time() - }); + time: event.time(), + }, + ); #[cfg(feature = "debug")] if self.common.seats.iter().position(|x| x == seat).unwrap() == 0 { @@ -548,7 +562,9 @@ impl State { pos - output_geo.loc.to_f64(), WindowSurfaceType::ALL, ) - .map(|(_, _)| window.toplevel().wl_surface().clone()); + .map(|(_, _)| { + window.toplevel().wl_surface().clone() + }); } } else { if let Some(layer) = layers @@ -568,11 +584,9 @@ impl State { ) .map(|(_, _)| layer.wl_surface().clone()); } - } else if let Some((window, _, _)) = - workspace.space.surface_under( - relative_pos, - WindowSurfaceType::ALL, - ) + } else if let Some((window, _, _)) = workspace + .space + .surface_under(relative_pos, WindowSurfaceType::ALL) { under = Some(window.toplevel().wl_surface().clone()); } else if let Some(layer) = @@ -594,20 +608,23 @@ impl State { }; } - self.common.set_focus(dh, under.as_ref(), seat, Some(serial)); + self.common + .set_focus(dh, under.as_ref(), seat, Some(serial)); } wl_pointer::ButtonState::Pressed } ButtonState::Released => wl_pointer::ButtonState::Released, }; - seat.get_pointer() - .unwrap() - .button(self, dh, &ButtonEvent { + seat.get_pointer().unwrap().button( + self, + dh, + &ButtonEvent { button, state, serial, - time: event.time() - }); + time: event.time(), + }, + ); break; } } diff --git a/src/main.rs b/src/main.rs index 0f3451bb..5063c0ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,10 @@ use smithay::{ }; use anyhow::{Context, Result}; -use std::{ffi::OsString, sync::{Arc, atomic::Ordering}}; +use std::{ + ffi::OsString, + sync::{atomic::Ordering, Arc}, +}; pub mod backend; pub mod config; @@ -47,10 +50,7 @@ fn main() -> Result<()> { // potentially tell systemd we are setup now systemd::ready(&state); - let mut data = state::Data { - display, - state, - }; + let mut data = state::Data { display, state }; // run the event loop event_loop.run(None, &mut data, |data| { // shall we shut down? @@ -85,13 +85,15 @@ fn main() -> Result<()> { Ok(()) } -fn init_wayland_display(event_loop: &mut EventLoop) -> Result<(Display, OsString)> { +fn init_wayland_display( + event_loop: &mut EventLoop, +) -> Result<(Display, OsString)> { let mut display = Display::new().unwrap(); let source = ListeningSocketSource::new_auto(None).unwrap(); let socket_name = source.socket_name().to_os_string(); slog_scope::info!("Listening on {:?}", socket_name); - + event_loop .handle() .insert_source(source, |client_stream, _, data| { @@ -108,14 +110,13 @@ fn init_wayland_display(event_loop: &mut EventLoop) -> Result<(Disp .handle() .insert_source( Generic::new(display.backend().poll_fd(), Interest::READ, Mode::Level), - move |_, _, data: &mut state::Data| { - match data.display.dispatch_clients(&mut data.state) { - Ok(_) => Ok(PostAction::Continue), - Err(e) => { - slog_scope::error!("I/O error on the Wayland display: {}", e); - data.state.common.should_stop = true; - Err(e) - } + move |_, _, data: &mut state::Data| match data.display.dispatch_clients(&mut data.state) + { + Ok(_) => Ok(PostAction::Continue), + Err(e) => { + slog_scope::error!("I/O error on the Wayland display: {}", e); + data.state.common.should_stop = true; + Err(e) } }, ) diff --git a/src/shell/focus.rs b/src/shell/focus.rs index bd3c6d01..7649fbf6 100644 --- a/src/shell/focus.rs +++ b/src/shell/focus.rs @@ -1,32 +1,23 @@ -use std::{ - cell::{Ref, RefMut, RefCell}, - collections::HashMap, - sync::Mutex, +use crate::{ + shell::{OutputBoundState, Shell, Workspace, WorkspaceMode}, + state::Common, + utils::prelude::*, + wayland::handlers::xdg_shell::PopupGrabData, }; use indexmap::IndexSet; use smithay::{ - desktop::{ - Window, WindowSurfaceType, - PopupUngrabStrategy, - }, - reexports::wayland_server::{ - DisplayHandle, - protocol::wl_surface::WlSurface, - }, + desktop::{PopupUngrabStrategy, Window, WindowSurfaceType}, + reexports::wayland_server::{protocol::wl_surface::WlSurface, DisplayHandle}, + utils::IsAlive, wayland::{ - compositor::with_states, - seat::Seat, - shell::xdg::XdgToplevelSurfaceRoleAttributes, - Serial, + compositor::with_states, seat::Seat, shell::xdg::XdgToplevelSurfaceRoleAttributes, Serial, SERIAL_COUNTER, }, - utils::IsAlive, }; -use crate::{ - state::Common, - shell::{Shell, OutputBoundState, Workspace, WorkspaceMode}, - wayland::handlers::xdg_shell::PopupGrabData, - utils::prelude::*, +use std::{ + cell::{Ref, RefCell, RefMut}, + collections::HashMap, + sync::Mutex, }; #[derive(Debug, serde::Deserialize, Clone, Copy, PartialEq, Eq)] @@ -130,7 +121,10 @@ impl Shell { // update FocusStack and notify layouts about new focus (if any window) if let Some(surface) = surface { if let Some(workspace) = self.space_for_surface_mut(surface) { - if let Some(window) = workspace.space.window_for_surface(surface, WindowSurfaceType::ALL) { + if let Some(window) = workspace + .space + .window_for_surface(surface, WindowSurfaceType::ALL) + { let mut focus_stack = workspace.focus_stack_mut(active_seat); if Some(window) != focus_stack.last().as_ref() { slog_scope::debug!("Focusing window: {:?}", window); @@ -226,7 +220,10 @@ impl Common { } let workspace = self.shell.active_space(&output); - if let Some(window) = workspace.space.window_for_surface(&surface, WindowSurfaceType::ALL) { + if let Some(window) = workspace + .space + .window_for_surface(&surface, WindowSurfaceType::ALL) + { let focus_stack = workspace.focus_stack(&seat); if focus_stack.last().map(|w| &w != window).unwrap_or(true) { fixup = true; diff --git a/src/shell/layout/floating/grabs.rs b/src/shell/layout/floating/grabs.rs index 862d4117..99886d44 100644 --- a/src/shell/layout/floating/grabs.rs +++ b/src/shell/layout/floating/grabs.rs @@ -1,25 +1,23 @@ // SPDX-License-Identifier: GPL-3.0-only +use crate::utils::prelude::*; use smithay::{ desktop::{Kind, Window}, reexports::{ - wayland_protocols::xdg::shell::server::xdg_toplevel, - wayland_server::DisplayHandle, + wayland_protocols::xdg::shell::server::xdg_toplevel, wayland_server::DisplayHandle, }, utils::{IsAlive, Logical, Point, Size}, wayland::{ compositor::with_states, - seat::{AxisFrame, PointerGrab, PointerGrabStartData, PointerInnerHandle, MotionEvent, ButtonEvent}, + seat::{ + AxisFrame, ButtonEvent, MotionEvent, PointerGrab, PointerGrabStartData, + PointerInnerHandle, + }, shell::xdg::{SurfaceCachedState, ToplevelConfigure, XdgToplevelSurfaceRoleAttributes}, Serial, }, }; -use crate::utils::prelude::*; -use std::{ - cell::RefCell, - convert::TryFrom, - sync::Mutex, -}; +use std::{cell::RefCell, convert::TryFrom, sync::Mutex}; pub struct MoveSurfaceGrab { start_data: PointerGrabStartData, @@ -32,15 +30,19 @@ impl PointerGrab for MoveSurfaceGrab { fn motion( &mut self, data: &mut State, - _dh: &DisplayHandle, - handle: &mut PointerInnerHandle<'_, State>, - event: &MotionEvent + _dh: &DisplayHandle, + handle: &mut PointerInnerHandle<'_, State>, + event: &MotionEvent, ) { // While the grab is active, no client has pointer focus handle.motion(event.location, None, event.serial, event.time); self.delta = event.location - self.start_data.location; - - if let Some(workspace) = data.common.shell.space_for_surface_mut(self.window.toplevel().wl_surface()) { + + if let Some(workspace) = data + .common + .shell + .space_for_surface_mut(self.window.toplevel().wl_surface()) + { let new_location = (self.initial_window_location.to_f64() + self.delta).to_i32_round(); workspace.space.map_window(&self.window, new_location, true); } @@ -197,11 +199,10 @@ impl PointerGrab for ResizeSurfaceGrab { new_window_height = (self.initial_window_size.h as f64 + dy) as i32; } - let (min_size, max_size) = - with_states(self.window.toplevel().wl_surface(), |states| { - let data = states.cached_state.current::(); - (data.min_size, data.max_size) - }); + let (min_size, max_size) = with_states(self.window.toplevel().wl_surface(), |states| { + let data = states.cached_state.current::(); + (data.min_size, data.max_size) + }); let min_width = min_size.w.max(1); let min_height = min_size.h.max(1); diff --git a/src/shell/layout/floating/mod.rs b/src/shell/layout/floating/mod.rs index b823d060..fa6c8139 100644 --- a/src/shell/layout/floating/mod.rs +++ b/src/shell/layout/floating/mod.rs @@ -1,16 +1,16 @@ // SPDX-License-Identifier: GPL-3.0-only use smithay::{ - desktop::{layer_map_for_output, Kind, Space, Window, space::RenderZindex}, + desktop::{layer_map_for_output, space::RenderZindex, Kind, Space, Window}, reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::{ ResizeEdge, State as XdgState, }, + utils::IsAlive, wayland::{ output::Output, seat::{PointerGrabStartData, Seat}, Serial, }, - utils::IsAlive, }; use std::collections::HashSet; @@ -30,12 +30,7 @@ impl FloatingLayout { Default::default() } - pub fn map_window( - &mut self, - space: &mut Space, - window: Window, - seat: &Seat, - ) { + pub fn map_window(&mut self, space: &mut Space, window: Window, seat: &Seat) { if let Some(output) = super::output_from_seat(Some(seat), space) { self.map_window_internal(space, window, &output); } else { @@ -53,12 +48,7 @@ impl FloatingLayout { // TODO make sure all windows are still visible on any output or move them } - fn map_window_internal( - &mut self, - space: &mut Space, - window: Window, - output: &Output - ) { + fn map_window_internal(&mut self, space: &mut Space, window: Window, output: &Output) { let win_geo = window.bbox(); let layers = layer_map_for_output(&output); let geometry = layers.non_exclusive_zone(); diff --git a/src/shell/layout/mod.rs b/src/shell/layout/mod.rs index f2ab6314..c3cf977f 100644 --- a/src/shell/layout/mod.rs +++ b/src/shell/layout/mod.rs @@ -1,15 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only -use crate::{ - input::ActiveOutput, - state::State, -}; +use crate::{input::ActiveOutput, state::State}; use smithay::{ desktop::{Space, Window}, wayland::{ - compositor::with_states, - output::Output, - seat::Seat, + compositor::with_states, output::Output, seat::Seat, shell::xdg::XdgToplevelSurfaceRoleAttributes, }, }; @@ -37,9 +32,7 @@ pub fn should_be_floating(window: &Window) -> bool { // simple heuristic taken from // sway/desktop/xdg_shell.c:188 @ 0ee54a52 if attrs.parent.is_some() - || (attrs.min_size.w != 0 - && attrs.min_size.h != 0 - && attrs.min_size == attrs.max_size) + || (attrs.min_size.w != 0 && attrs.min_size.h != 0 && attrs.min_size == attrs.max_size) { return true; } diff --git a/src/shell/layout/tiling/grabs.rs b/src/shell/layout/tiling/grabs.rs index fddeb9cd..74baf07c 100644 --- a/src/shell/layout/tiling/grabs.rs +++ b/src/shell/layout/tiling/grabs.rs @@ -1,16 +1,13 @@ // SPDX-License-Identifier: GPL-3.0-only -use crate::{ - utils::prelude::*, - shell::layout::Orientation, -}; +use crate::{shell::layout::Orientation, utils::prelude::*}; use atomic_float::AtomicF64; use smithay::{ - reexports::wayland_server::{ - DisplayHandle, - }, + reexports::wayland_server::DisplayHandle, utils::{Logical, Size}, - wayland::seat::{AxisFrame, PointerGrab, PointerGrabStartData, PointerInnerHandle, MotionEvent, ButtonEvent}, + wayland::seat::{ + AxisFrame, ButtonEvent, MotionEvent, PointerGrab, PointerGrabStartData, PointerInnerHandle, + }, }; use std::sync::{atomic::Ordering, Arc}; @@ -26,9 +23,9 @@ impl PointerGrab for ResizeForkGrab { fn motion( &mut self, _data: &mut State, - _dh: &DisplayHandle, - handle: &mut PointerInnerHandle<'_, State>, - event: &MotionEvent + _dh: &DisplayHandle, + handle: &mut PointerInnerHandle<'_, State>, + event: &MotionEvent, ) { // While the grab is active, no client has pointer focus handle.motion(event.location, None, event.serial, event.time); @@ -58,7 +55,8 @@ impl PointerGrab for ResizeForkGrab { } } - fn axis(&mut self, + fn axis( + &mut self, _data: &mut State, _dh: &DisplayHandle, handle: &mut PointerInnerHandle<'_, State>, diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index 3a4102cb..09dcdcb9 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -1,10 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only use crate::{ - shell::{ - layout::Orientation, - focus::FocusDirection, - }, + shell::{focus::FocusDirection, layout::Orientation}, utils::prelude::*, }; @@ -187,7 +184,12 @@ impl TilingLayout { if let Some(root_id) = tree.root_node_id() { for node in tree.traverse_pre_order(root_id).unwrap() { if let Data::Window(window) = node.data() { - self.map_window_internal(space, window, None, Option::>::None); + self.map_window_internal( + space, + window, + None, + Option::>::None, + ); } } } @@ -274,7 +276,7 @@ impl TilingLayout { } } } - + fn active_tree<'a>(trees: &'a mut Vec>, output: usize) -> &'a mut Tree { while trees.len() <= output { trees.push(Tree::new()) @@ -558,11 +560,8 @@ impl TilingLayout { if let Some(geo) = geo { #[allow(irrefutable_let_patterns)] if let Kind::Xdg(xdg) = &window.toplevel() { - if xdg - .current_state() - .states.contains(XdgState::Fullscreen) - || xdg - .with_pending_state(|pending| { + if xdg.current_state().states.contains(XdgState::Fullscreen) + || xdg.with_pending_state(|pending| { pending.states.contains(XdgState::Fullscreen) }) { diff --git a/src/shell/mod.rs b/src/shell/mod.rs index aeb830ae..d6278930 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -1,54 +1,41 @@ -use std::{ - cell::Cell, - mem::MaybeUninit, -}; +use std::{cell::Cell, mem::MaybeUninit}; use smithay::{ - desktop::{ - LayerSurface, - PopupManager, - Window, - WindowSurfaceType, - layer_map_for_output, - }, - reexports::wayland_server::{ - DisplayHandle, - protocol::wl_surface::WlSurface, - }, + desktop::{layer_map_for_output, LayerSurface, PopupManager, Window, WindowSurfaceType}, + reexports::wayland_server::{protocol::wl_surface::WlSurface, DisplayHandle}, + utils::{Logical, Point, Rectangle}, wayland::{ compositor::with_states, - seat::{Seat, MotionEvent}, + output::Output, + seat::{MotionEvent, Seat}, shell::{ - wlr_layer::{WlrLayerShellState, Layer, LayerSurfaceCachedState, KeyboardInteractivity}, + wlr_layer::{ + KeyboardInteractivity, Layer, LayerSurfaceCachedState, WlrLayerShellState, + }, xdg::XdgShellState, }, - output::Output, SERIAL_COUNTER, }, - utils::{Point, Rectangle, Logical}, }; use cosmic_protocols::workspace::v1::server::zcosmic_workspace_handle_v1::State as WState; use crate::{ config::{Config, WorkspaceMode as ConfigMode}, + utils::prelude::*, wayland::protocols::{ toplevel_info::ToplevelInfoState, workspace::{ - WorkspaceState, - WorkspaceGroupHandle, - WorkspaceHandle, - WorkspaceCapabilities, + WorkspaceCapabilities, WorkspaceGroupHandle, WorkspaceHandle, WorkspaceState, WorkspaceUpdateGuard, }, }, - utils::prelude::*, }; pub const MAX_WORKSPACES: usize = 10; +pub mod focus; pub mod layout; mod workspace; -pub mod focus; pub use self::workspace::*; pub struct Shell { @@ -101,11 +88,20 @@ impl Shell { let mut spaces = unsafe { let mut spaces = [UNINIT_SPACE; MAX_WORKSPACES]; for (idx, space) in spaces.iter_mut().enumerate() { - *space = MaybeUninit::new(Workspace::new(idx as u8, std::mem::zeroed() /* Will be initialized by init_mode */)); + *space = MaybeUninit::new(Workspace::new( + idx as u8, + std::mem::zeroed(), /* Will be initialized by init_mode */ + )); } std::mem::transmute(spaces) }; - let mode = init_mode(&config.static_conf.workspace_mode, None, &[], &mut workspace_state, &mut spaces); + let mode = init_mode( + &config.static_conf.workspace_mode, + None, + &[], + &mut workspace_state, + &mut spaces, + ); Shell { popups: PopupManager::new(None), @@ -131,14 +127,22 @@ impl Shell { match self.workspace_mode { WorkspaceMode::OutputBound => { - let idx = self.spaces + let idx = self + .spaces .iter() .position(|x| x.space.outputs().next().is_none()) .expect("More then 10 outputs?"); - remap_output(output, &mut self.spaces, None, idx, Point::from((0, 0)), &mut self.toplevel_info_state); + remap_output( + output, + &mut self.spaces, + None, + idx, + Point::from((0, 0)), + &mut self.toplevel_info_state, + ); let mut workspace = &mut self.spaces[idx]; - + let group = state.create_workspace_group(); state.add_group_output(&group, output); state.remove_workspace(workspace.handle); @@ -156,16 +160,26 @@ impl Shell { } } - if !output.user_data().insert_if_missing(|| output_state.clone()) { + if !output + .user_data() + .insert_if_missing(|| output_state.clone()) + { let existing_state = output.user_data().get::().unwrap(); existing_state.active.set(output_state.active.get()); existing_state.group.set(output_state.group.get()); } - }, + } WorkspaceMode::Global { active, group } => { state.add_group_output(&group, output); - - remap_output(output, &mut self.spaces, None, active, output.current_location(), &mut self.toplevel_info_state); + + remap_output( + output, + &mut self.spaces, + None, + active, + output.current_location(), + &mut self.toplevel_info_state, + ); } } } @@ -173,16 +187,29 @@ impl Shell { pub fn remove_output(&mut self, output: &Output) { let mut state = self.workspace_state.update(); self.outputs.retain(|o| o != output); - + match self.workspace_mode { WorkspaceMode::OutputBound => { let output_state = output.user_data().get::().unwrap(); - remap_output(output, &mut self.spaces, output_state.active.get(), None, None, &mut self.toplevel_info_state); + remap_output( + output, + &mut self.spaces, + output_state.active.get(), + None, + None, + &mut self.toplevel_info_state, + ); // reassign workspaces to a different output - let new_group = self.outputs.iter().next().map(|o| o.user_data().get::().unwrap().group.get()); + let new_group = self + .outputs + .iter() + .next() + .map(|o| o.user_data().get::().unwrap().group.get()); for mut workspace in self.spaces.iter_mut() { - if state.workspace_belongs_to_group(&output_state.group.get(), &workspace.handle) { + if state + .workspace_belongs_to_group(&output_state.group.get(), &workspace.handle) + { state.remove_workspace(workspace.handle); if let Some(new_group) = new_group { init_workspace_handle(&mut state, &new_group, &mut workspace); @@ -192,12 +219,19 @@ impl Shell { // destroy workspace group state.remove_workspace_group(output_state.group.get()); - }, + } WorkspaceMode::Global { active, group } => { state.remove_group_output(&group, output); - remap_output(output, &mut self.spaces, active, None, None, &mut self.toplevel_info_state); - }, + remap_output( + output, + &mut self.spaces, + active, + None, + None, + &mut self.toplevel_info_state, + ); + } }; } @@ -205,7 +239,9 @@ impl Shell { if let WorkspaceMode::Global { active, .. } = self.workspace_mode { let workspace = &mut self.spaces[active]; for output in self.outputs.iter() { - workspace.space.map_output(output, output.current_location()); + workspace + .space + .map_output(output, output.current_location()); } } else { for output in self.outputs.iter() { @@ -225,27 +261,68 @@ impl Shell { match (&mut self.workspace_mode, mode) { (WorkspaceMode::OutputBound, ConfigMode::Global) => { let new_active = 0; - init_mode(&mode, Some(&WorkspaceMode::OutputBound), &self.outputs, &mut self.workspace_state, &mut self.spaces); + init_mode( + &mode, + Some(&WorkspaceMode::OutputBound), + &self.outputs, + &mut self.workspace_state, + &mut self.spaces, + ); for output in &self.outputs { - let old_active = output.user_data().get::().unwrap().active.get(); - remap_output(output, &mut self.spaces, old_active, new_active, output.current_location(), &mut self.toplevel_info_state); + let old_active = output + .user_data() + .get::() + .unwrap() + .active + .get(); + remap_output( + output, + &mut self.spaces, + old_active, + new_active, + output.current_location(), + &mut self.toplevel_info_state, + ); } - }, + } (x @ WorkspaceMode::Global { .. }, ConfigMode::OutputBound) => { // inits OutputBoundState if it not exists - init_mode(&mode, Some(x), &self.outputs, &mut self.workspace_state, &mut self.spaces); + init_mode( + &mode, + Some(x), + &self.outputs, + &mut self.workspace_state, + &mut self.spaces, + ); if let WorkspaceMode::Global { ref active, .. } = x { for output in &self.outputs { - let new_active = output.user_data().get::().unwrap().active.get(); - remap_output(output, &mut self.spaces, *active, new_active, Point::from((0, 0)), &mut self.toplevel_info_state); + let new_active = output + .user_data() + .get::() + .unwrap() + .active + .get(); + remap_output( + output, + &mut self.spaces, + *active, + new_active, + Point::from((0, 0)), + &mut self.toplevel_info_state, + ); } } - }, - _ => {}, + } + _ => {} } } - pub fn activate(&mut self, seat: &Seat, output: &Output, idx: usize) -> Option { + pub fn activate( + &mut self, + seat: &Seat, + output: &Output, + idx: usize, + ) -> Option { if idx > MAX_WORKSPACES { return None; } @@ -254,7 +331,14 @@ impl Shell { WorkspaceMode::OutputBound => { // if the workspace is active on a different output, move the cursor over for output in self.outputs.iter().filter(|o| o != &output) { - if output.user_data().get::().unwrap().active.get() == idx { + if output + .user_data() + .get::() + .unwrap() + .active + .get() + == idx + { let geometry = output.geometry(); set_active_output(seat, output); return Some(MotionEvent { @@ -277,25 +361,46 @@ impl Shell { let mut state = self.workspace_state.update(); output_state.active.set(idx); - if !state.workspace_belongs_to_group(&output_state.group.get(), &self.spaces[idx].handle) { + if !state.workspace_belongs_to_group( + &output_state.group.get(), + &self.spaces[idx].handle, + ) { state.remove_workspace(self.spaces[idx].handle); - init_workspace_handle(&mut state, &output_state.group.get(), &mut self.spaces[idx]); + init_workspace_handle( + &mut state, + &output_state.group.get(), + &mut self.spaces[idx], + ); } - + state.remove_workspace_state(&self.spaces[old_active].handle, WState::Active); state.add_workspace_state(&self.spaces[idx].handle, WState::Active); std::mem::drop(state); - remap_output(output, &mut self.spaces, old_active, idx, Point::from((0, 0)), &mut self.toplevel_info_state); + remap_output( + output, + &mut self.spaces, + old_active, + idx, + Point::from((0, 0)), + &mut self.toplevel_info_state, + ); } - }, + } WorkspaceMode::Global { ref mut active, .. } => { let old = *active; *active = idx; let mut state = self.workspace_state.update(); for output in &self.outputs { - remap_output(output, &mut self.spaces, old, idx, output.current_location(), &mut self.toplevel_info_state); + remap_output( + output, + &mut self.spaces, + old, + idx, + output.current_location(), + &mut self.toplevel_info_state, + ); } state.remove_workspace_state(&self.spaces[old].handle, WState::Active); state.add_workspace_state(&self.spaces[idx].handle, WState::Active); @@ -335,28 +440,38 @@ impl Shell { } } - pub fn outputs_for_surface(&self, surface: &WlSurface) -> impl Iterator { + pub fn outputs_for_surface(&self, surface: &WlSurface) -> impl Iterator { self.space_for_surface(surface) - .and_then(|w| if let Some(window) = w.space.window_for_surface(surface, WindowSurfaceType::ALL) { - Some(w.space.outputs_for_window(&window).into_iter()) - } else { None }) + .and_then(|w| { + if let Some(window) = w.space.window_for_surface(surface, WindowSurfaceType::ALL) { + Some(w.space.outputs_for_window(&window).into_iter()) + } else { + None + } + }) .into_iter() .flatten() } pub fn space_for_surface(&self, surface: &WlSurface) -> Option<&Workspace> { self.spaces.iter().find(|workspace| { - workspace.space.window_for_surface(surface, WindowSurfaceType::ALL).is_some() + workspace + .space + .window_for_surface(surface, WindowSurfaceType::ALL) + .is_some() }) } pub fn space_for_surface_mut(&mut self, surface: &WlSurface) -> Option<&mut Workspace> { - self.spaces - .iter_mut() - .find(|workspace| workspace.space.window_for_surface(surface, WindowSurfaceType::ALL).is_some()) + self.spaces.iter_mut().find(|workspace| { + workspace + .space + .window_for_surface(surface, WindowSurfaceType::ALL) + .is_some() + }) } - - pub fn outputs(&self) -> impl Iterator { + + pub fn outputs(&self) -> impl Iterator { self.outputs.iter() } @@ -411,11 +526,16 @@ impl Shell { map.cleanup(); } std::mem::drop(state); - self.toplevel_info_state.refresh(Some(&self.workspace_state)); + self.toplevel_info_state + .refresh(Some(&self.workspace_state)); } - + pub fn map_window(&mut self, window: &Window, output: &Output) { - let pos = self.pending_windows.iter().position(|(w, _)| w == window).unwrap(); + let pos = self + .pending_windows + .iter() + .position(|(w, _)| w == window) + .unwrap(); let (window, seat) = self.pending_windows.remove(pos); let workspace = match &self.workspace_mode { @@ -430,20 +550,34 @@ impl Shell { } WorkspaceMode::Global { active, .. } => &mut self.spaces[*active], }; - self.workspace_state.update().remove_workspace_state(&workspace.handle, WState::Hidden); - self.toplevel_info_state.toplevel_enter_workspace(&window, &workspace.handle); + self.workspace_state + .update() + .remove_workspace_state(&workspace.handle, WState::Hidden); + self.toplevel_info_state + .toplevel_enter_workspace(&window, &workspace.handle); let focus_stack = workspace.focus_stack(&seat); if layout::should_be_floating(&window) { - workspace.floating_layer.map_window(&mut workspace.space, window, &seat); + workspace + .floating_layer + .map_window(&mut workspace.space, window, &seat); } else { - workspace.tiling_layer.map_window(&mut workspace.space, window, &seat, focus_stack.iter()); + workspace.tiling_layer.map_window( + &mut workspace.space, + window, + &seat, + focus_stack.iter(), + ); } } pub fn map_layer(&mut self, layer_surface: &LayerSurface, dh: &DisplayHandle) { - let pos = self.pending_layers.iter().position(|(l, _, _)| l == layer_surface).unwrap(); + let pos = self + .pending_layers + .iter() + .position(|(l, _, _)| l == layer_surface) + .unwrap(); let (layer_surface, output, seat) = self.pending_layers.remove(pos); - + let surface = layer_surface.wl_surface(); let wants_focus = { with_states(surface, |states| { @@ -484,17 +618,30 @@ impl Shell { let maybe_window = workspace.focus_stack(seat).last(); if let Some(window) = maybe_window { - workspace.floating_layer.unmap_window(&mut workspace.space, &window); - workspace.tiling_layer.unmap_window(&mut workspace.space, &window); - self.toplevel_info_state.toplevel_leave_workspace(&window, &workspace.handle); - + workspace + .floating_layer + .unmap_window(&mut workspace.space, &window); + workspace + .tiling_layer + .unmap_window(&mut workspace.space, &window); + self.toplevel_info_state + .toplevel_leave_workspace(&window, &workspace.handle); + let new_workspace = &mut self.spaces[idx]; - self.toplevel_info_state.toplevel_enter_workspace(&window, &new_workspace.handle); + self.toplevel_info_state + .toplevel_enter_workspace(&window, &new_workspace.handle); let focus_stack = new_workspace.focus_stack(&seat); if layout::should_be_floating(&window) { - new_workspace.floating_layer.map_window(&mut new_workspace.space, window, &seat); + new_workspace + .floating_layer + .map_window(&mut new_workspace.space, window, &seat); } else { - new_workspace.tiling_layer.map_window(&mut new_workspace.space, window, &seat, focus_stack.iter()); + new_workspace.tiling_layer.map_window( + &mut new_workspace.space, + window, + &seat, + focus_stack.iter(), + ); } } } @@ -505,7 +652,7 @@ fn init_mode( old_mode: Option<&WorkspaceMode>, outputs: &[Output], state: &mut WorkspaceState, - workspaces: &mut [Workspace; MAX_WORKSPACES] + workspaces: &mut [Workspace; MAX_WORKSPACES], ) -> WorkspaceMode { let mut state = state.update(); @@ -513,15 +660,17 @@ fn init_mode( for workspace in workspaces.iter_mut() { state.remove_workspace(workspace.handle); } - + match old_mode { Some(WorkspaceMode::Global { group, .. }) => state.remove_workspace_group(group.clone()), - Some(WorkspaceMode::OutputBound) => for output in outputs { - if let Some(old_state) = output.user_data().get::() { - state.remove_workspace_group(old_state.group.get()); + Some(WorkspaceMode::OutputBound) => { + for output in outputs { + if let Some(old_state) = output.user_data().get::() { + state.remove_workspace_group(old_state.group.get()); + } } - }, - _ => {}, + } + _ => {} }; // set the new state (especially cosmic_workspace state) @@ -536,11 +685,8 @@ fn init_mode( } state.add_workspace_state(&workspaces[0].handle, WState::Active); state.remove_workspace_state(&workspaces[0].handle, WState::Hidden); - WorkspaceMode::Global { - active: 0, - group, - } - }, + WorkspaceMode::Global { active: 0, group } + } ConfigMode::OutputBound => { for (i, output) in outputs.iter().enumerate() { let group = state.create_workspace_group(); @@ -564,7 +710,12 @@ fn init_mode( } if !outputs.is_empty() { for workspace in workspaces.iter_mut().skip(outputs.iter().count()) { - let group = outputs[0].user_data().get::().unwrap().group.get(); + let group = outputs[0] + .user_data() + .get::() + .unwrap() + .group + .get(); init_workspace_handle(&mut state, &group, workspace); } } @@ -573,7 +724,11 @@ fn init_mode( } } -fn init_workspace_handle<'a>(state: &mut WorkspaceUpdateGuard<'a, State>, group: &WorkspaceGroupHandle, workspace: &mut Workspace) -> WorkspaceHandle { +fn init_workspace_handle<'a>( + state: &mut WorkspaceUpdateGuard<'a, State>, + group: &WorkspaceGroupHandle, + workspace: &mut Workspace, +) -> WorkspaceHandle { let handle = state.create_workspace(&group).unwrap(); state.set_workspace_capabilities(&handle, [WorkspaceCapabilities::Activate].into_iter()); state.set_workspace_name(&handle, format!("{}", workspace.idx)); @@ -591,7 +746,7 @@ fn remap_output( old: impl Into>, new: impl Into>, pos: impl Into>>, - info_state: &mut ToplevelInfoState + info_state: &mut ToplevelInfoState, ) { if let Some(old) = old.into() { let old_space = &mut spaces[old].space; @@ -607,4 +762,4 @@ fn remap_output( info_state.toplevel_enter_output(window, output); } } -} \ No newline at end of file +} diff --git a/src/shell/workspace.rs b/src/shell/workspace.rs index 9d2ec52c..56e7406b 100644 --- a/src/shell/workspace.rs +++ b/src/shell/workspace.rs @@ -1,7 +1,6 @@ - use crate::{ + shell::layout::{floating::FloatingLayout, tiling::TilingLayout}, state::State, - shell::layout::{tiling::TilingLayout, floating::FloatingLayout}, wayland::protocols::workspace::WorkspaceHandle, }; @@ -11,12 +10,12 @@ use smithay::{ wayland_protocols::xdg::shell::server::xdg_toplevel::{self, ResizeEdge}, wayland_server::DisplayHandle, }, + utils::IsAlive, wayland::{ output::Output, seat::{PointerGrabStartData, Seat}, Serial, }, - utils::IsAlive, }; use std::collections::HashMap; @@ -64,7 +63,8 @@ impl Workspace { return; } if self.floating_layer.windows.contains(window) { - self.floating_layer.maximize_request(&mut self.space, window, output); + self.floating_layer + .maximize_request(&mut self.space, window, output); } } @@ -79,7 +79,8 @@ impl Workspace { return; } if self.floating_layer.windows.contains(window) { - self.floating_layer.move_request(&mut self.space, window, seat, serial, start_data) + self.floating_layer + .move_request(&mut self.space, window, seat, serial, start_data) } } @@ -95,10 +96,24 @@ impl Workspace { return; } if self.floating_layer.windows.contains(window) { - self.floating_layer.resize_request(&mut self.space, window, seat, serial, start_data.clone(), edges) + self.floating_layer.resize_request( + &mut self.space, + window, + seat, + serial, + start_data.clone(), + edges, + ) } if self.tiling_layer.windows.contains(window) { - self.tiling_layer.resize_request(&mut self.space, window, seat, serial, start_data, edges) + self.tiling_layer.resize_request( + &mut self.space, + window, + seat, + serial, + start_data, + edges, + ) } } @@ -155,8 +170,6 @@ impl Workspace { if !self.space.outputs().any(|o| o == output) { return None; } - self.fullscreen - .get(&output.name()) - .filter(|w| w.alive()) + self.fullscreen.get(&output.name()).filter(|w| w.alive()) } } diff --git a/src/state.rs b/src/state.rs index a1bfedaa..31c2bc02 100644 --- a/src/state.rs +++ b/src/state.rs @@ -6,8 +6,7 @@ use crate::{ logger::LogState, shell::Shell, wayland::protocols::{ - drm::WlDrmState, - output_configuration::OutputConfigurationState, + drm::WlDrmState, output_configuration::OutputConfigurationState, workspace::WorkspaceClientState, }, }; @@ -24,10 +23,7 @@ use smithay::{ compositor::CompositorState, data_device::DataDeviceState, dmabuf::DmabufState, - output::{ - OutputManagerState, - Mode as OutputMode, Output, Scale, - }, + output::{Mode as OutputMode, Output, OutputManagerState, Scale}, seat::{Seat, SeatState}, shm::ShmState, viewporter::ViewporterState, diff --git a/src/utils/prelude.rs b/src/utils/prelude.rs index dde908a1..347b3919 100644 --- a/src/utils/prelude.rs +++ b/src/utils/prelude.rs @@ -1,19 +1,11 @@ -use std::cell::RefCell; +use crate::{input::ActiveOutput, state::Common}; use smithay::{ - wayland::{ - output::Output, - seat::Seat, - }, - utils::{Rectangle, Transform, Logical}, -}; -use crate::{ - input::ActiveOutput, - state::Common, + utils::{Logical, Rectangle, Transform}, + wayland::{output::Output, seat::Seat}, }; +use std::cell::RefCell; -pub use crate::{ - state::State, -}; +pub use crate::state::State; pub trait OutputExt { fn geometry(&self) -> Rectangle; @@ -21,14 +13,17 @@ pub trait OutputExt { impl OutputExt for Output { fn geometry(&self) -> Rectangle { - Rectangle::from_loc_and_size( - self.current_location(), - { - Transform::from(self.current_transform()).transform_size( - self.current_mode().map(|m| m.size).unwrap_or_else(|| (0,0).into()) - ).to_f64().to_logical(self.current_scale().fractional_scale()).to_i32_round() - }, - ) + Rectangle::from_loc_and_size(self.current_location(), { + Transform::from(self.current_transform()) + .transform_size( + self.current_mode() + .map(|m| m.size) + .unwrap_or_else(|| (0, 0).into()), + ) + .to_f64() + .to_logical(self.current_scale().fractional_scale()) + .to_i32_round() + }) } } diff --git a/src/wayland/handlers/buffer.rs b/src/wayland/handlers/buffer.rs index 842c5e57..eb21f57f 100644 --- a/src/wayland/handlers/buffer.rs +++ b/src/wayland/handlers/buffer.rs @@ -1,10 +1,9 @@ // SPDX-License-Identifier: GPL-3.0-only -use smithay::{ - reexports::wayland_server::protocol::wl_buffer::WlBuffer, - wayland::buffer::BufferHandler, -}; use crate::utils::prelude::*; +use smithay::{ + reexports::wayland_server::protocol::wl_buffer::WlBuffer, wayland::buffer::BufferHandler, +}; impl BufferHandler for State { fn buffer_destroyed(&mut self, _buffer: &WlBuffer) {} diff --git a/src/wayland/handlers/compositor.rs b/src/wayland/handlers/compositor.rs index 5f57fbb4..70b72011 100644 --- a/src/wayland/handlers/compositor.rs +++ b/src/wayland/handlers/compositor.rs @@ -1,43 +1,22 @@ // SPDX-License-Identifier: GPL-3.0-only -use std::{ - sync::Mutex, -}; +use crate::{state::BackendData, utils::prelude::*}; use smithay::{ - backend::renderer::utils::{ - on_commit_buffer_handler, - }, - desktop::{ - LayerSurface, - PopupKind, - Kind, - WindowSurfaceType, - }, - reexports::wayland_server::{ - DisplayHandle, - protocol::wl_surface::WlSurface, - }, - wayland::{ - compositor::{ - CompositorHandler, - CompositorState, - with_states, - }, - shell::{ - xdg::{ - ToplevelSurface, - XdgToplevelSurfaceRoleAttributes, - XdgPopupSurfaceRoleAttributes, - }, - wlr_layer::LayerSurfaceAttributes, - }, - }, + backend::renderer::utils::on_commit_buffer_handler, delegate_compositor, + desktop::{Kind, LayerSurface, PopupKind, WindowSurfaceType}, + reexports::wayland_server::{protocol::wl_surface::WlSurface, DisplayHandle}, + wayland::{ + compositor::{with_states, CompositorHandler, CompositorState}, + shell::{ + wlr_layer::LayerSurfaceAttributes, + xdg::{ + ToplevelSurface, XdgPopupSurfaceRoleAttributes, XdgToplevelSurfaceRoleAttributes, + }, + }, + }, }; -use crate::{ - state::BackendData, - utils::prelude::*, -}; +use std::sync::Mutex; impl State { fn early_import_surface(&mut self, dh: &DisplayHandle, surface: &WlSurface) { @@ -46,12 +25,17 @@ impl State { if let BackendData::Kms(ref mut kms_state) = &mut self.backend { if let Some(target) = kms_state.target_node_for_output(&output) { if import_nodes.insert(target) { - kms_state.try_early_import(dh, surface, &output, target, &self.common.shell); + kms_state.try_early_import( + dh, + surface, + &output, + target, + &self.common.shell, + ); } } } - self - .backend + self.backend .schedule_render(&self.common.event_loop_handle, &output); } } @@ -119,9 +103,14 @@ impl CompositorHandler for State { fn commit(&mut self, dh: &DisplayHandle, surface: &WlSurface) { // initial configure - if let Some((window, seat)) = self.common.shell.pending_windows.iter().find(|(window, _)| { - window.toplevel().wl_surface() == surface - }).cloned() { + if let Some((window, seat)) = self + .common + .shell + .pending_windows + .iter() + .find(|(window, _)| window.toplevel().wl_surface() == surface) + .cloned() + { match window.toplevel() { Kind::Xdg(toplevel) => { if self.toplevel_ensure_initial_configure(&toplevel) { @@ -134,9 +123,14 @@ impl CompositorHandler for State { } } - if let Some((layer_surface, _, _)) = self.common.shell.pending_layers.iter().find(|(layer_surface, _, _)| { - layer_surface.wl_surface() == surface - }).cloned() { + if let Some((layer_surface, _, _)) = self + .common + .shell + .pending_layers + .iter() + .find(|(layer_surface, _, _)| layer_surface.wl_surface() == surface) + .cloned() + { if self.layer_surface_ensure_inital_configure(&layer_surface) { self.common.shell.map_layer(&layer_surface, dh); } else { @@ -163,16 +157,17 @@ impl CompositorHandler for State { .map(|window| (&mut workspace.space, window)) }) { - let new_location = crate::shell::layout::floating::ResizeSurfaceGrab::apply_resize_state( - &window, - space.window_location(&window).unwrap(), - window.geometry().size, - ); + let new_location = + crate::shell::layout::floating::ResizeSurfaceGrab::apply_resize_state( + &window, + space.window_location(&window).unwrap(), + window.geometry().size, + ); if let Some(location) = new_location { space.map_window(&window, location, true); } } - + on_commit_buffer_handler(surface); self.early_import_surface(dh, surface); self.common.shell.popups.commit(surface); diff --git a/src/wayland/handlers/data_device.rs b/src/wayland/handlers/data_device.rs index b6a4edfc..4295b0d9 100644 --- a/src/wayland/handlers/data_device.rs +++ b/src/wayland/handlers/data_device.rs @@ -1,23 +1,17 @@ // SPDX-License-Identifier: GPL-3.0-only -use std::cell::RefCell; +use crate::state::State; use smithay::{ - reexports::wayland_server::protocol::{ - wl_data_source::WlDataSource, - wl_surface::WlSurface, - }, + delegate_data_device, + reexports::wayland_server::protocol::{wl_data_source::WlDataSource, wl_surface::WlSurface}, wayland::{ data_device::{ - DataDeviceState, - DataDeviceHandler, - ClientDndGrabHandler, - ServerDndGrabHandler, + ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, ServerDndGrabHandler, }, seat::Seat, }, - delegate_data_device, }; -use crate::state::State; +use std::cell::RefCell; pub struct DnDIcon { surface: RefCell>, @@ -32,10 +26,10 @@ pub fn get_dnd_icon(seat: &Seat) -> Option { impl ClientDndGrabHandler for State { fn started( - &mut self, - _source: Option, - icon: Option, - seat: Seat + &mut self, + _source: Option, + icon: Option, + seat: Seat, ) { let user_data = seat.user_data(); user_data.insert_if_missing(|| DnDIcon { diff --git a/src/wayland/handlers/dmabuf.rs b/src/wayland/handlers/dmabuf.rs index df6e8fce..0e35c65c 100644 --- a/src/wayland/handlers/dmabuf.rs +++ b/src/wayland/handlers/dmabuf.rs @@ -1,32 +1,36 @@ // SPDX-License-Identifier: GPL-3.0-only +use crate::state::{BackendData, State}; use smithay::{ - backend::{ - allocator::dmabuf::Dmabuf, - renderer::ImportDma, - }, + backend::{allocator::dmabuf::Dmabuf, renderer::ImportDma}, + delegate_dmabuf, reexports::wayland_server::DisplayHandle, wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportError}, - delegate_dmabuf, }; -use crate::state::{BackendData, State}; impl DmabufHandler for State { fn dmabuf_state(&mut self) -> &mut DmabufState { &mut self.common.dmabuf_state } - fn dmabuf_imported(&mut self, dh: &DisplayHandle, global: &DmabufGlobal, dmabuf: Dmabuf) -> Result<(), ImportError> { + fn dmabuf_imported( + &mut self, + dh: &DisplayHandle, + global: &DmabufGlobal, + dmabuf: Dmabuf, + ) -> Result<(), ImportError> { match &mut self.backend { BackendData::Kms(ref mut state) => state .dmabuf_imported(dh, global, dmabuf) .map_err(|_| ImportError::Failed), - BackendData::Winit(ref mut state) => state.backend + BackendData::Winit(ref mut state) => state + .backend .renderer() .import_dmabuf(&dmabuf, None) .map(|_| ()) .map_err(|_| ImportError::Failed), - BackendData::X11(ref mut state) => state.renderer + BackendData::X11(ref mut state) => state + .renderer .import_dmabuf(&dmabuf, None) .map(|_| ()) .map_err(|_| ImportError::Failed), diff --git a/src/wayland/handlers/layer_shell.rs b/src/wayland/handlers/layer_shell.rs index 7669aec3..70d0aa77 100644 --- a/src/wayland/handlers/layer_shell.rs +++ b/src/wayland/handlers/layer_shell.rs @@ -1,23 +1,17 @@ // SPDX-License-Identifier: GPL-3.0-only +use crate::utils::prelude::*; use smithay::{ + delegate_layer_shell, desktop::LayerSurface, - reexports::wayland_server::{ - DisplayHandle, - protocol::wl_output::WlOutput, - }, + reexports::wayland_server::{protocol::wl_output::WlOutput, DisplayHandle}, wayland::{ output::Output, shell::wlr_layer::{ - WlrLayerShellHandler, - WlrLayerShellState, - LayerSurface as WlrLayerSurface, - Layer, + Layer, LayerSurface as WlrLayerSurface, WlrLayerShellHandler, WlrLayerShellState, }, }, - delegate_layer_shell, }; -use crate::utils::prelude::*; impl WlrLayerShellHandler for State { fn shell_state(&mut self) -> &mut WlrLayerShellState { @@ -25,12 +19,12 @@ impl WlrLayerShellHandler for State { } fn new_layer_surface( - &mut self, - _dh: &DisplayHandle, - surface: WlrLayerSurface, - wl_output: Option, - _layer: Layer, - namespace: String + &mut self, + _dh: &DisplayHandle, + surface: WlrLayerSurface, + wl_output: Option, + _layer: Layer, + namespace: String, ) { super::mark_dirty_on_drop(&self.common, surface.wl_surface()); let seat = self.common.last_active_seat.clone(); diff --git a/src/wayland/handlers/mod.rs b/src/wayland/handlers/mod.rs index 0569df3d..c22de5a1 100644 --- a/src/wayland/handlers/mod.rs +++ b/src/wayland/handlers/mod.rs @@ -23,8 +23,8 @@ use smithay::{ fn mark_dirty_on_drop(state: &Common, wl_surface: &WlSurface) { use std::sync::{ - Arc, atomic::{AtomicBool, Ordering}, + Arc, }; let dirty = state.dirty_flag.clone(); @@ -33,7 +33,9 @@ fn mark_dirty_on_drop(state: &Common, wl_surface: &WlSurface) { with_states(wl_surface, |data| { data.data_map.insert_if_missing(|| DirtyFlag(dirty)); }); - add_destruction_hook(wl_surface, |data| if let Some(DirtyFlag(dirty)) = data.data_map.get::() { - dirty.store(true, Ordering::SeqCst); + add_destruction_hook(wl_surface, |data| { + if let Some(DirtyFlag(dirty)) = data.data_map.get::() { + dirty.store(true, Ordering::SeqCst); + } }) -} \ No newline at end of file +} diff --git a/src/wayland/handlers/output.rs b/src/wayland/handlers/output.rs index f34fa652..f631ba10 100644 --- a/src/wayland/handlers/output.rs +++ b/src/wayland/handlers/output.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only -use smithay::delegate_output; use crate::state::State; +use smithay::delegate_output; delegate_output!(State); diff --git a/src/wayland/handlers/output_configuration.rs b/src/wayland/handlers/output_configuration.rs index ef67f4c4..7e3a1fb8 100644 --- a/src/wayland/handlers/output_configuration.rs +++ b/src/wayland/handlers/output_configuration.rs @@ -6,11 +6,8 @@ use crate::{ config::OutputConfig, state::State, wayland::protocols::output_configuration::{ - OutputConfigurationState, - OutputConfigurationHandler, - OutputConfiguration, - ModeConfiguration, - delegate_output_configuration, + delegate_output_configuration, ModeConfiguration, OutputConfiguration, + OutputConfigurationHandler, OutputConfigurationState, }, }; @@ -30,8 +27,15 @@ impl OutputConfigurationHandler for State { } impl State { - fn output_configuration(&mut self, test_only: bool, conf: Vec<(Output, OutputConfiguration)>) -> bool { - if conf.iter().all(|(_, conf)| matches!(conf, OutputConfiguration::Disabled)) { + fn output_configuration( + &mut self, + test_only: bool, + conf: Vec<(Output, OutputConfiguration)>, + ) -> bool { + if conf + .iter() + .all(|(_, conf)| matches!(conf, OutputConfiguration::Disabled)) + { return false; // we don't allow the user to accidentally disable all their outputs } @@ -50,15 +54,15 @@ impl State { scale, transform, position, - } = conf { + } = conf + { match mode { Some(ModeConfiguration::Mode(mode)) => { current_config.mode = ((mode.size.w, mode.size.h), Some(mode.refresh as u32)); } Some(ModeConfiguration::Custom { size, refresh }) => { - current_config.mode = - ((size.w, size.h), refresh.map(|x| x as u32)); + current_config.mode = ((size.w, size.h), refresh.map(|x| x as u32)); } _ => {} } @@ -116,22 +120,25 @@ impl State { } } - for output in conf.iter().filter(|(_, c)| matches!(c, OutputConfiguration::Enabled { .. })).map(|(o, _)| o) { + for output in conf + .iter() + .filter(|(_, c)| matches!(c, OutputConfiguration::Enabled { .. })) + .map(|(o, _)| o) + { self.common.output_configuration_state.enable_head(output); } - for output in conf.iter().filter(|(_, c)| matches!(c, OutputConfiguration::Disabled)).map(|(o, _)| o) { + for output in conf + .iter() + .filter(|(_, c)| matches!(c, OutputConfiguration::Disabled)) + .map(|(o, _)| o) + { self.common.output_configuration_state.disable_head(output); } - self - .common + self.common .config .write_outputs(self.common.output_configuration_state.outputs()); self.common.event_loop_handle.insert_idle(move |data| { - data - .state - .common - .output_configuration_state - .update(); + data.state.common.output_configuration_state.update(); }); true diff --git a/src/wayland/handlers/seat.rs b/src/wayland/handlers/seat.rs index 076a9aee..512ac28f 100644 --- a/src/wayland/handlers/seat.rs +++ b/src/wayland/handlers/seat.rs @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only -use smithay::{ - wayland::seat::{SeatHandler, SeatState}, - delegate_seat, -}; use crate::state::State; +use smithay::{ + delegate_seat, + wayland::seat::{SeatHandler, SeatState}, +}; impl SeatHandler for State { fn seat_state(&mut self) -> &mut SeatState { diff --git a/src/wayland/handlers/shm.rs b/src/wayland/handlers/shm.rs index f76cac83..9b2f7d9b 100644 --- a/src/wayland/handlers/shm.rs +++ b/src/wayland/handlers/shm.rs @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only -use smithay::{ - wayland::shm::{ShmHandler, ShmState}, - delegate_shm, -}; use crate::state::State; +use smithay::{ + delegate_shm, + wayland::shm::{ShmHandler, ShmState}, +}; impl ShmHandler for State { fn shm_state(&self) -> &ShmState { diff --git a/src/wayland/handlers/toplevel_info.rs b/src/wayland/handlers/toplevel_info.rs index 11d6fa15..30fc99b9 100644 --- a/src/wayland/handlers/toplevel_info.rs +++ b/src/wayland/handlers/toplevel_info.rs @@ -3,9 +3,7 @@ use crate::{ state::State, wayland::protocols::toplevel_info::{ - ToplevelInfoHandler, - ToplevelInfoState, - delegate_toplevel_info, + delegate_toplevel_info, ToplevelInfoHandler, ToplevelInfoState, }, }; diff --git a/src/wayland/handlers/viewporter.rs b/src/wayland/handlers/viewporter.rs index 4cdd6ace..ffa83093 100644 --- a/src/wayland/handlers/viewporter.rs +++ b/src/wayland/handlers/viewporter.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only -use smithay::delegate_viewporter; use crate::state::State; +use smithay::delegate_viewporter; delegate_viewporter!(State); diff --git a/src/wayland/handlers/wl_drm.rs b/src/wayland/handlers/wl_drm.rs index 9a5adc86..2bfdafbf 100644 --- a/src/wayland/handlers/wl_drm.rs +++ b/src/wayland/handlers/wl_drm.rs @@ -1,8 +1,5 @@ // SPDX-License-Identifier: GPL-3.0-only -use crate::{ - state::State, - wayland::protocols::drm::delegate_wl_drm, -}; +use crate::{state::State, wayland::protocols::drm::delegate_wl_drm}; delegate_wl_drm!(State); diff --git a/src/wayland/handlers/workspace.rs b/src/wayland/handlers/workspace.rs index 271684c4..41344e1b 100644 --- a/src/wayland/handlers/workspace.rs +++ b/src/wayland/handlers/workspace.rs @@ -1,18 +1,14 @@ // SPDX-License-Identifier: GPL-3.0-only -use smithay::reexports::wayland_server::DisplayHandle; use crate::{ state::ClientState, - wayland::protocols::workspace::{ - Request, - WorkspaceHandler, - WorkspaceState, - WorkspaceClientHandler, - WorkspaceClientState, - delegate_workspace, - }, utils::prelude::*, + wayland::protocols::workspace::{ + delegate_workspace, Request, WorkspaceClientHandler, WorkspaceClientState, + WorkspaceHandler, WorkspaceState, + }, }; +use smithay::reexports::wayland_server::DisplayHandle; impl WorkspaceClientHandler for ClientState { fn workspace_state(&self) -> &WorkspaceClientState { @@ -28,18 +24,24 @@ impl WorkspaceHandler for State { fn workspace_state_mut(&mut self) -> &mut WorkspaceState { &mut self.common.shell.workspace_state } - + fn commit_requests(&mut self, _dh: &DisplayHandle, requests: Vec) { for request in requests.into_iter() { match request { Request::Activate(handle) => { - if let Some(idx) = self.common.shell.spaces.iter().position(|w| w.handle == handle) { + if let Some(idx) = self + .common + .shell + .spaces + .iter() + .position(|w| w.handle == handle) + { let seat = &self.common.last_active_seat; let output = active_output(seat, &self.common); self.common.shell.activate(seat, &output, idx); } - }, - _ => {}, + } + _ => {} } } } diff --git a/src/wayland/handlers/xdg_shell.rs b/src/wayland/handlers/xdg_shell.rs index 9aa63869..cc70fd8a 100644 --- a/src/wayland/handlers/xdg_shell.rs +++ b/src/wayland/handlers/xdg_shell.rs @@ -1,53 +1,36 @@ // SPDX-License-Identifier: GPL-3.0-only +use crate::utils::prelude::*; use smithay::{ + delegate_xdg_shell, desktop::{ - Kind, - PopupKind, - PopupUngrabStrategy, - PopupKeyboardGrab, - PopupPointerGrab, - PopupGrab, - Window, - WindowSurfaceType, + Kind, PopupGrab, PopupKeyboardGrab, PopupKind, PopupPointerGrab, PopupUngrabStrategy, + Window, WindowSurfaceType, }, reexports::{ - wayland_server::{ - DisplayHandle, - protocol::{ - wl_seat::WlSeat, - wl_surface::WlSurface, - wl_output::WlOutput, - }, - }, wayland_protocols::xdg::shell::server::xdg_toplevel, + wayland_server::{ + protocol::{wl_output::WlOutput, wl_seat::WlSeat, wl_surface::WlSurface}, + DisplayHandle, + }, }, wayland::{ - shell::xdg::{ - XdgShellHandler, - XdgShellState, - ToplevelSurface, - PopupSurface, - PositionerState, - Configure, - }, - seat::{ - Seat, - PointerGrabStartData, - }, output::Output, + seat::{PointerGrabStartData, Seat}, + shell::xdg::{ + Configure, PopupSurface, PositionerState, ToplevelSurface, XdgShellHandler, + XdgShellState, + }, Serial, }, - delegate_xdg_shell, }; use std::cell::Cell; -use crate::utils::prelude::*; pub type PopupGrabData = Cell>; impl XdgShellHandler for State { fn xdg_shell_state(&mut self) -> &mut XdgShellState { - &mut self.common.shell.xdg_shell_state + &mut self.common.shell.xdg_shell_state } fn new_toplevel(&mut self, _dh: &DisplayHandle, surface: ToplevelSurface) { @@ -56,7 +39,10 @@ impl XdgShellHandler for State { let seat = &self.common.last_active_seat; let window = Window::new(Kind::Xdg(surface)); self.common.shell.toplevel_info_state.new_toplevel(&window); - self.common.shell.pending_windows.push((window, seat.clone())); + self.common + .shell + .pending_windows + .push((window, seat.clone())); // We will position the window after the first commit, when we know its size hints } @@ -67,7 +53,7 @@ impl XdgShellHandler for State { _positioner: PositionerState, ) { super::mark_dirty_on_drop(&self.common, surface.wl_surface()); - + self.common .shell .popups @@ -75,37 +61,33 @@ impl XdgShellHandler for State { .unwrap(); } - fn ack_configure( - &mut self, - _dh: &DisplayHandle, - surface: WlSurface, - configure: Configure - ) { + fn ack_configure(&mut self, _dh: &DisplayHandle, surface: WlSurface, configure: Configure) { if let Configure::Toplevel(configure) = configure { // If we would re-position the window inside the grab we would get a weird jittery animation. // We only want to resize once the client has acknoledged & commited the new size, // so we need to carefully track the state through different handlers. - if let Some(window) = self.common - .shell - .space_for_surface(&surface) - .and_then(|workspace| workspace.space.window_for_surface(&surface, WindowSurfaceType::TOPLEVEL)) + if let Some(window) = + self.common + .shell + .space_for_surface(&surface) + .and_then(|workspace| { + workspace + .space + .window_for_surface(&surface, WindowSurfaceType::TOPLEVEL) + }) { - crate::shell::layout::floating::ResizeSurfaceGrab::ack_configure( - window, configure, - ) + crate::shell::layout::floating::ResizeSurfaceGrab::ack_configure(window, configure) } } } - fn grab( - &mut self, - dh: &DisplayHandle, - surface: PopupSurface, - seat: WlSeat, - serial: Serial, - ) { + fn grab(&mut self, dh: &DisplayHandle, surface: PopupSurface, seat: WlSeat, serial: Serial) { let seat = Seat::from_resource(&seat).unwrap(); - let ret = self.common.shell.popups.grab_popup(dh, surface.into(), &seat, serial); + let ret = self + .common + .shell + .popups + .grab_popup(dh, surface.into(), &seat, serial); if let Ok(mut grab) = ret { if let Some(keyboard) = seat.get_keyboard() { @@ -116,16 +98,16 @@ impl XdgShellHandler for State { grab.ungrab(dh, PopupUngrabStrategy::All); return; } - self.common.set_focus(dh, grab.current_grab().as_ref(), &seat, Some(serial)); + self.common + .set_focus(dh, grab.current_grab().as_ref(), &seat, Some(serial)); keyboard.set_grab(PopupKeyboardGrab::new(&grab), serial); } if let Some(pointer) = seat.get_pointer() { if pointer.is_grabbed() && !(pointer.has_grab(serial) - || pointer.has_grab( - grab.previous_serial().unwrap_or_else(|| grab.serial()), - )) + || pointer + .has_grab(grab.previous_serial().unwrap_or_else(|| grab.serial()))) { grab.ungrab(dh, PopupUngrabStrategy::All); return; @@ -147,7 +129,7 @@ impl XdgShellHandler for State { _dh: &DisplayHandle, surface: PopupSurface, positioner: PositionerState, - token: u32 + token: u32, ) { surface.with_pending_state(|state| { // TODO: This is a simplification, a proper compositor would @@ -166,12 +148,10 @@ impl XdgShellHandler for State { _dh: &DisplayHandle, surface: ToplevelSurface, seat: WlSeat, - serial: Serial + serial: Serial, ) { let seat = Seat::from_resource(&seat).unwrap(); - if let Some(start_data) = - check_grab_preconditions(&seat, surface.wl_surface(), serial) - { + if let Some(start_data) = check_grab_preconditions(&seat, surface.wl_surface(), serial) { let workspace = self .common .shell @@ -184,7 +164,7 @@ impl XdgShellHandler for State { .clone(); workspace.move_request(&window, &seat, serial, start_data); - } + } } fn resize_request( @@ -193,12 +173,10 @@ impl XdgShellHandler for State { surface: ToplevelSurface, seat: WlSeat, serial: Serial, - edges: xdg_toplevel::ResizeEdge + edges: xdg_toplevel::ResizeEdge, ) { let seat = Seat::from_resource(&seat).unwrap(); - if let Some(start_data) = - check_grab_preconditions(&seat, surface.wl_surface(), serial) - { + if let Some(start_data) = check_grab_preconditions(&seat, surface.wl_surface(), serial) { let workspace = self .common .shell @@ -220,8 +198,11 @@ impl XdgShellHandler for State { let output = active_output(seat, &self.common); if let Some(workspace) = self.common.shell.space_for_surface_mut(surface) { - let window = - workspace.space.window_for_surface(surface, WindowSurfaceType::TOPLEVEL).unwrap().clone(); + let window = workspace + .space + .window_for_surface(surface, WindowSurfaceType::TOPLEVEL) + .unwrap() + .clone(); workspace.maximize_request(&window, &output) } } @@ -234,7 +215,12 @@ impl XdgShellHandler for State { surface.send_configure(); } - fn fullscreen_request(&mut self, _dh: &DisplayHandle, surface: ToplevelSurface, output: Option) { + fn fullscreen_request( + &mut self, + _dh: &DisplayHandle, + surface: ToplevelSurface, + output: Option, + ) { let output = output .as_ref() .and_then(Output::from_resource) @@ -245,8 +231,11 @@ impl XdgShellHandler for State { let surface = surface.wl_surface(); if let Some(workspace) = self.common.shell.space_for_surface_mut(surface) { - let window = - workspace.space.window_for_surface(surface, WindowSurfaceType::TOPLEVEL).unwrap().clone(); + let window = workspace + .space + .window_for_surface(surface, WindowSurfaceType::TOPLEVEL) + .unwrap() + .clone(); workspace.fullscreen_request(&window, &output) } } @@ -254,8 +243,11 @@ impl XdgShellHandler for State { fn unfullscreen_request(&mut self, _dh: &DisplayHandle, surface: ToplevelSurface) { let surface = surface.wl_surface(); if let Some(workspace) = self.common.shell.space_for_surface_mut(surface) { - let window = - workspace.space.window_for_surface(surface, WindowSurfaceType::TOPLEVEL).unwrap().clone(); + let window = workspace + .space + .window_for_surface(surface, WindowSurfaceType::TOPLEVEL) + .unwrap() + .clone(); workspace.unfullscreen_request(&window) } } @@ -294,5 +286,4 @@ fn check_grab_preconditions( Some(start_data) } - delegate_xdg_shell!(State); diff --git a/src/wayland/mod.rs b/src/wayland/mod.rs index 9ce58adb..74262624 100644 --- a/src/wayland/mod.rs +++ b/src/wayland/mod.rs @@ -1,4 +1,4 @@ // SPDX-License-Identifier: GPL-3.0-only -pub mod protocols; pub mod handlers; +pub mod protocols; diff --git a/src/wayland/protocols/drm.rs b/src/wayland/protocols/drm.rs index be23b4d3..ff065c9d 100644 --- a/src/wayland/protocols/drm.rs +++ b/src/wayland/protocols/drm.rs @@ -26,11 +26,8 @@ use smithay::{ Format, Fourcc, Modifier, }, reexports::wayland_server::{ - Client, DataInit, DisplayHandle, - DelegateGlobalDispatch, DelegateDispatch, - GlobalDispatch, Dispatch, Resource, - New, backend::GlobalId, - protocol::wl_buffer::WlBuffer, + backend::GlobalId, protocol::wl_buffer::WlBuffer, Client, DataInit, DelegateDispatch, + DelegateGlobalDispatch, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, }, wayland::{ buffer::BufferHandler, @@ -38,11 +35,7 @@ use smithay::{ }, }; -use std::{ - convert::TryFrom, - path::PathBuf, - sync::Arc, -}; +use std::{convert::TryFrom, path::PathBuf, sync::Arc}; pub struct WlDrmState; @@ -118,18 +111,14 @@ where ) { match request { wl_drm::Request::Authenticate { .. } => drm.authenticated(), - wl_drm::Request::CreateBuffer { .. } => { - drm.post_error( - wl_drm::Error::InvalidName, - String::from("Flink handles are unsupported, use PRIME"), - ) - }, - wl_drm::Request::CreatePlanarBuffer { .. } => { - drm.post_error( - wl_drm::Error::InvalidName, - String::from("Flink handles are unsupported, use PRIME"), - ) - }, + wl_drm::Request::CreateBuffer { .. } => drm.post_error( + wl_drm::Error::InvalidName, + String::from("Flink handles are unsupported, use PRIME"), + ), + wl_drm::Request::CreatePlanarBuffer { .. } => drm.post_error( + wl_drm::Error::InvalidName, + String::from("Flink handles are unsupported, use PRIME"), + ), wl_drm::Request::CreatePrimeBuffer { id, name, @@ -150,7 +139,7 @@ where return; } format - }, + } Err(_) => { drm.post_error( wl_drm::Error::InvalidFormat, @@ -171,29 +160,30 @@ where let mut dma = Dmabuf::builder((width, height), format, DmabufFlags::empty()); dma.add_plane(name, 0, offset0 as u32, stride0 as u32, Modifier::Invalid); match dma.build() { - Some(dmabuf) => match state.dmabuf_imported(dh, &data.dmabuf_global, dmabuf.clone()) { - Ok(_) => { - // import was successful - data_init.init(id, dmabuf); - slog_scope::trace!("Created a new validated dma wl_buffer via wl_drm."); - }, + Some(dmabuf) => { + match state.dmabuf_imported(dh, &data.dmabuf_global, dmabuf.clone()) { + Ok(_) => { + // import was successful + data_init.init(id, dmabuf); + slog_scope::trace!( + "Created a new validated dma wl_buffer via wl_drm." + ); + } - Err(ImportError::InvalidFormat) => { - drm.post_error( - wl_drm::Error::InvalidFormat, - "format and plane combination are not valid", - ); - } + Err(ImportError::InvalidFormat) => { + drm.post_error( + wl_drm::Error::InvalidFormat, + "format and plane combination are not valid", + ); + } - Err(ImportError::Failed) => { - // Buffer import failed. The protocol documentation heavily implies killing the - // client is the right thing to do here. - drm.post_error( - wl_drm::Error::InvalidName, - "buffer import failed", - ); + Err(ImportError::Failed) => { + // Buffer import failed. The protocol documentation heavily implies killing the + // client is the right thing to do here. + drm.post_error(wl_drm::Error::InvalidName, "buffer import failed"); + } } - }, + } None => { // Buffer import failed. The protocol documentation heavily implies killing the // client is the right thing to do here. @@ -223,7 +213,9 @@ impl WlDrmState { + DmabufHandler + 'static, { - self.create_global_with_filter::(display, device_path, formats, dmabuf_global, |_| true) + self.create_global_with_filter::(display, device_path, formats, dmabuf_global, |_| { + true + }) } pub fn create_global_with_filter( @@ -242,7 +234,13 @@ impl WlDrmState { + 'static, F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static, { - let formats = Arc::new(formats.into_iter().filter(|f| f.modifier == Modifier::Invalid).map(|f| f.code).collect()); + let formats = Arc::new( + formats + .into_iter() + .filter(|f| f.modifier == Modifier::Invalid) + .map(|f| f.code) + .collect(), + ); let data = DrmGlobalData { filter: Box::new(client_filter), formats, @@ -266,4 +264,3 @@ macro_rules! delegate_wl_drm { }; } pub(crate) use delegate_wl_drm; - \ No newline at end of file diff --git a/src/wayland/protocols/output_configuration.rs b/src/wayland/protocols/output_configuration.rs index 0ec7594f..05c3379c 100644 --- a/src/wayland/protocols/output_configuration.rs +++ b/src/wayland/protocols/output_configuration.rs @@ -1,12 +1,5 @@ // SPDX-License-Identifier: GPL-3.0-only -use std::{ - convert::{TryFrom, TryInto}, - sync::{ - Arc, Mutex, - atomic::{AtomicBool, Ordering}, - }, -}; use smithay::{ reexports::{ wayland_protocols_wlr::output_management::v1::server::{ @@ -17,16 +10,21 @@ use smithay::{ zwlr_output_mode_v1::{self, ZwlrOutputModeV1}, }, wayland_server::{ - Client, DisplayHandle, - GlobalDispatch, Dispatch, - DelegateGlobalDispatch, DelegateDispatch, - DataInit, New, Resource, backend::{ClientId, GlobalId, ObjectId}, protocol::wl_output::WlOutput, + Client, DataInit, DelegateDispatch, DelegateGlobalDispatch, Dispatch, DisplayHandle, + GlobalDispatch, New, Resource, }, }, - wayland::output::{Output, Mode, OutputData}, utils::{Logical, Physical, Point, Size, Transform}, + wayland::output::{Mode, Output, OutputData}, +}; +use std::{ + convert::{TryFrom, TryInto}, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, Mutex, + }, }; pub struct OutputConfigurationState { @@ -105,7 +103,9 @@ pub enum OutputConfiguration { impl<'a> TryFrom<&'a mut PendingOutputConfigurationInner> for OutputConfiguration { type Error = zwlr_output_configuration_head_v1::Error; - fn try_from(pending: &'a mut PendingOutputConfigurationInner) -> Result { + fn try_from( + pending: &'a mut PendingOutputConfigurationInner, + ) -> Result { let mode = match pending.mode.clone() { Some(ModeConfiguration::Mode(wlr_mode)) => Some(ModeConfiguration::Mode( wlr_mode @@ -133,7 +133,8 @@ struct OutputStateInner { } type OutputState = Mutex; -impl DelegateGlobalDispatch for OutputConfigurationState +impl DelegateGlobalDispatch + for OutputConfigurationState where D: GlobalDispatch + Dispatch @@ -142,7 +143,7 @@ where + Dispatch + Dispatch + OutputConfigurationHandler - + 'static + + 'static, { fn bind( state: &mut D, @@ -161,7 +162,7 @@ where heads: Vec::new(), active, }; - + let mngr_state = state.output_configuration_state(); for output in &mngr_state.outputs { send_head_to_client::(dh, &mut instance, output); @@ -175,7 +176,8 @@ where } } -impl DelegateDispatch for OutputConfigurationState +impl DelegateDispatch + for OutputConfigurationState where D: GlobalDispatch + Dispatch @@ -184,7 +186,7 @@ where + Dispatch + Dispatch + OutputConfigurationHandler - + 'static + + 'static, { fn request( state: &mut D, @@ -196,25 +198,25 @@ where data_init: &mut DataInit<'_, D>, ) { match request { - zwlr_output_manager_v1::Request::CreateConfiguration { - id, - serial, - } => { - let conf = data_init.init(id, PendingConfiguration::new(PendingConfigurationInner { - serial, - used: false, - heads: Vec::new(), - })); + zwlr_output_manager_v1::Request::CreateConfiguration { id, serial } => { + let conf = data_init.init( + id, + PendingConfiguration::new(PendingConfigurationInner { + serial, + used: false, + heads: Vec::new(), + }), + ); let state = state.output_configuration_state(); if serial != state.serial_counter { conf.cancelled(); } - }, + } zwlr_output_manager_v1::Request::Stop => { data.active.store(false, Ordering::SeqCst); - }, - _ => {}, + } + _ => {} } } } @@ -228,7 +230,7 @@ where + Dispatch + Dispatch + OutputConfigurationHandler - + 'static + + 'static, { fn request( _state: &mut D, @@ -244,12 +246,7 @@ where } } - fn destroyed( - state: &mut D, - _client: ClientId, - resource: ObjectId, - _data: &Output, - ) { + fn destroyed(state: &mut D, _client: ClientId, resource: ObjectId, _data: &Output) { for instance in &mut state.output_configuration_state().instances { instance.heads.retain(|h| h.head.id() != resource); } @@ -265,7 +262,7 @@ where + Dispatch + Dispatch + OutputConfigurationHandler - + 'static + + 'static, { fn request( _state: &mut D, @@ -282,7 +279,8 @@ where } } -impl DelegateDispatch for OutputConfigurationState +impl DelegateDispatch + for OutputConfigurationState where D: GlobalDispatch + Dispatch @@ -291,7 +289,7 @@ where + Dispatch + Dispatch + OutputConfigurationHandler - + 'static + + 'static, { fn request( state: &mut D, @@ -315,7 +313,7 @@ where let conf_head = data_init.init(id, PendingOutputConfiguration::default()); pending.heads.push((head, Some(conf_head))); - }, + } zwlr_output_configuration_v1::Request::DisableHead { head } => { let mut pending = data.lock().unwrap(); if pending.heads.iter().any(|(h, _)| *h == head) { @@ -326,11 +324,11 @@ where return; } pending.heads.push((head, None)); - }, + } x @ zwlr_output_configuration_v1::Request::Apply | x @ zwlr_output_configuration_v1::Request::Test => { let mut pending = data.lock().unwrap(); - + if pending.used { return obj.post_error( zwlr_output_configuration_v1::Error::AlreadyUsed, @@ -350,16 +348,17 @@ where .iter_mut() .map(|(head, conf)| { let output = match { - inner.instances + inner + .instances .iter() - .find_map(|instance| instance.heads.iter().find(|h| h.head == *head)) + .find_map(|instance| { + instance.heads.iter().find(|h| h.head == *head) + }) .map(|i| i.output.clone()) } { Some(o) => o, None => { - return Err( - zwlr_output_configuration_head_v1::Error::InvalidMode, - ); + return Err(zwlr_output_configuration_head_v1::Error::InvalidMode); } }; @@ -374,8 +373,10 @@ where None => Ok((output, OutputConfiguration::Disabled)), } }) - .collect::, zwlr_output_configuration_head_v1::Error>>() - { + .collect::, + zwlr_output_configuration_head_v1::Error, + >>() { Ok(conf) => conf, Err(code) => { return obj.post_error(code, "Incomplete configuration".to_string()); @@ -393,14 +394,15 @@ where } else { obj.failed(); } - }, - zwlr_output_configuration_v1::Request::Destroy => {}, - _ => {}, + } + zwlr_output_configuration_v1::Request::Destroy => {} + _ => {} } } } -impl DelegateDispatch for OutputConfigurationState +impl DelegateDispatch + for OutputConfigurationState where D: GlobalDispatch + Dispatch @@ -409,7 +411,7 @@ where + Dispatch + Dispatch + OutputConfigurationHandler - + 'static + + 'static, { fn request( _state: &mut D, @@ -431,8 +433,12 @@ where return; } pending.mode = Some(ModeConfiguration::Mode(mode)); - }, - zwlr_output_configuration_head_v1::Request::SetCustomMode { width, height, refresh } => { + } + zwlr_output_configuration_head_v1::Request::SetCustomMode { + width, + height, + refresh, + } => { let mut pending = data.lock().unwrap(); if pending.mode.is_some() { obj.post_error( @@ -445,7 +451,7 @@ where size: Size::from((width, height)), refresh: if refresh == 0 { None } else { Some(refresh) }, }); - }, + } zwlr_output_configuration_head_v1::Request::SetPosition { x, y } => { let mut pending = data.lock().unwrap(); if pending.position.is_some() { @@ -456,7 +462,7 @@ where return; } pending.position = Some(Point::from((x, y))); - }, + } zwlr_output_configuration_head_v1::Request::SetScale { scale } => { let mut pending = data.lock().unwrap(); if pending.scale.is_some() { @@ -467,7 +473,7 @@ where return; } pending.scale = Some(scale); - }, + } zwlr_output_configuration_head_v1::Request::SetTransform { transform } => { let mut pending = data.lock().unwrap(); if pending.transform.is_some() { @@ -485,36 +491,36 @@ where format!("Invalid transform: {:?}", err), ); return; - }, + } }); - }, - _ => {}, + } + _ => {} } } } impl OutputConfigurationState where - D: GlobalDispatch - + GlobalDispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + OutputConfigurationHandler - + 'static, + D: GlobalDispatch + + GlobalDispatch + + Dispatch + + Dispatch + + Dispatch + + Dispatch + + Dispatch + + OutputConfigurationHandler + + 'static, { - pub fn new( - dh: &DisplayHandle, - client_filter: F, - ) -> OutputConfigurationState + pub fn new(dh: &DisplayHandle, client_filter: F) -> OutputConfigurationState where F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static, { - let global = dh.create_global::(2, OutputMngrGlobalData { - filter: Box::new(client_filter), - }); + let global = dh.create_global::( + 2, + OutputMngrGlobalData { + filter: Box::new(client_filter), + }, + ); OutputConfigurationState { outputs: Vec::new(), @@ -530,19 +536,23 @@ where pub fn global_id(&self) -> GlobalId { self.global.clone() } - + pub fn add_heads<'a>(&mut self, outputs: impl Iterator) { - let new_outputs = outputs.filter(|o| !self.outputs.contains(o)).collect::>(); + let new_outputs = outputs + .filter(|o| !self.outputs.contains(o)) + .collect::>(); for output in new_outputs { - output.user_data().insert_if_missing(|| OutputState::new(OutputStateInner { - enabled: true, - global: None, - })); + output.user_data().insert_if_missing(|| { + OutputState::new(OutputStateInner { + enabled: true, + global: None, + }) + }); self.outputs.push(output.clone()); } } - + pub fn remove_heads<'a>(&mut self, outputs: impl Iterator) { for output in outputs { if self.outputs.contains(output) { @@ -577,17 +587,19 @@ where pub fn update(&mut self) { self.instances.retain(|x| x.active.load(Ordering::SeqCst)); self.serial_counter += 1; - + for output in std::mem::take(&mut self.removed_outputs).into_iter() { for instance in &mut self.instances { - instance.heads.retain_mut(|head| if &head.output == &output { - for mode in &head.modes { - mode.finished(); + instance.heads.retain_mut(|head| { + if &head.output == &output { + for mode in &head.modes { + mode.finished(); + } + head.head.finished(); + false + } else { + true } - head.head.finished(); - false - } else { - true }); } } @@ -624,13 +636,17 @@ where + Dispatch + Dispatch + OutputConfigurationHandler - + 'static + + 'static, { let instance = match mngr.heads.iter_mut().find(|i| i.output == *output) { Some(i) => i, None => { if let Ok(client) = dh.get_client(mngr.obj.id()) { - if let Ok(head) = client.create_resource::(dh, mngr.obj.version(), output.clone()) { + if let Ok(head) = client.create_resource::( + dh, + mngr.obj.version(), + output.clone(), + ) { mngr.obj.head(&head); let data = OutputHeadInstance { head, @@ -652,7 +668,9 @@ where instance.head.description(output.description()); let physical = output.physical_properties(); if !(physical.size.w == 0 || physical.size.h == 0) { - instance.head.physical_size(physical.size.w, physical.size.h); + instance + .head + .physical_size(physical.size.w, physical.size.h); } let inner = output @@ -664,26 +682,37 @@ where let output_modes = output.modes(); // remove old modes - instance.modes.retain_mut(|m| if !output_modes.contains(m.data::().unwrap()) { - m.finished(); - false - } else { - true + instance.modes.retain_mut(|m| { + if !output_modes.contains(m.data::().unwrap()) { + m.finished(); + false + } else { + true + } }); // update other modes for output_mode in output_modes.into_iter() { - if let Some(mode) = if let Some(wlr_mode) = instance.modes + if let Some(mode) = if let Some(wlr_mode) = instance + .modes .iter() .find(|mode| *mode.data::().unwrap() == output_mode) { Some(wlr_mode) } else if let Ok(client) = dh.get_client(instance.head.id()) { // create the mode if it does not exist yet - if let Ok(mode) = client.create_resource::(dh, instance.head.version(), output_mode) { + if let Ok(mode) = client.create_resource::( + dh, + instance.head.version(), + output_mode, + ) { instance.head.mode(&mode); mode.size(output_mode.size.w, output_mode.size.h); mode.refresh(output_mode.refresh); - if output.preferred_mode().map(|p| p == output_mode).unwrap_or(false) { + if output + .preferred_mode() + .map(|p| p == output_mode) + .unwrap_or(false) + { mode.preferred(); } instance.modes.push(mode); @@ -694,7 +723,12 @@ where } else { None } { - if inner.enabled && output.current_mode().map(|c| c == output_mode).unwrap_or(false) { + if inner.enabled + && output + .current_mode() + .map(|c| c == output_mode) + .unwrap_or(false) + { instance.head.current_mode(&*mode); } } diff --git a/src/wayland/protocols/toplevel_info.rs b/src/wayland/protocols/toplevel_info.rs index df657333..eb7a8de1 100644 --- a/src/wayland/protocols/toplevel_info.rs +++ b/src/wayland/protocols/toplevel_info.rs @@ -5,30 +5,24 @@ use std::sync::Mutex; use smithay::{ desktop::Window, reexports::{ - wayland_server::{ - Client, DataInit, - DisplayHandle, Resource, New, - GlobalDispatch, Dispatch, - DelegateGlobalDispatch, DelegateDispatch, - backend::{ClientId, GlobalId, ObjectId}, - }, wayland_protocols::xdg::shell::server::xdg_toplevel, - }, - wayland::{ - compositor::with_states, - output::Output, - shell::xdg::XdgToplevelSurfaceRoleAttributes, + wayland_server::{ + backend::{ClientId, GlobalId, ObjectId}, + Client, DataInit, DelegateDispatch, DelegateGlobalDispatch, Dispatch, DisplayHandle, + GlobalDispatch, New, Resource, + }, }, utils::IsAlive, + wayland::{ + compositor::with_states, output::Output, shell::xdg::XdgToplevelSurfaceRoleAttributes, + }, }; -use super::workspace::{WorkspaceHandler, WorkspaceHandle, WorkspaceState}; +use super::workspace::{WorkspaceHandle, WorkspaceHandler, WorkspaceState}; -use cosmic_protocols::{ - toplevel_info::v1::server::{ - zcosmic_toplevel_info_v1::{self, ZcosmicToplevelInfoV1}, - zcosmic_toplevel_handle_v1::{self, ZcosmicToplevelHandleV1, State as States}, - }, +use cosmic_protocols::toplevel_info::v1::server::{ + zcosmic_toplevel_handle_v1::{self, State as States, ZcosmicToplevelHandleV1}, + zcosmic_toplevel_info_v1::{self, ZcosmicToplevelInfoV1}, }; pub struct ToplevelInfoState { @@ -67,13 +61,14 @@ pub struct ToplevelHandleStateInner { } pub type ToplevelHandleState = Mutex; -impl DelegateGlobalDispatch for ToplevelInfoState +impl DelegateGlobalDispatch + for ToplevelInfoState where D: GlobalDispatch + Dispatch + Dispatch + ToplevelInfoHandler - + 'static + + 'static, { fn bind( state: &mut D, @@ -100,7 +95,7 @@ where + Dispatch + Dispatch + ToplevelInfoHandler - + 'static + + 'static, { fn request( state: &mut D, @@ -113,19 +108,20 @@ where ) { match request { zcosmic_toplevel_info_v1::Request::Stop => { - state.toplevel_info_state_mut().instances.retain(|i| i != obj); - }, - _ => {}, + state + .toplevel_info_state_mut() + .instances + .retain(|i| i != obj); + } + _ => {} } } - fn destroyed( - state: &mut D, - _client: ClientId, - resource: ObjectId, - _data: &(), - ) { - state.toplevel_info_state_mut().instances.retain(|i| i.id() != resource); + fn destroyed(state: &mut D, _client: ClientId, resource: ObjectId, _data: &()) { + state + .toplevel_info_state_mut() + .instances + .retain(|i| i.id() != resource); } } @@ -135,7 +131,7 @@ where + Dispatch + Dispatch + ToplevelInfoHandler - + 'static + + 'static, { fn request( _state: &mut D, @@ -147,20 +143,24 @@ where _data_init: &mut DataInit<'_, D>, ) { match request { - zcosmic_toplevel_handle_v1::Request::Destroy => {}, - _ => {}, + zcosmic_toplevel_handle_v1::Request::Destroy => {} + _ => {} } } fn destroyed( - state: &mut D, - _client: ClientId, - resource: ObjectId, + state: &mut D, + _client: ClientId, + resource: ObjectId, _data: &ToplevelHandleState, ) { for toplevel in &state.toplevel_info_state_mut().toplevels { if let Some(state) = toplevel.user_data().get::() { - state.lock().unwrap().instances.retain(|i| i.id() != resource); + state + .lock() + .unwrap() + .instances + .retain(|i| i.id() != resource); } } } @@ -174,16 +174,16 @@ where + ToplevelInfoHandler + 'static, { - pub fn new( - dh: &DisplayHandle, - client_filter: F, - ) -> ToplevelInfoState + pub fn new(dh: &DisplayHandle, client_filter: F) -> ToplevelInfoState where - F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static + F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static, { - let global = dh.create_global::(1, ToplevelInfoGlobalData { - filter: Box::new(client_filter), - }); + let global = dh.create_global::( + 1, + ToplevelInfoGlobalData { + filter: Box::new(client_filter), + }, + ); ToplevelInfoState { dh: dh.clone(), toplevels: Vec::new(), @@ -194,7 +194,9 @@ where } pub fn new_toplevel(&mut self, toplevel: &Window) { - toplevel.user_data().insert_if_missing(ToplevelState::default); + toplevel + .user_data() + .insert_if_missing(ToplevelState::default); for instance in &self.instances { send_toplevel_to_client::(&self.dh, None, instance, toplevel); } @@ -233,10 +235,19 @@ where } true } else { - let state = window.user_data().get::().unwrap().lock().unwrap(); + let state = window + .user_data() + .get::() + .unwrap() + .lock() + .unwrap(); for handle in &state.instances { // don't send events to stopped instances - if self.instances.iter().any(|i| i.id().same_client_as(&handle.id())) { + if self + .instances + .iter() + .any(|i| i.id().same_client_as(&handle.id())) + { handle.closed(); } } @@ -250,20 +261,39 @@ where } } -fn send_toplevel_to_client(dh: &DisplayHandle, workspace_state: Option<&WorkspaceState>, info: &ZcosmicToplevelInfoV1, window: &Window) -where +fn send_toplevel_to_client( + dh: &DisplayHandle, + workspace_state: Option<&WorkspaceState>, + info: &ZcosmicToplevelInfoV1, + window: &Window, +) where D: GlobalDispatch + Dispatch + Dispatch + ToplevelInfoHandler + 'static, { - let mut state = window.user_data().get::().unwrap().lock().unwrap(); - let instance = match state.instances.iter().find(|i| i.id().same_client_as(&info.id())) { + let mut state = window + .user_data() + .get::() + .unwrap() + .lock() + .unwrap(); + let instance = match state + .instances + .iter() + .find(|i| i.id().same_client_as(&info.id())) + { Some(i) => i, None => { if let Ok(client) = dh.get_client(info.id()) { - if let Ok(toplevel_handle) = client.create_resource::(dh, info.version(), ToplevelHandleState::default()) { + if let Ok(toplevel_handle) = client + .create_resource::( + dh, + info.version(), + ToplevelHandleState::default(), + ) + { state.instances.push(toplevel_handle); state.instances.last().unwrap() } else { @@ -275,7 +305,11 @@ where } }; - let mut handle_state = instance.data::().unwrap().lock().unwrap(); + let mut handle_state = instance + .data::() + .unwrap() + .lock() + .unwrap(); let mut changed = false; with_states(window.toplevel().wl_surface(), |states| { let attributes = states @@ -284,7 +318,7 @@ where .unwrap() .lock() .unwrap(); - + if handle_state.title != attributes.title.as_deref().unwrap_or(&"") { handle_state.title = attributes.title.clone().unwrap_or_else(String::new); instance.title(handle_state.title.clone()); @@ -296,21 +330,50 @@ where changed = true; } - if (handle_state.states.contains(&States::Maximized) != attributes.current.states.contains(xdg_toplevel::State::Maximized)) - || (handle_state.states.contains(&States::Fullscreen) != attributes.current.states.contains(xdg_toplevel::State::Fullscreen)) - || (handle_state.states.contains(&States::Activated) != attributes.current.states.contains(xdg_toplevel::State::Activated)) - || (handle_state.states.contains(&States::Minimized) != state.minimized) { + if (handle_state.states.contains(&States::Maximized) + != attributes + .current + .states + .contains(xdg_toplevel::State::Maximized)) + || (handle_state.states.contains(&States::Fullscreen) + != attributes + .current + .states + .contains(xdg_toplevel::State::Fullscreen)) + || (handle_state.states.contains(&States::Activated) + != attributes + .current + .states + .contains(xdg_toplevel::State::Activated)) + || (handle_state.states.contains(&States::Minimized) != state.minimized) + { let mut states = Vec::new(); - if attributes.current.states.contains(xdg_toplevel::State::Maximized) { + if attributes + .current + .states + .contains(xdg_toplevel::State::Maximized) + { states.push(States::Maximized); } - if attributes.current.states.contains(xdg_toplevel::State::Fullscreen) { + if attributes + .current + .states + .contains(xdg_toplevel::State::Fullscreen) + { states.push(States::Fullscreen); } - if attributes.current.states.contains(xdg_toplevel::State::Activated) { + if attributes + .current + .states + .contains(xdg_toplevel::State::Activated) + { states.push(States::Activated); } - if attributes.current.states.contains(xdg_toplevel::State::Maximized) { + if attributes + .current + .states + .contains(xdg_toplevel::State::Maximized) + { states.push(States::Maximized); } handle_state.states = states.clone(); @@ -329,13 +392,21 @@ where }); if let Ok(client) = dh.get_client(instance.id()) { - for new_output in state.outputs.iter().filter(|o| !handle_state.outputs.contains(o)) { + for new_output in state + .outputs + .iter() + .filter(|o| !handle_state.outputs.contains(o)) + { new_output.with_client_outputs(dh, &client, |_dh, wl_output| { instance.output_enter(wl_output); }); changed = true; } - for old_output in handle_state.outputs.iter().filter(|o| !state.outputs.contains(o)) { + for old_output in handle_state + .outputs + .iter() + .filter(|o| !state.outputs.contains(o)) + { old_output.with_client_outputs(dh, &client, |_dh, wl_output| { instance.output_leave(wl_output); }); @@ -345,14 +416,26 @@ where } if let Some(workspace_state) = workspace_state { - for new_workspace in state.workspaces.iter().filter(|w| !handle_state.workspaces.contains(w)) { - if let Some(handle) = workspace_state.raw_workspace_handle(&new_workspace, &instance.id()) { + for new_workspace in state + .workspaces + .iter() + .filter(|w| !handle_state.workspaces.contains(w)) + { + if let Some(handle) = + workspace_state.raw_workspace_handle(&new_workspace, &instance.id()) + { instance.workspace_enter(&handle); changed = true; } } - for old_workspace in handle_state.workspaces.iter().filter(|w| !state.workspaces.contains(w)) { - if let Some(handle) = workspace_state.raw_workspace_handle(&old_workspace, &instance.id()) { + for old_workspace in handle_state + .workspaces + .iter() + .filter(|w| !state.workspaces.contains(w)) + { + if let Some(handle) = + workspace_state.raw_workspace_handle(&old_workspace, &instance.id()) + { instance.workspace_leave(&handle); changed = true; } diff --git a/src/wayland/protocols/workspace.rs b/src/wayland/protocols/workspace.rs index d281ed57..647fb306 100644 --- a/src/wayland/protocols/workspace.rs +++ b/src/wayland/protocols/workspace.rs @@ -4,19 +4,17 @@ use std::sync::Mutex; use smithay::{ reexports::wayland_server::{ - Client, DataInit, - DisplayHandle, Resource, New, - GlobalDispatch, Dispatch, - DelegateGlobalDispatch, DelegateDispatch, - backend::{ClientId, ClientData, GlobalId, ObjectId}, + backend::{ClientData, ClientId, GlobalId, ObjectId}, + Client, DataInit, DelegateDispatch, DelegateGlobalDispatch, Dispatch, DisplayHandle, + GlobalDispatch, New, Resource, }, wayland::output::Output, }; use cosmic_protocols::workspace::v1::server::{ - zcosmic_workspace_manager_v1::{self, ZcosmicWorkspaceManagerV1}, zcosmic_workspace_group_handle_v1::{self, ZcosmicWorkspaceGroupHandleV1}, zcosmic_workspace_handle_v1::{self, ZcosmicWorkspaceHandleV1}, + zcosmic_workspace_manager_v1::{self, ZcosmicWorkspaceManagerV1}, }; pub use cosmic_protocols::workspace::v1::server::{ @@ -32,9 +30,7 @@ where + Dispatch + WorkspaceHandler + 'static, - ::Client: ClientData - + WorkspaceClientHandler - + 'static, + ::Client: ClientData + WorkspaceClientHandler + 'static, { dh: DisplayHandle, global: GlobalId, @@ -50,10 +46,7 @@ where + Dispatch + WorkspaceHandler + 'static, - ::Client: ClientData - + WorkspaceClientHandler - + 'static -; + ::Client: ClientData + WorkspaceClientHandler + 'static; crate::utils::id_gen!(next_group_id, GROUP_ID, GROUP_IDS); crate::utils::id_gen!(next_workspace_id, WORKSPACE_ID, WORKSPACE_IDS); @@ -63,7 +56,7 @@ pub struct WorkspaceGroup { id: usize, instances: Vec, workspaces: Vec, - + outputs: Vec, capabilities: Vec, } @@ -114,9 +107,7 @@ where + Sized + 'static, { - type Client: ClientData - + WorkspaceClientHandler - + 'static; + type Client: ClientData + WorkspaceClientHandler + 'static; fn workspace_state(&self) -> &WorkspaceState; fn workspace_state_mut(&mut self) -> &mut WorkspaceState; @@ -144,12 +135,12 @@ pub struct WorkspaceClientStateInner { } pub type WorkspaceClientState = Mutex; - pub trait WorkspaceClientHandler { fn workspace_state(&self) -> &WorkspaceClientState; } -impl DelegateGlobalDispatch for WorkspaceState +impl DelegateGlobalDispatch + for WorkspaceState where D: GlobalDispatch + Dispatch @@ -157,9 +148,7 @@ where + Dispatch + WorkspaceHandler + 'static, - ::Client: ClientData - + WorkspaceClientHandler - + 'static, + ::Client: ClientData + WorkspaceClientHandler + 'static, { fn bind( state: &mut D, @@ -191,10 +180,8 @@ where + Dispatch + WorkspaceHandler + 'static, - ::Client: ClientData - + WorkspaceClientHandler - + 'static, -{ + ::Client: ClientData + WorkspaceClientHandler + 'static, +{ fn request( state: &mut D, client: &Client, @@ -207,26 +194,29 @@ where match request { zcosmic_workspace_manager_v1::Request::Commit => { if state.workspace_state().instances.contains(obj) { - let mut client_state = client.get_data::<::Client>().unwrap().workspace_state().lock().unwrap(); + let mut client_state = client + .get_data::<::Client>() + .unwrap() + .workspace_state() + .lock() + .unwrap(); state.commit_requests(dh, std::mem::take(&mut client_state.requests)); } - }, + } zcosmic_workspace_manager_v1::Request::Stop => { state.workspace_state_mut().instances.retain(|i| i != obj); // without an instance, the whole send_group_to_client machinery doesn't work // so there is no way for the whole clients hierachy to get any new events - }, - _ => {}, + } + _ => {} } } - fn destroyed( - state: &mut D, - _client: ClientId, - resource: ObjectId, - _data: &(), - ) { - state.workspace_state_mut().instances.retain(|i| i.id() != resource); + fn destroyed(state: &mut D, _client: ClientId, resource: ObjectId, _data: &()) { + state + .workspace_state_mut() + .instances + .retain(|i| i.id() != resource); } } @@ -237,10 +227,8 @@ where + Dispatch + Dispatch + WorkspaceHandler - + 'static, - ::Client: ClientData - + WorkspaceClientHandler + 'static, + ::Client: ClientData + WorkspaceClientHandler + 'static, { fn request( state: &mut D, @@ -253,29 +241,35 @@ where ) { match request { zcosmic_workspace_group_handle_v1::Request::CreateWorkspace { workspace } => { - if let Some(id) = state.workspace_state().groups.iter().find(|g| g.instances.contains(obj)).map(|g| g.id) { - let mut state = client.get_data::<::Client>().unwrap().workspace_state().lock().unwrap(); + if let Some(id) = state + .workspace_state() + .groups + .iter() + .find(|g| g.instances.contains(obj)) + .map(|g| g.id) + { + let mut state = client + .get_data::<::Client>() + .unwrap() + .workspace_state() + .lock() + .unwrap(); state.requests.push(Request::Create { in_group: WorkspaceGroupHandle { id }, name: workspace, }); } - }, + } zcosmic_workspace_group_handle_v1::Request::Destroy => { for group in &mut state.workspace_state_mut().groups { group.instances.retain(|i| i != obj) } - }, - _ => {}, + } + _ => {} } } - fn destroyed( - state: &mut D, - _client: ClientId, - resource: ObjectId, - _data: &WorkspaceGroupData, - ) { + fn destroyed(state: &mut D, _client: ClientId, resource: ObjectId, _data: &WorkspaceGroupData) { for group in &mut state.workspace_state_mut().groups { group.instances.retain(|i| i.id() != resource) } @@ -290,9 +284,7 @@ where + Dispatch + WorkspaceHandler + 'static, - ::Client: ClientData - + WorkspaceClientHandler - + 'static, + ::Client: ClientData + WorkspaceClientHandler + 'static, { fn request( state: &mut D, @@ -305,30 +297,58 @@ where ) { match request { zcosmic_workspace_handle_v1::Request::Activate => { - if let Some(id) = state.workspace_state().groups.iter() + if let Some(id) = state + .workspace_state() + .groups + .iter() .find_map(|g| g.workspaces.iter().find(|w| w.instances.contains(obj))) .map(|w| w.id) { - let mut state = client.get_data::<::Client>().unwrap().workspace_state().lock().unwrap(); - state.requests.push(Request::Activate(WorkspaceHandle { id })); + let mut state = client + .get_data::<::Client>() + .unwrap() + .workspace_state() + .lock() + .unwrap(); + state + .requests + .push(Request::Activate(WorkspaceHandle { id })); } } zcosmic_workspace_handle_v1::Request::Deactivate => { - if let Some(id) = state.workspace_state().groups.iter() + if let Some(id) = state + .workspace_state() + .groups + .iter() .find_map(|g| g.workspaces.iter().find(|w| w.instances.contains(obj))) .map(|w| w.id) { - let mut state = client.get_data::<::Client>().unwrap().workspace_state().lock().unwrap(); - state.requests.push(Request::Deactivate(WorkspaceHandle { id })); + let mut state = client + .get_data::<::Client>() + .unwrap() + .workspace_state() + .lock() + .unwrap(); + state + .requests + .push(Request::Deactivate(WorkspaceHandle { id })); } } zcosmic_workspace_handle_v1::Request::Remove => { - if let Some(id) = state.workspace_state().groups.iter() + if let Some(id) = state + .workspace_state() + .groups + .iter() .find_map(|g| g.workspaces.iter().find(|w| w.instances.contains(obj))) .map(|w| w.id) { - let mut state = client.get_data::<::Client>().unwrap().workspace_state().lock().unwrap(); - state.requests.push(Request::Remove(WorkspaceHandle { id })); + let mut state = client + .get_data::<::Client>() + .unwrap() + .workspace_state() + .lock() + .unwrap(); + state.requests.push(Request::Remove(WorkspaceHandle { id })); } } zcosmic_workspace_handle_v1::Request::Destroy => { @@ -338,16 +358,11 @@ where } } } - _ => {}, + _ => {} } } - fn destroyed( - state: &mut D, - _client: ClientId, - resource: ObjectId, - _data: &WorkspaceData, - ) { + fn destroyed(state: &mut D, _client: ClientId, resource: ObjectId, _data: &WorkspaceData) { for group in &mut state.workspace_state_mut().groups { for workspace in &mut group.workspaces { workspace.instances.retain(|i| i.id() != resource) @@ -356,7 +371,6 @@ where } } - impl WorkspaceState where D: GlobalDispatch @@ -365,20 +379,18 @@ where + Dispatch + WorkspaceHandler + 'static, - ::Client: ClientData - + WorkspaceClientHandler - + 'static, + ::Client: ClientData + WorkspaceClientHandler + 'static, { - pub fn new( - dh: &DisplayHandle, - client_filter: F, - ) -> WorkspaceState - where + pub fn new(dh: &DisplayHandle, client_filter: F) -> WorkspaceState + where F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static, { - let global = dh.create_global::(1, WorkspaceGlobalData { - filter: Box::new(client_filter), - }); + let global = dh.create_global::( + 1, + WorkspaceGlobalData { + filter: Box::new(client_filter), + }, + ); WorkspaceState { dh: dh.clone(), @@ -388,8 +400,12 @@ where _marker: std::marker::PhantomData, } } - - pub fn workspace_belongs_to_group(&self, group: &WorkspaceGroupHandle, workspace: &WorkspaceHandle) -> bool { + + pub fn workspace_belongs_to_group( + &self, + group: &WorkspaceGroupHandle, + workspace: &WorkspaceHandle, + ) -> bool { if let Some(group) = self.groups.iter().find(|g| g.id == group.id) { group.workspaces.iter().any(|w| w.id == workspace.id) } else { @@ -397,38 +413,86 @@ where } } - pub fn group_capabilities(&self, group: &WorkspaceGroupHandle) -> Option> { - self.groups.iter().find(|g| g.id == group.id).map(|g| g.capabilities.iter()) + pub fn group_capabilities( + &self, + group: &WorkspaceGroupHandle, + ) -> Option> { + self.groups + .iter() + .find(|g| g.id == group.id) + .map(|g| g.capabilities.iter()) } - pub fn group_outputs(&self, group: &WorkspaceGroupHandle) -> Option> { - self.groups.iter().find(|g| g.id == group.id).map(|g| g.outputs.iter()) + pub fn group_outputs( + &self, + group: &WorkspaceGroupHandle, + ) -> Option> { + self.groups + .iter() + .find(|g| g.id == group.id) + .map(|g| g.outputs.iter()) } - - pub fn workspace_capabilities(&self, workspace: &WorkspaceHandle) -> Option> { - self.groups.iter().find_map(|g| g.workspaces.iter().find(|w| w.id == workspace.id).map(|w| w.capabilities.iter())) + + pub fn workspace_capabilities( + &self, + workspace: &WorkspaceHandle, + ) -> Option> { + self.groups.iter().find_map(|g| { + g.workspaces + .iter() + .find(|w| w.id == workspace.id) + .map(|w| w.capabilities.iter()) + }) } pub fn workspace_name(&self, workspace: &WorkspaceHandle) -> Option<&str> { - self.groups.iter().find_map(|g| g.workspaces.iter().find(|w| w.id == workspace.id).map(|w| &*w.name)) + self.groups.iter().find_map(|g| { + g.workspaces + .iter() + .find(|w| w.id == workspace.id) + .map(|w| &*w.name) + }) } pub fn workspace_coordinates(&self, workspace: &WorkspaceHandle) -> Option<&[u32]> { - self.groups.iter().find_map(|g| g.workspaces.iter().find(|w| w.id == workspace.id).map(|w| &*w.coordinates)) + self.groups.iter().find_map(|g| { + g.workspaces + .iter() + .find(|w| w.id == workspace.id) + .map(|w| &*w.coordinates) + }) } - pub fn workspace_states(&self, workspace: &WorkspaceHandle) -> Option> { - self.groups.iter().find_map(|g| g.workspaces.iter().find(|w| w.id == workspace.id).map(|w| w.states.iter())) + pub fn workspace_states( + &self, + workspace: &WorkspaceHandle, + ) -> Option> { + self.groups.iter().find_map(|g| { + g.workspaces + .iter() + .find(|w| w.id == workspace.id) + .map(|w| w.states.iter()) + }) } - pub fn raw_group_handle(&self, group: &WorkspaceGroupHandle, client: &ObjectId) -> Option { - self.groups.iter() + pub fn raw_group_handle( + &self, + group: &WorkspaceGroupHandle, + client: &ObjectId, + ) -> Option { + self.groups + .iter() .find(|g| g.id == group.id) .and_then(|g| g.instances.iter().find(|i| i.id().same_client_as(client))) .cloned() } - pub fn raw_workspace_handle(&self, workspace: &WorkspaceHandle, client: &ObjectId) -> Option { - self.groups.iter() + pub fn raw_workspace_handle( + &self, + workspace: &WorkspaceHandle, + client: &ObjectId, + ) -> Option { + self.groups + .iter() .find_map(|g| g.workspaces.iter().find(|w| w.id == workspace.id)) .and_then(|w| w.instances.iter().find(|i| i.id().same_client_as(client))) .cloned() @@ -467,9 +531,7 @@ where + Dispatch + WorkspaceHandler + 'static, - ::Client: ClientData - + WorkspaceClientHandler - + 'static, + ::Client: ClientData + WorkspaceClientHandler + 'static, { pub fn create_workspace_group(&mut self) -> WorkspaceGroupHandle { let id = next_group_id(); @@ -478,9 +540,7 @@ where ..Default::default() }; self.0.groups.push(group); - WorkspaceGroupHandle { - id - } + WorkspaceGroupHandle { id } } pub fn create_workspace(&mut self, group: &WorkspaceGroupHandle) -> Option { @@ -491,9 +551,7 @@ where ..Default::default() }; group.workspaces.push(workspace); - Some(WorkspaceHandle { - id - }) + Some(WorkspaceHandle { id }) } else { None } @@ -501,10 +559,14 @@ where pub fn remove_workspace_group(&mut self, group: WorkspaceGroupHandle) { // "The compositor must remove all workspaces belonging to a workspace group before removing the workspace group." - for workspace in self.0.groups.iter() + for workspace in self + .0 + .groups + .iter() .filter(|g| g.id == group.id) .flat_map(|g| g.workspaces.iter().map(|w| WorkspaceHandle { id: w.id })) - .collect::>().into_iter() + .collect::>() + .into_iter() { self.remove_workspace(workspace); } @@ -518,7 +580,7 @@ where GROUP_IDS.lock().unwrap().remove(&group.id); } - pub fn remove_workspace(&mut self, workspace: WorkspaceHandle) { + pub fn remove_workspace(&mut self, workspace: WorkspaceHandle) { for group in &mut self.0.groups { if let Some(workspace) = group.workspaces.iter().find(|w| w.id == workspace.id) { for instance in &workspace.instances { @@ -529,22 +591,36 @@ where } WORKSPACE_IDS.lock().unwrap().remove(&workspace.id); } - - pub fn workspace_belongs_to_group(&self, group: &WorkspaceGroupHandle, workspace: &WorkspaceHandle) -> bool { + + pub fn workspace_belongs_to_group( + &self, + group: &WorkspaceGroupHandle, + workspace: &WorkspaceHandle, + ) -> bool { self.0.workspace_belongs_to_group(group, workspace) } - - pub fn group_capabilities(&mut self, group: &WorkspaceGroupHandle) -> Option> { + + pub fn group_capabilities( + &mut self, + group: &WorkspaceGroupHandle, + ) -> Option> { self.0.group_capabilities(group) } - pub fn set_group_capabilities(&mut self, group: &WorkspaceGroupHandle, capabilities: impl Iterator) { + pub fn set_group_capabilities( + &mut self, + group: &WorkspaceGroupHandle, + capabilities: impl Iterator, + ) { if let Some(group) = self.0.groups.iter_mut().find(|g| g.id == group.id) { group.capabilities = capabilities.collect(); } } - pub fn group_outputs(&self, group: &WorkspaceGroupHandle) -> Option> { + pub fn group_outputs( + &self, + group: &WorkspaceGroupHandle, + ) -> Option> { self.0.group_outputs(group) } @@ -559,13 +635,23 @@ where group.outputs.retain(|o| o != output) } } - - pub fn workspace_capabilities(&self, workspace: &WorkspaceHandle) -> Option> { + + pub fn workspace_capabilities( + &self, + workspace: &WorkspaceHandle, + ) -> Option> { self.0.workspace_capabilities(workspace) } - pub fn set_workspace_capabilities(&mut self, workspace: &WorkspaceHandle, capabilities: impl Iterator) { - if let Some(workspace) = self.0.groups.iter_mut() + pub fn set_workspace_capabilities( + &mut self, + workspace: &WorkspaceHandle, + capabilities: impl Iterator, + ) { + if let Some(workspace) = self + .0 + .groups + .iter_mut() .find_map(|g| g.workspaces.iter_mut().find(|w| w.id == workspace.id)) { workspace.capabilities = capabilities.collect(); @@ -577,7 +663,10 @@ where } pub fn set_workspace_name(&mut self, workspace: &WorkspaceHandle, name: impl Into) { - if let Some(workspace) = self.0.groups.iter_mut() + if let Some(workspace) = self + .0 + .groups + .iter_mut() .find_map(|g| g.workspaces.iter_mut().find(|w| w.id == workspace.id)) { workspace.name = name.into(); @@ -588,28 +677,56 @@ where self.0.workspace_coordinates(workspace) } - pub fn set_workspace_coordinates(&mut self, workspace: &WorkspaceHandle, coords: [Option; 3]) { - if let Some(workspace) = self.0.groups.iter_mut() + pub fn set_workspace_coordinates( + &mut self, + workspace: &WorkspaceHandle, + coords: [Option; 3], + ) { + if let Some(workspace) = self + .0 + .groups + .iter_mut() .find_map(|g| g.workspaces.iter_mut().find(|w| w.id == workspace.id)) { - workspace.coordinates = coords.iter().flat_map(std::convert::identity).copied().collect(); + workspace.coordinates = coords + .iter() + .flat_map(std::convert::identity) + .copied() + .collect(); } } - pub fn workspace_states(&self, workspace: &WorkspaceHandle) -> Option> { + pub fn workspace_states( + &self, + workspace: &WorkspaceHandle, + ) -> Option> { self.0.workspace_states(workspace) } - pub fn add_workspace_state(&mut self, workspace: &WorkspaceHandle, state: zcosmic_workspace_handle_v1::State) { - if let Some(workspace) = self.0.groups.iter_mut() + pub fn add_workspace_state( + &mut self, + workspace: &WorkspaceHandle, + state: zcosmic_workspace_handle_v1::State, + ) { + if let Some(workspace) = self + .0 + .groups + .iter_mut() .find_map(|g| g.workspaces.iter_mut().find(|w| w.id == workspace.id)) { workspace.states.push(state); } } - pub fn remove_workspace_state(&mut self, workspace: &WorkspaceHandle, state: zcosmic_workspace_handle_v1::State) { - if let Some(workspace) = self.0.groups.iter_mut() + pub fn remove_workspace_state( + &mut self, + workspace: &WorkspaceHandle, + state: zcosmic_workspace_handle_v1::State, + ) { + if let Some(workspace) = self + .0 + .groups + .iter_mut() .find_map(|g| g.workspaces.iter_mut().find(|w| w.id == workspace.id)) { workspace.states.retain(|s| *s != state); @@ -625,16 +742,18 @@ where + Dispatch + WorkspaceHandler + 'static, - ::Client: ClientData - + WorkspaceClientHandler - + 'static, + ::Client: ClientData + WorkspaceClientHandler + 'static, { fn drop(&mut self) { self.0.done(); } } -fn send_group_to_client(dh: &DisplayHandle, mngr: &ZcosmicWorkspaceManagerV1, group: &mut WorkspaceGroup) -> bool +fn send_group_to_client( + dh: &DisplayHandle, + mngr: &ZcosmicWorkspaceManagerV1, + group: &mut WorkspaceGroup, +) -> bool where D: GlobalDispatch + Dispatch @@ -642,15 +761,21 @@ where + Dispatch + WorkspaceHandler + 'static, - ::Client: ClientData - + WorkspaceClientHandler - + 'static, + ::Client: ClientData + WorkspaceClientHandler + 'static, { - let instance = match group.instances.iter_mut().find(|i| i.id().same_client_as(&mngr.id())) { + let instance = match group + .instances + .iter_mut() + .find(|i| i.id().same_client_as(&mngr.id())) + { Some(i) => i, None => { if let Ok(client) = dh.get_client(mngr.id()) { - if let Ok(handle) = client.create_resource::(dh, mngr.version(), WorkspaceGroupData::default()) { + if let Ok(handle) = client.create_resource::( + dh, + mngr.version(), + WorkspaceGroupData::default(), + ) { mngr.workspace_group(&handle); group.instances.push(handle); group.instances.last_mut().unwrap() @@ -663,16 +788,28 @@ where } }; - let mut handle_state = instance.data::().unwrap().lock().unwrap(); + let mut handle_state = instance + .data::() + .unwrap() + .lock() + .unwrap(); let mut changed = false; if let Ok(client) = dh.get_client(instance.id()) { - for new_output in group.outputs.iter().filter(|o| !handle_state.outputs.contains(o)) { + for new_output in group + .outputs + .iter() + .filter(|o| !handle_state.outputs.contains(o)) + { new_output.with_client_outputs(dh, &client, |_dh, wl_output| { instance.output_enter(wl_output); }); changed = true; } - for old_output in handle_state.outputs.iter().filter(|o| group.outputs.contains(o)) { + for old_output in handle_state + .outputs + .iter() + .filter(|o| group.outputs.contains(o)) + { old_output.with_client_outputs(dh, &client, |_dh, wl_output| { instance.output_leave(wl_output); }); @@ -705,7 +842,11 @@ where changed } -fn send_workspace_to_client(dh: &DisplayHandle, group: &ZcosmicWorkspaceGroupHandleV1, workspace: &mut Workspace) -> bool +fn send_workspace_to_client( + dh: &DisplayHandle, + group: &ZcosmicWorkspaceGroupHandleV1, + workspace: &mut Workspace, +) -> bool where D: GlobalDispatch + Dispatch @@ -713,15 +854,21 @@ where + Dispatch + WorkspaceHandler + 'static, - ::Client: ClientData - + WorkspaceClientHandler - + 'static, + ::Client: ClientData + WorkspaceClientHandler + 'static, { - let instance = match workspace.instances.iter_mut().find(|i| i.id().same_client_as(&group.id())) { + let instance = match workspace + .instances + .iter_mut() + .find(|i| i.id().same_client_as(&group.id())) + { Some(i) => i, None => { if let Ok(client) = dh.get_client(group.id()) { - if let Ok(handle) = client.create_resource::(dh, group.version(), WorkspaceData::default()) { + if let Ok(handle) = client.create_resource::( + dh, + group.version(), + WorkspaceData::default(), + ) { group.workspace(&handle); workspace.instances.push(handle); workspace.instances.last_mut().unwrap() @@ -736,7 +883,7 @@ where let mut handle_state = instance.data::().unwrap().lock().unwrap(); let mut changed = false; - + if handle_state.name != workspace.name { instance.name(workspace.name.clone()); handle_state.name = workspace.name.clone(); @@ -773,7 +920,8 @@ where if handle_state.states != workspace.states { let states: Vec = { let mut states = workspace.states.clone(); - let ratio = std::mem::size_of::() / std::mem::size_of::(); + let ratio = std::mem::size_of::() + / std::mem::size_of::(); let ptr = states.as_mut_ptr() as *mut u8; let len = states.len() * ratio; let cap = states.capacity() * ratio;