Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gesture-based dragging #1109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cosmic-comp-config/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ pub struct InputConfig {
pub tap_config: Option<TapConfig>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub map_to_output: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub three_finger_drag: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub three_finger_drag_delay: Option<u32>,
// #[serde(skip_serializing_if = "Option::is_none", default)]
// pub three_finger_gesture: Option<Gesture>,
// #[serde(skip_serializing_if = "Option::is_none", default)]
// pub four_finger_gesture: Option<Gesture>,
// #[serde(skip_serializing_if = "Option::is_none", default)]
// pub gesture_drag_delay: Option<u32>,
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub enum Gesture {
Drag,
SwitchWorkspace,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)]
Expand Down
2 changes: 2 additions & 0 deletions src/config/input_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pub fn for_device(device: &InputDevice) -> InputConfig {
None
},
map_to_output: None,
three_finger_drag: (device.config_tap_finger_count() > 2).then_some(true),
three_finger_drag_delay: (device.config_tap_finger_count() > 2).then_some(1000),
}
}

Expand Down
37 changes: 36 additions & 1 deletion src/input/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ impl State {
}
}

pub fn handle_swipe_action(&mut self, action: gestures::SwipeAction, seat: &Seat<State>) {
pub fn handle_swipe_action(
&mut self,
action: gestures::SwipeAction,
seat: &Seat<State>,
event_time: u32,
continuation: bool,
) {
use gestures::SwipeAction;

match action {
Expand All @@ -112,6 +118,35 @@ impl State {
&mut self.common.workspace_state.update(),
);
}
SwipeAction::Drag if !continuation => {
use smithay::backend::input::{ButtonState, MouseButton};

let left_handed = self
.common
.config
.cosmic_conf
.input_touchpad
.left_handed
.unwrap_or(false);
let (button, mouse_button) = if left_handed {
(super::BTN_RIGHT, MouseButton::Right)
} else {
(super::BTN_LEFT, MouseButton::Left)
};
self.process_pointer_button(
seat,
button,
ButtonState::Pressed,
Some(mouse_button),
event_time,
);
}
SwipeAction::Drag => {
// Do not press again if this is a continuation.
}
SwipeAction::DragEnd(_) => {
// Not a user-triggered action.
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/input/gestures/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use calloop::RegistrationToken;
use cosmic_settings_config::shortcuts::action::Direction;
use smithay::utils::{Logical, Point};
use std::{collections::VecDeque, time::Duration};
Expand All @@ -16,6 +17,8 @@ pub struct SwipeEvent {
pub enum SwipeAction {
NextWorkspace,
PrevWorkspace,
Drag,
DragEnd(RegistrationToken),
}

#[derive(Debug, Clone)]
Expand All @@ -26,16 +29,19 @@ pub struct GestureState {
pub delta: f64,
// Delta tracking inspired by Niri (GPL-3.0) https://github.com/YaLTeR/niri/tree/v0.1.3
pub history: VecDeque<SwipeEvent>,
/// `true` if this is a continuation of a previous gesture.
pub continuation: bool,
}

impl GestureState {
pub fn new(fingers: u32) -> Self {
pub fn new(fingers: u32, continuation: bool) -> Self {
GestureState {
fingers,
direction: None,
action: None,
delta: 0.0,
history: VecDeque::new(),
continuation,
}
}

Expand Down Expand Up @@ -129,7 +135,7 @@ impl GestureState {

impl Default for GestureState {
fn default() -> Self {
GestureState::new(0)
GestureState::new(0, false)
}
}

Expand Down
Loading