xwayland: allow windows to scale themselves
This commit is contained in:
parent
cc8db84289
commit
19b07fa7dc
40 changed files with 800 additions and 80 deletions
|
|
@ -124,7 +124,8 @@ impl ZwpTabletToolV2 {
|
|||
self.client.event(Up { self_id: self.id });
|
||||
}
|
||||
|
||||
pub fn send_motion(&self, x: Fixed, y: Fixed) {
|
||||
pub fn send_motion(&self, mut x: Fixed, mut y: Fixed) {
|
||||
logical_to_client_wire_scale!(self.client, x, y);
|
||||
self.client.event(Motion {
|
||||
self_id: self.id,
|
||||
x,
|
||||
|
|
@ -199,7 +200,7 @@ impl ZwpTabletToolV2 {
|
|||
impl ZwpTabletToolV2RequestHandler for ZwpTabletToolV2 {
|
||||
type Error = ZwpTabletToolV2Error;
|
||||
|
||||
fn set_cursor(&self, req: SetCursor, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
fn set_cursor(&self, mut req: SetCursor, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
let Some(tool) = self.tool.get() else {
|
||||
return Ok(());
|
||||
};
|
||||
|
|
@ -209,6 +210,7 @@ impl ZwpTabletToolV2RequestHandler for ZwpTabletToolV2 {
|
|||
}
|
||||
let mut cursor_opt = None;
|
||||
if req.surface.is_some() {
|
||||
client_wire_scale_to_logical!(self.client, req.hotspot_x, req.hotspot_y);
|
||||
let surface = self.seat.client.lookup(req.surface)?;
|
||||
let cursor = surface.get_cursor(&tool.cursor)?;
|
||||
cursor.set_hotspot(req.hotspot_x, req.hotspot_y);
|
||||
|
|
|
|||
|
|
@ -86,8 +86,9 @@ impl WlPointer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn send_enter(&self, serial: u32, surface: WlSurfaceId, x: Fixed, y: Fixed) {
|
||||
pub fn send_enter(&self, serial: u32, surface: WlSurfaceId, mut x: Fixed, mut y: Fixed) {
|
||||
self.last_motion.set((x, y));
|
||||
logical_to_client_wire_scale!(self.seat.client, x, y);
|
||||
self.seat.client.event(Enter {
|
||||
self_id: self.id,
|
||||
serial,
|
||||
|
|
@ -105,10 +106,11 @@ impl WlPointer {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn send_motion(&self, time: u32, x: Fixed, y: Fixed) {
|
||||
pub fn send_motion(&self, time: u32, mut x: Fixed, mut y: Fixed) {
|
||||
if self.last_motion.replace((x, y)) == (x, y) {
|
||||
return;
|
||||
}
|
||||
logical_to_client_wire_scale!(self.seat.client, x, y);
|
||||
self.seat.client.event(Motion {
|
||||
self_id: self.id,
|
||||
time,
|
||||
|
|
@ -135,7 +137,8 @@ impl WlPointer {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn send_axis(&self, time: u32, axis: u32, value: Fixed) {
|
||||
pub fn send_axis(&self, time: u32, axis: u32, mut value: Fixed) {
|
||||
logical_to_client_wire_scale!(self.seat.client, value);
|
||||
self.seat.client.event(Axis {
|
||||
self_id: self.id,
|
||||
time,
|
||||
|
|
@ -183,13 +186,14 @@ impl WlPointer {
|
|||
impl WlPointerRequestHandler for WlPointer {
|
||||
type Error = WlPointerError;
|
||||
|
||||
fn set_cursor(&self, req: SetCursor, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
fn set_cursor(&self, mut req: SetCursor, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
if !self.seat.client.valid_serial(req.serial) {
|
||||
log::warn!("Client tried to set_cursor with an invalid serial");
|
||||
return Ok(());
|
||||
}
|
||||
let mut cursor_opt = None;
|
||||
if req.surface.is_some() {
|
||||
client_wire_scale_to_logical!(self.seat.client, req.hotspot_x, req.hotspot_y);
|
||||
let surface = self.seat.client.lookup(req.surface)?;
|
||||
let cursor = surface.get_cursor(&self.seat.global.pointer_cursor)?;
|
||||
cursor.set_hotspot(req.hotspot_x, req.hotspot_y);
|
||||
|
|
|
|||
|
|
@ -37,9 +37,10 @@ impl WlTouch {
|
|||
time: u32,
|
||||
surface: WlSurfaceId,
|
||||
id: i32,
|
||||
x: Fixed,
|
||||
y: Fixed,
|
||||
mut x: Fixed,
|
||||
mut y: Fixed,
|
||||
) {
|
||||
logical_to_client_wire_scale!(self.seat.client, x, y);
|
||||
self.seat.client.event(Down {
|
||||
self_id: self.id,
|
||||
serial,
|
||||
|
|
@ -60,7 +61,8 @@ impl WlTouch {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn send_motion(&self, time: u32, id: i32, x: Fixed, y: Fixed) {
|
||||
pub fn send_motion(&self, time: u32, id: i32, mut x: Fixed, mut y: Fixed) {
|
||||
logical_to_client_wire_scale!(self.seat.client, x, y);
|
||||
self.seat.client.event(Motion {
|
||||
self_id: self.id,
|
||||
time,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use {
|
|||
},
|
||||
leaks::Tracker,
|
||||
object::{Object, Version},
|
||||
rect::Region,
|
||||
rect::{Rect, Region},
|
||||
utils::clonecell::CloneCell,
|
||||
wire::{
|
||||
zwp_pointer_constraints_v1::*, WlPointerId, WlRegionId, WlSurfaceId,
|
||||
|
|
@ -125,11 +125,7 @@ impl SeatConstraint {
|
|||
}
|
||||
|
||||
fn set_region(&self, region: WlRegionId) -> Result<(), ZwpPointerConstraintsV1Error> {
|
||||
let region = if region.is_some() {
|
||||
Some(self.client.lookup(region)?.region())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let region = get_region(&self.client, region)?;
|
||||
self.region.set(region);
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -166,6 +162,35 @@ impl ZwpPointerConstraintsV1Global {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_region(
|
||||
client: &Client,
|
||||
region: WlRegionId,
|
||||
) -> Result<Option<Rc<Region>>, ZwpPointerConstraintsV1Error> {
|
||||
let region = if region.is_some() {
|
||||
let mut region = client.lookup(region)?.region();
|
||||
if let Some(scale) = client.wire_scale.get() {
|
||||
let rects: Vec<_> = region
|
||||
.rects()
|
||||
.iter()
|
||||
.map(|r| {
|
||||
Rect::new_sized(
|
||||
r.x1() / scale,
|
||||
r.y1() / scale,
|
||||
r.width() / scale,
|
||||
r.height() / scale,
|
||||
)
|
||||
.unwrap()
|
||||
})
|
||||
.collect();
|
||||
region = Region::from_rects(&rects);
|
||||
}
|
||||
Some(region)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Ok(region)
|
||||
}
|
||||
|
||||
impl ZwpPointerConstraintsV1 {
|
||||
fn create_constraint(
|
||||
&self,
|
||||
|
|
@ -181,11 +206,7 @@ impl ZwpPointerConstraintsV1 {
|
|||
if surface.constraints.contains(&seat.id) {
|
||||
return Err(ZwpPointerConstraintsV1Error::AlreadyConstrained);
|
||||
}
|
||||
let region = if region.is_some() {
|
||||
Some(self.client.lookup(region)?.region())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let region = get_region(&self.client, region)?;
|
||||
let one_shot = match lifetime {
|
||||
LT_ONESHOT => true,
|
||||
LT_PERSISTENT => false,
|
||||
|
|
|
|||
|
|
@ -23,11 +23,12 @@ impl ZwpRelativePointerV1 {
|
|||
pub fn send_relative_motion(
|
||||
&self,
|
||||
time_usec: u64,
|
||||
dx: Fixed,
|
||||
dy: Fixed,
|
||||
mut dx: Fixed,
|
||||
mut dy: Fixed,
|
||||
dx_unaccelerated: Fixed,
|
||||
dy_unaccelerated: Fixed,
|
||||
) {
|
||||
logical_to_client_wire_scale!(self.client, dx, dy);
|
||||
self.client.event(RelativeMotion {
|
||||
self_id: self.id,
|
||||
utime_hi: (time_usec >> 32) as u32,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue