mirror of
https://github.com/YaLTeR/niri.git
synced 2024-10-26 20:04:05 +03:00
Merge 9f543afffe
into db49deb7fd
This commit is contained in:
commit
24fd3f799e
@ -747,6 +747,7 @@ pub enum Action {
|
||||
ChangeVt(i32),
|
||||
Suspend,
|
||||
PowerOffMonitors,
|
||||
ToggleTabletMode,
|
||||
ToggleDebugTint,
|
||||
Spawn(#[knuffel(arguments)] Vec<String>),
|
||||
#[knuffel(skip)]
|
||||
@ -884,6 +885,7 @@ impl From<niri_ipc::Action> for Action {
|
||||
niri_ipc::Action::MoveWorkspaceToMonitorDown => Self::MoveWorkspaceToMonitorDown,
|
||||
niri_ipc::Action::MoveWorkspaceToMonitorUp => Self::MoveWorkspaceToMonitorUp,
|
||||
niri_ipc::Action::ToggleDebugTint => Self::ToggleDebugTint,
|
||||
niri_ipc::Action::ToggleTabletMode => Self::ToggleTabletMode,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -207,6 +207,8 @@ pub enum Action {
|
||||
MoveWorkspaceToMonitorUp,
|
||||
/// Toggle a debug tint on windows.
|
||||
ToggleDebugTint,
|
||||
/// Toggle tablet mode (disable keyboard and touchpad)
|
||||
ToggleTabletMode,
|
||||
}
|
||||
|
||||
/// Change in window or column size.
|
||||
|
40
src/input.rs
40
src/input.rs
@ -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);
|
||||
}
|
||||
@ -774,6 +780,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;
|
||||
@ -1011,6 +1021,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();
|
||||
@ -1076,6 +1090,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
|
||||
@ -1609,6 +1626,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
|
||||
@ -1626,6 +1651,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
|
||||
@ -1643,6 +1669,13 @@ fn should_intercept_key(
|
||||
disable_power_key_handling,
|
||||
);
|
||||
|
||||
if tablet_mode {
|
||||
if final_action != Some(Action::ToggleTabletMode) {
|
||||
suppressed_keys.insert(key_code);
|
||||
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() {
|
||||
@ -1919,6 +1952,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.
|
||||
@ -1936,6 +1970,7 @@ mod tests {
|
||||
mods,
|
||||
&screenshot_ui,
|
||||
disable_power_key_handling,
|
||||
tablet_mode,
|
||||
)
|
||||
};
|
||||
|
||||
@ -1952,6 +1987,7 @@ mod tests {
|
||||
mods,
|
||||
&screenshot_ui,
|
||||
disable_power_key_handling,
|
||||
tablet_mode,
|
||||
)
|
||||
};
|
||||
|
||||
|
@ -206,6 +206,7 @@ pub struct Niri {
|
||||
pub gesture_swipe_3f_cumulative: Option<(f64, f64)>,
|
||||
|
||||
pub lock_state: LockState,
|
||||
pub tablet_mode: bool,
|
||||
|
||||
pub screenshot_ui: ScreenshotUi,
|
||||
pub config_error_notification: ConfigErrorNotification,
|
||||
@ -1265,6 +1266,7 @@ impl Niri {
|
||||
gesture_swipe_3f_cumulative: None,
|
||||
|
||||
lock_state: LockState::Unlocked,
|
||||
tablet_mode: false,
|
||||
|
||||
screenshot_ui,
|
||||
config_error_notification,
|
||||
@ -1918,6 +1920,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;
|
||||
|
Loading…
Reference in New Issue
Block a user