void Sys_InitConsole (void) { #ifdef QHOST int t; // initialize the windows dedicated server console if needed tevent = CreateEvent(NULL, false, false, NULL); if (!tevent) Sys_Error ("Couldn't create event"); #endif houtput = GetStdHandle (STD_OUTPUT_HANDLE); hinput = GetStdHandle (STD_INPUT_HANDLE); // LordHavoc: can't check cls.state because it hasn't been initialized yet // if (cls.state == ca_dedicated) if (COM_CheckParm("-dedicated")) { //if ((houtput == 0) || (houtput == INVALID_HANDLE_VALUE)) // LordHavoc: on Windows XP this is never 0 or invalid, but hinput is invalid { if (!AllocConsole ()) Sys_Error ("Couldn't create dedicated server console (error code %x)", (unsigned int)GetLastError()); houtput = GetStdHandle (STD_OUTPUT_HANDLE); hinput = GetStdHandle (STD_INPUT_HANDLE); } if ((houtput == 0) || (houtput == INVALID_HANDLE_VALUE)) Sys_Error ("Couldn't create dedicated server console"); #ifdef QHOST #ifdef _WIN64 #define atoi _atoi64 #endif // give QHOST a chance to hook into the console if ((t = COM_CheckParm ("-HFILE")) > 0) { if (t < com_argc) hFile = (HANDLE)atoi (com_argv[t+1]); } if ((t = COM_CheckParm ("-HPARENT")) > 0) { if (t < com_argc) heventParent = (HANDLE)atoi (com_argv[t+1]); } if ((t = COM_CheckParm ("-HCHILD")) > 0) { if (t < com_argc) heventChild = (HANDLE)atoi (com_argv[t+1]); } InitConProc (hFile, heventParent, heventChild); #endif } // because sound is off until we become active S_BlockSound (); }
static void VID_AppFocusChanged(qboolean windowIsActive) { if (vid_activewindow != windowIsActive) { vid_activewindow = windowIsActive; if (!vid_activewindow) VID_RestoreSystemGamma(); } if (windowIsActive || !snd_mutewhenidle.integer) { if (!sound_active) { S_UnblockSound (); sound_active = true; } } else { if (sound_active) { S_BlockSound (); sound_active = false; } } }
void AppActivate(BOOL fActive, BOOL minimize) /**************************************************************************** * * Function: AppActivate * Parameters: fActive - True if app is activating * * Description: If the application is activating, then swap the system * into SYSPAL_NOSTATIC mode so that our palettes will display * correctly. * ****************************************************************************/ { static BOOL sound_active; ActiveApp = fActive; Minimized = minimize; // enable/disable sound on focus gain/loss if (!ActiveApp && sound_active) { S_BlockSound (); sound_active = false; } else if (ActiveApp && !sound_active) { S_UnblockSound (); sound_active = true; } if (fActive) { IN_ActivateMouse (); IN_HideMouse (); } else { IN_DeactivateMouse (); IN_ShowMouse (); } }
/****************************************************************************** * * Function: AppActivate * Parameters: fActive - True if app is activating * * Description: If the application is activating, then swap the system * into SYSPAL_NOSTATIC mode so that our palettes will display * correctly. * ******************************************************************************/ void AppActivate(BOOL fActive, BOOL minimize) { static BOOL sound_active; extern cvar_t sys_inactivesound; ActiveApp = fActive; Minimized = minimize; // enable/disable sound on focus gain/loss if (!ActiveApp && sound_active && !sys_inactivesound.value) { S_BlockSound (); sound_active = false; } else if (ActiveApp && !sound_active) { S_UnblockSound (); sound_active = true; } if ( fActive ) { // if ( glConfig.isFullscreen /* || ( !glConfig.isFullscreen && _windowed_mouse.value && key_dest == key_game ) */ ) { IN_ActivateMouse (); IN_HideMouse (); } } else { // if ( glConfig.isFullscreen /* || ( !glConfig.isFullscreen && _windowed_mouse.value ) */ ) { IN_DeactivateMouse (); IN_ShowMouse (); } } // FIXME: where we must put this, before mouse activeate/deactivate or after? WG_AppActivate(fActive, minimize); }
/* =========== IN_ProcessEvents =========== */ void IN_ProcessEvents (void) { // handle the mouse state when windowed if that's changed if (!vidmode_fullscreen) { if ( key_dest == key_game && !mouse_grab_active && vid_activewindow ) // if ( key_dest != key_console && !mouse_grab_active && vid_activewindow ) { IN_GrabMouse (); } else if ( key_dest != key_game && mouse_grab_active ) // else if ( key_dest == key_console && mouse_grab_active ) { IN_UngrabMouse (); } } // getting and handle events { XEvent x_event; static qboolean active = true; if (!x_disp) return; while (XPending(x_disp)) { XNextEvent(x_disp, &x_event); switch (x_event.type) { case KeyPress: // key pressed case KeyRelease: // key released Key_Event(XLateKey(&x_event.xkey), x_event.type == KeyPress); break; case MotionNotify: // mouse moved if (mouse_grab_active) { if (dga_mouse_active) { mouse_x += (float)x_event.xmotion.x_root; mouse_y += (float)x_event.xmotion.y_root; } else { mouse_x = (float)x_event.xmotion.x - (float)(vid.width / 2); mouse_y = (float)x_event.xmotion.y - (float)(vid.height / 2); if (mouse_x || mouse_y) // do warp { // move the mouse to the window center again XWarpPointer(x_disp, None, x_win, 0, 0, 0, 0, vid.width / 2, vid.height / 2); } } } break; case ButtonPress: // mouse button pressed case ButtonRelease: // mouse button released switch (x_event.xbutton.button) { case 1: Key_Event (K_MOUSE1, x_event.type == ButtonPress); break; case 2: Key_Event (K_MOUSE3, x_event.type == ButtonPress); break; case 3: Key_Event (K_MOUSE2, x_event.type == ButtonPress); break; case 4: Key_Event (K_MWHEELUP, x_event.type == ButtonPress); break; case 5: Key_Event (K_MWHEELDOWN, x_event.type == ButtonPress); break; case 6: Key_Event (K_MOUSE4, x_event.type == ButtonPress); break; case 7: Key_Event (K_MOUSE5, x_event.type == ButtonPress); break; case 8: Key_Event (K_MOUSE6, x_event.type == ButtonPress); break; case 9: Key_Event (K_MOUSE7, x_event.type == ButtonPress); break; case 10: Key_Event (K_MOUSE8, x_event.type == ButtonPress); break; } break; case CreateNotify: // window created window_x = x_event.xcreatewindow.x; window_y = x_event.xcreatewindow.y; window_width = x_event.xcreatewindow.width; window_height = x_event.xcreatewindow.height; break; case ConfigureNotify: // window changed size/location window_x = x_event.xconfigure.x; window_y = x_event.xconfigure.y; window_width = x_event.xconfigure.width; window_height = x_event.xconfigure.height; // check for resize if (!vidmode_fullscreen) { if (window_width < 320) window_width = 320; if (window_height < 200) window_height = 200; vid.width = window_width; vid.height = window_height; vid.conwidth = vid.width; vid.conheight = vid.height; vid.recalc_refdef = true; // force a surface cache flush } break; case DestroyNotify: // window has been destroyed Sys_Quit (0); break; case ClientMessage: // window manager messages if ((x_event.xclient.format == 32) && ((unsigned int)x_event.xclient.data.l[0] == wm_delete_window_atom)) Sys_Quit (0); break; case MapNotify: // window restored case UnmapNotify: // window iconified/rolledup/whatever vid_hiddenwindow = (x_event.type == UnmapNotify); case FocusIn: // window is now the input focus case FocusOut: // window is no longer the input focus switch (x_event.xfocus.mode) { case NotifyNormal: case NotifyGrab: case NotifyUngrab: vid_activewindow = (x_event.type == FocusIn); break; } if(vidmode_fullscreen) { if(x_event.type == MapNotify) { // set our video mode XF86VidModeSwitchToMode(x_disp, scrnum, &game_vidmode); // move the viewport to top left XF86VidModeSetViewPort(x_disp, scrnum, 0, 0); } else if(x_event.type == UnmapNotify) { // set our video mode XF86VidModeSwitchToMode(x_disp, scrnum, &init_vidmode); } } else //if (!vidmode_fullscreen) { // enable/disable sound, set/restore gamma and grab/ungrab keyb // on focus gain/loss if (vid_activewindow && !vid_hiddenwindow && !active) { S_UnblockSound (); S_ClearBuffer (); VID_Gamma_Set (); IN_GrabKeyboard(); active = true; } else if (active) { S_BlockSound (); S_ClearBuffer (); VID_Gamma_Restore (); IN_UngrabKeyboard(); active = false; } } // fix the leftover Alt from any Alt-Tab or the like that switched us away Key_ClearStates (); break; case EnterNotify: // mouse entered window case LeaveNotify: // mouse left window vid_notifywindow = (x_event.type == EnterNotify); break; } } } }
void IN_SendKeyEvents (void) { struct IntuiMessage *intuimsg; struct InputEvent *inputev; int sym, state, code; if (!window) return;/* dedicated server? */ while ((intuimsg = (struct IntuiMessage *) GetMsg(window->UserPort))) { switch (intuimsg->Class) { case IDCMP_ACTIVEWINDOW: S_UnblockSound(); break; case IDCMP_INACTIVEWINDOW: S_BlockSound(); break; case IDCMP_CLOSEWINDOW: CL_Disconnect (); Sys_Quit (); break; } ReplyMsg((struct Message *)intuimsg); } while ((inputev = IN_GetNextEvent())) { sym = 0; code = inputev->ie_Code & ~IECODE_UP_PREFIX; state = !(inputev->ie_Code & IECODE_UP_PREFIX); if (inputev->ie_Class == IECLASS_RAWKEY) { if (!Key_IsGameKey()) { UBYTE bufascii; if (KeymapBase && MapRawKey(inputev, (STRPTR) &bufascii, sizeof(bufascii), NULL) > 0) { //Con_Printf("%d\n", bufascii); sym = (bufascii == 8) ? K_BACKSPACE : bufascii; } } if (!sym && code < MAX_KEYCONV) sym = keyconv[code]; //Con_Printf("rawkey code %d sym %d state %d\n", code, sym, state); } else if (inputev->ie_Class == IECLASS_RAWMOUSE) { switch (code) { case IECODE_LBUTTON: sym = K_MOUSE1; break; case IECODE_RBUTTON: sym = K_MOUSE2; break; case IECODE_MBUTTON: sym = K_MOUSE3; break; } //Con_Printf("rawmouse code %d sym %d state %d\n", code, sym, state); } else if (inputev->ie_Class == IECLASS_NEWMOUSE) { switch (code) { case NM_WHEEL_UP: sym = K_MWHEELUP; break; case NM_WHEEL_DOWN: sym = K_MWHEELDOWN; break; case NM_BUTTON_FOURTH: sym = K_MOUSE4; break; } //Con_Printf("newmouse code %d sym %d state %d\n", code, sym, state); } if (sym) { if (sym == K_MWHEELUP || sym == K_MWHEELDOWN) { /* the mouse wheel doesn't generate a key up event */ Key_Event(sym, true); Key_Event(sym, false); } else { Key_Event(sym, state); } } } IN_HandleJoystick(); }
void IN_SendKeyEvents (void) { SDL_Event event; int sym, state; int modstate; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_ACTIVEEVENT: if (event.active.state & (SDL_APPINPUTFOCUS|SDL_APPACTIVE)) { if (event.active.gain) { // Sys_Printf("FOCUS GAIN\n"); S_UnblockSound(); } else { // Sys_Printf("FOCUS LOSS\n"); S_BlockSound(); } } break; case SDL_KEYDOWN: if ((event.key.keysym.sym == SDLK_RETURN) && (event.key.keysym.mod & KMOD_ALT)) { VID_ToggleFullscreen(); break; } else if ((event.key.keysym.sym == SDLK_ESCAPE) && (event.key.keysym.mod & KMOD_SHIFT)) { Con_ToggleConsole_f(); break; } else if ((event.key.keysym.sym == SDLK_g) && (event.key.keysym.mod & KMOD_CTRL)) { SDL_WM_GrabInput( (SDL_WM_GrabInput (SDL_GRAB_QUERY) == SDL_GRAB_ON) ? SDL_GRAB_OFF : SDL_GRAB_ON ); break; } case SDL_KEYUP: sym = event.key.keysym.sym; state = event.key.state; modstate = SDL_GetModState(); switch (key_dest) { case key_game: if ((event.key.keysym.unicode != 0) || (modstate & KMOD_SHIFT)) { /* only use unicode for ~ and ` in game mode */ if ((event.key.keysym.unicode & 0xFF80) == 0) { if (((event.key.keysym.unicode & 0x7F) == '`') || ((event.key.keysym.unicode & 0x7F) == '~') ) sym = event.key.keysym.unicode & 0x7F; } } break; case key_message: case key_console: if ((event.key.keysym.unicode != 0) || (modstate & KMOD_SHIFT)) { #if defined(__QNX__) if ((sym == SDLK_BACKSPACE) || (sym == SDLK_RETURN)) break; // S.A: fixes QNX weirdness #endif /* __QNX__ */ if ((event.key.keysym.unicode & 0xFF80) == 0) sym = event.key.keysym.unicode & 0x7F; /* else: it's an international character */ } // printf("You pressed %s (%d) (%c)\n", SDL_GetKeyName(sym), sym, sym); break; default: break; } switch (sym) { case SDLK_DELETE: sym = K_DEL; break; case SDLK_BACKSPACE: sym = K_BACKSPACE; break; case SDLK_F1: sym = K_F1; break; case SDLK_F2: sym = K_F2; break; case SDLK_F3: sym = K_F3; break; case SDLK_F4: sym = K_F4; break; case SDLK_F5: sym = K_F5; break; case SDLK_F6: sym = K_F6; break; case SDLK_F7: sym = K_F7; break; case SDLK_F8: sym = K_F8; break; case SDLK_F9: sym = K_F9; break; case SDLK_F10: sym = K_F10; break; case SDLK_F11: sym = K_F11; break; case SDLK_F12: sym = K_F12; break; case SDLK_BREAK: case SDLK_PAUSE: sym = K_PAUSE; break; case SDLK_UP: sym = K_UPARROW; break; case SDLK_DOWN: sym = K_DOWNARROW; break; case SDLK_RIGHT: sym = K_RIGHTARROW; break; case SDLK_LEFT: sym = K_LEFTARROW; break; case SDLK_INSERT: sym = K_INS; break; case SDLK_HOME: sym = K_HOME; break; case SDLK_END: sym = K_END; break; case SDLK_PAGEUP: sym = K_PGUP; break; case SDLK_PAGEDOWN: sym = K_PGDN; break; case SDLK_RSHIFT: case SDLK_LSHIFT: sym = K_SHIFT; break; case SDLK_RCTRL: case SDLK_LCTRL: sym = K_CTRL; break; case SDLK_RALT: case SDLK_LALT: sym = K_ALT; break; case SDLK_KP0: if (modstate & KMOD_NUM) sym = K_INS; else sym = SDLK_0; break; case SDLK_KP1: if (modstate & KMOD_NUM) sym = K_END; else sym = SDLK_1; break; case SDLK_KP2: if (modstate & KMOD_NUM) sym = K_DOWNARROW; else sym = SDLK_2; break; case SDLK_KP3: if (modstate & KMOD_NUM) sym = K_PGDN; else sym = SDLK_3; break; case SDLK_KP4: if (modstate & KMOD_NUM) sym = K_LEFTARROW; else sym = SDLK_4; break; case SDLK_KP5: sym = SDLK_5; break; case SDLK_KP6: if (modstate & KMOD_NUM) sym = K_RIGHTARROW; else sym = SDLK_6; break; case SDLK_KP7: if (modstate & KMOD_NUM) sym = K_HOME; else sym = SDLK_7; break; case SDLK_KP8: if (modstate & KMOD_NUM) sym = K_UPARROW; else sym = SDLK_8; break; case SDLK_KP9: if (modstate & KMOD_NUM) sym = K_PGUP; else sym = SDLK_9; break; case SDLK_KP_PERIOD: if (modstate & KMOD_NUM) sym = K_DEL; else sym = SDLK_PERIOD; break; case SDLK_KP_DIVIDE: sym = SDLK_SLASH; break; case SDLK_KP_MULTIPLY: sym = SDLK_ASTERISK; break; case SDLK_KP_MINUS: sym = SDLK_MINUS; break; case SDLK_KP_PLUS: sym = SDLK_PLUS; break; case SDLK_KP_ENTER: sym = SDLK_RETURN; break; case SDLK_KP_EQUALS: sym = SDLK_EQUALS; break; case 178: /* the '²' key */ sym = '~'; break; } // If we're not directly handled and still // above 255, just force it to 0 if (sym > 255) sym = 0; Key_Event (sym, state); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: if (!mouseactive || in_mode_set) break; if (event.button.button < 1 || event.button.button > sizeof(buttonremap) / sizeof(buttonremap[0])) { Con_Printf ("Ignored event for mouse button %d\n", event.button.button); break; } Key_Event(buttonremap[event.button.button - 1], event.button.state == SDL_PRESSED); break; case SDL_MOUSEMOTION: // SDL_GetMouseState (NULL, NULL); break; #if USE_JOYSTICK case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: if (!in_joystick.value) break; if (event.jbutton.button > K_AUX32 - K_JOY1) { Con_Printf ("Ignored event for joystick button %d\n", event.jbutton.button); break; } Key_Event(K_JOY1 + event.jbutton.button, event.jbutton.state == SDL_PRESSED); break; case SDL_JOYAXISMOTION: case SDL_JOYHATMOTION: case SDL_JOYBALLMOTION: /* to be coded.. */ break; #endif /* USE_JOYSTICK */ case SDL_QUIT: CL_Disconnect (); Sys_Quit (); break; default: break; } } }
void IN_SendKeyEvents (void) { SDL_Event event; int key; qboolean down; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_WINDOWEVENT: if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) S_UnblockSound(); else if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) S_BlockSound(); break; case SDL_TEXTINPUT: if (in_debugkeys.value) IN_DebugTextEvent(&event); // SDL2: We use SDL_TEXTINPUT for typing in the console / chat. // SDL2 uses the local keyboard layout and handles modifiers // (shift for uppercase, etc.) for us. { unsigned char *ch; for (ch = (unsigned char *)event.text.text; *ch; ch++) if ((*ch & ~0x7F) == 0) Char_Event (*ch); } break; case SDL_KEYDOWN: case SDL_KEYUP: down = (event.key.state == SDL_PRESSED); if (in_debugkeys.value) IN_DebugKeyEvent(&event); // SDL2: we interpret the keyboard as the US layout, so keybindings // are based on key position, not the label on the key cap. key = IN_SDL2_ScancodeToQuakeKey(event.key.keysym.scancode); Key_Event (key, down); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: if (event.button.button < 1 || event.button.button > sizeof(buttonremap) / sizeof(buttonremap[0])) { Con_Printf ("Ignored event for mouse button %d\n", event.button.button); break; } Key_Event(buttonremap[event.button.button - 1], event.button.state == SDL_PRESSED); break; case SDL_MOUSEWHEEL: if (event.wheel.y > 0) { Key_Event(K_MWHEELUP, true); Key_Event(K_MWHEELUP, false); } else if (event.wheel.y < 0) { Key_Event(K_MWHEELDOWN, true); Key_Event(K_MWHEELDOWN, false); } break; case SDL_MOUSEMOTION: IN_MouseMotion(event.motion.xrel, event.motion.yrel); break; case SDL_CONTROLLERDEVICEADDED: if (joy_active_instaceid == -1) { joy_active_controller = SDL_GameControllerOpen(event.cdevice.which); if (joy_active_controller == NULL) Con_DPrintf("Couldn't open game controller\n"); else { SDL_Joystick *joy; joy = SDL_GameControllerGetJoystick(joy_active_controller); joy_active_instaceid = SDL_JoystickInstanceID(joy); } } else Con_DPrintf("Ignoring SDL_CONTROLLERDEVICEADDED\n"); break; case SDL_CONTROLLERDEVICEREMOVED: if (joy_active_instaceid != -1 && event.cdevice.which == joy_active_instaceid) { SDL_GameControllerClose(joy_active_controller); joy_active_controller = NULL; joy_active_instaceid = -1; } else Con_DPrintf("Ignoring SDL_CONTROLLERDEVICEREMOVED\n"); break; case SDL_CONTROLLERDEVICEREMAPPED: Con_DPrintf("Ignoring SDL_CONTROLLERDEVICEREMAPPED\n"); break; case SDL_QUIT: CL_Disconnect (); Sys_Quit (); break; default: break; } } }