Commit graph

65 commits

Author SHA1 Message Date
Sylvain c5c94a6be6 Change return type from void to int, for functions that set an error
(SDL_SetError(), SDL_OutOfMemory(), SDL_Unsupported(), SDL_InvalidParam())

Update prototype to forward errors to generic layer, for the functions:
MoveCursor, WarpMouse, GL_DeleteContext, GetDisplayModes.

Check invalid parameter in SDL_SetTextInputRect() generic layer.
2023-02-07 13:51:45 -08:00
Sam Lantinga 6b137579ea Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
    SDL_DisplayID display = SDL_GetPrimaryDisplay();
    int num_modes = 0;
    SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
    if (modes) {
        for (i = 0; i < num_modes; ++i) {
            SDL_DisplayMode *mode = modes[i];
            SDL_Log("Display %" SDL_PRIu32 " mode %d:  %dx%d@%gHz, %d%% scale\n",
                    display, i, mode->pixel_w, mode->pixel_h, mode->refresh_rate, (int)(mode->display_scale * 100.0f));
        }
        SDL_free(modes);
    }
}

SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.

Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 12:05:25 -08:00
Sam Lantinga 22c69bccdf Displays are now referenced by instance ID instead of index 2023-01-29 19:25:15 -08:00
Sam Lantinga 24fec13ac1 Add full high DPI information to SDL_DisplayMode
SDL_DisplayMode now includes the pixel size, the screen size and the relationship between the two. For example, a 4K display at 200% scale could have a pixel size of 3840x2160, a screen size of 1920x1080, and a display scale of 2.0.
2023-01-27 12:38:46 -08:00
Sam Lantinga 6a27188023 SDL_DisplayMode now represents physical pixels and has added a display scaling factor
Work in progress on https://github.com/libsdl-org/SDL/issues/7134
2023-01-25 09:26:59 -08:00
Sam Lantinga bf53183c8b Fixed building on Raspberry Pi 2023-01-13 14:20:57 -08:00
Sam Lantinga e9b86eebf3 Functions which return function pointers now return SDL_FunctionPointer instead of void*
This fixes the clang warning "Cast between pointer-to-function and pointer-to-object is an extension"

You can define SDL_FUNCTION_POINTER_IS_VOID_POINTER in your project to restore the previous behavior.

Fixes https://github.com/libsdl-org/SDL/issues/2866
2023-01-09 15:46:21 -08:00
Sam Lantinga fde78d12f2 Updated copyright for 2023 2023-01-09 09:41:41 -08:00
Sam Lantinga e3c1749f5b The refresh rate in SDL_DisplayMode is now a float 2023-01-03 06:35:25 -08:00
Sam Lantinga cefbeb582f Mouse coordinates are floating point
You can get sub-pixel mouse coordinates and motion depending on the platform and display scaling.

Fixes https://github.com/libsdl-org/SDL/issues/2999
2022-12-29 23:12:19 -08:00
Sylvain Becker 07808d6a03
Remove underscore in guard header defines (#6922) 2022-12-27 12:31:12 -08:00
Sam Lantinga 63724c113b Removed the vi format comments from the source
Vim users can use the [editorconfig plugin](https://github.com/editorconfig/editorconfig-vim) to automatically set tab spacing for the SDL coding style.

Fixes https://github.com/libsdl-org/SDL/issues/6903
2022-12-26 11:17:23 -08:00
Sam Lantinga 0a3262e819 Pass the OS event timestamp for keyboard, mouse, and touch events where possible
Currently implemented for Windows and Apple platforms
2022-12-02 12:37:41 -08:00
Sam Lantinga 5750bcb174
Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.

In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.

The script I ran for the src directory is added as build-scripts/clang-format-src.sh

This fixes:
#6592
#6593
#6594
2022-11-30 12:51:59 -08:00
Sam Lantinga c5790359fd
Added precompiled header support for Visual Studio and Xcode (#6710)
Fixes https://github.com/libsdl-org/SDL/issues/6704
2022-11-29 18:34:15 -08:00
Sylvain Becker 6a2200823c
Cleanup add brace (#6545)
* Add braces after if conditions

* More add braces after if conditions

* Add braces after while() conditions

* Fix compilation because of macro being modified

* Add braces to for loop

* Add braces after if/goto

* Move comments up

* Remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements after merge

* Fix inconsistent patterns are xxx == NULL vs !xxx

* More "{}" for "if() break;"  and "if() continue;"

* More "{}" after if() short statement

* More "{}" after "if () return;" statement

* More fix inconsistent patterns are xxx == NULL vs !xxx

* Revert some modificaion on SDL_RLEaccel.c

* SDL_RLEaccel: no short statement

* Cleanup 'if' where the bracket is in a new line

* Cleanup 'while' where the bracket is in a new line

* Cleanup 'for' where the bracket is in a new line

* Cleanup 'else' where the bracket is in a new line
2022-11-27 08:38:43 -08:00
Sam Lantinga 0a48abc860 Switch header convention from #include "SDL.h" to #include <SDL3/SDLh>
I ran this script in the include directory:
```sh
sed -i '' -e 's,#include "\(SDL.*\)",#include <SDL3/\1>,' *.h
```

I ran this script in the src directory:
```sh
for i in ../include/SDL3/SDL*.h
do hdr=$(basename $i)
   if [ x"$(echo $hdr | egrep 'SDL_main|SDL_name|SDL_test|SDL_syswm|SDL_opengl|SDL_egl|SDL_vulkan')" != x ]; then
        find . -type f -exec sed -i '' -e 's,#include "\('$hdr'\)",#include <SDL3/\1>,' {} \;
    else
        find . -type f -exec sed -i '' -e '/#include "'$hdr'"/d' {} \;
    fi
done
```

Fixes https://github.com/libsdl-org/SDL/issues/6575
2022-11-26 22:15:18 -08:00
Sam Lantinga b0840eb32e Updated SDL_syswm.h for SDL 3.0
* The header is no longer dependent on SDL build configuration
* The structures are versioned separately from the rest of SDL
* SDL_GetWindowWMInfo() now returns a standard result code and is passed the version expected by the application
* Updated WhatsNew.txt and docs/README-migration.md with the first API changes in SDL 3.0
2022-11-23 14:05:59 -08:00
Ryan C. Gordon dcd9e21966
Merge branch 'main' into wip/angle-egl 2022-11-23 14:01:17 -05:00
Sam Lantinga 2c4159b99a First pass at changing SDL 2.0 to SDL 3.0 2022-11-21 20:28:58 -08:00
Steven Noonan 0644042eb8
egl: implement public functions to obtain internal EGL handles
These functions allow applications to call EGL functions against the SDL
EGL context. For example, applications can use an EGL API loader via
SDL_EGL_GetCurrentDisplay and SDL_EGL_GetProcAddress, and can call
functions such as eglQuerySurface against the internal EGLSurface and
EGLDisplay.
2022-11-10 18:06:11 -08:00
Cameron Cawley 78089e6598 Remove unused internal header SDL_sysevents.h 2022-07-01 07:39:48 -07:00
Simon McVittie 412ceb84d4 video: Only check major version in SDL_GetWindowWMInfo
Since #5602, SDL is intended to have the same ABI across the whole
major-version 2 cycle, so we should not check that the minor version
matches the one that was used to compile an application.

There are two checks that could make sense here.

The first check is that the major version matches the expected major
version. This is usually unnecessary and is not usually done (if we're
calling into the wrong library we'll likely crash anyway), but since we
have the information, we might as well continue to use it.

The second check is whether the version provided by the caller is
equal to or greater than a threshold version at which additional fields
were added to the struct. If it is, we should populate those fields;
if it is not, then we cannot. This is only useful on platforms where
additional fields have genuinely been added during the lifetime of
SDL 2, like Windows and DirectFB (but not X11).

This commit changes the first check to be consistent about only looking
at the minor version, while leaving the second check using SDL_VERSIONNUM
(which will be removed or widened in SDL 3, but it's fine for now).

Resolves: https://github.com/libsdl-org/SDL/issues/5711
Fixes: cd7c2f1 "Switch versioning scheme to be the same as GLib and Flatpak"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-24 08:56:23 -07:00
Sam Lantinga 120c76c84b Updated copyright for 2022 2022-01-03 09:40:21 -08:00
Sam Lantinga f23022ef97 Removed non-functional window grab implementations 2021-02-10 10:22:16 -05:00
Cameron Gutman a0d3c6c63c Rename SetWindowGrab() to SetWindowMouseGrab() 2021-02-10 10:22:16 -05: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
Sam Lantinga 76980e30f2 Added events for dynamically connecting and disconnecting displays, with an iOS implementation 2020-10-08 16:42:20 -07:00
M Stoeckl 052a13738d Merge VideoBootStrap::available into VideoBootStrap::create
The two are only ever called together, and combining them makes it possible
to eliminate redundant symbol loading and redundant attempts to connect
to a display server.
2020-07-12 19:11:15 -04:00
Sam Lantinga b6afbe6317 Added SDL_log.h to SDL_internal.h so logging is available everywhere 2020-04-07 09:38:57 -07:00
Sam Lantinga a8780c6a28 Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
Ozkan Sezer 1e47790c8d RPI_FreeCursor: set global_cursor to NULL to prevent double-free (bug 4769) 2019-08-26 18:41:40 +03:00
Ryan C. Gordon b46c771994 raspberry: Actually commit the whole patch. :) (Thanks, Joe!)
Fixes Bugzilla #4699.
2019-07-02 16:49:35 -04:00
Ryan C. Gordon d2058b45ae raspberry: Fixed missing mouse cursor (thanks, Joe!)
"Starting with changeset 12433, the mouse cursor is not displayed on the
Raspberry Pi platform, due to a bug in the handling of the new
"global_cursor" in RPI_ShowCursor(). Currently, if cursor == global_cursor,
the function immediately returns 0. The function should not return here.
Instead, if cursor == global_cursor, it shouldn't try to hide the current
cursor and update global_cursor = cursor. However, it *should* still continue
through the rest of the function."

Fixes Bugzilla #4699.
2019-07-02 10:26:54 -04:00
Ryan C. Gordon 6fbe9e23fa raspberry: expose second display.
This lets apps see and choose between both an HDMI and DSI-connected display,
such as a television and the Pi Foundation's official touchscreen. It only
exposes the second display if the hardware reports that it is connected.
2019-02-19 23:46:54 -05:00
Sam Lantinga 5e13087b0f Updated copyright for 2019 2019-01-04 22:01:14 -08:00
Sam Lantinga a95291c9c8 Fixed the hotspot for cursors on Raspberry Pi 2018-11-27 11:16:04 -08:00
Sam Lantinga aea483577a Fixed bug changing cursors on Raspberry Pi 2018-11-27 10:20:29 -08:00
Sam Lantinga 5febdfcece Fixed whitespace 2018-09-24 11:49:25 -07:00
Sam Lantinga 940933d892 Fixed bug 4054 - Raspberry Pi refresh rate detection
Viacheslav Slavinsky

SDL_rpivideo driver has 60 frames per second hardcoded in it, this is a problem for games that need to keep pace using VSYNC. I believe that I have found a solution to this. It is based on code in tvservice.c in rpi userland:

a1b89e91f3/host_applications/linux/apps/tvservice/tvservice.c (L433)
2018-02-07 15:05:30 -08:00
Sam Lantinga e3cc5b2c6b Updated copyright for 2018 2018-01-03 10:03:25 -08:00
Sam Lantinga b7be5bce33 Fixed bug 4000 - SDL2 on raspberry: mouse displayed at 0,0 after SDL_ShowCursor
Laurent Merckx

I have a problem with the SDL_ShowCursor method on Raspberry.

Depending on the context, my application hides or show the mouse cursor with SDL_ShowCursor.
But when calling SDL_ShowCursor(true), the cursor is displayed at 0,0 (and not at last position).

After debugging sources by myself, it seems that the problem is in SDL_rpimouse.c - RPI_ShowCursor:

vc_dispmanx_rect_set( &dst_rect, 0, 0, curdata->w, curdata->h);
should be
vc_dispmanx_rect_set( &dst_rect, mouse->x, mouse->y, curdata->w, curdata->h);

For me, it solves the problem.
2017-12-19 11:17:37 -08:00
Sam Lantinga 47506fe1de Fixed bug 3974 - Fix SDL_WarpMouseInWindow on both KMSDRM and RaspberryPi drivers
Manuel Alfayate Corchete

This patch fixes SDL_WarpMouseInWindow() in both the KMSDRM and Raspberry Pi graphic backends.
2017-12-04 20:37:01 -08:00
Brandon Schaefer 9f4e4be8e0 Fixed bug 3943 - General SDL_HINT_VIDEO_DOUBLE_BUFFER hint support 2017-11-07 09:10:32 -08:00
Sam Lantinga 222d25ad4b Fixed bug 3805 - Why is there no --enable-video-rpi option in configure?
Andreas Falkenhahn

When compiling SDL for the Raspberry Pi, I have to use the --host parameter to enable compilation of the native Raspberry Pi video driver, like so:

    --host=arm-raspberry-linux-gnueabihf

It took me a while to figure out that this was necessary in order to have the native Raspberry Pi video driver compiled in. I think it would be better if there was an option like --enable-video-rpi that could be passed to configure and that would also show up when saying configure --help. Currently, it?s rather difficult to figure out that you have to use the --host parameter with arm-raspberry-linux-gnueabihf in order to get Raspberry Pi video support. It?s also somewhat inconsistent because most other video drivers can in fact be enabled/disabled through specific configure parameters but there is no such parameter for the native Raspberry Pi video driver.
2017-09-08 22:21:01 -07:00
Ryan C. Gordon 167398b363 video: Let video targets optionally decide their default OpenGL configs.
This is necessary because the Raspberry Pi is a strange beast, that believes
it has OpenGL support (through glX?) but generally has GLES2 support.

So when using the raspberry video target, we need to force this to default
to a GLES2 context, or by default SDL_CreateWindow() will fail, deep down
when it tries to load the proper GL library.

Fixes testsprite2 (and basically everything else that wasn't testgles2) when
run on a Raspberry Pi without a X server.

Please note that other targets might also need this filled in, the Raspberry
Pi is just the most prominent and readily-available System-On-A-Chip style
thing on my desk.  :)
2017-09-02 19:35:32 -04:00
Sam Lantinga 50efbda736 Fixed mingw Windows build, since SDL_vulkan_internal.h includes windows.h 2017-08-28 00:43:14 -07:00
Sam Lantinga 0d011ec66d Renaming of guard header names to quiet -Wreserved-id-macro 2017-08-28 00:22:23 -07:00
Sam Lantinga 56363ebf61 Fixed bug 3690 - SDL2 KMS/DRM render context support
Manuel

The attached patch adds support for KMS/DRM context graphics.

It builds with no problem on X86_64 GNU/Linux systems, provided the needed libraries are present, and on ARM GNU/Linux systems that have KMS/DRM support and a GLES2 implementation.
Tested on Raspberry Pi: KMS/DRM is what the Raspberry Pi will use as default in the near future, once the propietary DispmanX API by Broadcom is overtaken by open graphics stack, it's possible to boot current Raspbian system in KMS mode by adding "dtoverlay=vc4-kms-v3d" to config.txt on Raspbian's boot partition.
X86 systems use KMS right away in every current GNU/Linux system.

Simple build instructions:

$./autogen.sh
$./configure --enable-video-kmsdrm
$make
2017-08-02 10:22:48 -07:00