Obsolete VTE pre-2.91 ABI
[oi-userland.git] / components / x11 / xorg-server / patches / 27-add-input-dev-in-multi-session.patch
blobeacf930649bbfb867145aecf130f4e33e00e1cd9
1 diff --git a/config/hal.c b/config/hal.c
2 index ea574ca..e108f03 100644
3 --- a/config/hal.c
4 +++ b/config/hal.c
5 @@ -1,6 +1,7 @@
6 /*
7 * Copyright © 2007 Daniel Stone
8 * Copyright © 2007 Red Hat, Inc.
9 + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 @@ -40,6 +41,23 @@
14 #include "config-backends.h"
15 #include "os.h"
17 +#if ((defined(__sparc__) || defined(__sparc)) && defined(SUNSOFT))
18 +#include <sys/stat.h>
19 +#include <unistd.h>
21 +#define MAX_DEVICES 4
23 +DeviceIntPtr added_devices[MAX_DEVICES];
24 +int num_added_devices = 0;
25 +Bool abort_on_fail_over = FALSE;
26 +static Bool do_abort = FALSE;
28 +extern int num_total_disp_dev;
29 +extern int num_session_disp_dev;
30 +extern char disp_dev_path[PATH_MAX];
31 +extern void GiveUp(int sig);
32 +#endif
34 #define LIBHAL_PROP_KEY "input.x11_options."
35 #define LIBHAL_XKB_PROP_KEY "input.xkb."
37 @@ -124,6 +142,51 @@ get_prop_string_array(LibHalContext * hal_ctx, const char *udi,
38 return ret;
41 +#if defined(SUNSOFT) && (defined(__sparc__) || defined(__sparc))
42 +Bool check_inactive_session(char const *path) {
43 + struct stat statbuf;
44 + char linkpath[PATH_MAX];
45 + ssize_t readstatus;
46 + char *usbpath = NULL;
47 + char *ptr;
48 + char disppath[PATH_MAX];
50 + if ((num_session_disp_dev == num_total_disp_dev) || !disp_dev_path[0])
51 + return FALSE;
53 + if (lstat(path, &statbuf) == 0 &&
54 + (statbuf.st_mode & S_IFMT) == S_IFLNK) {
55 + readstatus = readlink(path, linkpath, sizeof(linkpath));
57 + if (readstatus > 0 && readstatus < sizeof(linkpath)) {
58 + linkpath[readstatus] = 0;
59 + usbpath = linkpath;
60 + if (strncmp(usbpath, "../..", sizeof("../..") - 1) == 0)
61 + usbpath += sizeof("../..") - 1;
62 + if (strncmp(usbpath, "/devices", sizeof("/devices") - 1) == 0)
63 + usbpath += sizeof("/devices") - 1;
64 + }
65 + }
67 + if (!usbpath)
68 + return FALSE;
70 + if (ptr = strchr(usbpath + 1, '/'))
71 + *ptr = 0;
72 + else
73 + return FALSE;
75 + strncpy(disppath, disp_dev_path, sizeof(disppath));
77 + if (ptr = strchr(disppath + 1, '/'))
78 + *ptr = 0;
79 + else
80 + return FALSE;
82 + return (strcmp(usbpath, disppath));
84 +#endif
86 static void
87 device_added(LibHalContext * hal_ctx, const char *udi)
89 @@ -136,6 +199,11 @@ device_added(LibHalContext * hal_ctx, const char *udi)
90 struct xkb_options xkb_opts = { 0 };
91 int rc;
93 +#if ((defined(__sparc__) || defined(__sparc)) && defined(SUNSOFT))
94 + if (do_abort)
95 + return;
96 +#endif
98 LibHalPropertySet *set = NULL;
99 LibHalPropertySetIterator set_iter;
100 char *psi_key = NULL, *tmp_val;
101 @@ -232,6 +300,28 @@ device_added(LibHalContext * hal_ctx, const char *udi)
102 input_options = input_option_new(input_options, "driver", driver);
103 input_options = input_option_new(input_options, "name", name);
105 +#if ((defined(__sparc__) || defined(__sparc)) && defined(SUNSOFT))
106 + if (!strcmp(name, "keyboard") || !strcmp(name, "mouse")) {
107 + if (check_inactive_session(path)) {
108 + if (abort_on_fail_over) {
109 + /* M5: Input devices were removed, new input device added is to
110 + activate another session, reset it.
111 + */
112 + do_abort = TRUE;
113 + LogMessage(X_INFO, "config/hal: Server to abort\n");
114 + } else
115 + /* M5: No removal of input devices happened, new input device
116 + added is to activate another session, do nothing.
117 + */
118 + LogMessage(X_INFO, "config/hal: Not adding input device %s\n", name);
120 + goto unwind;
121 + } else
122 + /* M5: new input device added is to activate current session. */
123 + abort_on_fail_over = FALSE;
125 +#endif
127 if (asprintf(&config_info, "hal:%s", udi) == -1) {
128 config_info = NULL;
129 LogMessage(X_ERROR, "config/hal: couldn't allocate name\n");
130 @@ -402,6 +492,26 @@ device_added(LibHalContext * hal_ctx, const char *udi)
131 goto unwind;
134 +#if ((defined(__sparc__) || defined(__sparc)) && defined(SUNSOFT))
135 + if ((num_session_disp_dev < num_total_disp_dev) &&
136 + (!strcmp(name, "keyboard") || !strcmp(name, "mouse"))) {
137 + int i;
139 + if (num_added_devices == MAX_DEVICES) {
140 + LogMessage(X_ERROR, "config/hal: Too manay devices to add\n");
141 + goto unwind;
144 + for (i = 0; i < MAX_DEVICES; i++) {
145 + if (added_devices[i] == 0) {
146 + added_devices[i] = dev;
147 + num_added_devices++;
148 + break;
152 +#endif
154 unwind:
155 if (set)
156 libhal_free_property_set(set);
157 @@ -434,6 +544,12 @@ device_added(LibHalContext * hal_ctx, const char *udi)
159 dbus_error_free(&error);
161 +#if ((defined(__sparc__) || defined(__sparc)) && defined(SUNSOFT))
162 + if (do_abort) {
163 + config_fini();
164 + GiveUp(0);
166 +#endif
167 return;
170 diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
171 index c56a2b9..a3a7645 100644
172 --- a/hw/xfree86/common/xf86Xinput.c
173 +++ b/hw/xfree86/common/xf86Xinput.c
174 @@ -45,6 +45,9 @@
175 * the sale, use or other dealings in this Software without prior written
176 * authorization from the copyright holder(s) and author(s).
179 + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
180 + */
182 #ifdef HAVE_XORG_CONFIG_H
183 #include <xorg-config.h>
184 @@ -113,6 +116,15 @@ static int
185 static InputInfoPtr *new_input_devices;
186 static int new_input_devices_count;
188 +#if ((defined(__sparc__) || defined(__sparc)) && defined(sun))
189 +#define MAX_DEVICES 4
190 +extern int num_total_disp_dev;
191 +extern int num_session_disp_dev;
192 +extern DeviceIntPtr added_devices[MAX_DEVICES];
193 +extern int num_added_devices;
194 +extern Bool abort_on_fail_over;
195 +#endif
198 * Eval config and modify DeviceVelocityRec accordingly
200 @@ -1469,6 +1481,25 @@ xf86DisableDevice(DeviceIntPtr dev, Bool panic)
201 SendDevicePresenceEvent(dev->id, DeviceUnrecoverable);
202 DeleteInputDeviceRequest(dev);
205 +#if ((defined(__sparc__) || defined(__sparc)) && defined(sun))
206 + if (num_session_disp_dev < num_total_disp_dev) {
207 + int i;
209 + for (i = 0; i < MAX_DEVICES; i++) {
210 + if (added_devices[i] == dev) {
211 + added_devices[i] = 0;
212 + if (--num_added_devices == 0)
213 + /* M5: will abort server when another X session
214 + is activated.
215 + */
216 + abort_on_fail_over = TRUE;
218 + break;
222 +#endif
226 diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
227 index 8158c2b..f812a3b 100644
228 --- a/hw/xfree86/common/xf86pciBus.c
229 +++ b/hw/xfree86/common/xf86pciBus.c
230 @@ -1,5 +1,6 @@
232 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
233 + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
235 * Permission is hereby granted, free of charge, to any person obtaining a
236 * copy of this software and associated documentation files (the "Software"),
237 @@ -54,6 +55,12 @@
238 /* Bus-specific globals */
239 int pciSlotClaimed = 0;
241 +#if ((defined(__sparc__) || defined(__sparc)) && defined (sun))
242 +int num_total_disp_dev = 0;
243 +int num_session_disp_dev = 0;
244 +char disp_dev_path[PATH_MAX];
245 +#endif
247 #define PCIINFOCLASSES(c) \
248 ( (((c) & 0x00ff0000) == (PCI_CLASS_PREHISTORIC << 16)) \
249 || (((c) & 0x00ff0000) == (PCI_CLASS_DISPLAY << 16)) \
250 @@ -115,6 +122,11 @@ xf86PciProbe(void)
251 primaryBus.id.pci = info;
253 info->user_data = 0;
255 +#if ((defined(__sparc__) || defined(__sparc)) && defined (sun))
256 + if (IS_VGA(info->device_class))
257 + num_total_disp_dev++;
258 +#endif
261 free(iter);
262 @@ -483,6 +495,15 @@ xf86PciProbeDev(DriverPtr drvp)
263 const struct pci_id_match *const devices = drvp->supported_devices;
264 GDevPtr *devList;
265 const unsigned numDevs = xf86MatchDevice(drvp->driverName, &devList);
266 +#if ((defined(__sparc__) || defined(__sparc)) && defined (sun))
267 + struct sol_device_private {
268 + struct pci_device base;
269 + const char * device_string;
270 + };
271 +#define DEV_PATH(dev) (((struct sol_device_private *) dev)->device_string)
273 + num_session_disp_dev = numDevs;
274 +#endif
276 for (i = 0; i < numDevs; i++) {
277 struct pci_device_iterator *iter;
278 @@ -560,6 +581,11 @@ xf86PciProbeDev(DriverPtr drvp)
279 if ((*drvp->PciProbe) (drvp, entry, pPci,
280 devices[j].match_data)) {
281 foundScreen = TRUE;
283 +#if ((defined(__sparc__) || defined(__sparc)) && defined (sun))
284 + strncpy(disp_dev_path, DEV_PATH(pPci), sizeof(disp_dev_path));
285 +#endif
288 else
289 xf86UnclaimPciSlot(pPci, devList[i]);
290 @@ -568,6 +594,7 @@ xf86PciProbeDev(DriverPtr drvp)
291 break;
296 free(devList);