📄 i_video_xshm.c
字号:
if(!displayname) displayname = (char *) getenv("DISPLAY"); // check for local display if(displayname) { strncpy(displaycopy, displayname, 256); d = displaycopy; while (*d && (*d != ':')) d++; if (*d) *d = 0; if (!(!strcasecmp(displaycopy, "unix") || !*displaycopy)) localDisplay = false; } return displayname;}static void checkForShm(char *displayname) // FIXME: why do we need displayname ??{ if(rendermode==render_soft) { // check for the MITSHM extension doShm = XShmQueryExtension(X_display); // even if it's available, make sure it's a local connection if(doShm && localDisplay) { doShm = true; fprintf(stderr, "Using MITSHM extension\n"); } else doShm = false; } else //if(rendermode==render_soft) doShm = false; return;}static void createColorMap(){ if (x_pseudo) X_cmap = XCreateColormap(X_display, RootWindow(X_display, X_screen), X_visual, AllocAll); else if (x_bpp==2) x_colormap2 = &color8to16[0]; // cheat...19990119 by Kin else if (x_bpp==3) x_colormap3 = malloc(3*256); else if (x_bpp==4) x_colormap4 = malloc(4*256); return;}static int dirtyMapTable[256] ={0, 0, 0, 0, 0, 0, 0, 0, 0, 65307, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 45, 61, 65288, 65289, 113, 119, 101, 114, 116, 121, 117, 105, 111, 112, 91, 93, 65293, 65507, 97, 115, 100, 102, 103, 104, 106, 107, 108, 59, 39, 96, 65505, 92, 122, 120, 99, 118, 98, 110, 109, 44, 46, 47, 65506, 65450, 65511, 32, 65509, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65407, 65300, 65429, 65431, 65434, 65453, 65430, 65437, 65432, 65451, 65436, 65433, 65435, 65438, 65439, 0, 0, 0, 65480, 65481, 65360, 65362, 65365, 65361, 0, 65363, 65367, 65364, 65366, 65379, 65535, 65421, 65312, 65299, 65377, 65455, 65514, 0, 65515, 65516, 65518, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //// Translates the key currently in X_event//static int xlatekey(void){ KeyCode keycode; KeySym keysym; int rc; keycode = X_event.xkey.keycode; keysym = XKeycodeToKeysym(X_display, keycode, 0); if(con_keymap == english) { rc = keysym; } else { rc = dirtyMapTable[keycode]; } switch(rc) { case XK_Left : rc = KEY_LEFTARROW; break; case XK_Right : rc = KEY_RIGHTARROW; break; case XK_Down : rc = KEY_DOWNARROW; break; case XK_Up : rc = KEY_UPARROW; break; case XK_Escape: rc = KEY_ESCAPE; break; case XK_Return: rc = KEY_ENTER; break; case XK_Tab: rc = KEY_TAB; break; case XK_F1: rc = KEY_F1; break; case XK_F2: rc = KEY_F2; break; case XK_F3: rc = KEY_F3; break; case XK_F4: rc = KEY_F4; break; case XK_F5: rc = KEY_F5; break; case XK_F6: rc = KEY_F6; break; case XK_F7: rc = KEY_F7; break; case XK_F8: rc = KEY_F8; break; case XK_F9: rc = KEY_F9; break; case XK_F10: rc = KEY_F10; break; case XK_F11: rc = KEY_F11; break; case XK_F12: rc = KEY_F12; break; // hey, it's not a sparc 19990128 by Kin case XK_BackSpace: rc = KEY_BACKSPACE; break; case XK_Delete: rc = KEY_DEL; break; case XK_Pause: rc = KEY_PAUSE; break; case XK_KP_Equal: case XK_KP_Add: case XK_equal: rc = KEY_EQUALS; break; case XK_KP_Subtract: case XK_minus: rc = KEY_MINUS; break; case XK_Shift_L: case XK_Shift_R: rc = KEY_SHIFT; break; case XK_Caps_Lock: rc = KEY_CAPSLOCK; break; case XK_Multi_key: case XK_Control_L: case XK_Control_R: rc = KEY_CTRL; break; case XK_Mode_switch: case XK_Alt_L: case XK_Meta_L: case XK_Alt_R: case XK_Meta_R: rc = KEY_ALT; break; // I forgot them..... 19990128 by Kin case XK_Page_Up: rc = KEY_PGUP; break; case XK_Page_Down: rc = KEY_PGDN; break; case XK_End: rc = KEY_END; break; case XK_Home: rc = KEY_HOME; break; case XK_Insert: rc = KEY_INS; break; // metzgermeister: keypad layout as in g_input.c case XK_KP_Insert : rc = KEY_KEYPAD0; break; case XK_KP_End : rc = KEY_KEYPAD1; break; case XK_KP_Down : rc = KEY_KEYPAD2; break; case XK_KP_Page_Down : rc = KEY_KEYPAD3; break; case XK_KP_Left : rc = KEY_KEYPAD4; break; case XK_KP_Begin : rc = KEY_KEYPAD5; break; case XK_KP_Right : rc = KEY_KEYPAD6; break; case XK_KP_Home : rc = KEY_KEYPAD7; break; case XK_KP_Up : rc = KEY_KEYPAD8; break; case XK_KP_Page_Up : rc = KEY_KEYPAD9; break; case XK_KP_Delete : rc = KEY_KPADDEL; break; case XK_KP_Divide : rc = KEY_KPADSLASH; break; case XK_KP_Enter : rc = KEY_ENTER; break; default: if (rc >= XK_space && rc <= XK_asciitilde) rc = rc - XK_space + ' '; if (rc >= 'A' && rc <= 'Z') rc = rc - 'A' + 'a'; break; } if (showkey) fprintf(stdout,"Key: %d\n", rc); return rc;}//// I_StartFrame//void I_StartFrame(void){ /* frame syncronous IO operations not needed for X11 */}static int lastmousex = 0;static int lastmousey = 0;#ifdef POLL_POINTERstatic int newmousex;static int newmousey;#endif// last button state from dos code... 19990110 by Kinstatic int lastbuttons = 0;boolean shmFinished;#ifdef LJOYSTICKextern void I_GetJoyEvent();#endif#ifdef LMOUSE2extern void I_GetMouse2Event();#endifvoid I_GetEvent(void){ event_t event;#ifdef LJOYSTICK I_GetJoyEvent();#endif#ifdef LMOUSE2 I_GetMouse2Event();#endif // put event-grabbing stuff in here XNextEvent(X_display, &X_event); switch (X_event.type) { case KeyPress: event.type = ev_keydown; event.data1 = xlatekey(); D_PostEvent(&event); break; case KeyRelease: event.type = ev_keyup; event.data1 = xlatekey(); D_PostEvent(&event); break;#ifndef POLL_POINTER case ButtonPress: if (cv_usemouse.value) { int buttons,i,j=1,k; event.type = ev_keydown; buttons = (X_event.xbutton.state & Button1Mask ? 1 : 0) | (X_event.xbutton.state & Button2Mask ? 2 : 0) | (X_event.xbutton.state & Button3Mask ? 4 : 0) | (X_event.xbutton.button == Button1 ? 1 : 0) | (X_event.xbutton.button == Button2 ? 2 : 0) | (X_event.xbutton.button == Button3 ? 4 : 0); k=(buttons ^ lastbuttons); // only changed bit to 1 lastbuttons = buttons; for(i=0;i<MOUSEBUTTONS;i++,j<<=1) if(k & j) { event.data1=KEY_MOUSE1+i; D_PostEvent(&event); break; // right? 19990110 by Kin } } break; case ButtonRelease: if (cv_usemouse.value) { int buttons,i,j=1,k; event.type = ev_keyup; buttons = (X_event.xbutton.state & Button1Mask ? 1 : 0) | (X_event.xbutton.state & Button2Mask ? 2 : 0) | (X_event.xbutton.state & Button3Mask ? 4 : 0); // suggest parentheses around arithmetic in operand of | buttons = buttons ^ (X_event.xbutton.button == Button1 ? 1 : 0) ^ (X_event.xbutton.button == Button2 ? 2 : 0) ^ (X_event.xbutton.button == Button3 ? 4 : 0); k=(buttons ^ lastbuttons); // only changed bit to 1 lastbuttons = buttons; for(i=0;i<MOUSEBUTTONS;i++,j<<=1) if(k & j) { event.data1=KEY_MOUSE1+i; D_PostEvent(&event); break; // right? 19990110 by Kin } } break; case MotionNotify: if (cv_usemouse.value) { // If the event is from warping the pointer back to middle // of the screen then ignore it. if ((X_event.xmotion.x == X_width/2) && (X_event.xmotion.y == X_height/2)) { lastmousex = X_event.xmotion.x; lastmousey = X_event.xmotion.y; break; } else { event.data2 = (X_event.xmotion.x - lastmousex) << 2; lastmousex = X_event.xmotion.x; event.data3 = (lastmousey - X_event.xmotion.y) << 2; lastmousey = X_event.xmotion.y; } event.type = ev_mouse; event.data1 = (X_event.xmotion.state & Button1Mask ? 1 : 0) | (X_event.xmotion.state & Button2Mask ? 2 : 0) | (X_event.xmotion.state & Button3Mask ? 4 : 0); D_PostEvent(&event); // Warp the pointer back to the middle of the window // or we cannot move any further if it's at a border. if ((X_event.xmotion.x < 1) || (X_event.xmotion.y < 1) || (X_event.xmotion.x > X_width-2) || (X_event.xmotion.y > X_height-2)) { XWarpPointer(X_display, None, X_mainWindow, 0, 0, 0, 0, X_width/2, X_height/2); } } break;#endif case UnmapNotify: if (!demoplayback) { paused = true; S_PauseSound(); } break; case MapNotify: if (!demoplayback) { paused = false; S_ResumeSound(); } break; case ClientMessage: if (X_event.xclient.data.l[0] == X_wm_delwin) { M_QuitResponse('y'); } break; case Expose: case ConfigureNotify: break; default: if (doShm && X_event.type == X_shmeventtype) shmFinished = true; break; }}static Cursor createnullcursor(Display* display, Window root){ Pixmap cursormask; XGCValues xgc; GC gc; XColor dummycolour; Cursor cursor; cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/); xgc.function = GXclear; gc = XCreateGC(display, cursormask, GCFunction, &xgc); XFillRectangle(display, cursormask, gc, 0, 0, 1, 1); dummycolour.pixel = 0; dummycolour.red = 0; dummycolour.flags = 04; cursor = XCreatePixmapCursor(display, cursormask, cursormask, &dummycolour,&dummycolour, 0,0); XFreePixmap(display,cursormask); XFreeGC(display,gc); return cursor;}static void disableScreensaver(){ int timeout, interval, prefer_blanking, allow_exposures; XGetScreenSaver(X_display, &timeout, &interval, &prefer_blanking, &allow_exposures); XSetScreenSaver(X_display, 0, interval, prefer_blanking, allow_exposures); XGetScreenSaver(X_display, &timeout, &interval, &prefer_blanking, &allow_exposures); }static void enableScreensaver(){ int timeout, interval, prefer_blanking, allow_exposures; XGetScreenSaver(X_display, &timeout, &interval, &prefer_blanking, &allow_exposures); XSetScreenSaver(X_display, -1, interval, prefer_blanking, allow_exposures); XGetScreenSaver(X_display, &timeout, &interval, &prefer_blanking, &allow_exposures); }static void doGrabMouse(void){ if(!X_display || cv_usemouse.value == 0 || M_CheckParm("-nomouse")) return; if(!Mousegrabbed) { XGrabPointer(X_display, X_mainWindow, True,#ifndef POLL_POINTER ButtonPressMask|ButtonReleaseMask|PointerMotionMask,#else 0,#endif GrabModeAsync, GrabModeAsync, X_mainWindow, None, CurrentTime); XGrabKeyboard(X_display, X_mainWindow, True, GrabModeAsync, GrabModeAsync, CurrentTime);#ifdef POLL_POINTER XQueryPointer(X_display, X_mainWindow, &dummy, &dummy, &dont_care, &dont_care, &lastmousex, &lastmousey, &dont_care);#endif disableScreensaver(); } Mousegrabbed = true; return;}static void doUngrabMouse(void){ if(!X_display) return; if(Mousegrabbed) { XUngrabKeyboard(X_display, CurrentTime); XUngrabPointer(X_display, CurrentTime); enableScreensaver(); } Mousegrabbed = false; return;}void I_StartupMouse(void){ if(vidmode_active || (haveVoodoo && !M_CheckParm("-winvoodoo"))) { doGrabMouse(); } else { if(cv_usemouse.value) { doGrabMouse(); } else { doUngrabMouse(); } } return;}//// I_OsPolling//void I_OsPolling(void){#ifdef POLL_POINTER unsigned int mask;#endif if (!X_display) return; if (cv_usemouse.value) {#ifdef POLL_POINTER XQueryPointer(X_display, X_mainWindow, &dummy, &dummy, &dont_care, &dont_care, &newmousex, &newmousey, &mask); { // process mouse 19990130 by Kin int buttons,i,j=1,k; buttons = (mask & Button1Mask ? 1 : 0) | (mask & Button2Mask ? 2 : 0) | (mask & Button3Mask ? 4 : 0); k=(buttons ^ lastbuttons); // only changed bit to 1 for(i=0;i<MOUSEBUTTONS;i++,j<<=1) if(k & j){ if(buttons & j) event.type = ev_keydown; else event.type = ev_keyup; event.data1=KEY_MOUSE1+i; D_PostEvent(&event); // don't break!!! 19990130 by Kin } lastbuttons = buttons; } event.type = ev_mouse;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -