src/video/cocoa/SDL_cocoamouse.m


Log

Author Commit Date CI Message
Sam Lantinga cb361896 2020-12-09T07:16:22 Fixed bug 5235 - All internal sources should include SDL_assert.h Ryan C. Gordon We should really stick this in SDL_internal.h or something so it's always available.
Sam Lantinga a8780c6a 2020-01-16T20:49:25 Updated copyright date for 2020
Ryan C. Gordon e841b066 2019-07-08T13:41:01 cocoa: Another attempt at mouse vs touch support. This time, we make anything we think is a MacBook trackpad report its touches as SDL_MOUSE_TOUCHID, even though they're not _actually_ synthesized events, and let all mouse input--even if the OS synthesized it from a multitouch trackpad on our behalf--look like physical input. This is backwards from reality, but produces the results most apps will expect. Note that if you have a real touch device that doesn't appear to be the trackpad, it'll produce real touch events with unique device ids, so it's not a total loss here, but also note that the way we decide if it was the trackpad is an imperfect heuristic; it happens to work out right now, but it's not impossible that a real touchscreen could come to the Mac at some point and (incorrectly?) call it a "mouse" input, etc. But for now, good enough. Fixes Bugzilla #4690.
Ryan C. Gordon d2d06f44 2019-07-02T12:29:36 cocoa: Don't report trackpad mouse events as synthesized touches. Fixes Bugzilla #4690, sort of. I guess.
Ryan C. Gordon d3bedda4 2019-06-18T16:53:49 cocoa: Patched to compile and also handle possible malloc failure.
Sam Lantinga 3e720d2a 2019-06-18T13:41:38 Fixed potential double-free in mouse cleanup code
Ryan C. Gordon 90e2dc98 2019-06-14T18:23:51 A few minor changes to placate static analysis.
Ryan C. Gordon d9a2eff2 2019-06-13T21:31:03 cocoa: Another attempt at synthesized mouse/touch events.
Ryan C. Gordon 29457464 2019-06-13T01:57:13 cocoa: Revised synthesized mouse/touch event strategy. I _think_ I understand what Sylvain is working on here now, so hopefully I got this right. Fixes Bugzilla #4576. (I think!)
Ryan C. Gordon 781692c0 2019-06-09T19:27:25 cocoa: report proper input IDs for mouse/touch events. Otherwise, we generate incorrect mouse events for MacBook trackpads (which are also multitouch devices), etc. Partially fixes Bugzilla #4576.
Sam Lantinga d4c0f498 2019-01-04T22:09:38 Fixed bug 4255 - SDL_GetGlobalMouseState() returns incorrect Y on secondary display Julian Raschke I use an open Mac laptop with an additional external monitor. The coordinate spaces from SDL_GetGlobalMouseState() and SDL_GetWindowPosition() match on the primary display, but not on the secondary display. Cocoa window coordinates are vertically flipped in relation to the primary display: https://github.com/spurious/SDL-mirror/blob/release-2.0.8/src/video/cocoa/SDL_cocoawindow.m#L219-L222 However, Cocoa_GetGlobalMouseState inverts the cursor Y coordinate per-display: https://github.com/spurious/SDL-mirror/blob/release-2.0.8/src/video/cocoa/SDL_cocoamouse.m#L320-L323 Suggested fix: Replace the for-loop with this simpler calculation: *x = (int) cocoaLocation.x; *y = (int) (CGDisplayPixelsHigh(kCGDirectMainDisplay) - cocoaLocation.y);
Sam Lantinga 5e13087b 2019-01-04T22:01:14 Updated copyright for 2019
Sam Lantinga cc7b2fc5 2018-03-10T21:13:50 Temporary fix for bug 3432 - macOS 10.12: small scrolls (1 wheel notch) don't generate events Eric Wasylishen This bug was reintroduced by https://hg.libsdl.org/SDL/rev/fcf24b38a28a The steps to reproduce are the same: run the "testrelative" SDL demo with "--info all", connect a USB mouse with a scroll wheel, and roll the scroll wheel one "notch". You'll get log output like: testdraw2[1644:67222] INFO: SDL EVENT: Mouse: wheel scrolled 0 in x and 0 in y (reversed: 1) in window 1 As far as I can tell macOS doesn't have an API for getting the number of "wheel notches"; I get a deltaY of 0.100006 for one "notch", and it's heavily accelerated (if you roll the wheel quickly you'll get large deltas). So NSEvent's deltaY is only meant to be used for scrolling a scroll view, with the given distance in points, not something like selecting an item in a game. Here's a temporary patch that at restores the foor/ceil in Cocoa_HandleMouseWheel. Not ideal, but at least it restores the ability to scroll one notch of a mousewheel.
Sam Lantinga e3cc5b2c 2018-01-03T10:03:25 Updated copyright for 2018
Sam Lantinga a4cfa936 2017-08-14T21:28:04 Fixed bug 2293 - Precise scrolling events Martijn Courteaux I implemented precise scrolling events. I have been through all the folders in /src/video/[platform] to implement where possible. This works on OS X, but I can't speak for others. Build farm will figure that out, I guess. I think this patch should introduce precise scrolling on OS X, Wayland, Mir, Windows, Android, Nacl, Windows RT. The way I provide precise scrolling events is by adding two float fields to the SDL_MouseWheelScrollEvent datastructure, called "preciseX" and "preciseY". The old integer fields "x" and "y" are still present. The idea is that every platform specific code normalises the scroll amounts and forwards them to the SDL_SendMouseWheel function. It is this function that will now accumulate these (using a static variable, as I have seen how it was implemented in the Windows specific code) and once we hit a unit size, set the traditional integer "x" and "y" fields. I believe this is pretty solid way of doing it, although I'm not the expert here. There is also a fix in the patch for a typo recently introduced, that might need to be taken away by the time anybody merges this in. There is also a file in Nacl which I have stripped a horrible amount of trailing whitespaces. (Leave that part out if you want).
Alex Szpakowski bc3ede1e 2017-07-13T22:59:02 macOS: Replace uses of deprecated Cocoa enum names with modern/consistent equivalents.
Sam Lantinga 45b774e3 2017-01-01T18:33:28 Updated copyright for 2017
Alex Szpakowski bac53941 2016-09-24T13:28:40 Fix mouse wheel events on macOS 10.12 (thanks Eric Wasylishen!) Fixes bug #3432
Alex Szpakowski b15efce2 2016-05-01T21:41:30 Cocoa mouse code: Replaced NSPointInRect with NSMouseInRect (thanks Eric Wasylishen!) Fixes bug #3312.
Alex Szpakowski 08488e6d 2016-03-20T15:35:34 Mac: avoid calling CGSetLocalEventsSuppressionInterval, it was deprecated in OS X 10.6.
Sam Lantinga 42065e78 2016-01-02T10:10:34 Updated copyright to 2016
Ryan C. Gordon e346f142 2015-07-17T21:03:58 SDL_WarpMouseGlobal() should return non-void. There are platforms it isn't implemented on (and currently can't be implemented on!), and there's currently no way for an app to know this. This shouldn't break ABI on apps that moved to a revision between 2.0.3 and 2.0.4.
Philipp Wiesemann 0e45984f 2015-06-21T17:33:46 Fixed crash if initialization of EGL failed but was tried again later. The internal function SDL_EGL_LoadLibrary() did not delete and remove a mostly uninitialized data structure if loading the library first failed. A later try to use EGL then skipped initialization and assumed it was previously successful because the data structure now already existed. This led to at least one crash in the internal function SDL_EGL_ChooseConfig() because a NULL pointer was dereferenced to make a call to eglBindAPI().
Ryan C. Gordon 7619ad34 2015-05-31T21:43:36 Cocoa: deal with mouse focus when warping the cursor from outside a window. Otherwise, you might not get appropriate mouse enter/leave events. Better fix for Bugzilla #2984.
Ryan C. Gordon 5b2ff76c 2015-05-31T13:58:36 Cocoa: send a MOUSEMOTION event when warping cursor from outside the window. Fixes Bugzilla #2984.
Sam Lantinga 2c4a6ea0 2015-05-26T06:27:46 Updated the copyright year to 2015
Ryan C. Gordon b72938c8 2015-04-20T12:22:44 Windows: Always set the system timer resolution to 1ms by default. An existing hint lets apps that don't need the timer resolution changed avoid this, to save battery, etc, but this fixes several problems in timing, audio callbacks not firing fast enough, etc. Fixes Bugzilla #2944.
Alex Szpakowski fe6c797c 2015-04-10T23:30:31 Fixed an iOS view orientation issue when SDL_GL_CreateContext or SDL_CreateRenderer is called.
Edward Rudd b88ca1b4 2015-02-10T16:28:56 the last parameter of XChangeProperty is the number of elements.. and when the element format is 32.. the element is "long" so we have 5 long elements here. Yes this seems confusing as on mac+linux Long is either 32 or 64bits depending on the architecture, but this is how the X11 protocol is defined. Thus 5 is the correct value for the nelts here. Not 5 or 10 depending on the architecture. More info on the confusion https://bugs.freedesktop.org/show_bug.cgi?id=16802
Philipp Wiesemann b48e54aa 2015-01-26T22:00:29 Fixed bug 2802 - [patch] Fix android build compiling in wrong filesystem implementation Jonas Kulla The configure script didn't differentiate between Linux and Android, unconditionally compiling in the unix implementation of SDL_sysfilesystem.c. I'm probably one of the very few people building SDL for android using classic configure + standalone toolchain, so this has gone undetected all along.
David Ludwig 70438be2 2014-12-03T10:55:23 WinRT: fixed bug whereby SDL would override an app's default orientation WinRT apps can set a default, preferred orientation via a .appxmanifest file. SDL was overriding this on app startup, and making the app use all possible orientations (landscape and portrait). Thanks to Eric Wing for the heads up on this!
Edward Rudd 5b5823ee 2014-11-23T21:09:54 add in support for passing down the "natural" (or flipped) scrolling direction in the MouseWheelEvent event
Philipp Wiesemann 9c398852 2014-11-22T22:20:40 Corrected header file documentation comment.
Pierre-Loup A. Griffais 24c86b55 2014-09-11T19:24:42 [X11] Reconcile logical keyboard state with physical state on FocusIn since the window system doesn't do it for us like other platforms. This prevents sticky keys and missed keys when going in and out of focus, for example Alt would appear to stick if switching away from an SDL app with Alt-Tab and had to be pressed again. CR: Sam
Sam Lantinga d1cc47b3 2014-08-17T15:07:00 Fixed 2680 - OSX: Replace NSAutoreleasePool with @autoreleasepool Tim McDaniel This patch replaces all use of NSAutoreleasePool with the Apple recommended @autoreleasepool. @autoreleasepool is supposedly more efficient, and since it is scope based it can't be accidentally not released.
Sam Lantinga 5e501804 2014-08-17T14:57:52 Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different Tim McDaniel On OSX, with revision 8729, the coordinate space for window position and the coordinate space for global mouse position don't match. For a non-fullscreen window, the window position is global relative to the bottom of the menubar. The global mouse position is relative to the top of the screen. This affects Cocoa_WarpMouse and potentially other things as well. Further, the coordinate system for window position is now affected by what screen it is on. For example, if I have two equal size screens oriented side by side such that the tops of the screens are equal in global space, with the menubar on one screen, and a window straddles the two screens, the window's y position makes no sense. The window's y position depends on what screen "most" of the window is on. So if I move the window horizontally just a bit, the y position of my window is now different by the size of the menubar, even though the window was not moved vertically. I'd like to reiterate that this was a fairly fundamental change (and a breaking change for us). If SDL OSX is to really support multi-display configurations, this is especially problematic. If the real concern is preventing windows from going under the menubar, then perhaps a solution involving something like overriding [NSWindow constrainFrameRect] would be less problematic than redefining the global window coord space for the main display.
Sam Lantinga fc4e798d 2014-07-07T12:48:25 Fixed bug 2631 - Mac: minor code cleanup Alex Szpakowski Some minor changes to the Mac-specific backend code: - Fixed up some code style issues (mostly brace style inconsistencies). - Fixed a compiler warning in SDL_cocoaevents.m. - Removed some useless code now that the 10.7 SDK is required to build SDL. - Removed Gestalt(gestaltSystemVersion, ...) call and switched to NSAppKitVersionNumber for version checking code. Using Gestalt with gestaltSystemVersion will give 0x1090 in Mac OS 10.10+, and the whole Gestalt function was deprecated in Mac OS 10.8.
Ryan C. Gordon b29740b8 2014-06-25T17:06:12 Merged Ryan's SDL-gui-backend branch. Adds three APIs, and implements them on X11, Cocoa, and Windows: - SDL_CaptureMouse() - SDL_GetGlobalMouseState() - SDL_SetWindowHitTest()
Ryan C. Gordon 84369567 2014-06-25T16:16:55 Changed SDL_GetAbsoluteMouseState() to SDL_GetGlobalMouseState(). This matches naming conventions in the main repository, between SDL_GetRelativeMouseState() and SDL_WarpMouseGlobal().
Ryan C. Gordon 39bad809 2014-06-15T11:59:16 Mac: Fixed crash when returning from a fullscreen Space on shutdown.
Ryan C. Gordon 2cce7b2e 2014-06-11T00:40:19 Implemented Cocoa GetAbsoluteMouseState().
Sam Lantinga 1e00c03f 2014-06-04T10:56:17 Fixed Mac OS X build
Sam Lantinga 45ed5ee4 2014-06-04T10:55:26 Added an API function to warp the mouse cursor in global screen space: SDL_WarpMouseGlobal()
Sam Lantinga 6b90d7f5 2014-06-02T09:06:38 Fixed bug 2550 - [OS X 10.9] Enabling SDL_WINDOW_FULLSCREEN after relative mouse mode leaves cursor visible Eric Wasylishen Steps to reproduce: - Run testwm2 app in the SDLTest Xcode project - Press Control+R to enable relative mouse mode. The mouse cursor should disappear. - Press Control+Enter to enter fullscreen. - Expected: a black screen with no cursor visible. Observed: a black screen, but the mouse cursor is visible in the middle of the screen. It doesn't move when I move the mouse. Reproduced with latest sdl2 hg (changeset f6010ead184f) on OS X 10.9.2. Can't reproduce the problem on OS X 10.6.8 or 10.7.5. I'm speculating that this really an Apple bug.. but anyway, the attached workaround seems to fix it for me, and I think it's fairly safe. A more obvious idea, sticking a call SDL_SetCursor(NULL) at the end of Cocoa_SetWindowFullscreen, didn't work.
Ryan C. Gordon 668025c2 2014-05-24T18:23:39 Implement SDL_CaptureMouse() for Mac OS X.
David Ludwig 3dcb451f 2014-04-09T21:29:19 Added a README file regarding WinRT support To note, this file is currently formatted with CRLF line endings, rather than LF, to allow the file to be viewed with Notepad.
J?rgen P. Tjern? 0d5957df 2014-02-26T16:27:03 Mac: Forgot return value in last commit.
J?rgen P. Tjern? dd94c5fa 2014-02-26T16:10:52 Mac: Don't disassociate cursor if window is moving / doesn't have focus. Bug: https://bugzilla.libsdl.org/show_bug.cgi?id=2396
J?rgen P. Tjern? 4850d259 2014-02-26T11:35:02 Mac: Redo cursor warp handling. This fixes bugs related to getting unnaturally large xrel/yrel for SDL_MOUSEMOTION after warps and enabling / disabling relative mode. Bug: https://bugzilla.libsdl.org/show_bug.cgi?id=1836
J?rgen P. Tjern? 52a63e82 2014-02-25T17:27:41 Mac: Improve moving relative mode windows. This makes it possible to move windows by their title bar, even if they're in relative mode, if you click the title bar when the window does not have focus. Bug: https://bugzilla.libsdl.org/show_bug.cgi?id=2396
Sam Lantinga af0ab490 2014-02-22T14:57:12 Fixed bug 2346 - Mac: mousewheel events have flipped horizontal scroll values Alex Szpakowski On my Mac OS X system (10.9.1), the SDL_MOUSEWHEEL event reports negative X values when my trackpad scrolls to the right, and positive X values when my trackpad scrolls to the left. This is backwards from what I'd expect, and I don't think it matches the Windows wheel events. The vertical scroll values are what I'd expect though, and are consistent what gets reported on Windows (positive Y for scrolling up, negative Y for scrolling down.) This is with "scroll direction: natural" disabled in the OS X trackpad settings (i.e. my scroll direction in non-SDL OS X programs matches what happens in Windows and Linux.) I also tested with the horizontal scroll on a real mouse (Logitech G500 without custom drivers), and the horizontal scroll values in SDL are still flipped. I "solved" the issue for myself by changing this line in the Cocoa_HandleMouseWheel function: float x = [event deltaX]; to this: float x = -[event deltaX]; I believe it should work fine with that change - I found something similar in another codebase while looking online for my issue - but I haven't tested on anything below Mac OS 10.8.
Sam Lantinga 58edac3e 2014-02-02T00:53:27 Fixed bug 2374 - Update copyright for 2014... Is it that time already??
Gabriel Jacobo f848adff 2013-11-29T10:06:08 Improve Android pause/resume behavior.
Ryan C. Gordon 7e1289af 2013-11-24T23:56:17 Make internal SDL sources include SDL_internal.h instead of SDL_config.h The new header will include SDL_config.h, but allows for other global stuff.
J?rgen P. Tjern? c455f729 2013-10-07T14:16:38 Fix SDL_SetWindowPosition on fullscreen windows. This reverts http://hg.libsdl.org/SDL/rev/7cdeb64faa72 and fixes it in the correct way. If you call SDL_SetWindowPosition on a fullscreen window, it would update the x & y variables for the window, but not actually move the window (since it was fullscreen). That would make the internal state of the SDL_Window incorrect, causing SDL_WarpMouseInWindow to offset incorrectly. This makes it so SDL_SetWindowPosition updates the `windowed' x & y coordinates, which take effect when you revert from fullscreen.
Gabriel Jacobo dad42067 2013-08-12T11:13:50 Fixes #2022, do not resume on Android when surfaceChanged If the app is in landscape mode and the user presses the power button, a pause is followed immediately by a surfaceChanged event because the lock screen is shown in portrait mode. This triggers a "false" resume. So, we just pause and resume following the onWindowFocusChanged events. Also, wait for SDL_APP_WILLENTERBACKGROUND and SDL_APP_DIDENTERBACKGROUND before blocking the event pump.
Sam Lantinga 1ad936eb 2013-08-11T19:56:43 Fixed bug 2027 - Full-screen appears to be broken - hang in SDL_DestroyWindow() Rainer Deyke I'm running Linux Mint 15 with the Cinnamon window manager. SDL_DestroyWindow consistently locks up for me when the window if fullscreen.