28 #include "../../idlib/precompiled.h"
29 #include "../posix/posix_public.h"
39 static bool have_xkb =
false;
42 static bool mouse_active =
false;
46 static int mx = 0, my = 0;
49 static int mouse_reset_time = 0;
50 #define MOUSE_RESET_DELAY 50
53 static int mouse_accel_numerator;
54 static int mouse_accel_denominator;
55 static int mouse_threshold;
57 static byte s_scantokey[128] = {
58 0, 0, 0, 0, 0, 0, 0, 0,
59 0, 27,
'1',
'2',
'3',
'4',
'5',
'6',
61 'q',
'w',
'e',
'r',
't',
'y',
'u',
'i',
63 'd',
'f',
'g',
'h',
'j',
'k',
'l',
';',
64 '\'',
'`',
K_SHIFT,
'\\',
'z',
'x',
'c',
'v',
72 '/',
K_ALT, 0, 0, 0, 0, 0, 0,
73 0, 0, 0, 0, 0, 0, 0, 0
91 int major_in_out, minor_in_out, opcode_rtrn, event_rtrn, error_rtrn;
94 common->
Printf(
"\n------- Input Initialization -------\n" );
97 major_in_out = XkbMajorVersion;
98 minor_in_out = XkbMinorVersion;
99 ret = XkbLibraryVersion( &major_in_out, &minor_in_out );
100 common->
Printf(
"XKB extension: compile time 0x%x:0x%x, runtime 0x%x:0x%x: %s\n", XkbMajorVersion, XkbMinorVersion, major_in_out, minor_in_out, ret ?
"OK" :
"Not compatible" );
102 ret = XkbQueryExtension(
dpy, &opcode_rtrn, &event_rtrn, &error_rtrn, &major_in_out, &minor_in_out );
104 common->
Printf(
"XKB extension present on server ( 0x%x:0x%x )\n", major_in_out, minor_in_out );
107 common->
Printf(
"XKB extension not present on server\n" );
113 common->
Printf(
"------------------------------------\n" );
119 static Cursor Sys_XCreateNullCursor( Display *display, Window root ) {
126 cursormask = XCreatePixmap(display, root, 1, 1, 1);
127 xgc.function = GXclear;
128 gc = XCreateGC(display, cursormask, GCFunction, &xgc);
129 XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
130 dummycolour.pixel = 0;
132 dummycolour.flags = 04;
133 cursor = XCreatePixmapCursor(display, cursormask, cursormask,
134 &dummycolour,&dummycolour, 0,0);
135 XFreePixmap(display,cursormask);
140 static void Sys_XInstallGrabs(
void ) {
143 XWarpPointer(
dpy, None,
win,
149 XDefineCursor(
dpy,
win, Sys_XCreateNullCursor(
dpy,
win ) );
154 GrabModeAsync, GrabModeAsync,
159 XGetPointerControl(
dpy, &mouse_accel_numerator, &mouse_accel_denominator,
162 XChangePointerControl(
dpy, True, True, 1, 1, 0 );
169 common->
Printf(
"XF86DGA not available, forcing DGA mouse off\n");
174 #if defined( ID_ENABLE_DGA )
175 XF86DGADirectVideo(
dpy, DefaultScreen(
dpy ), XF86DGADirectMouse );
176 XWarpPointer(
dpy, None,
win, 0, 0, 0, 0, 0, 0 );
186 GrabModeAsync, GrabModeAsync,
197 #if defined( ID_ENABLE_DGA )
199 common->
DPrintf(
"DGA Mouse - Disabling DGA DirectVideo\n" );
200 XF86DGADirectVideo(
dpy, DefaultScreen(
dpy ), 0 );
204 XChangePointerControl(
dpy,
true,
true, mouse_accel_numerator,
205 mouse_accel_denominator, mouse_threshold );
207 XUngrabPointer(
dpy, CurrentTime );
208 XUngrabKeyboard(
dpy, CurrentTime );
210 XWarpPointer(
dpy, None,
win,
214 XUndefineCursor(
dpy,
win );
216 mouse_active =
false;
221 #if defined( ID_DEDICATED )
237 common->
DPrintf(
"forcing in_nograb 0 while running fullscreen\n");
244 common->
DPrintf(
"in_nograb 1, forcing forcing DGA mouse off\n");
250 mouse_active =
false;
255 if ( grabIt && !mouse_active ) {
257 }
else if ( !grabIt && mouse_active ) {
274 static bool Sys_XPendingInput(
void ) {
278 if ( XEventsQueued(
dpy, QueuedAlready) ) {
283 static struct timeval zero_time;
287 x11_fd = ConnectionNumber(
dpy );
289 FD_SET( x11_fd, &fdset );
291 return XPending(
dpy );
301 static bool Sys_XRepeatPress( XEvent *event ) {
303 bool repeated =
false;
308 if ( Sys_XPendingInput() ) {
309 XPeekEvent(
dpy, &peekevent );
311 if ((peekevent.type == KeyPress) &&
312 (peekevent.xkey.keycode == event->xkey.keycode) &&
313 (peekevent.xkey.time == event->xkey.time)) {
315 XNextEvent(
dpy, &peekevent );
317 lookupRet = XLookupString( (XKeyEvent*)&peekevent, buf,
sizeof(buf), &keysym,
NULL );
340 static XKeyEvent *key_event = (XKeyEvent*)&event;
352 while ( XPending(
dpy ) ) {
353 XNextEvent(
dpy, &event );
354 switch (event.type) {
357 if (key_event->keycode > 0x7F)
360 key_event->keycode &= 0x7F;
362 printf(
"SE_KEY press %d\n", key_event->keycode);
365 lookupRet = XLookupString(key_event, buf,
sizeof(buf), &keysym,
NULL);
370 common->
DPrintf(
"WARNING: got XLookupString buffer '%s' (%d)\n", buf, strlen(buf));
373 printf(
"SE_CHAR %s\n", buf);
382 if (Sys_XRepeatPress(&event)) {
384 printf(
"RepeatPress\n");
389 if (key_event->keycode > 0x7F)
392 key_event->keycode &= 0x7F;
394 printf(
"SE_KEY release %d\n", key_event->keycode);
402 if (event.xbutton.button == 4) {
406 }
else if (event.xbutton.button == 5) {
412 if (event.xbutton.button == 1) {
414 }
else if (event.xbutton.button == 2) {
416 }
else if (event.xbutton.button == 3) {
418 }
else if (event.xbutton.button == 6) {
420 }
else if (event.xbutton.button == 7) {
423 if (b == -1 || b > 4) {
424 common->
DPrintf(
"X ButtonPress %d not supported\n", event.xbutton.button);
434 if (event.xbutton.button == 4) {
436 }
else if (event.xbutton.button == 5) {
440 if (event.xbutton.button == 1) {
442 }
else if (event.xbutton.button == 2) {
444 }
else if (event.xbutton.button == 3) {
446 }
else if (event.xbutton.button == 6) {
448 }
else if (event.xbutton.button == 7) {
451 if (b == -1 || b > 4) {
452 common->
DPrintf(
"X ButtonRelease %d not supported\n", event.xbutton.button);
465 dx =
event.xmotion.x_root;
466 dy =
event.xmotion.y_root;
491 dx = ((
int) event.xmotion.x - mwx);
492 dy = ((
int) event.xmotion.y - mwy);
496 mwx =
event.xmotion.x;
497 mwy =
event.xmotion.y;
519 XkbStateRec kbd_state;
525 if ( !have_xkb || !
dpy ) {
526 return (
unsigned char)_key;
531 XkbGetState(
dpy, XkbUseCoreKbd, &kbd_state );
534 for ( key = 0; key < 128; key++ ) {
535 if ( _key == s_scantokey[ key ] ) {
541 common->
DPrintf(
"Sys_MapCharForKey: doom key %d -> keycode failed\n", _key );
542 return (
unsigned char)_key;
545 memset( &event, 0,
sizeof( XEvent ) );
546 event.xkey.type = KeyPress;
547 event.xkey.display =
dpy;
548 event.xkey.time = CurrentTime;
549 event.xkey.keycode = key;
550 event.xkey.state = kbd_state.group << 13;
552 lookupRet = XLookupString( (XKeyEvent *)&event, buf,
sizeof( buf ), &keysym,
NULL );
553 if ( lookupRet <= 0 ) {
554 Sys_Printf(
"Sys_MapCharForKey: XLookupString key 0x%x failed\n", key );
555 return (
unsigned char)_key;
557 if ( lookupRet > 1 ) {
559 Sys_Printf(
"Sys_MapCharForKey: XLookupString returned '%s'\n", buf );
assert(prefInfo.fullscreenBtn)
void Sys_Printf(const char *msg,...)
int Sys_Milliseconds(void)
virtual void Printf(const char *fmt,...) id_attribute((format(printf
void Posix_QueEvent(sysEventType_t type, int value, int value2, int ptrLength, void *ptr)
void SetBool(const bool value)
virtual void DPrintf(const char *fmt,...) id_attribute((format(printf
virtual void AddCommand(const char *cmdName, cmdFunction_t function, int flags, const char *description, argCompletion_t argCompletion=NULL)=0