Commit Graph

11616 Commits

Author SHA1 Message Date
Bill Currie af5d92708d [x11] Implement raw keyboard input via XInput2
UI key presses are still handled by regular X events, but in-game
"button" presses arrive via raw keyboard events. This gives transparent
handling of keyboard repeat (UI keys see repeat, game keys do not),
without messing with the server's settings (yay, that was most annoying
when it came to debugging), and the keyboard is never grabbed, so this
is a fairly user-friendly setup.

At first, I wasn't too keen on capturing them from the root window
(thinking about the user's security), but after a lot of investigation,
I found a post by Peter Hutterer
(http://who-t.blogspot.com/2011/09/whats-new-in-xi-21-raw-events.html)
commenting that root window events were added to XInput2 specifically
for games. Since application focus is tracked and unfocused key events
are dropped very early on, there's no way for code further down the
food-chain to know there even was an event, abusing the access would
require modifying the x11 input code, in which case all bets are off
anyway and any attempt at security anywhere in the code will fail,
meaning that nefarious progs code and the like shouldn't be a problem.
2021-11-23 11:39:48 +09:00
Bill Currie 0c1927d631 [x11] Remove -nomouse handling
After a lot of thought, it really doesn't make sense to have an option
to block mouse input in x11 (not grabbing or similar does make sense, of
course). Not initializing mouse input made perfect sense in DOS and even
console Linux (SVGA) what with the low level access.
2021-11-22 23:54:31 +09:00
Bill Currie c3ce12de4c [x11] Use root window for barriers
It turns out that if the barriers are set on the app window, and the app
grabs the pointer (even passively), barrier events will no longer be
sent to the app. However, creating the barriers on the root window and
the events are selected on the root window, the barrier events are sent
regardless of the grab state.
2021-11-22 15:42:22 +09:00
Bill Currie d930a49de6 [console] Close console when escape key is pressed
I should have fixed this back when I got console working with the new
input system.
2021-11-22 14:59:32 +09:00
Bill Currie bc0451634a [input] Drop unfocused evdev axis/button events
The kernel knows nothing about X11 application focus, so we need to take
care of it ourselves.

Device add/remove events are unaffected: the are always passed on.
2021-11-22 14:59:32 +09:00
Bill Currie ce8eac5ca0 [x11] Send app focus loss/gain events
Other subsystems, especially low-level input drivers, need to know when
the app has input focus. eg, as the evdev driver uses the raw stream
from the kernel, which has no idea about X application focus (in fact,
it seems the events are shared across multiple apps without any issue),
the evdev driver sees all the events thus needs to know when to drop
them.
2021-11-22 14:59:32 +09:00
Bill Currie 67483eea37 [input] Make event names easy to print
Handy for debugging and testing.
2021-11-22 14:59:32 +09:00
Bill Currie e8a7e8218e [x11] Check hit barrier is valid before releasing pointer
It turns out to be possible to get a barrier event at the same time as a
configure notify event (which rebuilds the barriers), and trying to
release the pointer at such a time results in a bad barrier error and
program crash. Thus check the event barrier against the currently
existing barriers before attempting to release the pointer.

This does mean that a better mechanism for sequencing window
repositioning and barrier creation may be required.
2021-11-22 14:59:32 +09:00
Bill Currie d8a836e9da [input] Add broadcast events for app focus gain/loss
These are for when the application itself gains or loses focus, rather
than individual event handlers.
2021-11-22 14:59:32 +09:00
Bill Currie 3ac6d2aa22 [x11] Use barriers to trap the pointer in the window
This should be a much friendlier way of "grabbing" input, though I
suspect that using raw keyboard events will result in a keyboard grab,
which is part of the reason for wanting a friendly grab.

There does seem to be a problem with the mouse sneaking out of the
top-right and bottom-left corners. I currently suspect a bug in the X
server, but further investigation is needed.
2021-11-22 14:59:27 +09:00
Bill Currie 3af078b77a [x11] Send app_window event when window moves
This is needed for getting window position info into in_x11 without
exposing more globals, and is likely to be useful for other things,
especially as it doubles as a resize event when that's eventually
supported.
2021-11-22 13:20:13 +09:00
Bill Currie 52c5f0545b [input] Add broadcast event for application window changes
This is the first step in the long-sought goal of allowing the window
size to change, but is required for passing on getting window position
and size information (though size is in viddef, it makes sense to pass
both together).
2021-11-22 13:20:13 +09:00
Bill Currie f5b8fb0220 [build] Relax autoconf version requirement
It seems 2.71 only made things we use deprecated, and the new stuff was
at least in 2.69.
2021-11-22 07:41:16 +09:00
Bill Currie 4391b87d04 [x11] Grab focus when the pointer enters the window
This is necessary in focus-follows-mouse environments (at least for
openbox, but it wouldn't surprise me if most other WMs behave the same
way) because the WMs don't set focus when the pointer is grabbed (which
XInput does before the WM sees the enter event). This is especially
important when the window is fullscreen on a multi-monitor setup as
there is no border to *maybe* catch the mouse before it enters the
window.
2021-11-21 23:42:33 +09:00
Bill Currie a32f83d50f whitespace 2021-11-21 23:42:33 +09:00
Bill Currie e45d19835c [x11] Add initial support for XInput2
Right now, only raw pointer motion and button events are handled, and
the mouse escapes the window, and there are some issues with focus in
focus-follows-mouse environments. However, this should be a much nicer
setup than DGA.
2021-11-21 23:42:33 +09:00
Bill Currie 4944c40f86 [x11] Remove the magic number for mouse buttons
The current limit is still 32. Dealing with it properly will take some
rather advanced messing with XInput, and will be necessary assuming
non-XInput support is continued.
2021-11-21 22:16:08 +09:00
Bill Currie 26a1f66b4e [x11] Split up in_x11_init into three stages
There's now IN_X11_Preinit, IN_X11_Postinit (both for want of better
names), and in_x11_init. The first two are for taking care of
initialization that needs to be done before window creation and between
window creation and mapping (ie, are very specific to X11 stuff) while
in_x11_init takes care of the setup for the input system. This proved
necessary in my XInput experimentation: a passive enter grab takes
effect only when the pointer enters the window, thus setting up the grab
with the pointer already in the window has no effect until the pointer
leaves the window and returns.
2021-11-21 21:22:11 +09:00
Bill Currie 95becc5c05 [x11] Add some braces around an if block 2021-11-21 21:16:55 +09:00
Bill Currie fe2dd013be [x11] Clean out some unnecessary includes 2021-11-21 21:16:55 +09:00
Bill Currie 8988008ad6 [x11] Don't mess with the mouse when going fullscreen
This was always a horrible hack just to get the screen centered on the
window back when we were doing fullscreen badly. With my experiments
with XInput, it has proven to be a liability (I'd forgotten it was even
there until it started imposing a 2s delay to QF's startup).
2021-11-21 20:59:49 +09:00
Bill Currie 925a55f6cc [input] Allow drivers to initialize cvars early
Input driver can now have an optional init_cvars function. This allows
them to create all their cvars before the actual init pass thus avoiding
some initialization order interdependency issues (in this case, fixing a
segfault when starting x11 clients fullscreen due to the in_dga cvar not
existing yet).
2021-11-21 11:33:58 +09:00
Bill Currie 799d247e1a [build] Fix which obsolete warning
bootstrap uses sh, so command should always be a thing.
2021-11-20 14:26:33 +09:00
Bill Currie ba8da88f56 [build] Update for autoconf 2.71
Only because I didn't appreciate the warnings about things being
obsolete.
2021-11-20 12:54:05 +09:00
Bill Currie 88b3965794 [vulkan] Pick up vulkan.h from correct location
Well... it could be done better, but this works for now assuming it's in
/usr/include (and it's correct for mxe builts). Does need proper
autoconfiscation, though.
2021-11-19 22:36:19 +09:00
Bill Currie e080bb333c [win] Update windows input for new binding system
Seems to work nicely for keyboard (though key bindings are not
cross-platform). Mouse not tested yet, and I expect there are problems
with it for absolute inputs (yay mouse warp :P).
2021-11-19 13:52:40 +09:00
Bill Currie b1d388563e [input] Don't specify ld flags for evdev lib
libtool gets confused if the convenience library has normal library
linker flags and fails to properly relink the main library when
installing.
2021-11-19 12:08:58 +09:00
Bill Currie 83abdfa7b9 [qw] Rmove include of rpc/types.h
I have no idea why it was necessary, and certainly should not be now as
any such portability issues should be tucked away such that the client
code never sees such.
2021-11-19 11:57:16 +09:00
Bill Currie aa7fe66d9d [gamecode] Check resmap return before memset
New gcc (11) Caught another issue (only one this time, which is nice).
2021-11-19 11:55:32 +09:00
Bill Currie 48ecfcf411 [cexpr] Fix a naming issue with uint
I didn't notice that uint is defined somewhere on Linux... until I tried
compiling for windows (not defined). Use a define to keep the cast
function naming nice.
2021-11-19 08:58:02 +09:00
Bill Currie b892ce637a [input] Nuke IN_Move from orbit
gotta be sure :)

On a serious note, it was always a problem in that it had
client-specific code and concepts embedded in the libraries.
2021-11-19 08:58:02 +09:00
Bill Currie 15dbe443b0 [nq] Hook up the new input and config systems
This gets nq in line with qw (and highlights more places than need
merging, *sigh*)
2021-11-18 15:27:44 +09:00
Bill Currie 793914718f [x11] Implement input names
Mouse axis and button names are handled internally (and thus
case-insensitive).

Key names are handled by X11. Case-sensitivity is currently determined
by Xlib.
2021-11-18 13:01:33 +09:00
Bill Currie 84f746dab2 [input] Allow button and axis inputs to be named
keyhelp provides the input name if it is known, and in_bind tries to use
the provided input name if not a number. Case sensitivity for name
lookups is dependent on the input driver.
2021-11-18 12:59:18 +09:00
Bill Currie f4c521d51d [input] Move in_devbindings_t definition
In the end, it doesn't need to be public, so move it into in_binding.c
2021-11-18 11:17:04 +09:00
Bill Currie fbcb22d41a [qw] Sort out move axis directions and names
Everything is set up so default recipes work as expected (by me) for a
3Dconnexion SpaceNavigator:
    translation axes move quakeguy in the direction the puck is moved
    tilting the puck forward pitches forward (look down)
    tilting the puck to the left rolls to the left
    twisting the puck clockwise (looked at from the top) turns quakeguy
    to the right.

This does mean that the default pitch motion for a regular mouse is now
push forward to pitch forward (look down) (inverted from before).

Mouse scaling is out (too small), but that's because in_amp etc are
ignored for now (thinking about how to integrate cvars with axis
recipes). Joystick input will be the same.
2021-11-16 20:26:19 +09:00
Bill Currie c3fa0d6464 [input] Fix incorrect arg count in in_unbind_f
Yay for copying and editing code :P
2021-11-16 20:14:33 +09:00
Bill Currie 1381932552 [input] Fix imt block management
Reset the blocks completely when loading configs and fix a leftover from
when I thought I'd expose the block numbers to bindings but then changed
my mind to simply track the base binding.
2021-11-16 20:12:53 +09:00
Bill Currie 111e5d923e [cexpr] Support casting to double
For int, uint and float, also add uint to float (not that it will do any
good for values over 16M).
2021-11-16 19:59:47 +09:00
Bill Currie 73ab33ba97 [input] Actually return the button in IN_FindButton
Returning the wrapper object makes for some weird behaviour.
2021-11-16 16:33:53 +09:00
Bill Currie 7739972f19 [x11] Block raw inputs if cooked inputs are handled
The cooked inputs (ie_key, ie_mouse) are intended for UI interaction, so
generally should have priority over the raw events, which are intended
for game interaction.
2021-11-16 12:55:55 +09:00
Bill Currie b8baa04b2e [input] Split binding event handler
There's now an internal event handler for taking care of device addition
and removal, and a public event handler for dealing with device input
events in various contexts In particular, so the clients can check for
the escape key.
2021-11-16 12:54:23 +09:00
Bill Currie 1868fe7404 [qw] Save and load cvars before input config
Saving is not so important, but for loading, while the input system
doesn't make much use of cvars at this stage, it makes sense for them to
be loaded before the input system configuration is loaded.
2021-11-16 08:48:35 +09:00
Bill Currie b80c19bd77 [util] Save and load cvars to/from plist configs
Other than some backwards compatibility, this completes the
configuration updates for now.
2021-11-15 22:04:29 +09:00
Bill Currie 8cf0d00eda [qw] Switch quakeforge.cfg to property list format
Cvars aren't handled yet, but input configuration is. Seems to work :)
2021-11-14 10:32:35 +09:00
Bill Currie fede9125e1 [input] Save/load config to/from plist configs
While the console command line is quite good for setting everything up,
the devices being bound do need to be present when the commands are
executed (due to needing extra data provided by the devices). Thus
property lists that store the extra data (button and axis counts, device
names/ids, connection names, etc) seems to be the best solution.
2021-11-14 10:17:05 +09:00
Bill Currie 7c9f3a3b09 [util] Expose the quakerc check function
qargs probably needs to go away. It certainly needs to be rethought. For
now, this is good enough to get qw working with plist-based
quakeforge.cfg
2021-11-14 10:12:14 +09:00
Bill Currie 6a9e5f4970 [input] Fix incorrect placement of pure attribute
Should be on the prototype, not definition (for public functions).
2021-11-14 10:10:39 +09:00
Bill Currie 08bf3a6b8e [gamecode] Fix incorrect return in PR_RESRESET
I think it's a holdover from before switching the resmap macros to be
usable in larger functions. I'm surprised it took this long to run into.
2021-11-14 10:09:10 +09:00
Bill Currie 08083b8630 [input] Use double for recipe float values
Recipes themselves still use float, but using double in the cexpr values
allows bare floating point numbers (which parse as double) to be used,
making the bind command line a little more user-friendly.
2021-11-12 08:09:41 +09:00