Back to index

im-sdk  12.3.91
Functions
iiimpUtil.c File Reference
#include <stdio.h>
#include "iiimpReq.h"
#include "iiimpIM.h"
#include "iiimpUtil.h"
#include "KeyMap.h"

Go to the source code of this file.

Functions

static char * IMToString (CARD16 *chars, int char_length)
static unsigned int str_to_mod (char *str)
static void add_conversion_keys_from_resource (XrmDatabase rdb, IIIMCF_keyevent **ppkev, int *pnum)
static void register_conversion_keys_from_resource (XimCommon im)
void RegisterTriggerKeys (XimCommon im)
static Bool isMatchKey (XEvent *ev, const IIIMCF_keyevent *pkev, int num)
Bool isConversionOnKey (XimCommon im, XEvent *ev)
Bool isConversionOffKey (XimCommon im, XEvent *ev)

Function Documentation

static void add_conversion_keys_from_resource ( XrmDatabase  rdb,
IIIMCF_keyevent **  ppkev,
int *  pnum 
) [static]

Definition at line 106 of file iiimpUtil.c.

{
    char *buf = NULL;
    char *dummy = NULL;
    char *p;
    Bool is_modmask;
    unsigned int mod, mod_mask, tmp_mask;
    char *ret_type;
    XrmValue rmvalue;
    char *names = NULL;
    int num = *pnum;
    IIIMCF_keyevent *pkev = *ppkev;
    IIIMCF_keyevent kev;
    int code;

    if (!XrmGetResource(rdb, "conversionOnKeys", "ConversionOnKeys",
                     &ret_type, &rmvalue))
       return;

    names = (char *) malloc(rmvalue.size + 1);
    if (!names) goto err;
    strncpy(names, rmvalue.addr, rmvalue.size);
    names[rmvalue.size] = '\0';

    dummy = buf = (char *) malloc(strlen(names) + 1);
    if (!dummy) goto err;
    strcpy(buf, names);

    is_modmask = False;
    mod = 0;
    while (*buf) {
        switch(*buf) {
          case '~':
          if (is_modmask)
              goto err;
          is_modmask = True;
          buf += 1;
          break;
          case '<':
          p = strchr(buf+1, '>');
          if (!p)
              goto err;
          *p = 0;
          if ((tmp_mask = str_to_mod(buf + 1)) == 0)
              goto err;
          if (is_modmask) {
              mod_mask |= tmp_mask;
              is_modmask = False;
          } else {
              mod |= tmp_mask;
          }
          buf = p + 1;
          if (!*buf)
              goto err;
          break;
          default:
          p = strchr(buf, ' ');
          if (p) *p = 0;

          code = XStringToKeysym(buf);
          if (XKeysym_To_IIIMCF_keyevent(code, mod, &kev)) {
              pkev = (IIIMCF_keyevent*) realloc(pkev, sizeof(IIIMCF_keyevent) * (num + 1));
              if (!pkev) goto err;
              pkev[num] = kev;
              num++;
              *ppkev = pkev;
              *pnum = num;
          }

          mod = 0;
          if (p) {
              buf = p + 1;
              break;
          } else {
              goto done;
          }
        }
    }

done:
err:
    if (names) free(names);
    if (dummy) free(dummy);
    return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* IMToString ( CARD16 chars,
int  char_length 
) [static]

Definition at line 51 of file iiimpUtil.c.

{
    char *ptr;
    int i;
    int total_size;
    unsigned char *data;

    if (char_length & 0x01) {
       total_size = (2 + (2 * char_length));
    } else {
       total_size = (2 + (2 * char_length) + 2); /* padding */
    }

    data = (unsigned char *)Xmalloc(total_size);
    if (!data) {
       return NULL;
    }

    ptr = (char *)data;
    req_put16(ptr, (2 * char_length));
    for (i = 0; i < char_length; i++) {
       req_put16(ptr, *(chars + i));
    }
    if (0x00 == (char_length & 0x01)) {
       req_put16(ptr, 0);
    }

    return (char*)data;
}
Bool isConversionOffKey ( XimCommon  im,
XEvent *  ev 
)

Definition at line 292 of file iiimpUtil.c.

{
    if (!XIM_IS_IIIMP(im)) return False;
    return isMatchKey(ev, XIM_IIIMP(im, pkev_off), XIM_IIIMP(im, off_keys_num));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Bool isConversionOnKey ( XimCommon  im,
XEvent *  ev 
)

Definition at line 282 of file iiimpUtil.c.

{
    if (!XIM_IS_IIIMP(im)) return False;
    return isMatchKey(ev, XIM_IIIMP(im, pkev_on), XIM_IIIMP(im, on_keys_num));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Bool isMatchKey ( XEvent *  ev,
const IIIMCF_keyevent pkev,
int  num 
) [static]

Definition at line 257 of file iiimpUtil.c.

{
    int i;
    IIIMCF_keyevent kev;

    if (ev->type != KeyPress) return False;
    if (ev->xkey.keycode == XIM_COMPOSE_KEYCODE) return False;
    if (!XKeyEvent_To_IIIMCF_keyevent((XKeyEvent*)ev, &kev)) return False;

    for (i = 0; i < num; i++, pkev++) {
       if ((kev.keycode == pkev->keycode)
           /* && (kev.keychar == pkev->keychar )*/
           && (kev.modifier == pkev->modifier)) {
           return True;
       }
    }

    return False;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void register_conversion_keys_from_resource ( XimCommon  im) [static]

Definition at line 197 of file iiimpUtil.c.

{
    XrmDatabase rdb = im->core.rdb;

    if (!rdb) return;
    add_conversion_keys_from_resource(rdb, &XIM_IIIMP(im, pkev_on),
                                  &XIM_IIIMP(im, on_keys_num));
    add_conversion_keys_from_resource(rdb, &XIM_IIIMP(im, pkev_off),
                                  &XIM_IIIMP(im, off_keys_num));

    return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 213 of file iiimpUtil.c.

{
    int on_num, off_num;
    const IIIMCF_keyevent *pkev_on, *pkev_off;

    if (!XIM_IS_IIIMP(im)) return;

    if (XIM_IIIMP(im, pkev_on)) {
       Xfree(XIM_IIIMP(im, pkev_on));
       XIM_IIIMP(im, on_keys_num) = 0;
    }
    if (XIM_IIIMP(im, pkev_off)) {
       Xfree(XIM_IIIMP(im, pkev_off));
       XIM_IIIMP(im, off_keys_num) = 0;
    }

    if (iiimcf_get_trigger_keys(XIM_IIIMP(im, handle),
                            &on_num, &pkev_on,
                            &off_num, &pkev_off)
       == IIIMF_STATUS_SUCCESS) {
       IIIMCF_keyevent *pkev;

       pkev = (IIIMCF_keyevent*) Xmalloc(sizeof(*pkev) * on_num);
       if (pkev) {
           memcpy(pkev, pkev_on, sizeof(*pkev) * on_num);
           XIM_IIIMP(im, on_keys_num) = on_num;
           XIM_IIIMP(im, pkev_on) = pkev;
       }
       pkev = (IIIMCF_keyevent*) Xmalloc(sizeof(*pkev) * off_num);
       if (pkev) {
           memcpy(pkev, pkev_off, sizeof(*pkev) * off_num);
           XIM_IIIMP(im, off_keys_num) = off_num;
           XIM_IIIMP(im, pkev_off) = pkev;
       }
    }

    register_conversion_keys_from_resource(im);

    return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned int str_to_mod ( char *  str) [static]

Definition at line 89 of file iiimpUtil.c.

{
    if(!strcmp("Ctrl", str))
        return ControlMask;
    else if(!strcmp("Shift", str))
        return ShiftMask;
    else if(!strcmp("Meta", str))
        return Mod4Mask;
    else if(!strcmp("Alt", str))
        return Mod1Mask;
    else
        return 0;
}

Here is the caller graph for this function: