linux user group brescia

immagine del castello

Archivio della mailing list

R: Programmare X

Luca Giuzzi giuzzi a dmf.bs.unicatt.it
Ven 5 Gen 2001 15:10:41 UTC
Ecco un esempio di programmillo per aprire una finestra e disegnare 3 linee
 usando solo la libX11... buon divertimento!      
 [nota: il programma le finestre non le chiude... free the malloc!]     
Ciao,
 lg

#include<stdio.h>
#include<X11/Xlib.h>
Display *disp;
Window root, win;
GC gc;
XSetWindowAttributes *attr;
int set;
XGCValues *val;
int
main ()
{
  disp = XOpenDisplay (NULL);
  root = XDefaultRootWindow (disp);
  win = XCreateSimpleWindow (disp, root, 0, 0, 100, 100, 0x10L, 0x03L, 0x0cL);
  attr = (XSetWindowAttributes *) malloc (sizeof (XSetWindowAttributes));
  attr->backing_store = Always;
  XChangeWindowAttributes (disp, win, CWBackingStore, attr);
  free(attr);
  val = (XGCValues *) malloc (sizeof (XGCValues));
  val->line_style = LineSolid;
  val->line_width = 0x3;
  val->foreground = 0x2L;
  val->background = 0x3L;
  val->function = GXset;
  val->plane_mask = AllPlanes;
  set = GCFunction | GCLineStyle | GCLineWidth | GCForeground | GCBackground;
  set |= GCPlaneMask;
  gc = XCreateGC (disp, win, set, val);
  printf ("\nRoot window id=0x%x\n", root);
  printf ("New window id=0x%x\n", win);
  XMapWindow (disp, win);
  XSync (disp, False);
  XSync (disp, False);
  XRaiseWindow (disp, win);
  printf ("...\n");
  XDrawLine (disp, win, gc, 0, 0, 50, 50);
  XDrawLine (disp, win, gc, 100, 50, 50, 100);
  XDrawLine (disp, win, gc, 0, 100, 100, 0);
  XSync (disp, False);
  for (;;);
}



Maggiori informazioni sulla lista Lug