📄 xf86vmode.c
字号:
/* $XConsortium: XF86VMode.c /main/2 1995/11/14 18:17:58 kaleb $ *//* $XFree86: xc/lib/Xxf86vm/XF86VMode.c,v 3.32 2001/07/25 15:04:54 dawes Exp $ *//*Copyright (c) 1995 Kaleb S. KEITHLEYPermission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice shall beincluded in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL Kaleb S. KEITHLEY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OROTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of Kaleb S. KEITHLEY shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorizationfrom Kaleb S. KEITHLEY.*//* $XConsortium: XF86VMode.c /main/4 1996/01/16 07:52:25 kaleb CHECKEDOUT $ *//* THIS IS NOT AN X CONSORTIUM STANDARD */#define NEED_EVENTS#define NEED_REPLIES#ifndef XBUILD_IN_CLIENT#include <X11/Xlibint.h>#include "xf86vmstr.h"#include <X11/extensions/Xext.h>#include "extutil.h"#else#include "lib/X11/Xlibint.h"#include "include/extensions/xf86vmstr.h"#include "include/extensions/Xext.h"#include "include/extensions/extutil.h"#endif#ifdef DEBUG#include <stdio.h>#endif#ifndef MODE_BAD#define MODE_BAD 255#endifstatic XExtensionInfo _xf86vidmode_info_data;static XExtensionInfo *xf86vidmode_info = &_xf86vidmode_info_data;static char *xf86vidmode_extension_name = XF86VIDMODENAME;#define XF86VidModeCheckExtension(dpy,i,val) \ XextCheckExtension (dpy, i, xf86vidmode_extension_name, val)/***************************************************************************** * * * private utility routines * * * *****************************************************************************/static XEXT_CLOSE_DISPLAY_PROTO(close_display);static /* const */ XExtensionHooks xf86vidmode_extension_hooks = { NULL, /* create_gc */ NULL, /* copy_gc */ NULL, /* flush_gc */ NULL, /* free_gc */ NULL, /* create_font */ NULL, /* free_font */ close_display, /* close_display */ NULL, /* wire_to_event */ NULL, /* event_to_wire */ NULL, /* error */ NULL, /* error_string */};static XEXT_GENERATE_FIND_DISPLAY (find_display, xf86vidmode_info, xf86vidmode_extension_name, &xf86vidmode_extension_hooks, 0, NULL)static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xf86vidmode_info)/***************************************************************************** * * * public XFree86-VidMode Extension routines * * * *****************************************************************************/BoolSDL_NAME(XF86VidModeQueryExtension) (dpy, event_basep, error_basep) Display *dpy; int *event_basep, *error_basep;{ XExtDisplayInfo *info = find_display (dpy); if (XextHasExtension(info)) { *event_basep = info->codes->first_event; *error_basep = info->codes->first_error; return True; } else { return False; }}BoolSDL_NAME(XF86VidModeQueryVersion)(dpy, majorVersion, minorVersion) Display* dpy; int* majorVersion; int* minorVersion;{ XExtDisplayInfo *info = find_display (dpy); xXF86VidModeQueryVersionReply rep; xXF86VidModeQueryVersionReq *req; XF86VidModeCheckExtension (dpy, info, False); LockDisplay(dpy); GetReq(XF86VidModeQueryVersion, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeQueryVersion; if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return False; } *majorVersion = rep.majorVersion; *minorVersion = rep.minorVersion; UnlockDisplay(dpy); SyncHandle(); if (*majorVersion >= 2) SDL_NAME(XF86VidModeSetClientVersion)(dpy); return True;}BoolSDL_NAME(XF86VidModeSetClientVersion)(Display *dpy){ XExtDisplayInfo *info = find_display(dpy); xXF86VidModeSetClientVersionReq *req; XF86VidModeCheckExtension(dpy, info, False); LockDisplay(dpy); GetReq(XF86VidModeSetClientVersion, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeSetClientVersion; req->major = XF86VIDMODE_MAJOR_VERSION; req->minor = XF86VIDMODE_MINOR_VERSION; UnlockDisplay(dpy); SyncHandle(); return True;}BoolSDL_NAME(XF86VidModeSetGamma)(Display *dpy, int screen, SDL_NAME(XF86VidModeGamma) *Gamma){ XExtDisplayInfo *info = find_display(dpy); xXF86VidModeSetGammaReq *req; XF86VidModeCheckExtension(dpy, info, False); LockDisplay(dpy); GetReq(XF86VidModeSetGamma, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeSetGamma; req->screen = screen; req->red = (CARD32)(Gamma->red * 10000.); req->green = (CARD32)(Gamma->green * 10000.); req->blue = (CARD32)(Gamma->blue * 10000.); UnlockDisplay(dpy); SyncHandle(); return True;}BoolSDL_NAME(XF86VidModeGetGamma)(Display *dpy, int screen, SDL_NAME(XF86VidModeGamma) *Gamma){ XExtDisplayInfo *info = find_display (dpy); xXF86VidModeGetGammaReply rep; xXF86VidModeGetGammaReq *req; XF86VidModeCheckExtension (dpy, info, False); LockDisplay(dpy); GetReq(XF86VidModeGetGamma, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeGetGamma; req->screen = screen; if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return False; } Gamma->red = ((float)rep.red) / 10000.; Gamma->green = ((float)rep.green) / 10000.; Gamma->blue = ((float)rep.blue) / 10000.; UnlockDisplay(dpy); SyncHandle(); return True;}BoolSDL_NAME(XF86VidModeGetModeLine)(dpy, screen, dotclock, modeline) Display* dpy; int screen; int* dotclock; SDL_NAME(XF86VidModeModeLine)* modeline;{ XExtDisplayInfo *info = find_display (dpy); xXF86VidModeGetModeLineReply rep; xXF86OldVidModeGetModeLineReply oldrep; xXF86VidModeGetModeLineReq *req; int majorVersion, minorVersion; XF86VidModeCheckExtension (dpy, info, False); SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion); LockDisplay(dpy); GetReq(XF86VidModeGetModeLine, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeGetModeLine; req->screen = screen; if (majorVersion < 2) { if (!_XReply(dpy, (xReply *)&oldrep, (SIZEOF(xXF86OldVidModeGetModeLineReply) - SIZEOF(xReply)) >> 2, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return False; } *dotclock = oldrep.dotclock; modeline->hdisplay = oldrep.hdisplay; modeline->hsyncstart = oldrep.hsyncstart; modeline->hsyncend = oldrep.hsyncend; modeline->htotal = oldrep.htotal; modeline->hskew = 0; modeline->vdisplay = oldrep.vdisplay; modeline->vsyncstart = oldrep.vsyncstart; modeline->vsyncend = oldrep.vsyncend; modeline->vtotal = oldrep.vtotal; modeline->flags = oldrep.flags; modeline->privsize = oldrep.privsize; } else { if (!_XReply(dpy, (xReply *)&rep, (SIZEOF(xXF86VidModeGetModeLineReply) - SIZEOF(xReply)) >> 2, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return False; } *dotclock = rep.dotclock; modeline->hdisplay = rep.hdisplay; modeline->hsyncstart = rep.hsyncstart; modeline->hsyncend = rep.hsyncend; modeline->htotal = rep.htotal; modeline->hskew = rep.hskew; modeline->vdisplay = rep.vdisplay; modeline->vsyncstart = rep.vsyncstart; modeline->vsyncend = rep.vsyncend; modeline->vtotal = rep.vtotal; modeline->flags = rep.flags; modeline->privsize = rep.privsize; } if (modeline->privsize > 0) { if (!(modeline->private = Xcalloc(modeline->privsize, sizeof(INT32)))) { _XEatData(dpy, (modeline->privsize) * sizeof(INT32)); Xfree(modeline->private); return False; } _XRead(dpy, (char*)modeline->private, modeline->privsize * sizeof(INT32)); } else { modeline->private = NULL; } UnlockDisplay(dpy); SyncHandle(); return True;}BoolSDL_NAME(XF86VidModeGetAllModeLines)(dpy, screen, modecount, modelinesPtr) Display* dpy; int screen; int* modecount; SDL_NAME(XF86VidModeModeInfo) ***modelinesPtr;{ XExtDisplayInfo *info = find_display (dpy); xXF86VidModeGetAllModeLinesReply rep; xXF86VidModeGetAllModeLinesReq *req; SDL_NAME(XF86VidModeModeInfo) *mdinfptr, **modelines; xXF86VidModeModeInfo xmdline; xXF86OldVidModeModeInfo oldxmdline; int i; int majorVersion, minorVersion; Bool protocolBug = False; XF86VidModeCheckExtension (dpy, info, False); /* * Note: There was a bug in the protocol implementation in versions * 0.x with x < 8 (the .private field wasn't being passed over the wire). * Check the server's version, and accept the old format if appropriate. */ SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion); if (majorVersion == 0 && minorVersion < 8) { protocolBug = True;#ifdef DEBUG fprintf(stderr, "XF86VidModeGetAllModeLines: Warning: Xserver is" "running an old version (%d.%d)\n", majorVersion, minorVersion);#endif } LockDisplay(dpy); GetReq(XF86VidModeGetAllModeLines, req); req->reqType = info->codes->major_opcode; req->xf86vidmodeReqType = X_XF86VidModeGetAllModeLines; req->screen = screen; if (!_XReply(dpy, (xReply *)&rep, (SIZEOF(xXF86VidModeGetAllModeLinesReply) - SIZEOF(xReply)) >> 2, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return False; } *modecount = rep.modecount; if (!(modelines = (SDL_NAME(XF86VidModeModeInfo) **) Xcalloc(rep.modecount, sizeof(SDL_NAME(XF86VidModeModeInfo) *) +sizeof(SDL_NAME(XF86VidModeModeInfo))))) { if (majorVersion < 2) _XEatData(dpy, (rep.modecount) * sizeof(xXF86OldVidModeModeInfo)); else _XEatData(dpy, (rep.modecount) * sizeof(xXF86VidModeModeInfo)); Xfree(modelines); return False; } mdinfptr = (SDL_NAME(XF86VidModeModeInfo) *) ( (char *) modelines + rep.modecount*sizeof(SDL_NAME(XF86VidModeModeInfo) *) ); for (i = 0; i < rep.modecount; i++) { modelines[i] = mdinfptr++; if (majorVersion < 2) { _XRead(dpy, (char*)&oldxmdline, sizeof(xXF86OldVidModeModeInfo)); modelines[i]->dotclock = oldxmdline.dotclock; modelines[i]->hdisplay = oldxmdline.hdisplay; modelines[i]->hsyncstart = oldxmdline.hsyncstart; modelines[i]->hsyncend = oldxmdline.hsyncend; modelines[i]->htotal = oldxmdline.htotal; modelines[i]->hskew = 0; modelines[i]->vdisplay = oldxmdline.vdisplay; modelines[i]->vsyncstart = oldxmdline.vsyncstart; modelines[i]->vsyncend = oldxmdline.vsyncend; modelines[i]->vtotal = oldxmdline.vtotal; modelines[i]->flags = oldxmdline.flags; if (protocolBug) { modelines[i]->privsize = 0; modelines[i]->private = NULL; } else { modelines[i]->privsize = oldxmdline.privsize; if (oldxmdline.privsize > 0) { if (!(modelines[i]->private = Xcalloc(oldxmdline.privsize, sizeof(INT32)))) { _XEatData(dpy, (oldxmdline.privsize) * sizeof(INT32)); Xfree(modelines[i]->private); } else { _XRead(dpy, (char*)modelines[i]->private, oldxmdline.privsize * sizeof(INT32)); } } else { modelines[i]->private = NULL; } } } else { _XRead(dpy, (char*)&xmdline, sizeof(xXF86VidModeModeInfo)); modelines[i]->dotclock = xmdline.dotclock; modelines[i]->hdisplay = xmdline.hdisplay; modelines[i]->hsyncstart = xmdline.hsyncstart; modelines[i]->hsyncend = xmdline.hsyncend; modelines[i]->htotal = xmdline.htotal; modelines[i]->hskew = xmdline.hskew; modelines[i]->vdisplay = xmdline.vdisplay; modelines[i]->vsyncstart = xmdline.vsyncstart; modelines[i]->vsyncend = xmdline.vsyncend; modelines[i]->vtotal = xmdline.vtotal; modelines[i]->flags = xmdline.flags; if (protocolBug) { modelines[i]->privsize = 0; modelines[i]->private = NULL; } else { modelines[i]->privsize = xmdline.privsize;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -