Check only for partial match of modifier keys
This commit is contained in:
parent
eba2ded88a
commit
50b02d41a0
@ -1,5 +1,5 @@
|
|||||||
/// The current state of the keyboard modifiers.
|
/// The current state of the keyboard modifiers.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||||
pub struct ModifiersState {
|
pub struct ModifiersState {
|
||||||
/// Whether a shift key is pressed
|
/// Whether a shift key is pressed
|
||||||
pub shift: bool,
|
pub shift: bool,
|
||||||
@ -13,3 +13,18 @@ pub struct ModifiersState {
|
|||||||
/// Whether a logo key is pressed (e.g. windows key, command key...)
|
/// Whether a logo key is pressed (e.g. windows key, command key...)
|
||||||
pub logo: bool,
|
pub logo: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ModifiersState {
|
||||||
|
/// Returns true if the current [`ModifiersState`] has at least the same
|
||||||
|
/// modifiers enabled as the given value, and false otherwise.
|
||||||
|
///
|
||||||
|
/// [`ModifiersState`]: struct.ModifiersState.html
|
||||||
|
pub fn matches(&self, modifiers: ModifiersState) -> bool {
|
||||||
|
let shift = !modifiers.shift || modifiers.shift && self.shift;
|
||||||
|
let control = !modifiers.control || modifiers.control && self.control;
|
||||||
|
let alt = !modifiers.alt || modifiers.alt && self.alt;
|
||||||
|
let logo = !modifiers.logo || modifiers.logo && self.logo;
|
||||||
|
|
||||||
|
shift && control && alt && logo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -260,7 +260,9 @@ where
|
|||||||
if let Some(((pane, _), _)) = clicked_region.next() {
|
if let Some(((pane, _), _)) = clicked_region.next() {
|
||||||
match &self.on_drag {
|
match &self.on_drag {
|
||||||
Some(on_drag)
|
Some(on_drag)
|
||||||
if *self.modifiers == self.modifier_keys =>
|
if self
|
||||||
|
.modifiers
|
||||||
|
.matches(self.modifier_keys) =>
|
||||||
{
|
{
|
||||||
self.state.pick_pane(pane);
|
self.state.pick_pane(pane);
|
||||||
|
|
||||||
@ -309,7 +311,7 @@ where
|
|||||||
state: ButtonState::Pressed,
|
state: ButtonState::Pressed,
|
||||||
}) if self.on_resize.is_some()
|
}) if self.on_resize.is_some()
|
||||||
&& self.state.picked_pane().is_none()
|
&& self.state.picked_pane().is_none()
|
||||||
&& *self.modifiers == self.modifier_keys =>
|
&& self.modifiers.matches(self.modifier_keys) =>
|
||||||
{
|
{
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
let relative_cursor = Point::new(
|
let relative_cursor = Point::new(
|
||||||
@ -374,7 +376,7 @@ where
|
|||||||
// TODO: Discard when event is captured
|
// TODO: Discard when event is captured
|
||||||
if state == ButtonState::Pressed {
|
if state == ButtonState::Pressed {
|
||||||
if let Some(_) = self.state.idle_pane() {
|
if let Some(_) = self.state.idle_pane() {
|
||||||
if modifiers == self.modifier_keys {
|
if modifiers.matches(self.modifier_keys) {
|
||||||
if let Some(message) =
|
if let Some(message) =
|
||||||
on_key_press(KeyPressEvent {
|
on_key_press(KeyPressEvent {
|
||||||
key_code,
|
key_code,
|
||||||
|
Loading…
Reference in New Issue
Block a user