#include #include "lx.h" #include "internal.h" static void got_ev(LX_CONN *xc) { (*xc->event)(xc,&xc->evbuf); } static void process_KeyPress(LX_CONN *xc) { xc->evbuf.type = LX_EV_KeyPress; xc->evbuf.u.KeyPress.keycode = xc->rb[1]; xc->evbuf.u.KeyPress.seq = r_card16(&xc->rb[2]); xc->evbuf.u.KeyPress.time = r_card32(&xc->rb[4]); xc->evbuf.u.KeyPress.rootw = r_card32(&xc->rb[8]); xc->evbuf.u.KeyPress.eventw = r_card32(&xc->rb[12]); xc->evbuf.u.KeyPress.childw = r_card32(&xc->rb[16]); if (xc->evbuf.u.KeyPress.childw == 0) xc->evbuf.u.KeyPress.childw = LX_WINDOW_None; xc->evbuf.u.KeyPress.rootx = r_int16(&xc->rb[20]); xc->evbuf.u.KeyPress.rooty = r_int16(&xc->rb[22]); xc->evbuf.u.KeyPress.eventx = r_int16(&xc->rb[24]); xc->evbuf.u.KeyPress.eventy = r_int16(&xc->rb[26]); xc->evbuf.u.KeyPress.state = r_card16(&xc->rb[28]); if (xc->evbuf.u.KeyPress.state & EVS_KEYBUTMASK_MBZ) { lx__protoerr(xc,"KeyPress event has invalid state mask 0x%04x",xc->evbuf.u.KeyPress.state); return; } xc->evbuf.u.KeyPress.samescreen = lx__proto_to_boolean(xc->rb[30]); if (xc->evbuf.u.KeyPress.samescreen < 0) { lx__protoerr(xc,"KeyPress event has invalid same-screen value %d",xc->rb[30]); return; } got_ev(xc); } static void process_KeyRelease(LX_CONN *xc) { xc->evbuf.type = LX_EV_KeyRelease; xc->evbuf.u.KeyRelease.keycode = xc->rb[1]; xc->evbuf.u.KeyRelease.seq = r_card16(&xc->rb[2]); xc->evbuf.u.KeyRelease.time = r_card32(&xc->rb[4]); xc->evbuf.u.KeyRelease.rootw = r_card32(&xc->rb[8]); xc->evbuf.u.KeyRelease.eventw = r_card32(&xc->rb[12]); xc->evbuf.u.KeyRelease.childw = r_card32(&xc->rb[16]); if (xc->evbuf.u.KeyRelease.childw == 0) xc->evbuf.u.KeyRelease.childw = LX_WINDOW_None; xc->evbuf.u.KeyRelease.rootx = r_int16(&xc->rb[20]); xc->evbuf.u.KeyRelease.rooty = r_int16(&xc->rb[22]); xc->evbuf.u.KeyRelease.eventx = r_int16(&xc->rb[24]); xc->evbuf.u.KeyRelease.eventy = r_int16(&xc->rb[26]); xc->evbuf.u.KeyRelease.state = r_card16(&xc->rb[28]); if (xc->evbuf.u.KeyRelease.state & EVS_KEYBUTMASK_MBZ) if (xc->evbuf.u.KeyRelease.state & EVS_KEYBUTMASK_MBZ) { lx__protoerr(xc,"KeyRelease event has invalid state mask 0x%04x",xc->evbuf.u.KeyRelease.state); return; } xc->evbuf.u.KeyRelease.samescreen = lx__proto_to_boolean(xc->rb[30]); if (xc->evbuf.u.KeyRelease.samescreen < 0) { lx__protoerr(xc,"KeyRelease event has invalid same-screen value %d",xc->rb[30]); return; } got_ev(xc); } static void process_ButtonPress(LX_CONN *xc) { xc->evbuf.type = LX_EV_ButtonPress; xc->evbuf.u.ButtonPress.button = xc->rb[1]; xc->evbuf.u.ButtonPress.seq = r_card16(&xc->rb[2]); xc->evbuf.u.ButtonPress.time = r_card32(&xc->rb[4]); xc->evbuf.u.ButtonPress.rootw = r_card32(&xc->rb[8]); xc->evbuf.u.ButtonPress.eventw = r_card32(&xc->rb[12]); xc->evbuf.u.ButtonPress.childw = r_card32(&xc->rb[16]); if (xc->evbuf.u.ButtonPress.childw == 0) xc->evbuf.u.ButtonPress.childw = LX_WINDOW_None; xc->evbuf.u.ButtonPress.rootx = r_int16(&xc->rb[20]); xc->evbuf.u.ButtonPress.rooty = r_int16(&xc->rb[22]); xc->evbuf.u.ButtonPress.eventx = r_int16(&xc->rb[24]); xc->evbuf.u.ButtonPress.eventy = r_int16(&xc->rb[26]); xc->evbuf.u.ButtonPress.state = r_card16(&xc->rb[28]); if (xc->evbuf.u.ButtonPress.state & EVS_KEYBUTMASK_MBZ) { lx__protoerr(xc,"ButtonPress event has invalid state mask 0x%04x",xc->evbuf.u.ButtonPress.state); return; } xc->evbuf.u.ButtonPress.samescreen = lx__proto_to_boolean(xc->rb[30]); if (xc->evbuf.u.ButtonPress.samescreen < 0) { lx__protoerr(xc,"ButtonPress event has invalid same-screen value %d",xc->rb[30]); return; } got_ev(xc); } static void process_ButtonRelease(LX_CONN *xc) { xc->evbuf.type = LX_EV_ButtonRelease; xc->evbuf.u.ButtonRelease.button = xc->rb[1]; xc->evbuf.u.ButtonRelease.seq = r_card16(&xc->rb[2]); xc->evbuf.u.ButtonRelease.time = r_card32(&xc->rb[4]); xc->evbuf.u.ButtonRelease.rootw = r_card32(&xc->rb[8]); xc->evbuf.u.ButtonRelease.eventw = r_card32(&xc->rb[12]); xc->evbuf.u.ButtonRelease.childw = r_card32(&xc->rb[16]); if (xc->evbuf.u.ButtonRelease.childw == 0) xc->evbuf.u.ButtonRelease.childw = LX_WINDOW_None; xc->evbuf.u.ButtonRelease.rootx = r_int16(&xc->rb[20]); xc->evbuf.u.ButtonRelease.rooty = r_int16(&xc->rb[22]); xc->evbuf.u.ButtonRelease.eventx = r_int16(&xc->rb[24]); xc->evbuf.u.ButtonRelease.eventy = r_int16(&xc->rb[26]); xc->evbuf.u.ButtonRelease.state = r_card16(&xc->rb[28]); if (xc->evbuf.u.ButtonRelease.state & EVS_KEYBUTMASK_MBZ) { lx__protoerr(xc,"ButtonRelease event has invalid state mask 0x%04x",xc->evbuf.u.ButtonRelease.state); return; } xc->evbuf.u.ButtonRelease.samescreen = lx__proto_to_boolean(xc->rb[30]); if (xc->evbuf.u.ButtonRelease.samescreen < 0) { lx__protoerr(xc,"ButtonRelease event has invalid same-screen value %d",xc->rb[30]); return; } got_ev(xc); } static void process_MotionNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_MotionNotify; xc->evbuf.u.MotionNotify.detail = lx__proto_to_motiondetail(xc->rb[1]); if (xc->evbuf.u.MotionNotify.detail == LX__map_error) { lx__protoerr(xc,"MotionNotify event has invalid detail value %d",xc->rb[1]); return; } xc->evbuf.u.MotionNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.MotionNotify.time = r_card32(&xc->rb[4]); xc->evbuf.u.MotionNotify.rootw = r_card32(&xc->rb[8]); xc->evbuf.u.MotionNotify.eventw = r_card32(&xc->rb[12]); xc->evbuf.u.MotionNotify.childw = r_card32(&xc->rb[16]); if (xc->evbuf.u.MotionNotify.childw == 0) xc->evbuf.u.MotionNotify.childw = LX_WINDOW_None; xc->evbuf.u.MotionNotify.rootx = r_int16(&xc->rb[20]); xc->evbuf.u.MotionNotify.rooty = r_int16(&xc->rb[22]); xc->evbuf.u.MotionNotify.eventx = r_int16(&xc->rb[24]); xc->evbuf.u.MotionNotify.eventy = r_int16(&xc->rb[26]); xc->evbuf.u.MotionNotify.state = r_card16(&xc->rb[28]); if (xc->evbuf.u.MotionNotify.state & EVS_KEYBUTMASK_MBZ) { lx__protoerr(xc,"MotionNotify event has invalid state mask 0x%04x",xc->evbuf.u.MotionNotify.state); return; } xc->evbuf.u.MotionNotify.samescreen = lx__proto_to_boolean(xc->rb[30]); if (xc->evbuf.u.MotionNotify.samescreen < 0) { lx__protoerr(xc,"MotionNotify event has invalid same-screen value %d",xc->rb[30]); return; } got_ev(xc); } static void process_EnterNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_EnterNotify; xc->evbuf.u.EnterNotify.detail = lx__proto_to_enterleavedetail(xc->rb[1]); if (xc->evbuf.u.EnterNotify.detail == LX__map_error) { lx__protoerr(xc,"EnterNotify event has invalid detail value %d",xc->rb[1]); return; } xc->evbuf.u.EnterNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.EnterNotify.time = r_card32(&xc->rb[4]); xc->evbuf.u.EnterNotify.rootw = r_card32(&xc->rb[8]); xc->evbuf.u.EnterNotify.eventw = r_card32(&xc->rb[12]); xc->evbuf.u.EnterNotify.childw = r_card32(&xc->rb[16]); if (xc->evbuf.u.EnterNotify.childw == 0) xc->evbuf.u.EnterNotify.childw = LX_WINDOW_None; xc->evbuf.u.EnterNotify.rootx = r_int16(&xc->rb[20]); xc->evbuf.u.EnterNotify.rooty = r_int16(&xc->rb[22]); xc->evbuf.u.EnterNotify.eventx = r_int16(&xc->rb[24]); xc->evbuf.u.EnterNotify.eventy = r_int16(&xc->rb[26]); xc->evbuf.u.EnterNotify.state = r_card16(&xc->rb[28]); if (xc->evbuf.u.EnterNotify.state & EVS_KEYBUTMASK_MBZ) { lx__protoerr(xc,"EnterNotify event has invalid state mask 0x%04x",xc->evbuf.u.EnterNotify.state); return; } xc->evbuf.u.EnterNotify.mode = lx__proto_to_enterleavemode(xc->rb[30]); if (xc->evbuf.u.EnterNotify.mode == LX__map_error) { lx__protoerr(xc,"EnterNotify event has invalid mode value %d",xc->rb[30]); return; } if (xc->rb[31] & 0xfc) { lx__protoerr(xc,"EnterNotify event has invalid state mask 0x%04x",xc->evbuf.u.EnterNotify.state); return; } xc->evbuf.u.EnterNotify.samescreen = (xc->rb[31] >> 1) & 0x01; xc->evbuf.u.EnterNotify.focus = xc->rb[31] & 0x01; got_ev(xc); } static void process_LeaveNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_LeaveNotify; xc->evbuf.u.LeaveNotify.detail = lx__proto_to_enterleavedetail(xc->rb[1]); if (xc->evbuf.u.LeaveNotify.detail == LX__map_error) { lx__protoerr(xc,"LeaveNotify event has invalid detail value %d",xc->rb[1]); return; } xc->evbuf.u.LeaveNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.LeaveNotify.time = r_card32(&xc->rb[4]); xc->evbuf.u.LeaveNotify.rootw = r_card32(&xc->rb[8]); xc->evbuf.u.LeaveNotify.eventw = r_card32(&xc->rb[12]); xc->evbuf.u.LeaveNotify.childw = r_card32(&xc->rb[16]); if (xc->evbuf.u.LeaveNotify.childw == 0) xc->evbuf.u.LeaveNotify.childw = LX_WINDOW_None; xc->evbuf.u.LeaveNotify.rootx = r_int16(&xc->rb[20]); xc->evbuf.u.LeaveNotify.rooty = r_int16(&xc->rb[22]); xc->evbuf.u.LeaveNotify.eventx = r_int16(&xc->rb[24]); xc->evbuf.u.LeaveNotify.eventy = r_int16(&xc->rb[26]); xc->evbuf.u.LeaveNotify.state = r_card16(&xc->rb[28]); if (xc->evbuf.u.LeaveNotify.state & EVS_KEYBUTMASK_MBZ) { lx__protoerr(xc,"LeaveNotify event has invalid state mask 0x%04x",xc->evbuf.u.LeaveNotify.state); return; } xc->evbuf.u.LeaveNotify.mode = lx__proto_to_enterleavemode(xc->rb[30]); if (xc->evbuf.u.LeaveNotify.mode == LX__map_error) { lx__protoerr(xc,"LeaveNotify event has invalid mode value %d",xc->rb[30]); return; } if (xc->rb[31] & 0xfc) { lx__protoerr(xc,"LeaveNotify event has invalid state mask 0x%04x",xc->evbuf.u.LeaveNotify.state); return; } xc->evbuf.u.LeaveNotify.samescreen = (xc->rb[31] >> 1) & 0x01; xc->evbuf.u.LeaveNotify.focus = xc->rb[31] & 0x01; got_ev(xc); } static void process_FocusIn(LX_CONN *xc) { xc->evbuf.type = LX_EV_FocusIn; xc->evbuf.u.FocusIn.detail = lx__proto_to_focusdetail(xc->rb[1]); if (xc->evbuf.u.FocusIn.detail == LX__map_error) { lx__protoerr(xc,"FocusIn event has invalid detail value %d",xc->rb[1]); return; } xc->evbuf.u.FocusIn.seq = r_card16(&xc->rb[2]); xc->evbuf.u.FocusIn.eventw = r_card32(&xc->rb[4]); xc->evbuf.u.FocusIn.mode = lx__proto_to_focusmode(xc->rb[8]); if (xc->evbuf.u.FocusIn.mode == LX__map_error) { lx__protoerr(xc,"FocusIn event has invalid mode value %d",xc->rb[8]); return; } got_ev(xc); } static void process_FocusOut(LX_CONN *xc) { xc->evbuf.type = LX_EV_FocusOut; xc->evbuf.u.FocusOut.detail = lx__proto_to_focusdetail(xc->rb[1]); if (xc->evbuf.u.FocusOut.detail == LX__map_error) { lx__protoerr(xc,"FocusOut event has invalid detail value %d",xc->rb[1]); return; } xc->evbuf.u.FocusOut.seq = r_card16(&xc->rb[2]); xc->evbuf.u.FocusOut.eventw = r_card32(&xc->rb[4]); xc->evbuf.u.FocusOut.mode = lx__proto_to_focusmode(xc->rb[8]); if (xc->evbuf.u.FocusOut.mode == LX__map_error) { lx__protoerr(xc,"FocusOut event has invalid mode value %d",xc->rb[8]); return; } got_ev(xc); } static void process_KeymapNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_KeymapNotify; bcopy(&xc->rb[1],&xc->evbuf.u.KeymapNotify.map[0],31); got_ev(xc); } static void process_Expose(LX_CONN *xc) { xc->evbuf.type = LX_EV_Expose; xc->evbuf.u.Expose.seq = r_card16(&xc->rb[2]); xc->evbuf.u.Expose.eventw = r_card32(&xc->rb[4]); xc->evbuf.u.Expose.x = r_card16(&xc->rb[8]); xc->evbuf.u.Expose.y = r_card16(&xc->rb[10]); xc->evbuf.u.Expose.w = r_card16(&xc->rb[12]); xc->evbuf.u.Expose.h = r_card16(&xc->rb[14]); xc->evbuf.u.Expose.count = r_card16(&xc->rb[16]); got_ev(xc); } static void process_GraphicsExposure(LX_CONN *xc) { xc->evbuf.type = LX_EV_GraphicsExposure; xc->evbuf.u.GraphicsExposure.seq = r_card16(&xc->rb[2]); xc->evbuf.u.GraphicsExposure.drawable = r_card32(&xc->rb[4]); xc->evbuf.u.GraphicsExposure.x = r_card16(&xc->rb[8]); xc->evbuf.u.GraphicsExposure.y = r_card16(&xc->rb[10]); xc->evbuf.u.GraphicsExposure.w = r_card16(&xc->rb[12]); xc->evbuf.u.GraphicsExposure.h = r_card16(&xc->rb[14]); xc->evbuf.u.GraphicsExposure.minor_opc = r_card16(&xc->rb[16]); xc->evbuf.u.GraphicsExposure.count = r_card16(&xc->rb[18]); xc->evbuf.u.GraphicsExposure.major_opc = xc->rb[20]; got_ev(xc); } static void process_NoExposure(LX_CONN *xc) { xc->evbuf.type = LX_EV_NoExposure; xc->evbuf.u.NoExposure.seq = r_card16(&xc->rb[2]); xc->evbuf.u.NoExposure.drawable = r_card32(&xc->rb[4]); xc->evbuf.u.NoExposure.minor_opc = r_card16(&xc->rb[8]); xc->evbuf.u.NoExposure.major_opc = xc->rb[10]; got_ev(xc); } static void process_VisibilityNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_VisibilityNotify; xc->evbuf.u.VisibilityNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.VisibilityNotify.window = r_card32(&xc->rb[4]); xc->evbuf.u.VisibilityNotify.state = lx__proto_to_visibilitystate(xc->rb[8]); if (xc->evbuf.u.VisibilityNotify.state == LX__map_error) { lx__protoerr(xc,"VisibilityNotify event has invalid state value %d",xc->rb[8]); return; } got_ev(xc); } static void process_CreateNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_CreateNotify; xc->evbuf.u.CreateNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.CreateNotify.parent = r_card32(&xc->rb[4]); xc->evbuf.u.CreateNotify.window = r_card32(&xc->rb[8]); xc->evbuf.u.CreateNotify.x = r_int16(&xc->rb[12]); xc->evbuf.u.CreateNotify.y = r_int16(&xc->rb[14]); xc->evbuf.u.CreateNotify.w = r_card16(&xc->rb[16]); xc->evbuf.u.CreateNotify.h = r_card16(&xc->rb[18]); xc->evbuf.u.CreateNotify.borderwidth = r_card16(&xc->rb[20]); xc->evbuf.u.CreateNotify.override_redirect = lx__proto_to_boolean(xc->rb[22]); if (xc->evbuf.u.CreateNotify.override_redirect < 0) { lx__protoerr(xc,"CreateNotify event has invalid override-redirect value %d",xc->rb[30]); return; } got_ev(xc); } static void process_DestroyNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_DestroyNotify; xc->evbuf.u.DestroyNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.DestroyNotify.eventw = r_card32(&xc->rb[4]); xc->evbuf.u.DestroyNotify.window = r_card32(&xc->rb[8]); got_ev(xc); } static void process_UnmapNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_UnmapNotify; xc->evbuf.u.UnmapNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.UnmapNotify.eventw = r_card32(&xc->rb[4]); xc->evbuf.u.UnmapNotify.window = r_card32(&xc->rb[8]); xc->evbuf.u.UnmapNotify.from_configure = lx__proto_to_boolean(xc->rb[12]); if (xc->evbuf.u.UnmapNotify.from_configure < 0) { lx__protoerr(xc,"UnmapNotify event has invalid from-configure value %d",xc->rb[12]); return; } got_ev(xc); } static void process_MapNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_MapNotify; xc->evbuf.u.MapNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.MapNotify.eventw = r_card32(&xc->rb[4]); xc->evbuf.u.MapNotify.window = r_card32(&xc->rb[8]); xc->evbuf.u.MapNotify.override_redirect = lx__proto_to_boolean(xc->rb[12]); if (xc->evbuf.u.MapNotify.override_redirect < 0) { lx__protoerr(xc,"MapNotify event has invalid override-redirect value %d",xc->rb[12]); return; } got_ev(xc); } static void process_MapRequest(LX_CONN *xc) { xc->evbuf.type = LX_EV_MapRequest; xc->evbuf.u.MapRequest.seq = r_card16(&xc->rb[2]); xc->evbuf.u.MapRequest.parent = r_card32(&xc->rb[4]); xc->evbuf.u.MapRequest.window = r_card32(&xc->rb[8]); got_ev(xc); } static void process_ReparentNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_ReparentNotify; xc->evbuf.u.ReparentNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.ReparentNotify.eventw = r_card32(&xc->rb[4]); xc->evbuf.u.ReparentNotify.window = r_card32(&xc->rb[8]); xc->evbuf.u.ReparentNotify.parent = r_card32(&xc->rb[12]); xc->evbuf.u.ReparentNotify.x = r_int16(&xc->rb[16]); xc->evbuf.u.ReparentNotify.y = r_int16(&xc->rb[18]); xc->evbuf.u.ReparentNotify.override_redirect = lx__proto_to_boolean(xc->rb[20]); if (xc->evbuf.u.ReparentNotify.override_redirect < 0) { lx__protoerr(xc,"ReparentNotify event has invalid override-redirect value %d",xc->rb[20]); return; } got_ev(xc); } static void process_ConfigureNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_ConfigureNotify; xc->evbuf.u.ConfigureNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.ConfigureNotify.eventw = r_card32(&xc->rb[4]); xc->evbuf.u.ConfigureNotify.window = r_card32(&xc->rb[8]); xc->evbuf.u.ConfigureNotify.above_sibling = r_card32(&xc->rb[12]); if (xc->evbuf.u.ConfigureNotify.above_sibling == 0) xc->evbuf.u.ConfigureNotify.above_sibling = LX_WINDOW_None; xc->evbuf.u.ConfigureNotify.x = r_int16(&xc->rb[16]); xc->evbuf.u.ConfigureNotify.y = r_int16(&xc->rb[18]); xc->evbuf.u.ConfigureNotify.w = r_card16(&xc->rb[20]); xc->evbuf.u.ConfigureNotify.h = r_card16(&xc->rb[22]); xc->evbuf.u.ConfigureNotify.borderwidth = r_card16(&xc->rb[24]); xc->evbuf.u.ConfigureNotify.override_redirect = lx__proto_to_boolean(xc->rb[26]); if (xc->evbuf.u.ConfigureNotify.override_redirect < 0) { lx__protoerr(xc,"ConfigureNotify event has invalid override-redirect value %d",xc->rb[26]); return; } got_ev(xc); } static void process_ConfigureRequest(LX_CONN *xc) { xc->evbuf.type = LX_EV_ConfigureRequest; xc->evbuf.u.ConfigureRequest.stackmode = lx__proto_to_stackmode(xc->rb[1]); if (xc->evbuf.u.ConfigureRequest.stackmode == LX__map_error) { lx__protoerr(xc,"ConfigureRequest event has invalid stack-mode value %d",xc->rb[1]); return; } xc->evbuf.u.ConfigureRequest.seq = r_card16(&xc->rb[2]); xc->evbuf.u.ConfigureRequest.parent = r_card32(&xc->rb[4]); xc->evbuf.u.ConfigureRequest.window = r_card32(&xc->rb[8]); xc->evbuf.u.ConfigureRequest.sibling = r_card32(&xc->rb[12]); if (xc->evbuf.u.ConfigureRequest.sibling == 0) xc->evbuf.u.ConfigureRequest.sibling = LX_WINDOW_None; xc->evbuf.u.ConfigureRequest.x = r_int16(&xc->rb[16]); xc->evbuf.u.ConfigureRequest.y = r_int16(&xc->rb[18]); xc->evbuf.u.ConfigureRequest.w = r_card16(&xc->rb[20]); xc->evbuf.u.ConfigureRequest.h = r_card16(&xc->rb[22]); xc->evbuf.u.ConfigureRequest.borderwidth = r_card16(&xc->rb[24]); xc->evbuf.u.ConfigureRequest.mask = r_card16(&xc->rb[26]); // XXX are the 0xff80 bits MBZ, or ignore? got_ev(xc); } static void process_GravityNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_GravityNotify; xc->evbuf.u.GravityNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.GravityNotify.eventw = r_card32(&xc->rb[4]); xc->evbuf.u.GravityNotify.window = r_card32(&xc->rb[8]); xc->evbuf.u.GravityNotify.x = r_int16(&xc->rb[12]); xc->evbuf.u.GravityNotify.y = r_int16(&xc->rb[14]); got_ev(xc); } static void process_ResizeRequest(LX_CONN *xc) { xc->evbuf.type = LX_EV_ResizeRequest; xc->evbuf.u.ResizeRequest.seq = r_card16(&xc->rb[2]); xc->evbuf.u.ResizeRequest.window = r_card32(&xc->rb[4]); xc->evbuf.u.ResizeRequest.w = r_card16(&xc->rb[8]); xc->evbuf.u.ResizeRequest.h = r_card16(&xc->rb[10]); got_ev(xc); } static void process_CirculateNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_CirculateNotify; xc->evbuf.u.CirculateNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.CirculateNotify.eventw = r_card32(&xc->rb[4]); xc->evbuf.u.CirculateNotify.window = r_card32(&xc->rb[8]); // 4@12 documented as "4 WINDOW unused" // This appears to be accurate (!!) xc->evbuf.u.CirculateNotify.place = lx__proto_to_circulateplace(xc->rb[16]); if (xc->evbuf.u.CirculateNotify.place == LX__map_error) { lx__protoerr(xc,"CirculateNotify event has invalid place value %d",xc->rb[16]); return; } got_ev(xc); } static void process_CirculateRequest(LX_CONN *xc) { xc->evbuf.type = LX_EV_CirculateRequest; xc->evbuf.u.CirculateRequest.seq = r_card16(&xc->rb[2]); xc->evbuf.u.CirculateRequest.parent = r_card32(&xc->rb[4]); xc->evbuf.u.CirculateRequest.window = r_card32(&xc->rb[8]); // 4@12 documented as "4 WINDOW unused" // This appears to be accurate (!!) xc->evbuf.u.CirculateRequest.place = lx__proto_to_circulateplace(xc->rb[16]); if (xc->evbuf.u.CirculateRequest.place == LX__map_error) { lx__protoerr(xc,"CirculateRequest event has invalid place value %d",xc->rb[16]); return; } got_ev(xc); } static void process_PropertyNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_PropertyNotify; xc->evbuf.u.PropertyNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.PropertyNotify.window = r_card32(&xc->rb[4]); xc->evbuf.u.PropertyNotify.atom = r_card32(&xc->rb[8]); xc->evbuf.u.PropertyNotify.time = r_card32(&xc->rb[12]); xc->evbuf.u.PropertyNotify.state = lx__proto_to_propertystate(xc->rb[16]); if (xc->evbuf.u.PropertyNotify.state == LX__map_error) { lx__protoerr(xc,"PropertyNotify event has invalid state value %d",xc->rb[16]); return; } got_ev(xc); } static void process_SelectionClear(LX_CONN *xc) { xc->evbuf.type = LX_EV_SelectionClear; xc->evbuf.u.SelectionClear.seq = r_card16(&xc->rb[2]); xc->evbuf.u.SelectionClear.time = r_card32(&xc->rb[4]); xc->evbuf.u.SelectionClear.owner = r_card32(&xc->rb[8]); xc->evbuf.u.SelectionClear.selection = r_card32(&xc->rb[12]); got_ev(xc); } static void process_SelectionRequest(LX_CONN *xc) { xc->evbuf.type = LX_EV_SelectionRequest; xc->evbuf.u.SelectionRequest.seq = r_card16(&xc->rb[2]); xc->evbuf.u.SelectionRequest.time = r_card32(&xc->rb[4]); xc->evbuf.u.SelectionRequest.owner = r_card32(&xc->rb[8]); xc->evbuf.u.SelectionRequest.requestor = r_card32(&xc->rb[12]); xc->evbuf.u.SelectionRequest.selection = r_card32(&xc->rb[16]); xc->evbuf.u.SelectionRequest.target = r_card32(&xc->rb[20]); xc->evbuf.u.SelectionRequest.property = r_card32(&xc->rb[24]); if (xc->evbuf.u.SelectionRequest.property == 0) xc->evbuf.u.SelectionRequest.property = LX_ATOM_None; got_ev(xc); } static void process_SelectionNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_SelectionNotify; xc->evbuf.u.SelectionNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.SelectionNotify.time = r_card32(&xc->rb[4]); xc->evbuf.u.SelectionNotify.requestor = r_card32(&xc->rb[8]); xc->evbuf.u.SelectionNotify.selection = r_card32(&xc->rb[12]); xc->evbuf.u.SelectionNotify.target = r_card32(&xc->rb[16]); xc->evbuf.u.SelectionNotify.property = r_card32(&xc->rb[20]); if (xc->evbuf.u.SelectionNotify.property == 0) xc->evbuf.u.SelectionNotify.property = LX_ATOM_None; got_ev(xc); } static void process_ColormapNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_ColormapNotify; xc->evbuf.u.ColormapNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.ColormapNotify.window = r_card32(&xc->rb[4]); xc->evbuf.u.ColormapNotify.colormap = r_card32(&xc->rb[8]); if (xc->evbuf.u.ColormapNotify.colormap == 0) xc->evbuf.u.ColormapNotify.colormap = LX_COLORMAP_None; xc->evbuf.u.ColormapNotify.new = lx__proto_to_boolean(xc->rb[12]); if (xc->evbuf.u.ColormapNotify.new < 0) { lx__protoerr(xc,"ColormapNotify event has invalid new value %d",xc->rb[12]); return; } xc->evbuf.u.ColormapNotify.state = lx__proto_to_colormapstate(xc->rb[13]); got_ev(xc); } static void process_ClientMessage(LX_CONN *xc) { int i; xc->evbuf.type = LX_EV_ClientMessage; xc->evbuf.u.ClientMessage.format = xc->rb[1]; switch (xc->evbuf.u.ClientMessage.format) { case 8: bcopy(&xc->rb[12],&xc->evbuf.u.ClientMessage.u.data8[0],20); break; case 16: for (i=10-1;i>=0;i--) xc->evbuf.u.ClientMessage.u.data16[i] = r_card16(&xc->rb[12+(2*i)]); break; case 32: for (i=5-1;i>=0;i--) xc->evbuf.u.ClientMessage.u.data32[i] = r_card32(&xc->rb[12+(4*i)]); break; default: lx__protoerr(xc,"ClientMessage event has invalid format value %d",xc->rb[1]); return; } xc->evbuf.u.ClientMessage.seq = r_card16(&xc->rb[2]); xc->evbuf.u.ClientMessage.window = r_card32(&xc->rb[4]); xc->evbuf.u.ClientMessage.type = r_card32(&xc->rb[8]); got_ev(xc); } static void process_MappingNotify(LX_CONN *xc) { xc->evbuf.type = LX_EV_MappingNotify; xc->evbuf.u.MappingNotify.seq = r_card16(&xc->rb[2]); xc->evbuf.u.MappingNotify.request = lx__proto_to_mappingrequest(xc->rb[4]); if (xc->evbuf.u.MappingNotify.request == LX__map_error) { lx__protoerr(xc,"MappignNotify event has invalid request value %d",xc->rb[4]); return; } xc->evbuf.u.MappingNotify.first_keycode = xc->rb[5]; xc->evbuf.u.MappingNotify.count = xc->rb[6]; got_ev(xc); } void lx__process_event(LX_CONN *xc) { // No point parsing it if we have no handler! // XXX May change if we want to track some state regardless. if (! xc->event) return; switch (xc->rb[0]) { case LX_EV_KeyPress: process_KeyPress(xc); break; case LX_EV_KeyRelease: process_KeyRelease(xc); break; case LX_EV_ButtonPress: process_ButtonPress(xc); break; case LX_EV_ButtonRelease: process_ButtonRelease(xc); break; case LX_EV_MotionNotify: process_MotionNotify(xc); break; case LX_EV_EnterNotify: process_EnterNotify(xc); break; case LX_EV_LeaveNotify: process_LeaveNotify(xc); break; case LX_EV_FocusIn: process_FocusIn(xc); break; case LX_EV_FocusOut: process_FocusOut(xc); break; case LX_EV_KeymapNotify: process_KeymapNotify(xc); break; case LX_EV_Expose: process_Expose(xc); break; case LX_EV_GraphicsExposure: process_GraphicsExposure(xc); break; case LX_EV_NoExposure: process_NoExposure(xc); break; case LX_EV_VisibilityNotify: process_VisibilityNotify(xc); break; case LX_EV_CreateNotify: process_CreateNotify(xc); break; case LX_EV_DestroyNotify: process_DestroyNotify(xc); break; case LX_EV_UnmapNotify: process_UnmapNotify(xc); break; case LX_EV_MapNotify: process_MapNotify(xc); break; case LX_EV_MapRequest: process_MapRequest(xc); break; case LX_EV_ReparentNotify: process_ReparentNotify(xc); break; case LX_EV_ConfigureNotify: process_ConfigureNotify(xc); break; case LX_EV_ConfigureRequest: process_ConfigureRequest(xc); break; case LX_EV_GravityNotify: process_GravityNotify(xc); break; case LX_EV_ResizeRequest: process_ResizeRequest(xc); break; case LX_EV_CirculateNotify: process_CirculateNotify(xc); break; case LX_EV_CirculateRequest: process_CirculateRequest(xc); break; case LX_EV_PropertyNotify: process_PropertyNotify(xc); break; case LX_EV_SelectionClear: process_SelectionClear(xc); break; case LX_EV_SelectionRequest: process_SelectionRequest(xc); break; case LX_EV_SelectionNotify: process_SelectionNotify(xc); break; case LX_EV_ColormapNotify: process_ColormapNotify(xc); break; case LX_EV_ClientMessage: process_ClientMessage(xc); break; case LX_EV_MappingNotify: process_MappingNotify(xc); break; default: lx__dumphex("Unrecognized event",&xc->rb[0],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); }