x11_common.c
来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 2,222 行 · 第 1/5 页
C
2,222 行
DPMSInfo(mDisplay, &state, &onoff); if (onoff) { Status stat; mp_msg(MSGT_VO, MSGL_V, "Disabling DPMS\n"); dpms_disabled = 1; stat = DPMSDisable(mDisplay); // monitor powersave off mp_msg(MSGT_VO, MSGL_V, "DPMSDisable stat: %d\n", stat); } }#endif if (!timeout_save) { XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank, &allow_exp); if (timeout_save) XSetScreenSaver(mDisplay, 0, interval, prefer_blank, allow_exp); } // turning off screensaver if (stop_xscreensaver) xscreensaver_disable(mDisplay); if (stop_xscreensaver && !kdescreensaver_was_running) { kdescreensaver_was_running = (system ("dcop kdesktop KScreensaverIface isEnabled 2>/dev/null | sed 's/1/true/g' | grep true 2>/dev/null >/dev/null") == 0); if (kdescreensaver_was_running) system ("dcop kdesktop KScreensaverIface enable false 2>/dev/null >/dev/null"); }}static XErrorHandler old_handler = NULL;static int selectinput_err = 0;static int x11_selectinput_errorhandler(Display * display, XErrorEvent * event){ if (event->error_code == BadAccess) { selectinput_err = 1; mp_msg(MSGT_VO, MSGL_ERR, "X11 error: BadAccess during XSelectInput Call\n"); mp_msg(MSGT_VO, MSGL_ERR, "X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n"); /* If you think MPlayer should shutdown with this error, * comment out the following line */ return 0; } if (old_handler != NULL) old_handler(display, event); else x11_errorhandler(display, event); return 0;}void vo_x11_selectinput_witherr(Display * display, Window w, long event_mask){ XSync(display, False); old_handler = XSetErrorHandler(x11_selectinput_errorhandler); selectinput_err = 0; if (vo_nomouse_input) { XSelectInput(display, w, event_mask & (~(ButtonPressMask | ButtonReleaseMask))); } else { XSelectInput(display, w, event_mask); } XSync(display, False); XSetErrorHandler(old_handler); if (selectinput_err) { mp_msg(MSGT_VO, MSGL_ERR, "X11 error: MPlayer discards mouse control (reconfiguring)\n"); XSelectInput(display, w, event_mask & (~ (ButtonPressMask | ButtonReleaseMask | PointerMotionMask))); }}#ifdef HAVE_XF86VMvoid vo_vm_switch(uint32_t X, uint32_t Y, int *modeline_width, int *modeline_height){ int vm_event, vm_error; int vm_ver, vm_rev; int i, j, have_vm = 0; int modecount; if (XF86VidModeQueryExtension(mDisplay, &vm_event, &vm_error)) { XF86VidModeQueryVersion(mDisplay, &vm_ver, &vm_rev); mp_msg(MSGT_VO, MSGL_V, "XF86VidMode extension v%i.%i\n", vm_ver, vm_rev); have_vm = 1; } else mp_msg(MSGT_VO, MSGL_WARN, "XF86VidMode extension not available.\n"); if (have_vm) { if (vidmodes == NULL) XF86VidModeGetAllModeLines(mDisplay, mScreen, &modecount, &vidmodes); j = 0; *modeline_width = vidmodes[0]->hdisplay; *modeline_height = vidmodes[0]->vdisplay; for (i = 1; i < modecount; i++) if ((vidmodes[i]->hdisplay >= X) && (vidmodes[i]->vdisplay >= Y)) if ((vidmodes[i]->hdisplay <= *modeline_width) && (vidmodes[i]->vdisplay <= *modeline_height)) { *modeline_width = vidmodes[i]->hdisplay; *modeline_height = vidmodes[i]->vdisplay; j = i; } mp_msg(MSGT_VO, MSGL_INFO, MSGTR_SelectedVideoMode, *modeline_width, *modeline_height, X, Y); XF86VidModeLockModeSwitch(mDisplay, mScreen, 0); XF86VidModeSwitchToMode(mDisplay, mScreen, vidmodes[j]); XF86VidModeSwitchToMode(mDisplay, mScreen, vidmodes[j]); X = (vo_screenwidth - *modeline_width) / 2; Y = (vo_screenheight - *modeline_height) / 2; XF86VidModeSetViewPort(mDisplay, mScreen, X, Y); }}void vo_vm_close(Display * dpy){#ifdef HAVE_NEW_GUI if (vidmodes != NULL && vo_window != None)#else if (vidmodes != NULL)#endif { int i, modecount; int screen; screen = DefaultScreen(dpy); free(vidmodes); vidmodes = NULL; XF86VidModeGetAllModeLines(mDisplay, mScreen, &modecount, &vidmodes); for (i = 0; i < modecount; i++) if ((vidmodes[i]->hdisplay == vo_screenwidth) && (vidmodes[i]->vdisplay == vo_screenheight)) { mp_msg(MSGT_VO, MSGL_INFO, "Returning to original mode %dx%d\n", vo_screenwidth, vo_screenheight); break; } XF86VidModeSwitchToMode(dpy, screen, vidmodes[i]); XF86VidModeSwitchToMode(dpy, screen, vidmodes[i]); free(vidmodes); vidmodes = NULL; }}#endif#endif /* X11_FULLSCREEN *//* * Scan the available visuals on this Display/Screen. Try to find * the 'best' available TrueColor visual that has a decent color * depth (at least 15bit). If there are multiple visuals with depth * >= 15bit, we prefer visuals with a smaller color depth. */int vo_find_depth_from_visuals(Display * dpy, int screen, Visual ** visual_return){ XVisualInfo visual_tmpl; XVisualInfo *visuals; int nvisuals, i; int bestvisual = -1; int bestvisual_depth = -1; visual_tmpl.screen = screen; visual_tmpl.class = TrueColor; visuals = XGetVisualInfo(dpy, VisualScreenMask | VisualClassMask, &visual_tmpl, &nvisuals); if (visuals != NULL) { for (i = 0; i < nvisuals; i++) { mp_msg(MSGT_VO, MSGL_V, "vo: X11 truecolor visual %#lx, depth %d, R:%lX G:%lX B:%lX\n", visuals[i].visualid, visuals[i].depth, visuals[i].red_mask, visuals[i].green_mask, visuals[i].blue_mask); /* * Save the visual index and its depth, if this is the first * truecolor visul, or a visual that is 'preferred' over the * previous 'best' visual. */ if (bestvisual_depth == -1 || (visuals[i].depth >= 15 && (visuals[i].depth < bestvisual_depth || bestvisual_depth < 15))) { bestvisual = i; bestvisual_depth = visuals[i].depth; } } if (bestvisual != -1 && visual_return != NULL) *visual_return = visuals[bestvisual].visual; XFree(visuals); } return bestvisual_depth;}static Colormap cmap = None;static XColor cols[256];static int cm_size, red_mask, green_mask, blue_mask;Colormap vo_x11_create_colormap(XVisualInfo * vinfo){ unsigned k, r, g, b, ru, gu, bu, m, rv, gv, bv, rvu, gvu, bvu; if (vinfo->class != DirectColor) return XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone); /* can this function get called twice or more? */ if (cmap) return cmap; cm_size = vinfo->colormap_size; red_mask = vinfo->red_mask; green_mask = vinfo->green_mask; blue_mask = vinfo->blue_mask; ru = (red_mask & (red_mask - 1)) ^ red_mask; gu = (green_mask & (green_mask - 1)) ^ green_mask; bu = (blue_mask & (blue_mask - 1)) ^ blue_mask; rvu = 65536ull * ru / (red_mask + ru); gvu = 65536ull * gu / (green_mask + gu); bvu = 65536ull * bu / (blue_mask + bu); r = g = b = 0; rv = gv = bv = 0; m = DoRed | DoGreen | DoBlue; for (k = 0; k < cm_size; k++) { int t; cols[k].pixel = r | g | b; cols[k].red = rv; cols[k].green = gv; cols[k].blue = bv; cols[k].flags = m; t = (r + ru) & red_mask; if (t < r) m &= ~DoRed; r = t; t = (g + gu) & green_mask; if (t < g) m &= ~DoGreen; g = t; t = (b + bu) & blue_mask; if (t < b) m &= ~DoBlue; b = t; rv += rvu; gv += gvu; bv += bvu; } cmap = XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocAll); XStoreColors(mDisplay, cmap, cols, cm_size); return cmap;}/* * Via colormaps/gamma ramps we can do gamma, brightness, contrast, * hue and red/green/blue intensity, but we cannot do saturation. * Currently only gamma, brightness and contrast are implemented. * Is there sufficient interest for hue and/or red/green/blue intensity? *//* these values have range [-100,100] and are initially 0 */static int vo_gamma = 0;static int vo_brightness = 0;static int vo_contrast = 0;uint32_t vo_x11_set_equalizer(char *name, int value){ float gamma, brightness, contrast; float rf, gf, bf; int k; /* * IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case * of TrueColor-ed window but be careful: * Unlike the colormaps, which are private for the X client * who created them and thus automatically destroyed on client * disconnect, this gamma ramp is a system-wide (X-server-wide) * setting and _must_ be restored before the process exits. * Unforunately when the process crashes (or gets killed * for some reason) it is impossible to restore the setting, * and such behaviour could be rather annoying for the users. */ if (cmap == None) return VO_NOTAVAIL; if (!strcasecmp(name, "brightness")) vo_brightness = value; else if (!strcasecmp(name, "contrast")) vo_contrast = value; else if (!strcasecmp(name, "gamma")) vo_gamma = value; else return VO_NOTIMPL; brightness = 0.01 * vo_brightness; contrast = tan(0.0095 * (vo_contrast + 100) * M_PI / 4); gamma = pow(2, -0.02 * vo_gamma); rf = (float) ((red_mask & (red_mask - 1)) ^ red_mask) / red_mask; gf = (float) ((green_mask & (green_mask - 1)) ^ green_mask) / green_mask; bf = (float) ((blue_mask & (blue_mask - 1)) ^ blue_mask) / blue_mask; /* now recalculate the colormap using the newly set value */ for (k = 0; k < cm_size; k++) { float s; s = pow(rf * k, gamma); s = (s - 0.5) * contrast + 0.5; s += brightness; if (s < 0) s = 0; if (s > 1) s = 1; cols[k].red = (unsigned short) (s * 65535); s = pow(gf * k, gamma); s = (s - 0.5) * contrast + 0.5; s += brightness; if (s < 0) s = 0; if (s > 1) s = 1; cols[k].green = (unsigned short) (s * 65535); s = pow(bf * k, gamma); s = (s - 0.5) * contrast + 0.5; s += brightness; if (s < 0) s = 0; if (s > 1) s = 1; cols[k].blue = (unsigned short) (s * 65535); } XStoreColors(mDisplay, cmap, cols, cm_size); XFlush(mDisplay); return VO_TRUE;}uint32_t vo_x11_get_equalizer(char *name, int *value){ if (cmap == None) return VO_NOTAVAIL; if (!strcasecmp(name, "brightness")) *value = vo_brightness; else if (!strcasecmp(name, "contrast")) *value = vo_contrast; else if (!strcasecmp(name, "gamma")) *value = vo_gamma; else return VO_NOTIMPL; return VO_TRUE;}#ifdef HAVE_XVint vo_xv_set_eq(uint32_t xv_port, char *name, int value){ XvAttribute *attributes; int i, howmany, xv_atom; mp_dbg(MSGT_VO, MSGL_V, "xv_set_eq called! (%s, %d)\n", name, value); /* get available attributes */ attributes = XvQueryPortAttributes(mDisplay, xv_port, &howmany); for (i = 0; i < howmany && attributes; i++) if (attributes[i].flags & XvSettable) { xv_atom = XInternAtom(mDisplay, attributes[i].name, True);/* since we have SET_DEFAULTS first in our list, we can check if it's available then trigger it if it's ok so that the other values are at default upon query */ if (xv_atom != None) { int hue = 0, port_value, port_min, port_max; if (!strcmp(attributes[i].name, "XV_BRIGHTNESS") && (!strcasecmp(name, "brightness"))) port_value = value; else if (!strcmp(attributes[i].name, "XV_CONTRAST") && (!strcasecmp(name, "contrast"))) port_value = value; else if (!strcmp(attributes[i].name, "XV_SATURATION") && (!strcasecmp(name, "saturation"))) port_value = value; else if (!strcmp(attributes[i].name, "XV_HUE") && (!strcasecmp(name, "hue"))) { port_value = value; hue = 1; } else /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */ if (!strcmp(attributes[i].name, "XV_RED_INTENSITY") && (!strcasecmp(name, "red_intensity"))) port_value = value; else if (!strcmp(attributes[i].name, "XV_GREEN_INTENSITY") && (!strcasecmp(name, "green_intensity"))) port_value = value; else if (!strcmp(attributes[i].name, "XV_BLUE_INTENSITY") && (!strcasecmp(name, "blue_intensity"))) port_value = value; else continue; port_min = attributes[i].min_value; po
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?