2 * Copyright (c) 2011 Matthieu Herrb
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 #ifdef HAVE_DIX_CONFIG_H
25 #include <dix-config.h>
28 #include <dev/wscons/wsconsio.h>
29 #include <dev/wscons/wsksymdef.h>
31 #include <sys/ioctl.h>
39 #include "config-backends.h"
41 #define WSCONS_KBD_DEVICE "/dev/wskbd"
42 #define WSCONS_MOUSE_PREFIX "/dev/wsmouse"
61 struct nameint kbdvar
[] = {
62 {KB_NODEAD
| KB_SG
, "de_nodeadkeys"},
63 {KB_NODEAD
| KB_SF
, "fr_nodeadkeys"},
65 {KB_DVORAK
| KB_CF
, "fr-dvorak"},
66 {KB_DVORAK
| KB_FR
, "bepo"},
67 {KB_DVORAK
, "dvorak"},
69 {KB_NODEAD
, "nodeadkeys"},
73 struct nameint kbdopt
[] = {
74 {KB_SWAPCTRLCAPS
, "ctrl:swapcaps"},
78 struct nameint kbdmodel
[] = {
79 {WSKBD_TYPE_ZAURUS
, "zaurus"},
84 wscons_add_keyboard(void)
86 InputAttributes attrs
= { };
87 DeviceIntPtr dev
= NULL
;
88 InputOption
*input_options
= NULL
;
89 char *config_info
= NULL
;
94 /* Find keyboard configuration */
95 fd
= open(WSCONS_KBD_DEVICE
, O_RDWR
| O_NONBLOCK
| O_EXCL
);
97 LogMessage(X_ERROR
, "wskbd: open %s: %s\n",
98 WSCONS_KBD_DEVICE
, strerror(errno
));
101 if (ioctl(fd
, WSKBDIO_GETENCODING
, &wsenc
) == -1) {
102 LogMessage(X_WARNING
, "wskbd: ioctl(WSKBDIO_GETENCODING) "
103 "failed: %s\n", strerror(errno
));
107 if (ioctl(fd
, WSKBDIO_GTYPE
, &type
) == -1) {
108 LogMessage(X_WARNING
, "wskbd: ioctl(WSKBDIO_GTYPE) "
109 "failed: %s\n", strerror(errno
));
115 input_options
= input_option_new(input_options
, "_source", "server/wscons");
116 if (input_options
== NULL
)
119 LogMessage(X_INFO
, "config/wscons: checking input device %s\n",
121 input_options
= input_option_new(input_options
, "name", WSCONS_KBD_DEVICE
);
122 input_options
= input_option_new(input_options
, "driver", "kbd");
124 config_info
= Xprintf("wscons:%s", WSCONS_KBD_DEVICE
);
127 if (KB_ENCODING(wsenc
) == KB_USER
) {
128 /* Ignore wscons "user" layout */
129 LogMessageVerb(X_INFO
, 3, "wskbd: ignoring \"user\" layout\n");
130 goto kbd_config_done
;
132 for (i
= 0; kbdenc
[i
].val
; i
++)
133 if (KB_ENCODING(wsenc
) == kbdenc
[i
].val
) {
134 LogMessageVerb(X_INFO
, 3, "wskbd: using layout %s\n",
136 input_options
= input_option_new(input_options
,
137 "xkb_layout", kbdenc
[i
].name
);
140 for (i
= 0; kbdvar
[i
].val
; i
++)
141 if (wsenc
== kbdvar
[i
].val
|| KB_VARIANT(wsenc
) == kbdvar
[i
].val
) {
142 LogMessageVerb(X_INFO
, 3, "wskbd: using variant %s\n",
144 input_options
= input_option_new(input_options
,
145 "xkb_variant", kbdvar
[i
].name
);
148 for (i
= 0; kbdopt
[i
].val
; i
++)
149 if (KB_VARIANT(wsenc
) == kbdopt
[i
].val
) {
150 LogMessageVerb(X_INFO
, 3, "wskbd: using option %s\n",
152 input_options
= input_option_new(input_options
,
153 "xkb_options", kbdopt
[i
].name
);
156 for (i
= 0; kbdmodel
[i
].val
; i
++)
157 if (type
== kbdmodel
[i
].val
) {
158 LogMessageVerb(X_INFO
, 3, "wskbd: using model %s\n",
160 input_options
= input_option_new(input_options
,
161 "xkb_model", kbdmodel
[i
].name
);
166 attrs
.flags
|= ATTR_KEYBOARD
;
167 rc
= NewInputDeviceRequest(input_options
, &attrs
, &dev
);
171 for (; dev
; dev
= dev
->next
) {
172 free(dev
->config_info
);
173 dev
->config_info
= strdup(config_info
);
176 input_option_free_list(&input_options
);
180 wscons_add_pointer(const char *path
, const char *driver
, int flags
)
182 InputAttributes attrs
= { };
183 DeviceIntPtr dev
= NULL
;
184 InputOption
*input_options
= NULL
;
185 char *config_info
= NULL
;
188 config_info
= Xprintf("wscons:%s", path
);
192 input_options
= input_option_new(input_options
, "_source", "server/wscons");
193 if (input_options
== NULL
)
196 input_options
= input_option_new(input_options
, "name", strdup(path
));
197 input_options
= input_option_new(input_options
, "driver", strdup(driver
));
198 input_options
= input_option_new(input_options
, "device", strdup(path
));
199 LogMessage(X_INFO
, "config/wscons: checking input device %s\n", path
);
200 attrs
.flags
|= flags
;
201 rc
= NewInputDeviceRequest(input_options
, &attrs
, &dev
);
205 for (; dev
; dev
= dev
->next
) {
206 free(dev
->config_info
);
207 dev
->config_info
= strdup(config_info
);
210 input_option_free_list(&input_options
);
214 wscons_add_pointers(void)
217 int fd
, i
, wsmouse_type
;
219 /* Check pointing devices */
220 for (i
= 0; i
< 4; i
++) {
221 snprintf(devname
, sizeof(devname
), "%s%d", WSCONS_MOUSE_PREFIX
, i
);
222 LogMessageVerb(X_INFO
, 10, "wsmouse: checking %s\n", devname
);
223 fd
= open_device(devnamem O_RDWR
| O_NONBLOCK
| O_EXCL
);
225 LogMessageVerb(X_WARNING
, 10, "%s: %s\n", devname
, strerror(errno
));
228 if (ioctl(fd
, WSMOUSEIO_GTYPE
, &wsmouse_type
) != 0) {
229 LogMessageVerb(X_WARNING
, 10,
230 "%s: WSMOUSEIO_GTYPE failed\n", devname
);
235 switch (wsmouse_type
) {
236 case WSMOUSE_TYPE_SYNAPTICS
:
237 wscons_add_pointer(devname
, "synaptics", ATTR_TOUCHPAD
);
239 case WSMOUSE_TYPE_TPANEL
:
240 wscons_add_pointer(devname
, "ws", ATTR_TOUCHSCREEN
);
246 /* Add a default entry catching all other mux elements as "mouse" */
247 wscons_add_pointer(WSCONS_MOUSE_PREFIX
, "mouse", ATTR_POINTER
);
251 config_wscons_init(void)
253 wscons_add_keyboard();
254 wscons_add_pointers();
259 config_wscons_fini(void)
261 /* Not much to do ? */