#include #include "ext.h" #include "fmt-util.h" #include "fmt-core.h" static void print_shape_kind(FILE *o, unsigned int k) { switch (k) { case 0: fprintf(o,"Bounding"); break; case 1: fprintf(o,"Clip"); break; default: fprintf(o,"%u (INVALID)",k); break; } } static void print_shape_op(FILE *o, unsigned int op) { switch (op) { case 0: fprintf(o,"Set"); break; case 1: fprintf(o,"Union"); break; case 2: fprintf(o,"Intersect"); break; case 3: fprintf(o,"Subtract"); break; case 4: fprintf(o,"Invert"); break; default: fprintf(o,"%u (INVALID)",op); break; } } static void print_shape_ordering(FILE *o, unsigned int order) { switch (order) { case 0: fprintf(o,"Unsorted"); break; case 1: fprintf(o,"YSorted"); break; case 2: fprintf(o,"YXSorted"); break; case 3: fprintf(o,"YXBanded"); break; default: fprintf(o,"%u (INVALID)",order); break; } } static int match_shape(const char *name, int len) { return((len==5)&&!bcmp(name,"SHAPE",5)); } static void xtoc_shape_QueryVersion(FLOW *f, FILE *o, void *pv __attribute__((__unused__))) { unsigned int vmaj; unsigned int vmin; if (! f) return; rep_hdr(f,o,"SHAPE QueryVersion"); EXACTLENGTH(32); vmaj = get2u(f,8); vmin = get2u(f,10); fprintf(o," Version: %u.%u\n",vmaj,vmin); } static void request_shape_QueryVersion(FLOW *f, FILE *o) { req_hdr_exact(f,o,"SHAPE QueryVersion",4); expect_reply(f->conn,&xtoc_shape_QueryVersion,0); } static void request_shape_Rectangles(FLOW *f, FILE *o) { unsigned int n; unsigned int off; req_hdr_min(f,o,"SHAPE Rectangles",16); n = (f->ibfill - 16) / 8; EXACTLENGTH(16+(8*n)); fprintf(o," Operation: "); print_shape_op(o,get1u(f,4)); fprintf(o,"\n"); fprintf(o," Kind: "); print_shape_kind(o,get1u(f,5)); fprintf(o,"\n"); fprintf(o," Ordering: "); print_shape_ordering(o,get1u(f,6)); fprintf(o,"\n"); fprintf(o," Window: "XID_FMT"\n",get4u(f,8)); fprintf(o," Offset: (%d,%d)",get2s(f,12),get2s(f,14)); fprintf(o," Rectangles: %u\n",n); off = 16; for (;n>0;n--) { fprintf(o," %ux%u+%d+%d",get2u(f,off+4),get2u(f,off+6),get2s(f,off),get2s(f,off+2)); off += 8; } } static void request_shape_Mask(FLOW *f, FILE *o) { req_hdr_exact(f,o,"SHAPE Mask",20); fprintf(o," Operation: "); print_shape_op(o,get1u(f,4)); fprintf(o,"\n"); fprintf(o," Kind: "); print_shape_kind(o,get1u(f,5)); fprintf(o,"\n"); get_pad(f,6,2); fprintf(o," Window: "XID_FMT"\n",get4u(f,8)); fprintf(o," Offset: (%d,%d)",get2s(f,12),get2s(f,14)); fprintf(o," Pixmap: "); print_xid_z(o,get4u(f,16),"None"); fprintf(o,"\n"); } static void request_shape_Combine(FLOW *f, FILE *o) { req_hdr_exact(f,o,"SHAPE Combine",20); fprintf(o," Operation: "); print_shape_op(o,get1u(f,4)); fprintf(o,"\n"); fprintf(o," Destination kind: "); print_shape_kind(o,get1u(f,5)); fprintf(o,"\n"); fprintf(o," Source kind: "); print_shape_kind(o,get1u(f,6)); fprintf(o,"\n"); fprintf(o," Destination window: "XID_FMT"\n",get4u(f,8)); fprintf(o," Offset: (%d,%d)",get2s(f,12),get2s(f,14)); fprintf(o," Source window: "XID_FMT"\n",get4u(f,16)); } static void request_shape_Offset(FLOW *f, FILE *o) { req_hdr_exact(f,o,"SHAPE Offset",16); fprintf(o," Destination kind: "); print_shape_kind(o,get1u(f,4)); fprintf(o,"\n"); fprintf(o," Window: "XID_FMT"\n",get4u(f,8)); fprintf(o," Offset: (%d,%d)",get2s(f,12),get2s(f,14)); } static void xtoc_shape_QueryExtents(FLOW *f, FILE *o, void *pv __attribute__((__unused__))) { if (! f) return; rep_hdr(f,o,"SHAPE QueryExtents"); EXACTLENGTH(32); fprintf(o," Bounding shaped: "); print_bool(o,get1u(f,8)); fprintf(o,"\n"); fprintf(o," Clip shaped: "); print_bool(o,get1u(f,9)); fprintf(o,"\n"); fprintf(o," Bounding extent: %ux%u+%d+%d\n",get2u(f,16),get2u(f,18),get2s(f,12),get2s(f,14)); fprintf(o," Clip extent: %ux%u+%d+%d\n",get2u(f,24),get2u(f,26),get2s(f,20),get2s(f,22)); } static void request_shape_QueryExtents(FLOW *f, FILE *o) { req_hdr_exact(f,o,"SHAPE QueryExtents",8); fprintf(o," Window: "XID_FMT"\n",get4u(f,4)); expect_reply(f->conn,&xtoc_shape_QueryExtents,0); } static void request_shape_SelectInput(FLOW *f, FILE *o) { req_hdr_exact(f,o,"SHAPE SelectInput",12); fprintf(o," Window: "XID_FMT"\n",get4u(f,4)); fprintf(o," Enable: "); print_bool(o,get1u(f,8)); fprintf(o,"\n"); } static void xtoc_shape_InputSelected(FLOW *f, FILE *o, void *pv __attribute__((__unused__))) { if (! f) return; rep_hdr(f,o,"SHAPE InputSelected"); EXACTLENGTH(32); fprintf(o," Enabled: "); print_bool(o,get1u(f,1)); fprintf(o,"\n"); } static void request_shape_InputSelected(FLOW *f, FILE *o) { req_hdr_exact(f,o,"SHAPE InputSelected",8); fprintf(o," Window: "XID_FMT"\n",get4u(f,4)); expect_reply(f->conn,&xtoc_shape_InputSelected,0); } static void xtoc_shape_GetRectangles(FLOW *f, FILE *o, void *pv __attribute__((__unused__))) { unsigned int n; unsigned int off; if (! f) return; rep_hdr(f,o,"SHAPE GetRectangles"); n = (f->ibfill - 32) / 8; EXACTLENGTH(32+(8*n)); fprintf(o," Ordering: "); print_shape_ordering(o,get1u(f,1)); fprintf(o,"\n"); fprintf(o," Rectangles: %u\n",n); off = 32; for (;n>0;n--) { fprintf(o," %ux%u+%d+%d",get2u(f,off+4),get2u(f,off+6),get2s(f,off),get2s(f,off+2)); off += 8; } } static void request_shape_GetRectangles(FLOW *f, FILE *o) { req_hdr_exact(f,o,"SHAPE GetRectangles",12); fprintf(o," Window: "XID_FMT"\n",get4u(f,4)); fprintf(o," Kind: "); print_shape_kind(o,get1u(f,8)); fprintf(o,"\n"); expect_reply(f->conn,&xtoc_shape_GetRectangles,0); } #define REQ_FIRST 0 static void (*reqimpl[])(FLOW *, FILE *) = { &request_shape_QueryVersion, &request_shape_Rectangles, &request_shape_Mask, &request_shape_Combine, &request_shape_Offset, &request_shape_QueryExtents, &request_shape_SelectInput, &request_shape_InputSelected, &request_shape_GetRectangles }; #define REQ_N (sizeof(reqimpl)/sizeof(reqimpl[0])) static void request_shape(FLOW *f, FILE *o) { unsigned int sub; sub = get1u(f,1); if ( #if REQ_FIRST > 0 (sub < REQ_FIRST) || #endif (sub >= REQ_FIRST+REQ_N)) { fprintf(o,"Impossible SHAPE request %u",sub); print_raw_data(o,f); abort_packet_print(); return; } (*reqimpl[sub])(f,o); } static void event_shape_ShapeNotify(FLOW *f, FILE *o) { event_hdr(f,o,"SHAPE ShapeNotify"); fprintf(o," Kind: "); print_shape_kind(o,get1u(f,1)); fprintf(o,"\n"); fprintf(o," Window: "XID_FMT"\n",get4u(f,4)); fprintf(o," Extent: %ux%u+%d+%d\n",get2u(f,12),get2u(f,14),get2s(f,8),get2s(f,10)); fprintf(o," Timestamp: "); print_timestamp(o,get4u(f,16)); fprintf(o,"\n"); fprintf(o," Shaped: "); print_bool(o,get1u(f,20)); fprintf(o,"\n"); } #define EV_FIRST 0 static void (*evimpl[])(FLOW *, FILE *) = { &event_shape_ShapeNotify }; #define EV_N (sizeof(evimpl)/sizeof(evimpl[0])) static void event_shape(FLOW *f, FILE *o) { unsigned int sub; sub = get1u(f,0); if ( #if EV_FIRST > 0 (sub < EV_FIRST) || #endif (sub >= EV_FIRST+EV_N)) { fprintf(o,"Impossible SHAPE event %u",sub); print_raw_data(o,f); abort_packet_print(); return; } (*evimpl[sub])(f,o); } static void error_shape(FLOW *f, FILE *o) { fprintf(o,"Impossible SHAPE error %u",get1u(f,1)); print_raw_data(o,f); abort_packet_print(); } EXTDEF extdef_shape = { "SHAPE", &match_shape, &request_shape, &event_shape, &error_shape };