-
-
Notifications
You must be signed in to change notification settings - Fork 123
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
implement tablet mode (disabling keyboard and mouse/touch pad) #238
Open
exoticorn
wants to merge
2
commits into
YaLTeR:main
Choose a base branch
from
exoticorn:tablet-mode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ use smithay::backend::input::{ | |
AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event, | ||
GestureBeginEvent, GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _, | ||
InputBackend, InputEvent, KeyState, KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent, | ||
PointerMotionEvent, ProximityState, TabletToolButtonEvent, TabletToolEvent, | ||
PointerMotionEvent, ProximityState, SwitchToggleEvent, TabletToolButtonEvent, TabletToolEvent, | ||
TabletToolProximityEvent, TabletToolTipEvent, TabletToolTipState, TouchEvent, | ||
}; | ||
use smithay::backend::libinput::LibinputInputBackend; | ||
|
@@ -109,7 +109,7 @@ impl State { | |
TouchUp { event } => self.on_touch_up::<I>(event), | ||
TouchCancel { event } => self.on_touch_cancel::<I>(event), | ||
TouchFrame { event } => self.on_touch_frame::<I>(event), | ||
SwitchToggle { .. } => (), | ||
SwitchToggle { event } => self.on_switch_toggle::<I>(event), | ||
Special(_) => (), | ||
} | ||
|
||
|
@@ -278,6 +278,7 @@ impl State { | |
*mods, | ||
&this.niri.screenshot_ui, | ||
this.niri.config.borrow().input.disable_power_key_handling, | ||
this.niri.tablet_mode, | ||
) | ||
}, | ||
) else { | ||
|
@@ -332,6 +333,11 @@ impl State { | |
self.backend.toggle_debug_tint(); | ||
self.niri.queue_redraw_all(); | ||
} | ||
Action::ToggleTabletMode => { | ||
self.niri.tablet_mode = !self.niri.tablet_mode; | ||
// FIXME: redraw only outputs overlapping the cursor. | ||
self.niri.queue_redraw_all(); | ||
} | ||
Action::Spawn(command) => { | ||
spawn(command); | ||
} | ||
|
@@ -697,6 +703,10 @@ impl State { | |
} | ||
|
||
fn on_pointer_motion<I: InputBackend>(&mut self, event: I::PointerMotionEvent) { | ||
if self.niri.tablet_mode { | ||
return; | ||
} | ||
|
||
// We need an output to be able to move the pointer. | ||
if self.niri.global_space.outputs().next().is_none() { | ||
return; | ||
|
@@ -932,6 +942,10 @@ impl State { | |
} | ||
|
||
fn on_pointer_button<I: InputBackend>(&mut self, event: I::PointerButtonEvent) { | ||
if self.niri.tablet_mode { | ||
return; | ||
} | ||
|
||
let pointer = self.niri.seat.get_pointer().unwrap(); | ||
|
||
let serial = SERIAL_COUNTER.next_serial(); | ||
|
@@ -997,6 +1011,9 @@ impl State { | |
} | ||
|
||
fn on_pointer_axis<I: InputBackend>(&mut self, event: I::PointerAxisEvent) { | ||
if self.niri.tablet_mode { | ||
return; | ||
} | ||
let source = event.source(); | ||
|
||
let horizontal_amount = event | ||
|
@@ -1538,6 +1555,14 @@ impl State { | |
}; | ||
handle.cancel(self); | ||
} | ||
|
||
fn on_switch_toggle<B: InputBackend>(&mut self, event: B::SwitchToggleEvent) { | ||
if event.switch() == Some(smithay::backend::input::Switch::TabletMode) { | ||
self.niri.tablet_mode = event.state() == smithay::backend::input::SwitchState::On; | ||
// FIXME: redraw only outputs overlapping the cursor. | ||
self.niri.queue_redraw_all(); | ||
} | ||
} | ||
} | ||
|
||
/// Check whether the key should be intercepted and mark intercepted | ||
|
@@ -1555,6 +1580,7 @@ fn should_intercept_key( | |
mods: ModifiersState, | ||
screenshot_ui: &ScreenshotUi, | ||
disable_power_key_handling: bool, | ||
tablet_mode: bool, | ||
) -> FilterResult<Option<Action>> { | ||
// Actions are only triggered on presses, release of the key | ||
// shouldn't try to intercept anything unless we have marked | ||
|
@@ -1572,6 +1598,13 @@ fn should_intercept_key( | |
disable_power_key_handling, | ||
); | ||
|
||
if tablet_mode { | ||
if final_action != Some(Action::ToggleTabletMode) { | ||
suppressed_keys.insert(key_code); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this need to remove on key release? |
||
return FilterResult::Intercept(None); | ||
} | ||
} | ||
|
||
// Allow only a subset of compositor actions while the screenshot UI is open, since the user | ||
// cannot see the screen. | ||
if screenshot_ui.is_open() { | ||
|
@@ -1842,6 +1875,7 @@ mod tests { | |
|
||
let screenshot_ui = ScreenshotUi::new(); | ||
let disable_power_key_handling = false; | ||
let tablet_mode = false; | ||
|
||
// The key_code we pick is arbitrary, the only thing | ||
// that matters is that they are different between cases. | ||
|
@@ -1859,6 +1893,7 @@ mod tests { | |
mods, | ||
&screenshot_ui, | ||
disable_power_key_handling, | ||
tablet_mode, | ||
) | ||
}; | ||
|
||
|
@@ -1875,6 +1910,7 @@ mod tests { | |
mods, | ||
&screenshot_ui, | ||
disable_power_key_handling, | ||
tablet_mode, | ||
) | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -208,6 +208,7 @@ pub struct Niri { | |||||||
pub gesture_swipe_3f_cumulative: Option<(f64, f64)>, | ||||||||
|
||||||||
pub lock_state: LockState, | ||||||||
pub tablet_mode: bool, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
pub screenshot_ui: ScreenshotUi, | ||||||||
pub config_error_notification: ConfigErrorNotification, | ||||||||
|
@@ -1096,6 +1097,7 @@ impl Niri { | |||||||
gesture_swipe_3f_cumulative: None, | ||||||||
|
||||||||
lock_state: LockState::Unlocked, | ||||||||
tablet_mode: false, | ||||||||
|
||||||||
screenshot_ui, | ||||||||
config_error_notification, | ||||||||
|
@@ -1736,6 +1738,10 @@ impl Niri { | |||||||
renderer: &mut R, | ||||||||
output: &Output, | ||||||||
) -> Vec<OutputRenderElements<R>> { | ||||||||
if self.tablet_mode && self.tablet_cursor_location.is_none() { | ||||||||
return vec![]; | ||||||||
} | ||||||||
|
||||||||
let _span = tracy_client::span!("Niri::pointer_element"); | ||||||||
let output_scale = output.current_scale(); | ||||||||
let output_pos = self.global_space.output_geometry(output).unwrap().loc; | ||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking, maybe handle all of these one level above? I.e. before dispatching in
process_input_event()
, do: