1607N/A###############################################################################
1607N/A# Copyright (c) 2008, 2011, Oracle
and/or its affiliates. All rights reserved.
1607N/A# Permission is hereby granted, free of charge, to any person obtaining a
1607N/A# copy of this software and associated documentation files (the "Software"),
1607N/A# to deal in the Software without restriction, including without limitation
1607N/A# the rights to use, copy, modify, merge, publish, distribute, sublicense,
1607N/A#
and/or sell copies of the Software, and to permit persons to whom the
1607N/A# Software is furnished to do so, subject to the following conditions:
1607N/A# The above copyright notice and this permission notice (including the next
1607N/A# paragraph) shall be included in all copies or substantial portions of the
1607N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1607N/A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1607N/A# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1607N/A# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1607N/A# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1607N/A# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1607N/A@@ -45,6 +45,7 @@ in this Software without prior written a
1607N/A@@ -56,6 +57,20 @@ in this Software without prior written a
1607N/A+/* Sun: compose sequence support
1607N/A+ * (state = chars_matched in XComposeStatus)
1607N/A@@ -77,6 +92,11 @@ ComputeMaskFromKeytrans(
1607N/A register struct _XKeytrans *p);
1607N/A+ void SetLed (Display *dpy, int num, int state);
1607N/A struct _XKeytrans *next;/* next on list */
1607N/A char *string; /* string to return when the time comes */
1607N/A@@ -98,6 +118,10 @@ KeyCodetoKeySym(register Display *dpy, K
1607N/A ((int)keycode < dpy->min_keycode) || ((int)keycode > dpy->max_keycode))
1607N/A+/* Sun comment: We need not protect dpy->keysyms[], because,
1607N/A+ * this is * changed only in the initialize routine and
1607N/A syms = &dpy->keysyms[(keycode - dpy->min_keycode) * per];
1607N/A@@ -766,6 +790,9 @@ _XTranslateKey( register Display *dpy,
2433N/A if ((! dpy->keysyms) && (! _XKeyInitialize(dpy)))
2433N/A@@ -780,17 +807,54 @@ _XTranslateKey( register Display *dpy,
2433N/A syms = &dpy->keysyms[(keycode - dpy->min_keycode) * per];
2433N/A while ((per > 2) && (syms[per - 1] == NoSymbol))
2433N/A+ /* Sun: Japanese keypad support */
2375N/A+ /* in case of Hobo keyboards, the keypad would be
2433N/A+ * superimposed on the other (qwerty) keys. So by doing
2375N/A+ * this * check, we would not get the Japanese keysyms
2433N/A+ * on the * Hobo keypad superimposed keys.
2457N/A if ((per > 2) && (modifiers & dpy->mode_switch)) {
2457N/A+/* Sun: ModeSwitch does not apply to function keys (Japanese kbd) */
2457N/A+ if ((modifiers & dpy->num_lock) &&
2457N/A+ (per > 1 && (IsKeypadKey(syms[2]) ))) {
2457N/A if ((modifiers & dpy->num_lock) &&
2457N/A (per > 1 && (IsKeypadKey(syms[1]) || IsPrivateKeypadKey(syms[1])))) {
2457N/A if ((modifiers & ShiftMask) ||
2457N/A ((modifiers & LockMask) && (dpy->lock_meaning == XK_Shift_Lock)))
2457N/A } else if (!(modifiers & ShiftMask) &&
2457N/A (!(modifiers & LockMask) || (dpy->lock_meaning == NoSymbol))) {
2457N/A if ((per == 1) || (syms[1] == NoSymbol))
2457N/A@@ -818,19 +882,41 @@ _XTranslateKey( register Display *dpy,
2457N/A register struct _XKeytrans *p;
2457N/A /* see if symbol rebound, if so, return that string. */
2457N/A for (p = dpy->key_bindings; p; p = p->next) {
2457N/A if (((modifiers & AllMods) == p->state) && (symbol == p->key)) {
2457N/A@@ -844,8 +930,29 @@ _XTranslateKeySym(
2375N/A+/* The check for 0x100500 <= hiBytes < 0x100600 is Sun-specific.
2375N/A+ * This represents Sun's registered range of vendor-specific
2375N/A+ * keysyms. We need the check so that Sun specific keysyms will
2375N/A+ * pass through this check and onto to be handled by
2375N/A+ ((0x100500 <= hiBytes) && (hiBytes < 0x100600)) ||
2375N/A+ * The following hard-coded line is to support the euro sign for legacy apps
2375N/A+ * and single byte codeset locale apps with the euro sign at 0xa4.
2375N/A+ * For any other codeset locales with properly internationalized apps,
2375N/A+ * one must have an entry in the Compose file of the locale that will map
2375N/A+ * the XK_EuroSign keysym to the correct character code value of the locale's
2375N/A+ (symbol == XK_EuroSign) ||
2375N/A (((symbol >= XK_BackSpace) && (symbol <= XK_Clear)) ||
2375N/A+ (symbol == XK_Multi_key) ||
2375N/A@@ -856,15 +963,35 @@ _XTranslateKeySym(
2375N/A+ /* if this is a compose sequence, then HandleComposeSequence
2375N/A+ * already deals w/ this. This is Sun-specific.
1607N/A+ if (HandleComposeSequence(symbol, buffer, keysym, status, &return_val, event)) {
1607N/A /* if X keysym, convert to ascii by grabbing low 7 bits */
1607N/A c = XK_space & 0x7F; /* patch encoding botch */
2375N/A+ else if (symbol == XK_EuroSign)
2375N/A+ c = (unsigned char)0xa4; /* Latin-9 euro symbol code for legacy apps. */
2375N/A /* only apply Control key if it makes sense, else ignore it */
2375N/A if (modifiers & ControlMask) {
2375N/A+ /* Sun: map control characters with high bit set */
1607N/A+ if ((c >= (unsigned char)'\300' && c <= (unsigned char)'\377')) c &= 0x9F;
1607N/A+ /* MIT "standard" control character handling */
1607N/A if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
1607N/A else if (c == '2') c = '\000';
1607N/A else if (c >= '3' && c <= '7') c -= ('3' - '\033');
1607N/A@@ -958,11 +1085,22 @@ XLookupString (
2375N/A+ return _XTranslateKeySym(event->display, keysym, event->state,
2375N/A+ buffer, nbytes, event, status);
2375N/A+ return _XTranslateKeySym(event->display, &symbol, event->state,
1607N/A+ buffer, nbytes, event, status);
/* arguable whether to use (event->state & ~modifiers) here */
return _XTranslateKeySym(event->display, symbol, event->state,
+#endif /* SUNSOFT_KBD */
@@ -1076,3 +1214,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 */
@@ -577,6 +577,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)
@@ -618,6 +632,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))
@@ -744,9 +769,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,
@@ -772,16 +797,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],
@@ -802,7 +827,8 @@ XLookupString ( register XKeyEvent * eve
- return XkbTranslateKeySym(dpy,keysym,new_mods,buffer,nbytes,NULL);
+ return XkbTranslateKeySymExt(dpy,keysym,new_mods,buffer,nbytes,NULL,
@@ -175,10 +175,19 @@ extern int _XTranslateKey(
extern int _XTranslateKeySym(
+ register KeySym * /* symbol */,
register KeySym /* symbol */,
unsigned int /* modifiers */,
+ XKeyEvent * /* event */,
+ XComposeStatus * /* status */
extern int _XLookupString(
@@ -338,6 +347,17 @@ extern Status _XkbReadGetGeometryReply(
+extern int HandleComposeSequence(
+ XComposeStatus *status,
+#endif /* SUNSOFT_KBD */
#endif /* _XKBLIBINT_H_ */
@@ -67,6 +67,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 */
XmbLookupString(XIC ic, XKeyEvent *ev, char *buffer, int nbytes,
KeySym *keysym, Status *status)
- 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;
XwcLookupString(XIC ic, XKeyEvent *ev, wchar_t *buffer, int nchars,
KeySym *keysym, Status *status)
- 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;
@@ -418,12 +452,25 @@ Xutf8LookupString(XIC ic, XKeyEvent *ev,
KeySym *keysym, Status *status)
+ 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;