Squashed commit of the following: (#853)
commit fa95f204d3c10ceca70e794870657a0f33349761
Author: Hal Gentz <zegentzy@protonmail.com>
Date: Sun Apr 28 00:14:01 2019 -0600
xrender
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
commit b62cee51c7b22f6f150bfe04f9b28f024e641323
Merge: 3f021ea7 a6551f46
Author: Hal Gentz <zegentzy@protonmail.com>
Date: Thu Apr 25 18:13:43 2019 -0600
Merge branch 'macos-gentz' of github.com:ZeGentzy/winit into macos-gentz
commit 3f021ea7f7ac6bc2a697a5b6e4e6424e838a2139
Author: Hal Gentz <zegentzy@protonmail.com>
Date: Thu Apr 25 18:04:02 2019 -0600
Get rid of warnings.
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
commit a6551f4607ea0bc26df8716dee8115371ef367db
Author: Hal Gentz <zegentzy@protonmail.com>
Date: Thu Apr 25 07:40:56 2019 -0600
Fix example
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
commit cbfda6c57e9740b49d2b496bda43197f611cb48c
Author: Hal Gentz <zegentzy@protonmail.com>
Date: Wed Apr 24 23:47:46 2019 -0600
Fixes
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
commit 86bc86f3d3add4a6125aa9b2eca79061c0dfcd91
Author: Hal Gentz <zegentzy@protonmail.com>
Date: Wed Apr 24 23:39:19 2019 -0600
Backport 9a23ec3c37 (diff-1d95fe39cdbaa708c975380a16c314cb)
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
commit 742a688efe2f0eeacc2ffbf49b1157c4aaffccbd
Author: Hal Gentz <zegentzy@protonmail.com>
Date: Wed Apr 24 23:09:14 2019 -0600
Backports 45a4281413 (diff-1d95fe39cdbaa708c975380a16c314cb)
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
commit 6c81f2a517d4e2d5ba2ff3eddca030bce972cb2a
Author: Hal Gentz <zegentzy@protonmail.com>
Date: Wed Apr 24 23:05:57 2019 -0600
Francesca's macos changes
Also backports bfbcab3a01 (diff-1d95fe39cdbaa708c975380a16c314cb)
commit 7c2e1300c26a0634ad505ce72b90eb6dc2fdcac7
Author: Francesca Plebani <franplebani@gmail.com>
Date: Wed Apr 24 20:58:26 2019 -0600
Squashed commit of the following:
commit 5f4aa9f01a719eef98c6d894801c20ee8f96d30f
Author: Francesca Plebani <franplebani@gmail.com>
Date: Fri Dec 21 17:14:14 2018 -0500
Protect against reentrancy (messily)
commit b75073a5b2a8d65ab8806a00ffee390752255c8c
Author: Francesca Plebani <franplebani@gmail.com>
Date: Fri Dec 21 15:15:27 2018 -0500
Send resize events immediately
commit 8e9fc01bd6b404f59488b130413f48e4e5f89b0d
Author: Francesca Plebani <franplebani@gmail.com>
Date: Fri Dec 21 16:07:43 2018 -0500
Don't use struct for window delegate
commit c6853b0c4a8fe357f463604bb879dc1be424860e
Author: Francesca Plebani <franplebani@gmail.com>
Date: Wed Dec 19 21:17:48 2018 -0500
Split up util
commit 262c46b148413130fa239099f1151c1f1bd5c13c
Author: Francesca Plebani <franplebani@gmail.com>
Date: Wed Dec 19 20:55:00 2018 -0500
Use dispatch crate
commit 63152c2f475794d1a36a5b3687c777664d7d5613
Author: Francesca Plebani <franplebani@gmail.com>
Date: Wed Dec 19 20:29:13 2018 -0500
RedrawRequested
commit 27e475c7c78b059fd9b5e8350cd26756eecdfc94
Author: Francesca Plebani <franplebani@gmail.com>
Date: Wed Dec 19 19:24:44 2018 -0500
User events
commit 157418d7dedace9c571e977d98ea92464c3188b2
Author: Francesca Plebani <franplebani@gmail.com>
Date: Tue Dec 18 22:38:05 2018 -0500
Moved out cursor loading
commit b4925641c973979a38743202b4269efe09ac43b4
Author: Francesca Plebani <franplebani@gmail.com>
Date: Tue Dec 18 21:32:12 2018 -0500
Fixed a bunch of threading issues
commit 4aef63dfb78dfaf38c83cb0e88d4ea9d8d0578a6
Author: Francesca Plebani <franplebani@gmail.com>
Date: Mon Dec 17 13:54:59 2018 -0500
Wait works
commit 72ed426c695df5dc410902263bd74188059b8ddd
Author: Francesca Plebani <franplebani@gmail.com>
Date: Fri Dec 14 20:49:10 2018 -0500
Fixed drag and dropg
commit 658209f4a20acd536218f41a01fb8cbbebc705e0
Author: Francesca Plebani <franplebani@gmail.com>
Date: Fri Dec 14 20:42:42 2018 -0500
Made mutexes finer for less deadlock risk
commit 8e6b9866084690da900c4d058e412cab8ebb30c4
Author: Francesca Plebani <franplebani@gmail.com>
Date: Fri Dec 14 16:45:06 2018 -0500
Dump (encapsulate) everything into AppState
commit d2dc83df15939d89301e2cff0ffa2d98c48b406f
Author: Francesca Plebani <franplebani@gmail.com>
Date: Thu Dec 13 17:36:47 2018 -0500
All window events work!
commit 7c7fcc98872b3c35bd7767b5c6235a74bc105e06
Author: Francesca Plebani <franplebani@gmail.com>
Date: Wed Dec 12 17:11:09 2018 -0500
Very rough usage of CFRunLoop
commit 3c7a52ff4df683b5b7e1751e4051ec445a818774
Author: Francesca Plebani <franplebani@gmail.com>
Date: Tue Dec 11 15:45:23 2018 -0500
Fixed deadlocks
commit b74c7fe1bcd173e9b0c0e004956c257e805bc2a2
Author: Francesca Plebani <franplebani@gmail.com>
Date: Mon Dec 10 18:59:46 2018 -0500
Fix keyDown deadlock
commit 3798f9c1a4bef2a3d1552f846b26efc31b1bbb6c
Author: Francesca Plebani <franplebani@gmail.com>
Date: Mon Dec 10 18:44:40 2018 -0500
It builds!
commit 8c8620214357714c5cd0b3beefda6704512e3f64
Author: Francesca Plebani <franplebani@gmail.com>
Date: Fri Dec 7 21:09:55 2018 -0500
Horribly broken so far
commit 8269ed2a9270e5ec5b14f80fd21d1e0e6f51be29
Author: Osspial <osspial@gmail.com>
Date: Mon Nov 19 23:51:20 2018 -0500
Fix crash with runner refcell not getting dropped
commit 54ce6a21a0722e408ae49c74f5008005fc1e4cbf
Author: Osspial <osspial@gmail.com>
Date: Sun Nov 18 19:12:45 2018 -0500
Fix buffered events not getting dispatched
commit 2c18b804df66f49f93cfe722a679d6c5e01d8cb1
Author: Osspial <osspial@gmail.com>
Date: Sun Nov 18 18:51:24 2018 -0500
Fix thread executor not executing closure when called from non-loop thread
commit 5a3a5e2293cec3e566c4aac344ae7eaa343608b5
Author: Osspial <osspial@gmail.com>
Date: Thu Nov 15 22:43:59 2018 -0500
Fix some deadlocks that could occur when changing window state
commit 2a3cefd8c5df1c06127b05651cbdf5e3d9e3a6d3
Author: Osspial <osspial@gmail.com>
Date: Thu Nov 15 16:45:17 2018 -0500
Document and implement Debug for EventLoopWindowTarget
commit fa46825a289ca0587dc97f9c00dea5516fb4925a
Author: Osspial <osspial@gmail.com>
Date: Thu Nov 15 16:40:48 2018 -0500
Replace &EventLoop in callback with &EventLoopWindowTarget
commit 9f36a7a68e1dc379cf9091213dae2c3586d3e473
Author: Osspial <osspial@gmail.com>
Date: Wed Nov 14 21:28:38 2018 -0500
Fix freeze when setting decorations
commit d9c3daca9b459e02ef614568fe803a723965fe8d
Author: Osspial <osspial@gmail.com>
Date: Fri Nov 9 20:41:15 2018 -0500
Fix 1.24.1 build
commit 5289d22372046bac403a279c3641737c0cfc46d2
Author: Osspial <osspial@gmail.com>
Date: Fri Nov 9 00:00:27 2018 -0500
Remove serde implementations from ControlFlow
commit 92ac3d6ac7915923c22c380cc3a74c5f3830708e
Author: Osspial <osspial@gmail.com>
Date: Thu Nov 8 23:46:41 2018 -0500
Remove crossbeam dependency and make drop events work again
commit 8299eb2f03773a34079c61fc8adb51405aafc467
Author: Osspial <osspial@gmail.com>
Date: Thu Sep 13 22:39:40 2018 -0400
Fix crash when running in release mode
commit bb6ab1bb6e9595e90f1915fdde7e23904f2ba594
Author: Osspial <osspial@gmail.com>
Date: Sun Sep 9 14:28:16 2018 -0400
Fix unreachable panic after setting ControlFlow to Poll during some RedrawRequested events.
commit 5068ff4ee152bfe93c9190235f02d001202feb88
Author: Osspial <osspial@gmail.com>
Date: Sun Sep 9 14:14:28 2018 -0400
Improve clarity/fix typos in docs
commit 8ed575ff4a4f0961bb2e784bda1ae109c6bd37b7
Author: Osspial <osspial@gmail.com>
Date: Sun Sep 9 00:19:53 2018 -0400
Update send test and errors that broke some examples/APIs
commit bf7bfa82ebb5d6ae110ce0492c124ef462945f85
Author: Osspial <osspial@gmail.com>
Date: Wed Sep 5 22:36:05 2018 -0400
Fix resize lag when waiting in some situations
commit 70722cc4c322e3e599b3a03bce5058a5d433970b
Author: Osspial <osspial@gmail.com>
Date: Wed Sep 5 19:58:52 2018 -1100
When SendEvent is called during event closure, buffer events
commit 53370924b25da15ddd172173150b228065324864
Author: Osspial <osspial@gmail.com>
Date: Sun Aug 26 21:55:51 2018 -0400
Improve WaitUntil timer precision
commit a654400e730400c2e3584be2f47153043b5b7efe
Author: Osspial <osspial@gmail.com>
Date: Thu Aug 23 21:06:19 2018 -0400
Add CHANGELOG entry
commit deb7d379b7c04e61d6d50ff655eccac0ad692e44
Author: Osspial <osspial@gmail.com>
Date: Thu Aug 23 20:19:56 2018 -0400
Rename MonitorId to MonitorHandle
commit 8d8d9b7cd1386c99c40023d86e17d10c3fd6652f
Author: Osspial <osspial@gmail.com>
Date: Thu Aug 23 20:16:52 2018 -0400
Change instances of "events_loop" to "event_loop"
commit 0f344087630ae252c9c8f453864e684a1a5405b1
Author: Osspial <osspial@gmail.com>
Date: Thu Aug 23 20:13:53 2018 -0400
Improve docs for run and run_return
commit fba41f7a7ed8585cbb658b6d0b2f34f75482cb3d
Author: Osspial <osspial@gmail.com>
Date: Thu Aug 23 19:09:53 2018 -0400
Small changes to examples
commit 42e8a0d2cf77af79da082fff7cd29cc8f52d99df
Author: Osspial <osspial@gmail.com>
Date: Thu Aug 23 19:09:19 2018 -0400
Improve documentation
commit 4377680a44ea86dad52954f90bc7d8ad7ed0b4bf
Author: Osspial <osspial@gmail.com>
Date: Wed Aug 22 23:01:36 2018 -0400
Re-organize into module structure
commit f20fac99f6ac57c51603a92d792fd4f665feb7f6
Author: Osspial <osspial@gmail.com>
Date: Wed Aug 22 22:07:39 2018 -0400
Add platform::desktop module with EventLoopExt::run_return
commit dad24d086aaaff60e557efc4f41d1ae7e3c71738
Author: Osspial <osspial@gmail.com>
Date: Wed Aug 22 18:03:41 2018 -0400
Rename os to platform, add Ext trait postfixes
commit 7df59c60a06008226f6455619e7242ed0156ed8d
Author: Osspial <osspial@gmail.com>
Date: Wed Aug 22 17:59:36 2018 -0400
Rename platform to platform_impl
commit 99c0f84a9fc771c9c96099232de3716ddf27ca80
Author: Osspial <osspial@gmail.com>
Date: Wed Aug 22 17:55:27 2018 -0400
Add request_redraw
commit a0fef1a5fad9b5d5da59fff191c7d9c398ea9e01
Author: Osspial <osspial@gmail.com>
Date: Mon Aug 20 01:47:11 2018 -0400
Fully invert windows control flow so win32 calls into winit's callback
commit 2c607ff87f8fbcad8aa9dc3783b3298c014dd177
Author: Osspial <osspial@gmail.com>
Date: Sun Aug 19 13:44:22 2018 -0400
Add ability to send custom user events
commit a0b2bb36953f018ff782cef8fc86c6db9343095d
Author: Osspial <osspial@gmail.com>
Date: Fri Aug 17 17:49:46 2018 -0400
Add StartCause::Init support, timer example
commit 02f922f003f56215b92b8feeb9148ad2dd181fc2
Author: Osspial <osspial@gmail.com>
Date: Fri Aug 17 17:31:04 2018 -0400
Implement new ControlFlow and associated events
commit 8b8a7675ec67e15a0f8f69db0bdeb79bee0ac20d
Author: Osspial <osspial@gmail.com>
Date: Fri Jul 13 01:48:26 2018 -0400
Replace windows Mutex with parking_lot Mutex
commit 9feada206f6b9fb1e9da118be6b77dfc217ace8d
Author: Osspial <osspial@gmail.com>
Date: Fri Jul 13 01:39:53 2018 -0400
Update run_forever to hijack thread
commit 2e83bac99cc264cd2723cb182feea84a0a15e08d
Author: Osspial <osspial@gmail.com>
Date: Thu Jul 12 23:43:58 2018 -0400
Remove second thread from win32 backend
commit 64b8a9c6a50362d10c074077a1e37b057f3e3c81
Author: Osspial <osspial@gmail.com>
Date: Thu Jul 12 22:13:07 2018 -0400
Rename WindowEvent::Refresh to WindowEvent::Redraw
commit 529c08555fd0b709a23d486211d28fbd0980fc94
Author: Osspial <osspial@gmail.com>
Date: Thu Jul 12 22:04:38 2018 -0400
Rename EventsLoop and associated types to EventLoop
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
Co-authored-by: Hal Gentz <zegentzy@protonmail.com>
commit cfb929ba0a9e787f8bb1a6dae4e05e4c7776bc97
Author: Hal Gentz <zegentzy@protonmail.com>
Date: Thu Apr 25 07:40:56 2019 -0600
Fix example
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
commit 68d3317ff58381d55f5f9bd3db0860d66544fe12
Author: Hal Gentz <zegentzy@protonmail.com>
Date: Wed Apr 24 23:47:46 2019 -0600
Fixes
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
commit 02d1aae4db27df054b703aa935ca118f31e17123
Author: Hal Gentz <zegentzy@protonmail.com>
Date: Wed Apr 24 23:39:19 2019 -0600
Backport 9a23ec3c37 (diff-1d95fe39cdbaa708c975380a16c314cb)
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
commit dd9de5a6d444a9ab17afe470f4cf2a57e3ed76ae
Author: Hal Gentz <zegentzy@protonmail.com>
Date: Wed Apr 24 23:09:14 2019 -0600
Backports 45a4281413 (diff-1d95fe39cdbaa708c975380a16c314cb)
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
commit 533e2adc1d1e417742475786635848b1620e476c
Author: Hal Gentz <zegentzy@protonmail.com>
Date: Wed Apr 24 23:05:57 2019 -0600
Francesca's macos changes
Also backports bfbcab3a01 (diff-1d95fe39cdbaa708c975380a16c314cb)
commit 73b52221080bd3a881ae3a58c2dbb19bc8d954c6
Author: Hal Gentz <zegentzy@protonmail.com>
Date: Wed Apr 24 20:58:26 2019 -0600
Squashed commit of the following:
commit 5f4aa9f01a719eef98c6d894801c20ee8f96d30f
Author: Francesca Plebani <franplebani@gmail.com>
Date: Fri Dec 21 17:14:14 2018 -0500
Protect against reentrancy (messily)
commit b75073a5b2a8d65ab8806a00ffee390752255c8c
Author: Francesca Plebani <franplebani@gmail.com>
Date: Fri Dec 21 15:15:27 2018 -0500
Send resize events immediately
commit 8e9fc01bd6b404f59488b130413f48e4e5f89b0d
Author: Francesca Plebani <franplebani@gmail.com>
Date: Fri Dec 21 16:07:43 2018 -0500
Don't use struct for window delegate
commit c6853b0c4a8fe357f463604bb879dc1be424860e
Author: Francesca Plebani <franplebani@gmail.com>
Date: Wed Dec 19 21:17:48 2018 -0500
Split up util
commit 262c46b148413130fa239099f1151c1f1bd5c13c
Author: Francesca Plebani <franplebani@gmail.com>
Date: Wed Dec 19 20:55:00 2018 -0500
Use dispatch crate
commit 63152c2f475794d1a36a5b3687c777664d7d5613
Author: Francesca Plebani <franplebani@gmail.com>
Date: Wed Dec 19 20:29:13 2018 -0500
RedrawRequested
commit 27e475c7c78b059fd9b5e8350cd26756eecdfc94
Author: Francesca Plebani <franplebani@gmail.com>
Date: Wed Dec 19 19:24:44 2018 -0500
User events
commit 157418d7dedace9c571e977d98ea92464c3188b2
Author: Francesca Plebani <franplebani@gmail.com>
Date: Tue Dec 18 22:38:05 2018 -0500
Moved out cursor loading
commit b4925641c973979a38743202b4269efe09ac43b4
Author: Francesca Plebani <franplebani@gmail.com>
Date: Tue Dec 18 21:32:12 2018 -0500
Fixed a bunch of threading issues
commit 4aef63dfb78dfaf38c83cb0e88d4ea9d8d0578a6
Author: Francesca Plebani <franplebani@gmail.com>
Date: Mon Dec 17 13:54:59 2018 -0500
Wait works
commit 72ed426c695df5dc410902263bd74188059b8ddd
Author: Francesca Plebani <franplebani@gmail.com>
Date: Fri Dec 14 20:49:10 2018 -0500
Fixed drag and dropg
commit 658209f4a20acd536218f41a01fb8cbbebc705e0
Author: Francesca Plebani <franplebani@gmail.com>
Date: Fri Dec 14 20:42:42 2018 -0500
Made mutexes finer for less deadlock risk
commit 8e6b9866084690da900c4d058e412cab8ebb30c4
Author: Francesca Plebani <franplebani@gmail.com>
Date: Fri Dec 14 16:45:06 2018 -0500
Dump (encapsulate) everything into AppState
commit d2dc83df15939d89301e2cff0ffa2d98c48b406f
Author: Francesca Plebani <franplebani@gmail.com>
Date: Thu Dec 13 17:36:47 2018 -0500
All window events work!
commit 7c7fcc98872b3c35bd7767b5c6235a74bc105e06
Author: Francesca Plebani <franplebani@gmail.com>
Date: Wed Dec 12 17:11:09 2018 -0500
Very rough usage of CFRunLoop
commit 3c7a52ff4df683b5b7e1751e4051ec445a818774
Author: Francesca Plebani <franplebani@gmail.com>
Date: Tue Dec 11 15:45:23 2018 -0500
Fixed deadlocks
commit b74c7fe1bcd173e9b0c0e004956c257e805bc2a2
Author: Francesca Plebani <franplebani@gmail.com>
Date: Mon Dec 10 18:59:46 2018 -0500
Fix keyDown deadlock
commit 3798f9c1a4bef2a3d1552f846b26efc31b1bbb6c
Author: Francesca Plebani <franplebani@gmail.com>
Date: Mon Dec 10 18:44:40 2018 -0500
It builds!
commit 8c8620214357714c5cd0b3beefda6704512e3f64
Author: Francesca Plebani <franplebani@gmail.com>
Date: Fri Dec 7 21:09:55 2018 -0500
Horribly broken so far
commit 8269ed2a9270e5ec5b14f80fd21d1e0e6f51be29
Author: Osspial <osspial@gmail.com>
Date: Mon Nov 19 23:51:20 2018 -0500
Fix crash with runner refcell not getting dropped
commit 54ce6a21a0722e408ae49c74f5008005fc1e4cbf
Author: Osspial <osspial@gmail.com>
Date: Sun Nov 18 19:12:45 2018 -0500
Fix buffered events not getting dispatched
commit 2c18b804df66f49f93cfe722a679d6c5e01d8cb1
Author: Osspial <osspial@gmail.com>
Date: Sun Nov 18 18:51:24 2018 -0500
Fix thread executor not executing closure when called from non-loop thread
commit 5a3a5e2293cec3e566c4aac344ae7eaa343608b5
Author: Osspial <osspial@gmail.com>
Date: Thu Nov 15 22:43:59 2018 -0500
Fix some deadlocks that could occur when changing window state
commit 2a3cefd8c5df1c06127b05651cbdf5e3d9e3a6d3
Author: Osspial <osspial@gmail.com>
Date: Thu Nov 15 16:45:17 2018 -0500
Document and implement Debug for EventLoopWindowTarget
commit fa46825a289ca0587dc97f9c00dea5516fb4925a
Author: Osspial <osspial@gmail.com>
Date: Thu Nov 15 16:40:48 2018 -0500
Replace &EventLoop in callback with &EventLoopWindowTarget
commit 9f36a7a68e1dc379cf9091213dae2c3586d3e473
Author: Osspial <osspial@gmail.com>
Date: Wed Nov 14 21:28:38 2018 -0500
Fix freeze when setting decorations
commit d9c3daca9b459e02ef614568fe803a723965fe8d
Author: Osspial <osspial@gmail.com>
Date: Fri Nov 9 20:41:15 2018 -0500
Fix 1.24.1 build
commit 5289d22372046bac403a279c3641737c0cfc46d2
Author: Osspial <osspial@gmail.com>
Date: Fri Nov 9 00:00:27 2018 -0500
Remove serde implementations from ControlFlow
commit 92ac3d6ac7915923c22c380cc3a74c5f3830708e
Author: Osspial <osspial@gmail.com>
Date: Thu Nov 8 23:46:41 2018 -0500
Remove crossbeam dependency and make drop events work again
commit 8299eb2f03773a34079c61fc8adb51405aafc467
Author: Osspial <osspial@gmail.com>
Date: Thu Sep 13 22:39:40 2018 -0400
Fix crash when running in release mode
commit bb6ab1bb6e9595e90f1915fdde7e23904f2ba594
Author: Osspial <osspial@gmail.com>
Date: Sun Sep 9 14:28:16 2018 -0400
Fix unreachable panic after setting ControlFlow to Poll during some RedrawRequested events.
commit 5068ff4ee152bfe93c9190235f02d001202feb88
Author: Osspial <osspial@gmail.com>
Date: Sun Sep 9 14:14:28 2018 -0400
Improve clarity/fix typos in docs
commit 8ed575ff4a4f0961bb2e784bda1ae109c6bd37b7
Author: Osspial <osspial@gmail.com>
Date: Sun Sep 9 00:19:53 2018 -0400
Update send test and errors that broke some examples/APIs
commit bf7bfa82ebb5d6ae110ce0492c124ef462945f85
Author: Osspial <osspial@gmail.com>
Date: Wed Sep 5 22:36:05 2018 -0400
Fix resize lag when waiting in some situations
commit 70722cc4c322e3e599b3a03bce5058a5d433970b
Author: Osspial <osspial@gmail.com>
Date: Wed Sep 5 19:58:52 2018 -1100
When SendEvent is called during event closure, buffer events
commit 53370924b25da15ddd172173150b228065324864
Author: Osspial <osspial@gmail.com>
Date: Sun Aug 26 21:55:51 2018 -0400
Improve WaitUntil timer precision
commit a654400e730400c2e3584be2f47153043b5b7efe
Author: Osspial <osspial@gmail.com>
Date: Thu Aug 23 21:06:19 2018 -0400
Add CHANGELOG entry
commit deb7d379b7c04e61d6d50ff655eccac0ad692e44
Author: Osspial <osspial@gmail.com>
Date: Thu Aug 23 20:19:56 2018 -0400
Rename MonitorId to MonitorHandle
commit 8d8d9b7cd1386c99c40023d86e17d10c3fd6652f
Author: Osspial <osspial@gmail.com>
Date: Thu Aug 23 20:16:52 2018 -0400
Change instances of "events_loop" to "event_loop"
commit 0f344087630ae252c9c8f453864e684a1a5405b1
Author: Osspial <osspial@gmail.com>
Date: Thu Aug 23 20:13:53 2018 -0400
Improve docs for run and run_return
commit fba41f7a7ed8585cbb658b6d0b2f34f75482cb3d
Author: Osspial <osspial@gmail.com>
Date: Thu Aug 23 19:09:53 2018 -0400
Small changes to examples
commit 42e8a0d2cf77af79da082fff7cd29cc8f52d99df
Author: Osspial <osspial@gmail.com>
Date: Thu Aug 23 19:09:19 2018 -0400
Improve documentation
commit 4377680a44ea86dad52954f90bc7d8ad7ed0b4bf
Author: Osspial <osspial@gmail.com>
Date: Wed Aug 22 23:01:36 2018 -0400
Re-organize into module structure
commit f20fac99f6ac57c51603a92d792fd4f665feb7f6
Author: Osspial <osspial@gmail.com>
Date: Wed Aug 22 22:07:39 2018 -0400
Add platform::desktop module with EventLoopExt::run_return
commit dad24d086aaaff60e557efc4f41d1ae7e3c71738
Author: Osspial <osspial@gmail.com>
Date: Wed Aug 22 18:03:41 2018 -0400
Rename os to platform, add Ext trait postfixes
commit 7df59c60a06008226f6455619e7242ed0156ed8d
Author: Osspial <osspial@gmail.com>
Date: Wed Aug 22 17:59:36 2018 -0400
Rename platform to platform_impl
commit 99c0f84a9fc771c9c96099232de3716ddf27ca80
Author: Osspial <osspial@gmail.com>
Date: Wed Aug 22 17:55:27 2018 -0400
Add request_redraw
commit a0fef1a5fad9b5d5da59fff191c7d9c398ea9e01
Author: Osspial <osspial@gmail.com>
Date: Mon Aug 20 01:47:11 2018 -0400
Fully invert windows control flow so win32 calls into winit's callback
commit 2c607ff87f8fbcad8aa9dc3783b3298c014dd177
Author: Osspial <osspial@gmail.com>
Date: Sun Aug 19 13:44:22 2018 -0400
Add ability to send custom user events
commit a0b2bb36953f018ff782cef8fc86c6db9343095d
Author: Osspial <osspial@gmail.com>
Date: Fri Aug 17 17:49:46 2018 -0400
Add StartCause::Init support, timer example
commit 02f922f003f56215b92b8feeb9148ad2dd181fc2
Author: Osspial <osspial@gmail.com>
Date: Fri Aug 17 17:31:04 2018 -0400
Implement new ControlFlow and associated events
commit 8b8a7675ec67e15a0f8f69db0bdeb79bee0ac20d
Author: Osspial <osspial@gmail.com>
Date: Fri Jul 13 01:48:26 2018 -0400
Replace windows Mutex with parking_lot Mutex
commit 9feada206f6b9fb1e9da118be6b77dfc217ace8d
Author: Osspial <osspial@gmail.com>
Date: Fri Jul 13 01:39:53 2018 -0400
Update run_forever to hijack thread
commit 2e83bac99cc264cd2723cb182feea84a0a15e08d
Author: Osspial <osspial@gmail.com>
Date: Thu Jul 12 23:43:58 2018 -0400
Remove second thread from win32 backend
commit 64b8a9c6a50362d10c074077a1e37b057f3e3c81
Author: Osspial <osspial@gmail.com>
Date: Thu Jul 12 22:13:07 2018 -0400
Rename WindowEvent::Refresh to WindowEvent::Redraw
commit 529c08555fd0b709a23d486211d28fbd0980fc94
Author: Osspial <osspial@gmail.com>
Date: Thu Jul 12 22:04:38 2018 -0400
Rename EventsLoop and associated types to EventLoop
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
commit ab1dfaaaa53a3acd206bf494ac90e3fe130dc609
Author: Hal Gentz <zegentzy@protonmail.com>
Date: Tue Apr 23 21:52:17 2019 -0600
Minor
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
commit 7933209d603e0794adb806d9cf53507f1c2f1d3c
Author: Victor Berger <victor.berger@m4x.org>
Date: Thu Apr 18 09:10:41 2019 +0200
wayland/x11: Make ControlFlow::Exit sticky
commit 8355a7513e299ffba21062c8518bcf4bdb735ba9
Author: Victor Berger <victor.berger@m4x.org>
Date: Tue Apr 16 12:21:33 2019 +0200
x11: Implement run_return using calloop
commit f64edb60cc85fcd98a1cec955ba9980f617fdd73
Author: Victor Berger <victor.berger@m4x.org>
Date: Tue Apr 16 10:42:04 2019 +0200
x11: port to evl2 with stubs
commit be372898ddc60e47887c9a152c10ff498445f8cf
Author: Victor Berger <victor.berger@m4x.org>
Date: Mon Apr 15 17:35:59 2019 +0200
Fix compilation on Linux.
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
Co-authored-by: Francesca Plebani <franplebani@gmail.com>
This commit is contained in:
parent
94f998af0a
commit
d5391686ae
28 changed files with 3303 additions and 2147 deletions
|
|
@ -1,812 +1,144 @@
|
|||
use {ControlFlow, EventLoopClosed};
|
||||
use cocoa::{self, appkit, foundation};
|
||||
use cocoa::appkit::{NSApplication, NSEvent, NSEventMask, NSEventModifierFlags, NSEventPhase, NSView, NSWindow};
|
||||
use events::{self, ElementState, Event, TouchPhase, WindowEvent, DeviceEvent, ModifiersState, KeyboardInput};
|
||||
use std::collections::VecDeque;
|
||||
use std::sync::{Arc, Mutex, Weak};
|
||||
use super::window::Window2;
|
||||
use std;
|
||||
use std::os::raw::*;
|
||||
use super::DeviceId;
|
||||
use std::{
|
||||
collections::VecDeque, mem, os::raw::c_void, process, ptr, sync::mpsc, marker::PhantomData
|
||||
};
|
||||
|
||||
pub struct EventLoop {
|
||||
modifiers: Modifiers,
|
||||
pub shared: Arc<Shared>,
|
||||
use cocoa::{appkit::NSApp, base::{id, nil}, foundation::NSAutoreleasePool};
|
||||
|
||||
use {
|
||||
event::Event,
|
||||
event_loop::{ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootWindowTarget},
|
||||
};
|
||||
use platform_impl::platform::{
|
||||
app::APP_CLASS, app_delegate::APP_DELEGATE_CLASS,
|
||||
app_state::AppState, monitor::{self, MonitorHandle},
|
||||
observer::*, util::IdRef,
|
||||
};
|
||||
|
||||
pub struct EventLoopWindowTarget<T: 'static> {
|
||||
pub sender: mpsc::Sender<T>, // this is only here to be cloned elsewhere
|
||||
pub receiver: mpsc::Receiver<T>,
|
||||
}
|
||||
|
||||
// State shared between the `EventLoop` and its registered windows.
|
||||
pub struct Shared {
|
||||
pub windows: Mutex<Vec<Weak<Window2>>>,
|
||||
pub pending_events: Mutex<VecDeque<Event>>,
|
||||
// The user event callback given via either of the `poll_events` or `run_forever` methods.
|
||||
//
|
||||
// We store the user's callback here so that it may be accessed by each of the window delegate
|
||||
// callbacks (e.g. resize, close, etc) for the duration of a call to either of the
|
||||
// `poll_events` or `run_forever` methods.
|
||||
//
|
||||
// This is *only* `Some` for the duration of a call to either of these methods and will be
|
||||
// `None` otherwise.
|
||||
user_callback: UserCallback,
|
||||
impl<T> Default for EventLoopWindowTarget<T> {
|
||||
fn default() -> Self {
|
||||
let (sender, receiver) = mpsc::channel();
|
||||
EventLoopWindowTarget { sender, receiver }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EventLoop<T: 'static> {
|
||||
window_target: RootWindowTarget<T>,
|
||||
_delegate: IdRef,
|
||||
}
|
||||
|
||||
impl<T> EventLoop<T> {
|
||||
pub fn new() -> Self {
|
||||
let delegate = unsafe {
|
||||
if !msg_send![class!(NSThread), isMainThread] {
|
||||
panic!("On macOS, `EventLoop` must be created on the main thread!");
|
||||
}
|
||||
|
||||
// This must be done before `NSApp()` (equivalent to sending
|
||||
// `sharedApplication`) is called anywhere else, or we'll end up
|
||||
// with the wrong `NSApplication` class and the wrong thread could
|
||||
// be marked as main.
|
||||
let app: id = msg_send![APP_CLASS.0, sharedApplication];
|
||||
|
||||
let delegate = IdRef::new(msg_send![APP_DELEGATE_CLASS.0, new]);
|
||||
let pool = NSAutoreleasePool::new(nil);
|
||||
let _: () = msg_send![app, setDelegate:*delegate];
|
||||
let _: () = msg_send![pool, drain];
|
||||
delegate
|
||||
};
|
||||
setup_control_flow_observers();
|
||||
EventLoop {
|
||||
window_target: RootWindowTarget {
|
||||
p: Default::default(),
|
||||
_marker: PhantomData,
|
||||
},
|
||||
_delegate: delegate,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_available_monitors(&self) -> VecDeque<MonitorHandle> {
|
||||
monitor::get_available_monitors()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_primary_monitor(&self) -> MonitorHandle {
|
||||
monitor::get_primary_monitor()
|
||||
}
|
||||
|
||||
pub fn window_target(&self) -> &RootWindowTarget<T> {
|
||||
&self.window_target
|
||||
}
|
||||
|
||||
pub fn run<F>(self, callback: F) -> !
|
||||
where F: 'static + FnMut(Event<T>, &RootWindowTarget<T>, &mut ControlFlow),
|
||||
{
|
||||
unsafe {
|
||||
let _pool = NSAutoreleasePool::new(nil);
|
||||
let app = NSApp();
|
||||
assert_ne!(app, nil);
|
||||
AppState::set_callback(callback, self.window_target);
|
||||
let _: () = msg_send![app, run];
|
||||
AppState::exit();
|
||||
process::exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_return<F>(&mut self, _callback: F)
|
||||
where F: FnMut(Event<T>, &RootWindowTarget<T>, &mut ControlFlow),
|
||||
{
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
pub fn create_proxy(&self) -> Proxy<T> {
|
||||
Proxy::new(self.window_target.p.sender.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Proxy {}
|
||||
|
||||
struct Modifiers {
|
||||
shift_pressed: bool,
|
||||
ctrl_pressed: bool,
|
||||
win_pressed: bool,
|
||||
alt_pressed: bool,
|
||||
pub struct Proxy<T> {
|
||||
sender: mpsc::Sender<T>,
|
||||
source: CFRunLoopSourceRef,
|
||||
}
|
||||
|
||||
// Wrapping the user callback in a type allows us to:
|
||||
//
|
||||
// - ensure the callback pointer is never accidentally cloned
|
||||
// - ensure that only the `EventLoop` can `store` and `drop` the callback pointer
|
||||
// - Share access to the user callback with the NSWindow callbacks.
|
||||
pub struct UserCallback {
|
||||
mutex: Mutex<Option<*mut FnMut(Event)>>,
|
||||
}
|
||||
unsafe impl<T> Send for Proxy<T> {}
|
||||
unsafe impl<T> Sync for Proxy<T> {}
|
||||
|
||||
|
||||
impl Shared {
|
||||
|
||||
pub fn new() -> Self {
|
||||
Shared {
|
||||
windows: Mutex::new(Vec::new()),
|
||||
pending_events: Mutex::new(VecDeque::new()),
|
||||
user_callback: UserCallback { mutex: Mutex::new(None) },
|
||||
}
|
||||
}
|
||||
|
||||
fn call_user_callback_with_pending_events(&self) {
|
||||
loop {
|
||||
let event = match self.pending_events.lock().unwrap().pop_front() {
|
||||
Some(event) => event,
|
||||
None => return,
|
||||
};
|
||||
unsafe {
|
||||
self.user_callback.call_with_event(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calls the user callback if one exists.
|
||||
//
|
||||
// Otherwise, stores the event in the `pending_events` queue.
|
||||
//
|
||||
// This is necessary for the case when `WindowDelegate` callbacks are triggered during a call
|
||||
// to the user's callback.
|
||||
pub fn call_user_callback_with_event_or_store_in_pending(&self, event: Event) {
|
||||
if self.user_callback.mutex.lock().unwrap().is_some() {
|
||||
unsafe {
|
||||
self.user_callback.call_with_event(event);
|
||||
}
|
||||
} else {
|
||||
self.pending_events.lock().unwrap().push_back(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Removes the window with the given `Id` from the `windows` list.
|
||||
//
|
||||
// This is called in response to `windowWillClose`.
|
||||
pub fn find_and_remove_window(&self, id: super::window::Id) {
|
||||
if let Ok(mut windows) = self.windows.lock() {
|
||||
windows.retain(|w| match w.upgrade() {
|
||||
Some(w) => w.id() != id,
|
||||
None => false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
impl Modifiers {
|
||||
pub fn new() -> Self {
|
||||
Modifiers {
|
||||
shift_pressed: false,
|
||||
ctrl_pressed: false,
|
||||
win_pressed: false,
|
||||
alt_pressed: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl UserCallback {
|
||||
|
||||
// Here we store user's `callback` behind the mutex so that they may be safely shared between
|
||||
// each of the window delegates.
|
||||
//
|
||||
// In order to make sure that the pointer is always valid, we must manually guarantee that it
|
||||
// is dropped before the callback itself is dropped. Thus, this should *only* be called at the
|
||||
// beginning of a call to `poll_events` and `run_forever`, both of which *must* drop the
|
||||
// callback at the end of their scope using the `drop` method.
|
||||
fn store<F>(&self, callback: &mut F)
|
||||
where F: FnMut(Event)
|
||||
{
|
||||
let trait_object = callback as &mut FnMut(Event);
|
||||
let trait_object_ptr = trait_object as *const FnMut(Event) as *mut FnMut(Event);
|
||||
*self.mutex.lock().unwrap() = Some(trait_object_ptr);
|
||||
}
|
||||
|
||||
// Emits the given event via the user-given callback.
|
||||
//
|
||||
// This is unsafe as it requires dereferencing the pointer to the user-given callback. We
|
||||
// guarantee this is safe by ensuring the `UserCallback` never lives longer than the user-given
|
||||
// callback.
|
||||
//
|
||||
// Note that the callback may not always be `Some`. This is because some `NSWindowDelegate`
|
||||
// callbacks can be triggered by means other than `NSApp().sendEvent`. For example, if a window
|
||||
// is destroyed or created during a call to the user's callback, the `WindowDelegate` methods
|
||||
// may be called with `windowShouldClose` or `windowDidResignKey`.
|
||||
unsafe fn call_with_event(&self, event: Event) {
|
||||
let callback = match self.mutex.lock().unwrap().take() {
|
||||
Some(callback) => callback,
|
||||
None => return,
|
||||
};
|
||||
(*callback)(event);
|
||||
*self.mutex.lock().unwrap() = Some(callback);
|
||||
}
|
||||
|
||||
// Used to drop the user callback pointer at the end of the `poll_events` and `run_forever`
|
||||
// methods. This is done to enforce our guarantee that the top callback will never live longer
|
||||
// than the call to either `poll_events` or `run_forever` to which it was given.
|
||||
fn drop(&self) {
|
||||
self.mutex.lock().unwrap().take();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
impl EventLoop {
|
||||
|
||||
pub fn new() -> Self {
|
||||
// Mark this thread as the main thread of the Cocoa event system.
|
||||
//
|
||||
// This must be done before any worker threads get a chance to call it
|
||||
// (e.g., via `EventLoopProxy::wakeup()`), causing a wrong thread to be
|
||||
// marked as the main thread.
|
||||
unsafe { appkit::NSApp(); }
|
||||
|
||||
EventLoop {
|
||||
shared: Arc::new(Shared::new()),
|
||||
modifiers: Modifiers::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn poll_events<F>(&mut self, mut callback: F)
|
||||
where F: FnMut(Event),
|
||||
{
|
||||
impl<T> Proxy<T> {
|
||||
fn new(sender: mpsc::Sender<T>) -> Self {
|
||||
unsafe {
|
||||
if !msg_send![class!(NSThread), isMainThread] {
|
||||
panic!("Events can only be polled from the main thread on macOS");
|
||||
}
|
||||
// just wakeup the eventloop
|
||||
extern "C" fn event_loop_proxy_handler(_: *mut c_void) {}
|
||||
|
||||
// adding a Source to the main CFRunLoop lets us wake it up and
|
||||
// process user events through the normal OS EventLoop mechanisms.
|
||||
let rl = CFRunLoopGetMain();
|
||||
let mut context: CFRunLoopSourceContext = mem::zeroed();
|
||||
context.perform = event_loop_proxy_handler;
|
||||
let source = CFRunLoopSourceCreate(
|
||||
ptr::null_mut(),
|
||||
CFIndex::max_value() - 1,
|
||||
&mut context,
|
||||
);
|
||||
CFRunLoopAddSource(rl, source, kCFRunLoopCommonModes);
|
||||
CFRunLoopWakeUp(rl);
|
||||
|
||||
Proxy { sender, source }
|
||||
}
|
||||
|
||||
self.shared.user_callback.store(&mut callback);
|
||||
|
||||
// Loop as long as we have pending events to return.
|
||||
loop {
|
||||
unsafe {
|
||||
// First, yield all pending events.
|
||||
self.shared.call_user_callback_with_pending_events();
|
||||
|
||||
let pool = foundation::NSAutoreleasePool::new(cocoa::base::nil);
|
||||
|
||||
// Poll for the next event, returning `nil` if there are none.
|
||||
let ns_event = appkit::NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_(
|
||||
NSEventMask::NSAnyEventMask.bits() | NSEventMask::NSEventMaskPressure.bits(),
|
||||
foundation::NSDate::distantPast(cocoa::base::nil),
|
||||
foundation::NSDefaultRunLoopMode,
|
||||
cocoa::base::YES);
|
||||
|
||||
let event = self.ns_event_to_event(ns_event);
|
||||
|
||||
let _: () = msg_send![pool, release];
|
||||
|
||||
match event {
|
||||
// Call the user's callback.
|
||||
Some(event) => self.shared.user_callback.call_with_event(event),
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.shared.user_callback.drop();
|
||||
}
|
||||
|
||||
pub fn run_forever<F>(&mut self, mut callback: F)
|
||||
where F: FnMut(Event) -> ControlFlow
|
||||
{
|
||||
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed> {
|
||||
self.sender.send(event).map_err(|_| EventLoopClosed)?;
|
||||
unsafe {
|
||||
if !msg_send![class!(NSThread), isMainThread] {
|
||||
panic!("Events can only be polled from the main thread on macOS");
|
||||
}
|
||||
}
|
||||
|
||||
// Track whether or not control flow has changed.
|
||||
let control_flow = std::cell::Cell::new(ControlFlow::Continue);
|
||||
|
||||
let mut callback = |event| {
|
||||
if let ControlFlow::Break = callback(event) {
|
||||
control_flow.set(ControlFlow::Break);
|
||||
}
|
||||
};
|
||||
|
||||
self.shared.user_callback.store(&mut callback);
|
||||
|
||||
loop {
|
||||
unsafe {
|
||||
// First, yield all pending events.
|
||||
self.shared.call_user_callback_with_pending_events();
|
||||
if let ControlFlow::Break = control_flow.get() {
|
||||
break;
|
||||
}
|
||||
|
||||
let pool = foundation::NSAutoreleasePool::new(cocoa::base::nil);
|
||||
|
||||
// Wait for the next event. Note that this function blocks during resize.
|
||||
let ns_event = appkit::NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_(
|
||||
NSEventMask::NSAnyEventMask.bits() | NSEventMask::NSEventMaskPressure.bits(),
|
||||
foundation::NSDate::distantFuture(cocoa::base::nil),
|
||||
foundation::NSDefaultRunLoopMode,
|
||||
cocoa::base::YES);
|
||||
|
||||
let maybe_event = self.ns_event_to_event(ns_event);
|
||||
|
||||
// Release the pool before calling the top callback in case the user calls either
|
||||
// `run_forever` or `poll_events` within the callback.
|
||||
let _: () = msg_send![pool, release];
|
||||
|
||||
if let Some(event) = maybe_event {
|
||||
self.shared.user_callback.call_with_event(event);
|
||||
if let ControlFlow::Break = control_flow.get() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.shared.user_callback.drop();
|
||||
}
|
||||
|
||||
// Convert some given `NSEvent` into a winit `Event`.
|
||||
unsafe fn ns_event_to_event(&mut self, ns_event: cocoa::base::id) -> Option<Event> {
|
||||
if ns_event == cocoa::base::nil {
|
||||
return None;
|
||||
}
|
||||
|
||||
// FIXME: Despite not being documented anywhere, an `NSEvent` is produced when a user opens
|
||||
// Spotlight while the NSApplication is in focus. This `NSEvent` produces a `NSEventType`
|
||||
// with value `21`. This causes a SEGFAULT as soon as we try to match on the `NSEventType`
|
||||
// enum as there is no variant associated with the value. Thus, we return early if this
|
||||
// sneaky event occurs. If someone does find some documentation on this, please fix this by
|
||||
// adding an appropriate variant to the `NSEventType` enum in the cocoa-rs crate.
|
||||
if ns_event.eventType() as u64 == 21 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let event_type = ns_event.eventType();
|
||||
let ns_window = ns_event.window();
|
||||
let window_id = super::window::get_window_id(ns_window);
|
||||
|
||||
// FIXME: Document this. Why do we do this? Seems like it passes on events to window/app.
|
||||
// If we don't do this, window does not become main for some reason.
|
||||
appkit::NSApp().sendEvent_(ns_event);
|
||||
|
||||
let windows = self.shared.windows.lock().unwrap();
|
||||
let maybe_window = windows.iter()
|
||||
.filter_map(Weak::upgrade)
|
||||
.find(|window| window_id == window.id());
|
||||
|
||||
let into_event = |window_event| Event::WindowEvent {
|
||||
window_id: ::WindowId(window_id),
|
||||
event: window_event,
|
||||
};
|
||||
|
||||
// Returns `Some` window if one of our windows is the key window.
|
||||
let maybe_key_window = || windows.iter()
|
||||
.filter_map(Weak::upgrade)
|
||||
.find(|window| {
|
||||
let is_key_window: cocoa::base::BOOL = msg_send![*window.window, isKeyWindow];
|
||||
is_key_window == cocoa::base::YES
|
||||
});
|
||||
|
||||
match event_type {
|
||||
// https://github.com/glfw/glfw/blob/50eccd298a2bbc272b4977bd162d3e4b55f15394/src/cocoa_window.m#L881
|
||||
appkit::NSKeyUp => {
|
||||
if let Some(key_window) = maybe_key_window() {
|
||||
if event_mods(ns_event).logo {
|
||||
let _: () = msg_send![*key_window.window, sendEvent:ns_event];
|
||||
}
|
||||
}
|
||||
None
|
||||
},
|
||||
// similar to above, but for `<Cmd-.>`, the keyDown is suppressed instead of the
|
||||
// KeyUp, and the above trick does not appear to work.
|
||||
appkit::NSKeyDown => {
|
||||
let modifiers = event_mods(ns_event);
|
||||
let keycode = NSEvent::keyCode(ns_event);
|
||||
if modifiers.logo && keycode == 47 {
|
||||
modifier_event(ns_event, NSEventModifierFlags::NSCommandKeyMask, false)
|
||||
.map(into_event)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
appkit::NSFlagsChanged => {
|
||||
let mut events = std::collections::VecDeque::new();
|
||||
|
||||
if let Some(window_event) = modifier_event(
|
||||
ns_event,
|
||||
NSEventModifierFlags::NSShiftKeyMask,
|
||||
self.modifiers.shift_pressed,
|
||||
) {
|
||||
self.modifiers.shift_pressed = !self.modifiers.shift_pressed;
|
||||
events.push_back(into_event(window_event));
|
||||
}
|
||||
|
||||
if let Some(window_event) = modifier_event(
|
||||
ns_event,
|
||||
NSEventModifierFlags::NSControlKeyMask,
|
||||
self.modifiers.ctrl_pressed,
|
||||
) {
|
||||
self.modifiers.ctrl_pressed = !self.modifiers.ctrl_pressed;
|
||||
events.push_back(into_event(window_event));
|
||||
}
|
||||
|
||||
if let Some(window_event) = modifier_event(
|
||||
ns_event,
|
||||
NSEventModifierFlags::NSCommandKeyMask,
|
||||
self.modifiers.win_pressed,
|
||||
) {
|
||||
self.modifiers.win_pressed = !self.modifiers.win_pressed;
|
||||
events.push_back(into_event(window_event));
|
||||
}
|
||||
|
||||
if let Some(window_event) = modifier_event(
|
||||
ns_event,
|
||||
NSEventModifierFlags::NSAlternateKeyMask,
|
||||
self.modifiers.alt_pressed,
|
||||
) {
|
||||
self.modifiers.alt_pressed = !self.modifiers.alt_pressed;
|
||||
events.push_back(into_event(window_event));
|
||||
}
|
||||
|
||||
let event = events.pop_front();
|
||||
self.shared.pending_events
|
||||
.lock()
|
||||
.unwrap()
|
||||
.extend(events.into_iter());
|
||||
event
|
||||
},
|
||||
|
||||
appkit::NSMouseEntered => {
|
||||
let window = match maybe_window.or_else(maybe_key_window) {
|
||||
Some(window) => window,
|
||||
None => return None,
|
||||
};
|
||||
|
||||
let window_point = ns_event.locationInWindow();
|
||||
let view_point = if ns_window == cocoa::base::nil {
|
||||
let ns_size = foundation::NSSize::new(0.0, 0.0);
|
||||
let ns_rect = foundation::NSRect::new(window_point, ns_size);
|
||||
let window_rect = window.window.convertRectFromScreen_(ns_rect);
|
||||
window.view.convertPoint_fromView_(window_rect.origin, cocoa::base::nil)
|
||||
} else {
|
||||
window.view.convertPoint_fromView_(window_point, cocoa::base::nil)
|
||||
};
|
||||
|
||||
let view_rect = NSView::frame(*window.view);
|
||||
let x = view_point.x as f64;
|
||||
let y = (view_rect.size.height - view_point.y) as f64;
|
||||
let window_event = WindowEvent::CursorMoved {
|
||||
device_id: DEVICE_ID,
|
||||
position: (x, y).into(),
|
||||
modifiers: event_mods(ns_event),
|
||||
};
|
||||
let event = Event::WindowEvent { window_id: ::WindowId(window.id()), event: window_event };
|
||||
self.shared.pending_events.lock().unwrap().push_back(event);
|
||||
Some(into_event(WindowEvent::CursorEntered { device_id: DEVICE_ID }))
|
||||
},
|
||||
appkit::NSMouseExited => { Some(into_event(WindowEvent::CursorLeft { device_id: DEVICE_ID })) },
|
||||
|
||||
appkit::NSMouseMoved |
|
||||
appkit::NSLeftMouseDragged |
|
||||
appkit::NSOtherMouseDragged |
|
||||
appkit::NSRightMouseDragged => {
|
||||
// If the mouse movement was on one of our windows, use it.
|
||||
// Otherwise, if one of our windows is the key window (receiving input), use it.
|
||||
// Otherwise, return `None`.
|
||||
match maybe_window.or_else(maybe_key_window) {
|
||||
Some(_window) => (),
|
||||
None => return None,
|
||||
}
|
||||
|
||||
let mut events = std::collections::VecDeque::with_capacity(3);
|
||||
|
||||
let delta_x = ns_event.deltaX() as f64;
|
||||
if delta_x != 0.0 {
|
||||
let motion_event = DeviceEvent::Motion { axis: 0, value: delta_x };
|
||||
let event = Event::DeviceEvent { device_id: DEVICE_ID, event: motion_event };
|
||||
events.push_back(event);
|
||||
}
|
||||
|
||||
let delta_y = ns_event.deltaY() as f64;
|
||||
if delta_y != 0.0 {
|
||||
let motion_event = DeviceEvent::Motion { axis: 1, value: delta_y };
|
||||
let event = Event::DeviceEvent { device_id: DEVICE_ID, event: motion_event };
|
||||
events.push_back(event);
|
||||
}
|
||||
|
||||
if delta_x != 0.0 || delta_y != 0.0 {
|
||||
let motion_event = DeviceEvent::MouseMotion { delta: (delta_x, delta_y) };
|
||||
let event = Event::DeviceEvent { device_id: DEVICE_ID, event: motion_event };
|
||||
events.push_back(event);
|
||||
}
|
||||
|
||||
let event = events.pop_front();
|
||||
self.shared.pending_events.lock().unwrap().extend(events.into_iter());
|
||||
event
|
||||
},
|
||||
|
||||
appkit::NSScrollWheel => {
|
||||
// If none of the windows received the scroll, return `None`.
|
||||
if maybe_window.is_none() {
|
||||
return None;
|
||||
}
|
||||
|
||||
use events::MouseScrollDelta::{LineDelta, PixelDelta};
|
||||
let delta = if ns_event.hasPreciseScrollingDeltas() == cocoa::base::YES {
|
||||
PixelDelta((
|
||||
ns_event.scrollingDeltaX() as f64,
|
||||
ns_event.scrollingDeltaY() as f64,
|
||||
).into())
|
||||
} else {
|
||||
// TODO: This is probably wrong
|
||||
LineDelta(
|
||||
ns_event.scrollingDeltaX() as f32,
|
||||
ns_event.scrollingDeltaY() as f32,
|
||||
)
|
||||
};
|
||||
let phase = match ns_event.phase() {
|
||||
NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => TouchPhase::Started,
|
||||
NSEventPhase::NSEventPhaseEnded => TouchPhase::Ended,
|
||||
_ => TouchPhase::Moved,
|
||||
};
|
||||
self.shared.pending_events.lock().unwrap().push_back(Event::DeviceEvent {
|
||||
device_id: DEVICE_ID,
|
||||
event: DeviceEvent::MouseWheel {
|
||||
delta: if ns_event.hasPreciseScrollingDeltas() == cocoa::base::YES {
|
||||
PixelDelta((
|
||||
ns_event.scrollingDeltaX() as f64,
|
||||
ns_event.scrollingDeltaY() as f64,
|
||||
).into())
|
||||
} else {
|
||||
LineDelta(
|
||||
ns_event.scrollingDeltaX() as f32,
|
||||
ns_event.scrollingDeltaY() as f32,
|
||||
)
|
||||
},
|
||||
}
|
||||
});
|
||||
let window_event = WindowEvent::MouseWheel { device_id: DEVICE_ID, delta: delta, phase: phase, modifiers: event_mods(ns_event) };
|
||||
Some(into_event(window_event))
|
||||
},
|
||||
|
||||
appkit::NSEventTypePressure => {
|
||||
let pressure = ns_event.pressure();
|
||||
let stage = ns_event.stage();
|
||||
let window_event = WindowEvent::TouchpadPressure { device_id: DEVICE_ID, pressure: pressure, stage: stage };
|
||||
Some(into_event(window_event))
|
||||
},
|
||||
|
||||
appkit::NSApplicationDefined => match ns_event.subtype() {
|
||||
appkit::NSEventSubtype::NSApplicationActivatedEventType => {
|
||||
Some(Event::Awakened)
|
||||
},
|
||||
_ => None,
|
||||
},
|
||||
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_proxy(&self) -> Proxy {
|
||||
Proxy {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Proxy {
|
||||
pub fn wakeup(&self) -> Result<(), EventLoopClosed> {
|
||||
// Awaken the event loop by triggering `NSApplicationActivatedEventType`.
|
||||
unsafe {
|
||||
let pool = foundation::NSAutoreleasePool::new(cocoa::base::nil);
|
||||
let event =
|
||||
NSEvent::otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_(
|
||||
cocoa::base::nil,
|
||||
appkit::NSApplicationDefined,
|
||||
foundation::NSPoint::new(0.0, 0.0),
|
||||
appkit::NSEventModifierFlags::empty(),
|
||||
0.0,
|
||||
0,
|
||||
cocoa::base::nil,
|
||||
appkit::NSEventSubtype::NSApplicationActivatedEventType,
|
||||
0,
|
||||
0);
|
||||
appkit::NSApp().postEvent_atStart_(event, cocoa::base::NO);
|
||||
foundation::NSAutoreleasePool::drain(pool);
|
||||
// let the main thread know there's a new event
|
||||
CFRunLoopSourceSignal(self.source);
|
||||
let rl = CFRunLoopGetMain();
|
||||
CFRunLoopWakeUp(rl);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn char_to_keycode(c: char) -> Option<events::VirtualKeyCode> {
|
||||
// We only translate keys that are affected by keyboard layout.
|
||||
//
|
||||
// Note that since keys are translated in a somewhat "dumb" way (reading character)
|
||||
// there is a concern that some combination, i.e. Cmd+char, causes the wrong
|
||||
// letter to be received, and so we receive the wrong key.
|
||||
//
|
||||
// Implementation reference: https://github.com/WebKit/webkit/blob/82bae82cf0f329dbe21059ef0986c4e92fea4ba6/Source/WebCore/platform/cocoa/KeyEventCocoa.mm#L626
|
||||
Some(match c {
|
||||
'a' | 'A' => events::VirtualKeyCode::A,
|
||||
'b' | 'B' => events::VirtualKeyCode::B,
|
||||
'c' | 'C' => events::VirtualKeyCode::C,
|
||||
'd' | 'D' => events::VirtualKeyCode::D,
|
||||
'e' | 'E' => events::VirtualKeyCode::E,
|
||||
'f' | 'F' => events::VirtualKeyCode::F,
|
||||
'g' | 'G' => events::VirtualKeyCode::G,
|
||||
'h' | 'H' => events::VirtualKeyCode::H,
|
||||
'i' | 'I' => events::VirtualKeyCode::I,
|
||||
'j' | 'J' => events::VirtualKeyCode::J,
|
||||
'k' | 'K' => events::VirtualKeyCode::K,
|
||||
'l' | 'L' => events::VirtualKeyCode::L,
|
||||
'm' | 'M' => events::VirtualKeyCode::M,
|
||||
'n' | 'N' => events::VirtualKeyCode::N,
|
||||
'o' | 'O' => events::VirtualKeyCode::O,
|
||||
'p' | 'P' => events::VirtualKeyCode::P,
|
||||
'q' | 'Q' => events::VirtualKeyCode::Q,
|
||||
'r' | 'R' => events::VirtualKeyCode::R,
|
||||
's' | 'S' => events::VirtualKeyCode::S,
|
||||
't' | 'T' => events::VirtualKeyCode::T,
|
||||
'u' | 'U' => events::VirtualKeyCode::U,
|
||||
'v' | 'V' => events::VirtualKeyCode::V,
|
||||
'w' | 'W' => events::VirtualKeyCode::W,
|
||||
'x' | 'X' => events::VirtualKeyCode::X,
|
||||
'y' | 'Y' => events::VirtualKeyCode::Y,
|
||||
'z' | 'Z' => events::VirtualKeyCode::Z,
|
||||
'1' | '!' => events::VirtualKeyCode::Key1,
|
||||
'2' | '@' => events::VirtualKeyCode::Key2,
|
||||
'3' | '#' => events::VirtualKeyCode::Key3,
|
||||
'4' | '$' => events::VirtualKeyCode::Key4,
|
||||
'5' | '%' => events::VirtualKeyCode::Key5,
|
||||
'6' | '^' => events::VirtualKeyCode::Key6,
|
||||
'7' | '&' => events::VirtualKeyCode::Key7,
|
||||
'8' | '*' => events::VirtualKeyCode::Key8,
|
||||
'9' | '(' => events::VirtualKeyCode::Key9,
|
||||
'0' | ')' => events::VirtualKeyCode::Key0,
|
||||
'=' | '+' => events::VirtualKeyCode::Equals,
|
||||
'-' | '_' => events::VirtualKeyCode::Minus,
|
||||
']' | '}' => events::VirtualKeyCode::RBracket,
|
||||
'[' | '{' => events::VirtualKeyCode::LBracket,
|
||||
'\''| '"' => events::VirtualKeyCode::Apostrophe,
|
||||
';' | ':' => events::VirtualKeyCode::Semicolon,
|
||||
'\\'| '|' => events::VirtualKeyCode::Backslash,
|
||||
',' | '<' => events::VirtualKeyCode::Comma,
|
||||
'/' | '?' => events::VirtualKeyCode::Slash,
|
||||
'.' | '>' => events::VirtualKeyCode::Period,
|
||||
'`' | '~' => events::VirtualKeyCode::Grave,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn scancode_to_keycode(code: c_ushort) -> Option<events::VirtualKeyCode> {
|
||||
Some(match code {
|
||||
0x00 => events::VirtualKeyCode::A,
|
||||
0x01 => events::VirtualKeyCode::S,
|
||||
0x02 => events::VirtualKeyCode::D,
|
||||
0x03 => events::VirtualKeyCode::F,
|
||||
0x04 => events::VirtualKeyCode::H,
|
||||
0x05 => events::VirtualKeyCode::G,
|
||||
0x06 => events::VirtualKeyCode::Z,
|
||||
0x07 => events::VirtualKeyCode::X,
|
||||
0x08 => events::VirtualKeyCode::C,
|
||||
0x09 => events::VirtualKeyCode::V,
|
||||
//0x0a => World 1,
|
||||
0x0b => events::VirtualKeyCode::B,
|
||||
0x0c => events::VirtualKeyCode::Q,
|
||||
0x0d => events::VirtualKeyCode::W,
|
||||
0x0e => events::VirtualKeyCode::E,
|
||||
0x0f => events::VirtualKeyCode::R,
|
||||
0x10 => events::VirtualKeyCode::Y,
|
||||
0x11 => events::VirtualKeyCode::T,
|
||||
0x12 => events::VirtualKeyCode::Key1,
|
||||
0x13 => events::VirtualKeyCode::Key2,
|
||||
0x14 => events::VirtualKeyCode::Key3,
|
||||
0x15 => events::VirtualKeyCode::Key4,
|
||||
0x16 => events::VirtualKeyCode::Key6,
|
||||
0x17 => events::VirtualKeyCode::Key5,
|
||||
0x18 => events::VirtualKeyCode::Equals,
|
||||
0x19 => events::VirtualKeyCode::Key9,
|
||||
0x1a => events::VirtualKeyCode::Key7,
|
||||
0x1b => events::VirtualKeyCode::Minus,
|
||||
0x1c => events::VirtualKeyCode::Key8,
|
||||
0x1d => events::VirtualKeyCode::Key0,
|
||||
0x1e => events::VirtualKeyCode::RBracket,
|
||||
0x1f => events::VirtualKeyCode::O,
|
||||
0x20 => events::VirtualKeyCode::U,
|
||||
0x21 => events::VirtualKeyCode::LBracket,
|
||||
0x22 => events::VirtualKeyCode::I,
|
||||
0x23 => events::VirtualKeyCode::P,
|
||||
0x24 => events::VirtualKeyCode::Return,
|
||||
0x25 => events::VirtualKeyCode::L,
|
||||
0x26 => events::VirtualKeyCode::J,
|
||||
0x27 => events::VirtualKeyCode::Apostrophe,
|
||||
0x28 => events::VirtualKeyCode::K,
|
||||
0x29 => events::VirtualKeyCode::Semicolon,
|
||||
0x2a => events::VirtualKeyCode::Backslash,
|
||||
0x2b => events::VirtualKeyCode::Comma,
|
||||
0x2c => events::VirtualKeyCode::Slash,
|
||||
0x2d => events::VirtualKeyCode::N,
|
||||
0x2e => events::VirtualKeyCode::M,
|
||||
0x2f => events::VirtualKeyCode::Period,
|
||||
0x30 => events::VirtualKeyCode::Tab,
|
||||
0x31 => events::VirtualKeyCode::Space,
|
||||
0x32 => events::VirtualKeyCode::Grave,
|
||||
0x33 => events::VirtualKeyCode::Back,
|
||||
//0x34 => unkown,
|
||||
0x35 => events::VirtualKeyCode::Escape,
|
||||
0x36 => events::VirtualKeyCode::RWin,
|
||||
0x37 => events::VirtualKeyCode::LWin,
|
||||
0x38 => events::VirtualKeyCode::LShift,
|
||||
//0x39 => Caps lock,
|
||||
0x3a => events::VirtualKeyCode::LAlt,
|
||||
0x3b => events::VirtualKeyCode::LControl,
|
||||
0x3c => events::VirtualKeyCode::RShift,
|
||||
0x3d => events::VirtualKeyCode::RAlt,
|
||||
0x3e => events::VirtualKeyCode::RControl,
|
||||
//0x3f => Fn key,
|
||||
0x40 => events::VirtualKeyCode::F17,
|
||||
0x41 => events::VirtualKeyCode::Decimal,
|
||||
//0x42 -> unkown,
|
||||
0x43 => events::VirtualKeyCode::Multiply,
|
||||
//0x44 => unkown,
|
||||
0x45 => events::VirtualKeyCode::Add,
|
||||
//0x46 => unkown,
|
||||
0x47 => events::VirtualKeyCode::Numlock,
|
||||
//0x48 => KeypadClear,
|
||||
0x49 => events::VirtualKeyCode::VolumeUp,
|
||||
0x4a => events::VirtualKeyCode::VolumeDown,
|
||||
0x4b => events::VirtualKeyCode::Divide,
|
||||
0x4c => events::VirtualKeyCode::NumpadEnter,
|
||||
0x4e => events::VirtualKeyCode::Subtract,
|
||||
//0x4d => unkown,
|
||||
0x4e => events::VirtualKeyCode::Subtract,
|
||||
0x4f => events::VirtualKeyCode::F18,
|
||||
0x50 => events::VirtualKeyCode::F19,
|
||||
0x51 => events::VirtualKeyCode::NumpadEquals,
|
||||
0x52 => events::VirtualKeyCode::Numpad0,
|
||||
0x53 => events::VirtualKeyCode::Numpad1,
|
||||
0x54 => events::VirtualKeyCode::Numpad2,
|
||||
0x55 => events::VirtualKeyCode::Numpad3,
|
||||
0x56 => events::VirtualKeyCode::Numpad4,
|
||||
0x57 => events::VirtualKeyCode::Numpad5,
|
||||
0x58 => events::VirtualKeyCode::Numpad6,
|
||||
0x59 => events::VirtualKeyCode::Numpad7,
|
||||
0x5a => events::VirtualKeyCode::F20,
|
||||
0x5b => events::VirtualKeyCode::Numpad8,
|
||||
0x5c => events::VirtualKeyCode::Numpad9,
|
||||
0x5d => events::VirtualKeyCode::Yen,
|
||||
//0x5e => JIS Ro,
|
||||
//0x5f => unkown,
|
||||
0x60 => events::VirtualKeyCode::F5,
|
||||
0x61 => events::VirtualKeyCode::F6,
|
||||
0x62 => events::VirtualKeyCode::F7,
|
||||
0x63 => events::VirtualKeyCode::F3,
|
||||
0x64 => events::VirtualKeyCode::F8,
|
||||
0x65 => events::VirtualKeyCode::F9,
|
||||
//0x66 => JIS Eisuu (macOS),
|
||||
0x67 => events::VirtualKeyCode::F11,
|
||||
//0x68 => JIS Kana (macOS),
|
||||
0x69 => events::VirtualKeyCode::F13,
|
||||
0x6a => events::VirtualKeyCode::F16,
|
||||
0x6b => events::VirtualKeyCode::F14,
|
||||
//0x6c => unkown,
|
||||
0x6d => events::VirtualKeyCode::F10,
|
||||
//0x6e => unkown,
|
||||
0x6f => events::VirtualKeyCode::F12,
|
||||
//0x70 => unkown,
|
||||
0x71 => events::VirtualKeyCode::F15,
|
||||
0x72 => events::VirtualKeyCode::Insert,
|
||||
0x73 => events::VirtualKeyCode::Home,
|
||||
0x74 => events::VirtualKeyCode::PageUp,
|
||||
0x75 => events::VirtualKeyCode::Delete,
|
||||
0x76 => events::VirtualKeyCode::F4,
|
||||
0x77 => events::VirtualKeyCode::End,
|
||||
0x78 => events::VirtualKeyCode::F2,
|
||||
0x79 => events::VirtualKeyCode::PageDown,
|
||||
0x7a => events::VirtualKeyCode::F1,
|
||||
0x7b => events::VirtualKeyCode::Left,
|
||||
0x7c => events::VirtualKeyCode::Right,
|
||||
0x7d => events::VirtualKeyCode::Down,
|
||||
0x7e => events::VirtualKeyCode::Up,
|
||||
//0x7f => unkown,
|
||||
|
||||
0xa => events::VirtualKeyCode::Caret,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn check_function_keys(
|
||||
s: &String
|
||||
) -> Option<events::VirtualKeyCode> {
|
||||
if let Some(ch) = s.encode_utf16().next() {
|
||||
return Some(match ch {
|
||||
0xf718 => events::VirtualKeyCode::F21,
|
||||
0xf719 => events::VirtualKeyCode::F22,
|
||||
0xf71a => events::VirtualKeyCode::F23,
|
||||
0xf71b => events::VirtualKeyCode::F24,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn event_mods(event: cocoa::base::id) -> ModifiersState {
|
||||
let flags = unsafe {
|
||||
NSEvent::modifierFlags(event)
|
||||
};
|
||||
ModifiersState {
|
||||
shift: flags.contains(NSEventModifierFlags::NSShiftKeyMask),
|
||||
ctrl: flags.contains(NSEventModifierFlags::NSControlKeyMask),
|
||||
alt: flags.contains(NSEventModifierFlags::NSAlternateKeyMask),
|
||||
logo: flags.contains(NSEventModifierFlags::NSCommandKeyMask),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_scancode(event: cocoa::base::id) -> c_ushort {
|
||||
// In AppKit, `keyCode` refers to the position (scancode) of a key rather than its character,
|
||||
// and there is no easy way to navtively retrieve the layout-dependent character.
|
||||
// In winit, we use keycode to refer to the key's character, and so this function aligns
|
||||
// AppKit's terminology with ours.
|
||||
unsafe {
|
||||
msg_send![event, keyCode]
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn modifier_event(
|
||||
ns_event: cocoa::base::id,
|
||||
keymask: NSEventModifierFlags,
|
||||
was_key_pressed: bool,
|
||||
) -> Option<WindowEvent> {
|
||||
if !was_key_pressed && NSEvent::modifierFlags(ns_event).contains(keymask)
|
||||
|| was_key_pressed && !NSEvent::modifierFlags(ns_event).contains(keymask) {
|
||||
let state = if was_key_pressed {
|
||||
ElementState::Released
|
||||
} else {
|
||||
ElementState::Pressed
|
||||
};
|
||||
|
||||
let scancode = get_scancode(ns_event);
|
||||
let virtual_keycode = scancode_to_keycode(scancode);
|
||||
Some(WindowEvent::KeyboardInput {
|
||||
device_id: DEVICE_ID,
|
||||
input: KeyboardInput {
|
||||
state,
|
||||
scancode: scancode as u32,
|
||||
virtual_keycode,
|
||||
modifiers: event_mods(ns_event),
|
||||
},
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
// Constant device ID, to be removed when this backend is updated to report real device IDs.
|
||||
pub const DEVICE_ID: ::DeviceId = ::DeviceId(DeviceId);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue