#include #include #include #include #include "lx.h" #define INTERVAL 100000 #define LINESTEP 13 typedef unsigned long long int TIME; static int bid; static LX_CONN *xc; static LX_XID root; static int depth; static LX_XID win; static LX_XID visual; static LX_XID cmap; static unsigned int pixv[8]; static LX_XID gc; static LX_XID pm; static TIME exp; static int x; static int pixx; static LX_ACCESSCONTROL accctl; static LX_HOSTLIST *hl; static LX_STRLIST *exts; static TIME now_time(void) { struct timeval tv; gettimeofday(&tv,0); return((tv.tv_sec*1000000ULL)+tv.tv_usec); } static void one_tick(void) { LX_SEGMENT seg; seg.x1 = 0; seg.y1 = 0; seg.x2 = x; seg.y2 = 255; lx_PolySegment(xc,win,gc,1,&seg); x = (x + LINESTEP) & 255; if (x == 0) { pixx = (pixx + 1) & 7; lx_ChangeGC(xc,gc,LX_GCV_Foreground(pixv[pixx]),LX_GCV_END); } } static int tick(void *arg __attribute__((__unused__))) { TIME now; int d; now = now_time(); if (now < exp) { d = (exp - now) / 1000; if (d < 1) d = 1; return(d); } exp += INTERVAL; one_tick(); return(AIO_BLOCK_LOOP); } static void startup3(void *arg __attribute__((__unused__))) { LX_POINT pt[2]; gc = lx_CreateGC(xc,root,LX_GCV_Foreground(pixv[0]),LX_GCV_END); printf("gc = %08lx\n",(unsigned long int)gc); pm = lx_CreatePixmap(xc,root,depth,2,2); printf("pm = %08lx\n",(unsigned long int)pm); pt[0].x = 0; pt[0].y = 0; pt[1].x = 1; pt[1].y = 1; lx_PolyPoint(xc,pm,gc,LX_COORDMODE_Origin,2,&pt[0]); lx_ChangeGC(xc,gc,LX_GCV_Foreground(pixv[7]),LX_GCV_END); pt[0].x = 0; pt[0].y = 1; pt[1].x = 1; pt[1].y = 0; lx_PolyPoint(xc,pm,gc,LX_COORDMODE_Origin,2,&pt[0]); win = lx_CreateWindow( xc, root, 100, 100, 256, 256, 1, depth, LX_WCLASS_InputOutput, visual, LX_CWV_BackPixmap(pm), LX_CWV_BorderPixel(pixv[7]), LX_CWV_EventMask( LX_EM_KeyPress | LX_EM_KeyRelease | LX_EM_ButtonPress | LX_EM_ButtonRelease | LX_EM_EnterWindow | LX_EM_LeaveWindow | LX_EM_Exposure), LX_CWV_END ); printf("win = %08lx\n",(unsigned long int)win); lx_MapWindow(xc,win); pixx = 7; x = 0; exp = now_time() + INTERVAL; aio_add_block(&tick,0); } static void got_hostlist(void *arg __attribute__((__unused__))) { int i; int n; LX_HOSTTYPE t; int s; const unsigned char *d; int j; printf("got host list\n"); n = lx_hostlist_entries(hl); for (i=0;i>2,((d[1]&3)*256)+d[0]); continue; } else { printf(" DECnet, size %d (expected 2)",s); } break; case LX_HOSTTYPE_Chaos: if (s == 2) { printf(" Chaos, net %d host %d\n",d[1],d[0]); continue; } else { printf(" DECnet, size %d (expected 2)",s); } break; case LX_HOSTTYPE_Other: printf(" unknown type"); break; } printf(" [%d]:",s); for (j=0;jkeycode, e->seq, e->time, e->rootw, e->eventw, e->childw, e->rootx, e->rooty, e->eventx, e->eventy, e->state, e->samescreen); } static void key_release(const LX_EVENT_KeyRelease *e) { printf("KeyRelease: kc=%d seq=%04x ts=%d rw=%08x ew=%08x cw=%08x rxy=(%d,%d) exy=(%d,%d) st=%08x ss=%d\n", e->keycode, e->seq, e->time, e->rootw, e->eventw, e->childw, e->rootx, e->rooty, e->eventx, e->eventy, e->state, e->samescreen); } static void handle_event(LX_CONN *c, LX_EVENT *e) { if (c != xc) abort(); switch (e->type) { case LX_EV_KeyPress: key_press(&e->u.KeyPress); break; case LX_EV_KeyRelease: key_release(&e->u.KeyRelease); break; case LX_EV_ButtonPress: printf("ButtonPress"); break; case LX_EV_ButtonRelease: printf("ButtonRelease"); break; case LX_EV_MotionNotify: printf("MotionNotify"); break; case LX_EV_EnterNotify: printf("EnterNotify"); break; case LX_EV_LeaveNotify: printf("LeaveNotify"); break; case LX_EV_FocusIn: printf("FocusIn"); break; case LX_EV_FocusOut: printf("FocusOut"); break; case LX_EV_KeymapNotify: printf("KeymapNotify"); break; case LX_EV_Expose: printf("Expose"); break; case LX_EV_GraphicsExposure: printf("GraphicsExposure"); break; case LX_EV_NoExposure: printf("NoExposure"); break; case LX_EV_VisibilityNotify: printf("VisibilityNotify"); break; case LX_EV_CreateNotify: printf("CreateNotify"); break; case LX_EV_DestroyNotify: printf("DestroyNotify"); break; case LX_EV_UnmapNotify: printf("UnmapNotify"); break; case LX_EV_MapNotify: printf("MapNotify"); break; case LX_EV_MapRequest: printf("MapRequest"); break; case LX_EV_ReparentNotify: printf("ReparentNotify"); break; case LX_EV_ConfigureNotify: printf("ConfigureNotify"); break; case LX_EV_ConfigureRequest: printf("ConfigureRequest"); break; case LX_EV_GravityNotify: printf("GravityNotify"); break; case LX_EV_ResizeRequest: printf("ResizeRequest"); break; case LX_EV_CirculateNotify: printf("CirculateNotify"); break; case LX_EV_CirculateRequest: printf("CirculateRequest"); break; case LX_EV_PropertyNotify: printf("PropertyNotify"); break; case LX_EV_SelectionClear: printf("SelectionClear"); break; case LX_EV_SelectionRequest: printf("SelectionRequest"); break; case LX_EV_SelectionNotify: printf("SelectionNotify"); break; case LX_EV_ColormapNotify: printf("ColormapNotify"); break; case LX_EV_ClientMessage: printf("ClientMessage"); break; case LX_EV_MappingNotify: printf("MappingNotify"); break; default: printf("Type %d",e->type); break; } printf(" event\n"); } static void startup2(LX_CONN *newc, void *arg __attribute__((__unused__))) { int i; LX_OP *op; xc = newc; lx_set_event_handler(xc,&handle_event); printf("open worked\n"); lx_Bell(xc,0); printf("screen count = %d\n",lx_nscreens(xc)); root = lx_root(xc,0); depth = lx_root_depth(xc,0); visual = lx_root_visual(xc,0); printf("root = %08lx, depth %d\n",(unsigned long int)root,depth); cmap = lx_CreateColormap(xc,visual,root,LX_AllocNone); printf("cmap = %08lx\n",(unsigned long int)cmap); op = 0; for (i=7;i>=0;i--) { if (op) lx_op_drop(op); op = lx_AllocColor(xc,cmap,(i&1)*65535,((i>>1)&1)*65535,((i>>2)&1)*65535,&pixv[i],0,0,0); } lx_op_callback(op,&startup3,0,0); lx_op_callback(lx_ListHosts(xc,&accctl,&hl),&got_hostlist,0,0); lx_op_callback(lx_ListExtensions(xc,&exts),&got_extlist,0,0); } static int startup(void *arg __attribute__((__unused__))) { aio_remove_block(bid); lx_open(0,0,&startup2,0,0,getenv("TESTER_DEBUG")?LX_OPENF_DEBUG:0); return(AIO_BLOCK_LOOP); } int main(void); int main(void) { aio_poll_init(); bid = aio_add_block(&startup,0); aio_event_loop(); return(0); }