~ubuntu-branches/ubuntu/quantal/xorg-server/quantal-proposed

« back to all changes in this revision

Viewing changes to config/wscons.c

  • Committer: Package Import Robot
  • Author(s): Bryce Harrington, Maarten Lankhorst, Bryce Harrington
  • Date: 2012-06-04 19:12:23 UTC
  • mfrom: (0.11.40 sid)
  • Revision ID: package-import@ubuntu.com-20120604191223-7gt8pm5dtw7k340f
Tags: 2:1.12.1.902-1ubuntu1
[ Maarten Lankhorst ]
* Refresh patches to apply on x-server 1.12
  - patch-x-indent.sh from xorg-pkg-tools was used to redo coding style
* Deleted following patches because they have been committed upstream
  - 224_return_BadWindow_not_BadMatch.diff
  - 225_non-root_config_paths.patch
  - 505_query_pointer_touchscreen.patch
  - 506_touchscreen_pointer_emulation_checks.patch
  - 507_touchscreen_fixes.patch
* Non-trivial refresh of 500_pointer_barrier_thresholds.diff, based on 
  xorg-edgers
* Rest was refreshed with patch-x-indent.sh to survive coding style changes
* Add upstream patches for proper device disabling:
  - 510-dix-return-early-from-DisableDevice-if-the-device-is.patch
  - 511-dix-move-freeing-the-sprite-into-a-function.patch
  - 512-dix-free-the-sprite-when-disabling-the-device.patch
  - 513-dix-disable-non-sprite-owners-first-when-disabling-p.patch
  - 514-Xi-drop-forced-unpairing-when-changing-the-hierarchy.patch
  - 515-dix-disable-all-devices-before-shutdown.patch

[ Bryce Harrington ]
* Drop 209_add_legacy_bgnone_option.patch: lightdm and other *dm's have
  switched to the new standard -background option.  No need to continue
  providing the legacy -nr synonym.
* Drop 201_report-real-dpi.patch:  Commented out in series.
* Drop 198_nohwaccess.patch: Rootless-X no longer a development focus
  for us; the patch would need reworked anyway to provide proper
  support.
* Drop 166_nullptr_xinerama_keyrepeat.patch: Fixed differently upstream
  in commit 24e682d0, as verified by original reporter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2011 Matthieu Herrb
 
3
 *
 
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:
 
10
 *
 
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
 
13
 * Software.
 
14
 *
 
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.
 
22
 */
 
23
 
 
24
#ifdef HAVE_DIX_CONFIG_H
 
25
#include <dix-config.h>
 
26
#endif
 
27
 
 
28
#include <dev/wscons/wsconsio.h>
 
29
#include <dev/wscons/wsksymdef.h>
 
30
 
 
31
#include <sys/ioctl.h>
 
32
#include <errno.h>
 
33
#include <string.h>
 
34
#include <unistd.h>
 
35
 
 
36
#include "input.h"
 
37
#include "inputstr.h"
 
38
#include "os.h"
 
39
#include "config-backends.h"
 
40
 
 
41
#define WSCONS_KBD_DEVICE "/dev/wskbd"
 
42
#define WSCONS_MOUSE_PREFIX "/dev/wsmouse"
 
43
 
 
44
#define KB_OVRENC \
 
45
        { KB_UK,        "gb" }, \
 
46
        { KB_SV,        "se" }, \
 
47
        { KB_SG,        "ch" }, \
 
48
        { KB_SF,        "ch" }, \
 
49
        { KB_LA,        "latam" }, \
 
50
        { KB_CF,        "ca" }
 
51
 
 
52
struct nameint {
 
53
    int val;
 
54
    char *name;
 
55
} kbdenc[] = {
 
56
    KB_OVRENC, KB_ENCTAB, {
 
57
0}};
 
58
 
 
59
struct nameint kbdvar[] = {
 
60
    {KB_NODEAD | KB_SG, "de_nodeadkeys"},
 
61
    {KB_NODEAD | KB_SF, "fr_nodeadkeys"},
 
62
    {KB_SF, "fr"},
 
63
    {KB_DVORAK | KB_CF, "fr-dvorak"},
 
64
    {KB_DVORAK | KB_FR, "bepo"},
 
65
    {KB_DVORAK, "dvorak"},
 
66
    {KB_CF, "fr-legacy"},
 
67
    {KB_NODEAD, "nodeadkeys"},
 
68
    {0}
 
69
};
 
70
 
 
71
struct nameint kbdopt[] = {
 
72
    {KB_SWAPCTRLCAPS, "ctrl:swapcaps"},
 
73
    {0}
 
74
};
 
75
 
 
76
struct nameint kbdmodel[] = {
 
77
    {WSKBD_TYPE_ZAURUS, "zaurus"},
 
78
    {0}
 
79
};
 
80
 
 
81
static void
 
82
wscons_add_keyboard(void)
 
83
{
 
84
    InputAttributes attrs = { };
 
85
    DeviceIntPtr dev = NULL;
 
86
    InputOption *input_options = NULL;
 
87
    char *config_info = NULL;
 
88
    int fd, i, rc;
 
89
    unsigned int type;
 
90
    kbd_t wsenc = 0;
 
91
 
 
92
    /* Find keyboard configuration */
 
93
    fd = open(WSCONS_KBD_DEVICE, O_RDWR | O_NONBLOCK | O_EXCL);
 
94
    if (fd == -1) {
 
95
        LogMessage(X_ERROR, "wskbd: open %s: %s\n",
 
96
                   WSCONS_KBD_DEVICE, strerror(errno));
 
97
        return;
 
98
    }
 
99
    if (ioctl(fd, WSKBDIO_GETENCODING, &wsenc) == -1) {
 
100
        LogMessage(X_WARNING, "wskbd: ioctl(WSKBDIO_GETENCODING) "
 
101
                   "failed: %s\n", strerror(errno));
 
102
        close(fd);
 
103
        return;
 
104
    }
 
105
    if (ioctl(fd, WSKBDIO_GTYPE, &type) == -1) {
 
106
        LogMessage(X_WARNING, "wskbd: ioctl(WSKBDIO_GTYPE) "
 
107
                   "failed: %s\n", strerror(errno));
 
108
        close(fd);
 
109
        return;
 
110
    }
 
111
    close(fd);
 
112
 
 
113
    input_options = input_option_new(input_options, "_source", "server/wscons");
 
114
    if (input_options == NULL)
 
115
        return;
 
116
 
 
117
    LogMessage(X_INFO, "config/wscons: checking input device %s\n",
 
118
               WSCONS_KBD_DEVICE);
 
119
    input_options = input_option_new(input_options, "name", WSCONS_KBD_DEVICE);
 
120
    input_options = input_option_new(input_options, "driver", "kbd");
 
121
 
 
122
    config_info = Xprintf("wscons:%s", WSCONS_KBD_DEVICE);
 
123
    if (!config_info)
 
124
        goto unwind;
 
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;
 
129
    }
 
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",
 
133
                           kbdenc[i].name);
 
134
            input_options = input_option_new(input_options,
 
135
                                             "xkb_layout", kbdenc[i].name);
 
136
            break;
 
137
        }
 
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",
 
141
                           kbdvar[i].name);
 
142
            input_options = input_option_new(input_options,
 
143
                                             "xkb_variant", kbdvar[i].name);
 
144
            break;
 
145
        }
 
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",
 
149
                           kbdopt[i].name);
 
150
            input_options = input_option_new(input_options,
 
151
                                             "xkb_options", kbdopt[i].name);
 
152
            break;
 
153
        }
 
154
    for (i = 0; kbdmodel[i].val; i++)
 
155
        if (type == kbdmodel[i].val) {
 
156
            LogMessageVerb(X_INFO, 3, "wskbd: using model %s\n",
 
157
                           kbdmodel[i].name);
 
158
            input_options = input_option_new(input_options,
 
159
                                             "xkb_model", kbdmodel[i].name);
 
160
            break;
 
161
        }
 
162
 
 
163
 kbd_config_done:
 
164
    attrs.flags |= ATTR_KEYBOARD;
 
165
    rc = NewInputDeviceRequest(input_options, &attrs, &dev);
 
166
    if (rc != Success)
 
167
        goto unwind;
 
168
 
 
169
    for (; dev; dev = dev->next) {
 
170
        free(dev->config_info);
 
171
        dev->config_info = strdup(config_info);
 
172
    }
 
173
 unwind:
 
174
    input_option_free_list(&input_options);
 
175
}
 
176
 
 
177
static void
 
178
wscons_add_pointer(const char *path, const char *driver, int flags)
 
179
{
 
180
    InputAttributes attrs = { };
 
181
    DeviceIntPtr dev = NULL;
 
182
    InputOption *input_options = NULL;
 
183
    char *config_info = NULL;
 
184
    int rc;
 
185
 
 
186
    config_info = Xprintf("wscons:%s", path);
 
187
    if (!config_info)
 
188
        return;
 
189
 
 
190
    input_options = input_option_new(input_options, "_source", "server/wscons");
 
191
    if (input_options == NULL)
 
192
        return;
 
193
 
 
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);
 
200
    if (rc != Success)
 
201
        goto unwind;
 
202
 
 
203
    for (; dev; dev = dev->next) {
 
204
        free(dev->config_info);
 
205
        dev->config_info = strdup(config_info);
 
206
    }
 
207
 unwind:
 
208
    input_option_free_list(&input_options);
 
209
}
 
210
 
 
211
static void
 
212
wscons_add_pointers(void)
 
213
{
 
214
    char devname[256];
 
215
    int fd, i, wsmouse_type;
 
216
 
 
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);
 
222
        if (fd == -1) {
 
223
            LogMessageVerb(X_WARNING, 10, "%s: %s\n", devname, strerror(errno));
 
224
            continue;
 
225
        }
 
226
        if (ioctl(fd, WSMOUSEIO_GTYPE, &wsmouse_type) != 0) {
 
227
            LogMessageVerb(X_WARNING, 10,
 
228
                           "%s: WSMOUSEIO_GTYPE failed\n", devname);
 
229
            close(fd);
 
230
            continue;
 
231
        }
 
232
        close(fd);
 
233
        switch (wsmouse_type) {
 
234
        case WSMOUSE_TYPE_SYNAPTICS:
 
235
            wscons_add_pointer(devname, "synaptics", ATTR_TOUCHPAD);
 
236
            break;
 
237
        case WSMOUSE_TYPE_TPANEL:
 
238
            wscons_add_pointer(devname, "ws", ATTR_TOUCHSCREEN);
 
239
            break;
 
240
        default:
 
241
            break;
 
242
        }
 
243
    }
 
244
    /* Add a default entry catching all other mux elements as "mouse" */
 
245
    wscons_add_pointer(WSCONS_MOUSE_PREFIX, "mouse", ATTR_POINTER);
 
246
}
 
247
 
 
248
int
 
249
config_wscons_init(void)
 
250
{
 
251
    wscons_add_keyboard();
 
252
    wscons_add_pointers();
 
253
    return 1;
 
254
}
 
255
 
 
256
void
 
257
config_wscons_fini(void)
 
258
{
 
259
    /* Not much to do ? */
 
260
}