Commit Graph

208 Commits

Author SHA1 Message Date
Cameron Gutman
e1f73e642b Refactor keyboard grab to be managed by the video core
This gives us flexibility to add others hints to control keyboard grab behavior
without having to touch all of the backends. It also allows us to possibly
expose keyboard grab separately from mouse grab for applications that want to
manage those independently.
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
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
Ozkan Sezer
5c212cb0c5 remove a few stale NULL message/title checks after commit e2b729b1756a
top-level guarantees non-NULL message / title passed in messageboxdata
2020-12-10 12:24:24 +03:00
Ozkan Sezer
f1cab8aea6 fix bug #5253: handle NULL title or message fields in SDL_MessageBoxData
- SDL_video.c (SDL_ShowMessageBox): replace messageboxdata, set title
  or message field to "" if either of them is NULL.
- SDL_video.c (SDL_ShowSimpleMessageBox):  set title or message to ""
  if either of them is NULL for EMSCRIPTEN builds.
- SDL_bmessagebox.cc: add empty string check along with NULL check for
  title and message fields.
- SDL_windowsmessagebox.c (AddDialogString): remove NULL string check
- SDL_windowsmessagebox.c (AddDialogControl):  add empty string check
  along with the NULL check.
- SDL_x11messagebox.c: revert commit 677c4cd68069
- SDL_os2messagebox.c: revert commit 2c2a489d76e7
- test/testmessage.c: Add NULL title and NULL message tests.
2020-12-10 11:20:56 +03: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
0ff5d55a07 x11: Don't try to grab the pointer on an unmapped window (thanks, Lee!)
Fixes Bugzilla #5352.
2020-11-23 21:07:28 -05:00
Ryan C. Gordon
335cfa107b x11: Don't crash if a messagebox has a NULL title string.
Fixes Bugzilla #5253.
2020-11-18 11:24:08 -05:00
Sam Lantinga
1ef45c1801 Fixed bug 5339 - Minor memory leak in SDL_x11events.c
wcodelyokoyt

The atom name that X11_GetAtomName() returns never gets freed, which result in a minor memory leak (14 bytes?) every time the user drops a file on a window.
You can see the line in question here:
6b6170caf6/src/video/x11/SDL_x11events.c (L1350)

Fix: call XFree on name after the while loop.
2020-11-08 23:40:17 -08:00
Alberts Muktup?vels
73010da4dc x11events: ignore UnmapNotify events from XReparentWindow
UnmapNotify event does not mean that window has been iconified. It
just reports that window changed state from mapped to unmapped.

XReparentWindow can unmap and remap window if it was mapped. This
causes unnecessary events - HIDDEN, MINIMIZED, RESTORED and SHOW.

These events are problematic with Metacity 3.36+ which started to
remove window decorations from fullscreen windows.

- SDL makes decorated window fullscreen
- Metacity removes decorations
- SDL gets UnmapNotify and exits from fullscreen
- Metacity re-adds decorations

As SDL will also get MapNotify event it will try to restore
window state causing above steps to repeat.

https://bugzilla.libsdl.org/show_bug.cgi?id=5314
2020-10-19 17:26:33 -07:00
Sam Lantinga
76980e30f2 Added events for dynamically connecting and disconnecting displays, with an iOS implementation 2020-10-08 16:42:20 -07:00
Cameron Gutman
9a769da04a X11: Remove our X11 error callback in X11_DeleteDevice()
If we don't remove it, we will infinitely recurse if X11_CreateDevice() is
called again and orig_x11_errhandler becomes X11_SafetyNetErrHandler().
2020-09-07 20:10:50 -07:00
Sam Lantinga
8709f67ebc Fixed bug 5215 - Fixing filenames passed to dlopen for OpenBSD
Brad Smith

Attached is a patch to use the proper filenames when trying to dlopen the respective shared libraries on OpenBSD.
2020-09-08 08:42:30 -07:00
M Stoeckl
8669a87f05 Reuse X11 connection from availability check
Instead of creating an X11 connection to test that X11 is available,
closing the connection, and then reconnecting for real, use the same
connection to handle both cases.

The X11 connection retry delay mechanism in the case where X11 is
dynamically loaded has been removed. It was only necessary to avoid
authetnication token reuse from the XOpenDisplay call that used to
exist in X11_Available. Now that this call is only made once, it
is no longer needed.

Also drop unused and inapplicable code from a comment.
***
2020-07-14 21:13:27 -04: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
ce293eed8d Fixed bug 5208 - Fix libGL loading on OpenBSD 2020-06-23 10:12:24 -07:00
James Legg
f1d5ced167 x11: Fix spurious keyboard focus events 2020-06-17 12:48:40 +01:00
Sam Lantinga
eadc8693dd Fixed bug 5103 - Port fcitx support to both fcitx 4 & 5
wengxt

Due to the new major fcitx version is coming close, the existing code need to be ported to use new Fcitx dbus interface.

The new dbus interface is supported by both fcitx 4 and 5, and has a good side effect, which is that it will work with flatpak for free. Also the patch remove the dependency on fcitx header. Instead, it just hardcodes a few enum value in the code so need to handle the different header for fcitx4 or 5.
2020-05-11 14:31:04 -07:00
Sam Lantinga
589d636bb9 Fixed rare crash when creating an X11 window 2020-04-22 14:57:06 -07: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
e05d92a17d Fixed bug 5075 - Don't assume a GL library version number on NetBSD.
Nia Alarie

If you install X as part of NetBSD, the GL library is libGL.so.3, but if you install the GL library later as a package, it's libGL.so.1.
2020-04-05 09:01:33 -07:00
Ryan C. Gordon
1b82606e1d x11: Wait a bit in SDL_SetWindowSize() to see if window manager vetoed change.
Same idea as the fix for Bugzilla #4646.

Fixes Bugzilla #4727.
2020-02-17 16:11:18 -05:00
Ryan C. Gordon
e731522578 x11: Don't delay an extra 10ms if we were just going to break out of the loop. 2020-02-17 15:02:37 -05:00
Ryan C. Gordon
367a8b9701 x11: Don't wait for the window to move if it's already in the place we want it. 2020-02-17 15:00:02 -05:00
Ryan C. Gordon
d1df34370e x11: SDL_SetWindowPosition should try to wait for the window manager.
Wait up to 100 milliseconds, since the window manager might alter or
outright veto the window change...or not respond at all.

In a well-functioning system, though, this should help make sure
that SDL_SetWindowPosition's results match reality.

Fixes Bugzilla #4646.
2020-02-14 13:17:18 -05:00
Sam Lantinga
4b585e75d9 Fixed bug 4833 - Use EGL for X11?
Martin Fiedler

To be precise, this is about *desktop OpenGL* on X11. For OpenGL ES, EGL is already used (as it's the only way to get an OpenGL ES context), as Sylvain noted above.

To shine some light on why this is needed:
In 99% of all cases, using GLX on X11 is fine, even though it's effectively deprecated in favor of EGL [1]. However, there's at least one use case that *requires* the OpenGL context being created with EGL instead of GLX, and that's DRM_PRIME interoperability: The function glEGLImageTargetTexture2DOES simply doesn't work with GLX. (Currently, Mesa actually crashes when trying that.)
Some example code:
https://gist.github.com/kajott/d1b29c613be30893c855621edd1f212e
Runs on Intel and open-source AMD drivers just fine (others unconfirmed), but with #define USE_EGL 0 (i.e. forcing it to GLX), it crashes. The same happens when using SDL for window and context creation.

The good news is that most of the pieces for EGL support on X11 are already in place: SDL_egl.c is pretty complete (and used for desktop OpenGL on Wayland, for example), and SDL_x11opengl.c has the aforementioned OpenGL-ES-on-EGL support. However, when it comes to desktop OpenGL, it's hardcoded to fall back to GLX.

I'm not advocating to make EGL the default for desktop OpenGL on X11; don't fix what ain't broken. But something like an SDL_HINT_VIDEO_X11_FORCE_EGL would be very appreciated to make use cases like the above work with SDL.


[1] source: Eric Anholt, major Linux graphics stack developer, 7 years ago already - see last paragraph of https://www.phoronix.com/scan.php?page=news_item&px=MTE3MTI
2020-02-03 08:06:52 -08:00
Ryan C. Gordon
39563b7bfa x11: Use XSync when changing window position instead of XFlush.
Attempt to fix regression in Bugzilla #4646.
2020-01-28 13:51:24 -05:00
Sam Lantinga
a8780c6a28 Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
Dmitry V. Levin
2b1edf4113 X11_InitKeyboard: do not call XAutoRepeatOn unnecessarily
Use XGetKeyboardControl to initialize the current XKeyboardState, and
skip XAutoRepeatOn invocation if global_auto_repeat is AutoRepeatModeOn.

This fixes SDL2 when the X11 client is untrusted.
2020-01-04 11:05:06 -08:00
Dmitry V. Levin
ed514cd0e4 have_mitshm: use XShmQueryExtension to check for MIT-SHM extension
Do not try to guess MIT_SHM extension availability from the string
returned by XDisplayName, use the appropriate API instead.

This fixes SDL2 inside hasher.
2020-01-04 11:03:04 -08:00
Ozkan Sezer
9340cfa9a1 SDL_x11events.c (X11_DispatchEvent): remove FIXME and use SDL_strtokr(). 2019-12-27 23:01:10 +03:00
Alex Smith
e5af951eae Fix sending SDL_WINDOWEVENT_RESTORED after unminimizing windows on X11
SDL_SendWindowEvent will only send a RESTORED event if the window has
the minimized or maximized flag set. However, for a SHOWN event, it
will clear the minimized flag. Since the SHOWN event was being sent
first for a MapNotify event, the RESTORED event would never be sent.
Swapping the SendWindowEvent calls around fixes this.

https://bugzilla.libsdl.org/show_bug.cgi?id=4821
2019-12-02 15:41:25 +00:00
Sam Lantinga
b1539c4c49 Fixed bug 4819 - Attempting to create an OpenGL ES context with unachievable MSAA parameters under X11 dooms the program
Solra Bizna

I have written a program that, in the event that the user requests more MSAA samples than their hardware supports, attempts to gracefully fall back to the best MSAA available. This code works with my conventional OpenGL renderer, but if I change nothing about the code except to make it request an OpenGL ES profile instead, Xlib kills the program with an error that looks like:

X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  4 (X_DestroyWindow)
  Resource id in failed request:  0x5c00008
  Serial number of failed request:  188
  Current serial number in output stream:  193

To trigger the bug, attempt to create a window with the SDL_WINDOW_OPENGL flag, with SDL_GL_CONTEXT_PROFILE_MASK set to SDL_GL_CONTEXT_PROFILE_ES, and with SDL_GL_MULTISAMPLESAMPLES set to any unsupported value. SDL_CreateWindow properly returns NULL, but at this point the program is already doomed. Xlib will shortly terminate the program with an error. Calling SDL_CreateWindow again will immediately trigger this termination.

I have attached a skeletal program that reproduces this bug for me. Replacing SDL_GL_CONTEXT_PROFILE_ES with SDL_GL_CONTEXT_PROFILE_COMPATIBILITY avoids the bug (but, obviously, doesn't create an OpenGL ES context).

As I suspected, the problem was with XDestroyWindow being called twice on the same window. The X11_CreateWindow function in src/video/x11/SDL_x11window.c calls SetupWindowData. If initialization fails after that point, XDestroyWindow gets called on the window by a subsequent call to X11_DestroyWindow. But, later in the same function, iff a GLES context is requested and initializing it fails, X11_XDestroyWindow (which wraps XDestroyWindow) is manually called. Shortly after, the intended call to X11_DestroyWindow occurs, which attempts to destroy the same window again. Boom.

(The above confusing summary involves three separate, similarly-named functions: XDestroyWindow, X11_DestroyWindow, X11_XDestroyWindow)

I have attached a simple patch that removes the redundant X11_XDestroyWindow calls. I've tested that XDestroyWindow still gets called for the windows in question, and that it only gets called once.
2019-11-16 22:35:48 -08:00
Sylvain Becker
ce308a7841 revert this const parameter for X11 function 2019-10-30 16:33:32 +01:00
Sylvain Becker
d4a67e2541 Readability: change some pointer parameter to be pointer to const 2019-10-30 16:06:51 +01:00
Sylvain Becker
b458d7a28f Readability: remove redundant cast to the same type 2019-10-30 15:13:55 +01:00
Sylvain Becker
735691ecd6 Remove nested redundant #ifndef 2019-10-30 14:29:41 +01:00
Ryan C. Gordon
c0255be458 x11: check if the X server honored our XMoveWindow() call (thanks, R.E. Rust!).
This can happen if a window is still grabbed when we try to move it, or if
the X11 ecosystem is just in a bad mood, I guess.

This makes sure that SDL will report the correct position for a window;
otherwise, SDL_GetWindowPosition will just report whatever the last
SDL_SetWindowPosition call requested, even if the window didn't actually move.

Fixes Bugzilla #4646.
2019-10-26 23:58:55 -04:00
Ryan C. Gordon
ed7483f82c x11: On macOS, look for X11 install in /opt/X11 instead of /usr/X11R6.
This is where Apple installs XQuartz now (and apparently, the compatibility
symlink at /usr/X11R6 can be missing).

Fixes Bugzilla #4706.
2019-10-15 22:36:08 -04:00
Sam Lantinga
e5580e18ba x11: add a hint to force the VisualID used when creating a window. 2019-09-04 09:27:58 -07:00
Alex Szpakowski
2fb71ac52d Implement touch window IDs on x11/xinput2. 2019-08-04 00:34:23 -03:00
Sam Lantinga
63197c4338 Fix bug where the wrong button was the default in the old message box because buttons were added backwards, breaking the indexing used by GetButtonIndex.
Add messagebox flags to explicilty request left-to-right button order or right-to-left.  If neither is specified it'll be some platform default.
2019-08-02 17:19:50 -07:00
Alex Szpakowski
d5ec735a33 Add a windowID field to SDL_TouchFingerEvent (bug #4331).
This is unimplemented on some platforms and will cause compile errors when building those platform backends for now.
2019-08-01 18:22:12 -03:00
Ozkan Sezer
4953e050f5 use SDL_zeroa at more places where the argument is an array. 2019-07-31 05:11:40 +03:00
Sylvain Becker
86965eecd3 x11: prevent a synthetic mouse event when using a touchscreen
With multitouch, register to receive XI_Motion (which desctivates MotionNotify),
so that we can distinguish real mouse motions from synthetic one.

(bug 4690)
2019-07-10 10:06:28 +02:00
Ryan C. Gordon
6ef01e5236 x11: set some modality things on message boxes with parent windows. 2019-07-09 17:28:02 -04:00
Sam Lantinga
8dea23c705 Fixed bug 3911 - SYSWM generic X11 events missing event data
Andrei Drexler

For X11 GenericEvents, the associated data is only available between a call to XGetEventData and the matching XFreeEventData, i.e. in X11_HandleGenericEvent. Trying to call XGetEventData a second time on the same event will fail, so an application that wants to inspect XInput2 events (e.g. for stylus pressure) has no way of retrieving its data from queued SYSWM events.

The attached patch (based on SDL-2.0.7-11629) sends SYSWM messages from X11_HandleGenericEvent while the data is still available, allowing client code to register an event filter/watcher and process the event inside the callback.
2019-05-19 10:44:14 -07:00
Sam Lantinga
5e13087b0f Updated copyright for 2019 2019-01-04 22:01:14 -08:00
Alex Szpakowski
5029d50ea8 Add SDL_TouchDeviceType enum and SDL_GetTouchDeviceType(SDL_TouchID id).
Touch device types include SDL_TOUCH_DEVICE_DIRECT (a touch screen with window-relative coordinates for touches), SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE (a trackpad-style device with absolute device coordinates), and SDL_TOUCH_DEVICE_INDIRECT_RELATIVE (a trackpad-style device with screen cursor-relative coordinates).

Phone screens are an example of a direct device type. Mac trackpads are the indirect-absolute touch device type. The Apple TV remote is an indirect-relative touch device type.
2018-11-10 16:15:48 -04:00
Micha? Janiszewski
91820998fc Add and update include guards
Include guards in most changed files were missing, I added them keeping
the same style as other SDL files. In some cases I moved the include
guards around to be the first thing the header has to take advantage of
any possible improvements compiler may have for inclusion guards.
2018-10-28 21:36:48 +01:00