ia64/xen-unstable

changeset 13566:b1c03f19a4ef

[PVFB] Support keymap localisation.

Conversion to the scan code uses QEMU's function.
Moreover, keyboard support for PVFB uses QEMU's keymaps.
Keyboard default layout is en-us.

Signed-off-by: Junko Ichino <ichino.junko@jp.fujitsu.com>
Signed-off-by: Takanori Kasai <kasai.takanori@jp.fujitsu.com>
Signed-off-by: Hirofumi Tsujimura <tsujimura.hirof@jp.fujitsu.com>
Signed-off-by: Tsunehisa Doi <Doi.Tsunehisa@jp.fujitsu.com>
author kfraser@localhost.localdomain
date Mon Jan 22 16:26:00 2007 +0000 (2007-01-22)
parents a02622437e07
children 200a9c6deeb3
files tools/xenfb/Makefile tools/xenfb/vncfb.c
line diff
     1.1 --- a/tools/xenfb/Makefile	Mon Jan 22 15:59:41 2007 +0000
     1.2 +++ b/tools/xenfb/Makefile	Mon Jan 22 16:26:00 2007 +0000
     1.3 @@ -1,7 +1,7 @@
     1.4  XEN_ROOT=../..
     1.5  include $(XEN_ROOT)/tools/Rules.mk
     1.6  
     1.7 -CFLAGS += -I$(XEN_LIBXC) -I$(XEN_XENSTORE) -I$(XEN_ROOT)/linux-2.6-xen-sparse/include
     1.8 +CFLAGS += -I$(XEN_LIBXC) -I$(XEN_XENSTORE) -I$(XEN_ROOT)/linux-2.6-xen-sparse/include -I$(XEN_ROOT)/tools/ioemu
     1.9  LDFLAGS += -L$(XEN_LIBXC) -L$(XEN_XENSTORE)
    1.10  
    1.11  INSTALL         = install
     2.1 --- a/tools/xenfb/vncfb.c	Mon Jan 22 15:59:41 2007 +0000
     2.2 +++ b/tools/xenfb/vncfb.c	Mon Jan 22 16:26:00 2007 +0000
     2.3 @@ -11,143 +11,51 @@
     2.4  #include <xs.h>
     2.5  #include "xenfb.h"
     2.6  
     2.7 -static int xk2linux[0x10000] = {
     2.8 -	[XK_a] = KEY_A,
     2.9 -	[XK_b] = KEY_B,
    2.10 -	[XK_c] = KEY_C,
    2.11 -	[XK_d] = KEY_D,
    2.12 -	[XK_e] = KEY_E,
    2.13 -	[XK_f] = KEY_F,
    2.14 -	[XK_g] = KEY_G,
    2.15 -	[XK_h] = KEY_H,
    2.16 -	[XK_i] = KEY_I,
    2.17 -	[XK_j] = KEY_J,
    2.18 -	[XK_k] = KEY_K,
    2.19 -	[XK_l] = KEY_L,
    2.20 -	[XK_m] = KEY_M,
    2.21 -	[XK_n] = KEY_N,
    2.22 -	[XK_o] = KEY_O,
    2.23 -	[XK_p] = KEY_P,
    2.24 -	[XK_q] = KEY_Q,
    2.25 -	[XK_r] = KEY_R,
    2.26 -	[XK_s] = KEY_S,
    2.27 -	[XK_t] = KEY_T,
    2.28 -	[XK_u] = KEY_U,
    2.29 -	[XK_v] = KEY_V,
    2.30 -	[XK_w] = KEY_W,
    2.31 -	[XK_x] = KEY_X,
    2.32 -	[XK_y] = KEY_Y,
    2.33 -	[XK_z] = KEY_Z,
    2.34 -	[XK_A] = KEY_A,
    2.35 -	[XK_B] = KEY_B,
    2.36 -	[XK_C] = KEY_C,
    2.37 -	[XK_D] = KEY_D,
    2.38 -	[XK_E] = KEY_E,
    2.39 -	[XK_F] = KEY_F,
    2.40 -	[XK_G] = KEY_G,
    2.41 -	[XK_H] = KEY_H,
    2.42 -	[XK_I] = KEY_I,
    2.43 -	[XK_J] = KEY_J,
    2.44 -	[XK_K] = KEY_K,
    2.45 -	[XK_L] = KEY_L,
    2.46 -	[XK_M] = KEY_M,
    2.47 -	[XK_N] = KEY_N,
    2.48 -	[XK_O] = KEY_O,
    2.49 -	[XK_P] = KEY_P,
    2.50 -	[XK_Q] = KEY_Q,
    2.51 -	[XK_R] = KEY_R,
    2.52 -	[XK_S] = KEY_S,
    2.53 -	[XK_T] = KEY_T,
    2.54 -	[XK_U] = KEY_U,
    2.55 -	[XK_V] = KEY_V,
    2.56 -	[XK_W] = KEY_W,
    2.57 -	[XK_X] = KEY_X,
    2.58 -	[XK_Y] = KEY_Y,
    2.59 -	[XK_Z] = KEY_Z,
    2.60 -	[XK_0] = KEY_0,
    2.61 -	[XK_1] = KEY_1,
    2.62 -	[XK_2] = KEY_2,
    2.63 -	[XK_3] = KEY_3,
    2.64 -	[XK_4] = KEY_4,
    2.65 -	[XK_5] = KEY_5,
    2.66 -	[XK_6] = KEY_6,
    2.67 -	[XK_7] = KEY_7,
    2.68 -	[XK_8] = KEY_8,
    2.69 -	[XK_9] = KEY_9,
    2.70 -	[XK_Return] = KEY_ENTER,
    2.71 -	[XK_BackSpace] = KEY_BACKSPACE,
    2.72 -	[XK_Tab] = KEY_TAB,
    2.73 -	[XK_Pause] = KEY_PAUSE,
    2.74 -	[XK_Delete] = KEY_DELETE,
    2.75 -	[XK_slash] = KEY_SLASH,
    2.76 -	[XK_minus] = KEY_MINUS,
    2.77 -	[XK_equal] = KEY_EQUAL,
    2.78 -	[XK_Escape] = KEY_ESC,
    2.79 -	[XK_braceleft] = KEY_LEFTBRACE,
    2.80 -	[XK_braceright] = KEY_RIGHTBRACE,
    2.81 -	[XK_bracketleft] = KEY_LEFTMETA,
    2.82 -	[XK_bracketright] = KEY_RIGHTMETA,
    2.83 -	[XK_Control_L] = KEY_LEFTCTRL,
    2.84 -	[XK_Control_R] = KEY_RIGHTCTRL,
    2.85 -	[XK_Shift_L] = KEY_LEFTSHIFT,
    2.86 -	[XK_Shift_R] = KEY_RIGHTSHIFT,
    2.87 -	[XK_Alt_L] = KEY_LEFTALT,
    2.88 -	[XK_Alt_R] = KEY_RIGHTALT,
    2.89 -	[XK_semicolon] = KEY_SEMICOLON, 
    2.90 -	[XK_apostrophe] = KEY_APOSTROPHE,
    2.91 -	[XK_grave] = KEY_GRAVE,
    2.92 -	[XK_backslash] = KEY_BACKSLASH,
    2.93 -	[XK_comma] = KEY_COMMA,
    2.94 -	[XK_period] = KEY_DOT,
    2.95 -	[XK_space] = KEY_SPACE,
    2.96 -	[XK_Caps_Lock] = KEY_CAPSLOCK,
    2.97 -	[XK_Num_Lock] = KEY_NUMLOCK,
    2.98 -	[XK_Scroll_Lock] = KEY_SCROLLLOCK,
    2.99 -	[XK_Sys_Req] = KEY_SYSRQ,
   2.100 -	[XK_Linefeed] = KEY_LINEFEED,
   2.101 -	[XK_Home] = KEY_HOME,
   2.102 -	[XK_Pause] = KEY_PAUSE,
   2.103 -	[XK_F1] = KEY_F1,
   2.104 -	[XK_F2] = KEY_F2,
   2.105 -	[XK_F3] = KEY_F3,
   2.106 -	[XK_F4] = KEY_F4,
   2.107 -	[XK_F5] = KEY_F5,
   2.108 -	[XK_F6] = KEY_F6,
   2.109 -	[XK_F7] = KEY_F7,
   2.110 -	[XK_F8] = KEY_F8,
   2.111 -	[XK_F9] = KEY_F9,
   2.112 -	[XK_F10] = KEY_F10,
   2.113 -	[XK_F11] = KEY_F11,
   2.114 -	[XK_F12] = KEY_F12,
   2.115 -	[XK_Up] = KEY_UP,
   2.116 -	[XK_Page_Up] = KEY_PAGEUP,
   2.117 -	[XK_Left] = KEY_LEFT,
   2.118 -	[XK_Right] = KEY_RIGHT,
   2.119 -	[XK_End] = KEY_END,
   2.120 -	[XK_Down] = KEY_DOWN,
   2.121 -	[XK_Page_Down] = KEY_PAGEDOWN,
   2.122 -	[XK_Insert] = KEY_INSERT, 
   2.123 -	[XK_colon] = KEY_SEMICOLON,
   2.124 -	[XK_quotedbl] = KEY_APOSTROPHE,
   2.125 -	[XK_less] = KEY_COMMA,
   2.126 -	[XK_greater] = KEY_DOT,
   2.127 -	[XK_question] = KEY_SLASH,
   2.128 -	[XK_bar] = KEY_BACKSLASH,
   2.129 -	[XK_asciitilde] = KEY_GRAVE,
   2.130 -	[XK_exclam] = KEY_1,
   2.131 -	[XK_at] = KEY_2,
   2.132 -	[XK_numbersign] = KEY_3,
   2.133 -	[XK_dollar] = KEY_4,
   2.134 -	[XK_percent] = KEY_5,
   2.135 -	[XK_asciicircum] = KEY_6,
   2.136 -	[XK_ampersand] = KEY_7,
   2.137 -	[XK_asterisk] = KEY_8,
   2.138 -	[XK_parenleft] = KEY_9,
   2.139 -	[XK_parenright] = KEY_0,
   2.140 -	[XK_underscore] = KEY_MINUS,
   2.141 -	[XK_plus] = KEY_EQUAL,
   2.142 +/* Grab key translation support routines from qemu directory. */
   2.143 +#define qemu_mallocz(size) calloc(1, (size))
   2.144 +static const char *bios_dir = "/usr/share/xen/qemu";
   2.145 +#include "vnc_keysym.h"
   2.146 +#include "keymaps.c"
   2.147 +
   2.148 +static unsigned char atkbd_set2_keycode[512] = {
   2.149 +
   2.150 +	  0, 67, 65, 63, 61, 59, 60, 88,  0, 68, 66, 64, 62, 15, 41,117,
   2.151 +	  0, 56, 42, 93, 29, 16,  2,  0,  0,  0, 44, 31, 30, 17,  3,  0,
   2.152 +	  0, 46, 45, 32, 18,  5,  4, 95,  0, 57, 47, 33, 20, 19,  6,183,
   2.153 +	  0, 49, 48, 35, 34, 21,  7,184,  0,  0, 50, 36, 22,  8,  9,185,
   2.154 +	  0, 51, 37, 23, 24, 11, 10,  0,  0, 52, 53, 38, 39, 25, 12,  0,
   2.155 +	  0, 89, 40,  0, 26, 13,  0,  0, 58, 54, 28, 27,  0, 43,  0, 85,
   2.156 +	  0, 86, 91, 90, 92,  0, 14, 94,  0, 79,124, 75, 71,121,  0,  0,
   2.157 +	 82, 83, 80, 76, 77, 72,  1, 69, 87, 78, 81, 74, 55, 73, 70, 99,
   2.158 +
   2.159 +	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
   2.160 +	217,100,255,  0, 97,165,  0,  0,156,  0,  0,  0,  0,  0,  0,125,
   2.161 +	173,114,  0,113,  0,  0,  0,126,128,  0,  0,140,  0,  0,  0,127,
   2.162 +	159,  0,115,  0,164,  0,  0,116,158,  0,150,166,  0,  0,  0,142,
   2.163 +	157,  0,  0,  0,  0,  0,  0,  0,155,  0, 98,  0,  0,163,  0,  0,
   2.164 +	226,  0,  0,  0,  0,  0,  0,  0,  0,255, 96,  0,  0,  0,143,  0,
   2.165 +	  0,  0,  0,  0,  0,  0,  0,  0,  0,107,  0,105,102,  0,  0,112,
   2.166 +	110,111,108,112,106,103,  0,119,  0,118,109,  0, 99,104,119,  0,
   2.167 +
   2.168  };
   2.169  
   2.170 +static unsigned char atkbd_unxlate_table[128] = {
   2.171 +
   2.172 +	  0,118, 22, 30, 38, 37, 46, 54, 61, 62, 70, 69, 78, 85,102, 13,
   2.173 +	 21, 29, 36, 45, 44, 53, 60, 67, 68, 77, 84, 91, 90, 20, 28, 27,
   2.174 +	 35, 43, 52, 51, 59, 66, 75, 76, 82, 14, 18, 93, 26, 34, 33, 42,
   2.175 +	 50, 49, 58, 65, 73, 74, 89,124, 17, 41, 88,  5,  6,  4, 12,  3,
   2.176 +	 11,  2, 10,  1,  9,119,126,108,117,125,123,107,115,116,121,105,
   2.177 +	114,122,112,113,127, 96, 97,120,  7, 15, 23, 31, 39, 47, 55, 63,
   2.178 +	 71, 79, 86, 94,  8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 87,111,
   2.179 +	 19, 25, 57, 81, 83, 92, 95, 98, 99,100,101,103,104,106,109,110
   2.180 +
   2.181 +};
   2.182 +
   2.183 +unsigned char keycode_table[512];
   2.184 +
   2.185 +static void *kbd_layout;
   2.186 +
   2.187  static int btnmap[] = {
   2.188  	BTN_LEFT, BTN_MIDDLE, BTN_RIGHT, BTN_FORWARD, BTN_BACK
   2.189  };
   2.190 @@ -165,13 +73,16 @@ static void on_kbd_event(rfbBool down, r
   2.191  	 */
   2.192  	rfbScreenInfoPtr server = cl->screen;
   2.193  	struct xenfb *xenfb = server->screenData;
   2.194 -	if (keycode >= sizeof(xk2linux) / sizeof(*xk2linux))
   2.195 -		return;
   2.196 -	if (xk2linux[keycode] == 0)
   2.197 +
   2.198 +	if( keycode >= 'A' && keycode <= 'Z' )
   2.199 +		keycode += 'a' - 'A';
   2.200 +
   2.201 +	int scancode = keycode_table[keysym2scancode(kbd_layout, keycode)];
   2.202 +	if (scancode == 0)
   2.203  		return;
   2.204 -	if (xenfb_send_key(xenfb, down, xk2linux[keycode]) < 0)
   2.205 +	if (xenfb_send_key(xenfb, down, scancode) < 0)
   2.206  		fprintf(stderr, "Key %d %s lost (%s)\n",
   2.207 -			xk2linux[keycode], down ? "down" : "up",
   2.208 +			scancode, down ? "down" : "up",
   2.209  			strerror(errno));
   2.210  }
   2.211  
   2.212 @@ -305,6 +216,7 @@ static struct option options[] = {
   2.213  	{ "title", 1, NULL, 't' },
   2.214  	{ "unused", 0, NULL, 'u' },
   2.215  	{ "listen", 1, NULL, 'l' },
   2.216 +	{ "keymap", 1, NULL, 'k' },
   2.217  	{ NULL }
   2.218  };
   2.219  
   2.220 @@ -318,6 +230,7 @@ int main(int argc, char **argv)
   2.221  	int domid = -1, port = -1;
   2.222  	char *title = NULL;
   2.223  	char *listen = NULL;
   2.224 +	char *keymap = NULL;
   2.225  	bool unused = false;
   2.226  	int opt;
   2.227  	struct xenfb *xenfb;
   2.228 @@ -328,10 +241,11 @@ int main(int argc, char **argv)
   2.229  	int r;
   2.230  	struct xs_handle *xsh;
   2.231  	char vncpasswd[1024];
   2.232 +	int i;
   2.233  
   2.234  	vncpasswd[0] = '\0';
   2.235  
   2.236 -	while ((opt = getopt_long(argc, argv, "d:p:t:u", options,
   2.237 +	while ((opt = getopt_long(argc, argv, "d:p:t:uk:", options,
   2.238  				  NULL)) != -1) {
   2.239  		switch (opt) {
   2.240                  case 'd':
   2.241 @@ -359,6 +273,9 @@ int main(int argc, char **argv)
   2.242                  case 'l':
   2.243  			listen = strdup(optarg);
   2.244  			break;
   2.245 +                case 'k':
   2.246 +			keymap = strdup(optarg);
   2.247 +			break;
   2.248  		case '?':
   2.249  			exit(1);
   2.250                  }
   2.251 @@ -378,7 +295,23 @@ int main(int argc, char **argv)
   2.252  		fprintf(stderr, "Invalid port specified\n");
   2.253  		exit(1);
   2.254          }
   2.255 -            
   2.256 +
   2.257 +	if (keymap == NULL){
   2.258 +		keymap = "en-us";
   2.259 +	}
   2.260 +
   2.261 +	kbd_layout = init_keyboard_layout(keymap);
   2.262 +	if( !kbd_layout ){
   2.263 +		fprintf(stderr, "Invalid keyboard_layout\n");
   2.264 +		exit(1);
   2.265 +        }
   2.266 +
   2.267 +	for (i = 0; i < 128; i++) {
   2.268 +		keycode_table[i] = atkbd_set2_keycode[atkbd_unxlate_table[i]];
   2.269 +		keycode_table[i | 0x80] = 
   2.270 +			atkbd_set2_keycode[atkbd_unxlate_table[i] | 0x80];
   2.271 +	}
   2.272 +
   2.273  	fake_argv[2] = portstr;
   2.274  
   2.275          if (title != NULL)
   2.276 @@ -409,7 +342,8 @@ int main(int argc, char **argv)
   2.277  	}
   2.278  
   2.279  
   2.280 -	if (xenstore_read_vncpasswd(xsh, domid, vncpasswd, sizeof(vncpasswd)/sizeof(char)) < 0) {
   2.281 +	if (xenstore_read_vncpasswd(xsh, domid, vncpasswd,
   2.282 +				    sizeof(vncpasswd)/sizeof(char)) < 0) {
   2.283  		fprintf(stderr, "cannot read VNC password from xenstore\n");
   2.284  		exit(1);
   2.285  	}
   2.286 @@ -432,7 +366,8 @@ int main(int argc, char **argv)
   2.287  	if (vncpasswd[0]) {
   2.288  		char **passwds = malloc(sizeof(char**)*2);
   2.289  		if (!passwds) {
   2.290 -			fprintf(stderr, "cannot allocate memory (%s)\n", strerror(errno));
   2.291 +			fprintf(stderr, "cannot allocate memory (%s)\n",
   2.292 +				strerror(errno));
   2.293  			exit(1);
   2.294  		}
   2.295  		fprintf(stderr, "Registered password\n");