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"
56
KB_OVRENC, KB_ENCTAB, {
59
struct nameint kbdvar[] = {
60
{KB_NODEAD | KB_SG, "de_nodeadkeys"},
61
{KB_NODEAD | KB_SF, "fr_nodeadkeys"},
63
{KB_DVORAK | KB_CF, "fr-dvorak"},
64
{KB_DVORAK | KB_FR, "bepo"},
65
{KB_DVORAK, "dvorak"},
67
{KB_NODEAD, "nodeadkeys"},
71
struct nameint kbdopt[] = {
72
{KB_SWAPCTRLCAPS, "ctrl:swapcaps"},
76
struct nameint kbdmodel[] = {
77
{WSKBD_TYPE_ZAURUS, "zaurus"},
82
wscons_add_keyboard(void)
84
InputAttributes attrs = { };
85
DeviceIntPtr dev = NULL;
86
InputOption *input_options = NULL;
87
char *config_info = NULL;
92
/* Find keyboard configuration */
93
fd = open(WSCONS_KBD_DEVICE, O_RDWR | O_NONBLOCK | O_EXCL);
95
LogMessage(X_ERROR, "wskbd: open %s: %s\n",
96
WSCONS_KBD_DEVICE, strerror(errno));
99
if (ioctl(fd, WSKBDIO_GETENCODING, &wsenc) == -1) {
100
LogMessage(X_WARNING, "wskbd: ioctl(WSKBDIO_GETENCODING) "
101
"failed: %s\n", strerror(errno));
105
if (ioctl(fd, WSKBDIO_GTYPE, &type) == -1) {
106
LogMessage(X_WARNING, "wskbd: ioctl(WSKBDIO_GTYPE) "
107
"failed: %s\n", strerror(errno));
113
input_options = input_option_new(input_options, "_source", "server/wscons");
114
if (input_options == NULL)
117
LogMessage(X_INFO, "config/wscons: checking input device %s\n",
119
input_options = input_option_new(input_options, "name", WSCONS_KBD_DEVICE);
120
input_options = input_option_new(input_options, "driver", "kbd");
122
config_info = Xprintf("wscons:%s", WSCONS_KBD_DEVICE);
125
if (KB_ENCODING(wsenc) == KB_USER) {
126
/* Ignore wscons "user" layout */
127
LogMessageVerb(X_INFO, 3, "wskbd: ignoring \"user\" layout\n");
128
goto kbd_config_done;
130
for (i = 0; kbdenc[i].val; i++)
131
if (KB_ENCODING(wsenc) == kbdenc[i].val) {
132
LogMessageVerb(X_INFO, 3, "wskbd: using layout %s\n",
134
input_options = input_option_new(input_options,
135
"xkb_layout", kbdenc[i].name);
138
for (i = 0; kbdvar[i].val; i++)
139
if (wsenc == kbdvar[i].val || KB_VARIANT(wsenc) == kbdvar[i].val) {
140
LogMessageVerb(X_INFO, 3, "wskbd: using variant %s\n",
142
input_options = input_option_new(input_options,
143
"xkb_variant", kbdvar[i].name);
146
for (i = 0; kbdopt[i].val; i++)
147
if (KB_VARIANT(wsenc) == kbdopt[i].val) {
148
LogMessageVerb(X_INFO, 3, "wskbd: using option %s\n",
150
input_options = input_option_new(input_options,
151
"xkb_options", kbdopt[i].name);
154
for (i = 0; kbdmodel[i].val; i++)
155
if (type == kbdmodel[i].val) {
156
LogMessageVerb(X_INFO, 3, "wskbd: using model %s\n",
158
input_options = input_option_new(input_options,
159
"xkb_model", kbdmodel[i].name);
164
attrs.flags |= ATTR_KEYBOARD;
165
rc = NewInputDeviceRequest(input_options, &attrs, &dev);
169
for (; dev; dev = dev->next) {
170
free(dev->config_info);
171
dev->config_info = strdup(config_info);
174
input_option_free_list(&input_options);
178
wscons_add_pointer(const char *path, const char *driver, int flags)
180
InputAttributes attrs = { };
181
DeviceIntPtr dev = NULL;
182
InputOption *input_options = NULL;
183
char *config_info = NULL;
186
config_info = Xprintf("wscons:%s", path);
190
input_options = input_option_new(input_options, "_source", "server/wscons");
191
if (input_options == NULL)
194
input_options = input_option_new(input_options, "name", strdup(path));
195
input_options = input_option_new(input_options, "driver", strdup(driver));
196
input_options = input_option_new(input_options, "device", strdup(path));
197
LogMessage(X_INFO, "config/wscons: checking input device %s\n", path);
198
attrs.flags |= flags;
199
rc = NewInputDeviceRequest(input_options, &attrs, &dev);
203
for (; dev; dev = dev->next) {
204
free(dev->config_info);
205
dev->config_info = strdup(config_info);
208
input_option_free_list(&input_options);
212
wscons_add_pointers(void)
215
int fd, i, wsmouse_type;
217
/* Check pointing devices */
218
for (i = 0; i < 4; i++) {
219
snprintf(devname, sizeof(devname), "%s%d", WSCONS_MOUSE_PREFIX, i);
220
LogMessageVerb(X_INFO, 10, "wsmouse: checking %s\n", devname);
221
fd = open_device(devnamem O_RDWR | O_NONBLOCK | O_EXCL);
223
LogMessageVerb(X_WARNING, 10, "%s: %s\n", devname, strerror(errno));
226
if (ioctl(fd, WSMOUSEIO_GTYPE, &wsmouse_type) != 0) {
227
LogMessageVerb(X_WARNING, 10,
228
"%s: WSMOUSEIO_GTYPE failed\n", devname);
233
switch (wsmouse_type) {
234
case WSMOUSE_TYPE_SYNAPTICS:
235
wscons_add_pointer(devname, "synaptics", ATTR_TOUCHPAD);
237
case WSMOUSE_TYPE_TPANEL:
238
wscons_add_pointer(devname, "ws", ATTR_TOUCHSCREEN);
244
/* Add a default entry catching all other mux elements as "mouse" */
245
wscons_add_pointer(WSCONS_MOUSE_PREFIX, "mouse", ATTR_POINTER);
249
config_wscons_init(void)
251
wscons_add_keyboard();
252
wscons_add_pointers();
257
config_wscons_fini(void)
259
/* Not much to do ? */