// // Command line. // UBOOL UXViewport::Exec( const TCHAR* Cmd, FOutputDevice& Ar ) { guard(UXViewport::Exec); if( UViewport::Exec( Cmd, Ar ) ) { return 1; } else if( ParseCommand(&Cmd,TEXT("EndFullscreen")) ) { EndFullscreen(); return 1; } else if( ParseCommand(&Cmd,TEXT("ToggleFullscreen")) ) { ToggleFullscreen(); return 1; } else if( ParseCommand(&Cmd,TEXT("Iconify")) ) { Iconify(); return 1; } else if( ParseCommand(&Cmd,TEXT("GetCurrentRes")) ) { Ar.Logf( TEXT("%ix%i"), SizeX, SizeY, (ColorBytes?ColorBytes:2)*8 ); return 1; } else if( ParseCommand(&Cmd,TEXT("GetCurrentColorDepth")) ) { Ar.Logf( TEXT("%i"), (ColorBytes?ColorBytes:2)*8 ); return 1; } else if( ParseCommand(&Cmd,TEXT("GetColorDepths")) ) { Ar.Log( TEXT("16 32") ); return 1; } else if( ParseCommand(&Cmd,TEXT("GetCurrentRenderDevice")) ) { Ar.Log( RenDev->GetClass()->GetPathName() ); return 1; } else if( ParseCommand(&Cmd,TEXT("SetRenderDevice")) ) { FString Saved = RenDev->GetClass()->GetPathName(); INT SavedSizeX=SizeX, SavedSizeY=SizeY, SavedColorBytes=ColorBytes, SavedFullscreen=((BlitFlags & BLIT_Fullscreen)!=0); TryRenderDevice( Cmd, SizeX, SizeY, ColorBytes, SavedFullscreen ); if( !RenDev ) { TryRenderDevice( *Saved, SavedSizeX, SavedSizeY, SavedColorBytes, SavedFullscreen ); check(RenDev); Ar.Log(TEXT("0")); } else Ar.Log(TEXT("1")); return 1; } else if( ParseCommand(&Cmd,TEXT("GetRes")) ) { return 1; } else if( ParseCommand(&Cmd,TEXT("SetRes")) ) { INT X=appAtoi(Cmd); TCHAR* CmdTemp = (TCHAR*) (appStrchr(Cmd,'x') ? appStrchr(Cmd,'x')+1 : appStrchr(Cmd,'X') ? appStrchr(Cmd,'X')+1 : TEXT("")); INT Y=appAtoi(CmdTemp); Cmd = CmdTemp; CmdTemp = (TCHAR*) (appStrchr(Cmd,'x') ? appStrchr(Cmd,'x')+1 : appStrchr(Cmd,'X') ? appStrchr(Cmd,'X')+1 : TEXT("")); INT C=appAtoi(CmdTemp); INT NewColorBytes = C ? C/8 : ColorBytes; if( X && Y ) { HoldCount++; UBOOL Result = RenDev->SetRes( X, Y, NewColorBytes, IsFullscreen() ); HoldCount--; if( !Result ) EndFullscreen(); } return 1; } else if( ParseCommand(&Cmd,TEXT("Preferences")) ) { // No preferences window. return 1; } else return 0; unguard; }
void UXViewport::Tick() { guard(UXViewport::Tick); UXClient* Client = GetOuterUXClient(); if (!XWindow) return; // Keyboard. EInputKey Key; KeySym LowerCase, UpperCase; // Mouse movement management. UBOOL MouseMoved; INT BaseX = SizeX/2; INT BaseY = SizeY/2; INT DX = 0, DY = 0; XEvent Event; while( XPending(XDisplay) ) { XNextEvent(XDisplay, &Event); switch( Event.type ) { case CreateNotify: // Window has been created. ViewportStatus = X_ViewportNormal; // Make this viewport current and update its title bar. GetOuterUClient()->MakeCurrent( this ); break; case DestroyNotify: // Window has been destroyed. if( BlitFlags & BLIT_Fullscreen ) EndFullscreen(); if( ViewportStatus == X_ViewportNormal ) { // Closed normally. ViewportStatus = X_ViewportClosing; delete this; } break; case Expose: // Redraw the window. break; case KeyPress: // Reset timer. RepeatTimer = appSeconds(); LastKey = True; // Get key code. Key = (EInputKey) XKeycodeToKeysym( XDisplay, Event.xkey.keycode, 0 ); XConvertCase( Key, &LowerCase, &UpperCase ); Key = (EInputKey) UpperCase; // Check the Keysym map. if (KeysymMap[Key] != 0) Key = (EInputKey) KeysymMap[Key]; // Send key to input system. CauseInputEvent( Key, IST_Press ); // Emulate WM_CHAR. // Check for shift modifier. if (Event.xkey.state & ShiftMask) { Key = (EInputKey) UpperCase; if (ShiftMaskMap[Key] != 0) Key = (EInputKey) ShiftMaskMap[Key]; } else Key = (EInputKey) LowerCase; if (Key == XK_BackSpace) Key = IK_Backspace; if (Key == XK_Tab) Key = IK_Tab; if (Key == XK_Return) Key = IK_Enter; if (WMCharMap[Key] == 1) { KeyRepeatMap[Key] = 1; Client->Engine->Key( this, Key ); } break; case KeyRelease: // Get key code. Key = (EInputKey) XKeycodeToKeysym( XDisplay, Event.xkey.keycode, 0 ); XConvertCase( Key, &LowerCase, &UpperCase ); Key = (EInputKey) UpperCase; // Check the Keysym map. if (KeysymMap[Key] != 0) Key = (EInputKey) KeysymMap[Key]; // Send key to input system. CauseInputEvent( Key, IST_Release ); // Release all types of this key. if (Key == XK_BackSpace) Key = IK_Backspace; if (Key == XK_Tab) Key = IK_Tab; if (Key == XK_Return) Key = IK_Enter; KeyRepeatMap[Key] = 0; KeyRepeatMap[ShiftMaskMap[Key]] = 0; KeyRepeatMap[ShiftMaskMap[(EInputKey) LowerCase]] = 0; KeyRepeatMap[(EInputKey) LowerCase] = 0; break; case ButtonPress: switch (Event.xbutton.button) { case 1: Key = IK_LeftMouse; break; case 2: Key = IK_MiddleMouse; break; case 3: Key = IK_RightMouse; break; case 4: Key = IK_MouseWheelUp; break; case 5: Key = IK_MouseWheelDown; break; } // Send to input system. CauseInputEvent( Key, IST_Press ); break; case ButtonRelease: switch (Event.xbutton.button) { case 1: Key = IK_LeftMouse; break; case 2: Key = IK_MiddleMouse; break; case 3: Key = IK_RightMouse; break; case 4: Key = IK_MouseWheelUp; break; case 5: Key = IK_MouseWheelDown; break; } // Send to input system. CauseInputEvent( Key, IST_Release ); break; case MotionNotify: MouseMoved = True; if (UseDGA) { if (abs(Event.xmotion.x_root) > 1) DX += Event.xmotion.x_root * 2; else DX += Event.xmotion.x_root; if (abs(Event.xmotion.y_root) > 1) DY += Event.xmotion.y_root * 2; else DY += Event.xmotion.y_root; } else { DX += Event.xmotion.x - BaseX; DY += Event.xmotion.y - BaseY; BaseX = Event.xmotion.x; BaseY = Event.xmotion.y; } break; case ResizeRequest: // Eventually resize and setres. break; case MapNotify: if (Iconified) { guard(Uniconify); Iconified = false; // Unpause the game if applicable. Exec( TEXT("SETPAUSE 0"), *this ); // Reset the input buffer. Input->ResetInput(); // Snag the mouse again. SetMouseCapture( 1, 1, 0 ); // Make this viewport current. GetOuterUClient()->MakeCurrent( this ); // Turn off that damn auto repeat. XAutoRepeatOff( XDisplay ); // Return to fullscreen. if( BlitFlags & BLIT_Fullscreen ) TryRenderDevice( TEXT("ini:Engine.Engine.GameRenderDevice"), INDEX_NONE, INDEX_NONE, ColorBytes, 1 ); unguard; } break; case UnmapNotify: if (!Iconified) Iconify(); break; case FocusIn: break; case FocusOut: Iconify(); break; } } if (Iconified) return; // Deliver mouse behavior to the engine. if (MouseMoved) { if (!UseDGA) { XWarpPointer(XDisplay, None, XWindow, 0, 0, 0, 0, SizeX/2, SizeY/2); // Clear out the warp. XEvent MouseEvent; while( XCheckWindowEvent(XDisplay, XWindow, ButtonMotionMask | PointerMotionMask, &MouseEvent) ) { // Do Nothing. } } // Send to input subsystem. if( DX ) CauseInputEvent( IK_MouseX, IST_Axis, +DX ); if( DY ) CauseInputEvent( IK_MouseY, IST_Axis, -DY ); } // Send WM_CHAR for down keys. if ( LastKey && (appSeconds() - RepeatTimer < 0.5) ) return; LastKey = False; if ( appSeconds() - RepeatTimer < 0.1 ) return; RepeatTimer = appSeconds(); for (INT i=0; i<256; i++) if (KeyRepeatMap[i] != 0) { if (i == IK_Backspace) { CauseInputEvent( i, IST_Press ); CauseInputEvent( i, IST_Release ); } else Client->Engine->Key( this, (EInputKey) i ); } unguard; }
void HandleMapRequestKeepRaised(Window KeepRaised) { extern long isIconicState; extern Boolean PPosOverride; Boolean OnThisPage = False; Event.xany.window = Event.xmaprequest.window; if(XFindContext(dpy, Event.xany.window, FvwmContext, (caddr_t *)&Tmp_win)==XCNOENT) Tmp_win = NULL; if(!PPosOverride) XFlush(dpy); /* If the window has never been mapped before ... */ if(!Tmp_win) { /* Add decorations. */ Tmp_win = AddWindow(Event.xany.window); if (Tmp_win == NULL) return; } /* Make sure at least part of window is on this page before giving it focus... */ if ( (Tmp_win->Desk == Scr.CurrentDesk) && ( ((Tmp_win->frame_x + Tmp_win->frame_width) >= 0 && Tmp_win->frame_x < Scr.MyDisplayWidth) && ((Tmp_win->frame_y + Tmp_win->frame_height) >= 0 && Tmp_win->frame_y < Scr.MyDisplayHeight) ) ) { OnThisPage = True; } if(KeepRaised != None) XRaiseWindow(dpy,KeepRaised); /* If it's not merely iconified, and we have hints, use them. */ if (!(Tmp_win->flags & ICONIFIED)) { int state; if(Tmp_win->wmhints && (Tmp_win->wmhints->flags & StateHint)) state = Tmp_win->wmhints->initial_state; else state = NormalState; if(Tmp_win->flags & STARTICONIC) state = IconicState; if(isIconicState != DontCareState) state = isIconicState; MyXGrabServer(dpy); switch (state) { case DontCareState: case NormalState: case InactiveState: default: if (Tmp_win->Desk == Scr.CurrentDesk) { XMapWindow(dpy, Tmp_win->w); XMapWindow(dpy, Tmp_win->frame); Tmp_win->flags |= MAP_PENDING; SetMapStateProp(Tmp_win, NormalState); if((Tmp_win->flags & ClickToFocus)&& ((!Scr.Focus)||(Scr.Focus->flags & ClickToFocus))) { if (OnThisPage) { SetFocus(Tmp_win->w,Tmp_win,1); } } } else { XMapWindow(dpy, Tmp_win->w); SetMapStateProp(Tmp_win, NormalState); } break; case IconicState: if (Tmp_win->wmhints) { Iconify(Tmp_win, Tmp_win->wmhints->icon_x, Tmp_win->wmhints->icon_y); } else { Iconify(Tmp_win, 0, 0); } break; } if(!PPosOverride) XSync(dpy,0); MyXUngrabServer(dpy); } /* If no hints, or currently an icon, just "deiconify" */ else { DeIconify(Tmp_win); } if(!PPosOverride) KeepOnTop(); }