Commit Graph

38 Commits

Author SHA1 Message Date
Alex Szpakowski ec8fa57750 macOS: always use Objective-C ARC (automatic ref counting).
Change Cocoa SDL_VideoData and SDL_WindowData implementations from C structs to Objective-C objects, since bridging between C and ObjC is easier that way.
2022-05-09 21:53:40 -07:00
Sam Lantinga 120c76c84b Updated copyright for 2022 2022-01-03 09:40:21 -08:00
Ozkan Sezer 2f248a2a31 SDL_cocoaevents.m: fix build against SDK < 10.12 after commit 0dd7024d. 2021-06-11 04:00:32 +03:00
Francesco Abbate 0dd7024d55 Modifies WaitEvent and WaitEventTimeout to actually wait instead of polling
When possible use native os functions to make a blocking call waiting for
an incoming event. Previous behavior was to continuously poll the event
queue with a small delay between each poll.

The blocking call uses a new optional video driver event,
WaitEventTimeout, if available. It is called only if an window
already shown is available. If present the window is designated
using the variable wakeup_window to receive a wakeup event if
needed.

The WaitEventTimeout function accept a timeout parameter. If
positive the call will wait for an event or return if the timeout
expired without any event. If the timeout is zero it will
implement a polling behavior. If the timeout is negative the
function will block indefinetely waiting for an event.

To let the main thread sees events sent form a different thread
a "wake-up" signal is sent to the main thread if the main thread
is in a blocking state. The wake-up event is sent to the designated
wakeup_window if present.

The wake-up event is sent only if the PushEvent call is coming
from a different thread. Before sending the wake-up event
the ID of the thread making the blocking call is saved using the
variable blocking_thread_id and it is compared to the current
thread's id to decide if the wake-up event should be sent.

Two new optional video device methods are introduced:

WaitEventTimeout
SendWakeupEvent

in addition the mutex

wakeup_lock

which is defined and initialized but only for the drivers supporting the
methods above.

If the methods are not present the system behaves as previously
performing a periodic polling of the events queue.

The blocking call is disabled if a joystick or sensor is detected
and falls back to previous behavior.
2021-06-04 13:50:50 -07:00
Sam Lantinga 9ef0b97c6d Changes to macOS event handler to better interact with the running app
- Only focus a new window when one closes if the window that was closed was an SDL window

- If the application already has a key window set that is not an SDL window, don't replace it when the application is activated

- Only register the URL event handler when SDLAppDelegate is going to be set as the applications app delegate. This is to
   be consistent with previous behavior that would only register the handler in -[SDLAppDelegate applicationDidFinishLaunching:]
   and allows the running app to opt out of the behavior by setting its own app delegate.

- The URL event handler is now removed if it was set on SDLAppDelegate dealloc
2021-04-12 11:25:44 -07:00
Jay 0052339b66 Move handleURLEvent setEventHandler to init 2021-02-20 22:59:11 -08:00
Sam Lantinga 9130f7c377 Updated copyright for 2021 2021-01-02 10:25:38 -08:00
Sam Lantinga cb36189692 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.
2020-12-09 07:16:22 -08:00
Ryan C. Gordon b79832ba11 cocoa: Cut and paste from HTML strikes again! 2020-10-08 21:11:09 -04:00
Ozkan Sezer 69fbd60d25 Fix https://bugzilla.libsdl.org/show_bug.cgi?id=4877#c2
loadNibNamed:owner:topLevelObjects is available on 10.8 and newer.
There is an issue report here about an app failing to function on
10.7 and earlier: https://discourse.libsdl.org/t/28179
2020-10-09 04:00:00 +03:00
Ryan C. Gordon fa23e3d00b locale: Implemented SDL_GetPreferredLocales().
This was something I proposed a long time ago, Sylvain Becker did
additional work on it, then back to me.

Fixes Bugzilla #2131.
2020-05-04 02:27:29 -04:00
Sam Lantinga dad73b1f0c Fixed bug 5073 - SDL does not handle URL Schemes in MacOS
Jason

In iOS, URL Events trigger the DropFile event. I would also expect the same event to be fired on the macOS platform but this is not implemented at all in the AppDelegate.
2020-04-05 10:47:58 -07:00
Ryan C. Gordon 0a6d80abf7 mac: Wait a bit before activating app at startup.
This is obnoxious and wrong, but the patch that activates the Dock before
activating the app fixes the _menu_ not responding on Catalina, but the
first window created by the app won't have keyboard focus without a small
delay inserted.

This obviously needs a better solution, but it gets it limping along correctly
for now.
2020-02-12 13:08:29 -05:00
Sam Lantinga c9c89783cb Miscellaneous pending fixes 2020-01-29 20:09:08 -08:00
Ryan C. Gordon c7e1b289ee cocoa: Fix command line apps' menu bar not working on macOS Catalina.
Fixes Bugzilla #4937.
2020-01-27 17:15:12 -05:00
Sam Lantinga a8780c6a28 Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
Sam Lantinga 7a3ae59037 Fixed bug 4877 - Add support for loading menus from a nib/xib instead of building a hardcoded minimum set
Eric Shepherd

Currently, SDL on Cocoa macOS creates a rudimentary menu bar programmatically if none is already present when the app is registered during setup.

SDL could be much more easily and flexibly used on macOS if upon finding that no menus are currently in place, it first looked for the application's main menu nib or xib file and, if found, loaded that instead of programmatically building the menus.

This would then let developers simply drop in a nib file with a menu bar defined in it and it would be installed and used automatically.

Attached is a patch that does just this. It changes the SDL_cocoaevents.m file to:

* In Cocoa_RegisterApp(), before calling CreateApplicationMenus(), it calls a new function, LoadMainMenuNibIfAvailable(), which attempts to load and install the main menu nib file, using the nib name fetched from the Info.plist file. If that succeeds, LoadMainMenuNibIfAvailable() returns true; otherwise false.
* If LMMNIA() returns false, CreateApplicationMenus() is called to programmatically build the menus as before.
* Otherwise, we're done, and using the menus from the nib/xib file!

I made these changes to support a project I'm working on, and felt they were useful enough to be worth offering them for uplift. They should have zero impact on existing projects' behavior, but make Cocoa SDL development miles easier.
2019-12-03 07:12:55 -08:00
Sam Lantinga 5e13087b0f Updated copyright for 2019 2019-01-04 22:01:14 -08:00
Sam Lantinga 1c9595b16f Fixed bug 4415 - SDL menu bar is nonstandard on Mac
foo.null

I'm on macOS 10.14 and I think I'm using or around SDL 2.0.9. This is about the menu bar that SDL sets up which looks like:

<App Name> <Window> <View>

1. View menu never proceeds after the Window menu in any Mac application (it is always before).
2. For SDL, the only purpose of the View menu is for a single fullscreen menu item, which is not justifiable enough to reserve space for a menu. The View menu should thus be removed, and the full screen menu item should be added at the end inside of Window's menu. See built in apps like Dictionary, Chess, App Store (on 10.14) that do this.
3. SDL should add a "Close" menu item to the Window's submenu, and it should be the first item. Its key equivalent should map to command w. Without this, you cannot close the game window via this shortcut, and you cannot close the app's About window via this shortcut.
4. Apps typically use "Enter Full Screen" or "Exit Full Screen" depending on context, not "Toggle Full Screen" which is less user friendly -- I personally care about this point the least.
2018-12-08 11:06:40 -08:00
Sam Lantinga 5febdfcece Fixed whitespace 2018-09-24 11:49:25 -07:00
Sam Lantinga e3cc5b2c6b Updated copyright for 2018 2018-01-03 10:03:25 -08:00
Alex Szpakowski 5501bcc834 macOS: Fix an OS-generated warning printed to stdout on launch in bundled apps. 2017-11-09 22:24:09 -04:00
Alex Szpakowski fb071a4cd9 Mac: Fix the menu bar not always working for non-.app-bundled apps. Fixes bug #3051. 2017-09-25 20:49:31 -03:00
Alex Szpakowski 562473c1f4 macOS: Address more compiler warnings when building with a recent deployment target. 2017-07-13 23:09:37 -03:00
Alex Szpakowski bc3ede1ed0 macOS: Replace uses of deprecated Cocoa enum names with modern/consistent equivalents. 2017-07-13 22:59:02 -03:00
Sam Lantinga 45b774e3f7 Updated copyright for 2017 2017-01-01 18:33:28 -08:00
Sam Lantinga 1b689c335c Fixed bug 3503 - osx builds don't run on 10.6 as of rev. 10651
Ozkan Sezer

With rev. 10651, i.e. http://hg.libsdl.org/SDL/rev/747a6a795b21 ,
SDL2 - OS X builds fail to run on 10.6 (my setup: i686 / 10.6.8)
because the symbol _IOPMAssertionCreateWithDescription is missing.
The SDK listing it for 10.7+ does seem correct.  Reverting r10651
and rebuilding makes it to function again.
2016-12-01 11:52:47 -08:00
Ryan C. Gordon d1c35febce macOS: removed deprecated UpdateSystemActivity() call.
The non-deprecated approach (IOPMAssertion) already exists in SDL, and is
available in Mac OS X 10.6 and later (although it was incorrectly listed as
10.7 and later in SDL). Since SDL now requires 10.6 or later, this is no
longer conditionally used.
2016-11-25 00:13:13 -05:00
Sam Lantinga 824ecc8f7a Fixed processing mouse and keyboard events in hatari, which uses the old SDLMain.m without creating an SDLApplication instance 2016-10-14 08:15:39 -07:00
Sam Lantinga 27d4f09929 Implemented SDL_GetHintBoolean() to make it easier to check boolean hints 2016-10-07 23:40:44 -07:00
Sam Lantinga fae5d0eab3 Fixed bug 3107 OSX - Process events in SDLApplication to fix integration with CEF.
John Wordsworth

While attempting to integrate CEF (Browser) into an SDL application, we noticed that there were problems on OS X where approximately 50% of the input events were essentially being lost - even when we were using off-screen rendering in CEF and passing through input events manually.

It appears that this problem has been around for a while (see: http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=11141).

Please consider the following patch that fixes this issue. Instead of processing events directly after calling [NSApp nextEventMatchingMask:...] we now pass these events down to NSApp, for processing by an overloaded sendEvent: method. Chromium also forwards events to NSApp in the same way, which means we don't miss events, even if they were originally dequeued by CEF.
2016-10-01 14:34:52 -07:00
Alex Szpakowski 4a468739f8 Removed Mac OS 10.5 support (bug #3137). Also fixed a warning about deprecated Carbon code when using SDL_audio (bug #3127, thanks Dominik!) 2016-05-21 00:20:52 -03:00
Ryan C. Gordon 8e855f2fbc Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
This allows an app to know when a set of drops are coming in a grouping of
some sort (for example, a user selected multiple files and dropped them all
on the window with a single drag), and when that set is complete.

This also adds a window ID to the drop events, so the app can determine to
which window a given drop was delivered. For application-level drops (for
example, you launched an app by dropping a file on its icon), the window ID
will be zero.
2016-01-05 01:42:00 -05:00
Sam Lantinga 42065e785d Updated copyright to 2016 2016-01-02 10:10:34 -08:00
Philipp Wiesemann c57f409fe8 Mac: Fixed check for SDL_HINT_MAC_BACKGROUND_APP. 2015-07-31 20:16:58 +02:00
Alfred Reynolds 0aa2a6df2c SDL
- fix hint check, we want or not and
2015-07-31 09:16:21 -07:00
Alfred Reynolds 628d8edb95 SDL
- add a new SDL_HINT_MAC_BACKGROUND_APP hint, when set or set to 1 don't force the app to be foreground
2015-07-29 17:19:15 -07:00
Philipp Wiesemann 0e45984fa0 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().
2015-06-21 17:33:46 +02:00