Compare commits

...

3 commits

Author SHA1 Message Date
0654da34ee merge: pop-os/winit 9567503 (pin iced epoch-1.9.0) 2026-09-24 20:44:57 +02:00
Hojjat
9567503d34 feat: touch resize, move, window menu 2026-09-16 07:04:27 -06:00
Wildan M
71ce08c043 winit-orbital: Redox i586 compilation 2026-07-12 13:18:37 -06:00
3 changed files with 41 additions and 8 deletions

View file

@ -1,5 +1,6 @@
use std::cell::Cell;
use std::collections::VecDeque;
use std::os::raw::c_long;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex, mpsc};
use std::time::Instant;
@ -658,7 +659,7 @@ impl EventLoop {
if let Some(duration) = instant.checked_duration_since(start) {
time.tv_sec += duration.as_secs() as i64;
time.tv_nsec += duration.subsec_nanos() as i64;
time.tv_nsec += duration.subsec_nanos() as c_long;
// Normalize timespec so tv_nsec is not greater than one second.
while time.tv_nsec >= 1_000_000_000 {
time.tv_sec += 1;

View file

@ -19,7 +19,7 @@ impl TouchHandler for WinitState {
_: &Connection,
_: &QueueHandle<Self>,
touch: &WlTouch,
_: u32,
serial: u32,
_: u32,
surface: WlSurface,
id: i32,
@ -27,7 +27,12 @@ impl TouchHandler for WinitState {
) {
let window_id = crate::make_wid(&surface);
let scale_factor = match self.windows.get_mut().get(&window_id) {
Some(window) => window.lock().unwrap().scale_factor(),
Some(window) => {
let mut window = window.lock().unwrap();
// Remember the serial so drag/resize requests can use it while the finger is down.
window.touch_down = Some((touch.seat().clone(), serial));
window.scale_factor()
},
None => return,
};
@ -105,8 +110,15 @@ impl TouchHandler for WinitState {
}
let window_id = crate::make_wid(&touch_point.surface);
let still_touched = seat_state.touch_map.values().any(|p| p.surface == touch_point.surface);
let scale_factor = match self.windows.get_mut().get(&window_id) {
Some(window) => window.lock().unwrap().scale_factor(),
Some(window) => {
let mut window = window.lock().unwrap();
if !still_touched {
window.touch_down = None;
}
window.scale_factor()
},
None => return,
};
@ -193,7 +205,11 @@ impl TouchHandler for WinitState {
for (id, touch_point) in seat_state.touch_map.drain() {
let window_id = crate::make_wid(&touch_point.surface);
let scale_factor = match self.windows.get_mut().get(&window_id) {
Some(window) => window.lock().unwrap().scale_factor(),
Some(window) => {
let mut window = window.lock().unwrap();
window.touch_down = None;
window.scale_factor()
},
None => return,
};

View file

@ -69,6 +69,9 @@ pub struct WindowState {
/// The pointers observed on the window.
pub pointers: Vec<Weak<ThemedPointer<WinitPointerData>>>,
/// The seat and serial of the touch currently down on the window, if any.
pub touch_down: Option<(WlSeat, u32)>,
selected_cursor: SelectedCursor,
/// Whether the cursor is visible.
@ -224,6 +227,7 @@ impl WindowState {
min_surface_size: MIN_WINDOW_SIZE,
pointer_constraints,
pointers: Default::default(),
touch_down: None,
queue_handle: queue_handle.clone(),
resizable: true,
scale_factor: 1.,
@ -414,7 +418,11 @@ impl WindowState {
pub fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), RequestError> {
let xdg_toplevel = self.window.xdg_toplevel();
// TODO(kchibisov) handle touch serials.
if let Some((seat, serial)) = &self.touch_down {
xdg_toplevel.resize(seat, *serial, resize_direction_to_xdg(direction));
return Ok(());
}
self.apply_on_pointer(|_, data| {
let serial = data.latest_button_serial();
let seat = data.seat();
@ -427,7 +435,11 @@ impl WindowState {
/// Start the window drag.
pub fn drag_window(&self) -> Result<(), RequestError> {
let xdg_toplevel = self.window.xdg_toplevel();
// TODO(kchibisov) handle touch serials.
if let Some((seat, serial)) = &self.touch_down {
xdg_toplevel._move(seat, *serial);
return Ok(());
}
self.apply_on_pointer(|_, data| {
let serial = data.latest_button_serial();
let seat = data.seat();
@ -916,7 +928,11 @@ impl WindowState {
}
pub fn show_window_menu(&self, position: LogicalPosition<u32>) {
// TODO(kchibisov) handle touch serials.
if let Some((seat, serial)) = &self.touch_down {
self.window.show_window_menu(seat, *serial, position.into());
return;
}
self.apply_on_pointer(|_, data| {
let serial = data.latest_button_serial();
let seat = data.seat();