summaryrefslogtreecommitdiff
path: root/hw/dmx/examples
diff options
context:
space:
mode:
Diffstat (limited to 'hw/dmx/examples')
-rw-r--r--hw/dmx/examples/dmxaddinput.c84
-rw-r--r--hw/dmx/examples/dmxaddscreen.c106
-rw-r--r--hw/dmx/examples/dmxreconfig.c163
-rw-r--r--hw/dmx/examples/dmxresize.c105
-rw-r--r--hw/dmx/examples/dmxrminput.c79
-rw-r--r--hw/dmx/examples/dmxrmscreen.c81
-rw-r--r--hw/dmx/examples/dmxwininfo.c497
-rw-r--r--hw/dmx/examples/ev.c183
-rw-r--r--hw/dmx/examples/evi.c87
-rw-r--r--hw/dmx/examples/res.c100
-rw-r--r--hw/dmx/examples/xbell.c102
-rw-r--r--hw/dmx/examples/xdmx.c240
-rw-r--r--hw/dmx/examples/xinput.c319
-rw-r--r--hw/dmx/examples/xled.c125
-rw-r--r--hw/dmx/examples/xtest.c76
15 files changed, 2347 insertions, 0 deletions
diff --git a/hw/dmx/examples/dmxaddinput.c b/hw/dmx/examples/dmxaddinput.c
new file mode 100644
index 000000000..d4ec963a0
--- /dev/null
+++ b/hw/dmx/examples/dmxaddinput.c
@@ -0,0 +1,84 @@
+/* $XFree86$ */
+/*
+ * Copyright 2003,2004 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include "dmxext.h"
+
+int main(int argc, char **argv)
+{
+ Display *display = NULL;
+ int event_base;
+ int error_base;
+ int major_version, minor_version, patch_version;
+ int id = -1;
+ int status;
+
+ if (argc != 5) {
+ printf("Usage: %s display c|b name|screen isCore\n", argv[0]);
+ return -1;
+ }
+
+ if (!(display = XOpenDisplay(argv[1]))) {
+ printf("Cannot open display %s\n", argv[1]);
+ return -1;
+ }
+
+ if (!DMXQueryExtension(display, &event_base, &error_base)) {
+ printf("DMX extension not present\n");
+ return -1;
+ }
+ printf("DMX extension present: event_base = %d, error_base = %d\n",
+ event_base, error_base);
+
+ if (!DMXQueryVersion(display,
+ &major_version, &minor_version, &patch_version)) {
+ printf("Could not get extension version\n");
+ return -1;
+ }
+ printf("Extension version: %d.%d patch %d\n",
+ major_version, minor_version, patch_version);
+
+ if (argv[2][0] == 'c') {
+ status = DMXAddConsoleInput(display, argv[3], atoi(argv[4]), &id);
+ } else {
+ status = DMXAddBackendInput(display, atoi(argv[3]), atoi(argv[4]),&id);
+ }
+
+ printf("status = %d, id = %d\n", status, id);
+
+ XCloseDisplay(display);
+ return 0;
+}
diff --git a/hw/dmx/examples/dmxaddscreen.c b/hw/dmx/examples/dmxaddscreen.c
new file mode 100644
index 000000000..a1118f437
--- /dev/null
+++ b/hw/dmx/examples/dmxaddscreen.c
@@ -0,0 +1,106 @@
+/* $XFree86$ */
+/*
+ * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Kevin E. Martin <kem@redhat.com>
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include "dmxext.h"
+
+int main(int argc, char **argv)
+{
+ Display *display = NULL;
+ int event_base;
+ int error_base;
+ int major_version, minor_version, patch_version;
+ int screenNum;
+ DMXScreenAttributes attr;
+ unsigned int mask = 0;
+
+ if (argc != 4 && argc != 14) {
+ printf("Usage: %s display screenNum displayName [scrnx scrny scrnw scrnh rootx rooty rootw rooth originx originy]\n", argv[0]);
+ return -1;
+ }
+
+ if (!(display = XOpenDisplay(argv[1]))) {
+ printf("Cannot open display %s\n", argv[1]);
+ return -1;
+ }
+
+ screenNum = strtol(argv[2], NULL, 0);
+ if (argc == 14) {
+ mask |= (DMXScreenWindowXoffset |
+ DMXScreenWindowYoffset |
+ DMXScreenWindowWidth |
+ DMXScreenWindowHeight);
+ attr.screenWindowXoffset = strtol(argv[4], NULL, 0);
+ attr.screenWindowYoffset = strtol(argv[5], NULL, 0);
+ attr.screenWindowWidth = strtol(argv[6], NULL, 0);
+ attr.screenWindowHeight = strtol(argv[7], NULL, 0);
+
+ mask |= (DMXRootWindowXoffset |
+ DMXRootWindowYoffset |
+ DMXRootWindowWidth |
+ DMXRootWindowHeight);
+ attr.rootWindowXoffset = strtol(argv[8], NULL, 0);
+ attr.rootWindowYoffset = strtol(argv[9], NULL, 0);
+ attr.rootWindowWidth = strtol(argv[10], NULL, 0);
+ attr.rootWindowHeight = strtol(argv[11], NULL, 0);
+
+ mask |= DMXRootWindowXorigin | DMXRootWindowYorigin;
+ attr.rootWindowXorigin = strtol(argv[12], NULL, 0);
+ attr.rootWindowYorigin = strtol(argv[13], NULL, 0);
+ }
+
+ if (!DMXQueryExtension(display, &event_base, &error_base)) {
+ printf("DMX extension not present\n");
+ return -1;
+ }
+ printf("DMX extension present: event_base = %d, error_base = %d\n",
+ event_base, error_base);
+
+ if (!DMXQueryVersion(display,
+ &major_version, &minor_version, &patch_version)) {
+ printf("Could not get extension version\n");
+ return -1;
+ }
+ printf("Extension version: %d.%d patch %d\n",
+ major_version, minor_version, patch_version);
+
+ if (!DMXAddScreen(display, argv[3], mask, &attr, &screenNum))
+ printf("Failed to add %s as screen #%d\n", argv[2], screenNum);
+
+ XCloseDisplay(display);
+ return 0;
+}
diff --git a/hw/dmx/examples/dmxreconfig.c b/hw/dmx/examples/dmxreconfig.c
new file mode 100644
index 000000000..a334fb3cf
--- /dev/null
+++ b/hw/dmx/examples/dmxreconfig.c
@@ -0,0 +1,163 @@
+/* $XFree86$ */
+/*
+ * Copyright 2003 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Kevin E. Martin <kem@redhat.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include "dmxext.h"
+
+int main(int argc, char **argv)
+{
+ Display *display = NULL;
+ int event_base;
+ int error_base;
+ int major_version, minor_version, patch_version;
+ int screen;
+ DMXScreenAttributes attr;
+ unsigned int mask = 0;
+ int status;
+ int errorScreen;
+
+ if (argc != 13) {
+ fprintf(stderr, "Usage: %s display screen scrnx scrny scrnw scrnh rootx rooty rootw rooth originx originy\n", argv[0]);
+ return -1;
+ }
+
+ if (!(display = XOpenDisplay(argv[1]))) {
+ fprintf(stderr, "Cannot open display %s\n", argv[1]);
+ return -1;
+ }
+
+ screen = strtol(argv[2], NULL, 0);
+
+ mask |= (DMXScreenWindowXoffset |
+ DMXScreenWindowYoffset |
+ DMXScreenWindowWidth |
+ DMXScreenWindowHeight);
+ attr.screenWindowXoffset = strtol(argv[3], NULL, 0);
+ attr.screenWindowYoffset = strtol(argv[4], NULL, 0);
+ attr.screenWindowWidth = strtol(argv[5], NULL, 0);
+ attr.screenWindowHeight = strtol(argv[6], NULL, 0);
+
+ mask |= (DMXRootWindowXoffset |
+ DMXRootWindowYoffset |
+ DMXRootWindowWidth |
+ DMXRootWindowHeight);
+ attr.rootWindowXoffset = strtol(argv[7], NULL, 0);
+ attr.rootWindowYoffset = strtol(argv[8], NULL, 0);
+ attr.rootWindowWidth = strtol(argv[9], NULL, 0);
+ attr.rootWindowHeight = strtol(argv[10], NULL, 0);
+
+ mask |= DMXRootWindowXorigin | DMXRootWindowYorigin;
+ attr.rootWindowXorigin = strtol(argv[11], NULL, 0);
+ attr.rootWindowYorigin = strtol(argv[12], NULL, 0);
+
+ if (!DMXQueryExtension(display, &event_base, &error_base)) {
+ fprintf(stderr, "DMX extension not present\n");
+ return -1;
+ }
+ printf("DMX extension present: event_base = %d, error_base = %d\n",
+ event_base, error_base);
+
+ if (!DMXQueryVersion(display,
+ &major_version, &minor_version, &patch_version)) {
+ fprintf(stderr, "Could not get extension version\n");
+ return -1;
+ }
+ printf("Extension version: %d.%d patch %d\n",
+ major_version, minor_version, patch_version);
+
+ if (major_version == 1 && minor_version < 3) {
+ fprintf(stderr,
+ "ReconfigureScreen not supported in this extension version\n");
+ return -1;
+ }
+
+ if (major_version < 2) {
+ fprintf(stderr,
+ "ChangeScreensAttributes not supported in this extension "
+ "version\n");
+ return -1;
+ }
+
+ if (!(status = DMXChangeScreensAttributes(display, 1, &screen, 1, &mask,
+ &attr, &errorScreen))) {
+ printf("Reconfigured screen #%d to "
+ "%dx%d%s%d%s%d %dx%d%s%d%s%d %s%d%s%d\n",
+ screen,
+ attr.screenWindowWidth,
+ attr.screenWindowHeight,
+ (attr.screenWindowXoffset < 0 ? "" : "+"),
+ attr.screenWindowXoffset,
+ (attr.screenWindowYoffset < 0 ? "" : "+"),
+ attr.screenWindowYoffset,
+ attr.rootWindowWidth,
+ attr.rootWindowHeight,
+ (attr.rootWindowXoffset < 0 ? "" : "+"),
+ attr.rootWindowXoffset,
+ (attr.rootWindowYoffset < 0 ? "" : "+"),
+ attr.rootWindowYoffset,
+ (attr.rootWindowXorigin < 0 ? "" : "+"),
+ attr.rootWindowXorigin,
+ (attr.rootWindowYorigin < 0 ? "" : "+"),
+ attr.rootWindowYorigin);
+ } else {
+ fprintf(stderr,
+ "Could not set screen #%d to "
+ "%dx%d%s%d%s%d %dx%d%s%d%s%d %s%d%s%d\n"
+ "[status = %d, errorScreen=%d]\n",
+ screen,
+ attr.screenWindowWidth,
+ attr.screenWindowHeight,
+ (attr.screenWindowXoffset < 0 ? "" : "+"),
+ attr.screenWindowXoffset,
+ (attr.screenWindowYoffset < 0 ? "" : "+"),
+ attr.screenWindowYoffset,
+ attr.rootWindowWidth,
+ attr.rootWindowHeight,
+ (attr.rootWindowXoffset < 0 ? "" : "+"),
+ attr.rootWindowXoffset,
+ (attr.rootWindowYoffset < 0 ? "" : "+"),
+ attr.rootWindowYoffset,
+ (attr.rootWindowXorigin < 0 ? "" : "+"),
+ attr.rootWindowXorigin,
+ (attr.rootWindowYorigin < 0 ? "" : "+"),
+ attr.rootWindowYorigin,
+ status, errorScreen);
+ return -1;
+ }
+
+ XCloseDisplay(display);
+ return 0;
+}
diff --git a/hw/dmx/examples/dmxresize.c b/hw/dmx/examples/dmxresize.c
new file mode 100644
index 000000000..3801658a6
--- /dev/null
+++ b/hw/dmx/examples/dmxresize.c
@@ -0,0 +1,105 @@
+/* $XFree86$ */
+/*
+ * Copyright 2003 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include "dmxext.h"
+
+int main(int argc, char **argv)
+{
+ Display *display = NULL;
+ int event_base;
+ int error_base;
+ int major_version, minor_version, patch_version;
+ int width, height, shiftX, shiftY, status;
+ DMXDesktopAttributes attr;
+ unsigned int mask;
+
+ if (argc != 6) {
+ printf("Usage: %s display width height shiftX shiftY\n", argv[0]);
+ return -1;
+ }
+
+ if (!(display = XOpenDisplay(argv[1]))) {
+ printf("Cannot open display %s\n", argv[1]);
+ return -1;
+ }
+
+ width = strtol(argv[2], NULL, 0);
+ height = strtol(argv[3], NULL, 0);
+ shiftX = strtol(argv[4], NULL, 0);
+ shiftY = strtol(argv[5], NULL, 0);
+
+ if (!DMXQueryExtension(display, &event_base, &error_base)) {
+ printf("DMX extension not present\n");
+ return -1;
+ }
+ printf("DMX extension present: event_base = %d, error_base = %d\n",
+ event_base, error_base);
+
+ if (!DMXQueryVersion(display,
+ &major_version, &minor_version, &patch_version)) {
+ printf("Could not get extension version\n");
+ return -1;
+ }
+ printf("Extension version: %d.%d patch %d\n",
+ major_version, minor_version, patch_version);
+
+ mask = (DMXDesktopWidth |
+ DMXDesktopHeight |
+ DMXDesktopShiftX |
+ DMXDesktopShiftY);
+ attr.width = width;
+ attr.height = height;
+ attr.shiftX = shiftX;
+ attr.shiftY = shiftY;
+ switch (status = DMXChangeDesktopAttributes(display, mask, &attr)) {
+ case DmxBadXinerama:
+ printf("status = %d (No Xinerama)\n", status);
+ break;
+ case DmxBadValue:
+ printf("status = %d (Bad Value)\n", status);
+ break;
+ case Success:
+ printf("status = %d (Success)\n", status);
+ break;
+ default:
+ printf("status = %d (UNKNOWN ERROR *****)\n", status);
+ break;
+ }
+
+ XCloseDisplay(display);
+ return 0;
+}
diff --git a/hw/dmx/examples/dmxrminput.c b/hw/dmx/examples/dmxrminput.c
new file mode 100644
index 000000000..932a5d321
--- /dev/null
+++ b/hw/dmx/examples/dmxrminput.c
@@ -0,0 +1,79 @@
+/* $XFree86$ */
+/*
+ * Copyright 2003,2004 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include "dmxext.h"
+
+int main(int argc, char **argv)
+{
+ Display *display = NULL;
+ int event_base;
+ int error_base;
+ int major_version, minor_version, patch_version;
+ int status;
+
+ if (argc != 3) {
+ printf("Usage: %s display id\n", argv[0]);
+ return -1;
+ }
+
+ if (!(display = XOpenDisplay(argv[1]))) {
+ printf("Cannot open display %s\n", argv[1]);
+ return -1;
+ }
+
+ if (!DMXQueryExtension(display, &event_base, &error_base)) {
+ printf("DMX extension not present\n");
+ return -1;
+ }
+ printf("DMX extension present: event_base = %d, error_base = %d\n",
+ event_base, error_base);
+
+ if (!DMXQueryVersion(display,
+ &major_version, &minor_version, &patch_version)) {
+ printf("Could not get extension version\n");
+ return -1;
+ }
+ printf("Extension version: %d.%d patch %d\n",
+ major_version, minor_version, patch_version);
+
+ status = DMXRemoveInput(display, atoi(argv[2]));
+
+ printf("status = %d\n", status);
+
+ XCloseDisplay(display);
+ return 0;
+}
diff --git a/hw/dmx/examples/dmxrmscreen.c b/hw/dmx/examples/dmxrmscreen.c
new file mode 100644
index 000000000..1b60b1088
--- /dev/null
+++ b/hw/dmx/examples/dmxrmscreen.c
@@ -0,0 +1,81 @@
+/* $XFree86$ */
+/*
+ * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Kevin E. Martin <kem@redhat.com>
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include "dmxext.h"
+
+int main(int argc, char **argv)
+{
+ Display *display = NULL;
+ int event_base;
+ int error_base;
+ int major_version, minor_version, patch_version;
+ int screenNum;
+
+ if (argc != 3) {
+ printf("Usage: %s display screenNum\n", argv[0]);
+ return -1;
+ }
+
+ if (!(display = XOpenDisplay(argv[1]))) {
+ printf("Cannot open display %s\n", argv[1]);
+ return -1;
+ }
+
+ screenNum = strtol(argv[2], NULL, 0);
+
+ if (!DMXQueryExtension(display, &event_base, &error_base)) {
+ printf("DMX extension not present\n");
+ return -1;
+ }
+ printf("DMX extension present: event_base = %d, error_base = %d\n",
+ event_base, error_base);
+
+ if (!DMXQueryVersion(display,
+ &major_version, &minor_version, &patch_version)) {
+ printf("Could not get extension version\n");
+ return -1;
+ }
+ printf("Extension version: %d.%d patch %d\n",
+ major_version, minor_version, patch_version);
+
+ if (!DMXRemoveScreen(display, screenNum))
+ printf("Failed to remove screen #%d\n", screenNum);
+
+ XCloseDisplay(display);
+ return 0;
+}
diff --git a/hw/dmx/examples/dmxwininfo.c b/hw/dmx/examples/dmxwininfo.c
new file mode 100644
index 000000000..201420574
--- /dev/null
+++ b/hw/dmx/examples/dmxwininfo.c
@@ -0,0 +1,497 @@
+/* $XFree86$ */
+/*
+ * Copyright (c) 2003 by the XFree86 Project, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Create a window and use the DMX extension to query the window's
+ * back-end properties. Display the info inside the window itself.
+ *
+ * Brian Paul
+ * 23 Jan 2003
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xmu/SysUtil.h>
+#include "dmxext.h"
+
+static const char *FontName = "fixed";
+
+
+static void
+EventLoop(Display *dpy, Window win, GC gc)
+{
+ XEvent ev;
+ while (1) {
+ XNextEvent( dpy, &ev );
+ switch (ev.type) {
+ case ReparentNotify:
+ break;
+ case MapNotify:
+ break;
+ case ConfigureNotify:
+ case Expose:
+ {
+ int numScreens, count, i;
+ DMXWindowAttributes *winInfo;
+ int x, y;
+ const char *msg = "DMX window info:";
+
+ DMXGetScreenCount(dpy, &numScreens);
+ winInfo
+ = (DMXWindowAttributes *)
+ malloc(numScreens * sizeof(DMXWindowAttributes));
+ assert(winInfo);
+ if (!DMXGetWindowAttributes(dpy, win, &count,
+ numScreens, winInfo)) {
+ printf("Could not get window information for 0x%08lx\n",
+ (long unsigned)win);
+ }
+ x = y = 50;
+ XClearWindow(dpy, win);
+ XDrawString(dpy, win, gc, x, y, msg, strlen(msg));
+ y += 20;
+ for (i = 0; i < count; i++) {
+ char str[500];
+ XmuSnprintf(str, sizeof(str),
+ "screen %d: pos: %dx%d+%d+%d visible: %dx%d+%d+%d",
+ winInfo[i].screen,
+ winInfo[i].pos.width, winInfo[i].pos.height,
+ winInfo[i].pos.x, winInfo[i].pos.y,
+ winInfo[i].vis.width, winInfo[i].vis.height,
+ winInfo[i].vis.x, winInfo[i].vis.y);
+ XDrawString(dpy, win, gc, x, y, str, strlen(str));
+ y += 20;
+ }
+ free(winInfo);
+ }
+ break;
+ default:
+ printf("Event type 0x%x\n", ev.type);
+ }
+ }
+}
+
+int
+main(int argc, char *argv[])
+{
+ const char *displayName = NULL;
+ Display *dpy;
+ int event_base, error_base;
+ int scr, n;
+ long vinfoMask, attrMask;
+ XVisualInfo vinfoTemp, *visInfo;
+ Visual *vis;
+ Window win, root;
+ XSetWindowAttributes attr;
+ XFontStruct *fontInfo;
+ GC gc;
+
+ if (argc > 1) {
+ displayName = argv[1];
+ }
+
+ dpy = XOpenDisplay(displayName);
+ if (!dpy) {
+ fprintf(stderr, "Unable to open display %s\n", displayName);
+ return -1;
+ }
+
+ if (!DMXQueryExtension(dpy, &event_base, &error_base)) {
+ fprintf(stderr, "DMX extension not available on this display.\n");
+ return -1;
+ }
+
+ scr = DefaultScreen(dpy);
+ root = RootWindow(dpy, scr);
+ vis = DefaultVisual(dpy, scr);
+
+ vinfoMask = VisualIDMask;
+ vinfoTemp.visualid = vis->visualid;
+ visInfo = XGetVisualInfo(dpy, vinfoMask, &vinfoTemp, &n);
+ if (!visInfo || n != 1) {
+ fprintf(stderr, "Unable to get visual!\n");
+ XCloseDisplay(dpy);
+ return -1;
+ }
+
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap(dpy, root, visInfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask;
+ attrMask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow(dpy, root,
+ 500, 500, 600, 400, /* x, y, w, h */
+ 0, /* border_width */
+ visInfo->depth, InputOutput,
+ visInfo->visual, attrMask, &attr);
+
+
+ if (!win) {
+ fprintf(stderr, "Unable to create window!\n");
+ XCloseDisplay(dpy);
+ return -1;
+ }
+
+ fontInfo = XLoadQueryFont(dpy, FontName);
+ if (!fontInfo) {
+ fprintf(stderr, "Error: font %s not found\n", FontName);
+ exit(0);
+ }
+
+ gc = XCreateGC(dpy, win, 0, NULL);
+ XSetBackground(dpy, gc, BlackPixel(dpy, scr));
+ XSetForeground(dpy, gc, WhitePixel(dpy, scr));
+ XSetFont(dpy, gc, fontInfo->fid);
+
+ XMapWindow(dpy, win);
+
+ EventLoop(dpy, win, gc);
+
+ XDestroyWindow(dpy, win);
+ XCloseDisplay(dpy);
+ return 0;
+}
+
+#if 00
+
+static void make_window( char *title, int color_flag )
+{
+ int x = 10, y = 10, width = 400, height = 300;
+ Display *dpy;
+ int scr;
+ Window root, win;
+ Colormap cmap;
+ XColor xcolor;
+ int attr_flags;
+ XVisualInfo *visinfo;
+ XSetWindowAttributes attr;
+ XTextProperty tp;
+ XSizeHints sh;
+ XEvent e;
+ XMesaContext context;
+ XMesaVisual visual;
+ XMesaBuffer buffer;
+
+
+ /*
+ * Do the usual X things to make a window.
+ */
+
+ dpy = XOpenDisplay(NULL);
+ if (!dpy) {
+ printf("Couldn't open default display!\n");
+ exit(1);
+ }
+
+ scr = DefaultScreen(dpy);
+ root = RootWindow(dpy, scr);
+
+ /* alloc visinfo struct */
+ visinfo = (XVisualInfo *) malloc( sizeof(XVisualInfo) );
+
+ /* Get a visual and colormap */
+ if (color_flag) {
+ /* Open TrueColor window */
+
+/*
+ if (!XMatchVisualInfo( dpy, scr, 24, TrueColor, visinfo )) {
+ printf("Couldn't get 24-bit TrueColor visual!\n");
+ exit(1);
+ }
+*/
+ if (!XMatchVisualInfo( dpy, scr, 8, PseudoColor, visinfo )) {
+ printf("Couldn't get 8-bit PseudoColor visual!\n");
+ exit(1);
+ }
+
+ cmap = XCreateColormap( dpy, root, visinfo->visual, AllocNone );
+ Black = Red = Green = Blue = 0;
+ }
+ else {
+ /* Open color index window */
+
+ if (!XMatchVisualInfo( dpy, scr, 8, PseudoColor, visinfo )) {
+ printf("Couldn't get 8-bit PseudoColor visual\n");
+ exit(1);
+ }
+
+ cmap = XCreateColormap( dpy, root, visinfo->visual, AllocNone );
+
+ /* Allocate colors */
+ xcolor.red = 0x0;
+ xcolor.green = 0x0;
+ xcolor.blue = 0x0;
+ xcolor.flags = DoRed | DoGreen | DoBlue;
+ if (!XAllocColor( dpy, cmap, &xcolor )) {
+ printf("Couldn't allocate black!\n");
+ exit(1);
+ }
+ Black = xcolor.pixel;
+
+ xcolor.red = 0xffff;
+ xcolor.green = 0x0;
+ xcolor.blue = 0x0;
+ xcolor.flags = DoRed | DoGreen | DoBlue;
+ if (!XAllocColor( dpy, cmap, &xcolor )) {
+ printf("Couldn't allocate red!\n");
+ exit(1);
+ }
+ Red = xcolor.pixel;
+
+ xcolor.red = 0x0;
+ xcolor.green = 0xffff;
+ xcolor.blue = 0x0;
+ xcolor.flags = DoRed | DoGreen | DoBlue;
+ if (!XAllocColor( dpy, cmap, &xcolor )) {
+ printf("Couldn't allocate green!\n");
+ exit(1);
+ }
+ Green = xcolor.pixel;
+
+ xcolor.red = 0x0;
+ xcolor.green = 0x0;
+ xcolor.blue = 0xffff;
+ xcolor.flags = DoRed | DoGreen | DoBlue;
+ if (!XAllocColor( dpy, cmap, &xcolor )) {
+ printf("Couldn't allocate blue!\n");
+ exit(1);
+ }
+ Blue = xcolor.pixel;
+ }
+
+ /* set window attributes */
+ attr.colormap = cmap;
+ attr.event_mask = ExposureMask | StructureNotifyMask;
+ attr.border_pixel = BlackPixel( dpy, scr );
+ attr.background_pixel = BlackPixel( dpy, scr );
+ attr_flags = CWColormap | CWEventMask | CWBorderPixel | CWBackPixel;
+
+ /* Create the window */
+ win = XCreateWindow( dpy, root, x,y, width, height, 0,
+ visinfo->depth, InputOutput,
+ visinfo->visual,
+ attr_flags, &attr);
+ if (!win) {
+ printf("Couldn't open window!\n");
+ exit(1);
+ }
+
+ XStringListToTextProperty(&title, 1, &tp);
+ sh.flags = USPosition | USSize;
+ XSetWMProperties(dpy, win, &tp, &tp, 0, 0, &sh, 0, 0);
+ XMapWindow(dpy, win);
+ while (1) {
+ XNextEvent( dpy, &e );
+ if (e.type == MapNotify && e.xmap.window == win) {
+ break;
+ }
+ }
+
+
+ /*
+ * Now do the special Mesa/Xlib stuff!
+ */
+
+ visual = XMesaCreateVisual( dpy, visinfo,
+ (GLboolean) color_flag,
+ GL_FALSE, /* alpha_flag */
+ GL_FALSE, /* db_flag */
+ GL_FALSE, /* stereo flag */
+ GL_FALSE, /* ximage_flag */
+ 0, /* depth size */
+ 0, /* stencil size */
+ 0,0,0,0, /* accum_size */
+ 0, /* num samples */
+ 0, /* level */
+ 0 /* caveat */
+ );
+ if (!visual) {
+ printf("Couldn't create Mesa/X visual!\n");
+ exit(1);
+ }
+
+ /* Create a Mesa rendering context */
+ context = XMesaCreateContext( visual,
+ NULL /* share_list */
+ );
+ if (!context) {
+ printf("Couldn't create Mesa/X context!\n");
+ exit(1);
+ }
+
+ buffer = XMesaCreateWindowBuffer( visual, win );
+ if (!buffer) {
+ printf("Couldn't create Mesa/X buffer!\n");
+ exit(1);
+ }
+
+
+ XMesaMakeCurrent( context, buffer );
+
+ /* Ready to render! */
+}
+
+
+
+static void draw_cube( void )
+{
+ /* X faces */
+ glIndexi( Red );
+ glColor3f( 1.0, 0.0, 0.0 );
+ glBegin( GL_POLYGON );
+ glVertex3f( 1.0, 1.0, 1.0 );
+ glVertex3f( 1.0, -1.0, 1.0 );
+ glVertex3f( 1.0, -1.0, -1.0 );
+ glVertex3f( 1.0, 1.0, -1.0 );
+ glEnd();
+
+ glBegin( GL_POLYGON );
+ glVertex3f( -1.0, 1.0, 1.0 );
+ glVertex3f( -1.0, 1.0, -1.0 );
+ glVertex3f( -1.0, -1.0, -1.0 );
+ glVertex3f( -1.0, -1.0, 1.0 );
+ glEnd();
+
+ /* Y faces */
+ glIndexi( Green );
+ glColor3f( 0.0, 1.0, 0.0 );
+ glBegin( GL_POLYGON );
+ glVertex3f( 1.0, 1.0, 1.0 );
+ glVertex3f( 1.0, 1.0, -1.0 );
+ glVertex3f( -1.0, 1.0, -1.0 );
+ glVertex3f( -1.0, 1.0, 1.0 );
+ glEnd();
+
+ glBegin( GL_POLYGON );
+ glVertex3f( 1.0, -1.0, 1.0 );
+ glVertex3f( -1.0, -1.0, 1.0 );
+ glVertex3f( -1.0, -1.0, -1.0 );
+ glVertex3f( 1.0, -1.0, -1.0 );
+ glEnd();
+
+ /* Z faces */
+ glIndexi( Blue );
+ glColor3f( 0.0, 0.0, 1.0 );
+ glBegin( GL_POLYGON );
+ glVertex3f( 1.0, 1.0, 1.0 );
+ glVertex3f( -1.0, 1.0, 1.0 );
+ glVertex3f( -1.0, -1.0, 1.0 );
+ glVertex3f( 1.0, -1.0, 1.0 );
+ glEnd();
+
+ glBegin( GL_POLYGON );
+ glVertex3f( 1.0, 1.0, -1.0 );
+ glVertex3f( 1.0,-1.0, -1.0 );
+ glVertex3f( -1.0,-1.0, -1.0 );
+ glVertex3f( -1.0, 1.0, -1.0 );
+ glEnd();
+}
+
+
+
+
+static void display_loop( void )
+{
+ GLfloat xrot, yrot, zrot;
+
+ xrot = yrot = zrot = 0.0;
+
+ glClearColor( 0.0, 0.0, 0.0, 0.0 );
+ glClearIndex( Black );
+
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ glFrustum( -1.0, 1.0, -1.0, 1.0, 1.0, 10.0 );
+ glTranslatef( 0.0, 0.0, -5.0 );
+
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+
+ glCullFace( GL_BACK );
+ glEnable( GL_CULL_FACE );
+
+ glShadeModel( GL_FLAT );
+
+ while (1) {
+ glClear( GL_COLOR_BUFFER_BIT );
+ glPushMatrix();
+ glRotatef( xrot, 1.0, 0.0, 0.0 );
+ glRotatef( yrot, 0.0, 1.0, 0.0 );
+ glRotatef( zrot, 0.0, 0.0, 1.0 );
+
+ draw_cube();
+
+ glPopMatrix();
+ glFinish();
+
+ xrot += 10.0;
+ yrot += 7.0;
+ zrot -= 3.0;
+ }
+
+}
+
+
+
+
+int main( int argc, char *argv[] )
+{
+ int mode = 0;
+
+ if (argc >= 2)
+ {
+ if (strcmp(argv[1],"-ci")==0)
+ mode = 0;
+ else if (strcmp(argv[1],"-rgb")==0)
+ mode = 1;
+ else
+ {
+ printf("Bad flag: %s\n", argv[1]);
+ printf("Specify -ci for 8-bit color index or -rgb for RGB mode\n");
+ exit(1);
+ }
+ }
+ else
+ {
+ printf("Specify -ci for 8-bit color index or -rgb for RGB mode\n");
+ printf("Defaulting to 8-bit color index\n");
+ }
+
+ make_window( argv[0], mode );
+
+ display_loop();
+ return 0;
+}
+
+
+#endif
diff --git a/hw/dmx/examples/ev.c b/hw/dmx/examples/ev.c
new file mode 100644
index 000000000..04c47eb11
--- /dev/null
+++ b/hw/dmx/examples/ev.c
@@ -0,0 +1,183 @@
+/* $XFree86$ */
+/*
+ * Copyright 2002 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * This is a simple test program that reads from /dev/input/event*,
+ * decoding events into a human readable form.
+ */
+
+/*
+ * Authors:
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <time.h>
+#include <linux/input.h>
+
+struct input_event event;
+
+int main(int argc, char **argv)
+{
+ char name[64]; /* RATS: Use ok, but could be better */
+ char buf[256] = { 0, }; /* RATS: Use ok */
+ unsigned char mask[EV_MAX/8 + 1]; /* RATS: Use ok */
+ int version;
+ int fd = 0;
+ int rc;
+ int i, j;
+ char *tmp;
+
+#define test_bit(bit) (mask[(bit)/8] & (1 << ((bit)%8)))
+
+ for (i = 0; i < 32; i++) {
+ sprintf(name, "/dev/input/event%d", i);
+ if ((fd = open(name, O_RDONLY, 0)) >= 0) {
+ ioctl(fd, EVIOCGVERSION, &version);
+ ioctl(fd, EVIOCGNAME(sizeof(buf)), buf);
+ ioctl(fd, EVIOCGBIT(0, sizeof(mask)), mask);
+ printf("%s\n", name);
+ printf(" evdev version: %d.%d.%d\n",
+ version >> 16, (version >> 8) & 0xff, version & 0xff);
+ printf(" name: %s\n", buf);
+ printf(" features:");
+ for (j = 0; j < EV_MAX; j++) {
+ if (test_bit(j)) {
+ const char *type = "unknown";
+ switch(j) {
+ case EV_KEY: type = "keys/buttons"; break;
+ case EV_REL: type = "relative"; break;
+ case EV_ABS: type = "absolute"; break;
+ case EV_MSC: type = "reserved"; break;
+ case EV_LED: type = "leds"; break;
+ case EV_SND: type = "sound"; break;
+ case EV_REP: type = "repeat"; break;
+ case EV_FF: type = "feedback"; break;
+ }
+ printf(" %s", type);
+ }
+ }
+ printf("\n");
+ close(fd);
+ }
+ }
+
+ if (argc > 1) {
+ sprintf(name, "/dev/input/event%d", atoi(argv[1]));
+ if ((fd = open(name, O_RDWR, 0)) >= 0) {
+ printf("%s: open, fd = %d\n", name, fd);
+ for (i = 0; i < LED_MAX; i++) {
+ event.time.tv_sec = time(0);
+ event.time.tv_usec = 0;
+ event.type = EV_LED;
+ event.code = i;
+ event.value = 0;
+ write(fd, &event, sizeof(event));
+ }
+
+ while ((rc = read(fd, &event, sizeof(event))) > 0) {
+ printf("%-24.24s.%06lu type 0x%04x; code 0x%04x;"
+ " value 0x%08x; ",
+ ctime(&event.time.tv_sec),
+ event.time.tv_usec,
+ event.type, event.code, event.value);
+ switch (event.type) {
+ case EV_KEY:
+ if (event.code > BTN_MISC) {
+ printf("Button %d %s",
+ event.code & 0xff,
+ event.value ? "press" : "release");
+ } else {
+ printf("Key %d (0x%x) %s",
+ event.code & 0xff,
+ event.code & 0xff,
+ event.value ? "press" : "release");
+ }
+ break;
+ case EV_REL:
+ switch (event.code) {
+ case REL_X: tmp = "X"; break;
+ case REL_Y: tmp = "Y"; break;
+ case REL_HWHEEL: tmp = "HWHEEL"; break;
+ case REL_DIAL: tmp = "DIAL"; break;
+ case REL_WHEEL: tmp = "WHEEL"; break;
+ case REL_MISC: tmp = "MISC"; break;
+ default: tmp = "UNKNOWN"; break;
+ }
+ printf("Relative %s %d", tmp, event.value);
+ break;
+ case EV_ABS:
+ switch (event.code) {
+ case ABS_X: tmp = "X"; break;
+ case ABS_Y: tmp = "Y"; break;
+ case ABS_Z: tmp = "Z"; break;
+ case ABS_RX: tmp = "RX"; break;
+ case ABS_RY: tmp = "RY"; break;
+ case ABS_RZ: tmp = "RZ"; break;
+ case ABS_THROTTLE: tmp = "THROTTLE"; break;
+ case ABS_RUDDER: tmp = "RUDDER"; break;
+ case ABS_WHEEL: tmp = "WHEEL"; break;
+ case ABS_GAS: tmp = "GAS"; break;
+ case ABS_BRAKE: tmp = "BRAKE"; break;
+ case ABS_HAT0X: tmp = "HAT0X"; break;
+ case ABS_HAT0Y: tmp = "HAT0Y"; break;
+ case ABS_HAT1X: tmp = "HAT1X"; break;
+ case ABS_HAT1Y: tmp = "HAT1Y"; break;
+ case ABS_HAT2X: tmp = "HAT2X"; break;
+ case ABS_HAT2Y: tmp = "HAT2Y"; break;
+ case ABS_HAT3X: tmp = "HAT3X"; break;
+ case ABS_HAT3Y: tmp = "HAT3Y"; break;
+ case ABS_PRESSURE: tmp = "PRESSURE"; break;
+ case ABS_DISTANCE: tmp = "DISTANCE"; break;
+ case ABS_TILT_X: tmp = "TILT_X"; break;
+ case ABS_TILT_Y: tmp = "TILT_Y"; break;
+ case ABS_MISC: tmp = "MISC"; break;
+ default: tmp = "UNKNOWN"; break;
+ }
+ printf("Absolute %s %d", tmp, event.value);
+ break;
+ case EV_MSC: printf("Misc"); break;
+ case EV_LED: printf("Led"); break;
+ case EV_SND: printf("Snd"); break;
+ case EV_REP: printf("Rep"); break;
+ case EV_FF: printf("FF"); break;
+ break;
+ }
+ printf("\n");
+ }
+ printf("rc = %d, errno = %d (%s)\n", rc, errno, strerror(errno));
+ close(fd);
+ }
+ }
+ return 0;
+}
diff --git a/hw/dmx/examples/evi.c b/hw/dmx/examples/evi.c
new file mode 100644
index 000000000..14af95d5a
--- /dev/null
+++ b/hw/dmx/examples/evi.c
@@ -0,0 +1,87 @@
+/* $XFree86$ */
+/*
+ * Copyright 2003 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include <X11/extensions/XEVI.h>
+
+int main(int argc, char **argv)
+{
+ Display *display = NULL;
+ int major_version, minor_version;
+ ExtendedVisualInfo *evi;
+ int count;
+ int i;
+
+ if (argc == 2) {
+ if (!(display = XOpenDisplay(argv[1]))) {
+ printf("Cannot open display %s\n", argv[1]);
+ return -1;
+ }
+ } else {
+ printf("Usage: %s display\n", argv[0]);
+ return -1;
+ }
+
+ if (!display && !(display = XOpenDisplay(NULL))) {
+ printf("Cannot open default display\n");
+ return -1;
+ }
+
+ if (!XeviQueryVersion(display, &major_version, &minor_version)) {
+ printf("EVI extension not present\n");
+ return -1;
+ }
+ printf("EVI Extension version: %d.%d\n", major_version, minor_version);
+
+ XeviGetVisualInfo(display, NULL, 0, &evi, &count);
+
+ for (i = 0; i < count; i++) {
+ printf("%02d vid=0x%02lx screen=%d level=%d type=%u value=%u"
+ " min=%u max=%u conflicts=%u\n",
+ i,
+ (long unsigned)evi[i].core_visual_id,
+ evi[i].screen,
+ evi[i].level,
+ evi[i].transparency_type,
+ evi[i].transparency_value,
+ evi[i].min_hw_colormaps,
+ evi[i].max_hw_colormaps,
+ evi[i].num_colormap_conflicts);
+ }
+
+ XCloseDisplay(display);
+ return 0;
+}
diff --git a/hw/dmx/examples/res.c b/hw/dmx/examples/res.c
new file mode 100644
index 000000000..3af5541fa
--- /dev/null
+++ b/hw/dmx/examples/res.c
@@ -0,0 +1,100 @@
+/* $XFree86$ */
+/*
+ * Copyright 2003 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include <X11/extensions/XRes.h>
+
+int main(int argc, char **argv)
+{
+ Display *display = NULL;
+ int major_version, minor_version;
+ int event, error;
+ int count;
+ int i;
+ XResClient *clients;
+
+ if (argc == 2) {
+ if (!(display = XOpenDisplay(argv[1]))) {
+ printf("Cannot open display %s\n", argv[1]);
+ return -1;
+ }
+ } else {
+ printf("Usage: %s display\n", argv[0]);
+ return -1;
+ }
+
+ if (!display && !(display = XOpenDisplay(NULL))) {
+ printf("Cannot open default display\n");
+ return -1;
+ }
+
+ if (!XResQueryExtension(display, &event, &error)) {
+ printf("X-Resource extension not present\n");
+ return -1;
+ }
+ printf("X-Resource extension present: event=%d error=%d\n", event, error);
+
+ if (!XResQueryVersion(display, &major_version, &minor_version)) {
+ printf("XResQueryVersion call failed\n");
+ return -1;
+ }
+ printf("X-Resource extension version: %d.%d\n",
+ major_version, minor_version);
+
+ XResQueryClients(display, &count, &clients);
+
+ printf("%d clients:\n", count);
+ for (i = 0; i < count; i++) {
+ int c, j;
+ XResType *types;
+
+ XResQueryClientResources(display, clients[i].resource_base,
+ &c, &types);
+ printf(" %3d: base = 0x%lx, mask = 0x%lx, %d resource types:\n",
+ i, (long unsigned)clients[i].resource_base,
+ (long unsigned)clients[i].resource_mask, c);
+ for (j = 0; j < c; j++) {
+ char *name = XGetAtomName(display, types[j].resource_type);
+ printf(" %2d: %s %d\n", j, name, types[j].count);
+ XFree(name);
+ }
+ XFree(types);
+ }
+
+ XFree(clients);
+ XCloseDisplay(display);
+ return 0;
+}
diff --git a/hw/dmx/examples/xbell.c b/hw/dmx/examples/xbell.c
new file mode 100644
index 000000000..4d55740a8
--- /dev/null
+++ b/hw/dmx/examples/xbell.c
@@ -0,0 +1,102 @@
+/* $XFree86$ */
+/*
+ * Copyright 2002 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+
+static void pkc(XKeyboardControl *kc, unsigned long vm)
+{
+ if (vm&KBKeyClickPercent)
+ printf(" key_click_percent = %d\n", kc->key_click_percent);
+ if (vm&KBBellPercent)
+ printf(" bell_percent = %d\n", kc->bell_percent);
+ if (vm&KBBellPitch)
+ printf(" bell_pitch = %d\n", kc->bell_pitch);
+ if (vm&KBBellDuration)
+ printf(" bell_duration = %d\n", kc->bell_duration);
+ if (vm&KBLed)
+ printf(" led = 0x%x\n", kc->led);
+ if (vm&KBLedMode)
+ printf(" led_mode = %d\n", kc->led_mode);
+ if (vm&KBKey)
+ printf(" key = %d\n", kc->key);
+ if (vm&KBAutoRepeatMode)
+ printf(" auto_repeat_mode = %d\n", kc->auto_repeat_mode);
+}
+
+static void pks(XKeyboardState *ks)
+{
+ printf(" key_click_percent = %d\n", ks->key_click_percent);
+ printf(" bell_percent = %d\n", ks->bell_percent);
+ printf(" bell_pitch = %u\n", ks->bell_pitch);
+ printf(" bell_duration = %u\n", ks->bell_duration);
+ printf(" led_mask = 0x%lx\n", ks->led_mask);
+ printf(" global_auto_repeat = %d\n", ks->global_auto_repeat);
+}
+
+int main(int argc, char **argv)
+{
+ Display *display = XOpenDisplay(NULL);
+ XKeyboardControl kc;
+ XKeyboardState ks;
+ unsigned long vm;
+ int percent;
+
+ if (argc != 5) {
+ printf("Usage: xbell percent baseVolume pitch duration\n");
+ return 1;
+ }
+
+ vm = (KBBellPercent
+ | KBBellPitch
+ | KBBellDuration);
+ percent = atoi(argv[1]);
+ kc.bell_percent = atoi(argv[2]);
+ kc.bell_pitch = atoi(argv[3]);
+ kc.bell_duration = atoi(argv[4]);
+
+ printf("Setting:\n");
+ pkc(&kc, vm);
+ XChangeKeyboardControl(display, vm, &kc);
+
+ printf("Have:\n");
+ XGetKeyboardControl(display, &ks);
+ pks(&ks);
+
+ XBell(display, 100);
+
+ XCloseDisplay(display);
+ return 0;
+}
diff --git a/hw/dmx/examples/xdmx.c b/hw/dmx/examples/xdmx.c
new file mode 100644
index 000000000..540465a79
--- /dev/null
+++ b/hw/dmx/examples/xdmx.c
@@ -0,0 +1,240 @@
+/* $XFree86$ */
+/*
+ * Copyright 2001,2002 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include "dmxext.h"
+
+static void indent(int level)
+{
+ int i;
+ for (i = 0; i < level; i++) printf(" ");
+}
+
+static void print_window_id(const char *displayName, Display *display,
+ Window window, int level, int child)
+{
+ char *name;
+
+ if (!XFetchName(display, window, &name)) name = NULL;
+ indent(level);
+ if (child) printf("(%d) ", child);
+ printf("%s window 0x%08lx: %s%s\n",
+ displayName,
+ (long unsigned)window,
+ name ? name : "",
+ (window == DefaultRootWindow(display))
+ ? " (DMX root window)" : "");
+ if (name) XFree(name);
+}
+
+static void print_info(Display *display, Window window, int level, int child)
+{
+ DMXWindowAttributes winfo[128];
+ int count;
+ int i;
+
+ if (!DMXGetWindowAttributes(display, window, &count, 128, winfo)) {
+ printf("Could not get window information for 0x%08lx\n",
+ (long unsigned)window);
+ exit(-2);
+ }
+ printf("\n");
+ print_window_id("DMX", display, window, level, child);
+ for (i = 0; i < count; i++) {
+ DMXScreenAttributes sinfo;
+ Display *backend;
+
+ /* This could also be cached -- the information doesn't change. */
+ if (!DMXGetScreenAttributes(display, winfo[i].screen, &sinfo)) {
+ printf("Could not get screen information for screen %d\n", i);
+ exit(-2);
+ }
+ if (!(backend = XOpenDisplay(sinfo.displayName))) {
+ printf("Cannot open backend display %s\n", sinfo.displayName);
+ exit(-2);
+ }
+ XCloseDisplay(backend);
+
+ indent(level+1);
+ printf("%s window 0x%08lx: %dx%d%+d%+d",
+ sinfo.displayName,
+ (long unsigned)winfo[i].window,
+ winfo[i].pos.width, winfo[i].pos.height,
+ winfo[i].pos.x, winfo[i].pos.y);
+ if (!winfo[i].vis.width
+ && !winfo[i].vis.height
+ && !winfo[i].vis.x
+ && !winfo[i].vis.y) printf(" not visible\n");
+ else if (winfo[i].vis.width == winfo[i].pos.width
+ && winfo[i].vis.height == winfo[i].pos.height) {
+ printf( " %+d%+d\n", winfo[i].vis.x, winfo[i].vis.y);
+ } else {
+ printf( " %dx%d%+d%+d\n",
+ winfo[i].vis.width, winfo[i].vis.height,
+ winfo[i].vis.x, winfo[i].vis.y);
+ }
+ }
+}
+
+static void print_tree(Display *display, Window window, int level, int child)
+{
+ Window root, parent;
+ Window *list;
+ unsigned int count;
+ unsigned int i;
+
+ print_info(display, window, level, child);
+
+ if (!XQueryTree(display, window, &root, &parent, &list, &count)) {
+ printf("Cannot query window tree for 0x%08lx\n",
+ (long unsigned)window);
+ exit(-3);
+ }
+
+ if (count) {
+ indent(level+1);
+ printf("%d child%s:\n", count, count > 1 ? "ren" : "");
+ for (i = 0; i < count; i++) {
+ print_tree(display, list[i], level+1, i+1);
+ }
+ }
+}
+
+static const char *core(DMXInputAttributes *iinfo)
+{
+ if (iinfo->isCore) return "core";
+ else if (iinfo->sendsCore) return "extension (sends core)";
+ else return "extension";
+}
+
+int main(int argc, char **argv)
+{
+ Display *display = NULL;
+ Window window = 0;
+ int event_base;
+ int error_base;
+ int major_version, minor_version, patch_version;
+ DMXScreenAttributes sinfo;
+ DMXInputAttributes iinfo;
+ int count;
+ int i;
+
+ if (argc == 2 || argc == 3) {
+ if (!(display = XOpenDisplay(argv[1]))) {
+ printf("Cannot open display %s\n", argv[1]);
+ return -1;
+ }
+ if (argc == 3) window = strtol(argv[2], NULL, 0);
+ } else {
+ printf("Usage: %s display [windowid]\n", argv[0]);
+ return -1;
+ }
+
+ if (!display && !(display = XOpenDisplay(NULL))) {
+ printf("Cannot open default display\n");
+ return -1;
+ }
+
+ if (!DMXQueryExtension(display, &event_base, &error_base)) {
+ printf("DMX extension not present\n");
+ return -1;
+ }
+ printf("DMX extension present: event_base = %d, error_base = %d\n",
+ event_base, error_base);
+
+ if (!DMXQueryVersion(display,
+ &major_version, &minor_version, &patch_version)) {
+ printf("Could not get extension version\n");
+ return -1;
+ }
+ printf("Extension version: %d.%d patch %d\n",
+ major_version, minor_version, patch_version);
+
+ if (!DMXGetScreenCount(display, &count)) {
+ printf("Could not get screen count\n");
+ return -1;
+ }
+ printf("Screen count = %d\n", count);
+
+ for (i = 0; i < count; i++) {
+ if (!DMXGetScreenAttributes(display, i, &sinfo)) {
+ printf("Could not get screen information for %d\n", i);
+ return -1;
+ }
+ printf("%d: %s %ux%u+%d+%d %d @%dx%d (root: %dx%d%+d%+d)\n",
+ i, sinfo.displayName,
+ sinfo.screenWindowWidth, sinfo.screenWindowHeight,
+ sinfo.screenWindowXoffset, sinfo.screenWindowYoffset,
+ sinfo.logicalScreen,
+ sinfo.rootWindowXorigin, sinfo.rootWindowYorigin,
+ sinfo.rootWindowWidth, sinfo.rootWindowHeight,
+ sinfo.rootWindowXoffset, sinfo.rootWindowYoffset);
+ }
+
+ if (major_version == 1 && minor_version >= 1) {
+ if (!DMXGetInputCount(display, &count)) {
+ printf("Could not get input count\n");
+ return -1;
+ }
+ printf("Input count = %d\n", count);
+ for (i = 0; i < count; i++) {
+ if (!DMXGetInputAttributes(display, i, &iinfo)) {
+ printf("Could not get input information for id %d\n", i);
+ return -1;
+ }
+ switch (iinfo.inputType) {
+ case DMXLocalInputType:
+ printf(" %2d local %-20.20s %s\n", i, "", core(&iinfo));
+ break;
+ case DMXConsoleInputType:
+ printf(" %2d console %-20.20s %s\n",
+ i, iinfo.name, core(&iinfo));
+ break;
+ case DMXBackendInputType:
+ printf(" %2d backend %-20.20s id=%2d screen=%2d %s\n",
+ i, iinfo.name, iinfo.physicalId, iinfo.physicalScreen,
+ core(&iinfo));
+ break;
+ }
+ }
+ }
+
+ if (window) print_info(display, window, 0, 0);
+ else print_tree(display, DefaultRootWindow(display), 0, 0);
+
+ XCloseDisplay(display);
+ return 0;
+}
diff --git a/hw/dmx/examples/xinput.c b/hw/dmx/examples/xinput.c
new file mode 100644
index 000000000..c1787f18c
--- /dev/null
+++ b/hw/dmx/examples/xinput.c
@@ -0,0 +1,319 @@
+/* $XFree86$ */
+/*
+ * Copyright 2001,2002 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <X11/Xlib.h>
+#include <X11/XKBlib.h>
+#include <X11/extensions/XInput.h>
+#include <X11/extensions/XKB.h>
+#include <X11/extensions/XKBstr.h>
+#include "dmxext.h"
+#include <sys/time.h>
+
+static const char *core(DMXInputAttributes *iinf)
+{
+ if (iinf->isCore) return "core";
+ else if (iinf->sendsCore) return "extension (sends core events)";
+ else return "extension";
+}
+
+static void printdmxinfo(Display *display, int id)
+{
+ int event_base;
+ int error_base;
+ int major_version, minor_version, patch_version;
+ DMXInputAttributes iinf;
+ Display *backend;
+ char *backendname = NULL;
+
+ if (!DMXQueryExtension(display, &event_base, &error_base)) return;
+ if (!DMXQueryVersion(display, &major_version, &minor_version,
+ &patch_version)) return;
+ if (major_version == 1 && minor_version == 0) return; /* too old */
+ if (!DMXGetInputAttributes(display, id, &iinf)) return;
+
+ printf(" DMX Information: ");
+ if (iinf.detached) printf("detached ");
+ else printf("active ");
+ switch (iinf.inputType) {
+ case DMXLocalInputType:
+ printf("local, %s", core(&iinf));
+ break;
+ case DMXConsoleInputType:
+ printf("console %s, %s", iinf.name, core(&iinf));
+ break;
+ case DMXBackendInputType:
+ if (iinf.physicalId >= 0) {
+ if ((backend = XOpenDisplay(iinf.name))) {
+ XExtensionVersion *ext = XGetExtensionVersion(backend, INAME);
+ if (ext && ext != (XExtensionVersion *)NoSuchExtension) {
+ int count, i;
+ XDeviceInfo *devInfo = XListInputDevices(backend, &count);
+ if (devInfo) {
+ for (i = 0; i < count; i++) {
+ if ((unsigned)iinf.physicalId == devInfo[i].id
+ && devInfo[i].name) {
+ backendname = strdup(devInfo[i].name);
+ break;
+ }
+ }
+ XFreeDeviceList(devInfo);
+ }
+ }
+ XCloseDisplay(backend);
+ }
+ }
+ printf("backend o%d/%s",iinf.physicalScreen, iinf.name);
+ if (iinf.physicalId >= 0) printf("/id%d", iinf.physicalId);
+ if (backendname) {
+ printf("=%s", backendname);
+ free(backendname);
+ }
+ printf(" %s", core(&iinf));
+ break;
+ }
+ printf("\n");
+}
+
+int main(int argc, char **argv)
+{
+ Display *display = NULL;
+ int device = -1;
+ int newmouse = -1;
+ int newkbd = -1;
+ int count;
+ int i, j;
+ XDeviceInfo *devInfo;
+ XExtensionVersion *ext;
+
+ if (argc == 2 || argc == 3 || argc == 4 || argc == 5) {
+ if (!(display = XOpenDisplay(argv[1]))) {
+ printf("Cannot open display %s\n", argv[1]);
+ return -1;
+ }
+ if (argc >= 3) device = strtol(argv[2], NULL, 0);
+ if (argc >= 4) newmouse = strtol(argv[3], NULL, 0);
+ if (argc >= 5) newkbd = strtol(argv[4], NULL, 0);
+ } else {
+ printf("Usage: %s display [device] [newmouse] [newkbd]\n", argv[0]);
+ return -1;
+ }
+
+ if (!display && !(display = XOpenDisplay(NULL))) {
+ printf("Cannot open default display\n");
+ return -1;
+ }
+
+ ext = XGetExtensionVersion(display, INAME);
+ if (!ext || ext == (XExtensionVersion *)NoSuchExtension) {
+ printf("No XInputExtension\n");
+ return -1;
+ }
+ printf("%s version %d.%d\n",
+ INAME, ext->major_version, ext->minor_version);
+
+ if (!(devInfo = XListInputDevices(display, &count)) || !count) {
+ printf("Cannot list devices\n");
+ return -1;
+ }
+
+ for (i = 0; i < count; i++) {
+ XAnyClassPtr any;
+ const char *kind = "Unknown";
+ int has_key = 0;
+
+ switch (devInfo[i].use) {
+ case IsXPointer: kind = "XPointer"; break;
+ case IsXKeyboard: kind = "XKeyboard"; break;
+ case IsXExtensionDevice: kind = "XExtensionDevice"; break;
+ }
+ printf("%2lu %-20.20s %-16.16s",
+ (long unsigned)devInfo[i].id,
+ devInfo[i].name ? devInfo[i].name : "", kind);
+
+ for (j = 0, any = devInfo[i].inputclassinfo;
+ j < devInfo[i].num_classes;
+ any = (XAnyClassPtr)((char *)any + any->length), j++) {
+ const char *class = "unk";
+ switch (any->class) {
+ case KeyClass: class = "key"; ++has_key; break;
+ case ButtonClass: class = "btn"; break;
+ case ValuatorClass: class = "val"; break;
+ case FeedbackClass: class = "fdb"; break;
+ case ProximityClass: class = "prx"; break;
+ case FocusClass: class = "foc"; break;
+ case OtherClass: class = "oth"; break;
+ }
+ printf(" %s", class);
+ }
+ printf("\n");
+ printdmxinfo(display, i);
+
+ if (has_key) {
+ XkbDescPtr xkb;
+ if ((xkb = XkbGetKeyboard(display,
+ XkbAllComponentsMask,
+ devInfo[i].id))) {
+ printf(" Xkb Information:\n");
+ printf(" Device id = %d\n", xkb->device_spec);
+ printf(" Min keycode = 0x%02x\n", xkb->min_key_code);
+ printf(" Max keycode = 0x%02x\n", xkb->max_key_code);
+#define PRINTNAME(x) \
+ printf(" %s = %s\n", \
+ #x, xkb->names->x ? XGetAtomName(display, xkb->names->x) : "")
+ PRINTNAME(keycodes);
+ PRINTNAME(geometry);
+ PRINTNAME(symbols);
+ PRINTNAME(types);
+ PRINTNAME(compat);
+ }
+ }
+ }
+
+ if (newmouse >= 0) {
+ XDevice *dev;
+
+ printf("Trying to make device %d core mouse\n", newmouse);
+ dev = XOpenDevice(display, devInfo[newmouse].id);
+ printf("Status = %d\n",
+ XChangePointerDevice(display, dev, 0, 1));
+ return 0;
+ }
+
+ if (newkbd >= 0) {
+ XDevice *dev;
+
+ printf("Trying to make device %d core keyboard\n", newkbd);
+ dev = XOpenDevice(display, devInfo[newkbd].id);
+ printf("Status = %d\n",
+ XChangeKeyboardDevice(display, dev));
+ return 0;
+ }
+
+
+ if (device >=0){
+#define MAX_EVENTS 100
+ int cnt = 0;
+ XDevice *dev;
+ XEventClass event_list[MAX_EVENTS];
+ int event_type[MAX_EVENTS];
+ const char *names[MAX_EVENTS];
+ int total = 0;
+
+#define ADD(type) \
+ if (cnt >= MAX_EVENTS) abort(); \
+ names[cnt] = #type; \
+ type(dev, event_type[cnt], event_list[cnt]); \
+ if (event_type[cnt]) ++cnt
+
+
+ dev = XOpenDevice(display, devInfo[device].id);
+ ADD(DeviceKeyPress);
+ ADD(DeviceKeyRelease);
+ ADD(DeviceButtonPress);
+ ADD(DeviceButtonRelease);
+ ADD(DeviceMotionNotify);
+ ADD(DeviceFocusIn);
+ ADD(DeviceFocusOut);
+ ADD(ProximityIn);
+ ADD(ProximityOut);
+ ADD(DeviceStateNotify);
+ ADD(DeviceMappingNotify);
+ ADD(ChangeDeviceNotify);
+
+ for (i = 0; i < cnt; i++) {
+ printf("Waiting for %s events of type %d (%lu) on 0x%08lx\n",
+ names[i],
+ event_type[i], (unsigned long)event_list[i],
+ (long unsigned)DefaultRootWindow(display));
+ }
+ XSelectExtensionEvent(display, DefaultRootWindow(display),
+ event_list, cnt);
+
+ for (;;) {
+ XEvent event;
+ XNextEvent(display, &event);
+ for (i = 0; i < cnt; i++) {
+ XDeviceMotionEvent *e = (XDeviceMotionEvent *)&event;
+ XDeviceButtonEvent *b = (XDeviceButtonEvent *)&event;
+ if (event.type == event_type[i]) {
+ printf("%s id=%lu (%d @ %d,%d; s=0x%04x, d=%d, t=%lu)"
+ " axes_count=%d first=%d %d %d %d %d %d %d\n",
+ names[i],
+ (long unsigned)e->deviceid,
+ e->type,
+ e->x, e->y,
+ e->device_state,
+ b->button,
+ (long unsigned)b->time,
+ e->axes_count,
+ e->first_axis,
+ e->axis_data[0],
+ e->axis_data[1],
+ e->axis_data[2],
+ e->axis_data[3],
+ e->axis_data[4],
+ e->axis_data[5]);
+ }
+ }
+ ++total;
+#if 0
+ /* Used to check motion history for
+ * extension devices. */
+ if (!(total % 10)) {
+ XDeviceTimeCoord *tc;
+ int n, m, a;
+ struct timeval tv;
+ unsigned long ms;
+ gettimeofday(&tv, NULL);
+ ms = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+ tc = XGetDeviceMotionEvents(display, dev, ms-1000, ms,
+ &n, &m, &a);
+ printf("Got %d events of mode %s with %d axes\n",
+ n, m == Absolute ? "Absolute" : "Relative", a);
+ for (i = 0; i < n && i < 10; i++) {
+ printf(" %d: %lu %d %d\n",
+ i, tc[i].time, tc[i].data[0], tc[i].data[1]);
+ }
+ XFreeDeviceMotionEvents(tc);
+ }
+#endif
+ }
+ }
+
+ XCloseDisplay(display);
+ return 0;
+}
diff --git a/hw/dmx/examples/xled.c b/hw/dmx/examples/xled.c
new file mode 100644
index 000000000..cb4bcb1ac
--- /dev/null
+++ b/hw/dmx/examples/xled.c
@@ -0,0 +1,125 @@
+/* $XFree86$ */
+/*
+ * Copyright 2003 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <X11/Xlib.h>
+#include <X11/XKBlib.h>
+#include <X11/extensions/XKB.h>
+#include <X11/extensions/XKBstr.h>
+#include <sys/time.h>
+
+int main(int argc, char **argv)
+{
+ Display *display = NULL;
+ int mask = 0;
+ unsigned i;
+ XKeyboardState ks;
+ XKeyboardControl kc;
+ XkbDescPtr xkb;
+ int old[32];
+
+ if (argc == 2 || argc == 3) {
+ if (!(display = XOpenDisplay(argv[1]))) {
+ printf("Cannot open display %s\n", argv[1]);
+ return -1;
+ }
+ if (argc >= 3) mask = strtol(argv[2], NULL, 0);
+ } else {
+ printf("Usage: %s display [mask]\n", argv[0]);
+ return -1;
+ }
+
+ if (!display && !(display = XOpenDisplay(NULL))) {
+ printf("Cannot open default display\n");
+ return -1;
+ }
+
+ if (!(xkb = XkbAllocKeyboard())) {
+ printf("Cannot allocate\n");
+ return -1;
+ }
+ if (XkbGetIndicatorMap(display, XkbAllIndicatorsMask, xkb)) {
+ printf("Cannot Get Indicators\n");
+ return -1;
+ }
+ if (XkbGetNames(display, XkbAllNamesMask, xkb)) {
+ printf("Cannot Get Names\n");
+ return -1;
+ }
+ for (i = 0; i < XkbNumIndicators; i++) {
+ if (xkb->indicators->phys_indicators & (1 << i)) {
+ printf("led %d = %d\n", i, xkb->indicators->maps[i].flags);
+ old[i] = xkb->indicators->maps[i].flags;
+ xkb->indicators->maps[i].flags = XkbIM_NoAutomatic;
+ }
+ }
+ printf("XkbSetIndicatorMap = %d\n", XkbSetIndicatorMap(display, ~0, xkb));
+ XkbFreeKeyboard(xkb, 0, True);
+
+
+ if (!(xkb = XkbAllocKeyboard())) {
+ printf("Cannot allocate\n");
+ return -1;
+ }
+ if (XkbGetIndicatorMap(display, XkbAllIndicatorsMask, xkb)) {
+ printf("Cannot Get Indicators\n");
+ return -1;
+ }
+ for (i = 0; i < XkbNumIndicators; i++) {
+ if (xkb->indicators->phys_indicators & (1 << i))
+ printf("led %d = %d\n", i, xkb->indicators->maps[i].flags);
+ }
+
+ printf("XGetKeyboardControl = %d\n", XGetKeyboardControl(display, &ks));
+ printf("old mask = 0x%08lx\n", ks.led_mask);
+ for (i = 0; i < 5; i++) {
+ kc.led = i + 1;
+ kc.led_mode = (mask & (1 << i)) ? LedModeOn : LedModeOff;
+ printf("XChangeKeyboardControl = %d\n",
+ XChangeKeyboardControl(display, KBLed | KBLedMode, &kc));
+ }
+ printf("XGetKeyboardControl = %d\n", XGetKeyboardControl(display, &ks));
+ printf("new mask = 0x%08lx\n", ks.led_mask);
+
+ for (i = 0; i < XkbNumIndicators; i++)
+ if (xkb->indicators->phys_indicators & (i << 1))
+ xkb->indicators->maps[i].flags = old[i];
+ printf("XkbSetIndicatorMap = %d\n", XkbSetIndicatorMap(display, ~0, xkb));
+
+ XkbFreeKeyboard(xkb, 0, True);
+ XCloseDisplay(display);
+ return 0;
+}
diff --git a/hw/dmx/examples/xtest.c b/hw/dmx/examples/xtest.c
new file mode 100644
index 000000000..b6f223d27
--- /dev/null
+++ b/hw/dmx/examples/xtest.c
@@ -0,0 +1,76 @@
+/* $XFree86$ */
+/*
+ * Copyright 2003 Red Hat Inc., Durham, North Carolina.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation on the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include <X11/extensions/XTest.h>
+
+int main(int argc, char **argv)
+{
+ Display *display = NULL;
+ int event_base;
+ int error_base;
+ int major_version, minor_version;
+
+ if (argc == 2) {
+ if (!(display = XOpenDisplay(argv[1]))) {
+ printf("Cannot open display %s\n", argv[1]);
+ return -1;
+ }
+ } else {
+ printf("Usage: %s display\n", argv[0]);
+ return -1;
+ }
+
+ if (!display && !(display = XOpenDisplay(NULL))) {
+ printf("Cannot open default display\n");
+ return -1;
+ }
+
+ if (!XTestQueryExtension(display, &event_base, &error_base,
+ &major_version, &minor_version)) {
+ printf("XTEST extension not present\n");
+ return -1;
+ }
+ printf("XTEST extension present: event_base = %d, error_base = %d\n",
+ event_base, error_base);
+ printf("Extension version: %d.%d\n", major_version, minor_version);
+
+ XTestFakeKeyEvent(display, 30, True, 10);
+ XTestFakeKeyEvent(display, 30, False, 10);
+
+ XCloseDisplay(display);
+ return 0;
+}