void IN_DeactivateMouse( void ) { if (!mouse_avail || !dpy || !win) return; if (mouse_active) { uninstall_grabs(); mouse_active = qfalse; } }
void IN_DeactivateMouse( void ) { if (!mouse_avail || !screen) return; if (mouse_active) { if (!in_nograb->value) uninstall_grabs(); mouse_active = qfalse; } }
void IN_Shutdown( void ) { if( !input_inited ) return; uninstall_grabs(); #ifdef WSW_EVDEV evdev_closedevices(); #endif input_inited = qfalse; }
void IN_DeactivateMouse( void ) { if ( !mouse_avail || !dpy || !win ) { return; } if ( mouse_active ) { if ( !in_nograb->value ) { uninstall_grabs(); } else if ( in_dgamouse->value ) { // force dga mouse to 0 if using nograb ri.Cvar_Set( "in_dgamouse", "0" ); } mouse_active = qfalse; } }
void IN_Activate( qboolean active ) { if( !input_inited ) return; assert( x11display.dpy && x11display.win ); if( active ) { install_grabs(); } else { uninstall_grabs(); } }
void IN_DeactivateMouse( void ) { if (!mouse_avail || !eglDisplay) return; if (mouse_active) { // TODO: comment this first // zongzong.yan #if 0 if (!in_nograb->value) uninstall_grabs(); else if (in_dgamouse->value) // force dga mouse to 0 if using nograb #endif ri.Cvar_Set("in_dgamouse", "0"); mouse_active = qfalse; } }
void VID_Shutdown(void) { if (!ctx) return; uninstall_grabs(); RestoreHWGamma(); #ifdef USE_VMODE if (x_disp) { glXDestroyContext(x_disp, ctx); if (x_win) XDestroyWindow(x_disp, x_win); if (vidmode_active) XF86VidModeSwitchToMode(x_disp, scrnum, vidmodes[0]); XCloseDisplay(x_disp); vidmode_active = false; } #else glXDestroyContext(x_disp, ctx); #endif }
void IN_Frame( void ) { if( !input_inited ) return; if( !mapped || ( ( x11display.features.wmStateFullscreen || !Cvar_Value( "vid_fullscreen" ) ) && ( !focus || ( ( cls.key_dest == key_console ) && !in_grabinconsole->integer ) ) ) ) { if( input_active ) IN_Activate( qfalse ); } else { if( !input_active ) IN_Activate( qtrue ); } HandleEvents(); if( input_active && in_dgamouse->modified ) { uninstall_grabs(); install_grabs(); } }
static void HandleEvents( void ) { int b; int key; XEvent event; qboolean dowarp = qfalse; char *p; int dx, dy; int t; if ( !dpy ) { return; } while ( XPending( dpy ) ) { XNextEvent( dpy, &event ); switch ( event.type ) { case KeyPress: p = XLateKey( &event.xkey, &key ); if ( key ) { Sys_QueEvent( 0, SE_KEY, key, qtrue, 0, NULL ); } if ( p ) { while ( *p ) { Sys_QueEvent( 0, SE_CHAR, *p++, 0, 0, NULL ); } } break; case KeyRelease: // bk001206 - handle key repeat w/o XAutRepatOn/Off // also: not done if console/menu is active. // From Ryan's Fakk2. // see game/q_shared.h, KEYCATCH_* . 0 == in 3d game. if ( cls.keyCatchers == 0 ) { // FIXME: KEYCATCH_NONE if ( repeated_press( &event ) == qtrue ) { continue; } } // if XLateKey( &event.xkey, &key ); Sys_QueEvent( 0, SE_KEY, key, qfalse, 0, NULL ); break; case MotionNotify: if ( mouse_active ) { #ifdef PANDORA //broken on Pandora if (0) { #else if ( dgamouse ) { #endif if ( abs( event.xmotion.x_root ) > 1 ) { mx += event.xmotion.x_root * 2; } else { mx += event.xmotion.x_root; } if ( abs( event.xmotion.y_root ) > 1 ) { my += event.xmotion.y_root * 2; } else { my += event.xmotion.y_root; } t = Sys_Milliseconds(); if ( t - mouseResetTime > MOUSE_RESET_DELAY ) { Sys_QueEvent( t, SE_MOUSE, mx, my, 0, NULL ); } mx = my = 0; } else { // If it's a center motion, we've just returned from our warp if ( event.xmotion.x == glConfig.vidWidth / 2 && event.xmotion.y == glConfig.vidHeight / 2 ) { mwx = glConfig.vidWidth / 2; mwy = glConfig.vidHeight / 2; t = Sys_Milliseconds(); if ( t - mouseResetTime > MOUSE_RESET_DELAY ) { Sys_QueEvent( t, SE_MOUSE, mx, my, 0, NULL ); } mx = my = 0; break; } dx = ( (int)event.xmotion.x - mwx ); dy = ( (int)event.xmotion.y - mwy ); if ( abs( dx ) > 1 ) { mx += dx * 2; } else { mx += dx; } if ( abs( dy ) > 1 ) { my += dy * 2; } else { my += dy; } mwx = event.xmotion.x; mwy = event.xmotion.y; dowarp = qtrue; } } break; case ButtonPress: if ( event.xbutton.button == 4 ) { Sys_QueEvent( 0, SE_KEY, K_MWHEELUP, qtrue, 0, NULL ); } else if ( event.xbutton.button == 5 ) { Sys_QueEvent( 0, SE_KEY, K_MWHEELDOWN, qtrue, 0, NULL ); } else { // NOTE TTimo there seems to be a weird mapping for K_MOUSE1 K_MOUSE2 K_MOUSE3 .. b = -1; if ( event.xbutton.button == 1 ) { b = 0; // K_MOUSE1 } else if ( event.xbutton.button == 2 ) { b = 2; // K_MOUSE3 } else if ( event.xbutton.button == 3 ) { b = 1; // K_MOUSE2 } else if ( event.xbutton.button == 6 ) { b = 3; // K_MOUSE4 } else if ( event.xbutton.button == 7 ) { b = 4; // K_MOUSE5 } ; Sys_QueEvent( 0, SE_KEY, K_MOUSE1 + b, qtrue, 0, NULL ); } break; case ButtonRelease: if ( event.xbutton.button == 4 ) { Sys_QueEvent( 0, SE_KEY, K_MWHEELUP, qfalse, 0, NULL ); } else if ( event.xbutton.button == 5 ) { Sys_QueEvent( 0, SE_KEY, K_MWHEELDOWN, qfalse, 0, NULL ); } else { b = -1; if ( event.xbutton.button == 1 ) { b = 0; } else if ( event.xbutton.button == 2 ) { b = 2; } else if ( event.xbutton.button == 3 ) { b = 1; } else if ( event.xbutton.button == 6 ) { b = 3; // K_MOUSE4 } else if ( event.xbutton.button == 7 ) { b = 4; // K_MOUSE5 } ; Sys_QueEvent( 0, SE_KEY, K_MOUSE1 + b, qfalse, 0, NULL ); } break; case CreateNotify: win_x = event.xcreatewindow.x; win_y = event.xcreatewindow.y; break; case ConfigureNotify: win_x = event.xconfigure.x; win_y = event.xconfigure.y; break; } } if ( dowarp ) { XWarpPointer( dpy,None,win,0,0,0,0, ( glConfig.vidWidth / 2 ),( glConfig.vidHeight / 2 ) ); } } void IN_ActivateMouse( void ) { if ( !mouse_avail || !dpy || !win ) { return; } if ( !mouse_active ) { install_grabs(); mouse_active = qtrue; } } void IN_DeactivateMouse( void ) { if ( !mouse_avail || !dpy || !win ) { return; } if ( mouse_active ) { uninstall_grabs(); mouse_active = qfalse; } } /*****************************************************************************/ static qboolean signalcaught = qfalse;; void Sys_Exit( int ); // bk010104 - abstraction static void signal_handler( int sig ) { // bk010104 - replace this... (NOTE TTimo huh?) if ( signalcaught ) { printf( "DOUBLE SIGNAL FAULT: Received signal %d, exiting...\n", sig ); Sys_Exit( 1 ); // bk010104 - abstraction } signalcaught = qtrue; printf( "Received signal %d, exiting...\n", sig ); GLimp_Shutdown(); // bk010104 - shouldn't this be CL_Shutdown Sys_Exit( 0 ); // bk010104 - abstraction NOTE TTimo send a 0 to avoid DOUBLE SIGNAL FAULT } static void InitSig( void ) { signal( SIGHUP, signal_handler ); signal( SIGQUIT, signal_handler ); signal( SIGILL, signal_handler ); signal( SIGTRAP, signal_handler ); signal( SIGIOT, signal_handler ); signal( SIGBUS, signal_handler ); signal( SIGFPE, signal_handler ); signal( SIGSEGV, signal_handler ); signal( SIGTERM, signal_handler ); }
static void GetEvent(void) { XEvent event; int b; qbool grab_input; if (!x_disp) return; XNextEvent(x_disp, &event); switch (event.type) { case KeyPress: case KeyRelease: Key_Event(XLateKey(&event.xkey), event.type == KeyPress); break; case MotionNotify: if (input_grabbed) { #ifdef USE_DGA if (dgamouse) { mouse_x += event.xmotion.x_root; mouse_y += event.xmotion.y_root; } else #endif { mouse_x = (float) ((int)event.xmotion.x - (int)(vid.width/2)); mouse_y = (float) ((int)event.xmotion.y - (int)(vid.height/2)); /* move the mouse to the window center again */ XSelectInput(x_disp, x_win, X_MASK & ~PointerMotionMask); XWarpPointer(x_disp, None, x_win, 0, 0, 0, 0, (vid.width/2), (vid.height/2)); XSelectInput(x_disp, x_win, X_MASK); } } break; case ButtonPress: b=-1; if (event.xbutton.button == 1) b = 0; else if (event.xbutton.button == 2) b = 2; else if (event.xbutton.button == 3) b = 1; if (b>=0) Key_Event(K_MOUSE1 + b, true); break; case ButtonRelease: b=-1; if (event.xbutton.button == 1) b = 0; else if (event.xbutton.button == 2) b = 2; else if (event.xbutton.button == 3) b = 1; if (b>=0) Key_Event(K_MOUSE1 + b, false); break; } #ifdef USE_VMODE grab_input = _windowed_mouse.value != 0 || vidmode_active; #else grab_input = _windowed_mouse.value != 0; #endif if (grab_input && !input_grabbed) { /* grab the pointer */ install_grabs(); } else if (!grab_input && input_grabbed) { /* ungrab the pointer */ uninstall_grabs(); } }
static void HandleEvents( void ) { XEvent event; qboolean dowarp = qfalse, was_focused = focus; int mwx = x11display.win_width / 2; int mwy = x11display.win_height / 2; char *p; int key = 0; int time = 0; assert( x11display.dpy && x11display.win ); #ifdef WSW_EVDEV if( mouse_active && m_evdev_num ) { evdev_read(); } else #endif if( mouse_active && !dgamouse ) { int root_x, root_y, win_x, win_y; unsigned int mask; Window root, child; if( XQueryPointer( x11display.dpy, x11display.win, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask ) ) { mx += ( (int)win_x - mwx ); my += ( (int)win_y - mwy ); mwx = win_x; mwy = win_y; if( mx || my ) dowarp = qtrue; if( ignore_one ) { mx = my = 0; ignore_one = qfalse; } } } while( XPending( x11display.dpy ) ) { XNextEvent( x11display.dpy, &event ); switch( event.type ) { case KeyPress: time = Sys_XTimeToSysTime(event.xkey.time); p = XLateKey( &event.xkey, &key ); if( key ) Key_Event( key, qtrue, time ); while ( p && *p ) { qwchar wc = Q_GrabWCharFromUtf8String( (const char **)&p ); Key_CharEvent( key, wc ); } break; case KeyRelease: if( repeated_press( &event ) ) break; // don't send release events when repeating time = Sys_XTimeToSysTime(event.xkey.time); XLateKey( &event.xkey, &key ); Key_Event( key, event.type == KeyPress, time ); break; case MotionNotify: #ifdef WSW_EVDEV if( mouse_active && dgamouse && !m_evdev_num ) #else if( mouse_active && dgamouse ) #endif { mx += event.xmotion.x_root; my += event.xmotion.y_root; if( ignore_one ) { mx = my = 0; ignore_one = qfalse; } } break; case ButtonPress: if( ( cls.key_dest == key_console ) && !in_grabinconsole->integer ) break; #ifdef WSW_EVDEV if( m_evdev_num ) break; #endif time = Sys_XTimeToSysTime(event.xkey.time); if( event.xbutton.button == 1 ) Key_MouseEvent( K_MOUSE1, 1, time ); else if( event.xbutton.button == 2 ) Key_MouseEvent( K_MOUSE3, 1, time ); else if( event.xbutton.button == 3 ) Key_MouseEvent( K_MOUSE2, 1, time ); else if( event.xbutton.button == 4 ) Key_Event( K_MWHEELUP, 1, time ); else if( event.xbutton.button == 5 ) Key_Event( K_MWHEELDOWN, 1, time ); else if( event.xbutton.button >= 6 && event.xbutton.button <= 10 ) Key_MouseEvent( K_MOUSE4+event.xbutton.button-6, 1, time ); break; case ButtonRelease: if( ( cls.key_dest == key_console ) && !in_grabinconsole->integer ) break; #ifdef WSW_EVDEV if( m_evdev_num ) break; #endif time = Sys_XTimeToSysTime(event.xkey.time); if( event.xbutton.button == 1 ) Key_MouseEvent( K_MOUSE1, 0, time ); else if( event.xbutton.button == 2 ) Key_MouseEvent( K_MOUSE3, 0, time ); else if( event.xbutton.button == 3 ) Key_MouseEvent( K_MOUSE2, 0, time ); else if( event.xbutton.button == 4 ) Key_Event( K_MWHEELUP, 0, time ); else if( event.xbutton.button == 5 ) Key_Event( K_MWHEELDOWN, 0, time ); else if( event.xbutton.button >= 6 && event.xbutton.button <= 10 ) Key_MouseEvent( K_MOUSE4+event.xbutton.button-6, 0, time ); break; case FocusIn: if( x11display.ic ) XSetICFocus(x11display.ic); if( !focus ) { focus = qtrue; } break; case FocusOut: if( x11display.ic ) XUnsetICFocus(x11display.ic); if( focus ) { Key_ClearStates(); focus = qfalse; } break; case ClientMessage: if( event.xclient.data.l[0] == x11display.wmDeleteWindow ) Cbuf_ExecuteText( EXEC_NOW, "quit" ); break; case MapNotify: mapped = qtrue; if( x11display.modeset ) { if ( x11display.dpy && x11display.win ) { XSetInputFocus( x11display.dpy, x11display.win, RevertToPointerRoot, CurrentTime ); x11display.modeset = qfalse; } } if( input_active ) { uninstall_grabs(); install_grabs(); } break; case ConfigureNotify: VID_AppActivate( qtrue, qfalse ); break; case PropertyNotify: if( event.xproperty.window == x11display.win ) { if ( event.xproperty.atom == x11display.wmState ) { qboolean was_minimized = minimized; _X11_CheckWMSTATE(); if( minimized != was_minimized ) { // FIXME: find a better place for this?.. CL_SoundModule_Activate( !minimized ); } } } break; } } if( dowarp ) { XWarpPointer( x11display.dpy, None, x11display.win, 0, 0, 0, 0, x11display.win_width/2, x11display.win_height/2 ); } // set fullscreen or windowed mode upon focus in/out events if: // a) lost focus in fullscreen -> windowed // b) received focus -> fullscreen if a) if( ( focus != was_focused ) ) { if( x11display.features.wmStateFullscreen ) { if( !focus && Cvar_Value( "vid_fullscreen" ) ) { go_fullscreen_on_focus = qtrue; Cbuf_ExecuteText( EXEC_APPEND, "vid_fullscreen 0\n" ); } else if( focus && go_fullscreen_on_focus ) { go_fullscreen_on_focus = qfalse; Cbuf_ExecuteText( EXEC_APPEND, "vid_fullscreen 1\n" ); } } } }