Commit graph

1824 commits

Author SHA1 Message Date
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
Francesca Frangipane d667a395b6 x11: Destroy dropped windows; handle WM_DELETE_WINDOW (#416)
Fixes #79 #414

This changes the implementation of Drop for Window to send a WM_DELETE_WINDOW ClientMessage,
offloading all the cleanup and window destruction to the event loop. Unsurprisingly, this
entails that the event loop now handles WM_DELETE_WINDOW using the behavior that was
previously contained in Window's Drop implementation, along with destroying the Window.
Not only does this mean that dropped windows are closed, but also that clicking the × button
on the window actually closes it now.

The previous implemention of Drop was also broken, as the event loop would be (seemingly
permenanently) frozen after its invocation. That was caused specifically by the mutex
locking, and is no longer an issue now that the locking is done in the event loop.

While I don't have full confidence that it makes sense for the Drop implementation to behave
this way, this is nonetheless a significant improvement. The previous behavior led to
inconsistent state, panics, and event loop breakage, along with not actually destroying the
window.

This additionally makes the assumption that users don't need Focused or CursorLeft events
for the destroyed window, as Closed is adequate to indicate unfocus, and users may not
expect to receive events for closed/dropped windows. In my testing, those specific events
were sent immediately after the window was destroyed, though this sort of behavior could be
WM-specific. I've opted to explicitly suppress those events in the case of the window no
longer existing.
2018-03-23 10:31:31 +01:00
Joe Moon 76118af341 update changelog (#431) 2018-03-23 10:25:02 +01:00
Joe Moon ce7a426bb5 323 windowbuilder ext macos (#423)
* macOS: Allow hiding the title from the titlebar

* macOS: Allow making the titlebar transparent

* macOS: Give control over content view size

Allows setting `NSFullSizeContentViewWindowMask` with WindowBuilder.

* macOS: add `.with_titlebar_hidden` to WindowBuilderExt

* macOS: adds `titlebar_buttons_hidden` platform specific attribute
2018-03-22 17:57:35 +01:00
icefoxen 5dcde83b4c Fix readme for webassembly usage. (#425)
Needs to do `getElementById()`, not just have the ID name.
Not sure if this is a winit change or what.
2018-03-22 17:56:21 +01:00
YVT 559681b0ed [macOS] Fix crashes due to the stabilization of the ! (never) type (#428)
Due to the recent changes in the Rust compiler, unconstrained type
variables are now deduced to `!` instead of `()`. There are some
occurrences where `msg_send!` is used without constraining its return
type (relying on the assumption that they would be deduced to be `()`).
As a result, the macOS port of winit stopped working.

This PR fixes this issue (#426) by adding explicit return types to
such uses of `msg_send!`.
2018-03-21 20:36:06 +01:00
Paul Rouget 51181b4347 Version bump (#418)
* Send Awakened event on Android when event loop is woken up

* v0.11.2
2018-03-06 18:07:18 +01:00
Paul Rouget e6fefd5e93 Send Awakened event on Android when event loop is woken up (#417) 2018-03-06 18:06:56 +01:00
Nicholas Lordello f3d43016ad Implement MonitorId::get_hidpi_factor for macOS (#410)
* Implement MonitorId::get_hidpi_factor for macOS

* Added changelog entry
2018-03-06 09:35:04 +01:00
Jim Turner 4c62d71950 Derive more traits for events::ModifiersState (#411) 2018-02-22 18:15:56 +01:00
Chet Gurevitch f279b2f229 Version 0.11.1 (#409) 2018-02-20 16:18:16 +01:00
Imanol Fernandez c62296dc2b Add set_suspend_callback method for Android (#406)
Makes it possible for glutin to register a callback when a suspend event happens on Android
2018-02-15 14:09:14 +01:00
HDM 7daf27f389 Add mouse event capturing when click-dragging out of a win32 window (#292)
* Add mouse event capturing when click-dragging out of a win32 window

* Remove git merge conflict comments

* Add changelog entry
2018-02-14 10:31:25 +01:00
Pierre Krieger 4abcc164cd
Publish 0.11.0 (#404) 2018-02-09 12:07:19 +01:00
Joe Wilm 4cce65274f Fix x11 window size calculations (#402)
The fix for returning accurate window position lead to a regression
computing inner size in pixels. This commit resolves that by getting
inner size from the window ID winit caches and still resolving position
by climbing the window hierarchy.

Resolves #398
2018-02-08 18:10:39 +01:00
Paul Rouget ff17eff00f Implement MonitorId::get_dimensions for Android (#400) 2018-02-08 14:55:17 +01:00
Paul Rouget 9b5254adeb Version 0.10.1 (#397) 2018-02-05 18:50:13 +01:00
Jeff Muizelaar b49abbbf17 Update mac dependencies (#390) 2018-02-05 14:34:37 +01:00
Johannes Hofmann 107a1e7332 x11: Support XRandR versions older than 1.5 (#394)
* x11: Support XRandR versions older than 1.5

Fixes #392

Previously, initializing the member `xrandr` of `XConnection` resulted
in a panic when symbols from XRandR version 1.5 were missing. There was
already code to handle older versions of XRandR but it was never
executed because of the panic.

The member `XConnection.xrandr` now contains only functions that can
safely be used with older versions. Additionally, this commit adds a new
member to `XConnection` of type `Option<ffi::XRandr>` that only contains
a value if version 1.5 functionality is present.

* x11: Document the xrandr* members of XConnection
2018-02-03 11:18:51 +01:00
Joe Wilm 150d2706f9 Fix x11 Window::get_position wrong values (#386)
Some window managers like i3wm will actually nest application windows
(like those opened by winit) within other windows to, for example, add
decorations. Initially when debugging this method on i3, the x and y
positions were always returned as "2".

The solution that other xlib abstractions use is to climb up the window
hierarchy until just below the root window, and that window must be used
to determine the appropriate position.

This patch doesn't take into account borders or the window's offset
within its parent, but it's much more usable than the original
implementation on certain WMs.
2018-01-27 14:26:13 +01:00
Benjamin Cheng 7d38ed2fab X11: Cursor grabbing fixes (#385)
- Only update cursor_state when the grab is successful
- Ungrab before grabbing to prevent passive grabs (ex. clicking) from
causing AlreadyGrabbed
2018-01-26 21:52:18 +01:00
Michael Schumacher 1609808e27 Add support for Caret (^) Key in OSX (de_DE) (#380)
* Add caret key

* Use hex value

* Added caret key support.
2018-01-25 13:32:30 +01:00
Robert Günzler 7e1c70964d [macOS] Move the window if there is no title bar (#382)
* macOS: Move the window if there is no title bar

On macOS by default windows can only be moved by clicking and
dragging on the titlebar, if we spawn a window without one we
need to set the `movableByWindowBackground` property.

Partial fix for #368

* macOS: Make moveByWindowBackground optional

Implements setting the property via WindowBuilderExt:

    WindowBuilder::new()
        .with_decorations(false)
        .with_movable_by_window_background(true)

* Update CHANGELOG
2018-01-22 19:07:51 +01:00