/* ================ Sys_GetEvent ================ */ sysEvent_t Sys_GetEvent( void ) { sysEvent_t ev; char *s; msg_t netmsg; netadr_t adr; // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // pump the message loop // in vga this calls KBD_Update, under X, it calls GetEvent Sys_SendKeyEvents (); // check for console commands s = Sys_ConsoleInput(); if ( s ) { char *b; int len; len = strlen( s ) + 1; b = (char *)malloc( len ); strcpy( b, s ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b ); } // check for other input devices IN_Frame(); // check for network packets MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) ); #if 0 if ( Sys_GetPacket ( &adr, &netmsg ) ) { netadr_t *buf; int len; // copy out to a seperate buffer for qeueing len = sizeof( netadr_t ) + netmsg.cursize; buf = malloc( len ); *buf = adr; memcpy( buf+1, netmsg.data, netmsg.cursize ); Sys_QueEvent( 0, SE_PACKET, 0, 0, len, buf ); } #endif // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // create an empty event to return memset( &ev, 0, sizeof( ev ) ); ev.evTime = Sys_Milliseconds(); return ev; }
void Sys_QueMouseEvents( int dwElements ) { int i, value; for( i = 0; i < dwElements; i++ ) { if ( polled_didod[i].dwOfs >= DIMOFS_BUTTON0 && polled_didod[i].dwOfs <= DIMOFS_BUTTON7 ) { value = (polled_didod[i].dwData & 0x80) == 0x80; Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_KEY, K_MOUSE1 + ( polled_didod[i].dwOfs - DIMOFS_BUTTON0 ), value, 0, NULL ); } else { switch (polled_didod[i].dwOfs) { case DIMOFS_X: value = polled_didod[i].dwData; Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_MOUSE, value, 0, 0, NULL ); break; case DIMOFS_Y: value = polled_didod[i].dwData; Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_MOUSE, 0, value, 0, NULL ); break; case DIMOFS_Z: value = ( (int) polled_didod[i].dwData ) / WHEEL_DELTA; int key = value < 0 ? K_MWHEELDOWN : K_MWHEELUP; value = abs( value ); while( value-- > 0 ) { Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_KEY, key, true, 0, NULL ); Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_KEY, key, false, 0, NULL ); } break; } } } }
void Sys_QueMouseEvents( int dwElements ) { int i, value; for( i = 0; i < dwElements; i++ ) { int diaction = polled_didod[i].dwOfs; if ( diaction >= DIMOFS_BUTTON0 && diaction <= DIMOFS_BUTTON7 ) { value = (polled_didod[i].dwData & 0x80) == 0x80; Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_KEY, K_MOUSE1 + ( diaction - DIMOFS_BUTTON0 ), value, 0, NULL ); } else if (diaction == DIMOFS_X) { value = polled_didod[i].dwData; Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_MOUSE, value, 0, 0, NULL ); } else if (diaction == DIMOFS_Y) { value = polled_didod[i].dwData; Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_MOUSE, 0, value, 0, NULL ); } else if (diaction == DIMOFS_Z) { value = ( (int) polled_didod[i].dwData ) / WHEEL_DELTA; int key = value < 0 ? K_MWHEELDOWN : K_MWHEELUP; value = abs( value ); while( value-- > 0 ) { Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_KEY, key, true, 0, NULL ); Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_KEY, key, false, 0, NULL ); } } } }
/* =========== IN_MouseEvent =========== */ void IN_MouseEvent(int mstate) { int i; if(!s_wmv.mouseInitialized && !directInput) { return; } // perform button actions for(i = 0; i < 5; i++) { if((mstate & (1 << i)) && !(s_wmv.oldButtonState & (1 << i))) { Sys_QueEvent(g_wv.sysMsgTime, SE_KEY, K_MOUSE1 + i, qtrue, 0, NULL); } if(!(mstate & (1 << i)) && (s_wmv.oldButtonState & (1 << i))) { Sys_QueEvent(g_wv.sysMsgTime, SE_KEY, K_MOUSE1 + i, qfalse, 0, NULL); } } s_wmv.oldButtonState = mstate; }
void QGLView::MouseScrolled(float delta_x, float delta_y) { if (delta_y < 0) { Sys_QueEvent(0, SE_KEY, K_MWHEELUP, qtrue, 0, NULL); Sys_QueEvent(0, SE_KEY, K_MWHEELUP, qfalse, 0, NULL); } else { Sys_QueEvent(0, SE_KEY, K_MWHEELDOWN, qtrue, 0, NULL); Sys_QueEvent(0, SE_KEY, K_MWHEELDOWN, qfalse, 0, NULL); } }
void GLimp_EndFrame( void ) { char buffer[500]; char *p; int len; const char *msg = NULL; int interval; int size[2]; int pos[2]; int rc; if ( strcmp( r_drawBuffer->string, "GL_FRONT" ) != 0 ) { SwapBuffers(); } while ( (len = read(ppsfd, buffer, sizeof( buffer ) -1 ) ) >= 0 ) { if ( len == 0 ) { return; } buffer[len] = '\0'; p = buffer; pps_decoder_parse( &decoder, p, len ); pps_decoder_push( &decoder, NULL ); pps_decoder_get_string(&decoder, "msg", &msg); if (pps_decoder_status(&decoder, true) == PPS_DECODER_OK ) { if ( strcmp(msg, "SWIPE_DOWN") == 0 ) { Sys_QueEvent( Sys_Milliseconds(), SE_KEY, K_ESCAPE, qtrue, 0, NULL ); Sys_QueEvent( Sys_Milliseconds(), SE_KEY, K_ESCAPE, qfalse, 0, NULL ); } /* if ( strcmp(msg, "activate") == 0 ) { Com_Printf("pps:orientation\n"); } else if ( strcmp(msg, "deactivate") == 0 ) { Com_Printf("pps:orientation\n"); } else if ( strcmp(msg, "deflate") == 0 ) { Com_Printf("pps:deflate\n"); } else if ( strcmp(msg, "orientation") == 0 ) { Com_Printf("pps:orientation\n"); } else if ( strcmp(msg, "exit") == 0 ) { Com_Printf("pps:exit\n"); } else if ( strcmp(msg, "invoke") == 0 ) { Com_Printf("pps:invoke\n"); } */ } } }
void DoKeyDown(EventRecord *event) { int myCharCode; int myKeyCode; myCharCode = BitAnd(event->message,charCodeMask); myKeyCode = ( event->message & keyCodeMask ) >> 8; Sys_QueEvent( Sys_MsecForMacEvent(), SE_KEY, vkeyToQuakeKey[ myKeyCode ], 1, 0, NULL ); Sys_QueEvent( Sys_MsecForMacEvent(), SE_CHAR, myCharCode, 0, 0, NULL ); }
void QGLView::MouseDown(BPoint point) { SetMouseEventMask(B_POINTER_EVENTS|B_KEYBOARD_EVENTS); int32 buttons; if (Window()->CurrentMessage()->FindInt32("buttons", (int32 *)&buttons) == B_NO_ERROR) { if (buttons & B_PRIMARY_MOUSE_BUTTON) Sys_QueEvent(0, SE_KEY, K_MOUSE1, qtrue, 0, NULL); if (buttons & B_SECONDARY_MOUSE_BUTTON) Sys_QueEvent(0, SE_KEY, K_MOUSE2, qtrue, 0, NULL); if (buttons & B_TERTIARY_MOUSE_BUTTON) Sys_QueEvent(0, SE_KEY, K_MOUSE3, qtrue, 0, NULL); old_buttons = buttons; } }
sysEvent_t Sys_GetEvent( void ) { sysEvent_t ev; char *s; msg_t netmsg; netadr_t adr; // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // check for console commands s = Sys_ConsoleInput(); if ( s ) { char *b; int len; len = strlen( s ) + 1; b = (char *)Z_Malloc( len,TAG_EVENT,qfalse ); strcpy( b, s ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b ); } // check for network packets MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) ); if ( Sys_GetPacket ( &adr, &netmsg ) ) { netadr_t *buf; int len; // copy out to a seperate buffer for qeueing len = sizeof( netadr_t ) + netmsg.cursize; buf = (netadr_t *)Z_Malloc( len,TAG_EVENT,qfalse ); *buf = adr; memcpy( buf+1, netmsg.data, netmsg.cursize ); Sys_QueEvent( 0, SE_PACKET, 0, 0, len, buf ); } // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // create an empty event to return memset( &ev, 0, sizeof( ev ) ); ev.evTime = Sys_Milliseconds(); return ev; }
// extern void G_DemoKeypress(); // extern void CG_SkipCredits(void); void IN_CommonJoyPress(int controller, fakeAscii_t button, bool pressed) { // Check for special cases for map hack // This should be #ifdef'd out in FINAL_BUILD, but I really don't care. // If someone wants to copy the retail version to their modded xbox and // edit the config file to turn on maphack, let them. if (Cvar_VariableIntegerValue("cl_maphack")) { if (_UIRunning && button == A_JOY11 && pressed) { // Left trigger -> F1 Sys_QueEvent( 0, SE_KEY, A_F1, pressed, 0, NULL ); return; } else if (_UIRunning && button == A_JOY12 && pressed) { // Right trigger -> F2 Sys_QueEvent( 0, SE_KEY, A_F2, pressed, 0, NULL ); return; } else if (_UIRunning && button == A_JOY4 && pressed) { // Start button -> F3 IN_SetMainController(controller); Sys_QueEvent( 0, SE_KEY, A_F3, pressed, 0, NULL ); return; } } if(IN_GetMainController() == controller || _UIRunning) { // Always map start button to ESCAPE if (!_UIRunning && button == A_JOY4 && cls.state != CA_CINEMATIC) Sys_QueEvent( 0, SE_KEY, A_ESCAPE, pressed, 0, NULL ); #ifdef DEBUG_CONTROLLER if (controller != 3) #endif Sys_QueEvent( 0, SE_KEY, _UIRunning ? UIJoy2Key(button) : button, pressed, 0, NULL ); } #ifdef DEBUG_CONTROLLER if (controller == 3 && pressed) { HandleDebugJoystickPress(button); return; } #endif }
void QGLView::MouseUp(BPoint point) { uint32 buttons; if (Window()->CurrentMessage()->FindInt32("buttons", (int32 *)&buttons) == B_NO_ERROR) { if ((buttons ^ B_PRIMARY_MOUSE_BUTTON) & old_buttons) { Sys_QueEvent(0, SE_KEY, K_MOUSE1, qfalse, 0, NULL); } if ((buttons ^ B_SECONDARY_MOUSE_BUTTON) & old_buttons) { Sys_QueEvent(0, SE_KEY, K_MOUSE2, qfalse, 0, NULL); } if ((buttons ^ B_TERTIARY_MOUSE_BUTTON) & old_buttons) { Sys_QueEvent(0, SE_KEY, K_MOUSE3, qfalse, 0, NULL); } old_buttons = buttons; } }
void IN_MouseMove(void) { if (!mouse_avail || !dpy || !win) return; #if 0 if (!dgamouse) { Window root, child; int root_x, root_y; int win_x, win_y; unsigned int mask_return; int mwx = glConfig.vidWidth/2; int mwy = glConfig.vidHeight/2; XQueryPointer(dpy, win, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask_return); mx = win_x - mwx; my = win_y - mwy; XWarpPointer(dpy,None,win,0,0,0,0, mwx, mwy); } #endif if (mx || my) Sys_QueEvent( 0, SE_MOUSE, mx, my, 0, NULL ); mx = my = 0; }
/* ================ Sys_GenerateEvents ================ */ void Sys_GenerateEvents() { static int entered = false; char *s; if ( entered ) { return; } entered = true; // pump the message loop Sys_PumpEvents(); // grab or release the mouse cursor if necessary IN_Frame(); // check for console commands s = Sys_ConsoleInput(); if ( s ) { char *b; int len; len = strlen( s ) + 1; b = (char *)Mem_Alloc( len, TAG_EVENTS ); strcpy( b, s ); Sys_QueEvent( SE_CONSOLE, 0, 0, len, b, 0 ); } entered = false; }
/* ================ Sys_GenerateEvents ================ */ void Sys_GenerateEvents(void) { static int entered = false; char *s; if (entered) { return; } entered = true; // pump the message loop Sys_PumpEvents(); // make sure mouse and joystick are only called once a frame IN_Frame(); // check for console commands s = Sys_ConsoleInput(); if (s) { char *b; int len; len = strlen(s) + 1; b = (char *)Mem_Alloc(len); strcpy(b, s); Sys_QueEvent(0, SE_CONSOLE, 0, 0, len, b); } entered = false; }
/* ======================== idJoystickWin32::PushButton ======================== */ void idJoystickWin32::PushButton( int inputDeviceNum, int key, bool value ) { // So we don't keep sending the same SE_KEY message over and over again if( buttonStates[inputDeviceNum][key] != value ) { buttonStates[inputDeviceNum][key] = value; Sys_QueEvent( SE_KEY, key, value, 0, NULL, inputDeviceNum ); } }
/* ================= Sys_PumpEvents ================= */ void Sys_PumpEvents( void ) { char *s; msg_t netmsg; netadr_t adr; // pump the message loop Sys_SendKeyEvents(); // check for console commands s = Sys_ConsoleInput(); if ( s ) { char *b; int len; len = strlen( s ) + 1; b = malloc( len ); if ( !b ) { Com_Error( ERR_FATAL, "malloc failed in Sys_PumpEvents" ); } strcpy( b, s ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b ); } // check for other input devices Sys_Input(); // check for network packets MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) ); if ( Sys_GetPacket ( &adr, &netmsg ) ) { netadr_t *buf; int len; // copy out to a seperate buffer for qeueing len = sizeof( netadr_t ) + netmsg.cursize; buf = malloc( len ); if ( !buf ) { Com_Error( ERR_FATAL, "malloc failed in Sys_PumpEvents" ); } *buf = adr; memcpy( buf+1, netmsg.data, netmsg.cursize ); Sys_QueEvent( 0, SE_PACKET, 0, 0, len, buf ); } }
/* ======================== idJoystickWin32::PostInputEvent ======================== */ void idJoystickWin32::PostInputEvent( int inputDeviceNum, int event, int value, int range ) { // These events are used for GUI button presses if( ( event >= J_ACTION1 ) && ( event <= J_ACTION_MAX ) ) { PushButton( inputDeviceNum, K_JOY1 + ( event - J_ACTION1 ), value != 0 ); } else if( event == J_AXIS_LEFT_X ) { PushButton( inputDeviceNum, K_JOY_STICK1_LEFT, ( value < -range ) ); PushButton( inputDeviceNum, K_JOY_STICK1_RIGHT, ( value > range ) ); } else if( event == J_AXIS_LEFT_Y ) { PushButton( inputDeviceNum, K_JOY_STICK1_UP, ( value < -range ) ); PushButton( inputDeviceNum, K_JOY_STICK1_DOWN, ( value > range ) ); } else if( event == J_AXIS_RIGHT_X ) { PushButton( inputDeviceNum, K_JOY_STICK2_LEFT, ( value < -range ) ); PushButton( inputDeviceNum, K_JOY_STICK2_RIGHT, ( value > range ) ); } else if( event == J_AXIS_RIGHT_Y ) { PushButton( inputDeviceNum, K_JOY_STICK2_UP, ( value < -range ) ); PushButton( inputDeviceNum, K_JOY_STICK2_DOWN, ( value > range ) ); } else if( ( event >= J_DPAD_UP ) && ( event <= J_DPAD_RIGHT ) ) { PushButton( inputDeviceNum, K_JOY_DPAD_UP + ( event - J_DPAD_UP ), value != 0 ); } else if( event == J_AXIS_LEFT_TRIG ) { PushButton( inputDeviceNum, K_JOY_TRIGGER1, ( value > range ) ); } else if( event == J_AXIS_RIGHT_TRIG ) { PushButton( inputDeviceNum, K_JOY_TRIGGER2, ( value > range ) ); } if( event >= J_AXIS_MIN && event <= J_AXIS_MAX ) { int axis = event - J_AXIS_MIN; int percent = ( value * 16 ) / range; if( joyAxis[inputDeviceNum][axis] != percent ) { joyAxis[inputDeviceNum][axis] = percent; Sys_QueEvent( SE_JOYSTICK, axis, percent, 0, NULL, inputDeviceNum ); } } // These events are used for actual game input events[numEvents].event = event; events[numEvents].value = value; numEvents++; }
static void MIDI_NoteOff( int note ) { int qkey; qkey = note - 60 + K_AUX1; if ( qkey > 255 || qkey < K_AUX1 ) { return; } Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, qkey, qfalse, 0, NULL ); }
/* ================ Sys_GetEvent ================ */ sysEvent_t Sys_GetEvent( void ) { MSG msg; sysEvent_t ev; char *s; msg_t netmsg; // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // pump the message loop while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) { if ( !GetMessage (&msg, NULL, 0, 0) ) { Com_Quit_f(); } // save the msg time, because wndprocs don't have access to the timestamp g_wv.sysMsgTime = msg.time; TranslateMessage (&msg); DispatchMessage (&msg); } // check for console commands s = Sys_ConsoleInput(); if ( s ) { char *b; int len; len = strlen( s ) + 1; b = (char *) Z_Malloc( len, TAG_EVENT, qfalse); strcpy( b, s ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b ); } // check for network packets MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) ); // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // create an empty event to return memset( &ev, 0, sizeof( ev ) ); ev.evTime = timeGetTime(); return ev; }
/* ==================== Sys_PollKeyboardInputEvents ==================== */ int Sys_ReturnKeyboardInputEvent( const int n, int &ch, bool &state ) { ch = IN_DIMapKey( polled_didod[ n ].dwOfs ); state = (polled_didod[ n ].dwData & 0x80) == 0x80; if ( ch == K_PRINT_SCR || ch == K_CTRL || ch == K_ALT || ch == K_RIGHT_ALT ) { // for windows, add a keydown event for print screen here, since // windows doesn't send keydown events to the WndProc for this key. // ctrl and alt are handled here to get around windows sending ctrl and // alt messages when the right-alt is pressed on non-US 102 keyboards. Sys_QueEvent( GetTickCount(), SE_KEY, ch, state, 0, NULL ); } return ch; }
void pumpEvents(void) { struct eventlist_s *ev; if (events_used != events_avail) { ev = &eventlist[events_used & (EVENTQUEUELENGTH-1)]; LOGI("Queue event"); Sys_QueEvent( 0, SE_KEY, ev->scancode, ev->state?qtrue:qfalse, 0, NULL ); if( ev->unicode && ev->state) Sys_QueEvent( 0, SE_CHAR,ev->unicode, 0, 0, NULL ); events_used++; } //Ok so can not issue commands more than 60 times/sec, who cares! if (postedCommand) { Cmd_ExecuteString(postedCommand); postedCommand = 0; } if (mdx || mdy) Sys_QueEvent( 0, SE_MOUSE, -mdx, -mdy, 0, NULL ); mdx=mdy=0; /* if (absx || absy) Sys_QueEvent( 0, SE_MOUSE_ABS, absx, absy, 0, NULL ); absx = 0; absy = 0; */ }
sysEvent_t Sys_GetEvent( void ) { sysEvent_t ev; // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // check for network packets msg_t netmsg; netadr_t adr; for (int poll = 0; poll < MAX_POLL_RATE; ++poll) { MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) ); if ( Sys_GetPacket ( &adr, &netmsg ) ) { netadr_t *buf; int len; // copy out to a seperate buffer for qeueing // the readcount stepahead is for SOCKS support len = sizeof( netadr_t ) + netmsg.cursize - netmsg.readcount; //buf = (netadr_t *)GG_Malloc( len, MemoryBlock::kEventTag, qtrue ); buf = (netadr_t *) Z_Malloc(len, TAG_EVENT, qfalse, 4); *buf = adr; memcpy( buf+1, &netmsg.data[netmsg.readcount], netmsg.cursize - netmsg.readcount ); Sys_QueEvent( 0, SE_PACKET, 0, 0, len, buf ); } else { // Bail out if there's no more data break; } } #if 0 // Removed as in SOF2 // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } #endif // create an empty event to return memset( &ev, 0, sizeof( ev ) ); ev.evTime = Sys_Milliseconds(); return ev; }
static void MIDI_NoteOn( int note, int velocity ) { int qkey; if ( velocity == 0 ) { MIDI_NoteOff( note ); } qkey = note - 60 + K_AUX1; if ( qkey > 255 || qkey < K_AUX1 ) { return; } Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, qkey, qtrue, 0, NULL ); }
sysEvent_t Sys_GetEvent( void ) { sysEvent_t ev; char *s; msg_t netmsg; // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // pump the message loop // in vga this calls KBD_Update, under X, it calls GetEvent Sys_SendKeyEvents (); // check for console commands s = Sys_ConsoleInput(); if ( s ) { char *b; int len; len = strlen( s ) + 1; b = (char *)Z_Malloc( len,TAG_EVENT,qfalse ); strcpy( b, s ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b ); } // check for other input devices IN_Frame(); // check for network packets MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) ); // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // create an empty event to return memset( &ev, 0, sizeof( ev ) ); ev.evTime = Sys_Milliseconds(); return ev; }
void QGLView::MouseMoved(BPoint point, uint32 transit, const BMessage *message) { if (!Window()->IsActive()) return; // If the cursor is already centered on screen, return; // Because set_mouse_position below issues a MouseMoved() :/ if (point.x == glConfig.vidWidth/2 && point.y == glConfig.vidHeight/2) return; int mx, my = 0; mx = (int)point.x - (glConfig.vidWidth/2); my = (int)point.y - (glConfig.vidHeight/2); Sys_QueEvent(0, SE_MOUSE, mx, my, 0, NULL); //Center on screen set_mouse_position((long int)(Window()->Frame().right - Window()->Bounds().Width()/2)+1, (long int)(Window()->Frame().bottom - Window()->Bounds().Height()/2)+1); }
/* ================== Sys_ModifierEvents ================== */ static void Sys_ModifierEvents( int modifiers ) { static int oldModifiers; int changed; int i; typedef struct { int bit; int keyCode; } modifierKey_t; static modifierKey_t keys[] = { { 128, K_MOUSE1 }, { 256, K_COMMAND }, { 512, K_SHIFT }, {1024, K_CAPSLOCK }, {2048, K_ALT }, {4096, K_CTRL }, {-1, -1 } }; changed = modifiers ^ oldModifiers; for ( i = 0 ; keys[i].bit != -1 ; i++ ) { // if we have input sprockets running, ignore mouse events we // get from the debug passthrough driver if ( inputActive && keys[i].keyCode == K_MOUSE1 ) { continue; } if ( changed & keys[i].bit ) { Sys_QueEvent( Sys_MsecForMacEvent(), SE_KEY, keys[i].keyCode, !!( modifiers & keys[i].bit ), 0, NULL ); } } oldModifiers = modifiers; }
static LONG WINAPI ConWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { const char *cmdString; static qboolean s_timePolarity; switch (uMsg) { case WM_ACTIVATE: if ( LOWORD( wParam ) != WA_INACTIVE ) { SetFocus( s_wcd.hwndInputLine ); } if ( com_viewlog && ( com_dedicated && !com_dedicated->integer ) ) { // if the viewlog is open, check to see if it's being minimized if ( com_viewlog->integer == 1 ) { if ( HIWORD( wParam ) ) // minimized flag { Cvar_Set( "viewlog", "2" ); } } else if ( com_viewlog->integer == 2 ) { if ( !HIWORD( wParam ) ) // minimized flag { Cvar_Set( "viewlog", "1" ); } } } break; case WM_CLOSE: if ( ( com_dedicated && com_dedicated->integer ) ) { cmdString = CopyString( "quit" ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, strlen( cmdString ) + 1, (void *)cmdString ); } else if ( s_wcd.quitOnClose ) { PostQuitMessage( 0 ); } else { Sys_ShowConsole( 0, qfalse ); Cvar_Set( "viewlog", "0" ); } return 0; case WM_CTLCOLORSTATIC: if ( ( HWND ) lParam == s_wcd.hwndBuffer ) { SetBkColor( ( HDC ) wParam, RGB( 0, 0, 0 ) ); SetTextColor( ( HDC ) wParam, RGB( 249, 249, 000 ) ); return ( long ) s_wcd.hbrEditBackground; } else if ( ( HWND ) lParam == s_wcd.hwndErrorBox ) { if ( s_timePolarity & 1 ) { SetBkColor( ( HDC ) wParam, RGB( 0x80, 0x80, 0x80 ) ); SetTextColor( ( HDC ) wParam, RGB( 0xff, 0x00, 0x00 ) ); } else { SetBkColor( ( HDC ) wParam, RGB( 0x80, 0x80, 0x80 ) ); SetTextColor( ( HDC ) wParam, RGB( 0x00, 0x00, 0x00 ) ); } return ( long ) s_wcd.hbrErrorBackground; } return FALSE; break; case WM_COMMAND: if ( wParam == COPY_ID ) { SendMessage( s_wcd.hwndBuffer, EM_SETSEL, 0, -1 ); SendMessage( s_wcd.hwndBuffer, WM_COPY, 0, 0 ); } else if ( wParam == QUIT_ID ) { if ( s_wcd.quitOnClose ) { PostQuitMessage( 0 ); } else { cmdString = CopyString( "quit" ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, strlen( cmdString ) + 1, (void *)cmdString ); } } else if ( wParam == CLEAR_ID ) { SendMessage( s_wcd.hwndBuffer, EM_SETSEL, 0, -1 ); SendMessage( s_wcd.hwndBuffer, EM_REPLACESEL, FALSE, ( LPARAM ) "" ); UpdateWindow( s_wcd.hwndBuffer ); } break; case WM_CREATE: s_wcd.hbrEditBackground = CreateSolidBrush( RGB( 0x00, 0x00, 0x00 ) ); s_wcd.hbrErrorBackground = CreateSolidBrush( RGB( 0x80, 0x80, 0x80 ) ); SetTimer( hWnd, 1, 1000, NULL ); break; case WM_ERASEBKGND: return DefWindowProc( hWnd, uMsg, wParam, lParam ); case WM_TIMER: if ( wParam == 1 ) { s_timePolarity = (qboolean)!s_timePolarity; if ( s_wcd.hwndErrorBox ) { InvalidateRect( s_wcd.hwndErrorBox, NULL, FALSE ); } } break; } return DefWindowProc( hWnd, uMsg, wParam, lParam ); }
static LONG WINAPI ConWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { char *cmdString; static qboolean s_timePolarity; switch (uMsg) { case WM_ACTIVATE: if ( LOWORD( wParam ) != WA_INACTIVE ) { SetFocus( s_wcd.hwndInputLine ); } if ( com_viewlog && ( com_dedicated && !com_dedicated->integer ) ) { // if the viewlog is open, check to see if it's being minimized if ( com_viewlog->integer == 1 ) { if ( HIWORD( wParam ) ) // minimized flag { Cvar_Set( "viewlog", "2" ); } } else if ( com_viewlog->integer == 2 ) { if ( !HIWORD( wParam ) ) // minimized flag { Cvar_Set( "viewlog", "1" ); } } } break; case WM_CLOSE: if ( ( com_dedicated && com_dedicated->integer ) ) { cmdString = CopyString( "quit" ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, strlen( cmdString ) + 1, cmdString ); } else if ( s_wcd.quitOnClose ) { PostQuitMessage( 0 ); } else { Sys_ShowConsole( 0, qfalse ); Cvar_Set( "viewlog", "0" ); } return 0; case WM_CTLCOLORSTATIC: if ( ( HWND ) lParam == s_wcd.hwndBuffer ) { SetBkColor( ( HDC ) wParam, RGB( 0x80, 0x00, 0x00 ) ); SetTextColor( ( HDC ) wParam, RGB( 0xff, 0xff, 0xff ) ); #if 0 // this draws a background in the edit box, but there are issues with this if ( ( hdcScaled = CreateCompatibleDC( ( HDC ) wParam ) ) != 0 ) { if ( SelectObject( ( HDC ) hdcScaled, s_wcd.hbmLogo ) ) { StretchBlt( ( HDC ) wParam, 0, 0, 512, 384, hdcScaled, 0, 0, 512, 384, SRCCOPY ); } DeleteDC( hdcScaled ); } #endif return ( long ) s_wcd.hbrEditBackground; } else if ( ( HWND ) lParam == s_wcd.hwndErrorBox ) { if ( s_timePolarity & 1 ) { SetBkColor( ( HDC ) wParam, RGB( 0x40, 0x40, 0x40 ) ); SetTextColor( ( HDC ) wParam, RGB( 0xff, 0x0, 0x00 ) ); } else { SetBkColor( ( HDC ) wParam, RGB( 0x40, 0x40, 0x40 ) ); SetTextColor( ( HDC ) wParam, RGB( 0x00, 0x0, 0x00 ) ); } return ( long ) s_wcd.hbrErrorBackground; } break; case WM_COMMAND: if ( wParam == COPY_ID ) { SendMessage( s_wcd.hwndBuffer, EM_SETSEL, 0, -1 ); SendMessage( s_wcd.hwndBuffer, WM_COPY, 0, 0 ); } else if ( wParam == QUIT_ID ) { if ( s_wcd.quitOnClose ) { PostQuitMessage( 0 ); } else { cmdString = CopyString( "quit" ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, strlen( cmdString ) + 1, cmdString ); } } else if ( wParam == CLEAR_ID ) { SendMessage( s_wcd.hwndBuffer, EM_SETSEL, 0, -1 ); SendMessage( s_wcd.hwndBuffer, EM_REPLACESEL, FALSE, ( LPARAM ) "" ); UpdateWindow( s_wcd.hwndBuffer ); } break; case WM_CREATE: // s_wcd.hbmLogo = LoadBitmap( g_wv.hInstance, MAKEINTRESOURCE( IDB_BITMAP1 ) ); // s_wcd.hbmClearBitmap = LoadBitmap( g_wv.hInstance, MAKEINTRESOURCE( IDB_BITMAP2 ) ); s_wcd.hbrEditBackground = CreateSolidBrush( RGB( 0x80, 0x00, 0x00 ) ); s_wcd.hbrErrorBackground = CreateSolidBrush( RGB( 0x80, 0x80, 0x80 ) ); SetTimer( hWnd, 1, 1000, NULL ); break; case WM_ERASEBKGND: #if 0 HDC hdcScaled; HGDIOBJ oldObject; #if 1 // a single, large image hdcScaled = CreateCompatibleDC( ( HDC ) wParam ); assert( hdcScaled != 0 ); if ( hdcScaled ) { oldObject = SelectObject( ( HDC ) hdcScaled, s_wcd.hbmLogo ); assert( oldObject != 0 ); if ( oldObject ) { StretchBlt( ( HDC ) wParam, 0, 0, s_wcd.windowWidth, s_wcd.windowHeight, hdcScaled, 0, 0, 512, 384, SRCCOPY ); } DeleteDC( hdcScaled ); hdcScaled = 0; } #else // a repeating brush { HBRUSH hbrClearBrush; RECT r; GetWindowRect( hWnd, &r ); r.bottom = r.bottom - r.top + 1; r.right = r.right - r.left + 1; r.top = 0; r.left = 0; hbrClearBrush = CreatePatternBrush( s_wcd.hbmClearBitmap ); assert( hbrClearBrush != 0 ); if ( hbrClearBrush ) { FillRect( ( HDC ) wParam, &r, hbrClearBrush ); DeleteObject( hbrClearBrush ); } } #endif return 1; #endif return DefWindowProc( hWnd, uMsg, wParam, lParam ); case WM_TIMER: if ( wParam == 1 ) { s_timePolarity = !s_timePolarity; if ( s_wcd.hwndErrorBox ) { InvalidateRect( s_wcd.hwndErrorBox, NULL, FALSE ); } } break; } return DefWindowProc( hWnd, uMsg, wParam, lParam ); }
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 ); }
LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { int key; switch( uMsg ) { case WM_WINDOWPOSCHANGED: break; case WM_CREATE: win32.hWnd = hWnd; //void GLW_WM_CREATE( HWND hWnd ); //GLW_WM_CREATE( hWnd ); break; case WM_DESTROY: break; case WM_CLOSE: Sys_Quit(); break; case WM_ACTIVATE: // if we got here because of an alt-tab or maximize, // we should activate immediately. If we are here because // the mouse was clicked on a title bar or drag control, // don't activate until the mouse button is released { int fActive, fMinimized; fActive = LOWORD(wParam); fMinimized = (BOOL) HIWORD(wParam); //win32.activeApp = (fActive != WA_INACTIVE); //if ( win32.activeApp ) { // idKeyInput::ClearStates(); // com_editorActive = false; // Sys_GrabMouseCursor( true ); //} //if ( fActive == WA_INACTIVE ) { // win32.movingWindow = false; //} //// start playing the game sound world //session->SetPlayingSoundWorld(); // we do not actually grab or release the mouse here, // that will be done next time through the main loop } break; case WM_MOVE: { int xPos, yPos; RECT r; int style; if (!win32.cdsFullscreen ) { xPos = (short) LOWORD(lParam); // horizontal position yPos = (short) HIWORD(lParam); // vertical position r.left = 0; r.top = 0; r.right = 1; r.bottom = 1; style = GetWindowLong( hWnd, GWL_STYLE ); AdjustWindowRect( &r, style, FALSE ); /* win32.win_xpos.SetInteger( xPos + r.left ); win32.win_ypos.SetInteger( yPos + r.top ); win32.win_xpos.ClearModified(); win32.win_ypos.ClearModified();*/ } break; } case WM_TIMER: { //if ( win32.win_timerUpdate.GetBool() ) { //common->Frame(); //} break; } case WM_SYSCOMMAND: if ( wParam == SC_SCREENSAVE || wParam == SC_KEYMENU ) { return 0; } break; case WM_SYSKEYDOWN: //if ( wParam == 13 ) { // alt-enter toggles full-screen // cvarSystem->SetCVarBool( "r_fullscreen", !renderSystem->IsFullScreen() ); // cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "vid_restart\n" ); // return 0; //} // fall through for other keys case WM_KEYDOWN: key = MapKey(wParam); Sys_QueEvent( win32.sysMsgTime, SE_KEY, key, true, 0, NULL ); break; case WM_SYSKEYUP: case WM_KEYUP: key = MapKey(wParam); Sys_QueEvent( win32.sysMsgTime, SE_KEY, key, false, 0, NULL ); break; case WM_CHAR: //Sys_QueEvent( win32.sysMsgTime, SE_CHAR, wParam, 0, 0, NULL ); break; case WM_NCLBUTTONDOWN: // win32.movingWindow = true; break; case WM_ENTERSIZEMOVE: win32.movingWindow = true; break; case WM_EXITSIZEMOVE: win32.movingWindow = false; break; case WM_SIZING: //WIN_Sizing(wParam, (RECT *)lParam); break; case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_MBUTTONDOWN: case WM_MBUTTONUP: //case WM_MOUSEMOVE: case WM_LBUTTONDOWN:{ POINT p; GetCursorPos(&p); Sys_QueEvent( win32.sysMsgTime, SE_MOUSE, p.x, p.y, 0, NULL ); break; } case WM_MOUSEWHEEL: { int delta = GET_WHEEL_DELTA_WPARAM( wParam ) / WHEEL_DELTA; // int key = delta < 0 ? K_MWHEELDOWN : K_MWHEELUP; delta = abs( delta ); while( delta-- > 0 ) { //Sys_QueEvent( win32.sysMsgTime, SE_KEY, key, true, 0, NULL ); //Sys_QueEvent( win32.sysMsgTime, SE_KEY, key, false, 0, NULL ); } break; } } return DefWindowProc( hWnd, uMsg, wParam, lParam ); }