static void HandleEvents() { SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: Sys_Quit(); break; case SDL_WINDOWEVENT: window_event(&event.window); break; case SDL_KEYDOWN: case SDL_KEYUP: keyb_event(&event.key); break; case SDL_MOUSEMOTION: if (mouse_active && !SDL_GetRelativeMouseMode()) { mx = old_x - event.motion.x; my = old_y - event.motion.y; old_x = event.motion.x; old_y = event.motion.y; SDL_WarpMouseInWindow(sdl_window, glConfig.vidWidth / 2, glConfig.vidHeight / 2); } break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: mouse_button_event(&event.button); break; case SDL_MOUSEWHEEL: mouse_wheel_event(&event.wheel); break; } } }
static void raw_mouse_event( PRAWMOUSE rm ) { int i; if( rm->usButtonFlags ) { for( i = 0; i < MOUSE_BUTTONS; i++ ) { if( rm->usButtonFlags & ( 1 << ( i * 2 ) ) ) { Key_Event( K_MOUSE1 + i, qtrue, win.lastMsgTime ); } if( rm->usButtonFlags & ( 1 << ( i * 2 + 1 ) ) ) { Key_Event( K_MOUSE1 + i, qfalse, win.lastMsgTime ); } } if( rm->usButtonFlags & RI_MOUSE_WHEEL ) { mouse_wheel_event( ( short )rm->usButtonData ); } // this flag is undocumented, but confirmed to work on Win7 if( rm->usButtonFlags & 0x0800 ) { mouse_hwheel_event( ( short )rm->usButtonData ); } } if( ( rm->usFlags & (MOUSE_MOVE_RELATIVE|MOUSE_MOVE_ABSOLUTE) ) == MOUSE_MOVE_RELATIVE ) { win.mouse.mx += rm->lLastX; win.mouse.my += rm->lLastY; } }
// main window procedure STATIC LONG WINAPI Win_MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch( uMsg ) { case WM_MOUSEWHEEL: if( win.mouse.initialized == WIN_MOUSE_LEGACY ) { mouse_wheel_event( ( short )HIWORD( wParam ) ); } break; case WM_MOUSEHWHEEL: if( win.mouse.initialized == WIN_MOUSE_LEGACY ) { mouse_hwheel_event( ( short )HIWORD( wParam ) ); } break; case WM_NCMOUSEMOVE: if( win.mouse.initialized ) { // don't hide cursor IN_MouseEvent( -1, -1 ); } break; case WM_MOUSEMOVE: if( win.mouse.initialized ) { int x = ( short )LOWORD( lParam ); int y = ( short )HIWORD( lParam ); IN_MouseEvent( x, y ); } // fall through case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_MBUTTONDOWN: case WM_MBUTTONUP: case WM_XBUTTONDOWN: case WM_XBUTTONUP: if( win.mouse.initialized == WIN_MOUSE_LEGACY ) { legacy_mouse_event( wParam ); } break; case WM_HOTKEY: return FALSE; case WM_INPUT: if( wParam == RIM_INPUT && win.mouse.initialized == WIN_MOUSE_RAW ) { raw_input_event( ( HANDLE )lParam ); } break; case WM_CLOSE: PostQuitMessage( 0 ); return FALSE; case WM_ACTIVATE: Win_Activate( wParam ); break; case WM_WINDOWPOSCHANGING: if( !( win.flags & QVF_FULLSCREEN ) ) { WINDOWPOS *pos = ( WINDOWPOS * )lParam; if( !( pos->flags & SWP_NOSIZE ) ) { resizing_event( hWnd, pos ); } } break; case WM_SIZE: if( wParam == SIZE_RESTORED && !( win.flags & QVF_FULLSCREEN ) ) { int w = ( short )LOWORD( lParam ); int h = ( short )HIWORD( lParam ); win.rc.width = w; win.rc.height = h; win.mode_changed |= MODE_SIZE; } break; case WM_MOVE: if( !( win.flags & QVF_FULLSCREEN ) ) { int x = ( short )LOWORD( lParam ); int y = ( short )HIWORD( lParam ); RECT r; // adjust for non-client area get_nc_area_size( hWnd, &r ); win.rc.x = x + r.left; win.rc.y = y + r.top; win.mode_changed |= MODE_POS; } break; case WM_SYSCOMMAND: switch( wParam & 0xFFF0 ) { case SC_SCREENSAVE: return FALSE; case SC_MAXIMIZE: if( !vid_fullscreen->integer ) { VID_ToggleFullscreen(); } return FALSE; } break; case WM_KEYDOWN: case WM_SYSKEYDOWN: legacy_key_event( wParam, lParam, qtrue ); return FALSE; case WM_KEYUP: case WM_SYSKEYUP: legacy_key_event( wParam, lParam, qfalse ); return FALSE; case WM_SYSCHAR: case WM_CHAR: #if USE_CHAR_EVENTS Key_CharEvent( wParam ); #endif return FALSE; default: break; } // pass all unhandled messages to DefWindowProc return DefWindowProc( hWnd, uMsg, wParam, lParam ); }
static void IN_HandleEvents( void ) { Uint16 *wtext = NULL; SDL_PumpEvents(); SDL_Event event; while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_KEYDOWN: key_event( &event.key, true ); // Emulate copy/paste #if defined( __APPLE__ ) #define KEYBOARD_COPY_PASTE_MODIFIER KMOD_GUI #else #define KEYBOARD_COPY_PASTE_MODIFIER KMOD_CTRL #endif if( event.key.keysym.sym == SDLK_c ) { if( event.key.keysym.mod & KEYBOARD_COPY_PASTE_MODIFIER ) { Key_CharEvent( KC_CTRLC, KC_CTRLC ); } } else if( event.key.keysym.sym == SDLK_v ) { if( event.key.keysym.mod & KEYBOARD_COPY_PASTE_MODIFIER ) { Key_CharEvent( KC_CTRLV, KC_CTRLV ); } } break; case SDL_KEYUP: key_event( &event.key, false ); break; case SDL_TEXTINPUT: // SDL_iconv_utf8_ucs2 uses "UCS-2-INTERNAL" as tocode and fails to convert text on Linux // where SDL_iconv uses system iconv. So we force needed encoding directly #if SDL_BYTEORDER == SDL_LIL_ENDIAN #define UCS_2_INTERNAL "UCS-2LE" #else #define UCS_2_INTERNAL "UCS-2BE" #endif wtext = (Uint16 *)SDL_iconv_string( UCS_2_INTERNAL, "UTF-8", event.text.text, SDL_strlen( event.text.text ) + 1 ); if( wtext ) { wchar_t charkey = wtext[0]; int key = ( charkey <= 255 ) ? charkey : 0; Key_CharEvent( key, charkey ); SDL_free( wtext ); } break; case SDL_MOUSEMOTION: mouse_motion_event( &event.motion ); break; case SDL_MOUSEBUTTONDOWN: mouse_button_event( &event.button, true ); break; case SDL_MOUSEBUTTONUP: mouse_button_event( &event.button, false ); break; case SDL_MOUSEWHEEL: mouse_wheel_event( &event.wheel ); break; case SDL_QUIT: Cbuf_ExecuteText( EXEC_NOW, "quit" ); break; case SDL_WINDOWEVENT: switch( event.window.event ) { case SDL_WINDOWEVENT_SHOWN: AppActivate( true ); break; case SDL_WINDOWEVENT_HIDDEN: AppActivate( false ); break; case SDL_WINDOWEVENT_CLOSE: break; case SDL_WINDOWEVENT_FOCUS_GAINED: input_focus = true; break; case SDL_WINDOWEVENT_FOCUS_LOST: input_focus = false; break; case SDL_WINDOWEVENT_MOVED: // FIXME: move this somewhere else Cvar_SetValue( "vid_xpos", event.window.data1 ); Cvar_SetValue( "vid_ypos", event.window.data2 ); vid_xpos->modified = false; vid_ypos->modified = false; break; } break; } } }