本文整理匯總了C++中DefaultDepth函數的典型用法代碼示例。如果您正苦於以下問題:C++ DefaultDepth函數的具體用法?C++ DefaultDepth怎麽用?C++ DefaultDepth使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了DefaultDepth函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: mume_x11_create_window
Window mume_x11_create_window(
Display *display, int type, Window parent,
int x, int y, unsigned int width, unsigned int height,
unsigned int clazz, int eventmask)
{
int screen;
int depth;
Visual *visual;
unsigned long valuemask;
XSetWindowAttributes attributes;
XSizeHints *size_hints;
XWMHints *wm_hints;
XClassHint *class_hints;
Window window;
screen = DefaultScreen(display);
visual = DefaultVisual(display, screen);
if (clazz != InputOnly) {
depth = DefaultDepth(display, screen);
valuemask = CWBackPixel | CWBorderPixel;
attributes.background_pixel = WhitePixel(display, screen);
attributes.border_pixel = BlackPixel(display, screen);
if (MUME_BACKWIN_MENU == type) {
assert(RootWindow(display, screen) == parent);
valuemask |= CWSaveUnder | CWOverrideRedirect;
attributes.save_under = True;
attributes.override_redirect = True;
}
}
else {
depth = 0;
valuemask = 0;
}
if (None == parent)
parent = RootWindow(display, screen);
window = XCreateWindow(
display, parent, x, y, width, height, 0, depth,
clazz, visual, valuemask, &attributes);
if (clazz != InputOnly) {
/* Setup standard properties. */
if (!(size_hints = XAllocSizeHints()))
mume_abort(("allocating memory failed!\n"));
if (!(wm_hints = XAllocWMHints()))
mume_abort(("allocating memory failed!\n"));
if (!(class_hints = XAllocClassHint()))
mume_abort(("allocating memory failed!\n"));
size_hints->flags = PPosition | PSize | PMinSize;
size_hints->min_width = 0;
size_hints->min_height = 0;
wm_hints->initial_state = NormalState;
wm_hints->input = True;
/* wm_hints->icon_pixmap = icon_pixmap; */
wm_hints->flags = StateHint/* | IconPixmapHint*/ | InputHint;
class_hints->res_name = "mume";
class_hints->res_class = "mume";
/* or use XSizeHints, XSetClassHint, XSetWMHints */
XmbSetWMProperties(display, window, "mume", "mume",
NULL, 0, size_hints, wm_hints, class_hints);
XFree(wm_hints);
XFree(class_hints);
XFree(size_hints);
}
/* Select event */
XSelectInput(display, window, eventmask);
return window;
}
示例2: main
int main(int ac, char **av)
{
Display *xDpy = XOpenDisplay(NULL);
int screenId;
GC gc;
XGCValues values;
Pixmap blendPixmap;
vertexDataRec warpData[6];
int nvDpyId;
if (!xDpy) {
fprintf (stderr, "Could not open X Display %s!\n", XDisplayName(NULL));
return 1;
}
screenId = XDefaultScreen(xDpy);
if (ac != 2) {
fprintf (stderr, "Usage: ./nv-control-warpblend nvDpyId\n");
fprintf (stderr, "See 'nvidia-settings -q CurrentMetaMode' for currently connected DPYs.\n");
return 1;
}
nvDpyId = atoi(av[1]);
// Start with two screen-aligned triangles, and warp them using the sample
// keystone matrix in transformPoint. Make sure we save W for correct
// perspective and pass it through as the last texture coordinate component.
warpData[0].pos.x = 0.0f;
warpData[0].pos.y = 0.0f;
warpData[0].tex.x = 0.0f;
warpData[0].tex.y = 0.0f;
warpData[0].tex2.x = 0.0f;
warpData[0].tex2.y = transformPoint(&warpData[0].pos);
warpData[1].pos.x = 1.0f;
warpData[1].pos.y = 0.0f;
warpData[1].tex.x = 1.0f;
warpData[1].tex.y = 0.0f;
warpData[1].tex2.x = 0.0f;
warpData[1].tex2.y = transformPoint(&warpData[1].pos);
warpData[2].pos.x = 0.0f;
warpData[2].pos.y = 1.0f;
warpData[2].tex.x = 0.0f;
warpData[2].tex.y = 1.0f;
warpData[2].tex2.x = 0.0f;
warpData[2].tex2.y = transformPoint(&warpData[2].pos);
warpData[3].pos.x = 1.0f;
warpData[3].pos.y = 0.0f;
warpData[3].tex.x = 1.0f;
warpData[3].tex.y = 0.0f;
warpData[3].tex2.x = 0.0f;
warpData[3].tex2.y = transformPoint(&warpData[3].pos);
warpData[4].pos.x = 1.0f;
warpData[4].pos.y = 1.0f;
warpData[4].tex.x = 1.0f;
warpData[4].tex.y = 1.0f;
warpData[4].tex2.x = 0.0f;
warpData[4].tex2.y = transformPoint(&warpData[4].pos);
warpData[5].pos.x = 0.0f;
warpData[5].pos.y = 1.0f;
warpData[5].tex.x = 0.0f;
warpData[5].tex.y = 1.0f;
warpData[5].tex2.x = 0.0f;
warpData[5].tex2.y = transformPoint(&warpData[5].pos);
// Prime the random number generator, since the helper functions need it.
srand(time(NULL));
// Apply our transformed warp data to the chosen display.
XNVCTRLSetScanoutWarping(xDpy,
screenId,
nvDpyId,
NV_CTRL_WARP_DATA_TYPE_MESH_TRIANGLES_XYUVRQ,
6, // 6 vertices for two triangles
(float *)warpData);
// Create a sample blending pixmap; let's make it solid white with a grey
// border and rely on upscaling with filtering to feather the edges.
// Start with a 32x32 pixmap.
blendPixmap = XCreatePixmap(xDpy, RootWindow(xDpy, screenId), 32, 32, DefaultDepth(xDpy, screenId));
values.foreground = 0x77777777;
gc = XCreateGC(xDpy, blendPixmap, GCForeground, &values);
// Fill it fully with grey.
XFillRectangle(xDpy, blendPixmap, gc, 0, 0, 32, 32);
values.foreground = 0xffffffff;
XChangeGC(xDpy, gc, GCForeground, &values);
// Fill everything but a one-pixel border with white.
XFillRectangle(xDpy, blendPixmap, gc, 1, 1, 30, 30);
// Apply it to the display. blendAfterWarp is FALSE, so the edges will be
//.........這裏部分代碼省略.........
示例3: alock_bg_shade_init
static int alock_bg_shade_init(const char* args, struct aXInfo* xinfo) {
char* color_name = strdup("black");
unsigned int shade = 80;
Pixmap src_pm = None;
Pixmap dst_pm = None;
int width = 0;
int height = 0;
if (!xinfo || !args)
return 0;
if (strstr(args, "shade:") == args && strlen(&args[6]) > 0) {
char* arguments = strdup(&args[6]);
char* tmp;
char* arg = NULL;
for (tmp = arguments; tmp; ) {
arg = strsep(&tmp, ",");
if (arg) {
if (strstr(arg, "color=") == arg && strlen(arg) > 6 && strlen(&arg[6])) {
free(color_name);
color_name = strdup(&arg[6]);
}
else if (strstr(arg, "shade=") == arg && strlen(arg) > 6 && strlen(&arg[6])) {
long int tmp_shade;
char* tmp_char;
tmp_shade = strtol(&arg[6], &tmp_char, 0);
if ((!tmp_shade || tmp_char != &arg[6]) && tmp_shade > 0 && tmp_shade < 100)
shade = tmp_shade;
else {
printf("%s", "alock: error, given value invalid or out of range for [shade].\n");
free(arguments);
free(color_name);
return 0;
}
}
}
}
free(arguments);
}
if (!alock_check_xrender(xinfo)) {
free(color_name);
return 0;
}
{
window = (Window*)calloc(xinfo->nr_screens, sizeof(Window));
color = (XColor*)calloc(xinfo->nr_screens, sizeof(XColor));
}
{
int scr;
for (scr = 0; scr < xinfo->nr_screens; scr++) {
/* get a color from color_name */
alock_alloc_color(xinfo, scr, color_name, "black", &color[scr]);
width = xinfo->width_of_root[scr];
height = xinfo->height_of_root[scr];
{ /* xrender stuff */
Display* dpy = xinfo->display;
Window root = xinfo->root[scr];
int depth = DefaultDepth(dpy, scr);
GC gc = DefaultGC(dpy, scr);
{ /* grab whats on the screen */
XImage* image = XGetImage(dpy, root, 0, 0, width, height, AllPlanes, ZPixmap);
src_pm = XCreatePixmap(dpy, root, width, height, depth);
XPutImage(dpy, src_pm, gc, image, 0, 0, 0, 0, width, height);
XDestroyImage(image);
}
dst_pm = XCreatePixmap(dpy, root, width, height, depth);
{ /* tint the dst*/
GC tintgc;
XGCValues tintval;
tintval.foreground = color[scr].pixel;
tintgc = XCreateGC(dpy, dst_pm, GCForeground, &tintval);
XFillRectangle(dpy, dst_pm, tintgc, 0, 0, width, height);
XFreeGC(dpy, tintgc);
}
alock_shade_pixmap(xinfo, scr, src_pm, dst_pm, shade, 0, 0, 0, 0, width, height);
}
{ /* create final window */
XSetWindowAttributes xswa;
long xsmask = 0;
xswa.override_redirect = True;
xswa.colormap = xinfo->colormap[scr];
xswa.background_pixmap = dst_pm;
xsmask |= CWOverrideRedirect;
//.........這裏部分代碼省略.........
示例4: setup
void
setup(int topbar, const char *bg, unsigned int lines) {
int x = 0, y = 0; /* position of the window */
/* if (!dc) { */
dc = initdc();
/* } */
initfont(dc, font);
XInitThreads();
screen = DefaultScreen(dc->dpy);
Window root = RootWindow(dc->dpy, screen);
XSetWindowAttributes swa;
XIM xim;
#ifdef XINERAMA
int n;
XineramaScreenInfo *info;
#endif
clip = XInternAtom(dc->dpy, "CLIPBOARD", False);
utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);
/* calculate menu geometry */
bh = dc->font.height + 2;
lines = MAX(lines, 0);
mh = (lines + 1) * bh;
#ifdef XINERAMA
if((info = XineramaQueryScreens(dc->dpy, &n))) {
int a, j, di, i = 0, area = 0;
unsigned int du;
Window w, pw, dw, *dws;
XWindowAttributes wa;
XGetInputFocus(dc->dpy, &w, &di);
if(w != root && w != PointerRoot && w != None) {
/* find top-level window containing current input focus */
do {
if(XQueryTree(dc->dpy, (pw = w), &dw, &w, &dws, &du) && dws)
XFree(dws);
} while(w != root && w != pw);
/* find xinerama screen with which the window intersects most */
if(XGetWindowAttributes(dc->dpy, pw, &wa))
for(j = 0; j < n; j++)
if((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) {
area = a;
i = j;
}
}
/* no focused window is on screen, so use pointer location instead */
if(!area && XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du))
for(i = 0; i < n; i++)
if(INTERSECT(x, y, 1, 1, info[i]))
break;
x = info[i].x_org;
y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
mw = info[i].width;
XFree(info);
}
else
#endif
{
x = 0;
y = topbar ? 0 : DisplayHeight(dc->dpy, screen) - mh;
mw = DisplayWidth(dc->dpy, screen);
}
/* create menu window */
swa.override_redirect = True;
swa.background_pixel = getcolor(dc, bg);
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0,
DefaultDepth(dc->dpy, screen), CopyFromParent,
DefaultVisual(dc->dpy, screen),
CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
XResizeWindow(dc->dpy, win, mw, mh);
/* open input methods */
xim = XOpenIM(dc->dpy, NULL, NULL, NULL);
xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
XNClientWindow, win, XNFocusWindow, win, NULL);
XMapRaised(dc->dpy, win);
resizedc(dc, mw, mh);
mapdc(dc, win, mw, mh);
}
示例5: value
XImage *xNewImage (Display *dpy /* display pointer */,
unsigned long pmin /* minimum pixel value (corresponding to byte=0) */,
unsigned long pmax /* maximum pixel value (corresponding to byte=255) */,
int width /* number of bytes in x dimension */,
int height /* number of bytes in y dimension */,
float blank /* portion for blanking (0 to 1) */,
unsigned char *bytes /* unsigned bytes to be mapped to an image */)
/*< make a new image of pixels from bytes >*/
/******************************************************************************
Author: Dave Hale, Colorado School of Mines, 06/08/90
*****************************************************************************/
{
int scr=DefaultScreen(dpy);
int i,j,k,line,iline,jline,widthpad;
float base,scale;
unsigned long map[256],bkgnd;
unsigned char *data;
int byte_perpixel;
unsigned int depth;
XImage *xim;
xim=(XImage *) NULL;
depth=(unsigned int)DefaultDepth(dpy,scr);
byte_perpixel=4;
if(depth<=8) byte_perpixel=1;
else if(depth<=16) byte_perpixel=2;
/* else if(depth<=24) byte_perpixel=3;*/
/* build map for translating bytes to pixels */
base = ((double) pmin)+0.499;
scale = ((double) (pmax-pmin))/255.0;
for (i=0; i<=255; ++i){
map[i] = base+i*scale;
}
/* blanking */
bkgnd = (unsigned long) WhitePixel(dpy,scr);
j = SF_MAX(0,SF_MIN(256,(int)(256*blank)));
for (i = 0; i < j; i++)
map[255-i] = bkgnd;
/* allocate memory for image data */
widthpad = (1+(width-1)/(BitmapPad(dpy)/8))*BitmapPad(dpy)/8;
data = (unsigned char*) sf_alloc(widthpad*height,byte_perpixel);
xim=XCreateImage( (Display *) dpy,
(Visual *) DefaultVisual(dpy,scr),
(unsigned int) DefaultDepth(dpy,scr),
(int) ZPixmap,
(int) 0,
(char *) data,
(unsigned int) widthpad,
(unsigned int) height,
/* (int) BitmapPad(dpy),
(int) widthpad*byte_perpixel
*/
8,0);
byte_perpixel=xim->bits_per_pixel/8;
/* fprintf(stderr,"\nbyte_perpixel = %d, depth= %d\n", byte_perpixel,depth); */
/* translate bytes to pixels, padding scanlines as necessary */
for (line=0; line<height; line++) {
iline = line*width;
jline = line*widthpad;
for (i=iline,j=jline,k=0; k<width; ++i,++j,++k)
{ if(byte_perpixel==1)
((unsigned char *)data)[j] =(unsigned char)map[bytes[i]];
if(byte_perpixel==2)
{
int edn=xim->byte_order;
if(edn==LSBFirst){
((unsigned char *)data)[j*2+0] =(unsigned char)(truecolor_pixel[bytes[i]]);
((unsigned char *)data)[j*2+1] =(unsigned char)(truecolor_pixel[bytes[i]]>>8);
}else{
((unsigned char *)data)[j*2+0] =(unsigned char)(truecolor_pixel[bytes[i]]>>24);
((unsigned char *)data)[j*2+1] =(unsigned char)(truecolor_pixel[bytes[i]]>>16);
}
/*((unsigned short *)data)[j] =(unsigned short)(truecolor_pixel[bytes[i]]);*/
}
示例6: CGX_SetIcon
void CGX_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
{
#if 0
SDL_Surface *sicon;
XWMHints *wmhints;
XImage *icon_image;
Pixmap icon_pixmap;
Pixmap mask_pixmap;
#ifdef USE_ICON_WINDOW
Window icon_window;
#endif
GC GC;
XGCValues GCvalues;
int i, b, dbpp;
SDL_Rect bounds;
Uint8 *LSBmask, *color_tried;
Visual *dvis;
/* Lock the event thread, in multi-threading environments */
SDL_Lock_EventThread();
/* The icon must use the default visual, depth and colormap of the
screen, so it might need a conversion */
dbpp = DefaultDepth(SDL_Display, SDL_Screen);
switch(dbpp) {
case 15:
dbpp = 16; break;
case 24:
dbpp = 32; break;
}
dvis = DefaultVisual(SDL_Display, SDL_Screen);
/* The Visual struct is supposed to be opaque but we cheat a little */
sicon = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h,
dbpp,
dvis->red_mask, dvis->green_mask,
dvis->blue_mask, 0);
if ( sicon == NULL ) {
goto done;
}
/* If we already have allocated colours from the default colormap,
copy them */
if(SDL_Visual == dvis && SDL_XColorMap == SDL_DisplayColormap
&& this->screen->format->palette && sicon->format->palette) {
memcpy(sicon->format->palette->colors,
this->screen->format->palette->colors,
this->screen->format->palette->ncolors * sizeof(SDL_Color));
}
bounds.x = 0;
bounds.y = 0;
bounds.w = icon->w;
bounds.h = icon->h;
if ( SDL_LowerBlit(icon, &bounds, sicon, &bounds) < 0 )
goto done;
/* Lock down the colors used in the colormap */
color_tried = NULL;
if ( sicon->format->BitsPerPixel == 8 ) {
SDL_Palette *palette;
Uint8 *p;
XColor wanted;
palette = sicon->format->palette;
color_tried = malloc(palette->ncolors);
if ( color_tried == NULL ) {
goto done;
}
if ( SDL_iconcolors != NULL ) {
free(SDL_iconcolors);
}
SDL_iconcolors = malloc(palette->ncolors
* sizeof(*SDL_iconcolors));
if ( SDL_iconcolors == NULL ) {
free(color_tried);
goto done;
}
memset(color_tried, 0, palette->ncolors);
memset(SDL_iconcolors, 0,
palette->ncolors * sizeof(*SDL_iconcolors));
p = (Uint8 *)sicon->pixels;
for ( i = sicon->w*sicon->h; i > 0; --i, ++p ) {
if ( ! color_tried[*p] ) {
wanted.pixel = *p;
wanted.red = (palette->colors[*p].r<<8);
wanted.green = (palette->colors[*p].g<<8);
wanted.blue = (palette->colors[*p].b<<8);
wanted.flags = (DoRed|DoGreen|DoBlue);
if (XAllocColor(SDL_Display,
SDL_DisplayColormap, &wanted)) {
++SDL_iconcolors[wanted.pixel];
}
color_tried[*p] = 1;
}
}
}
if ( color_tried != NULL ) {
free(color_tried);
//.........這裏部分代碼省略.........
示例7: SilChessMachine
XSilChessWindow::XSilChessWindow(XtAppContext app, Widget toplevel,
Visual * vsl, int vsldepth, Colormap cmap)
{
char tmp[512];
Arg al[10];
int i;
XmString xms;
// Initialize member variables
App=app;
TopLevel=toplevel;
Disp=XtDisplay(TopLevel);
Vsl=vsl;
VslDepth=vsldepth;
CMap=cmap;
DlgVsl=DefaultVisual(Disp,XScreenNumberOfScreen(XtScreen(TopLevel)));
DlgVslDepth=DefaultDepth(Disp,XScreenNumberOfScreen(XtScreen(TopLevel)));
DlgCMap=DefaultColormap(Disp,XScreenNumberOfScreen(XtScreen(TopLevel)));
PixelSize=(VslDepth<=8 ? 1 : (VslDepth<=16 ? 2 : 4));
RedMask=Vsl->red_mask;
GreenMask=Vsl->green_mask;
BlueMask=Vsl->blue_mask;
SelX=SelY-1;
IsSearching=false;
AbortSearching=false;
NeedPainting=false;
IsPainting=false;
HintWanted=false;
HintValid=false;
// Create main window
MainWin=XtVaCreateManagedWidget(
"mainWin",xmMainWindowWidgetClass,TopLevel,
(char*)NULL
);
// Create main menu bar
MainMenu=XmCreateMenuBar(MainWin,(char*)"mainMenu",NULL,0);
XtManageChild(MainMenu);
// Create menu item: file
XtSetArg(al[0],XmNvisual,Vsl);
XtSetArg(al[1],XmNdepth,VslDepth);
XtSetArg(al[2],XmNcolormap,CMap);
FileMenu=XmCreatePulldownMenu(MainMenu,(char*)"fileMenu",al,3);
BFile=XtVaCreateManagedWidget(
"file",xmCascadeButtonWidgetClass,MainMenu,
XmNsubMenuId,FileMenu,
(char*)NULL
);
// Create menu item: file/load
BFileLoad=XtVaCreateManagedWidget(
"load",xmPushButtonWidgetClass,FileMenu,
(char*)NULL
);
XtAddCallback(BFileLoad,XmNactivateCallback,HandleCallback,this);
// Create menu item: file/save
BFileSave=XtVaCreateManagedWidget(
"save",xmPushButtonWidgetClass,FileMenu,
(char*)NULL
);
XtAddCallback(BFileSave,XmNactivateCallback,HandleCallback,this);
// Create menu item: file/exit
XtVaCreateManagedWidget(
"separator",xmSeparatorWidgetClass,FileMenu,
(char*)NULL
);
BFileExit=XtVaCreateManagedWidget(
"exit",xmPushButtonWidgetClass,FileMenu,
(char*)NULL
);
XtAddCallback(BFileExit,XmNactivateCallback,HandleCallback,this);
// Create menu item: game
XtSetArg(al[0],XmNvisual,Vsl);
XtSetArg(al[1],XmNdepth,VslDepth);
XtSetArg(al[2],XmNcolormap,CMap);
GameMenu=XmCreatePulldownMenu(MainMenu,(char*)"gameMenu",al,3);
BGame=XtVaCreateManagedWidget(
"game",xmCascadeButtonWidgetClass,MainMenu,
XmNsubMenuId,GameMenu,
(char*)NULL
);
// Create menu item: game/new
BGameNew=XtVaCreateManagedWidget(
"new",xmPushButtonWidgetClass,GameMenu,
(char*)NULL
);
XtAddCallback(BGameNew,XmNactivateCallback,HandleCallback,this);
// Create menu item: game/flip
BGameFlip=XtVaCreateManagedWidget(
"flip",xmPushButtonWidgetClass,GameMenu,
(char*)NULL
);
XtAddCallback(BGameFlip,XmNactivateCallback,HandleCallback,this);
//.........這裏部分代碼省略.........
示例8: lockscreen
static Lock *
lockscreen(Display *dpy, int screen) {
char curs[] = {0, 0, 0, 0, 0, 0, 0, 0};
unsigned int len;
Lock *lock;
XColor color;
XSetWindowAttributes wa;
Cursor invisible;
int hue1, hue2;
if(dpy == NULL || screen < 0)
return NULL;
lock = malloc(sizeof(Lock));
if(lock == NULL)
return NULL;
lock->screen = screen;
lock->root = RootWindow(dpy, lock->screen);
/* init */
wa.override_redirect = 1;
lock->win = XCreateWindow(dpy, lock->root, 0, 0, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen),
0, DefaultDepth(dpy, lock->screen), CopyFromParent,
DefaultVisual(dpy, lock->screen), CWOverrideRedirect | CWBackPixel, &wa);
/* locked color */
hue1 = rand() % 360;
gen_random_pastel(&color, hue1);
XAllocColor(dpy, DefaultColormap(dpy, lock->screen), &color);
lock->colors[0] = color.pixel;
XSetWindowBackground(dpy, lock->win, lock->colors[0]);
/* trying to unlock color */
hue2 = hue1 + 180;
if (hue2 >= 360) {
hue2 -= 360;
}
gen_random_pastel(&color, hue2);
XAllocColor(dpy, DefaultColormap(dpy, lock->screen), &color);
lock->colors[1] = color.pixel;
lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8);
invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &color, &color, 0, 0);
XDefineCursor(dpy, lock->win, invisible);
XMapRaised(dpy, lock->win);
for(len = 1000; len; len--) {
if(XGrabPointer(dpy, lock->root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess)
break;
usleep(1000);
}
if(running && (len > 0)) {
for(len = 1000; len; len--) {
if(XGrabKeyboard(dpy, lock->root, True, GrabModeAsync, GrabModeAsync, CurrentTime)
== GrabSuccess)
break;
usleep(1000);
}
}
running &= (len > 0);
if(!running) {
unlockscreen(dpy, lock);
lock = NULL;
}
else
XSelectInput(dpy, lock->root, SubstructureNotifyMask);
return lock;
}
示例9: Init_X
int Init_X (int swidth, int sheight)
{
XGCValues vals;
Colormap TheColormap;
XColor TheColor;
int i;
TheWidth = swidth ;
TheHeight = sheight ;
TheDisplay = XOpenDisplay("\0");
TheRootWindow = DefaultRootWindow(TheDisplay);
TheScreenNumber = DefaultScreen(TheDisplay);
TheDepth = DefaultDepth(TheDisplay, TheScreenNumber);
if (TheDepth != 24) {
printf("24 bit color not supported.\n") ;
printf("Color function not likely to work.\n") ;
}
TheWindow = XCreateSimpleWindow(TheDisplay, TheRootWindow,
0, 0, TheWidth, TheHeight, 0, 0, 0);
if (!TheWindow) return 0 ;
ThePixmap = XCreatePixmap(TheDisplay, TheRootWindow, TheWidth, TheHeight,
TheDepth);
if (!ThePixmap) return 0 ;
TheDrawable = ThePixmap;
XMapWindow(TheDisplay, TheWindow);
XSelectInput(TheDisplay, TheWindow, ExposureMask |
StructureNotifyMask |
PointerMotionMask |
ButtonPressMask |
KeyPressMask );
/*
TheWindowContext = XCreateGC(TheDisplay, TheWindow, 0, 0);
// this is a bad idea ... see test t02.c for an example
// of what can happen to the behavior of the event handler,
// int Handle_Events_X(int *px, int *py)
// if you do this, you'll get runaway calls to Handle_Events
// with the default condition being met and this produces
// a great deal of tearing in the animation of t02.c
*/
/* also a bad idea...same behavior as above
vals.graphics_exposures = 1; // True
*/
// so this is what you want :
vals.graphics_exposures = 0; // False
TheWindowContext = XCreateGC(TheDisplay, TheWindow,
GCGraphicsExposures, &vals);
if (!TheWindowContext) return 0;
ThePixmapContext = XCreateGC(TheDisplay, ThePixmap, 0, 0);
if (!ThePixmapContext) return 0;
TheColormap = DefaultColormap(TheDisplay, TheScreenNumber);
for(i = 0; i < 256; i++) {
TheColor.green = TheColor.blue = TheColor.red = (i << 8) | i;
TheColor.flags = DoRed | DoGreen | DoBlue;
XAllocColor(TheDisplay, TheColormap, &TheColor);
Grays[i] = TheColor.pixel;
}
TheFontInfo = XLoadQueryFont(TheDisplay, TheFont) ;
XSetFont(TheDisplay, TheWindowContext, TheFontInfo->fid) ;
// XClearWindow(TheDisplay, TheWindow);
// XClearArea(TheDisplay, TheWindow, 0,0,0,0,False); // same as above
XClearArea(TheDisplay, TheWindow, 0,0,0,0,True);
// Does the boolean matter here?
// most people expect a white piece of paper
// with a black pencil
Set_Color_Rgb_X (255,255,255) ; // white
Clear_Buffer_X() ; // otherwise you can inherit garbage
// from the parent window
// Set_Color_Rgb_X (255,0,255) ; // purple
// Fill_Rectangle_X(10,10,50,80) ;
// above was just a test
//.........這裏部分代碼省略.........
示例10: WPwcic
short WPwcic(
Window px_id,
short x,
short y,
short bw,
char *fnam,
short cb,
short cf,
WPICON **outptr)
/* Create WPICON.
*
* In: px_id = Parent window X-id.
* x = X-position.
* y = Y-position.
* fnam = Pixmap file.
* cb = Not used.
* cf = Not used.
*
* Ut: *outptr = Ptr to a WPICON.
*
* Felkod: WP1212 = Can't load pixmap file %s
* WP1292 = Can't malloc()
* WP1712 = XPM error code = %s
*
* (C)microform ab 13/1/94 J. Kjellander
*
* 2007-06-17 Xpm, J.Kjellander
*
********************************************************/
{
char errbuf[V3STRLEN];
XSetWindowAttributes xwina;
unsigned long xwinm;
unsigned int dx,dy;
int status;
Window xwin_id;
Pixmap icon_pixmap,icon_mask;
XGCValues values;
XpmAttributes attributes;
WPICON *icoptr;
/*
***Read the xpm-file and create a pixmap. Set attributes to XpmSize so
***that the size of the icon is returned.
***XpmColorError = 1
***XpmSuccess = 0
***XpmOpenFailed = -1
***XpmFileInvalid = -2
***XpmNoMemory = -3
***XpmColorFailed = -4
*/
attributes.valuemask = XpmSize;
status = XpmReadFileToPixmap(xdisp,px_id,fnam,&icon_pixmap,&icon_mask,&attributes);
if ( status != XpmSuccess )
{
sprintf(errbuf,"%d",status);
erpush("WP1712",errbuf);
return(erpush("WP1212",fnam));
}
dx = attributes.width;
dy = attributes.height;
/*
***Create the X window.
*/
xwina.background_pixel = WPgcol(cb);
xwina.border_pixel = WPgcol(WP_BGND2);
xwina.override_redirect = True;
xwina.save_under = False;
xwinm = ( CWBackPixel | CWBorderPixel |
CWOverrideRedirect | CWSaveUnder );
if ( bw > 0 )
{
dx += 2*bw + 2;
dy += 2*bw + 2;
}
xwin_id = XCreateWindow(xdisp,px_id,x,y,dx,dy,bw,
DefaultDepth(xdisp,xscr),
InputOutput,CopyFromParent,xwinm,&xwina);
/*
***Input events.
*/
if ( bw > 0 ) XSelectInput(xdisp,xwin_id,ButtonPressMask |
ButtonReleaseMask |
EnterWindowMask |
LeaveWindowMask);
/*
***Create a WPICON.
*/
if ( (icoptr=(WPICON *)v3mall(sizeof(WPICON),"WPwcic")) == NULL )
return(erpush("WP1292",fnam));
icoptr->id.w_id = (wpw_id)NULL;
//.........這裏部分代碼省略.........
示例11: X11_SetupWindow
/*
* Setup X11 wnd System
*/
void
X11_SetupWindow (GF_VideoOutput * vout)
{
X11VID ();
const char *sOpt;
Bool autorepeat, supported;
xWindow->display = XOpenDisplay (NULL);
xWindow->screennum = DefaultScreen (xWindow->display);
xWindow->screenptr = DefaultScreenOfDisplay (xWindow->display);
xWindow->visual = DefaultVisualOfScreen (xWindow->screenptr);
xWindow->depth = DefaultDepth (xWindow->display, xWindow->screennum);
{
Float screenWidth = (Float)XWidthOfScreen(xWindow->screenptr);
Float screenWidthIn = (Float)XWidthMMOfScreen(xWindow->screenptr) / 25.4f;
Float screenHeight = (Float)XHeightOfScreen(xWindow->screenptr);
Float screenHeightIn = (Float)XHeightMMOfScreen(xWindow->screenptr) / 25.4f;
vout->dpi_x = (u32)(screenWidth / screenWidthIn);
vout->dpi_y = (u32)(screenHeight / screenHeightIn);
}
switch (xWindow->depth) {
case 8:
xWindow->pixel_format = GF_PIXEL_GREYSCALE;
break;
case 16:
xWindow->pixel_format = GF_PIXEL_RGB_565;
break;
case 24:
xWindow->pixel_format = GF_PIXEL_RGB_32;
break;
default:
xWindow->pixel_format = GF_PIXEL_GREYSCALE;
break;
}
xWindow->bpp = xWindow->depth / 8;
xWindow->bpp = xWindow->bpp == 3 ? 4 : xWindow->bpp;
xWindow->screennum=0;
vout->max_screen_width = DisplayWidth(xWindow->display, xWindow->screennum);
vout->max_screen_height = DisplayHeight(xWindow->display, xWindow->screennum);
/*
* Full screen wnd
*/
xWindow->full_wnd = XCreateWindow (xWindow->display,
RootWindowOfScreen (xWindow->screenptr),
0, 0,
vout->max_screen_width,
vout->max_screen_height, 0,
xWindow->depth, InputOutput,
xWindow->visual, 0, NULL);
XSelectInput(xWindow->display, xWindow->full_wnd,
FocusChangeMask | ExposureMask | PointerMotionMask | ButtonReleaseMask | ButtonPressMask | KeyPressMask | KeyReleaseMask);
if (!xWindow->par_wnd) {
xWindow->w_width = 320;
xWindow->w_height = 240;
xWindow->wnd = XCreateWindow (xWindow->display,
RootWindowOfScreen(xWindow->screenptr), 0, 0,
xWindow->w_width, xWindow->w_height, 0,
xWindow->depth, InputOutput,
xWindow->visual, 0, NULL);
XMapWindow (xWindow->display, (Window) xWindow->wnd);
} else {
XWindowAttributes pwa;
XGetWindowAttributes(xWindow->display, xWindow->par_wnd, &pwa);
xWindow->w_width = pwa.width;
xWindow->w_height = pwa.height;
xWindow->wnd = XCreateWindow (xWindow->display, xWindow->par_wnd, pwa.x, pwa.y,
xWindow->w_width, xWindow->w_height, 0,
xWindow->depth, InputOutput,
xWindow->visual, 0, NULL);
XMapWindow (xWindow->display, (Window) xWindow->wnd);
}
XSync(xWindow->display, False);
XUnmapWindow (xWindow->display, (Window) xWindow->wnd);
XSync(xWindow->display, False);
old_handler = XSetErrorHandler(X11_BadAccess_ByPass);
selectinput_err = 0;
XSelectInput(xWindow->display, xWindow->wnd,
FocusChangeMask | StructureNotifyMask | PropertyChangeMask | ExposureMask |
PointerMotionMask | ButtonReleaseMask | ButtonPressMask |
KeyPressMask | KeyReleaseMask);
XSync(xWindow->display, False);
XSetErrorHandler(old_handler);
if (selectinput_err) {
XSelectInput(xWindow->display, xWindow->wnd,
StructureNotifyMask | PropertyChangeMask | ExposureMask |
KeyPressMask | KeyReleaseMask);
GF_LOG(GF_LOG_ERROR, GF_LOG_MMIO, ("[X11] Cannot select input focus\n"));
}
XSync(xWindow->display, False);
XMapWindow (xWindow->display, (Window) xWindow->wnd);
//.........這裏部分代碼省略.........
示例12: read_ppm_file
XImage *
read_ppm_file(Display *disp, Colormap cmap, int depth, IOSTREAM *fd)
{ XImage *img;
long here = Stell(fd);
int c;
int fmt, encoding;
int width, height, bytes_per_line, scale=0;
char *data;
int allocdepth;
int pad = XBitmapPad(disp);
Visual *v = DefaultVisual(disp, DefaultScreen(disp));
ncolours = nmapped = nfailed = 0; /* statistics */
assert(pad%8 == 0);
if ( (c=Sgetc(fd)) != 'P' )
{ Sungetc(c, fd);
return NULL;
}
if ( !cmap )
cmap = DefaultColormap(disp, DefaultScreen(disp));
c = Sgetc(fd);
if ( c < '1' || c > '9' )
goto errout;
c -= '0';
fmt = ((c - 1) % 3) + 1;
encoding = c - fmt;
width = getNum(fd);
height = getNum(fd);
if ( fmt == PNM_PBM )
{ depth = 1;
} else
{ scale = getNum(fd);
if ( !depth )
depth = DefaultDepth(disp, DefaultScreen(disp));
}
if ( width < 0 || height < 0 || scale < 0 )
goto errout;
allocdepth = (depth >= 24 ? 32 : depth);
bytes_per_line = roundup((width*allocdepth+7)/8, pad/8);
data = (char *)pceMalloc(height * bytes_per_line);
img = XCreateImage(disp,
v,
depth,
fmt == PNM_PBM ? XYBitmap : ZPixmap,
0,
data,
width, height,
pad, bytes_per_line);
if ( !img )
{ perror("XCreateImage");
pceFree(data);
goto errout;
}
img->bits_per_pixel = depth;
switch(encoding)
{ int x, y;
case PNM_ASCII:
{ switch(fmt)
{ case PNM_PBM:
for(y=0; y<height; y++)
{ for(x=0; x<width; x++)
{ int value = getNum(fd);
if ( value < 0 || value > 1 )
goto errout;
XPutPixel(img, x, y, value);
}
}
break;
case PNM_PGM:
{ Table t = newTable(64);
for(y=0; y<height; y++)
{ for(x=0; x<width; x++)
{ int g = getNum(fd);
unsigned long pixel;
if ( g < 0 || g > scale )
goto errout;
if ( scale != 255 )
g = rescale(g, scale, 255);
pixel = colourPixel(disp, depth, cmap, t, g, g, g);
XPutPixel(img, x, y, pixel);
}
}
freeTable(t);
break;
//.........這裏部分代碼省略.........
示例13: int
bool GlxBackend::initDrawableConfigs()
{
const int attribs[] = {
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT | GLX_PIXMAP_BIT,
GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
GLX_X_RENDERABLE, True,
GLX_CONFIG_CAVEAT, int(GLX_DONT_CARE), // The ARGB32 visual is marked non-conformant in Catalyst
GLX_RED_SIZE, 5,
GLX_GREEN_SIZE, 5,
GLX_BLUE_SIZE, 5,
GLX_ALPHA_SIZE, 0,
GLX_STENCIL_SIZE, 0,
GLX_DEPTH_SIZE, 0,
0
};
int count = 0;
GLXFBConfig *configs = glXChooseFBConfig(display(), DefaultScreen(display()), attribs, &count);
if (count < 1) {
qCritical() << "Could not find any usable framebuffer configurations.";
return false;
}
for (int i = 0; i <= 32; i++) {
fbcdrawableinfo[i].fbconfig = NULL;
fbcdrawableinfo[i].bind_texture_format = 0;
fbcdrawableinfo[i].texture_targets = 0;
fbcdrawableinfo[i].y_inverted = 0;
fbcdrawableinfo[i].mipmap = 0;
}
// Find the first usable framebuffer configuration for each depth.
// Single-buffered ones will appear first in the list.
const int depths[] = { 15, 16, 24, 30, 32 };
for (unsigned int i = 0; i < sizeof(depths) / sizeof(depths[0]); i++) {
const int depth = depths[i];
for (int j = 0; j < count; j++) {
int alpha_size, buffer_size;
glXGetFBConfigAttrib(display(), configs[j], GLX_ALPHA_SIZE, &alpha_size);
glXGetFBConfigAttrib(display(), configs[j], GLX_BUFFER_SIZE, &buffer_size);
if (buffer_size != depth && (buffer_size - alpha_size) != depth)
continue;
if (depth == 32 && alpha_size != 8)
continue;
XVisualInfo *vi = glXGetVisualFromFBConfig(display(), configs[j]);
if (vi == NULL)
continue;
int visual_depth = vi->depth;
XFree(vi);
if (visual_depth != depth)
continue;
int bind_rgb, bind_rgba;
glXGetFBConfigAttrib(display(), configs[j], GLX_BIND_TO_TEXTURE_RGBA_EXT, &bind_rgba);
glXGetFBConfigAttrib(display(), configs[j], GLX_BIND_TO_TEXTURE_RGB_EXT, &bind_rgb);
// Skip this config if it cannot be bound to a texture
if (!bind_rgb && !bind_rgba)
continue;
int texture_format;
if (depth == 32)
texture_format = bind_rgba ? GLX_TEXTURE_FORMAT_RGBA_EXT : GLX_TEXTURE_FORMAT_RGB_EXT;
else
texture_format = bind_rgb ? GLX_TEXTURE_FORMAT_RGB_EXT : GLX_TEXTURE_FORMAT_RGBA_EXT;
int y_inverted, texture_targets;
glXGetFBConfigAttrib(display(), configs[j], GLX_BIND_TO_TEXTURE_TARGETS_EXT, &texture_targets);
glXGetFBConfigAttrib(display(), configs[j], GLX_Y_INVERTED_EXT, &y_inverted);
fbcdrawableinfo[depth].fbconfig = configs[j];
fbcdrawableinfo[depth].bind_texture_format = texture_format;
fbcdrawableinfo[depth].texture_targets = texture_targets;
fbcdrawableinfo[depth].y_inverted = y_inverted;
fbcdrawableinfo[depth].mipmap = 0;
break;
}
}
if (count)
XFree(configs);
if (fbcdrawableinfo[DefaultDepth(display(), DefaultScreen(display()))].fbconfig == NULL) {
qCritical() << "Could not find a framebuffer configuration for the default depth.";
return false;
}
if (fbcdrawableinfo[32].fbconfig == NULL) {
qCritical() << "Could not find a framebuffer configuration for depth 32.";
return false;
}
//.........這裏部分代碼省略.........
示例14: setup
static void
setup(void)
{
int x, y;
XSetWindowAttributes swa;
XIM xim;
#ifdef XINERAMA
XineramaScreenInfo *info;
Window w, pw, dw, *dws;
XWindowAttributes wa;
int a, j, di, n, i = 0, area = 0;
unsigned int du;
#endif
/* init appearance */
scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor);
scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor);
scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor);
scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor);
scheme[SchemeOut].bg = drw_clr_create(drw, outbgcolor);
scheme[SchemeOut].fg = drw_clr_create(drw, outfgcolor);
clip = XInternAtom(dpy, "CLIPBOARD", False);
utf8 = XInternAtom(dpy, "UTF8_STRING", False);
/* calculate menu geometry */
bh = drw->fonts[0]->h + 2;
lines = MAX(lines, 0);
mh = (lines + 1) * bh;
#ifdef XINERAMA
if ((info = XineramaQueryScreens(dpy, &n))) {
XGetInputFocus(dpy, &w, &di);
if (mon != -1 && mon < n)
i = mon;
else if (w != root && w != PointerRoot && w != None) {
/* find top-level window containing current input focus */
do {
if (XQueryTree(dpy, (pw = w), &dw, &w, &dws, &du) && dws)
XFree(dws);
} while (w != root && w != pw);
/* find xinerama screen with which the window intersects most */
if (XGetWindowAttributes(dpy, pw, &wa))
for (j = 0; j < n; j++)
if ((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) {
area = a;
i = j;
}
}
/* no focused window is on screen, so use pointer location instead */
if (mon == -1 && !area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du))
for (i = 0; i < n; i++)
if (INTERSECT(x, y, 1, 1, info[i]))
break;
x = info[i].x_org;
y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
mw = info[i].width;
XFree(info);
} else
#endif
{
x = 0;
y = topbar ? 0 : sh - mh;
mw = sw;
}
promptw = (prompt && *prompt) ? TEXTW(prompt) : 0;
inputw = MIN(inputw, mw/3);
fuzzymatch();
/* create menu window */
swa.override_redirect = True;
swa.background_pixel = scheme[SchemeNorm].bg->pix;
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
win = XCreateWindow(dpy, root, x, y, mw, mh, 0,
DefaultDepth(dpy, screen), CopyFromParent,
DefaultVisual(dpy, screen),
CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
/* open input methods */
xim = XOpenIM(dpy, NULL, NULL, NULL);
xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
XNClientWindow, win, XNFocusWindow, win, NULL);
XMapRaised(dpy, win);
drw_resize(drw, mw, mh);
drawmenu();
}
示例15: x11grab_read_header
/**
* Initialize the x11 grab device demuxer (public device demuxer API).
*
* @param s1 Context from avformat core
* @param ap Parameters from avformat core
* @return <ul>
* <li>AVERROR(ENOMEM) no memory left</li>
* <li>AVERROR(EIO) other failure case</li>
* <li>0 success</li>
* </ul>
*/
static int
x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
{
struct x11_grab *x11grab = s1->priv_data;
Display *dpy;
AVStream *st = NULL;
enum PixelFormat input_pixfmt;
XImage *image;
int x_off = 0;
int y_off = 0;
int screen;
int use_shm;
char *param, *offset;
int ret = 0;
AVRational framerate;
param = av_strdup(s1->filename);
offset = strchr(param, '+');
if (offset) {
sscanf(offset, "%d,%d", &x_off, &y_off);
x11grab->draw_mouse = !strstr(offset, "nomouse");
*offset= 0;
}
if ((ret = av_parse_video_size(&x11grab->width, &x11grab->height, x11grab->video_size)) < 0) {
av_log(s1, AV_LOG_ERROR, "Couldn't parse video size.\n");
goto out;
}
if ((ret = av_parse_video_rate(&framerate, x11grab->framerate)) < 0) {
av_log(s1, AV_LOG_ERROR, "Could not parse framerate: %s.\n", x11grab->framerate);
goto out;
}
av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d height: %d\n",
s1->filename, param, x_off, y_off, x11grab->width, x11grab->height);
dpy = XOpenDisplay(param);
if(!dpy) {
av_log(s1, AV_LOG_ERROR, "Could not open X display.\n");
ret = AVERROR(EIO);
goto out;
}
st = avformat_new_stream(s1, NULL);
if (!st) {
ret = AVERROR(ENOMEM);
goto out;
}
av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
screen = DefaultScreen(dpy);
if (x11grab->follow_mouse) {
int screen_w, screen_h;
Window w;
screen_w = DisplayWidth(dpy, screen);
screen_h = DisplayHeight(dpy, screen);
XQueryPointer(dpy, RootWindow(dpy, screen), &w, &w, &x_off, &y_off, &ret, &ret, &ret);
x_off -= x11grab->width / 2;
y_off -= x11grab->height / 2;
x_off = FFMIN(FFMAX(x_off, 0), screen_w - x11grab->width);
y_off = FFMIN(FFMAX(y_off, 0), screen_h - x11grab->height);
av_log(s1, AV_LOG_INFO, "followmouse is enabled, resetting grabbing region to x: %d y: %d\n", x_off, y_off);
}
use_shm = XShmQueryExtension(dpy);
av_log(s1, AV_LOG_INFO, "shared memory extension %s found\n", use_shm ? "" : "not");
if(use_shm) {
int scr = XDefaultScreen(dpy);
image = XShmCreateImage(dpy,
DefaultVisual(dpy, scr),
DefaultDepth(dpy, scr),
ZPixmap,
NULL,
&x11grab->shminfo,
x11grab->width, x11grab->height);
x11grab->shminfo.shmid = shmget(IPC_PRIVATE,
image->bytes_per_line * image->height,
IPC_CREAT|0777);
if (x11grab->shminfo.shmid == -1) {
av_log(s1, AV_LOG_ERROR, "Fatal: Can't get shared memory!\n");
ret = AVERROR(ENOMEM);
goto out;
}
x11grab->shminfo.shmaddr = image->data = shmat(x11grab->shminfo.shmid, 0, 0);
x11grab->shminfo.readOnly = False;
if (!XShmAttach(dpy, &x11grab->shminfo)) {
//.........這裏部分代碼省略.........