Commit graph

1846 commits

Author SHA1 Message Date
OJ Kwon 1819be1173 fix(mac_platform): forward keyevent to system (#511)
* fix(mac_platform): forward keyevent to system

* doc(changelog): update changelog
2018-05-12 22:10:57 -04:00
Victor Berger ffa9b51d27 wayland: improve diagnostic of failed init (#512) 2018-05-12 07:58:11 -04:00
tinaun b4a8c08f43 compile with icon_loading feature on docs.rs (#509)
* compile with icon_loading feature on docs.rs

these functions should be more visible now.

* Explicitly document which functions require icon_loading
2018-05-11 10:33:06 -04:00
Francesca Frangipane 741bcc4672
Correct privacy for Icon::to_cardinals (#510) 2018-05-10 18:42:41 -04:00
Francesca Frangipane e48f1fc5f1
Release winit 0.14.0 (#503) 2018-05-09 10:58:06 -04:00
Johannes Hofmann 374f131f1e Update wayland-client to version 0.20.4 (#505)
Fixes #504
2018-05-08 19:00:54 -04:00
Jack Magnus 363261077f Windows: Fix panic when calling set_fullscreen(None) (#502)
* Windows: Fix panic for set_fullscreen(None) (#501)

* Add condition to prevent panic

Trying to call set_fullscreen(None) on a window that has never been in
fullscreen mode caused a panic before this change.
The responsible method now simply checks if this precondition is met and
returns (does nothing) otherwise.

* Add entry to CHANGELOG

* Add platform specification to CHANGELOG entry

Forgot to add that the to_fullscreen(None) bugfix is Windows only in
CHANGELOG.
2018-05-08 08:16:49 -04:00
Francesca Frangipane 102dd07456
Window icons (#497) 2018-05-07 17:36:21 -04:00
Victor Berger 1e97103094 wayland: migrate to smithay-client-toolkit (#490)
* wayland: migrate to smithay-client-toolkit

* Update smithay-client-toolkit

* Add changelog entry for wayland rework
2018-05-05 13:36:34 -04:00
Francesca Frangipane cc8907b956
X11: Implement resize increments and base size (#494) 2018-05-03 09:41:11 -04:00
Francesca Frangipane c4b92ebd45
X11: General cleanup (#491)
* X11: General cleanup

This is almost entirely internal changes, and as usual, doesn't actually
fix any problems people have complained about.

- `XSetInputFocus` can't be called before the window is visible. This
was previously handled by looping (with a sleep) and querying for the
window's state until it was visible. Now we use `XIfEvent`, which blocks
until we receive `VisibilityNotify`. Note that this can't be replaced
with an `XSync` (I tried).
- We now call `XSync` at the end of window creation and check for
errors, assuring that broken windows are never returned. When creating
invisible windows, this is the only time the output buffer is flushed
during the entire window creation process (AFAIK). For visible windows,
`XIfEvent` will generally flush, but window creation has overall been
reduced to the minimum number of flushes.
- `check_errors().expect()` has been a common pattern throughout the
backend, but it seems that people (myself included) didn't make a
distinction between using it after synchronous requests and asynchronous
requests. Now we only use it after async requests if we flush first,
though this still isn't correct (since the request likely hasn't been
processed yet). The only real solution (besides forcing a sync *every
time*) is to handle asynchronous errors *asynchronously*. For future
work, I plan on adding logging, though I don't plan on actually
*handling* those errors; that's more of something to hope for in the
hypothetical async/await XCB paradise.
- We now flush whenever it makes sense to. `util::Flusher` was added to
force contributors to be aware of the output buffer.
- `Window::get_position`, `Window::get_inner_position`,
`Window::get_inner_size`, and `Window::get_outer_size` previously all
required *several* round-trips. On my machine, it took an average of
around 80µs. They've now been reduced to one round-trip each, which
reduces my measurement to 16µs. This was accomplished simply by caching
the frame extents, which are expensive to calculate (due to various
queries and heuristics), but change infrequently and predictably. I
still recommend that application developers use these methods sparingly
and generally prefer storing the values from `Resized`/`Moved`, as
that's zero overhead.
- The above change enabled me to change the `Moved` event to supply
window positions, rather than client area positions. Additionally, we no
longer generate `Moved` for real (as in, not synthetic)
`ConfigureNotify` events. Real `ConfigureNotify` events contain
positions relative to the parent window, which are typically constant
and useless. Since that position would be completely different from the
root-relative positions supplied by synthetic `ConfigureNotify` events
(which are the vast majority of them), that meant real `ConfigureNotify`
events would *always* be detected as the position having changed, so the
resultant `Moved` was multiple levels of misleading. In practice, this
meant a garbage `Moved` would be sent every time the window was resized;
now a resize has to actually change the window's position to be
accompanied by `Moved`.
- Every time we processed an `XI_Enter` event, we would leak 4 bytes via
`util::query_pointer` (`XIQueryPointer`). `XIButtonState` contains a
dynamically-allocated mask field which we weren't freeing. As this event
occurs with fairly high frequency, long-running applications could
easily accumulate substantial leaks. `util::PointerState::drop` now
takes care of this.
- The `util` module has been split up into several sub-modules, as it
was getting rather lengthy. This accounts for a significant part of this
diff, unfortunately.
- Atoms are now cached. Xlib caches them too, so `XInternAtom` wouldn't
typically be a round-trip anyway, but the added complexity is
negligible.
- Switched from `std::sync::Mutex` to `parking_lot::Mutex` (within this
backend). There appears to be no downside to this, but if anyone finds
one, this would be easy to revert.
- The WM name and supported hints are now global to the application, and
are updated upon `ReparentNotify`, which should detect when the WM was
replaced (assuming a reparenting WM was involved, that is). Previously,
these values were per-window and would never update, meaning replacing
the WM could potentially lead to (admittedly very minor) problems.
- The result of `Window2::create_empty_cursor` will now only be used if
it actually succeeds.
- `Window2::load_cursor` no longer re-allocates the cursor name.
- `util::lookup_utf8` previously allocated a 16-byte buffer on the heap.
Now it allocates a 1024-byte buffer on the stack, and falls back to
dynamic allocation if the buffer is too small. This base buffer size is
admittedly gratuitous, but less so if you're using IME.
- `with_c_str` was finally removed.
- Added `util::Format` enum to help prevent goofs when dealing with
format arguments.
- `util::get_property`, something I added way back in my first winit PR,
only calculated offsets correctly for `util::Format::Char`. This was
concealed by the accomodating buffer size, as it would be very rare for
the offset to be needed; however, testing with a buffer size of 1,
`util::Format::Long` would read from the same offset multiple times, and
`util::Format::Short` would miss data. This function now works correctly
for all formats, relying on the simple fact that the offset increases by
the buffer size on each iteration. We also account for the extra byte
that `XGetWindowProperty` allocates at the end of the buffer, and copy
data from the buffer instead of moving it and taking ownership of the
pointer.
- Drag and drop now reliably works in release mode. This is presumably
related to the `util::get_property` changes.
- `util::change_property` now exists, which should make it easier to add
features in the future.
- The `EventsLoop` device map is no longer in a mutex.
- `XConnection` now implements `Debug`.
- Valgrind no longer complains about anything related to winit (with
either the system allocator or jemalloc, though "not having valgrind
complain about jemalloc" isn't something to strive for).

* X11: Add better diagnostics when initialization fails

* X11: Handle XIQueryDevice failure

* X11: Use correct types in error handler
2018-05-03 09:15:49 -04:00
Christian Duerr fee874b5b7 Add Copy/Paste keys (#495)
* Add Copy/Paste keys

This is only a tiny update which introduces the `Copy` and `Paste` keys
which are present on X11/Wayland/Windows. I'm not sure if this exists on
MacOS too, but I'm not able to test that and it doesn't have names but
just matches on the hex key values.

The "Copy" element is a reserved keyword in Rust but shouldn't cause any
conflicts in this scenario, this behavior falls in line with
https://docs.rs/winit/0.13.1/winit/enum.MouseCursor.html#variant.Copy,
but it would be possible to rename it. However `Copy` seems like the
most intuitive choice.

* Add Cut key, fix windows and update CHANGELOG

This introduces a bunch of minor fixes:
 * The changes introduced by this branch have been added to the changelog
 * Since related, the `Cut` key has also been added
 * An attempt has been made to fix Windows

* Fix position of fallback comment

The new keys have been inserted at the wrong position, so the fallback
comment has been moved to the `_ => ...` section again.

* Fix windows build

Apparently there are no keys for Cut/Paste on Windows, so for now those
have been removed on Windows and only the `Copy` key has been added on
Windows, the changelog has been updated to reflect that.

Linux still implements Copy/Clone/Paste, but `Copy` is now working
properly on Wayland.

MacOS still does not have any of these keys.

* Remove Windows changes

Because the Windows design wasn't completely clear the VirtualKeyCode
variants are now only used on Linux with X11 and Wayland and ignored on
both MacOS and Windows.

The CHANGELOG has also been updated. Windows has been removed from it
and the Linux section has been clarified a bit.
2018-05-02 19:18:52 -04:00
Joe Moon eba888207e macos platform attributes regression (#488)
* macOS: fix regression in 03c3e794097676888234b3cc82c01228dcbe48c8

fixed !decorations case and refactored logic to be a little easier to
read

* fix default case to inlude closable mask

* add comment to default case of macos platform attrs
2018-04-29 18:51:57 -04:00
Johannes Hofmann ea28791da6 x11: Always receive Awakened event in run_forever (#489)
* x11: Always receive Awakened event in run_forever

Do not reset the pending_wakeup boolean at the start of run_forever so
that each call to EventsLoopProxy::wakeup results in an Awakened event.

Fixes #462

* Update CHANGELOG.md
2018-04-28 19:03:06 -04:00
Francesca Frangipane fe2d37fcdc
Windows: Implement DeviceEvents (#482)
Fixes #467

All variants other than Text have been implemented. While Text can
be implemented using ToUnicode, that doesn't play nice with dead
keys, IME, etc.

Most of the mouse DeviceEvents were already implemented, but due
to the flags that were used when registering for raw input events,
they only worked when the window was in the foreground.

This is also a step forward for #338, as DeviceIds are no longer
useless on Windows. On DeviceEvents, the DeviceId contains that
device's handle. While that handle could ostensibly be used by
developers to query device information, my actual reason for
choosing it is because it's simply a very easy way to handle this.
As a fun bonus, this enabled me to create this method:
  DevideIdExt::get_persistent_identifier() -> Option<String>
Using this gives you a unique identifier for the device that
persists across replugs/reboots/etc., so it's ideal for something
like device-specific configuration.

There's a notable caveat to the new DeviceIds, which is that the
value will always be 0 for a WindowEvent. There doesn't seem to be
any straightforward way around this limitation.

I was concerned that multi-window applications would receive n
copies of every DeviceEvent, but Windows only sends them to one
window per application.

Lastly, there's a chance that these additions will cause
antivirus/etc. software to detect winit applications as keyloggers.
I don't know how likely that is to actually happen to people, but
if it does become an issue, the raw input code is neatly
sequestered and would be easy to make optional during compilation.
2018-04-28 12:42:33 -04:00
Vladimir 3407a8dd78 Macos multi windows leak (#481)
* adding a multiwindow example

* Added NSAutoReleasepool for WindowDelegate::Drop
as setDelegate:nil autoreleases WindowDelegate during work.

Added NSAutoReleasepool for Window2::Create,
as it uses autorelease on objects while doing work.

Added NSAutoreleasepool for Window2::Drop
as nswindow::close uses autorelease on objects.

Added NSAutoreleasepool for IdRef.

Moved Window2 WinitWindow objc class to a static var, as we are creating
multiple windows.

* specifying return type for msg_send!

* removing example/recreate_window_leak.rs

* EventLoop, Shared, no need to retain dead weak ptr

* Change log entry added

* added comment about Shared.find_and_remove_window

* fixed code style errors
2018-04-28 12:10:06 -04:00
Joe Moon 5761fb6b30 macOS: fix subtle regression introduced in 0474dc986 (#487)
* macOS: fix subtle regression introduced in 0474dc986

* update changelog
2018-04-28 00:12:50 -04:00
Francesca Frangipane 7aeb2c083b
macOS: Implement Moved (#478)
* macOS: Implement Moved

Fixes #67

* Also emit Moved after resizes that change position
2018-04-27 20:46:20 -04:00
Francesca Frangipane 8f47fdbe67
Windows: Position fixes (#479)
* Remove executable flag from os/macos.rs

This was causing me some grief while working on Windows, and it
doesn't belong here to begin with.

* Windows: get_position returns screen coordinates instead of workspace coordinates

Previously, get_position used GetWindowPlacement. As per the
documentation of WINDOWSTRUCT, the returned coordinates are in
workspace space, meaning they're relative to the taskbar. It's
also explicitly remarked that these coordinates should only be
used in conjunction with SetWindowPlacement, as mixing them with
functions expecting screen coordinates can cause unpleasantness.
Since our set_position (correctly) uses SetWindowPos, this meant
that passing the return of get_position to set_position would
cause the window to move.

We now use GetWindowRect, which returns screen coordinates. This
gives us both better consistency within the Windows backend and
across platforms.

Note that this only makes a difference if the taskbar is visible.
With the taskbar hidden, the values are exactly the same as before.

* Windows: Moved event position values are consistent with get_position

The old Moved values had two problems:

* They were obtained by casting a WORD (u16) straight to an i32.
This meant wrap-around would never be interpreted as negative,
thus negative positions (which are ubiquitous when using multiple
monitors) would result in positions around u16::MAX.

* WM_MOVE supplies client area positions, not window positions.

Switching to handling WM_WINDOWPOSCHANGED solves both of these
problems.

* Better documentation for Moved and Resized
2018-04-26 20:09:33 -04:00
Francesca Frangipane 2ea42b3947
Release winit 0.13.1 (#486) 2018-04-26 18:53:16 -04:00
Branan Riley 7510b95d8c Set minimum x11-dl version to include Z (#484)
Without this pin, an existing cargo.lock for an older winit will not
update the x11-dl dependency, and thus will select a version that is
missing required new XIM features.
2018-04-26 11:53:11 -04:00
Joe Moon 4641433c6a bump minor version (#468)
* bump minor version

* update changelog date and fix typo

* Updated date (we're going to release for real this time)

* Update version in README for the first time in a long time
2018-04-25 11:43:32 -04:00
Francesca Frangipane eadd9a19b2
Replace Closed event with CloseRequested and Destroyed (#476)
* Replace Closed event with CloseRequested and Destroyed

Implements #434

The existing Closed event had ambiguous meaning, both in name and in
cross-platform behavior. Closed is now split into two more precise events:

* CloseRequested - the window has been requested to close, most commonly by
having clicked the window's close button. Whether or not you respond by
closing the window is up to you.

* Destroyed - the window has been destroyed, and can no longer be safely
used.

Most notably, now you can reliably implement classic patterns like
prompting the user to save their work before closing, and have the
opportunity to perform any necessary cleanup.

Migrating to the new API is straightforward. In most cases, you can simply
replace all existing usages of Closed with CloseRequested. For more
information, see the example programs, particularly handling_close and
multiwindow.

iOS applications must replace all usages of Closed with Destroyed, and
require no other changes.
2018-04-24 16:20:40 -04:00
Francesca Frangipane 42f0671531
x11: Windows are Sync again (#474)
* x11: Windows are Sync again

Fixes #472

* Add test ensuring that Window is Sync

Window must be Sync for Vulkano's Arc<FramebufferAbstract> to be usable.
2018-04-21 11:53:57 -04:00
Francesca Frangipane eae7cb247c
Revert #466 'Discard mouse down after Cocoa window resize' (#470)
This reverts commit 19cd53193b.

Testing fullscreen functionality revealed that windowDidResize is invoked in more cases than previously thought, causing the user's events to be eaten and HiDPI problems.
2018-04-17 20:48:57 -04:00
Edwin Cheng 0474dc9861 Implement set_maximized, get_current_monitor, set_fullscreen and set_decorations for MacOS (#465)
* Added helper function for make monitor from display.

* Implement get_current_monitor  for macos

* Implemented with_fullscreen and set_fullscreen for macos

* Implemented set_decorations for macos

* Implement set_maximized and with_maximized for macos

* Changed fullscreen example fullscreen keypress from F11 to F

* Update CHANGELOG.md

* Add and fixed some comments

* Reformat and add more comments

* Better handling window and maximized state

* Reformat and typo fix
2018-04-17 14:07:54 -04:00
Osspial 8fd49a4dbe Add methods to get the position of a window's client area, relative to the desktop (#430)
* Add get_inner_position for windows, prototypes for other platforms

* Fix linux builds

* Implement get_inner_position for osx

* Add get_inner_pos implementations for other platforms

* Fixed get_inner_position on macOS

* Corrected set_position on macOS

* Added CHANGELOG entry
2018-04-16 21:40:30 -04:00
YVT 10688915eb [macOS] Register the Cocoa main thread at an earlier point (#456)
Solves the issues caused by calling `EventsLoopProxy::wakeup()` too
early from a worker thread.
2018-04-16 18:09:02 -04:00
Tristam MacDonald 19cd53193b Discard mouse down after Cocoa window resize (#466)
* Discard mouse down after Cocoa window resize

We are sending the mouse down event after the window resize has
completed, because Cocoa uses a modal event loop to implement window
resize. This leads to a mouse down without a matching mouse up.

* Also handle event discard in poll_events

Add some explanatory comments and a changelog entry.
2018-04-15 10:16:44 -07:00
Evan Weiler 2477d8ce46 [ci skip] Doc fix for struct winit::Window (#452) 2018-04-13 14:51:10 -04:00
Francesca Frangipane 8b0b4ab248
Moved CHANGELOG entry from #444 to correct section (#461) 2018-04-13 14:15:30 -04:00
Osspial 24333b806a Update windows set_cursor to use more variants of MouseCursor (#407)
* Update windows set_cursor to use more variants of MouseCursor

* Add changelog entry
2018-04-13 13:53:01 -04:00
Lymia Aluysia c327960f3e windows: Adjust min_dimensions and max_dimensions using AdjustWindowRectEx. (#444) 2018-04-13 12:51:29 -04:00
Edwin Cheng bdc01fee1a Implement set_maximized, get_current_monitor, set_fullscreen and set_decorations for windows (#457)
* Implement set_fullscreen for windows

* Implement get_current_monitor for windows

* Implement set_maximized

* Implement set_decorations for windows

* Update CHANGELOG.md

* Fixed minor syntax bug for stable rust version

* Added support for WindowBuilder::with_maximized

* Move all window sized related functions to main thread

* Refactor and formatting force_window_active

* Remove unused code

* Update CHANGELOG.md

* Refactor and change keyboard handling code

* Reformatting and refactoring

* Added back missing link for comment

* Fixed set_maximized and set_fullscreen wrong order bug

* Call ShowWindow(SW_RESTORE) when restore_saved_window

* Sync system maximized status when set_fullscreen

* Fixed wrong function name
2018-04-12 13:12:15 -04:00
Francesca Frangipane 457c0b7208
Windows: Implement Refresh event (#454)
Fixes #180
2018-04-11 09:29:01 -04:00
Francesca Frangipane 09c809003b
x11: Overhaul XIM code (#451)
Fixes #195
Fixes #277
Fixes #455

* Read `XMODIFIERS` explicitly/directly instead of calling `XSetLocaleModifiers` with an
empty string. This is useful for debugging purposes, and more clear to read and handle.
* Fallback to local input method if the one specified in `XMODIFIERS` is later closed on the
server end (i.e. if ibus/fcitx is terminated). Previously, that would cause the event loop
to freeze and usually also segfault.
* If using the fallback input method, respond to the `XMODIFIERS` input method later
becoming available. This means that the input method restarting is handled, and that even if
the program was started while ibus/fcitx/etc. was unavailable, it will start using it as
soon as it becomes available.
* Only one input method is opened for the whole event loop, with each window having its own
input context.
* IME works completely out of the box now, no longer requiring application developers to
call `setlocale` or `XSetLocaleModifiers`.
* Detailed error messages are provided if no input method could be opened. However, no
information is provided to the user if their intended `XMODIFIERS` input method failed to
open but the fallbacks (which will ostensibly always succeed) succeeded; in my opinion, this
is something that is best filled by adding a logging feature to winit.
2018-04-10 22:18:30 -04:00
Joe Moon f08bf44670 [macOS] implement HiDPIFactorChanged event on relevant events: (#443)
* moving window to another screen
* changing resolution of screen
2018-04-10 21:42:22 -04:00
Simon Sapin e36fd1788d Fix some more unconstrained types in msg_send results (#453)
The error I was investigating https://github.com/servo/servo/pull/20474#issuecomment-379802897 turned out to be already be fixed by https://github.com/tomaka/winit/pull/428, but there was a few more cases of the same problem.
2018-04-09 15:58:47 -04:00
Francesca Frangipane 4005bf11e4
x11: More robust geometry calculations (#438)
Tested on the following window managers:
* Xfwm4 4.12.4
* Mutter 3.26.2
* Muffin 3.6.0
* Budgie 10.4
* Marco 1.20.0
* Compiz 0.9.13.1
* KWin 5.12.3
* Enlightenment 0.22.2
* FVWM 2.6.7
* Awesome 4.2
* i3 4.15
* xmonad 0.13
* dwm 6.1
* Openbox 3.6.1
* Fluxbox 1.3.7
* Blackbox 0.70.1
* IceWM 1.3.8
* IceWM 1.4.2
2018-04-07 15:36:10 -04:00
mitchmindtree 9d036a6faa
Publish 0.12.0. Update CHANGELOG. (#449)
See the CHANGELOG for all relevant changes included in this new version.
2018-04-06 15:04:12 +05:45
Ed Barnard 591e0d9b8e Fix macOS window sizes to follow convention with changelog entry (#435)
* Fix macOS window sizes to follow convention

* Add changelog entry
2018-04-05 15:51:15 -04:00
cpardotortosa 580321b56f Add Touch events for win32. (#377)
* Add Touch events for win32.

* Add entry to CHANGELOG.md
2018-04-05 15:25:37 -04:00
Francesca Frangipane 1c4973d5b7
x11: Only access XIM from the event loop thread (#439)
XIM isn't thread-safe at all. Any call made to it from another thread will result in the
event loop freezing (this is why the old implementation of Drop for Window had that
problem).

XIM is now confined to one thread, and the existing API is maintained using channels. In
testing this with Alacritty, I initially thought the occasional slight lag on updating the
spot location was due to this change, but it's present without it as well.
2018-04-05 14:58:10 -04:00
hcpl 7cd440135a Try XOpenIM with different locale modifiers (#424)
* Try XOpenIM with different locale modifiers

Implements the solution suggested in
https://github.com/tomaka/winit/issues/277#issuecomment-337751136.

* Use empty XSetLocaleModifiers beforehand

Also, for modifiers, convert from length-based UTF-8 strings to
null-terminated bytestrings.

* Add CHANGELOG entry and comments
2018-04-05 13:21:50 -04:00
Francesca Frangipane f3ab8af813
x11: Don't panic when using dead keys (#432) 2018-04-05 12:58:24 -04:00
Joe Moon be6d2ed3b9 subclass windows in macos so they can be made resizable even with no decorations (#408)
* make windows without decorations resizable and movable in macos

fixes #368

The subclassing logic was copied from servo's fork of glutin:
63026a0f4c/src/api/cocoa/mod.rs (L418)

* remove `isMovableByWindowBackground` and `mouseDownCanMoveWindow`

* revert example changes

* remove resizable mask from decoration: false

* avoid duplicate class declarations

* update changelog

* fix changelog

* changelog whitespace
2018-04-02 19:12:38 -04:00
Pierre Krieger 0b922ad9c0
0.11.3 (#437) 2018-03-28 13:32:46 +02:00
Gabriel Majeri b40b14f37f Avoid destroying the window twice (#388) 2018-03-25 20:30:16 +02:00
forbjok 7a1946589c x11: Support numpad arrows/Home/End/PageUp/PageDown/Insert/Delete (#396) 2018-03-23 10:36:04 +01:00
Osspial bbcd3019e8 Add ability to change the min/max size of windows at runtime (#405)
* Add min/max size setting for win32 and wayland backends

* Implement dynamic min/max size on macos

* Add min/max size setting for x11

* Add empty functions for remaining platforms

* Improved min/max size setting for x11

* Added CHANGELOG entry for new min/max methods

* Added documentation for new min/max methods

* On win32, bound window size to min/max dimensions on window creation

* On win32, force re-check of window size when changing min/max dimensions

* Fix freeze when setting min and max size
2018-03-23 10:35:35 +01:00