mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 06:11:30 +11:00
Make set_device_event_filter
non-mut
Commit f10a984
added `EventLoopWindowTarget::set_device_event_filter`
with for a mutable reference, however most winit APIs work with
immutable references, so altering API to play nicely with existing APIs.
This also disables device event filtering on debug example.
This commit is contained in:
parent
10419ff441
commit
eec84ade86
|
@ -6,7 +6,7 @@ use simple_logger::SimpleLogger;
|
||||||
use winit::{
|
use winit::{
|
||||||
dpi::{LogicalSize, PhysicalSize},
|
dpi::{LogicalSize, PhysicalSize},
|
||||||
event::{DeviceEvent, ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
|
event::{DeviceEvent, ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
|
||||||
event_loop::EventLoop,
|
event_loop::{DeviceEventFilter, EventLoop},
|
||||||
window::{Fullscreen, WindowBuilder},
|
window::{Fullscreen, WindowBuilder},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ fn main() {
|
||||||
let mut minimized = false;
|
let mut minimized = false;
|
||||||
let mut visible = true;
|
let mut visible = true;
|
||||||
|
|
||||||
|
event_loop.set_device_event_filter(DeviceEventFilter::Never);
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
control_flow.set_wait();
|
control_flow.set_wait();
|
||||||
|
|
||||||
|
|
|
@ -306,7 +306,7 @@ impl<T> EventLoopWindowTarget<T> {
|
||||||
/// - **Wayland / Windows / macOS / iOS / Android / Web**: Unsupported.
|
/// - **Wayland / Windows / macOS / iOS / Android / Web**: Unsupported.
|
||||||
///
|
///
|
||||||
/// [`DeviceEvent`]: crate::event::DeviceEvent
|
/// [`DeviceEvent`]: crate::event::DeviceEvent
|
||||||
pub fn set_device_event_filter(&mut self, _filter: DeviceEventFilter) {
|
pub fn set_device_event_filter(&self, _filter: DeviceEventFilter) {
|
||||||
#[cfg(any(
|
#[cfg(any(
|
||||||
target_os = "linux",
|
target_os = "linux",
|
||||||
target_os = "dragonfly",
|
target_os = "dragonfly",
|
||||||
|
|
|
@ -788,12 +788,12 @@ impl<T> EventLoopWindowTarget<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_device_event_filter(&mut self, _filter: DeviceEventFilter) {
|
pub fn set_device_event_filter(&self, _filter: DeviceEventFilter) {
|
||||||
match *self {
|
match *self {
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
EventLoopWindowTarget::Wayland(_) => (),
|
EventLoopWindowTarget::Wayland(_) => (),
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
EventLoopWindowTarget::X(ref mut evlp) => evlp.set_device_event_filter(_filter),
|
EventLoopWindowTarget::X(ref evlp) => evlp.set_device_event_filter(_filter),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub use self::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
cell::RefCell,
|
cell::{Cell, RefCell},
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
ffi::CStr,
|
ffi::CStr,
|
||||||
mem::{self, MaybeUninit},
|
mem::{self, MaybeUninit},
|
||||||
|
@ -108,7 +108,7 @@ pub struct EventLoopWindowTarget<T> {
|
||||||
ime: RefCell<Ime>,
|
ime: RefCell<Ime>,
|
||||||
windows: RefCell<HashMap<WindowId, Weak<UnownedWindow>>>,
|
windows: RefCell<HashMap<WindowId, Weak<UnownedWindow>>>,
|
||||||
redraw_sender: WakeSender<WindowId>,
|
redraw_sender: WakeSender<WindowId>,
|
||||||
device_event_filter: DeviceEventFilter,
|
device_event_filter: Cell<DeviceEventFilter>,
|
||||||
_marker: ::std::marker::PhantomData<T>,
|
_marker: ::std::marker::PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,14 +536,14 @@ impl<T> EventLoopWindowTarget<T> {
|
||||||
&self.xconn
|
&self.xconn
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_device_event_filter(&mut self, filter: DeviceEventFilter) {
|
pub fn set_device_event_filter(&self, filter: DeviceEventFilter) {
|
||||||
self.device_event_filter = filter;
|
self.device_event_filter.set(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the device event filter based on window focus.
|
/// Update the device event filter based on window focus.
|
||||||
pub fn update_device_event_filter(&self, focus: bool) {
|
pub fn update_device_event_filter(&self, focus: bool) {
|
||||||
let filter_events = self.device_event_filter == DeviceEventFilter::Never
|
let filter_events = self.device_event_filter.get() == DeviceEventFilter::Never
|
||||||
|| (self.device_event_filter == DeviceEventFilter::Unfocused && !focus);
|
|| (self.device_event_filter.get() == DeviceEventFilter::Unfocused && !focus);
|
||||||
|
|
||||||
let mut mask = 0;
|
let mut mask = 0;
|
||||||
if !filter_events {
|
if !filter_events {
|
||||||
|
|
Loading…
Reference in a new issue