autocommit 2022-01-31 23:45:42 CET
This commit is contained in:
parent
865d5f295d
commit
f2117256b9
33 changed files with 784 additions and 178 deletions
73
src/ifs/wl_surface/cursor.rs
Normal file
73
src/ifs/wl_surface/cursor.rs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
use crate::ifs::wl_seat::{WlSeatGlobal};
|
||||
use crate::ifs::wl_surface::{WlSurface};
|
||||
use crate::rect::Rect;
|
||||
|
||||
pub struct CursorSurface {
|
||||
seat: Rc<WlSeatGlobal>,
|
||||
surface: Rc<WlSurface>,
|
||||
hotspot: Cell<(i32, i32)>,
|
||||
pos: Cell<(i32, i32)>,
|
||||
extents: Cell<Rect>,
|
||||
}
|
||||
|
||||
impl CursorSurface {
|
||||
pub fn new(seat: &Rc<WlSeatGlobal>, surface: &Rc<WlSurface>) -> Self {
|
||||
Self {
|
||||
seat: seat.clone(),
|
||||
surface: surface.clone(),
|
||||
hotspot: Cell::new((0, 0)),
|
||||
pos: Cell::new((0, 0)),
|
||||
extents: Cell::new(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
fn update_extents(&self) {
|
||||
let (pos_x, pos_y) = self.pos.get();
|
||||
let extents = self.extents.get();
|
||||
let (hot_x, hot_y) = self.hotspot.get();
|
||||
self.extents.set(Rect::new_sized(pos_x - hot_x, pos_y - hot_y, extents.width(), extents.height()).unwrap());
|
||||
}
|
||||
|
||||
pub fn set_position(&self, x: i32, y: i32) {
|
||||
self.pos.set((x, y));
|
||||
self.update_extents();
|
||||
}
|
||||
|
||||
pub fn handle_unset(&self) {
|
||||
self.surface.cursors.remove(&self.seat.id());
|
||||
}
|
||||
|
||||
pub fn handle_surface_destroy(&self) {
|
||||
self.seat.set_cursor(None);
|
||||
}
|
||||
|
||||
pub fn handle_buffer_change(&self) {
|
||||
let (width, height) = match self.surface.buffer.get() {
|
||||
Some(b) => (b.rect.width(), b.rect.height()),
|
||||
_ => (0, 0),
|
||||
};
|
||||
self.extents.set(Rect::new_sized(0, 0, width, height).unwrap());
|
||||
self.update_extents();
|
||||
}
|
||||
|
||||
pub fn set_hotspot(&self, x: i32, y: i32) {
|
||||
self.hotspot.set((x, y));
|
||||
self.update_extents();
|
||||
}
|
||||
|
||||
pub fn dec_hotspot(&self, hotspot_dx: i32, hotspot_dy: i32) {
|
||||
let (hot_x, hot_y) = self.hotspot.get();
|
||||
self.hotspot.set((hot_x - hotspot_dx, hot_y - hotspot_dy));
|
||||
self.update_extents();
|
||||
}
|
||||
|
||||
pub fn surface(&self) -> &Rc<WlSurface> {
|
||||
&self.surface
|
||||
}
|
||||
|
||||
pub fn extents(&self) -> Rect {
|
||||
self.extents.get()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
mod types;
|
||||
pub mod wl_subsurface;
|
||||
pub mod xdg_surface;
|
||||
pub mod cursor;
|
||||
|
||||
use crate::backend::{KeyState, ScrollAxis};
|
||||
use crate::client::{Client, RequestParser};
|
||||
use crate::backend::{KeyState, ScrollAxis, SeatId};
|
||||
use crate::client::{Client, ClientId, DynEventFormatter, RequestParser};
|
||||
use crate::fixed::Fixed;
|
||||
use crate::ifs::wl_buffer::WlBuffer;
|
||||
use crate::ifs::wl_callback::WlCallback;
|
||||
|
|
@ -23,7 +24,12 @@ use std::mem;
|
|||
use std::ops::{Deref, DerefMut};
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
|
||||
use crate::ifs::wl_output::WlOutputId;
|
||||
use crate::ifs::wl_surface::cursor::CursorSurface;
|
||||
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceRole};
|
||||
use crate::render::Renderer;
|
||||
use crate::utils::smallmap::SmallMap;
|
||||
use crate::xkbcommon::ModifierState;
|
||||
|
||||
const DESTROY: u32 = 0;
|
||||
const ATTACH: u32 = 1;
|
||||
|
|
@ -55,6 +61,7 @@ pub enum SurfaceRole {
|
|||
None,
|
||||
Subsurface,
|
||||
XdgSurface,
|
||||
Cursor,
|
||||
}
|
||||
|
||||
impl SurfaceRole {
|
||||
|
|
@ -63,6 +70,7 @@ impl SurfaceRole {
|
|||
SurfaceRole::None => "none",
|
||||
SurfaceRole::Subsurface => "subsurface",
|
||||
SurfaceRole::XdgSurface => "xdg_surface",
|
||||
SurfaceRole::Cursor => "cursor",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -86,6 +94,7 @@ pub struct WlSurface {
|
|||
pub frame_requests: RefCell<Vec<Rc<WlCallback>>>,
|
||||
seat_state: NodeSeatState,
|
||||
xdg: CloneCell<Option<Rc<XdgSurface>>>,
|
||||
cursors: SmallMap<SeatId, Rc<CursorSurface>, 1>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
|
|
@ -180,9 +189,38 @@ impl WlSurface {
|
|||
frame_requests: RefCell::new(vec![]),
|
||||
seat_state: Default::default(),
|
||||
xdg: Default::default(),
|
||||
cursors: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_cursor(&self) -> bool {
|
||||
self.role.get() == SurfaceRole::Cursor
|
||||
}
|
||||
|
||||
pub fn get_cursor(self: &Rc<Self>, seat: &Rc<WlSeatGlobal>) -> Result<Rc<CursorSurface>, WlSurfaceError> {
|
||||
if let Some(cursor) = self.cursors.get(&seat.id()) {
|
||||
return Ok(cursor);
|
||||
}
|
||||
self.set_role(SurfaceRole::Cursor)?;
|
||||
let cursor = Rc::new(CursorSurface::new(seat, self));
|
||||
self.cursors.insert(seat.id(), cursor.clone());
|
||||
Ok(cursor)
|
||||
}
|
||||
|
||||
pub fn belongs_to_toplevel(&self) -> bool {
|
||||
if let Some(xdg) = self.xdg.get() {
|
||||
return xdg.role() == XdgSurfaceRole::XdgToplevel;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn enter_event(self: &Rc<Self>, output: WlOutputId) -> DynEventFormatter {
|
||||
Box::new(Enter {
|
||||
obj: self.clone(),
|
||||
output,
|
||||
})
|
||||
}
|
||||
|
||||
fn set_xdg_surface(&self, xdg: Option<Rc<XdgSurface>>) {
|
||||
let ch = self.children.borrow();
|
||||
if let Some(ch) = &*ch {
|
||||
|
|
@ -190,6 +228,11 @@ impl WlSurface {
|
|||
ss.surface.set_xdg_surface(xdg.clone());
|
||||
}
|
||||
}
|
||||
if self.seat_state.is_active() {
|
||||
if let Some(xdg) = &xdg {
|
||||
xdg.surface_active_changed(true);
|
||||
}
|
||||
}
|
||||
self.xdg.set(xdg);
|
||||
}
|
||||
|
||||
|
|
@ -261,8 +304,15 @@ impl WlSurface {
|
|||
self.client.parse(self, parser)
|
||||
}
|
||||
|
||||
fn unset_cursors(&self) {
|
||||
while let Some((_, cursor)) = self.cursors.pop() {
|
||||
cursor.handle_surface_destroy();
|
||||
}
|
||||
}
|
||||
|
||||
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let _req: Destroy = self.parse(parser)?;
|
||||
self.unset_cursors();
|
||||
self.destroy_node(true);
|
||||
if self.ext.get().is_some() {
|
||||
return Err(DestroyError::ReloObjectStillExists);
|
||||
|
|
@ -276,17 +326,11 @@ impl WlSurface {
|
|||
}
|
||||
*children = None;
|
||||
}
|
||||
{
|
||||
let buffer = self.buffer.get();
|
||||
if let Some(buffer) = &buffer {
|
||||
buffer.surfaces.remove(&self.id);
|
||||
}
|
||||
}
|
||||
self.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn attach(&self, parser: MsgParser<'_, '_>) -> Result<(), AttachError> {
|
||||
fn attach(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), AttachError> {
|
||||
let req: Attach = self.parse(parser)?;
|
||||
let buf = if req.buffer.is_some() {
|
||||
Some((req.x, req.y, self.client.get_buffer(req.buffer)?))
|
||||
|
|
@ -332,7 +376,7 @@ impl WlSurface {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn do_commit(&self, ctx: CommitContext) -> Result<(), WlSurfaceError> {
|
||||
fn do_commit(self: &Rc<Self>, ctx: CommitContext) -> Result<(), WlSurfaceError> {
|
||||
let ext = self.ext.get();
|
||||
if ext.clone().pre_commit(ctx)? == CommitAction::AbortCommit {
|
||||
return Ok(());
|
||||
|
|
@ -350,8 +394,9 @@ impl WlSurface {
|
|||
let mut new_size = None;
|
||||
if let Some(buffer) = self.buffer.take() {
|
||||
old_size = Some(buffer.rect);
|
||||
self.client.event(buffer.release());
|
||||
buffer.surfaces.remove(&self.id);
|
||||
if !buffer.destroyed() {
|
||||
self.client.event(buffer.release());
|
||||
}
|
||||
}
|
||||
if let Some((dx, dy, buffer)) = buffer_change {
|
||||
let _ = buffer.update_texture();
|
||||
|
|
@ -361,14 +406,23 @@ impl WlSurface {
|
|||
self.buf_y.fetch_add(dy);
|
||||
if (dx, dy) != (0, 0) {
|
||||
self.need_extents_update.set(true);
|
||||
for (_, cursor) in &self.cursors {
|
||||
cursor.dec_hotspot(dx, dy);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.buf_x.set(0);
|
||||
self.buf_y.set(0);
|
||||
for (_, cursor) in &self.cursors {
|
||||
cursor.set_hotspot(0, 0);
|
||||
}
|
||||
}
|
||||
if old_size != new_size {
|
||||
self.need_extents_update.set(true);
|
||||
}
|
||||
for (_, cursor) in &self.cursors {
|
||||
cursor.handle_buffer_change();
|
||||
}
|
||||
}
|
||||
{
|
||||
let mut pfr = self.pending.frame_request.borrow_mut();
|
||||
|
|
@ -389,7 +443,7 @@ impl WlSurface {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn commit(&self, parser: MsgParser<'_, '_>) -> Result<(), CommitError> {
|
||||
fn commit(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), CommitError> {
|
||||
let _req: Commit = self.parse(parser)?;
|
||||
self.do_commit(CommitContext::RootCommit)?;
|
||||
Ok(())
|
||||
|
|
@ -414,7 +468,7 @@ impl WlSurface {
|
|||
}
|
||||
|
||||
fn handle_request_(
|
||||
&self,
|
||||
self: &Rc<Self>,
|
||||
request: u32,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlSurfaceError> {
|
||||
|
|
@ -494,6 +548,7 @@ impl Object for WlSurface {
|
|||
}
|
||||
|
||||
fn break_loops(&self) {
|
||||
self.unset_cursors();
|
||||
self.destroy_node(true);
|
||||
*self.children.borrow_mut() = None;
|
||||
self.unset_ext();
|
||||
|
|
@ -530,10 +585,23 @@ impl Node for WlSurface {
|
|||
for seat in remove {
|
||||
xdg.focus_surface.remove(&seat);
|
||||
}
|
||||
if self.seat_state.is_active() {
|
||||
xdg.surface_active_changed(false);
|
||||
}
|
||||
}
|
||||
self.seat_state.destroy_node(self);
|
||||
}
|
||||
|
||||
fn active_changed(&self, active: bool) {
|
||||
if let Some(xdg) = self.xdg.get() {
|
||||
xdg.surface_active_changed(active);
|
||||
}
|
||||
}
|
||||
|
||||
fn key(&self, seat: &WlSeatGlobal, key: u32, state: u32, mods: Option<ModifierState>) {
|
||||
seat.key_surface(self, key, state, mods);
|
||||
}
|
||||
|
||||
fn button(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, button: u32, state: KeyState) {
|
||||
seat.button_surface(&self, button, state);
|
||||
}
|
||||
|
|
@ -563,4 +631,12 @@ impl Node for WlSurface {
|
|||
fn motion(&self, seat: &WlSeatGlobal, x: Fixed, y: Fixed) {
|
||||
seat.motion_surface(self, x, y)
|
||||
}
|
||||
|
||||
fn render(&self, renderer: &mut Renderer, x: i32, y: i32) {
|
||||
renderer.render_surface(self, x, y);
|
||||
}
|
||||
|
||||
fn client_id(&self) -> Option<ClientId> {
|
||||
Some(self.client.id)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
use crate::client::{ClientError, RequestParser};
|
||||
use crate::client::{ClientError, EventFormatter, RequestParser};
|
||||
use crate::ifs::wl_callback::WlCallbackId;
|
||||
use crate::ifs::wl_region::WlRegionId;
|
||||
use crate::ifs::wl_surface::xdg_surface::XdgSurfaceError;
|
||||
use crate::ifs::wl_surface::{SurfaceRole, WlSurfaceId};
|
||||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||
use crate::ifs::wl_surface::{ENTER, SurfaceRole, WlSurface, WlSurfaceId};
|
||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
use crate::ifs::wl_output::WlOutputId;
|
||||
use crate::object::Object;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlSurfaceError {
|
||||
|
|
@ -329,3 +333,21 @@ impl Debug for DamageBuffer {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Enter {
|
||||
pub obj: Rc<WlSurface>,
|
||||
pub output: WlOutputId,
|
||||
}
|
||||
impl EventFormatter for Enter {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, ENTER).object(self.output);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
self.obj.deref()
|
||||
}
|
||||
}
|
||||
impl Debug for Enter {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "enter(output: {})", self.output)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,6 +95,10 @@ trait XdgSurfaceExt {
|
|||
fn extents_changed(&self) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
fn surface_active_changed(self: Rc<Self>, active: bool) {
|
||||
let _ = active;
|
||||
}
|
||||
}
|
||||
|
||||
impl XdgSurface {
|
||||
|
|
@ -118,6 +122,16 @@ impl XdgSurface {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn surface_active_changed(&self, active: bool) {
|
||||
if let Some(ext) = self.ext.get() {
|
||||
ext.surface_active_changed(active);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn role(&self) -> XdgSurfaceRole {
|
||||
self.role.get()
|
||||
}
|
||||
|
||||
fn set_workspace(&self, ws: &Rc<WorkspaceNode>) {
|
||||
self.workspace.set(Some(ws.clone()));
|
||||
let pu = self.popups.lock();
|
||||
|
|
@ -311,7 +325,9 @@ impl XdgSurface {
|
|||
});
|
||||
FindTreeResult::AcceptsInput
|
||||
},
|
||||
_ => FindTreeResult::Other
|
||||
_ => {
|
||||
FindTreeResult::Other
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
mod types;
|
||||
|
||||
use crate::client::DynEventFormatter;
|
||||
use crate::client::{ClientId, DynEventFormatter};
|
||||
use crate::fixed::Fixed;
|
||||
use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal};
|
||||
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceError, XdgSurfaceExt};
|
||||
|
|
@ -199,8 +199,8 @@ impl AbsoluteNode for XdgPopup {
|
|||
self
|
||||
}
|
||||
|
||||
fn absolute_position(&self) -> Rect {
|
||||
self.xdg.absolute_desired_extents.get()
|
||||
fn absolute_position(&self) -> (Rect, bool) {
|
||||
(self.xdg.absolute_desired_extents.get(), false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -235,6 +235,10 @@ impl Node for XdgPopup {
|
|||
fn set_workspace(self: Rc<Self>, ws: &Rc<WorkspaceNode>) {
|
||||
self.xdg.set_workspace(ws);
|
||||
}
|
||||
|
||||
fn client_id(&self) -> Option<ClientId> {
|
||||
Some(self.xdg.surface.client.id)
|
||||
}
|
||||
}
|
||||
|
||||
impl XdgSurfaceExt for XdgPopup {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
mod types;
|
||||
|
||||
use crate::client::DynEventFormatter;
|
||||
use crate::client::{ClientId, DynEventFormatter};
|
||||
use crate::fixed::Fixed;
|
||||
use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal};
|
||||
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceError, XdgSurfaceExt};
|
||||
|
|
@ -17,7 +17,8 @@ use std::cell::{Cell, RefCell};
|
|||
use std::mem;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
use crate::backend::SeatId;
|
||||
use crate::backend::{SeatId};
|
||||
use crate::NumCell;
|
||||
use crate::utils::linkedlist::LinkedNode;
|
||||
use crate::utils::smallmap::SmallMap;
|
||||
|
||||
|
|
@ -80,6 +81,7 @@ pub struct XdgToplevel {
|
|||
pub children: RefCell<AHashMap<XdgToplevelId, Rc<XdgToplevel>>>,
|
||||
states: RefCell<AHashSet<u32>>,
|
||||
pub toplevel_history: SmallMap<SeatId, LinkedNode<Rc<XdgToplevel>>, 1>,
|
||||
active_surfaces: NumCell<u32>,
|
||||
}
|
||||
|
||||
impl XdgToplevel {
|
||||
|
|
@ -98,6 +100,22 @@ impl XdgToplevel {
|
|||
children: RefCell::new(Default::default()),
|
||||
states: RefCell::new(states),
|
||||
toplevel_history: Default::default(),
|
||||
active_surfaces: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_active(self: &Rc<Self>, active: bool) {
|
||||
let changed = {
|
||||
let mut states = self.states.borrow_mut();
|
||||
match active {
|
||||
true => states.insert(STATE_ACTIVATED),
|
||||
false => states.remove(&STATE_ACTIVATED),
|
||||
}
|
||||
};
|
||||
if changed {
|
||||
let rect = self.xdg.absolute_desired_extents.get();
|
||||
self.xdg.surface.client.event(self.configure(rect.width(), rect.height()));
|
||||
self.xdg.send_configure();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -278,7 +296,6 @@ impl XdgToplevel {
|
|||
}
|
||||
|
||||
fn map_tiled(self: &Rc<Self>) {
|
||||
log::info!("mapping tiled");
|
||||
let state = &self.xdg.surface.client.state;
|
||||
let seat = state.seat_queue.last();
|
||||
if let Some(seat) = seat {
|
||||
|
|
@ -389,6 +406,10 @@ impl Node for XdgToplevel {
|
|||
fn set_workspace(self: Rc<Self>, ws: &Rc<WorkspaceNode>) {
|
||||
self.xdg.set_workspace(ws);
|
||||
}
|
||||
|
||||
fn client_id(&self) -> Option<ClientId> {
|
||||
Some(self.xdg.surface.client.id)
|
||||
}
|
||||
}
|
||||
|
||||
impl XdgSurfaceExt for XdgToplevel {
|
||||
|
|
@ -418,10 +439,29 @@ impl XdgSurfaceExt for XdgToplevel {
|
|||
self.map_tiled();
|
||||
}
|
||||
self.extents_changed();
|
||||
if let Some(workspace) = self.xdg.workspace.get() {
|
||||
let output = workspace.output.get();
|
||||
let bindings = output.global.bindings.borrow_mut();
|
||||
for binding in bindings.get(&self.xdg.surface.client.id) {
|
||||
for binding in binding.values() {
|
||||
self.xdg.surface.client.event(self.xdg.surface.enter_event(binding.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
let seats = surface.client.state.globals.lock_seats();
|
||||
for seat in seats.values() {
|
||||
seat.focus_toplevel(&self);
|
||||
}
|
||||
}
|
||||
surface.client.state.tree_changed();
|
||||
}
|
||||
}
|
||||
|
||||
fn into_node(self: Rc<Self>) -> Option<Rc<dyn Node>> {
|
||||
Some(self)
|
||||
}
|
||||
|
||||
fn extents_changed(&self) {
|
||||
if let Some(parent) = self.parent_node.get() {
|
||||
let extents = self.xdg.extents.get();
|
||||
|
|
@ -430,7 +470,15 @@ impl XdgSurfaceExt for XdgToplevel {
|
|||
}
|
||||
}
|
||||
|
||||
fn into_node(self: Rc<Self>) -> Option<Rc<dyn Node>> {
|
||||
Some(self)
|
||||
fn surface_active_changed(self: Rc<Self>, active: bool) {
|
||||
if active {
|
||||
if self.active_surfaces.fetch_add(1) == 0 {
|
||||
self.set_active(true);
|
||||
}
|
||||
} else {
|
||||
if self.active_surfaces.fetch_sub(1) == 1 {
|
||||
self.set_active(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue