* On macOS, add `WindowBuilderExtMacOS::with_parent_window`
* Replace Parent with Option<Id<NSWindow, Shared>>
* Add addChildWindow method on NSWindow instead
* Update with_parent_window to be unsafe fn
* Add unified `with_parent_window`
* Remove `WindowBuilderExtUnix::with_parent`
* Remove `WindowBuilderExtWindows::with_parent_window`
* Clean up CI warnings
* Update CHANGELOG.md
It's `WindowBuilderExtX11` rather than `WindowBuilderExtUnix`
* Rename parent to owner
* Make with_parent_window unsafe and update its doc
* Add another way to get window on mac
* Add more documentations
* Add match arm and panic on invalid varients
* Add Xcb arm
* Update child_window example to make it safer and work in i686
* Remove duplicate entry in CHANGELOG.md
* Propogate error instead of expect
* Replace unreachable to panic
* Add platform note to X11
Co-authored-by: Wu Yu Wei <wusyong9104@gmail.com>
* On Windows and macOS, add API to enable/disable window controls
* fix build
* missing import
* use `WindowButtons` flags
* rename to `[set_]enabled_buttons`
* add example, fix windows impl for minimize
* macOS: Fix button enabling close/minimize while disabling maximized
* Update src/platform_impl/windows/window.rs
Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
* compose the flags on a sep line, use `bool::then`
Co-authored-by: Mads Marquart <mads@marquart.dk>
Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
This adds `Window::set_window_level` to control the preferred
z level of the window.
Co-authored-by: Markus Siglreithmaier <m.siglreith@gmail.com>
Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
Co-authored-by: Mads Marquart <mads@marquart.dk>
Android also supports `EventLoopExtRunReturn`. The user will still have
to follow the README to turn this example into a `cdylib` and add the
`ndk_glue::main()` initialization attribute, though.
This commit renames `Window::set_cursor_grab` to
`Window::set_cursor_grab_mode`. The new API now accepts enumeration
to control the way cursor grab is performed. The value could be: `lock`,
`confine`, or `none`.
This commit also implements `Window::set_cursor_position` for Wayland,
since it's tied to locked cursor.
Implements API from #1677.
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 brings new Ime event to account for preedit state of input
method, also adding `Window::set_ime_allowed` to toggle IME input on
the particular window.
This commit implements API as designed in #1497 for desktop platforms.
Co-authored-by: Artur Kovacs <kovacs.artur.barnabas@gmail.com>
Co-authored-by: Markus Siglreithmaier <m.siglreith@gmail.com>
Co-authored-by: Murarth <murarth@gmail.com>
Co-authored-by: Yusuke Kominami <yukke.konan@gmail.com>
Co-authored-by: moko256 <koutaro.mo@gmail.com>
* Improve web example
* Implement basic logger into the example webpage
* Repace bash script with xtask
* replace wasm-bindgen-cli with wasm-bindgen-cli-support
* refactor
* Move logic into external crate.
* Remove CI changes
* Review feedback
This commit adds an `EventLoopBuilder` struct to simplify event loop
customization and providing options to it upon creation. It also
deprecates the use of `EventLoop::with_user_event` in favor of the same
method on new builder, and replaces old platforms specific extension
traits with the new ones on the `EventLoopBuilder`.
* examples: Fix unused `Result` that must be used when initializing console_log
* examples: Fix unused imports
* Fix unread name field warning in linux x11 ime InputMethod struct
* Fix unread name field warning in linux x11 Device struct
* Ignore unread field warning in macos/ios MonitorHandle struct
* ci: Add `--deny warnings` to `RUSTFLAGS`
* Remove support for `stdweb`
* Expunge `stdweb`; make `web-sys` the default
* Mark this change as a breaking change
* Re-insert accidental removal of space
* Use the correct cargo feature syntax
* Re-add some `cfg` attributes
* Remove `web-sys` feature from CI
This changes 'Fullscreen::Borderless' enum variant from
'Fullscreen::Borderless(MonitorHandle)' to
'Fullscreen::Borderless(Option<MonitorHandle>)'. Providing
'None' to it will result in picking the current monitor.
Certain platforms like Wayland don't have a concept of
primary Monitor in particular. To indicate that
'primary_monitor' will return 'None' as well as in cases
where the primary monitor can't be detected.
Fixes#1683.
On certain platforms window couldn't be on any monitor
resulting in failures of 'current_monitor' function.
Such issue was happening on Wayland, since the window
isn't on any monitor, unless the user has drawn something into it.
Returning 'Option<MonitorHandle>' will give an ability to
handle such situations gracefully by properly indicating that
there's no current monitor.
Fixes#793.
* 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>
User can switch between Wait, WaitUntil and Poll modes with key '1', '2' and '3' respectivly.
User can toggle request_redraw calls with the 'R' key.
Helpful for testing all control flow modes and use of request_redraw.
* 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
* 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
* 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
* 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