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