2018-10-02 21:37:24 +00:00
|
|
|
use std::{
|
|
|
|
cell::RefCell,
|
|
|
|
rc::Rc,
|
|
|
|
sync::{Arc, Mutex},
|
|
|
|
};
|
2018-05-07 17:56:38 +00:00
|
|
|
|
2018-10-02 21:37:24 +00:00
|
|
|
use smithay::{
|
2020-02-03 13:31:15 +00:00
|
|
|
reexports::{
|
|
|
|
wayland_protocols::xdg_shell::server::xdg_toplevel,
|
|
|
|
wayland_server::{
|
2020-04-17 16:27:10 +00:00
|
|
|
protocol::{wl_buffer, wl_callback, wl_pointer::ButtonState, wl_shell_surface, wl_surface},
|
2020-02-03 13:31:15 +00:00
|
|
|
Display,
|
|
|
|
},
|
2018-12-15 21:01:24 +00:00
|
|
|
},
|
2020-01-22 04:00:37 +00:00
|
|
|
utils::Rectangle,
|
2018-10-02 21:37:24 +00:00
|
|
|
wayland::{
|
2020-04-21 18:53:55 +00:00
|
|
|
compositor::{
|
|
|
|
compositor_init, roles::Role, BufferAssignment, CompositorToken, RegionAttributes,
|
|
|
|
SubsurfaceRole, SurfaceEvent, TraversalAction,
|
|
|
|
},
|
2018-11-22 15:02:01 +00:00
|
|
|
data_device::DnDIconRole,
|
2020-02-02 15:05:49 +00:00
|
|
|
seat::{AxisFrame, CursorImageRole, GrabStartData, PointerGrab, PointerInnerHandle, Seat},
|
2018-10-02 21:37:24 +00:00
|
|
|
shell::{
|
|
|
|
legacy::{
|
|
|
|
wl_shell_init, ShellRequest, ShellState as WlShellState, ShellSurfaceKind, ShellSurfaceRole,
|
|
|
|
},
|
|
|
|
xdg::{
|
|
|
|
xdg_shell_init, PopupConfigure, ShellState as XdgShellState, ToplevelConfigure, XdgRequest,
|
2020-02-08 06:24:27 +00:00
|
|
|
XdgSurfacePendingState, XdgSurfaceRole,
|
2018-10-02 21:37:24 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-09-24 22:32:09 +00:00
|
|
|
};
|
2017-12-10 21:09:17 +00:00
|
|
|
|
2020-02-03 05:42:12 +00:00
|
|
|
use crate::{
|
|
|
|
buffer_utils::BufferUtils,
|
|
|
|
window_map::{Kind as SurfaceKind, WindowMap},
|
|
|
|
};
|
2017-09-22 12:56:59 +00:00
|
|
|
|
2018-11-22 15:01:29 +00:00
|
|
|
define_roles!(Roles =>
|
|
|
|
[ XdgSurface, XdgSurfaceRole ]
|
2019-04-23 21:52:14 +00:00
|
|
|
[ ShellSurface, ShellSurfaceRole]
|
2018-11-22 15:02:01 +00:00
|
|
|
[ DnDIcon, DnDIconRole ]
|
2018-11-22 15:01:29 +00:00
|
|
|
[ CursorImage, CursorImageRole ]
|
|
|
|
);
|
2017-09-22 12:56:59 +00:00
|
|
|
|
2020-02-03 12:55:48 +00:00
|
|
|
pub type MyWindowMap = WindowMap<Roles>;
|
2017-09-22 12:56:59 +00:00
|
|
|
|
2019-04-23 20:46:11 +00:00
|
|
|
pub type MyCompositorToken = CompositorToken<Roles>;
|
2018-05-08 18:08:17 +00:00
|
|
|
|
2020-02-01 15:42:08 +00:00
|
|
|
struct MoveSurfaceGrab {
|
2020-02-02 15:05:49 +00:00
|
|
|
start_data: GrabStartData,
|
2020-02-01 15:42:08 +00:00
|
|
|
window_map: Rc<RefCell<MyWindowMap>>,
|
|
|
|
toplevel: SurfaceKind<Roles>,
|
|
|
|
initial_window_location: (i32, i32),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PointerGrab for MoveSurfaceGrab {
|
|
|
|
fn motion(
|
|
|
|
&mut self,
|
|
|
|
_handle: &mut PointerInnerHandle<'_>,
|
|
|
|
location: (f64, f64),
|
|
|
|
_focus: Option<(wl_surface::WlSurface, (f64, f64))>,
|
|
|
|
_serial: u32,
|
|
|
|
_time: u32,
|
|
|
|
) {
|
2020-02-02 15:05:49 +00:00
|
|
|
let dx = location.0 - self.start_data.location.0;
|
|
|
|
let dy = location.1 - self.start_data.location.1;
|
2020-02-01 15:42:08 +00:00
|
|
|
let new_window_x = (self.initial_window_location.0 as f64 + dx) as i32;
|
|
|
|
let new_window_y = (self.initial_window_location.1 as f64 + dy) as i32;
|
|
|
|
|
|
|
|
self.window_map
|
|
|
|
.borrow_mut()
|
|
|
|
.set_location(&self.toplevel, (new_window_x, new_window_y));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn button(
|
|
|
|
&mut self,
|
|
|
|
handle: &mut PointerInnerHandle<'_>,
|
|
|
|
button: u32,
|
|
|
|
state: ButtonState,
|
|
|
|
serial: u32,
|
|
|
|
time: u32,
|
|
|
|
) {
|
|
|
|
handle.button(button, state, serial, time);
|
|
|
|
if handle.current_pressed().is_empty() {
|
|
|
|
// No more buttons are pressed, release the grab.
|
|
|
|
handle.unset_grab(serial, time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn axis(&mut self, handle: &mut PointerInnerHandle<'_>, details: AxisFrame) {
|
|
|
|
handle.axis(details)
|
|
|
|
}
|
2020-02-02 15:05:49 +00:00
|
|
|
|
|
|
|
fn start_data(&self) -> &GrabStartData {
|
|
|
|
&self.start_data
|
|
|
|
}
|
2020-02-01 15:42:08 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 10:37:18 +00:00
|
|
|
bitflags::bitflags! {
|
2020-02-11 08:06:36 +00:00
|
|
|
struct ResizeEdge: u32 {
|
|
|
|
const NONE = 0;
|
|
|
|
const TOP = 1;
|
|
|
|
const BOTTOM = 2;
|
|
|
|
const LEFT = 4;
|
|
|
|
const TOP_LEFT = 5;
|
|
|
|
const BOTTOM_LEFT = 6;
|
|
|
|
const RIGHT = 8;
|
|
|
|
const TOP_RIGHT = 9;
|
|
|
|
const BOTTOM_RIGHT = 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<wl_shell_surface::Resize> for ResizeEdge {
|
|
|
|
#[inline]
|
|
|
|
fn from(x: wl_shell_surface::Resize) -> Self {
|
|
|
|
Self::from_bits(x.bits()).unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ResizeEdge> for wl_shell_surface::Resize {
|
|
|
|
#[inline]
|
|
|
|
fn from(x: ResizeEdge) -> Self {
|
|
|
|
Self::from_bits(x.bits()).unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<xdg_toplevel::ResizeEdge> for ResizeEdge {
|
|
|
|
#[inline]
|
|
|
|
fn from(x: xdg_toplevel::ResizeEdge) -> Self {
|
|
|
|
Self::from_bits(x.to_raw()).unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ResizeEdge> for xdg_toplevel::ResizeEdge {
|
|
|
|
#[inline]
|
|
|
|
fn from(x: ResizeEdge) -> Self {
|
|
|
|
Self::from_raw(x.bits()).unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-03 13:31:15 +00:00
|
|
|
struct ResizeSurfaceGrab {
|
|
|
|
start_data: GrabStartData,
|
2020-02-08 05:46:15 +00:00
|
|
|
ctoken: MyCompositorToken,
|
2020-02-03 13:31:15 +00:00
|
|
|
toplevel: SurfaceKind<Roles>,
|
2020-02-11 08:06:36 +00:00
|
|
|
edges: ResizeEdge,
|
2020-02-03 13:31:15 +00:00
|
|
|
initial_window_size: (i32, i32),
|
|
|
|
last_window_size: (i32, i32),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PointerGrab for ResizeSurfaceGrab {
|
|
|
|
fn motion(
|
|
|
|
&mut self,
|
|
|
|
_handle: &mut PointerInnerHandle<'_>,
|
|
|
|
location: (f64, f64),
|
|
|
|
_focus: Option<(wl_surface::WlSurface, (f64, f64))>,
|
|
|
|
serial: u32,
|
|
|
|
_time: u32,
|
|
|
|
) {
|
|
|
|
let mut dx = location.0 - self.start_data.location.0;
|
|
|
|
let mut dy = location.1 - self.start_data.location.1;
|
|
|
|
|
2020-02-08 06:24:50 +00:00
|
|
|
let mut new_window_width = self.initial_window_size.0;
|
|
|
|
let mut new_window_height = self.initial_window_size.1;
|
|
|
|
|
2020-02-11 08:06:36 +00:00
|
|
|
let left_right = ResizeEdge::LEFT | ResizeEdge::RIGHT;
|
|
|
|
let top_bottom = ResizeEdge::TOP | ResizeEdge::BOTTOM;
|
2020-02-08 06:24:50 +00:00
|
|
|
|
|
|
|
if self.edges.intersects(left_right) {
|
2020-02-11 08:06:36 +00:00
|
|
|
if self.edges.intersects(ResizeEdge::LEFT) {
|
2020-02-03 13:31:15 +00:00
|
|
|
dx = -dx;
|
|
|
|
}
|
|
|
|
|
2020-02-08 06:24:50 +00:00
|
|
|
new_window_width = (self.initial_window_size.0 as f64 + dx) as i32;
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.edges.intersects(top_bottom) {
|
2020-02-11 08:06:36 +00:00
|
|
|
if self.edges.intersects(ResizeEdge::TOP) {
|
2020-02-03 13:31:15 +00:00
|
|
|
dy = -dy;
|
|
|
|
}
|
|
|
|
|
2020-02-08 06:24:50 +00:00
|
|
|
new_window_height = (self.initial_window_size.1 as f64 + dy) as i32;
|
|
|
|
}
|
|
|
|
|
|
|
|
let (min_size, max_size) =
|
|
|
|
self.ctoken
|
|
|
|
.with_surface_data(self.toplevel.get_surface().unwrap(), |attrs| {
|
2020-04-05 17:01:08 +00:00
|
|
|
let data = attrs.user_data.get::<RefCell<SurfaceData>>().unwrap().borrow();
|
2020-02-08 06:24:50 +00:00
|
|
|
(data.min_size, data.max_size)
|
|
|
|
});
|
|
|
|
|
|
|
|
let min_width = min_size.0.max(1);
|
|
|
|
let min_height = min_size.1.max(1);
|
|
|
|
let max_width = if max_size.0 == 0 {
|
|
|
|
i32::max_value()
|
2020-02-03 13:31:15 +00:00
|
|
|
} else {
|
2020-02-08 06:24:50 +00:00
|
|
|
max_size.0
|
2020-02-03 13:31:15 +00:00
|
|
|
};
|
2020-02-08 06:24:50 +00:00
|
|
|
let max_height = if max_size.1 == 0 {
|
|
|
|
i32::max_value()
|
|
|
|
} else {
|
|
|
|
max_size.1
|
|
|
|
};
|
|
|
|
|
|
|
|
new_window_width = new_window_width.max(min_width).min(max_width);
|
|
|
|
new_window_height = new_window_height.max(min_height).min(max_height);
|
2020-02-03 13:31:15 +00:00
|
|
|
|
|
|
|
self.last_window_size = (new_window_width, new_window_height);
|
|
|
|
|
|
|
|
match &self.toplevel {
|
|
|
|
SurfaceKind::Xdg(xdg) => xdg.send_configure(ToplevelConfigure {
|
|
|
|
size: Some(self.last_window_size),
|
|
|
|
states: vec![xdg_toplevel::State::Resizing],
|
|
|
|
serial,
|
|
|
|
}),
|
|
|
|
SurfaceKind::Wl(wl) => wl.send_configure(
|
|
|
|
(self.last_window_size.0 as u32, self.last_window_size.1 as u32),
|
2020-02-11 08:06:36 +00:00
|
|
|
self.edges.into(),
|
2020-02-03 13:31:15 +00:00
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn button(
|
|
|
|
&mut self,
|
|
|
|
handle: &mut PointerInnerHandle<'_>,
|
|
|
|
button: u32,
|
|
|
|
state: ButtonState,
|
|
|
|
serial: u32,
|
|
|
|
time: u32,
|
|
|
|
) {
|
|
|
|
handle.button(button, state, serial, time);
|
|
|
|
if handle.current_pressed().is_empty() {
|
|
|
|
// No more buttons are pressed, release the grab.
|
|
|
|
handle.unset_grab(serial, time);
|
|
|
|
|
|
|
|
if let SurfaceKind::Xdg(xdg) = &self.toplevel {
|
|
|
|
// Send the final configure without the resizing state.
|
|
|
|
xdg.send_configure(ToplevelConfigure {
|
|
|
|
size: Some(self.last_window_size),
|
|
|
|
states: vec![],
|
|
|
|
serial,
|
|
|
|
});
|
2020-02-08 05:46:15 +00:00
|
|
|
|
|
|
|
self.ctoken
|
|
|
|
.with_surface_data(self.toplevel.get_surface().unwrap(), |attrs| {
|
2020-04-10 15:01:49 +00:00
|
|
|
let mut data = attrs
|
|
|
|
.user_data
|
|
|
|
.get::<RefCell<SurfaceData>>()
|
|
|
|
.unwrap()
|
|
|
|
.borrow_mut();
|
2020-02-08 05:46:15 +00:00
|
|
|
if let ResizeState::Resizing(resize_data) = data.resize_state {
|
|
|
|
data.resize_state = ResizeState::WaitingForFinalAck(resize_data, serial);
|
|
|
|
} else {
|
|
|
|
panic!("invalid resize state: {:?}", data.resize_state);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
self.ctoken
|
|
|
|
.with_surface_data(self.toplevel.get_surface().unwrap(), |attrs| {
|
2020-04-10 15:01:49 +00:00
|
|
|
let mut data = attrs
|
|
|
|
.user_data
|
|
|
|
.get::<RefCell<SurfaceData>>()
|
|
|
|
.unwrap()
|
|
|
|
.borrow_mut();
|
2020-02-08 05:46:15 +00:00
|
|
|
if let ResizeState::Resizing(resize_data) = data.resize_state {
|
|
|
|
data.resize_state = ResizeState::WaitingForCommit(resize_data);
|
|
|
|
} else {
|
|
|
|
panic!("invalid resize state: {:?}", data.resize_state);
|
|
|
|
}
|
|
|
|
});
|
2020-02-03 13:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn axis(&mut self, handle: &mut PointerInnerHandle<'_>, details: AxisFrame) {
|
|
|
|
handle.axis(details)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn start_data(&self) -> &GrabStartData {
|
|
|
|
&self.start_data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-02 10:42:02 +00:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct ShellHandles {
|
|
|
|
pub token: CompositorToken<Roles>,
|
|
|
|
pub xdg_state: Arc<Mutex<XdgShellState<Roles>>>,
|
|
|
|
pub wl_state: Arc<Mutex<WlShellState<Roles>>>,
|
|
|
|
pub window_map: Rc<RefCell<MyWindowMap>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn init_shell(display: &mut Display, buffer_utils: BufferUtils, log: ::slog::Logger) -> ShellHandles {
|
2020-02-08 05:44:39 +00:00
|
|
|
// TODO: this is awkward...
|
|
|
|
let almost_window_map = Rc::new(RefCell::new(None::<Rc<RefCell<MyWindowMap>>>));
|
|
|
|
let almost_window_map_compositor = almost_window_map.clone();
|
|
|
|
|
2018-04-22 09:58:39 +00:00
|
|
|
// Create the compositor
|
|
|
|
let (compositor_token, _, _) = compositor_init(
|
|
|
|
display,
|
2018-09-24 22:30:39 +00:00
|
|
|
move |request, surface, ctoken| match request {
|
2020-02-08 05:44:39 +00:00
|
|
|
SurfaceEvent::Commit => {
|
|
|
|
let window_map = almost_window_map_compositor.borrow();
|
|
|
|
let window_map = window_map.as_ref().unwrap();
|
|
|
|
surface_commit(&surface, ctoken, &buffer_utils, &*window_map)
|
|
|
|
}
|
2018-04-22 09:58:39 +00:00
|
|
|
},
|
|
|
|
log.clone(),
|
|
|
|
);
|
2017-09-22 12:56:59 +00:00
|
|
|
|
2018-04-22 09:58:39 +00:00
|
|
|
// Init a window map, to track the location of our windows
|
2020-02-03 12:55:48 +00:00
|
|
|
let window_map = Rc::new(RefCell::new(WindowMap::new(compositor_token)));
|
2020-02-08 05:44:39 +00:00
|
|
|
*almost_window_map.borrow_mut() = Some(window_map.clone());
|
2017-09-22 12:56:59 +00:00
|
|
|
|
2018-04-22 09:58:39 +00:00
|
|
|
// init the xdg_shell
|
2018-04-23 09:40:41 +00:00
|
|
|
let xdg_window_map = window_map.clone();
|
|
|
|
let (xdg_shell_state, _, _) = xdg_shell_init(
|
2018-04-22 09:58:39 +00:00
|
|
|
display,
|
2018-06-27 12:04:29 +00:00
|
|
|
compositor_token,
|
2018-09-24 22:30:39 +00:00
|
|
|
move |shell_event| match shell_event {
|
2018-04-22 17:58:10 +00:00
|
|
|
XdgRequest::NewToplevel { surface } => {
|
2018-11-21 00:46:34 +00:00
|
|
|
// place the window at a random location in the [0;800]x[0;800] square
|
2019-02-24 07:50:21 +00:00
|
|
|
use rand::distributions::{Distribution, Uniform};
|
|
|
|
let range = Uniform::new(0, 800);
|
2018-04-22 09:58:39 +00:00
|
|
|
let mut rng = rand::thread_rng();
|
2019-02-24 07:50:21 +00:00
|
|
|
let x = range.sample(&mut rng);
|
|
|
|
let y = range.sample(&mut rng);
|
2018-04-22 09:58:39 +00:00
|
|
|
surface.send_configure(ToplevelConfigure {
|
|
|
|
size: None,
|
|
|
|
states: vec![],
|
|
|
|
serial: 42,
|
|
|
|
});
|
2018-04-23 09:40:41 +00:00
|
|
|
xdg_window_map
|
|
|
|
.borrow_mut()
|
|
|
|
.insert(SurfaceKind::Xdg(surface), (x, y));
|
2018-04-22 09:58:39 +00:00
|
|
|
}
|
2018-04-22 17:58:10 +00:00
|
|
|
XdgRequest::NewPopup { surface } => surface.send_configure(PopupConfigure {
|
2018-04-22 09:58:39 +00:00
|
|
|
size: (10, 10),
|
|
|
|
position: (10, 10),
|
|
|
|
serial: 42,
|
|
|
|
}),
|
2020-02-01 15:42:08 +00:00
|
|
|
XdgRequest::Move {
|
|
|
|
surface,
|
|
|
|
seat,
|
|
|
|
serial,
|
|
|
|
} => {
|
|
|
|
let seat = Seat::from_resource(&seat).unwrap();
|
|
|
|
// TODO: touch move.
|
|
|
|
let pointer = seat.get_pointer().unwrap();
|
|
|
|
|
2020-02-02 15:07:43 +00:00
|
|
|
// Check that this surface has a click grab.
|
|
|
|
if !pointer.has_grab(serial) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-02 15:05:49 +00:00
|
|
|
let start_data = pointer.grab_start_data().unwrap();
|
|
|
|
|
2020-02-02 15:09:21 +00:00
|
|
|
// If the focus was for a different surface, ignore the request.
|
|
|
|
if start_data.focus.is_none()
|
|
|
|
|| !start_data
|
|
|
|
.focus
|
|
|
|
.as_ref()
|
|
|
|
.unwrap()
|
|
|
|
.0
|
|
|
|
.as_ref()
|
|
|
|
.same_client_as(surface.get_surface().unwrap().as_ref())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-01 15:42:08 +00:00
|
|
|
let toplevel = SurfaceKind::Xdg(surface);
|
|
|
|
let initial_window_location = xdg_window_map.borrow().location(&toplevel).unwrap();
|
|
|
|
|
|
|
|
let grab = MoveSurfaceGrab {
|
2020-02-02 15:05:49 +00:00
|
|
|
start_data,
|
2020-02-01 15:42:08 +00:00
|
|
|
window_map: xdg_window_map.clone(),
|
|
|
|
toplevel,
|
|
|
|
initial_window_location,
|
|
|
|
};
|
|
|
|
|
|
|
|
pointer.set_grab(grab, serial);
|
|
|
|
}
|
2020-02-03 13:31:15 +00:00
|
|
|
XdgRequest::Resize {
|
|
|
|
surface,
|
|
|
|
seat,
|
|
|
|
serial,
|
|
|
|
edges,
|
|
|
|
} => {
|
|
|
|
let seat = Seat::from_resource(&seat).unwrap();
|
|
|
|
// TODO: touch resize.
|
|
|
|
let pointer = seat.get_pointer().unwrap();
|
|
|
|
|
|
|
|
// Check that this surface has a click grab.
|
|
|
|
if !pointer.has_grab(serial) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let start_data = pointer.grab_start_data().unwrap();
|
|
|
|
|
|
|
|
// If the focus was for a different surface, ignore the request.
|
|
|
|
if start_data.focus.is_none()
|
|
|
|
|| !start_data
|
|
|
|
.focus
|
|
|
|
.as_ref()
|
|
|
|
.unwrap()
|
|
|
|
.0
|
|
|
|
.as_ref()
|
|
|
|
.same_client_as(surface.get_surface().unwrap().as_ref())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-08 05:46:15 +00:00
|
|
|
let toplevel = SurfaceKind::Xdg(surface.clone());
|
2020-02-03 13:31:15 +00:00
|
|
|
let initial_window_location = xdg_window_map.borrow().location(&toplevel).unwrap();
|
|
|
|
let geometry = xdg_window_map.borrow().geometry(&toplevel).unwrap();
|
|
|
|
let initial_window_size = (geometry.width, geometry.height);
|
|
|
|
|
2020-02-08 05:46:15 +00:00
|
|
|
compositor_token.with_surface_data(surface.get_surface().unwrap(), move |attrs| {
|
2020-04-10 15:01:49 +00:00
|
|
|
attrs
|
|
|
|
.user_data
|
|
|
|
.get::<RefCell<SurfaceData>>()
|
|
|
|
.unwrap()
|
|
|
|
.borrow_mut()
|
|
|
|
.resize_state = ResizeState::Resizing(ResizeData {
|
|
|
|
edges: edges.into(),
|
|
|
|
initial_window_location,
|
|
|
|
initial_window_size,
|
|
|
|
});
|
2020-02-08 05:46:15 +00:00
|
|
|
});
|
|
|
|
|
2020-02-03 13:31:15 +00:00
|
|
|
let grab = ResizeSurfaceGrab {
|
|
|
|
start_data,
|
2020-02-08 05:46:15 +00:00
|
|
|
ctoken: compositor_token,
|
2020-02-03 13:31:15 +00:00
|
|
|
toplevel,
|
2020-02-11 08:06:36 +00:00
|
|
|
edges: edges.into(),
|
2020-02-03 13:31:15 +00:00
|
|
|
initial_window_size,
|
|
|
|
last_window_size: initial_window_size,
|
|
|
|
};
|
|
|
|
|
|
|
|
pointer.set_grab(grab, serial);
|
|
|
|
}
|
2020-02-08 05:46:15 +00:00
|
|
|
XdgRequest::AckConfigure { surface, .. } => {
|
|
|
|
let waiting_for_serial = compositor_token.with_surface_data(&surface, |attrs| {
|
2020-04-05 17:01:08 +00:00
|
|
|
if let Some(data) = attrs.user_data.get::<RefCell<SurfaceData>>() {
|
|
|
|
if let ResizeState::WaitingForFinalAck(_, serial) = data.borrow().resize_state {
|
2020-02-08 05:46:15 +00:00
|
|
|
return Some(serial);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
});
|
|
|
|
|
|
|
|
if let Some(serial) = waiting_for_serial {
|
|
|
|
let acked = compositor_token
|
|
|
|
.with_role_data(&surface, |role: &mut XdgSurfaceRole| {
|
|
|
|
!role.pending_configures.contains(&serial)
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
if acked {
|
|
|
|
compositor_token.with_surface_data(&surface, |attrs| {
|
2020-04-10 15:01:49 +00:00
|
|
|
let mut data = attrs
|
|
|
|
.user_data
|
|
|
|
.get::<RefCell<SurfaceData>>()
|
|
|
|
.unwrap()
|
|
|
|
.borrow_mut();
|
2020-02-08 05:46:15 +00:00
|
|
|
if let ResizeState::WaitingForFinalAck(resize_data, _) = data.resize_state {
|
|
|
|
data.resize_state = ResizeState::WaitingForCommit(resize_data);
|
|
|
|
} else {
|
|
|
|
unreachable!()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-22 09:58:39 +00:00
|
|
|
_ => (),
|
2017-09-22 12:56:59 +00:00
|
|
|
},
|
|
|
|
log.clone(),
|
|
|
|
);
|
|
|
|
|
2018-04-23 09:40:41 +00:00
|
|
|
// init the wl_shell
|
|
|
|
let shell_window_map = window_map.clone();
|
|
|
|
let (wl_shell_state, _) = wl_shell_init(
|
|
|
|
display,
|
2018-06-27 12:04:29 +00:00
|
|
|
compositor_token,
|
2019-04-23 21:52:14 +00:00
|
|
|
move |req: ShellRequest<_>| {
|
2020-02-01 15:42:08 +00:00
|
|
|
match req {
|
|
|
|
ShellRequest::SetKind {
|
|
|
|
surface,
|
|
|
|
kind: ShellSurfaceKind::Toplevel,
|
|
|
|
} => {
|
|
|
|
// place the window at a random location in the [0;800]x[0;800] square
|
|
|
|
use rand::distributions::{Distribution, Uniform};
|
|
|
|
let range = Uniform::new(0, 800);
|
|
|
|
let mut rng = rand::thread_rng();
|
|
|
|
let x = range.sample(&mut rng);
|
|
|
|
let y = range.sample(&mut rng);
|
|
|
|
shell_window_map
|
|
|
|
.borrow_mut()
|
|
|
|
.insert(SurfaceKind::Wl(surface), (x, y));
|
|
|
|
}
|
|
|
|
ShellRequest::Move {
|
|
|
|
surface,
|
|
|
|
seat,
|
|
|
|
serial,
|
|
|
|
} => {
|
|
|
|
let seat = Seat::from_resource(&seat).unwrap();
|
|
|
|
// TODO: touch move.
|
|
|
|
let pointer = seat.get_pointer().unwrap();
|
|
|
|
|
2020-02-02 15:07:43 +00:00
|
|
|
// Check that this surface has a click grab.
|
|
|
|
if !pointer.has_grab(serial) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-02 15:05:49 +00:00
|
|
|
let start_data = pointer.grab_start_data().unwrap();
|
|
|
|
|
2020-02-02 15:09:21 +00:00
|
|
|
// If the focus was for a different surface, ignore the request.
|
|
|
|
if start_data.focus.is_none()
|
|
|
|
|| !start_data
|
|
|
|
.focus
|
|
|
|
.as_ref()
|
|
|
|
.unwrap()
|
|
|
|
.0
|
|
|
|
.as_ref()
|
|
|
|
.same_client_as(surface.get_surface().unwrap().as_ref())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-01 15:42:08 +00:00
|
|
|
let toplevel = SurfaceKind::Wl(surface);
|
|
|
|
let initial_window_location = shell_window_map.borrow().location(&toplevel).unwrap();
|
|
|
|
|
|
|
|
let grab = MoveSurfaceGrab {
|
2020-02-02 15:05:49 +00:00
|
|
|
start_data,
|
2020-02-01 15:42:08 +00:00
|
|
|
window_map: shell_window_map.clone(),
|
|
|
|
toplevel,
|
|
|
|
initial_window_location,
|
|
|
|
};
|
|
|
|
|
|
|
|
pointer.set_grab(grab, serial);
|
|
|
|
}
|
2020-02-03 13:31:15 +00:00
|
|
|
ShellRequest::Resize {
|
|
|
|
surface,
|
|
|
|
seat,
|
|
|
|
serial,
|
|
|
|
edges,
|
|
|
|
} => {
|
|
|
|
let seat = Seat::from_resource(&seat).unwrap();
|
|
|
|
// TODO: touch resize.
|
|
|
|
let pointer = seat.get_pointer().unwrap();
|
|
|
|
|
|
|
|
// Check that this surface has a click grab.
|
|
|
|
if !pointer.has_grab(serial) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let start_data = pointer.grab_start_data().unwrap();
|
|
|
|
|
|
|
|
// If the focus was for a different surface, ignore the request.
|
|
|
|
if start_data.focus.is_none()
|
|
|
|
|| !start_data
|
|
|
|
.focus
|
|
|
|
.as_ref()
|
|
|
|
.unwrap()
|
|
|
|
.0
|
|
|
|
.as_ref()
|
|
|
|
.same_client_as(surface.get_surface().unwrap().as_ref())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-08 05:46:15 +00:00
|
|
|
let toplevel = SurfaceKind::Wl(surface.clone());
|
2020-02-03 13:31:15 +00:00
|
|
|
let initial_window_location = shell_window_map.borrow().location(&toplevel).unwrap();
|
|
|
|
let geometry = shell_window_map.borrow().geometry(&toplevel).unwrap();
|
|
|
|
let initial_window_size = (geometry.width, geometry.height);
|
|
|
|
|
2020-02-08 05:46:15 +00:00
|
|
|
compositor_token.with_surface_data(surface.get_surface().unwrap(), move |attrs| {
|
2020-04-10 15:01:49 +00:00
|
|
|
attrs
|
|
|
|
.user_data
|
|
|
|
.get::<RefCell<SurfaceData>>()
|
|
|
|
.unwrap()
|
|
|
|
.borrow_mut()
|
|
|
|
.resize_state = ResizeState::Resizing(ResizeData {
|
|
|
|
edges: edges.into(),
|
|
|
|
initial_window_location,
|
|
|
|
initial_window_size,
|
|
|
|
});
|
2020-02-08 05:46:15 +00:00
|
|
|
});
|
|
|
|
|
2020-02-03 13:31:15 +00:00
|
|
|
let grab = ResizeSurfaceGrab {
|
|
|
|
start_data,
|
2020-02-08 05:46:15 +00:00
|
|
|
ctoken: compositor_token,
|
2020-02-03 13:31:15 +00:00
|
|
|
toplevel,
|
2020-02-11 08:06:36 +00:00
|
|
|
edges: edges.into(),
|
2020-02-03 13:31:15 +00:00
|
|
|
initial_window_size,
|
|
|
|
last_window_size: initial_window_size,
|
|
|
|
};
|
|
|
|
|
|
|
|
pointer.set_grab(grab, serial);
|
|
|
|
}
|
2020-02-01 15:42:08 +00:00
|
|
|
_ => (),
|
2018-09-24 22:32:09 +00:00
|
|
|
}
|
|
|
|
},
|
2018-04-23 09:40:41 +00:00
|
|
|
log.clone(),
|
|
|
|
);
|
|
|
|
|
2020-05-02 10:42:02 +00:00
|
|
|
ShellHandles {
|
|
|
|
token: compositor_token,
|
|
|
|
xdg_state: xdg_shell_state,
|
|
|
|
wl_state: wl_shell_state,
|
|
|
|
window_map,
|
|
|
|
}
|
2017-09-22 12:56:59 +00:00
|
|
|
}
|
2018-05-07 17:56:38 +00:00
|
|
|
|
2020-02-08 05:46:15 +00:00
|
|
|
/// Information about the resize operation.
|
|
|
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
|
|
|
pub struct ResizeData {
|
|
|
|
/// The edges the surface is being resized with.
|
2020-02-11 08:06:36 +00:00
|
|
|
edges: ResizeEdge,
|
2020-02-08 05:46:15 +00:00
|
|
|
/// The initial window location.
|
|
|
|
initial_window_location: (i32, i32),
|
|
|
|
/// The initial window size (geometry width and height).
|
|
|
|
initial_window_size: (i32, i32),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// State of the resize operation.
|
|
|
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
|
|
|
pub enum ResizeState {
|
|
|
|
/// The surface is not being resized.
|
|
|
|
NotResizing,
|
|
|
|
/// The surface is currently being resized.
|
|
|
|
Resizing(ResizeData),
|
|
|
|
/// The resize has finished, and the surface needs to ack the final configure.
|
|
|
|
WaitingForFinalAck(ResizeData, u32),
|
|
|
|
/// The resize has finished, and the surface needs to commit its final state.
|
|
|
|
WaitingForCommit(ResizeData),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ResizeState {
|
|
|
|
fn default() -> Self {
|
|
|
|
ResizeState::NotResizing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 18:53:55 +00:00
|
|
|
#[derive(Default, Clone)]
|
|
|
|
pub struct CommitedState {
|
|
|
|
pub buffer: Option<wl_buffer::WlBuffer>,
|
|
|
|
pub input_region: Option<RegionAttributes>,
|
|
|
|
pub dimensions: Option<(i32, i32)>,
|
|
|
|
pub frame_callback: Option<wl_callback::WlCallback>,
|
|
|
|
pub sub_location: (i32, i32),
|
|
|
|
}
|
|
|
|
|
2018-05-07 17:56:38 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct SurfaceData {
|
2020-06-27 16:27:47 +00:00
|
|
|
pub texture: Option<crate::buffer_utils::BufferTextures>,
|
2020-02-03 13:22:48 +00:00
|
|
|
pub geometry: Option<Rectangle>,
|
2020-02-08 05:46:15 +00:00
|
|
|
pub resize_state: ResizeState,
|
2020-02-08 06:24:27 +00:00
|
|
|
/// Minimum width and height, as requested by the surface.
|
|
|
|
///
|
|
|
|
/// `0` means unlimited.
|
|
|
|
pub min_size: (i32, i32),
|
|
|
|
/// Maximum width and height, as requested by the surface.
|
|
|
|
///
|
|
|
|
/// `0` means unlimited.
|
|
|
|
pub max_size: (i32, i32),
|
2020-04-21 18:53:55 +00:00
|
|
|
pub current_state: CommitedState,
|
|
|
|
pub cached_state: Option<CommitedState>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SurfaceData {
|
|
|
|
/// Apply a next state into the surface current state
|
|
|
|
pub fn apply_state(&mut self, next_state: CommitedState) {
|
|
|
|
if Self::merge_state(&mut self.current_state, next_state) {
|
2020-06-27 16:27:47 +00:00
|
|
|
let _ = self.texture.take();
|
2020-04-21 18:53:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Apply a next state into the cached state
|
|
|
|
pub fn apply_cache(&mut self, next_state: CommitedState) {
|
|
|
|
match self.cached_state {
|
|
|
|
Some(ref mut cached) => {
|
|
|
|
Self::merge_state(cached, next_state);
|
|
|
|
}
|
|
|
|
None => self.cached_state = Some(next_state),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Apply the current cached state if any
|
|
|
|
pub fn apply_from_cache(&mut self) {
|
|
|
|
if let Some(cached) = self.cached_state.take() {
|
|
|
|
self.apply_state(cached);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// merge the "next" state into the "into" state
|
|
|
|
//
|
|
|
|
// returns true if the texture cache should be invalidated
|
|
|
|
fn merge_state(into: &mut CommitedState, next: CommitedState) -> bool {
|
|
|
|
// release the previous buffer if relevant
|
2020-04-25 17:12:51 +00:00
|
|
|
let new_buffer = into.buffer != next.buffer;
|
|
|
|
if new_buffer {
|
2020-04-21 18:53:55 +00:00
|
|
|
if let Some(buffer) = into.buffer.take() {
|
|
|
|
buffer.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ping the previous callback if relevant
|
|
|
|
if into.frame_callback != next.frame_callback {
|
|
|
|
if let Some(callback) = into.frame_callback.take() {
|
|
|
|
callback.done(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*into = next;
|
|
|
|
new_buffer
|
|
|
|
}
|
2018-05-07 17:56:38 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 12:55:48 +00:00
|
|
|
impl SurfaceData {
|
|
|
|
/// Returns the size of the surface.
|
|
|
|
pub fn size(&self) -> Option<(i32, i32)> {
|
2020-04-21 18:53:55 +00:00
|
|
|
self.current_state.dimensions
|
2020-02-03 12:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Checks if the surface's input region contains the point.
|
|
|
|
pub fn contains_point(&self, point: (f64, f64)) -> bool {
|
|
|
|
let (w, h) = match self.size() {
|
|
|
|
None => return false, // If the surface has no size, it can't have an input region.
|
|
|
|
Some(wh) => wh,
|
|
|
|
};
|
|
|
|
|
|
|
|
let rect = Rectangle {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: w,
|
|
|
|
height: h,
|
|
|
|
};
|
|
|
|
|
|
|
|
let point = (point.0 as i32, point.1 as i32);
|
|
|
|
|
|
|
|
// The input region is always within the surface itself, so if the surface itself doesn't contain the
|
|
|
|
// point we can return false.
|
|
|
|
if !rect.contains(point) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's no input region, we're done.
|
2020-04-21 18:53:55 +00:00
|
|
|
if self.current_state.input_region.is_none() {
|
2020-02-03 12:55:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-21 18:53:55 +00:00
|
|
|
self.current_state.input_region.as_ref().unwrap().contains(point)
|
2020-02-03 12:55:48 +00:00
|
|
|
}
|
2020-04-21 17:42:03 +00:00
|
|
|
|
|
|
|
/// Send the frame callback if it had been requested
|
|
|
|
pub fn send_frame(&mut self, serial: u32) {
|
2020-04-21 18:53:55 +00:00
|
|
|
if let Some(callback) = self.current_state.frame_callback.take() {
|
2020-04-21 17:42:03 +00:00
|
|
|
callback.done(serial);
|
|
|
|
}
|
|
|
|
}
|
2018-05-07 17:56:38 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 05:42:12 +00:00
|
|
|
fn surface_commit(
|
|
|
|
surface: &wl_surface::WlSurface,
|
|
|
|
token: CompositorToken<Roles>,
|
|
|
|
buffer_utils: &BufferUtils,
|
2020-02-08 05:44:39 +00:00
|
|
|
window_map: &RefCell<MyWindowMap>,
|
2020-02-03 05:42:12 +00:00
|
|
|
) {
|
2020-02-08 06:24:27 +00:00
|
|
|
let mut geometry = None;
|
|
|
|
let mut min_size = (0, 0);
|
|
|
|
let mut max_size = (0, 0);
|
|
|
|
let _ = token.with_role_data(surface, |role: &mut XdgSurfaceRole| {
|
|
|
|
if let XdgSurfacePendingState::Toplevel(ref state) = role.pending_state {
|
|
|
|
min_size = state.min_size;
|
|
|
|
max_size = state.max_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
geometry = role.window_geometry;
|
|
|
|
});
|
2020-02-03 13:22:48 +00:00
|
|
|
|
2020-04-21 18:53:55 +00:00
|
|
|
let sub_data = token
|
2020-04-25 17:12:51 +00:00
|
|
|
.with_role_data(surface, |&mut role: &mut SubsurfaceRole| role)
|
2020-04-21 18:53:55 +00:00
|
|
|
.ok();
|
|
|
|
|
|
|
|
let mut next_state = CommitedState::default();
|
|
|
|
|
|
|
|
let (refresh, apply_children) = token.with_surface_data(surface, |attributes| {
|
2020-04-10 15:01:49 +00:00
|
|
|
attributes
|
|
|
|
.user_data
|
|
|
|
.insert_if_missing(|| RefCell::new(SurfaceData::default()));
|
|
|
|
let mut data = attributes
|
|
|
|
.user_data
|
|
|
|
.get::<RefCell<SurfaceData>>()
|
|
|
|
.unwrap()
|
|
|
|
.borrow_mut();
|
2020-02-02 09:41:35 +00:00
|
|
|
|
2020-04-21 18:53:55 +00:00
|
|
|
if let Some(ref cached_state) = data.cached_state {
|
|
|
|
// There is a pending state, accumulate into it
|
|
|
|
next_state = cached_state.clone();
|
|
|
|
} else {
|
|
|
|
// start from the current state
|
|
|
|
next_state = data.current_state.clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(ref data) = sub_data {
|
|
|
|
next_state.sub_location = data.location;
|
|
|
|
}
|
|
|
|
|
2020-02-03 13:22:48 +00:00
|
|
|
data.geometry = geometry;
|
2020-04-21 18:53:55 +00:00
|
|
|
next_state.input_region = attributes.input_region.clone();
|
2020-02-08 06:24:27 +00:00
|
|
|
data.min_size = min_size;
|
|
|
|
data.max_size = max_size;
|
2020-02-02 09:41:35 +00:00
|
|
|
|
|
|
|
// we retrieve the contents of the associated buffer and copy it
|
2018-05-07 17:56:38 +00:00
|
|
|
match attributes.buffer.take() {
|
2020-04-15 07:28:22 +00:00
|
|
|
Some(BufferAssignment::NewBuffer { buffer, .. }) => {
|
2018-05-19 17:51:26 +00:00
|
|
|
// new contents
|
2020-04-21 18:53:55 +00:00
|
|
|
next_state.dimensions = buffer_utils.dimensions(&buffer);
|
|
|
|
next_state.buffer = Some(buffer);
|
2018-05-07 17:56:38 +00:00
|
|
|
}
|
2020-04-15 07:28:22 +00:00
|
|
|
Some(BufferAssignment::Removed) => {
|
2020-04-21 18:53:55 +00:00
|
|
|
// remove the contents
|
|
|
|
next_state.buffer = None;
|
|
|
|
next_state.dimensions = None;
|
2018-05-07 17:56:38 +00:00
|
|
|
}
|
|
|
|
None => {}
|
|
|
|
}
|
2020-02-08 05:44:39 +00:00
|
|
|
|
2020-04-21 18:53:55 +00:00
|
|
|
if let Some(frame_cb) = attributes.frame_callback.take() {
|
|
|
|
if let Some(old_cb) = next_state.frame_callback.take() {
|
|
|
|
old_cb.done(0);
|
2020-04-17 16:27:10 +00:00
|
|
|
}
|
2020-04-21 18:53:55 +00:00
|
|
|
next_state.frame_callback = Some(frame_cb);
|
2020-04-17 16:27:10 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 18:53:55 +00:00
|
|
|
data.apply_cache(next_state);
|
|
|
|
|
|
|
|
let apply_children = if let Some(SubsurfaceRole { sync: true, .. }) = sub_data {
|
|
|
|
false
|
|
|
|
} else {
|
|
|
|
data.apply_from_cache();
|
|
|
|
true
|
|
|
|
};
|
|
|
|
|
|
|
|
(window_map.borrow().find(surface), apply_children)
|
2018-05-07 17:56:38 +00:00
|
|
|
});
|
|
|
|
|
2020-04-21 18:53:55 +00:00
|
|
|
// Apply the cached state of all sync children
|
|
|
|
if apply_children {
|
|
|
|
token.with_surface_tree_upward(
|
|
|
|
surface,
|
|
|
|
true,
|
|
|
|
|_, _, role, &is_root| {
|
|
|
|
// only process children if the surface is sync or we are the root
|
|
|
|
if is_root {
|
|
|
|
// we are the root
|
|
|
|
TraversalAction::DoChildren(false)
|
|
|
|
} else if let Ok(sub_data) = Role::<SubsurfaceRole>::data(role) {
|
|
|
|
if sub_data.sync || is_root {
|
|
|
|
TraversalAction::DoChildren(false)
|
|
|
|
} else {
|
|
|
|
// if we are not sync, we won't apply from cache and don't process
|
|
|
|
// the children
|
|
|
|
TraversalAction::SkipChildren
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unreachable!();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|_, attributes, role, _| {
|
|
|
|
// only apply from cache if we are a sync subsurface
|
|
|
|
if let Ok(sub_data) = Role::<SubsurfaceRole>::data(role) {
|
|
|
|
if sub_data.sync {
|
|
|
|
if let Some(data) = attributes.user_data.get::<RefCell<SurfaceData>>() {
|
|
|
|
data.borrow_mut().apply_from_cache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|_, _, _, _| true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-02-08 05:44:39 +00:00
|
|
|
if let Some(toplevel) = refresh {
|
|
|
|
let mut window_map = window_map.borrow_mut();
|
|
|
|
window_map.refresh_toplevel(&toplevel);
|
2020-02-08 05:46:15 +00:00
|
|
|
// Get the geometry outside since it uses the token, and so would block inside.
|
|
|
|
let Rectangle { width, height, .. } = window_map.geometry(&toplevel).unwrap();
|
|
|
|
|
|
|
|
let new_location = token.with_surface_data(surface, |attributes| {
|
2020-04-10 15:01:49 +00:00
|
|
|
let mut data = attributes
|
|
|
|
.user_data
|
|
|
|
.get::<RefCell<SurfaceData>>()
|
|
|
|
.unwrap()
|
|
|
|
.borrow_mut();
|
2020-02-08 05:46:15 +00:00
|
|
|
|
|
|
|
let mut new_location = None;
|
|
|
|
|
|
|
|
// If the window is being resized by top or left, its location must be adjusted
|
|
|
|
// accordingly.
|
|
|
|
match data.resize_state {
|
|
|
|
ResizeState::Resizing(resize_data)
|
|
|
|
| ResizeState::WaitingForFinalAck(resize_data, _)
|
|
|
|
| ResizeState::WaitingForCommit(resize_data) => {
|
|
|
|
let ResizeData {
|
|
|
|
edges,
|
|
|
|
initial_window_location,
|
|
|
|
initial_window_size,
|
|
|
|
} = resize_data;
|
2020-01-22 04:00:37 +00:00
|
|
|
|
2020-02-11 08:06:36 +00:00
|
|
|
if edges.intersects(ResizeEdge::TOP_LEFT) {
|
2020-02-08 05:46:15 +00:00
|
|
|
let mut location = window_map.location(&toplevel).unwrap();
|
2020-01-22 04:45:25 +00:00
|
|
|
|
2020-02-11 08:06:36 +00:00
|
|
|
if edges.intersects(ResizeEdge::LEFT) {
|
2020-02-08 05:46:15 +00:00
|
|
|
location.0 = initial_window_location.0 + (initial_window_size.0 - width);
|
|
|
|
}
|
2020-02-11 08:06:36 +00:00
|
|
|
if edges.intersects(ResizeEdge::TOP) {
|
2020-02-08 05:46:15 +00:00
|
|
|
location.1 = initial_window_location.1 + (initial_window_size.1 - height);
|
|
|
|
}
|
2020-02-02 09:42:23 +00:00
|
|
|
|
2020-02-08 05:46:15 +00:00
|
|
|
new_location = Some(location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ResizeState::NotResizing => (),
|
|
|
|
}
|
2020-01-22 04:45:25 +00:00
|
|
|
|
2020-02-08 05:46:15 +00:00
|
|
|
// Finish resizing.
|
|
|
|
if let ResizeState::WaitingForCommit(_) = data.resize_state {
|
|
|
|
data.resize_state = ResizeState::NotResizing;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_location
|
|
|
|
});
|
|
|
|
|
|
|
|
if let Some(location) = new_location {
|
|
|
|
window_map.set_location(&toplevel, location);
|
|
|
|
}
|
2020-02-08 05:44:39 +00:00
|
|
|
}
|
2020-01-22 04:00:37 +00:00
|
|
|
}
|