Commit Graph

182 Commits

Author SHA1 Message Date
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
Ryan C. Gordon
1ec56f7302 x11: Fixed incorrect function signature for XkbSetDetectableAutoRepeat.
It needs to use Bool (which is an int) and not BOOL (which is CARD8), which
causes problems on platforms with different byte order and alignment, etc.

Fixes Bugzilla #4326.
2018-10-20 21:35:48 -04:00
Ryan C. Gordon
dae4a01361 x11: Don't hardcode limit on lines of text in message boxes.
Plus other text parsing fixes.

Fixes Bugzilla #4306.
2018-10-15 00:46:43 -04:00
Sam Lantinga
5febdfcece Fixed whitespace 2018-09-24 11:49:25 -07:00
Ryan C. Gordon
e061a92dc9 Some drag'and'drop improvements.
First: disable d'n'd events by default; most apps don't need these at all, and
if an app doesn't explicitly handle these, each drop on the window will cause
a memory leak if the events are enabled. This follows the guidelines we have
for SDL_TEXTINPUT events already.

Second: when events are enabled or disabled, signal the video layer, as it
might be able to inform the OS, causing UI changes or optimizations (for
example, dropping a file icon on a Cocoa app that isn't accepting drops will
cause macOS to show a rejection animation instead of the drop operation just
vanishing into the ether, X11 might show a different cursor when dragging
onto an accepting window, etc).

Third: fill in the drop event details in the test library and enable the
events in testwm.c for making sure this all works as expected.
2018-08-02 16:03:47 -04:00
Ryan C. Gordon
8f0cc4a4b7 Backed out changeset 2e42ec46061e.
This change isn't correct. See comments in Bugzilla #4183.
2018-07-22 19:42:08 -04:00
Marc Di Luzio
c3178e67ca Ensure we still clear the X locale modifiers even if not compiled with ibus or fcitx support 2018-07-12 16:52:45 +01:00
Ryan C. Gordon
59574fe2f0 x11: Normalize x11xinput2 touch x to be 1.0 at width (thanks, Zach!).
"Applications (such as SDL's testgesture) do "event.tfinger.x * window_width"
to find window coord. Currently the X11 XInput2 backend expects application
to do "event.tfinger.x * (window_width-1)" instead.

X11 XInput2 touch events are normalized so x is 1.0 at "width - 1" but other
SDL backends appear to have x be 1.0 at "width". Same issue for touch event
y with regards to height."

Fixes Bugzilla #4183.
2018-06-24 13:57:22 -04:00
Sam Lantinga
8ddebfa06e Fixed bug 4085 - X11: Allow configuring _NET_WM_BYPASS_COMPOSITOR through SDL hints
Callum McGing

This patch allows the user to disable the behaviour that blocks the compositor through a new hint: SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR. This allows tools or other windowed applications to behave properly under KWin.
2018-02-16 10:23:10 -08:00
sezero
40b27fd51b revert the recent typecast assignment changes (see bug #4079)
also change the void* typedefs for the two vulkan function
pointers added in vulkan_internal.h  into generic function
pointer typedefs.
2018-02-12 17:00:00 +03:00
Sam Lantinga
90e72bf4e2 Fixed ISO C99 compatibility
SDL now builds with gcc 7.2 with the following command line options:
-Wall -pedantic-errors -Wno-deprecated-declarations -Wno-overlength-strings --std=c99
2018-01-30 18:08:34 -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
Sven Hesse
b89cac6761 Don't X error in SDL_CreateWindow with unsupported GL attributes 2017-10-22 20:24:58 +02:00
Sam Lantinga
5bed4ca92e Fixed divide by zero with a 1x1 sized window 2017-10-12 08:27:22 -07:00
Sam Lantinga
c0019b7f49 Fixed bug 3871 - Touch events are not normalised on X11
Trent Gamblin

The documentation for SDL_TouchFingerEvent says that the x and y coordinates are normalised between 0-1. I've found that to be true on Windows, Android and iOS but on X11 they are in pixel coordinates. This patch fixes the issue. This was the cleanest way I could do it with what was available without changing things around a lot but you may know a better way.
2017-10-11 13:31:21 -07:00
Ryan C. Gordon
c9e73c3e00 x11: make sure SDL_GetGlobalMouseState notices mouse warping through SDL APIs. 2017-09-05 16:15:54 -04: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
Ryan C. Gordon
74043994b8 x11: Correctly restore previous GL context after sacrificial context is done. 2017-09-01 14:08:09 -04:00
Ryan C. Gordon
a3dda100f4 x11: don't try to make a NULL GL context current when we already did that. 2017-09-01 14:00:11 -04:00
Ryan C. Gordon
4649ac463c x11: Clean up sacrificial GL context code.
Check for failures, restore any previously-current context.
2017-09-01 13:57:40 -04:00
Ryan C. Gordon
507659c6ac x11: Make a sacrificial glX context to check for extensions during init.
This is necessary because we need to see if GLES compat extensions exist.

All of this code (including ShouldUseTextureFramebuffer()) should be
revisited after 2.0.6 ships; ideally we don't make throwaway contexts if
we can avoid it...but maybe we can't. I hear Vulkan is pretty cool.

Fixes Bugzilla #3725.
2017-09-01 13:27:53 -04:00
Sam Lantinga
3c7f9d692a Fixed redefinition of typedef warnings and errors on BSD 2017-08-28 00:51:14 -07: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
ce2b16445e Be clear that disabling Vulkan surface support disables the entire SDL Vulkan integration 2017-08-28 00:11:38 -07:00
Ryan C. Gordon
25e3a1ec90 vulkan: Initial Vulkan support!
This work was done by Jacob Lifshay and Mark Callow; I'm just merging it
into revision control.
2017-08-27 22:15:57 -04:00