82739d
From 5a555338bf11afb5942daabfdae8638e7aab2ac6 Mon Sep 17 00:00:00 2001
Peter Hutterer 37aa2d
From: Lennart Poettering <lennart@poettering.net>
Peter Hutterer 37aa2d
Date: Mon, 18 Jul 2011 21:19:23 +0200
Peter Hutterer 37aa2d
Subject: [PATCH] config: add udev/systemd multi-seat support
Peter Hutterer 37aa2d
Peter Hutterer 37aa2d
Add support for multi-seat-aware input device hotplugging. This
Peter Hutterer 37aa2d
implements the multi-seat scheme explained here:
Peter Hutterer 37aa2d
Peter Hutterer 37aa2d
http://www.freedesktop.org/wiki/Software/systemd/multiseat
Peter Hutterer 37aa2d
Peter Hutterer 37aa2d
This introduces a new X server switch "-seat" which allows configuration
Peter Hutterer 37aa2d
of the seat to enumerate hotplugging devices on. If specified the value
Peter Hutterer 37aa2d
of this parameter will also be exported as root window property
Peter Hutterer 37aa2d
Xorg_Seat.
Peter Hutterer 37aa2d
Peter Hutterer 37aa2d
To properly support input hotplugging devices need to be tagged in udev
Peter Hutterer 37aa2d
according to the seat they are on. Untagged devices are assumed to be on
Peter Hutterer 37aa2d
the default seat "seat0". If no "-seat" parameter is passed only devices
Peter Hutterer 37aa2d
on "seat0" are used. This means that the new scheme is perfectly
Peter Hutterer 37aa2d
compatible with existing setups which have no tagged input devices.
Peter Hutterer 37aa2d
Peter Hutterer 37aa2d
Note that the -seat switch takes a completely generic identifier, and
Peter Hutterer 37aa2d
that it has no effect on non-Linux systems. In fact, on other OSes a
Peter Hutterer 37aa2d
completely different identifier scheme for seats could be used but still
Peter Hutterer 37aa2d
be exposed with the Xorg_Seat and -seat.
Peter Hutterer 37aa2d
Peter Hutterer 37aa2d
I tried to follow the coding style of the surrounding code blocks if
Peter Hutterer 37aa2d
there was any one could follow.
Peter Hutterer 37aa2d
Peter Hutterer 37aa2d
Signed-off-by: Lennart Poettering <lennart@poettering.net>
Peter Hutterer 37aa2d
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Peter Hutterer 37aa2d
Peter Hutterer 37aa2d
Conflicts:
Peter Hutterer 37aa2d
Peter Hutterer 37aa2d
	config/udev.c
Peter Hutterer 37aa2d
Peter Hutterer 37aa2d
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Peter Hutterer 37aa2d
---
82739d
 config/udev.c                |   18 ++++++++++++++++++
Peter Hutterer 37aa2d
 hw/xfree86/common/xf86Init.c |   19 +++++++++++++++++++
Peter Hutterer 37aa2d
 include/globals.h            |    2 +-
Peter Hutterer 37aa2d
 include/xserver-properties.h |    3 +++
82739d
 man/Xserver.man              |    6 ++++++
Peter Hutterer 37aa2d
 os/utils.c                   |   10 ++++++++++
82739d
 6 files changed, 57 insertions(+), 1 deletions(-)
Peter Hutterer 37aa2d
Peter Hutterer 37aa2d
diff --git a/config/udev.c b/config/udev.c
82739d
index e7383dc..fc6ee5d 100644
Peter Hutterer 37aa2d
--- a/config/udev.c
Peter Hutterer 37aa2d
+++ b/config/udev.c
Peter Hutterer 37aa2d
@@ -35,6 +35,7 @@
Peter Hutterer 37aa2d
 #include "hotplug.h"
Peter Hutterer 37aa2d
 #include "config-backends.h"
Peter Hutterer 37aa2d
 #include "os.h"
Peter Hutterer 37aa2d
+#include "globals.h"
Peter Hutterer 37aa2d
 
Peter Hutterer 37aa2d
 #define UDEV_XKB_PROP_KEY "xkb"
Peter Hutterer 37aa2d
 
Peter Hutterer 37aa2d
@@ -65,6 +66,7 @@ device_added(struct udev_device *udev_device)
Peter Hutterer 37aa2d
     struct udev_list_entry *set, *entry;
Peter Hutterer 37aa2d
     struct udev_device *parent;
Peter Hutterer 37aa2d
     int rc;
Peter Hutterer 37aa2d
+    const char *dev_seat;
Peter Hutterer 37aa2d
 
Peter Hutterer 37aa2d
     path = udev_device_get_devnode(udev_device);
Peter Hutterer 37aa2d
 
Peter Hutterer 37aa2d
@@ -73,6 +75,16 @@ device_added(struct udev_device *udev_device)
Peter Hutterer 37aa2d
     if (!path || !syspath)
Peter Hutterer 37aa2d
         return;
Peter Hutterer 37aa2d
 
Peter Hutterer 37aa2d
+    dev_seat = udev_device_get_property_value(udev_device, "ID_SEAT");
Peter Hutterer 37aa2d
+    if (!dev_seat)
Peter Hutterer 37aa2d
+        dev_seat = "seat0";
Peter Hutterer 37aa2d
+
Peter Hutterer 37aa2d
+    if (SeatId && strcmp(dev_seat, SeatId))
Peter Hutterer 37aa2d
+        return;
Peter Hutterer 37aa2d
+
Peter Hutterer 37aa2d
+    if (!SeatId && strcmp(dev_seat, "seat0"))
Peter Hutterer 37aa2d
+        return;
Peter Hutterer 37aa2d
+
Peter Hutterer 37aa2d
     if (!udev_device_get_property_value(udev_device, "ID_INPUT")) {
Peter Hutterer 37aa2d
         LogMessageVerb(X_INFO, 10,
Peter Hutterer 37aa2d
                        "config/udev: ignoring device %s without "
82739d
@@ -284,6 +296,9 @@ config_udev_init(void)
82739d
     udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "input", NULL);
82739d
     udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "tty", NULL); /* For Wacom serial devices */
Peter Hutterer 37aa2d
 
Peter Hutterer 37aa2d
+    if (SeatId && strcmp(SeatId, "seat0"))
Peter Hutterer 37aa2d
+        udev_monitor_filter_add_match_tag(udev_monitor, SeatId);
Peter Hutterer 37aa2d
+
Peter Hutterer 37aa2d
     if (udev_monitor_enable_receiving(udev_monitor)) {
Peter Hutterer 37aa2d
         ErrorF("config/udev: failed to bind the udev monitor\n");
Peter Hutterer 37aa2d
         return 0;
82739d
@@ -296,6 +311,9 @@ config_udev_init(void)
82739d
     udev_enumerate_add_match_subsystem(enumerate, "input");
82739d
     udev_enumerate_add_match_subsystem(enumerate, "tty");
82739d
 
Peter Hutterer 37aa2d
+    if (SeatId && strcmp(SeatId, "seat0"))
Peter Hutterer 37aa2d
+        udev_enumerate_add_match_tag(enumerate, SeatId);
Peter Hutterer 37aa2d
+
Peter Hutterer 37aa2d
     udev_enumerate_scan_devices(enumerate);
Peter Hutterer 37aa2d
     devices = udev_enumerate_get_list_entry(enumerate);
Peter Hutterer 37aa2d
     udev_list_entry_foreach(device, devices) {
Peter Hutterer 37aa2d
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
82739d
index 71926f8..a268ced 100644
Peter Hutterer 37aa2d
--- a/hw/xfree86/common/xf86Init.c
Peter Hutterer 37aa2d
+++ b/hw/xfree86/common/xf86Init.c
Peter Hutterer 37aa2d
@@ -80,6 +80,7 @@
Peter Hutterer 37aa2d
 #include "xf86Bus.h"
Peter Hutterer 37aa2d
 #include "xf86VGAarbiter.h"
Peter Hutterer 37aa2d
 #include "globals.h"
Peter Hutterer 37aa2d
+#include "xserver-properties.h"
Peter Hutterer 37aa2d
 
Peter Hutterer 37aa2d
 #ifdef DPMSExtension
Peter Hutterer 37aa2d
 #include <X11/extensions/dpmsconst.h>
Peter Hutterer 37aa2d
@@ -654,6 +655,24 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
Peter Hutterer 37aa2d
       }
Peter Hutterer 37aa2d
     }
Peter Hutterer 37aa2d
 
Peter Hutterer 37aa2d
+    if (SeatId) {
Peter Hutterer 37aa2d
+        Atom SeatAtom;
Peter Hutterer 37aa2d
+
Peter Hutterer 37aa2d
+        SeatAtom = MakeAtom(SEAT_ATOM_NAME, sizeof(SEAT_ATOM_NAME) - 1, TRUE);
Peter Hutterer 37aa2d
+
Peter Hutterer 37aa2d
+        for (i = 0; i < xf86NumScreens; i++) {
Peter Hutterer 37aa2d
+            int ret;
Peter Hutterer 37aa2d
+
Peter Hutterer 37aa2d
+            ret = xf86RegisterRootWindowProperty(xf86Screens[i]->scrnIndex,
Peter Hutterer 37aa2d
+                                                 SeatAtom, XA_STRING, 8,
Peter Hutterer 37aa2d
+                                                 strlen(SeatId)+1, SeatId );
Peter Hutterer 37aa2d
+            if (ret != Success) {
Peter Hutterer 37aa2d
+                xf86DrvMsg(xf86Screens[i]->scrnIndex, X_WARNING,
Peter Hutterer 37aa2d
+                           "Failed to register seat property\n");
Peter Hutterer 37aa2d
+            }
Peter Hutterer 37aa2d
+        }
Peter Hutterer 37aa2d
+    }
Peter Hutterer 37aa2d
+
Peter Hutterer 37aa2d
     /* If a screen uses depth 24, show what the pixmap format is */
Peter Hutterer 37aa2d
     for (i = 0; i < xf86NumScreens; i++) {
Peter Hutterer 37aa2d
 	if (xf86Screens[i]->depth == 24) {
Peter Hutterer 37aa2d
diff --git a/include/globals.h b/include/globals.h
Peter Hutterer 37aa2d
index 8b80a65..17bca82 100644
Peter Hutterer 37aa2d
--- a/include/globals.h
Peter Hutterer 37aa2d
+++ b/include/globals.h
Peter Hutterer 37aa2d
@@ -21,7 +21,7 @@ extern _X_EXPORT int defaultColorVisualClass;
Peter Hutterer 37aa2d
 
Peter Hutterer 37aa2d
 extern _X_EXPORT int GrabInProgress;
Peter Hutterer 37aa2d
 extern _X_EXPORT Bool noTestExtensions;
Peter Hutterer 37aa2d
-
Peter Hutterer 37aa2d
+extern _X_EXPORT char *SeatId;
Peter Hutterer 37aa2d
 extern _X_EXPORT char *ConnectionInfo;
Peter Hutterer 37aa2d
 
Peter Hutterer 37aa2d
 #ifdef DPMSExtension
Peter Hutterer 37aa2d
diff --git a/include/xserver-properties.h b/include/xserver-properties.h
82739d
index 2b1feab..bf50042 100644
Peter Hutterer 37aa2d
--- a/include/xserver-properties.h
Peter Hutterer 37aa2d
+++ b/include/xserver-properties.h
Peter Hutterer 37aa2d
@@ -30,6 +30,9 @@
Peter Hutterer 37aa2d
  * byte-ordering. */
Peter Hutterer 37aa2d
 #define XATOM_FLOAT "FLOAT"
Peter Hutterer 37aa2d
 
Peter Hutterer 37aa2d
+/* STRING. Seat name of this display */
Peter Hutterer 37aa2d
+#define SEAT_ATOM_NAME "Xorg_Seat"
Peter Hutterer 37aa2d
+
Peter Hutterer 37aa2d
 /* BOOL. 0 - device disabled, 1 - device enabled */
Peter Hutterer 37aa2d
 #define XI_PROP_ENABLED      "Device Enabled"
Peter Hutterer 37aa2d
 /* BOOL. If present, device is a virtual XTEST device */
82739d
diff --git a/man/Xserver.man b/man/Xserver.man
82739d
index f743912..1a36b09 100644
82739d
--- a/man/Xserver.man
82739d
+++ b/man/Xserver.man
82739d
@@ -220,6 +220,12 @@ sets screen-saver timeout time in minutes.
82739d
 .B \-su
82739d
 disables save under support on all screens.
82739d
 .TP 8
82739d
+.B \-seat \fIseat\fP
82739d
+seat to run on. Takes a string identifying a seat in a platform
82739d
+specific syntax. On platforms which support this feature this may be
82739d
+used to limit the server to expose only a specific subset of devices
82739d
+connected to the system.
82739d
+.TP 8
82739d
 .B \-t \fInumber\fP
82739d
 sets pointer acceleration threshold in pixels (i.e. after how many pixels
82739d
 pointer acceleration should take effect).
Peter Hutterer 37aa2d
diff --git a/os/utils.c b/os/utils.c
82739d
index 6338860..db2ae84 100644
Peter Hutterer 37aa2d
--- a/os/utils.c
Peter Hutterer 37aa2d
+++ b/os/utils.c
Peter Hutterer 37aa2d
@@ -201,6 +201,8 @@ Bool PanoramiXExtensionDisabledHack = FALSE;
Peter Hutterer 37aa2d
 
Peter Hutterer 37aa2d
 int auditTrailLevel = 1;
Peter Hutterer 37aa2d
 
Peter Hutterer 37aa2d
+char *SeatId = NULL;
Peter Hutterer 37aa2d
+
Peter Hutterer 37aa2d
 #if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED)
Peter Hutterer 37aa2d
 #define HAS_SAVED_IDS_AND_SETEUID
Peter Hutterer 37aa2d
 #endif
Peter Hutterer 37aa2d
@@ -511,6 +513,7 @@ void UseMsg(void)
Peter Hutterer 37aa2d
     ErrorF("-render [default|mono|gray|color] set render color alloc policy\n");
Peter Hutterer 37aa2d
     ErrorF("-retro                 start with classic stipple and cursor\n");
Peter Hutterer 37aa2d
     ErrorF("-s #                   screen-saver timeout (minutes)\n");
Peter Hutterer 37aa2d
+    ErrorF("-seat string           seat to run on\n");
Peter Hutterer 37aa2d
     ErrorF("-t #                   default pointer threshold (pixels/t)\n");
Peter Hutterer 37aa2d
     ErrorF("-terminate             terminate at server reset\n");
Peter Hutterer 37aa2d
     ErrorF("-to #                  connection time out\n");
82739d
@@ -813,6 +816,13 @@ ProcessCommandLine(int argc, char *argv[])
Peter Hutterer 37aa2d
 	    else
Peter Hutterer 37aa2d
 		UseMsg();
Peter Hutterer 37aa2d
 	}
Peter Hutterer 37aa2d
+	else if ( strcmp( argv[i], "-seat") == 0)
Peter Hutterer 37aa2d
+	{
Peter Hutterer 37aa2d
+	    if(++i < argc)
Peter Hutterer 37aa2d
+		SeatId = argv[i];
Peter Hutterer 37aa2d
+	    else
Peter Hutterer 37aa2d
+		UseMsg();
Peter Hutterer 37aa2d
+	}
Peter Hutterer 37aa2d
 	else if ( strcmp( argv[i], "-t") == 0)
Peter Hutterer 37aa2d
 	{
Peter Hutterer 37aa2d
 	    if(++i < argc)
Peter Hutterer 37aa2d
-- 
Peter Hutterer 37aa2d
1.7.6
Peter Hutterer 37aa2d