Skip to content
Extraits de code Groupes Projets

Comparer les révisions

Les modifications sont affichées comme si la révision source était fusionnée avec la révision cible. En savoir plus sur la comparaison des révisions.

Source

Sélectionner le projet cible
No results found

Cible

Sélectionner le projet cible
  • salixor/rs-wayland-compositor
1 résultat
Afficher les modifications
Validations sur la source (2)
......@@ -3,9 +3,9 @@ use smithay::{
desktop::Window,
input::pointer::{
AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent,
GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, GestureSwipeEndEvent,
GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab,
PointerInnerHandle, RelativeMotionEvent,
GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent,
GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData,
MotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent,
},
reexports::wayland_server::protocol::wl_surface::WlSurface,
utils::{Logical, Point},
......@@ -30,8 +30,21 @@ impl PointerGrab<Smallvil> for MoveSurfaceGrab {
let delta = event.location - self.start_data.location;
let new_location = self.initial_window_location.to_f64() + delta;
let wsize = data.space.element_geometry(&self.window).unwrap().size;
let window_outputs = data.space.outputs_for_element(&self.window);
let output = window_outputs
.first()
.or_else(|| data.space.outputs().next())
.expect("No outputs?");
let output_size = output.current_mode().unwrap().size;
let x = (new_location.x as i32).max(0).min(output_size.w - wsize.w);
let y = (new_location.y as i32).max(0).min(output_size.h - wsize.h);
data.space
.map_element(self.window.clone(), new_location.to_i32_round(), true);
.map_element(self.window.clone(), Point::from((x, y)), true);
}
fn relative_motion(
......@@ -57,6 +70,33 @@ impl PointerGrab<Smallvil> for MoveSurfaceGrab {
const BTN_LEFT: u32 = 0x110;
if !handle.current_pressed().contains(&BTN_LEFT) {
let window_outputs = data.space.outputs_for_element(&self.window);
let output = window_outputs
.first()
.or_else(|| data.space.outputs().next())
.expect("No outputs?");
let output_size = output.current_mode().unwrap().size;
let current_location = handle.current_location();
let is_anchor_left_side = current_location.x <= 15.0;
let is_anchor_right_side = current_location.x >= (output_size.w - 15).into();
if is_anchor_left_side || is_anchor_right_side {
let new_location = Point::from((
is_anchor_right_side.then(|| output_size.w / 2).unwrap_or(0),
0,
));
data.space
.map_element(self.window.clone(), new_location, true);
let xdg = self.window.toplevel();
xdg.with_pending_state(|state| {
state.size = Some((output_size.w / 2, output_size.h).into());
});
xdg.send_pending_configure();
}
// No more buttons are pressed, release the grab.
handle.unset_grab(data, event.serial, event.time, true);
}
......
......@@ -14,7 +14,7 @@ use smithay::{
Resource,
},
},
utils::{Rectangle, Serial},
utils::{Point, Rectangle, Serial},
wayland::{
compositor::with_states,
shell::xdg::{
......@@ -104,11 +104,10 @@ impl XdgShellHandler for Smallvil {
let ratio =
(pointer_pos.x - win_geometry.loc.x as f64) / (win_geometry.size.w as f64);
initial_window_location = (
initial_window_location = Point::from((
(pointer_pos.x - ratio * target_size.w as f64) as i32,
(pointer_pos.y as i32),
)
.into();
));
}
let grab = MoveSurfaceGrab {
......