Commit Graph

340 Commits

Author SHA1 Message Date
Sylvain ce5da5d579
Don't compare pointer against '0', but NULL 2022-11-16 21:47:43 +01:00
Frank Praznik c855184765 wayland: Handle virtual keyboards that don't fit the X mapping
SDL is built around the concept of keyboards having a fixed layout with scancodes that correspond to physical keys no matter what linguistic layout is used. Virtual keyboards don't have this concept and can present an arbitrary layout of keys with arbitrary scancodes and names, which don't fit the SDL model. When one of these keyboards is encountered, it requires special handling: use the keysym of the pressed keys to derive their ANSI keyboard scancode equivalents for control keys and ASCII characters. All other characters are passed through as text events only.
2022-11-15 11:00:39 -08:00
Frank Praznik 0e446c54bd events: Factor out the xkb keysym to scancode conversion from the X11 driver 2022-11-15 11:00:39 -08:00
Ethan Lee f3cc99fb93
x11: Minor style fixes for recent OSK changes 2022-11-15 13:56:44 -05:00
Ethan Lee c4b9f62164 x11: Add support for the Steam Deck on-screen keyboard 2022-11-13 11:02:27 -08:00
Sam Lantinga 4556074e18 Re-set the maximize state if we were maximized while fullscreen 2022-10-29 09:35:07 -07:00
Sam Lantinga ab06a307dc Don't report windows being maximized when fullscreen on X11
This is a functional state for some window managers (tested using stock Ubuntu 22.04.1), and removing that state, e.g. using SDL_RestoreWindow(), results in a window centered and floating, and not visually covering the rest of the desktop.
2022-10-29 09:21:17 -07:00
Ryan C. Gordon 41d38c0f64 shape: More robust handling of failure cases in CreateShaper. 2022-10-26 13:57:49 -04:00
Ryan C. Gordon c8d20f96ba shape: Free platform-specific shaped window data.
Fixes #2128.
2022-10-26 13:57:49 -04:00
Sam Lantinga b6cf889af4 Use ScreenCount() instead of SDL_GetNumVideoDisplays()
The limitation appears to be specific to multi-screen setups
2022-10-25 15:10:50 -07:00
Sam Lantinga e3f5744db4 Don't use XIWarpPointer() on multi-display configurations 2022-10-25 12:14:00 -07:00
Sam Lantinga 139192140c Fixed reported cases of "Keyboard layout unknown" messages
In all cases they were using SDL_SCANCODE_TABLE_XFREE86_2 with some keycodes remapped or fewer than expected keycodes. This adds a sanity check that catches all of them and gives them the right scancode table.
2022-10-13 23:23:55 -07:00
Sam Lantinga 2c1923859a Don't remove entries from an existing scancode keymap
If we can't find the X11 keysym, it's likely that either the keysym is NoSymbol, in which case we won't hit it anyway, or it's been mapped to a character, in which case the existing mapping is correct for the scancode and the character will be reflected in the keycode mapping.
2022-10-13 22:50:57 -07:00
Sam Lantinga 99f2a50394 X11 scancode mapping cleanup
* Consolidated scancode mapping tables into a single location for all backends
* Verified that the xfree86_scancode_table2 is largely identical to the Linux scancode table
* Updated the Linux scancode table with the latest kernel keycodes (still unmapped)
* Route X11 keysym -> scancode mapping through the linux scancode table (which a few hand-written exceptions), which will allow mappings to automatically get picked up as they are added in the Linux scancode table
* Disabled verbose reporting of missing keysym mappings, we have enough data for now
2022-10-13 22:41:47 -07:00
Desour 6836273d14 Use XIWarpPointer if compiled with xinput2
Co-authored-by: Andrei E <andreien@proton.me>
2022-10-11 16:43:24 -07: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
DS ac5b9bc4ee
Add support for X11 primary selection (#6132)
X11 has a so-called primary selection, which you can use by marking text and middle-clicking elsewhere to copy the marked text.

There are 3 new API functions in `SDL_clipboard.h`, which work exactly like their clipboard equivalents.

## Test Instructions

* Run the tests (just a copy of the clipboard tests): `$ ./test/testautomation --filter Clipboard`
* Build and run this small application:
<details>
```C
#include <SDL.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void print_error(const char *where)
{
	const char *errstr = SDL_GetError();
	if (errstr == NULL || errstr[0] == '\0')
		return;
	fprintf(stderr, "SDL Error after '%s': %s\n", where, errstr);
	SDL_ClearError();
}

int main()
{
	char text_buf[256];

	srand(time(NULL));

	SDL_Init(SDL_INIT_VIDEO);
	print_error("SDL_INIT()");
	SDL_Window *window = SDL_CreateWindow("Primary Selection Test", SDL_WINDOWPOS_UNDEFINED,
			SDL_WINDOWPOS_UNDEFINED, 400, 400, SDL_WINDOW_SHOWN);
	print_error("SDL_CreateWindow()");
	SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
	print_error("SDL_CreateRenderer()");

	bool quit = false;
	unsigned int do_render = 0;
	while (!quit) {
		SDL_Event event;
		while (SDL_PollEvent(&event)) {
			print_error("SDL_PollEvent()");
			switch (event.type) {
			case SDL_QUIT: {
				quit = true;
				break;
			} case SDL_KEYDOWN: {
				switch (event.key.keysym.sym) {
				case SDLK_ESCAPE:
				case SDLK_q:
					quit = true;
					break;
				case SDLK_c:
					snprintf(text_buf, sizeof(text_buf), "foo%d", rand());
					SDL_SetClipboardText(text_buf);
					print_error("SDL_SetClipboardText()");
					printf("clipboard: set_to=\"%s\"\n", text_buf);
					break;
				case SDLK_v: {
					printf("clipboard: has=%d, ", SDL_HasClipboardText());
					print_error("SDL_HasClipboardText()");
					char *text = SDL_GetClipboardText();
					print_error("SDL_GetClipboardText()");
					printf("text=\"%s\"\n", text);
					SDL_free(text);
					break;
				} case SDLK_d:
					snprintf(text_buf, sizeof(text_buf), "bar%d", rand());
					SDL_SetPrimarySelectionText(text_buf);
					print_error("SDL_SetPrimarySelectionText()");
					printf("primselec: set_to=\"%s\"\n", text_buf);
					break;
				case SDLK_f: {
					printf("primselec: has=%d, ", SDL_HasPrimarySelectionText());
					print_error("SDL_HasPrimarySelectionText()");
					char *text = SDL_GetPrimarySelectionText();
					print_error("SDL_GetPrimarySelectionText()");
					printf("text=\"%s\"\n", text);
					SDL_free(text);
					break;
				} default:
					break;
				}
				break;
			} default: {
				break;
			}}
		}
		// create less noise with WAYLAND_DEBUG=1
		if (do_render == 0) {
			SDL_RenderPresent(renderer);
			print_error("SDL_RenderPresent()");
		}
		do_render += 1;
		usleep(12000);
	}

	SDL_DestroyRenderer(renderer);
	SDL_DestroyWindow(window);
	SDL_Quit();
	print_error("quit");
	return 0;
}
```
</details>

* Use c,v,d,f to get and set the clipboard and primary selection.
* Mark text and middle-click also in other applications.
* For wayland under x:
  * `$ mutter --wayland --no-x11 --nested`
  * `$ XDG_SESSION_TYPE=wayland SDL_VIDEODRIVER=wayland ./<path_to_test_appl_binary>`
2022-09-14 09:28:35 -07:00
Brad Smith 371735e95b Silence unused variable warning
SDL_x11dyn.c:123:17: warning: unused variable 'i' [-Wunused-variable]
            int i;
                ^
2022-08-30 12:52:01 -07:00
Ryan C. Gordon 4ca7b378c5
x11: Specify windowed dimensions when creating fullscreen windows.
This lets the window manager adjust the window correctly if it ever
leaves fullscreen mode.

Fixes #5725.
2022-08-21 11:35:14 -04:00
Sam Lantinga 8acb4e45b3 Fixed interactions between mouse capture and grab on X11
Fixes https://github.com/libsdl-org/SDL/issues/6072
2022-08-17 14:26:34 -07:00
Ryan C. Gordon b599205d0c
x11: Don't look up xinput2 devices unless we're in relative mode. 2022-08-09 09:50:55 -04:00
Ozkan Sezer 293d29b78a SDL_x11xinput2.c: fix build for macOS 2022-08-04 10:11:02 +03:00
Ryan C. Gordon 5907db56f1
x11: Attempt to deal with XInput2 devices with absolute coordinates.
This is untested!

Reference Issue #1836.
2022-08-04 02:12:46 -04:00
Shootfast 60d1944e46 SDL_video: Added SDL_GL_FLOATBUFFERS to allow Cocoa GL contexts to use EDR 2022-08-02 15:45:30 -07:00
Sam Lantinga 3a6cb7e7c5 Convert XLookupString Latin-1 text to UTF-8
Fixes bug https://github.com/libsdl-org/SDL/issues/4699
2022-08-01 10:28:29 -07:00
Cameron Gutman 8b438f7b51 keyboard: Only send SDL_KEYMAPCHANGED when the keymap actually changes 2022-07-31 14:02:28 -07:00
Sam Lantinga dbf7940541 Enable capturing raw Xinput2 touch events and use to flag global mouse state as dirty
- Touch events may be translated to mouse movement events without the normal Xinput2 raw motion events
  being sent. Not all touch events will necessarily move the mouse but this ensures we update the global
  mouse state just in case.

- Fix up some formatting

CR: saml
2022-07-27 10:31:24 -07:00
Ryan C. Gordon 20a76b0e3e
video: removed unused devindex argument from bootstrap's create method. 2022-07-26 00:19:52 -04:00
Ryan C. Gordon fdb86b8266
x11: Don't try to use XInput2 multitouch if not supported.
Fixes #5889.
2022-07-04 12:48:32 -04:00
rohlem b085c18251 make SDL_SetTextInputRect take a pointer to const
The documentation doesn't state that the argument is ever modified,
and no implementation does so currently.
This is a non-breaking change to guarantee as much to callers.
2022-07-04 09:38:01 -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
Simon McVittie 63b3b9a558 Fix some typos in diagnostic messages
Detected by Debian's packaging QA tool, Lintian.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-13 08:33:27 -07:00
Ryan C. Gordon b75cd2b36d
x11: Force window back to expected size after SDL_SetWindowBordered.
This helps if the window manager decided to let it fill the space that
an existing border was using before its removal.

Fixes #5718.
2022-06-10 14:13:07 -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
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
Ryan C. Gordon 9edd411a83
x11: send move/resize events when waiting on fullscreen change.
Otherwise we ignore the Configure/etc events when they come in because
the window is already in an identical state as far as SDL is concerned.

Fixes #5593.

May also fix:
Issue #5572.
Issue #5595.
2022-05-19 17:19:52 -04:00
Pierre Wendling 501a499180 Add clang-format on/off comments where necessary.
Comments were added in places where INDENT-ON/OFF comments are. Places
like stdlib's asm don't need it as clang-format doesn't try to indent it.
2022-05-19 01:31:29 -07:00
Sam Lantinga c7dff3a22e Attempt to get the X1 and X2 button state on X11 by using the current event state instead of direct X11 query. 2022-05-19 00:35:22 -07:00
Sam Lantinga 57130b75a9 Revert "x11: get x1/x2 button state in GetGlobalMouseState"
This reverts commit 3fcc2cb500.

Button4 and Button5 are for the scrollwheel, not the extended buttons.
I don't know of a way to query the state of the extended buttons using X11.
2022-05-19 00:31:20 -07:00
Ryan C. Gordon 2317a96c8e
x11: Use XC_top_left_corner/XC_top_right_corner instead of XC_fleur.
On Gnome (and hopefully others!), this produces something that actually
matches SDL_SYSTEM_CURSOR_SIZENWSE/SDL_SYSTEM_CURSOR_SIZENESW. On
other desktop enviroments, it probably fits the spirit better than
XC_fleur in any case.

Reference Issue #2123.
2022-05-16 10:53:01 -04:00
emily 3fcc2cb500 x11: get x1/x2 button state in GetGlobalMouseState 2022-05-03 07:12:04 -07: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
Sam Lantinga 01ef98a5d0 Don't force keyboard auto-repeat on, if the user has disabled it for some reason
Fixes https://github.com/libsdl-org/SDL/issues/2400
2022-04-26 10:19:52 -07:00
Ryan C. Gordon 53dea98309
x11: revert checks for _NET_WM_STATE_FULLSCREEN changes.
This reverts commit 85977354fb.
This reverts commit 0249df9d96.

Fixes #5572.
Reopens #5390.
2022-04-25 14:00:04 -04:00
Sam Lantinga 02225aa738 Fixed build 2022-04-18 22:57:03 -07:00