wip: New shell logic
This commit is contained in:
parent
146a4893ca
commit
00f1b029da
39 changed files with 3922 additions and 2503 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -83,12 +83,6 @@ version = "1.5.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "983cd8b9d4b02a6dc6ffa557262eb5858a27a0038ffffe21a0f133eaa819a164"
|
||||
|
||||
[[package]]
|
||||
name = "atomic_float"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62af46d040ba9df09edc6528dae9d8e49f5f3e82f55b7d2ec31a733c38dbc49d"
|
||||
|
||||
[[package]]
|
||||
name = "atomic_refcell"
|
||||
version = "0.1.8"
|
||||
|
|
@ -292,7 +286,6 @@ name = "cosmic-comp"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"atomic_float",
|
||||
"bitflags",
|
||||
"cosmic-protocols",
|
||||
"edid-rs",
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ xkbcommon = "0.4"
|
|||
indexmap = "1.8.0"
|
||||
xdg = "^2.1"
|
||||
ron = "0.7"
|
||||
atomic_float = "0.1"
|
||||
libsystemd = "0.5"
|
||||
wayland-backend = "=0.1.0-beta.10"
|
||||
wayland-scanner = "=0.30.0-beta.10"
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
(modifiers: [Logo], key: "y"): ToggleTiling,
|
||||
(modifiers: [Logo], key: "g"): ToggleWindowFloating,
|
||||
(modifiers: [Logo, Shift], key: "f"): Fullscreen,
|
||||
(modifiers: [Logo, Shift], key: "s"): Screenshot,
|
||||
//(modifiers: [Logo, Shift], key: "s"): Screenshot,
|
||||
//TODO: ability to select default web browser
|
||||
(modifiers: [Logo], key: "b"): Spawn("firefox"),
|
||||
//TODO: ability to select default file browser
|
||||
|
|
@ -53,5 +53,6 @@
|
|||
(modifiers: [], key: "XF86MonBrightnessDown"): Spawn("busctl --user call com.system76.CosmicSettingsDaemon /com/system76/CosmicSettingsDaemon com.system76.CosmicSettingsDaemon DecreaseDisplayBrightness"),
|
||||
},
|
||||
workspace_mode: OutputBound,
|
||||
workspace_amount: Dynamic,
|
||||
floating_default: false,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ use smithay::{
|
|||
input::InputEvent,
|
||||
libinput::{LibinputInputBackend, LibinputSessionInterface},
|
||||
renderer::{
|
||||
gles2::Gles2Renderbuffer,
|
||||
damage::DamageTrackedRenderer,
|
||||
gles2::{Gles2Renderbuffer, Gles2Renderer},
|
||||
multigpu::{egl::EglGlesBackend, GpuManager},
|
||||
Bind,
|
||||
},
|
||||
|
|
@ -51,7 +52,7 @@ use std::{
|
|||
os::unix::io::{FromRawFd, OwnedFd},
|
||||
path::PathBuf,
|
||||
rc::Rc,
|
||||
time::{Duration, Instant},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
mod drm_helpers;
|
||||
|
|
@ -60,9 +61,11 @@ mod socket;
|
|||
use session_fd::*;
|
||||
use socket::*;
|
||||
|
||||
use super::render::GlMultiRenderer;
|
||||
|
||||
pub struct KmsState {
|
||||
devices: HashMap<DrmNode, Device>,
|
||||
pub api: GpuManager<EglGlesBackend>,
|
||||
pub api: GpuManager<EglGlesBackend<Gles2Renderer>>,
|
||||
pub primary: DrmNode,
|
||||
session: AutoSession,
|
||||
signaler: Signaler<Signal>,
|
||||
|
|
@ -83,9 +86,9 @@ pub struct Device {
|
|||
|
||||
pub struct Surface {
|
||||
surface: Option<GbmBufferedSurface<Rc<RefCell<GbmDevice<SessionFd>>>, SessionFd>>,
|
||||
damage_tracker: DamageTrackedRenderer,
|
||||
connector: connector::Handle,
|
||||
output: Output,
|
||||
last_render: Option<(Dmabuf, Instant)>,
|
||||
last_submit: Option<DrmEventTime>,
|
||||
refresh_rate: u32,
|
||||
vrr: bool,
|
||||
|
|
@ -142,7 +145,8 @@ pub fn init_backend(
|
|||
.map_err(|err| err.error)
|
||||
.context("Failed to initialize session event source")?;
|
||||
|
||||
let api = GpuManager::new(EglGlesBackend, None).context("Failed to initialize renderers")?;
|
||||
let api = GpuManager::new(EglGlesBackend::<Gles2Renderer>::default(), None)
|
||||
.context("Failed to initialize renderers")?;
|
||||
|
||||
// TODO get this info from system76-power, if available and setup a watcher
|
||||
let primary = if let Some(path) = std::env::var("COSMIC_RENDER_DEVICE")
|
||||
|
|
@ -370,15 +374,7 @@ impl State {
|
|||
Some(Ok(_)) => {
|
||||
surface.last_submit = metadata.take().map(|data| data.time);
|
||||
surface.pending = false;
|
||||
data.state
|
||||
.common
|
||||
.shell
|
||||
.active_space_mut(&surface.output)
|
||||
.space
|
||||
.send_frames(
|
||||
data.state.common.start_time.elapsed().as_millis()
|
||||
as u32,
|
||||
);
|
||||
data.state.common.send_frames(&surface.output);
|
||||
}
|
||||
Some(Err(err)) => {
|
||||
slog_scope::warn!("Failed to submit frame: {}", err)
|
||||
|
|
@ -689,12 +685,12 @@ impl Device {
|
|||
|
||||
let data = Surface {
|
||||
output: output.clone(),
|
||||
damage_tracker: DamageTrackedRenderer::from_output(&output),
|
||||
surface: None,
|
||||
connector: conn,
|
||||
vrr,
|
||||
refresh_rate,
|
||||
last_submit: None,
|
||||
last_render: None,
|
||||
pending: false,
|
||||
render_timer_token: None,
|
||||
#[cfg(feature = "debug")]
|
||||
|
|
@ -717,8 +713,8 @@ fn render_node_for_output(
|
|||
let workspace = shell.active_space(output);
|
||||
let nodes = workspace
|
||||
.get_fullscreen(output)
|
||||
.map(|w| vec![w])
|
||||
.unwrap_or_else(|| workspace.space.windows().collect::<Vec<_>>())
|
||||
.map(|w| vec![w.clone()])
|
||||
.unwrap_or_else(|| workspace.windows().collect::<Vec<_>>())
|
||||
.into_iter()
|
||||
.flat_map(|w| {
|
||||
dh.get_client(w.toplevel().wl_surface().id())
|
||||
|
|
@ -750,7 +746,7 @@ impl Surface {
|
|||
pub fn render_output(
|
||||
&mut self,
|
||||
dh: &DisplayHandle,
|
||||
api: &mut GpuManager<EglGlesBackend>,
|
||||
api: &mut GpuManager<EglGlesBackend<Gles2Renderer>>,
|
||||
target_node: &DrmNode,
|
||||
state: &mut Common,
|
||||
) -> Result<()> {
|
||||
|
|
@ -758,12 +754,8 @@ impl Surface {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
if render::needs_buffer_reset(&self.output, state) {
|
||||
self.surface.as_mut().unwrap().reset_buffers();
|
||||
}
|
||||
|
||||
let render_node = render_node_for_output(dh, &self.output, *target_node, &state.shell);
|
||||
let mut renderer = api.renderer(&render_node, &target_node).unwrap();
|
||||
let mut renderer: GlMultiRenderer = api.renderer(&render_node, &target_node).unwrap();
|
||||
|
||||
let surface = self.surface.as_mut().unwrap();
|
||||
let (buffer, age) = surface
|
||||
|
|
@ -777,7 +769,8 @@ impl Surface {
|
|||
match render::render_output(
|
||||
Some(&render_node),
|
||||
&mut renderer,
|
||||
age,
|
||||
&mut self.damage_tracker,
|
||||
age as usize,
|
||||
state,
|
||||
&self.output,
|
||||
false,
|
||||
|
|
@ -785,7 +778,6 @@ impl Surface {
|
|||
Some(&mut self.fps),
|
||||
) {
|
||||
Ok(_) => {
|
||||
self.last_render = Some((buffer, Instant::now()));
|
||||
surface
|
||||
.queue_buffer()
|
||||
.with_context(|| "Failed to submit buffer for display")?;
|
||||
|
|
@ -1026,17 +1018,4 @@ impl KmsState {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn capture_output(&self, output: &Output) -> Option<(DrmNode, Dmabuf, Instant)> {
|
||||
self.devices.values().find_map(|dev| {
|
||||
dev.surfaces
|
||||
.values()
|
||||
.find(|s| &s.output == output)
|
||||
.and_then(|s| {
|
||||
s.last_render
|
||||
.clone()
|
||||
.map(|(buf, time)| (dev.render_node.clone(), buf, time))
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,18 +39,22 @@ pub fn init_backend_auto(
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
if res.is_ok() {
|
||||
for seat in &state.common.seats {
|
||||
let output = state
|
||||
.common
|
||||
.shell
|
||||
.outputs()
|
||||
.next()
|
||||
.with_context(|| "Backend initialized without output")?
|
||||
.clone();
|
||||
seat.user_data()
|
||||
.insert_if_missing(|| crate::input::ActiveOutput(std::cell::RefCell::new(output)));
|
||||
}
|
||||
let output = state
|
||||
.common
|
||||
.shell
|
||||
.outputs()
|
||||
.next()
|
||||
.with_context(|| "Backend initialized without output")?;
|
||||
let initial_seat = crate::input::add_seat(
|
||||
dh,
|
||||
&mut state.common.seat_state,
|
||||
output,
|
||||
&state.common.config,
|
||||
"seat-0".into(),
|
||||
);
|
||||
state.common.add_seat(initial_seat);
|
||||
}
|
||||
res
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,20 @@
|
|||
|
||||
use crate::utils::prelude::*;
|
||||
use smithay::{
|
||||
backend::renderer::{Frame, ImportAll, ImportMem, Renderer, Texture},
|
||||
desktop::space::{RenderElement, SpaceOutputTuple, SurfaceTree},
|
||||
backend::renderer::{
|
||||
element::{
|
||||
surface::{render_elements_from_surface_tree, WaylandSurfaceRenderElement},
|
||||
texture::{TextureBuffer, TextureRenderElement},
|
||||
},
|
||||
ImportAll, ImportMem, Renderer,
|
||||
},
|
||||
input::{
|
||||
pointer::{CursorImageAttributes, CursorImageStatus},
|
||||
Seat,
|
||||
},
|
||||
reexports::wayland_server::protocol::wl_surface,
|
||||
utils::{IsAlive, Logical, Physical, Point, Rectangle, Scale, Size, Transform},
|
||||
render_elements,
|
||||
utils::{IsAlive, Logical, Point, Scale, Transform},
|
||||
wayland::compositor::{get_role, with_states},
|
||||
};
|
||||
use std::{
|
||||
|
|
@ -119,13 +125,21 @@ fn load_icon(theme: &CursorTheme) -> Result<Vec<Image>, Error> {
|
|||
parse_xcursor(&cursor_data).ok_or(Error::Parse)
|
||||
}
|
||||
|
||||
pub fn draw_surface_cursor(
|
||||
surface: wl_surface::WlSurface,
|
||||
render_elements! {
|
||||
pub CursorRenderElement<R> where R: ImportAll;
|
||||
Static=TextureRenderElement<<R as Renderer>::TextureId>,
|
||||
Surface=WaylandSurfaceRenderElement,
|
||||
}
|
||||
|
||||
pub fn draw_surface_cursor<R: Renderer + ImportAll>(
|
||||
surface: &wl_surface::WlSurface,
|
||||
location: impl Into<Point<i32, Logical>>,
|
||||
) -> SurfaceTree
|
||||
scale: impl Into<Scale<f64>>,
|
||||
) -> Vec<CursorRenderElement<R>>
|
||||
where
|
||||
{
|
||||
let mut position = location.into();
|
||||
let scale = scale.into();
|
||||
let h = with_states(&surface, |states| {
|
||||
states
|
||||
.data_map
|
||||
|
|
@ -136,125 +150,26 @@ where
|
|||
.hotspot
|
||||
});
|
||||
position -= h;
|
||||
SurfaceTree {
|
||||
surface,
|
||||
position,
|
||||
z_index: 100,
|
||||
}
|
||||
|
||||
render_elements_from_surface_tree(surface, position.to_physical_precise_round(scale), scale)
|
||||
}
|
||||
|
||||
pub fn draw_dnd_icon(
|
||||
surface: wl_surface::WlSurface,
|
||||
pub fn draw_dnd_icon<R: Renderer + ImportAll>(
|
||||
surface: &wl_surface::WlSurface,
|
||||
location: impl Into<Point<i32, Logical>>,
|
||||
) -> SurfaceTree {
|
||||
scale: impl Into<Scale<f64>>,
|
||||
) -> Vec<CursorRenderElement<R>> {
|
||||
if get_role(&surface) != Some("dnd_icon") {
|
||||
slog_scope::warn!(
|
||||
"Trying to display as a dnd icon a surface that does not have the DndIcon role."
|
||||
);
|
||||
}
|
||||
SurfaceTree {
|
||||
let scale = scale.into();
|
||||
render_elements_from_surface_tree(
|
||||
surface,
|
||||
position: location.into(),
|
||||
z_index: 100,
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PointerElement<T: Texture> {
|
||||
seat_id: usize,
|
||||
texture: T,
|
||||
position: Point<f64, Logical>,
|
||||
size: Size<i32, Logical>,
|
||||
new_frame: bool,
|
||||
}
|
||||
|
||||
impl<T: Texture> PointerElement<T> {
|
||||
pub fn new(
|
||||
seat: &Seat<State>,
|
||||
texture: T,
|
||||
relative_pointer_pos: Point<f64, Logical>,
|
||||
new_frame: bool,
|
||||
) -> PointerElement<T> {
|
||||
let size = texture.size().to_logical(1, Transform::Normal);
|
||||
PointerElement {
|
||||
seat_id: seat.id(),
|
||||
texture,
|
||||
position: relative_pointer_pos,
|
||||
size,
|
||||
new_frame,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<R> RenderElement<R> for PointerElement<<R as Renderer>::TextureId>
|
||||
where
|
||||
R: Renderer + ImportAll,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
{
|
||||
fn id(&self) -> usize {
|
||||
self.seat_id
|
||||
}
|
||||
|
||||
fn location(&self, scale: impl Into<Scale<f64>>) -> Point<f64, Physical> {
|
||||
self.position.to_physical(scale)
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
fn accumulated_damage(
|
||||
&self,
|
||||
scale: impl Into<Scale<f64>>,
|
||||
_: Option<SpaceOutputTuple<'_, '_>>,
|
||||
) -> Vec<Rectangle<i32, Physical>> {
|
||||
if self.new_frame {
|
||||
let scale = scale.into();
|
||||
vec![Rectangle::from_loc_and_size(
|
||||
self.position.to_physical(scale).to_i32_round(),
|
||||
self.size.to_physical_precise_round(scale),
|
||||
)]
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
fn opaque_regions(
|
||||
&self,
|
||||
_scale: impl Into<Scale<f64>>,
|
||||
) -> Option<Vec<Rectangle<i32, Physical>>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn draw(
|
||||
&self,
|
||||
_renderer: &mut R,
|
||||
frame: &mut <R as Renderer>::Frame,
|
||||
scale: impl Into<Scale<f64>>,
|
||||
position: Point<f64, Physical>,
|
||||
damage: &[Rectangle<i32, Physical>],
|
||||
_log: &slog::Logger,
|
||||
) -> Result<(), <R as Renderer>::Error> {
|
||||
let scale = scale.into();
|
||||
frame.render_texture_at(
|
||||
&self.texture,
|
||||
position.to_i32_round(),
|
||||
1,
|
||||
scale,
|
||||
Transform::Normal,
|
||||
&damage
|
||||
.iter()
|
||||
.copied()
|
||||
.map(|mut rect| {
|
||||
rect.loc -= self.position.to_physical(scale).to_i32_round();
|
||||
rect
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
1.0,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
location.into().to_physical_precise_round(scale),
|
||||
scale,
|
||||
)
|
||||
}
|
||||
|
||||
struct CursorState {
|
||||
|
|
@ -273,15 +188,15 @@ impl Default for CursorState {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn draw_cursor<R, I>(
|
||||
pub fn draw_cursor<R>(
|
||||
renderer: &mut R,
|
||||
seat: &Seat<State>,
|
||||
location: Point<f64, Logical>,
|
||||
scale: Scale<f64>,
|
||||
start_time: &std::time::Instant,
|
||||
draw_default: bool,
|
||||
) -> Option<I>
|
||||
) -> Vec<CursorRenderElement<R>>
|
||||
where
|
||||
I: From<SurfaceTree> + From<PointerElement<<R as Renderer>::TextureId>>,
|
||||
R: Renderer + ImportAll + ImportMem,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
{
|
||||
|
|
@ -302,50 +217,69 @@ where
|
|||
})
|
||||
.unwrap_or(CursorImageStatus::Default);
|
||||
|
||||
if let CursorImageStatus::Surface(wl_surface) = cursor_status {
|
||||
Some(draw_surface_cursor(wl_surface.clone(), location.to_i32_round()).into())
|
||||
if let CursorImageStatus::Surface(ref wl_surface) = cursor_status {
|
||||
return draw_surface_cursor(wl_surface, location.to_i32_round(), scale);
|
||||
} else if draw_default {
|
||||
let integer_scale = scale.x.max(scale.y).ceil() as u32;
|
||||
|
||||
let seat_userdata = seat.user_data();
|
||||
seat_userdata.insert_if_missing(CursorState::default);
|
||||
let state = seat_userdata.get::<CursorState>().unwrap();
|
||||
let frame = state
|
||||
.cursor
|
||||
.get_image(1, start_time.elapsed().as_millis() as u32);
|
||||
let new_frame = state.current_image.borrow().as_ref() != Some(&frame);
|
||||
.get_image(integer_scale, start_time.elapsed().as_millis() as u32);
|
||||
|
||||
let mut cache = state.image_cache.borrow_mut();
|
||||
let pointer_images = cache
|
||||
.entry((TypeId::of::<<R as Renderer>::TextureId>(), renderer.id()))
|
||||
.entry((
|
||||
TypeId::of::<TextureBuffer<<R as Renderer>::TextureId>>(),
|
||||
renderer.id(),
|
||||
))
|
||||
.or_default();
|
||||
let pointer_image = pointer_images
|
||||
|
||||
let maybe_image = pointer_images
|
||||
.iter()
|
||||
.find_map(|(image, texture)| if image == &frame { Some(texture) } else { None })
|
||||
.and_then(|texture| {
|
||||
texture
|
||||
.downcast_ref::<<R as Renderer>::TextureId>()
|
||||
.cloned()
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
let texture = renderer
|
||||
.import_memory(
|
||||
&frame.pixels_rgba,
|
||||
(frame.width as i32, frame.height as i32).into(),
|
||||
false,
|
||||
)
|
||||
.expect("Failed to import cursor bitmap");
|
||||
pointer_images.push((frame.clone(), Box::new(texture.clone())));
|
||||
texture
|
||||
texture.downcast_ref::<TextureBuffer<<R as Renderer>::TextureId>>()
|
||||
});
|
||||
let pointer_image = match maybe_image {
|
||||
Some(image) => image,
|
||||
None => {
|
||||
let texture = TextureBuffer::from_memory(
|
||||
renderer,
|
||||
&frame.pixels_rgba,
|
||||
(frame.width as i32, frame.height as i32),
|
||||
false,
|
||||
integer_scale as i32,
|
||||
Transform::Normal,
|
||||
None,
|
||||
)
|
||||
.expect("Failed to import cursor bitmap");
|
||||
pointer_images.push((frame.clone(), Box::new(texture.clone())));
|
||||
pointer_images
|
||||
.last()
|
||||
.and_then(|(_, i)| {
|
||||
i.downcast_ref::<TextureBuffer<<R as Renderer>::TextureId>>()
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
};
|
||||
|
||||
let hotspot =
|
||||
Point::<i32, Logical>::from((frame.xhot as i32, frame.yhot as i32)).to_f64();
|
||||
*state.current_image.borrow_mut() = Some(frame);
|
||||
|
||||
Some(
|
||||
PointerElement::new(seat, pointer_image.clone(), location - hotspot, new_frame)
|
||||
.into(),
|
||||
)
|
||||
return vec![CursorRenderElement::Static(
|
||||
TextureRenderElement::from_texture_buffer(
|
||||
(location - hotspot).to_physical(scale),
|
||||
pointer_image,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
)];
|
||||
} else {
|
||||
None
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,162 +6,74 @@ use crate::{
|
|||
state::Fps,
|
||||
utils::prelude::*,
|
||||
};
|
||||
//grabs::{MoveGrabRenderElement, SeatMoveGrabState},
|
||||
use crate::{
|
||||
shell::grabs::{MoveGrabRenderElement, SeatMoveGrabState},
|
||||
state::Common,
|
||||
wayland::handlers::data_device::get_dnd_icon,
|
||||
shell::WorkspaceRenderElement, state::Common, wayland::handlers::data_device::get_dnd_icon,
|
||||
};
|
||||
|
||||
use slog::Logger;
|
||||
use smithay::{
|
||||
backend::{
|
||||
drm::DrmNode,
|
||||
renderer::{
|
||||
gles2::{Gles2Renderbuffer, Gles2Renderer, Gles2Texture},
|
||||
multigpu::{egl::EglGlesBackend, Error as MultiError, MultiFrame, MultiRenderer},
|
||||
Frame, ImportAll, Renderer,
|
||||
damage::{
|
||||
DamageTrackedRenderer, DamageTrackedRendererError as RenderError, OutputNoMode,
|
||||
},
|
||||
gles2::{Gles2Renderbuffer, Gles2Renderer},
|
||||
multigpu::{egl::EglGlesBackend, MultiFrame, MultiRenderer},
|
||||
ImportAll, ImportMem, Renderer,
|
||||
},
|
||||
},
|
||||
desktop::{
|
||||
draw_layer_popups, draw_layer_surface, draw_window, draw_window_popups,
|
||||
layer_map_for_output,
|
||||
space::{RenderElement, RenderError, SpaceOutputTuple, SurfaceTree},
|
||||
utils::damage_from_surface_tree,
|
||||
Window,
|
||||
},
|
||||
output::Output,
|
||||
utils::{Physical, Point, Rectangle, Scale, Transform},
|
||||
wayland::shell::wlr_layer::Layer as WlrLayer,
|
||||
utils::{Physical, Rectangle},
|
||||
};
|
||||
|
||||
pub mod cursor;
|
||||
use self::cursor::PointerElement;
|
||||
use self::cursor::CursorRenderElement;
|
||||
|
||||
pub type GlMultiRenderer<'a> =
|
||||
MultiRenderer<'a, 'a, EglGlesBackend, EglGlesBackend, Gles2Renderbuffer>;
|
||||
pub type GlMultiFrame = MultiFrame<EglGlesBackend, EglGlesBackend>;
|
||||
pub type GlMultiRenderer<'a> = MultiRenderer<
|
||||
'a,
|
||||
'a,
|
||||
EglGlesBackend<Gles2Renderer>,
|
||||
EglGlesBackend<Gles2Renderer>,
|
||||
Gles2Renderbuffer,
|
||||
>;
|
||||
pub type GlMultiFrame = MultiFrame<EglGlesBackend<Gles2Renderer>, EglGlesBackend<Gles2Renderer>>;
|
||||
|
||||
static CLEAR_COLOR: [f32; 4] = [0.153, 0.161, 0.165, 1.0];
|
||||
|
||||
smithay::custom_elements! {
|
||||
pub CustomElem<=Gles2Renderer>;
|
||||
SurfaceTree=SurfaceTree,
|
||||
PointerElement=PointerElement::<Gles2Texture>,
|
||||
MoveGrabRenderElement=MoveGrabRenderElement,
|
||||
#[cfg(feature = "debug")]
|
||||
EguiFrame=EguiFrame,
|
||||
smithay::render_elements! {
|
||||
pub CosmicElement<R> where R: ImportAll;
|
||||
WorkspaceElement=WorkspaceRenderElement<R>,
|
||||
CursorElement=CursorRenderElement<R>,
|
||||
//MoveGrabRenderElement=MoveGrabRenderElement,
|
||||
//#[cfg(feature = "debug")]
|
||||
//EguiFrame=EguiFrame,
|
||||
}
|
||||
|
||||
// TODO: due to the lifetime of MultiRenderer, we cannot be generic over CustomElem's renderer
|
||||
// util after GATs land. So we generate with the macro for Gles2 and then
|
||||
// do a manual impl for MultiRenderer.
|
||||
impl RenderElement<GlMultiRenderer<'_>> for CustomElem {
|
||||
fn id(&self) -> usize {
|
||||
RenderElement::<Gles2Renderer>::id(self)
|
||||
}
|
||||
|
||||
fn location(&self, scale: impl Into<Scale<f64>>) -> Point<f64, Physical> {
|
||||
RenderElement::<Gles2Renderer>::location(self, scale)
|
||||
}
|
||||
|
||||
fn geometry(&self, scale: impl Into<Scale<f64>>) -> Rectangle<i32, Physical> {
|
||||
RenderElement::<Gles2Renderer>::geometry(self, scale)
|
||||
}
|
||||
|
||||
fn accumulated_damage(
|
||||
&self,
|
||||
scale: impl Into<Scale<f64>>,
|
||||
for_values: Option<SpaceOutputTuple<'_, '_>>,
|
||||
) -> Vec<Rectangle<i32, Physical>> {
|
||||
RenderElement::<Gles2Renderer>::accumulated_damage(self, scale, for_values)
|
||||
}
|
||||
|
||||
fn opaque_regions(
|
||||
&self,
|
||||
scale: impl Into<Scale<f64>>,
|
||||
) -> Option<Vec<Rectangle<i32, Physical>>> {
|
||||
RenderElement::<Gles2Renderer>::opaque_regions(self, scale)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
&self,
|
||||
renderer: &mut GlMultiRenderer<'_>,
|
||||
frame: &mut GlMultiFrame,
|
||||
scale: impl Into<Scale<f64>>,
|
||||
location: Point<f64, Physical>,
|
||||
damage: &[Rectangle<i32, Physical>],
|
||||
log: &Logger,
|
||||
) -> Result<(), MultiError<EglGlesBackend, EglGlesBackend>> {
|
||||
RenderElement::<Gles2Renderer>::draw(
|
||||
self,
|
||||
renderer.as_mut(),
|
||||
frame.as_mut(),
|
||||
scale,
|
||||
location,
|
||||
damage,
|
||||
log,
|
||||
)
|
||||
.map_err(MultiError::Render)
|
||||
}
|
||||
|
||||
fn z_index(&self) -> u8 {
|
||||
RenderElement::<Gles2Renderer>::z_index(self)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AsGles2Renderer {
|
||||
fn as_gles2(&mut self) -> &mut Gles2Renderer;
|
||||
}
|
||||
impl AsGles2Renderer for Gles2Renderer {
|
||||
fn as_gles2(&mut self) -> &mut Gles2Renderer {
|
||||
self
|
||||
}
|
||||
}
|
||||
impl AsGles2Renderer for GlMultiRenderer<'_> {
|
||||
fn as_gles2(&mut self) -> &mut Gles2Renderer {
|
||||
self.as_mut()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn needs_buffer_reset(output: &Output, state: &Common) -> bool {
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
struct DidCustomRendering(AtomicBool);
|
||||
|
||||
let will_render_custom = {
|
||||
let workspace = state.shell.active_space(output);
|
||||
workspace.get_fullscreen(output).is_some()
|
||||
};
|
||||
|
||||
let userdata = output.user_data();
|
||||
userdata.insert_if_missing(|| DidCustomRendering(AtomicBool::new(false)));
|
||||
userdata
|
||||
.get::<DidCustomRendering>()
|
||||
.unwrap()
|
||||
.0
|
||||
.swap(will_render_custom, Ordering::AcqRel)
|
||||
!= will_render_custom
|
||||
}
|
||||
|
||||
pub fn cursor_custom_elements<R>(
|
||||
pub fn cursor_elements<E, R>(
|
||||
renderer: &mut R,
|
||||
state: &Common,
|
||||
output: &Output,
|
||||
hardware_cursor: bool,
|
||||
) -> Vec<CustomElem>
|
||||
) -> Vec<E>
|
||||
where
|
||||
R: AsGles2Renderer,
|
||||
R: Renderer + ImportAll + ImportMem,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
E: From<CursorRenderElement<R>>,
|
||||
{
|
||||
let mut custom_elements = Vec::new();
|
||||
let scale = output.current_scale().fractional_scale();
|
||||
let mut elements = Vec::new();
|
||||
|
||||
for seat in &state.seats {
|
||||
for seat in state.seats() {
|
||||
let pointer = match seat.get_pointer() {
|
||||
Some(ptr) => ptr,
|
||||
None => continue,
|
||||
};
|
||||
let location = state
|
||||
.shell
|
||||
.space_relative_output_geometry(pointer.current_location().to_i32_round(), output);
|
||||
.map_global_to_space(pointer.current_location().to_i32_round(), output);
|
||||
|
||||
/*
|
||||
if let Some(grab) = seat
|
||||
.user_data()
|
||||
.get::<SeatMoveGrabState>()
|
||||
|
|
@ -172,147 +84,92 @@ where
|
|||
{
|
||||
custom_elements.push(grab);
|
||||
}
|
||||
*/
|
||||
|
||||
if let Some(wl_surface) = get_dnd_icon(seat) {
|
||||
custom_elements.push(cursor::draw_dnd_icon(wl_surface, location.to_i32_round()).into());
|
||||
elements.extend(
|
||||
cursor::draw_dnd_icon(&wl_surface, location.to_i32_round(), scale)
|
||||
.into_iter()
|
||||
.map(E::from),
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(cursor) = cursor::draw_cursor(
|
||||
renderer.as_gles2(),
|
||||
seat,
|
||||
location,
|
||||
&state.start_time,
|
||||
!hardware_cursor,
|
||||
) {
|
||||
custom_elements.push(cursor)
|
||||
}
|
||||
elements.extend(
|
||||
cursor::draw_cursor(
|
||||
renderer,
|
||||
seat,
|
||||
location,
|
||||
scale.into(),
|
||||
&state.start_time,
|
||||
!hardware_cursor,
|
||||
)
|
||||
.into_iter()
|
||||
.map(E::from),
|
||||
);
|
||||
}
|
||||
|
||||
custom_elements
|
||||
elements
|
||||
}
|
||||
|
||||
pub fn render_output<R>(
|
||||
gpu: Option<&DrmNode>,
|
||||
renderer: &mut R,
|
||||
age: u8,
|
||||
damage_tracker: &mut DamageTrackedRenderer,
|
||||
age: usize,
|
||||
state: &mut Common,
|
||||
output: &Output,
|
||||
hardware_cursor: bool,
|
||||
#[cfg(feature = "debug")] mut fps: Option<&mut Fps>,
|
||||
) -> Result<Option<Vec<Rectangle<i32, Physical>>>, RenderError<R>>
|
||||
where
|
||||
R: Renderer + ImportAll + AsGles2Renderer,
|
||||
R: Renderer + ImportAll + ImportMem,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CustomElem: RenderElement<R>,
|
||||
{
|
||||
let workspace = state.shell.active_space(output).idx;
|
||||
let idx = state.shell.workspaces.active_num(output);
|
||||
render_workspace(
|
||||
gpu,
|
||||
renderer,
|
||||
damage_tracker,
|
||||
age,
|
||||
state,
|
||||
workspace,
|
||||
output,
|
||||
idx,
|
||||
hardware_cursor,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_workspace<R>(
|
||||
gpu: Option<&DrmNode>,
|
||||
_gpu: Option<&DrmNode>,
|
||||
renderer: &mut R,
|
||||
age: u8,
|
||||
damage_tracker: &mut DamageTrackedRenderer,
|
||||
age: usize,
|
||||
state: &mut Common,
|
||||
space_idx: u8,
|
||||
output: &Output,
|
||||
idx: usize,
|
||||
hardware_cursor: bool,
|
||||
#[cfg(feature = "debug")] mut fps: Option<&mut Fps>,
|
||||
) -> Result<Option<Vec<Rectangle<i32, Physical>>>, RenderError<R>>
|
||||
where
|
||||
R: Renderer + ImportAll + AsGles2Renderer,
|
||||
R: Renderer + ImportAll + ImportMem,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CustomElem: RenderElement<R>,
|
||||
{
|
||||
#[cfg(feature = "debug")]
|
||||
if let Some(ref mut fps) = fps {
|
||||
fps.start();
|
||||
}
|
||||
|
||||
let space_idx = space_idx as usize;
|
||||
let workspace = &mut state.shell.spaces[space_idx];
|
||||
let maybe_fullscreen_window = workspace.get_fullscreen(output).cloned();
|
||||
let workspace = &state
|
||||
.shell
|
||||
.workspaces
|
||||
.get(idx, output)
|
||||
.ok_or(OutputNoMode)?;
|
||||
|
||||
let res = if let Some(window) = maybe_fullscreen_window {
|
||||
#[cfg(not(feature = "debug"))]
|
||||
{
|
||||
render_fullscreen(gpu, renderer, window, state, output, hardware_cursor)
|
||||
}
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
render_fullscreen(
|
||||
gpu,
|
||||
renderer,
|
||||
window,
|
||||
state,
|
||||
output,
|
||||
hardware_cursor,
|
||||
fps.as_deref_mut(),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
#[cfg(not(feature = "debug"))]
|
||||
{
|
||||
render_desktop(
|
||||
gpu,
|
||||
renderer,
|
||||
age,
|
||||
state,
|
||||
space_idx,
|
||||
output,
|
||||
hardware_cursor,
|
||||
)
|
||||
}
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
render_desktop(
|
||||
gpu,
|
||||
renderer,
|
||||
age,
|
||||
state,
|
||||
space_idx,
|
||||
output,
|
||||
hardware_cursor,
|
||||
fps.as_deref_mut(),
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
if let Some(ref mut fps) = fps {
|
||||
fps.end();
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
fn render_desktop<R>(
|
||||
_gpu: Option<&DrmNode>,
|
||||
renderer: &mut R,
|
||||
age: u8,
|
||||
state: &mut Common,
|
||||
space_idx: usize,
|
||||
output: &Output,
|
||||
hardware_cursor: bool,
|
||||
#[cfg(feature = "debug")] fps: Option<&mut Fps>,
|
||||
) -> Result<Option<Vec<Rectangle<i32, Physical>>>, RenderError<R>>
|
||||
where
|
||||
R: Renderer + ImportAll + AsGles2Renderer,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CustomElem: RenderElement<R>,
|
||||
{
|
||||
let mut custom_elements = Vec::<CustomElem>::new();
|
||||
let mut elements: Vec<CosmicElement<R>> =
|
||||
cursor_elements(renderer, state, output, hardware_cursor);
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
// TODO add debug elements
|
||||
let workspace = &state.shell.spaces[space_idx];
|
||||
let output_geo = workspace
|
||||
.space
|
||||
|
|
@ -346,132 +203,20 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
custom_elements.extend(cursor_custom_elements(
|
||||
renderer,
|
||||
state,
|
||||
output,
|
||||
hardware_cursor,
|
||||
));
|
||||
elements.extend(
|
||||
workspace
|
||||
.render_output(output)
|
||||
.map_err(|_| OutputNoMode)?
|
||||
.into_iter()
|
||||
.map(Into::into),
|
||||
);
|
||||
|
||||
state.shell.spaces[space_idx].space.render_output(
|
||||
renderer,
|
||||
&output,
|
||||
age as usize,
|
||||
CLEAR_COLOR,
|
||||
&*custom_elements,
|
||||
)
|
||||
}
|
||||
|
||||
fn render_fullscreen<R>(
|
||||
_gpu: Option<&DrmNode>,
|
||||
renderer: &mut R,
|
||||
window: Window,
|
||||
state: &mut Common,
|
||||
output: &Output,
|
||||
hardware_cursor: bool,
|
||||
#[cfg(feature = "debug")] fps: Option<&mut Fps>,
|
||||
) -> Result<Option<Vec<Rectangle<i32, Physical>>>, RenderError<R>>
|
||||
where
|
||||
R: Renderer + ImportAll + AsGles2Renderer,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CustomElem: RenderElement<R>,
|
||||
{
|
||||
let transform = Transform::from(output.current_transform());
|
||||
let mode = output.current_mode().unwrap();
|
||||
let scale = output.current_scale().fractional_scale();
|
||||
|
||||
let mut custom_elements = Vec::<CustomElem>::new();
|
||||
let res = damage_tracker.render_output(renderer, age, &elements, CLEAR_COLOR, None);
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
if let Some(fps) = fps {
|
||||
let output_geo = output.geometry();
|
||||
let fps_overlay = fps_ui(
|
||||
_gpu,
|
||||
state,
|
||||
fps,
|
||||
Rectangle::from_loc_and_size((0, 0), output_geo.size)
|
||||
.to_f64()
|
||||
.to_physical(scale),
|
||||
scale,
|
||||
);
|
||||
custom_elements.push(fps_overlay.into());
|
||||
if let Some(ref mut fps) = fps {
|
||||
fps.end();
|
||||
}
|
||||
|
||||
custom_elements.extend(cursor_custom_elements(
|
||||
renderer,
|
||||
state,
|
||||
output,
|
||||
hardware_cursor,
|
||||
));
|
||||
|
||||
renderer
|
||||
.render(mode.size, transform, |renderer, frame| {
|
||||
let mut damage = window.accumulated_damage((0.0, 0.0), scale, None);
|
||||
frame.clear(
|
||||
CLEAR_COLOR,
|
||||
&[Rectangle::from_loc_and_size((0, 0), mode.size)],
|
||||
)?;
|
||||
draw_window(
|
||||
renderer,
|
||||
frame,
|
||||
&window,
|
||||
scale,
|
||||
(0.0, 0.0),
|
||||
&[Rectangle::from_loc_and_size((0, 0), mode.size)],
|
||||
&slog_scope::logger(),
|
||||
)?;
|
||||
draw_window_popups(
|
||||
renderer,
|
||||
frame,
|
||||
&window,
|
||||
scale,
|
||||
(0.0, 0.0),
|
||||
&[Rectangle::from_loc_and_size((0, 0), mode.size)],
|
||||
&slog_scope::logger(),
|
||||
)?;
|
||||
let layer_map = layer_map_for_output(output);
|
||||
for layer_surface in layer_map.layers_on(WlrLayer::Overlay) {
|
||||
let geo = layer_map.layer_geometry(&layer_surface).unwrap();
|
||||
draw_layer_surface(
|
||||
renderer,
|
||||
frame,
|
||||
layer_surface,
|
||||
scale,
|
||||
geo.loc.to_f64().to_physical(scale),
|
||||
&[Rectangle::from_loc_and_size(
|
||||
(0, 0),
|
||||
geo.size.to_physical_precise_round(scale),
|
||||
)],
|
||||
&slog_scope::logger(),
|
||||
)?;
|
||||
draw_layer_popups(
|
||||
renderer,
|
||||
frame,
|
||||
layer_surface,
|
||||
scale,
|
||||
geo.loc.to_f64().to_physical(scale),
|
||||
&[Rectangle::from_loc_and_size(
|
||||
(0, 0),
|
||||
geo.size.to_physical_precise_round(scale),
|
||||
)],
|
||||
&slog_scope::logger(),
|
||||
)?;
|
||||
damage.extend(damage_from_surface_tree(
|
||||
layer_surface.wl_surface(),
|
||||
geo.loc.to_f64().to_physical(scale),
|
||||
scale,
|
||||
None,
|
||||
));
|
||||
}
|
||||
for elem in custom_elements {
|
||||
let loc = elem.location(scale);
|
||||
let geo = elem.geometry(scale);
|
||||
let elem_damage = elem.accumulated_damage(scale, None);
|
||||
elem.draw(renderer, frame, scale, loc, &[geo], &slog_scope::logger())?;
|
||||
damage.extend(elem_damage)
|
||||
}
|
||||
Ok(Some(damage))
|
||||
})
|
||||
.and_then(std::convert::identity)
|
||||
.map_err(RenderError::<R>::Rendering)
|
||||
res
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
use anyhow::{anyhow, Context, Result};
|
||||
use smithay::{
|
||||
backend::{
|
||||
renderer::{ImportDma, ImportEgl},
|
||||
renderer::{damage::DamageTrackedRenderer, ImportDma, ImportEgl},
|
||||
winit::{self, WinitEvent, WinitGraphicsBackend, WinitVirtualDevice},
|
||||
},
|
||||
desktop::layer_map_for_output,
|
||||
|
|
@ -30,31 +30,23 @@ pub struct WinitState {
|
|||
// The winit backend currently has no notion of multiple windows
|
||||
pub backend: WinitGraphicsBackend,
|
||||
output: Output,
|
||||
age_reset: u8,
|
||||
damage_tracker: DamageTrackedRenderer,
|
||||
#[cfg(feature = "debug")]
|
||||
fps: Fps,
|
||||
}
|
||||
|
||||
impl WinitState {
|
||||
pub fn render_output(&mut self, state: &mut Common) -> Result<()> {
|
||||
if render::needs_buffer_reset(&self.output, state) {
|
||||
self.reset_buffers();
|
||||
}
|
||||
|
||||
self.backend
|
||||
.bind()
|
||||
.with_context(|| "Failed to bind buffer")?;
|
||||
let age = if self.age_reset > 0 {
|
||||
self.age_reset -= 1;
|
||||
0
|
||||
} else {
|
||||
self.backend.buffer_age().unwrap_or(0)
|
||||
};
|
||||
let age = self.backend.buffer_age().unwrap_or(0);
|
||||
|
||||
match render::render_output(
|
||||
None,
|
||||
self.backend.renderer(),
|
||||
age as u8,
|
||||
&mut self.damage_tracker,
|
||||
age,
|
||||
state,
|
||||
&self.output,
|
||||
true,
|
||||
|
|
@ -62,11 +54,7 @@ impl WinitState {
|
|||
Some(&mut self.fps),
|
||||
) {
|
||||
Ok(damage) => {
|
||||
state
|
||||
.shell
|
||||
.active_space_mut(&self.output)
|
||||
.space
|
||||
.send_frames(state.start_time.elapsed().as_millis() as u32);
|
||||
state.send_frames(&self.output);
|
||||
self.backend
|
||||
.submit(damage.as_ref().map(|x| &**x))
|
||||
.with_context(|| "Failed to submit buffer for display")?;
|
||||
|
|
@ -104,10 +92,6 @@ impl WinitState {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset_buffers(&mut self) {
|
||||
self.age_reset = 3;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_backend(
|
||||
|
|
@ -180,8 +164,7 @@ pub fn init_backend(
|
|||
.handle()
|
||||
.insert_source(event_source, move |_, _, data| {
|
||||
match input.dispatch_new_events(|event| {
|
||||
data.state
|
||||
.process_winit_event(&data.display.handle(), event, &render_ping_handle)
|
||||
data.state.process_winit_event(event, &render_ping_handle)
|
||||
}) {
|
||||
Ok(_) => {
|
||||
event_ping_handle.ping();
|
||||
|
|
@ -202,9 +185,9 @@ pub fn init_backend(
|
|||
state.backend = BackendData::Winit(WinitState {
|
||||
backend,
|
||||
output: output.clone(),
|
||||
damage_tracker: DamageTrackedRenderer::from_output(&output),
|
||||
#[cfg(feature = "debug")]
|
||||
fps: Fps::default(),
|
||||
age_reset: 0,
|
||||
});
|
||||
state
|
||||
.common
|
||||
|
|
@ -250,19 +233,14 @@ fn init_egl_client_side(
|
|||
}
|
||||
|
||||
impl State {
|
||||
pub fn process_winit_event(
|
||||
&mut self,
|
||||
dh: &DisplayHandle,
|
||||
event: WinitEvent,
|
||||
render_ping: &ping::Ping,
|
||||
) {
|
||||
pub fn process_winit_event(&mut self, event: WinitEvent, render_ping: &ping::Ping) {
|
||||
// here we can handle special cases for winit inputs
|
||||
match event {
|
||||
WinitEvent::Focus(true) => {
|
||||
for seat in self.common.seats.clone().iter() {
|
||||
for seat in self.common.seats().cloned().collect::<Vec<_>>().iter() {
|
||||
let devices = seat.user_data().get::<Devices>().unwrap();
|
||||
if devices.has_device(&WinitVirtualDevice) {
|
||||
set_active_output(seat, &self.backend.winit().output);
|
||||
seat.set_active_output(&self.backend.winit().output);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -286,7 +264,7 @@ impl State {
|
|||
output.delete_mode(output.current_mode().unwrap());
|
||||
output.set_preferred(mode);
|
||||
output.change_current_state(Some(mode), None, None, None);
|
||||
layer_map_for_output(output).arrange(dh);
|
||||
layer_map_for_output(output).arrange();
|
||||
self.common.output_configuration_state.update();
|
||||
self.common.shell.refresh_outputs();
|
||||
render_ping.ping();
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@ use smithay::{
|
|||
allocator::dmabuf::Dmabuf,
|
||||
egl::{EGLContext, EGLDisplay},
|
||||
input::{Event, InputEvent},
|
||||
renderer::{gles2::Gles2Renderer, Bind, ImportDma, ImportEgl},
|
||||
renderer::{
|
||||
damage::DamageTrackedRenderer, gles2::Gles2Renderer, Bind, ImportDma, ImportEgl,
|
||||
},
|
||||
x11::{Window, WindowBuilder, X11Backend, X11Event, X11Handle, X11Input, X11Surface},
|
||||
},
|
||||
desktop::layer_map_for_output,
|
||||
|
|
@ -114,6 +116,7 @@ impl X11State {
|
|||
self.surfaces.push(Surface {
|
||||
window,
|
||||
surface,
|
||||
damage_tracker: DamageTrackedRenderer::from_output(&output),
|
||||
output: output.clone(),
|
||||
render: ping.clone(),
|
||||
dirty: false,
|
||||
|
|
@ -168,6 +171,7 @@ impl X11State {
|
|||
|
||||
pub struct Surface {
|
||||
window: Window,
|
||||
damage_tracker: DamageTrackedRenderer,
|
||||
surface: X11Surface,
|
||||
output: Output,
|
||||
render: ping::Ping,
|
||||
|
|
@ -183,10 +187,6 @@ impl Surface {
|
|||
renderer: &mut Gles2Renderer,
|
||||
state: &mut Common,
|
||||
) -> Result<()> {
|
||||
if render::needs_buffer_reset(&self.output, state) {
|
||||
self.surface.reset_buffers();
|
||||
}
|
||||
|
||||
let (buffer, age) = self
|
||||
.surface
|
||||
.buffer()
|
||||
|
|
@ -198,7 +198,8 @@ impl Surface {
|
|||
match render::render_output(
|
||||
None,
|
||||
renderer,
|
||||
age as u8,
|
||||
&mut self.damage_tracker,
|
||||
age as usize,
|
||||
state,
|
||||
&self.output,
|
||||
true,
|
||||
|
|
@ -206,11 +207,7 @@ impl Surface {
|
|||
Some(&mut self.fps),
|
||||
) {
|
||||
Ok(_) => {
|
||||
state
|
||||
.shell
|
||||
.active_space_mut(&self.output)
|
||||
.space
|
||||
.send_frames(state.start_time.elapsed().as_millis() as u32);
|
||||
state.send_frames(&self.output);
|
||||
self.surface
|
||||
.submit()
|
||||
.with_context(|| "Failed to submit buffer for display")?;
|
||||
|
|
@ -336,7 +333,7 @@ pub fn init_backend(
|
|||
output.delete_mode(output.current_mode().unwrap());
|
||||
output.change_current_state(Some(mode), None, None, None);
|
||||
output.set_preferred(mode);
|
||||
layer_map_for_output(output).arrange(&data.display.handle());
|
||||
layer_map_for_output(output).arrange();
|
||||
data.state.common.output_configuration_state.update();
|
||||
data.state.common.shell.refresh_outputs();
|
||||
surface.dirty = true;
|
||||
|
|
@ -405,10 +402,10 @@ impl State {
|
|||
.unwrap();
|
||||
|
||||
let device = event.device();
|
||||
for seat in self.common.seats.clone().iter() {
|
||||
for seat in self.common.seats().cloned().collect::<Vec<_>>().iter() {
|
||||
let devices = seat.user_data().get::<Devices>().unwrap();
|
||||
if devices.has_device(&device) {
|
||||
set_active_output(seat, &output);
|
||||
seat.set_active_output(&output);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::{
|
||||
shell::{focus::FocusDirection, Shell},
|
||||
shell::{focus::FocusDirection, Shell, WorkspaceAmount},
|
||||
state::{BackendData, Data},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -32,6 +32,7 @@ pub struct Config {
|
|||
pub struct StaticConfig {
|
||||
pub key_bindings: HashMap<KeyPattern, Action>,
|
||||
pub workspace_mode: WorkspaceMode,
|
||||
pub workspace_amount: WorkspaceAmount,
|
||||
pub floating_default: bool,
|
||||
}
|
||||
|
||||
|
|
@ -215,6 +216,7 @@ impl Config {
|
|||
StaticConfig {
|
||||
key_bindings: HashMap::new(),
|
||||
workspace_mode: WorkspaceMode::Global,
|
||||
workspace_amount: WorkspaceAmount::Dynamic,
|
||||
floating_default: false,
|
||||
}
|
||||
}
|
||||
|
|
@ -787,6 +789,6 @@ pub enum Action {
|
|||
ToggleTiling,
|
||||
ToggleWindowFloating,
|
||||
Fullscreen,
|
||||
Screenshot,
|
||||
//Screenshot,
|
||||
Spawn(String),
|
||||
}
|
||||
|
|
|
|||
342
src/input/mod.rs
342
src/input/mod.rs
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use crate::{
|
||||
config::{Action, Config},
|
||||
shell::{grabs::SeatMoveGrabState, Workspace},
|
||||
shell::{focus::target::PointerFocusTarget, Workspace}, // shell::grabs::SeatMoveGrabState
|
||||
state::Common,
|
||||
utils::prelude::*,
|
||||
};
|
||||
|
|
@ -11,17 +11,17 @@ use smithay::{
|
|||
AbsolutePositionEvent, Axis, AxisSource, Device, DeviceCapability, InputBackend,
|
||||
InputEvent, KeyState, PointerAxisEvent,
|
||||
},
|
||||
desktop::{layer_map_for_output, Kind, WindowSurfaceType},
|
||||
desktop::layer_map_for_output,
|
||||
input::{
|
||||
keyboard::{keysyms, FilterResult, KeysymHandle, XkbConfig},
|
||||
pointer::{AxisFrame, ButtonEvent, CursorImageStatus, MotionEvent},
|
||||
Seat, SeatState,
|
||||
},
|
||||
output::Output,
|
||||
reexports::wayland_server::{protocol::wl_surface::WlSurface, DisplayHandle},
|
||||
utils::{Buffer, Logical, Point, Rectangle, Size, SERIAL_COUNTER},
|
||||
reexports::wayland_server::DisplayHandle,
|
||||
utils::{Logical, Point, Rectangle, SERIAL_COUNTER},
|
||||
wayland::{
|
||||
keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitorSeat,
|
||||
keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitorSeat, seat::WaylandFocus,
|
||||
shell::wlr_layer::Layer as WlrLayer,
|
||||
},
|
||||
};
|
||||
|
|
@ -103,6 +103,7 @@ impl Devices {
|
|||
pub fn add_seat(
|
||||
dh: &DisplayHandle,
|
||||
seat_state: &mut SeatState<State>,
|
||||
output: &Output,
|
||||
config: &Config,
|
||||
name: String,
|
||||
) -> Seat<State> {
|
||||
|
|
@ -111,7 +112,8 @@ pub fn add_seat(
|
|||
userdata.insert_if_missing(SeatId::default);
|
||||
userdata.insert_if_missing(Devices::default);
|
||||
userdata.insert_if_missing(SupressedKeys::default);
|
||||
userdata.insert_if_missing(SeatMoveGrabState::default);
|
||||
//userdata.insert_if_missing(SeatMoveGrabState::default);
|
||||
userdata.insert_if_missing(|| ActiveOutput(RefCell::new(output.clone())));
|
||||
userdata.insert_if_missing(|| RefCell::new(CursorImageStatus::Default));
|
||||
|
||||
// A lot of clients bind keyboard and pointer unconditionally once on launch..
|
||||
|
|
@ -143,7 +145,7 @@ impl State {
|
|||
|
||||
match event {
|
||||
InputEvent::DeviceAdded { device } => {
|
||||
let seat = &mut self.common.last_active_seat;
|
||||
let seat = &mut self.common.last_active_seat();
|
||||
let userdata = seat.user_data();
|
||||
let devices = userdata.get::<Devices>().unwrap();
|
||||
for cap in devices.add_device(&device) {
|
||||
|
|
@ -159,7 +161,7 @@ impl State {
|
|||
}
|
||||
}
|
||||
InputEvent::DeviceRemoved { device } => {
|
||||
for seat in &mut self.common.seats {
|
||||
for seat in &mut self.common.seats() {
|
||||
let userdata = seat.user_data();
|
||||
let devices = userdata.get::<Devices>().unwrap();
|
||||
if devices.has_device(&device) {
|
||||
|
|
@ -182,16 +184,17 @@ impl State {
|
|||
use smithay::backend::input::KeyboardKeyEvent;
|
||||
|
||||
let device = event.device();
|
||||
for seat in self.common.seats.clone().iter() {
|
||||
let current_output = active_output(seat, &self.common);
|
||||
for seat in self.common.seats().cloned().collect::<Vec<_>>().iter() {
|
||||
let current_output = seat.active_output();
|
||||
let workspace = self.common.shell.active_space_mut(¤t_output);
|
||||
let shortcuts_inhibited = workspace
|
||||
.focus_stack(seat)
|
||||
.focus_stack
|
||||
.get(seat)
|
||||
.last()
|
||||
.and_then(|window| {
|
||||
seat.keyboard_shortcuts_inhibitor_for_surface(
|
||||
&window.toplevel().wl_surface(),
|
||||
)
|
||||
window.wl_surface().and_then(|surface| {
|
||||
seat.keyboard_shortcuts_inhibitor_for_surface(&surface)
|
||||
})
|
||||
})
|
||||
.map(|inhibitor| inhibitor.is_active())
|
||||
.unwrap_or(false);
|
||||
|
|
@ -309,34 +312,31 @@ impl State {
|
|||
slog_scope::info!("Debug overlay not included in this version")
|
||||
}
|
||||
Action::Close => {
|
||||
let current_output = active_output(seat, &self.common);
|
||||
let current_output = seat.active_output();
|
||||
let workspace =
|
||||
self.common.shell.active_space_mut(¤t_output);
|
||||
if let Some(window) = workspace.focus_stack(seat).last() {
|
||||
#[allow(irrefutable_let_patterns)]
|
||||
if let Kind::Xdg(xdg) = &window.toplevel() {
|
||||
xdg.send_close();
|
||||
}
|
||||
if let Some(window) = workspace.focus_stack.get(seat).last() {
|
||||
window.send_close();
|
||||
}
|
||||
}
|
||||
Action::Workspace(key_num) => {
|
||||
let current_output = active_output(seat, &self.common);
|
||||
let current_output = seat.active_output();
|
||||
let workspace = match key_num {
|
||||
0 => 9,
|
||||
x => x - 1,
|
||||
};
|
||||
if let Some(motion_event) = self.common.shell.activate(
|
||||
seat,
|
||||
¤t_output,
|
||||
workspace as usize,
|
||||
) {
|
||||
if let Some(motion_event) = self
|
||||
.common
|
||||
.shell
|
||||
.activate(¤t_output, workspace as usize)
|
||||
{
|
||||
if let Some(ptr) = seat.get_pointer() {
|
||||
ptr.motion(self, None, &motion_event);
|
||||
}
|
||||
}
|
||||
}
|
||||
Action::MoveToWorkspace(key_num) => {
|
||||
let current_output = active_output(seat, &self.common);
|
||||
let current_output = seat.active_output();
|
||||
let workspace = match key_num {
|
||||
0 => 9,
|
||||
x => x - 1,
|
||||
|
|
@ -348,52 +348,47 @@ impl State {
|
|||
);
|
||||
}
|
||||
Action::Focus(focus) => {
|
||||
let current_output = active_output(seat, &self.common);
|
||||
let current_output = seat.active_output();
|
||||
let workspace =
|
||||
self.common.shell.active_space_mut(¤t_output);
|
||||
let focus_stack = workspace.focus_stack(seat);
|
||||
if let Some(window) = workspace.tiling_layer.move_focus(
|
||||
let focus_stack = workspace.focus_stack.get(seat);
|
||||
if let Some(target) = workspace.tiling_layer.next_focus(
|
||||
focus,
|
||||
seat,
|
||||
&mut workspace.space,
|
||||
focus_stack.iter(),
|
||||
) {
|
||||
std::mem::drop(focus_stack);
|
||||
Common::set_focus(
|
||||
self,
|
||||
Some(window.toplevel().wl_surface()),
|
||||
seat,
|
||||
None,
|
||||
);
|
||||
Common::set_focus(self, Some(&target), seat, None);
|
||||
}
|
||||
}
|
||||
Action::Fullscreen => {
|
||||
let current_output = active_output(seat, &self.common);
|
||||
let current_output = seat.active_output();
|
||||
let workspace =
|
||||
self.common.shell.active_space_mut(¤t_output);
|
||||
let focused_window = workspace.focus_stack(seat).last();
|
||||
if let Some(window) = focused_window {
|
||||
let focus_stack = workspace.focus_stack.get(seat);
|
||||
let focused_window = focus_stack.last();
|
||||
if let Some(window) = focused_window.map(|f| f.active_window())
|
||||
{
|
||||
workspace.fullscreen_toggle(&window, ¤t_output);
|
||||
}
|
||||
}
|
||||
Action::Orientation(orientation) => {
|
||||
let output = active_output(seat, &self.common);
|
||||
let output = seat.active_output();
|
||||
let workspace = self.common.shell.active_space_mut(&output);
|
||||
let focus_stack = workspace.focus_stack(seat);
|
||||
let focus_stack = workspace.focus_stack.get(seat);
|
||||
workspace.tiling_layer.update_orientation(
|
||||
orientation,
|
||||
&seat,
|
||||
&mut workspace.space,
|
||||
focus_stack.iter(),
|
||||
);
|
||||
}
|
||||
Action::ToggleTiling => {
|
||||
let output = active_output(seat, &self.common);
|
||||
let output = seat.active_output();
|
||||
let workspace = self.common.shell.active_space_mut(&output);
|
||||
workspace.toggle_tiling(seat);
|
||||
}
|
||||
Action::ToggleWindowFloating => {
|
||||
let output = active_output(seat, &self.common);
|
||||
let output = seat.active_output();
|
||||
let workspace = self.common.shell.active_space_mut(&output);
|
||||
workspace.toggle_floating_window(seat);
|
||||
}
|
||||
|
|
@ -407,80 +402,81 @@ impl State {
|
|||
{
|
||||
slog_scope::warn!("Failed to spawn: {}", err);
|
||||
}
|
||||
}
|
||||
Action::Screenshot => {
|
||||
let home = match std::env::var("HOME") {
|
||||
Ok(home) => home,
|
||||
Err(err) => {
|
||||
slog_scope::error!(
|
||||
"$HOME is not set, can't save screenshots: {}",
|
||||
err
|
||||
);
|
||||
break;
|
||||
}
|
||||
};
|
||||
let timestamp = match std::time::SystemTime::UNIX_EPOCH
|
||||
.elapsed()
|
||||
{
|
||||
Ok(duration) => duration.as_secs(),
|
||||
Err(err) => {
|
||||
slog_scope::error!("Unable to get timestamp, can't save screenshots: {}", err);
|
||||
break;
|
||||
}
|
||||
};
|
||||
for output in self.common.shell.outputs.clone().into_iter() {
|
||||
match self
|
||||
.backend
|
||||
.offscreen_for_output(&output, &mut self.common)
|
||||
{
|
||||
Ok((buffer, size)) => {
|
||||
let mut path = std::path::PathBuf::new();
|
||||
path.push(&home);
|
||||
path.push(format!(
|
||||
"{}_{}.png",
|
||||
output.name(),
|
||||
timestamp
|
||||
));
|
||||
} /*
|
||||
Action::Screenshot => {
|
||||
let home = match std::env::var("HOME") {
|
||||
Ok(home) => home,
|
||||
Err(err) => {
|
||||
slog_scope::error!(
|
||||
"$HOME is not set, can't save screenshots: {}",
|
||||
err
|
||||
);
|
||||
break;
|
||||
}
|
||||
};
|
||||
let timestamp = match std::time::SystemTime::UNIX_EPOCH
|
||||
.elapsed()
|
||||
{
|
||||
Ok(duration) => duration.as_secs(),
|
||||
Err(err) => {
|
||||
slog_scope::error!("Unable to get timestamp, can't save screenshots: {}", err);
|
||||
break;
|
||||
}
|
||||
};
|
||||
for output in self.common.shell.outputs.clone().into_iter() {
|
||||
match self
|
||||
.backend
|
||||
.offscreen_for_output(&output, &mut self.common)
|
||||
{
|
||||
Ok((buffer, size)) => {
|
||||
let mut path = std::path::PathBuf::new();
|
||||
path.push(&home);
|
||||
path.push(format!(
|
||||
"{}_{}.png",
|
||||
output.name(),
|
||||
timestamp
|
||||
));
|
||||
|
||||
fn write_png(
|
||||
path: impl AsRef<std::path::Path>,
|
||||
data: Vec<u8>,
|
||||
size: Size<i32, Buffer>,
|
||||
) -> anyhow::Result<()>
|
||||
{
|
||||
use std::{fs, io};
|
||||
fn write_png(
|
||||
path: impl AsRef<std::path::Path>,
|
||||
data: Vec<u8>,
|
||||
size: Size<i32, Buffer>,
|
||||
) -> anyhow::Result<()>
|
||||
{
|
||||
use std::{fs, io};
|
||||
|
||||
let file = io::BufWriter::new(
|
||||
fs::File::create(&path)?,
|
||||
);
|
||||
let mut encoder = png::Encoder::new(
|
||||
file,
|
||||
size.w as u32,
|
||||
size.h as u32,
|
||||
);
|
||||
encoder.set_color(png::ColorType::Rgba);
|
||||
encoder.set_depth(png::BitDepth::Eight);
|
||||
let mut writer = encoder.write_header()?;
|
||||
writer.write_image_data(&data)?;
|
||||
Ok(())
|
||||
}
|
||||
let file = io::BufWriter::new(
|
||||
fs::File::create(&path)?,
|
||||
);
|
||||
let mut encoder = png::Encoder::new(
|
||||
file,
|
||||
size.w as u32,
|
||||
size.h as u32,
|
||||
);
|
||||
encoder.set_color(png::ColorType::Rgba);
|
||||
encoder.set_depth(png::BitDepth::Eight);
|
||||
let mut writer = encoder.write_header()?;
|
||||
writer.write_image_data(&data)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
if let Err(err) = write_png(&path, buffer, size) {
|
||||
slog_scope::error!(
|
||||
"Unable to save screenshot at {}: {}",
|
||||
path.display(),
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
Err(err) => slog_scope::error!(
|
||||
"Could not save screenshot for output {}: {}",
|
||||
output.name(),
|
||||
err
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Err(err) = write_png(&path, buffer, size) {
|
||||
slog_scope::error!(
|
||||
"Unable to save screenshot at {}: {}",
|
||||
path.display(),
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
Err(err) => slog_scope::error!(
|
||||
"Could not save screenshot for output {}: {}",
|
||||
output.name(),
|
||||
err
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -491,11 +487,11 @@ impl State {
|
|||
use smithay::backend::input::PointerMotionEvent;
|
||||
|
||||
let device = event.device();
|
||||
for seat in self.common.seats.clone().iter() {
|
||||
for seat in self.common.seats().cloned().collect::<Vec<_>>().iter() {
|
||||
let userdata = seat.user_data();
|
||||
let devices = userdata.get::<Devices>().unwrap();
|
||||
if devices.has_device(&device) {
|
||||
let current_output = active_output(seat, &self.common);
|
||||
let current_output = seat.active_output();
|
||||
|
||||
let mut position = seat.get_pointer().unwrap().current_location();
|
||||
position += event.delta();
|
||||
|
|
@ -508,7 +504,7 @@ impl State {
|
|||
.cloned()
|
||||
.unwrap_or(current_output.clone());
|
||||
if output != current_output {
|
||||
set_active_output(seat, &output);
|
||||
seat.set_active_output(&output);
|
||||
}
|
||||
let output_geometry = output.geometry();
|
||||
|
||||
|
|
@ -520,10 +516,7 @@ impl State {
|
|||
.min((output_geometry.loc.y + output_geometry.size.h) as f64);
|
||||
|
||||
let serial = SERIAL_COUNTER.next_serial();
|
||||
let relative_pos = self
|
||||
.common
|
||||
.shell
|
||||
.space_relative_output_geometry(position, &output);
|
||||
let relative_pos = self.common.shell.map_global_to_space(position, &output);
|
||||
let workspace = self.common.shell.active_space_mut(&output);
|
||||
let under = State::surface_under(
|
||||
position,
|
||||
|
|
@ -559,18 +552,15 @@ impl State {
|
|||
}
|
||||
InputEvent::PointerMotionAbsolute { event, .. } => {
|
||||
let device = event.device();
|
||||
for seat in self.common.seats.clone().iter() {
|
||||
for seat in self.common.seats().cloned().collect::<Vec<_>>().iter() {
|
||||
let userdata = seat.user_data();
|
||||
let devices = userdata.get::<Devices>().unwrap();
|
||||
if devices.has_device(&device) {
|
||||
let output = active_output(seat, &self.common);
|
||||
let output = seat.active_output();
|
||||
let geometry = output.geometry();
|
||||
let position =
|
||||
geometry.loc.to_f64() + event.position_transformed(geometry.size);
|
||||
let relative_pos = self
|
||||
.common
|
||||
.shell
|
||||
.space_relative_output_geometry(position, &output);
|
||||
let relative_pos = self.common.shell.map_global_to_space(position, &output);
|
||||
let workspace = self.common.shell.active_space_mut(&output);
|
||||
let serial = SERIAL_COUNTER.next_serial();
|
||||
let under = State::surface_under(
|
||||
|
|
@ -609,7 +599,7 @@ impl State {
|
|||
use smithay::backend::input::{ButtonState, PointerButtonEvent};
|
||||
|
||||
let device = event.device();
|
||||
for seat in self.common.seats.clone().iter() {
|
||||
for seat in self.common.seats().cloned().collect::<Vec<_>>().iter() {
|
||||
let userdata = seat.user_data();
|
||||
let devices = userdata.get::<Devices>().unwrap();
|
||||
if devices.has_device(&device) {
|
||||
|
|
@ -649,13 +639,10 @@ impl State {
|
|||
if !seat.get_pointer().unwrap().is_grabbed()
|
||||
&& !seat.get_keyboard().map(|k| k.is_grabbed()).unwrap_or(false)
|
||||
{
|
||||
let output = active_output(seat, &self.common);
|
||||
let output = seat.active_output();
|
||||
let pos = seat.get_pointer().unwrap().current_location();
|
||||
let output_geo = output.geometry();
|
||||
let relative_pos = self
|
||||
.common
|
||||
.shell
|
||||
.space_relative_output_geometry(pos, &output);
|
||||
let relative_pos =
|
||||
self.common.shell.map_global_to_space(pos, &output);
|
||||
let workspace = self.common.shell.active_space_mut(&output);
|
||||
let layers = layer_map_for_output(&output);
|
||||
let mut under = None;
|
||||
|
|
@ -665,23 +652,10 @@ impl State {
|
|||
layers.layer_under(WlrLayer::Overlay, relative_pos)
|
||||
{
|
||||
if layer.can_receive_keyboard_focus() {
|
||||
let layer_loc =
|
||||
layers.layer_geometry(layer).unwrap().loc;
|
||||
under = layer
|
||||
.surface_under(
|
||||
pos - output_geo.loc.to_f64()
|
||||
- layer_loc.to_f64(),
|
||||
WindowSurfaceType::ALL,
|
||||
)
|
||||
.map(|(_, _)| layer.wl_surface().clone());
|
||||
under = Some(layer.clone().into());
|
||||
}
|
||||
} else {
|
||||
under = window
|
||||
.surface_under(
|
||||
pos - output_geo.loc.to_f64(),
|
||||
WindowSurfaceType::ALL,
|
||||
)
|
||||
.map(|(_, _)| window.toplevel().wl_surface().clone());
|
||||
under = Some(window.clone().into());
|
||||
}
|
||||
} else {
|
||||
if let Some(layer) = layers
|
||||
|
|
@ -689,35 +663,18 @@ impl State {
|
|||
.or_else(|| layers.layer_under(WlrLayer::Top, relative_pos))
|
||||
{
|
||||
if layer.can_receive_keyboard_focus() {
|
||||
let layer_loc =
|
||||
layers.layer_geometry(layer).unwrap().loc;
|
||||
under = layer
|
||||
.surface_under(
|
||||
pos - output_geo.loc.to_f64()
|
||||
- layer_loc.to_f64(),
|
||||
WindowSurfaceType::ALL,
|
||||
)
|
||||
.map(|(_, _)| layer.wl_surface().clone());
|
||||
under = Some(layer.clone().into());
|
||||
}
|
||||
} else if let Some((window, _, _)) = workspace
|
||||
.space
|
||||
.surface_under(relative_pos, WindowSurfaceType::ALL)
|
||||
} else if let Some((window, _)) =
|
||||
workspace.element_under(relative_pos)
|
||||
{
|
||||
under = Some(window.toplevel().wl_surface().clone());
|
||||
under = Some(window.clone().into());
|
||||
} else if let Some(layer) = layers
|
||||
.layer_under(WlrLayer::Bottom, pos)
|
||||
.or_else(|| layers.layer_under(WlrLayer::Background, pos))
|
||||
{
|
||||
if layer.can_receive_keyboard_focus() {
|
||||
let layer_loc =
|
||||
layers.layer_geometry(layer).unwrap().loc;
|
||||
under = layer
|
||||
.surface_under(
|
||||
pos - output_geo.loc.to_f64()
|
||||
- layer_loc.to_f64(),
|
||||
WindowSurfaceType::ALL,
|
||||
)
|
||||
.map(|(_, _)| layer.wl_surface().clone());
|
||||
under = Some(layer.clone().into());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -740,7 +697,7 @@ impl State {
|
|||
}
|
||||
InputEvent::PointerAxis { event, .. } => {
|
||||
let device = event.device();
|
||||
for seat in self.common.seats.clone().iter() {
|
||||
for seat in self.common.seats().cloned().collect::<Vec<_>>().iter() {
|
||||
#[cfg(feature = "debug")]
|
||||
if self.common.seats.iter().position(|x| x == seat).unwrap() == 0
|
||||
&& self.common.egui.active
|
||||
|
|
@ -820,7 +777,7 @@ impl State {
|
|||
output: &Output,
|
||||
output_geo: Rectangle<i32, Logical>,
|
||||
workspace: &Workspace,
|
||||
) -> Option<(WlSurface, Point<i32, Logical>)> {
|
||||
) -> Option<(PointerFocusTarget, Point<i32, Logical>)> {
|
||||
let layers = layer_map_for_output(output);
|
||||
if let Some(window) = workspace.get_fullscreen(output) {
|
||||
if let Some(layer) = layers
|
||||
|
|
@ -828,16 +785,9 @@ impl State {
|
|||
.or_else(|| layers.layer_under(WlrLayer::Top, relative_pos))
|
||||
{
|
||||
let layer_loc = layers.layer_geometry(layer).unwrap().loc;
|
||||
layer
|
||||
.surface_under(
|
||||
global_pos - output_geo.loc.to_f64() - layer_loc.to_f64(),
|
||||
WindowSurfaceType::ALL,
|
||||
)
|
||||
.map(|(s, loc)| (s, loc + layer_loc + output_geo.loc))
|
||||
Some((layer.clone().into(), output_geo.loc + layer_loc))
|
||||
} else {
|
||||
window
|
||||
.surface_under(global_pos - output_geo.loc.to_f64(), WindowSurfaceType::ALL)
|
||||
.map(|(s, loc)| (s, loc + output_geo.loc))
|
||||
Some((window.clone().into(), output_geo.loc))
|
||||
}
|
||||
} else {
|
||||
if let Some(layer) = layers
|
||||
|
|
@ -845,28 +795,18 @@ impl State {
|
|||
.or_else(|| layers.layer_under(WlrLayer::Top, relative_pos))
|
||||
{
|
||||
let layer_loc = layers.layer_geometry(layer).unwrap().loc;
|
||||
layer
|
||||
.surface_under(
|
||||
global_pos - output_geo.loc.to_f64() - layer_loc.to_f64(),
|
||||
WindowSurfaceType::ALL,
|
||||
)
|
||||
.map(|(s, loc)| (s, loc + layer_loc + output_geo.loc))
|
||||
} else if let Some((_, surface, loc)) = workspace
|
||||
.space
|
||||
.surface_under(relative_pos, WindowSurfaceType::ALL)
|
||||
{
|
||||
Some((surface, loc + (global_pos - relative_pos).to_i32_round()))
|
||||
Some((layer.clone().into(), output_geo.loc + layer_loc))
|
||||
} else if let Some((mapped, loc)) = workspace.element_under(relative_pos) {
|
||||
Some((
|
||||
mapped.clone().into(),
|
||||
loc + (global_pos - relative_pos).to_i32_round(),
|
||||
))
|
||||
} else if let Some(layer) = layers
|
||||
.layer_under(WlrLayer::Bottom, relative_pos)
|
||||
.or_else(|| layers.layer_under(WlrLayer::Background, relative_pos))
|
||||
{
|
||||
let layer_loc = layers.layer_geometry(layer).unwrap().loc;
|
||||
layer
|
||||
.surface_under(
|
||||
global_pos - output_geo.loc.to_f64() - layer_loc.to_f64(),
|
||||
WindowSurfaceType::ALL,
|
||||
)
|
||||
.map(|(s, loc)| (s, loc + layer_loc + output_geo.loc))
|
||||
Some((layer.clone().into(), output_geo.loc + layer_loc))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ fn main() -> Result<()> {
|
|||
}
|
||||
|
||||
// trigger routines
|
||||
data.state.common.shell.refresh(&data.display.handle());
|
||||
data.state.common.shell.refresh();
|
||||
state::Common::refresh_focus(&mut data.state);
|
||||
|
||||
// do we need to trigger another render
|
||||
|
|
|
|||
631
src/shell/element/mod.rs
Normal file
631
src/shell/element/mod.rs
Normal file
|
|
@ -0,0 +1,631 @@
|
|||
use crate::state::State;
|
||||
use id_tree::NodeId;
|
||||
use smithay::{
|
||||
backend::{
|
||||
input::KeyState,
|
||||
renderer::{element::AsRenderElements, ImportAll, Renderer},
|
||||
},
|
||||
desktop::{space::SpaceElement, Kind, PopupManager, Window, WindowSurfaceType},
|
||||
input::{
|
||||
keyboard::{KeyboardTarget, KeysymHandle, ModifiersState},
|
||||
pointer::{AxisFrame, ButtonEvent, MotionEvent, PointerTarget},
|
||||
Seat,
|
||||
},
|
||||
output::Output,
|
||||
reexports::{
|
||||
wayland_protocols::xdg::shell::server::xdg_toplevel::State as XdgState,
|
||||
wayland_server::{backend::ObjectId, protocol::wl_surface::WlSurface},
|
||||
},
|
||||
render_elements, space_elements,
|
||||
utils::{IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size},
|
||||
wayland::{
|
||||
compositor::{with_states, with_surface_tree_downward, TraversalAction},
|
||||
seat::WaylandFocus,
|
||||
shell::xdg::XdgToplevelSurfaceRoleAttributes,
|
||||
},
|
||||
};
|
||||
use std::{
|
||||
hash::Hash,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
pub mod stack;
|
||||
pub use self::stack::CosmicStack;
|
||||
pub mod window;
|
||||
pub use self::window::CosmicWindow;
|
||||
|
||||
use super::focus::FocusDirection;
|
||||
|
||||
space_elements! {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
CosmicMappedInternal;
|
||||
Window=CosmicWindow,
|
||||
Stack=CosmicStack,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CosmicMapped {
|
||||
element: CosmicMappedInternal,
|
||||
|
||||
// associated data
|
||||
|
||||
//tiling
|
||||
pub(super) tiling_node_id: Arc<Mutex<Option<NodeId>>>,
|
||||
//floating
|
||||
pub(super) last_geometry: Arc<Mutex<Option<Rectangle<i32, Logical>>>>,
|
||||
}
|
||||
|
||||
impl PartialEq for CosmicMapped {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.element == other.element
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for CosmicMapped {}
|
||||
|
||||
impl Hash for CosmicMapped {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.element.hash(state)
|
||||
}
|
||||
}
|
||||
|
||||
impl CosmicMapped {
|
||||
pub fn windows(&self) -> impl Iterator<Item = (Window, Point<i32, Logical>)> + '_ {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(stack) => Box::new(stack.windows().map(|w| {
|
||||
(
|
||||
w,
|
||||
stack
|
||||
.header
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.map(|header| Point::from((0, header.height() as i32)))
|
||||
.unwrap_or(Point::from((0, 0))),
|
||||
)
|
||||
}))
|
||||
as Box<dyn Iterator<Item = (Window, Point<i32, Logical>)>>,
|
||||
CosmicMappedInternal::Window(window) => Box::new(std::iter::once((
|
||||
window.window.clone(),
|
||||
window
|
||||
.header
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.map(|header| Point::from((0, header.height() as i32)))
|
||||
.unwrap_or(Point::from((0, 0))),
|
||||
))),
|
||||
_ => Box::new(std::iter::empty()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn active_window(&self) -> Window {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(stack) => stack.active(),
|
||||
CosmicMappedInternal::Window(win) => win.window.clone(),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn focus_window(&self, window: &Window) {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(stack) => stack.set_active(window),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_surface(&self, surface: &WlSurface, surface_type: WindowSurfaceType) -> bool {
|
||||
self.windows().any(|(w, _)| {
|
||||
let toplevel = w.toplevel().wl_surface();
|
||||
|
||||
if surface_type.contains(WindowSurfaceType::TOPLEVEL) {
|
||||
if toplevel == surface {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if surface_type.contains(WindowSurfaceType::SUBSURFACE) {
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
let found = AtomicBool::new(false);
|
||||
with_surface_tree_downward(
|
||||
toplevel,
|
||||
surface,
|
||||
|_, _, search| TraversalAction::DoChildren(search),
|
||||
|s, _, search| {
|
||||
found.fetch_or(s == *search, Ordering::SeqCst);
|
||||
},
|
||||
|_, _, _| !found.load(Ordering::SeqCst),
|
||||
);
|
||||
if found.load(Ordering::SeqCst) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if surface_type.contains(WindowSurfaceType::POPUP) {
|
||||
PopupManager::popups_for_surface(toplevel).any(|(p, _)| p.wl_surface() == surface)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn handle_focus(&self, direction: FocusDirection) -> bool {
|
||||
if let CosmicMappedInternal::Stack(stack) = &self.element {
|
||||
//TODO: stack.handle_focus(direction)
|
||||
false
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_tiled(&self, tiled: bool) {
|
||||
for toplevel in match &self.element {
|
||||
// we use the tiled state of stack windows anyway to get rid of decorations
|
||||
CosmicMappedInternal::Stack(s) => None,
|
||||
CosmicMappedInternal::Window(w) => Some(w.window.toplevel()),
|
||||
_ => unreachable!(),
|
||||
} {
|
||||
match toplevel {
|
||||
Kind::Xdg(xdg) => xdg.with_pending_state(|state| {
|
||||
if tiled {
|
||||
state.states.set(XdgState::TiledLeft);
|
||||
state.states.set(XdgState::TiledRight);
|
||||
state.states.set(XdgState::TiledTop);
|
||||
state.states.set(XdgState::TiledBottom);
|
||||
} else {
|
||||
state.states.unset(XdgState::TiledLeft);
|
||||
state.states.unset(XdgState::TiledRight);
|
||||
state.states.unset(XdgState::TiledTop);
|
||||
state.states.unset(XdgState::TiledBottom);
|
||||
}
|
||||
}),
|
||||
// Kind::X11?
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_tiled(&self) -> bool {
|
||||
let window = match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => s.active(),
|
||||
CosmicMappedInternal::Window(w) => w.window.clone(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
match window.toplevel() {
|
||||
Kind::Xdg(xdg) => xdg.current_state().states.contains(XdgState::TiledLeft),
|
||||
// Kind::X11?
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_fullscreen(&self, fullscreen: bool) {
|
||||
for window in match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => {
|
||||
Box::new(s.windows()) as Box<dyn Iterator<Item = Window>>
|
||||
}
|
||||
CosmicMappedInternal::Window(w) => Box::new(std::iter::once(w.window.clone())),
|
||||
_ => unreachable!(),
|
||||
} {
|
||||
match window.toplevel() {
|
||||
Kind::Xdg(xdg) => xdg.with_pending_state(|state| {
|
||||
if fullscreen {
|
||||
state.states.set(XdgState::Fullscreen);
|
||||
} else {
|
||||
state.states.unset(XdgState::Fullscreen);
|
||||
}
|
||||
}),
|
||||
// Kind::X11?
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_fullscreen(&self) -> bool {
|
||||
let window = match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => s.active(),
|
||||
CosmicMappedInternal::Window(w) => w.window.clone(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
match window.toplevel() {
|
||||
Kind::Xdg(xdg) => xdg.current_state().states.contains(XdgState::Fullscreen),
|
||||
// Kind::X11?
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_maximized(&self, maximized: bool) {
|
||||
for window in match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => {
|
||||
Box::new(s.windows()) as Box<dyn Iterator<Item = Window>>
|
||||
}
|
||||
CosmicMappedInternal::Window(w) => Box::new(std::iter::once(w.window.clone())),
|
||||
_ => unreachable!(),
|
||||
} {
|
||||
match window.toplevel() {
|
||||
Kind::Xdg(xdg) => xdg.with_pending_state(|state| {
|
||||
if maximized {
|
||||
state.states.set(XdgState::Maximized);
|
||||
} else {
|
||||
state.states.unset(XdgState::Maximized);
|
||||
}
|
||||
}),
|
||||
// Kind::X11?
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_maximized(&self) -> bool {
|
||||
let window = match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => s.active(),
|
||||
CosmicMappedInternal::Window(w) => w.window.clone(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
match window.toplevel() {
|
||||
Kind::Xdg(xdg) => xdg.current_state().states.contains(XdgState::Maximized),
|
||||
// Kind::X11?
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_activated(&self, activated: bool) {
|
||||
for window in match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => {
|
||||
Box::new(s.windows()) as Box<dyn Iterator<Item = Window>>
|
||||
}
|
||||
CosmicMappedInternal::Window(w) => Box::new(std::iter::once(w.window.clone())),
|
||||
_ => unreachable!(),
|
||||
} {
|
||||
match window.toplevel() {
|
||||
Kind::Xdg(xdg) => xdg.with_pending_state(|state| {
|
||||
if activated {
|
||||
state.states.set(XdgState::Activated);
|
||||
} else {
|
||||
state.states.unset(XdgState::Activated);
|
||||
}
|
||||
}),
|
||||
// Kind::X11?
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_activated(&self) -> bool {
|
||||
let window = match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => s.active(),
|
||||
CosmicMappedInternal::Window(w) => w.window.clone(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
match window.toplevel() {
|
||||
Kind::Xdg(xdg) => xdg.current_state().states.contains(XdgState::Activated),
|
||||
// Kind::X11?
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_size(&self, size: Size<i32, Logical>) {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => s.set_size(size),
|
||||
CosmicMappedInternal::Window(w) => w.set_size(size),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn min_size(&self) -> Size<i32, Logical> {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(stack) => stack
|
||||
.windows()
|
||||
.fold(None, |min_size, window| {
|
||||
let win_min_size = with_states(window.toplevel().wl_surface(), |states| {
|
||||
let attrs = states
|
||||
.data_map
|
||||
.get::<Mutex<XdgToplevelSurfaceRoleAttributes>>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap();
|
||||
attrs.min_size
|
||||
});
|
||||
match (min_size, win_min_size) {
|
||||
(None, x) => Some(x),
|
||||
(Some(min1), min2) => Some((min1.w.max(min2.w), min1.h.max(min2.h)).into()),
|
||||
}
|
||||
})
|
||||
.expect("Empty stack?"),
|
||||
CosmicMappedInternal::Window(window) => {
|
||||
with_states(window.window.toplevel().wl_surface(), |states| {
|
||||
let attrs = states
|
||||
.data_map
|
||||
.get::<Mutex<XdgToplevelSurfaceRoleAttributes>>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap();
|
||||
attrs.min_size
|
||||
})
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max_size(&self) -> Size<i32, Logical> {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(stack) => {
|
||||
let theoretical_max = stack.windows().fold(None, |max_size, window| {
|
||||
let win_max_size = with_states(window.toplevel().wl_surface(), |states| {
|
||||
let attrs = states
|
||||
.data_map
|
||||
.get::<Mutex<XdgToplevelSurfaceRoleAttributes>>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap();
|
||||
attrs.max_size
|
||||
});
|
||||
match (max_size, win_max_size) {
|
||||
(None, x) => Some(x),
|
||||
(Some(max1), max2) => Some(
|
||||
(
|
||||
if max1.w == 0 {
|
||||
max2.w
|
||||
} else if max2.w == 0 {
|
||||
max1.w
|
||||
} else {
|
||||
max1.w.min(max2.w)
|
||||
},
|
||||
if max1.h == 0 {
|
||||
max2.h
|
||||
} else if max2.h == 0 {
|
||||
max1.h
|
||||
} else {
|
||||
max1.h.min(max2.h)
|
||||
},
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
}
|
||||
});
|
||||
// The problem is, with accumulated sizes, the minimum size could be larger than our maximum...
|
||||
let min_size = self.min_size();
|
||||
match (theoretical_max, min_size) {
|
||||
(None, _) => (0, 0).into(),
|
||||
(Some(max), min) => (max.w.max(min.w), max.h.max(min.h)).into(),
|
||||
}
|
||||
}
|
||||
CosmicMappedInternal::Window(window) => {
|
||||
with_states(window.window.toplevel().wl_surface(), |states| {
|
||||
let attrs = states
|
||||
.data_map
|
||||
.get::<Mutex<XdgToplevelSurfaceRoleAttributes>>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap();
|
||||
attrs.max_size
|
||||
})
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn configure(&self) {
|
||||
for window in match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => {
|
||||
Box::new(s.windows()) as Box<dyn Iterator<Item = Window>>
|
||||
}
|
||||
CosmicMappedInternal::Window(w) => Box::new(std::iter::once(w.window.clone())),
|
||||
_ => unreachable!(),
|
||||
} {
|
||||
match window.toplevel() {
|
||||
Kind::Xdg(xdg) => xdg.send_configure(),
|
||||
// Kind::X11?
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_close(&self) {
|
||||
let window = match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => s.active(),
|
||||
CosmicMappedInternal::Window(w) => w.window.clone(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
match window.toplevel() {
|
||||
Kind::Xdg(xdg) => xdg.send_close(),
|
||||
// Kind::X11?
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl IsAlive for CosmicMapped {
|
||||
fn alive(&self) -> bool {
|
||||
self.element.alive()
|
||||
}
|
||||
}
|
||||
|
||||
impl SpaceElement for CosmicMapped {
|
||||
fn bbox(&self) -> Rectangle<i32, Logical> {
|
||||
SpaceElement::bbox(&self.element)
|
||||
}
|
||||
fn is_in_input_region(&self, point: &Point<f64, Logical>) -> bool {
|
||||
SpaceElement::is_in_input_region(&self.element, point)
|
||||
}
|
||||
fn set_activate(&self, activated: bool) {
|
||||
SpaceElement::set_activate(&self.element, activated)
|
||||
}
|
||||
fn output_enter(&self, output: &Output, overlap: Rectangle<i32, Logical>) {
|
||||
SpaceElement::output_enter(&self.element, output, overlap)
|
||||
}
|
||||
fn output_leave(&self, output: &Output) {
|
||||
SpaceElement::output_leave(&self.element, output)
|
||||
}
|
||||
fn geometry(&self) -> Rectangle<i32, Logical> {
|
||||
SpaceElement::geometry(&self.element)
|
||||
}
|
||||
fn z_index(&self) -> u8 {
|
||||
SpaceElement::z_index(&self.element)
|
||||
}
|
||||
fn refresh(&self) {
|
||||
SpaceElement::refresh(&self.element)
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyboardTarget<State> for CosmicMapped {
|
||||
fn enter(
|
||||
&self,
|
||||
seat: &Seat<State>,
|
||||
data: &mut State,
|
||||
keys: Vec<KeysymHandle<'_>>,
|
||||
serial: Serial,
|
||||
) {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => KeyboardTarget::enter(s, seat, data, keys, serial),
|
||||
CosmicMappedInternal::Window(w) => KeyboardTarget::enter(w, seat, data, keys, serial),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial) {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => KeyboardTarget::leave(s, seat, data, serial),
|
||||
CosmicMappedInternal::Window(w) => KeyboardTarget::leave(w, seat, data, serial),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
fn key(
|
||||
&self,
|
||||
seat: &Seat<State>,
|
||||
data: &mut State,
|
||||
key: KeysymHandle<'_>,
|
||||
state: KeyState,
|
||||
serial: Serial,
|
||||
time: u32,
|
||||
) {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => {
|
||||
KeyboardTarget::key(s, seat, data, key, state, serial, time)
|
||||
}
|
||||
CosmicMappedInternal::Window(w) => {
|
||||
KeyboardTarget::key(w, seat, data, key, state, serial, time)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
fn modifiers(
|
||||
&self,
|
||||
seat: &Seat<State>,
|
||||
data: &mut State,
|
||||
modifiers: ModifiersState,
|
||||
serial: Serial,
|
||||
) {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => {
|
||||
KeyboardTarget::modifiers(s, seat, data, modifiers, serial)
|
||||
}
|
||||
CosmicMappedInternal::Window(w) => {
|
||||
KeyboardTarget::modifiers(w, seat, data, modifiers, serial)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PointerTarget<State> for CosmicMapped {
|
||||
fn enter(&self, seat: &Seat<State>, data: &mut State, event: &MotionEvent) {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => PointerTarget::enter(s, seat, data, event),
|
||||
CosmicMappedInternal::Window(w) => PointerTarget::enter(w, seat, data, event),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
fn motion(&self, seat: &Seat<State>, data: &mut State, event: &MotionEvent) {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => PointerTarget::motion(s, seat, data, event),
|
||||
CosmicMappedInternal::Window(w) => PointerTarget::motion(w, seat, data, event),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
fn button(&self, seat: &Seat<State>, data: &mut State, event: &ButtonEvent) {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => PointerTarget::button(s, seat, data, event),
|
||||
CosmicMappedInternal::Window(w) => PointerTarget::button(w, seat, data, event),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
fn axis(&self, seat: &Seat<State>, data: &mut State, frame: AxisFrame) {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => PointerTarget::axis(s, seat, data, frame),
|
||||
CosmicMappedInternal::Window(w) => PointerTarget::axis(w, seat, data, frame),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => PointerTarget::leave(s, seat, data, serial, time),
|
||||
CosmicMappedInternal::Window(w) => PointerTarget::leave(w, seat, data, serial, time),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WaylandFocus for CosmicMapped {
|
||||
fn wl_surface(&self) -> Option<WlSurface> {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Window(w) => w.window.wl_surface().clone(),
|
||||
CosmicMappedInternal::Stack(s) => s.active().wl_surface().clone(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn same_client_as(&self, object_id: &ObjectId) -> bool {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Window(w) => w.window.same_client_as(object_id),
|
||||
CosmicMappedInternal::Stack(s) => s.windows().any(|w| w.same_client_as(object_id)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CosmicWindow> for CosmicMapped {
|
||||
fn from(w: CosmicWindow) -> Self {
|
||||
CosmicMapped {
|
||||
element: CosmicMappedInternal::Window(w),
|
||||
tiling_node_id: Arc::new(Mutex::new(None)),
|
||||
last_geometry: Arc::new(Mutex::new(None)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CosmicStack> for CosmicMapped {
|
||||
fn from(s: CosmicStack) -> Self {
|
||||
CosmicMapped {
|
||||
element: CosmicMappedInternal::Stack(s),
|
||||
tiling_node_id: Arc::new(Mutex::new(None)),
|
||||
last_geometry: Arc::new(Mutex::new(None)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
render_elements! {
|
||||
pub CosmicMappedRenderElement<R> where R: ImportAll;
|
||||
Stack=self::stack::CosmicStackRenderElement<R>,
|
||||
Window=self::window::CosmicWindowRenderElement<R>,
|
||||
}
|
||||
|
||||
impl<R> AsRenderElements<R> for CosmicMapped
|
||||
where
|
||||
R: Renderer + ImportAll,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
{
|
||||
type RenderElement = CosmicMappedRenderElement<R>;
|
||||
fn render_elements<C: From<Self::RenderElement>>(
|
||||
&self,
|
||||
location: Point<i32, Physical>,
|
||||
scale: Scale<f64>,
|
||||
) -> Vec<C> {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Stack(s) => AsRenderElements::<R>::render_elements::<
|
||||
CosmicMappedRenderElement<R>,
|
||||
>(s, location, scale),
|
||||
CosmicMappedInternal::Window(w) => AsRenderElements::<R>::render_elements::<
|
||||
CosmicMappedRenderElement<R>,
|
||||
>(w, location, scale),
|
||||
_ => Vec::new(),
|
||||
}
|
||||
.into_iter()
|
||||
.map(C::from)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
293
src/shell/element/stack.rs
Normal file
293
src/shell/element/stack.rs
Normal file
|
|
@ -0,0 +1,293 @@
|
|||
use crate::state::State;
|
||||
use smithay::{
|
||||
backend::{
|
||||
input::KeyState,
|
||||
renderer::{
|
||||
element::{surface::WaylandSurfaceRenderElement, AsRenderElements},
|
||||
ImportAll, Renderer,
|
||||
},
|
||||
},
|
||||
desktop::{space::SpaceElement, Kind, Window},
|
||||
input::{
|
||||
keyboard::{KeyboardTarget, KeysymHandle, ModifiersState},
|
||||
pointer::{AxisFrame, ButtonEvent, MotionEvent, PointerTarget},
|
||||
Seat,
|
||||
},
|
||||
output::Output,
|
||||
render_elements,
|
||||
utils::{IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size},
|
||||
};
|
||||
use std::{
|
||||
hash::Hash,
|
||||
sync::{
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
Arc, Mutex,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CosmicStack {
|
||||
windows: Arc<Mutex<Vec<Window>>>,
|
||||
active: Arc<AtomicUsize>,
|
||||
pub(super) header: Arc<Mutex<Option<HeaderBar>>>,
|
||||
}
|
||||
|
||||
impl PartialEq for CosmicStack {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
*self.windows.lock().unwrap() == *other.windows.lock().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for CosmicStack {}
|
||||
|
||||
impl Hash for CosmicStack {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
Arc::as_ptr(&self.windows).hash(state)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct HeaderBar {}
|
||||
|
||||
impl HeaderBar {
|
||||
pub fn height(&self) -> i32 {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
impl CosmicStack {
|
||||
pub fn active(&self) -> Window {
|
||||
self.windows.lock().unwrap()[self.active.load(Ordering::SeqCst)].clone()
|
||||
}
|
||||
|
||||
pub fn set_active(&self, window: &Window) {
|
||||
if let Some(val) = self
|
||||
.windows
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.position(|w| w == window)
|
||||
{
|
||||
self.active.store(val, Ordering::SeqCst)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_size(&self, size: Size<i32, Logical>) {
|
||||
let surface_size = (
|
||||
size.w,
|
||||
size.h
|
||||
- self
|
||||
.header
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.map(|h| h.height())
|
||||
.unwrap_or(0),
|
||||
)
|
||||
.into();
|
||||
|
||||
for window in self.windows.lock().unwrap().iter() {
|
||||
match window.toplevel() {
|
||||
Kind::Xdg(xdg) => xdg.with_pending_state(|state| state.size = Some(surface_size)),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IsAlive for CosmicStack {
|
||||
fn alive(&self) -> bool {
|
||||
self.windows.lock().unwrap().iter().any(IsAlive::alive)
|
||||
}
|
||||
}
|
||||
|
||||
impl SpaceElement for CosmicStack {
|
||||
fn bbox(&self) -> Rectangle<i32, Logical> {
|
||||
SpaceElement::bbox(&self.windows.lock().unwrap()[self.active.load(Ordering::SeqCst)])
|
||||
}
|
||||
fn is_in_input_region(&self, point: &Point<f64, Logical>) -> bool {
|
||||
SpaceElement::is_in_input_region(
|
||||
&self.windows.lock().unwrap()[self.active.load(Ordering::SeqCst)],
|
||||
point,
|
||||
)
|
||||
}
|
||||
fn set_activate(&self, activated: bool) {
|
||||
self.windows
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.for_each(|w| SpaceElement::set_activate(w, activated))
|
||||
}
|
||||
fn output_enter(&self, output: &Output, overlap: Rectangle<i32, Logical>) {
|
||||
self.windows
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.for_each(|w| SpaceElement::output_enter(w, output, overlap))
|
||||
}
|
||||
fn output_leave(&self, output: &Output) {
|
||||
self.windows
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.for_each(|w| SpaceElement::output_leave(w, output))
|
||||
}
|
||||
fn geometry(&self) -> Rectangle<i32, Logical> {
|
||||
SpaceElement::geometry(&self.windows.lock().unwrap()[self.active.load(Ordering::SeqCst)])
|
||||
}
|
||||
fn z_index(&self) -> u8 {
|
||||
SpaceElement::z_index(&self.windows.lock().unwrap()[self.active.load(Ordering::SeqCst)])
|
||||
}
|
||||
fn refresh(&self) {
|
||||
let mut windows = self.windows.lock().unwrap();
|
||||
windows.retain(IsAlive::alive);
|
||||
let len = windows.len();
|
||||
let _ = self
|
||||
.active
|
||||
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |active| {
|
||||
(active > len).then_some(len - 1)
|
||||
});
|
||||
windows.iter().for_each(|w| SpaceElement::refresh(w))
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyboardTarget<State> for CosmicStack {
|
||||
fn enter(
|
||||
&self,
|
||||
seat: &Seat<State>,
|
||||
data: &mut State,
|
||||
keys: Vec<KeysymHandle<'_>>,
|
||||
serial: Serial,
|
||||
) {
|
||||
KeyboardTarget::enter(
|
||||
&self.windows.lock().unwrap()[self.active.load(Ordering::SeqCst)],
|
||||
seat,
|
||||
data,
|
||||
keys,
|
||||
serial,
|
||||
)
|
||||
}
|
||||
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial) {
|
||||
KeyboardTarget::leave(
|
||||
&self.windows.lock().unwrap()[self.active.load(Ordering::SeqCst)],
|
||||
seat,
|
||||
data,
|
||||
serial,
|
||||
)
|
||||
}
|
||||
fn key(
|
||||
&self,
|
||||
seat: &Seat<State>,
|
||||
data: &mut State,
|
||||
key: KeysymHandle<'_>,
|
||||
state: KeyState,
|
||||
serial: Serial,
|
||||
time: u32,
|
||||
) {
|
||||
KeyboardTarget::key(
|
||||
&self.windows.lock().unwrap()[self.active.load(Ordering::SeqCst)],
|
||||
seat,
|
||||
data,
|
||||
key,
|
||||
state,
|
||||
serial,
|
||||
time,
|
||||
)
|
||||
}
|
||||
fn modifiers(
|
||||
&self,
|
||||
seat: &Seat<State>,
|
||||
data: &mut State,
|
||||
modifiers: ModifiersState,
|
||||
serial: Serial,
|
||||
) {
|
||||
KeyboardTarget::modifiers(
|
||||
&self.windows.lock().unwrap()[self.active.load(Ordering::SeqCst)],
|
||||
seat,
|
||||
data,
|
||||
modifiers,
|
||||
serial,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl PointerTarget<State> for CosmicStack {
|
||||
fn enter(&self, seat: &Seat<State>, data: &mut State, event: &MotionEvent) {
|
||||
PointerTarget::enter(
|
||||
&self.windows.lock().unwrap()[self.active.load(Ordering::SeqCst)],
|
||||
seat,
|
||||
data,
|
||||
event,
|
||||
)
|
||||
}
|
||||
fn motion(&self, seat: &Seat<State>, data: &mut State, event: &MotionEvent) {
|
||||
PointerTarget::motion(
|
||||
&self.windows.lock().unwrap()[self.active.load(Ordering::SeqCst)],
|
||||
seat,
|
||||
data,
|
||||
event,
|
||||
)
|
||||
}
|
||||
fn button(&self, seat: &Seat<State>, data: &mut State, event: &ButtonEvent) {
|
||||
PointerTarget::button(
|
||||
&self.windows.lock().unwrap()[self.active.load(Ordering::SeqCst)],
|
||||
seat,
|
||||
data,
|
||||
event,
|
||||
)
|
||||
}
|
||||
fn axis(&self, seat: &Seat<State>, data: &mut State, frame: AxisFrame) {
|
||||
PointerTarget::axis(
|
||||
&self.windows.lock().unwrap()[self.active.load(Ordering::SeqCst)],
|
||||
seat,
|
||||
data,
|
||||
frame,
|
||||
)
|
||||
}
|
||||
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {
|
||||
PointerTarget::leave(
|
||||
&self.windows.lock().unwrap()[self.active.load(Ordering::SeqCst)],
|
||||
seat,
|
||||
data,
|
||||
serial,
|
||||
time,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
render_elements! {
|
||||
pub CosmicStackRenderElement<R> where R: ImportAll;
|
||||
Window=WaylandSurfaceRenderElement,
|
||||
}
|
||||
|
||||
impl<R> AsRenderElements<R> for CosmicStack
|
||||
where
|
||||
R: Renderer + ImportAll,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
{
|
||||
type RenderElement = CosmicStackRenderElement<R>;
|
||||
fn render_elements<C: From<Self::RenderElement>>(
|
||||
&self,
|
||||
location: Point<i32, Physical>,
|
||||
scale: Scale<f64>,
|
||||
) -> Vec<C> {
|
||||
AsRenderElements::<R>::render_elements::<CosmicStackRenderElement<R>>(
|
||||
&self.windows.lock().unwrap()[self.active.load(Ordering::SeqCst)],
|
||||
location,
|
||||
scale,
|
||||
)
|
||||
.into_iter()
|
||||
.map(C::from)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
impl CosmicStack {
|
||||
pub fn windows(&self) -> impl Iterator<Item = Window> {
|
||||
self.windows
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
231
src/shell/element/window.rs
Normal file
231
src/shell/element/window.rs
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
use crate::state::State;
|
||||
use smithay::{
|
||||
backend::{
|
||||
input::KeyState,
|
||||
renderer::{
|
||||
element::{surface::WaylandSurfaceRenderElement, AsRenderElements},
|
||||
ImportAll, Renderer,
|
||||
},
|
||||
},
|
||||
desktop::{space::SpaceElement, Kind, Window},
|
||||
input::{
|
||||
keyboard::{KeyboardTarget, KeysymHandle, ModifiersState},
|
||||
pointer::{AxisFrame, ButtonEvent, MotionEvent, PointerTarget},
|
||||
Seat,
|
||||
},
|
||||
output::Output,
|
||||
reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1::Mode as DecorationMode,
|
||||
render_elements,
|
||||
utils::{IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size},
|
||||
wayland::shell::xdg::ToplevelSurface,
|
||||
};
|
||||
use std::{
|
||||
hash::Hash,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CosmicWindow {
|
||||
pub(super) window: Window,
|
||||
pub(super) header: Arc<Mutex<Option<HeaderBar>>>,
|
||||
}
|
||||
|
||||
impl PartialEq<Window> for CosmicWindow {
|
||||
fn eq(&self, other: &Window) -> bool {
|
||||
&self.window == other
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<CosmicWindow> for Window {
|
||||
fn eq(&self, other: &CosmicWindow) -> bool {
|
||||
self == &other.window
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for CosmicWindow {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.window == other.window
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for CosmicWindow {}
|
||||
|
||||
impl Hash for CosmicWindow {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.window.hash(state)
|
||||
}
|
||||
}
|
||||
|
||||
impl CosmicWindow {
|
||||
pub fn set_size(&self, size: Size<i32, Logical>) {
|
||||
let surface_size = (
|
||||
size.w,
|
||||
size.h
|
||||
- self
|
||||
.header
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.map(|h| h.height())
|
||||
.unwrap_or(0),
|
||||
)
|
||||
.into();
|
||||
match self.window.toplevel() {
|
||||
Kind::Xdg(xdg) => xdg.with_pending_state(|state| state.size = Some(surface_size)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Window> for CosmicWindow {
|
||||
fn from(window: Window) -> Self {
|
||||
let is_ssd = matches!(
|
||||
match window.toplevel() {
|
||||
Kind::Xdg(xdg) => xdg.current_state().decoration_mode,
|
||||
},
|
||||
Some(DecorationMode::ServerSide)
|
||||
);
|
||||
CosmicWindow {
|
||||
window,
|
||||
header: Arc::new(Mutex::new(is_ssd.then_some(HeaderBar::default()))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ToplevelSurface> for CosmicWindow {
|
||||
fn from(surf: ToplevelSurface) -> Self {
|
||||
let is_ssd = matches!(
|
||||
surf.current_state().decoration_mode,
|
||||
Some(DecorationMode::ServerSide)
|
||||
);
|
||||
CosmicWindow {
|
||||
window: Window::new(Kind::Xdg(surf)),
|
||||
header: Arc::new(Mutex::new(is_ssd.then_some(HeaderBar::default()))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, PartialEq)]
|
||||
pub(super) struct HeaderBar {
|
||||
pointer_loc: Option<Point<f64, Logical>>,
|
||||
close_button_hover: bool,
|
||||
maximize_button_hover: bool,
|
||||
}
|
||||
|
||||
impl HeaderBar {
|
||||
pub fn height(&self) -> i32 {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
impl IsAlive for CosmicWindow {
|
||||
fn alive(&self) -> bool {
|
||||
self.window.alive()
|
||||
}
|
||||
}
|
||||
|
||||
impl SpaceElement for CosmicWindow {
|
||||
fn bbox(&self) -> Rectangle<i32, Logical> {
|
||||
SpaceElement::bbox(&self.window)
|
||||
}
|
||||
fn is_in_input_region(&self, point: &Point<f64, Logical>) -> bool {
|
||||
SpaceElement::is_in_input_region(&self.window, point)
|
||||
}
|
||||
fn set_activate(&self, activated: bool) {
|
||||
SpaceElement::set_activate(&self.window, activated)
|
||||
}
|
||||
fn output_enter(&self, output: &Output, overlap: Rectangle<i32, Logical>) {
|
||||
SpaceElement::output_enter(&self.window, output, overlap)
|
||||
}
|
||||
fn output_leave(&self, output: &Output) {
|
||||
SpaceElement::output_leave(&self.window, output)
|
||||
}
|
||||
fn geometry(&self) -> Rectangle<i32, Logical> {
|
||||
SpaceElement::geometry(&self.window)
|
||||
}
|
||||
fn z_index(&self) -> u8 {
|
||||
SpaceElement::z_index(&self.window)
|
||||
}
|
||||
fn refresh(&self) {
|
||||
SpaceElement::refresh(&self.window)
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyboardTarget<State> for CosmicWindow {
|
||||
fn enter(
|
||||
&self,
|
||||
seat: &Seat<State>,
|
||||
data: &mut State,
|
||||
keys: Vec<KeysymHandle<'_>>,
|
||||
serial: Serial,
|
||||
) {
|
||||
KeyboardTarget::enter(&self.window, seat, data, keys, serial)
|
||||
}
|
||||
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial) {
|
||||
KeyboardTarget::leave(&self.window, seat, data, serial)
|
||||
}
|
||||
fn key(
|
||||
&self,
|
||||
seat: &Seat<State>,
|
||||
data: &mut State,
|
||||
key: KeysymHandle<'_>,
|
||||
state: KeyState,
|
||||
serial: Serial,
|
||||
time: u32,
|
||||
) {
|
||||
KeyboardTarget::key(&self.window, seat, data, key, state, serial, time)
|
||||
}
|
||||
fn modifiers(
|
||||
&self,
|
||||
seat: &Seat<State>,
|
||||
data: &mut State,
|
||||
modifiers: ModifiersState,
|
||||
serial: Serial,
|
||||
) {
|
||||
KeyboardTarget::modifiers(&self.window, seat, data, modifiers, serial)
|
||||
}
|
||||
}
|
||||
|
||||
impl PointerTarget<State> for CosmicWindow {
|
||||
fn enter(&self, seat: &Seat<State>, data: &mut State, event: &MotionEvent) {
|
||||
PointerTarget::enter(&self.window, seat, data, event)
|
||||
}
|
||||
fn motion(&self, seat: &Seat<State>, data: &mut State, event: &MotionEvent) {
|
||||
PointerTarget::motion(&self.window, seat, data, event)
|
||||
}
|
||||
fn button(&self, seat: &Seat<State>, data: &mut State, event: &ButtonEvent) {
|
||||
PointerTarget::button(&self.window, seat, data, event)
|
||||
}
|
||||
fn axis(&self, seat: &Seat<State>, data: &mut State, frame: AxisFrame) {
|
||||
PointerTarget::axis(&self.window, seat, data, frame)
|
||||
}
|
||||
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {
|
||||
PointerTarget::leave(&self.window, seat, data, serial, time)
|
||||
}
|
||||
}
|
||||
|
||||
render_elements! {
|
||||
pub CosmicWindowRenderElement<R> where R: ImportAll;
|
||||
Window=WaylandSurfaceRenderElement,
|
||||
}
|
||||
|
||||
impl<R> AsRenderElements<R> for CosmicWindow
|
||||
where
|
||||
R: Renderer + ImportAll,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
{
|
||||
type RenderElement = CosmicWindowRenderElement<R>;
|
||||
fn render_elements<C: From<Self::RenderElement>>(
|
||||
&self,
|
||||
location: Point<i32, Physical>,
|
||||
scale: Scale<f64>,
|
||||
) -> Vec<C> {
|
||||
AsRenderElements::<R>::render_elements::<CosmicWindowRenderElement<R>>(
|
||||
&self.window,
|
||||
location - self.window.geometry().loc.to_physical_precise_round(scale),
|
||||
scale,
|
||||
)
|
||||
.into_iter()
|
||||
.map(C::from)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +1,18 @@
|
|||
use crate::{
|
||||
shell::{OutputBoundState, Shell, Workspace, WorkspaceMode},
|
||||
shell::{element::CosmicMapped, Shell, Workspace},
|
||||
state::Common,
|
||||
utils::prelude::*,
|
||||
wayland::handlers::xdg_shell::PopupGrabData,
|
||||
};
|
||||
use indexmap::IndexSet;
|
||||
use smithay::{
|
||||
desktop::{layer_map_for_output, PopupUngrabStrategy, Window, WindowSurfaceType},
|
||||
desktop::{layer_map_for_output, PopupUngrabStrategy},
|
||||
input::Seat,
|
||||
reexports::wayland_server::protocol::wl_surface::WlSurface,
|
||||
utils::{IsAlive, Serial, SERIAL_COUNTER},
|
||||
wayland::{
|
||||
compositor::get_role,
|
||||
shell::{wlr_layer::LAYER_SURFACE_ROLE, xdg::XDG_TOPLEVEL_ROLE},
|
||||
},
|
||||
};
|
||||
use std::{
|
||||
cell::{Ref, RefCell, RefMut},
|
||||
collections::HashMap,
|
||||
};
|
||||
use std::cell::RefCell;
|
||||
|
||||
use self::target::{KeyboardFocusTarget, WindowGroup};
|
||||
|
||||
pub mod target;
|
||||
|
||||
|
|
@ -32,80 +26,59 @@ pub enum FocusDirection {
|
|||
Out,
|
||||
}
|
||||
|
||||
pub struct FocusStack<'a>(Ref<'a, IndexSet<Window>>);
|
||||
pub struct FocusStackMut<'a>(RefMut<'a, IndexSet<Window>>);
|
||||
pub struct FocusStack<'a>(pub(super) Option<&'a IndexSet<CosmicMapped>>);
|
||||
pub struct FocusStackMut<'a>(pub(super) &'a mut IndexSet<CosmicMapped>);
|
||||
|
||||
impl<'a> FocusStack<'a> {
|
||||
pub fn last(&self) -> Option<Window> {
|
||||
self.0.iter().rev().find(|w| w.toplevel().alive()).cloned()
|
||||
pub fn last(&self) -> Option<&CosmicMapped> {
|
||||
self.0
|
||||
.as_ref()
|
||||
.and_then(|set| set.iter().rev().find(|w| w.alive()))
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = &'_ Window> {
|
||||
self.0.iter().rev().filter(|w| w.toplevel().alive())
|
||||
pub fn iter(&self) -> impl Iterator<Item = &'_ CosmicMapped> {
|
||||
self.0
|
||||
.iter()
|
||||
.flat_map(|set| set.iter().rev().filter(|w| w.alive()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> FocusStackMut<'a> {
|
||||
pub fn append(&mut self, window: &Window) {
|
||||
self.0.retain(|w| w.toplevel().alive());
|
||||
pub fn append(&mut self, window: &CosmicMapped) {
|
||||
self.0.retain(|w| w.alive());
|
||||
self.0.shift_remove(window);
|
||||
self.0.insert(window.clone());
|
||||
}
|
||||
|
||||
pub fn last(&self) -> Option<Window> {
|
||||
self.0.iter().rev().find(|w| w.toplevel().alive()).cloned()
|
||||
pub fn last(&self) -> Option<&CosmicMapped> {
|
||||
self.0.iter().rev().find(|w| w.alive())
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = &'_ Window> {
|
||||
self.0.iter().rev().filter(|w| w.toplevel().alive())
|
||||
pub fn iter(&self) -> impl Iterator<Item = &'_ CosmicMapped> {
|
||||
self.0.iter().rev().filter(|w| w.alive())
|
||||
}
|
||||
}
|
||||
|
||||
type FocusStackData = RefCell<(HashMap<u8, IndexSet<Window>>, IndexSet<Window>)>;
|
||||
impl Workspace {}
|
||||
|
||||
impl Workspace {
|
||||
pub fn focus_stack<'a, 'b>(&'b self, seat: &'a Seat<State>) -> FocusStack<'a> {
|
||||
seat.user_data()
|
||||
.insert_if_missing(|| FocusStackData::new((HashMap::new(), IndexSet::new())));
|
||||
let idx = self.idx;
|
||||
FocusStack(Ref::map(
|
||||
seat.user_data().get::<FocusStackData>().unwrap().borrow(),
|
||||
|map| map.0.get(&idx).unwrap_or(&map.1), //TODO: workaround until Ref::filter_map goes stable
|
||||
))
|
||||
}
|
||||
|
||||
pub fn focus_stack_mut<'a, 'b>(&'b self, seat: &'a Seat<State>) -> FocusStackMut<'a> {
|
||||
seat.user_data()
|
||||
.insert_if_missing(|| FocusStackData::new((HashMap::new(), IndexSet::new())));
|
||||
let idx = self.idx;
|
||||
FocusStackMut(RefMut::map(
|
||||
seat.user_data()
|
||||
.get::<FocusStackData>()
|
||||
.unwrap()
|
||||
.borrow_mut(),
|
||||
|map| map.0.entry(idx).or_insert_with(|| IndexSet::new()),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ActiveFocus(RefCell<Option<WlSurface>>);
|
||||
pub struct ActiveFocus(RefCell<Option<KeyboardFocusTarget>>);
|
||||
|
||||
impl ActiveFocus {
|
||||
fn set(seat: &Seat<State>, surface: Option<WlSurface>) {
|
||||
fn set(seat: &Seat<State>, target: Option<KeyboardFocusTarget>) {
|
||||
if !seat
|
||||
.user_data()
|
||||
.insert_if_missing(|| ActiveFocus(RefCell::new(surface.clone())))
|
||||
.insert_if_missing(|| ActiveFocus(RefCell::new(target.clone())))
|
||||
{
|
||||
*seat
|
||||
.user_data()
|
||||
.get::<ActiveFocus>()
|
||||
.unwrap()
|
||||
.0
|
||||
.borrow_mut() = surface;
|
||||
.borrow_mut() = target;
|
||||
}
|
||||
}
|
||||
|
||||
fn get(seat: &Seat<State>) -> Option<WlSurface> {
|
||||
fn get(seat: &Seat<State>) -> Option<KeyboardFocusTarget> {
|
||||
seat.user_data()
|
||||
.get::<ActiveFocus>()
|
||||
.and_then(|a| a.0.borrow().clone())
|
||||
|
|
@ -115,30 +88,25 @@ impl ActiveFocus {
|
|||
impl Shell {
|
||||
pub fn set_focus<'a>(
|
||||
state: &mut State,
|
||||
surface: Option<&WlSurface>,
|
||||
target: Option<&KeyboardFocusTarget>,
|
||||
active_seat: &Seat<State>,
|
||||
serial: Option<Serial>,
|
||||
) {
|
||||
// update FocusStack and notify layouts about new focus (if any window)
|
||||
if let Some(surface) = surface {
|
||||
if let Some(workspace) = state.common.shell.space_for_window_mut(surface) {
|
||||
if let Some(window) = workspace
|
||||
.space
|
||||
.window_for_surface(surface, WindowSurfaceType::ALL)
|
||||
{
|
||||
let mut focus_stack = workspace.focus_stack_mut(active_seat);
|
||||
if Some(window) != focus_stack.last().as_ref() {
|
||||
slog_scope::debug!("Focusing window: {:?}", window);
|
||||
focus_stack.append(window);
|
||||
// also remove popup grabs, if we are switching focus
|
||||
if let Some(mut popup_grab) = active_seat
|
||||
.user_data()
|
||||
.get::<PopupGrabData>()
|
||||
.and_then(|x| x.take())
|
||||
{
|
||||
if !popup_grab.has_ended() {
|
||||
popup_grab.ungrab(PopupUngrabStrategy::All);
|
||||
}
|
||||
if let Some(KeyboardFocusTarget::Element(mapped)) = target {
|
||||
if let Some(workspace) = state.common.shell.space_for_mut(mapped) {
|
||||
let mut focus_stack = workspace.focus_stack.get_mut(active_seat);
|
||||
if Some(mapped) != focus_stack.last() {
|
||||
slog_scope::debug!("Focusing window: {:?}", mapped);
|
||||
focus_stack.append(mapped);
|
||||
// also remove popup grabs, if we are switching focus
|
||||
if let Some(mut popup_grab) = active_seat
|
||||
.user_data()
|
||||
.get::<PopupGrabData>()
|
||||
.and_then(|x| x.take())
|
||||
{
|
||||
if !popup_grab.has_ended() {
|
||||
popup_grab.ungrab(PopupUngrabStrategy::All);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -147,10 +115,10 @@ impl Shell {
|
|||
|
||||
// update keyboard focus
|
||||
if let Some(keyboard) = active_seat.get_keyboard() {
|
||||
ActiveFocus::set(active_seat, surface.cloned());
|
||||
ActiveFocus::set(active_seat, target.cloned());
|
||||
keyboard.set_focus(
|
||||
state,
|
||||
surface.cloned(),
|
||||
target.cloned(),
|
||||
serial.unwrap_or_else(|| SERIAL_COUNTER.next_serial()),
|
||||
);
|
||||
}
|
||||
|
|
@ -160,30 +128,23 @@ impl Shell {
|
|||
// update activate status
|
||||
let focused_windows = seats
|
||||
.flat_map(|seat| {
|
||||
self.outputs
|
||||
.iter()
|
||||
.flat_map(|o| self.active_space(o).focus_stack(seat).last().clone())
|
||||
self.outputs.iter().flat_map(|o| {
|
||||
let space = self.active_space(o);
|
||||
let stack = space.focus_stack.get(seat);
|
||||
stack.last().cloned()
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for output in self.outputs.iter() {
|
||||
let workspace = match &self.workspace_mode {
|
||||
WorkspaceMode::OutputBound => {
|
||||
let active = output
|
||||
.user_data()
|
||||
.get::<OutputBoundState>()
|
||||
.unwrap()
|
||||
.active
|
||||
.get();
|
||||
&mut self.spaces[active]
|
||||
}
|
||||
WorkspaceMode::Global { active, .. } => &mut self.spaces[*active],
|
||||
};
|
||||
let workspace = self.workspaces.active_mut(output);
|
||||
for focused in focused_windows.iter() {
|
||||
workspace.space.raise_window(focused, true);
|
||||
if workspace.floating_layer.mapped().any(|m| m == focused) {
|
||||
workspace.floating_layer.space.raise_element(focused, true);
|
||||
}
|
||||
}
|
||||
for window in workspace.space.windows() {
|
||||
window.set_activated(focused_windows.contains(window));
|
||||
for window in workspace.mapped() {
|
||||
window.set_activated(focused_windows.contains(&window));
|
||||
window.configure();
|
||||
}
|
||||
}
|
||||
|
|
@ -193,55 +154,50 @@ impl Shell {
|
|||
impl Common {
|
||||
pub fn set_focus(
|
||||
state: &mut State,
|
||||
surface: Option<&WlSurface>,
|
||||
target: Option<&KeyboardFocusTarget>,
|
||||
active_seat: &Seat<State>,
|
||||
serial: Option<Serial>,
|
||||
) {
|
||||
Shell::set_focus(state, surface, active_seat, serial);
|
||||
state.common.shell.update_active(state.common.seats.iter());
|
||||
Shell::set_focus(state, target, active_seat, serial);
|
||||
let seats = state.common.seats().cloned().collect::<Vec<_>>();
|
||||
state.common.shell.update_active(seats.iter());
|
||||
}
|
||||
|
||||
pub fn refresh_focus(state: &mut State) {
|
||||
let seats = state.common.seats.clone();
|
||||
let seats = state.common.seats().cloned().collect::<Vec<_>>();
|
||||
for seat in seats {
|
||||
let output = active_output(&seat, &state.common);
|
||||
let output = seat.active_output();
|
||||
let last_known_focus = ActiveFocus::get(&seat);
|
||||
|
||||
if let Some(surface) = last_known_focus {
|
||||
if surface.alive() {
|
||||
let is_toplevel = matches!(get_role(&surface), Some(XDG_TOPLEVEL_ROLE));
|
||||
let is_layer = matches!(get_role(&surface), Some(LAYER_SURFACE_ROLE));
|
||||
|
||||
if let Some(popup) = state.common.shell.popups.find_popup(&surface) {
|
||||
if popup.alive() {
|
||||
continue;
|
||||
}
|
||||
} else if is_layer {
|
||||
if layer_map_for_output(&output)
|
||||
.layer_for_surface(&surface, WindowSurfaceType::ALL)
|
||||
.is_some()
|
||||
{
|
||||
continue; // Focus is valid
|
||||
}
|
||||
} else if is_toplevel {
|
||||
let workspace = state.common.shell.active_space(&output);
|
||||
if let Some(window) = workspace
|
||||
.space
|
||||
.window_for_surface(&surface, WindowSurfaceType::ALL)
|
||||
{
|
||||
let focus_stack = workspace.focus_stack(&seat);
|
||||
if !focus_stack.last().map(|w| &w != window).unwrap_or(true) {
|
||||
if let Some(target) = last_known_focus {
|
||||
if target.alive() {
|
||||
match target {
|
||||
KeyboardFocusTarget::Element(mapped) => {
|
||||
let workspace = state.common.shell.active_space(&output);
|
||||
let focus_stack = workspace.focus_stack.get(&seat);
|
||||
if focus_stack.last().map(|m| m == &mapped).unwrap_or(false) {
|
||||
continue; // Focus is valid
|
||||
} else {
|
||||
slog_scope::debug!("Wrong Window, focus fixup");
|
||||
}
|
||||
} else {
|
||||
slog_scope::debug!("Different workspaces Window, focus fixup");
|
||||
}
|
||||
} else {
|
||||
// unknown surface type, fixup
|
||||
slog_scope::debug!("Surface unmapped, focus fixup");
|
||||
}
|
||||
KeyboardFocusTarget::LayerSurface(layer) => {
|
||||
if layer_map_for_output(&output).layers().any(|l| l == &layer) {
|
||||
continue; // Focus is valid
|
||||
}
|
||||
}
|
||||
KeyboardFocusTarget::Group(WindowGroup {
|
||||
output: weak_output,
|
||||
..
|
||||
}) => {
|
||||
if weak_output == output {
|
||||
continue; // Focus is valid,
|
||||
}
|
||||
}
|
||||
KeyboardFocusTarget::Popup(_) | KeyboardFocusTarget::Fullscreen(_) => {
|
||||
continue;
|
||||
} // Focus is valid
|
||||
};
|
||||
} else {
|
||||
slog_scope::debug!("Surface dead, focus fixup");
|
||||
}
|
||||
|
|
@ -263,21 +219,24 @@ impl Common {
|
|||
}
|
||||
|
||||
// update keyboard focus
|
||||
let surface = state
|
||||
let target = state
|
||||
.common
|
||||
.shell
|
||||
.active_space(&output)
|
||||
.focus_stack(&seat)
|
||||
.focus_stack
|
||||
.get(&seat)
|
||||
.last()
|
||||
.map(|w| w.toplevel().wl_surface().clone());
|
||||
.cloned()
|
||||
.map(KeyboardFocusTarget::from);
|
||||
if let Some(keyboard) = seat.get_keyboard() {
|
||||
slog_scope::info!("restoring focus to: {:?}", surface.as_ref());
|
||||
keyboard.set_focus(state, surface.clone(), SERIAL_COUNTER.next_serial());
|
||||
ActiveFocus::set(&seat, surface);
|
||||
slog_scope::info!("restoring focus to: {:?}", target.as_ref());
|
||||
keyboard.set_focus(state, target.clone(), SERIAL_COUNTER.next_serial());
|
||||
ActiveFocus::set(&seat, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state.common.shell.update_active(state.common.seats.iter())
|
||||
let seats = state.common.seats().cloned().collect::<Vec<_>>();
|
||||
state.common.shell.update_active(seats.iter())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
use crate::utils::prelude::*;
|
||||
pub use smithay::{
|
||||
use std::sync::Weak;
|
||||
|
||||
use crate::{shell::element::CosmicMapped, utils::prelude::*};
|
||||
use id_tree::NodeId;
|
||||
use smithay::{
|
||||
backend::input::KeyState,
|
||||
desktop::{LayerSurface, PopupKind, Window},
|
||||
input::{
|
||||
|
|
@ -7,83 +10,139 @@ pub use smithay::{
|
|||
pointer::{AxisFrame, ButtonEvent, MotionEvent, PointerTarget},
|
||||
Seat,
|
||||
},
|
||||
output::WeakOutput,
|
||||
reexports::wayland_server::{backend::ObjectId, protocol::wl_surface::WlSurface, Resource},
|
||||
utils::{IsAlive, Serial},
|
||||
wayland::seat::WaylandFocus,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum FocusTarget {
|
||||
Window(Window),
|
||||
pub enum PointerFocusTarget {
|
||||
Element(CosmicMapped),
|
||||
Fullscreen(Window),
|
||||
LayerSurface(LayerSurface),
|
||||
Popup(PopupKind),
|
||||
}
|
||||
|
||||
impl IsAlive for FocusTarget {
|
||||
fn alive(&self) -> bool {
|
||||
match self {
|
||||
FocusTarget::Window(w) => w.alive(),
|
||||
FocusTarget::LayerSurface(l) => l.alive(),
|
||||
FocusTarget::Popup(p) => p.alive(),
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum KeyboardFocusTarget {
|
||||
Element(CosmicMapped),
|
||||
Fullscreen(Window),
|
||||
Group(WindowGroup),
|
||||
LayerSurface(LayerSurface),
|
||||
Popup(PopupKind),
|
||||
}
|
||||
|
||||
impl From<KeyboardFocusTarget> for PointerFocusTarget {
|
||||
fn from(target: KeyboardFocusTarget) -> Self {
|
||||
match target {
|
||||
KeyboardFocusTarget::Element(elem) => PointerFocusTarget::Element(elem),
|
||||
KeyboardFocusTarget::Fullscreen(elem) => PointerFocusTarget::Fullscreen(elem),
|
||||
KeyboardFocusTarget::LayerSurface(layer) => PointerFocusTarget::LayerSurface(layer),
|
||||
KeyboardFocusTarget::Popup(popup) => PointerFocusTarget::Popup(popup),
|
||||
_ => unreachable!("A window grab cannot start a popup grab"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PointerTarget<State> for FocusTarget {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct WindowGroup {
|
||||
pub(in crate::shell) node: NodeId,
|
||||
pub(in crate::shell) output: WeakOutput,
|
||||
pub(in crate::shell) alive: Weak<()>,
|
||||
}
|
||||
|
||||
impl PartialEq for WindowGroup {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.node == other.node
|
||||
&& self.output == other.output
|
||||
&& Weak::ptr_eq(&self.alive, &other.alive)
|
||||
}
|
||||
}
|
||||
|
||||
impl IsAlive for PointerFocusTarget {
|
||||
fn alive(&self) -> bool {
|
||||
match self {
|
||||
PointerFocusTarget::Element(e) => e.alive(),
|
||||
PointerFocusTarget::Fullscreen(f) => f.alive(),
|
||||
PointerFocusTarget::LayerSurface(l) => l.alive(),
|
||||
PointerFocusTarget::Popup(p) => p.alive(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IsAlive for KeyboardFocusTarget {
|
||||
fn alive(&self) -> bool {
|
||||
match self {
|
||||
KeyboardFocusTarget::Element(e) => e.alive(),
|
||||
KeyboardFocusTarget::Fullscreen(f) => f.alive(),
|
||||
KeyboardFocusTarget::Group(g) => g.alive.upgrade().is_some(),
|
||||
KeyboardFocusTarget::LayerSurface(l) => l.alive(),
|
||||
KeyboardFocusTarget::Popup(p) => p.alive(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PointerTarget<State> for PointerFocusTarget {
|
||||
fn enter(&self, seat: &Seat<State>, data: &mut State, event: &MotionEvent) {
|
||||
match self {
|
||||
FocusTarget::Window(w) => {
|
||||
PointerTarget::enter(w.toplevel().wl_surface(), seat, data, event)
|
||||
PointerFocusTarget::Element(w) => PointerTarget::enter(w, seat, data, event),
|
||||
PointerFocusTarget::Fullscreen(w) => PointerTarget::enter(w, seat, data, event),
|
||||
PointerFocusTarget::LayerSurface(l) => {
|
||||
PointerTarget::enter(l.wl_surface(), seat, data, event)
|
||||
}
|
||||
FocusTarget::LayerSurface(l) => PointerTarget::enter(l.wl_surface(), seat, data, event),
|
||||
FocusTarget::Popup(p) => PointerTarget::enter(p.wl_surface(), seat, data, event),
|
||||
PointerFocusTarget::Popup(p) => PointerTarget::enter(p.wl_surface(), seat, data, event),
|
||||
}
|
||||
}
|
||||
fn motion(&self, seat: &Seat<State>, data: &mut State, event: &MotionEvent) {
|
||||
match self {
|
||||
FocusTarget::Window(w) => {
|
||||
PointerTarget::motion(w.toplevel().wl_surface(), seat, data, event)
|
||||
}
|
||||
FocusTarget::LayerSurface(l) => {
|
||||
PointerFocusTarget::Element(w) => PointerTarget::motion(w, seat, data, event),
|
||||
PointerFocusTarget::Fullscreen(w) => PointerTarget::motion(w, seat, data, event),
|
||||
PointerFocusTarget::LayerSurface(l) => {
|
||||
PointerTarget::motion(l.wl_surface(), seat, data, event)
|
||||
}
|
||||
FocusTarget::Popup(p) => PointerTarget::motion(p.wl_surface(), seat, data, event),
|
||||
PointerFocusTarget::Popup(p) => {
|
||||
PointerTarget::motion(p.wl_surface(), seat, data, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn button(&self, seat: &Seat<State>, data: &mut State, event: &ButtonEvent) {
|
||||
match self {
|
||||
FocusTarget::Window(w) => {
|
||||
PointerTarget::button(w.toplevel().wl_surface(), seat, data, event)
|
||||
}
|
||||
FocusTarget::LayerSurface(l) => {
|
||||
PointerFocusTarget::Element(w) => PointerTarget::button(w, seat, data, event),
|
||||
PointerFocusTarget::Fullscreen(w) => PointerTarget::button(w, seat, data, event),
|
||||
PointerFocusTarget::LayerSurface(l) => {
|
||||
PointerTarget::button(l.wl_surface(), seat, data, event)
|
||||
}
|
||||
FocusTarget::Popup(p) => PointerTarget::button(p.wl_surface(), seat, data, event),
|
||||
PointerFocusTarget::Popup(p) => {
|
||||
PointerTarget::button(p.wl_surface(), seat, data, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn axis(&self, seat: &Seat<State>, data: &mut State, frame: AxisFrame) {
|
||||
match self {
|
||||
FocusTarget::Window(w) => {
|
||||
PointerTarget::axis(w.toplevel().wl_surface(), seat, data, frame)
|
||||
PointerFocusTarget::Element(w) => PointerTarget::axis(w, seat, data, frame),
|
||||
PointerFocusTarget::Fullscreen(w) => PointerTarget::axis(w, seat, data, frame),
|
||||
PointerFocusTarget::LayerSurface(l) => {
|
||||
PointerTarget::axis(l.wl_surface(), seat, data, frame)
|
||||
}
|
||||
FocusTarget::LayerSurface(l) => PointerTarget::axis(l.wl_surface(), seat, data, frame),
|
||||
FocusTarget::Popup(p) => PointerTarget::axis(p.wl_surface(), seat, data, frame),
|
||||
PointerFocusTarget::Popup(p) => PointerTarget::axis(p.wl_surface(), seat, data, frame),
|
||||
}
|
||||
}
|
||||
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {
|
||||
match self {
|
||||
FocusTarget::Window(w) => {
|
||||
PointerTarget::leave(w.toplevel().wl_surface(), seat, data, serial, time)
|
||||
}
|
||||
FocusTarget::LayerSurface(l) => {
|
||||
PointerFocusTarget::Element(w) => PointerTarget::leave(w, seat, data, serial, time),
|
||||
PointerFocusTarget::Fullscreen(w) => PointerTarget::leave(w, seat, data, serial, time),
|
||||
PointerFocusTarget::LayerSurface(l) => {
|
||||
PointerTarget::leave(l.wl_surface(), seat, data, serial, time)
|
||||
}
|
||||
FocusTarget::Popup(p) => PointerTarget::leave(p.wl_surface(), seat, data, serial, time),
|
||||
PointerFocusTarget::Popup(p) => {
|
||||
PointerTarget::leave(p.wl_surface(), seat, data, serial, time)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyboardTarget<State> for FocusTarget {
|
||||
impl KeyboardTarget<State> for KeyboardFocusTarget {
|
||||
fn enter(
|
||||
&self,
|
||||
seat: &Seat<State>,
|
||||
|
|
@ -92,26 +151,30 @@ impl KeyboardTarget<State> for FocusTarget {
|
|||
serial: Serial,
|
||||
) {
|
||||
match self {
|
||||
FocusTarget::Window(w) => {
|
||||
KeyboardTarget::enter(w.toplevel().wl_surface(), seat, data, keys, serial)
|
||||
KeyboardFocusTarget::Element(w) => KeyboardTarget::enter(w, seat, data, keys, serial),
|
||||
KeyboardFocusTarget::Fullscreen(w) => {
|
||||
KeyboardTarget::enter(w, seat, data, keys, serial)
|
||||
}
|
||||
FocusTarget::LayerSurface(l) => {
|
||||
KeyboardFocusTarget::Group(_) => {}
|
||||
KeyboardFocusTarget::LayerSurface(l) => {
|
||||
KeyboardTarget::enter(l.wl_surface(), seat, data, keys, serial)
|
||||
}
|
||||
FocusTarget::Popup(p) => {
|
||||
KeyboardFocusTarget::Popup(p) => {
|
||||
KeyboardTarget::enter(p.wl_surface(), seat, data, keys, serial)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial) {
|
||||
match self {
|
||||
FocusTarget::Window(w) => {
|
||||
KeyboardTarget::leave(w.toplevel().wl_surface(), seat, data, serial)
|
||||
}
|
||||
FocusTarget::LayerSurface(l) => {
|
||||
KeyboardFocusTarget::Element(w) => KeyboardTarget::leave(w, seat, data, serial),
|
||||
KeyboardFocusTarget::Fullscreen(w) => KeyboardTarget::leave(w, seat, data, serial),
|
||||
KeyboardFocusTarget::Group(_) => {}
|
||||
KeyboardFocusTarget::LayerSurface(l) => {
|
||||
KeyboardTarget::leave(l.wl_surface(), seat, data, serial)
|
||||
}
|
||||
FocusTarget::Popup(p) => KeyboardTarget::leave(p.wl_surface(), seat, data, serial),
|
||||
KeyboardFocusTarget::Popup(p) => {
|
||||
KeyboardTarget::leave(p.wl_surface(), seat, data, serial)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn key(
|
||||
|
|
@ -124,19 +187,17 @@ impl KeyboardTarget<State> for FocusTarget {
|
|||
time: u32,
|
||||
) {
|
||||
match self {
|
||||
FocusTarget::Window(w) => KeyboardTarget::key(
|
||||
w.toplevel().wl_surface(),
|
||||
seat,
|
||||
data,
|
||||
key,
|
||||
state,
|
||||
serial,
|
||||
time,
|
||||
),
|
||||
FocusTarget::LayerSurface(l) => {
|
||||
KeyboardFocusTarget::Element(w) => {
|
||||
KeyboardTarget::key(w, seat, data, key, state, serial, time)
|
||||
}
|
||||
KeyboardFocusTarget::Fullscreen(w) => {
|
||||
KeyboardTarget::key(w, seat, data, key, state, serial, time)
|
||||
}
|
||||
KeyboardFocusTarget::Group(_) => {}
|
||||
KeyboardFocusTarget::LayerSurface(l) => {
|
||||
KeyboardTarget::key(l.wl_surface(), seat, data, key, state, serial, time)
|
||||
}
|
||||
FocusTarget::Popup(p) => {
|
||||
KeyboardFocusTarget::Popup(p) => {
|
||||
KeyboardTarget::key(p.wl_surface(), seat, data, key, state, serial, time)
|
||||
}
|
||||
}
|
||||
|
|
@ -149,50 +210,113 @@ impl KeyboardTarget<State> for FocusTarget {
|
|||
serial: Serial,
|
||||
) {
|
||||
match self {
|
||||
FocusTarget::Window(w) => {
|
||||
KeyboardTarget::modifiers(w.toplevel().wl_surface(), seat, data, modifiers, serial)
|
||||
KeyboardFocusTarget::Element(w) => {
|
||||
KeyboardTarget::modifiers(w, seat, data, modifiers, serial)
|
||||
}
|
||||
FocusTarget::LayerSurface(l) => {
|
||||
KeyboardFocusTarget::Fullscreen(w) => {
|
||||
KeyboardTarget::modifiers(w, seat, data, modifiers, serial)
|
||||
}
|
||||
KeyboardFocusTarget::Group(_) => {}
|
||||
KeyboardFocusTarget::LayerSurface(l) => {
|
||||
KeyboardTarget::modifiers(l.wl_surface(), seat, data, modifiers, serial)
|
||||
}
|
||||
FocusTarget::Popup(p) => {
|
||||
KeyboardFocusTarget::Popup(p) => {
|
||||
KeyboardTarget::modifiers(p.wl_surface(), seat, data, modifiers, serial)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WaylandFocus for FocusTarget {
|
||||
fn wl_surface(&self) -> Option<&WlSurface> {
|
||||
Some(match self {
|
||||
FocusTarget::Window(w) => w.toplevel().wl_surface(),
|
||||
FocusTarget::LayerSurface(l) => l.wl_surface(),
|
||||
FocusTarget::Popup(p) => p.wl_surface(),
|
||||
})
|
||||
impl WaylandFocus for KeyboardFocusTarget {
|
||||
fn wl_surface(&self) -> Option<WlSurface> {
|
||||
match self {
|
||||
KeyboardFocusTarget::Element(w) => WaylandFocus::wl_surface(w),
|
||||
KeyboardFocusTarget::Fullscreen(w) => WaylandFocus::wl_surface(w),
|
||||
KeyboardFocusTarget::Group(_) => None,
|
||||
KeyboardFocusTarget::LayerSurface(l) => Some(l.wl_surface().clone()),
|
||||
KeyboardFocusTarget::Popup(p) => Some(p.wl_surface().clone()),
|
||||
}
|
||||
}
|
||||
fn same_client_as(&self, object_id: &ObjectId) -> bool {
|
||||
match self {
|
||||
FocusTarget::Window(w) => w.toplevel().wl_surface().id().same_client_as(object_id),
|
||||
FocusTarget::LayerSurface(l) => l.wl_surface().id().same_client_as(object_id),
|
||||
FocusTarget::Popup(p) => p.wl_surface().id().same_client_as(object_id),
|
||||
KeyboardFocusTarget::Element(w) => WaylandFocus::same_client_as(w, object_id),
|
||||
KeyboardFocusTarget::Fullscreen(w) => WaylandFocus::same_client_as(w, object_id),
|
||||
KeyboardFocusTarget::Group(_) => false,
|
||||
KeyboardFocusTarget::LayerSurface(l) => l.wl_surface().id().same_client_as(object_id),
|
||||
KeyboardFocusTarget::Popup(p) => p.wl_surface().id().same_client_as(object_id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Window> for FocusTarget {
|
||||
impl WaylandFocus for PointerFocusTarget {
|
||||
fn wl_surface(&self) -> Option<WlSurface> {
|
||||
Some(match self {
|
||||
PointerFocusTarget::Element(w) => WaylandFocus::wl_surface(w)?,
|
||||
PointerFocusTarget::Fullscreen(w) => WaylandFocus::wl_surface(w)?,
|
||||
PointerFocusTarget::LayerSurface(l) => l.wl_surface().clone(),
|
||||
PointerFocusTarget::Popup(p) => p.wl_surface().clone(),
|
||||
})
|
||||
}
|
||||
fn same_client_as(&self, object_id: &ObjectId) -> bool {
|
||||
match self {
|
||||
PointerFocusTarget::Element(w) => WaylandFocus::same_client_as(w, object_id),
|
||||
PointerFocusTarget::Fullscreen(w) => WaylandFocus::same_client_as(w, object_id),
|
||||
PointerFocusTarget::LayerSurface(l) => l.wl_surface().id().same_client_as(object_id),
|
||||
PointerFocusTarget::Popup(p) => p.wl_surface().id().same_client_as(object_id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CosmicMapped> for PointerFocusTarget {
|
||||
fn from(w: CosmicMapped) -> Self {
|
||||
PointerFocusTarget::Element(w)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Window> for PointerFocusTarget {
|
||||
fn from(w: Window) -> Self {
|
||||
FocusTarget::Window(w)
|
||||
PointerFocusTarget::Fullscreen(w)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LayerSurface> for FocusTarget {
|
||||
impl From<LayerSurface> for PointerFocusTarget {
|
||||
fn from(l: LayerSurface) -> Self {
|
||||
FocusTarget::LayerSurface(l)
|
||||
PointerFocusTarget::LayerSurface(l)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PopupKind> for FocusTarget {
|
||||
impl From<PopupKind> for PointerFocusTarget {
|
||||
fn from(p: PopupKind) -> Self {
|
||||
FocusTarget::Popup(p)
|
||||
PointerFocusTarget::Popup(p)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CosmicMapped> for KeyboardFocusTarget {
|
||||
fn from(w: CosmicMapped) -> Self {
|
||||
KeyboardFocusTarget::Element(w)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Window> for KeyboardFocusTarget {
|
||||
fn from(w: Window) -> Self {
|
||||
KeyboardFocusTarget::Fullscreen(w)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WindowGroup> for KeyboardFocusTarget {
|
||||
fn from(w: WindowGroup) -> Self {
|
||||
KeyboardFocusTarget::Group(w)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LayerSurface> for KeyboardFocusTarget {
|
||||
fn from(l: LayerSurface) -> Self {
|
||||
KeyboardFocusTarget::LayerSurface(l)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PopupKind> for KeyboardFocusTarget {
|
||||
fn from(p: PopupKind) -> Self {
|
||||
KeyboardFocusTarget::Popup(p)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,10 +51,11 @@ impl Shell {
|
|||
.space
|
||||
.outputs_for_window(&window)
|
||||
.into_iter()
|
||||
.find(|o| o.geometry().contains(pos.to_i32_round())) {
|
||||
Some(o) => o,
|
||||
None => return,
|
||||
};
|
||||
.find(|o| o.geometry().contains(pos.to_i32_round()))
|
||||
{
|
||||
Some(o) => o,
|
||||
None => return,
|
||||
};
|
||||
let mut initial_window_location = workspace.space.window_location(&window).unwrap();
|
||||
|
||||
match &window.toplevel() {
|
||||
|
|
@ -356,7 +357,7 @@ impl MoveSurfaceGrab {
|
|||
time: u32,
|
||||
) {
|
||||
// No more buttons are pressed, release the grab.
|
||||
let output = active_output(&self.seat, &state.common);
|
||||
let output = self.seat.active_output();
|
||||
let seat = self.seat.clone();
|
||||
|
||||
state.common.event_loop_handle.insert_idle(move |data| {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::utils::prelude::*;
|
||||
use crate::{shell::focus::target::PointerFocusTarget, utils::prelude::*};
|
||||
use smithay::{
|
||||
desktop::{Kind, Window},
|
||||
input::pointer::{
|
||||
AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab,
|
||||
PointerInnerHandle,
|
||||
},
|
||||
reexports::{
|
||||
wayland_protocols::xdg::shell::server::xdg_toplevel,
|
||||
wayland_server::protocol::wl_surface::WlSurface,
|
||||
},
|
||||
reexports::wayland_protocols::xdg::shell::server::xdg_toplevel,
|
||||
utils::{IsAlive, Logical, Point, Serial, Size},
|
||||
wayland::{
|
||||
compositor::with_states,
|
||||
|
|
@ -90,7 +87,7 @@ impl PointerGrab<State> for ResizeSurfaceGrab {
|
|||
&mut self,
|
||||
data: &mut State,
|
||||
handle: &mut PointerInnerHandle<'_, State>,
|
||||
_focus: Option<(WlSurface, Point<i32, Logical>)>,
|
||||
_focus: Option<(PointerFocusTarget, Point<i32, Logical>)>,
|
||||
event: &MotionEvent,
|
||||
) {
|
||||
// While the grab is active, no client has pointer focus
|
||||
|
|
|
|||
|
|
@ -1,99 +1,86 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use smithay::{
|
||||
desktop::{layer_map_for_output, space::RenderZindex, Kind, Space, Window},
|
||||
input::{
|
||||
pointer::{Focus, GrabStartData as PointerGrabStartData},
|
||||
Seat,
|
||||
},
|
||||
backend::renderer::{ImportAll, Renderer},
|
||||
desktop::{layer_map_for_output, space::SpaceElement, Space, Window},
|
||||
input::Seat,
|
||||
output::Output,
|
||||
reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::{
|
||||
ResizeEdge, State as XdgState,
|
||||
},
|
||||
utils::{IsAlive, Logical, Point, Rectangle, Serial},
|
||||
wayland::{compositor::with_states, shell::xdg::XdgToplevelSurfaceRoleAttributes},
|
||||
render_elements,
|
||||
utils::{Logical, Point, Rectangle},
|
||||
};
|
||||
use std::{collections::HashSet, sync::Mutex};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::state::State;
|
||||
use crate::{
|
||||
shell::{
|
||||
element::{CosmicMapped, CosmicMappedRenderElement},
|
||||
OutputNotMapped,
|
||||
},
|
||||
state::State,
|
||||
utils::prelude::*,
|
||||
};
|
||||
|
||||
mod grabs;
|
||||
pub use self::grabs::*;
|
||||
|
||||
pub const FLOATING_INDEX: u8 = RenderZindex::Shell as u8 + 1;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug)]
|
||||
pub struct FloatingLayout {
|
||||
pending_windows: Vec<Window>,
|
||||
pub windows: HashSet<Window>,
|
||||
pub(in crate::shell) space: Space<CosmicMapped>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct WindowUserDataInner {
|
||||
last_geometry: Rectangle<i32, Logical>,
|
||||
impl Default for FloatingLayout {
|
||||
fn default() -> Self {
|
||||
FloatingLayout {
|
||||
space: Space::new(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
pub type WindowUserData = Mutex<WindowUserDataInner>;
|
||||
|
||||
impl FloatingLayout {
|
||||
pub fn new() -> FloatingLayout {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
pub fn map_window(
|
||||
pub fn map_output(&mut self, output: &Output, location: Point<i32, Logical>) {
|
||||
self.space.map_output(output, location)
|
||||
}
|
||||
|
||||
pub fn unmap_output(&mut self, output: &Output) {
|
||||
self.space.unmap_output(output);
|
||||
self.refresh();
|
||||
}
|
||||
|
||||
pub fn map(
|
||||
&mut self,
|
||||
space: &mut Space,
|
||||
window: Window,
|
||||
mapped: impl Into<CosmicMapped>,
|
||||
seat: &Seat<State>,
|
||||
position: impl Into<Option<Point<i32, Logical>>>,
|
||||
) {
|
||||
if let Some(output) = super::output_from_seat(Some(seat), space) {
|
||||
self.map_window_internal(space, window, &output, position.into());
|
||||
} else {
|
||||
self.pending_windows.push(window);
|
||||
}
|
||||
let mapped = mapped.into();
|
||||
let output = seat.active_output();
|
||||
let position = position.into();
|
||||
|
||||
self.map_internal(mapped, &output, position)
|
||||
}
|
||||
|
||||
pub fn refresh(&mut self, space: &mut Space) {
|
||||
self.pending_windows.retain(|w| w.toplevel().alive());
|
||||
if let Some(output) = super::output_from_seat(None, space) {
|
||||
for window in std::mem::take(&mut self.pending_windows).into_iter() {
|
||||
self.map_window_internal(space, window, &output, None);
|
||||
}
|
||||
}
|
||||
// TODO make sure all windows are still visible on any output or move them
|
||||
}
|
||||
|
||||
fn map_window_internal(
|
||||
pub(in crate::shell) fn map_internal(
|
||||
&mut self,
|
||||
space: &mut Space,
|
||||
window: Window,
|
||||
mapped: CosmicMapped,
|
||||
output: &Output,
|
||||
position: Option<Point<i32, Logical>>,
|
||||
) {
|
||||
let last_geometry = window
|
||||
.user_data()
|
||||
.get::<WindowUserData>()
|
||||
.map(|u| u.lock().unwrap().last_geometry);
|
||||
let mut win_geo = window.geometry();
|
||||
let mut win_geo = mapped.geometry();
|
||||
|
||||
let layers = layer_map_for_output(&output);
|
||||
let geometry = layers.non_exclusive_zone();
|
||||
let last_geometry = mapped.last_geometry.lock().unwrap().clone();
|
||||
|
||||
let mut geo_updated = false;
|
||||
if let Some(size) = last_geometry.clone().map(|g| g.size) {
|
||||
if let Some(size) = last_geometry.map(|g| g.size) {
|
||||
geo_updated = win_geo.size == size;
|
||||
win_geo.size = size;
|
||||
}
|
||||
{
|
||||
let (min_size, max_size) = with_states(window.toplevel().wl_surface(), |states| {
|
||||
let attrs = states
|
||||
.data_map
|
||||
.get::<Mutex<XdgToplevelSurfaceRoleAttributes>>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap();
|
||||
(attrs.min_size, attrs.max_size)
|
||||
});
|
||||
let (min_size, max_size) = (mapped.min_size(), mapped.max_size());
|
||||
if win_geo.size.w > geometry.size.w / 3 * 2 {
|
||||
// try a more reasonable size
|
||||
let mut width = geometry.size.w / 3 * 2;
|
||||
|
|
@ -136,103 +123,67 @@ impl FloatingLayout {
|
|||
.into()
|
||||
});
|
||||
|
||||
#[allow(irrefutable_let_patterns)]
|
||||
if let Kind::Xdg(xdg) = &window.toplevel() {
|
||||
xdg.with_pending_state(|state| {
|
||||
state.states.unset(XdgState::TiledLeft);
|
||||
state.states.unset(XdgState::TiledRight);
|
||||
state.states.unset(XdgState::TiledTop);
|
||||
state.states.unset(XdgState::TiledBottom);
|
||||
if geo_updated {
|
||||
state.size = Some(win_geo.size);
|
||||
}
|
||||
});
|
||||
xdg.send_configure();
|
||||
// TODO: Move this into CosmicMapped, this needs to differciate between stacks and windows
|
||||
mapped.set_tiled(false);
|
||||
if geo_updated {
|
||||
mapped.set_size(win_geo.size);
|
||||
}
|
||||
mapped.configure();
|
||||
|
||||
space.map_window(&window, position, FLOATING_INDEX, false);
|
||||
self.windows.insert(window);
|
||||
self.space.map_element(mapped, position, false);
|
||||
}
|
||||
|
||||
pub fn unmap_window(&mut self, space: &mut Space, window: &Window) {
|
||||
pub fn unmap(&mut self, window: &CosmicMapped) -> bool {
|
||||
#[allow(irrefutable_let_patterns)]
|
||||
let is_maximized = match &window.toplevel() {
|
||||
Kind::Xdg(surface) => {
|
||||
surface.with_pending_state(|state| state.states.contains(XdgState::Maximized))
|
||||
}
|
||||
};
|
||||
let is_maximized = window.is_maximized();
|
||||
|
||||
if !is_maximized {
|
||||
if let Some(location) = space.window_location(window) {
|
||||
let user_data = window.user_data();
|
||||
user_data.insert_if_missing(|| WindowUserData::default());
|
||||
user_data
|
||||
.get::<WindowUserData>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap()
|
||||
.last_geometry = Rectangle::from_loc_and_size(location, window.geometry().size);
|
||||
if let Some(location) = self.space.element_location(window) {
|
||||
*window.last_geometry.lock().unwrap() = Some(Rectangle::from_loc_and_size(
|
||||
location,
|
||||
window.geometry().size,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
space.unmap_window(window);
|
||||
self.pending_windows.retain(|w| w != window);
|
||||
self.windows.remove(window);
|
||||
let was_unmaped = self.space.elements().any(|e| e == window);
|
||||
self.space.unmap_elem(&window);
|
||||
was_unmaped
|
||||
}
|
||||
|
||||
pub fn maximize_request(&mut self, space: &mut Space, window: &Window, output: &Output) {
|
||||
pub fn element_geometry(&self, elem: &CosmicMapped) -> Option<Rectangle<i32, Logical>> {
|
||||
self.space.element_geometry(elem)
|
||||
}
|
||||
|
||||
pub fn maximize_request(&mut self, window: &CosmicMapped, output: &Output) {
|
||||
let layers = layer_map_for_output(&output);
|
||||
let geometry = layers.non_exclusive_zone();
|
||||
|
||||
if let Some(location) = space.window_location(window) {
|
||||
let user_data = window.user_data();
|
||||
user_data.insert_if_missing(|| WindowUserData::default());
|
||||
user_data
|
||||
.get::<WindowUserData>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap()
|
||||
.last_geometry = Rectangle::from_loc_and_size(location, window.geometry().size);
|
||||
if let Some(location) = self.space.element_location(window) {
|
||||
*window.last_geometry.lock().unwrap() = Some(Rectangle::from_loc_and_size(
|
||||
location,
|
||||
window.geometry().size,
|
||||
));
|
||||
}
|
||||
|
||||
space.map_window(
|
||||
&window,
|
||||
(geometry.loc.x, geometry.loc.y),
|
||||
FLOATING_INDEX,
|
||||
true,
|
||||
);
|
||||
#[allow(irrefutable_let_patterns)]
|
||||
if let Kind::Xdg(surface) = &window.toplevel() {
|
||||
surface.with_pending_state(|state| {
|
||||
state.states.set(XdgState::Maximized);
|
||||
state.size = Some(geometry.size);
|
||||
});
|
||||
window.configure();
|
||||
}
|
||||
self.space.map_element(window.clone(), geometry.loc, true);
|
||||
window.set_maximized(true);
|
||||
window.set_size(geometry.size);
|
||||
window.configure();
|
||||
}
|
||||
|
||||
pub fn unmaximize_request(&mut self, space: &mut Space, window: &Window) {
|
||||
let last_geometry = window
|
||||
.user_data()
|
||||
.get::<WindowUserData>()
|
||||
.map(|u| u.lock().unwrap().last_geometry);
|
||||
match window.toplevel() {
|
||||
Kind::Xdg(toplevel) => {
|
||||
toplevel.with_pending_state(|state| {
|
||||
state.states.unset(XdgState::Maximized);
|
||||
state.size = last_geometry.map(|g| g.size);
|
||||
});
|
||||
toplevel.send_configure();
|
||||
}
|
||||
}
|
||||
if let Some(last_location) = last_geometry.map(|g| g.loc) {
|
||||
space.map_window(&window, last_location, FLOATING_INDEX, true);
|
||||
}
|
||||
pub fn unmaximize_request(&mut self, window: &CosmicMapped) {
|
||||
let last_geometry = window.last_geometry.lock().unwrap().clone();
|
||||
window.set_maximized(false);
|
||||
window.set_size(last_geometry.map(|g| g.size).expect("No previous size?"));
|
||||
window.configure();
|
||||
let last_location = last_geometry.map(|g| g.loc).expect("No previous location?");
|
||||
self.space.map_element(window.clone(), last_location, true);
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn resize_request(
|
||||
state: &mut State,
|
||||
window: &Window,
|
||||
window: &CosmicWindow,
|
||||
seat: &Seat<State>,
|
||||
serial: Serial,
|
||||
start_data: PointerGrabStartData<State>,
|
||||
|
|
@ -256,4 +207,111 @@ impl FloatingLayout {
|
|||
pointer.set_grab(state, grab, serial, Focus::Clear);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn mapped(&self) -> impl Iterator<Item = &CosmicMapped> {
|
||||
self.space.elements()
|
||||
}
|
||||
|
||||
pub fn windows(&self) -> impl Iterator<Item = Window> + '_ {
|
||||
self.mapped().flat_map(|e| e.windows().map(|(w, _)| w))
|
||||
}
|
||||
|
||||
pub fn refresh(&mut self) {
|
||||
for element in self
|
||||
.space
|
||||
.elements()
|
||||
.filter(|e| self.space.outputs_for_element(e).is_empty())
|
||||
.cloned()
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
{
|
||||
// TODO what about windows leaving to the top with no headerbar to drag? can that happen? (Probably if the user is moving outputs down)
|
||||
*element.last_geometry.lock().unwrap() = None;
|
||||
let output = self.space.outputs().next().unwrap().clone();
|
||||
self.map_internal(element, &output, None);
|
||||
}
|
||||
self.space.refresh()
|
||||
}
|
||||
|
||||
pub fn most_overlapped_output_for_element(&self, elem: &CosmicMapped) -> Option<Output> {
|
||||
let elem_geo = self.space.element_geometry(elem)?;
|
||||
|
||||
if self.space.outputs().nth(1).is_none() {
|
||||
return self.space.outputs().next().cloned();
|
||||
}
|
||||
|
||||
Some(
|
||||
self.space
|
||||
.outputs_for_element(elem)
|
||||
.into_iter()
|
||||
.max_by_key(|o| {
|
||||
let output_geo = self.space.output_geometry(o).unwrap();
|
||||
if let Some(intersection) = output_geo.intersection(elem_geo) {
|
||||
intersection.size.w * intersection.size.h
|
||||
} else {
|
||||
0
|
||||
}
|
||||
})
|
||||
.unwrap_or(self.space.outputs().next().unwrap().clone()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn merge(&mut self, other: FloatingLayout) {
|
||||
let mut output_pos_map = HashMap::new();
|
||||
for output in self.space.outputs() {
|
||||
output_pos_map.insert(
|
||||
output.clone(),
|
||||
self.space.output_geometry(output).unwrap().loc
|
||||
- other
|
||||
.space
|
||||
.output_geometry(output)
|
||||
.map(|geo| geo.loc)
|
||||
.unwrap_or_else(|| (0, 0).into()),
|
||||
);
|
||||
}
|
||||
for element in other.space.elements() {
|
||||
let mut elem_geo = other.space.element_geometry(element).unwrap();
|
||||
let output = other
|
||||
.space
|
||||
.outputs_for_element(element)
|
||||
.into_iter()
|
||||
.filter(|o| self.space.outputs().any(|o2| o == o2))
|
||||
.max_by_key(|o| {
|
||||
let output_geo = other.space.output_geometry(o).unwrap();
|
||||
let intersection = output_geo.intersection(elem_geo).unwrap();
|
||||
intersection.size.w * intersection.size.h
|
||||
})
|
||||
.unwrap_or(self.space.outputs().next().unwrap().clone());
|
||||
elem_geo.loc += output_pos_map
|
||||
.get(&output)
|
||||
.copied()
|
||||
.unwrap_or_else(|| (0, 0).into());
|
||||
self.space.map_element(element.clone(), elem_geo.loc, false);
|
||||
}
|
||||
self.refresh(); //fixup any out of bounds elements
|
||||
}
|
||||
|
||||
pub fn render_output<R>(
|
||||
&self,
|
||||
output: &Output,
|
||||
) -> Result<Vec<FloatingRenderElement<R>>, OutputNotMapped>
|
||||
where
|
||||
R: Renderer + ImportAll,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
{
|
||||
let output_scale = output.current_scale().fractional_scale();
|
||||
let output_geo = self.space.output_geometry(output).ok_or(OutputNotMapped)?;
|
||||
Ok(self
|
||||
.space
|
||||
.render_elements_for_region::<R, _>(&output_geo, output_scale)
|
||||
.into_iter()
|
||||
.map(FloatingRenderElement::from)
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
|
||||
render_elements! {
|
||||
pub FloatingRenderElement<R> where R: ImportAll;
|
||||
Window=CosmicMappedRenderElement<R>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::{input::ActiveOutput, state::State};
|
||||
use regex::RegexSet;
|
||||
use smithay::{
|
||||
desktop::{Space, Window},
|
||||
input::Seat,
|
||||
output::Output,
|
||||
desktop::Window,
|
||||
wayland::{compositor::with_states, shell::xdg::XdgToplevelSurfaceRoleAttributes},
|
||||
};
|
||||
use std::sync::Mutex;
|
||||
|
|
@ -118,17 +115,3 @@ pub fn should_be_floating(window: &Window) -> bool {
|
|||
false
|
||||
})
|
||||
}
|
||||
|
||||
fn output_from_seat(seat: Option<&Seat<State>>, space: &Space) -> Option<Output> {
|
||||
seat.and_then(|seat| {
|
||||
seat.user_data()
|
||||
.get::<ActiveOutput>()
|
||||
.map(|active| active.0.borrow().clone())
|
||||
.or_else(|| {
|
||||
seat.get_pointer()
|
||||
.map(|ptr| space.output_under(ptr.current_location()).next().unwrap())
|
||||
.cloned()
|
||||
})
|
||||
})
|
||||
.or_else(|| space.outputs().next().cloned())
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
1223
src/shell/mod.rs
1223
src/shell/mod.rs
File diff suppressed because it is too large
Load diff
|
|
@ -1,79 +1,179 @@
|
|||
use crate::{
|
||||
shell::layout::{floating::FloatingLayout, tiling::TilingLayout},
|
||||
shell::{
|
||||
element::CosmicWindow,
|
||||
layout::{floating::FloatingLayout, tiling::TilingLayout},
|
||||
},
|
||||
state::State,
|
||||
utils::prelude::*,
|
||||
wayland::protocols::workspace::WorkspaceHandle,
|
||||
};
|
||||
|
||||
use indexmap::IndexSet;
|
||||
use smithay::{
|
||||
desktop::{Kind, Space, Window, WindowSurfaceType},
|
||||
backend::renderer::{
|
||||
element::{surface::WaylandSurfaceRenderElement, AsRenderElements},
|
||||
ImportAll, Renderer,
|
||||
},
|
||||
desktop::{
|
||||
layer_map_for_output, space::SpaceElement, Kind, LayerSurface, Space, Window,
|
||||
WindowSurfaceType,
|
||||
},
|
||||
input::{pointer::GrabStartData as PointerGrabStartData, Seat},
|
||||
output::Output,
|
||||
output::{Output, WeakOutput},
|
||||
reexports::{
|
||||
wayland_protocols::xdg::shell::server::xdg_toplevel::{self, ResizeEdge},
|
||||
wayland_server::{protocol::wl_surface::WlSurface, DisplayHandle},
|
||||
},
|
||||
utils::{IsAlive, Serial},
|
||||
render_elements,
|
||||
utils::{IsAlive, Logical, Point, Rectangle, Scale, Serial},
|
||||
wayland::shell::wlr_layer::Layer,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, time::Duration};
|
||||
|
||||
use super::{
|
||||
element::CosmicMapped,
|
||||
focus::{FocusStack, FocusStackMut},
|
||||
layout::{floating::FloatingRenderElement, tiling::TilingRenderElement},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Workspace {
|
||||
pub idx: u8,
|
||||
pub space: Space,
|
||||
pub tiling_layer: TilingLayout,
|
||||
pub floating_layer: FloatingLayout,
|
||||
tiling_enabled: bool,
|
||||
pub fullscreen: HashMap<String, Window>,
|
||||
pub tiling_enabled: bool,
|
||||
pub fullscreen: HashMap<Output, Window>,
|
||||
pub handle: WorkspaceHandle,
|
||||
pub focus_stack: FocusStacks,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct FocusStacks(HashMap<Seat<State>, IndexSet<CosmicMapped>>);
|
||||
|
||||
impl Workspace {
|
||||
pub fn new(idx: u8, handle: WorkspaceHandle) -> Workspace {
|
||||
pub fn new(handle: WorkspaceHandle) -> Workspace {
|
||||
Workspace {
|
||||
idx,
|
||||
space: Space::new(None),
|
||||
tiling_layer: TilingLayout::new(),
|
||||
floating_layer: FloatingLayout::new(),
|
||||
tiling_enabled: true,
|
||||
fullscreen: HashMap::new(),
|
||||
handle,
|
||||
focus_stack: FocusStacks::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn refresh(&mut self, dh: &DisplayHandle) {
|
||||
let outputs = self.space.outputs().collect::<Vec<_>>();
|
||||
let dead_output_windows = self
|
||||
.fullscreen
|
||||
.iter()
|
||||
.filter(|(name, _)| !outputs.iter().any(|o| o.name() == **name))
|
||||
.map(|(_, w)| w)
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
for window in dead_output_windows {
|
||||
self.unfullscreen_request(&window);
|
||||
}
|
||||
pub fn refresh(&mut self) {
|
||||
self.fullscreen.retain(|_, w| w.alive());
|
||||
self.floating_layer.refresh(&mut self.space);
|
||||
self.tiling_layer.refresh(&mut self.space);
|
||||
self.space.refresh(dh);
|
||||
self.floating_layer.refresh();
|
||||
self.tiling_layer.refresh();
|
||||
}
|
||||
|
||||
pub fn maximize_request(&mut self, window: &Window, output: &Output) {
|
||||
pub fn commit(&mut self, surface: &WlSurface) {
|
||||
if let Some(mapped) = self.element_for_surface(surface) {
|
||||
mapped
|
||||
.windows()
|
||||
.find(|(w, _)| w.toplevel().wl_surface() == surface)
|
||||
.unwrap()
|
||||
.0
|
||||
.on_commit();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_output(&mut self, output: &Output, position: Point<i32, Logical>) {
|
||||
self.tiling_layer.map_output(output, position);
|
||||
self.floating_layer.map_output(output, position);
|
||||
}
|
||||
|
||||
pub fn unmap_output(&mut self, output: &Output) {
|
||||
if let Some(dead_output_window) = self.fullscreen.remove(output) {
|
||||
self.unfullscreen_request(&dead_output_window);
|
||||
}
|
||||
self.tiling_layer.unmap_output(output);
|
||||
self.floating_layer.unmap_output(output);
|
||||
self.refresh();
|
||||
}
|
||||
|
||||
pub fn element_for_surface(&self, surface: &WlSurface) -> Option<&CosmicMapped> {
|
||||
self.floating_layer
|
||||
.mapped()
|
||||
.chain(self.tiling_layer.mapped().map(|(_, w, _)| w))
|
||||
.find(|e| {
|
||||
e.windows()
|
||||
.any(|(w, _)| w.toplevel().wl_surface() == surface)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn outputs_for_element(&self, elem: &CosmicMapped) -> impl Iterator<Item = Output> {
|
||||
self.floating_layer
|
||||
.space
|
||||
.outputs_for_element(elem)
|
||||
.into_iter()
|
||||
.chain(self.tiling_layer.output_for_element(elem).cloned())
|
||||
}
|
||||
|
||||
pub fn output_under(&self, point: Point<i32, Logical>) -> Option<&Output> {
|
||||
let space = &self.floating_layer.space;
|
||||
space.outputs().find(|o| {
|
||||
let internal_output_geo = space.output_geometry(o).unwrap();
|
||||
let external_output_geo = o.geometry();
|
||||
internal_output_geo.contains(point - external_output_geo.loc + internal_output_geo.loc)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn element_under(
|
||||
&self,
|
||||
location: Point<f64, Logical>,
|
||||
) -> Option<(&CosmicMapped, Point<i32, Logical>)> {
|
||||
self.floating_layer
|
||||
.space
|
||||
.element_under(location)
|
||||
.or_else(|| {
|
||||
self.tiling_layer.mapped().find_map(|(_, mapped, loc)| {
|
||||
let test_point = location - loc.to_f64();
|
||||
mapped
|
||||
.is_in_input_region(&test_point)
|
||||
.then_some((mapped, loc))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub fn element_geometry(&self, elem: &CosmicMapped) -> Option<Rectangle<i32, Logical>> {
|
||||
let space = &self.floating_layer.space;
|
||||
let outputs = space.outputs().collect::<Vec<_>>();
|
||||
let offset = if outputs.len() == 1
|
||||
&& space.output_geometry(&outputs[0]).unwrap().loc == Point::from((0, 0))
|
||||
{
|
||||
outputs[0].geometry().loc
|
||||
} else {
|
||||
(0, 0).into()
|
||||
};
|
||||
|
||||
self.floating_layer
|
||||
.space
|
||||
.element_geometry(elem)
|
||||
.or_else(|| self.tiling_layer.element_geometry(elem))
|
||||
.map(|mut geo| {
|
||||
geo.loc += offset;
|
||||
geo
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn maximize_request(&mut self, window: &CosmicWindow, output: &Output) {
|
||||
if self.fullscreen.values().any(|w| w == window) {
|
||||
return;
|
||||
}
|
||||
if self.floating_layer.windows.contains(window) {
|
||||
self.floating_layer
|
||||
.maximize_request(&mut self.space, window, output);
|
||||
.maximize_request(, window, output);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unmaximize_request(&mut self, window: &Window) {
|
||||
pub fn unmaximize_request(&mut self, window: &CosmicMapped) {
|
||||
if self.fullscreen.values().any(|w| w == window) {
|
||||
return self.unfullscreen_request(window);
|
||||
}
|
||||
if self.floating_layer.windows.contains(window) {
|
||||
self.floating_layer
|
||||
.unmaximize_request(&mut self.space, window);
|
||||
.unmaximize_request(window);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -101,9 +201,10 @@ impl Workspace {
|
|||
TilingLayout::resize_request(state, &window, seat, serial, start_data, edges)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn fullscreen_request(&mut self, window: &Window, output: &Output) {
|
||||
if self.fullscreen.contains_key(&output.name()) {
|
||||
if self.fullscreen.contains_key(output) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +224,7 @@ impl Workspace {
|
|||
});
|
||||
|
||||
xdg.send_configure();
|
||||
self.fullscreen.insert(output.name(), window.clone());
|
||||
self.fullscreen.insert(output.clone(), window.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -135,8 +236,8 @@ impl Workspace {
|
|||
state.states.unset(xdg_toplevel::State::Fullscreen);
|
||||
state.size = None;
|
||||
});
|
||||
self.floating_layer.refresh(&mut self.space);
|
||||
self.tiling_layer.refresh(&mut self.space);
|
||||
self.floating_layer.refresh();
|
||||
self.tiling_layer.refresh();
|
||||
xdg.send_configure();
|
||||
}
|
||||
self.fullscreen.retain(|_, w| w != window);
|
||||
|
|
@ -144,7 +245,7 @@ impl Workspace {
|
|||
}
|
||||
|
||||
pub fn fullscreen_toggle(&mut self, window: &Window, output: &Output) {
|
||||
if self.fullscreen.contains_key(&output.name()) {
|
||||
if self.fullscreen.contains_key(output) {
|
||||
self.unfullscreen_request(window)
|
||||
} else {
|
||||
self.fullscreen_request(window, output)
|
||||
|
|
@ -152,26 +253,33 @@ impl Workspace {
|
|||
}
|
||||
|
||||
pub fn get_fullscreen(&self, output: &Output) -> Option<&Window> {
|
||||
if !self.space.outputs().any(|o| o == output) {
|
||||
return None;
|
||||
}
|
||||
self.fullscreen.get(&output.name()).filter(|w| w.alive())
|
||||
self.fullscreen.get(output).filter(|w| w.alive())
|
||||
}
|
||||
|
||||
pub fn toggle_tiling(&mut self, seat: &Seat<State>) {
|
||||
if self.tiling_enabled {
|
||||
for window in self.tiling_layer.windows.clone().into_iter() {
|
||||
self.tiling_layer.unmap_window(&mut self.space, &window);
|
||||
self.floating_layer
|
||||
.map_window(&mut self.space, window, seat, None);
|
||||
for window in self
|
||||
.tiling_layer
|
||||
.mapped()
|
||||
.map(|(_, m, _)| m.clone())
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
{
|
||||
self.tiling_layer.unmap(&window);
|
||||
self.floating_layer.map(window, seat, None);
|
||||
}
|
||||
self.tiling_enabled = false;
|
||||
} else {
|
||||
let focus_stack = self.focus_stack(seat);
|
||||
for window in self.floating_layer.windows.clone().into_iter() {
|
||||
self.floating_layer.unmap_window(&mut self.space, &window);
|
||||
self.tiling_layer
|
||||
.map_window(&mut self.space, window, seat, focus_stack.iter())
|
||||
let focus_stack = self.focus_stack.get(seat);
|
||||
for window in self
|
||||
.floating_layer
|
||||
.mapped()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
{
|
||||
self.floating_layer.unmap(&window);
|
||||
self.tiling_layer.map(window, seat, focus_stack.iter())
|
||||
}
|
||||
self.tiling_enabled = true;
|
||||
}
|
||||
|
|
@ -179,18 +287,157 @@ impl Workspace {
|
|||
|
||||
pub fn toggle_floating_window(&mut self, seat: &Seat<State>) {
|
||||
if self.tiling_enabled {
|
||||
if let Some(window) = self.focus_stack(seat).iter().next().cloned() {
|
||||
if self.tiling_layer.windows.contains(&window) {
|
||||
self.tiling_layer.unmap_window(&mut self.space, &window);
|
||||
self.floating_layer
|
||||
.map_window(&mut self.space, window, seat, None);
|
||||
} else if self.floating_layer.windows.contains(&window) {
|
||||
let focus_stack = self.focus_stack(seat);
|
||||
self.floating_layer.unmap_window(&mut self.space, &window);
|
||||
self.tiling_layer
|
||||
.map_window(&mut self.space, window, seat, focus_stack.iter())
|
||||
if let Some(window) = self.focus_stack.get(seat).iter().next().cloned() {
|
||||
if self.tiling_layer.mapped().any(|(_, m, _)| m == &window) {
|
||||
self.tiling_layer.unmap(&window);
|
||||
self.floating_layer.map(window, seat, None);
|
||||
} else if self.floating_layer.mapped().any(|w| w == &window) {
|
||||
let focus_stack = self.focus_stack.get(seat);
|
||||
self.floating_layer.unmap(&window);
|
||||
self.tiling_layer.map(window, seat, focus_stack.iter())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mapped(&self) -> impl Iterator<Item = &CosmicMapped> {
|
||||
self.floating_layer
|
||||
.mapped()
|
||||
.chain(self.tiling_layer.mapped().map(|(_, w, _)| w))
|
||||
}
|
||||
|
||||
pub fn windows(&self) -> impl Iterator<Item = Window> + '_ {
|
||||
self.floating_layer
|
||||
.windows()
|
||||
.chain(self.tiling_layer.windows().map(|(_, w, _)| w))
|
||||
}
|
||||
|
||||
pub fn render_output<R>(
|
||||
&self,
|
||||
output: &Output,
|
||||
) -> Result<Vec<WorkspaceRenderElement<R>>, OutputNotMapped>
|
||||
where
|
||||
R: Renderer + ImportAll,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
{
|
||||
let mut render_elements = Vec::new();
|
||||
|
||||
let output_scale = output.current_scale().fractional_scale();
|
||||
let layer_map = layer_map_for_output(output);
|
||||
|
||||
if let Some(fullscreen) = self.fullscreen.get(output) {
|
||||
// overlay layer surfaces
|
||||
render_elements.extend(
|
||||
layer_map
|
||||
.layers()
|
||||
.rev()
|
||||
.filter(|s| s.layer() == Layer::Overlay)
|
||||
.filter_map(|surface| {
|
||||
layer_map
|
||||
.layer_geometry(surface)
|
||||
.map(|geo| (geo.loc, surface))
|
||||
})
|
||||
.flat_map(|(loc, surface)| {
|
||||
AsRenderElements::<R>::render_elements::<WorkspaceRenderElement<R>>(
|
||||
surface,
|
||||
loc.to_physical_precise_round(output_scale),
|
||||
Scale::from(output_scale),
|
||||
)
|
||||
}),
|
||||
);
|
||||
|
||||
// fullscreen window
|
||||
render_elements.extend(AsRenderElements::<R>::render_elements::<
|
||||
WorkspaceRenderElement<R>,
|
||||
>(fullscreen, (0, 0).into(), output_scale.into()));
|
||||
} else {
|
||||
// TODO: Handle modes like
|
||||
// - keyboard window swapping
|
||||
// - resizing / moving in tiling
|
||||
|
||||
// overlay and top layer surfaces
|
||||
let lower = {
|
||||
let (upper, lower): (Vec<&LayerSurface>, Vec<&LayerSurface>) = layer_map
|
||||
.layers()
|
||||
.rev()
|
||||
.partition(|s| matches!(s.layer(), Layer::Background | Layer::Bottom));
|
||||
|
||||
render_elements.extend(
|
||||
upper
|
||||
.into_iter()
|
||||
.filter_map(|surface| {
|
||||
layer_map
|
||||
.layer_geometry(surface)
|
||||
.map(|geo| (geo.loc, surface))
|
||||
})
|
||||
.flat_map(|(loc, surface)| {
|
||||
AsRenderElements::<R>::render_elements::<WorkspaceRenderElement<R>>(
|
||||
surface,
|
||||
loc.to_physical_precise_round(output_scale),
|
||||
Scale::from(output_scale),
|
||||
)
|
||||
}),
|
||||
);
|
||||
|
||||
lower
|
||||
};
|
||||
|
||||
// floating surfaces
|
||||
render_elements.extend(
|
||||
self.floating_layer
|
||||
.render_output::<R>(output)?
|
||||
.into_iter()
|
||||
.map(WorkspaceRenderElement::from),
|
||||
);
|
||||
|
||||
//tiling surfaces
|
||||
render_elements.extend(
|
||||
self.tiling_layer
|
||||
.render_output::<R>(output)?
|
||||
.into_iter()
|
||||
.map(WorkspaceRenderElement::from),
|
||||
);
|
||||
|
||||
// bottom and background layer surfaces
|
||||
{
|
||||
render_elements.extend(
|
||||
lower
|
||||
.into_iter()
|
||||
.filter_map(|surface| {
|
||||
layer_map
|
||||
.layer_geometry(surface)
|
||||
.map(|geo| (geo.loc, surface))
|
||||
})
|
||||
.flat_map(|(loc, surface)| {
|
||||
AsRenderElements::<R>::render_elements::<WorkspaceRenderElement<R>>(
|
||||
surface,
|
||||
loc.to_physical_precise_round(output_scale),
|
||||
Scale::from(output_scale),
|
||||
)
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(render_elements)
|
||||
}
|
||||
}
|
||||
|
||||
impl FocusStacks {
|
||||
pub fn get<'a>(&'a self, seat: &Seat<State>) -> FocusStack<'a> {
|
||||
FocusStack(self.0.get(seat))
|
||||
}
|
||||
|
||||
pub fn get_mut<'a>(&'a mut self, seat: &Seat<State>) -> FocusStackMut<'a> {
|
||||
FocusStackMut(self.0.entry(seat.clone()).or_default())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OutputNotMapped;
|
||||
|
||||
render_elements! {
|
||||
pub WorkspaceRenderElement<R> where R: ImportAll;
|
||||
Wayland=WaylandSurfaceRenderElement,
|
||||
Floating=FloatingRenderElement<R>,
|
||||
Tiling=TilingRenderElement<R>,
|
||||
}
|
||||
|
|
|
|||
152
src/state.rs
152
src/state.rs
|
|
@ -7,8 +7,8 @@ use crate::{
|
|||
shell::Shell,
|
||||
utils::prelude::*,
|
||||
wayland::protocols::{
|
||||
drm::WlDrmState, export_dmabuf::ExportDmabufState,
|
||||
output_configuration::OutputConfigurationState, workspace::WorkspaceClientState,
|
||||
drm::WlDrmState, output_configuration::OutputConfigurationState,
|
||||
workspace::WorkspaceClientState,
|
||||
},
|
||||
};
|
||||
use smithay::{
|
||||
|
|
@ -22,7 +22,6 @@ use smithay::{
|
|||
Display, DisplayHandle,
|
||||
},
|
||||
},
|
||||
utils::{Buffer, Size},
|
||||
wayland::{
|
||||
compositor::CompositorState, data_device::DataDeviceState, dmabuf::DmabufState,
|
||||
keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitState, output::OutputManagerState,
|
||||
|
|
@ -71,8 +70,8 @@ pub struct Common {
|
|||
pub shell: Shell,
|
||||
pub dirty_flag: Arc<AtomicBool>,
|
||||
|
||||
pub seats: Vec<Seat<State>>,
|
||||
pub last_active_seat: Seat<State>,
|
||||
seats: Vec<Seat<State>>,
|
||||
last_active_seat: Option<Seat<State>>,
|
||||
|
||||
pub start_time: Instant,
|
||||
pub should_stop: bool,
|
||||
|
|
@ -85,7 +84,6 @@ pub struct Common {
|
|||
pub compositor_state: CompositorState,
|
||||
pub data_device_state: DataDeviceState,
|
||||
pub dmabuf_state: DmabufState,
|
||||
pub export_dmabuf_state: ExportDmabufState,
|
||||
pub keyboard_shortcuts_inhibit_state: KeyboardShortcutsInhibitState,
|
||||
pub output_state: OutputManagerState,
|
||||
pub output_configuration_state: OutputConfigurationState<State>,
|
||||
|
|
@ -201,88 +199,6 @@ impl BackendData {
|
|||
_ => unreachable!("No backend was initialized"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn offscreen_for_output(
|
||||
&mut self,
|
||||
output: &Output,
|
||||
state: &mut Common,
|
||||
) -> anyhow::Result<(Vec<u8>, Size<i32, Buffer>)> {
|
||||
use crate::backend::render::{render_output, AsGles2Renderer, CustomElem};
|
||||
use anyhow::Context;
|
||||
use smithay::backend::renderer::{ImportAll, Renderer};
|
||||
use smithay::desktop::space::RenderElement;
|
||||
use smithay::{
|
||||
backend::{
|
||||
drm::NodeType,
|
||||
renderer::{gles2::Gles2Renderbuffer, Bind, ExportMem, Offscreen},
|
||||
},
|
||||
utils::Rectangle,
|
||||
};
|
||||
|
||||
fn capture<E, T, R>(
|
||||
gpu: Option<DrmNode>,
|
||||
renderer: &mut R,
|
||||
output: &Output,
|
||||
state: &mut Common,
|
||||
) -> anyhow::Result<(Vec<u8>, Size<i32, Buffer>)>
|
||||
where
|
||||
E: std::error::Error + Send + Sync + 'static,
|
||||
T: Clone + 'static,
|
||||
R: Renderer<Error = E, TextureId = T>
|
||||
+ ImportAll
|
||||
+ AsGles2Renderer
|
||||
+ Offscreen<Gles2Renderbuffer>
|
||||
+ Bind<Gles2Renderbuffer>
|
||||
+ ExportMem,
|
||||
CustomElem: RenderElement<R>,
|
||||
{
|
||||
let size = output
|
||||
.geometry()
|
||||
.size
|
||||
.to_f64()
|
||||
.to_buffer(
|
||||
output.current_scale().fractional_scale(),
|
||||
output.current_transform().into(),
|
||||
)
|
||||
.to_i32_round();
|
||||
let buffer = Offscreen::<Gles2Renderbuffer>::create_buffer(renderer, size)?;
|
||||
renderer.bind(buffer)?;
|
||||
render_output(
|
||||
gpu.as_ref(),
|
||||
renderer,
|
||||
0,
|
||||
state,
|
||||
output,
|
||||
false,
|
||||
#[cfg(feature = "debug")]
|
||||
None,
|
||||
)
|
||||
.map_err(|err| anyhow::anyhow!("Failed to render output: {:?}", err))?; // lifetime issue, grrr
|
||||
let mapping = renderer.copy_framebuffer(Rectangle::from_loc_and_size((0, 0), size))?;
|
||||
let data = Vec::from(renderer.map_texture(&mapping)?);
|
||||
|
||||
Ok((data, size))
|
||||
}
|
||||
|
||||
match self {
|
||||
BackendData::Winit(winit) => capture(None, winit.backend.renderer(), output, state),
|
||||
BackendData::X11(x11) => capture(None, &mut x11.renderer, output, state),
|
||||
BackendData::Kms(kms) => {
|
||||
let node = kms
|
||||
.target_node_for_output(output)
|
||||
.unwrap_or(kms.primary)
|
||||
.node_with_type(NodeType::Render)
|
||||
.with_context(|| "Unable to find node")??;
|
||||
capture(
|
||||
Some(node),
|
||||
&mut kms.api.renderer::<Gles2Renderbuffer>(&node, &node)?,
|
||||
output,
|
||||
state,
|
||||
)
|
||||
}
|
||||
BackendData::Unset => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl State {
|
||||
|
|
@ -297,22 +213,16 @@ impl State {
|
|||
let compositor_state = CompositorState::new::<Self, _>(dh, None);
|
||||
let data_device_state = DataDeviceState::new::<Self, _>(dh, None);
|
||||
let dmabuf_state = DmabufState::new();
|
||||
let export_dmabuf_state = ExportDmabufState::new::<Self, _>(
|
||||
dh,
|
||||
//|client| client.get_data::<ClientState>().unwrap().privileged,
|
||||
|_| true,
|
||||
);
|
||||
let keyboard_shortcuts_inhibit_state = KeyboardShortcutsInhibitState::new::<Self>(dh);
|
||||
let output_state = OutputManagerState::new_with_xdg_output::<Self>(dh);
|
||||
let output_configuration_state = OutputConfigurationState::new(dh, |_| true);
|
||||
let primary_selection_state = PrimarySelectionState::new::<Self, _>(dh, None);
|
||||
let shm_state = ShmState::new::<Self, _>(dh, vec![], None);
|
||||
let mut seat_state = SeatState::<Self>::new();
|
||||
let seat_state = SeatState::<Self>::new();
|
||||
let viewporter_state = ViewporterState::new::<Self, _>(dh, None);
|
||||
let wl_drm_state = WlDrmState;
|
||||
|
||||
let shell = Shell::new(&config, dh);
|
||||
let initial_seat = crate::input::add_seat(dh, &mut seat_state, &config, "seat-0".into());
|
||||
|
||||
#[cfg(not(feature = "debug"))]
|
||||
let dirty_flag = Arc::new(AtomicBool::new(false));
|
||||
|
|
@ -330,8 +240,8 @@ impl State {
|
|||
shell,
|
||||
dirty_flag,
|
||||
|
||||
seats: vec![initial_seat.clone()],
|
||||
last_active_seat: initial_seat,
|
||||
seats: Vec::new(),
|
||||
last_active_seat: None,
|
||||
|
||||
start_time: Instant::now(),
|
||||
should_stop: false,
|
||||
|
|
@ -354,7 +264,6 @@ impl State {
|
|||
compositor_state,
|
||||
data_device_state,
|
||||
dmabuf_state,
|
||||
export_dmabuf_state,
|
||||
shm_state,
|
||||
seat_state,
|
||||
keyboard_shortcuts_inhibit_state,
|
||||
|
|
@ -376,10 +285,9 @@ impl State {
|
|||
match std::env::var("COSMIC_RENDER_AUTO_ASSIGN").map(|val| val.to_lowercase()) {
|
||||
Ok(val) if val == "y" || val == "yes" || val == "true" => Some(
|
||||
kms_state
|
||||
.target_node_for_output(&active_output(
|
||||
&self.common.last_active_seat,
|
||||
&self.common,
|
||||
))
|
||||
.target_node_for_output(
|
||||
&self.common.last_active_seat().active_output(),
|
||||
)
|
||||
.unwrap_or(kms_state.primary),
|
||||
),
|
||||
_ => Some(kms_state.primary),
|
||||
|
|
@ -415,6 +323,46 @@ impl State {
|
|||
}
|
||||
}
|
||||
|
||||
impl Common {
|
||||
pub fn add_seat(&mut self, seat: Seat<State>) {
|
||||
if self.seats.is_empty() {
|
||||
self.last_active_seat = Some(seat.clone());
|
||||
}
|
||||
self.seats.push(seat);
|
||||
}
|
||||
|
||||
pub fn remove_seat(&mut self, seat: &Seat<State>) {
|
||||
self.seats.retain(|s| s != seat);
|
||||
if self.seats.is_empty() {
|
||||
self.last_active_seat = None;
|
||||
} else if self.last_active_seat() == seat {
|
||||
self.last_active_seat = Some(self.seats[0].clone());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn seats(&self) -> impl Iterator<Item = &Seat<State>> {
|
||||
self.seats.iter()
|
||||
}
|
||||
|
||||
pub fn last_active_seat(&self) -> &Seat<State> {
|
||||
self.last_active_seat.as_ref().expect("No seat?")
|
||||
}
|
||||
|
||||
pub fn send_frames(&self, output: &Output) {
|
||||
let workspace = self.shell.active_space(output);
|
||||
workspace.mapped().for_each(|mapped| {
|
||||
if workspace.outputs_for_element(mapped).any(|o| &o == output) {
|
||||
let window = mapped.active_window();
|
||||
window.send_frame(self.start_time.elapsed().as_millis() as u32)
|
||||
}
|
||||
});
|
||||
let map = smithay::desktop::layer_map_for_output(output);
|
||||
for layer_surface in map.layers() {
|
||||
layer_surface.send_frame(self.start_time.elapsed().as_millis() as u32)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
impl Fps {
|
||||
const WINDOW_SIZE: usize = 100;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ use smithay::{
|
|||
output::Output,
|
||||
utils::{Logical, Rectangle, Transform},
|
||||
};
|
||||
use std::cell::RefCell;
|
||||
|
||||
pub use crate::shell::{Shell, Workspace};
|
||||
pub use crate::state::{Common, State};
|
||||
|
|
@ -32,34 +31,25 @@ impl OutputExt for Output {
|
|||
|
||||
pub trait SeatExt {
|
||||
fn id(&self) -> usize;
|
||||
|
||||
fn active_output(&self) -> Output;
|
||||
fn set_active_output(&self, output: &Output);
|
||||
}
|
||||
|
||||
impl SeatExt for Seat<State> {
|
||||
fn id(&self) -> usize {
|
||||
self.user_data().get::<SeatId>().unwrap().0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn active_output(seat: &Seat<State>, state: &Common) -> Output {
|
||||
seat.user_data()
|
||||
.get::<ActiveOutput>()
|
||||
.map(|x| x.0.borrow().clone())
|
||||
.unwrap_or_else(|| {
|
||||
state
|
||||
.shell
|
||||
.outputs()
|
||||
.next()
|
||||
.cloned()
|
||||
.expect("Backend has no outputs?")
|
||||
})
|
||||
}
|
||||
fn active_output(&self) -> Output {
|
||||
self.user_data()
|
||||
.get::<ActiveOutput>()
|
||||
.map(|x| x.0.borrow().clone())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn set_active_output(seat: &Seat<State>, output: &Output) {
|
||||
if !seat
|
||||
.user_data()
|
||||
.insert_if_missing(|| ActiveOutput(RefCell::new(output.clone())))
|
||||
{
|
||||
*seat
|
||||
fn set_active_output(&self, output: &Output) {
|
||||
*self
|
||||
.user_data()
|
||||
.get::<ActiveOutput>()
|
||||
.unwrap()
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ impl CompositorHandler for State {
|
|||
state.wl_buffer().is_some()
|
||||
})
|
||||
{
|
||||
let output = active_output(&seat, &self.common);
|
||||
let output = seat.active_output();
|
||||
Shell::map_window(self, &window, &output);
|
||||
} else {
|
||||
return;
|
||||
|
|
@ -147,6 +147,7 @@ impl CompositorHandler for State {
|
|||
self.xdg_popup_ensure_initial_configure(&popup);
|
||||
}
|
||||
|
||||
/*
|
||||
// at last handle some special cases, like grabs and changing layer surfaces
|
||||
|
||||
// If we would re-position the window inside the grab we would get a weird jittery animation.
|
||||
|
|
@ -182,6 +183,7 @@ impl CompositorHandler for State {
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// We need to know every potential output for importing to the right gpu and scheduling a render,
|
||||
// so call this only after every potential surface map operation has been done.
|
||||
|
|
@ -189,8 +191,8 @@ impl CompositorHandler for State {
|
|||
|
||||
// and refresh smithays internal state
|
||||
self.common.shell.popups.commit(surface);
|
||||
for workspace in &self.common.shell.spaces {
|
||||
workspace.space.commit(surface);
|
||||
for workspace in self.common.shell.workspaces.spaces_mut() {
|
||||
workspace.commit(surface);
|
||||
}
|
||||
|
||||
// re-arrange layer-surfaces (commits may change size and positioning)
|
||||
|
|
@ -199,8 +201,7 @@ impl CompositorHandler for State {
|
|||
map.layer_for_surface(surface, WindowSurfaceType::ALL)
|
||||
.is_some()
|
||||
}) {
|
||||
let dh = &self.common.display_handle;
|
||||
layer_map_for_output(output).arrange(dh);
|
||||
layer_map_for_output(output).arrange();
|
||||
}
|
||||
|
||||
// schedule a new render
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ impl ExportDmabufHandler for State {
|
|||
if cursor_status != CursorImageStatus::Hidden {
|
||||
let workspace = workspace.as_deref()?;
|
||||
let loc = seat.get_pointer().map(|ptr| ptr.current_location())?;
|
||||
let output = active_output(seat, &self.common);
|
||||
let output = seat.active_output();
|
||||
|
||||
if self.common.shell.active_space(&output).idx == workspace.idx {
|
||||
let relative = self
|
||||
|
|
|
|||
|
|
@ -27,11 +27,11 @@ impl WlrLayerShellHandler for State {
|
|||
namespace: String,
|
||||
) {
|
||||
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();
|
||||
let output = wl_output
|
||||
.as_ref()
|
||||
.and_then(Output::from_resource)
|
||||
.unwrap_or_else(|| active_output(&seat, &self.common));
|
||||
.unwrap_or_else(|| seat.active_output());
|
||||
self.common.shell.pending_layers.push((
|
||||
LayerSurface::new(surface, namespace),
|
||||
output,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ pub mod buffer;
|
|||
pub mod compositor;
|
||||
pub mod data_device;
|
||||
pub mod dmabuf;
|
||||
pub mod export_dmabuf;
|
||||
//pub mod export_dmabuf;
|
||||
pub mod keyboard_shortcuts_inhibit;
|
||||
pub mod layer_shell;
|
||||
pub mod output;
|
||||
|
|
|
|||
|
|
@ -1,17 +1,23 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::state::State;
|
||||
use crate::{
|
||||
shell::focus::target::{KeyboardFocusTarget, PointerFocusTarget},
|
||||
state::State,
|
||||
};
|
||||
use smithay::{
|
||||
delegate_seat,
|
||||
input::{pointer::CursorImageStatus, SeatHandler, SeatState},
|
||||
reexports::wayland_server::{protocol::wl_surface::WlSurface, Resource},
|
||||
wayland::{data_device::set_data_device_focus, primary_selection::set_primary_focus},
|
||||
reexports::wayland_server::Resource,
|
||||
wayland::{
|
||||
data_device::set_data_device_focus, primary_selection::set_primary_focus,
|
||||
seat::WaylandFocus,
|
||||
},
|
||||
};
|
||||
use std::cell::RefCell;
|
||||
|
||||
impl SeatHandler for State {
|
||||
type KeyboardFocus = WlSurface;
|
||||
type PointerFocus = WlSurface;
|
||||
type KeyboardFocus = KeyboardFocusTarget;
|
||||
type PointerFocus = PointerFocusTarget;
|
||||
|
||||
fn seat_state(&mut self) -> &mut SeatState<Self> {
|
||||
&mut self.common.seat_state
|
||||
|
|
@ -35,10 +41,12 @@ impl SeatHandler for State {
|
|||
focused: Option<&Self::KeyboardFocus>,
|
||||
) {
|
||||
let dh = &self.common.display_handle;
|
||||
if let Some(client) = focused.and_then(|s| dh.get_client(s.id()).ok()) {
|
||||
set_data_device_focus(dh, seat, Some(client));
|
||||
let client2 = focused.and_then(|s| dh.get_client(s.id()).ok()).unwrap();
|
||||
set_primary_focus(dh, seat, Some(client2))
|
||||
if let Some(client) = focused
|
||||
.and_then(|t| t.wl_surface())
|
||||
.and_then(|s| dh.get_client(s.id()).ok())
|
||||
{
|
||||
set_data_device_focus(dh, seat, Some(client.clone()));
|
||||
set_primary_focus(dh, seat, Some(client))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,18 +19,35 @@ impl ToplevelManagementHandler for State {
|
|||
}
|
||||
|
||||
fn activate(&mut self, _dh: &DisplayHandle, window: &Window, seat: Option<Seat<Self>>) {
|
||||
if let Some(idx) = self
|
||||
for output in self
|
||||
.common
|
||||
.shell
|
||||
.space_for_window(window.toplevel().wl_surface())
|
||||
.map(|w| w.idx)
|
||||
.outputs()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>()
|
||||
.iter()
|
||||
{
|
||||
let seat = seat.unwrap_or(self.common.last_active_seat.clone());
|
||||
let output = active_output(&seat, &self.common);
|
||||
if self.common.shell.active_space(&output).idx != idx {
|
||||
self.common.shell.activate(&seat, &output, idx as usize);
|
||||
let maybe = self
|
||||
.common
|
||||
.shell
|
||||
.workspaces
|
||||
.spaces_for_output(output)
|
||||
.enumerate()
|
||||
.find(|(_, w)| w.windows().any(|w| &w == window));
|
||||
if let Some((idx, workspace)) = maybe {
|
||||
let seat = seat.unwrap_or(self.common.last_active_seat().clone());
|
||||
let mapped = workspace
|
||||
.mapped()
|
||||
.find(|m| m.windows().any(|(w, _)| &w == window))
|
||||
.unwrap()
|
||||
.clone();
|
||||
|
||||
std::mem::drop(workspace);
|
||||
self.common.shell.activate(&output, idx as usize);
|
||||
mapped.focus_window(window);
|
||||
Common::set_focus(self, Some(&mapped.clone().into()), &seat, None);
|
||||
return;
|
||||
}
|
||||
Common::set_focus(self, Some(window.toplevel().wl_surface()), &seat, None);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,16 +29,15 @@ impl WorkspaceHandler for State {
|
|||
for request in requests.into_iter() {
|
||||
match request {
|
||||
Request::Activate(handle) => {
|
||||
if let Some(idx) = self
|
||||
let output = self.common.last_active_seat().active_output();
|
||||
let maybe_idx = self
|
||||
.common
|
||||
.shell
|
||||
.spaces
|
||||
.iter()
|
||||
.position(|w| w.handle == handle)
|
||||
{
|
||||
let seat = &self.common.last_active_seat;
|
||||
let output = active_output(seat, &self.common);
|
||||
self.common.shell.activate(seat, &output, idx);
|
||||
.workspaces
|
||||
.spaces_for_output(&output)
|
||||
.position(|w| w.handle == handle);
|
||||
if let Some(idx) = maybe_idx {
|
||||
self.common.shell.activate(&output, idx);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use smithay::{
|
|||
delegate_xdg_shell,
|
||||
desktop::{
|
||||
find_popup_root_surface, Kind, PopupGrab, PopupKeyboardGrab, PopupKind, PopupPointerGrab,
|
||||
PopupUngrabStrategy, Window, WindowSurfaceType,
|
||||
PopupUngrabStrategy, Window,
|
||||
},
|
||||
input::{
|
||||
pointer::{Focus, GrabStartData as PointerGrabStartData},
|
||||
|
|
@ -17,8 +17,12 @@ use smithay::{
|
|||
wayland_server::protocol::{wl_output::WlOutput, wl_seat::WlSeat, wl_surface::WlSurface},
|
||||
},
|
||||
utils::Serial,
|
||||
wayland::shell::xdg::{
|
||||
Configure, PopupSurface, PositionerState, ToplevelSurface, XdgShellHandler, XdgShellState,
|
||||
wayland::{
|
||||
seat::WaylandFocus,
|
||||
shell::xdg::{
|
||||
Configure, PopupSurface, PositionerState, ToplevelSurface, XdgShellHandler,
|
||||
XdgShellState,
|
||||
},
|
||||
},
|
||||
};
|
||||
use std::cell::Cell;
|
||||
|
|
@ -35,13 +39,10 @@ impl XdgShellHandler for State {
|
|||
fn new_toplevel(&mut self, surface: ToplevelSurface) {
|
||||
super::mark_dirty_on_drop(&self.common, surface.wl_surface());
|
||||
|
||||
let seat = &self.common.last_active_seat;
|
||||
let seat = self.common.last_active_seat().clone();
|
||||
let window = Window::new(Kind::Xdg(surface));
|
||||
self.common.shell.toplevel_info_state.new_toplevel(&window);
|
||||
self.common
|
||||
.shell
|
||||
.pending_windows
|
||||
.push((window, seat.clone()));
|
||||
self.common.shell.pending_windows.push((window, seat));
|
||||
// We will position the window after the first commit, when we know its size hints
|
||||
}
|
||||
|
||||
|
|
@ -72,17 +73,9 @@ impl XdgShellHandler for State {
|
|||
// If we would re-position the window inside the grab we would get a weird jittery animation.
|
||||
// We only want to resize once the client has acknoledged & commited the new size,
|
||||
// so we need to carefully track the state through different handlers.
|
||||
if let Some(window) =
|
||||
self.common
|
||||
.shell
|
||||
.space_for_window(&surface)
|
||||
.and_then(|workspace| {
|
||||
workspace
|
||||
.space
|
||||
.window_for_surface(&surface, WindowSurfaceType::TOPLEVEL)
|
||||
})
|
||||
{
|
||||
crate::shell::layout::floating::ResizeSurfaceGrab::ack_configure(window, configure)
|
||||
if let Some(mapped) = self.common.shell.element_for_surface(&surface) {
|
||||
//TODO
|
||||
//crate::shell::layout::floating::ResizeSurfaceGrab::ack_configure(window, configure)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -90,12 +83,16 @@ impl XdgShellHandler for State {
|
|||
fn grab(&mut self, surface: PopupSurface, seat: WlSeat, serial: Serial) {
|
||||
let seat = Seat::from_resource(&seat).unwrap();
|
||||
let kind = PopupKind::Xdg(surface);
|
||||
if let Ok(root) = find_popup_root_surface(&kind) {
|
||||
if let Some(root) = find_popup_root_surface(&kind)
|
||||
.ok()
|
||||
.and_then(|root| self.common.shell.element_for_surface(&root))
|
||||
{
|
||||
let target = root.clone().into();
|
||||
let ret = self
|
||||
.common
|
||||
.shell
|
||||
.popups
|
||||
.grab_popup(root, kind, &seat, serial);
|
||||
.grab_popup(target, kind, &seat, serial);
|
||||
|
||||
if let Ok(mut grab) = ret {
|
||||
if let Some(keyboard) = seat.get_keyboard() {
|
||||
|
|
@ -157,18 +154,9 @@ impl XdgShellHandler for State {
|
|||
fn move_request(&mut self, surface: ToplevelSurface, seat: WlSeat, serial: Serial) {
|
||||
let seat = Seat::from_resource(&seat).unwrap();
|
||||
if let Some(start_data) = check_grab_preconditions(&seat, surface.wl_surface(), serial) {
|
||||
let workspace = self
|
||||
.common
|
||||
.shell
|
||||
.space_for_window_mut(surface.wl_surface())
|
||||
.unwrap();
|
||||
let window = workspace
|
||||
.space
|
||||
.window_for_surface(surface.wl_surface(), WindowSurfaceType::TOPLEVEL)
|
||||
.unwrap()
|
||||
.clone();
|
||||
|
||||
Shell::move_request(self, &window, &seat, serial, start_data);
|
||||
if let Some(mapped) = self.common.shell.element_for_surface(surface.wl_surface()) {
|
||||
// Shell::move_request(self, &window, &seat, serial, start_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -181,35 +169,31 @@ impl XdgShellHandler for State {
|
|||
) {
|
||||
let seat = Seat::from_resource(&seat).unwrap();
|
||||
if let Some(start_data) = check_grab_preconditions(&seat, surface.wl_surface(), serial) {
|
||||
Workspace::resize_request(self, surface.wl_surface(), &seat, serial, start_data, edges);
|
||||
if let Some(mapped) = self.common.shell.element_for_surface(surface.wl_surface()) {
|
||||
// Shell::resize_request(self, mapped, &seat, serial, start_data, edges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn maximize_request(&mut self, surface: ToplevelSurface) {
|
||||
let surface = surface.wl_surface();
|
||||
let seat = &self.common.last_active_seat;
|
||||
let output = active_output(seat, &self.common);
|
||||
let seat = self.common.last_active_seat();
|
||||
let output = seat.active_output();
|
||||
|
||||
if let Some(workspace) = self.common.shell.space_for_window_mut(surface) {
|
||||
let window = workspace
|
||||
.space
|
||||
.window_for_surface(surface, WindowSurfaceType::TOPLEVEL)
|
||||
.unwrap()
|
||||
.clone();
|
||||
workspace.maximize_request(&window, &output)
|
||||
if let Some(mapped) = self.common.shell.element_for_surface(surface).cloned() {
|
||||
if let Some(workspace) = self.common.shell.space_for_mut(&mapped) {
|
||||
//workspace.maximize_request(mapped, &output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn unmaximize_request(&mut self, surface: ToplevelSurface) {
|
||||
let surface = surface.wl_surface();
|
||||
|
||||
if let Some(workspace) = self.common.shell.space_for_window_mut(surface) {
|
||||
let window = workspace
|
||||
.space
|
||||
.window_for_surface(surface, WindowSurfaceType::TOPLEVEL)
|
||||
.unwrap()
|
||||
.clone();
|
||||
workspace.unmaximize_request(&window)
|
||||
if let Some(mapped) = self.common.shell.element_for_surface(surface).cloned() {
|
||||
if let Some(workspace) = self.common.shell.space_for_mut(&mapped) {
|
||||
//workspace.unmaximize_request(mapped, &output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -218,29 +202,25 @@ impl XdgShellHandler for State {
|
|||
.as_ref()
|
||||
.and_then(Output::from_resource)
|
||||
.unwrap_or_else(|| {
|
||||
let seat = &self.common.last_active_seat;
|
||||
active_output(seat, &self.common)
|
||||
let seat = self.common.last_active_seat();
|
||||
seat.active_output()
|
||||
});
|
||||
|
||||
let surface = surface.wl_surface();
|
||||
if let Some(workspace) = self.common.shell.space_for_window_mut(surface) {
|
||||
let window = workspace
|
||||
.space
|
||||
.window_for_surface(surface, WindowSurfaceType::TOPLEVEL)
|
||||
.unwrap()
|
||||
.clone();
|
||||
workspace.fullscreen_request(&window, &output)
|
||||
if let Some(mapped) = self.common.shell.element_for_surface(surface).cloned() {
|
||||
if let Some(workspace) = self.common.shell.space_for_mut(&mapped) {
|
||||
workspace.fullscreen_request(&mapped.active_window(), &output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn unfullscreen_request(&mut self, surface: ToplevelSurface) {
|
||||
let surface = surface.wl_surface();
|
||||
if let Some(workspace) = self.common.shell.space_for_window_mut(surface) {
|
||||
let window = workspace
|
||||
.space
|
||||
.window_for_surface(surface, WindowSurfaceType::TOPLEVEL)
|
||||
.unwrap()
|
||||
.clone();
|
||||
if let Some((workspace, window)) = self.common.shell.workspaces.spaces_mut().find_map(|w| {
|
||||
let window = w
|
||||
.windows()
|
||||
.find(|w| w.toplevel().wl_surface() == surface.wl_surface());
|
||||
window.map(|win| (w, win))
|
||||
}) {
|
||||
workspace.unfullscreen_request(&window)
|
||||
}
|
||||
}
|
||||
|
|
@ -270,7 +250,6 @@ fn check_grab_preconditions(
|
|||
.as_ref()
|
||||
.unwrap()
|
||||
.0
|
||||
.id()
|
||||
.same_client_as(&surface.id())
|
||||
{
|
||||
return None;
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@
|
|||
use crate::{shell::Shell, utils::prelude::*};
|
||||
use smithay::{
|
||||
desktop::{
|
||||
layer_map_for_output, LayerSurface, PopupKind, PopupManager, Space, Window,
|
||||
WindowSurfaceType,
|
||||
layer_map_for_output, LayerSurface, PopupKind, PopupManager, Window, WindowSurfaceType,
|
||||
},
|
||||
output::Output,
|
||||
reexports::{
|
||||
|
|
@ -27,12 +26,19 @@ use std::sync::Mutex;
|
|||
impl Shell {
|
||||
pub fn unconstrain_popup(&self, surface: &PopupSurface, positioner: &PositionerState) {
|
||||
if let Some(parent) = get_popup_toplevel(&surface) {
|
||||
if let Some(workspace) = self.space_for_window(&parent) {
|
||||
let window = workspace
|
||||
.space
|
||||
.window_for_surface(&parent, WindowSurfaceType::ALL)
|
||||
if let Some(elem) = self.element_for_surface(&parent) {
|
||||
let workspace = self.space_for(elem).unwrap();
|
||||
let element_loc = workspace.element_geometry(elem).unwrap().loc;
|
||||
let (window, offset) = elem
|
||||
.windows()
|
||||
.find(|(w, _)| w.toplevel().wl_surface() == &parent)
|
||||
.unwrap();
|
||||
unconstrain_xdg_popup(surface, positioner, &workspace.space, window);
|
||||
let window_geo_offset = window.geometry().loc;
|
||||
let window_loc = element_loc + offset + window_geo_offset;
|
||||
let anchor_point = get_anchor_point(&positioner) + window_loc;
|
||||
if let Some(output) = workspace.output_under(anchor_point) {
|
||||
unconstrain_xdg_popup(surface, positioner, window_loc, output.geometry());
|
||||
}
|
||||
} else if let Some((output, layer_surface)) = self.outputs().find_map(|o| {
|
||||
let map = layer_map_for_output(o);
|
||||
map.layer_for_surface(&parent, WindowSurfaceType::ALL)
|
||||
|
|
@ -42,15 +48,14 @@ impl Shell {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_reactive_popups(&self, window: &Window) {
|
||||
if let Some(workspace) = self.space_for_window(window.toplevel().wl_surface()) {
|
||||
update_reactive_popups(&workspace.space, window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_reactive_popups(space: &Space, window: &Window) {
|
||||
pub fn update_reactive_popups<'a>(
|
||||
window: &Window,
|
||||
loc: Point<i32, Logical>,
|
||||
outputs: impl Iterator<Item = &'a Output>,
|
||||
) {
|
||||
let output_geo = outputs.map(|o| o.geometry()).collect::<Vec<_>>();
|
||||
for (popup, _) in PopupManager::popups_for_surface(window.toplevel().wl_surface()) {
|
||||
match popup {
|
||||
PopupKind::Xdg(surface) => {
|
||||
|
|
@ -64,12 +69,19 @@ pub fn update_reactive_popups(space: &Space, window: &Window) {
|
|||
attributes.current.positioner.clone()
|
||||
});
|
||||
if positioner.reactive {
|
||||
unconstrain_xdg_popup(&surface, &positioner, space, window);
|
||||
if let Err(err) = surface.send_configure() {
|
||||
slog_scope::warn!(
|
||||
"Compositor bug: Unable to re-configure reactive popup: {}",
|
||||
err
|
||||
);
|
||||
let anchor_point = get_anchor_point(&positioner) + loc;
|
||||
if let Some(rect) = output_geo
|
||||
.iter()
|
||||
.find(|geo| geo.contains(anchor_point))
|
||||
.copied()
|
||||
{
|
||||
unconstrain_xdg_popup(&surface, &positioner, loc, rect);
|
||||
if let Err(err) = surface.send_configure() {
|
||||
slog_scope::warn!(
|
||||
"Compositor bug: Unable to re-configure reactive popup: {}",
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -80,32 +92,18 @@ pub fn update_reactive_popups(space: &Space, window: &Window) {
|
|||
fn unconstrain_xdg_popup(
|
||||
surface: &PopupSurface,
|
||||
positioner: &PositionerState,
|
||||
space: &Space,
|
||||
window: &Window,
|
||||
window_loc: Point<i32, Logical>,
|
||||
rect: Rectangle<i32, Logical>,
|
||||
) {
|
||||
let anchor_point = get_anchor_point(&positioner) + space.window_location(&window).unwrap();
|
||||
if let Some(output_rect) = space
|
||||
.outputs_for_window(window)
|
||||
.into_iter()
|
||||
.find(|o| {
|
||||
space
|
||||
.output_geometry(o)
|
||||
.map(|rect| rect.contains(anchor_point))
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.map(|o| space.output_geometry(&o).unwrap())
|
||||
{
|
||||
// the output_rect represented relative to the parents coordinate system
|
||||
let mut relative = output_rect;
|
||||
relative.loc -= space.window_location(&window).unwrap();
|
||||
let offset = check_constrained(&surface, positioner.get_geometry(), relative);
|
||||
let mut relative = rect;
|
||||
relative.loc -= window_loc;
|
||||
let offset = check_constrained(&surface, positioner.get_geometry(), relative);
|
||||
|
||||
if offset.x != 0 || offset.y != 0 {
|
||||
slog_scope::debug!("Unconstraining popup: {:?}", surface);
|
||||
if !unconstrain_flip(&surface, &positioner, relative) {
|
||||
if !unconstrain_slide(&surface, &positioner, relative) {
|
||||
unconstrain_resize(&surface, &positioner, relative);
|
||||
}
|
||||
if offset.x != 0 || offset.y != 0 {
|
||||
slog_scope::debug!("Unconstraining popup: {:?}", surface);
|
||||
if !unconstrain_flip(&surface, &positioner, relative) {
|
||||
if !unconstrain_slide(&surface, &positioner, relative) {
|
||||
unconstrain_resize(&surface, &positioner, relative);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
pub mod drm;
|
||||
pub mod export_dmabuf;
|
||||
//pub mod export_dmabuf;
|
||||
pub mod output_configuration;
|
||||
pub mod toplevel_info;
|
||||
pub mod toplevel_management;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use smithay::{
|
||||
output::{Mode, Output, OutputData},
|
||||
output::{Mode, Output},
|
||||
reexports::{
|
||||
wayland_protocols_wlr::output_management::v1::server::{
|
||||
zwlr_output_configuration_head_v1::{self, ZwlrOutputConfigurationHeadV1},
|
||||
|
|
@ -17,6 +17,7 @@ use smithay::{
|
|||
},
|
||||
},
|
||||
utils::{Logical, Physical, Point, Size, Transform},
|
||||
wayland::output::WlOutputData,
|
||||
};
|
||||
use std::{
|
||||
convert::{TryFrom, TryInto},
|
||||
|
|
@ -498,7 +499,7 @@ where
|
|||
impl<D> OutputConfigurationState<D>
|
||||
where
|
||||
D: GlobalDispatch<ZwlrOutputManagerV1, OutputMngrGlobalData>
|
||||
+ GlobalDispatch<WlOutput, OutputData>
|
||||
+ GlobalDispatch<WlOutput, WlOutputData>
|
||||
+ Dispatch<ZwlrOutputManagerV1, OutputMngrInstanceData>
|
||||
+ Dispatch<ZwlrOutputHeadV1, Output>
|
||||
+ Dispatch<ZwlrOutputModeV1, Mode>
|
||||
|
|
|
|||
|
|
@ -413,7 +413,7 @@ fn send_toplevel_to_client<D>(
|
|||
.iter()
|
||||
.filter(|o| !handle_state.outputs.contains(o))
|
||||
{
|
||||
new_output.with_client_outputs(dh, &client, |_dh, wl_output| {
|
||||
new_output.with_client_outputs(&client, |wl_output| {
|
||||
instance.output_enter(wl_output);
|
||||
});
|
||||
changed = true;
|
||||
|
|
@ -423,7 +423,7 @@ fn send_toplevel_to_client<D>(
|
|||
.iter()
|
||||
.filter(|o| !state.outputs.contains(o))
|
||||
{
|
||||
old_output.with_client_outputs(dh, &client, |_dh, wl_output| {
|
||||
old_output.with_client_outputs(&client, |wl_output| {
|
||||
instance.output_leave(wl_output);
|
||||
});
|
||||
changed = true;
|
||||
|
|
|
|||
|
|
@ -821,7 +821,7 @@ where
|
|||
.iter()
|
||||
.filter(|o| !handle_state.outputs.contains(o))
|
||||
{
|
||||
new_output.with_client_outputs(dh, &client, |_dh, wl_output| {
|
||||
new_output.with_client_outputs(&client, |wl_output| {
|
||||
instance.output_enter(wl_output);
|
||||
});
|
||||
changed = true;
|
||||
|
|
@ -831,7 +831,7 @@ where
|
|||
.iter()
|
||||
.filter(|o| !group.outputs.contains(o))
|
||||
{
|
||||
old_output.with_client_outputs(dh, &client, |_dh, wl_output| {
|
||||
old_output.with_client_outputs(&client, |wl_output| {
|
||||
instance.output_leave(wl_output);
|
||||
});
|
||||
changed = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue