event: get current modifier flags
This commit is contained in:
parent
abbf078482
commit
0ab38ad14f
|
@ -48,7 +48,7 @@ pub enum EventMask {
|
||||||
Pressure = 1 << 34,
|
Pressure = 1 << 34,
|
||||||
DirectTouch = 1 << 37,
|
DirectTouch = 1 << 37,
|
||||||
|
|
||||||
ChangeMode = 1 << 38
|
ChangeMode = 1 << 38,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A wrapper over an `NSEvent`.
|
/// A wrapper over an `NSEvent`.
|
||||||
|
@ -103,19 +103,23 @@ impl Event {
|
||||||
unsafe { msg_send![&*self.0, clickCount] }
|
unsafe { msg_send![&*self.0, clickCount] }
|
||||||
}
|
}
|
||||||
|
|
||||||
/*pub fn contains_modifier_flags(&self, flags: &[EventModifierFlag]) -> bool {
|
pub fn current_modifier_flags(&self) -> Vec<EventModifierFlag> {
|
||||||
let modifier_flags: NSUInteger = unsafe {
|
let pressed_modifier_flags: NSUInteger = unsafe { msg_send![&*self.0, modifierFlags] };
|
||||||
msg_send![&*self.0, modifierFlags]
|
|
||||||
};
|
|
||||||
|
|
||||||
for flag in flags {
|
let all_modifier_flags = vec![
|
||||||
let f: NSUInteger = flag.into();
|
EventModifierFlag::CapsLock,
|
||||||
|
EventModifierFlag::Control,
|
||||||
|
EventModifierFlag::Option,
|
||||||
|
EventModifierFlag::Command,
|
||||||
|
EventModifierFlag::DeviceIndependentFlagsMask,
|
||||||
|
];
|
||||||
|
|
||||||
|
all_modifier_flags
|
||||||
|
.into_iter()
|
||||||
|
.filter(|modifier| (Into::<NSUInteger>::into(modifier) & pressed_modifier_flags) != 0)
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
false
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/// Register an event handler with the local system event stream. This method
|
/// Register an event handler with the local system event stream. This method
|
||||||
/// watches for events that occur _within the application_. Events outside
|
/// watches for events that occur _within the application_. Events outside
|
||||||
/// of the application require installing a `global_monitor` handler.
|
/// of the application require installing a `global_monitor` handler.
|
||||||
|
@ -124,14 +128,14 @@ impl Event {
|
||||||
/// monitors are required - the streams don't mix.
|
/// monitors are required - the streams don't mix.
|
||||||
pub fn local_monitor<F>(mask: EventMask, handler: F) -> EventMonitor
|
pub fn local_monitor<F>(mask: EventMask, handler: F) -> EventMonitor
|
||||||
where
|
where
|
||||||
F: Fn(Event) -> Option<Event> + Send + Sync + 'static
|
F: Fn(Event) -> Option<Event> + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
let block = ConcreteBlock::new(move |event: id| {
|
let block = ConcreteBlock::new(move |event: id| {
|
||||||
let evt = Event::new(event);
|
let evt = Event::new(event);
|
||||||
|
|
||||||
match handler(evt) {
|
match handler(evt) {
|
||||||
Some(mut evt) => &mut *evt.0,
|
Some(mut evt) => &mut *evt.0,
|
||||||
None => nil
|
None => nil,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let block = block.copy();
|
let block = block.copy();
|
||||||
|
@ -153,14 +157,14 @@ impl Event {
|
||||||
/// monitors are required - the streams don't mix.
|
/// monitors are required - the streams don't mix.
|
||||||
pub fn global_monitor<F>(mask: EventMask, handler: F) -> EventMonitor
|
pub fn global_monitor<F>(mask: EventMask, handler: F) -> EventMonitor
|
||||||
where
|
where
|
||||||
F: Fn(Event) -> Option<Event> + Send + Sync + 'static
|
F: Fn(Event) -> Option<Event> + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
let block = ConcreteBlock::new(move |event: id| {
|
let block = ConcreteBlock::new(move |event: id| {
|
||||||
let evt = Event::new(event);
|
let evt = Event::new(event);
|
||||||
|
|
||||||
match handler(evt) {
|
match handler(evt) {
|
||||||
Some(mut evt) => &mut *evt.0,
|
Some(mut evt) => &mut *evt.0,
|
||||||
None => nil
|
None => nil,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let block = block.copy();
|
let block = block.copy();
|
||||||
|
@ -183,7 +187,7 @@ pub enum EventModifierFlag {
|
||||||
Control,
|
Control,
|
||||||
Option,
|
Option,
|
||||||
Command,
|
Command,
|
||||||
DeviceIndependentFlagsMask
|
DeviceIndependentFlagsMask,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<EventModifierFlag> for NSUInteger {
|
impl From<EventModifierFlag> for NSUInteger {
|
||||||
|
@ -193,7 +197,7 @@ impl From<EventModifierFlag> for NSUInteger {
|
||||||
EventModifierFlag::Control => 1 << 18,
|
EventModifierFlag::Control => 1 << 18,
|
||||||
EventModifierFlag::Option => 1 << 19,
|
EventModifierFlag::Option => 1 << 19,
|
||||||
EventModifierFlag::Command => 1 << 20,
|
EventModifierFlag::Command => 1 << 20,
|
||||||
EventModifierFlag::DeviceIndependentFlagsMask => 0xffff0000
|
EventModifierFlag::DeviceIndependentFlagsMask => 0xffff0000,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,7 +209,7 @@ impl From<&EventModifierFlag> for NSUInteger {
|
||||||
EventModifierFlag::Control => 1 << 18,
|
EventModifierFlag::Control => 1 << 18,
|
||||||
EventModifierFlag::Option => 1 << 19,
|
EventModifierFlag::Option => 1 << 19,
|
||||||
EventModifierFlag::Command => 1 << 20,
|
EventModifierFlag::Command => 1 << 20,
|
||||||
EventModifierFlag::DeviceIndependentFlagsMask => 0xffff0000
|
EventModifierFlag::DeviceIndependentFlagsMask => 0xffff0000,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue