config: make ui dragging configurable
This commit is contained in:
parent
1dd20fb87b
commit
d8ee1ac19c
19 changed files with 255 additions and 12 deletions
|
|
@ -267,6 +267,8 @@ fn start_compositor2(
|
|||
ei_clients: EiClients::new(),
|
||||
slow_ei_clients: Default::default(),
|
||||
cpu_worker,
|
||||
ui_drag_enabled: Cell::new(true),
|
||||
ui_drag_threshold_squared: Cell::new(10),
|
||||
});
|
||||
state.tracker.register(ClientId::from_raw(0));
|
||||
create_dummy_output(&state);
|
||||
|
|
|
|||
|
|
@ -759,6 +759,16 @@ impl ConfigProxyHandler {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_set_ui_drag_enabled(&self, enabled: bool) {
|
||||
self.state.ui_drag_enabled.set(enabled);
|
||||
}
|
||||
|
||||
fn handle_set_ui_drag_threshold(&self, threshold: i32) {
|
||||
let threshold = threshold.max(1);
|
||||
let squared = threshold.saturating_mul(threshold);
|
||||
self.state.ui_drag_threshold_squared.set(squared);
|
||||
}
|
||||
|
||||
fn handle_set_direct_scanout_enabled(
|
||||
&self,
|
||||
device: Option<DrmDevice>,
|
||||
|
|
@ -1951,6 +1961,10 @@ impl ConfigProxyHandler {
|
|||
ClientMessage::SetFlipMargin { device, margin } => self
|
||||
.handle_set_flip_margin(device, margin)
|
||||
.wrn("set_flip_margin")?,
|
||||
ClientMessage::SetUiDragEnabled { enabled } => self.handle_set_ui_drag_enabled(enabled),
|
||||
ClientMessage::SetUiDragThreshold { threshold } => {
|
||||
self.handle_set_ui_drag_threshold(threshold)
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -776,11 +776,15 @@ impl WlSeatGlobal {
|
|||
}
|
||||
|
||||
pub fn start_tile_drag(self: &Rc<Self>, tl: &Rc<dyn ToplevelNode>) {
|
||||
self.pointer_owner.start_tile_drag(self, tl);
|
||||
if self.state.ui_drag_enabled.get() {
|
||||
self.pointer_owner.start_tile_drag(self, tl);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_workspace_drag(self: &Rc<Self>, ws: &Rc<WorkspaceNode>) {
|
||||
self.pointer_owner.start_workspace_drag(self, ws);
|
||||
if self.state.ui_drag_enabled.get() {
|
||||
self.pointer_owner.start_workspace_drag(self, ws);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cancel_dnd(self: &Rc<Self>) {
|
||||
|
|
|
|||
11
src/state.rs
11
src/state.rs
|
|
@ -218,6 +218,8 @@ pub struct State {
|
|||
pub ei_clients: EiClients,
|
||||
pub slow_ei_clients: AsyncQueue<Rc<EiClient>>,
|
||||
pub cpu_worker: Rc<CpuWorker>,
|
||||
pub ui_drag_enabled: Cell<bool>,
|
||||
pub ui_drag_threshold_squared: Cell<i32>,
|
||||
}
|
||||
|
||||
// impl Drop for State {
|
||||
|
|
@ -1240,6 +1242,15 @@ impl State {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ui_drag_threshold_reached(&self, (x1, y1): (i32, i32), (x2, y2): (i32, i32)) -> bool {
|
||||
if !self.ui_drag_enabled.get() {
|
||||
return false;
|
||||
}
|
||||
let dx = x1 - x2;
|
||||
let dy = y1 - y2;
|
||||
dx * dx + dy * dy > self.ui_drag_threshold_squared.get()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
|
|
|||
|
|
@ -586,10 +586,7 @@ impl ContainerNode {
|
|||
match op.kind {
|
||||
SeatOpKind::Move => {
|
||||
if let CursorType::Seat(_) = id {
|
||||
const DRAG_DIST: i32 = 10;
|
||||
let dx = x - op.x;
|
||||
let dy = y - op.y;
|
||||
if dx * dx + dy * dy > DRAG_DIST * DRAG_DIST {
|
||||
if self.state.ui_drag_threshold_reached((x, y), (op.x, op.y)) {
|
||||
let node = op.child.node.clone();
|
||||
drop(seats);
|
||||
seat.start_tile_drag(&node);
|
||||
|
|
|
|||
|
|
@ -1341,10 +1341,10 @@ impl Node for OutputNode {
|
|||
fn node_on_pointer_motion(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, x: Fixed, y: Fixed) {
|
||||
self.pointer_move(PointerType::Seat(seat.id()), x, y);
|
||||
if let Some((down_x, down_y)) = self.pointer_down.get(&seat.id()) {
|
||||
const DRAG_DIST: i32 = 10;
|
||||
let dx = x.round_down() - down_x;
|
||||
let dy = y.round_down() - down_y;
|
||||
if dx * dx + dy * dy > DRAG_DIST * DRAG_DIST {
|
||||
if self
|
||||
.state
|
||||
.ui_drag_threshold_reached((x.round_down(), y.round_down()), (down_x, down_y))
|
||||
{
|
||||
let rd = self.render_data.borrow_mut();
|
||||
for title in &rd.titles {
|
||||
if down_x >= title.x1 && down_x < title.x2 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue