x11_common.c
来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 2,222 行 · 第 1/5 页
C
2,222 行
return; if (vo_fsmode & 8) { XSetTransientForHint(vo_Display, w, RootWindow(vo_Display, mScreen)); } vo_MotifHints = XInternAtom(vo_Display, "_MOTIF_WM_HINTS", 0); if (vo_MotifHints != None) { if (!d) { MotifWmHints *mhints = NULL; XGetWindowProperty(vo_Display, w, vo_MotifHints, 0, 20, False, vo_MotifHints, &mtype, &mformat, &mn, &mb, (unsigned char **) &mhints); if (mhints) { if (mhints->flags & MWM_HINTS_DECORATIONS) olddecor = mhints->decorations; if (mhints->flags & MWM_HINTS_FUNCTIONS) oldfuncs = mhints->functions; XFree(mhints); } } memset(&vo_MotifWmHints, 0, sizeof(MotifWmHints)); vo_MotifWmHints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; if (d) { vo_MotifWmHints.functions = oldfuncs; d = olddecor; }#if 0 vo_MotifWmHints.decorations = d | ((vo_fsmode & 2) ? 0 : MWM_DECOR_MENU);#else vo_MotifWmHints.decorations = d | ((vo_fsmode & 2) ? MWM_DECOR_MENU : 0);#endif XChangeProperty(vo_Display, w, vo_MotifHints, vo_MotifHints, 32, PropModeReplace, (unsigned char *) &vo_MotifWmHints, (vo_fsmode & 4) ? 4 : 5); }}void vo_x11_classhint(Display * display, Window window, char *name){ XClassHint wmClass; pid_t pid = getpid(); wmClass.res_name = name; wmClass.res_class = "MPlayer"; XSetClassHint(display, window, &wmClass); XChangeProperty(display, window, XA_NET_WM_PID, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &pid, 1);}Window vo_window = None;GC vo_gc = NULL;GC f_gc = NULL;XSizeHints vo_hint;#ifdef HAVE_NEW_GUIvoid vo_setwindow(Window w, GC g){ vo_window = w; vo_gc = g;}#endifvoid vo_x11_uninit(void){ saver_on(mDisplay); if (vo_window != None) vo_showcursor(mDisplay, vo_window); if (f_gc) { XFreeGC(mDisplay, f_gc); f_gc = NULL; }#ifdef HAVE_NEW_GUI /* destroy window only if it's not controlled by the GUI */ if (!use_gui)#endif { if (vo_gc) { XSetBackground(mDisplay, vo_gc, 0); XFreeGC(mDisplay, vo_gc); vo_gc = NULL; } if (vo_window != None) { XClearWindow(mDisplay, vo_window); if (WinID < 0) { XEvent xev; XUnmapWindow(mDisplay, vo_window); XDestroyWindow(mDisplay, vo_window); do { XNextEvent(mDisplay, &xev); } while (xev.type != DestroyNotify || xev.xdestroywindow.event != vo_window); } vo_window = None; } vo_fs = 0; vo_old_width = vo_old_height = 0; }}static unsigned int mouse_timer;static int mouse_waiting_hide;int vo_x11_check_events(Display * mydisplay){ int ret = 0; XEvent Event; char buf[100]; KeySym keySym; static XComposeStatus stat;// unsigned long vo_KeyTable[512]; if ((vo_mouse_autohide) && mouse_waiting_hide && (GetTimerMS() - mouse_timer >= 1000)) { vo_hidecursor(mydisplay, vo_window); mouse_waiting_hide = 0; } while (XPending(mydisplay)) { XNextEvent(mydisplay, &Event);#ifdef HAVE_NEW_GUI if (use_gui) { guiGetEvent(0, (char *) &Event); if (vo_window != Event.xany.window) continue; }#endif// printf("\rEvent.type=%X \n",Event.type); switch (Event.type) { case Expose: ret |= VO_EVENT_EXPOSE; break; case ConfigureNotify:// if (!vo_fs && (Event.xconfigure.width == vo_screenwidth || Event.xconfigure.height == vo_screenheight)) break;// if (vo_fs && Event.xconfigure.width != vo_screenwidth && Event.xconfigure.height != vo_screenheight) break; if (vo_window == None) break; vo_dwidth = Event.xconfigure.width; vo_dheight = Event.xconfigure.height;#if 0 /* when resizing, x and y are zero :( */ vo_dx = Event.xconfigure.x; vo_dy = Event.xconfigure.y;#else { Window root; int foo; Window win; XGetGeometry(mydisplay, vo_window, &root, &foo, &foo, &foo /*width */ , &foo /*height */ , &foo, &foo); XTranslateCoordinates(mydisplay, vo_window, root, 0, 0, &vo_dx, &vo_dy, &win); }#endif ret |= VO_EVENT_RESIZE; break; case KeyPress: { int key;#ifdef HAVE_NEW_GUI if ( use_gui ) { break; }#endif XLookupString(&Event.xkey, buf, sizeof(buf), &keySym, &stat);#ifdef XF86XK_AudioPause vo_x11_putkey_ext(keySym);#endif key = ((keySym & 0xff00) != 0 ? ((keySym & 0x00ff) + 256) : (keySym)); vo_x11_putkey(key); ret |= VO_EVENT_KEYPRESS; } break; case MotionNotify: if(enable_mouse_movements) { char cmd_str[40]; sprintf(cmd_str,"set_mouse_pos %i %i",Event.xmotion.x, Event.xmotion.y); mp_input_queue_cmd(mp_input_parse_cmd(cmd_str)); } if (vo_mouse_autohide) { vo_showcursor(mydisplay, vo_window); mouse_waiting_hide = 1; mouse_timer = GetTimerMS(); } break; case ButtonPress: if (vo_mouse_autohide) { vo_showcursor(mydisplay, vo_window); mouse_waiting_hide = 1; mouse_timer = GetTimerMS(); }#ifdef HAVE_NEW_GUI // Ignore mouse button 1-3 under GUI. if (use_gui && (Event.xbutton.button >= 1) && (Event.xbutton.button <= 3)) break;#endif mplayer_put_key((MOUSE_BTN0 + Event.xbutton.button - 1) | MP_KEY_DOWN); break; case ButtonRelease: if (vo_mouse_autohide) { vo_showcursor(mydisplay, vo_window); mouse_waiting_hide = 1; mouse_timer = GetTimerMS(); }#ifdef HAVE_NEW_GUI // Ignore mouse button 1-3 under GUI. if (use_gui && (Event.xbutton.button >= 1) && (Event.xbutton.button <= 3)) break;#endif mplayer_put_key(MOUSE_BTN0 + Event.xbutton.button - 1); break; case PropertyNotify: { char *name = XGetAtomName(mydisplay, Event.xproperty.atom); if (!name) break;// fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",vo_window,name,Event.xproperty.atom ); XFree(name); } break; case MapNotify: vo_hint.win_gravity = old_gravity; XSetWMNormalHints(mDisplay, vo_window, &vo_hint); vo_fs_flip = 0; break; case ClientMessage: if (Event.xclient.message_type == XAWM_PROTOCOLS && Event.xclient.data.l[0] == XAWM_DELETE_WINDOW) mplayer_put_key(KEY_CLOSE_WIN); break; } } return ret;}/** * \brief sets the size and position of the non-fullscreen window. */void vo_x11_nofs_sizepos(int x, int y, int width, int height){ vo_x11_sizehint(x, y, width, height, 0); if (vo_fs) { vo_old_x = x; vo_old_y = y; vo_old_width = width; vo_old_height = height; } else { vo_dwidth = width; vo_dheight = height; XMoveResizeWindow(mDisplay, vo_window, x, y, width, height); }}void vo_x11_sizehint(int x, int y, int width, int height, int max){ vo_hint.flags = 0; if (vo_keepaspect) { vo_hint.flags |= PAspect; vo_hint.min_aspect.x = width; vo_hint.min_aspect.y = height; vo_hint.max_aspect.x = width; vo_hint.max_aspect.y = height; } vo_hint.flags |= PPosition | PSize; vo_hint.x = x; vo_hint.y = y; vo_hint.width = width; vo_hint.height = height; if (max) { vo_hint.flags |= PMaxSize; vo_hint.max_width = width; vo_hint.max_height = height; } else { vo_hint.max_width = 0; vo_hint.max_height = 0; } // Set minimum height/width to 4 to avoid off-by-one errors // and because mga_vid requires a minimal size of 4 pixels. vo_hint.flags |= PMinSize; vo_hint.min_width = vo_hint.min_height = 4; vo_hint.flags |= PWinGravity; vo_hint.win_gravity = StaticGravity; XSetWMNormalHints(mDisplay, vo_window, &vo_hint);}static int vo_x11_get_gnome_layer(Display * mDisplay, Window win){ Atom type; int format; unsigned long nitems; unsigned long bytesafter; unsigned short *args = NULL; if (XGetWindowProperty(mDisplay, win, XA_WIN_LAYER, 0, 16384, False, AnyPropertyType, &type, &format, &nitems, &bytesafter, (unsigned char **) &args) == Success && nitems > 0 && args) { mp_msg(MSGT_VO, MSGL_V, "[x11] original window layer is %d.\n", *args); return *args; } return WIN_LAYER_NORMAL;}//Window vo_x11_create_smooth_window(Display * mDisplay, Window mRoot, Visual * vis, int x, int y, unsigned int width, unsigned int height, int depth, Colormap col_map){ unsigned long xswamask = CWBackingStore | CWBorderPixel; XSetWindowAttributes xswa; Window ret_win; if (col_map != CopyFromParent) { xswa.colormap = col_map; xswamask |= CWColormap; } xswa.background_pixel = 0; xswa.border_pixel = 0; xswa.backing_store = Always; xswa.bit_gravity = StaticGravity; ret_win = XCreateWindow(mDisplay, mRootWin, x, y, width, height, 0, depth, CopyFromParent, vis, xswamask, &xswa); XSetWMProtocols(mDisplay, ret_win, &XAWM_DELETE_WINDOW, 1); if (!f_gc) f_gc = XCreateGC(mDisplay, ret_win, 0, 0); XSetForeground(mDisplay, f_gc, 0); return ret_win;}/** * \brief create and setup a window suitable for display * \param vis Visual to use for creating the window * \param x x position of window * \param y y position of window * \param width width of window * \param height height of window * \param flags flags for window creation. * Only VOFLAG_FULLSCREEN is supported so far. * \param col_map Colourmap for window or CopyFromParent if a specific colormap isn't needed * \param classname name to use for the classhint * \param title title for the window * * This also does the grunt-work like setting Window Manager hints etc. * If vo_window is already set it just moves and resizes it. */void vo_x11_create_vo_window(XVisualInfo *vis, int x, int y, unsigned int width, unsigned int height, int flags, Colormap col_map, const char *classname, const char *title){ if (vo_window == None) { XSizeHints hint; XEvent xev; vo_fs = 0; vo_dwidth = width; vo_dheight = height; vo_window = vo_x11_create_smooth_window(mDisplay, mRootWin, vis->visual, x, y, width, height, vis->depth, col_map); vo_x11_classhint(mDisplay, vo_window, classname); XStoreName(mDisplay, vo_window, title); vo_hidecursor(mDisplay, vo_window); XSelectInput(mDisplay, vo_window, StructureNotifyMask); hint.x = x; hint.y = y; hint.width = width; hint.height = height; hint.flags = PPosition | PSize; XSetStandardProperties(mDisplay, vo_window, title, title, None, NULL, 0, &hint); vo_x11_sizehint(x, y, width, height, 0); // map window XMapWindow(mDisplay, vo_window); XClearWindow(mDisplay, vo_window); // wait for map do { XNextEvent(mDisplay, &xev); } while (xev.type != MapNotify || xev.xmap.event != vo_window); XSelectInput(mDisplay, vo_window, NoEventMask); XSync(mDisplay, False); vo_x11_selectinput_witherr(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask); } if (vo_ontop) vo_x11_setlayer(mDisplay, vo_window, vo_ontop); vo_x11_nofs_sizepos(vo_dx, vo_dy, width, height); if (!!vo_fs != !!(flags & VOFLAG_FULLSCREEN)) vo_x11_fullscreen();}void vo_x11_clearwindow_part(Display * mDisplay, Window vo_window, int img_width, int img_height, int use_fs)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?