AccessXcomm.c revision 551
551N/A/*
551N/A*
551N/A* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
551N/A* Use subject to license terms.
551N/A*
551N/A* Permission is hereby granted, free of charge, to any person obtaining a
551N/A* copy of this software and associated documentation files (the
551N/A* "Software"), to deal in the Software without restriction, including
551N/A* without limitation the rights to use, copy, modify, merge, publish,
551N/A* distribute, and/or sell copies of the Software, and to permit persons
551N/A* to whom the Software is furnished to do so, provided that the above
551N/A* copyright notice(s) and this permission notice appear in all copies of
551N/A* the Software and that both the above copyright notice(s) and this
551N/A* permission notice appear in supporting documentation.
551N/A*
551N/A* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
551N/A* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
551N/A* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
551N/A* OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
551N/A* HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
551N/A* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
551N/A* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
551N/A* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
551N/A* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
551N/A*
551N/A* Except as contained in this notice, the name of a copyright holder
551N/A* shall not be used in advertising or otherwise to promote the sale, use
551N/A* or other dealings in this Software without prior written authorization
551N/A* of the copyright holder.
551N/A*/
551N/A
551N/A/************************************************************************/
551N/A/* */
551N/A/* Copyright 1987, 1988, 1989, 1990, 1991, 1992, 1993 */
551N/A/* by Digital Equipment Corp., Maynard, MA */
551N/A/* */
551N/A/* Permission to use, copy, modify, and distribute this software */
551N/A/* and its documentation for any purpose and without fee is hereby */
551N/A/* granted, provided that the above copyright notice appear in all */
551N/A/* copies and that both that copyright notice and this permission */
551N/A/* notice appear in supporting documentation, and that the name of */
551N/A/* Digital not be used in advertising or publicity pertaining to */
551N/A/* distribution of the software without specific, written prior */
551N/A/* permission. */
551N/A/* */
551N/A/* DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, */
551N/A/* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND */
551N/A/* FITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, */
551N/A/* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER */
551N/A/* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN */
551N/A/* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
551N/A/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE */
551N/A/* OF THIS SOFTWARE. */
551N/A/* */
551N/A/************************************************************************/
551N/A
551N/A/************************************************************************/
551N/A/* */
551N/A/* AccessX */
551N/A/* */
551N/A/* This module provides the client library functions necessary for */
551N/A/* an AccessX client to communicate with the AccessX server */
551N/A/* extension. */
551N/A/* */
551N/A/* Revision History: */
551N/A/* */
551N/A/* 11-Jun-1993 WDW & MEN */
551N/A/* Develop sample implementation. */
551N/A/* */
551N/A/************************************************************************/
551N/A#include <stdio.h>
551N/A#define NEED_EVENTS
551N/A#define NEED_REPLIES
551N/A#include <X11/Xlibint.h>
551N/A#include <X11/Xproto.h>
551N/A#include <X11/keysym.h>
551N/A#include <X11/extensions/extutil.h>
551N/A#include <X11/extensions/Xext.h>
551N/A#include <X11/Intrinsic.h>
551N/A#include "AccessXproto.h"
551N/A#include "AccessXlibint.h"
551N/A
551N/A#ifndef WORD64
551N/A#define _XRead32(dpy, data, len) _XRead((dpy), (char *)(data), (len))
551N/A#endif
551N/A
551N/Aint XAccessXCloseDisplay();
551N/ABool XAccessXWireToEvent();
551N/AStatus XAccessXEventToWire();
551N/A
551N/AXExtensionInfo *accessXExtensionInfo = NULL;
551N/AXExtensionHooks accessXExtensionHooks =
551N/A{
551N/A NULL, /* create_gc */
551N/A NULL, /* copy_gc */
551N/A NULL, /* flush_gc */
551N/A NULL, /* free_gc */
551N/A NULL, /* create_font */
551N/A NULL, /* free_font */
551N/A XAccessXCloseDisplay, /* close_display */
551N/A XAccessXWireToEvent, /* wire_to_event */
551N/A NULL, /* event_to_wire */
551N/A NULL, /* error */
551N/A NULL /* error_string */
551N/A};
551N/A
551N/AXEXT_GENERATE_FIND_DISPLAY(XAccessXFindDisplay,
551N/A accessXExtensionInfo,
551N/A AccessXExtName,
551N/A &accessXExtensionHooks,
551N/A AccessXNumEvents,
551N/A NULL)
551N/A
551N/AXEXT_GENERATE_CLOSE_DISPLAY(XAccessXCloseDisplay,
551N/A accessXExtensionInfo)
551N/A
551N/A/************************************************************************/
551N/A/* */
551N/A/* XAccessXWireToEvent - takes a raw event off the wire an converts it */
551N/A/* into an Xlib event structure. */
551N/A/* */
551N/A/************************************************************************/
551N/A#if NeedFunctionPrototypes
551N/ABool XAccessXWireToEvent(Display *dpy,
551N/A XEvent *libevent,
551N/A xEvent *netevent)
551N/A#else
551N/ABool XAccessXWireToEvent(dpy,libevent,netevent)
551N/A Display *dpy;
551N/A XEvent *libevent;
551N/A xEvent *netevent;
551N/A#endif
551N/A{
551N/A XExtDisplayInfo *info = XAccessXFindDisplay(dpy);
551N/A XAccessXEvent *ev = (XAccessXEvent *) libevent;
551N/A xAccessXEvent *event = (xAccessXEvent *) netevent;
551N/A
551N/A XextCheckExtension(dpy,info,AccessXExtName,False);
551N/A
551N/A ev->type = event->type & 0x7f;
551N/A ev->serial = _XSetLastRequestRead(dpy,(xGenericReply *)netevent);
551N/A ev->send_event = ((event->type & 0x80) != 0);
551N/A ev->display = dpy;
551N/A ev->detail = event->detail;
551N/A ev->keyOrButton = event->keyOrButton;
551N/A ev->modifier = event->modifier;
551N/A ev->control = event->control;
551N/A ev->gain = event->gain;
551N/A
551N/A return True;
551N/A
551N/A} /* XAccessXWireToEvent */
551N/A
551N/A/************************************************************************/
551N/A/* */
551N/A/* XAccessXQueryExtension */
551N/A/* */
551N/A/* DESCRIPTION: */
551N/A/* */
551N/A/* This routine returns TRUE if the AccessX extension is */
551N/A/* available on the given display. */
551N/A/* */
551N/A/************************************************************************/
551N/A#if NeedFunctionPrototypes
551N/ABool XAccessXQueryExtension(Display *dpy,
551N/A AccessXClientContextRec *accessXClient)
551N/A#else
551N/ABool XAccessXQueryExtension(dpy,accessXClient)
551N/A Display *dpy;
551N/A AccessXClientContextRec *accessXClient;
551N/A#endif
551N/A{
551N/A XExtDisplayInfo *info = XAccessXFindDisplay(dpy);
551N/A
551N/A if (XextHasExtension(info))
551N/A {
551N/A accessXClient->majorOpcode = (CARD16) (info->codes->major_opcode);
551N/A accessXClient->eventBase = (CARD16) (info->codes->first_event);
551N/A accessXClient->errorBase = (CARD16) (info->codes->first_error);
551N/A return True;
551N/A }
551N/A else
551N/A return False;
551N/A
551N/A} /* XAccessXQueryExtension */
551N/A
551N/A/************************************************************************/
551N/A/* */
551N/A/* XAccessXQueryVersion */
551N/A/* */
551N/A/* DESCRIPTION: */
551N/A/* */
551N/A/* This routine sends an X_AccessXQueryVersion request to the */
551N/A/* AccessX extension on the server, and then waits for a reply. */
551N/A/* */
551N/A/************************************************************************/
551N/A#if NeedFunctionPrototypes
551N/Aint XAccessXQueryVersion(Display *dpy,
551N/A AccessXClientContextRec *accessXClient,
551N/A CARD8 *majorVersion,
551N/A CARD8 *minorVersion)
551N/A#else
551N/Aint XAccessXQueryVersion(dpy,accessXClient,majorVersion,minorVersion)
551N/A Display *dpy;
551N/A AccessXClientContextRec *accessXClient;
551N/A CARD8 *majorVersion;
551N/A CARD8 *minorVersion;
551N/A#endif
551N/A{
551N/A int status = True;
551N/A xAccessXQueryVersionReq *req;
551N/A xAccessXQueryVersionReply rep;
551N/A
551N/A /* Send the request and wait for the reply.
551N/A */
551N/A LockDisplay(dpy);
551N/A ExtGetReq(accessXClient->majorOpcode,AccessXQueryVersion,req);
551N/A status = _XReply(dpy,(xReply *)&rep,0,xTrue);
551N/A
551N/A SyncHandle();
551N/A UnlockDisplay(dpy);
551N/A
551N/A *majorVersion = rep.majorVersion;
551N/A *minorVersion = rep.minorVersion;
551N/A
551N/A return(status);
551N/A
551N/A} /* XAccessXQueryVersion */
551N/A
551N/A/************************************************************************/
551N/A/* */
551N/A/* XAccessXSelectInput */
551N/A/* */
551N/A/* DESCRIPTION: */
551N/A/* */
551N/A/* This routine sends an X_AccessXSelectInput request to the */
551N/A/* AccessX extension on the server. */
551N/A/* */
551N/A/************************************************************************/
551N/A#if NeedFunctionPrototypes
551N/Avoid XAccessXSelectInput(Display *dpy,
551N/A AccessXClientContextRec *accessXClient,
551N/A BYTE enable)
551N/A#else
551N/Avoid XAccessXSelectInput(dpy,accessXClient,enable)
551N/A Display *dpy;
551N/A AccessXClientContextRec *accessXClient;
551N/A BYTE enable;
551N/A#endif
551N/A{
551N/A xAccessXSelectInputReq *req;
551N/A
551N/A ExtGetReq(accessXClient->majorOpcode,AccessXSelectInput,req);
551N/A req->enable = enable;
551N/A
551N/A XFlush(dpy);
551N/A SyncHandle();
551N/A
551N/A return;
551N/A
551N/A} /* XAccessXSelectInput */
551N/A
551N/A/************************************************************************/
551N/A/* */
551N/A/* XAccessXQueryState */
551N/A/* */
551N/A/* DESCRIPTION: */
551N/A/* */
551N/A/* This routine sends an X_AccessXQueryState request to the */
551N/A/* AccessX extension on the server, and then waits for a reply. */
551N/A/* */
551N/A/************************************************************************/
551N/A#if NeedFunctionPrototypes
551N/Aint XAccessXQueryState(Display *dpy,
551N/A AccessXClientContextRec *accessXClient,
551N/A AccessXStateRec *accessXState)
551N/A#else
551N/Aint XAccessXQueryState(dpy,accessXClient,accessXState)
551N/A Display *dpy;
551N/A AccessXClientContextRec *accessXClient;
551N/A AccessXStateRec *accessXState;
551N/A#endif
551N/A{
551N/A int status = True;
551N/A xAccessXQueryStateReply rep;
551N/A xAccessXQueryStateReq *req;
551N/A
551N/A /* Send the request and wait for the reply.
551N/A */
551N/A LockDisplay(dpy);
551N/A ExtGetReq(accessXClient->majorOpcode,AccessXQueryState,req);
551N/A status = _XReply(dpy,(xReply *)&rep,2,xTrue);
551N/A
551N/A accessXState->control = rep.control;
551N/A accessXState->timeOutInterval = rep.timeOutInterval;
551N/A accessXState->mouseKeysTimeToMax = rep.mouseKeysTimeToMax;
551N/A accessXState->mouseKeysGain = rep.mouseKeysGain;
551N/A accessXState->mouseKeysInterval = rep.mouseKeysInterval;
551N/A accessXState->mouseKeysCtrlMask = rep.mouseKeysCtrlMask;
551N/A accessXState->mouseKeysCtrlKeyCode = rep.mouseKeysCtrlKeyCode;
551N/A accessXState->currentMouseButton = rep.currentMouseButton;
551N/A accessXState->latchedModifiers = rep.latchedModifiers;
551N/A accessXState->lockedModifiers = rep.lockedModifiers;
551N/A accessXState->slowKeysDelay = rep.slowKeysDelay;
551N/A accessXState->debounceDelay = rep.debounceDelay;
551N/A accessXState->repeatKeysDelay = rep.repeatKeysDelay;
551N/A accessXState->repeatKeysRate = rep.repeatKeysRate;
551N/A
551N/A SyncHandle();
551N/A UnlockDisplay(dpy);
551N/A
551N/A return(status);
551N/A
551N/A} /* XAccessXQueryState */
551N/A
551N/A/************************************************************************/
551N/A/* */
551N/A/* XAccessXConfigure */
551N/A/* */
551N/A/* DESCRIPTION: */
551N/A/* */
551N/A/* This routine sends an X_AccessXConfigure request to the */
551N/A/* AccessX extension on the server. */
551N/A/* */
551N/A/************************************************************************/
551N/A#if NeedFunctionPrototypes
551N/Aint XAccessXConfigure(Display *dpy,
551N/A AccessXClientContextRec *accessXClient,
551N/A CARD16 mask,
551N/A AccessXStateRec *accessXState)
551N/A#else
551N/Aint XAccessXConfigure(dpy,accessXClient,mask,accessXState)
551N/A Display *dpy;
551N/A AccessXClientContextRec *accessXClient;
551N/A CARD16 mask;
551N/A AccessXStateRec *accessXState;
551N/A#endif
551N/A{
551N/A int status = True;
551N/A xAccessXConfigureReq *req;
551N/A
551N/A ExtGetReq(accessXClient->majorOpcode,AccessXConfigure,req);
551N/A
551N/A req->mask = mask;
551N/A req->control = accessXState->control;
551N/A req->timeOutInterval = accessXState->timeOutInterval;
551N/A req->mouseKeysTimeToMax = accessXState->mouseKeysTimeToMax;
551N/A req->mouseKeysGain = accessXState->mouseKeysGain;
551N/A req->mouseKeysInterval = accessXState->mouseKeysInterval;
551N/A req->mouseKeysCtrlMask = accessXState->mouseKeysCtrlMask;
551N/A req->mouseKeysCtrlKeyCode = accessXState->mouseKeysCtrlKeyCode;
551N/A req->currentMouseButton = accessXState->currentMouseButton;
551N/A req->slowKeysDelay = accessXState->slowKeysDelay;
551N/A req->debounceDelay = accessXState->debounceDelay;
551N/A req->repeatKeysDelay = accessXState->repeatKeysDelay;
551N/A req->repeatKeysRate = accessXState->repeatKeysRate;
551N/A
551N/A XFlush(dpy);
551N/A SyncHandle();
551N/A
551N/A return(status);
551N/A
551N/A} /* XAccessXConfigure */
551N/A#if 0
551N/A/************************************************************************/
551N/A/* */
551N/A/* XAccessXGetMouseKeys */
551N/A/* */
551N/A/* DESCRIPTION: */
551N/A/* */
551N/A/* This routine sends an X_AccessXGetMouseKeys request to the */
551N/A/* AccessX extension on the server, and then waits for a reply. */
551N/A/* */
551N/A/************************************************************************/
551N/A#if NeedFunctionPrototypes
551N/AAccessXMouseKeysRec *XAccessXGetMouseKeys(Display *dpy,
551N/A AccessXClientContextRec *accessXClient,
551N/A int *numKeys)
551N/A#else
551N/AAccessXMouseKeysRec *XAccessXGetMouseKeys(dpy,accessXClient,numKeys)
551N/A Display *dpy;
551N/A AccessXClientContextRec *accessXClient;
551N/A int *numKeys;
551N/A#endif
551N/A{
551N/A int status = True;
551N/A xAccessXGetMouseKeysReq *req;
551N/A xAccessXGetMouseKeysReply rep;
551N/A int numBytes;
551N/A AccessXMouseKeysRec *mouseKeys = NULL;
551N/A
551N/A *numKeys = 0;
551N/A
551N/A /* Send the request and wait for the reply.
551N/A */
551N/A return; /* NOthing for now */
551N/A LockDisplay(dpy);
551N/A ExtGetReq(accessXClient->majorOpcode,AccessXGetMouseKeys,req);
551N/A
551N/A if (! _XReply(dpy,(xReply *)&rep,0,xFalse))
551N/A {
551N/A UnlockDisplay(dpy);
551N/A SyncHandle();
551N/A return (AccessXMouseKeysRec *) NULL;
551N/A }
551N/A
551N/A *numKeys = rep.numKeys;
551N/A numBytes = rep.numKeys * sizeof(AccessXMouseKeysRec);
551N/A
551N/A mouseKeys = (AccessXMouseKeysRec *) Xmalloc(numBytes);
551N/A if (!mouseKeys)
551N/A _XEatData(dpy,(unsigned long) numBytes);
551N/A else
551N/A _XRead32(dpy,(char *) mouseKeys, numBytes);
551N/A
551N/A SyncHandle();
551N/A UnlockDisplay(dpy);
551N/A
551N/A return(mouseKeys);
551N/A
551N/A} /* XAccessXGetMouseKeys */
551N/A
551N/A/************************************************************************/
551N/A/* */
551N/A/* XAccessXSetMouseKey */
551N/A/* */
551N/A/* DESCRIPTION: */
551N/A/* */
551N/A/* This routine sends an X_AccessXSetMouseKey request to the */
551N/A/* AccessX extension in the server. */
551N/A/* */
551N/A/************************************************************************/
551N/A#if NeedFunctionPrototypes
551N/Avoid XAccessXSetMouseKey(Display *dpy,
551N/A AccessXClientContextRec *accessXClient,
551N/A CARD8 keyCode,
551N/A CARD8 action,
551N/A INT8 info1,
551N/A INT8 info2)
551N/A#else
551N/Avoid XAccessXSetMouseKey(dpy,accessXClient,keyCode,action,info1,info2)
551N/A Display *dpy;
551N/A AccessXClientContextRec *accessXClient;
551N/A CARD8 keyCode;
551N/A CARD8 action;
551N/A INT8 info1;
551N/A INT8 info2;
551N/A#endif
551N/A{
551N/A xAccessXSetMouseKeyReq *req;
551N/A
551N/A return; /* Nothing for now */
551N/A ExtGetReq(accessXClient->majorOpcode,AccessXSetMouseKey,req);
551N/A
551N/A req->keyCode = keyCode; /* KeyCode of key to be modified */
551N/A req->action = action; /* What to do if MouseKeys is on */
551N/A req->info1 = info1; /* button or deltax */
551N/A req->info2 = info2; /* how_many or deltay */
551N/A
551N/A XFlush(dpy);
551N/A SyncHandle();
551N/A
551N/A return;
551N/A
551N/A} /* XAccessXSetMouseKey */
551N/A#endif
551N/A
551N/A/************************************************************************/
551N/A/* */
551N/A/* XAccessXInit */
551N/A/* */
551N/A/* DESCRIPTION: */
551N/A/* */
551N/A/* Initialize the connection with the AccessX server extension. */
551N/A/* */
551N/A/************************************************************************/
551N/A#if NeedFunctionPrototypes
551N/Avoid XAccessXInit(Display *dpy,
551N/A AccessXClientContextRec *accessXClient)
551N/A#else
551N/Avoid XAccessXInit(dpy,accessXClient)
551N/A Display *dpy;
551N/A AccessXClientContextRec *accessXClient;
551N/A#endif
551N/A{
551N/A /* Find the AccessX extension
551N/A */
551N/A if (!XAccessXQueryExtension(dpy,accessXClient))
551N/A {
551N/A fprintf(stderr,"Could not query %s extension\n",
551N/A AccessXExtName);
551N/A exit(1L);
551N/A }
551N/A
551N/A} /* XAccessXInit */
551N/A
551N/A/************************************************************************/
551N/A/* */
551N/A/* XAccessXMainLoop */
551N/A/* */
551N/A/************************************************************************/
551N/A#if NeedFunctionPrototypes
551N/Avoid XAccessXAppMainLoop(XtAppContext appContext,
551N/A AccessXClientContextRec *accessXClient)
551N/A#else
551N/Avoid XAccessXAppMainLoop(appContext,accessXClient)
551N/A XtAppContext appContext;
551N/A AccessXClientContextRec *accessXClient;
551N/A#endif
551N/A{
551N/A XEvent event;
551N/A
551N/A for (;;)
551N/A {
551N/A /* The AccessX extension will spit out only one event type,
551N/A * and this the type accessXEventBase. The intrinsics do not
551N/A * have a graceful way to allow extensions to add events to
551N/A * XtAppMainLoop, so it is necessary to write our own which
551N/A * checks for accessXEventBase.
551N/A */
551N/A XtAppNextEvent(appContext,&event);
551N/A if ((event.type == accessXClient->eventBase) &&
551N/A (accessXClient->eventHandler))
551N/A (*accessXClient->eventHandler)((XAccessXEvent *)&event);
551N/A else
551N/A XtDispatchEvent(&event);
551N/A }
551N/A} /* XAccessXAppMainLoop */