コード例 #1
0
  void drawText(XPoint position, string message, Color clr){

    XGCValues local_gc_vals;
    local_gc_vals.foreground = clr;
    local_gc_vals.font = xfs->fid;

    // Create gc for current drawable
    GC local_gc = XCreateGC(display, curr_d, GCForeground
			 |GCFont, &local_gc_vals);

    char *cstr = new char [message.size()+1];
    strcpy (cstr, message.c_str());

    XTextItem ti;
    ti.chars = cstr;
    ti.nchars = strlen(cstr);
    ti.delta = 0;
    ti.font = None;

    XSync(display, false);

    XDrawText(display, curr_d, local_gc, 
	      position.x-textWidth(message)/2,
	      position.y+textHeight()/2 - textDescent(), &ti, 1);

    XSync(display, false); 

    // Free temporary GC
    XFreeGC(display, local_gc);
  }
コード例 #2
0
ファイル: exii-calibrator.c プロジェクト: arfrank/EXII-Tool
void DrawAim(Display * dpy, Window w, GC gc, int x, int y, char c, int color) {
    XTextItem text = { &c, 1, 5, None };

    XSetForeground(dpy, gc, color);
    XDrawArc(dpy, w, gc, x - R / 2, y - R / 2, R, R, 0, 23040);
    XDrawLine(dpy, w, gc, x - R / 2 - 10, y, x + R / 2 + 10, y);
    XDrawLine(dpy, w, gc, x, y - R / 2 - 10, x, y + R / 2 + 10);
    XDrawText(dpy, w, gc, x, y - 4, &text, 1);
}
コード例 #3
0
ファイル: gi.cpp プロジェクト: unstablebear/rars_mod
void Gi::TextOutput(double X, double Y, const char * source)
{
  XTextItem thistext;

  thistext.chars = (char *)source;
  thistext.nchars = strlen(source);
  thistext.delta = 0;
  thistext.font = fnt->fid;

  XDrawText(dpy, drawable, gc, xcon(X), ycon(Y)+fnt->ascent, &thistext, 1);
}
コード例 #4
0
ファイル: Graphics.cpp プロジェクト: HeliWang/cs349
 void Graphics::DrawText(const Point & p, const string & text)
 {
   this->PrepareGraphicsContext();
   XTextItem xTextItem;
   xTextItem.chars  = const_cast<char*>(text.c_str());
   xTextItem.nchars = text.size();
   xTextItem.font   = XLoadFont(this->display, "a14");
   xTextItem.delta  = 0;
   Point newPoint = this->transform * p;
   XDrawText(this->display, this->window, this->gc, (int)newPoint.x, (int)newPoint.y, &xTextItem, 1);
   DebugDelay(string("DrawText"));
 }
コード例 #5
0
ファイル: mlx.c プロジェクト: TijmenW/tom7
void ml_drawtext_nofont(Display * display,
			Drawable d,
			GC gc,
			int x, int y,
			char * text,
			int len) {

  XTextItem xti;

  xti.chars = text;
  xti.nchars = len;
  xti.delta = 0;
  xti.font = None;

  XDrawText(display, d, gc, x, y, &xti, 1);

}
コード例 #6
0
ファイル: clock_main.c プロジェクト: inf0-warri0r/wm_black
int main(int argc, char *argv[])
{
	Display *dpy;
	if(!(dpy = XOpenDisplay(0x0))) return 1;

	int scr = XDefaultScreen(dpy);
	int display_width = DisplayWidth(dpy, scr);
	GC gc = XDefaultGC(dpy, scr);

	XColor col = color(dpy, "green");
	Window win = XCreateSimpleWindow(dpy,
				XRootWindow(dpy, scr),
				display_width - 320 , 150, 
				300, 100, 
				3,
				col.pixel, XBlackPixel(dpy, scr));

	XStoreName(dpy, win, "clock");
	XSetForeground(dpy, gc, col.pixel);
	XMapWindow(dpy, win);
	
	Atom delete_message = XInternAtom(dpy, "WM_DELETE_WINDOW", True);
	XSetWMProtocols(dpy, win, &delete_message, 1);

	XFontStruct *font = get_font(dpy);
	
	XTextItem item;
	item.delta = 10;
	item.font = font -> fid;
	time_t now;
 
	while (1) {
		time(&now);
		char *msg1 = (char *)ctime(&now);
		XClearArea(dpy, win, 0, 0, 300, 100, False);		
		item.chars = msg1;
		item.nchars = strlen(msg1) - 1;
		XDrawText(dpy, win, gc, 50, 50, &item, 1);
		XFlush(dpy);
		sleep(1);
	}
	XDestroyWindow(dpy, win);
	XCloseDisplay(dpy);
	return 1;
}
コード例 #7
0
ファイル: NativeDrawing.cpp プロジェクト: codemodo/pxCore
    void onDraw(pxSurfaceNative s)
    {
        // Draw the texture into this window
	    mTexture.blit(s);
		
		// Now do some native Drawing
		
		#if defined(PX_PLATFORM_WIN)
            // On Windows pxSurfaceNative is a HDC        
            TCHAR *t = _T("Some Native Windows Text");
            ::SetBkMode(s, TRANSPARENT);
			::ExtTextOut(s, 100, 100, 0, NULL, t, (UINT)_tcslen(t), NULL);
            ::MoveToEx(s, 100, 100, NULL);
            ::LineTo(s, 200, 200);
		#elif defined(PX_PLATFORM_MAC)
            // On Mac pxSurfaceNative is a GraphPtr
		    SetPort(s);
		    char* t = "Some Native Mac Text";
		    MoveTo(100, 100);
		    DrawText(t, 0, strlen(t));
		    MoveTo(100, 100);
		    LineTo(200, 200);
		#elif defined(PX_PLATFORM_X11)
            // On X11 pxSurfaceNative is a ptr to a structure
            // Please see pxBufferNative.h for its definition
		    XTextItem item;
		    item.chars = "Some Native X11 Text";
		    item.nchars = strlen(item.chars);
		    item.delta = 0;
		    item.font = None;
		    
		    XDrawText(s->display, s->drawable, s->gc,
			      100, 100, &item, 1);
		    XDrawLine(s->display, s->drawable, s->gc,
			      100, 100, 200, 200);
		    
		#endif
    }
コード例 #8
0
ファイル: aax.c プロジェクト: coolwanglu/aalib.js
static void X_flush(aa_context * c)
{
    struct xdriverdata *d=c->driverdata;
    int x, y, attr;
    int xs = 0, ys = 0;
    int l, same;
    int s = 0;
    int pos;
    attr = AA_NORMAL;
    alloctables(d);
    drawed = 0;
    area = 0;
    nrectangles[0] = 0;
    nrectangles[1] = 0;
    nrectangles[2] = 0;
    nrectangles[3] = 0;
    if (d->previoust == NULL) {
	d->previoust = malloc(d->width * d->height);
	d->previousa = calloc(d->width * d->height, 1);
	memset(d->previoust, ' ', d->width * d->height);
    }
    for (y = 0; y < aa_scrheight(c); y++) {
	s = l = 0;
	xs = 0;
	ys = y;
	for (x = 0; x < aa_scrwidth(c); x++) {
	    pos = x + y * aa_scrwidth(c);
	    if (s > 5 || (c->attrbuffer[pos] != attr && (c->textbuffer[pos] != ' ' || Black[c->attrbuffer[pos]] || Black[attr]))) {
		if (l - s)
		    MyDrawString(d,attr, xs, ys,
			&c->textbuffer[xs + ys * aa_scrwidth(c)], l - s);
		attr = c->attrbuffer[pos];
		s = l = 0;
		xs = x;
		ys = y;
	    }
	    if ((d->previoust[pos] == c->textbuffer[pos] && d->previousa[pos] == c->attrbuffer[pos]) || (!Black[attr] && d->previoust[pos] == ' ' && c->textbuffer[pos] == ' ' && !Black[d->previousa[pos]]))
		same = 1;
	    else
		same = 0;
	    if (xs == x && same)
		xs++;
	    else {
		if (same)
		    s++;
		else
		    s = 0;
		l++;
	    }
	}
	if (l - s)
	    MyDrawString(d,attr, xs, ys,
			 &c->textbuffer[xs + ys * aa_scrwidth(c)], l - s);
    }
    if (drawed) {
	memcpy(d->previousa, c->attrbuffer, d->width * d->height);
	memcpy(d->previoust, c->textbuffer, d->width * d->height);
	if (nrectangles[0])
	    XFillRectangles(d->dp, dr, d->blackGC, &rectangles(0, 0), nrectangles[0]);
	if (nrectangles[1])
	    XFillRectangles(d->dp, dr, d->normalGC, &rectangles(1, 0), nrectangles[1]);
	if (nrectangles[2])
	    XFillRectangles(d->dp, dr, d->specialGC, &rectangles(2, 0), nrectangles[2]);
	if (d->cvisible)
	    XDrawLine(d->dp, dr, d->normalGC, d->Xpos * d->realfontwidth, (d->Ypos + 1) * d->fontheight - 1, (d->Xpos + 1) * d->realfontwidth - 1, (d->Ypos + 1) * d->fontheight - 1);

	for (y = 0; y < d->height; y++) {
	    for (x = 0; x < NATT; x++) {
		if (nitem[y][x]) {
		    X_setattr(d,x);
		    XDrawText(d->dp, dr, d->currGC, 0, (y + 1) * d->fontheight - d->font_s->descent, &texty(y, x, 0), nitem[y][x]);
		    if (x == 4)
			XDrawText(d->dp, dr, d->currGC, 1, (y + 1) * d->fontheight - d->font_s->descent, &texty(y, x, 0), nitem[y][x]);
		}
	    }
	}
	if (d->pixmapmode) {
	    if (nrectangles[3] && area < d->width*d->height/2 && nrectangles[3] < 5)
	      {
		int i;
	        /*fprintf (stderr, "%i %i\n",nrectangles[3], area);*/
		for (i = 0; i < nrectangles[3]; i++)
		  XClearArea (d->dp, d->wi, rectangles(3, i).x, rectangles(3,i).y,
			      rectangles(3,i).width, rectangles(3,i).height, 0);
	      }
	    else
	      XClearWindow(d->dp, d->wi);
	}
	/*if(!d->pixmapmode) */
	XSync(d->dp, 0);
    }
    freetables();
}
コード例 #9
0
ファイル: liscur.c プロジェクト: smi13/semester06
void draw( Display *dsp, Drawable *win )
{
  GC gc = XCreateGC(dsp, *win, 0, NULL);     
  char Buf[100] = { 0 }, Buf1[100] = { 0 }, Buf2[100] = { 0 }, Buf3[100] = { 0 }, Buf4[100] = { 0 };

  XSetForeground(dsp, gc, black);
  XFillRectangle(dsp, *win, gc, 0, 0, 600, 800);

  XTextItem titem_time[] = { Buf, strlen(Buf), -3, None },
	    titem_bufx[] = { Buf1, strlen(Buf1), -3, None },
            titem_bufy[] = { Buf2, strlen(Buf2), -3, None },
	    titem_bufp[] = { Buf3, strlen(Buf3), -3, None },
	    titem_bufr[] = { Buf4, strlen(Buf4), -3, None };

  XSetBackground(dsp, gc, black);
  XSetForeground(dsp, gc, white);

  XImage *img = XGetImage(dsp, *win, 0, 100, img_width, img_height, AllPlanes, ZPixmap);

  /* The main part */
  drawing_time = getTime(); 
  fillbuf(img->data, img_width, img_height, img->bytes_per_line);
  drawing_time = getTime() - drawing_time;
  /*****************/

  XPutImage(dsp, *win, gc, img, 0, 0, 0, 100, 600, 600);

  sprintf(titem_time[0].chars, "Time: %llu\0", drawing_time);
  titem_time[0].nchars = strlen(titem_time[0].chars);


  switch (cur_renderer)
  {
  case C_RENDERER:
    sprintf(titem_bufr[0].chars, "Render type: C ");	  
    break;
  case ASM1_RENDERER:
    sprintf(titem_bufr[0].chars, "Render type: simple asm ");	  
    break;
  case ASM2_RENDERER:
    sprintf(titem_bufr[0].chars, "Render type: asm modified (2) ");	  
    break;
  }

  titem_bufr[0].nchars = strlen(titem_bufr[0].chars);

  sprintf(titem_bufx[0].chars, "X modifier: %i\0", x_modif);
  titem_bufx[0].nchars = strlen(titem_bufx[0].chars);
  
  sprintf(titem_bufy[0].chars, "Y modifier: %i\0", y_modif);
  titem_bufy[0].nchars = strlen(titem_bufy[0].chars);
  
  sprintf(titem_bufp[0].chars, "Number of points: %i\0", points_number);
  titem_bufp[0].nchars = strlen(titem_bufp[0].chars);

  XDrawText(dsp, *win, gc, 10, 30, titem_time, 1);
  XDrawText(dsp, *win, gc, 10, 50, titem_bufr, 1); 
  XDrawText(dsp, *win, gc, 450, 40, titem_bufx, 1);
  XDrawText(dsp, *win, gc, 450, 60, titem_bufy, 1);
  XDrawText(dsp, *win, gc, 450, 80, titem_bufp, 1);

  XFreeGC(dsp, gc);
}
コード例 #10
0
ファイル: allrequests.cpp プロジェクト: glegris/tiny-x-server
main()
{
      Window w2;

      Display *dpy = XOpenDisplay(NIL);
      assert(dpy);
      Screen *scr = DefaultScreenOfDisplay(dpy);

      // CreateWindow

      Window w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent,
			       CopyFromParent, CopyFromParent,
			       0, NIL);

      XDestroyWindow(dpy, w);

      // CreateWindow with arguments

      XSetWindowAttributes swa;
      swa.background_pixel = WhitePixelOfScreen(scr);
      swa.bit_gravity = NorthWestGravity;
      swa.border_pixel = BlackPixelOfScreen(scr);
      swa.colormap = DefaultColormapOfScreen(scr);
      swa.cursor = None;
      swa.win_gravity = NorthGravity;

      w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent,
			CopyFromParent, CopyFromParent,
			CWBackPixel | CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWWinGravity, 
			&swa);
      
      // CreateWindow with other arguments

      XDestroyWindow(dpy, w);

      Pixmap pixmap = XCreatePixmap(dpy, RootWindowOfScreen(scr), 45, 25, DefaultDepthOfScreen(scr));
      assert(pixmap);

      swa.background_pixmap = pixmap;
      swa.border_pixmap = pixmap;

      w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent,
			CopyFromParent, CopyFromParent,
			CWBackPixmap | CWBorderPixmap,
			&swa);
      
      // ChangeWindowAttributes

      swa.backing_planes = 0x1;
      swa.backing_pixel = WhitePixelOfScreen(scr);
      swa.save_under = True;
      swa.event_mask = KeyPressMask | KeyReleaseMask;
      swa.do_not_propagate_mask = ButtonPressMask | Button4MotionMask;
      swa.override_redirect = False;
      XChangeWindowAttributes(dpy, w, CWBackingPlanes | CWBackingPixel | CWSaveUnder | CWEventMask
			      | CWDontPropagate | CWOverrideRedirect, &swa);

      // GetWindowAttributes

      XWindowAttributes wa;
      Status success = XGetWindowAttributes(dpy, w, &wa);

      // DestroyWindow (done)

      // DestroySubwindows

      w2 = XCreateWindow(dpy, w, 20, 30, 40, 50, 3, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL);
      XDestroySubwindows(dpy, w);

      // ChangeSaveSet

//        Display *dpy2 = XOpenDisplay(NIL);
//        assert(dpy2);
//        XAddToSaveSet(dpy2, w);
//        XCloseDisplay(dpy2);

      // ReparentWindow

      w2 = XCreateWindow(dpy, RootWindowOfScreen(scr), 20, 30, 40, 50, 3, 
			 CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL);
      XReparentWindow(dpy, w2, w, 10, 5);

      // MapWindow

      XMapWindow(dpy, w);

      // MapSubwindows
      
      XMapSubwindows(dpy, w);

      // UnmapWindow
      
      XUnmapWindow(dpy, w);

      // UnmapSubwindows

      XMapWindow(dpy, w);
      XUnmapSubwindows(dpy, w2);
      XMapSubwindows(dpy, w);

      // ConfigureWindow

      Window w3 = XCreateWindow(dpy, w, 10, 50, 100, 10, 2,
			 CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL);

      XMapWindow(dpy, w3);

      XWindowChanges wc;
      wc.x = -5;
      wc.y = -10;
      wc.width = 50;
      wc.height = 40;
      wc.border_width = 7;
      wc.sibling = w2;
      wc.stack_mode = Opposite;
      XConfigureWindow(dpy, w3, 
		       CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWSibling | CWStackMode, 
		       &wc);

      // CirculateWindow

      XCirculateSubwindows(dpy, w, RaiseLowest);

      // GetGeometry

      Window root;
      int x, y;
      unsigned width, height, border_width, depth;
      XGetGeometry(dpy, w, &root, &x, &y, &width, &height, &border_width, &depth);

      // QueryTree

      Window parent;
      Window *children;
      unsigned nchildren;
      success = XQueryTree(dpy, w, &root, &parent, &children, &nchildren);
      XFree(children);

      // InternAtom

      Atom a = XInternAtom(dpy, "WM_PROTOCOLS", True);

      // GetAtomName

      char *string = XGetAtomName(dpy, XA_PRIMARY);
      XFree(string);

      // ChangeProperty

      XStoreName(dpy, w, "test window");

      // DeleteProperty

      XDeleteProperty(dpy, w, XA_WM_NAME);

      // GetProperty
      // TODO

      // ListProperties

      int num_prop;
      Atom *list = XListProperties(dpy, w, &num_prop);
      XFree(list);

      // SetSelectionOwner

      XSetSelectionOwner(dpy, XA_PRIMARY, w, 12000);
      XSetSelectionOwner(dpy, XA_SECONDARY, w, CurrentTime);

      // GetSelectionOwner

      Window wx = XGetSelectionOwner(dpy, XA_PRIMARY);

      // ConvertSelection

      XConvertSelection(dpy, XA_SECONDARY, XA_CURSOR, XA_POINT, w, CurrentTime);

      // SendEvent

      // GrabPointer

      std::cerr << "Grabbing" << std::endl;
      int res = XGrabPointer(dpy, w, False, Button5MotionMask | PointerMotionHintMask,
			     GrabModeSync, GrabModeAsync, w, None, CurrentTime);
      XSync(dpy, False);
//      sleep(5);

      // UngrabPointer

      std::cerr << "Ungrabbing" << std::endl;
      XUngrabPointer(dpy, CurrentTime);

      // GrabButton

      XGrabButton(dpy, 3, ShiftMask | ControlMask, w, False, PointerMotionHintMask | Button2MotionMask, 
		  GrabModeAsync, GrabModeSync, None, None);
		  
      XGrabButton(dpy, 2, AnyModifier, w, False, PointerMotionHintMask | Button2MotionMask, 
		  GrabModeAsync, GrabModeSync, None, None);
		  
      // UngrabButton

      XUngrabButton(dpy, 2, LockMask, w);

      // ChangeActivePointerGrab

      XChangeActivePointerGrab(dpy, ButtonPressMask, None, CurrentTime);

      // GrabKeyboard

      XGrabKeyboard(dpy, w, True, GrabModeSync, GrabModeSync, 12000);

      // UngrabKeyboard

      XUngrabKeyboard(dpy, 13000);

      // GrabKey

      XGrabKey(dpy, XKeysymToKeycode(dpy, XK_Tab), ShiftMask | Mod3Mask, w, True, GrabModeSync,
	       GrabModeSync);

      // UngrabKey

      XUngrabKey(dpy, AnyKey, AnyModifier, w);

      // AllowEvents

      XAllowEvents(dpy, AsyncPointer, 14000);

      // GrabServer

      XGrabServer(dpy);

      // UngrabServer

      XUngrabServer(dpy);

      // QueryPointer

      Window child;
      int root_x, root_y, win_x, win_y;
      unsigned mask;
      Bool bres = XQueryPointer(dpy, w, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask);

      // GetMotionEvents

      int nevents;
      XGetMotionEvents(dpy, w, 15000, 16000, &nevents);

      // TranslateCoordinates

      int dest_x, dest_y;

      XTranslateCoordinates(dpy, w, w2, 10, 20, &dest_x, &dest_y, &child);

      // WarpPointer

      XWarpPointer(dpy, w, w2, 0, 0, 100, 100, 20, 30);

      // SetInputFocus

      XSetInputFocus(dpy,w, RevertToPointerRoot, 17000);
      XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, 17000);

      // GetInputFocus

      Window focus;
      int revert_to;
      XGetInputFocus(dpy, &focus, &revert_to);

      // QueryKeymap

      char keys_return[32];
      XQueryKeymap(dpy, keys_return);

      // OpenFont

      Font fid = XLoadFont(dpy, "cursor");

      // CloseFont

      XUnloadFont(dpy, fid);

      // QueryFont

      XFontStruct *fs = XLoadQueryFont(dpy, "cursor");
      assert(fs);

      // QueryTextExtents

      int direction, font_ascent, font_descent;
      XCharStruct overall;
      XQueryTextExtents(dpy, fs -> fid, "toto", 4, &direction, &font_ascent, &font_descent, &overall);
      XQueryTextExtents(dpy, fs -> fid, "odd__length", 11, &direction, &font_ascent, &font_descent, &overall);

      XChar2b c2bs;
      c2bs.byte1 = '$';
      c2bs.byte2 = 'B';
      XQueryTextExtents16(dpy, fs -> fid, &c2bs, 1, &direction, &font_ascent, &font_descent, &overall);

      XQueryTextExtents(dpy, fs -> fid, longString, strlen(longString), &direction, &font_ascent, 
			&font_descent, &overall);

      // ListFonts

      int actual_count;
      char **fontList = XListFonts(dpy, "*", 100, &actual_count);
      XFree((char *)fontList);

      // ListFontsWithInfo

      int count;
      XFontStruct *info;
      char **names = XListFontsWithInfo(dpy, "*", 100, &count, &info);
      XFreeFontInfo(names, info, count);

      // SetFontPath
      // GetFontPath

      int npaths;
      char **charList = XGetFontPath(dpy, &npaths);

      char **charList2 = new char *[npaths + 1];
      memcpy(charList2, charList, npaths * sizeof(char *));
      charList2[npaths] = charList2[0];

      XSetFontPath(dpy, charList2, npaths + 1);
      XSetFontPath(dpy, charList, npaths); // Reset to some reasonnable value

      XFreeFontPath(charList);
      delete [] charList2;

      // CreatePixmap

      Pixmap pix2 = XCreatePixmap(dpy, w, 100, 200, DefaultDepthOfScreen(scr));

      // FreePixmap

      XFreePixmap(dpy, pix2);

      // CreateGC

      Pixmap bitmap = XCreateBitmapFromData(dpy, RootWindowOfScreen(scr), 
					    "\000\000\001\000\000\001\000\000\001\377\377\377", 3, 4);

      XGCValues gcv;
      gcv.function = GXand;
      gcv.plane_mask = 0x1;
      gcv.foreground = WhitePixelOfScreen(scr);
      gcv.background = BlackPixelOfScreen(scr);
      gcv.line_width = 2;
      gcv.line_style = LineDoubleDash;
      gcv.cap_style = CapProjecting;
      gcv.join_style = JoinRound;
      gcv.fill_style = FillStippled;
      gcv.fill_rule = EvenOddRule;
      gcv.arc_mode = ArcPieSlice;
      gcv.tile = pixmap;
      gcv.stipple = bitmap;
      gcv.ts_x_origin = 3;
      gcv.ts_y_origin = 4;
      gcv.font = fs -> fid;
      gcv.subwindow_mode = ClipByChildren;
      gcv.graphics_exposures = True;
      gcv.clip_x_origin = 5;
      gcv.clip_y_origin = 6;
      gcv.clip_mask = bitmap;
      gcv.dash_offset = 1;
      gcv.dashes = 0xc2;
      
      GC gc = XCreateGC(dpy, w, 
			  GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineWidth
			| GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle | GCFillRule | GCTile
			| GCStipple | GCTileStipXOrigin | GCTileStipYOrigin | GCFont | GCSubwindowMode
			| GCGraphicsExposures | GCClipXOrigin | GCClipYOrigin | GCClipMask | GCDashOffset
			| GCDashList | GCArcMode,
			&gcv);

      // ChangeGC

      gcv.function = GXandReverse;

      // Only a few of these should appear, since the values are cached on the client side by the Xlib.

      XChangeGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, &gcv);

      // CopyGC
      
      GC gc2 = XCreateGC(dpy, w, 0, NIL);
      XCopyGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, gc2);

      // SetDashes

      XSetDashes(dpy, gc, 3, "\001\377\001", 3);

      // SetClipRectangles

      XRectangle rectangles[] = { { 10, 20, 30, 40 }, { 100, 200, 5, 3 }, { -5, 1, 12, 24 } };
      XSetClipRectangles(dpy, gc, 12, 9, rectangles, SIZEOF(rectangles), Unsorted);

      // FreeGC

	    // done already

      // ClearArea

      XClearArea(dpy, w, 30, 10, 10, 100, False);

      // CopyArea

      XCopyArea(dpy, w, pixmap, gc, 0, 0, 100, 100, 10, 10);

      // CopyPlane

      // This won't work if the Screen doesn't have at least 3 planes
      XCopyPlane(dpy, pixmap, w, gc, 20, 10, 40, 30, 0, 0, 0x4);

      // PolyPoint

      XDrawPoint(dpy, w, gc, 1, 2);

      XPoint points[] = { { 3, 4 }, { 5, 6 } };
      XDrawPoints(dpy, w, gc, points, SIZEOF(points), CoordModeOrigin);

      // PolyLine

      XDrawLines(dpy, w, gc, points, SIZEOF(points), CoordModePrevious);

      // PolySegment

      XSegment segments[] = { { 7, 8, 9, 10 }, { 11, 12, 13, 14 }, { 15, 16, 17, 18 } };
      XDrawSegments(dpy, w, gc, segments, SIZEOF(segments));

      // PolyRectangle

      XDrawRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles));

      // PolyArc

      XArc arcs[] = { { 10, 20, 30, 40, 50, 60 }, { -70, 80, 90, 100, 110, 120 }, 
		      { 10, 20, 30, 40, 50, -30 } };

      XDrawArcs(dpy, w, gc, arcs, SIZEOF(arcs));

      // FillPoly

      XFillPolygon(dpy, w, gc, points, SIZEOF(points), Convex, CoordModePrevious);

      // PolyFillRectangle
      
      XFillRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles));

      // PolyFillArc
      
      XFillArcs(dpy, w, gc, arcs, SIZEOF(arcs));

      // PutImage
      // GetImage

      XImage *image = XGetImage(dpy, w, 10, 20, 40, 30, AllPlanes, ZPixmap);
      XPutImage(dpy, w, gc, image, 0, 0, 50, 60, 40, 30);
      XSync(dpy, False); // Make the next request starts at the beginning of a packet

      // PolyText8
      XTextItem textItems[3];
      textItems[0].chars = "toto";
      textItems[0].nchars = strlen(textItems[0].chars);
      textItems[0].delta = -3;
      textItems[0].font = fs->fid;
      textItems[1].chars = "titi";
      textItems[1].nchars = strlen(textItems[1].chars);
      textItems[1].delta = 3;
      textItems[1].font = None;
      textItems[2].chars = "tutu";
      textItems[2].nchars = strlen(textItems[2].chars);
      textItems[2].delta = 0;
      textItems[2].font = fs->fid;

      XDrawText(dpy, w, gc, 10, 10, textItems, 3);


      XTextItem textItems2[3];
      textItems2[0].chars = "totox";
      textItems2[0].nchars = strlen(textItems2[0].chars);
      textItems2[0].delta = -3;
      textItems2[0].font = fs->fid;
      textItems2[1].chars = "titi";
      textItems2[1].nchars = strlen(textItems2[1].chars);
      textItems2[1].delta = 3;
      textItems2[1].font = None;
      textItems2[2].chars = "tutu";
      textItems2[2].nchars = strlen(textItems2[2].chars);
      textItems2[2].delta = 0;
      textItems2[2].font = fs->fid;

      XDrawText(dpy, w, gc, 10, 10, textItems2, 3);

      // PolyText16

      XChar2b c2b2[] = { 0, 't', 0, 'x' };

      XTextItem16 items16[] = { { &c2bs, 1, -5, None }, { NULL, 0, 0, None }, { c2b2, 2, 0, fs -> fid } };
      XDrawText16(dpy, w, gc, 10, 0, items16, SIZEOF(items16));

      // ImageText8

      XDrawImageString(dpy, w, gc, 10, 10, "toto", 4);

      // ImageText16

      XDrawImageString16(dpy, w, gc, 10, 10, &c2bs, 1);
      XDrawImageString16(dpy, w, gc, 10, 20, c2b2, 2);

      // CreateColormap
      // Don't forget to tell the kids how it was when we had only 8 bits per pixel.

      Colormap colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None);

      // FreeColormap

      XFreeColormap(dpy, colormap);
      colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None);

      // CopyColormapAndFree

      Colormap colormap2 = XCopyColormapAndFree(dpy, colormap);

      // InstallColormap

      XInstallColormap(dpy, colormap2);

      // UninstallColormap

      XUninstallColormap(dpy, colormap2);

      // ListInstalledColormaps

      int num;
      Colormap *colormapList = XListInstalledColormaps(dpy, w, &num);

      // AllocColor

      XColor screen;
      screen.red = 0;
      screen.green = 32767;
      screen.blue = 65535;
      screen.flags = DoRed | DoGreen | DoBlue;
      success = XAllocColor(dpy, colormap, &screen);

      // AllocNamedColor

      XColor screen2, exact;
      success = XAllocNamedColor(dpy, colormap, "Wheat", &screen2, &exact);

      // AllocColorCells

      unsigned long plane_masks, pixels;
      success = XAllocColorCells(dpy, colormap, False, &plane_masks, 1, &pixels, 1);

      // AllocColorPlanes

      unsigned long rmask, gmask, bmask;
      success = XAllocColorPlanes(dpy, colormap, False, &pixels, 1, 0, 0, 0, &rmask, &gmask, &bmask);

      // FreeColors

      unsigned long pixels2[2] = { screen.pixel, screen2.pixel };
      XFreeColors(dpy, colormap, pixels2, 2, 0);

      // StoreColors

      success = XAllocColorCells(dpy, colormap, False, NIL, 0, pixels2, 2);

      // On many contemporary (that is, year 2000) video cards, you can't allocate read / write cells
      // I want my requests to be sent, however.
      if (!success) {
	    XSetErrorHandler(errorHandler);
      }

      XColor colors[2];
      colors[0] = screen;  colors[0].pixel = pixels2[0];
      colors[1] = screen2; colors[1].pixel = pixels2[1];
      XStoreColors(dpy, colormap, colors, 2);

      // StoreNamedColor

      XStoreNamedColor(dpy, colormap, "Wheat", colors[0].pixel, DoBlue);

      XSync(dpy, False);
      XSetErrorHandler(NIL); // Restore the default handler

      // QueryColors

      screen2.pixel = WhitePixelOfScreen(scr);
      XQueryColor(dpy, colormap, &screen2);

      // LookupColor

      success = XLookupColor(dpy, colormap, "DarkCyan", &exact, &screen);

      // CreateCursor

      Cursor cursor = XCreatePixmapCursor(dpy, pixmap, None, &exact, colors, 10, 10);

      // CreateGlyphCursor
      
      Cursor cursor2 = XCreateGlyphCursor(dpy, fs -> fid, fs -> fid, 'X', 0, &exact, colors);

      // FreeCursor
      
      XFreeCursor(dpy, cursor2);

      // RecolorCursor

      XRecolorCursor(dpy, cursor, colors, &exact);

      // QueryBestSize

      success = XQueryBestSize(dpy, CursorShape, RootWindowOfScreen(scr), 100, 20, &width, &height);

      // QueryExtension

      int major_opcode, first_event, first_error;
      XQueryExtension(dpy, "toto", &major_opcode, &first_event, &first_error);

      // ListExtensions

      int nextensions;
      char **extensionList = XListExtensions(dpy, &nextensions);
      for(char **p = extensionList; nextensions; nextensions--, p++) std::cout << *p << std::endl;
      XFree(extensionList);

      // ChangeKeyboardMapping
      // GetKeyboardMapping

      int min_keycodes, max_keycodes;
      XDisplayKeycodes(dpy, &min_keycodes, &max_keycodes);

      int keysyms_per_keycode;
      KeySym *keysyms = XGetKeyboardMapping(dpy, min_keycodes, max_keycodes - min_keycodes + 1,
					    &keysyms_per_keycode);
      XChangeKeyboardMapping(dpy, min_keycodes, keysyms_per_keycode, keysyms, 
			     max_keycodes - min_keycodes + 1);

      // ChangeKeyboardControl
      // GetKeyboardControl

      XKeyboardState keyboardState;
      XGetKeyboardControl(dpy, &keyboardState);

      XKeyboardControl keyboardValues;
      keyboardValues.key_click_percent = keyboardState.key_click_percent;
      keyboardValues.bell_percent = keyboardState.bell_percent;
      keyboardValues.bell_pitch = keyboardState.bell_pitch;
      keyboardValues.bell_duration = keyboardState.bell_duration;
      keyboardValues.led = 1;
      keyboardValues.led_mode = LedModeOn;
      keyboardValues.key = min_keycodes;
      keyboardValues.auto_repeat_mode = AutoRepeatModeDefault;
      XChangeKeyboardControl(dpy, 
			       KBKeyClickPercent | KBBellPercent | KBBellPitch | KBBellDuration
			     | KBLed | KBLedMode | KBKey | KBAutoRepeatMode,
			     &keyboardValues);

      // Bell

      XBell(dpy, 90);

      // ChangePointerControl
      // GetPointerControl

      int accel_numerator, accel_denominator, threshold;
      XGetPointerControl(dpy, &accel_numerator, &accel_denominator, &threshold);

      XChangePointerControl(dpy, True, True, accel_numerator, accel_denominator, threshold);

      // SetScreenSaver
      // GetScreenSaver

      int timeout, interval, prefer_blanking, allow_exposures;
      XGetScreenSaver(dpy, &timeout, &interval, &prefer_blanking, &allow_exposures);
      XSetScreenSaver(dpy, timeout, interval, prefer_blanking, allow_exposures);

      // ChangeHosts
      // ListHosts

      int nhosts;
      Bool state;
      XHostAddress *hostList = XListHosts(dpy, &nhosts, &state);

      XHostAddress host;
      host.family = FamilyInternet;
      host.length = 4;
      host.address = "\001\002\003\004";
      XAddHost(dpy, &host);

      // SetAccessControl

      XSetAccessControl(dpy, EnableAccess);

      // SetCloseDownMode

      XSetCloseDownMode(dpy, RetainTemporary);

      // KillClient

      XKillClient(dpy, AllTemporary);

      // RotateProperties

      Atom properties[] = { XInternAtom(dpy, "CUT_BUFFER0", False), 
			    XInternAtom(dpy, "CUT_BUFFER1", False),
			    XInternAtom(dpy, "CUT_BUFFER2", False) };
      XRotateWindowProperties(dpy, RootWindowOfScreen(scr), properties, SIZEOF(properties), -1);

      // ForceScreenSaver

      XForceScreenSaver(dpy, ScreenSaverReset);

      // SetPointerMapping
      // GetPointerMapping

      unsigned char map[64];
      int map_length = XGetPointerMapping(dpy, map, 64);
      XSetPointerMapping(dpy, map, map_length);

      // SetModifierMapping
      // GetModifierMapping

      XModifierKeymap *modmap = XGetModifierMapping(dpy);
      XSetModifierMapping(dpy, modmap);

      // NoOperation

      XNoOp(dpy);

      for(;;) {
	    XEvent e;
	    XNextEvent(dpy, &e);
	    std::cout << "Got an event of type " << e.type << std::endl;
      }
}
コード例 #11
0
ファイル: exii-calibrator.c プロジェクト: arfrank/EXII-Tool
int main(int argc, char *argv[]) {

    MwmHints hints;
    XWindowChanges chg;
    Display *dpy = XOpenDisplay(NULL);
    XEvent e;
    assert(dpy);
    char reply[32];

    int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
    int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
    int color[2] = { whiteColor, whiteColor };
    int fds[2], seq = 0, n, status, update = 0;
    char message[] = "Push the center of aim 1 and 2 for 2 seconds or press Esc";
    fd_set rd;
    pid_t pid;
    struct timeval tv;
    XTextItem text = { message, sizeof(message) - 1, 5, None };

    if (argc < 2) {
        printf("Usage: %s <device>\n", argv[0]);
        return 0;
    }

    if (pipe(fds) < 0) {
        perror("pipe");
        return -1;
    }
    if ((pid = fork()) < 0) {
        perror("fork");
        return -1;
    }
    if (pid) {
        close(fds[1]);
        Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,
                                       400, 400, 0, blackColor, blackColor);

        hints.flags = MWM_HINTS_DECORATIONS;
        hints.decorations = MWM_DECOR_NONE;
        Atom props = XInternAtom(dpy, "_MOTIF_WM_HINTS", True);
        XChangeProperty(dpy, w, props, props, 32, PropModeReplace,
                        (unsigned char *)&hints, MWM_HINTS_ELEMENTS);

        XMapWindow(dpy, w);

        memset(&chg, 0, sizeof(chg));
        chg.x = chg.y = 0;
        chg.width = DisplayWidth(dpy, 0);
        chg.height = DisplayHeight(dpy, 0);
        chg.stack_mode = TopIf;

        XConfigureWindow(dpy, w, CWX | CWY | CWWidth | CWHeight | CWStackMode, &chg);

        GC gc = XCreateGC(dpy, w, 0, NULL);
        XSetForeground(dpy, gc, whiteColor);

        XSelectInput(dpy, w, StructureNotifyMask | VisibilityChangeMask | KeyPressMask);

        while (seq < 3) {

            FD_ZERO(&rd);
            FD_SET(fds[0], &rd);
            tv.tv_sec = 0;
            tv.tv_usec = 100;
            waitpid(pid, &status, WNOHANG);
            if (WIFEXITED(status))
                break;
            if (select(fds[1] + 1, &rd, NULL, NULL, &tv) < 0)
                perror("select");
            if (FD_ISSET(fds[0], &rd)) {
                if ((n = read(fds[0], &reply, sizeof(reply))) == -1)
                    perror("pipe read");
                if (n > 0)
                    switch (seq) {
                    case 0:
                        if (reply[0] == '0')
                            seq++;
                        else
                            seq = 3;
                        break;
                    case 1:
                        if (reply[0] == '1') {
                            seq++;
                            color[0] = blackColor;
                            update = 1;
                        } else
                            seq = 3;
                        break;
                    case 2:
                        if (reply[0] == '1') {
                            seq++;
                            color[1] = blackColor;
                            update = 1;
                        } else
                            seq = 3;
                        break;
                    }
            }
            memset(&e, 0, sizeof(XEvent));
            if (XPending(dpy)) {

                XNextEvent(dpy, &e);
                if (e.type == KeyPress && e.xkey.keycode == 9)
                    break;
            }
            if (update
                    || e.type == MapNotify
                    || e.type == VisibilityNotify
                    || e.type == ConfigureNotify || e.type == KeyPress) {
                XSetForeground(dpy, gc, whiteColor);
                DrawAim(dpy, w, gc, chg.width / 8,
                        chg.height * 7 / 8, '1', color[0]);
                DrawAim(dpy, w, gc, chg.width * 7 / 8,
                        chg.height / 8, '2', color[1]);
                XSetForeground(dpy, gc, whiteColor);
                XDrawText(dpy, w, gc,
                          chg.width / 2 - 200, chg.height / 2, &text, 1);
                XFlush(dpy);
                update = 0;
            }
            usleep(1000);
        }
    } else {
        close(fds[0]);
        close(1);
        if (dup2(fds[1], 1) < 0) {
            perror("dup2");
            return -1;
        }
        if (execlp("exii-tool", "exii-tool", argv[1], "CX", NULL) < 0)
            perror("execl");
    }
    return 0;
}
コード例 #12
0
ファイル: xmarquee.c プロジェクト: zhemao/hodgepodge
int main(int argc, char *argv[]){
	XTextItem textItem;
	int whiteColor, blackColor, color;
	int speed = 5;
	char opt;

	textItem.delta = 0;
	textItem.font = None;

	display = XOpenDisplay(NULL);
	
	if(display == NULL){
		fprintf(stderr, "Failed to open display.\n");
		exit(EXIT_FAILURE);
	}

	width = DisplayWidth(display, DefaultScreen(display));
	height = DisplayHeight(display, DefaultScreen(display));

	whiteColor = WhitePixel(display, DefaultScreen(display));
	blackColor = BlackPixel(display, DefaultScreen(display));
	color = whiteColor;

	while((opt = getopt(argc, argv, "wbs:")) != -1){
		switch(opt){
		case 'w':
			color = whiteColor;
			break;
		case 'b':
			color = blackColor;
			break;
		case 's':
			speed = atoi(optarg);
			break;
		default:
			fprintf(stderr, "Unrecognized option: %c", opt);
			XCloseDisplay(display);
			exit(EXIT_FAILURE);
		}
	}

	if(optind >= argc){
		fprintf(stderr, "Usage: %s [options] command\n", argv[0]);
		XCloseDisplay(display);
		exit(EXIT_FAILURE);
	}

	window = DefaultRootWindow(display);

	signal(SIGINT, cleanup);
	
	gc = XCreateGC(display, window, 0, NULL);
	
	XSetForeground(display, gc, color);

	x = 0;
	y = height / 2;

	for(;;){ 
		clearScreen();
		
		textItem.chars = argv[optind];
		textItem.nchars = strlen(argv[optind]);
		XDrawText(display, window, gc, x, y, &textItem, 1);

		x += speed;

		if(x > width) x = 0;
		
		XFlush(display);
		usleep(10000); 
	}

	cleanup(SIGINT);

	return 0;
}