550N/A###############################################################################
550N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
550N/A# Use subject to license terms.
550N/A# Permission is hereby granted, free of charge, to any person obtaining a
550N/A# copy of this software and associated documentation files (the
550N/A# "Software"), to deal in the Software without restriction, including
550N/A# without limitation the rights to use, copy, modify, merge, publish,
550N/A# distribute,
and/or sell copies of the Software, and to permit persons
550N/A# to whom the Software is furnished to do so, provided that the above
550N/A# copyright notice(s) and this permission notice appear in all copies of
550N/A# the Software and that both the above copyright notice(s) and this
550N/A# permission notice appear in supporting documentation.
550N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
550N/A# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
550N/A# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
550N/A# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
550N/A# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
550N/A# INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
550N/A# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
550N/A# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
550N/A# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
550N/A# Except as contained in this notice, the name of a copyright holder
550N/A# shall not be used in advertising or otherwise to promote the sale, use
550N/A# or other dealings in this Software without prior written authorization
550N/A# of the copyright holder.
550N/A@@ -47,6 +47,7 @@ in this Software without prior written a
@@ -58,6 +59,20 @@ in this Software without prior written a
+/* Sun: compose sequence support
+ * (state = chars_matched in XComposeStatus)
+#endif /* SUNSOFT_KBD */
@@ -79,6 +94,11 @@ ComputeMaskFromKeytrans(
register struct _XKeytrans *p);
+ void SetLed (Display *dpy, int num, int state);
+#endif /* SUNSOFT_KBD */
struct _XKeytrans *next;/* next on list */
char *string; /* string to return when the time comes */
@@ -100,6 +120,10 @@ KeyCodetoKeySym(register Display *dpy, K
((int)keycode < dpy->min_keycode) || ((int)keycode > dpy->max_keycode))
+/* Sun comment: We need not protect dpy->keysyms[], because,
+ * this is * changed only in the initialize routine and
syms = &dpy->keysyms[(keycode - dpy->min_keycode) * per];
@@ -768,6 +792,9 @@ _XTranslateKey( register Display *dpy,
+ int i, column, KeypadKey;
+#endif /* SUNSOFT_KBD */
if ((! dpy->keysyms) && (! _XKeyInitialize(dpy)))
@@ -782,17 +809,54 @@ _XTranslateKey( register Display *dpy,
syms = &dpy->keysyms[(keycode - dpy->min_keycode) * per];
while ((per > 2) && (syms[per - 1] == NoSymbol))
+ /* Sun: Japanese keypad support */
+ /* in case of Hobo keyboards, the keypad would be
+ * superimposed on the other (qwerty) keys. So by doing
+ * this * check, we would not get the Japanese keysyms
+ * on the * Hobo keypad superimposed keys.
+ for (i=0; i < per; i++)
+ if (IsKeypadKey(syms[i]))
+#endif /* SUNSOFT_KBD */
if ((per > 2) && (modifiers & dpy->mode_switch)) {
+/* Sun: ModeSwitch does not apply to function keys (Japanese kbd) */
+#endif /* SUNSOFT_KBD */
+#endif /* SUNSOFT_KBD */
+ if ((modifiers & dpy->num_lock) &&
+ (per > 1 && (IsKeypadKey(syms[2]) ))) {
if ((modifiers & dpy->num_lock) &&
(per > 1 && (IsKeypadKey(syms[1]) || IsPrivateKeypadKey(syms[1])))) {
+#endif /* SUNSOFT_KBD */
if ((modifiers & ShiftMask) ||
((modifiers & LockMask) && (dpy->lock_meaning == XK_Shift_Lock)))
*keysym_return = syms[0];
+ *keysym_return = syms[2];
*keysym_return = syms[1];
+#endif /* SUNSOFT_KBD */
} else if (!(modifiers & ShiftMask) &&
(!(modifiers & LockMask) || (dpy->lock_meaning == NoSymbol))) {
if ((per == 1) || (syms[1] == NoSymbol))
@@ -820,19 +884,41 @@ _XTranslateKey( register Display *dpy,
- register KeySym symbol,
- unsigned int modifiers,
+ register KeySym * keysym,
+ register KeySym keysym,
+ unsigned int modifiers,
+ XComposeStatus * status
register struct _XKeytrans *p;
register unsigned char c;
+#endif /* SUNSOFT_KBD */
+#endif /* SUNSOFT_KBD */
/* see if symbol rebound, if so, return that string. */
for (p = dpy->key_bindings; p; p = p->next) {
if (((modifiers & AllMods) == p->state) && (symbol == p->key)) {
@@ -846,8 +932,29 @@ _XTranslateKeySym(
+/* The check for 0x100500 <= hiBytes < 0x100600 is Sun-specific.
+ * This represents Sun's registered range of vendor-specific
+ * keysyms. We need the check so that Sun specific keysyms will
+ * pass through this check and onto to be handled by
+ * HandleComposeSequence.
+ ((0x100500 <= hiBytes) && (hiBytes < 0x100600)) ||
+ * The following hard-coded line is to support the euro sign for legacy apps
+ * and single byte codeset locale apps with the euro sign at 0xa4.
+ * For any other codeset locales with properly internationalized apps,
+ * one must have an entry in the Compose file of the locale that will map
+ * the XK_EuroSign keysym to the correct character code value of the locale's
+ (symbol == XK_EuroSign) ||
+#endif /* SUNSOFT_KBD */
(((symbol >= XK_BackSpace) && (symbol <= XK_Clear)) ||
+ (symbol == XK_Multi_key) ||
+#endif /* SUNSOFT_KBD */
(symbol == XK_KP_Space) ||
@@ -858,15 +965,35 @@ _XTranslateKeySym(
(symbol == XK_Delete))))))
+ /* if this is a compose sequence, then HandleComposeSequence
+ * already deals w/ this. This is Sun-specific.
+ if (HandleComposeSequence(symbol, buffer, keysym, status, &return_val, event)) {
+#endif /* SUNSOFT_KBD */
/* if X keysym, convert to ascii by grabbing low 7 bits */
if (symbol == XK_KP_Space)
c = XK_space & 0x7F; /* patch encoding botch */
else if (hiBytes == 0xFF)
+ else if (symbol == XK_EuroSign)
+ c = (unsigned char)0xa4; /* Latin-9 euro symbol code for legacy apps. */
+#endif /* SUNSOFT_KBD */
/* only apply Control key if it makes sense, else ignore it */
if (modifiers & ControlMask) {
+ /* Sun: map control characters with high bit set */
+ if ((c >= (unsigned char)'\300' && c <= (unsigned char)'\377')) c &= 0x9F;
+#endif /* SUNSOFT_KBD */
+ /* MIT "standard" control character handling */
if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
else if (c == '2') c = '\000';
else if (c >= '3' && c <= '7') c -= ('3' - '\033');
@@ -960,11 +1087,22 @@ XLookupString (
+ return _XTranslateKeySym(event->display, keysym, event->state,
+ buffer, nbytes, event, status);
+ return _XTranslateKeySym(event->display, &symbol, event->state,
+ buffer, nbytes, event, status);
/* arguable whether to use (event->state & ~modifiers) here */
return _XTranslateKeySym(event->display, symbol, event->state,
+#endif /* SUNSOFT_KBD */
@@ -1078,3 +1216,287 @@ ComputeMaskFromKeytrans(
+ * HandleComposeSequence and DoCompose;
+/* Called from XTranslateKeySym & XkbTranslateKeySymExt
+ * Look at compose sequence and dead key sequence and try to get
+ * a Latin-1 character out of it. Return 1 if it is able to
+ * resolve the lookup based on the info it has, return 0 if it
+ * can't, then XTranslateKeySym needs to do further processing.
+Bool compose_led_is_on = False;
+int compose_state = START;
+ XComposeStatus *status,
+ static char compose_sequence[5]; /* initialized to NULL */
+ static KeyCode last_composed_keycode; /* initialized to NULL */
+ static KeySym last_composed_keysym; /* initialized to NULL */
+ static char watching_keypresses = 0;
+ static int initialized = 0;
+ * Even if the caller doesn't pass us a compose structure, we'll still
+ * support compose sequence processing. Note that the client won't be able
+ * to support multiple compose sequence clients within a single application.
+ if (status != (XComposeStatus *) NULL) {
+ * The caller provided a structure so we'll track his state * (if reasonable) and we'll point him at our private
+ * compose_sequence (at bottom). This allows him to implement
+ * multiple compose sequence clients within a single application.
+ if (! initialized) { /* start him out right */
+ /* bug 4247009, vivekp, set the compose LED off very first
+ time, initialization time */
+ SetLed (event->display,COMPOSE_LED, LedModeOff);
+ } else { /* then track him */
+ compose_state = status->chars_matched;
+ if (compose_state < START || compose_state > ACCEPTED3) compose_state = START;
+ if (event->type == KeyPress) {
+ /* if we've ever seen a KeyPress, we're watching KeyPresses */
+ watching_keypresses = 1;
+ } else if (event->type == KeyRelease && watching_keypresses) {
+ * don't let someone watching both KeyPresses and KeyReleases
+ * screw us unwittingly. Try to return the right thing.
+ if (compose_state > START) {
+ if (compose_state == ACCEPTED3 && event->keycode == last_composed_keycode) {
+ buffer[0] = last_composed_keysym;
+ *keysym = last_composed_keysym;
+ if ((*keysym == XK_Multi_key) ||
+ (*keysym == SunXK_FA_Circum) ||
+ (*keysym == SunXK_FA_Tilde) ||
+ (*keysym == SunXK_FA_Grave) ||
+ (*keysym == SunXK_FA_Acute) ||
+ (*keysym == SunXK_FA_Cedilla) ||
+ (*keysym == SunXK_FA_Diaeresis))
+ /* XTranslateKeysym filters these out before we get here, but the
+ * XKB version doesn't so we need to punt these here to avoid breaking
+ * compose sequences when modifiers like the shift key are pressed.
+ if (IsModifierKey(*keysym)) {
+ if (compose_state == ACCEPTED3)
+ switch (compose_state) {
+ if (*keysym == XK_Multi_key) {
+ /* bug 4247009, vivekp, set the compose LED when the
+ compose key is pressed first time. */
+ SetLed (event->display,COMPOSE_LED, LedModeOn);
+ compose_state = ACCEPTED1;
+ compose_led_is_on = True;
+ else if (*keysym == SunXK_FA_Circum) {
+ compose_sequence[0] = '^';
+ compose_state = ACCEPTED2;
+ else if (*keysym == SunXK_FA_Tilde) {
+ compose_sequence[0] = '~';
+ compose_state = ACCEPTED2;
+ else if (*keysym == SunXK_FA_Grave) {
+ compose_sequence[0] = '`';
+ compose_state = ACCEPTED2;
+ else if (*keysym == SunXK_FA_Acute) {
+ compose_sequence[0] = '\'';
+ compose_state = ACCEPTED2;
+ else if (*keysym == SunXK_FA_Cedilla) {
+ compose_sequence[0] = ',';
+ compose_state = ACCEPTED2;
+ else if (*keysym == SunXK_FA_Diaeresis){
+ compose_sequence[0] = '"';
+ compose_state = ACCEPTED2;
+ /* else don't change state */
+ case ACCEPTED1: /* Got Compose last time */
+ if (*keysym < ASCII_SET_SIZE) {
+ if (compose_map[*keysym] >= 0) {
+ compose_sequence[0] = *keysym;
+ compose_state = ACCEPTED2;
+ compose_state = REJECTED;
+ compose_state = REJECTED;
+ case ACCEPTED2: /* Got Compose + composable char */
+ /* bug 4247009, vivekp, set the compose LED off after
+ compose+composable char is pressed. */
+ SetLed (event->display,COMPOSE_LED, LedModeOff);
+ compose_led_is_on = False;
+ if (*keysym < ASCII_SET_SIZE) {
+ if (compose_map[*keysym] >= 0) {
+ compose_sequence[1] = *keysym;
+ * If the second character is space, compose sequence should return * the first character. See
TBITS/NCTTI-5, Section 2.1
+ * Note: <Compose>+<space>+<space> = non-breaking space
+ if (compose_sequence[1] == XK_space &&
+ compose_sequence[0] != XK_space) {
+ *keysym = compose_sequence[0];
+ compose_state = ACCEPTED3;
+ if (compose_sequence[0] <= compose_sequence[1])
+ ret_val = DoCompose(compose_sequence[0],
+ compose_sequence[1], keysym);
+ ret_val = DoCompose(compose_sequence[1],
+ compose_sequence[0], keysym);
+ compose_state = ACCEPTED3;
+ compose_sequence[2] = *keysym;
+ compose_state = REJECTED;
+ compose_state = REJECTED;
+ compose_state = REJECTED;
+ if (compose_state == REJECTED)
+ /* bug 4247009, vivekp, set the compose LED off after the
+ compose key pressed second time or composable + 1st char +
+ SetLed (event->display,COMPOSE_LED, LedModeOff);
+ compose_led_is_on = False;
+ if (status != (XComposeStatus *) NULL) {
+ * Ok, since the caller provided a compose structure,
+ * we need to point him at our private compose_sequence
+ * and copy the new state back to him.
+ status->compose_ptr = compose_sequence;
+ status->chars_matched = compose_state;
+ if (compose_state == START) {
+ compose_sequence[0] = '\0';
+ last_composed_keycode = 0;
+ last_composed_keysym = 0;
+ if ((*keysym == XK_Multi_key) ||
+ (*keysym == SunXK_FA_Circum) ||
+ (*keysym == SunXK_FA_Tilde) ||
+ (*keysym == SunXK_FA_Grave) ||
+ (*keysym == SunXK_FA_Acute) ||
+ (*keysym == SunXK_FA_Cedilla) ||
+ (*keysym == SunXK_FA_Diaeresis)) {
+ compose_sequence[compose_state-1] = '\0';
+ last_composed_keycode = event->keycode;
+ last_composed_keysym = *keysym;
+ if (compose_state == ACCEPTED3) {
+ * DoCompose - put result in keysym
+DoCompose(KeySym first_keysym, KeySym second_keysym, KeySym *result_keysym)
+ ComposeTableEntry *ptr;
+ /* Note: this code presumes first_keysym rangecheck has
+ * been done in invoking routine.
+ ptr = &compose_table[compose_map[first_keysym]];
+ while (ptr->first == first_keysym) {
+ if (ptr->second == second_keysym) {
+ *result_keysym = ptr->result;
+SetLed (Display *dpy, int num, int state)
+ XKeyboardControl led_control;
+ if ((dpy->xkb_info == NULL) || (num != COMPOSE_LED) ||
+ XkbSetNamedIndicator(dpy,dpy->xkb_info->composeLED,
+ True,state,False,NULL) == False)
+ XChangeKeyboardControl (dpy, KBLed | KBLedMode, &led_control);
+#endif /* SUNSOFT_KBD */
@@ -582,6 +582,20 @@ XkbTranslateKeySym( register Display * d
+ /* Call the new extended function but put in NULL for the extra params */
+ return XkbTranslateKeySymExt(dpy, sym_rtrn, mods, buffer, nbytes, extra_rtrn, NULL, NULL);
+XkbTranslateKeySymExt( register Display * dpy,
+ register KeySym * sym_rtrn,
+ XComposeStatus * status)
@@ -623,6 +637,17 @@ XkbTranslateKeySym( register Display * d
n = (*cvtr)(priv,*sym_rtrn,buffer,nbytes,extra_rtrn);
+ /* Add Suns specific compose key handler here. Be sure the special
+ * globals are set before calling this function.
+ if (event && HandleComposeSequence(*sym_rtrn, buffer, sym_rtrn,
+ status, &return_val, event))
@@ -749,9 +770,9 @@ XLookupString ( register XKeyEvent * eve
for (n=len=0;
rtrn.sym[n]!=XK_VoidSymbol;n++) {
- len+= XkbTranslateKeySym(dpy,&
rtrn.sym[n],new_mods,
+ len+= XkbTranslateKeySymExt(dpy,&
rtrn.sym[n],new_mods,
@@ -777,16 +798,16 @@ XLookupString ( register XKeyEvent * eve
len = (int)strlen(buffer);
- len = XkbTranslateKeySym(dpy,keysym,new_mods,
+ len = XkbTranslateKeySymExt(dpy,keysym,new_mods,
for (n=0;
rtrn.sym[n]!=XK_VoidSymbol;n++) {
- len+= XkbTranslateKeySym(dpy,&
rtrn.sym[n],
+ len+= XkbTranslateKeySymExt(dpy,&
rtrn.sym[n],
@@ -807,7 +828,8 @@ XLookupString ( register XKeyEvent * eve
- return XkbTranslateKeySym(dpy,keysym,new_mods,buffer,nbytes,NULL);
+ return XkbTranslateKeySymExt(dpy,keysym,new_mods,buffer,nbytes,NULL,
@@ -177,10 +177,19 @@ extern int _XTranslateKey(
extern int _XTranslateKeySym(
+ register KeySym * /* symbol */,
register KeySym /* symbol */,
unsigned int /* modifiers */,
+ XKeyEvent * /* event */,
+ XComposeStatus * /* status */
extern int _XLookupString(
@@ -340,6 +349,17 @@ extern Status _XkbReadGetGeometryReply(
+extern int HandleComposeSequence(
+ XComposeStatus *status,
+#endif /* SUNSOFT_KBD */
#endif /* _XKBLIBINT_H_ */
@@ -73,6 +73,12 @@ from The Open Group.
+extern void SetLed (Display *dpy, int num, int state);
+extern int compose_state, compose_led_is_on;
_XIMNestedListToNestedList(
XIMArg *nlist, /* This is the new list */
@@ -415,9 +421,23 @@ XmbLookupString(ic, ev, buffer, nbytes,
- return (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes,
+ KeySym keysym_temp = NoSymbol;
+ ret = (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes,
+ if (ev->display->im_filters && !IsModifierKey(keysym_temp) &&
+ compose_led_is_on && compose_state != 0) {
+ SetLed (ev->display, COMPOSE_LED, LedModeOff);
+ compose_led_is_on = False;
@@ -430,9 +450,23 @@ XwcLookupString(ic, ev, buffer, nchars,
- return (*ic->methods->wc_lookup_string) (ic, ev, buffer, nchars,
+ KeySym keysym_temp = NoSymbol;
+ ret = (*ic->methods->wc_lookup_string) (ic, ev, buffer, nchars,
+ if (ev->display->im_filters && !IsModifierKey(keysym_temp) &&
+ compose_led_is_on && compose_state != 0) {
+ SetLed (ev->display, COMPOSE_LED, LedModeOff);
+ compose_led_is_on = False;
@@ -446,12 +480,25 @@ Xutf8LookupString(ic, ev, buffer, nbytes
+ KeySym keysym_temp = NoSymbol;
if (ic->methods->utf8_lookup_string)
- return (*ic->methods->utf8_lookup_string) (ic, ev, buffer, nbytes,
+ ret = (*ic->methods->utf8_lookup_string) (ic, ev, buffer, nbytes,
else if (ic->methods->mb_lookup_string)
- return (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes,
+ ret = (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes,
+ if (ev->display->im_filters && !IsModifierKey(keysym_temp) &&
+ compose_led_is_on && compose_state != 0){
+ SetLed (ev->display, COMPOSE_LED, LedModeOff);
+ compose_led_is_on = False;