#include #include "lx.h" #include "internal.h" static void got_ev(LX_CONN *xc) { xc->evbuf.type = xc->rb[0] & 0x7f; xc->evbuf.send_event = (xc->rb[0] >> 7) & 1; (*xc->event)(xc,&xc->evbuf); } static void process_KeyPress(const unsigned char *b, LX_EVENT_KeyPress *e, LX_CONN *c) { e->keycode = b[1]; e->seq = r_card16(b+2); e->time = r_card32(b+4); e->rootw = r_card32(b+8); e->eventw = r_card32(b+12); e->childw = r_card32(b+16); if (e->childw == 0) e->childw = LX_WINDOW_None; e->rootx = r_int16(b+20); e->rooty = r_int16(b+22); e->eventx = r_int16(b+24); e->eventy = r_int16(b+26); e->state = r_card16(b+28); if (e->state & EVS_KEYBUTMASK_MBZ) { lx__protoerr(c,"KeyPress event has invalid state mask 0x%04x",e->state); return; } e->samescreen = lx__proto_to_boolean(b[30]); if (e->samescreen < 0) { lx__protoerr(c,"KeyPress event has invalid same-screen value %d",b[30]); return; } got_ev(c); } static void process_KeyRelease(const unsigned char *b, LX_EVENT_KeyRelease *e, LX_CONN *c) { e->keycode = b[1]; e->seq = r_card16(b+2); e->time = r_card32(b+4); e->rootw = r_card32(b+8); e->eventw = r_card32(b+12); e->childw = r_card32(b+16); if (e->childw == 0) e->childw = LX_WINDOW_None; e->rootx = r_int16(b+20); e->rooty = r_int16(b+22); e->eventx = r_int16(b+24); e->eventy = r_int16(b+26); e->state = r_card16(b+28); if (e->state & EVS_KEYBUTMASK_MBZ) { lx__protoerr(c,"KeyRelease event has invalid state mask 0x%04x",e->state); return; } e->samescreen = lx__proto_to_boolean(b[30]); if (e->samescreen < 0) { lx__protoerr(c,"KeyRelease event has invalid same-screen value %d",b[30]); return; } got_ev(c); } static void process_ButtonPress(const unsigned char *b, LX_EVENT_ButtonPress *e, LX_CONN *c) { e->button = b[1]; e->seq = r_card16(b+2); e->time = r_card32(b+4); e->rootw = r_card32(b+8); e->eventw = r_card32(b+12); e->childw = r_card32(b+16); if (e->childw == 0) e->childw = LX_WINDOW_None; e->rootx = r_int16(b+20); e->rooty = r_int16(b+22); e->eventx = r_int16(b+24); e->eventy = r_int16(b+26); e->state = r_card16(b+28); if (e->state & EVS_KEYBUTMASK_MBZ) { lx__protoerr(c,"ButtonPress event has invalid state mask 0x%04x",e->state); return; } e->samescreen = lx__proto_to_boolean(b[30]); if (e->samescreen < 0) { lx__protoerr(c,"ButtonPress event has invalid same-screen value %d",b[30]); return; } got_ev(c); } static void process_ButtonRelease(const unsigned char *b, LX_EVENT_ButtonRelease *e, LX_CONN *c) { e->button = b[1]; e->seq = r_card16(b+2); e->time = r_card32(b+4); e->rootw = r_card32(b+8); e->eventw = r_card32(b+12); e->childw = r_card32(b+16); if (e->childw == 0) e->childw = LX_WINDOW_None; e->rootx = r_int16(b+20); e->rooty = r_int16(b+22); e->eventx = r_int16(b+24); e->eventy = r_int16(b+26); e->state = r_card16(b+28); if (e->state & EVS_KEYBUTMASK_MBZ) { lx__protoerr(c,"ButtonRelease event has invalid state mask 0x%04x",e->state); return; } e->samescreen = lx__proto_to_boolean(b[30]); if (e->samescreen < 0) { lx__protoerr(c,"ButtonRelease event has invalid same-screen value %d",b[30]); return; } got_ev(c); } static void process_MotionNotify(const unsigned char *b, LX_EVENT_MotionNotify *e, LX_CONN *c) { e->detail = lx__proto_to_motiondetail(b[1]); if (e->detail == LX__map_error) { lx__protoerr(c,"MotionNotify event has invalid detail value %d",b[1]); return; } e->seq = r_card16(b+2); e->time = r_card32(b+4); e->rootw = r_card32(b+8); e->eventw = r_card32(b+12); e->childw = r_card32(b+16); if (e->childw == 0) e->childw = LX_WINDOW_None; e->rootx = r_int16(b+20); e->rooty = r_int16(b+22); e->eventx = r_int16(b+24); e->eventy = r_int16(b+26); e->state = r_card16(b+28); if (e->state & EVS_KEYBUTMASK_MBZ) { lx__protoerr(c,"MotionNotify event has invalid state mask 0x%04x",e->state); return; } e->samescreen = lx__proto_to_boolean(b[30]); if (e->samescreen < 0) { lx__protoerr(c,"MotionNotify event has invalid same-screen value %d",b[30]); return; } got_ev(c); } static void process_EnterNotify(const unsigned char *b, LX_EVENT_EnterNotify *e, LX_CONN *c) { e->detail = lx__proto_to_enterleavedetail(b[1]); if (e->detail == LX__map_error) { lx__protoerr(c,"EnterNotify event has invalid detail value %d",b[1]); return; } e->seq = r_card16(b+2); e->time = r_card32(b+4); e->rootw = r_card32(b+8); e->eventw = r_card32(b+12); e->childw = r_card32(b+16); if (e->childw == 0) e->childw = LX_WINDOW_None; e->rootx = r_int16(b+20); e->rooty = r_int16(b+22); e->eventx = r_int16(b+24); e->eventy = r_int16(b+26); e->state = r_card16(b+28); if (e->state & EVS_KEYBUTMASK_MBZ) { lx__protoerr(c,"EnterNotify event has invalid state mask 0x%04x",e->state); return; } e->mode = lx__proto_to_enterleavemode(b[30]); if (e->mode == LX__map_error) { lx__protoerr(c,"EnterNotify event has invalid mode value %d",b[30]); return; } if (b[31] & 0xfc) { lx__protoerr(c,"EnterNotify event has invalid state mask 0x%04x",e->state); return; } e->samescreen = (b[31] >> 1) & 0x01; e->focus = b[31] & 0x01; got_ev(c); } static void process_LeaveNotify(const unsigned char *b, LX_EVENT_LeaveNotify *e, LX_CONN *c) { e->detail = lx__proto_to_enterleavedetail(b[1]); if (e->detail == LX__map_error) { lx__protoerr(c,"LeaveNotify event has invalid detail value %d",b[1]); return; } e->seq = r_card16(b+2); e->time = r_card32(b+4); e->rootw = r_card32(b+8); e->eventw = r_card32(b+12); e->childw = r_card32(b+16); if (e->childw == 0) e->childw = LX_WINDOW_None; e->rootx = r_int16(b+20); e->rooty = r_int16(b+22); e->eventx = r_int16(b+24); e->eventy = r_int16(b+26); e->state = r_card16(b+28); if (e->state & EVS_KEYBUTMASK_MBZ) { lx__protoerr(c,"LeaveNotify event has invalid state mask 0x%04x",e->state); return; } e->mode = lx__proto_to_enterleavemode(b[30]); if (e->mode == LX__map_error) { lx__protoerr(c,"LeaveNotify event has invalid mode value %d",b[30]); return; } if (b[31] & 0xfc) { lx__protoerr(c,"LeaveNotify event has invalid state mask 0x%04x",e->state); return; } e->samescreen = (b[31] >> 1) & 0x01; e->focus = b[31] & 0x01; got_ev(c); } static void process_FocusIn(const unsigned char *b, LX_EVENT_FocusIn *e, LX_CONN *c) { e->detail = lx__proto_to_focusdetail(b[1]); if (e->detail == LX__map_error) { lx__protoerr(c,"FocusIn event has invalid detail value %d",b[1]); return; } e->seq = r_card16(b+2); e->eventw = r_card32(b+4); e->mode = lx__proto_to_focusmode(b[8]); if (e->mode == LX__map_error) { lx__protoerr(c,"FocusIn event has invalid mode value %d",b[8]); return; } got_ev(c); } static void process_FocusOut(const unsigned char *b, LX_EVENT_FocusOut *e, LX_CONN *c) { e->detail = lx__proto_to_focusdetail(b[1]); if (e->detail == LX__map_error) { lx__protoerr(c,"FocusOut event has invalid detail value %d",b[1]); return; } e->seq = r_card16(b+2); e->eventw = r_card32(b+4); e->mode = lx__proto_to_focusmode(b[8]); if (e->mode == LX__map_error) { lx__protoerr(c,"FocusOut event has invalid mode value %d",b[8]); return; } got_ev(c); } static void process_KeymapNotify(const unsigned char *b, LX_EVENT_KeymapNotify *e, LX_CONN *c) { bcopy(b+1,&e->map[0],31); got_ev(c); } static void process_Expose(const unsigned char *b, LX_EVENT_Expose *e, LX_CONN *c) { e->seq = r_card16(b+2); e->eventw = r_card32(b+4); e->x = r_card16(b+8); e->y = r_card16(b+10); e->w = r_card16(b+12); e->h = r_card16(b+14); e->count = r_card16(b+16); got_ev(c); } static void process_GraphicsExposure(const unsigned char *b, LX_EVENT_GraphicsExposure *e, LX_CONN *c) { e->seq = r_card16(b+2); e->drawable = r_card32(b+4); e->x = r_card16(b+8); e->y = r_card16(b+10); e->w = r_card16(b+12); e->h = r_card16(b+14); e->minor_opc = r_card16(b+16); e->count = r_card16(b+18); e->major_opc = b[20]; got_ev(c); } static void process_NoExposure(const unsigned char *b, LX_EVENT_NoExposure *e, LX_CONN *c) { e->seq = r_card16(b+2); e->drawable = r_card32(b+4); e->minor_opc = r_card16(b+8); e->major_opc = b[10]; got_ev(c); } static void process_VisibilityNotify(const unsigned char *b, LX_EVENT_VisibilityNotify *e, LX_CONN *c) { e->seq = r_card16(b+2); e->window = r_card32(b+4); e->state = lx__proto_to_visibilitystate(b[8]); if (e->state == LX__map_error) { lx__protoerr(c,"VisibilityNotify event has invalid state value %d",b[8]); return; } got_ev(c); } static void process_CreateNotify(const unsigned char *b, LX_EVENT_CreateNotify *e, LX_CONN *c) { e->seq = r_card16(b+2); e->parent = r_card32(b+4); e->window = r_card32(b+8); e->x = r_int16(b+12); e->y = r_int16(b+14); e->w = r_card16(b+16); e->h = r_card16(b+18); e->borderwidth = r_card16(b+20); e->override_redirect = lx__proto_to_boolean(b[22]); if (e->override_redirect < 0) { lx__protoerr(c,"CreateNotify event has invalid override-redirect value %d",b[30]); return; } got_ev(c); } static void process_DestroyNotify(const unsigned char *b, LX_EVENT_DestroyNotify *e, LX_CONN *c) { e->seq = r_card16(b+2); e->eventw = r_card32(b+4); e->window = r_card32(b+8); got_ev(c); } static void process_UnmapNotify(const unsigned char *b, LX_EVENT_UnmapNotify *e, LX_CONN *c) { e->seq = r_card16(b+2); e->eventw = r_card32(b+4); e->window = r_card32(b+8); e->from_configure = lx__proto_to_boolean(b[12]); if (e->from_configure < 0) { lx__protoerr(c,"UnmapNotify event has invalid from-configure value %d",b[12]); return; } got_ev(c); } static void process_MapNotify(const unsigned char *b, LX_EVENT_MapNotify *e, LX_CONN *c) { e->seq = r_card16(b+2); e->eventw = r_card32(b+4); e->window = r_card32(b+8); e->override_redirect = lx__proto_to_boolean(b[12]); if (e->override_redirect < 0) { lx__protoerr(c,"MapNotify event has invalid override-redirect value %d",b[12]); return; } got_ev(c); } static void process_MapRequest(const unsigned char *b, LX_EVENT_MapRequest *e, LX_CONN *c) { e->seq = r_card16(b+2); e->parent = r_card32(b+4); e->window = r_card32(b+8); got_ev(c); } static void process_ReparentNotify(const unsigned char *b, LX_EVENT_ReparentNotify *e, LX_CONN *c) { e->seq = r_card16(b+2); e->eventw = r_card32(b+4); e->window = r_card32(b+8); e->parent = r_card32(b+12); e->x = r_int16(b+16); e->y = r_int16(b+18); e->override_redirect = lx__proto_to_boolean(b[20]); if (e->override_redirect < 0) { lx__protoerr(c,"ReparentNotify event has invalid override-redirect value %d",b[20]); return; } got_ev(c); } static void process_ConfigureNotify(const unsigned char *b, LX_EVENT_ConfigureNotify *e, LX_CONN *c) { e->seq = r_card16(b+2); e->eventw = r_card32(b+4); e->window = r_card32(b+8); e->above_sibling = r_card32(b+12); if (e->above_sibling == 0) e->above_sibling = LX_WINDOW_None; e->x = r_int16(b+16); e->y = r_int16(b+18); e->w = r_card16(b+20); e->h = r_card16(b+22); e->borderwidth = r_card16(b+24); e->override_redirect = lx__proto_to_boolean(b[26]); if (e->override_redirect < 0) { lx__protoerr(c,"ConfigureNotify event has invalid override-redirect value %d",b[26]); return; } got_ev(c); } static void process_ConfigureRequest(const unsigned char *b, LX_EVENT_ConfigureRequest *e, LX_CONN *c) { e->stackmode = lx__proto_to_stackmode(b[1]); if (e->stackmode == LX__map_error) { lx__protoerr(c,"ConfigureRequest event has invalid stack-mode value %d",b[1]); return; } e->seq = r_card16(b+2); e->parent = r_card32(b+4); e->window = r_card32(b+8); e->sibling = r_card32(b+12); if (e->sibling == 0) e->sibling = LX_WINDOW_None; e->x = r_int16(b+16); e->y = r_int16(b+18); e->w = r_card16(b+20); e->h = r_card16(b+22); e->borderwidth = r_card16(b+24); e->mask = r_card16(b+26); // XXX are the 0xff80 bits MBZ, or ignore? got_ev(c); } static void process_GravityNotify(const unsigned char *b, LX_EVENT_GravityNotify *e, LX_CONN *c) { e->seq = r_card16(b+2); e->eventw = r_card32(b+4); e->window = r_card32(b+8); e->x = r_int16(b+12); e->y = r_int16(b+14); got_ev(c); } static void process_ResizeRequest(const unsigned char *b, LX_EVENT_ResizeRequest *e, LX_CONN *c) { e->seq = r_card16(b+2); e->window = r_card32(b+4); e->w = r_card16(b+8); e->h = r_card16(b+10); got_ev(c); } static void process_CirculateNotify(const unsigned char *b, LX_EVENT_CirculateNotify *e, LX_CONN *c) { e->seq = r_card16(b+2); e->eventw = r_card32(b+4); e->window = r_card32(b+8); // 4@12 documented as "4 WINDOW unused" // This appears to be accurate(!); there really is a hole. e->place = lx__proto_to_circulateplace(b[16]); if (e->place == LX__map_error) { lx__protoerr(c,"CirculateNotify event has invalid place value %d",b[16]); return; } got_ev(c); } static void process_CirculateRequest(const unsigned char *b, LX_EVENT_CirculateRequest *e, LX_CONN *c) { e->seq = r_card16(b+2); e->parent = r_card32(b+4); e->window = r_card32(b+8); // 4@12 documented as "4 WINDOW unused" // This appears to be accurate(!); there really is a hole. e->place = lx__proto_to_circulateplace(b[16]); if (e->place == LX__map_error) { lx__protoerr(c,"CirculateRequest event has invalid place value %d",b[16]); return; } got_ev(c); } static void process_PropertyNotify(const unsigned char *b, LX_EVENT_PropertyNotify *e, LX_CONN *c) { e->seq = r_card16(b+2); e->window = r_card32(b+4); e->atom = r_card32(b+8); e->time = r_card32(b+12); e->state = lx__proto_to_propertystate(b[16]); if (e->state == LX__map_error) { lx__protoerr(c,"PropertyNotify event has invalid state value %d",b[16]); return; } got_ev(c); } static void process_SelectionClear(const unsigned char *b, LX_EVENT_SelectionClear *e, LX_CONN *c) { e->seq = r_card16(b+2); e->time = r_card32(b+4); e->owner = r_card32(b+8); e->selection = r_card32(b+12); got_ev(c); } static void process_SelectionRequest(const unsigned char *b, LX_EVENT_SelectionRequest *e, LX_CONN *c) { e->seq = r_card16(b+2); e->time = r_card32(b+4); e->owner = r_card32(b+8); e->requestor = r_card32(b+12); e->selection = r_card32(b+16); e->target = r_card32(b+20); e->property = r_card32(b+24); if (e->property == 0) e->property = LX_ATOM_None; got_ev(c); } static void process_SelectionNotify(const unsigned char *b, LX_EVENT_SelectionNotify *e, LX_CONN *c) { e->seq = r_card16(b+2); e->time = r_card32(b+4); e->requestor = r_card32(b+8); e->selection = r_card32(b+12); e->target = r_card32(b+16); e->property = r_card32(b+20); if (e->property == 0) e->property = LX_ATOM_None; got_ev(c); } static void process_ColormapNotify(const unsigned char *b, LX_EVENT_ColormapNotify *e, LX_CONN *c) { e->seq = r_card16(b+2); e->window = r_card32(b+4); e->colormap = r_card32(b+8); if (e->colormap == 0) e->colormap = LX_COLORMAP_None; e->new = lx__proto_to_boolean(b[12]); if (e->new < 0) { lx__protoerr(c,"ColormapNotify event has invalid new value %d",b[12]); return; } e->state = lx__proto_to_colormapstate(b[13]); if (e->state == LX__map_error) { lx__protoerr(c,"ColormapNotify event has invalid state value %d",b[13]); return; } got_ev(c); } static void process_ClientMessage(const unsigned char *b, LX_EVENT_ClientMessage *e, LX_CONN *c) { int i; e->format = b[1]; switch (e->format) { case 8: bcopy(b+12,&e->u.data8[0],20); break; case 16: for (i=10-1;i>=0;i--) e->u.data16[i] = r_card16(b+12+(2*i)); break; case 32: for (i=5-1;i>=0;i--) e->u.data32[i] = r_card32(b+12+(4*i)); break; default: lx__protoerr(c,"ClientMessage event has invalid format value %d",b[1]); return; break; } e->seq = r_card16(b+2); e->window = r_card32(b+4); e->type = r_card32(b+8); got_ev(c); } static void process_MappingNotify(const unsigned char *b, LX_EVENT_MappingNotify *e, LX_CONN *c) { e->seq = r_card16(b+2); e->request = lx__proto_to_mappingrequest(b[4]); if (e->request == LX__map_error) { lx__protoerr(c,"MappignNotify event has invalid request value %d",b[4]); return; } e->first_keycode = b[5]; e->count = b[6]; got_ev(c); } /* * Currently does nothing with extension events. This will need fixing * once we have a use case that cares about them. */ void lx__process_event(LX_CONN *xc) { // No point parsing it if we have no handler! // (Possibly excepting noticing protocol errors.) // XXX May change if we want to track some state regardless. if (! xc->event) return; switch (xc->rb[0] & 0x7f) { case LX_EV_KeyPress: process_KeyPress(xc->rb,&xc->evbuf.u.KeyPress,xc); break; case LX_EV_KeyRelease: process_KeyRelease(xc->rb,&xc->evbuf.u.KeyRelease,xc); break; case LX_EV_ButtonPress: process_ButtonPress(xc->rb,&xc->evbuf.u.ButtonPress,xc); break; case LX_EV_ButtonRelease: process_ButtonRelease(xc->rb,&xc->evbuf.u.ButtonRelease,xc); break; case LX_EV_MotionNotify: process_MotionNotify(xc->rb,&xc->evbuf.u.MotionNotify,xc); break; case LX_EV_EnterNotify: process_EnterNotify(xc->rb,&xc->evbuf.u.EnterNotify,xc); break; case LX_EV_LeaveNotify: process_LeaveNotify(xc->rb,&xc->evbuf.u.LeaveNotify,xc); break; case LX_EV_FocusIn: process_FocusIn(xc->rb,&xc->evbuf.u.FocusIn,xc); break; case LX_EV_FocusOut: process_FocusOut(xc->rb,&xc->evbuf.u.FocusOut,xc); break; case LX_EV_KeymapNotify: process_KeymapNotify(xc->rb,&xc->evbuf.u.KeymapNotify,xc); break; case LX_EV_Expose: process_Expose(xc->rb,&xc->evbuf.u.Expose,xc); break; case LX_EV_GraphicsExposure: process_GraphicsExposure(xc->rb,&xc->evbuf.u.GraphicsExposure,xc); break; case LX_EV_NoExposure: process_NoExposure(xc->rb,&xc->evbuf.u.NoExposure,xc); break; case LX_EV_VisibilityNotify: process_VisibilityNotify(xc->rb,&xc->evbuf.u.VisibilityNotify,xc); break; case LX_EV_CreateNotify: process_CreateNotify(xc->rb,&xc->evbuf.u.CreateNotify,xc); break; case LX_EV_DestroyNotify: process_DestroyNotify(xc->rb,&xc->evbuf.u.DestroyNotify,xc); break; case LX_EV_UnmapNotify: process_UnmapNotify(xc->rb,&xc->evbuf.u.UnmapNotify,xc); break; case LX_EV_MapNotify: process_MapNotify(xc->rb,&xc->evbuf.u.MapNotify,xc); break; case LX_EV_MapRequest: process_MapRequest(xc->rb,&xc->evbuf.u.MapRequest,xc); break; case LX_EV_ReparentNotify: process_ReparentNotify(xc->rb,&xc->evbuf.u.ReparentNotify,xc); break; case LX_EV_ConfigureNotify: process_ConfigureNotify(xc->rb,&xc->evbuf.u.ConfigureNotify,xc); break; case LX_EV_ConfigureRequest: process_ConfigureRequest(xc->rb,&xc->evbuf.u.ConfigureRequest,xc); break; case LX_EV_GravityNotify: process_GravityNotify(xc->rb,&xc->evbuf.u.GravityNotify,xc); break; case LX_EV_ResizeRequest: process_ResizeRequest(xc->rb,&xc->evbuf.u.ResizeRequest,xc); break; case LX_EV_CirculateNotify: process_CirculateNotify(xc->rb,&xc->evbuf.u.CirculateNotify,xc); break; case LX_EV_CirculateRequest: process_CirculateRequest(xc->rb,&xc->evbuf.u.CirculateRequest,xc); break; case LX_EV_PropertyNotify: process_PropertyNotify(xc->rb,&xc->evbuf.u.PropertyNotify,xc); break; case LX_EV_SelectionClear: process_SelectionClear(xc->rb,&xc->evbuf.u.SelectionClear,xc); break; case LX_EV_SelectionRequest: process_SelectionRequest(xc->rb,&xc->evbuf.u.SelectionRequest,xc); break; case LX_EV_SelectionNotify: process_SelectionNotify(xc->rb,&xc->evbuf.u.SelectionNotify,xc); break; case LX_EV_ColormapNotify: process_ColormapNotify(xc->rb,&xc->evbuf.u.ColormapNotify,xc); break; case LX_EV_ClientMessage: process_ClientMessage(xc->rb,&xc->evbuf.u.ClientMessage,xc); break; case LX_EV_MappingNotify: process_MappingNotify(xc->rb,&xc->evbuf.u.MappingNotify,xc); break; default: lx__dumphex("Unrecognized event",xc->rb,32); break; } } void (*lx_set_event_handler(LX_CONN *xc, void (*h)(LX_CONN *, LX_EVENT *)))(LX_CONN *, LX_EVENT *) { void (*old)(LX_CONN *, LX_EVENT *); old = xc->event; xc->event = h; return(old); } static int serialize_KeyPress(unsigned char *b, const LX_EVENT_KeyPress *e) { if ( (e->rootx < -32768) || (e->rootx > 32767) || (e->rooty < -32768) || (e->rooty > 32767) || (e->eventx < -32768) || (e->eventx > 32767) || (e->eventy < -32768) || (e->eventy > 32767) || (e->state & EVS_KEYBUTMASK_MBZ) ) return(-1); b[0] = LX_EV_KeyPress; b[1] = e->keycode; w_card32(b+4,e->time); w_card32(b+8,e->rootw); w_card32(b+12,e->eventw); w_card32(b+16,(e->childw==LX_WINDOW_None)?0:e->childw); w_int16(b+20,e->rootx); w_int16(b+22,e->rooty); w_int16(b+24,e->eventx); w_int16(b+26,e->eventy); w_card16(b+28,e->state); b[30] = lx__boolean_to_proto(e->samescreen); return(0); } static int serialize_KeyRelease(unsigned char *b, const LX_EVENT_KeyRelease *e) { if ( (e->rootx < -32768) || (e->rootx > 32767) || (e->rooty < -32768) || (e->rooty > 32767) || (e->eventx < -32768) || (e->eventx > 32767) || (e->eventy < -32768) || (e->eventy > 32767) || (e->state & EVS_KEYBUTMASK_MBZ) ) return(-1); b[0] = LX_EV_KeyRelease; b[1] = e->keycode; w_card32(b+4,e->time); w_card32(b+8,e->rootw); w_card32(b+12,e->eventw); w_card32(b+16,(e->childw==LX_WINDOW_None)?0:e->childw); w_int16(b+20,e->rootx); w_int16(b+22,e->rooty); w_int16(b+24,e->eventx); w_int16(b+26,e->eventy); w_card16(b+28,e->state); b[30] = lx__boolean_to_proto(e->samescreen); return(0); } static int serialize_ButtonPress(unsigned char *b, const LX_EVENT_ButtonPress *e) { if ( (e->rootx < -32768) || (e->rootx > 32767) || (e->rooty < -32768) || (e->rooty > 32767) || (e->eventx < -32768) || (e->eventx > 32767) || (e->eventy < -32768) || (e->eventy > 32767) || (e->state & EVS_KEYBUTMASK_MBZ) ) return(-1); b[0] = LX_EV_ButtonPress; b[1] = e->button; w_card32(b+4,e->time); w_card32(b+8,e->rootw); w_card32(b+12,e->eventw); w_card32(b+16,(e->childw==LX_WINDOW_None)?0:e->childw); w_int16(b+20,e->rootx); w_int16(b+22,e->rooty); w_int16(b+24,e->eventx); w_int16(b+26,e->eventy); w_card16(b+28,e->state); b[30] = lx__boolean_to_proto(e->samescreen); return(0); } static int serialize_ButtonRelease(unsigned char *b, const LX_EVENT_ButtonRelease *e) { if ( (e->rootx < -32768) || (e->rootx > 32767) || (e->rooty < -32768) || (e->rooty > 32767) || (e->eventx < -32768) || (e->eventx > 32767) || (e->eventy < -32768) || (e->eventy > 32767) || (e->state & EVS_KEYBUTMASK_MBZ) ) return(-1); b[0] = LX_EV_ButtonRelease; b[1] = e->button; w_card32(b+4,e->time); w_card32(b+8,e->rootw); w_card32(b+12,e->eventw); w_card32(b+16,(e->childw==LX_WINDOW_None)?0:e->childw); w_int16(b+20,e->rootx); w_int16(b+22,e->rooty); w_int16(b+24,e->eventx); w_int16(b+26,e->eventy); w_int16(b+28,e->state); b[30] = lx__boolean_to_proto(e->samescreen); return(0); } static int serialize_MotionNotify(unsigned char *b, const LX_EVENT_MotionNotify *e) { int v; if ( (e->rootx < -32768) || (e->rootx > 32767) || (e->rooty < -32768) || (e->rooty > 32767) || (e->eventx < -32768) || (e->eventx > 32767) || (e->eventy < -32768) || (e->eventy > 32767) || (e->state & EVS_KEYBUTMASK_MBZ) ) return(-1); b[0] = LX_EV_MotionNotify; v = lx__motiondetail_to_proto(e->detail); if (v < 0) return(-1); b[1] = v; w_card16(b+2,e->seq); w_card32(b+4,e->time); w_card32(b+8,e->rootw); w_card32(b+12,e->eventw); w_card32(b+16,(e->childw==LX_WINDOW_None)?0:e->childw); w_int16(b+20,e->rootx); w_int16(b+22,e->rooty); w_int16(b+24,e->eventx); w_int16(b+26,e->eventy); w_card16(b+28,e->state); b[30] = lx__boolean_to_proto(e->samescreen); return(0); } static int serialize_EnterNotify(unsigned char *b, const LX_EVENT_EnterNotify *e) { int v; if ( (e->rootx < -32768) || (e->rootx > 32767) || (e->rooty < -32768) || (e->rooty > 32767) || (e->eventx < -32768) || (e->eventx > 32767) || (e->eventy < -32768) || (e->eventy > 32767) || (e->state & EVS_KEYBUTMASK_MBZ) ) return(-1); b[0] = LX_EV_EnterNotify; v = lx__enterleavedetail_to_proto(e->detail); if (v < 0) return(-1); b[1] = v; w_card16(b+2,e->seq); w_card32(b+4,e->time); w_card32(b+8,e->rootw); w_card32(b+12,e->eventw); w_card32(b+16,(e->childw==LX_WINDOW_None)?0:e->childw); w_int16(b+20,e->rootx); w_int16(b+22,e->rooty); w_int16(b+24,e->eventx); w_int16(b+26,e->eventy); w_card16(b+28,e->state); v = lx__enterleavemode_to_proto(e->mode); if (v < 0) return(-1); b[30] = v; b[31] = (lx__boolean_to_proto(e->samescreen) << 1) | lx__boolean_to_proto(e->focus); return(0); } static int serialize_LeaveNotify(unsigned char *b, const LX_EVENT_LeaveNotify *e) { int v; if ( (e->rootx < -32768) || (e->rootx > 32767) || (e->rooty < -32768) || (e->rooty > 32767) || (e->eventx < -32768) || (e->eventx > 32767) || (e->eventy < -32768) || (e->eventy > 32767) || (e->state & EVS_KEYBUTMASK_MBZ) ) return(-1); b[0] = LX_EV_LeaveNotify; v = lx__enterleavedetail_to_proto(e->detail); if (v < 0) return(-1); b[1] = v; w_card16(b+2,e->seq); w_card32(b+4,e->time); w_card32(b+8,e->rootw); w_card32(b+12,e->eventw); w_card32(b+16,(e->childw==LX_WINDOW_None)?0:e->childw); w_int16(b+20,e->rootx); w_int16(b+22,e->rooty); w_int16(b+24,e->eventx); w_int16(b+26,e->eventy); w_card16(b+28,e->state); v = lx__enterleavemode_to_proto(e->mode); if (v < 0) return(-1); b[30] = v; b[31] = (lx__boolean_to_proto(e->samescreen) << 1) | lx__boolean_to_proto(e->focus); return(0); } static int serialize_FocusIn(unsigned char *b, const LX_EVENT_FocusIn *e) { int v; b[0] = LX_EV_FocusIn; v = lx__focusdetail_to_proto(e->detail); if (v < 0) return(-1); b[1] = v; w_card16(b+2,e->seq); w_card32(b+4,e->eventw); v = lx__focusmode_to_proto(e->mode); if (v < 0) return(-1); b[8] = v; return(0); } static int serialize_FocusOut(unsigned char *b, const LX_EVENT_FocusOut *e) { int v; b[0] = LX_EV_FocusOut; v = lx__focusdetail_to_proto(e->detail); if (v < 0) return(-1); b[1] = v; w_card16(b+2,e->seq); w_card32(b+4,e->eventw); v = lx__focusmode_to_proto(e->mode); if (v < 0) return(-1); b[8] = v; return(0); } static int serialize_KeymapNotify(unsigned char *b, const LX_EVENT_KeymapNotify *e) { b[0] = LX_EV_KeymapNotify; bcopy(&e->map[0],b+1,31); return(0); } static int serialize_Expose(unsigned char *b, const LX_EVENT_Expose *e) { b[0] = LX_EV_Expose; w_card16(b+2,e->seq); w_card32(b+4,e->eventw); w_card16(b+8,e->x); w_card16(b+10,e->y); w_card16(b+12,e->w); w_card16(b+14,e->h); w_card16(b+16,e->count); return(0); } static int serialize_GraphicsExposure(unsigned char *b, const LX_EVENT_GraphicsExposure *e) { b[0] = LX_EV_GraphicsExposure; w_card16(b+2,e->seq); w_card32(b+4,e->drawable); w_card16(b+8,e->x); w_card16(b+10,e->y); w_card16(b+12,e->w); w_card16(b+14,e->h); w_card16(b+16,e->minor_opc); w_card16(b+18,e->count); b[20] = e->major_opc; return(0); } static int serialize_NoExposure(unsigned char *b, const LX_EVENT_NoExposure *e) { b[0] = LX_EV_NoExposure; w_card16(b+2,e->seq); w_card32(b+4,e->drawable); w_card16(b+8,e->minor_opc); b[10] = e->major_opc; return(0); } static int serialize_VisibilityNotify(unsigned char *b, const LX_EVENT_VisibilityNotify *e) { int v; b[0] = LX_EV_VisibilityNotify; w_card16(b+2,e->seq); w_card32(b+4,e->window); v = lx__visibilitystate_to_proto(e->state); if (v < 0) return(0); b[8] = v; return(0); } static int serialize_CreateNotify(unsigned char *b, const LX_EVENT_CreateNotify *e) { b[0] = LX_EV_CreateNotify; w_card16(b+2,e->seq); w_card32(b+4,e->parent); w_card32(b+8,e->window); w_int16(b+12,e->x); w_int16(b+14,e->y); w_card16(b+16,e->w); w_card16(b+18,e->h); w_card16(b+20,e->borderwidth); b[22] = lx__boolean_to_proto(e->override_redirect); return(0); } static int serialize_DestroyNotify(unsigned char *b, const LX_EVENT_DestroyNotify *e) { b[0] = LX_EV_DestroyNotify; w_card16(b+2,e->seq); w_card32(b+4,e->eventw); w_card32(b+8,e->window); return(0); } static int serialize_UnmapNotify(unsigned char *b, const LX_EVENT_UnmapNotify *e) { b[0] = LX_EV_UnmapNotify; w_card16(b+2,e->seq); w_card32(b+4,e->eventw); w_card32(b+8,e->window); b[12] = lx__boolean_to_proto(e->from_configure); return(0); } static int serialize_MapNotify(unsigned char *b, const LX_EVENT_MapNotify *e) { b[0] = LX_EV_MapNotify; w_card16(b+2,e->seq); w_card32(b+4,e->eventw); w_card32(b+8,e->window); b[12] = lx__boolean_to_proto(e->override_redirect); return(0); } static int serialize_MapRequest(unsigned char *b, const LX_EVENT_MapRequest *e) { b[0] = LX_EV_MapRequest; w_card16(b+2,e->seq); w_card32(b+4,e->parent); w_card32(b+8,e->window); return(0); } static int serialize_ReparentNotify(unsigned char *b, const LX_EVENT_ReparentNotify *e) { b[0] = LX_EV_ReparentNotify; w_card16(b+2,e->seq); w_card32(b+4,e->eventw); w_card32(b+8,e->window); w_card32(b+12,e->parent); w_int16(b+16,e->x); w_int16(b+18,e->y); b[20] = lx__boolean_to_proto(e->override_redirect); return(0); } static int serialize_ConfigureNotify(unsigned char *b, const LX_EVENT_ConfigureNotify *e) { b[0] = LX_EV_ConfigureNotify; w_card16(b+2,e->seq); w_card32(b+4,e->eventw); w_card32(b+8,e->window); w_card32(b+12,(e->above_sibling==LX_WINDOW_None)?0:e->above_sibling); w_int16(b+16,e->x); w_int16(b+18,e->y); w_card16(b+20,e->w); w_card16(b+22,e->h); w_card16(b+24,e->borderwidth); b[26] = lx__boolean_to_proto(e->override_redirect); return(0); } static int serialize_ConfigureRequest(unsigned char *b, const LX_EVENT_ConfigureRequest *e) { int v; b[0] = LX_EV_ConfigureRequest; v = lx__stackmode_to_proto(e->stackmode); if (v < 0) return(-1); b[1] = v; w_card16(b+2,e->seq); w_card32(b+4,e->parent); w_card32(b+8,e->window); w_card32(b+12,(e->sibling==LX_WINDOW_None)?0:e->sibling); w_int16(b+16,e->x); w_int16(b+18,e->y); w_card16(b+20,e->w); w_card16(b+22,e->h); w_card16(b+24,e->borderwidth); w_card16(b+26,e->mask); // XXX are the 0xff80 bits MBZ, or ignore? return(0); } static int serialize_GravityNotify(unsigned char *b, const LX_EVENT_GravityNotify *e) { b[0] = LX_EV_GravityNotify; w_card16(b+2,e->seq); w_card32(b+4,e->eventw); w_card32(b+8,e->window); w_int16(b+12,e->x); w_int16(b+14,e->y); return(0); } static int serialize_ResizeRequest(unsigned char *b, const LX_EVENT_ResizeRequest *e) { b[0] = LX_EV_ResizeRequest; w_card16(b+2,e->seq); w_card32(b+4,e->window); w_card16(b+8,e->w); w_card16(b+10,e->h); return(0); } static int serialize_CirculateNotify(unsigned char *b, const LX_EVENT_CirculateNotify *e) { int v; b[0] = LX_EV_CirculateNotify; w_card16(b+2,e->seq); w_card32(b+4,e->eventw); w_card32(b+8,e->window); // 4@12 documented as "4 WINDOW unused" // This appears to be accurate (!!) v = lx__circulateplace_to_proto(e->place); if (v < 0) return(-1); b[16] = v; return(0); } static int serialize_CirculateRequest(unsigned char *b, const LX_EVENT_CirculateRequest *e) { int v; b[0] = LX_EV_CirculateRequest; w_card16(b+2,e->seq); w_card32(b+4,e->parent); w_card32(b+8,e->window); // 4@12 documented as "4 WINDOW unused" // This appears to be accurate (!!) v = lx__circulateplace_to_proto(e->place); if (v < 0) return(0); b[16] = v; return(0); } static int serialize_PropertyNotify(unsigned char *b, const LX_EVENT_PropertyNotify *e) { int v; b[0] = LX_EV_PropertyNotify; w_card16(b+2,e->seq); w_card32(b+4,e->window); w_card32(b+8,e->atom); w_card32(b+12,e->time); v = lx__propertystate_to_proto(e->state); if (v < 0) return(-1); b[16] = v; return(0); } static int serialize_SelectionClear(unsigned char *b, const LX_EVENT_SelectionClear *e) { b[0] = LX_EV_SelectionClear; w_card16(b+2,e->seq); w_card32(b+4,e->time); w_card32(b+8,e->owner); w_card32(b+12,e->selection); return(0); } static int serialize_SelectionRequest(unsigned char *b, const LX_EVENT_SelectionRequest *e) { b[0] = LX_EV_SelectionRequest; w_card16(b+2,e->seq); w_card32(b+4,e->time); w_card32(b+8,e->owner); w_card32(b+12,e->requestor); w_card32(b+16,e->selection); w_card32(b+20,e->target); w_card32(b+24,(e->property==LX_ATOM_None)?0:e->property); return(0); } static int serialize_SelectionNotify(unsigned char *b, const LX_EVENT_SelectionNotify *e) { b[0]= LX_EV_SelectionNotify; w_card16(b+2,e->seq); w_card32(b+4,e->time); w_card32(b+8,e->requestor); w_card32(b+12,e->selection); w_card32(b+16,e->target); w_card32(b+20,(e->property==LX_ATOM_None)?0:e->property); return(0); } static int serialize_ColormapNotify(unsigned char *b, const LX_EVENT_ColormapNotify *e) { int v; b[0] = LX_EV_ColormapNotify; w_card16(b+2,e->seq); w_card32(b+4,e->window); w_card32(b+8,(e->colormap==LX_COLORMAP_None)?0:e->colormap); b[12] = lx__boolean_to_proto(e->new); v = lx__colormapstate_to_proto(e->state); if (v < 0) return(-1); b[13] = v; return(0); } static int serialize_ClientMessage(unsigned char *b, const LX_EVENT_ClientMessage *e) { int i; b[0] = LX_EV_ClientMessage; b[1] = e->format; switch (e->format) { case 8: bcopy(&e->u.data8[0],&b[12],20); break; case 16: for (i=10-1;i>=0;i--) w_card16(b+12+(2*i),e->u.data16[i]); break; case 32: for (i=5-1;i>=0;i--) w_card32(b+12+(4*i),e->u.data32[i]); break; default: return(-1); break; } w_card16(b+2,e->seq); w_card32(b+4,e->window); w_card32(b+8,e->type); return(0); } static int serialize_MappingNotify(unsigned char *b, const LX_EVENT_MappingNotify *e) { int v; if ((e->first_keycode > 255) || (e->count > 255)) return(-1); b[0] = LX_EV_MappingNotify; w_card16(b+2,e->seq); v = lx__mappingrequest_to_proto(e->request); if (v < 0) return(-1); b[4] = v; b[5] = e->first_keycode; b[6] = e->count; return(0); } int lx__serialize_event(unsigned char *buf, const LX_EVENT *ev) { switch (ev->type) { case LX_EV_KeyPress: return(serialize_KeyPress(buf,&ev->u.KeyPress)); break; case LX_EV_KeyRelease: return(serialize_KeyRelease(buf,&ev->u.KeyRelease)); break; case LX_EV_ButtonPress: return(serialize_ButtonPress(buf,&ev->u.ButtonPress)); break; case LX_EV_ButtonRelease: return(serialize_ButtonRelease(buf,&ev->u.ButtonRelease)); break; case LX_EV_MotionNotify: return(serialize_MotionNotify(buf,&ev->u.MotionNotify)); break; case LX_EV_EnterNotify: return(serialize_EnterNotify(buf,&ev->u.EnterNotify)); break; case LX_EV_LeaveNotify: return(serialize_LeaveNotify(buf,&ev->u.LeaveNotify)); break; case LX_EV_FocusIn: return(serialize_FocusIn(buf,&ev->u.FocusIn)); break; case LX_EV_FocusOut: return(serialize_FocusOut(buf,&ev->u.FocusOut)); break; case LX_EV_KeymapNotify: return(serialize_KeymapNotify(buf,&ev->u.KeymapNotify)); break; case LX_EV_Expose: return(serialize_Expose(buf,&ev->u.Expose)); break; case LX_EV_GraphicsExposure: return(serialize_GraphicsExposure(buf,&ev->u.GraphicsExposure)); break; case LX_EV_NoExposure: return(serialize_NoExposure(buf,&ev->u.NoExposure)); break; case LX_EV_VisibilityNotify: return(serialize_VisibilityNotify(buf,&ev->u.VisibilityNotify)); break; case LX_EV_CreateNotify: return(serialize_CreateNotify(buf,&ev->u.CreateNotify)); break; case LX_EV_DestroyNotify: return(serialize_DestroyNotify(buf,&ev->u.DestroyNotify)); break; case LX_EV_UnmapNotify: return(serialize_UnmapNotify(buf,&ev->u.UnmapNotify)); break; case LX_EV_MapNotify: return(serialize_MapNotify(buf,&ev->u.MapNotify)); break; case LX_EV_MapRequest: return(serialize_MapRequest(buf,&ev->u.MapRequest)); break; case LX_EV_ReparentNotify: return(serialize_ReparentNotify(buf,&ev->u.ReparentNotify)); break; case LX_EV_ConfigureNotify: return(serialize_ConfigureNotify(buf,&ev->u.ConfigureNotify)); break; case LX_EV_ConfigureRequest: return(serialize_ConfigureRequest(buf,&ev->u.ConfigureRequest)); break; case LX_EV_GravityNotify: return(serialize_GravityNotify(buf,&ev->u.GravityNotify)); break; case LX_EV_ResizeRequest: return(serialize_ResizeRequest(buf,&ev->u.ResizeRequest)); break; case LX_EV_CirculateNotify: return(serialize_CirculateNotify(buf,&ev->u.CirculateNotify)); break; case LX_EV_CirculateRequest: return(serialize_CirculateRequest(buf,&ev->u.CirculateRequest)); break; case LX_EV_PropertyNotify: return(serialize_PropertyNotify(buf,&ev->u.PropertyNotify)); break; case LX_EV_SelectionClear: return(serialize_SelectionClear(buf,&ev->u.SelectionClear)); break; case LX_EV_SelectionRequest: return(serialize_SelectionRequest(buf,&ev->u.SelectionRequest)); break; case LX_EV_SelectionNotify: return(serialize_SelectionNotify(buf,&ev->u.SelectionNotify)); break; case LX_EV_ColormapNotify: return(serialize_ColormapNotify(buf,&ev->u.ColormapNotify)); break; case LX_EV_ClientMessage: return(serialize_ClientMessage(buf,&ev->u.ClientMessage)); break; case LX_EV_MappingNotify: return(serialize_MappingNotify(buf,&ev->u.MappingNotify)); break; } return(-1); }