/** * Example code file for xcb_lock.c error * Gunnar Besdo * E-mail: gunnar@besdo.de **/ #include #include #include #include #include int gb_thread_ret=0, gb_aus=0, gb_aus2=0, gb_screen_nr; pthread_t gb_pthread; Window gb_window, gb_rootw; Display *gb_display; XSetWindowAttributes gb_xswa; GC gb_gc; XGCValues gb_gcv; unsigned long *gb_pixdefcol; Colormap gb_colormap; unsigned long gbs_XW_GetColor(double r, double g, double b) { Colormap cmap; XColor exact_def; cmap=DefaultColormap(gb_display, gb_screen_nr); exact_def.red=(unsigned short)(r*65535); exact_def.green=(unsigned short)(g*65535); exact_def.blue=(unsigned short)(b*65535); if (!XAllocColor(gb_display, cmap, &exact_def)) { fprintf(stderr, "%s:Error in XAllocColor\n", "xcb_Test"); exit(0); } return(exact_def.pixel); } void *gb_thread(void *a) { static XEvent x_event; int ih1; printf("Test OK\n"); gb_pixdefcol=(unsigned long*) malloc(sizeof(long)*256); gb_display=XOpenDisplay(NULL); gb_screen_nr=XDefaultScreen(gb_display); gb_rootw=RootWindow(gb_display, gb_screen_nr); gb_xswa.event_mask=0x1FBFFFF; gb_xswa.override_redirect=False; gb_xswa.backing_store=1; gb_window=XCreateWindow(gb_display,gb_rootw,0,0,640,400,0, DefaultDepth(gb_display, gb_screen_nr), InputOutput, XDefaultVisual(gb_display, gb_screen_nr), CWEventMask|CWOverrideRedirect|CWBackingStore, &gb_xswa); gb_gcv.foreground=BlackPixel(gb_display, gb_screen_nr); gb_gcv.background=WhitePixel(gb_display, gb_screen_nr); gb_gc=XCreateGC(gb_display,gb_rootw,GCForeground | GCBackground, &gb_gcv); gb_colormap = DefaultColormap(gb_display, gb_screen_nr); gb_pixdefcol[ 0]=gbs_XW_GetColor( 1.0, 1.0, 1.0); /* Farbe 0: weiss */ gb_pixdefcol[ 1]=gbs_XW_GetColor( 0.0, 0.0, 0.0); /* Farbe 1: schwarz */ gb_pixdefcol[ 2]=gbs_XW_GetColor( 1.0, 0.0, 0.0); /* Farbe 2: rot */ gb_pixdefcol[ 3]=gbs_XW_GetColor( 0.0, 0.7, 0.0); /* Farbe 3: gruen */ gb_pixdefcol[ 4]=gbs_XW_GetColor( 0.0, 0.0, 1.0); /* Farbe 4: blau */ gb_pixdefcol[ 5]=gbs_XW_GetColor( 0.0, 1.0, 1.0); /* Farbe 5: cyan */ gb_pixdefcol[ 6]=gbs_XW_GetColor( 1.0, 1.0, 0.0); /* Farbe 6: gelb */ gb_pixdefcol[ 7]=gbs_XW_GetColor( 1.0, 0.0, 1.0); /* Farbe 7: magenta */ gb_pixdefcol[ 9]=gbs_XW_GetColor( 0.5, 0.5, 0.5); /* Farbe 9: dunkelgrau*/ gb_pixdefcol[ 8]=gbs_XW_GetColor( 0.8, 0.8, 0.8); /* Farbe 8: hellgrau */ gb_pixdefcol[10]=gbs_XW_GetColor( 1.0, 0.5, 0.5); /* Farbe 10: hellrot */ XSetWindowColormap(gb_display, gb_window, gb_colormap); XMapWindow(gb_display, gb_window); XNextEvent(gb_display, &x_event); ih1=0; while(ih1==0) { switch (x_event.type) { case KeyPress: printf("x_event.type=%d ",x_event.type); printf("KeyPress "); if ((x_event.xkey.keycode==24)&&(x_event.xkey.state==1)) { ih1=1; gb_aus=-1; } printf("x_event.xkey.keycode=%d ",x_event.xkey.keycode); printf("x_event.xkey.state=%d ",x_event.xkey.state); printf("\n"); break; case KeyRelease: printf("x_event.type=%d ",x_event.type); printf("KeyRelease "); gb_aus++; if (gb_aus>10) gb_aus=0; printf("\n"); break; } XNextEvent(gb_display, &x_event); } pthread_exit(a); } int main(int argv, char *argc[], char *env[]) { int rc; void *res; XPoint *xpp; int ih1, ih2; rc=pthread_create(&gb_pthread,NULL, gb_thread, (void*)&gb_thread_ret); printf("rc=%d\n",rc); xpp=(XPoint*) malloc(2000*sizeof(XPoint)); for (ih2=0; ih2<640; ih2++) xpp[ih2].x=ih2; while(gb_aus>-1) { sleep(1); if (gb_aus!=gb_aus2) { gb_aus2++; if (gb_aus2>10) gb_aus2=0; XSetForeground(gb_display, gb_gc, gb_pixdefcol[gb_aus2]); for (ih1=0; ih1<400; ih1++) { for (ih2=0; ih2<640; ih2++) xpp[ih2].y=ih1; XDrawPoints(gb_display,gb_window, gb_gc,&xpp[0],640,CoordModeOrigin); } } } rc=pthread_join(gb_pthread, res); free(res); sleep(1); XDestroyWindow(gb_display, gb_window); printf("rc=%d\n",rc); return(0); }