* Use requestAnimationFrame for polling wasm
* Implement `requestAnimationFrame` for stdweb
Co-authored-by: Ryan G <ryanisaacg@users.noreply.github.com>
This reverts commit 9daa0738a9.
This commit introduced other bug #1453 with likely much more common bindings,
so reverting it for now.
Fixes#1453.
Co-authored-by: Osspial <osspial@gmail.com>
* On Windows, fix request_redraw() related panics
These panics were introduced by 6a330a2894
Fixes https://github.com/rust-windowing/winit/issues/1391
Fixes https://github.com/rust-windowing/winit/issues/1400
Fixes https://github.com/rust-windowing/winit/issues/1466
Probably fixes other related issues
See https://github.com/rust-windowing/winit/issues/1429
* On Windows, replace all calls to UpdateWindow by calls to InvalidateRgn
This avoids directly sending a WM_PAINT message,
which might cause buffering of RedrawRequested events.
We don't want to buffer RedrawRequested events because:
- we wan't to handle RedrawRequested during processing of WM_PAINT messages
- state transitionning is broken when handling buffered RedrawRequested events
Fixes https://github.com/rust-windowing/winit/issues/1469
* On Windows, panic if we are trying to buffer a RedrawRequested event
* On Windows, move modal loop jumpstart to set_modal_loop() method
This fixes a panic.
Note that the WM_PAINT event is now sent to the modal_redraw_method
which is more correct and avoids an unecessary redraw of the window.
Relates to but does does not fix https://github.com/rust-windowing/winit/issues/1484
* On Window, filter by paint messages when draining paint messages
This seems to prevent PeekMessage from dispatching unrelated sent messages
* Change recently added panic/assert calls with warn calls
This makes the code less panicky...
And actually, winit's Windoww callbacks should not panic
because the panic will unwind into Windows code.
It is currently undefined behavior to unwind from Rust code into foreign code.
See https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
* add comments to clarify WM_PAINT handling in non modal loop
* made redraw_events_cleared more explicit and more comments
* Remove assertions from Windows dark mode code
In general, winit should never assert on anything unless it means that
it is impossible to continue the execution of the program. There are
several assertions in the Windows dark mode code where this is not the
case.
Based on surface level inspection, all existing assertions could be
easily replaced with just simple conditional checks, allowing the
execution of the program to proceed with sane default values.
Fixes#1458.
* Add changelog entry
* Format code
* Pass dark mode by mutable reference
* Format code
* Return bool instead of mutable reference
* Fix dark mode success reply
Co-Authored-By: daxpedda <daxpedda@gmail.com>
* Fix dark mode success reply
* Replace magic integers with constants
Co-authored-by: daxpedda <daxpedda@gmail.com>
* Move `ModifiersChanged` variant to `WindowEvent`
* macos: Fix flags_changed for ModifiersChanged variant move
I haven't look too deep at what this does internally, but at least
cargo-check is fully happy now. :)
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* macos: Fire a ModifiersChanged event on window_did_resign_key
From debugging, I determined that macOS' emission of a flagsChanged
around window switching is inconsistent. It is fair to assume, I think,
that when the user switches windows, they do not expect their former
modifiers state to remain effective; so I think it's best to clear that
state by sending a ModifiersChanged(ModifiersState::empty()).
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* windows: Fix build
I don't know enough about the code to implement the fix as it is done on
this branch, but this commit at least fixes the build.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* windows: Send ModifiersChanged(ModifiersState::empty) on KILLFOCUS
Very similar to the changes made in [1], as focus is lost, send an event
to the window indicating that the modifiers have been released.
It's unclear to me (without a Windows device to test this on) whether
this is necessary, but it certainly ensures that unfocused windows will
have at least received this event, which is an improvement.
[1]: f79f21641a31da3e4039d41be89047cdcc6028f7
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* macos: Add a hook to update stale modifiers
Sometimes, `ViewState` and `event` might have different values for their
stored `modifiers` flags. These are internally stored as a bitmask in
the latter and an enum in the former.
We can check to see if they differ, and if they do, automatically
dispatch an event to update consumers of modifier state as well as the
stored `state.modifiers`. That's what the hook does.
This hook is then called in the key_down, mouse_entered, mouse_exited,
mouse_click, scroll_wheel, and pressure_change_with_event callbacks,
which each will contain updated modifiers.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Only call event_mods once when determining whether to update state
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* flags_changed: Memoize window_id collection
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* window_did_resign_key: Remove synthetic ModifiersChanged event
We no longer need to emit this event, since we are checking the state of
our modifiers before emitting most other events.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* mouse_motion: Add a call to update_potentially_stale_modifiers
Now, cover all events (that I can think of, at least) where stale
modifiers might affect how user programs behave. Effectively, every
human-interface event (keypress, mouse click, keydown, etc.) will cause
a ModifiersChanged event to be fired if something has changed.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* key_up: Add a call to update_potentially_stale_modifiers
We also want to make sure modifiers state is synchronized here, too.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* mouse_motion: Remove update_potentially_stale_modifiers invocation
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Retry CI
* ViewState: Promote visibility of modifiers to the macos impl
This is so that we can interact with the ViewState directly from the
WindowDelegate.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* window_delegate: Synthetically set modifiers state to empty on resignKey
This logic is implemented similarly on other platforms, so we wish to
regain parity here. Originally this behavior was implemented to always
fire an event with ModifiersState::empty(), but that was not the best as
it was not necessarily correct and could be a duplicate event.
This solution is perhaps the most elegant possible to implement the
desired behavior of sending a synthetic empty modifiers event when a
window loses focus, trading some safety for interoperation between the
NSWindowDelegate and the NSView (as the objc runtime must now be
consulted in order to acquire access to the ViewState which is "owned"
by the NSView).
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Check for modifiers change in window events
* Fix modifier changed on macOS
Since the `mouse_entered` function was generating a mouse motion, which
updates the modifier state, a modifiers changed event was incorrectly
generated.
The updating of the modifier state has also been changed to make sure it
consistently happens before events that have a modifier state attached
to it, without happening on any other event.
This of course means that no `CursorMoved` event is generated anymore
when the user enters the window without it being focused, however I'd
say that is consistent with how winit should behave.
* Fix unused variable warning
* Move changelog entry into `Unreleased` section
Co-authored-by: Freya Gentz <zegentzy@protonmail.com>
Co-authored-by: Kristofer Rye <kristofer.rye@gmail.com>
Co-authored-by: Christian Duerr <contact@christianduerr.com>
This restores default portable 'C' locale when target locale is unsupported
by X11 backend (Xlib).
When target locale is unsupported by X11, some locale-dependent Xlib
functions like `XSetLocaleModifiers` fail or have no effect triggering
later failures and panics.
When target locale is not valid, `setLocale` should normally leave the
locale unchanged (`setLocale` returns 'C'). However, in some situations,
locale is accepted by `setLocale` (`setLocale` returns the new locale)
but the accepted locale is unsupported by Xlib (`XSupportsLocale` returns
`false`).
Fix#636
* On Wayland, fix coordinates in touch events when scale factor isn't 1
* Explicitly state that Wayland is using LogicalPosition internally
* Fix CHANGELOG
The current implementation of the event loop runner has some significant
problems. It can't handle multiple events being emitted at once (for
example, when a keyboard event causes a key input, a text input, and a
modifier change.) It's also relatively easy to introduce bugs for the
different possible control flow states.
The new model separates intentionally emitting a NewEvents (poll
completed, wait completed, init) and emitting a normal event, as well as
providing a method for emitting multiple events in a single call.
* Don't discard high-precision cursor position data
Most platforms (X11, wayland, macos, stdweb, ...) provide physical
positions in f64 units, which can contain meaningful fractional
data. For example, this can be empirically observed on modern X11
using a typical laptop touchpad. This is useful for e.g. content
creation tools, where cursor motion might map to brush strokes on a
canvas with higher-than-screen resolution, or positioning of an object
in a vector space.
* Update CHANGELOG.md
Co-Authored-By: Murarth <murarth@gmail.com>
Co-authored-by: Murarth <murarth@gmail.com>
* Fix bug causing RedrawRequested events to only get emitted every other iteration of the event loop.
* Initialize simple_logger in examples.
This PR's primary bug was discovered because a friend of mine reported
that winit was emitting concerning log messages, which I'd never seen
since none of the examples print out the log messages. This addresses
that, to hopefully reduce the chance of bugs going unnoticed in the
future.
* Add changelog entry
* Format
* Rename hidpi_factor to scale_factor
* Deprecate WINIT_HIDPI_FACTOR environment variable in favor of WINIT_X11_SCALE_FACTOR
* Rename HiDpiFactorChanged to DpiChanged and update docs
I'm renaming it to DpiChanged instead of ScaleFactorChanged, since I'd
like Winit to expose the raw DPI value at some point in the near future,
and DpiChanged is a more apt name for that purpose.
* Format
* Fix macos and ios again
* Fix bad macos rebase
* fix: use a 'static lifetime for the web backend's `Event` types
* implement hidpi for stdweb (web-sys wip?)
* fix: make all canvas resizes go through backend::set_canvas_size
* update Window docs for web, make `inner/outer_position` return the position in the viewport
* Begin implementing DPI generics
* Fix multithreaded example
* Format
* Fix serde test
* hopefully fix most of the errors
* Fix dpi module errors
* More error fixings
* Format
* fix macos errors
* Another error pass
* Replace bad type signatures
* more fixins
* WIP - Make EL2 DPI changes and implement on Windows (#895)
* Modify DPI API publicly and on Windows
* Add generic Position and make dpi creation functions const
* Make examples work
* Fix fullscreen windows not appearing
* Replace Logical coordinates in window events with Physical coordinates
* Update HiDpiFactorChanged
* Document to_static
* On Windows, make AdjustRect calls DPI-aware when possible (#1015)
* Use AdjustWidowRectExForDPI when available
* Prioritize presevering logical size when handling WM_DPICHANGED
* Format
* Add changelog entry
* macOS: Dpi overhaul (#997)
* WIP - Make EL2 DPI changes and implement on Windows (#895)
* Modify DPI API publicly and on Windows
* Add generic Position and make dpi creation functions const
* Make examples work
* Fix fullscreen windows not appearing
* Replace Logical coordinates in window events with Physical coordinates
* Update HiDpiFactorChanged
* Document to_static
* fix app_state errors
* fixes hidpi related errors in window_delegate
* fix bad merge
* dpi_factor edits in window_delegate
* fixes type and lifetime errors in window and window_delegate
* applies fmt
* complies with @aleksijuvani requested changes
* modifies Handler lifetimes
* fixes lifetime isues, adds propper handling for HiDpiChanged
* applies fmt
* restore original lifetimes
* solution is somewhere out there
* applies fmt
* pass as references
* resolves issue with HANDLER
* crate visible type error
* fixes visibility issues
* applies fmt
* deals with warnings
* simplifies new_inner_size setting algorthm
* moves proxy instead of referencing it and removes double deref from proxy.ns_window
* makes @Osspial tests (https://github.com/rust-windowing/winit/pull/997\#discussion_r301852354) pass
* complies with @aleksijuvani suggested changes
* makes max window size std::f32::MAX
* On Windows, fix new DPI API not setting window size properly (#1130)
* First attempt
* Second attempt
* Maintain cursor horizontal ratio
* Fix DPI change handling when maximized
* Revert window example
* Make new DPI code more understandable
* Format
* Implement DPI Usability Upgrades for X11 and Wayland (#1098)
* Fix compile errors
* Use `mio` for the X11 event loop
* Removes `calloop` from the X11 event loop, as the method of draining a
source using a closure provided to the `calloop::EventLoop` instance
conflicts with the need to deliver events directly to the callback
provided to `EventLoop::run`, in order to respond to the value provided by
`WindowEvent::HiDpiFactorChanged`.
* Implement interactive `HiDpiFactorChanged` event for X11
* Implement interactive `HiDpiFactorChanged` event for Wayland
* Run cargo fmt
* Fix Wayland not processing events from EventQueue
* Backport #981
* some lifetime tinkering
* finishes lifetime tinkering
* fixes all type errors
* adds support ffi functions
* adds wrappers for nonstatic events
* replaces events with event wrappers
* reimplementing hidpichanged event in app_state
* implements HiDpiFactorChanged for iOS
* applies formatter
* complies with @aleksijuvani requested changes
* resolves conflicts
* applies fmt
* removes merge blurp
* corrects state of CHANGELOG
* fix fmt check error
* fixes hidpi_factor for armv7-apple-ios
* WIP - Make EL2 DPI changes and implement on Windows (#895)
* Modify DPI API publicly and on Windows
* Add generic Position and make dpi creation functions const
* Make examples work
* Fix fullscreen windows not appearing
* Replace Logical coordinates in window events with Physical coordinates
* Update HiDpiFactorChanged
* Document to_static
* fix app_state errors
* fixes hidpi related errors in window_delegate
* fix bad merge
* dpi_factor edits in window_delegate
* fixes type and lifetime errors in window and window_delegate
* applies fmt
* complies with @aleksijuvani requested changes
* modifies Handler lifetimes
* fixes lifetime isues, adds propper handling for HiDpiChanged
* applies fmt
* restore original lifetimes
* solution is somewhere out there
* applies fmt
* pass as references
* resolves issue with HANDLER
* crate visible type error
* fixes visibility issues
* applies fmt
* deals with warnings
* simplifies new_inner_size setting algorthm
* moves proxy instead of referencing it and removes double deref from proxy.ns_window
* makes @Osspial tests (https://github.com/rust-windowing/winit/pull/997\#discussion_r301852354) pass
* complies with @aleksijuvani suggested changes
* makes max window size std::f32::MAX
Changes from rebasing:
* fixes compile errors
* applies fmt
* reimplements HiDpiFactorChanged after #1173 merge
* uses EventWrappers
* Fix compile errors
* Use `mio` for the X11 event loop
* Removes `calloop` from the X11 event loop, as the method of draining a
source using a closure provided to the `calloop::EventLoop` instance
conflicts with the need to deliver events directly to the callback
provided to `EventLoop::run`, in order to respond to the value provided by
`WindowEvent::HiDpiFactorChanged`.
* Implement interactive `HiDpiFactorChanged` event for X11
* Implement interactive `HiDpiFactorChanged` event for Wayland
* Run cargo fmt
* Fix Wayland not processing events from EventQueue
* Backport #981
* First attempt
* Second attempt
* Maintain cursor horizontal ratio
* Fix DPI change handling when maximized
* Revert window example
* Make new DPI code more understandable
* Format
* Modify DPI API publicly and on Windows
* Add generic Position and make dpi creation functions const
* Make examples work
* Fix fullscreen windows not appearing
* Replace Logical coordinates in window events with Physical coordinates
* Update HiDpiFactorChanged
* Document to_static
* On X11, make `WINIT_HIDPI_FACTOR` dominate `Xft.dpi` in some cases
This commit makes `WINIT_HIDPI_FACTOR` dominate `Xft.dpi` in general and
adds a special value `0` for `WINIT_HIDPI_FACTOR` to use winit computed
DPI factor with randr over Xft.dpi.
* Use `randr` instead of `0` for auto dpi scaling
* Update CHANGELOG
* blow up on wrong env var
* Allow empty string for env var
* Move DeviceEvent handling to the message target window.
Previously, device events seem to have only been sent to one particular
window, and when that window was closed Winit would stop receiving
device events. This also allows users to create windowless event loops
that process device events - an intriguing idea, to say the least.
* Emit LWin and RWin VirtualKeyCodes on Windows
* Implement ModifiersChanged on Windows
* Make ModifiersChanged a tuple variant instead of a struct variant
* Add changelog entries
* Format
* Update changelog entry
* Fix AltGr handling
* Reformat
* Publicly expose ModifiersChanged and deprecate misc. modifiers fields
* Change ModifiersState to a bitflags struct
* Make examples work
* Add modifier state methods
* all things considered, only erroring out in one file throughout all of these changes is kinda impressive
* Make expansion plans more clear
* Move changelog entry
* Try to fix macos build
* Revert modifiers println in cursor_grab
* Make serde serialization less bug-prone
* X11: Sync key press/release with window focus
* When a window loses focus, key release events are issued for all pressed keys
* When a window gains focus, key press events are issued for all pressed keys
* Adds `is_synthetic` field to `WindowEvent` variant `KeyboardInput`
to indicate that these events are synthetic.
* Adds `is_synthetic: false` to `WindowEvent::KeyboardInput` events issued
on all other platforms
* Implement windows focus key press/release on Windows
* Docs
Co-authored-by: Murarth <murarth@gmail.com>
* Register windowWillExitFullScreen
* On macOS: Do not toggle fullscreen during fullscreen transition
* Add CHANGELOG
Co-authored-by: Freya Gentz <zegentzy@protonmail.com>
* Add support for Windows Dark Mode
* Add is_dark_mode() getter to WindowExtWindows
* Add WindowEvent::DarkModeChanged
* Add support for dark mode in Windows 10 builds > 18362
* Change strategy for querying windows 10 build version
* Drop window state before sending event
Co-Authored-By: daxpedda <daxpedda@gmail.com>
* Change implementation of windows dark mode support
* Expand supported range of windows 10 versions with dark mode
* Use get_function! macro where possible
* Minor style fixes
* Improve documentation for ThemeChanged
* Use `as` conversion for `BOOL`
* Correct CHANGELOG entry for dark mode
Co-authored-by: daxpedda <daxpedda@gmail.com>
Co-authored-by: Osspial <osspial@gmail.com>
* Implement revamped `RedrawRequested` on iOS
* Added RedrawEventsCleared to events_cleared logic
* Fixed from comments
* Added RedrawEventsCleared to draw_rect handler.
* Fixed out of order `RedrawEventsCleared` events.
* cargo fmt
* Implement changes to `RedrawRequested` event
Implements the changes described in #1041 for the X11 platform and for
platform-independent public-facing code.
* Fix `request_redraw` example
* Fix examples in lib docs
* Only issue `RedrawRequested` on final `Expose` event
Mutter can reposition window on resize, if it is behind mutter's "bounding box".
So, when you start winit window in maximized mode with CSD, mutter places its CSD
behind the GNOME's status bar initially, and then sends configure with the
exact same size as your current window. If winit decides to optimize calling
frame.resize(..) in this case, we won't call set_geometry(we're calling
it through resize) and GNOME won't reposition your window to be inside the
"bounding box", which is not a desired behavior for the end user.
* Add ModifiersChanged event for macOS
This implements the macOS portion of #1124.
* Fix ModifiersChanged event import
* Fix event passing window instead of device id
* X11: Report `CursorMoved` when touch event occurs
* Only trigger CursorMoved events for the first touch ID
* Fix testing for current touch events
* Fix first touch logic
* X11: Sync key press/release with window focus
* When a window loses focus, key release events are issued for all pressed keys
* When a window gains focus, key press events are issued for all pressed keys
* Adds `is_synthetic` field to `WindowEvent` variant `KeyboardInput`
to indicate that these events are synthetic.
* Adds `is_synthetic: false` to `WindowEvent::KeyboardInput` events issued
on all other platforms
* Clarify code with comments
* X11: Fix incorrect modifiers when events are missed
* Syncs modifier state with state data in X key/button/motion events.
* Fixes modifier state in XWayland, as xinput2 raw input events will
not be received when a window does not have focus.
* Removes `impl From<_> for ModifiersState` on X11/Wayland API types,
replacing them with `pub(crate)` methods.
* Cleanup modifier state update using a macro
* Remove keys from modifier state when updating
* X11: Fix window creation hangs when another application is fullscreen
Previously, the X11 backend would block until a `VisibilityNotify` event
is received when creating a Window that is visible or when calling
`set_visible(true)` on a Window that is not currently visible. This
could cause winit to hang in situations where the WM does not quickly
send this event to the application, such as another window being
fullscreen at the time.
This behavior existed to prevent an X protocol error caused by setting
fullscreen state on an invisible window. This fix instead stores desired
fullscreen state when `set_fullscreen` is called (iff the window is not
visible or not yet visible) and issues X commands to set fullscreen
state when a `VisibilityNotify` event is received through the normal
processing of events in the event loop.
* Add window_debug example to facilitate testing
* Add a CHANGELOG entry
* Call `XUnmapWindow` if `VisibilityNotify` is received on an invisible window