Commit graph

74 commits

Author SHA1 Message Date
Sam Lantinga 824b9b0a58 Removed SDL_GetDisplayDPI()
This function wasn't consistently correct across platforms and devices.

If you want the UI scale factor, you can use display_scale in the structure returned by SDL_GetDesktopDisplayMode(). If you need an approximate DPI, you can multiply this value times 160 on iPhone and Android, and 96 on other platforms.
2023-02-08 17:35:54 -08:00
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
Frank Praznik 6c37d5b57f x11: Cast the dot clock value to 64-bit when calculating the refresh rate
The Xrandr dot clock value is declared as an unsigned long and the result when multiplying by 100 can overflow on a 32-bit system. Explicitly cast it to Sint64 to ensure that no overflow will occur.
2023-02-07 13:39:38 -05:00
Sam Lantinga 14338ab459 Removed display mode flags
They weren't really adding any value and added complexity to the API
2023-02-01 12:05:25 -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 b07f8e987b Fixed checking the return values of SDL_AddBasicVideoDisplay() and SDL_AddVideoDisplay()
Also fixed Wayland and Windows usage of SDL_DelVideoDisplay()

https://github.com/libsdl-org/SDL/issues/7192
2023-01-29 21:58:15 -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
Sylvain 78cc95e34e Rename internal GetDisplayDPI to GetDisplayPhysicalDPI 2023-01-25 00:04:00 -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 58aecf0a54 SDL API renaming: SDL_rect.h
Fixes https://github.com/libsdl-org/SDL/issues/6887
2022-12-27 11:01:11 -08:00
Sam Lantinga 083e436a1a SDL API renaming: SDL_pixels.h
Fixes https://github.com/libsdl-org/SDL/issues/6886
2022-12-27 06:08:31 -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
Pierre Wendling 3c501b963d
Clang-Tidy fixes (#6725) 2022-12-01 13:07:03 -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
Anonymous Maarten eb8eb621b1 SDL_x11modes: fix -Wunused-variable 2022-10-08 23:41:07 +02:00
Cameron Cawley 43fc6d593f Fix incorrect return value in X11_GetPixelFormatFromVisualInfo 2022-09-17 13:17:42 -07:00
Ryan C. Gordon 12b371ee0f
x11: Don't send diplay-add events for displays connected at init time.
Reference Issue #4977.
2022-06-21 14:49:21 -04:00
Ryan C. Gordon ec0204d243
x11: Don't use GetXftDPI() when XRandR can tell us the DPI per-output.
Fixes #5764.
2022-06-06 14:39:58 -04:00
Ryan C. Gordon a236bf4f25
x11: Hook up display hotplug notifications.
Obviously this needs XRandR support.

Fixes #4977.
2022-06-06 02:13:37 -04:00
Ozkan Sezer 12f15aaa74 fix build 2022-04-27 10:03:32 +03:00
Ryan C. Gordon 05bd225a80
x11: If XRandR isn't available, add a generic display.
We can get _some_ of the info we need out of standard Xlib and report a
single display (which might actually be multiple physical displays mushed
into a single desktop). This is better than nothing, but you should really
just build with XRandR support and get a better X server.  :)
2022-04-26 23:17:14 -04:00
Ryan C. Gordon ccc70e644b
x11: Fixed some compiler warnings. 2022-04-26 23:17:13 -04:00
Ryan C. Gordon 7d7ec9c951
x11: Remove XVidMode and Xinerama support.
Fixes #1782.
2022-04-26 23:17:13 -04:00
Ryan C. Gordon 1c7bf478ae
x11: Ignore BadValue for extremely small XRRSetScreenSize resolutions.
Reference Issue #4840.
2022-03-31 10:09:47 -04:00
Sam Lantinga 120c76c84b Updated copyright for 2022 2022-01-03 09:40:21 -08:00
Sylvain b4aeaa30a1 Use SDL_calloc / SDL_free 2021-11-22 08:38:46 -08:00
Sylvain d31251b014 use SDL's functions version inplace of libc version 2021-11-22 08:38:46 -08:00
Ryan C. Gordon d5fe9c308a x11: Log a warning if we decide to use XVidMode.
Reference issue #1782.
2021-08-24 14:29:39 -04:00
Simon McVittie 25cd749adb x11: Don't change mode if we are already in the correct mode
If we are already in the desired mode, changing it is a no-op at best,
and harmful at worst: on Xwayland, it sometimes happens that we disable
the crtc and cannot re-enable it.

Resolves: https://github.com/libsdl-org/SDL/issues/4630
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-12 12:23:40 -07:00
Sam Lantinga b033cd0d2e Fixed XSync sequence to match other cases where we set the X11 error handler 2021-07-31 16:01:48 -07:00
Ryan C. Gordon 4c7825f6bd
x11: XSync while trying to catch XRRSetScreenSize error.
Reference issue #4561
2021-07-31 18:27:14 -04:00
Ryan C. Gordon d0effadf68
x11: Don't let XRRSetScreenSize fire a BadMatch error.
This is a workaround and not a proper fix, but this is possibly complicated,
and possibly a corner case, so this will do for 2.0.16, if not the
foreseeable future.

Reference issue #4561
2021-07-31 15:58:31 -04:00
Austin Shafer 16e3bfe807 SetDisplayMode: Call XRRSetScreenSize before setting CRTC config
X11_SetDisplayMode currently calls X11_XRRSetCrtcConfig alone. This results
in the monitor's viewport getting changed, but the underlying screen dimensions
stay the same.

The spec indicates that RRSetCrtcConfig only changes the crtc mode and has no effect
on the screen dimensions, only mentioning that the new crtc must fit entirely within the
screen size. For the size to change, RRSetScreenSize also needs to be called.

This affects Metro Exodus on Linux, when changing the resolution in the in-game settings
Metro gets stuck in a loop waiting for the size of its vulkan surface to change. Because
XRRSetScreenSize is not called the screen size is never changed, the vulkan surface dimensions
do not change, and Metro hangs forever watching for a surface size update that will
never come.

This change disables the CRTC, calls XRRSetScreenSize, and then updates the
CRTC configuration. This fixes changing the resolution from the Metro settings.

Tested with:
Metro Exodus, Portal 2
2021-07-08 08:41:29 -07:00
Kyle Schaefer 4522cb1df9 Changing variable from float to int, this way we can check it's value without having to do an unnecessary conversion. Then do explicit conversions later on if we need. 2021-06-01 16:53:39 -07:00
Kyle Schaefer c289bad900 In x11, GetDisplayDPI can give incorrect or unusable DPI information. Using XGetDefaults to get the Xft DPI if it's available and returning that. This could allow you to figure out DPI scale. 2021-06-01 16:53:39 -07:00
Sam Lantinga 9130f7c377 Updated copyright for 2021 2021-01-02 10:25:38 -08:00
Sam Lantinga 93ccdee8c1 Fixed bug 5404 - stdlib: Added SDL_round, SDL_roundf, SDL_lround and SDL_lroundf
Cameron Cawley

stdlib: Added SDL_round, SDL_roundf, SDL_lround and SDL_lroundf

The default implementation is based on the one used in the Windows RT video driver.
2020-12-23 13:47:49 -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
Sam Lantinga a8780c6a28 Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
Sam Lantinga 5e13087b0f Updated copyright for 2019 2019-01-04 22:01:14 -08:00
Sam Lantinga e3cc5b2c6b Updated copyright for 2018 2018-01-03 10:03:25 -08:00
Sam Lantinga c5429bd975 Fixed bug 3939 - Remove static vm_error and vm_event from SDL_x11modes.c
tomwardio

Remove static int vm_error and vm_event, use local variables instead.

This fixes unused variable errors when compiling with SDL_VIDEO_DRIVER_X11_XINERAMA undefined.

src/video/x11/SDL_x11modes.c:505:22: error: unused variable 'vm_error' [-Werror,-Wunused-variable]

src/video/x11/SDL_x11modes.c:505:12: error: unused variable 'vm_event' [-Werror,-Wunused-variable]
2017-11-04 22:06:40 -07:00
Sam Lantinga 0782f9be51 Fixed bug 3273 - Fix for slow video subsystem initialization when using XRandR.
Mart?n Golini

I'm having a very slow initialization of the video subsystem that locks the window creation for about 500 ms ( tested in at least 4 different systems ). What i found is that X11_InitModes_XRandR is using XRRGetScreenResources, that explicitly ask to poll the hardware for changes. This is not really necessary since if the data is already available you can use XRRGetScreenResourcesCurrent.
I attached a tentative patch that fix this issue. With the patch there's no lock when the subsystem is initialized and the window creation is instant in my applications. The patch only uses XRRGetScreenResourcesCurrent in X11_InitModes_XRandR but it could be potentially used in X11_GetDisplayModes and X11_SetDisplayMode.
2017-09-05 08:24:38 -07:00
Brandon Schaefer 17453d495a x11: Move screen_w/h inside the only ifdef they are referenced in to avoid compiler warnings 2017-08-21 23:44:46 -07:00