1 ###############################################################################
2 # Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
4 # Permission is hereby granted, free of charge, to any person obtaining a
5 # copy of this software and associated documentation files (the "Software"),
6 # to deal in the Software without restriction, including without limitation
7 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 # and/or sell copies of the Software, and to permit persons to whom the
9 # Software is furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice (including the next
12 # paragraph) shall be included in all copies or substantial portions of the
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 # DEALINGS IN THE SOFTWARE.
24 --- a/src/KeyBind.c Tue Mar 17 09:26:07 2015
25 +++ b/src/KeyBind.c Tue Mar 17 09:55:54 2015
31 #include <X11/keysymdef.h>
35 #include "Xresource.h"
39 +/* Sun: compose sequence support
40 + * (state = chars_matched in XComposeStatus)
42 +#include "Suncompose.h"
43 +#include <X11/Sunkeysym.h>
49 +#define COMPOSE_LED 2
50 +#endif /* SUNSOFT_KBD */
54 #include "XKBlibint.h"
57 register struct _XKeytrans *p);
60 +static int DoCompose(KeySym first_keysym, KeySym second_keysym, KeySym *result_keysym);
61 + void SetLed (Display *dpy, int num, int state);
62 +#endif /* SUNSOFT_KBD */
65 struct _XKeytrans *next;/* next on list */
66 char *string; /* string to return when the time comes */
68 ((int)keycode < dpy->min_keycode) || ((int)keycode > dpy->max_keycode))
71 +/* Sun comment: We need not protect dpy->keysyms[], because,
72 + * this is * changed only in the initialize routine and
75 syms = &dpy->keysyms[(keycode - dpy->min_keycode) * per];
79 register KeySym *syms;
80 KeySym sym, lsym, usym;
83 + int i, column, KeypadKey;
84 +#endif /* SUNSOFT_KBD */
86 if ((! dpy->keysyms) && (! _XKeyInitialize(dpy)))
88 *modifiers_return = ((ShiftMask|LockMask)
90 syms = &dpy->keysyms[(keycode - dpy->min_keycode) * per];
91 while ((per > 2) && (syms[per - 1] == NoSymbol))
95 + /* Sun: Japanese keypad support */
99 + /* in case of Hobo keyboards, the keypad would be
100 + * superimposed on the other (qwerty) keys. So by doing
101 + * this * check, we would not get the Japanese keysyms
102 + * on the * Hobo keypad superimposed keys.
104 + for (i=0; i < per; i++)
106 + if (IsKeypadKey(syms[i]))
110 +#endif /* SUNSOFT_KBD */
112 if ((per > 2) && (modifiers & dpy->mode_switch)) {
114 +/* Sun: ModeSwitch does not apply to function keys (Japanese kbd) */
117 +#endif /* SUNSOFT_KBD */
122 +#endif /* SUNSOFT_KBD */
126 if ((modifiers & dpy->num_lock) &&
127 + (per > 1 && (IsKeypadKey(syms[2]) ))) {
129 + if ((modifiers & dpy->num_lock) &&
130 (per > 1 && (IsKeypadKey(syms[1]) || IsPrivateKeypadKey(syms[1])))) {
131 +#endif /* SUNSOFT_KBD */
132 if ((modifiers & ShiftMask) ||
133 ((modifiers & LockMask) && (dpy->lock_meaning == XK_Shift_Lock)))
134 *keysym_return = syms[0];
137 + *keysym_return = syms[2];
139 *keysym_return = syms[1];
140 +#endif /* SUNSOFT_KBD */
141 } else if (!(modifiers & ShiftMask) &&
142 (!(modifiers & LockMask) || (dpy->lock_meaning == NoSymbol))) {
143 if ((per == 1) || (syms[1] == NoSymbol))
144 @@ -814,19 +879,41 @@
149 - register KeySym symbol,
150 - unsigned int modifiers,
155 + register KeySym * keysym,
157 + register KeySym keysym,
159 + unsigned int modifiers,
165 + XComposeStatus * status
169 register struct _XKeytrans *p;
171 unsigned long hiBytes;
172 register unsigned char c;
177 +#endif /* SUNSOFT_KBD */
187 +#endif /* SUNSOFT_KBD */
188 /* see if symbol rebound, if so, return that string. */
189 for (p = dpy->key_bindings; p; p = p->next) {
190 if (((modifiers & AllMods) == p->state) && (symbol == p->key)) {
192 hiBytes = symbol >> 8;
196 +/* The check for 0x100500 <= hiBytes < 0x100600 is Sun-specific.
197 + * This represents Sun's registered range of vendor-specific
198 + * keysyms. We need the check so that Sun specific keysyms will
199 + * pass through this check and onto to be handled by
200 + * HandleComposeSequence.
202 + ((0x100500 <= hiBytes) && (hiBytes < 0x100600)) ||
204 + * The following hard-coded line is to support the euro sign for legacy apps
205 + * and single byte codeset locale apps with the euro sign at 0xa4.
206 + * For any other codeset locales with properly internationalized apps,
207 + * one must have an entry in the Compose file of the locale that will map
208 + * the XK_EuroSign keysym to the correct character code value of the locale's
211 + (symbol == XK_EuroSign) ||
212 +#endif /* SUNSOFT_KBD */
213 ((hiBytes == 0xFF) &&
214 (((symbol >= XK_BackSpace) && (symbol <= XK_Clear)) ||
216 + (symbol == XK_Multi_key) ||
217 +#endif /* SUNSOFT_KBD */
218 (symbol == XK_Return) ||
219 (symbol == XK_Escape) ||
220 (symbol == XK_KP_Space) ||
221 @@ -852,15 +960,34 @@
222 (symbol == XK_Delete))))))
226 + /* if this is a compose sequence, then HandleComposeSequence
227 + * already deals w/ this. This is Sun-specific.
229 + if (HandleComposeSequence(symbol, buffer, keysym, status, &return_val, event)) {
232 +#endif /* SUNSOFT_KBD */
234 /* if X keysym, convert to ascii by grabbing low 7 bits */
235 if (symbol == XK_KP_Space)
236 c = XK_space & 0x7F; /* patch encoding botch */
237 else if (hiBytes == 0xFF)
240 + else if (symbol == XK_EuroSign)
241 + c = (unsigned char)0xa4; /* Latin-9 euro symbol code for legacy apps. */
242 +#endif /* SUNSOFT_KBD */
245 /* only apply Control key if it makes sense, else ignore it */
246 if (modifiers & ControlMask) {
248 + /* Sun: map control characters with high bit set */
249 + if ((c >= (unsigned char)'\300' && c <= (unsigned char)'\377')) c &= 0x9F;
250 +#endif /* SUNSOFT_KBD */
252 + /* MIT "standard" control character handling */
253 if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
254 else if (c == '2') c = '\000';
255 else if (c >= '3' && c <= '7') c -= ('3' - '\033');
256 @@ -887,11 +1014,22 @@
257 &modifiers, &symbol))
263 + return _XTranslateKeySym(event->display, keysym, event->state,
264 + buffer, nbytes, event, status);
266 + return _XTranslateKeySym(event->display, &symbol, event->state,
267 + buffer, nbytes, event, status);
272 /* arguable whether to use (event->state & ~modifiers) here */
273 return _XTranslateKeySym(event->display, symbol, event->state,
275 +#endif /* SUNSOFT_KBD */
279 @@ -1003,3 +1141,282 @@
285 +/* added 2 functions:
286 + * HandleComposeSequence and DoCompose;
289 +/* Called from XTranslateKeySym & XkbTranslateKeySymExt
290 + * Look at compose sequence and dead key sequence and try to get
291 + * a Latin-1 character out of it. Return 1 if it is able to
292 + * resolve the lookup based on the info it has, return 0 if it
293 + * can't, then XTranslateKeySym needs to do further processing.
296 +Bool compose_led_is_on = False;
297 +int compose_state = START;
300 +HandleComposeSequence(
304 + XComposeStatus *status,
308 + static char compose_sequence[5]; /* initialized to NULL */
309 + static KeyCode last_composed_keycode; /* initialized to NULL */
310 + static KeySym last_composed_keysym; /* initialized to NULL */
311 + static char watching_keypresses = 0;
312 + static int initialized = 0;
316 + * Even if the caller doesn't pass us a compose structure, we'll still
317 + * support compose sequence processing. Note that the client won't be able
318 + * to support multiple compose sequence clients within a single application.
321 + /* must come first */
322 + if (status != (XComposeStatus *) NULL) {
324 + * The caller provided a structure so we'll track his state * (if reasonable) and we'll point him at our private
325 + * compose_sequence (at bottom). This allows him to implement
326 + * multiple compose sequence clients within a single application.
328 + if (! initialized) { /* start him out right */
329 + compose_state = START;
332 + /* bug 4247009, vivekp, set the compose LED off very first
333 + time, initialization time */
334 + if (compose_led_is_on)
335 + SetLed (event->display,COMPOSE_LED, LedModeOff);
337 + } else { /* then track him */
338 + compose_state = status->chars_matched;
339 + if (compose_state < START || compose_state > ACCEPTED3) compose_state = START;
343 + /* must come second */
344 + if (event->type == KeyPress) {
345 + /* if we've ever seen a KeyPress, we're watching KeyPresses */
346 + watching_keypresses = 1;
347 + } else if (event->type == KeyRelease && watching_keypresses) {
349 + * don't let someone watching both KeyPresses and KeyReleases
350 + * screw us unwittingly. Try to return the right thing.
353 + if (compose_state > START) {
354 + if (compose_state == ACCEPTED3 && event->keycode == last_composed_keycode) {
355 + buffer[0] = last_composed_keysym;
356 + *keysym = last_composed_keysym;
361 + if ((*keysym == XK_Multi_key) ||
362 + (*keysym == SunXK_FA_Circum) ||
363 + (*keysym == SunXK_FA_Tilde) ||
364 + (*keysym == SunXK_FA_Grave) ||
365 + (*keysym == SunXK_FA_Acute) ||
366 + (*keysym == SunXK_FA_Cedilla) ||
367 + (*keysym == SunXK_FA_Diaeresis))
372 + /* XTranslateKeysym filters these out before we get here, but the
373 + * XKB version doesn't so we need to punt these here to avoid breaking
374 + * compose sequences when modifiers like the shift key are pressed.
376 + if (IsModifierKey(*keysym)) {
380 + if (compose_state == ACCEPTED3)
381 + compose_state = START;
383 + /* now we're ready */
384 + switch (compose_state) {
386 + if (*keysym == XK_Multi_key) {
387 + /* bug 4247009, vivekp, set the compose LED when the
388 + compose key is pressed first time. */
389 + SetLed (event->display,COMPOSE_LED, LedModeOn);
390 + compose_state = ACCEPTED1;
391 + compose_led_is_on = True;
393 + else if (*keysym == SunXK_FA_Circum) {
394 + compose_sequence[0] = '^';
395 + compose_state = ACCEPTED2;
397 + else if (*keysym == SunXK_FA_Tilde) {
398 + compose_sequence[0] = '~';
399 + compose_state = ACCEPTED2;
401 + else if (*keysym == SunXK_FA_Cedilla) {
402 + compose_sequence[0] = ',';
403 + compose_state = ACCEPTED2;
405 + else if (*keysym == SunXK_FA_Diaeresis){
406 + compose_sequence[0] = '"';
407 + compose_state = ACCEPTED2;
409 + /* else don't change state */
412 + case ACCEPTED1: /* Got Compose last time */
413 + if (*keysym < ASCII_SET_SIZE) {
414 + if (compose_map[*keysym] >= 0) {
415 + compose_sequence[0] = *keysym;
416 + compose_state = ACCEPTED2;
419 + compose_state = REJECTED;
422 + compose_state = REJECTED;
425 + case ACCEPTED2: /* Got Compose + composable char */
427 + /* bug 4247009, vivekp, set the compose LED off after
428 + compose+composable char is pressed. */
429 + SetLed (event->display,COMPOSE_LED, LedModeOff);
430 + compose_led_is_on = False;
431 + if (*keysym < ASCII_SET_SIZE) {
432 + if (compose_map[*keysym] >= 0) {
433 + compose_sequence[1] = *keysym;
435 + * If the second character is space, compose sequence should return * the first character. See TBITS/NCTTI-5, Section 2.1
436 + * Note: <Compose>+<space>+<space> = non-breaking space
438 + if (compose_sequence[1] == XK_space &&
439 + compose_sequence[0] != XK_space) {
440 + *keysym = compose_sequence[0];
441 + compose_state = ACCEPTED3;
443 + if (compose_sequence[0] <= compose_sequence[1])
444 + ret_val = DoCompose(compose_sequence[0],
445 + compose_sequence[1], keysym);
447 + ret_val = DoCompose(compose_sequence[1],
448 + compose_sequence[0], keysym);
449 + if (ret_val == 1) {
450 + compose_state = ACCEPTED3;
451 + compose_sequence[2] = *keysym;
454 + compose_state = REJECTED;
458 + compose_state = REJECTED;
461 + compose_state = REJECTED;
465 + compose_state = START;
469 + if (compose_state == REJECTED)
471 + /* bug 4247009, vivekp, set the compose LED off after the
472 + compose key pressed second time or composable + 1st char +
474 + SetLed (event->display,COMPOSE_LED, LedModeOff);
475 + compose_led_is_on = False;
476 + compose_state = START;
478 + if (status != (XComposeStatus *) NULL) {
480 + * Ok, since the caller provided a compose structure,
481 + * we need to point him at our private compose_sequence
482 + * and copy the new state back to him.
484 + status->compose_ptr = compose_sequence;
485 + status->chars_matched = compose_state;
488 + if (compose_state == START) {
489 + compose_sequence[0] = '\0';
490 + last_composed_keycode = 0;
491 + last_composed_keysym = 0;
492 + if ((*keysym == XK_Multi_key) ||
493 + (*keysym == SunXK_FA_Circum) ||
494 + (*keysym == SunXK_FA_Tilde) ||
495 + (*keysym == SunXK_FA_Grave) ||
496 + (*keysym == SunXK_FA_Acute) ||
497 + (*keysym == SunXK_FA_Cedilla) ||
498 + (*keysym == SunXK_FA_Diaeresis)) {
505 + compose_sequence[compose_state-1] = '\0';
506 + last_composed_keycode = event->keycode;
507 + last_composed_keysym = *keysym;
509 + if (compose_state == ACCEPTED3) {
510 + buffer[0] = *keysym;
514 + if (compose_state == ACCEPTED2) {
524 + * DoCompose - put result in keysym
527 +DoCompose(KeySym first_keysym, KeySym second_keysym, KeySym *result_keysym)
529 + const ComposeTableEntry *ptr;
531 + /* Note: this code presumes first_keysym rangecheck has
532 + * been done in invoking routine.
534 + ptr = &compose_table[compose_map[first_keysym]];
535 + while (ptr->first == first_keysym) {
536 + if (ptr->second == second_keysym) {
537 + *result_keysym = ptr->result;
546 +SetLed (Display *dpy, int num, int state)
548 + XKeyboardControl led_control;
551 + if ((dpy->xkb_info == NULL) || (num != COMPOSE_LED) ||
552 + XkbSetNamedIndicator(dpy,dpy->xkb_info->composeLED,
553 + True,state,False,NULL) == False)
556 + led_control.led_mode = state;
557 + led_control.led = num;
558 + XChangeKeyboardControl (dpy, KBLed | KBLedMode, &led_control);
561 +#endif /* SUNSOFT_KBD */
562 --- a/src/imConv.c Tue Mar 17 09:56:27 2015
563 +++ b/src/imConv.c Tue Mar 17 10:00:06 2015
568 - count = nbytes - to_len;
570 + count = nbytes - to_len;
579 - count = nbytes - to_len;
581 + count = nbytes - to_len;
590 - count = nbytes - to_len;
592 + count = nbytes - to_len;
597 --- a/src/xkb/XKBBind.c Tue Mar 17 10:00:31 2015
598 +++ b/src/xkb/XKBBind.c Tue Mar 17 10:09:59 2015
601 static int _XkbLoadDpy(Display *dpy);
603 +static int XkbTranslateKeySymExt(
604 + register Display * dpy, register KeySym *sym_rtrn, unsigned int mods,
605 + char *buffer, int nbytes, int *extra_rtrn, XKeyEvent *event,
606 + XComposeStatus *status
610 struct _XKeytrans *next; /* next on list */
611 char *string; /* string to return when the time comes */
616 + /* Call the new extended function but put in NULL for the extra params */
617 + return XkbTranslateKeySymExt(dpy, sym_rtrn, mods, buffer, nbytes, extra_rtrn, NULL, NULL);
621 +XkbTranslateKeySymExt(register Display *dpy,
622 + register KeySym *sym_rtrn,
628 + XComposeStatus *status)
630 register XkbInfoPtr xkb;
635 n = (*cvtr) (priv, *sym_rtrn, buffer, nbytes, extra_rtrn);
637 + /* Add Suns specific compose key handler here. Be sure the special
638 + * globals are set before calling this function.
643 + if (event && HandleComposeSequence(*sym_rtrn, buffer, sym_rtrn,
644 + status, &return_val, event))
648 if ((!xkb->cvt.KSToUpper) && (mods & LockMask)) {
655 - return XkbTranslateKeySym(dpy, keysym, new_mods, buffer, nbytes, NULL);
656 + return XkbTranslateKeySymExt(dpy ,keysym, new_mods, buffer, nbytes, NULL,
661 --- a/src/xkb/XKBlibint.h Tue Mar 17 10:10:40 2015
662 +++ b/src/xkb/XKBlibint.h Tue Mar 17 10:11:56 2015
663 @@ -169,10 +169,19 @@
665 extern int _XTranslateKeySym(
667 - register KeySym /* symbol */,
668 - unsigned int /* modifiers */,
669 - char * /* buffer */,
672 + register KeySym * /* symbol */,
674 + register KeySym /* symbol */,
676 + unsigned int /* modifiers */,
677 + char * /* buffer */,
681 + XKeyEvent * /* event */,
682 + XComposeStatus * /* status */
686 extern int _XLookupString(
692 +extern int HandleComposeSequence(
696 + XComposeStatus *status,
699 +#endif /* SUNSOFT_KBD */
703 #endif /* _XKBLIBINT_H_ */
704 --- a/src/xlibi18n/ICWrap.c Tue Mar 17 10:12:23 2015
705 +++ b/src/xlibi18n/ICWrap.c Tue Mar 17 10:14:56 2015
711 +#define COMPOSE_LED 2
712 +extern void SetLed (Display *dpy, int num, int state);
713 +extern int compose_state, compose_led_is_on;
717 _XIMNestedListToNestedList(
718 XIMArg *nlist, /* This is the new list */
720 XmbLookupString(XIC ic, XKeyEvent *ev, char *buffer, int nbytes,
721 KeySym *keysym, Status *status)
724 - return (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes,
728 + KeySym keysym_temp = NoSymbol;
730 + ret = (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes,
731 + &keysym_temp, status);
733 + if (ev->display->im_filters && !IsModifierKey(keysym_temp) &&
734 + compose_led_is_on && compose_state != 0) {
735 + SetLed (ev->display, COMPOSE_LED, LedModeOff);
736 + compose_led_is_on = False;
740 + *keysym = keysym_temp;
747 XwcLookupString(XIC ic, XKeyEvent *ev, wchar_t *buffer, int nchars,
748 KeySym *keysym, Status *status)
751 - return (*ic->methods->wc_lookup_string) (ic, ev, buffer, nchars,
755 + KeySym keysym_temp = NoSymbol;
757 + ret = (*ic->methods->wc_lookup_string) (ic, ev, buffer, nchars,
758 + &keysym_temp, status);
760 + if (ev->display->im_filters && !IsModifierKey(keysym_temp) &&
761 + compose_led_is_on && compose_state != 0) {
762 + SetLed (ev->display, COMPOSE_LED, LedModeOff);
763 + compose_led_is_on = False;
767 + *keysym = keysym_temp;
773 @@ -418,12 +452,25 @@
774 KeySym *keysym, Status *status)
778 + KeySym keysym_temp = NoSymbol;
780 if (ic->methods->utf8_lookup_string)
781 - return (*ic->methods->utf8_lookup_string) (ic, ev, buffer, nbytes,
783 + ret = (*ic->methods->utf8_lookup_string) (ic, ev, buffer, nbytes,
784 + &keysym_temp, status);
785 else if (ic->methods->mb_lookup_string)
786 - return (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes,
788 + ret = (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes,
789 + &keysym_temp, status);
791 + if (ev->display->im_filters && !IsModifierKey(keysym_temp) &&
792 + compose_led_is_on && compose_state != 0){
793 + SetLed (ev->display, COMPOSE_LED, LedModeOff);
794 + compose_led_is_on = False;
798 + *keysym = keysym_temp;