FontInfoPtr SuckGlyphsFromServer(Display * dpy, Font font) { Pixmap offscreen; XFontStruct *fontinfo; XImage *image; GC xgc; XGCValues values; int numchars; int width, height, pixwidth; int i, j; XCharStruct *charinfo; XChar2b character; unsigned char *bitmapData; int x, y; int spanLength; int charWidth, charHeight, maxSpanLength; int grabList[MAX_GLYPHS_PER_GRAB]; int glyphsPerGrab = MAX_GLYPHS_PER_GRAB; int numToGrab, thisglyph; FontInfoPtr myfontinfo; fontinfo = XQueryFont(dpy, font); if (!fontinfo) return NULL; numchars = fontinfo->max_char_or_byte2 - fontinfo->min_char_or_byte2 + 1; if (numchars < 1) return NULL; myfontinfo = (FontInfoPtr) malloc(sizeof(FontInfo) + (numchars - 1) * sizeof(PerGlyphInfo)); if (!myfontinfo) return NULL; myfontinfo->min_char = fontinfo->min_char_or_byte2; myfontinfo->max_char = fontinfo->max_char_or_byte2; myfontinfo->max_ascent = fontinfo->max_bounds.ascent; myfontinfo->max_descent = fontinfo->max_bounds.descent; width = fontinfo->max_bounds.rbearing - fontinfo->min_bounds.lbearing; height = fontinfo->max_bounds.ascent + fontinfo->max_bounds.descent; maxSpanLength = (width + 7) / 8; /* Be careful determining the width of the pixmap; the X protocol allows pixmaps of width 2^16-1 (unsigned short size) but drawing coordinates max out at 2^15-1 (signed short size). If the width is too large, we need to limit the glyphs per grab. */ if ((glyphsPerGrab * 8 * maxSpanLength) >= (1 << 15)) { glyphsPerGrab = (1 << 15) / (8 * maxSpanLength); } pixwidth = glyphsPerGrab * 8 * maxSpanLength; offscreen = XCreatePixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), pixwidth, height, 1); values.font = font; values.background = 0; values.foreground = 0; xgc = XCreateGC(dpy, offscreen, GCFont | GCBackground | GCForeground, &values); XFillRectangle(dpy, offscreen, xgc, 0, 0, 8 * maxSpanLength * glyphsPerGrab, height); XSetForeground(dpy, xgc, 1); numToGrab = 0; if (fontinfo->per_char == NULL) { charinfo = &(fontinfo->min_bounds); charWidth = charinfo->rbearing - charinfo->lbearing; charHeight = charinfo->ascent + charinfo->descent; spanLength = (charWidth + 7) / 8; } for (i = 0; i < numchars; i++) { if (fontinfo->per_char != NULL) { charinfo = &(fontinfo->per_char[i]); charWidth = charinfo->rbearing - charinfo->lbearing; charHeight = charinfo->ascent + charinfo->descent; if (charWidth == 0 || charHeight == 0) { /* Still must move raster pos even if empty character */ myfontinfo->glyph[i].width = 0; myfontinfo->glyph[i].height = 0; myfontinfo->glyph[i].xoffset = 0; myfontinfo->glyph[i].yoffset = 0; myfontinfo->glyph[i].advance = charinfo->width; myfontinfo->glyph[i].bitmap = NULL; goto PossiblyDoGrab; } } grabList[numToGrab] = i; /* XXX is this right for large fonts? */ character.byte2 = (i + fontinfo->min_char_or_byte2) & 255; character.byte1 = (i + fontinfo->min_char_or_byte2) >> 8; /* XXX we could use XDrawImageString16 which would also paint the backing rectangle but X server bugs in some scalable font rasterizers makes it more effective to do XFillRectangles to clear the pixmap and XDrawImage16 for the text. */ XDrawString16(dpy, offscreen, xgc, -charinfo->lbearing + 8 * maxSpanLength * numToGrab, charinfo->ascent, &character, 1); numToGrab++; PossiblyDoGrab: if (numToGrab >= glyphsPerGrab || i == numchars - 1) { image = XGetImage(dpy, offscreen, 0, 0, pixwidth, height, 1, XYPixmap); for (j = 0; j < numToGrab; j++) { thisglyph = grabList[j]; if (fontinfo->per_char != NULL) { charinfo = &(fontinfo->per_char[thisglyph]); charWidth = charinfo->rbearing - charinfo->lbearing; charHeight = charinfo->ascent + charinfo->descent; spanLength = (charWidth + 7) / 8; } bitmapData = (unsigned char *)calloc(height * spanLength, sizeof(char)); if (!bitmapData) goto FreeFontAndReturn; DEBUG_GLYPH4("index %d, glyph %d (%d by %d)\n", j, thisglyph + fontinfo->min_char_or_byte2, charWidth, charHeight); for (y = 0; y < charHeight; y++) { for (x = 0; x < charWidth; x++) { /* XXX The algorithm used to suck across the font ensures that each glyph begins on a byte boundary. In theory this would make it convienent to copy the glyph into a byte oriented bitmap. We actually use the XGetPixel function to extract each pixel from the image which is not that efficient. We could either do tighter packing in the pixmap or more efficient extraction from the image. Oh well. */ if (XGetPixel(image, j * maxSpanLength * 8 + x, charHeight - 1 - y)) { DEBUG_GLYPH("x"); bitmapData[y * spanLength + x / 8] |= (1 << (x & 7)); } else { DEBUG_GLYPH(" "); } } DEBUG_GLYPH("\n"); } myfontinfo->glyph[thisglyph].width = charWidth; myfontinfo->glyph[thisglyph].height = charHeight; myfontinfo->glyph[thisglyph].xoffset = charinfo->lbearing; myfontinfo->glyph[thisglyph].yoffset = -charinfo->descent; myfontinfo->glyph[thisglyph].advance = charinfo->width; myfontinfo->glyph[thisglyph].bitmap = bitmapData; } XDestroyImage(image); numToGrab = 0; /* do we need to clear the offscreen pixmap to get more? */ if (i < numchars - 1) { XSetForeground(dpy, xgc, 0); XFillRectangle(dpy, offscreen, xgc, 0, 0, 8 * maxSpanLength * glyphsPerGrab, height); XSetForeground(dpy, xgc, 1); } } } XFreeGC(dpy, xgc); XFreePixmap(dpy, offscreen); return myfontinfo; FreeFontAndReturn: XDestroyImage(image); XFreeGC(dpy, xgc); XFreePixmap(dpy, offscreen); for (j = i - 1; j >= 0; j--) { if (myfontinfo->glyph[j].bitmap) free(myfontinfo->glyph[j].bitmap); } free(myfontinfo); return NULL; }
void xDrawLegendBox (Display *dpy, Window win, int x, int y, int width, int height, float bclip, float wclip, char *units, char *legendfont, char *labelfont, char *title, char *titlefont, char *axescolor, char *titlecolor, char *gridcolor, int style) /***************************************************************************** draw a labeled axes box ****************************************************************************** Input: dpy display pointer win window x x coordinate of upper left corner of box y y coordinate of upper left corner of box width width of box height height of box units label for legend legendfont name of font to use for legend labels labelfont name of font to use for axes labels title axes box title titlefont name of font to use for title axescolor name of color to use for axes titlecolor name of color to use for title gridcolor name of color to use for grid int style NORMAL (axis 1 on bottom, axis 2 on left) SEISMIC (axis 1 on left, axis 2 on top) ****************************************************************************** Notes: xDrawLegendBox will determine the numbered tic incremenet and first numbered tic automatically, if the specified increment is zero. Pad values must be specified in the same units as the corresponding axes values. These pads are useful when the contents of the axes box requires more space than implied by the axes values. For example, the first and last seismic wiggle traces plotted inside an axes box will typically extend beyond the axes values corresponding to the first and last traces. However, all tics will lie within the limits specified in the axes values (x1beg, x1end, x2beg, x2end). ****************************************************************************** Author: Dave Hale, Colorado School of Mines, 01/27/90 Author: Berend Scheffers , TNO Delft, 06/11/92 *****************************************************************************/ { GC gca,gct,gcg; XGCValues *values=NULL; XColor scolor,ecolor; XFontStruct *fa,*ft; XWindowAttributes wa; Colormap cmap; int labelca,labelcd,labelch,labelcw,titleca,titlecd,titlech,titlecw, xa,ya,tw,ticsize,ticb,numb,lstr,scr; float dnum=EPS,amin,amax,base,anum,azero; char str[256]; /* get screen */ scr = DefaultScreen(dpy); /* create graphics contexts */ gca = XCreateGC(dpy,win,0,values); gct = XCreateGC(dpy,win,0,values); gcg = XCreateGC(dpy,win,0,values); /* get and set fonts and determine character dimensions */ fa = XLoadQueryFont(dpy,legendfont); if (fa==NULL) fa = XLoadQueryFont(dpy,"fixed"); if (fa==NULL) { fprintf(stderr,"Cannot load/query legendfont=%s\n",legendfont); exit(-1); } XSetFont(dpy,gca,fa->fid); labelca = fa->max_bounds.ascent; labelcd = fa->max_bounds.descent; labelch = fa->max_bounds.ascent+fa->max_bounds.descent; labelcw = fa->max_bounds.lbearing+fa->max_bounds.rbearing; ft = XLoadQueryFont(dpy,titlefont); if (ft==NULL) ft = XLoadQueryFont(dpy,"fixed"); if (ft==NULL) { fprintf(stderr,"Cannot load/query titlefont=%s\n",titlefont); exit(-1); } XSetFont(dpy,gct,ft->fid); titleca = ft->max_bounds.ascent; titlecd = ft->max_bounds.descent; titlech = ft->max_bounds.ascent+ft->max_bounds.descent; titlecw = ft->max_bounds.lbearing+ft->max_bounds.rbearing; /* determine window's current colormap */ XGetWindowAttributes(dpy,win,&wa); cmap = wa.colormap; /* get and set colors */ if (XAllocNamedColor(dpy,cmap,axescolor,&scolor,&ecolor)) XSetForeground(dpy,gca,ecolor.pixel); else XSetForeground(dpy,gca,1L); if (XAllocNamedColor(dpy,cmap,titlecolor,&scolor,&ecolor)) XSetForeground(dpy,gct,ecolor.pixel); else XSetForeground(dpy,gct,1L); if (XAllocNamedColor(dpy,cmap,gridcolor,&scolor,&ecolor)) XSetForeground(dpy,gcg,ecolor.pixel); else XSetForeground(dpy,gcg,1L); /* determine tic size */ ticsize = labelcw; /* draw vertical axis */ amin = wclip; amax = bclip; /* trap for cases when bclip=wclip */ if ((bclip - wclip)!=0) dnum = (bclip-wclip)/4; base = y; ticb = -ticsize; numb = ticb-ticsize/4; azero = 0.0001*(amax-amin); xa = x+1.25*width; ya = y; for (anum=amax; anum>=amin; anum-=dnum) { if (anum<amin) continue; XDrawLine(dpy,win,gca,x,ya,x+width,ya); XDrawLine(dpy,win,gca,x+width,ya,xa,ya); sprintf(str,"%1.4g",anum); lstr = strlen(str); tw = XTextWidth(fa,str,lstr); XDrawString(dpy,win,gca,xa+width/4,ya+labelca/2,str,lstr); ya += height/4; } xa = x+width/8; ya = y+height+labelch; sprintf(str,units); lstr = strlen(str); tw = XTextWidth(fa,str,lstr); XDrawString(dpy,win,gca,xa,ya,str,lstr); /* draw axes box */ XDrawRectangle(dpy,win,gca,x,y,width,height); /* free resources before returning */ XFreeGC(dpy,gca); XFreeGC(dpy,gct); XFreeGC(dpy,gcg); }
int main(int argc, char**argv) { char **missing_charset_list; int missing_charset_count; XGCValues xgcv; unsigned long mask; Display* dpy; int scr; Window w, root; XSetWindowAttributes set_attr; int i; XIMStyle *style; static char buf[128]; KeySym keysym = 0; Status status; XWMHints wm_hints; XClassHint class_hints; XIMStyle input_style = 0; char **font_name_list; char *def_string; XFontStruct **font_struct_list; char **font_encoding_list; int nb_font; int len = 0; int no_xim = 0; char **missing_charset_list_return; int missing_charset_count_return; char *def_string_return; if (!setlocale(LC_ALL, "")) puts("locale not supported by C library, locale unchanged"); if (!XSetLocaleModifiers("")) puts("X locale modifiers not supported, using default"); dpy = XOpenDisplay(0); scr = DefaultScreen(dpy); root = RootWindow(dpy, scr); set_attr.event_mask = KeyPressMask|FocusChangeMask; set_attr.background_pixel = WhitePixel(dpy, DefaultScreen(dpy)); set_attr.border_pixel = BlackPixel(dpy, DefaultScreen(dpy)); w = XCreateWindow(dpy, root, 10,10,200,100,0, DefaultDepth(dpy, DefaultScreen(dpy)), InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)), CWEventMask | CWBackPixel | CWBorderPixel, &set_attr); class_hints.res_name = "test"; class_hints.res_class = "Test"; wm_hints.input = True; wm_hints.flags = InputHint; XmbSetWMProperties(dpy, w, "test", "test", NULL, 0, NULL, &wm_hints, &class_hints); XMapWindow(dpy, w); xim_im = XOpenIM(dpy, NULL, "test", "Test"); XGetIMValues(xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL); for (i = 0, style = xim_styles->supported_styles; i < xim_styles->count_styles; i++, style++) { if (*style == (XIMStatusNone|XIMPreeditNone)) { printf("this is not a XIM server !!!\n"); no_xim = 1; } printf("input style : 0x%X\n", *style); } XFree(xim_styles); xim_ic = XCreateIC(xim_im, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), XNClientWindow, w, XNFocusWindow, w, NULL); XSetICFocus(xim_ic); /*************************************************************** * I don't recommend to use a font base name list similar * to the following one in a real application ;-) ***************************************************************/ fontset = XCreateFontSet(dpy, "-*-*-*-*-*-*-*-*-*-*-*-*-iso8858-3," /* not valid */ "-*-*-medium-r-*-*-*-*-*-*-*-*-iso8859-1," "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-6," "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-8," "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific," "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-2," "-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1," "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0208.1983-0," "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0212.1990-0," "-*-*-*-*-*-*-*-*-*-*-*-*-big5-0," "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0201.1976-0," "-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1[0x300 0x400_0x500]," "-*-*-*-*-*-*-*-*-*-*-*-*-*-*", &missing_charset_list_return, &missing_charset_count_return, &def_string_return); mask = (GCForeground | GCBackground); xgcv.foreground = BlackPixel(dpy, DefaultScreen(dpy)); xgcv.background = WhitePixel(dpy, DefaultScreen(dpy)); gc = XCreateGC(dpy, w, mask, &xgcv); /***************************************************************/ while (1) { int filtered; static XEvent xevent; static XVaNestedList list1 = 0; int r; XNextEvent(dpy, &xevent); if (xevent.type == KeyPress) { XKeyEvent *e = (XKeyEvent*) &xevent; printf ("0x%X %d\n", e->state, e->keycode); } filtered = XFilterEvent(&xevent, w); if (xevent.type == FocusOut) XUnsetICFocus(xim_ic); if (xevent.type == FocusIn) XSetICFocus(xim_ic); if (xevent.type == KeyPress && !filtered) { len = Xutf8LookupString(xim_ic, &xevent.xkey, buf, 127, &keysym, &status); Xutf8DrawImageString(dpy, w, fontset, gc, x, y, buf, len); Xutf8DrawString(dpy, w, fontset, gc, 0, 20, jp_txt, strlen(jp_txt)); Xutf8DrawString(dpy, w, fontset, gc, 50, 90, rtl_txt, strlen(rtl_txt)); buf[len] = 0; printf("'%s' %d\n", buf, keysym); buf[0] = 0; XCloseIM(xim_im); } if (filtered) { printf("Dead key\n"); } } XFreeFontSet(dpy, fontset); return 0; }
static void winopen(void) { XWMHints *wmhints; XClassHint *classhint; xdpy = XOpenDisplay(NULL); if (!xdpy) winerror(&gapp, fz_throw("cannot open display")); XA_TARGETS = XInternAtom(xdpy, "TARGETS", False); XA_TIMESTAMP = XInternAtom(xdpy, "TIMESTAMP", False); XA_UTF8_STRING = XInternAtom(xdpy, "UTF8_STRING", False); WM_DELETE_WINDOW = XInternAtom(xdpy, "WM_DELETE_WINDOW", False); xscr = DefaultScreen(xdpy); ximage_init(xdpy, xscr, DefaultVisual(xdpy, xscr)); xcarrow = XCreateFontCursor(xdpy, XC_left_ptr); xchand = XCreateFontCursor(xdpy, XC_hand2); xcwait = XCreateFontCursor(xdpy, XC_watch); xbgcolor.red = 0x7000; xbgcolor.green = 0x7000; xbgcolor.blue = 0x7000; xshcolor.red = 0x4000; xshcolor.green = 0x4000; xshcolor.blue = 0x4000; XAllocColor(xdpy, DefaultColormap(xdpy, xscr), &xbgcolor); XAllocColor(xdpy, DefaultColormap(xdpy, xscr), &xshcolor); xwin = XCreateWindow(xdpy, DefaultRootWindow(xdpy), 10, 10, 200, 100, 1, ximage_get_depth(), InputOutput, ximage_get_visual(), 0, NULL); if (xwin == None) winerror(&gapp, fz_throw("cannot create window")); XSetWindowColormap(xdpy, xwin, ximage_get_colormap()); XSelectInput(xdpy, xwin, StructureNotifyMask | ExposureMask | KeyPressMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask); mapped = 0; xgc = XCreateGC(xdpy, xwin, 0, NULL); XDefineCursor(xdpy, xwin, xcarrow); wmhints = XAllocWMHints(); if (wmhints) { wmhints->flags = IconPixmapHint | IconMaskHint; xicon = XCreateBitmapFromData(xdpy, xwin, (char*)mupdf_icon_bitmap_16_bits, mupdf_icon_bitmap_16_width, mupdf_icon_bitmap_16_height); xmask = XCreateBitmapFromData(xdpy, xwin, (char*)mupdf_icon_bitmap_16_mask_bits, mupdf_icon_bitmap_16_mask_width, mupdf_icon_bitmap_16_mask_height); if (xicon && xmask) { wmhints->icon_pixmap = xicon; wmhints->icon_mask = xmask; XSetWMHints(xdpy, xwin, wmhints); } XFree(wmhints); } classhint = XAllocClassHint(); if (classhint) { classhint->res_name = "mupdf"; classhint->res_class = "MuPDF"; XSetClassHint(xdpy, xwin, classhint); XFree(classhint); } XSetWMProtocols(xdpy, xwin, &WM_DELETE_WINDOW, 1); x11fd = ConnectionNumber(xdpy); }
int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem) { Bool pixmaps; int major, minor; XGCValues values; if (!XShmQueryExtension(subsystem->display)) return -1; if (!XShmQueryVersion(subsystem->display, &major, &minor, &pixmaps)) return -1; if (!pixmaps) return -1; subsystem->fb_shm_info.shmid = -1; subsystem->fb_shm_info.shmaddr = (char*) -1; subsystem->fb_shm_info.readOnly = False; subsystem->fb_image = XShmCreateImage(subsystem->display, subsystem->visual, subsystem->depth, ZPixmap, NULL, &(subsystem->fb_shm_info), subsystem->width, subsystem->height); if (!subsystem->fb_image) { WLog_ERR(TAG, "XShmCreateImage failed"); return -1; } subsystem->fb_shm_info.shmid = shmget(IPC_PRIVATE, subsystem->fb_image->bytes_per_line * subsystem->fb_image->height, IPC_CREAT | 0600); if (subsystem->fb_shm_info.shmid == -1) { WLog_ERR(TAG, "shmget failed"); return -1; } subsystem->fb_shm_info.shmaddr = shmat(subsystem->fb_shm_info.shmid, 0, 0); subsystem->fb_image->data = subsystem->fb_shm_info.shmaddr; if (subsystem->fb_shm_info.shmaddr == ((char*) -1)) { WLog_ERR(TAG, "shmat failed"); return -1; } if (!XShmAttach(subsystem->display, &(subsystem->fb_shm_info))) return -1; XSync(subsystem->display, False); shmctl(subsystem->fb_shm_info.shmid, IPC_RMID, 0); subsystem->fb_pixmap = XShmCreatePixmap(subsystem->display, subsystem->root_window, subsystem->fb_image->data, &(subsystem->fb_shm_info), subsystem->fb_image->width, subsystem->fb_image->height, subsystem->fb_image->depth); XSync(subsystem->display, False); if (!subsystem->fb_pixmap) return -1; values.subwindow_mode = IncludeInferiors; values.graphics_exposures = False; subsystem->xshm_gc = XCreateGC(subsystem->display, subsystem->root_window, GCSubwindowMode | GCGraphicsExposures, &values); XSetFunction(subsystem->display, subsystem->xshm_gc, GXcopy); XSync(subsystem->display, False); return 1; }
ENTRYPOINT void init_strange(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); #ifndef NO_DBUF GC gc = MI_GC(mi); #endif ATTRACTOR *Attractor; #ifdef POINTS_HISTORY startedClearing=0; oldPointsIndex=0; #endif if (Root == NULL) { if ((Root = (ATTRACTOR *) calloc(MI_NUM_SCREENS(mi), sizeof (ATTRACTOR))) == NULL) return; } Attractor = &Root[MI_SCREEN(mi)]; if (Attractor->Fold == NULL) { int i; if ((Attractor->Fold = (PRM *) calloc(UNIT2 + 1, sizeof (PRM))) == NULL) { free_strange(display, Attractor); return; } for (i = 0; i <= UNIT2; ++i) { DBL x; /* x = ( DBL )(i)/UNIT2; */ /* x = sin( M_PI/2.0*x ); */ /* x = sqrt( x ); */ /* x = x*x; */ /* x = x*(1.0-x)*4.0; */ x = (DBL) (i) / UNIT; x = sin(x); Attractor->Fold[i] = DBL_To_PRM(x); } } Attractor->Max_Pt = points; if (Attractor->Buffer1 == NULL) if ((Attractor->Buffer1 = (XPoint *) calloc(Attractor->Max_Pt, sizeof (XPoint))) == NULL) { free_strange(display, Attractor); return; } if (Attractor->Buffer2 == NULL) if ((Attractor->Buffer2 = (XPoint *) calloc(Attractor->Max_Pt, sizeof (XPoint))) == NULL) { free_strange(display, Attractor); return; } Attractor->Width = MI_WIDTH(mi); Attractor->Height = MI_HEIGHT(mi); Attractor->Cur_Pt = 0; Attractor->Count = 0; Attractor->Col = NRAND(MI_NPIXELS(mi)); Attractor->Speed = 4; Attractor->Iterate = Funcs[NRAND(2)]; Random_Prm(Attractor->Prm1); Random_Prm(Attractor->Prm2); #ifndef NO_DBUF if (Attractor->dbuf != None) XFreePixmap(display, Attractor->dbuf); #ifdef useAccumulator #define colorDepth ( useAccumulator ? MI_DEPTH(mi) : 1 ) #else #define colorDepth 1 #endif Attractor->dbuf = XCreatePixmap(display, window, Attractor->Width, Attractor->Height, colorDepth); /* Allocation checked */ if (Attractor->dbuf != None) { XGCValues gcv; gcv.foreground = 0; gcv.background = 0; #ifndef HAVE_COCOA gcv.graphics_exposures = False; #endif /* HAVE_COCOA */ gcv.function = GXcopy; if (Attractor->dbuf_gc != None) XFreeGC(display, Attractor->dbuf_gc); if ((Attractor->dbuf_gc = XCreateGC(display, Attractor->dbuf, #ifndef HAVE_COCOA GCGraphicsExposures | #endif /* HAVE_COCOA */ GCFunction | GCForeground | GCBackground, &gcv)) == None) { XFreePixmap(display, Attractor->dbuf); Attractor->dbuf = None; } else { XFillRectangle(display, Attractor->dbuf, Attractor->dbuf_gc, 0, 0, Attractor->Width, Attractor->Height); XSetBackground(display, gc, MI_BLACK_PIXEL(mi)); XSetFunction(display, gc, GXcopy); } } #endif #ifdef useAccumulator #define A Attractor if (useAccumulator) { XWindowAttributes xgwa; int i,j; XGetWindowAttributes (display, window, &xgwa); /* cmap = xgwa.colormap; */ /* cmap = XCreateColormap(display, window, MI_VISUAL(mi), AllocAll); */ Attractor->accMap = (int**)calloc(Attractor->Width,sizeof(int*)); for (i=0;i<Attractor->Width;i++) { Attractor->accMap[i] = (int*)calloc(Attractor->Height,sizeof(int)); for (j=0;j<Attractor->Height;j++) { Attractor->accMap[i][j] = 0; } } #ifdef POINTS_HISTORY numOldPoints = A->Max_Pt * MERGE_FRAMES; oldPointsX = (int*)calloc(numOldPoints,sizeof(int)); oldPointsY = (int*)calloc(numOldPoints,sizeof(int)); #endif cols = (XColor*)calloc(NUM_COLS,sizeof(XColor)); for (i=0;i<NUM_COLS;i++) { float li; #define MINBLUE 1 #define FULLBLUE 128 li = MINBLUE + (255.0-MINBLUE) * log(1.0 + ACC_GAMMA*(float)i/NUM_COLS) / log(1.0 + ACC_GAMMA); if (li<FULLBLUE) { cols[i].red = 0; cols[i].green = 0; cols[i].blue = 65536*li/FULLBLUE; } else { cols[i].red = 65536*(li-FULLBLUE)/(256-FULLBLUE); cols[i].green = 65536*(li-FULLBLUE)/(256-FULLBLUE); cols[i].blue = 65535; } XAllocColor (display, xgwa.colormap, &cols[i]); /* if (!XAllocColor(MI_DISPLAY(mi), cmap, &cols[i])) { if (!XAllocColor(display, cmap, &cols[i])) { cols[i].pixel = WhitePixel (display, DefaultScreen (display)); cols[i].red = cols[i].green = cols[i].blue = 0xFFFF; } */ } /* XSetWindowColormap(display, window, cmap); (void) XSetWMColormapWindows(display, window, &window, 1); XInstallColormap(display, cmap); XStoreColors(display, cmap, cols, 256); */ } #undef A #endif MI_CLEARWINDOW(mi); /* Do not want any exposure events from XCopyPlane */ XSetGraphicsExposures(display, MI_GC(mi), False); }
stk_widget *stk_text_new(stk_widget *parent_win, int x, int y, uint w, uint h, char *label, int type) { stk_widget *new_txt = (stk_widget*) malloc(sizeof(stk_widget)); stk_text *txt = (stk_text*) malloc(sizeof(stk_text)); int screen; XGCValues gcval; long fg, bg; XSetWindowAttributes setwinattr; memset(new_txt, 0, sizeof(stk_widget)); memset(txt->text, 0, sizeof(stk_text)); new_txt->dsp = display; new_txt->fontname = STK_FONT_SIZE_7x13; screen = DefaultScreen(new_txt->dsp); fg = BlackPixel(new_txt->dsp, screen); bg = WhitePixel(new_txt->dsp, screen); gcval.foreground = fg; gcval.background = bg; new_txt->gc2 = XCreateGC(new_txt->dsp, parent_win->win, GCForeground | GCBackground, &gcval); setwinattr.backing_store = Always; new_txt->font_info = XLoadQueryFont(new_txt->dsp, new_txt->fontname); if(new_txt->fontname != NULL) XSetFont(display, new_txt->gc2, new_txt->font_info->fid); else perror("XLoadQueryFont"); if(new_txt->dsp) { new_txt->win = XCreateSimpleWindow(new_txt->dsp, parent_win->win, x, y, w, h, 1, fg, bg); if(type == STK_TEXT_INPUT) { new_txt->mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask | StructureNotifyMask | PropertyChangeMask | VisibilityChangeMask; } else { new_txt->mask = ExposureMask| EnterWindowMask | LeaveWindowMask | FocusChangeMask | StructureNotifyMask | PropertyChangeMask | VisibilityChangeMask; } XChangeWindowAttributes(new_txt->dsp, new_txt->win, CWBackingStore, &setwinattr); XSelectInput(new_txt->dsp, new_txt->win, new_txt->mask); XMapWindow(new_txt->dsp, new_txt->win); new_txt->x = x; new_txt->y = y; new_txt->w = w; new_txt->h = h; new_txt->handler = &stk_text_handle; new_txt->ext_struct = (void*)txt; if(label) strcpy(txt->text, label); stk_widget_insert((void*)new_txt); return new_txt; } else return NULL; }
void pxWindowNative::runEventLoop() { displayRef d; exitFlag = false; double lastAnimationTime = pxMilliseconds(); while(!exitFlag) { XEvent e; if (XPending(d.getDisplay())) { XNextEvent(d.getDisplay(), &e); XAnyEvent* ae = (XAnyEvent*)&e; pxWindowNative* w = getPXWindowFromX11Window(ae->window); if (w) { switch(ae->type) { case Expose: { if(e.xexpose.count<1) { GC gc=XCreateGC(ae->display, ae->window, 0, NULL); pxSurfaceNativeDesc d; d.display = ae->display; d.drawable = ae->window; d.gc = gc; w->onDraw(&d); XFreeGC(ae->display, gc); } } break; case ButtonPress: { XGrabPointer(ae->display, ae->window, true, ButtonPressMask|ButtonReleaseMask| PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); XButtonEvent *be = (XButtonEvent*)ae; unsigned long flags; switch(be->button) { case Button2: flags = PX_MIDDLEBUTTON; break; case Button3: flags = PX_RIGHTBUTTON; break; default: flags = PX_LEFTBUTTON; break; } flags |= (be->state & ShiftMask)?PX_MOD_SHIFT:0; flags |= (be->state & ControlMask)?PX_MOD_CONTROL:0; flags |= (be->state & Mod1Mask)?PX_MOD_ALT:0; w->onMouseDown(be->x, be->y, flags); } break; case ButtonRelease: { XUngrabPointer(ae->display, CurrentTime); XButtonEvent *be = (XButtonEvent*)ae; unsigned long flags; switch(be->button) { case Button2: flags = PX_MIDDLEBUTTON; break; case Button3: flags = PX_RIGHTBUTTON; break; default: flags = PX_LEFTBUTTON; break; } flags |= (be->state & ShiftMask)?PX_MOD_SHIFT:0; flags |= (be->state & ControlMask)?PX_MOD_CONTROL:0; flags |= (be->state & Mod1Mask)?PX_MOD_ALT:0; w->onMouseUp(be->x, be->y, flags); } break; case KeyPress: { XKeyEvent* ke = (XKeyEvent*)ae; KeySym keySym = ::XKeycodeToKeysym(ae->display, e.xkey.keycode, 0); if (keySym >= 'a' && keySym <= 'z') keySym = (keySym-'a')+'A'; else if (keySym == XK_Shift_R) keySym = XK_Shift_L; else if (keySym == XK_Control_R) keySym = XK_Control_L; else if (keySym == XK_Alt_R) keySym = XK_Alt_L; unsigned long flags = 0; flags |= (ke->state & ShiftMask)?PX_MOD_SHIFT:0; flags |= (ke->state & ControlMask)?PX_MOD_CONTROL:0; flags |= (ke->state & Mod1Mask)?PX_MOD_ALT:0; w->onKeyDown(keySym, flags); } break; case MotionNotify: { XMotionEvent *me = (XMotionEvent*)ae; w->onMouseMove(me->x, me->y); } break; case KeyRelease: { XKeyEvent* ke = (XKeyEvent*)ae; KeySym keySym = ::XKeycodeToKeysym(ae->display, e.xkey.keycode, 0); if (keySym >= 'a' && keySym <= 'z') keySym = (keySym-'a')+'A'; else if (keySym == XK_Shift_R) keySym = XK_Shift_L; else if (keySym == XK_Control_R) keySym = XK_Control_L; else if (keySym == XK_Alt_R) keySym = XK_Alt_L; unsigned long flags = 0; flags |= (ke->state & ShiftMask)?PX_MOD_SHIFT:0; flags |= (ke->state & ControlMask)?PX_MOD_CONTROL:0; flags |= (ke->state & Mod1Mask)?PX_MOD_ALT:0; w->onKeyUp(keySym, flags); } break; case ConfigureNotify: { // We defer the onSize message after some // time if (w->lastWidth != e.xconfigure.width || w->lastHeight != e.xconfigure.height) { w->resizeFlag = true; w->lastWidth = e.xconfigure.width; w->lastHeight = e.xconfigure.height; } } break; case ClientMessage: { if((e.xclient.format == 32) && (e.xclient.data.l[0] == int(w->closeatom))) { w->onCloseRequest(); } } break; case DestroyNotify: { w->onClose(); unregisterWindow(ae->window); } break; case LeaveNotify: { w->onMouseLeave(); } break; } } } else { // The animation/resize handling under x11 needs some serious // rework double currentAnimationTime = pxMilliseconds(); vector<windowDesc>::iterator i; for (i = mWindowMap.begin(); i < mWindowMap.end(); i++) { pxWindowNative* w = (*i).p; double animationDelta = currentAnimationTime-lastAnimationTime; if (w->resizeFlag) { w->resizeFlag = false; w->onSize((*i).p->lastWidth, (*i).p->lastHeight); w->invalidateRectInternal(NULL); } if (w->mTimerFPS) { animationDelta = currentAnimationTime- w->mLastAnimationTime; if (animationDelta > (1000/w->mTimerFPS)) { w->onAnimationTimerInternal(); w->mLastAnimationTime = currentAnimationTime; } } } pxSleepMS(10); // Breath } } }
int main(){ // puts(APP); Display*dpy=XOpenDisplay(NULL); if(!dpy){ //fprintf(stderr, "!!! could not open display\n"); return 1; } const int scr=DefaultScreen(dpy); const int screen_width=DisplayWidth(dpy,scr); const int win_height=23; const Window win=XCreateSimpleWindow(dpy,RootWindow(dpy,scr),-BORDER_WIDTH,0,screen_width,win_height,0,BlackPixel(dpy,scr),BlackPixel(dpy,scr)); // XSelectInput(dpy,win,ExposureMask|KeyPressMask); XSelectInput(dpy,win,KeyPressMask); XMapWindow(dpy,win); const GC gc=XCreateGC(dpy,win,0,NULL); const int x_init=(screen_width>>1)-(screen_width>>2)+(screen_width>>3); int x=x_init; const int y_init=(win_height>>1)+(win_height>>2); int y=y_init; const char cursor_str[1]="_"; XSetForeground(dpy,gc,WhitePixel(dpy,scr)); XDrawString(dpy,win,gc,x,y,cursor_str,1); char buf[32]; int bufi=0; char*bufp=buf; *bufp=0; const int char_width=7; const int char_y_wiggle=3; const int char_y_wiggle_up=-1; const int options_start_x=640; int go=1; XEvent e; while(go){ XNextEvent(dpy,&e); switch(e.type){ default: break; case Expose: // XSetForeground(dpy,gc,BlackPixel(dpy,scr)); // XFillRectangle(dpy,win,gc,0,0,screen_width,win_height); // XSetForeground(dpy,gc,WhitePixel(dpy,scr)); // const int buflen=strlen(buf); // printf("%d [%s]\n",buflen,buf); // XDrawString(dpy,win,gc,x_init,y_init,buf,buflen); // x=x_init+char_width*buflen; // XDrawString(dpy,win,gc,x,y,cursor_str,1); break; case DestroyNotify: go=0; break; case KeyPress:{ int keycode=0; //printf("KeyPress %d %d\n",e.xbutton.button,e.xbutton.state); keycode=e.xkey.keycode; if(keycode==9){//esc go=0; bufp=buf; *bufp=0; break; } keycode=e.xkey.keycode; if(keycode==36){//return go=0; *bufp=0; break; } if(keycode==22){//backspace if(bufi==0) break; x-=char_width; XSetForeground(dpy,gc,BlackPixel(dpy,scr)); XFillRectangle(dpy,win,gc,x,0,char_width<<1,win_height); XSetForeground(dpy,gc,WhitePixel(dpy,scr)); XDrawString(dpy,win,gc,x,y,"_",1); bufi--; bufp--; *bufp=0; }else{ // clear cursor XSetForeground(dpy,gc,BlackPixel(dpy,scr)); XFillRectangle(dpy,win,gc,x,0,char_width,win_height); XSetForeground(dpy,gc,WhitePixel(dpy,scr)); // get printable character char buffer[4]; KeySym keysym; XLookupString(&e.xkey,buffer,sizeof buffer,&keysym,NULL); if(!buffer[0])// printable character ? break; XDrawString(dpy,win,gc,x,y,buffer,1); x+=char_width; *bufp++=buffer[0]; bufi++; if((bufi+1)>=(int)sizeof buf)// buffer full ? go=0; y+=char_y_wiggle_up+rand()%char_y_wiggle; XDrawString(dpy,win,gc,x,y,cursor_str,1); } XFillRectangle(dpy,win,gc,options_start_x,0,screen_width-options_start_x-1,win_height-1); break; } } } XFreeGC(dpy,gc); XCloseDisplay(dpy); if(!*buf)return 0;//empty string strcat(buf,"&"); return system(buf); }
int xf_AppWindowInit(xfContext* xfc, xfAppWindow* appWindow) { XGCValues gcv; int input_mask; XWMHints* InputModeHint; XClassHint* class_hints; xf_FixWindowCoordinates(xfc, &appWindow->x, &appWindow->y, &appWindow->width, &appWindow->height); appWindow->decorations = FALSE; appWindow->fullscreen = FALSE; appWindow->local_move.state = LMS_NOT_ACTIVE; appWindow->is_mapped = FALSE; appWindow->is_transient = FALSE; appWindow->rail_state = 0; appWindow->rail_ignore_configure = FALSE; appWindow->handle = XCreateWindow(xfc->display, RootWindowOfScreen(xfc->screen), appWindow->x, appWindow->y, appWindow->width, appWindow->height, 0, xfc->depth, InputOutput, xfc->visual, 0, &xfc->attribs); if (!appWindow->handle) return -1; ZeroMemory(&gcv, sizeof(gcv)); appWindow->gc = XCreateGC(xfc->display, appWindow->handle, GCGraphicsExposures, &gcv); class_hints = XAllocClassHint(); if (class_hints) { char* class = NULL; if (xfc->context.settings->WmClass) { class_hints->res_class = xfc->context.settings->WmClass; } else { class = malloc(sizeof("RAIL:00000000")); sprintf_s(class, sizeof("RAIL:00000000"), "RAIL:%08"PRIX32"", appWindow->windowId); class_hints->res_class = class; } class_hints->res_name = "RAIL"; XSetClassHint(xfc->display, appWindow->handle, class_hints); XFree(class_hints); free(class); } /* Set the input mode hint for the WM */ InputModeHint = XAllocWMHints(); InputModeHint->flags = (1L << 0); InputModeHint->input = True; XSetWMHints(xfc->display, appWindow->handle, InputModeHint); XFree(InputModeHint); XSetWMProtocols(xfc->display, appWindow->handle, &(xfc->WM_DELETE_WINDOW), 1); input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask | ButtonMotionMask | KeymapStateMask | ExposureMask | VisibilityChangeMask | StructureNotifyMask | SubstructureNotifyMask | SubstructureRedirectMask | FocusChangeMask | PropertyChangeMask | ColormapChangeMask | OwnerGrabButtonMask; XSelectInput(xfc->display, appWindow->handle, input_mask); xf_SetWindowDecorations(xfc, appWindow->handle, appWindow->decorations); xf_SetWindowStyle(xfc, appWindow, appWindow->dwStyle, appWindow->dwExStyle); xf_SetWindowPID(xfc, appWindow->handle, 0); xf_ShowWindow(xfc, appWindow, WINDOW_SHOW); XClearWindow(xfc->display, appWindow->handle); XMapWindow(xfc->display, appWindow->handle); /* Move doesn't seem to work until window is mapped. */ xf_MoveWindow(xfc, appWindow, appWindow->x, appWindow->y, appWindow->width, appWindow->height); xf_SetWindowText(xfc, appWindow, appWindow->title); return 1; }
/** ** X11 initialize. */ global void CloneInitDisplay(void) { int i; Window window; XGCValues gcvalue; XSizeHints hints; XWMHints wmhints; XClassHint classhint; XSetWindowAttributes attributes; int shm_major,shm_minor; Bool pixmap_support; XShmSegmentInfo shminfo; XVisualInfo xvi; XPixmapFormatValues *xpfv; if( !(TheDisplay=XOpenDisplay(NULL)) ) { fprintf(stderr,"Cannot connect to X-Server.\n"); exit(-1); } TheScreen=DefaultScreen(TheDisplay); // I need shared memory pixmap extension. if( !XShmQueryVersion(TheDisplay,&shm_major,&shm_minor,&pixmap_support) ) { fprintf(stderr,"SHM-Extensions required.\n"); exit(-1); } if( !pixmap_support ) { fprintf(stderr,"SHM-Extensions with pixmap supported required.\n"); exit(-1); } // Look for a nice visual #ifdef USE_HICOLOR if(XMatchVisualInfo(TheDisplay, TheScreen, 16, TrueColor, &xvi)) goto foundvisual; if(XMatchVisualInfo(TheDisplay, TheScreen, 15, TrueColor, &xvi)) goto foundvisual; fprintf(stderr,"Sorry, this version is for 15/16-bit displays only.\n"); #else if(XMatchVisualInfo(TheDisplay, TheScreen, 8, PseudoColor, &xvi)) goto foundvisual; fprintf(stderr,"Sorry, this version is for 8-bit displays only.\n"); #endif #if 0 if(XMatchVisualInfo(TheDisplay, TheScreen, 24, TrueColor, &xvi)) goto foundvisual; #endif exit(-1); foundvisual: xpfv=XListPixmapFormats(TheDisplay, &i); for(i--;i>=0;i--) if(xpfv[i].depth==xvi.depth) break; if(i<0) { fprintf(stderr,"No Pixmap format for visual depth?\n"); exit(-1); } VideoDepth=xvi.depth; VideoWidth = 640; VideoHeight = 480; MapWidth = 14; // FIXME: Not the correct way MapHeight = 14; shminfo.shmid=shmget(IPC_PRIVATE, (VideoWidth*xpfv[i].bits_per_pixel+xpfv[i].scanline_pad-1) / xpfv[i].scanline_pad * xpfv[i].scanline_pad * VideoHeight / 8, IPC_CREAT|0777); XFree(xpfv); if( !shminfo.shmid==-1 ) { fprintf(stderr,"shmget failed.\n"); exit(-1); } VideoMemory=(VMemType*)shminfo.shmaddr=shmat(shminfo.shmid,0,0); if( shminfo.shmaddr==(void*)-1 ) { shmctl(shminfo.shmid,IPC_RMID,0); fprintf(stderr,"shmat failed.\n"); exit(-1); } shminfo.readOnly=False; if( !XShmAttach(TheDisplay,&shminfo) ) { shmctl(shminfo.shmid,IPC_RMID,0); fprintf(stderr,"XShmAttach failed.\n"); exit(-1); } // Mark segment as deleted as soon as both clone and the X server have // attached to it. The POSIX spec says that a segment marked as deleted // can no longer have addition processes attach to it, but Linux will let // them anyway. shmctl(shminfo.shmid,IPC_RMID,0); TheMainDrawable=attributes.background_pixmap= XShmCreatePixmap(TheDisplay,DefaultRootWindow(TheDisplay) ,shminfo.shmaddr,&shminfo ,VideoWidth,VideoHeight ,xvi.depth); attributes.cursor = XCreateFontCursor(TheDisplay,XC_tcross-1); attributes.backing_store = NotUseful; attributes.save_under = False; attributes.event_mask = KeyPressMask|KeyReleaseMask|/*ExposureMask|*/ FocusChangeMask|ButtonPressMask|PointerMotionMask|ButtonReleaseMask; i = CWBackPixmap|CWBackingStore|CWSaveUnder|CWEventMask|CWCursor; if(xvi.class==PseudoColor) { i|=CWColormap; attributes.colormap = XCreateColormap( TheDisplay, xvi.screen, xvi.visual, AllocNone); // FIXME: Really should fill in the colormap right now } window=XCreateWindow(TheDisplay,DefaultRootWindow(TheDisplay) ,0,0,VideoWidth,VideoHeight,3 ,xvi.depth,InputOutput,xvi.visual ,i,&attributes); TheMainWindow=window; gcvalue.graphics_exposures=False; GcLine=XCreateGC(TheDisplay,window,GCGraphicsExposures,&gcvalue); // // Clear initial window. // XSetForeground(TheDisplay,GcLine,BlackPixel(TheDisplay,TheScreen)); XFillRectangle(TheDisplay,TheMainDrawable,GcLine,0,0 ,VideoWidth,VideoHeight); WmDeleteWindowAtom=XInternAtom(TheDisplay,"WM_DELETE_WINDOW",False); // // Set some usefull min/max sizes as well as a 1.3 aspect // #if 0 if( geometry ) { hints.flags=0; f=XParseGeometry(geometry ,&hints.x,&hints.y,&hints.width,&hints.height); if( f&XValue ) { if( f&XNegative ) { hints.x+=DisplayWidth-hints.width; } hints.flags|=USPosition; // FIXME: win gravity } if( f&YValue ) { if( f&YNegative ) { hints.y+=DisplayHeight-hints.height; } hints.flags|=USPosition; // FIXME: win gravity } if( f&WidthValue ) { hints.flags|=USSize; } if( f&HeightValue ) { hints.flags|=USSize; } } else { #endif hints.width=VideoWidth; hints.height=VideoHeight; hints.flags=PSize; #if 0 } #endif hints.min_width=VideoWidth; hints.min_height=VideoHeight; hints.max_width=VideoWidth; hints.max_height=VideoHeight; hints.min_aspect.x=4; hints.min_aspect.y=3; hints.max_aspect.x=4; hints.max_aspect.y=3; hints.width_inc=4; hints.height_inc=3; hints.flags|=PMinSize|PMaxSize|PAspect|PResizeInc; wmhints.input=True; wmhints.initial_state=NormalState; wmhints.window_group=window; wmhints.flags=InputHint|StateHint|WindowGroupHint; classhint.res_name="aleclone"; classhint.res_class="AleClone"; XSetStandardProperties(TheDisplay,window ,"ALE Clone","ALE Clone",None,(char**)0,0,&hints); XSetClassHint(TheDisplay,window,&classhint); XSetWMHints(TheDisplay,window,&wmhints); XSetWMProtocols(TheDisplay,window,&WmDeleteWindowAtom,1); XMapWindow(TheDisplay,window); // // Input handling. // XAddConnectionWatch(TheDisplay,MyConnectionWatch,NULL); }
WMcursor *X11_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y) { WMcursor *cursor; XGCValues GCvalues; GC GCcursor; XImage *data_image, *mask_image; Pixmap data_pixmap, mask_pixmap; int clen, i; char *x_data, *x_mask; static XColor black = { 0, 0, 0, 0 }; static XColor white = { 0xffff, 0xffff, 0xffff, 0xffff }; /* Allocate the cursor memory */ cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor)); if ( cursor == NULL ) { SDL_OutOfMemory(); return(NULL); } /* Mix the mask and the data */ clen = (w/8)*h; x_data = (char *)SDL_malloc(clen); if ( x_data == NULL ) { SDL_free(cursor); SDL_OutOfMemory(); return(NULL); } x_mask = (char *)SDL_malloc(clen); if ( x_mask == NULL ) { SDL_free(cursor); SDL_free(x_data); SDL_OutOfMemory(); return(NULL); } for ( i=0; i<clen; ++i ) { /* The mask is OR'd with the data to turn inverted color pixels black since inverted color cursors aren't supported under X11. */ x_mask[i] = data[i] | mask[i]; x_data[i] = data[i]; } /* Prevent the event thread from running while we use the X server */ SDL_Lock_EventThread(); /* Create the data image */ data_image = XCreateImage(SDL_Display, DefaultVisual(SDL_Display, SDL_Screen), 1, XYBitmap, 0, x_data, w, h, 8, w/8); data_image->byte_order = MSBFirst; data_image->bitmap_bit_order = MSBFirst; data_pixmap = XCreatePixmap(SDL_Display, SDL_Root, w, h, 1); /* Create the data mask */ mask_image = XCreateImage(SDL_Display, DefaultVisual(SDL_Display, SDL_Screen), 1, XYBitmap, 0, x_mask, w, h, 8, w/8); mask_image->byte_order = MSBFirst; mask_image->bitmap_bit_order = MSBFirst; mask_pixmap = XCreatePixmap(SDL_Display, SDL_Root, w, h, 1); /* Create the graphics context */ GCvalues.function = GXcopy; GCvalues.foreground = ~0; GCvalues.background = 0; GCvalues.plane_mask = AllPlanes; GCcursor = XCreateGC(SDL_Display, data_pixmap, (GCFunction|GCForeground|GCBackground|GCPlaneMask), &GCvalues); /* Blit the images to the pixmaps */ XPutImage(SDL_Display, data_pixmap, GCcursor, data_image, 0, 0, 0, 0, w, h); XPutImage(SDL_Display, mask_pixmap, GCcursor, mask_image, 0, 0, 0, 0, w, h); XFreeGC(SDL_Display, GCcursor); /* These free the x_data and x_mask memory pointers */ XDestroyImage(data_image); XDestroyImage(mask_image); /* Create the cursor */ cursor->x_cursor = XCreatePixmapCursor(SDL_Display, data_pixmap, mask_pixmap, &black, &white, hot_x, hot_y); XFreePixmap(SDL_Display, data_pixmap); XFreePixmap(SDL_Display, mask_pixmap); /* Release the event thread */ XSync(SDL_Display, False); SDL_Unlock_EventThread(); return(cursor); }
static void * halo_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); XGCValues gcv; XWindowAttributes xgwa; char *mode_str = 0; st->dpy = dpy; st->window = window; XGetWindowAttributes (st->dpy, st->window, &xgwa); st->cmap = xgwa.colormap; st->global_count = get_integer_resource (st->dpy, "count", "Integer"); if (st->global_count < 0) st->global_count = 0; st->global_inc = get_integer_resource (st->dpy, "increment", "Integer"); if (st->global_inc < 0) st->global_inc = 0; st->anim_p = get_boolean_resource (st->dpy, "animate", "Boolean"); st->delay = get_integer_resource (st->dpy, "delay", "Integer"); st->delay2 = get_integer_resource (st->dpy, "delay2", "Integer") * 1000000; mode_str = get_string_resource (st->dpy, "colorMode", "ColorMode"); if (! mode_str) cmode = random_mode; else if (!strcmp (mode_str, "seuss")) cmode = seuss_mode; else if (!strcmp (mode_str, "ramp")) cmode = ramp_mode; else if (!strcmp (mode_str, "random")) cmode = random_mode; else { fprintf (stderr, "%s: colorMode must be seuss, ramp, or random, not \"%s\"\n", progname, mode_str); exit (1); } if (mode_str) free (mode_str); if (mono_p) cmode = seuss_mode; if (cmode == random_mode) cmode = ((random()&3) == 1) ? ramp_mode : seuss_mode; if (cmode == ramp_mode) st->anim_p = False; /* This combo doesn't work right... */ st->ncolors = get_integer_resource (st->dpy, "colors", "Colors"); if (st->ncolors < 2) st->ncolors = 2; if (st->ncolors <= 2) mono_p = True; if (mono_p) st->colors = 0; else st->colors = (XColor *) malloc(sizeof(*st->colors) * (st->ncolors+1)); if (mono_p) ; else if (random() % (cmode == seuss_mode ? 2 : 10)) make_uniform_colormap (xgwa.screen, xgwa.visual, st->cmap, st->colors, &st->ncolors, True, 0, True); else make_smooth_colormap (xgwa.screen, xgwa.visual, st->cmap, st->colors, &st->ncolors, True, 0, True); if (st->ncolors <= 2) mono_p = True; if (mono_p) cmode = seuss_mode; if (mono_p) { st->fg_pixel = get_pixel_resource (st->dpy, st->cmap, "foreground", "Foreground"); st->bg_pixel = get_pixel_resource (st->dpy, st->cmap, "background", "Background"); } else { st->fg_index = 0; st->bg_index = st->ncolors / 4; if (st->fg_index == st->bg_index) st->bg_index++; st->fg_pixel = st->colors[st->fg_index].pixel; st->bg_pixel = st->colors[st->bg_index].pixel; } st->width = max (50, xgwa.width); st->height = max (50, xgwa.height); #ifdef DEBUG st->width/=2; st->height/=2; #endif st->pixmap = XCreatePixmap (st->dpy, st->window, st->width, st->height, 1); if (cmode == seuss_mode) st->buffer = XCreatePixmap (st->dpy, st->window, st->width, st->height, 1); else st->buffer = 0; gcv.foreground = 1; gcv.background = 0; st->draw_gc = XCreateGC (st->dpy, st->pixmap, GCForeground | GCBackground, &gcv); gcv.foreground = 0; st->erase_gc = XCreateGC (st->dpy, st->pixmap, GCForeground, &gcv); gcv.foreground = st->fg_pixel; gcv.background = st->bg_pixel; st->copy_gc = XCreateGC (st->dpy, st->window, GCForeground | GCBackground, &gcv); #ifdef HAVE_JWXYZ jwxyz_XSetAntiAliasing (dpy, st->draw_gc, False); jwxyz_XSetAntiAliasing (dpy, st->erase_gc, False); jwxyz_XSetAntiAliasing (dpy, st->copy_gc, False); #endif if (cmode == seuss_mode) { gcv.foreground = 1; gcv.background = 0; gcv.function = GXxor; st->merge_gc = XCreateGC (st->dpy, st->pixmap, GCForeground | GCBackground | GCFunction, &gcv); } else { gcv.foreground = st->fg_pixel; gcv.background = st->bg_pixel; gcv.function = GXcopy; st->merge_gc = XCreateGC (st->dpy, st->window, GCForeground | GCBackground | GCFunction, &gcv); } init_circles_1 (st); XClearWindow (st->dpy, st->window); if (st->buffer) XFillRectangle (st->dpy, st->buffer, st->erase_gc, 0, 0, st->width, st->height); return st; }
int main(int argc, char**argv) { char **missing_charset_list; int missing_charset_count; XGCValues xgcv; unsigned long mask; Display* dpy; int scr; Window w, root; XSetWindowAttributes set_attr; int i; XIMStyle *style; static char buf[128]; KeySym keysym = 0; Status status; XWMHints wm_hints; XClassHint class_hints; XIMStyle input_style = 0; char **font_name_list; char *def_string; XFontStruct **font_struct_list; char **font_encoding_list; int nb_font; int len = 0; int no_xim = 0; printf ("A -> %c \n", XUtf8Tolower('A')); if (!setlocale(LC_ALL, "")) puts("locale not supported by C library, locale unchanged"); if (!XSetLocaleModifiers("")) puts("X locale modifiers not supported, using default"); dpy = XOpenDisplay(0); if (!dpy) { puts("cannot open display.\n"); exit(-1); } scr = DefaultScreen(dpy); root = RootWindow(dpy, scr); set_attr.event_mask = KeyPressMask|FocusChangeMask; set_attr.background_pixel = WhitePixel(dpy, DefaultScreen(dpy)); set_attr.border_pixel = BlackPixel(dpy, DefaultScreen(dpy)); w = XCreateWindow(dpy, root, 10,10,200,100,0, DefaultDepth(dpy, DefaultScreen(dpy)), InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)), CWEventMask | CWBackPixel | CWBorderPixel, &set_attr); if (!w) { puts("cannot creat window.\n"); exit(-1); } class_hints.res_name = "test"; class_hints.res_class = "Test"; wm_hints.input = True; wm_hints.flags = InputHint; XmbSetWMProperties(dpy, w, "test", "test", NULL, 0, NULL, &wm_hints, &class_hints); XMapWindow(dpy, w); xim_im = XOpenIM(dpy, NULL, "test", "Test"); if (!xim_im) { puts("cannot Open Input Manager: Try default.\n"); XSetLocaleModifiers("@im="); xim_im = XOpenIM(dpy, NULL, "test", "Test"); if (!xim_im) { puts("Failed exiting.\n"); exit(-1); } } XGetIMValues (xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL); for (i = 0, style = xim_styles->supported_styles; i < xim_styles->count_styles; i++, style++) { if (i == 0 && *style == (XIMStatusNone|XIMPreeditNone)) { printf("this is not a XIM server !!!\n"); no_xim = 1; } printf("input style : 0x%X\n", *style); } xim_ic = XCreateIC(xim_im, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), XNClientWindow, w, XNFocusWindow, w, NULL); if (!xim_ic) { puts("cannot create Input Context.\n"); exit(-1);} XFree(xim_styles); XSetICFocus(xim_ic); /***************************************************************/ /** I don't recommand to use a font base name list similar * to the following one in a real application ;-) * You should use an iso8859-1 font, plus a single font for * your language. */ /***************************************************************/ fontset = XCreateUtf8FontStruct(dpy, "-*-*-*-*-*-*-*-*-*-*-*-*-iso8858-3," /* not valid */ "-*-*-medium-r-*-*-*-*-*-*-*-*-iso8859-1," "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-6," "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-8," "-*-*-*-*-*-*-*-*-*-*-*-*-ksc5601.1987-0," "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific," "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-2," "-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1," "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0208.1983-0," "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0212.1990-0," "-*-*-*-*-*-*-*-*-*-*-*-*-big5-0," "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0201.1976-0," "-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1[0x300 0x400_0x500]," "-*-*-*-*-*-*-*-*-*-*-*-*-*-*"); /* THIS PART IS NOT REQUIERED */ nb_font = fontset->nb_font; while (nb_font > 0) { nb_font--; if (fontset->fonts[nb_font]) { printf("encoding=\"\" fid=%d \n %s\n", // fontset->encodings[nb_font], fontset->fonts[nb_font]->fid, fontset->font_name_list[nb_font]); } } /* END OF NOT REQUIERED PART*/ mask = (GCForeground | GCBackground); xgcv.foreground = BlackPixel(dpy, DefaultScreen(dpy)); xgcv.background = WhitePixel(dpy, DefaultScreen(dpy)); gc = XCreateGC(dpy, w, mask, &xgcv); if (!gc) { puts("cannot create Graphic Context.\n"); exit(-1);} /***************************************************************/ while (1) { int filtered; static XEvent xevent; static XVaNestedList list1 = 0; int r; XNextEvent(dpy, &xevent); if (xevent.type == KeyPress) { XKeyEvent *e = (XKeyEvent*) &xevent; printf ("0x%X %d\n", e->state, e->keycode); } if (xevent.type == DestroyNotify) { /* XIM server has crashed */ no_xim = 1; XSetLocaleModifiers("@im="); xim_im = XOpenIM(dpy, NULL, "test", "Test"); if (xim_im) { xim_ic = XCreateIC(xim_im, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), XNClientWindow, w, XNFocusWindow, w, NULL); } else { xim_ic = NULL; } if (!xim_ic) { puts("Crash recovery failed. exiting.\n"); exit(-1); } } if (xevent.type != DestroyNotify) { filtered = XFilterEvent(&xevent, 0); } if (xevent.type == FocusOut && xim_ic) XUnsetICFocus(xim_ic); if (xevent.type == FocusIn && xim_ic) XSetICFocus(xim_ic); if (xevent.type == KeyPress && !filtered) { len = XUtf8LookupString(xim_ic, &xevent.xkey, buf, 127, &keysym, &status); if (len == 1 && buf[0] == '\b') { x -= XUtf8TextWidth(fontset, buf, len); XUtf8DrawImageString(dpy, w, fontset, gc, x, y, buf, len); } else if (len == 1 && buf[0] == '\r') { y += fontset->ascent + fontset->descent; x = 0; XCloseIM(xim_im); } else { XUtf8DrawImageString(dpy, w, fontset, gc, x, y, buf, len); x += XUtf8TextWidth(fontset, buf, len); } XUtf8DrawString(dpy, w, fontset, gc, 0, 20, jp_txt, strlen(jp_txt)); XUtf8DrawString(dpy, w, fontset, gc, 50, 90, rtl_txt, strlen(rtl_txt)); XUtf8DrawRtlString(dpy, w, fontset, gc, 50, 90, rtl_txt, strlen(rtl_txt)); buf[len] = 0; printf("'%s' %d %x\n", buf, keysym, keysym); buf[0] = 0; } if (filtered) { printf("Dead key\n"); } } XFreeUtf8FontStruct(dpy, fontset); return 0; }
Pixmap GLXConfigurator::CreateBackdrop(Window rootWindow, int depth) { int bpl; /* Find out number of bytes per pixel */ switch(depth) { default: LogManager::getSingleton().logMessage("GLX backdrop: Unsupported bit depth"); /* Unsupported bit depth */ return 0; case 15: case 16: bpl = 2; break; case 24: case 32: bpl = 4; break; } /* Create background pixmap */ unsigned char *data = 0; // Must be allocated with malloc try { String imgType = "png"; Image img; MemoryDataStream *imgStream; DataStreamPtr imgStreamPtr; // Load backdrop image using OGRE imgStream = new MemoryDataStream((void*)GLX_backdrop_data, sizeof(GLX_backdrop_data), false); imgStreamPtr = DataStreamPtr(imgStream); img.load(imgStreamPtr, imgType); PixelBox src = img.getPixelBox(0, 0); // Convert and copy image data = (unsigned char*)malloc(mWidth * mHeight * bpl); // Must be allocated with malloc PixelBox dst(src, bpl == 2 ? PF_B5G6R5 : PF_A8R8G8B8, data ); PixelUtil::bulkPixelConversion(src, dst); } catch(Exception &e) { // Could not find image; never mind LogManager::getSingleton().logMessage("WARNING: Can not load backdrop for config dialog. " + e.getDescription(), LML_TRIVIAL); return 0; } GC context = XCreateGC (mDisplay, rootWindow, 0, NULL); /* put my pixmap data into the client side X image data structure */ XImage *image = XCreateImage (mDisplay, NULL, depth, ZPixmap, 0, (char*)data, mWidth, mHeight, 8, mWidth*bpl); #if OGRE_ENDIAN == OGRE_ENDIAN_BIG image->byte_order = MSBFirst; #else image->byte_order = LSBFirst; #endif /* tell server to start managing my pixmap */ Pixmap rv = XCreatePixmap(mDisplay, rootWindow, mWidth, mHeight, depth); /* copy from client to server */ XPutImage(mDisplay, rv, context, image, 0, 0, 0, 0, mWidth, mHeight); /* free up the client side pixmap data area */ XDestroyImage(image); // also cleans data XFreeGC(mDisplay, context); return rv; }
/***************************************************************************** FUNCTION : o_createOszi PURPOSE : creates the window GRAPH RETURNS : void NOTES : UPDATE : 08.03.95 ******************************************************************************/ void o_createOszi (void) { Widget menu,mItem,form,w1,w2,printlab; Widget Done_oszi, clear_oszi, print_oszi; Arg arg[5]; Cardinal n; char buf[40]; Colormap o_graph_col; unsigned long foreground,background; int curr_unit,test_unit, count_unit = 0; o_graph_error_scale = GRAPH_SSE; /* test whether there are output units defined. Since no error can be computed in the opposit case, the graph tool can not be used */ curr_unit = krui_getCurrentUnit(); test_unit = krui_getFirstUnit(); do{ n=krui_getUnitTType(test_unit); if( (n == 2) || (n == 7) ) count_unit = 1; }while((test_unit = krui_getNextUnit()) && (count_unit == 0)); curr_unit = krui_setCurrentUnit(curr_unit); if(count_unit == 0){ ui_confirmOk("No Output units defined!\nAn error can neither be\ncomputed nor displayed!"); return; } if(o_open) { XRaiseWindow (XtDisplay (o_displayMainWidget), XtWindow (o_displayMainWidget)); return; } o_open = 1; o_init(); sprintf (buf, "SNNS graph"); n = 0; XtSetArg(arg[n],XtNminWidth,460); n++; XtSetArg(arg[n],XtNminHeight,200); n++; XtSetArg(arg[n],XtNheight,o_WindowHeight+58); n++; XtSetArg(arg[n],XtNwidth,o_WindowWidth+10); n++; XtSetArg(arg[n],XtNborderWidth,1); n++; o_displayMainWidget = XtCreatePopupShell(buf, topLevelShellWidgetClass, ui_toplevel, arg, n); n = 0; form = XtCreateManagedWidget ("form", formWidgetClass, o_displayMainWidget, arg, n); grid_oszi = ui_xCreateToggleItem ("grid",form,NULL,NULL,NULL); ui_xSetToggleState (grid_oszi, FALSE) ; XtAddCallback (grid_oszi, XtNcallback, (XtCallbackProc) o_gridProc, NULL); print_oszi = ui_xCreateButtonItem ("print",form,grid_oszi,NULL); XtAddCallback(print_oszi, XtNcallback, (XtCallbackProc) o_printProc, NULL); if(strlen(o_printfile) == 0)sprintf(o_printfile,"./graph.ps"); printlab = ui_xCreateLabelItem("Print to file:",form,14*8,print_oszi,NULL); o_printW = ui_xCreateDialogItem ("o_printW",form,o_printfile,0, printlab,NULL); Done_oszi = ui_xCreateButtonItem ("done",form,NULL,grid_oszi); XtAddCallback(Done_oszi,XtNcallback,(XtCallbackProc) o_DoneProc,NULL); clear_oszi = ui_xCreateButtonItem ("clear",form,Done_oszi,grid_oszi); XtAddCallback(clear_oszi,XtNcallback,(XtCallbackProc) o_clearProc,NULL); w1 = ui_xCreateLabelItem ("Scale X:",form,7*8,print_oszi,grid_oszi); w2 = ui_xCreateButtonItem ("prev",form,w1,grid_oszi); XtAddCallback(w2,XtNcallback,(XtCallbackProc) o_XForwardProc,NULL); w1 = ui_xCreateButtonItem ("next",form,w2,grid_oszi); XtAddCallback(w1,XtNcallback,(XtCallbackProc) o_XBackProc,NULL); w2 = ui_xCreateLabelItem (" Scale Y:",form,9*8,w1,grid_oszi); w1 = ui_xCreateButtonItem ("prev",form,w2,grid_oszi); XtAddCallback(w1,XtNcallback,(XtCallbackProc) o_YBackProc,NULL); w2 = ui_xCreateButtonItem ("next",form,w1,grid_oszi); XtAddCallback(w2,XtNcallback,(XtCallbackProc) o_YForwardProc,NULL); w1 = ui_xCreateLabelItem (" Display:",form,9*8,w2,grid_oszi); o_scaleWidget = ui_xCreateMenuButtonItem(" SSE ",form,w1,grid_oszi); menu = XtCreatePopupShell("menu",simpleMenuWidgetClass,o_scaleWidget, NULL,ZERO); mItem = XtCreateManagedWidget(" SSE",smeBSBObjectClass,menu,NULL,ZERO); XtAddCallback(mItem,XtNcallback,(XtCallbackProc)o_set_err_scale,(caddr_t)1); mItem = XtCreateManagedWidget(" MSE",smeBSBObjectClass,menu,NULL,ZERO); XtAddCallback(mItem,XtNcallback,(XtCallbackProc)o_set_err_scale,(caddr_t)2); mItem = XtCreateManagedWidget("SSE/#out", smeBSBObjectClass,menu,NULL,ZERO); XtAddCallback(mItem,XtNcallback,(XtCallbackProc)o_set_err_scale,(caddr_t)3); o_DisplayWidget = o_xCreateScreenItem("screen",form,o_WindowWidth, o_WindowHeight,NULL,clear_oszi); XtAddEventHandler(o_DisplayWidget,StructureNotifyMask | ExposureMask, FALSE,(XtEventHandler) o_eventProc,o_display); XtAddEventHandler(form,KeyPressMask,FALSE, (XtEventHandler)ui_key_control,(Cardinal *) 0); ui_checkWindowPosition(o_displayMainWidget); XtPopup (o_displayMainWidget, XtGrabNone); o_display = XtDisplay (o_DisplayWidget); o_window = XtWindow (o_DisplayWidget); o_fontStruct = XLoadQueryFont(o_display, "6x12"); o_gc[label_gc] = XCreateGC (o_display, o_window, ZERO, NULL); o_gc[train_gc] = XCreateGC (o_display, o_window, ZERO, NULL); o_gc[test_gc] = XCreateGC (o_display, o_window, ZERO, NULL); XSetFont(o_display,o_gc[label_gc],(*o_fontStruct).fid); o_screen = DefaultScreen (o_display); o_depth = DisplayPlanes(o_display,o_screen); o_graph_col = DefaultColormap(o_display, o_screen); if(ui_col_monochromeMode == FALSE){ /* settings for black learning curve */ fg.red = 0; fg.green = 0; fg.blue = 0; fg2.red = 65535; fg2.green = 0; fg2.blue = 0; }else{ XSetLineAttributes(o_display, o_gc[test_gc],1,LineDoubleDash, CapButt,JoinMiter); fg.red = 0; fg.green = 0; fg.blue = 0; fg2.red = 0; fg2.green = 0; fg2.blue = 0; } background = WhitePixel (o_display, o_screen); XSetBackground (o_display, o_gc[train_gc], background); XSetBackground (o_display, o_gc[test_gc], background); XSetBackground (o_display, o_gc[label_gc], background); XAllocColor(o_display,o_graph_col,&fg); XAllocColor(o_display,o_graph_col,&fg2); foreground = BlackPixel (o_display, o_screen); XSetForeground (o_display, o_gc[train_gc], fg.pixel); XSetForeground (o_display, o_gc[test_gc], fg2.pixel); XSetForeground (o_display, o_gc[label_gc], foreground); XSetGraphicsExposures(o_display,o_gc[label_gc],0); XSetGraphicsExposures(o_display,o_gc[train_gc],0); XSetGraphicsExposures(o_display,o_gc[test_gc],0); o_Pixmap = XCreatePixmap(o_display,o_window, (unsigned int) o_PixmapWidth, (unsigned int) o_PixmapHeight, (unsigned int) o_depth); o_ClearPixmap(o_display,o_Pixmap,o_gc[train_gc],fg.pixel,o_screen,0,0, o_PixmapWidth,o_PixmapHeight); o_ClearPixmap(o_display,o_Pixmap,o_gc[test_gc],fg2.pixel,o_screen,0,0, o_PixmapWidth,o_PixmapHeight); XClearArea(o_display,o_window,o_OsziXPos,o_OsziYPos, (unsigned int) o_OsziWidth-1, (unsigned int) o_OsziHeight,1); o_PressPossible = 1; }
// Creates the event addon void* FcitxTabletCreate(FcitxInstance* instance) { FcitxTablet* tablet = fcitx_utils_new(FcitxTablet); FcitxTabletLoadConfig(&tablet->config); // TODO select driver from config, currently using lxbi { // Initialise the driver switch(tablet->config.Driver) { case DRIVER_LXBI: tablet->driverInstance = &lxbi; break; // add other drivers here } tablet->driverData = tablet->driverInstance->Create(); tablet->driverPacket = (char*) malloc(tablet->driverInstance->packet_size); } { // Initialise the X display if(NULL == (tablet->xDisplay = FcitxX11GetDisplay(instance))) { FcitxLog(ERROR, "Unable to open X display"); return NULL; } // get dimensions int screen = DefaultScreen(tablet->xDisplay); tablet->xWidth = tablet->config.Width; tablet->xHeight = tablet->config.Height; int x = tablet->config.XPos > 0 ? tablet->config.XPos : XDisplayWidth(tablet->xDisplay, screen) - tablet->xWidth + tablet->config.XPos; int y = tablet->config.YPos > 0 ? tablet->config.YPos : XDisplayHeight(tablet->xDisplay, screen) - tablet->xHeight + tablet->config.YPos; // create colours XColor back; XColor fore; { char colourString[32]; { int r = (255*tablet->config.BackgroundColour.r); int g = (255*tablet->config.BackgroundColour.g); int b = (255*tablet->config.BackgroundColour.b); sprintf(colourString,"rgb:%x/%x/%x",r,g,b); } Colormap defaultCMap = DefaultColormap(tablet->xDisplay, screen); XParseColor(tablet->xDisplay, defaultCMap, colourString, &back); XAllocColor(tablet->xDisplay, defaultCMap, &back); { int r = (255*tablet->config.StrokeColour.r); int g = (255*tablet->config.StrokeColour.g); int b = (255*tablet->config.StrokeColour.b); sprintf(colourString,"rgb:%x/%x/%x",r,g,b); } XParseColor(tablet->xDisplay, defaultCMap, colourString, &fore); XAllocColor(tablet->xDisplay, defaultCMap, &fore); } // set window attributes and create window XSetWindowAttributes attrs; attrs.override_redirect = True; attrs.background_pixel = back.pixel; tablet->xWindow = XCreateWindow(tablet->xDisplay, DefaultRootWindow(tablet->xDisplay), x, y, tablet->xWidth, tablet->xHeight, tablet->config.BorderWidth, CopyFromParent, InputOutput, CopyFromParent, CWBackPixel | CWOverrideRedirect, &attrs); // set up the foreground line (stroke) style XGCValues gcv; gcv.function = GXcopy; gcv.subwindow_mode = IncludeInferiors; gcv.line_width = 3; gcv.cap_style = CapRound; gcv.join_style = JoinRound; tablet->xGC = XCreateGC(tablet->xDisplay, tablet->xWindow, GCFunction | GCSubwindowMode | GCLineWidth | GCCapStyle | GCJoinStyle, &gcv); XSetForeground(tablet->xDisplay, tablet->xGC, fore.pixel); // prevent the window from getting focus or input XRectangle rect = {0,0,0,0}; XserverRegion region = XFixesCreateRegion(tablet->xDisplay,&rect, 1); XFixesSetWindowShapeRegion(tablet->xDisplay, tablet->xWindow, ShapeInput, 0, 0, region); XFixesDestroyRegion(tablet->xDisplay, region); } { // Initialise the stroke buffer tablet->strokesBufferSize = 2048; // should be heaps. Will get automatically enlarged if required tablet->strokesBuffer = (pt_t*) malloc(sizeof(pt_t) * tablet->strokesBufferSize); tablet->strokesPtr = tablet->strokesBuffer; } { // instantiate the engine switch(tablet->config.Engine) { case ENGINE_ZINNIA: tablet->engineInstance = &engZinnia; break; case ENGINE_FORK: tablet->engineInstance = &engFork; break; // add other engines here } tablet->engineData = tablet->engineInstance->Create(&tablet->config); } { // set up the timerfd tablet->timeoutFd = timerfd_create(CLOCK_MONOTONIC, 0); tablet->delay.it_interval.tv_sec = 0; tablet->delay.it_interval.tv_nsec = 0; tablet->delay.it_value.tv_sec = tablet->config.CommitCharMs / 1000; tablet->delay.it_value.tv_nsec = (tablet->config.CommitCharMs % 1000) * 1000000; tablet->timeoutCommitPending = 0; } tablet->fcitx = instance; return tablet; }
void xrectsel(unsigned *x_sel, unsigned *y_sel, unsigned *w_sel, unsigned *h_sel) { Display *dpy = XOpenDisplay(NULL); if (!dpy) return; Window root = DefaultRootWindow(dpy); XEvent ev; GC sel_gc; XGCValues sel_gv; int btn_pressed = 0; int x = 0, y = 0; unsigned int width = 0, height = 0; int start_x = 0, start_y = 0; Cursor cursor; cursor = XCreateFontCursor(dpy, XC_crosshair); /* Grab pointer for these events */ XGrabPointer(dpy, root, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime); sel_gv.function = GXinvert; sel_gv.subwindow_mode = IncludeInferiors; sel_gv.line_width = 1; sel_gc = XCreateGC(dpy, root, GCFunction | GCSubwindowMode | GCLineWidth, &sel_gv); for (;;) { XNextEvent(dpy, &ev); if (ev.type == ButtonPress) { btn_pressed = 1; x = start_x = ev.xbutton.x_root; y = start_y = ev.xbutton.y_root; width = height = 0; } else if (ev.type == MotionNotify) { if (!btn_pressed) continue; /* Draw only if button is pressed */ /* Re-draw last Rectangle to clear it */ XDrawRectangle(dpy, root, sel_gc, x, y, width, height); x = ev.xbutton.x_root; y = ev.xbutton.y_root; if (x > start_x) { width = x - start_x; x = start_x; } else { width = start_x - x; } if (y > start_y) { height = y - start_y; y = start_y; } else { height = start_y - y; } /* Draw Rectangle */ XDrawRectangle(dpy, root, sel_gc, x, y, width, height); XFlush(dpy); } else if (ev.type == ButtonRelease) break; } /* Re-draw last Rectangle to clear it */ XDrawRectangle(dpy, root, sel_gc, x, y, width, height); XFlush(dpy); XUngrabPointer(dpy, CurrentTime); XFreeCursor(dpy, cursor); XFreeGC(dpy, sel_gc); XSync(dpy, 1); *x_sel = x; *y_sel = y; *w_sel = width; *h_sel = height; XCloseDisplay(dpy); }
static void ShowAlert(const char *title, const char *ignore, const char *restart, const char *quit, const char *fmt, va_list args) { char text[4096], buf1[64], buf2[64], buf3[64]; Window win, b1 = 0, b2 = 0, b3 = 0, root; Display *dd; int wid, hih, w, h, i, k, mask; XGCValues gcv; GC gc; unsigned int len; XEvent ev; XSetWindowAttributes att; XRectangle rect1, rect2; char colorful; unsigned long cols[5]; XColor xcl; Colormap cmap; int cnum, fh, x, y, ww, hh, bw, bh; char *str1, *str2, *str3, *p; KeyCode keycode; int button; char **missing_charset_list_return, *def_string_return; int missing_charset_count_return; XFontStruct **font_struct_list_return; char **font_name_list_return; #if 0 /* Don't play sound here (maybe if not forked/in signal handler - later) */ SoundPlay(SOUND_ALERT); #endif if (!fmt) return; Evsnprintf(text, sizeof(text), fmt, args); /* * We may get here from obscure places like an X-error or signal handler * and things seem to work properly only if we do a new XOpenDisplay(). */ dd = XOpenDisplay(NULL); if (!dd) { fprintf(stderr, "%s\n", text); fflush(stderr); return; } button = 0; if (!title) title = _("Enlightenment Error"); str1 = AlertButtonText(1, buf1, sizeof(buf1), ignore); str2 = AlertButtonText(2, buf2, sizeof(buf2), restart); str3 = AlertButtonText(3, buf3, sizeof(buf3), quit); cnum = 0; colorful = 0; cols[0] = cols[1] = cols[2] = cols[3] = cols[4] = 0; cmap = DefaultColormap(dd, DefaultScreen(dd)); if (DefaultDepth(dd, DefaultScreen(dd)) > 4) { ExSetColor(&xcl, 220, 220, 220); if (!XAllocColor(dd, cmap, &xcl)) goto CN; cols[cnum++] = xcl.pixel; ExSetColor(&xcl, 160, 160, 160); if (!XAllocColor(dd, cmap, &xcl)) goto CN; cols[cnum++] = xcl.pixel; ExSetColor(&xcl, 100, 100, 100); if (!XAllocColor(dd, cmap, &xcl)) goto CN; cols[cnum++] = xcl.pixel; ExSetColor(&xcl, 0, 0, 0); if (!XAllocColor(dd, cmap, &xcl)) goto CN; cols[cnum++] = xcl.pixel; ExSetColor(&xcl, 255, 255, 255); if (!XAllocColor(dd, cmap, &xcl)) goto CN; cols[cnum++] = xcl.pixel; colorful = 1; } CN: if (colorful) att.background_pixel = cols[1]; else att.background_pixel = BlackPixel(dd, DefaultScreen(dd)); if (colorful) att.border_pixel = cols[3]; else att.border_pixel = WhitePixel(dd, DefaultScreen(dd)); att.backing_store = Always; att.save_under = True; att.override_redirect = True; mask = CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWSaveUnder | CWBackingStore; #if USE_COMPOSITE_OVERLAY_WINDOW /* * Intended workings: * Composite extension not enabled (or COW not available?) * - fall back to root * Composite extension enabled * - use COW whether or not compositing is enabled, window mode too */ root = XCompositeGetOverlayWindow(dd, DefaultRootWindow(dd)); if (root == None) #endif { root = DefaultRootWindow(dd); } win = XCreateWindow(dd, root, -100, -100, 1, 1, 0, CopyFromParent, InputOutput, CopyFromParent, mask, &att); gc = XCreateGC(dd, win, 0, &gcv); if (colorful) XSetForeground(dd, gc, cols[3]); else XSetForeground(dd, gc, att.border_pixel); xfs = XCreateFontSet(dd, "fixed", &missing_charset_list_return, &missing_charset_count_return, &def_string_return); if (!xfs) goto done; if (missing_charset_list_return) XFreeStringList(missing_charset_list_return); k = XFontsOfFontSet(xfs, &font_struct_list_return, &font_name_list_return); fh = 0; for (i = 0; i < k; i++) { h = font_struct_list_return[i]->ascent + font_struct_list_return[i]->descent; if (fh < h) fh = h; } XSelectInput(dd, win, ExposureMask); XMapWindow(dd, win); XGrabServer(dd); XGrabPointer(dd, win, False, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); XGrabKeyboard(dd, win, False, GrabModeAsync, GrabModeAsync, CurrentTime); XSetInputFocus(dd, win, RevertToPointerRoot, CurrentTime); XSync(dd, False); wid = DisplayWidth(dd, DefaultScreen(dd)); hih = DisplayHeight(dd, DefaultScreen(dd)); ww = (wid >= 600) ? 600 : (wid / 40) * 40; hh = (hih >= 440) ? 440 : (hih / 40) * 40; for (i = 40; i < ww; i += 40) { w = i; h = (i * hh) / ww; x = (wid - w) >> 1; y = (hih - h) >> 1; XMoveResizeWindow(dd, win, x, y, w, h); DRAW_BOX_OUT(dd, gc, win, 0, 0, w, h); XSync(dd, False); SleepUs(20000); } x = (wid - ww) >> 1; y = (hih - hh) >> 1; XMoveResizeWindow(dd, win, x, y, ww, hh); XSync(dd, False); bw = 0; if (str1) { ExTextExtents(xfs, str1, strlen(str1), &rect1, &rect2); bw = (rect2.width > bw) ? rect2.width : bw; } if (str2) { ExTextExtents(xfs, str2, strlen(str2), &rect1, &rect2); bw = (rect2.width > bw) ? rect2.width : bw; } if (str3) { ExTextExtents(xfs, str3, strlen(str3), &rect1, &rect2); bw = (rect2.width > bw) ? rect2.width : bw; } bw += 20; bh = fh + 10; #define BX(i) (5 + (((ww - bw - 10) * (i)) / 2)) #define BY (hh - bh - 5) if (str1) { b1 = XCreateWindow(dd, win, BX(0), BY, bw, bh, 0, CopyFromParent, InputOutput, CopyFromParent, mask, &att); XMapWindow(dd, b1); } if (str2) { b2 = XCreateWindow(dd, win, BX(1), BY, bw, bh, 0, CopyFromParent, InputOutput, CopyFromParent, mask, &att); XMapWindow(dd, b2); } if (str3) { b3 = XCreateWindow(dd, win, BX(2), BY, bw, bh, 0, CopyFromParent, InputOutput, CopyFromParent, mask, &att); XMapWindow(dd, b3); } XSync(dd, False); button = 0; for (; button == 0;) { XNextEvent(dd, &ev); switch (ev.type) { case KeyPress: keycode = XKeysymToKeycode(dd, XK_F1); if (keycode == ev.xkey.keycode) { DRAW_BOX_IN(dd, gc, b1, 0, 0, bw, bh); XSync(dd, False); SleepUs(500000); DRAW_BOX_OUT(dd, gc, b1, 0, 0, bw, bh); button = 1; goto do_sync; } keycode = XKeysymToKeycode(dd, XK_F2); if (keycode == ev.xkey.keycode) { DRAW_BOX_IN(dd, gc, b2, 0, 0, bw, bh); XSync(dd, False); SleepUs(500000); DRAW_BOX_OUT(dd, gc, b2, 0, 0, bw, bh); button = 2; goto do_sync; } keycode = XKeysymToKeycode(dd, XK_F3); if (keycode == ev.xkey.keycode) { DRAW_BOX_IN(dd, gc, b3, 0, 0, bw, bh); XSync(dd, False); SleepUs(500000); DRAW_BOX_OUT(dd, gc, b3, 0, 0, bw, bh); button = 3; goto do_sync; } break; case ButtonPress: if (!(ev.xbutton.y >= BY && ev.xbutton.y < BY + bh)) break; x = BX(0); if (b1 && ev.xbutton.x >= x && ev.xbutton.x < x + bw) { DRAW_BOX_IN(dd, gc, b1, 0, 0, bw, bh); goto do_sync; } x = BX(1); if (b2 && ev.xbutton.x >= x && ev.xbutton.x < x + bw) { DRAW_BOX_IN(dd, gc, b2, 0, 0, bw, bh); goto do_sync; } x = BX(2); if (b3 && ev.xbutton.x >= x && ev.xbutton.x < x + bw) { DRAW_BOX_IN(dd, gc, b3, 0, 0, bw, bh); goto do_sync; } break; case ButtonRelease: if (!(ev.xbutton.y >= BY && ev.xbutton.y < BY + bh)) break; x = BX(0); if (b1 && ev.xbutton.x >= x && ev.xbutton.x < x + bw) { DRAW_BOX_OUT(dd, gc, b1, 0, 0, bw, bh); button = 1; goto do_sync; } x = BX(1); if (b2 && ev.xbutton.x >= x && ev.xbutton.x < x + bw) { DRAW_BOX_OUT(dd, gc, b2, 0, 0, bw, bh); button = 2; goto do_sync; } x = BX(2); if (b3 && ev.xbutton.x >= x && ev.xbutton.x < x + bw) { DRAW_BOX_OUT(dd, gc, b3, 0, 0, bw, bh); button = 3; goto do_sync; } break; case Expose: /* Flush all other Expose events */ while (XCheckTypedWindowEvent(dd, ev.xexpose.window, Expose, &ev)) ; ExTextExtents(xfs, title, strlen(title), &rect1, &rect2); w = rect2.width; DRAW_HEADER(dd, gc, win, (ww - w) / 2, 5 - rect2.y, title); DRAW_BOX_OUT(dd, gc, win, 0, 0, ww, bh); DRAW_BOX_OUT(dd, gc, win, 0, bh - 1, ww, hh - fh - fh - 30 + 2); DRAW_BOX_OUT(dd, gc, win, 0, hh - fh - 20, ww, fh + 20); k = bh; for (p = text;; p += len + 1) { len = strcspn(p, "\n"); DRAW_STRING(dd, gc, win, 6, 6 + k + fh, p, len); k += fh + 2; if (p[len] == '\0') break; } if (str1) { ExTextExtents(xfs, str1, strlen(str1), &rect1, &rect2); w = rect2.width; DRAW_HEADER(dd, gc, b1, (bw - w) / 2, 5 - rect2.y, str1); DRAW_BOX_OUT(dd, gc, b1, 0, 0, bw, bh); DRAW_THIN_BOX_IN(dd, gc, win, BX(0) - 2, BY - 2, bw + 4, bh + 4); } if (str2) { ExTextExtents(xfs, str2, strlen(str2), &rect1, &rect2); w = rect2.width; DRAW_HEADER(dd, gc, b2, (bw - w) / 2, 5 - rect2.y, str2); DRAW_BOX_OUT(dd, gc, b2, 0, 0, bw, bh); DRAW_THIN_BOX_IN(dd, gc, win, BX(1) - 2, BY - 2, bw + 4, bh + 4); } if (str3) { ExTextExtents(xfs, str3, strlen(str3), &rect1, &rect2); w = rect2.width; DRAW_HEADER(dd, gc, b3, (bw - w) / 2, 5 - rect2.y, str3); DRAW_BOX_OUT(dd, gc, b3, 0, 0, bw, bh); DRAW_THIN_BOX_IN(dd, gc, win, BX(2) - 2, BY - 2, bw + 4, bh + 4); } do_sync: XSync(dd, False); break; default: break; } } XFreeFontSet(dd, xfs); done: XUngrabServer(dd); XDestroyWindow(dd, win); XFreeGC(dd, gc); if (cnum > 0) XFreeColors(dd, cmap, cols, cnum, 0); XCloseDisplay(dd); switch (button) { default: case 1: break; case 2: SessionExit(EEXIT_RESTART, NULL); break; case 3: SessionExit(EEXIT_EXIT, NULL); break; } }
void msg_win_create(MBPanel *panel, MBPanelMessageQueue *msg) { int msg_win_x = 0, msg_win_y = 0, msg_win_w = 0, msg_win_h = 0, box_x_offset = 0, box_y_offset = 0, arrow_offset = 0, cnt = 0, box_w, box_h; int x, y, txt_v_offset; unsigned char r, g, b, fr, fg, fb; MBPixbufImage *img_backing = NULL; MBDrawable *tmp_drw; Pixmap mask; GC mask_gc; XSetWindowAttributes attr; XWindowAttributes root_attr; XWMHints *wm_hints; long winmask; MBLayout *layout; /* #ifdef USE_XFT XftDraw *xftdraw; XftColor txt_xftcol; XRenderColor colortmp; #endif */ layout = msg_calc_win_size(panel, msg, &msg_win_w, &msg_win_h); msg_win_h += (2*MSG_WIN_Y_PAD); box_w = msg_win_w; box_h = msg_win_h; XGetWindowAttributes(panel->dpy, panel->win_root, &root_attr); #define ARROW_SIZE 4 #define MSG_TEXT_MARGIN 10 switch (panel->orientation) { case East: msg_win_w += ARROW_SIZE; msg_win_x = panel->x - msg_win_w - 5; break; case West: msg_win_w += ARROW_SIZE; box_x_offset += ARROW_SIZE; msg_win_x = panel->x + panel->w + 5; break; case South: msg_win_h += ARROW_SIZE; msg_win_y = panel->y - msg_win_h - 5; break; case North: msg_win_h += ARROW_SIZE; box_y_offset += ARROW_SIZE; msg_win_y = panel->y + panel->h + 5; break; } if (PANEL_IS_VERTICAL(panel)) { arrow_offset = msg_win_h / 2; msg_win_y = panel->y + msg->sender->y + (msg->sender->h/2) - arrow_offset; if (msg_win_y < 0) { msg_win_y = 5; /* a little margin to display top */ arrow_offset = msg->sender->y + (msg->sender->h/2); } if (msg_win_y + msg_win_h > panel->y + panel->h) { /* reposition with a bit of margin - 5px */ msg_win_y = (panel->y + panel->h) - msg_win_h - 5; arrow_offset = panel->y + msg->sender->y - msg_win_y + (msg->sender->h/2); } } else { arrow_offset = msg_win_w / 2; msg_win_x = panel->x + msg->sender->x + (msg->sender->w/2) - arrow_offset; if (msg_win_x < 0) { msg_win_x = 5; arrow_offset = msg->sender->x + (msg->sender->w/2); } if (msg_win_x + msg_win_w > panel->x + panel->w) { msg_win_x = (panel->x + panel->w) - msg_win_w - 5; arrow_offset = panel->x + msg->sender->x - msg_win_x + (msg->sender->w/2); } } attr.event_mask = ButtonPressMask|ButtonReleaseMask|ExposureMask; attr.background_pixel = BlackPixel(panel->dpy, panel->screen); attr.do_not_propagate_mask = ButtonPressMask|ButtonReleaseMask; winmask = CWBackPixel|CWEventMask|CWDontPropagate; if (panel->use_overide_wins) { winmask |= CWOverrideRedirect; attr.override_redirect = True; } panel->msg_win = XCreateWindow(panel->dpy, panel->win_root, msg_win_x, msg_win_y, msg_win_w, msg_win_h, 0, CopyFromParent, CopyFromParent, CopyFromParent, winmask, &attr); XChangeProperty(panel->dpy, panel->msg_win, panel->atoms[ATOM_WM_WINDOW_TYPE], XA_ATOM, 32, PropModeReplace, (unsigned char *) &panel->atoms[ATOM_WM_WINDOW_TYPE_SPLASH], 1); wm_hints = XAllocWMHints(); wm_hints->input = False; wm_hints->flags = InputHint; XSetWMHints(panel->dpy, panel->msg_win, wm_hints); tmp_drw = mb_drawable_new(panel->pb, msg_win_w, msg_win_h); img_backing = mb_pixbuf_img_rgba_new(panel->pb, msg_win_w, msg_win_h); mask = XCreatePixmap(panel->dpy, panel->win_root, msg_win_w, msg_win_h, 1 ); mask_gc = XCreateGC(panel->dpy, mask, 0, 0 ); XSetForeground(panel->dpy, mask_gc, WhitePixel( panel->dpy, panel->screen )); XFillRectangle(panel->dpy, mask, mask_gc, 0, 0, msg_win_w, msg_win_h ); XSetForeground(panel->dpy, mask_gc, BlackPixel( panel->dpy, panel->screen )); /* * - fill entire block with forground color * - alpha clear part * - draw arrow part * - curve corners ? */ r = mb_col_red(panel->msg_col); g = mb_col_green(panel->msg_col); b = mb_col_blue(panel->msg_col); fr = mb_col_red(panel->msg_fg_col); fg = mb_col_green(panel->msg_fg_col); fb = mb_col_blue(panel->msg_fg_col); mb_pixbuf_img_fill (panel->pb, img_backing, r, g, b, 255); /* border */ /* top/bottom */ for (x = box_x_offset; x < box_x_offset + box_w; x++) { mb_pixbuf_img_plot_pixel(panel->pb, img_backing, x, box_y_offset, fr, fg, fb); mb_pixbuf_img_plot_pixel(panel->pb, img_backing, x, box_h + box_y_offset - 1, fr, fg, fb); } /* sides */ for (y = box_y_offset; y < box_y_offset + box_h; y++) { mb_pixbuf_img_plot_pixel(panel->pb, img_backing, box_x_offset, y, fr, fg, fb); mb_pixbuf_img_plot_pixel(panel->pb, img_backing, box_w + box_x_offset - 1, y, fr, fg, fb); } /* arrow */ switch (panel->orientation) { case East: for (x= box_w; x < msg_win_w; x++) for (y=0; y < box_h; y++) XDrawPoint(panel->dpy, mask, mask_gc, x, y); XSetForeground( panel->dpy, mask_gc, WhitePixel( panel->dpy, panel->screen )); for (x= msg_win_w - 1; x > msg_win_w - ARROW_SIZE - 2 ; x--) { for (y = arrow_offset - cnt; y <= arrow_offset + cnt; y++) { XDrawPoint(panel->dpy, mask, mask_gc, x, y); if ( y == (arrow_offset - cnt) || y == (arrow_offset + cnt) ) mb_pixbuf_img_plot_pixel(panel->pb, img_backing, x, y, fr, fg, fb); else mb_pixbuf_img_plot_pixel(panel->pb, img_backing, x, y, r,g,b); } cnt++; } break; case West: for (x=0; x<ARROW_SIZE; x++) for (y=0; y < msg_win_h; y++) XDrawPoint(panel->dpy, mask, mask_gc, x, y); XSetForeground( panel->dpy, mask_gc, WhitePixel( panel->dpy, panel->screen )); for (x=0; x<ARROW_SIZE + 1; x++) { for (y = arrow_offset - cnt; y <= arrow_offset + cnt; y++) { XDrawPoint(panel->dpy, mask, mask_gc, x, y); if ( y == (arrow_offset - cnt) || y == (arrow_offset + cnt) ) mb_pixbuf_img_plot_pixel(panel->pb, img_backing, x, y, fr, fg, fb); else mb_pixbuf_img_plot_pixel(panel->pb, img_backing, x, y, r,g,b); } cnt++; } break; case South: for (y=msg_win_h-ARROW_SIZE; y < msg_win_h; y++) for (x=0; x < msg_win_w; x++) XDrawPoint(panel->dpy, mask, mask_gc, x, y); XSetForeground( panel->dpy, mask_gc, WhitePixel( panel->dpy, panel->screen )); for (y=msg_win_h; y >= msg_win_h - ARROW_SIZE - 1; y--) { for (x = arrow_offset - cnt; x <= arrow_offset + cnt; x++) { XDrawPoint(panel->dpy, mask, mask_gc, x, y); if ( x == (arrow_offset - cnt) || x == (arrow_offset + cnt) ) mb_pixbuf_img_plot_pixel(panel->pb, img_backing, x, y, fr, fg, fb); else mb_pixbuf_img_plot_pixel(panel->pb, img_backing, x, y, r,g,b); } cnt++; } break; case North: for (y=0; y < ARROW_SIZE; y++) for (x=0; x < msg_win_w; x++) XDrawPoint(panel->dpy, mask, mask_gc, x, y); XSetForeground( panel->dpy, mask_gc, WhitePixel( panel->dpy, panel->screen )); for (y=0; y < ARROW_SIZE + 1; y++) { for (x = arrow_offset - cnt; x <= arrow_offset + cnt; x++) { XDrawPoint(panel->dpy, mask, mask_gc, x, y); if ( x == (arrow_offset - cnt) || x == (arrow_offset + cnt) ) mb_pixbuf_img_plot_pixel(panel->pb, img_backing, x, y, fr, fg, fb); else mb_pixbuf_img_plot_pixel(panel->pb, img_backing, x, y, r,g,b); } cnt++; } break; } /* Render picture to pixmap */ mb_pixbuf_img_render_to_drawable(panel->pb, img_backing, mb_drawable_pixmap(tmp_drw), 0, 0); mb_font_set_color(panel->msg_font, panel->msg_fg_col); txt_v_offset = MSG_WIN_Y_PAD + box_y_offset; /* i = strlen(msg->sender->name); while (_get_text_length(panel, msg->sender->name, i) > ( box_w + ( 2 * MSG_TEXT_MARGIN )) && i > 0) i--; */ /* Title */ XSetForeground(panel->dpy, panel->msg_gc, mb_col_xpixel(panel->msg_fg_col)); mb_font_render_simple (panel->msg_font, tmp_drw, MSG_TEXT_MARGIN + box_x_offset, txt_v_offset, box_w, /* XXX - TEXT_MARGIN ? */ (unsigned char *)msg->sender->name, MB_ENCODING_UTF8, 0); /* close box */ XDrawRectangle(panel->dpy, mb_drawable_pixmap(tmp_drw), panel->msg_gc, box_x_offset + box_w - MSG_TEXT_MARGIN - mb_font_get_height(panel->msg_font), txt_v_offset, mb_font_get_height(panel->msg_font), mb_font_get_height(panel->msg_font) ); XDrawLine(panel->dpy, mb_drawable_pixmap(tmp_drw), panel->msg_gc, box_x_offset + box_w - MSG_TEXT_MARGIN - mb_font_get_height(panel->msg_font), txt_v_offset , box_x_offset + box_w - MSG_TEXT_MARGIN, txt_v_offset + mb_font_get_height(panel->msg_font)); XDrawLine(panel->dpy, mb_drawable_pixmap(tmp_drw), panel->msg_gc, box_x_offset + box_w - MSG_TEXT_MARGIN - mb_font_get_height(panel->msg_font), txt_v_offset + mb_font_get_height(panel->msg_font), box_x_offset + box_w - MSG_TEXT_MARGIN, txt_v_offset ); /* Title underline */ XDrawLine(panel->dpy, mb_drawable_pixmap(tmp_drw), panel->msg_gc, box_x_offset + MSG_TEXT_MARGIN / 2 , txt_v_offset + mb_font_get_height(panel->msg_font) + ( MSG_LINE_SPC / 2 ), box_x_offset + box_w - (MSG_TEXT_MARGIN / 2), txt_v_offset + mb_font_get_height(panel->msg_font) + ( MSG_LINE_SPC / 2 ) ); /* Forward render postion on */ txt_v_offset += mb_font_get_height(panel->msg_font) + MSG_LINE_SPC; /* render msg text */ mb_layout_render (layout, tmp_drw, MSG_TEXT_MARGIN + box_x_offset, txt_v_offset, 0); txt_v_offset += mb_layout_height(layout); /* Context button, if applicable */ if (msg->extra_context_data) { int context_width = mb_font_get_txt_width ( panel->msg_font, msg->extra_context_data, strlen((char*)msg->extra_context_data), MB_ENCODING_UTF8); XSetForeground( panel->dpy, panel->msg_gc, mb_col_xpixel(panel->msg_link_col)); panel->msg_context_y1 = txt_v_offset; panel->msg_context_y2 = txt_v_offset + mb_font_get_height(panel->msg_font); mb_font_set_color(panel->msg_font, panel->msg_link_col); mb_font_render_simple (panel->msg_font, tmp_drw, MSG_TEXT_MARGIN + box_x_offset, txt_v_offset, box_w, (unsigned char *)msg->extra_context_data, MB_ENCODING_UTF8, 0); /* underline */ XDrawLine(panel->dpy, mb_drawable_pixmap(tmp_drw), panel->msg_gc, MSG_TEXT_MARGIN + box_x_offset, txt_v_offset + mb_font_get_height(panel->msg_font), MSG_TEXT_MARGIN + box_x_offset + context_width, txt_v_offset + mb_font_get_height(panel->msg_font)); } XSetWindowBackgroundPixmap(panel->dpy, panel->msg_win, mb_drawable_pixmap(tmp_drw)); mb_drawable_unref(tmp_drw); XShapeCombineMask( panel->dpy, panel->msg_win, ShapeBounding, 0, 0, mask, ShapeSet); XMapWindow(panel->dpy, panel->msg_win); XFree(wm_hints); mb_pixbuf_img_free(panel->pb, img_backing); XFreePixmap(panel->dpy, mask); }
static void init_map (struct state *st) { XGCValues gcv; XGetWindowAttributes (st->dpy, st->window, &st->xgwa); st->cmap = st->xgwa.colormap; st->flip_x = (random() % 2); st->flip_xy = (random() % 2); if (mono_p) st->flip_xy = 0; else if (st->colors) free_colors (st->xgwa.screen, st->cmap, st->colors, st->ncolors); st->colors = 0; st->ncolors = get_integer_resource (st->dpy, "ncolors", "Integer"); st->delay = get_integer_resource (st->dpy, "delay", "Integer"); st->delay2 = get_integer_resource (st->dpy, "delay2", "Integer"); st->iterations = get_integer_resource (st->dpy, "iterations", "Integer"); if (st->iterations < 0) st->iterations = 0; else if (st->iterations > 7) st->iterations = 7; if (st->ncolors <= 2) st->ncolors = 0; if (st->ncolors == 0) mono_p = True; if (st->ncolors > 255) st->ncolors = 255; /* too many look bad */ if (!st->gc) st->gc = XCreateGC (st->dpy, st->window, 0, &gcv); if (!st->gc2) st->gc2 = XCreateGC (st->dpy, st->window, 0, &gcv); if (mono_p) st->extra_krinkly_p = !(random() % 15); else st->extra_krinkly_p = !(random() % 5); if (!mono_p) { st->colors = (XColor *) malloc (st->ncolors * sizeof(*st->colors)); make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->cmap, st->colors, &st->ncolors, True, 0, False); if (st->ncolors <= 2) mono_p = 1; } if (mono_p) { int i; unsigned long fg_pixel = get_pixel_resource (st->dpy, st->xgwa.colormap, "foreground", "Foreground"); unsigned long bg_pixel = get_pixel_resource (st->dpy, st->xgwa.colormap, "background", "Background"); if (!st->colors) { st->ncolors = 50; st->colors = (XColor *) calloc (st->ncolors, sizeof(*st->colors)); } st->colors[0].pixel = fg_pixel; for (i = 1; i < st->ncolors; i++) st->colors[i].pixel = bg_pixel; } XSetForeground (st->dpy, st->gc, st->colors[1].pixel); XFillRectangle (st->dpy, st->window, st->gc, 0, 0, st->xgwa.width, st->xgwa.height); if (st->flip_xy) { st->xmax = st->xgwa.height; st->ymax = st->xgwa.width; } else { st->xmax = st->xgwa.width; st->ymax = st->xgwa.height; } if (st->cell) free (st->cell); st->cell = (signed char *) calloc (st->xmax * st->ymax, 1); CELL (0, 0) = 0; st->xstep = COUNT; st->ystep = COUNT; st->iteration = 0; st->cx = 0; }
void winopen(void) { XWMHints *hints; xdpy = XOpenDisplay(nil); if (!xdpy) winerror(&gapp, "could not open display."); XA_TARGETS = XInternAtom(xdpy, "TARGETS", False); XA_TIMESTAMP = XInternAtom(xdpy, "TIMESTAMP", False); XA_UTF8_STRING = XInternAtom(xdpy, "UTF8_STRING", False); xscr = DefaultScreen(xdpy); ximage_init(xdpy, xscr, DefaultVisual(xdpy, xscr)); xcarrow = XCreateFontCursor(xdpy, XC_left_ptr); xchand = XCreateFontCursor(xdpy, XC_hand2); xcwait = XCreateFontCursor(xdpy, XC_watch); xbgcolor.red = 0x7000; xbgcolor.green = 0x7000; xbgcolor.blue = 0x7000; xshcolor.red = 0x4000; xshcolor.green = 0x4000; xshcolor.blue = 0x4000; XAllocColor(xdpy, DefaultColormap(xdpy, xscr), &xbgcolor); XAllocColor(xdpy, DefaultColormap(xdpy, xscr), &xshcolor); xwin = XCreateWindow(xdpy, DefaultRootWindow(xdpy), 10, 10, 200, 100, 1, ximage_get_depth(), InputOutput, ximage_get_visual(), 0, nil); XSetWindowColormap(xdpy, xwin, ximage_get_colormap()); XSelectInput(xdpy, xwin, StructureNotifyMask | ExposureMask | KeyPressMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask); mapped = 0; xgc = XCreateGC(xdpy, xwin, 0, nil); XDefineCursor(xdpy, xwin, xcarrow); hints = XAllocWMHints(); if (hints) { hints->flags = IconPixmapHint; hints->icon_pixmap = XCreateBitmapFromData(xdpy, xwin, gs_l_xbm_bits, gs_l_xbm_width, gs_l_xbm_height); if (hints->icon_pixmap) { XSetWMHints(xdpy, xwin, hints); } XFree(hints); } }
bool CWinSystemX11::CreateIconPixmap() { int depth; XImage *img = NULL; Visual *vis; XWindowAttributes wndattribs; XVisualInfo visInfo; double rRatio; double gRatio; double bRatio; int outIndex = 0; unsigned int i,j; unsigned char *buf; uint32_t *newBuf = 0; size_t numNewBufBytes; // Get visual Info XGetWindowAttributes(m_dpy, m_glWindow, &wndattribs); visInfo.visualid = wndattribs.visual->visualid; int nvisuals = 0; XVisualInfo* visuals = XGetVisualInfo(m_dpy, VisualIDMask, &visInfo, &nvisuals); if (nvisuals != 1) { CLog::Log(LOGERROR, "CWinSystemX11::CreateIconPixmap - could not find visual"); return false; } visInfo = visuals[0]; XFree(visuals); depth = visInfo.depth; vis = visInfo.visual; if (depth < 15) { CLog::Log(LOGERROR, "CWinSystemX11::CreateIconPixmap - no suitable depth"); return false; } rRatio = vis->red_mask / 255.0; gRatio = vis->green_mask / 255.0; bRatio = vis->blue_mask / 255.0; CBaseTexture *iconTexture = CBaseTexture::LoadFromFile("special://xbmc/media/icon256x256.png"); if (!iconTexture) return false; buf = iconTexture->GetPixels(); if (depth>=24) numNewBufBytes = (4 * (iconTexture->GetWidth() * iconTexture->GetHeight())); else numNewBufBytes = (2 * (iconTexture->GetWidth() * iconTexture->GetHeight())); newBuf = (uint32_t*)malloc(numNewBufBytes); if (!newBuf) { CLog::Log(LOGERROR, "CWinSystemX11::CreateIconPixmap - malloc failed"); return false; } for (i=0; i<iconTexture->GetHeight();++i) { for (j=0; j<iconTexture->GetWidth();++j) { unsigned int pos = i*iconTexture->GetPitch()+j*4; unsigned int r, g, b; r = (buf[pos+2] * rRatio); g = (buf[pos+1] * gRatio); b = (buf[pos+0] * bRatio); r &= vis->red_mask; g &= vis->green_mask; b &= vis->blue_mask; newBuf[outIndex] = r | g | b; ++outIndex; } } img = XCreateImage(m_dpy, vis, depth,ZPixmap, 0, (char *)newBuf, iconTexture->GetWidth(), iconTexture->GetHeight(), (depth>=24)?32:16, 0); if (!img) { CLog::Log(LOGERROR, "CWinSystemX11::CreateIconPixmap - could not create image"); free(newBuf); return false; } if (!XInitImage(img)) { CLog::Log(LOGERROR, "CWinSystemX11::CreateIconPixmap - init image failed"); XDestroyImage(img); return false; } // set byte order union { char c[sizeof(short)]; short s; } order; order.s = 1; if ((1 == order.c[0])) { img->byte_order = LSBFirst; } else { img->byte_order = MSBFirst; } // create icon pixmap from image m_icon = XCreatePixmap(m_dpy, m_glWindow, img->width, img->height, depth); GC gc = XCreateGC(m_dpy, m_glWindow, 0, NULL); XPutImage(m_dpy, m_icon, gc, img, 0, 0, 0, 0, img->width, img->height); XFreeGC(m_dpy, gc); XDestroyImage(img); // this also frees newBuf delete iconTexture; return true; }
BOOL InitPixelFormat(SCREENSAVER *ss) { ModeInfo *mi; int i; ss->modeinfo.gc = XCreateGC(ss->hdc, 0, 0, NULL); assert(ss->modeinfo.gc != NULL); if (hack_ncolors <= 0) hack_ncolors = 64; else if (hack_ncolors > MAX_COLORCELLS) hack_ncolors = MAX_COLORCELLS; mi = &ss->modeinfo; mi->install_p = fChildPreview; mi->writable_p = True; mi->black_pixel = 0; mi->white_pixel = 255; mi->npixels = hack_ncolors; mi->colors = NULL; mi->pixels = NULL; mi->threed = False; mi->threed_delta = 1.5; mi->threed_right_color = load_color(NULL, 0, "red"); mi->threed_left_color = load_color(NULL, 0, "blue"); mi->threed_both_color = load_color(NULL, 0, "magenta"); mi->threed_none_color = load_color(NULL, 0, "black"); if (hack_ncolors_enabled) { mi->colors = (XColor *) calloc(mi->npixels, sizeof(*mi->colors)); if (mi->colors == NULL) return FALSE; switch (hack_color_scheme) { case color_scheme_uniform: make_uniform_colormap(mi->xgwa.screen, mi->xgwa.visual, mi->xgwa.colormap, mi->colors, &mi->npixels, True, &mi->writable_p, True); break; case color_scheme_smooth: make_smooth_colormap(mi->xgwa.screen, mi->xgwa.visual, mi->xgwa.colormap, mi->colors, &mi->npixels, True, &mi->writable_p, True); break; case color_scheme_bright: case color_scheme_default: make_random_colormap(mi->xgwa.screen, mi->xgwa.visual, mi->xgwa.colormap, mi->colors, &mi->npixels, (hack_color_scheme == color_scheme_bright), True, &mi->writable_p, True); break; default: fprintf(stderr, "Bad color scheme\n"); abort(); } mi->pixels = (unsigned long *)calloc(mi->npixels, sizeof(*mi->pixels)); if (mi->pixels == NULL) { free(mi->colors); return FALSE; } for (i = 0; i < mi->npixels; i++) mi->pixels[i] = mi->colors[i].pixel; } return TRUE; }
int main() { XTextProperty title; XEvent event; XSizeHints *hints; XWMHints *wm_hints; KeySym key; Pixmap pix; pthread_t thread; /* grepare toPlot function */ spline_init(); /* visual routines */ int pressed_1[3] = {0, 0, 0}; // pressed state of button1: condition and coordinates char *caption = "Interpolation"; char *dpy_str = getenv("DISPLAY"); fprintf(stderr, "Connecting to %s\t ", dpy_str); dpy = XOpenDisplay(dpy_str); if( !dpy ) { fprintf(stderr, "Unable to connect\n"); exit(EXIT_FAILURE); } else { fprintf(stderr, "OK\n"); } scr = DefaultScreen(dpy); getColors(); width = 2 * DisplayWidth(dpy, scr) / 3; height = 2 * DisplayHeight(dpy, scr) / 3; win = XCreateSimpleWindow(dpy, RootWindow(dpy, scr), 0, 0, width, height, 0, black, white ); XStringListToTextProperty(&caption, 1, &title); XSetWMName(dpy, win, &title); XSetWMIconName(dpy, win, &title); cont = XCreateGC(dpy, win, 0, NULL); if( cont<0 ) { fprintf(stderr, "XCReateGC: unable to set GC"); exit(EXIT_FAILURE); } /* making window unresizeable */ hints = XAllocSizeHints(); if( !hints ) { fprintf(stderr, "XAllocSizeHints: out of memory"); exit(EXIT_FAILURE); } hints->flags = PMaxSize | PMinSize; hints->min_width = width; hints->min_height = height; hints->max_width = width; hints->max_height = height; XSetWMNormalHints(dpy, win, hints); XFree(hints); /* setting icon */ pix = XCreateBitmapFromData(dpy, win, icon_bits, icon_width, icon_height); if( !pix ) { fprintf(stderr, "XCreateBitmapFromData: cannot create icon"); exit(EXIT_FAILURE); } wm_hints = XAllocWMHints(); if( !wm_hints ) { fprintf(stderr, "XAllocWMHints: out of memory"); exit(EXIT_FAILURE); } wm_hints->flags = IconPixmapHint | StateHint | IconPositionHint; wm_hints->icon_pixmap = pix; wm_hints->initial_state = IconicState; wm_hints->icon_x = 0; wm_hints->icon_y = 0; XSetWMHints(dpy, win, wm_hints); XFree(wm_hints); /* making window visible */ XMapWindow(dpy, win); draw(2,1); XSelectInput(dpy, win, ExposureMask | KeyPressMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask); while( 1 ) { XNextEvent(dpy, &event); switch( event.type ) { case Expose: if( event.xexpose.count>0 ) break; draw(0,1); XFlush(dpy); break; case KeyPress: XLookupString((XKeyEvent*) &event, NULL, 0, &key, NULL); /* moving window */ switch( key ) { case XK_Down: pthread_create(&thread, NULL, dec, (void*)&shift_y); break; case XK_Up: pthread_create(&thread, NULL, inc, (void*)&shift_y); break; case XK_Right: pthread_create(&thread, NULL, dec, (void*)&shift_x); break; case XK_Left: pthread_create(&thread, NULL, inc, (void*)&shift_x); break; case XK_plus: pthread_create(&thread, NULL, inc, (void*)&shift_pix); break; case XK_minus: pthread_create(&thread, NULL, dec, (void*)&shift_pix); break; case XK_equal: pthread_create(&thread, NULL, def, (void*)NULL); break; case XK_Escape: XCloseDisplay(dpy); exit(EXIT_SUCCESS); default: break; } break; case ButtonPress: switch( event.xbutton.button ) { case Button1: pressed_1[0]=1; pressed_1[1]=event.xmotion.x; pressed_1[2]=event.xmotion.y; break; default: break; } break; case ButtonRelease: switch( event.xbutton.button ) { case Button1: pressed_1[0]=0; break; default: break; } break; case MotionNotify: if( pressed_1[0] ) { /* if button_1 is pressed while moving */ draw(1,0); shift_x-=pressed_1[1]-event.xmotion.x; shift_y-=pressed_1[2]-event.xmotion.y; pressed_1[1]=event.xmotion.x; pressed_1[2]=event.xmotion.y; draw(1,1); } pos_x=event.xmotion.x; pos_y=event.xmotion.y; drawInfo(); break; default: break; } /* switch(event.type) */ } /* endless loop */ XCloseDisplay(dpy); return EXIT_SUCCESS; }
int main(int argc, char **argv){ Display *dpy; Window w, quit, clearButton, drawButton; Window root; struct timespec wait; int screen; unsigned long black, white; GC gc; XEvent e; float t; int isDraw; int pointNum; int i; XPoint usrPoints[20]; XPoint bufPoints[20]; XPoint selectedPoints[20]; //*************************************init**** dpy = XOpenDisplay(""); root = DefaultRootWindow (dpy); screen = DefaultScreen (dpy); white = WhitePixel (dpy, screen); black = BlackPixel (dpy, screen); w = XCreateSimpleWindow(dpy, root, 100, 100, WIDTH, HEIGHT, BORDER, black, white); /* Make Buttons */ quit = XCreateSimpleWindow(dpy, w, 10, 3, 30, 12, BORDER, black, white); clearButton = XCreateSimpleWindow(dpy, w, 52, 3, 37, 12, BORDER, black, white); drawButton = XCreateSimpleWindow(dpy, w, 100, 3, 35, 12, BORDER, black, white); gc = XCreateGC(dpy, w, 0, NULL); pointNum = 0; isDraw = 0; t = 0; wait.tv_sec = 0; wait.tv_nsec = NANOTIME; for (i = 0; i < 20; i++) { usrPoints[i].x = 0; usrPoints[i].y = 0; bufPoints[i].x = 0; bufPoints[i].y = 0; } //********************************************* XSelectInput(dpy, w, ButtonPressMask | ExposureMask); XSelectInput(dpy, quit, ButtonPressMask); XSelectInput(dpy, clearButton, ButtonPressMask); XSelectInput(dpy, drawButton, ButtonPressMask); XMapWindow(dpy, w); XMapSubwindows(dpy, w); XSetForeground(dpy, gc, white); XSetForeground(dpy, gc, black); //*************************************loop**** while(1){ if(XEventsQueued(dpy, QueuedAfterReading)){ XDrawString(dpy, quit, gc, 4, 10, "Exit", 4); XDrawString(dpy, clearButton, gc, 4, 10, "Clear", 5); XDrawString(dpy, drawButton, gc, 4, 10, "Draw", 4); //***********************************event**** XNextEvent(dpy, &e); switch(e.type){ case ButtonPress : if (e.xany.window == quit) { return 0; } else if (e.xany.window == clearButton) { XClearWindow(dpy, w); t = 0; isDraw = 0; pointNum = 0; } else if (e.xany.window == drawButton) { if (!pointNum) break; isDraw = 1; } else { if (0 < t && t < 1) XClearWindow(dpy, w); selectedPoints[pointNum].x = e.xbutton.x; selectedPoints[pointNum].y = e.xbutton.y; bufPoints[pointNum] = selectedPoints[pointNum]; pointNum++; drawPointDetail(dpy, w, gc, bufPoints, pointNum); isDraw = 0; t = 0; } break; case Expose: drawPointDetail(dpy, w, gc, bufPoints, pointNum); isDraw = 0; t = 0; } } else { //********************************animation**** if (t < 1 && isDraw) { nanosleep(&wait, NULL); drawBeizerCurve(dpy, w, gc, selectedPoints, bufPoints, t, pointNum); t += 0.00001; } else if (t >= 1 && isDraw) { isDraw = 0; } } XFlush(dpy); } return 0; }
void xf_xdamage_init(xfInfo* xfi) { Bool pixmaps; int damage_event; int damage_error; int major, minor; XGCValues values; if (XShmQueryExtension(xfi->display) != False) { XShmQueryVersion(xfi->display, &major, &minor, &pixmaps); if (pixmaps != True) { printf("XShmQueryVersion failed\n"); return; } } else { printf("XShmQueryExtension failed\n"); return; } if (XDamageQueryExtension(xfi->display, &damage_event, &damage_error) == 0) { printf("XDamageQueryExtension failed\n"); return; } XDamageQueryVersion(xfi->display, &major, &minor); if (XDamageQueryVersion(xfi->display, &major, &minor) == 0) { printf("XDamageQueryVersion failed\n"); return; } else if (major < 1) { printf("XDamageQueryVersion failed: major:%d minor:%d\n", major, minor); return; } xfi->xdamage_notify_event = damage_event + XDamageNotify; xfi->xdamage = XDamageCreate(xfi->display, xfi->root_window, XDamageReportDeltaRectangles); if (xfi->xdamage == None) { printf("XDamageCreate failed\n"); return; } #ifdef WITH_XFIXES xfi->xdamage_region = XFixesCreateRegion(xfi->display, NULL, 0); if (xfi->xdamage_region == None) { printf("XFixesCreateRegion failed\n"); XDamageDestroy(xfi->display, xfi->xdamage); xfi->xdamage = None; return; } #endif values.subwindow_mode = IncludeInferiors; xfi->xdamage_gc = XCreateGC(xfi->display, xfi->root_window, GCSubwindowMode, &values); XSetFunction(xfi->display, xfi->xdamage_gc, GXcopy); }
/** * gdk_pixbuf_xlib_render_threshold_alpha: * @pixbuf: A pixbuf. * @bitmap: Bitmap where the bilevel mask will be painted to. * @src_x: Source X coordinate. * @src_y: source Y coordinate. * @dest_x: Destination X coordinate. * @dest_y: Destination Y coordinate. * @width: Width of region to threshold. * @height: Height of region to threshold. * @alpha_threshold: Opacity values below this will be painted as zero; all * other values will be painted as one. * * Takes the opacity values in a rectangular portion of a pixbuf and thresholds * them to produce a bi-level alpha mask that can be used as a clipping mask for * a drawable. * **/ void gdk_pixbuf_xlib_render_threshold_alpha (GdkPixbuf *pixbuf, Pixmap bitmap, int src_x, int src_y, int dest_x, int dest_y, int width, int height, int alpha_threshold) { GC gc; XColor color; int x, y; guchar *p; int start, start_status; int status; XGCValues gcv; g_return_if_fail (pixbuf != NULL); g_return_if_fail (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB); g_return_if_fail (gdk_pixbuf_get_n_channels (pixbuf) == 3 || gdk_pixbuf_get_n_channels (pixbuf) == 4); g_return_if_fail (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8); g_return_if_fail (bitmap != 0); g_return_if_fail (width >= 0 && height >= 0); g_return_if_fail (src_x >= 0 && src_x + width <= gdk_pixbuf_get_width (pixbuf)); g_return_if_fail (src_y >= 0 && src_y + height <= gdk_pixbuf_get_height (pixbuf)); g_return_if_fail (alpha_threshold >= 0 && alpha_threshold <= 255); if (width == 0 || height == 0) return; gc = XCreateGC (gdk_pixbuf_dpy, bitmap, 0, &gcv); if (!gdk_pixbuf_get_has_alpha (pixbuf)) { color.pixel = (alpha_threshold == 255) ? 0 : 1; XSetForeground (gdk_pixbuf_dpy, gc, color.pixel); XFillRectangle (gdk_pixbuf_dpy, bitmap, gc, dest_x, dest_y, width, height); XFreeGC (gdk_pixbuf_dpy, gc); return; } color.pixel = 0; XSetForeground (gdk_pixbuf_dpy, gc, color.pixel); XFillRectangle (gdk_pixbuf_dpy, bitmap, gc, dest_x, dest_y, width, height); color.pixel = 1; XSetForeground (gdk_pixbuf_dpy, gc, color.pixel); for (y = 0; y < height; y++) { p = (gdk_pixbuf_get_pixels (pixbuf) + (y + src_y) * gdk_pixbuf_get_rowstride (pixbuf) + src_x * gdk_pixbuf_get_n_channels (pixbuf) + gdk_pixbuf_get_n_channels (pixbuf) - 1); start = 0; start_status = *p < alpha_threshold; for (x = 0; x < width; x++) { status = *p < alpha_threshold; if (status != start_status) { if (!start_status) XDrawLine (gdk_pixbuf_dpy, bitmap, gc, start + dest_x, y + dest_y, x - 1 + dest_x, y + dest_y); start = x; start_status = status; } p += gdk_pixbuf_get_n_channels (pixbuf); } if (!start_status) XDrawLine (gdk_pixbuf_dpy, bitmap, gc, start + dest_x, y + dest_y, x - 1 + dest_x, y + dest_y); } XFreeGC (gdk_pixbuf_dpy, gc); }
int main(int argc, char* argv[]) { int number_of_stars = 200; int iterations = 1000; prec time_unit = gdt; if(argc == 3) { number_of_stars = atoi(argv[1]); iterations = atoi(argv[2]); } struct star* star_array = malloc(sizeof(struct star) * number_of_stars); generate_init_values(number_of_stars, star_array); #ifdef ANIMATE XPoint* points = malloc(sizeof(XPoint)*number_of_stars); Display* disp; Window window, rootwin; int screen; disp = XOpenDisplay(NULL); screen = DefaultScreen(disp); rootwin = RootWindow(disp,screen); window = XCreateSimpleWindow(disp,rootwin, 0,0,X_SIZE,Y_SIZE,1,0,0); GC gc = XCreateGC(disp, window, 0, 0); XSetForeground(disp, gc, WhitePixel(disp, screen)); XSetBackground(disp, gc, BlackPixel(disp, screen)); XMapWindow(disp,window); XClearWindow(disp,window); copyToXBuffer(star_array, points, number_of_stars); XDrawPoints(disp, window, gc, points, number_of_stars, 0); XFlush(disp); #endif clock_t start = clock(); for(int i = 0; i < iterations; i++) { #ifndef ANIMATE resetForces(number_of_stars, star_array); updateForces(number_of_stars, number_of_stars - 1, star_array); for(int j = 0; j < number_of_stars; ++j){ update_position(&star_array[j], time_unit); } #endif #ifdef ANIMATE resetForces(number_of_stars, star_array); updateForces(number_of_stars, number_of_stars - 1, star_array); for(int j = 0; j < number_of_stars; ++j){ update_position(&star_array[j], time_unit); copyToXBuffer(star_array, points,number_of_stars ); XDrawPoints(disp, window, gc, points, number_of_stars, CoordModeOrigin); } XClearWindow(disp,window); #endif } clock_t stop = clock(); float diff = (float)(stop - start)/CLOCKS_PER_SEC; printf("Total: %lf seconds\n",diff); printf("Bodies: %d\n",number_of_stars); printf("Iterations: %d\n", iterations); #ifdef ANIMATE free(points); XCloseDisplay(disp); #endif free(star_array); return 0; }
/*******************************************************************************\ |* openXwindow *| \*******************************************************************************/ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, int pixmask_width, int pixmask_height) { unsigned int borderwidth = 1; XClassHint classHint; char *display_name = NULL; char *wname = argv[0]; XTextProperty name; XGCValues gcv; unsigned long gcm; int dummy=0; int i; for (i=1; argv[i]; i++) { if (!strcmp(argv[i], "-display")) display_name = argv[i+1]; } if (!(display = XOpenDisplay(display_name))) { fprintf(stderr, "%s: can't open display %s\n", wname, XDisplayName(display_name)); exit(1); } screen = DefaultScreen(display); Root = RootWindow(display, screen); d_depth = DefaultDepth(display, screen); x_fd = XConnectionNumber(display); /* Convert XPM to XImage */ GetXPM(&wmgen, pixmap_bytes); /* Create a window to hold the stuff */ mysizehints.flags = USSize | USPosition; mysizehints.x = 0; mysizehints.y = 0; back_pix = GetColor("white"); fore_pix = GetColor("black"); XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); mysizehints.width = 64; mysizehints.height = 64; win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y, mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y, mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); /* Activate hints */ XSetWMNormalHints(display, win, &mysizehints); classHint.res_name = wname; classHint.res_class = wname; XSetClassHint(display, win, &classHint); XSelectInput(display, win, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask); XSelectInput(display, iconwin, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask); if (XStringListToTextProperty(&wname, 1, &name) == 0) { fprintf(stderr, "%s: can't allocate window name\n", wname); exit(1); } XSetWMName(display, win, &name); /* Create GC for drawing */ gcm = GCForeground | GCBackground | GCGraphicsExposures; gcv.foreground = fore_pix; gcv.background = back_pix; gcv.graphics_exposures = 0; NormalGC = XCreateGC(display, Root, gcm, &gcv); /* ONLYSHAPE ON */ pixmask = XCreateBitmapFromData(display, win, pixmask_bits, pixmask_width, pixmask_height); XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet); XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet); /* ONLYSHAPE OFF */ mywmhints.initial_state = WithdrawnState; mywmhints.icon_window = iconwin; mywmhints.icon_x = mysizehints.x; mywmhints.icon_y = mysizehints.y; mywmhints.window_group = win; mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint; XSetWMHints(display, win, &mywmhints); XSetCommand(display, win, argv, argc); XMapWindow(display, win); }