Commit 77c9d73b63219c445e68767d34b17c9f9311a674

Ryan C. Gordon 2020-10-05T11:30:33

Removed SDL_AndroidOpenURL, added SDL_OpenURL. Still needs to be wired into Xcode and Visual Studio projects.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
diff --git a/Android.mk b/Android.mk
index 6036a35..0d29167 100644
--- a/Android.mk
+++ b/Android.mk
@@ -37,6 +37,8 @@ LOCAL_SRC_FILES := \
 	$(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c) \
 	$(wildcard $(LOCAL_PATH)/src/locale/*.c) \
 	$(wildcard $(LOCAL_PATH)/src/locale/android/*.c) \
+	$(wildcard $(LOCAL_PATH)/src/misc/*.c) \
+	$(wildcard $(LOCAL_PATH)/src/misc/android/*.c) \
 	$(wildcard $(LOCAL_PATH)/src/power/*.c) \
 	$(wildcard $(LOCAL_PATH)/src/power/android/*.c) \
 	$(wildcard $(LOCAL_PATH)/src/filesystem/android/*.c) \
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1bbe2b0..c510440 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -407,6 +407,7 @@ file(GLOB SOURCE_FILES
   ${SDL2_SOURCE_DIR}/src/haptic/*.c
   ${SDL2_SOURCE_DIR}/src/libm/*.c
   ${SDL2_SOURCE_DIR}/src/locale/*.c
+  ${SDL2_SOURCE_DIR}/src/misc/*.c
   ${SDL2_SOURCE_DIR}/src/power/*.c
   ${SDL2_SOURCE_DIR}/src/render/*.c
   ${SDL2_SOURCE_DIR}/src/render/*/*.c
@@ -941,6 +942,10 @@ if(ANDROID)
   file(GLOB ANDROID_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/android/*.c)
   set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_CORE_SOURCES} ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
 
+  file(GLOB ANDROID_MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/android/*.c)
+  set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_MISC_SOURCES})
+  set(HAVE_SDL_MISC TRUE)
+
   # SDL_spinlock.c Needs to be compiled in ARM mode.
   # There seems to be no better way currently to set the ARM mode.
   # see: https://issuetracker.google.com/issues/62264618
@@ -1301,6 +1306,10 @@ elseif(UNIX AND NOT APPLE AND NOT ANDROID AND NOT RISCOS)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_LINUX_VERSION_H")
   endif()
 
+  file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/unix/*.c)
+  set(SOURCE_FILES ${SOURCE_FILES} ${MISC_SOURCES})
+  set(HAVE_SDL_MISC TRUE)
+
   if(SDL_POWER)
     if(LINUX)
       set(SDL_POWER_LINUX 1)
@@ -1366,6 +1375,10 @@ elseif(WINDOWS)
     endif()
   endif()
 
+  file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/windows/*.c)
+  set(SOURCE_FILES ${SOURCE_FILES} ${MISC_SOURCES})
+  set(HAVE_SDL_MISC TRUE)
+
   # Check for DirectX
   if(DIRECTX)
     if(DEFINED MSVC_VERSION AND NOT ${MSVC_VERSION} LESS 1700)
@@ -1606,6 +1619,10 @@ elseif(APPLE)
     message_error("SDL_FILE must be enabled to build on MacOS X")
   endif()
 
+  file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/macosx/*.m)
+  set(SOURCE_FILES ${SOURCE_FILES} ${MISC_SOURCES})
+  set(HAVE_SDL_MISC TRUE)
+
   if(SDL_AUDIO)
     set(SDL_AUDIO_DRIVER_COREAUDIO 1)
     file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.m)
@@ -1860,6 +1877,10 @@ elseif(APPLE)
   CheckPTHREAD()
 
 elseif(HAIKU)
+  file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/haiku/*.cc)
+  set(SOURCE_FILES ${SOURCE_FILES} ${MISC_SOURCES})
+  set(HAVE_SDL_MISC TRUE)
+
   if(SDL_VIDEO)
     set(SDL_VIDEO_DRIVER_HAIKU 1)
     file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.c)
@@ -1961,6 +1982,11 @@ if(NOT HAVE_SDL_LOCALE)
   file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/dummy/*.c)
   set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
 endif()
+if(NOT HAVE_SDL_MISC)
+  set(SDL_MISC_DISABLED 1)
+  file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/misc/dummy/*.c)
+  set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
+endif()
 
 # We always need to have threads and timers around
 if(NOT HAVE_SDL_THREADS)
diff --git a/Makefile.in b/Makefile.in
index 2e7db2c..834e7c6 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -87,6 +87,7 @@ HDRS = \
 	SDL_main.h \
 	SDL_messagebox.h \
 	SDL_metal.h \
+	SDL_misc.h \
 	SDL_mouse.h \
 	SDL_mutex.h \
 	SDL_name.h \
diff --git a/configure b/configure
index 00bf5eb..2fc4107 100755
--- a/configure
+++ b/configure
@@ -17313,6 +17313,7 @@ SOURCES="$SOURCES $srcdir/src/file/*.c"
 SOURCES="$SOURCES $srcdir/src/haptic/*.c"
 SOURCES="$SOURCES $srcdir/src/joystick/*.c"
 SOURCES="$SOURCES $srcdir/src/libm/*.c"
+SOURCES="$SOURCES $srcdir/src/misc/*.c"
 SOURCES="$SOURCES $srcdir/src/power/*.c"
 #SOURCES="$SOURCES $srcdir/src/filesystem/*.c"
 SOURCES="$SOURCES $srcdir/src/render/*.c"
@@ -24685,6 +24686,9 @@ case "$host" in
         CheckRPATH
         CheckVivanteVideo
 
+        SOURCES="$SOURCES $srcdir/src/misc/unix/*.c"
+        have_misc=yes
+
         SOURCES="$SOURCES $srcdir/src/locale/unix/*.c"
         have_locale=yes
 
@@ -24865,6 +24869,9 @@ $as_echo "#define SDL_TIMER_UNIX 1" >>confdefs.h
         # Set up the core platform files
         SOURCES="$SOURCES $srcdir/src/core/windows/*.c"
 
+        SOURCES="$SOURCES $srcdir/src/misc/windows/*.c"
+        have_misc=yes
+
         # Use the Windows locale APIs.
         SOURCES="$SOURCES $srcdir/src/locale/windows/*.c"
         have_locale=yes
@@ -25121,6 +25128,9 @@ $as_echo "#define SDL_FILESYSTEM_HAIKU 1" >>confdefs.h
             have_filesystem=yes
         fi
 
+        SOURCES="$SOURCES $srcdir/src/misc/haiku/*.cc"
+        have_misc=yes
+
         # Set up files for the locale library
         SOURCES="$SOURCES $srcdir/src/locale/haiku/*.cc"
         have_locale=yes
@@ -25167,6 +25177,9 @@ fi
         CheckVulkan
         CheckPTHREAD
 
+        SOURCES="$SOURCES $srcdir/src/misc/ios/*.m"
+        have_misc=yes
+
         # Set up files for the locale library
         SOURCES="$SOURCES $srcdir/src/locale/macosx/*.m"
         have_locale=yes
@@ -25295,6 +25308,9 @@ $as_echo "#define SDL_VIDEO_RENDER_OGL_ES2 1" >>confdefs.h
         CheckPTHREAD
         CheckHIDAPI
 
+        SOURCES="$SOURCES $srcdir/src/misc/macosx/*.m"
+        have_misc=yes
+
         # Set up files for the locale library
         SOURCES="$SOURCES $srcdir/src/locale/macosx/*.m"
         have_locale=yes
@@ -25514,6 +25530,9 @@ INSTALL_SDL2_CONFIG=$enable_sdl2_config
 
 # Verify that we have all the platform specific files we need
 
+if test x$have_misc != xyes; then
+    SOURCES="$SOURCES $srcdir/src/misc/dummy/*.c"
+fi
 if test x$have_locale != xyes; then
     SOURCES="$SOURCES $srcdir/src/locale/dummy/*.c"
 fi
diff --git a/configure.ac b/configure.ac
index 9b2b324..4675d36 100644
--- a/configure.ac
+++ b/configure.ac
@@ -413,6 +413,7 @@ SOURCES="$SOURCES $srcdir/src/file/*.c"
 SOURCES="$SOURCES $srcdir/src/haptic/*.c"
 SOURCES="$SOURCES $srcdir/src/joystick/*.c"
 SOURCES="$SOURCES $srcdir/src/libm/*.c"
+SOURCES="$SOURCES $srcdir/src/misc/*.c"
 SOURCES="$SOURCES $srcdir/src/power/*.c"
 #SOURCES="$SOURCES $srcdir/src/filesystem/*.c"
 SOURCES="$SOURCES $srcdir/src/render/*.c"
@@ -3533,6 +3534,9 @@ case "$host" in
         CheckRPATH
         CheckVivanteVideo
 
+        SOURCES="$SOURCES $srcdir/src/misc/unix/*.c"
+        have_misc=yes
+
         SOURCES="$SOURCES $srcdir/src/locale/unix/*.c"
         have_locale=yes
 
@@ -3685,6 +3689,9 @@ case "$host" in
         # Set up the core platform files
         SOURCES="$SOURCES $srcdir/src/core/windows/*.c"
 
+        SOURCES="$SOURCES $srcdir/src/misc/windows/*.c"
+        have_misc=yes
+
         # Use the Windows locale APIs.
         SOURCES="$SOURCES $srcdir/src/locale/windows/*.c"
         have_locale=yes
@@ -3861,6 +3868,9 @@ AS_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
             have_filesystem=yes
         fi
 
+        SOURCES="$SOURCES $srcdir/src/misc/haiku/*.cc"
+        have_misc=yes
+
         # Set up files for the locale library
         SOURCES="$SOURCES $srcdir/src/locale/haiku/*.cc"
         have_locale=yes
@@ -3885,6 +3895,9 @@ AS_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
         CheckVulkan
         CheckPTHREAD
 
+        SOURCES="$SOURCES $srcdir/src/misc/ios/*.m"
+        have_misc=yes
+
         # Set up files for the locale library
         SOURCES="$SOURCES $srcdir/src/locale/macosx/*.m"
         have_locale=yes
@@ -3991,6 +4004,9 @@ AS_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
         CheckPTHREAD
         CheckHIDAPI
 
+        SOURCES="$SOURCES $srcdir/src/misc/macosx/*.m"
+        have_misc=yes
+
         # Set up files for the locale library
         SOURCES="$SOURCES $srcdir/src/locale/macosx/*.m"
         have_locale=yes
@@ -4173,6 +4189,9 @@ AC_SUBST([INSTALL_SDL2_CONFIG], [$enable_sdl2_config])
 
 # Verify that we have all the platform specific files we need
 
+if test x$have_misc != xyes; then
+    SOURCES="$SOURCES $srcdir/src/misc/dummy/*.c"
+fi
 if test x$have_locale != xyes; then
     SOURCES="$SOURCES $srcdir/src/locale/dummy/*.c"
 fi
diff --git a/include/SDL.h b/include/SDL.h
index 9a8f580..e2656ca 100644
--- a/include/SDL.h
+++ b/include/SDL.h
@@ -60,6 +60,7 @@
 #include "SDL_version.h"
 #include "SDL_video.h"
 #include "SDL_locale.h"
+#include "SDL_misc.h"
 
 #include "begin_code.h"
 /* Set up for C function definitions, even when using C++ */
diff --git a/include/SDL_misc.h b/include/SDL_misc.h
new file mode 100644
index 0000000..e6ac925
--- /dev/null
+++ b/include/SDL_misc.h
@@ -0,0 +1,75 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ *  \file SDL_misc.h
+ *
+ *  \brief Include file for SDL API functions that don't fit elsewhere.
+ */
+
+#ifndef SDL_misc_h_
+#define SDL_misc_h_
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Open an URL / URI in the browser or other
+ *
+ * Open a URL in a separate, system-provided application. How this works will
+ *  vary wildly depending on the platform. This will likely launch what
+ *  makes sense to handle a specific URL's protocol (a web browser for http://,
+ *  etc), but it might also be able to launch file managers for directories
+ *  and other things.
+ *
+ * What happens when you open a URL varies wildly as well: your game window
+ *  may lose focus (and may or may not lose focus if your game was fullscreen
+ *  or grabbing input at the time). On mobile devices, your app will likely
+ *  move to the background or your process might be paused. Any given platform
+ *  may or may not handle a given URL.
+ *
+ * If this is unimplemented (or simply unavailable) for a platform, this will
+ *  fail with an error. A successful result does not mean the URL loaded, just
+ *  that we launched something to handle it (or at least believe we did).
+ *
+ * All this to say: this function can be useful, but you should definitely
+ *  test it on every platform you target.
+ *
+ *   \param url A valid URL to open.
+ *  \return 0 on success, or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_OpenURL(const char *url);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_filesystem_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/include/SDL_system.h b/include/SDL_system.h
index 8ad0184..48878b7 100644
--- a/include/SDL_system.h
+++ b/include/SDL_system.h
@@ -206,13 +206,6 @@ extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath(void);
  */
 extern DECLSPEC SDL_bool SDLCALL SDL_AndroidRequestPermission(const char *permission);
 
-/**
-   \brief Open an URL / URI in the browser or other
-
-   \return 0 on success, or -1 on error.
- */
-extern DECLSPEC int SDLCALL SDL_AndroidOpenURL(const char *url);
-
 #endif /* __ANDROID__ */
 
 /* Platform specific functions for WinRT */
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index 598d171..f8c02ea 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -2469,19 +2469,6 @@ SDL_bool SDL_AndroidRequestPermission(const char *permission)
     return Android_JNI_RequestPermission(permission);
 }
 
-int SDL_AndroidOpenURL(const char *url)
-{
-    JNIEnv *env = Android_JNI_GetEnv();
-    int ret = -1;
-
-    if (url) {
-        jstring jurl = (*env)->NewStringUTF(env, url);
-        ret = (*env)->CallStaticIntMethod(env, mActivityClass, midOpenURL, jurl);
-        (*env)->DeleteLocalRef(env, jurl);
-    }
-    return ret;
-}
-
 void Android_JNI_GetManifestEnvironmentVariables(void)
 {
     if (!mActivityClass || !midGetManifestEnvironmentVariables) {
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index bbdc9da..8720258 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -766,4 +766,4 @@
 #define SDL_truncf SDL_truncf_REAL
 #define SDL_GetPreferredLocales SDL_GetPreferredLocales_REAL
 #define SDL_AndroidRequestPermission SDL_AndroidRequestPermission_REAL
-#define SDL_AndroidOpenURL SDL_AndroidOpenURL_REAL
+#define SDL_OpenURL SDL_OpenURL_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 885d177..bb5843d 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -826,5 +826,5 @@ SDL_DYNAPI_PROC(float,SDL_truncf,(float a),(a),return)
 SDL_DYNAPI_PROC(SDL_Locale *,SDL_GetPreferredLocales,(void),(),return)
 #ifdef __ANDROID__
 SDL_DYNAPI_PROC(SDL_bool,SDL_AndroidRequestPermission,(const char *a),(a),return)
-SDL_DYNAPI_PROC(int,SDL_AndroidOpenURL,(const char *a),(a),return)
 #endif
+SDL_DYNAPI_PROC(int,SDL_OpenURL,(const char *a),(a),return)
diff --git a/src/misc/SDL_url.c b/src/misc/SDL_url.c
new file mode 100644
index 0000000..3f49bb9
--- /dev/null
+++ b/src/misc/SDL_url.c
@@ -0,0 +1,36 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+#include "SDL_error.h"
+
+extern int SDL_SYS_OpenURL(const char *url);
+
+int
+SDL_OpenURL(const char *url)
+{
+    if (!url) {
+        return SDL_InvalidParamError("url");
+    }
+    return SDL_SYS_OpenURL(url);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/misc/android/SDL_sysurl.c b/src/misc/android/SDL_sysurl.c
new file mode 100644
index 0000000..6ee5f8b
--- /dev/null
+++ b/src/misc/android/SDL_sysurl.c
@@ -0,0 +1,36 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+#include "../../core/android/SDL_android.h"
+
+int
+SDL_SYS_OpenURL(const char *url)
+{
+    JNIEnv *env = Android_JNI_GetEnv();
+    jstring jurl = (*env)->NewStringUTF(env, url);
+    const int ret = (*env)->CallStaticIntMethod(env, mActivityClass, midOpenURL, jurl);
+    (*env)->DeleteLocalRef(env, jurl);
+    return ret;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/misc/dummy/SDL_sysurl.c b/src/misc/dummy/SDL_sysurl.c
new file mode 100644
index 0000000..5fa49c0
--- /dev/null
+++ b/src/misc/dummy/SDL_sysurl.c
@@ -0,0 +1,32 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+#include "SDL_error.h"
+
+int
+SDL_SYS_OpenURL(const char *url)
+{
+    return SDL_Unimplemented();
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/misc/haiku/SDL_sysurl.cc b/src/misc/haiku/SDL_sysurl.cc
new file mode 100644
index 0000000..150028d
--- /dev/null
+++ b/src/misc/haiku/SDL_sysurl.cc
@@ -0,0 +1,35 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+#include "SDL_error.h"
+#include <Url.h>
+
+int
+SDL_SYS_OpenURL(const char *url)
+{
+    BUrl burl(url);
+    const status_t rc = burl.OpenWithPreferredApplication(false);
+    return (rc == B_NO_ERROR) ? 0 : SDL_SetError("URL open failed (err=%d)", (int) rc);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/misc/ios/SDL_sysurl.m b/src/misc/ios/SDL_sysurl.m
new file mode 100644
index 0000000..73b9fee
--- /dev/null
+++ b/src/misc/ios/SDL_sysurl.m
@@ -0,0 +1,34 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+int
+SDL_SYS_OpenURL(const char *url)
+{ @autoreleasepool {
+
+    NSString *nsstr = [NSString stringWithUTF8String:url];
+    NSURL *nsurl = [NSURL URLWithString:nsstr];
+    return [[UIApplication sharedApplication] openURL:nsurl] ? 0 : -1;
+}}
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/misc/macosx/SDL_sysurl.m b/src/misc/macosx/SDL_sysurl.m
new file mode 100644
index 0000000..18324e3
--- /dev/null
+++ b/src/misc/macosx/SDL_sysurl.m
@@ -0,0 +1,34 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+int
+SDL_SYS_OpenURL(const char *url)
+{ @autoreleasepool
+{
+    NSString *nsstr = [NSString stringWithUTF8String:url];
+    NSURL *nsurl = [NSURL URLWithString:nsstr];
+    return [[NSWorkspace sharedWorkspace] openURL:nsurl] ? 0 : -1;
+}}
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/misc/unix/SDL_sysurl.c b/src/misc/unix/SDL_sysurl.c
new file mode 100644
index 0000000..df00e93
--- /dev/null
+++ b/src/misc/unix/SDL_sysurl.c
@@ -0,0 +1,71 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+#include "SDL_error.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <errno.h>
+
+int
+SDL_SYS_OpenURL(const char *url)
+{
+    const pid_t pid1 = fork();
+    if (pid1 == 0) {  /* child process */
+        /* Notice this is vfork and not fork! */
+        const pid_t pid2 = vfork();
+        if (pid2 == 0) {  /* Grandchild process will try to launch the url */
+            execlp("xdg-open", "xdg-open", url, NULL);
+            _exit(EXIT_FAILURE);
+        } else if (pid2 < 0) {   /* There was an error forking */
+            _exit(EXIT_FAILURE);
+        } else {
+            /* Child process doesn't wait for possibly-blocking grandchild. */
+            _exit(EXIT_SUCCESS);
+        }
+    } else if (pid1 < 0) {
+        return SDL_SetError("fork() failed: %s", strerror(errno));
+    } else {
+        int status;
+        if (waitpid(pid1, &status, 0) == pid1) {
+            if (WIFEXITED(status)) {
+                 if (WEXITSTATUS(status) == 0) {
+                     return 0;  /* success! */
+                 } else {
+                     return SDL_SetError("xdg-open reported error or failed to launch: %d", WEXITSTATUS(status));
+                 }
+             } else {
+                return SDL_SetError("xdg-open failed for some reason");
+             }
+        } else {
+            return SDL_SetError("Waiting on xdg-open failed: %s", strerror(errno));
+        }
+    }
+
+    return 0;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/misc/windows/SDL_sysurl.c b/src/misc/windows/SDL_sysurl.c
new file mode 100644
index 0000000..d4c5a23
--- /dev/null
+++ b/src/misc/windows/SDL_sysurl.c
@@ -0,0 +1,43 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+#include "../../core/windows/SDL_windows.h"
+
+/* https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx */
+int
+SDL_SYS_OpenURL(const char *url)
+{
+    WCHAR* wurl = WIN_UTF8ToString(url);
+    int rc;
+
+    if (wurl == NULL) {
+        return SDL_OutOfMemory();
+    }
+
+    /* Success returns value greater than 32. Less is an error. */
+    rc = (int) ShellExecuteW(NULL, L"open", wurl, NULL, NULL, SW_SHOWNORMAL);
+    SDL_free(wurl);
+    return (rc > 32) ? 0 : WIN_SetError("Couldn't open given URL.");
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/video/haiku/SDL_bvideo.cc b/src/video/haiku/SDL_bvideo.cc
index 669a2ae..817fccf 100644
--- a/src/video/haiku/SDL_bvideo.cc
+++ b/src/video/haiku/SDL_bvideo.cc
@@ -37,6 +37,8 @@ extern "C" {
 #include "SDL_bframebuffer.h"
 #include "SDL_bevents.h"
 
+#include <Url.h>
+
 /* FIXME: Undefined functions */
 //    #define HAIKU_PumpEvents NULL
     #define HAIKU_StartTextInput NULL
@@ -193,6 +195,15 @@ void HAIKU_VideoQuit(_THIS)
     SDL_QuitBeApp();
 }
 
+// just sticking this function in here so it's in a C++ source file.
+extern "C" { int HAIKU_OpenURL(const char *url); }
+int HAIKU_OpenURL(const char *url)
+{
+    BUrl burl(url);
+    const status_t rc = burl.OpenWithPreferredApplication(false);
+    return (rc == B_NO_ERROR) ? 0 : SDL_SetError("URL open failed (err=%d)", (int) rc);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/test/Makefile.in b/test/Makefile.in
index c146924..41fa603 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -60,6 +60,7 @@ TARGETS = \
 	teststreaming$(EXE) \
 	testthread$(EXE) \
 	testtimer$(EXE) \
+	testurl$(EXE) \
 	testver$(EXE) \
 	testviewport$(EXE) \
 	testvulkan$(EXE) \
@@ -265,6 +266,9 @@ teststreaming$(EXE): $(srcdir)/teststreaming.c
 testtimer$(EXE): $(srcdir)/testtimer.c
 	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
 
+testurl$(EXE): $(srcdir)/testurl.c
+	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
+
 testver$(EXE): $(srcdir)/testver.c
 	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
 
diff --git a/test/testurl.c b/test/testurl.c
new file mode 100644
index 0000000..c1b26f0
--- /dev/null
+++ b/test/testurl.c
@@ -0,0 +1,36 @@
+/*
+  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely.
+*/
+#include "SDL.h"
+
+int main(int argc, char **argv)
+{
+    int i;
+    if (SDL_Init(SDL_INIT_VIDEO) == -1) {
+        fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
+        return 1;
+    }
+
+    for (i = 1; i < argc; i++) {
+        const char *url = argv[i];
+        SDL_Log("Opening '%s' ...", url);
+        if (SDL_OpenURL(url) == 0) {
+            SDL_Log("  success!");
+        } else {
+            SDL_Log("  failed! %s", SDL_GetError());
+        }
+    }
+
+    SDL_Quit();
+    return 0;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */