Back to index

im-sdk  12.3.91
Defines | Functions | Variables
aux_ext.c File Reference
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <X11/Xmd.h>
#include <Xm/Xm.h>
#include <Xm/RowColumn.h>
#include <Xm/Text.h>
#include <Xm/PushB.h>
#include "trace_message.h"

Go to the source code of this file.

Defines

#define HTT_AUX_EXT_NAME   "sample_ext"
#define HTT_AUX_SO_NAME   "sample_so"
#define HTT_AUX_PROP_NAME   "sample_prop"
#define HTT_AUX_PROP1_NAME   "sample_prop1"

Functions

void ButtonTextCallback (Widget w, XtPointer client_data, XtPointer call_data)
void ButtonMessageCallback (Widget w, XtPointer client_data, XtPointer call_data)
void ButtonQuitCallback (Widget w, XtPointer client_data, XtPointer call_data)
void ProcessInitialPropertyNotify (void)
void ProcessPropertyNotify (Widget w, XEvent *event)
void ProcessClientMessage (Widget w, XEvent *event)
void AuxEventHandler (Widget w, XtPointer client_data, XEvent *event, Boolean *b)
int main (int argc, char **argv)

Variables

Atom aux_so_atom
Atom aux_ext_atom
Atom aux_prop_atom
Atom aux_prop1_atom
Window aux_window
Widget toplevel
Widget aux
Widget input
Widget button_text
Widget button_message
Widget button_quit
int icid
int imid

Define Documentation

#define HTT_AUX_EXT_NAME   "sample_ext"

Definition at line 65 of file aux_ext.c.

#define HTT_AUX_PROP1_NAME   "sample_prop1"

Definition at line 68 of file aux_ext.c.

#define HTT_AUX_PROP_NAME   "sample_prop"

Definition at line 67 of file aux_ext.c.

#define HTT_AUX_SO_NAME   "sample_so"

Definition at line 66 of file aux_ext.c.


Function Documentation

void AuxEventHandler ( Widget  w,
XtPointer  client_data,
XEvent *  event,
Boolean b 
)

Definition at line 381 of file aux_ext.c.

{

       TRACE_MESSAGE('E', ("aux_ext:AuxEventHandler: %d\n", event->type));

       switch (event->type) {
       case PropertyNotify:
              ProcessPropertyNotify(w, event);
              break;
       case ClientMessage:
              if (XtWindow(w) == aux_window) {
                     ProcessClientMessage(w, event);
              }
              break;
       default:
              break;
       }

       return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ButtonMessageCallback ( Widget  w,
XtPointer  client_data,
XtPointer  call_data 
)

Definition at line 132 of file aux_ext.c.

{
       Display *            display;
       Window               w_so;
       XClientMessageEvent  event;

       display = XtDisplay(w);

       if (None == (w_so = XGetSelectionOwner(display, aux_so_atom))) {
              TRACE_MESSAGE('m', ("aux_ext:ButtonMessageCallback: no owner of %08x\n",
                                aux_so_atom));
              return;
       }

       event.type = ClientMessage;
       event.serial = 0;
       event.send_event = True;
       event.display = display;
       event.window = w_so;
       event.message_type = XA_STRING;
       event.format = 8;
       event.data.b[0] = ((imid & 0xff00) >> 8);
       event.data.b[1] = ((imid & 0x00ff) >> 0);
       event.data.b[2] = ((icid & 0xff00) >> 8);
       event.data.b[3] = ((icid & 0x00ff) >> 0);
       event.data.b[4] = 'h';
       event.data.b[5] = 'o';
       event.data.b[6] = 'g';
       event.data.b[7] = 'e';
       event.data.b[8] = '\0';

       XSendEvent(display, w_so, True, 0, (XEvent *)(&event));
}

Here is the caller graph for this function:

void ButtonQuitCallback ( Widget  w,
XtPointer  client_data,
XtPointer  call_data 
)

Definition at line 168 of file aux_ext.c.

{
       Display *            display;
       Window               w_so;
       XClientMessageEvent  event;
       pid_t                pid;

       display = XtDisplay(w);

       if (None == (w_so = XGetSelectionOwner(display, aux_so_atom))) {
              TRACE_MESSAGE('m', ("aux_ext:ButtonMessageCallback: no owner of %08x\n",
                                aux_so_atom));
       } else {
              event.type = ClientMessage;
              event.serial = 0;
              event.send_event = True;
              event.display = display;
              event.window = w_so;
              event.message_type = aux_so_atom;
              event.format = 32;
              event.data.l[0] = 0;

              XSendEvent(display, w_so, True, 0, (XEvent *)(&event));
              XFlush(display);
       }

       exit(1);
}

Here is the caller graph for this function:

void ButtonTextCallback ( Widget  w,
XtPointer  client_data,
XtPointer  call_data 
)

Definition at line 90 of file aux_ext.c.

{
       XmAnyCallbackStruct *       cb;
       char *               p;
       Display *            display;
       Window               w_so;
       unsigned char        buf[1024];
       int                  size;

       display = XtDisplay(w);
       cb = (XmAnyCallbackStruct *)call_data;
       p = XmTextGetString((Widget)client_data);

       TRACE_MESSAGE('B', ("aux_ext:ButtonTextCallback: %d %s\n", cb->reason, p));
       
       if (None == (w_so = XGetSelectionOwner(display, aux_so_atom))) {
              TRACE_MESSAGE('b', ("aux_ext:ButtonTextCallback: no owner of %08x\n",
                                aux_so_atom));
              return;
       }

       TRACE_MESSAGE('B', ("aux_ext:ButtonTextCallback: owner %08x\n", w_so));

       buf[0] = ((imid & 0xff00) >> 8);
       buf[1] = ((imid & 0x00ff) >> 0);
       buf[2] = ((icid & 0xff00) >> 8);
       buf[3] = ((icid & 0x00ff) >> 0);
       size = strlen(p);
       if (((sizeof (buf)) - 4) < size) {
              size = ((sizeof (buf)) - 4);
       }
       memcpy(buf + 4, p, size);
       XChangeProperty(display, w_so, aux_prop_atom, XA_STRING,
                     8, PropModeReplace, buf, size + 4);

       XFree(p);

       return;
}

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 408 of file aux_ext.c.

{
       XtAppContext  app;
       Display *     display;
       char          atom_name[1024];

       TRACE_MESSAGE_INIT("TRACE_AUX_EXT");

       setlocale(LC_ALL, NULL);
       XtSetLanguageProc(NULL, NULL, NULL);

       toplevel = XtAppInitialize(&app, "aux", NULL, 0,
                               &argc, argv, NULL, NULL, 0);

       display = XtDisplay(toplevel);

       sprintf(atom_name, "htt_%s_%s", *(argv + 0), HTT_AUX_EXT_NAME);
       aux_ext_atom = XInternAtom(display, atom_name, False);
       sprintf(atom_name, "htt_%s_%s", *(argv + 0), HTT_AUX_SO_NAME);
       aux_so_atom = XInternAtom(display, atom_name, False);
       sprintf(atom_name, "htt_%s_%s", *(argv + 0), HTT_AUX_PROP_NAME);
       aux_prop_atom = XInternAtom(display, atom_name, False);
       sprintf(atom_name, "htt_%s_%s", *(argv + 0), HTT_AUX_PROP1_NAME);
       aux_prop1_atom = XInternAtom(display, atom_name, False);

       if (None != XGetSelectionOwner(display, aux_ext_atom)) {
              fprintf(stderr, "%s\n", gettext("aux already exists"));
              exit(1);
       }

       aux = XtVaCreateManagedWidget("aux", xmRowColumnWidgetClass,
                                   toplevel, NULL, 0);

       input = XtCreateManagedWidget("input", xmTextWidgetClass,
                                  aux, NULL, 0);

       button_text = XtCreateManagedWidget("text", xmPushButtonWidgetClass,
                                       aux, NULL, 0);

       XtAddCallback(button_text, XmNarmCallback, ButtonTextCallback, input);

       button_message = XtCreateManagedWidget("message",
                                          xmPushButtonWidgetClass,
                                          aux, NULL, 0);

       XtAddCallback(button_message, XmNarmCallback,
                    ButtonMessageCallback, NULL);

       button_quit = XtCreateManagedWidget("quit", xmPushButtonWidgetClass,
                                       aux, NULL, 0);

       XtAddCallback(button_quit, XmNarmCallback, ButtonQuitCallback, NULL);

       XtRealizeWidget(toplevel);

       aux_window = XtWindow(toplevel);

       if (None != XGetSelectionOwner(display, aux_ext_atom)) {
              fprintf(stderr, "%s\n", gettext("aux already exists"));
              exit(1);
       }
       XSetSelectionOwner(display, aux_ext_atom, aux_window, CurrentTime);
       if (aux_window != XGetSelectionOwner(display, aux_ext_atom)) {
              fprintf(stderr, "%s\n", gettext("aux seems existing"));
              exit(1);
       }

       XtAddEventHandler(toplevel, PropertyChangeMask, False, 
                       AuxEventHandler, NULL);

       XtAddEventHandler(toplevel, NoEventMask, True,
                       AuxEventHandler, NULL);

       ProcessInitialPropertyNotify();

       XtAppMainLoop(app);

       return 0;
}

Here is the call graph for this function:

void ProcessClientMessage ( Widget  w,
XEvent *  event 
)

Definition at line 329 of file aux_ext.c.

{
       Display *            display;
       XClientMessageEvent *       client_message;
       int                  im_id;
       int                  ic_id;
       Window               w_client;
       XPoint               point;
       XWindowAttributes    attr;
       int                  x;
       int                  y;
       Window               w_none;

       client_message = (XClientMessageEvent *)event;

       im_id = client_message->data.s[0];
       ic_id = client_message->data.s[1];
       w_client = client_message->data.l[1];
       point.x = client_message->data.l[2];
       point.y = client_message->data.l[3];

       display = XtDisplay(w);

       if ((client_message->message_type != aux_ext_atom) ||
           (client_message->window != aux_window)) {
              TRACE_MESSAGE('P', ("aux_ext:ProcessClientMessage "
                                "%08x im=%d ic=%d w=%08x x=%d y=%d\n",
                                aux_window,
                                im_id, ic_id, w_client, point.x, point.y));

              return;
       }

       XGetWindowAttributes(display, w_client, &attr);
       XTranslateCoordinates(display, w_client, attr.root,
                           -(attr.border_width), -(attr.border_width),
                           &x, &y, &w_none);

       TRACE_MESSAGE('P', ("aux_ext:ProcessClientMessage "
                         "%08x im=%d ic=%d w=%08x x=%d+%d+%d y=%d+%d+%d\n",
                         aux_window,
                         im_id, ic_id, w_client,
                         attr.x, point.x,
                         attr.y, point.y));

       XtMoveWidget(w, x + point.x, y + point.y);

       return;
}

Here is the caller graph for this function:

Definition at line 199 of file aux_ext.c.

{
       Display *            display;
       long                 long_length;
       Atom                 actual_type_return;
       int                  actual_format_return;
       unsigned long        nitem_return;
       unsigned long        bytes_after_return;
       unsigned char *             prop_return;
       int                  r;
       XTextProperty        text_prop;
       Window               w_so;
       char                 buf[1024];
       int                  len;

       display = XtDisplay(toplevel);

       if (None == (w_so = XGetSelectionOwner(display, aux_so_atom))) {
              TRACE_MESSAGE('I', ("aux_ext:ProcessInitialPropertyNotify: no owner of %08x\n",
                                aux_so_atom));
              return;
       }

       TRACE_MESSAGE('I', ("aux_ext:ProcessInitialPropertyNotify: %08x %08x %08x\n",
                         display, w_so, aux_prop_atom));

       r = XGetWindowProperty(display, w_so,
                            aux_prop1_atom, 0, INT_MAX, True,
                            AnyPropertyType, &actual_type_return,
                            &actual_format_return, &nitem_return,
                            &bytes_after_return, &prop_return);
       if (Success != r) {
              TRACE_MESSAGE('P', ("aux_ext:ProcessInitialPropertyNotify: Fail\n"));
              return;
       }

       TRACE_MESSAGE('P',
                    ("aux_ext:ProcessInitialPropertyNotify: %x\n", actual_format_return));
       switch (actual_type_return) {
       case XA_STRING:
              TRACE_MESSAGE('P',
                           ("aux_ext:ProcessInitialPropertyNotify: \"%.*s\"\n",
                            nitem_return, prop_return));
              imid = *((CARD16 *)(prop_return + 0));
              icid = *((CARD16 *)(prop_return + 2));
              TRACE_MESSAGE('P', ("aux_ext:ProcessInitialPropertyNotify: imid=%08x icid=%08x\n",
                                imid, icid));
              len = (((nitem_return - 4) < (sizeof (buf))) ?
                     (nitem_return - 4) : ((sizeof (buf)) - 1));
              memcpy(buf, prop_return + 4, len);
              buf[len] = '\0';
              XmTextSetString(input, buf);

              break;
       case XA_INTEGER:
              break;
       }

       XFree(prop_return);
       return;
}
void ProcessPropertyNotify ( Widget  w,
XEvent *  event 
)

Definition at line 263 of file aux_ext.c.

{
       Display *            display;
       XPropertyEvent *     prop_event;
       long                 long_length;
       Atom                 actual_type_return;
       int                  actual_format_return;
       unsigned long        nitem_return;
       unsigned long        bytes_after_return;
       unsigned char *             prop_return;
       int                  r;
       XTextProperty        text_prop;
       char                 buf[1024];
       int                  len;

       prop_event = (XPropertyEvent *)event;

       display = XtDisplay(w);

       if ((prop_event->window != aux_window) ||
           (prop_event->atom != aux_prop_atom)) {
              return;
       }

       TRACE_MESSAGE('P', ("aux_ext:ProcessPropertyNotify: %08x %08x %08x %08x %08x\n",
                         display,
                         aux_window, aux_prop_atom,
                         prop_event->window, prop_event->atom));

       r = XGetWindowProperty(display, aux_window,
                            aux_prop_atom, 0, INT_MAX, False,
                            AnyPropertyType, &actual_type_return,
                            &actual_format_return, &nitem_return,
                            &bytes_after_return, &prop_return);
       if (Success != r) {
              TRACE_MESSAGE('P', ("aux_ext:ProcessPropertyNotify: Fail\n"));
              return;
       }

       switch (actual_type_return) {
       case XA_STRING:
              TRACE_MESSAGE('P',
                           ("aux_ext:ProcessPropertyNotify: \"%.*s\"\n",
                            nitem_return, prop_return));
              imid = *((CARD16 *)(prop_return + 0));
              icid = *((CARD16 *)(prop_return + 2));
              TRACE_MESSAGE('P', ("aux_ext:ProcessPropertyNotify: imid=%08x icid=%08x\n",
                                imid, icid));
              len = (((nitem_return - 4) < (sizeof (buf))) ?
                     (nitem_return - 4) : ((sizeof (buf)) - 1));
              memcpy(buf, prop_return + 4, len);
              buf[len] = '\0';
              if ('\0' != buf[0]) {
                     XmTextSetString(input, buf);
              }
              break;
       case XA_INTEGER:
              break;
       }

       XFree(prop_return);
       return;
}

Here is the caller graph for this function:


Variable Documentation

Widget aux

Definition at line 79 of file aux_ext.c.

Definition at line 72 of file aux_ext.c.

Definition at line 74 of file aux_ext.c.

Definition at line 73 of file aux_ext.c.

Definition at line 71 of file aux_ext.c.

Window aux_window

Definition at line 76 of file aux_ext.c.

Definition at line 82 of file aux_ext.c.

Widget button_quit

Definition at line 83 of file aux_ext.c.

Widget button_text

Definition at line 81 of file aux_ext.c.

int icid

Definition at line 85 of file aux_ext.c.

int imid

Definition at line 86 of file aux_ext.c.

Widget input

Definition at line 80 of file aux_ext.c.

Widget toplevel

Definition at line 78 of file aux_ext.c.