Commit graph

251 commits

Author SHA1 Message Date
Joe Wilm 0e81251f3a Implement hidpi factor for x11 MonitorId (#387)
This was previously hardcoded to 1.0. The values for physical size in
millimeters and pixel counts on each axis are used to compute the dpi
per monitor.
2018-01-22 18:36:26 +01:00
Victor Berger 0ea4f93f05 Implement set_maximized, set_fullscreen and set_decorations for wayland (#383)
* wayland: implement Window::set_decorations()

* wayland: implement Window::set_maximized()

* wayland: implement Window::set_fullscreen()

* Update changelog.
2018-01-13 06:38:12 +01:00
Francesca Sunshine 124b16fcde x11: Always use correct window ID for XInput2 events (#372)
The `CursorMoved` events that are used to send position updates alongside `Focused` and
`CursorEntered` events were using incorrect values for the window ID. This is a direct
result of the X11 backend being hard to understand, as those values came from variables in
the top-level scope of the function, which one would assume to be valid throughout the
entirety of their scope. In reality, their validity is dependent on the event belonging to
the `XEvent` union, so very surprising things can happen if those variables are read in the
case of XInput2/XKB/etc. events. To prevent future accidents, the aforementioned variables
have been removed, and are now defined per-event instead.

Additionally, the `CursorMoved` event sent alongside `Focused` now uses the correct device
ID; it previously used the ID of a master keyboard, but now uses the ID of the pointer
paired to that keyboard. Note that for those using multi-pointer X, the correctness of this
ID is dependent on the correctness of the window manager's focus model.
2018-01-08 11:06:02 +01:00
Dzmitry Malyshau a8d5a9e1ab [emscripten] request canvas size instead of CSS size (#370) 2017-12-27 18:37:01 +01:00
Tuomas Siipola f89dc9e903 x11: Remember cursor after changing cursor state (#374) 2017-12-27 14:30:59 +01:00
Bryan Gilbert 011720848a Added modifier support to mouse events (#328) 2017-12-26 22:46:28 +01:00
Gabriel Majeri d92666c188 Update winapi to 0.3 (#346)
* Update to `winapi` 0.3

* Update max size comment

* Fix missing import

* Shorten import path

* Update to stable winapi version
2017-12-24 14:46:47 +01:00
Francesca Sunshine 463f316cb8 Add set_decorations method to Window (#365)
This has been stubbed on all platforms other than X11. The X11 implementation has also been
revised to toggle correctly, as it was previously only able to remove decorations.
2017-12-22 13:50:46 +01:00
Francesca Sunshine 23e4293179 unix::WindowExt no longer returns pointers for things that aren't actually pointers (#364)
Fixes #256

`get_xlib_window` and `get_xlib_screen_id` previously returned `Option<*mut c_void>` by
casting integer IDs into pointers, which while producing no functionality issues, is
semantically incorrect and rather surprising. Worse still, the docs for `get_xlib_window`
stated that it was in fact a valid pointer.

Additionally, now all `unix::WindowExt` methods return `std::os::raw` types rather than
`libc` types; note that the two versions of `c_void` are not interchangeable in the eyes of
the compiler, so those wanting the `libc` type will need to explicitly cast.

This is a breaking change, and will require some trivial changes to glutin.
2017-12-17 10:17:26 +01:00
Francesca Sunshine 8f18dab061
x11: Send window maximization hints correctly (#363)
Previously, the maximization hints were being sent as two separate client messages: one for
horizontal, and one for vertical. That resulted in the window only being maximized
horizontally (at least with my WM). The corrected client message sets both of these hints at
once.

In the process of implementing that, the relevant components were refactored to use the util
module, as we gradually move towards a hopeful future of a more readable X11 backend.
2017-12-15 14:37:09 -05:00
Francesca Sunshine 9698d0a8d8
x11: Set window title prior to mapping window (#362)
Fixes #282

Some tiling window managers (i3, dwm, etc.) determine how a window should behave based on
its name. If the name is set after mapping, then window managers will check the name before
we set it, followed by them detecting it as a change when the name is actually set. That
results in the window briefly behaving in an unexpected way, followed by a rapid switch to
the expected behavior.

In accordance to section 4.1.2 of ICCCM, the name, decorations, size hints, and window
deletion redirection have all been moved up to be set before mapping.
2017-12-13 16:41:49 -05:00
Francesca Sunshine d18db208ff x11: Implement file drag and drop (#360)
* x11: Implement file drag and drop

* Fixed typo
2017-12-13 12:22:03 +01:00
thiolliere d2dd82c146 impl touch events for emscripten (#358) 2017-12-01 14:00:09 +01:00
thiolliere 663d615379 Emscripten (#357)
* impl modifiers state for emscripten

* impl mouse events emscripten

* impl mousemotion for emscripten

it is useful when cursor is grabbed

* changelog
2017-12-01 10:53:50 +01:00
stuart nelson 0f14e63b34 Send mouse position after focused/cursorenter events (#349)
* Update mouse pos after cursor enter event

* Update mouse position on windows focus

* Send device_id

* Update other device id

* Fix windows import

* Remove deque for vec

* Just send event

* Use correct push_back method

* Push correct event
2017-11-26 21:43:13 +01:00
Jacob Kiesel fae10c6072 Emit delete character on Windows (#352) 2017-11-21 10:12:51 +01:00
Jacob Kiesel cfd087d9a5 Mouse events (#344)
* Explicit mouse-related DeviceEvents

This makes the API more intuitive for common use-cases and allows us
to better propagate platform knowledge of motion semantics.

* Improve event naming consistency

* Clarify axis event forwards-compatibility

* Rename WindowEvent::MouseMoved/Entered/Left to CursorMoved/...

This emphasizes the difference between motion of the host GUI cursor,
as used for clicking on things, and raw mouse(-like) input data, as
used for first-person controls.

* Add support for windows and OSX, fix merging

* Fix warnings and errors on Linux

* Remove unnecessary breaking changes

* Add MouseWheel events to windows and OSX

* Fix bad push call.

* Fix docs, naming, and x11 events

* Remove mutability warning

* Add changelog entry
2017-11-12 21:56:57 +01:00
Victor Berger c61f9b75f8
Wayland: implement touch events (#342)
* wayland: move pointer to its own file

* wayland: touch events support

* update changelog
2017-11-11 10:03:42 +01:00
Victor Berger 61d25be3e0
wayland: upgrade wayland-window (#339)
* wayland: upgrade wayland-window

This new version of wayland window considerably simplifies the
window handling for winit, meaning much of the previous juggling
is no longer needed, and the windows will appear even if nothing is
drawn.

* wayland: cleanup unused stuff
2017-11-03 17:35:29 +01:00
Andriy Symonovych 37a10e6741 update macos deps (#335) 2017-10-31 11:03:18 +01:00
Victor Berger 62e45fa75d wayland: update dependencies (#334) 2017-10-30 07:27:43 +01:00
Ken Reed 01d1178d7b Made poll events loop over as many events as there may be instead of just one. (#333) 2017-10-29 07:02:57 +01:00
Alex Butler b3c5ee6219 Fix no primary monitor panic in XWayland (#318)
* Fix no primary monitor panic in XWayland

In this case try to use the first existing monitor instead of panicking.
Fixes #317

* Shift no monitor panic to x11::get_primary_monitor

* Update changelog with xll get_primary_monitor fallback
2017-10-28 15:24:37 +02:00
Chris Tolliday 159364bec3 Impl Clone for EventsLoopProxy (#331) 2017-10-25 20:03:57 +02:00
Victor Berger 58181dbff9 wayland: Fix drop order for display (#326) 2017-10-25 18:28:24 +02:00
kryptan 760e588627 Use EnumDisplayMonitors to enumerate monitors on Windows (#327)
* Use EnumDisplayMonitors to enumerate monitors on Windows

* Add requested changes
2017-10-25 17:12:39 +02:00
Victor Berger d10312c6b1 Rewrite of wayland backend to new wayland-client API (#325)
* wayland: clean state for rewrite to new wayland-client API

* wayland: context init

* wayland: Monitors logic

* wayland: Basic event loop logic

* wayland: Keyboard handling

* wayland: pointer handling

* wayland: refactor to remove WaylandContext

* wayland: window logic

* wayland: event dispatching logic

* wayland: update changelog
2017-10-20 09:46:42 +02:00
kryptan 4e4db1749d Make MonitorId::get_position() return (i32, i32) instead of (u32, u32) because it can be negative on Windows (#324) 2017-10-19 19:08:05 +02:00
kryptan 48902297b7 Implement public API for high-DPI (#319)
* Implement public API for high-DPI #105

* Recover get_inner_size_points and get_inner_size_pixels and change their implementation assuming get_inner_size() returns size in pixels

* Update changelog for high-DPI changes
2017-10-17 13:56:38 +02:00
Chet Gurevitch eff3440482 Mirror x11 ISO_LEFT_TAB detection on wayland and release version 0.8.3 (#314)
* wayland: mirror x11 ISO_LEFT_TAB detection

* Release 0.8.3
2017-10-12 09:39:41 +02:00
Victor Berger 3d8c94bae5 wayland: commit the empty surface at init (#309)
This should trigger the compositor's mechanism for sending a
configure event, which should most of the time be processed
before any winit user actually tries to draw.
2017-10-08 15:51:48 +02:00
Matteo Signer 3f33cd1929 Make ISO_Left_Tab generate VirtualKeyCode::Tab (#308)
* Make ISO_Left_Tab generate VirtualKeyCode::Tab

* Add changes to changelog
2017-10-08 13:59:45 +02:00
Pedro Côrte-Real 1db92063d9 Fix X11 on 32bit architectures (#311)
* Add an i386 target to travis

* Fix X11 on 32bit architectures

One would hope 32bit X11 was dead by now but apparently not :). Fix
the window hint setting code to not assume window IDs are 64bit as
apparently they are not in 32bit arches.
2017-10-07 21:20:37 +02:00
Chris Tolliday 5af88d97e8 On Windows, use SWP_ASYNCWINDOWPOS to prevent thread from blocking when calling (#302)
set_inner_size
2017-10-04 09:42:35 +02:00
Victor Berger 515595153d Wayland: rework the event loop & expose readiness signal (#298)
* wayland: don't create a second event_queue

As each EventsLoop has its own context, this is no longer necessary.

* wayland: buffer events rather than direct dispatch

Changes the behavior of the event loop to first internally
buffer the events generated by the wayland handlers, and then
dispatch them to the client's closure.

- It simplifies the event loop logic
- It makes it possible for the user to call window methods such as
  `set_title()` or `set_inner_size()` without causing a deadlock

* wayland: add is_ready() & fix protocol errors

Adds a `is_ready()` method to the windows to advertize
when it is legal to start drawing, and fix a few wayland
protocol mishandling in the process.
2017-09-27 16:31:46 +02:00
Victor Berger 9c116a1bae x11: uniformize keyboard scancodes with linux (#297) 2017-09-25 07:25:36 +02:00
tomaka 15fbc0dff4 Publish 0.8.1 with fixes necessary for glutin (#296) 2017-09-23 09:36:30 +02:00
Matteo Signer 52a78d61bf Fix #273 (#274) 2017-09-21 16:09:07 +02:00
Kelvin Ly 192bd798e3 Implement virtual key translation for emscripten (#289)
* Implement virtual key translation

* Remove unused std::mem import from the right file

* Install git on CircleCI instances

* Fix CircleCI config script

* Fix type error in emscripten keyboard events
2017-09-16 15:46:53 +02:00
tomaka 52a7b07c79 Move the Suspended event outside of WindowEvent (#284)
* Move Suspended event outside of WindowEvent

* Adjust the iOS code
2017-09-15 16:24:09 +02:00
tomaka 1d0b5bcfbd Remove the use platform_not_supported hack (#285) 2017-09-15 15:45:45 +02:00
tomaka 769d4fe897 Emscripten rework (#286)
* partial implementation for emscripten

this pull request contain a partial but working implementation of emscripten backend

some implementations may be controversial.

here some implementation detail:

* cursor state:
  * on grab: emscripten request pointer lock deferred and also set a callback when pointer lock change
             the callback request pointer lock deferred.
  * on hide: `emscripten_hide_mouse` exist but not `emscripten_show_mouse`
             a pull request has been open on october 2016 but never been merged
             so I copied the javascript function and put it in emscripten_asm_const function

* fullscreen: if fullscreen is requested then it request fullscreen deferred and set a callback on fullscreen change
              the callback request fullscreen deferred

* run forever: this method use emscripten main loop to run an infinite loop

* keyboard callback doesn't consume the event. I think it is more apopriate as in desktop environment it is the same, is it ?

* emscripten dir is added in example and contains html pages

Some things that are not implemented:

* lots of events

* min and max dimension can be implemented with a callback that listen to size change and resize if dimension out of bound

* title may be implemented using javascript to change document.title

* Use std::os::raw in the emscripten bindings

* Fix emscripten code

* Update code

* Add CI

* Remove the emscripten-specific examples

* Add some information to the README
2017-09-14 16:31:34 +02:00
tomaka ae7802c8c2 Fix warnings for win32 (#283) 2017-09-13 11:15:16 +02:00
Pedro Côrte-Real 59c33d2c6a Move fullscreen modes to not touch physical resolutions (#270)
* Fix X11 screen resolution change using XrandR

The previous XF86 resolution switching was broken and everything
seems to have moved on to xrandr. Use that instead while cleaning
up the code a bit as well.

* Use XRandR for actual multiscreen support in X11

* Use actual monitor names in X11

* Get rid of ptr::read usage in X11

* Use a bog standard Vec instead of VecDeque

* Get rid of the XRandR mode switching stuff

Wayland has made the decision that apps shouldn't change screen
resolutions and just take the screens as they've been setup. In the
modern world where GPU scaling is cheap and LCD panels are scaling
anyway it makes no sense to make "physical" resolution changes when
software should be taking care of it. This massively simplifies the
code and makes it easier to extend to more niche setups like MST and
videowalls.

* Rename fullscreen options to match new semantics

* Implement XRandR 1.5 support

* Get rid of the FullScreen enum

Moving to just having two states None and Some(MonitorId) and then
being able to set full screen in the current monitor with something
like:

window.set_fullscreen(Some(window.current_monitor()));

* Implement Window::get_current_monitor()

Do it by iterating over the available monitors and finding which
has the biggest overlap with the window. For this MonitorId needs
a new get_position() that needs to be implemented for all platforms.

* Add unimplemented get_position() to all MonitorId

* Make get_current_monitor() platform specific

* Add unimplemented get_current_monitor() to all

* Implement proper primary monitor selection in X11

* Shut up some warnings

* Remove libxxf86vm package from travis

Since we're no longer using XF86 there's no need to keep the package
around for CI.

* Don't use new struct syntax

* Fix indentation

* Adjust Android/iOS fullscreen/maximized

On Android and iOS we can assume single screen apps that are already
fullscreen and maximized so there are a few methods that are implemented
by just returning a fixed value or not doing anything.

* Mark OSX/Win fullscreen/maximized unimplemented()!

These would be safe as no-ops but we should make it explicit so
there is more of an incentive to actually implement them.
2017-09-07 10:33:46 +02:00
tomaka 342d5d8587 Remove api_transition macro (#279)
* Remove api_transition macro

* Rename Window2 to Window

* Try fix X11 code
2017-09-06 17:32:24 +02:00
tomaka 2a4b381384 Update iOS for EventsLoop design (#275)
* Inline gen_api_transition! in the ios module

* Event loop proxy work

* Monitors

* Use freestanding functions

* Finish conversion
2017-09-04 12:41:10 +02:00
tomaka fe1deb83ae Update Android code with EventsLoop (#272)
* Update Android code with EventsLoop

* Fix run_forever
2017-09-04 12:41:02 +02:00
Pedro Côrte-Real 5b57b73fe8 Remove dead code causing warnings (#278) 2017-09-04 08:45:56 +02:00
tomaka 3d1c18ded9 Events loop backend (#269)
* Don't use UNIX_BACKEND in Window2::new

* Move get_available_monitors and get_primary_monitor to EventsLoop

* Remove UNIX_BACKEND

* Restore choosing the Linux backend

* Return a XNotSupported for new_x11()

* Fix fullscreen example
2017-09-01 11:04:57 +02:00
tomaka e65cacbc86 Use a sync::Barrier on win32 to sync threads instead of a channel (#271) 2017-08-31 19:45:17 +02:00