xserver: Branch 'master' - 20 commits

Adam Jackson ajax at kemper.freedesktop.org
Mon Jul 18 20:29:01 UTC 2016


 Xext/sleepuntil.c                        |   17 -
 Xext/sync.c                              |   12 -
 Xext/xf86bigfont.c                       |    4 
 composite/compalloc.c                    |    4 
 configure.ac                             |    2 
 dix/dispatch.c                           |   34 +--
 dix/dixfonts.c                           |  326 ++++++++++++++++++-------------
 dix/dixutils.c                           |   34 +--
 dix/main.c                               |    4 
 doc/Xinput.xml                           |    8 
 doc/Xserver-spec.xml                     |   59 +----
 exa/exa.c                                |   10 
 glamor/glamor.c                          |    4 
 glamor/glamor_font.c                     |    6 
 hw/dmx/dmxfont.c                         |    9 
 hw/dmx/dmxscrinit.c                      |    4 
 hw/dmx/dmxsync.c                         |    4 
 hw/dmx/input/dmxcommon.c                 |   17 +
 hw/dmx/input/dmxinputinit.c              |    4 
 hw/dmx/input/lnx-ms.c                    |   19 -
 hw/dmx/input/lnx-ps2.c                   |   12 -
 hw/kdrive/ephyr/ephyr.c                  |    4 
 hw/kdrive/fake/mouse.c                   |    1 
 hw/kdrive/linux/evdev.c                  |   14 -
 hw/kdrive/linux/linux.c                  |   64 ++----
 hw/kdrive/linux/mouse.c                  |   34 ---
 hw/kdrive/linux/ms.c                     |   13 -
 hw/kdrive/linux/ps2.c                    |   13 -
 hw/kdrive/linux/tslib.c                  |    1 
 hw/kdrive/src/kdrive.h                   |    6 
 hw/kdrive/src/kinput.c                   |    4 
 hw/vfb/InitOutput.c                      |    4 
 hw/xfree86/common/xf86Events.c           |   51 ++--
 hw/xfree86/common/xf86Init.c             |    2 
 hw/xfree86/common/xf86Module.h           |    4 
 hw/xfree86/common/xf86Priv.h             |    2 
 hw/xfree86/common/xf86VGAarbiter.c       |   10 
 hw/xfree86/common/xf86VGAarbiterPriv.h   |    6 
 hw/xfree86/dri/dri.c                     |   16 -
 hw/xfree86/dri/dri.h                     |   13 -
 hw/xfree86/drivers/modesetting/driver.c  |    8 
 hw/xfree86/drivers/modesetting/vblank.c  |    2 
 hw/xfree86/modes/xf86Rotate.c            |    5 
 hw/xfree86/os-support/shared/posix_tty.c |   33 +--
 hw/xfree86/os-support/shared/sigio.c     |   64 +++---
 hw/xfree86/sdksyms.sh                    |    1 
 hw/xnest/Font.c                          |    7 
 hw/xnest/Handlers.c                      |    4 
 hw/xnest/Handlers.h                      |    5 
 hw/xnest/Init.c                          |   12 -
 hw/xquartz/quartzCocoa.m                 |    8 
 hw/xquartz/quartzCommon.h                |    5 
 hw/xwayland/xwayland.c                   |    4 
 hw/xwin/win.h                            |    4 
 hw/xwin/winwakeup.c                      |    3 
 include/dix.h                            |   26 +-
 include/dixfont.h                        |   18 -
 include/dixfontstr.h                     |    1 
 include/dixfontstubs.h                   |   43 ----
 include/os.h                             |   18 -
 include/scrnintstr.h                     |   11 -
 mi/miglblt.c                             |    6 
 mi/misprite.c                            |    8 
 miext/damage/damage.c                    |    4 
 miext/rootless/rootlessScreen.c          |    4 
 miext/shadow/shadow.c                    |    4 
 os/WaitFor.c                             |   71 ++----
 os/connection.c                          |   84 ++-----
 os/inputthread.c                         |   18 -
 os/io.c                                  |   14 -
 os/osdep.h                               |   14 +
 os/utils.c                               |   25 --
 72 files changed, 624 insertions(+), 765 deletions(-)

New commits:
commit 8d3a368d8980e37e7e8c57065dc901ce809887c6
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Jun 1 22:47:29 2016 -0700

    os: InputThreadFillPipe doesn't need select or poll
    
    The file descriptors passed to InputThreadFillPipe are always
    blocking, so there's no need to use Select (or poll).
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/os/inputthread.c b/os/inputthread.c
index 40a0443..a4266e9 100644
--- a/os/inputthread.c
+++ b/os/inputthread.c
@@ -127,24 +127,10 @@ InputThreadFillPipe(int writeHead)
 {
     int ret;
     char byte = 0;
-    fd_set writePipe;
 
-    FD_ZERO(&writePipe);
-
-    while (1) {
+    do {
         ret = write(writeHead, &byte, 1);
-        if (!ret)
-            FatalError("input-thread: write() returned 0");
-        if (ret > 0)
-            break;
-
-        if (errno != EAGAIN)
-            FatalError("input-thread: filling pipe");
-
-        DebugF("input-thread: pipe full\n");
-        FD_SET(writeHead, &writePipe);
-        Select(writeHead + 1, NULL, &writePipe, NULL, NULL);
-    }
+    } while (ret < 0 && ETEST(errno));
 }
 
 /**
commit ef7ddbe242ed4c461f816663fb88646e41f1c21b
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Jun 1 22:35:09 2016 -0700

    os: Move ETEST macro from io.c to osdep.h
    
    This lets other code share this functionality
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/os/io.c b/os/io.c
index d04ebd8..596deff 100644
--- a/os/io.c
+++ b/os/io.c
@@ -102,20 +102,6 @@ typedef struct _connectionOutput {
 static ConnectionInputPtr AllocateInputBuffer(void);
 static ConnectionOutputPtr AllocateOutputBuffer(void);
 
-/* If EAGAIN and EWOULDBLOCK are distinct errno values, then we check errno
- * for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
- * systems are broken and return EWOULDBLOCK when they should return EAGAIN
- */
-#ifndef WIN32
-# if (EAGAIN != EWOULDBLOCK)
-#  define ETEST(err) (err == EAGAIN || err == EWOULDBLOCK)
-# else
-#  define ETEST(err) (err == EAGAIN)
-# endif
-#else   /* WIN32 The socket errorcodes differ from the normal errors */
-#define ETEST(err) (err == EAGAIN || err == WSAEWOULDBLOCK)
-#endif
-
 static Bool CriticalOutputPending;
 static int timesThisConnection = 0;
 static ConnectionInputPtr FreeInputs = (ConnectionInputPtr) NULL;
diff --git a/os/osdep.h b/os/osdep.h
index 3dc2daf..9dbf0fb 100644
--- a/os/osdep.h
+++ b/os/osdep.h
@@ -100,6 +100,20 @@ SOFTWARE.
 
 #include <stddef.h>
 
+/* If EAGAIN and EWOULDBLOCK are distinct errno values, then we check errno
+ * for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
+ * systems are broken and return EWOULDBLOCK when they should return EAGAIN
+ */
+#ifndef WIN32
+# if (EAGAIN != EWOULDBLOCK)
+#  define ETEST(err) (err == EAGAIN || err == EWOULDBLOCK)
+# else
+#  define ETEST(err) (err == EAGAIN)
+# endif
+#else   /* WIN32 The socket errorcodes differ from the normal errors */
+#define ETEST(err) (err == EAGAIN || err == WSAEWOULDBLOCK)
+#endif
+
 #if defined(XDMCP) || defined(HASXDMAUTH)
 typedef Bool (*ValidatorFunc) (ARRAY8Ptr Auth, ARRAY8Ptr Data, int packet_type);
 typedef Bool (*GeneratorFunc) (ARRAY8Ptr Auth, ARRAY8Ptr Data, int packet_type);
commit 0d294462a5af08ada654c588fad921ed7a22749b
Author: Keith Packard <keithp at keithp.com>
Date:   Sun May 29 15:06:36 2016 -0700

    os: Add X_NOTIFY_ERROR value
    
    This provides a way to report errors on file descriptors that is
    better defined than "any bits which are not READ or WRITE".
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/include/os.h b/include/os.h
index 9a3d9a9..b0a068e 100644
--- a/include/os.h
+++ b/include/os.h
@@ -148,9 +148,10 @@ extern _X_EXPORT void CloseDownConnection(ClientPtr /*client */ );
 
 typedef void (*NotifyFdProcPtr)(int fd, int ready, void *data);
 
-#define X_NOTIFY_NONE   0
-#define X_NOTIFY_READ   1
-#define X_NOTIFY_WRITE  2
+#define X_NOTIFY_NONE   0x0
+#define X_NOTIFY_READ   0x1
+#define X_NOTIFY_WRITE  0x2
+#define X_NOTIFY_ERROR  0x4     /* don't need to select for, always reported */
 
 extern _X_EXPORT Bool SetNotifyFd(int fd, NotifyFdProcPtr notify_fd, int mask, void *data);
 
commit e6636b438322a9a2f2270ad9d60bf3dfc72be0b3
Author: Keith Packard <keithp at keithp.com>
Date:   Thu May 26 10:30:56 2016 -0700

    os: Compute timeout in milliseconds instead of struct timeval
    
    The timeout resolution offered in the AdjustWaitForDelay call is
    only milliseconds, so passing around the timeout as a pointer to a
    struct timeval is not helpful. Doing everything in milliseconds up to
    the point of the select call simplifies the code without affecting
    functionality at all.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/include/os.h b/include/os.h
index 5f65141..9a3d9a9 100644
--- a/include/os.h
+++ b/include/os.h
@@ -182,8 +182,7 @@ extern void ForceClockId(clockid_t /* forced_clockid */);
 extern _X_EXPORT CARD32 GetTimeInMillis(void);
 extern _X_EXPORT CARD64 GetTimeInMicros(void);
 
-extern _X_EXPORT void AdjustWaitForDelay(void *waitTime,
-                                         unsigned long newdelay);
+extern _X_EXPORT void AdjustWaitForDelay(void *waitTime, int newdelay);
 
 typedef struct _OsTimerRec *OsTimerPtr;
 
diff --git a/os/WaitFor.c b/os/WaitFor.c
index b6801fe..7bdd399 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -147,7 +147,7 @@ WaitForSomething(int *pClientsReady)
 {
     int i;
     struct timeval waittime, *wt;
-    INT32 timeout = 0;
+    int timeout;
     fd_set clientsReadable;
     fd_set clientsWritable;
     int curclient;
@@ -175,17 +175,15 @@ WaitForSomething(int *pClientsReady)
         if (workQueue)
             ProcessWorkQueue();
         if (XFD_ANYSET(&ClientsWithInput)) {
+            timeout = 0;
             someReady = TRUE;
-            waittime.tv_sec = 0;
-            waittime.tv_usec = 0;
-            wt = &waittime;
         }
         if (someReady) {
             XFD_COPYSET(&AllSockets, &LastSelectMask);
             XFD_UNSET(&LastSelectMask, &ClientsWithInput);
         }
         else {
-            wt = NULL;
+            timeout = -1;
             if (timers) {
                 now = GetTimeInMillis();
                 timeout = timers->expires - now;
@@ -198,16 +196,20 @@ WaitForSomething(int *pClientsReady)
                     timeout = timers->expires - now;
                     if (timeout < 0)
                         timeout = 0;
-                    waittime.tv_sec = timeout / MILLI_PER_SECOND;
-                    waittime.tv_usec = (timeout % MILLI_PER_SECOND) *
-                        (1000000 / MILLI_PER_SECOND);
-                    wt = &waittime;
                 }
             }
             XFD_COPYSET(&AllSockets, &LastSelectMask);
         }
 
-        BlockHandler(&wt);
+        BlockHandler(&timeout);
+        if (timeout < 0)
+            wt = NULL;
+        else {
+            waittime.tv_sec = timeout / MILLI_PER_SECOND;
+            waittime.tv_usec = (timeout % MILLI_PER_SECOND) *
+                (1000000 / MILLI_PER_SECOND);
+            wt = &waittime;
+        }
         if (NewOutputPending)
             FlushAllOutput();
         /* keep this check close to select() call to minimize race */
@@ -359,6 +361,16 @@ WaitForSomething(int *pClientsReady)
     return nready;
 }
 
+void
+AdjustWaitForDelay(void *waitTime, int newdelay)
+{
+    int *timeoutp = waitTime;
+    int timeout = *timeoutp;
+
+    if (timeout < 0 || newdelay < timeout)
+        *timeoutp = newdelay;
+}
+
 /* If time has rewound, re-run every affected timer.
  * Timers might drop out of the list, so we have to restart every time. */
 static void
diff --git a/os/utils.c b/os/utils.c
index a58603d..868a2d6 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -513,27 +513,6 @@ GetTimeInMicros(void)
 #endif
 
 void
-AdjustWaitForDelay(void *waitTime, unsigned long newdelay)
-{
-    static struct timeval delay_val;
-    struct timeval **wt = (struct timeval **) waitTime;
-    unsigned long olddelay;
-
-    if (*wt == NULL) {
-        delay_val.tv_sec = newdelay / 1000;
-        delay_val.tv_usec = 1000 * (newdelay % 1000);
-        *wt = &delay_val;
-    }
-    else {
-        olddelay = (*wt)->tv_sec * 1000 + (*wt)->tv_usec / 1000;
-        if (newdelay < olddelay) {
-            (*wt)->tv_sec = newdelay / 1000;
-            (*wt)->tv_usec = 1000 * (newdelay % 1000);
-        }
-    }
-}
-
-void
 UseMsg(void)
 {
     ErrorF("use: X [:<display>] [option]\n");
commit a414db021575accff64abad6f1047245e81c7476
Author: Keith Packard <keithp at keithp.com>
Date:   Thu May 19 15:08:05 2016 -0700

    dix: Intermediate GrabServer state 'GrabKickout' not needed
    
    The intermediate grabState, "GrabKickout", was used to trigger
    dispatch into going back to WaitForSomething after doing a GrabServer
    so that the set of ready clients would be recomputed to match what the
    server should be processing. As we only process one client per
    WaitForSomething call, we will always hit WaitForSomething after
    finishing the current client, and so don't need any special case here.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 28a3c3f..7eb200d 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -151,7 +151,6 @@ static ClientPtr grabClient;
 
 #define GrabNone 0
 #define GrabActive 1
-#define GrabKickout 2
 static int grabState = GrabNone;
 static long grabWaiters[mskcnt];
 CallbackListPtr ServerGrabCallback = NULL;
@@ -375,11 +374,6 @@ Dispatch(void)
                 /* KillClient can cause this to happen */
                 continue;
             }
-            /* GrabServer activation can cause this to be true */
-            if (grabState == GrabKickout) {
-                grabState = GrabActive;
-                break;
-            }
             isItTimeToYield = FALSE;
 
             start_tick = SmartScheduleTime;
@@ -1059,7 +1053,7 @@ ProcGrabServer(ClientPtr client)
     rc = OnlyListenToOneClient(client);
     if (rc != Success)
         return rc;
-    grabState = GrabKickout;
+    grabState = GrabActive;
     grabClient = client;
 
     if (ServerGrabCallback) {
commit 7762a602c1dfdd8cfcf2b8c2281cf4d683d05216
Author: Keith Packard <keithp at keithp.com>
Date:   Thu May 19 15:05:55 2016 -0700

    dix/os: Merge priority computation into SmartScheduleClient
    
    Instead of having scheduling done in two places (one in
    WaitForSomething, and the other in SmartScheduleClient), just stick
    all of the scheduling in SmartScheduleClient.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index a4e5358..28a3c3f 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -244,15 +244,13 @@ void Dispatch(void);
 static int
 SmartScheduleClient(int *clientReady, int nready)
 {
-    ClientPtr pClient;
     int i;
     int client;
-    int bestPrio, best = 0;
+    ClientPtr pClient, best = NULL;
     int bestRobin, robin;
     long now = SmartScheduleTime;
     long idle;
 
-    bestPrio = -0x7fffffff;
     bestRobin = 0;
     idle = 2 * SmartScheduleSlice;
     for (i = 0; i < nready; i++) {
@@ -269,11 +267,16 @@ SmartScheduleClient(int *clientReady, int nready)
             (pClient->index -
              SmartLastIndex[pClient->smart_priority -
                             SMART_MIN_PRIORITY]) & 0xff;
-        if (pClient->smart_priority > bestPrio ||
-            (pClient->smart_priority == bestPrio && robin > bestRobin)) {
-            bestPrio = pClient->smart_priority;
+
+        /* pick the best client */
+        if (!best ||
+            pClient->priority > best->priority ||
+            (pClient->priority == best->priority &&
+             (pClient->smart_priority > best->smart_priority ||
+              (pClient->smart_priority == best->smart_priority && robin > bestRobin))))
+        {
+            best = pClient;
             bestRobin = robin;
-            best = client;
         }
 #ifdef SMART_DEBUG
         if ((now - SmartLastPrint) >= 5000)
@@ -286,8 +289,7 @@ SmartScheduleClient(int *clientReady, int nready)
         SmartLastPrint = now;
     }
 #endif
-    pClient = clients[best];
-    SmartLastIndex[bestPrio - SMART_MIN_PRIORITY] = pClient->index;
+    SmartLastIndex[best->smart_priority - SMART_MIN_PRIORITY] = best->index;
     /*
      * Set current client pointer
      */
@@ -312,7 +314,7 @@ SmartScheduleClient(int *clientReady, int nready)
     else {
         SmartScheduleSlice = SmartScheduleInterval;
     }
-    return best;
+    return best->index;
 }
 
 void
diff --git a/os/WaitFor.c b/os/WaitFor.c
index 350f615..b6801fe 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -326,17 +326,14 @@ WaitForSomething(int *pClientsReady)
     if (XFD_ANYSET(&clientsReadable)) {
 #ifndef WIN32
         for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++) {
-            int highest_priority = 0;
-
             while (clientsReadable.fds_bits[i]) {
-                int client_priority, client_index;
+                int client_index;
 
                 curclient = mffs(clientsReadable.fds_bits[i]) - 1;
                 client_index =  /* raphael: modified */
                     ConnectionTranslation[curclient +
                                           (i * (sizeof(fd_mask) * 8))];
 #else
-        int highest_priority = 0;
         fd_set savedClientsReadable;
 
         XFD_COPYSET(&clientsReadable, &savedClientsReadable);
@@ -346,33 +343,7 @@ WaitForSomething(int *pClientsReady)
             curclient = XFD_FD(&savedClientsReadable, i);
             client_index = GetConnectionTranslation(curclient);
 #endif
-            /*  We implement "strict" priorities.
-             *  Only the highest priority client is returned to
-             *  dix.  If multiple clients at the same priority are
-             *  ready, they are all returned.  This means that an
-             *  aggressive client could take over the server.
-             *  This was not considered a big problem because
-             *  aggressive clients can hose the server in so many
-             *  other ways :)
-             */
-            client_priority = clients[client_index]->priority;
-            if (nready == 0 || client_priority > highest_priority) {
-                /*  Either we found the first client, or we found
-                 *  a client whose priority is greater than all others
-                 *  that have been found so far.  Either way, we want
-                 *  to initialize the list of clients to contain just
-                 *  this client.
-                 */
-                pClientsReady[0] = client_index;
-                highest_priority = client_priority;
-                nready = 1;
-            }
-            /*  the following if makes sure that multiple same-priority
-             *  clients get batched together
-             */
-            else if (client_priority == highest_priority) {
-                pClientsReady[nready++] = client_index;
-            }
+            pClientsReady[nready++] = client_index;
 #ifndef WIN32
             clientsReadable.fds_bits[i] &= ~(((fd_mask) 1L) << curclient);
         }
commit 4af00242ef1e39499b932d12423fdf449296090a
Author: Keith Packard <keithp at keithp.com>
Date:   Mon May 30 01:49:46 2016 -0700

    Bump ABI versions to reflect block/wakeup handler API changes
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index 14c7700..e0212cf 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -79,8 +79,8 @@ typedef enum {
  * mask is 0xFFFF0000.
  */
 #define ABI_ANSIC_VERSION	SET_ABI_VERSION(0, 4)
-#define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(22, 0)
-#define ABI_XINPUT_VERSION	SET_ABI_VERSION(23, 1)
+#define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(23, 0)
+#define ABI_XINPUT_VERSION	SET_ABI_VERSION(24, 1)
 #define ABI_EXTENSION_VERSION	SET_ABI_VERSION(10, 0)
 
 #define MODINFOSTRING1	0xef23fdc5
commit be5a513fee6cbf29ef7570e57eb0436d70fbd88c
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Dec 7 15:12:14 2015 -0800

    Remove AddEnabledDevice and AddGeneralSocket APIs
    
    All uses of these interfaces should instead be using the NotifyFd API
    instead.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/include/os.h b/include/os.h
index 702134b..5f65141 100644
--- a/include/os.h
+++ b/include/os.h
@@ -146,14 +146,6 @@ extern _X_EXPORT void CheckConnections(void);
 
 extern _X_EXPORT void CloseDownConnection(ClientPtr /*client */ );
 
-extern _X_EXPORT void AddGeneralSocket(int /*fd */ );
-
-extern _X_EXPORT void RemoveGeneralSocket(int /*fd */ );
-
-extern _X_EXPORT void AddEnabledDevice(int /*fd */ );
-
-extern _X_EXPORT void RemoveEnabledDevice(int /*fd */ );
-
 typedef void (*NotifyFdProcPtr)(int fd, int ready, void *data);
 
 #define X_NOTIFY_NONE   0
diff --git a/os/WaitFor.c b/os/WaitFor.c
index 24e1afc..350f615 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -153,7 +153,6 @@ WaitForSomething(int *pClientsReady)
     int curclient;
     int selecterr;
     static int nready;
-    fd_set devicesReadable;
     CARD32 now = 0;
     Bool someReady = FALSE;
     Bool someNotifyWriteReady = FALSE;
@@ -309,14 +308,13 @@ WaitForSomething(int *pClientsReady)
                 }
             }
 
-            XFD_ANDSET(&devicesReadable, &LastSelectMask, &EnabledDevices);
             XFD_ANDSET(&clientsReadable, &LastSelectMask, &AllClients);
 
             XFD_ANDSET(&tmp_set, &LastSelectMask, &NotifyReadFds);
             if (XFD_ANYSET(&tmp_set) || someNotifyWriteReady)
                 HandleNotifyFds();
 
-            if (XFD_ANYSET(&devicesReadable) || XFD_ANYSET(&clientsReadable))
+            if (XFD_ANYSET(&clientsReadable))
                 break;
             /* check here for DDXes that queue events during Block/Wakeup */
             if (*checkForInput[0] != *checkForInput[1])
diff --git a/os/connection.c b/os/connection.c
index d001b98..ad949c9 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -47,8 +47,8 @@ SOFTWARE.
  *  Stuff to create connections --- OS dependent
  *
  *      EstablishNewConnections, CreateWellKnownSockets, ResetWellKnownSockets,
- *      CloseDownConnection, CheckConnections, AddEnabledDevice,
- *	RemoveEnabledDevice, OnlyListToOneClient,
+ *      CloseDownConnection, CheckConnections
+ *	OnlyListToOneClient,
  *      ListenToAllClients,
  *
  *      (WaitForSomething is in its own file)
@@ -121,7 +121,6 @@ SOFTWARE.
 
 static int lastfdesc;           /* maximum file descriptor */
 
-fd_set EnabledDevices;          /* mask for input devices that are on */
 fd_set NotifyReadFds;           /* mask for other file descriptors */
 fd_set NotifyWriteFds;          /* mask for other write file descriptors */
 fd_set AllSockets;              /* select on this */
@@ -1045,36 +1044,6 @@ CloseDownConnection(ClientPtr client)
         AuditF("client %d disconnected\n", client->index);
 }
 
-void
-AddGeneralSocket(int fd)
-{
-    FD_SET(fd, &AllSockets);
-    if (GrabInProgress)
-        FD_SET(fd, &SavedAllSockets);
-}
-
-void
-AddEnabledDevice(int fd)
-{
-    FD_SET(fd, &EnabledDevices);
-    AddGeneralSocket(fd);
-}
-
-void
-RemoveGeneralSocket(int fd)
-{
-    FD_CLR(fd, &AllSockets);
-    if (GrabInProgress)
-        FD_CLR(fd, &SavedAllSockets);
-}
-
-void
-RemoveEnabledDevice(int fd)
-{
-    FD_CLR(fd, &EnabledDevices);
-    RemoveGeneralSocket(fd);
-}
-
 struct notify_fd {
     struct xorg_list list;
     int fd;
@@ -1132,9 +1101,13 @@ SetNotifyFd(int fd, NotifyFdProcPtr notify, int mask, void *data)
     if (changes & X_NOTIFY_READ) {
         if (mask & X_NOTIFY_READ) {
             FD_SET(fd, &NotifyReadFds);
-            AddGeneralSocket(fd);
+            FD_SET(fd, &AllSockets);
+            if (GrabInProgress)
+                FD_SET(fd, &SavedAllSockets);
         } else {
-            RemoveGeneralSocket(fd);
+            FD_CLR(fd, &AllSockets);
+            if (GrabInProgress)
+                FD_CLR(fd, &SavedAllSockets);
             FD_CLR(fd, &NotifyReadFds);
         }
     }
commit 9d15912aa475b733bbb20efc367a67dacad63bf1
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Sep 1 18:51:14 2015 -0700

    Remove fd_set from Block/Wakeup handler API
    
    This removes the last uses of fd_set from the server interfaces
    outside of the OS layer itself.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/Xext/sleepuntil.c b/Xext/sleepuntil.c
index 993c028..68a7a9b 100644
--- a/Xext/sleepuntil.c
+++ b/Xext/sleepuntil.c
@@ -63,14 +63,11 @@ static void ClientAwaken(ClientPtr /* client */ ,
 static int SertafiedDelete(void *  /* value */ ,
                            XID     /* id */
     );
-static void SertafiedBlockHandler(void *    /* data */ ,
-                                  OSTimePtr /* wt */ ,
-                                  void *    /* LastSelectMask */
-    );
-static void SertafiedWakeupHandler(void *   /* data */ ,
-                                   int      /* i */ ,
-                                   void *   /* LastSelectMask */
-    );
+static void SertafiedBlockHandler(void *data,
+                                  void *timeout);
+
+static void SertafiedWakeupHandler(void *data,
+                                   int i);
 
 int
 ClientSleepUntil(ClientPtr client,
@@ -154,7 +151,7 @@ SertafiedDelete(void *value, XID id)
 }
 
 static void
-SertafiedBlockHandler(void *data, OSTimePtr wt, void *LastSelectMask)
+SertafiedBlockHandler(void *data, void *wt)
 {
     SertafiedPtr pReq, pNext;
     unsigned long delay;
@@ -186,7 +183,7 @@ SertafiedBlockHandler(void *data, OSTimePtr wt, void *LastSelectMask)
 }
 
 static void
-SertafiedWakeupHandler(void *data, int i, void *LastSelectMask)
+SertafiedWakeupHandler(void *data, int i)
 {
     SertafiedPtr pReq, pNext;
     TimeStamp now;
diff --git a/Xext/sync.c b/Xext/sync.c
index 4c59fea..323b9db 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -2556,8 +2556,8 @@ static XSyncValue *pnext_time;
 *** Server Block Handler
 *** code inspired by multibuffer extension (now deprecated)
  */
- /*ARGSUSED*/ static void
-ServertimeBlockHandler(void *env, struct timeval **wt, void *LastSelectMask)
+/*ARGSUSED*/ static void
+ServertimeBlockHandler(void *env, void *wt)
 {
     XSyncValue delay;
     unsigned long timeout;
@@ -2582,8 +2582,8 @@ ServertimeBlockHandler(void *env, struct timeval **wt, void *LastSelectMask)
 /*
 *** Wakeup Handler
  */
- /*ARGSUSED*/ static void
-ServertimeWakeupHandler(void *env, int rc, void *LastSelectMask)
+/*ARGSUSED*/ static void
+ServertimeWakeupHandler(void *env, int rc)
 {
     if (pnext_time) {
         GetTime();
@@ -2658,7 +2658,7 @@ IdleTimeQueryValue(void *pCounter, CARD64 * pValue_return)
 }
 
 static void
-IdleTimeBlockHandler(void *pCounter, struct timeval **wt, void *LastSelectMask)
+IdleTimeBlockHandler(void *pCounter, void *wt)
 {
     SyncCounter *counter = pCounter;
     IdleCounterPriv *priv = SysCounterGetPrivate(counter);
@@ -2751,7 +2751,7 @@ IdleTimeCheckBrackets(SyncCounter *counter, XSyncValue idle, XSyncValue *less, X
 }
 
 static void
-IdleTimeWakeupHandler(void *pCounter, int rc, void *LastSelectMask)
+IdleTimeWakeupHandler(void *pCounter, int rc)
 {
     SyncCounter *counter = pCounter;
     IdleCounterPriv *priv = SysCounterGetPrivate(counter);
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index d217d12..cca92ed 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -197,7 +197,7 @@ RemoveFontWakeup(FontPathElementPtr fpe)
 }
 
 static void
-FontWakeup(void *data, int count, void *LastSelectMask)
+FontWakeup(void *data, int count)
 {
     int i;
     FontPathElementPtr fpe;
@@ -1918,8 +1918,7 @@ _client_auth_generation(ClientPtr client)
 static int fs_handlers_installed = 0;
 static unsigned int last_server_gen;
 
-static void
-fs_block_handler(void *blockData, OSTimePtr timeout, void *readmask)
+static void fs_block_handler(void *blockData, void *timeout)
 {
     FontBlockHandlerProcPtr block_handler = blockData;
 
@@ -2004,7 +2003,7 @@ _init_fs_handlers(FontPathElementPtr fpe, FontBlockHandlerProcPtr block_handler)
 
 static void
 _remove_fs_handlers(FontPathElementPtr fpe, FontBlockHandlerProcPtr block_handler,
-                   Bool all)
+                    Bool all)
 {
     if (all) {
         /* remove the handlers if no one else is using them */
diff --git a/dix/dixutils.c b/dix/dixutils.c
index d728929..540023c 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -360,8 +360,8 @@ NoopDDA(void)
 }
 
 typedef struct _BlockHandler {
-    BlockHandlerProcPtr BlockHandler;
-    WakeupHandlerProcPtr WakeupHandler;
+    ServerBlockHandlerProcPtr BlockHandler;
+    ServerWakeupHandlerProcPtr WakeupHandler;
     void *blockData;
     Bool deleted;
 } BlockHandlerRec, *BlockHandlerPtr;
@@ -378,14 +378,14 @@ static Bool handlerDeleted;
  *  \param pReadMask  nor how it represents the det of descriptors
  */
 void
-BlockHandler(void *pTimeout, void *pReadmask)
+BlockHandler(void *pTimeout)
 {
     int i, j;
 
     ++inHandler;
     for (i = 0; i < numHandlers; i++)
         if (!handlers[i].deleted)
-            (*handlers[i].BlockHandler) (handlers[i].blockData, pTimeout, pReadmask);
+            (*handlers[i].BlockHandler) (handlers[i].blockData, pTimeout);
 
     for (i = 0; i < screenInfo.numGPUScreens; i++)
         (*screenInfo.gpuscreens[i]->BlockHandler) (screenInfo.gpuscreens[i], pTimeout);
@@ -413,7 +413,7 @@ BlockHandler(void *pTimeout, void *pReadmask)
  *  \param pReadmask the resulting descriptor mask
  */
 void
-WakeupHandler(int result, void *pReadmask)
+WakeupHandler(int result)
 {
     int i, j;
 
@@ -424,7 +424,7 @@ WakeupHandler(int result, void *pReadmask)
         (*screenInfo.gpuscreens[i]->WakeupHandler) (screenInfo.gpuscreens[i], result);
     for (i = numHandlers - 1; i >= 0; i--)
         if (!handlers[i].deleted)
-            (*handlers[i].WakeupHandler) (handlers[i].blockData, result, pReadmask);
+            (*handlers[i].WakeupHandler) (handlers[i].blockData, result);
     if (handlerDeleted) {
         for (i = 0; i < numHandlers;)
             if (handlers[i].deleted) {
@@ -444,8 +444,8 @@ WakeupHandler(int result, void *pReadmask)
  * get called until next time
  */
 Bool
-RegisterBlockAndWakeupHandlers(BlockHandlerProcPtr blockHandler,
-                               WakeupHandlerProcPtr wakeupHandler,
+RegisterBlockAndWakeupHandlers(ServerBlockHandlerProcPtr blockHandler,
+                               ServerWakeupHandlerProcPtr wakeupHandler,
                                void *blockData)
 {
     BlockHandlerPtr new;
@@ -467,8 +467,8 @@ RegisterBlockAndWakeupHandlers(BlockHandlerProcPtr blockHandler,
 }
 
 void
-RemoveBlockAndWakeupHandlers(BlockHandlerProcPtr blockHandler,
-                             WakeupHandlerProcPtr wakeupHandler,
+RemoveBlockAndWakeupHandlers(ServerBlockHandlerProcPtr blockHandler,
+                             ServerWakeupHandlerProcPtr wakeupHandler,
                              void *blockData)
 {
     int i;
diff --git a/hw/dmx/dmxsync.c b/hw/dmx/dmxsync.c
index 81dbbc6..1bc2423 100644
--- a/hw/dmx/dmxsync.c
+++ b/hw/dmx/dmxsync.c
@@ -99,13 +99,13 @@ dmxSyncCallback(OsTimerPtr timer, CARD32 time, void *arg)
 }
 
 static void
-dmxSyncBlockHandler(void *blockData, OSTimePtr pTimeout, void *pReadMask)
+dmxSyncBlockHandler(void *blockData, void *timeout)
 {
     TimerForce(dmxSyncTimer);
 }
 
 static void
-dmxSyncWakeupHandler(void *blockData, int result, void *pReadMask)
+dmxSyncWakeupHandler(void *blockData, int result)
 {
 }
 
diff --git a/hw/dmx/input/dmxinputinit.c b/hw/dmx/input/dmxinputinit.c
index a9522ff..554d234 100644
--- a/hw/dmx/input/dmxinputinit.c
+++ b/hw/dmx/input/dmxinputinit.c
@@ -630,7 +630,7 @@ dmxCollectAll(DMXInputInfo * dmxInput)
 }
 
 static void
-dmxBlockHandler(void *blockData, OSTimePtr pTimeout, void *pReadMask)
+dmxBlockHandler(void *blockData, void *timeout)
 {
     DMXInputInfo *dmxInput = &dmxInputs[(uintptr_t) blockData];
     static unsigned long generation = 0;
@@ -658,7 +658,7 @@ dmxSwitchReturn(void *p)
 }
 
 static void
-dmxWakeupHandler(void *blockData, int result, void *pReadMask)
+dmxWakeupHandler(void *blockData, int result)
 {
     DMXInputInfo *dmxInput = &dmxInputs[(uintptr_t) blockData];
     int i;
diff --git a/hw/vfb/InitOutput.c b/hw/vfb/InitOutput.c
index 01bb631..d7bfd70 100644
--- a/hw/vfb/InitOutput.c
+++ b/hw/vfb/InitOutput.c
@@ -471,7 +471,7 @@ vfbSaveScreen(ScreenPtr pScreen, int on)
 
 /* this flushes any changes to the screens out to the mmapped file */
 static void
-vfbBlockHandler(void *blockData, OSTimePtr pTimeout, void *pReadmask)
+vfbBlockHandler(void *blockData, void *timeout)
 {
     int i;
 
@@ -492,7 +492,7 @@ vfbBlockHandler(void *blockData, OSTimePtr pTimeout, void *pReadmask)
 }
 
 static void
-vfbWakeupHandler(void *blockData, int result, void *pReadmask)
+vfbWakeupHandler(void *blockData, int result)
 {
 }
 
diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index 7d3c35f..9a8f432 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -242,7 +242,7 @@ xf86ProcessActionEvent(ActionEvent action, void *arg)
 
 /* ARGSUSED */
 void
-xf86Wakeup(void *blockData, int err, void *pReadmask)
+xf86Wakeup(void *blockData, int err)
 {
     if (xf86VTSwitchPending())
         xf86VTSwitch();
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 998100a..7a267f8 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -871,7 +871,7 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
     xf86Resetting = FALSE;
     xf86Initialising = FALSE;
 
-    RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr) NoopDDA, xf86Wakeup,
+    RegisterBlockAndWakeupHandlers((ServerBlockHandlerProcPtr) NoopDDA, xf86Wakeup,
                                    NULL);
 }
 
diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h
index 81f7294..c1f8a18 100644
--- a/hw/xfree86/common/xf86Priv.h
+++ b/hw/xfree86/common/xf86Priv.h
@@ -137,7 +137,7 @@ DoShowOptions(void)
 /* xf86Events.c */
 
 extern _X_EXPORT void
-xf86Wakeup(void *blockData, int err, void *pReadmask);
+xf86Wakeup(void *blockData, int err);
 extern _X_HIDDEN int
 xf86SigWrapper(int signo);
 extern _X_EXPORT void
diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index d399246..e4a21dc 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -1667,7 +1667,7 @@ DRIDestroyInfoRec(DRIInfoPtr DRIInfo)
 }
 
 void
-DRIWakeupHandler(void *wakeupData, int result, void *pReadmask)
+DRIWakeupHandler(void *wakeupData, int result)
 {
     int i;
 
@@ -1681,7 +1681,7 @@ DRIWakeupHandler(void *wakeupData, int result, void *pReadmask)
 }
 
 void
-DRIBlockHandler(void *blockData, OSTimePtr pTimeout, void *pReadmask)
+DRIBlockHandler(void *blockData, void *pTimeout)
 {
     int i;
 
diff --git a/hw/xfree86/dri/dri.h b/hw/xfree86/dri/dri.h
index c659a20..dfd2f82 100644
--- a/hw/xfree86/dri/dri.h
+++ b/hw/xfree86/dri/dri.h
@@ -263,11 +263,9 @@ extern _X_EXPORT void DRIDestroyInfoRec(DRIInfoPtr DRIInfo);
 
 extern _X_EXPORT Bool DRIFinishScreenInit(ScreenPtr pScreen);
 
-extern _X_EXPORT void DRIWakeupHandler(void *wakeupData,
-                                       int result, void *pReadmask);
+extern _X_EXPORT void DRIWakeupHandler(void *wakeupData, int result);
 
-extern _X_EXPORT void DRIBlockHandler(void *blockData,
-                                      OSTimePtr pTimeout, void *pReadmask);
+extern _X_EXPORT void DRIBlockHandler(void *blockData, void *timeout);
 
 extern _X_EXPORT void DRIDoWakeupHandler(ScreenPtr pScreen, int result);
 
diff --git a/hw/xnest/Handlers.c b/hw/xnest/Handlers.c
index 05d559d..e90a616 100644
--- a/hw/xnest/Handlers.c
+++ b/hw/xnest/Handlers.c
@@ -32,14 +32,14 @@ is" without express or implied warranty.
 #include "Handlers.h"
 
 void
-xnestBlockHandler(void *blockData, OSTimePtr pTimeout, void *pReadMask)
+xnestBlockHandler(void *blockData, void *timout)
 {
     xnestCollectExposures();
     XFlush(xnestDisplay);
 }
 
 void
-xnestWakeupHandler(void *blockData, int result, void *pReadMask)
+xnestWakeupHandler(void *blockData, int result)
 {
     xnestCollectEvents();
 }
diff --git a/hw/xnest/Handlers.h b/hw/xnest/Handlers.h
index d4ad6d2..6ebcc8b 100644
--- a/hw/xnest/Handlers.h
+++ b/hw/xnest/Handlers.h
@@ -15,8 +15,7 @@ is" without express or implied warranty.
 #ifndef XNESTHANDLERS_H
 #define XNESTHANDLERS_H
 
-void xnestBlockHandler(void *blockData, OSTimePtr pTimeout,
-                       void *pReadMask);
-void xnestWakeupHandler(void *blockData, int result, void *pReadMask);
+void xnestBlockHandler(void *blockData, void *timeout);
+void xnestWakeupHandler(void *blockData, int result);
 
 #endif                          /* XNESTHANDLERS_H */
diff --git a/hw/xwayland/xwayland.c b/hw/xwayland/xwayland.c
index 6daf385..c65a22f 100644
--- a/hw/xwayland/xwayland.c
+++ b/hw/xwayland/xwayland.c
@@ -507,12 +507,12 @@ socket_handler(int fd, int ready, void *data)
 }
 
 static void
-wakeup_handler(void *data, int err, void *pRead)
+wakeup_handler(void *data, int err)
 {
 }
 
 static void
-block_handler(void *data, OSTimePtr pTimeout, void *pRead)
+block_handler(void *data, void *timeout)
 {
     struct xwl_screen *xwl_screen = data;
 
diff --git a/include/dix.h b/include/dix.h
index f63606a..ae9719a 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -208,28 +208,28 @@ extern _X_EXPORT int AlterSaveSetForClient(ClientPtr /*client */ ,
 
 extern _X_EXPORT void DeleteWindowFromAnySaveSet(WindowPtr /*pWin */ );
 
-extern _X_EXPORT void BlockHandler(void *pTimeout,
-                                   void *pReadmask);
+extern _X_EXPORT void BlockHandler(void *timeout);
 
-extern _X_EXPORT void WakeupHandler(int result,
-                                    void *pReadmask);
+extern _X_EXPORT void WakeupHandler(int result);
 
 void
- EnableLimitedSchedulingLatency(void);
+EnableLimitedSchedulingLatency(void);
 
 void
- DisableLimitedSchedulingLatency(void);
+DisableLimitedSchedulingLatency(void);
 
-typedef void (*WakeupHandlerProcPtr) (void *blockData,
-                                      int result,
-                                      void *pReadmask);
+typedef void (*ServerBlockHandlerProcPtr) (void *blockData,
+                                           void *timeout);
 
-extern _X_EXPORT Bool RegisterBlockAndWakeupHandlers(BlockHandlerProcPtr blockHandler,
-                                                     WakeupHandlerProcPtr wakeupHandler,
+typedef void (*ServerWakeupHandlerProcPtr) (void *blockData,
+                                            int result);
+
+extern _X_EXPORT Bool RegisterBlockAndWakeupHandlers(ServerBlockHandlerProcPtr blockHandler,
+                                                     ServerWakeupHandlerProcPtr wakeupHandler,
                                                      void *blockData);
 
-extern _X_EXPORT void RemoveBlockAndWakeupHandlers(BlockHandlerProcPtr blockHandler,
-                                                   WakeupHandlerProcPtr wakeupHandler,
+extern _X_EXPORT void RemoveBlockAndWakeupHandlers(ServerBlockHandlerProcPtr blockHandler,
+                                                   ServerWakeupHandlerProcPtr wakeupHandler,
                                                    void *blockData);
 
 extern _X_EXPORT void InitBlockAndWakeupHandlers(void);
diff --git a/miext/rootless/rootlessScreen.c b/miext/rootless/rootlessScreen.c
index 4716564..2ec0ae5 100644
--- a/miext/rootless/rootlessScreen.c
+++ b/miext/rootless/rootlessScreen.c
@@ -603,7 +603,7 @@ RootlessQueueRedisplay(ScreenPtr pScreen)
  *  on select().
  */
 static void
-RootlessBlockHandler(void *pbdata, OSTimePtr pTimeout, void *pReadmask)
+RootlessBlockHandler(void *pbdata, void *ptimeout)
 {
     ScreenPtr pScreen = pbdata;
     RootlessScreenRec *screenRec = SCREENREC(pScreen);
@@ -616,7 +616,7 @@ RootlessBlockHandler(void *pbdata, OSTimePtr pTimeout, void *pReadmask)
 }
 
 static void
-RootlessWakeupHandler(void *data, int i, void *LastSelectMask)
+RootlessWakeupHandler(void *data, int result)
 {
     // nothing here
 }
diff --git a/os/WaitFor.c b/os/WaitFor.c
index b82f826..24e1afc 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -208,7 +208,7 @@ WaitForSomething(int *pClientsReady)
             XFD_COPYSET(&AllSockets, &LastSelectMask);
         }
 
-        BlockHandler((void *) &wt, (void *) &LastSelectMask);
+        BlockHandler(&wt);
         if (NewOutputPending)
             FlushAllOutput();
         /* keep this check close to select() call to minimize race */
@@ -223,7 +223,7 @@ WaitForSomething(int *pClientsReady)
             i = Select(MaxClients, &LastSelectMask, NULL, NULL, wt);
         }
         selecterr = GetErrno();
-        WakeupHandler(i, (void *) &LastSelectMask);
+        WakeupHandler(i);
         if (i <= 0) {           /* An error or timeout occurred */
             if (dispatchException)
                 return 0;
commit fb0802113b4c57819cba15d64baf79bf4148607e
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Sep 1 11:20:04 2015 -0700

    Remove readmask from screen block/wakeup handler
    
    With no users of the interface needing the readmask anymore, we can
    remove it from the argument passed to these functions.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/composite/compalloc.c b/composite/compalloc.c
index 8daded0..e6a203f 100644
--- a/composite/compalloc.c
+++ b/composite/compalloc.c
@@ -55,13 +55,13 @@ compScreenUpdate(ScreenPtr pScreen)
 }
 
 static void
-compBlockHandler(ScreenPtr pScreen, void *pTimeout, void *pReadmask)
+compBlockHandler(ScreenPtr pScreen, void *pTimeout)
 {
     CompScreenPtr cs = GetCompScreen(pScreen);
 
     pScreen->BlockHandler = cs->BlockHandler;
     compScreenUpdate(pScreen);
-    (*pScreen->BlockHandler) (pScreen, pTimeout, pReadmask);
+    (*pScreen->BlockHandler) (pScreen, pTimeout);
 
     /* Next damage will restore the block handler */
     cs->BlockHandler = NULL;
diff --git a/dix/dixutils.c b/dix/dixutils.c
index 3d2e7a3..d728929 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -385,16 +385,13 @@ BlockHandler(void *pTimeout, void *pReadmask)
     ++inHandler;
     for (i = 0; i < numHandlers; i++)
         if (!handlers[i].deleted)
-            (*handlers[i].BlockHandler) (handlers[i].blockData,
-                                         pTimeout, pReadmask);
+            (*handlers[i].BlockHandler) (handlers[i].blockData, pTimeout, pReadmask);
 
     for (i = 0; i < screenInfo.numGPUScreens; i++)
-        (*screenInfo.gpuscreens[i]->BlockHandler) (screenInfo.gpuscreens[i],
-                                                   pTimeout, pReadmask);
+        (*screenInfo.gpuscreens[i]->BlockHandler) (screenInfo.gpuscreens[i], pTimeout);
 
     for (i = 0; i < screenInfo.numScreens; i++)
-        (*screenInfo.screens[i]->BlockHandler) (screenInfo.screens[i],
-                                                pTimeout, pReadmask);
+        (*screenInfo.screens[i]->BlockHandler) (screenInfo.screens[i], pTimeout);
 
     if (handlerDeleted) {
         for (i = 0; i < numHandlers;)
@@ -422,15 +419,12 @@ WakeupHandler(int result, void *pReadmask)
 
     ++inHandler;
     for (i = 0; i < screenInfo.numScreens; i++)
-        (*screenInfo.screens[i]->WakeupHandler) (screenInfo.screens[i],
-                                                 result, pReadmask);
+        (*screenInfo.screens[i]->WakeupHandler) (screenInfo.screens[i], result);
     for (i = 0; i < screenInfo.numGPUScreens; i++)
-        (*screenInfo.gpuscreens[i]->WakeupHandler) (screenInfo.gpuscreens[i],
-                                                    result, pReadmask);
+        (*screenInfo.gpuscreens[i]->WakeupHandler) (screenInfo.gpuscreens[i], result);
     for (i = numHandlers - 1; i >= 0; i--)
         if (!handlers[i].deleted)
-            (*handlers[i].WakeupHandler) (handlers[i].blockData,
-                                          result, pReadmask);
+            (*handlers[i].WakeupHandler) (handlers[i].blockData, result, pReadmask);
     if (handlerDeleted) {
         for (i = 0; i < numHandlers;)
             if (handlers[i].deleted) {
diff --git a/doc/Xinput.xml b/doc/Xinput.xml
index 083b109..0e7fbda 100644
--- a/doc/Xinput.xml
+++ b/doc/Xinput.xml
@@ -210,7 +210,7 @@ A sample InitInput implementation is shown below.
 <literallayout class="monospaced">
 InitInput(argc,argv)
     {
-    int i, numdevs, ReadInput();
+    int i, numdevs;
     DeviceIntPtr dev;
     LocalDevice localdevs[LOCAL_MAX_DEVS];
     DeviceProc kbdproc, ptrproc, extproc;
@@ -224,12 +224,6 @@ InitInput(argc,argv)
     open_input_devices (&numdevs, localdevs);
 
     /**************************************************************
-     * Register a WakeupHandler to handle input when it is generated.
-     ***************************************************************/
-
-    RegisterBlockAndWakeupHandlers (NoopDDA, ReadInput, NULL);
-
-    /**************************************************************
      * Register the input devices with DIX.
      ***************************************************************/
 
diff --git a/doc/Xserver-spec.xml b/doc/Xserver-spec.xml
index 72a544b..7867544 100644
--- a/doc/Xserver-spec.xml
+++ b/doc/Xserver-spec.xml
@@ -674,30 +674,22 @@ If WaitForSomething() decides it is about to do something that might block
 routine called BlockHandler().
 <blockquote>
 <programlisting>
-	void BlockHandler(pTimeout, pReadmask)
-		pointer pTimeout;
-		pointer pReadmask;
+	void BlockHandler(void *pTimeout)
 </programlisting>
 </blockquote>
 The types of the arguments are for agreement between the OS and DDX
 implementations,  but the pTimeout is a pointer to the information
-determining how long the block is allowed to last,  and the
-pReadmask is a pointer to the information describing the descriptors
-that will be waited on.
+determining how long the block is allowed to last.
 </para>
 <para>
-In the sample server,  pTimeout is a pointer,  and pReadmask is
-the address of the select() mask for reading.
+In the sample server,  pTimeout is a pointer.
 </para>
 <para>
 The DIX BlockHandler() iterates through the Screens,  for each one calling
 its BlockHandler.  A BlockHandler is declared thus:
 <blockquote>
 <programlisting>
-	void xxxBlockHandler(pScreen, pTimeout, pReadmask)
-		ScreenPtr pScreen;
-		pointer pTimeout;
-		pointer pReadmask;
+	void xxxBlockHandler(ScreenPtr pScreen, void *pTimeout)
 </programlisting>
 </blockquote>
 The arguments are a pointer to the Screen, and the arguments to the
@@ -709,27 +701,20 @@ block,  even if it didn't actually block,  it must call the DIX routine
 WakeupHandler().
 <blockquote>
 <programlisting>
-	void WakeupHandler(result, pReadmask)
-		int result;
-		pointer pReadmask;
+	void WakeupHandler(int result)
 </programlisting>
 </blockquote>
 Once again,  the types are not specified by DIX.  The result is the
-success indicator for the thing that (may have) blocked,
-and the pReadmask is a mask of the descriptors that came active.
-In the sample server,  result is the result from select() (or equivalent
-operating system function),  and pReadmask is
-the address of the select() mask for reading.
+success indicator for the thing that (may have) blocked.
+In the sample server, result is the result from select() (or equivalent
+operating system function).
 </para>
 <para>
 The DIX WakeupHandler() calls each Screen's
 WakeupHandler.  A WakeupHandler is declared thus:
 <blockquote>
 <programlisting>
-	void xxxWakeupHandler(pScreen, result, pReadmask)
-		ScreenPtr pScreen;
-		unsigned long result;
-		pointer pReadmask;
+	void xxxWakeupHandler(ScreenPtr pScreen, int result)
 </programlisting>
 </blockquote>
 The arguments are the Screen, of the Screen, and the arguments to
@@ -741,8 +726,8 @@ block and wakeup handlers (only together) using:
 <blockquote>
 <programlisting>
 	Bool RegisterBlockAndWakeupHandlers (blockHandler, wakeupHandler, blockData)
-		BlockHandlerProcPtr    blockHandler;
-		WakeupHandlerProcPtr   wakeupHandler;
+		ServerBlockHandlerProcPtr    blockHandler;
+		ServerWakeupHandlerProcPtr   wakeupHandler;
 		pointer blockData;
 </programlisting>
 </blockquote>
@@ -752,8 +737,8 @@ memory.  To remove a registered Block handler at other than server reset time
 <blockquote>
 <programlisting>
 	RemoveBlockAndWakeupHandlers (blockHandler, wakeupHandler, blockData)
-		BlockHandlerProcPtr   blockHandler;
-		WakeupHandlerProcPtr  wakeupHandler;
+		ServerBlockHandlerProcPtr   blockHandler;
+		ServerWakeupHandlerProcPtr  wakeupHandler;
 		pointer blockData;
 </programlisting>
 </blockquote>
@@ -761,18 +746,15 @@ All three arguments must match the values passed to
 RegisterBlockAndWakeupHandlers.
 </para>
 <para>
-These registered block handlers are called after the per-screen handlers:
+These registered block handlers are called before the per-screen handlers:
 <blockquote>
 <programlisting>
-	void (*BlockHandler) (blockData, pptv, pReadmask)
-		pointer	blockData;
-		OsTimerPtr pptv;
-		pointer	pReadmask;
+	void (*ServerBlockHandler) (void *blockData, void *pTimeout)
 </programlisting>
 </blockquote>
 </para>
 <para>
-Sometimes block handlers need to adjust the time in a OSTimePtr structure,
+Sometimes block handlers need to adjust the time referenced by pTimeout,
 which on UNIX family systems is generally represented by a struct timeval
 consisting of seconds and microseconds in 32 bit values.
 As a convenience to reduce error prone struct timeval computations which
@@ -780,20 +762,17 @@ require modulus arithmetic and correct overflow behavior in the face of
 millisecond wrapping through 32 bits,
 <blockquote><programlisting>
 
-	void AdjustWaitForDelay(pointer /*waitTime*, unsigned long /* newdelay */)
+	void AdjustWaitForDelay(void *pTimeout, unsigned long newdelay)
 
 </programlisting></blockquote>
 has been provided.
 </para>
 <para>
 Any wakeup handlers registered with RegisterBlockAndWakeupHandlers will
-be called before the Screen handlers:
+be called after the Screen handlers:
 <blockquote><programlisting>
 
-	void (*WakeupHandler) (blockData, err, pReadmask)
-		pointer	blockData;
-		int err;
-		pointer pReadmask;
+	void (*ServerWakeupHandler) (void *blockData, int result)
 </programlisting></blockquote>
 </para>
 <para>
diff --git a/exa/exa.c b/exa/exa.c
index 51d36f3..7266b71 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -702,8 +702,7 @@ exaCreateScreenResources(ScreenPtr pScreen)
 }
 
 static void
-ExaBlockHandler(ScreenPtr pScreen, void *pTimeout,
-                void *pReadmask)
+ExaBlockHandler(ScreenPtr pScreen, void *pTimeout)
 {
     ExaScreenPriv(pScreen);
 
@@ -712,7 +711,7 @@ ExaBlockHandler(ScreenPtr pScreen, void *pTimeout,
         exaMoveInPixmap_mixed(pExaScr->deferred_mixed_pixmap);
 
     unwrap(pExaScr, pScreen, BlockHandler);
-    (*pScreen->BlockHandler) (pScreen, pTimeout, pReadmask);
+    (*pScreen->BlockHandler) (pScreen, pTimeout);
     wrap(pExaScr, pScreen, BlockHandler, ExaBlockHandler);
 
     /* The rest only applies to classic EXA */
@@ -732,13 +731,12 @@ ExaBlockHandler(ScreenPtr pScreen, void *pTimeout,
 }
 
 static void
-ExaWakeupHandler(ScreenPtr pScreen, unsigned long result,
-                 void *pReadmask)
+ExaWakeupHandler(ScreenPtr pScreen, int result)
 {
     ExaScreenPriv(pScreen);
 
     unwrap(pExaScr, pScreen, WakeupHandler);
-    (*pScreen->WakeupHandler) (pScreen, result, pReadmask);
+    (*pScreen->WakeupHandler) (pScreen, result);
     wrap(pExaScr, pScreen, WakeupHandler, ExaWakeupHandler);
 
     if (result == 0 && pExaScr->numOffscreenAvailable > 1) {
diff --git a/glamor/glamor.c b/glamor/glamor.c
index 867c53d..5ba440c 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -257,7 +257,7 @@ glamor_block_handler(ScreenPtr screen)
 }
 
 static void
-_glamor_block_handler(ScreenPtr screen, void *timeout, void *readmask)
+_glamor_block_handler(ScreenPtr screen, void *timeout)
 {
     glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
 
@@ -265,7 +265,7 @@ _glamor_block_handler(ScreenPtr screen, void *timeout, void *readmask)
     glFlush();
 
     screen->BlockHandler = glamor_priv->saved_procs.block_handler;
-    screen->BlockHandler(screen, timeout, readmask);
+    screen->BlockHandler(screen, timeout);
     glamor_priv->saved_procs.block_handler = screen->BlockHandler;
     screen->BlockHandler = _glamor_block_handler;
 }
diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index d7948e8..4eec72a 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -347,14 +347,14 @@ ephyrEventWorkProc(ClientPtr client, void *closure)
 }
 
 static void
-ephyrScreenBlockHandler(ScreenPtr pScreen, void *timeout, void *pRead)
+ephyrScreenBlockHandler(ScreenPtr pScreen, void *timeout)
 {
     KdScreenPriv(pScreen);
     KdScreenInfo *screen = pScreenPriv->screen;
     EphyrScrPriv *scrpriv = screen->driver;
 
     pScreen->BlockHandler = scrpriv->BlockHandler;
-    (*pScreen->BlockHandler)(pScreen, timeout, pRead);
+    (*pScreen->BlockHandler)(pScreen, timeout);
     scrpriv->BlockHandler = pScreen->BlockHandler;
     pScreen->BlockHandler = ephyrScreenBlockHandler;
 
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index e1d2b59..3c7f2cd 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -527,12 +527,10 @@ void
  KdScreenToPointerCoords(int *x, int *y);
 
 void
-
-KdBlockHandler(ScreenPtr pScreen, void *timeout, void *readmask);
+KdBlockHandler(ScreenPtr pScreen, void *timeout);
 
 void
-
-KdWakeupHandler(ScreenPtr pScreen, unsigned long result, void *readmask);
+KdWakeupHandler(ScreenPtr pScreen, int result);
 
 void
  KdDisableInput(void);
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 6ee575c..2c39624 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -1961,7 +1961,7 @@ _KdEnqueuePointerEvent(KdPointerInfo * pi, int type, int x, int y, int z,
 }
 
 void
-KdBlockHandler(ScreenPtr pScreen, void *timeo, void *readmask)
+KdBlockHandler(ScreenPtr pScreen, void *timeo)
 {
     KdPointerInfo *pi;
     int myTimeout = 0;
@@ -1987,7 +1987,7 @@ KdBlockHandler(ScreenPtr pScreen, void *timeo, void *readmask)
 }
 
 void
-KdWakeupHandler(ScreenPtr pScreen, unsigned long lresult, void *readmask)
+KdWakeupHandler(ScreenPtr pScreen, int result)
 {
     KdPointerInfo *pi;
 
diff --git a/hw/xfree86/common/xf86VGAarbiter.c b/hw/xfree86/common/xf86VGAarbiter.c
index 5cc2429..29a5f85 100644
--- a/hw/xfree86/common/xf86VGAarbiter.c
+++ b/hw/xfree86/common/xf86VGAarbiter.c
@@ -265,23 +265,21 @@ VGAarbiterCloseScreen(ScreenPtr pScreen)
 }
 
 static void
-VGAarbiterBlockHandler(ScreenPtr pScreen,
-                       void *pTimeout, void *pReadmask)
+VGAarbiterBlockHandler(ScreenPtr pScreen, void *pTimeout)
 {
     SCREEN_PROLOG(BlockHandler);
     VGAGet(pScreen);
-    pScreen->BlockHandler(pScreen, pTimeout, pReadmask);
+    pScreen->BlockHandler(pScreen, pTimeout);
     VGAPut();
     SCREEN_EPILOG(BlockHandler, VGAarbiterBlockHandler);
 }
 
 static void
-VGAarbiterWakeupHandler(ScreenPtr pScreen, unsigned long result,
-                        void *pReadmask)
+VGAarbiterWakeupHandler(ScreenPtr pScreen, int result)
 {
     SCREEN_PROLOG(WakeupHandler);
     VGAGet(pScreen);
-    pScreen->WakeupHandler(pScreen, result, pReadmask);
+    pScreen->WakeupHandler(pScreen, result);
     VGAPut();
     SCREEN_EPILOG(WakeupHandler, VGAarbiterWakeupHandler);
 }
diff --git a/hw/xfree86/common/xf86VGAarbiterPriv.h b/hw/xfree86/common/xf86VGAarbiterPriv.h
index b832c9a..09be10a 100644
--- a/hw/xfree86/common/xf86VGAarbiterPriv.h
+++ b/hw/xfree86/common/xf86VGAarbiterPriv.h
@@ -146,10 +146,8 @@ typedef struct _VGAarbiterGC {
 } VGAarbiterGCRec, *VGAarbiterGCPtr;
 
 /* Screen funcs */
-static void VGAarbiterBlockHandler(ScreenPtr pScreen, void *pTimeout,
-                                   void *pReadmask);
-static void VGAarbiterWakeupHandler(ScreenPtr pScreen,
-                                    unsigned long result, void *pReadmask);
+static void VGAarbiterBlockHandler(ScreenPtr pScreen, void *pTimeout);
+static void VGAarbiterWakeupHandler(ScreenPtr pScreen, int result);
 static Bool VGAarbiterCloseScreen(ScreenPtr pScreen);
 static void VGAarbiterGetImage(DrawablePtr pDrawable, int sx, int sy, int w,
                                int h, unsigned int format,
diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index dbad12f..d399246 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -1676,8 +1676,7 @@ DRIWakeupHandler(void *wakeupData, int result, void *pReadmask)
         DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
 
         if (pDRIPriv && pDRIPriv->pDriverInfo->wrap.WakeupHandler)
-            (*pDRIPriv->pDriverInfo->wrap.WakeupHandler) (pScreen,
-                                                          result, pReadmask);
+            (*pDRIPriv->pDriverInfo->wrap.WakeupHandler) (pScreen, result);
     }
 }
 
@@ -1691,14 +1690,12 @@ DRIBlockHandler(void *blockData, OSTimePtr pTimeout, void *pReadmask)
         DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
 
         if (pDRIPriv && pDRIPriv->pDriverInfo->wrap.BlockHandler)
-            (*pDRIPriv->pDriverInfo->wrap.BlockHandler) (pScreen,
-                                                         pTimeout, pReadmask);
+            (*pDRIPriv->pDriverInfo->wrap.BlockHandler) (pScreen, pTimeout);
     }
 }
 
 void
-DRIDoWakeupHandler(ScreenPtr pScreen,
-                   unsigned long result, void *pReadmask)
+DRIDoWakeupHandler(ScreenPtr pScreen, int result)
 {
     DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
 
@@ -1715,8 +1712,7 @@ DRIDoWakeupHandler(ScreenPtr pScreen,
 }
 
 void
-DRIDoBlockHandler(ScreenPtr pScreen,
-                  void *pTimeout, void *pReadmask)
+DRIDoBlockHandler(ScreenPtr pScreen, void *timeout)
 {
     DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
 
diff --git a/hw/xfree86/dri/dri.h b/hw/xfree86/dri/dri.h
index 7e0337f..c659a20 100644
--- a/hw/xfree86/dri/dri.h
+++ b/hw/xfree86/dri/dri.h
@@ -269,12 +269,9 @@ extern _X_EXPORT void DRIWakeupHandler(void *wakeupData,
 extern _X_EXPORT void DRIBlockHandler(void *blockData,
                                       OSTimePtr pTimeout, void *pReadmask);
 
-extern _X_EXPORT void DRIDoWakeupHandler(ScreenPtr pScreen,
-                                         unsigned long result,
-                                         void *pReadmask);
+extern _X_EXPORT void DRIDoWakeupHandler(ScreenPtr pScreen, int result);
 
-extern _X_EXPORT void DRIDoBlockHandler(ScreenPtr pScreen,
-                                        void *pTimeout, void *pReadmask);
+extern _X_EXPORT void DRIDoBlockHandler(ScreenPtr pScreen, void *timeout);
 
 extern _X_EXPORT void DRISwapContext(int drmFD, void *oldctx, void *newctx);
 
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 262a899..f262082 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -639,12 +639,12 @@ ms_dirty_get_ent(ScreenPtr screen, PixmapPtr slave_dst)
 }
 
 static void
-msBlockHandler(ScreenPtr pScreen, void *pTimeout, void *pReadmask)
+msBlockHandler(ScreenPtr pScreen, void *timeout)
 {
     modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen));
 
     pScreen->BlockHandler = ms->BlockHandler;
-    pScreen->BlockHandler(pScreen, pTimeout, pReadmask);
+    pScreen->BlockHandler(pScreen, timeout);
     ms->BlockHandler = pScreen->BlockHandler;
     pScreen->BlockHandler = msBlockHandler;
     if (pScreen->isGPU && !ms->drmmode.reverse_prime_offload_mode)
@@ -656,12 +656,12 @@ msBlockHandler(ScreenPtr pScreen, void *pTimeout, void *pReadmask)
 }
 
 static void
-msBlockHandler_oneshot(ScreenPtr pScreen, void *pTimeout, void *pReadmask)
+msBlockHandler_oneshot(ScreenPtr pScreen, void *pTimeout)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
 
-    msBlockHandler(pScreen, pTimeout, pReadmask);
+    msBlockHandler(pScreen, pTimeout);
 
     drmmode_set_desired_modes(pScrn, &ms->drmmode, TRUE);
 }
diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index fbd3c32..13e5a50 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -221,8 +221,7 @@ xf86RotateRedisplay(ScreenPtr pScreen)
 }
 
 static void
-xf86RotateBlockHandler(ScreenPtr pScreen,
-                       void *pTimeout, void *pReadmask)
+xf86RotateBlockHandler(ScreenPtr pScreen, void *pTimeout)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
@@ -235,7 +234,7 @@ xf86RotateBlockHandler(ScreenPtr pScreen,
 
     xf86RotateRedisplay(pScreen);
 
-    (*pScreen->BlockHandler) (pScreen, pTimeout, pReadmask);
+    (*pScreen->BlockHandler) (pScreen, pTimeout);
 
     /* Re-wrap if we still need this hook */
     if (xf86_config->rotation_damage != NULL) {
diff --git a/hw/xquartz/quartzCocoa.m b/hw/xquartz/quartzCocoa.m
index d21fb7d..ac6f67e 100644
--- a/hw/xquartz/quartzCocoa.m
+++ b/hw/xquartz/quartzCocoa.m
@@ -48,9 +48,7 @@
  *  Clean out any autoreleased objects.
  */
 void
-QuartzBlockHandler(void *blockData,
-                   OSTimePtr pTimeout,
-                   void *pReadmask)
+QuartzBlockHandler(void *blockData, void *pTimeout)
 {
     static NSAutoreleasePool *aPool = nil;
 
@@ -62,9 +60,7 @@ QuartzBlockHandler(void *blockData,
  * QuartzWakeupHandler
  */
 void
-QuartzWakeupHandler(void *blockData,
-                    int result,
-                    void *pReadmask)
+QuartzWakeupHandler(void *blockData, int result)
 {
     // nothing here
 }
diff --git a/hw/xquartz/quartzCommon.h b/hw/xquartz/quartzCommon.h
index 308a3f1..721886b 100644
--- a/hw/xquartz/quartzCommon.h
+++ b/hw/xquartz/quartzCommon.h
@@ -47,8 +47,9 @@ extern int aquaMenuBarHeight;
 extern const char      *quartzOpenGLBundle;
 
 void
-QuartzBlockHandler(void *blockData, OSTimePtr pTimeout, void *pReadmask);
+QuartzBlockHandler(void *blockData, void *pTimeout);
+
 void
-QuartzWakeupHandler(void *blockData, int result, void *pReadmask);
+QuartzWakeupHandler(void *blockData, int result);
 
 #endif  /* _QUARTZCOMMON_H */
diff --git a/hw/xwin/win.h b/hw/xwin/win.h
index 787c42a..9fa697d 100644
--- a/hw/xwin/win.h
+++ b/hw/xwin/win.h
@@ -902,9 +902,7 @@ Bool
  */
 
 void
-
-winWakeupHandler(ScreenPtr pScreen,
-                 unsigned long ulResult, void *pReadmask);
+winWakeupHandler(ScreenPtr pScreen, int iResult);
 
 /*
  * winwindow.c
diff --git a/hw/xwin/winwakeup.c b/hw/xwin/winwakeup.c
index ebcb0fa..f593886 100644
--- a/hw/xwin/winwakeup.c
+++ b/hw/xwin/winwakeup.c
@@ -38,8 +38,7 @@
 
 /* See Porting Layer Definition - p. 7 */
 void
-winWakeupHandler(ScreenPtr pScreen,
-                 unsigned long ulResult, void *pReadmask)
+winWakeupHandler(ScreenPtr pScreen, int iResult)
 {
     MSG msg;
 
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index c5dadc7..5330714 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -258,12 +258,15 @@ typedef void (*ResolveColorProcPtr) (unsigned short * /*pred */ ,
 typedef RegionPtr (*BitmapToRegionProcPtr) (PixmapPtr /*pPix */ );
 
 typedef void (*ScreenBlockHandlerProcPtr) (ScreenPtr pScreen,
-                                           void *pTimeout,
-                                           void *pReadmask);
+                                           void *timeout);
 
+/* result has three possible values:
+ * < 0 - error
+ * = 0 - timeout
+ * > 0 - activity
+ */
 typedef void (*ScreenWakeupHandlerProcPtr) (ScreenPtr pScreen,
-                                            unsigned long result,
-                                            void *pReadMask);
+                                            int result);
 
 typedef Bool (*CreateScreenResourcesProcPtr) (ScreenPtr /*pScreen */ );
 
diff --git a/mi/misprite.c b/mi/misprite.c
index 68a49be..e682b24 100644
--- a/mi/misprite.c
+++ b/mi/misprite.c
@@ -198,8 +198,7 @@ static void miSpriteSourceValidate(DrawablePtr pDrawable, int x, int y,
                                    unsigned int subWindowMode);
 static void miSpriteCopyWindow(WindowPtr pWindow,
                                DDXPointRec ptOldOrg, RegionPtr prgnSrc);
-static void miSpriteBlockHandler(ScreenPtr pScreen,
-                                 void *pTimeout, void *pReadMask);
+static void miSpriteBlockHandler(ScreenPtr pScreen, void *timeout);
 static void miSpriteInstallColormap(ColormapPtr pMap);
 static void miSpriteStoreColors(ColormapPtr pMap, int ndef, xColorItem * pdef);
 
@@ -512,8 +511,7 @@ miSpriteCopyWindow(WindowPtr pWindow, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
 }
 
 static void
-miSpriteBlockHandler(ScreenPtr pScreen, void *pTimeout,
-                     void *pReadmask)
+miSpriteBlockHandler(ScreenPtr pScreen, void *timeout)
 {
     miSpriteScreenPtr pPriv = GetSpriteScreen(pScreen);
     DeviceIntPtr pDev;
@@ -545,7 +543,7 @@ miSpriteBlockHandler(ScreenPtr pScreen, void *pTimeout,
         }
     }
 
-    (*pScreen->BlockHandler) (pScreen, pTimeout, pReadmask);
+    (*pScreen->BlockHandler) (pScreen, timeout);
 
     if (WorkToDo)
         SCREEN_EPILOGUE(pPriv, pScreen, BlockHandler);
diff --git a/miext/shadow/shadow.c b/miext/shadow/shadow.c
index 405c4dd..b8e23da 100644
--- a/miext/shadow/shadow.c
+++ b/miext/shadow/shadow.c
@@ -65,14 +65,14 @@ shadowRedisplay(ScreenPtr pScreen)
 }
 
 static void
-shadowBlockHandler(ScreenPtr pScreen, void *timeout, void *pRead)
+shadowBlockHandler(ScreenPtr pScreen, void *timeout)
 {
     shadowBuf(pScreen);
 
     shadowRedisplay(pScreen);
 
     unwrap(pBuf, pScreen, BlockHandler);
-    pScreen->BlockHandler(pScreen, timeout, pRead);
+    pScreen->BlockHandler(pScreen, timeout);
     wrap(pBuf, pScreen, BlockHandler);
 }
 
commit 410bc047480a9f98df678dc850bc6b99c3cfb5bf
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Dec 7 15:03:10 2015 -0800

    dmx: Eliminate use of AddEnabledDevice [v2]
    
    Use SetNotifyFd instead, with the hope that someday someone will come
    fix this to be more efficient -- right now, the wakeup handler is
    doing the event reading, instead of the notify callback.
    
    v2: no need to patch dmxsigio.c as it has been removed.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/dmx/input/dmxcommon.c b/hw/dmx/input/dmxcommon.c
index 90154ef..c7aed68 100644
--- a/hw/dmx/input/dmxcommon.c
+++ b/hw/dmx/input/dmxcommon.c
@@ -480,17 +480,26 @@ dmxCommonXSelect(DMXScreenInfo * dmxScreen, void *closure)
     return NULL;
 }
 
+static void
+dmxCommonFdNotify(int fd, int ready, void *data)
+{
+    /* This should process input on this fd, but instead all
+     * of that is delayed until the block and wakeup handlers are called
+     */
+    ;
+}
+
 static void *
 dmxCommonAddEnabledDevice(DMXScreenInfo * dmxScreen, void *closure)
 {
-    AddEnabledDevice(XConnectionNumber(dmxScreen->beDisplay));
+    SetNotifyFd(XConnectionNumber(dmxScreen->beDisplay), dmxCommonFdNotify, X_NOTIFY_READ, closure);
     return NULL;
 }
 
 static void *
 dmxCommonRemoveEnabledDevice(DMXScreenInfo * dmxScreen, void *closure)
 {
-    RemoveEnabledDevice(XConnectionNumber(dmxScreen->beDisplay));
+    RemoveNotifyFd(XConnectionNumber(dmxScreen->beDisplay));
     return NULL;
 }
 
@@ -504,7 +513,7 @@ dmxCommonMouOn(DevicePtr pDev)
     priv->eventMask |= DMX_POINTER_EVENT_MASK;
     if (!priv->be) {
         XSelectInput(priv->display, priv->window, priv->eventMask);
-        AddEnabledDevice(XConnectionNumber(priv->display));
+        SetNotifyFd(XConnectionNumber(priv->display), dmxCommonFdNotify,X_NOTIFY_READ, pDev);
     }
     else {
         dmxPropertyIterate(priv->be, dmxCommonXSelect, priv);
@@ -523,7 +532,7 @@ dmxCommonMouOff(DevicePtr pDev)
 
     priv->eventMask &= ~DMX_POINTER_EVENT_MASK;
     if (!priv->be) {
-        RemoveEnabledDevice(XConnectionNumber(priv->display));
+        RemoveNotifyFd(XConnectionNumber(priv->display));
         XSelectInput(priv->display, priv->window, priv->eventMask);
     }
     else {
commit 6299ef3d749d6f978d3d38d42f711ac56bf382eb
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Aug 27 11:49:35 2015 -0700

    modesetting: Use passed-in fd for drm event monitoring NotifyFd callback
    
    This is a cleanup, proposed by Adam Jackson, but wasn't merged with
    the original NotifyFD changes.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/vblank.c b/hw/xfree86/drivers/modesetting/vblank.c
index 869472a..0727887 100644
--- a/hw/xfree86/drivers/modesetting/vblank.c
+++ b/hw/xfree86/drivers/modesetting/vblank.c
@@ -253,7 +253,7 @@ ms_drm_socket_handler(int fd, int ready, void *data)
     if (data == NULL)
         return;
 
-    drmHandleEvent(ms->fd, &ms->event_context);
+    drmHandleEvent(fd, &ms->event_context);
 }
 
 /*
commit 6bf7b49f6711c7ed1837283dc04f93f4c1b77ecc
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Aug 27 11:47:26 2015 -0700

    hw/kdrive: Use passed-in fd for kdrive/linux APM monitoring [v2]
    
    This is a cleanup, proposed by Adam Jackson, but wasn't merged with
    the original NotifyFD changes.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/kdrive/linux/linux.c b/hw/kdrive/linux/linux.c
index 76daaf2..56c2cb7 100644
--- a/hw/kdrive/linux/linux.c
+++ b/hw/kdrive/linux/linux.c
@@ -173,41 +173,39 @@ static Bool LinuxApmRunning;
 static void
 LinuxApmNotify(int fd, int mask, void *blockData)
 {
-    if (LinuxApmFd >= 0) {
-        apm_event_t event;
-        Bool running = LinuxApmRunning;
-        int cmd = APM_IOC_SUSPEND;
-
-        while (read(LinuxApmFd, &event, sizeof(event)) == sizeof(event)) {
-            switch (event) {
-            case APM_SYS_STANDBY:
-            case APM_USER_STANDBY:
-                running = FALSE;
-                cmd = APM_IOC_STANDBY;
-                break;
-            case APM_SYS_SUSPEND:
-            case APM_USER_SUSPEND:
-            case APM_CRITICAL_SUSPEND:
-                running = FALSE;
-                cmd = APM_IOC_SUSPEND;
-                break;
-            case APM_NORMAL_RESUME:
-            case APM_CRITICAL_RESUME:
-            case APM_STANDBY_RESUME:
-                running = TRUE;
-                break;
-            }
-        }
-        if (running && !LinuxApmRunning) {
-            KdResume();
-            LinuxApmRunning = TRUE;
-        }
-        else if (!running && LinuxApmRunning) {
-            KdSuspend();
-            LinuxApmRunning = FALSE;
-            ioctl(LinuxApmFd, cmd, 0);
+    apm_event_t event;
+    Bool running = LinuxApmRunning;
+    int cmd = APM_IOC_SUSPEND;
+
+    while (read(fd, &event, sizeof(event)) == sizeof(event)) {
+        switch (event) {
+        case APM_SYS_STANDBY:
+        case APM_USER_STANDBY:
+            running = FALSE;
+            cmd = APM_IOC_STANDBY;
+            break;
+        case APM_SYS_SUSPEND:
+        case APM_USER_SUSPEND:
+        case APM_CRITICAL_SUSPEND:
+            running = FALSE;
+            cmd = APM_IOC_SUSPEND;
+            break;
+        case APM_NORMAL_RESUME:
+        case APM_CRITICAL_RESUME:
+        case APM_STANDBY_RESUME:
+            running = TRUE;
+            break;
         }
     }
+    if (running && !LinuxApmRunning) {
+        KdResume();
+        LinuxApmRunning = TRUE;
+    }
+    else if (!running && LinuxApmRunning) {
+        KdSuspend();
+        LinuxApmRunning = FALSE;
+        ioctl(fd, cmd, 0);
+    }
 }
 
 #ifdef FNONBLOCK
commit 55c2e1a3aa587c58a74066724e11e30b3df267b8
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Dec 7 15:11:33 2015 -0800

    xnest: Use SetNotifyFd to receive events
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xnest/Init.c b/hw/xnest/Init.c
index bec2c51..e8a700e 100644
--- a/hw/xnest/Init.c
+++ b/hw/xnest/Init.c
@@ -35,6 +35,7 @@ is" without express or implied warranty.
 #include "Pointer.h"
 #include "Keyboard.h"
 #include "Handlers.h"
+#include "Events.h"
 #include "Init.h"
 #include "Args.h"
 #include "Drawable.h"
@@ -86,6 +87,12 @@ InitOutput(ScreenInfo * screen_info, int argc, char *argv[])
     xnestDoFullGeneration = xnestFullGeneration;
 }
 
+static void
+xnestNotifyConnection(int fd, int ready, void *data)
+{
+    xnestCollectEvents();
+}
+
 void
 InitInput(int argc, char *argv[])
 {
@@ -101,7 +108,7 @@ InitInput(int argc, char *argv[])
 
     mieqInit();
 
-    AddEnabledDevice(XConnectionNumber(xnestDisplay));
+    SetNotifyFd(XConnectionNumber(xnestDisplay), xnestNotifyConnection, X_NOTIFY_READ, NULL);
 
     RegisterBlockAndWakeupHandlers(xnestBlockHandler, xnestWakeupHandler, NULL);
 }
commit 24e65bf0db57bf4ac70386c0a0e8275b73edd2fb
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Dec 3 01:02:02 2015 -0600

    hw/xfree86: Use NotifyFd for other input fd wakeups
    
    Remove code in xf86Wakeup for dealing with other input and switch to
    using the new NotifyFd interface.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index 7b9c33a..7d3c35f 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -100,8 +100,6 @@ Bool VTSwitchEnabled = TRUE;    /* Allows run-time disabling for
                                  switches when using the DRI
                                  automatic full screen mode.*/
 
-extern fd_set EnabledDevices;
-
 #ifdef XF86PM
 extern void (*xf86OSPMClose) (void);
 #endif
@@ -246,17 +244,6 @@ xf86ProcessActionEvent(ActionEvent action, void *arg)
 void
 xf86Wakeup(void *blockData, int err, void *pReadmask)
 {
-    if (err >= 0) {             /* we don't want the handlers called if select() */
-        IHPtr ih, ih_tmp;       /* returned with an error condition, do we?      */
-
-        nt_list_for_each_entry_safe(ih, ih_tmp, InputHandlers, next) {
-            if (ih->enabled && ih->fd >= 0 && ih->ihproc &&
-                (FD_ISSET(ih->fd, ((fd_set *) pReadmask)) != 0)) {
-                ih->ihproc(ih->fd, ih->data);
-            }
-        }
-    }
-
     if (xf86VTSwitchPending())
         xf86VTSwitch();
 }
@@ -601,6 +588,16 @@ xf86VTSwitch(void)
 
 /* Input handler registration */
 
+static void
+xf86InputHandlerNotify(int fd, int ready, void *data)
+{
+    IHPtr       ih = data;
+
+    if (ih->enabled && ih->fd >= 0 && ih->ihproc) {
+        ih->ihproc(ih->fd, ih->data);
+    }
+}
+
 static void *
 addInputHandler(int fd, InputHandlerProc proc, void *data)
 {
@@ -618,6 +615,11 @@ addInputHandler(int fd, InputHandlerProc proc, void *data)
     ih->data = data;
     ih->enabled = TRUE;
 
+    if (!SetNotifyFd(fd, xf86InputHandlerNotify, X_NOTIFY_READ, ih)) {
+        free(ih);
+        return NULL;
+    }
+
     ih->next = InputHandlers;
     InputHandlers = ih;
 
@@ -629,10 +631,8 @@ xf86AddInputHandler(int fd, InputHandlerProc proc, void *data)
 {
     IHPtr ih = addInputHandler(fd, proc, data);
 
-    if (ih) {
-        AddEnabledDevice(fd);
+    if (ih)
         ih->is_input = TRUE;
-    }
     return ih;
 }
 
@@ -641,8 +641,6 @@ xf86AddGeneralHandler(int fd, InputHandlerProc proc, void *data)
 {
     IHPtr ih = addInputHandler(fd, proc, data);
 
-    if (ih)
-        AddGeneralSocket(fd);
     return ih;
 }
 
@@ -672,6 +670,8 @@ removeInputHandler(IHPtr ih)
 {
     IHPtr p;
 
+    if (ih->fd >= 0)
+        RemoveNotifyFd(ih->fd);
     if (ih == InputHandlers)
         InputHandlers = ih->next;
     else {
@@ -696,8 +696,6 @@ xf86RemoveInputHandler(void *handler)
     ih = handler;
     fd = ih->fd;
 
-    if (ih->fd >= 0)
-        RemoveEnabledDevice(ih->fd);
     removeInputHandler(ih);
 
     return fd;
@@ -715,8 +713,6 @@ xf86RemoveGeneralHandler(void *handler)
     ih = handler;
     fd = ih->fd;
 
-    if (ih->fd >= 0)
-        RemoveGeneralSocket(ih->fd);
     removeInputHandler(ih);
 
     return fd;
@@ -733,7 +729,7 @@ xf86DisableInputHandler(void *handler)
     ih = handler;
     ih->enabled = FALSE;
     if (ih->fd >= 0)
-        RemoveEnabledDevice(ih->fd);
+        RemoveNotifyFd(ih->fd);
 }
 
 void
@@ -747,7 +743,7 @@ xf86DisableGeneralHandler(void *handler)
     ih = handler;
     ih->enabled = FALSE;
     if (ih->fd >= 0)
-        RemoveGeneralSocket(ih->fd);
+        RemoveNotifyFd(ih->fd);
 }
 
 void
@@ -761,7 +757,7 @@ xf86EnableInputHandler(void *handler)
     ih = handler;
     ih->enabled = TRUE;
     if (ih->fd >= 0)
-        AddEnabledDevice(ih->fd);
+        SetNotifyFd(ih->fd, xf86InputHandlerNotify, X_NOTIFY_READ, ih);
 }
 
 void
@@ -775,7 +771,7 @@ xf86EnableGeneralHandler(void *handler)
     ih = handler;
     ih->enabled = TRUE;
     if (ih->fd >= 0)
-        AddGeneralSocket(ih->fd);
+        SetNotifyFd(ih->fd, xf86InputHandlerNotify, X_NOTIFY_READ, ih);
 }
 
 /*
commit c3fea428aed919826130ef8ebdb2cceb445a845b
Author: Keith Packard <keithp at keithp.com>
Date:   Tue May 24 20:51:31 2016 -0700

    os: Use NotifyFd for ErrorConnMax
    
    Instead of open-coding a single FD wait, use NotifyFd to wait for the
    FD to become readable before returning the error message.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/os/connection.c b/os/connection.c
index 4c1ba4b..d001b98 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -863,7 +863,6 @@ EstablishNewConnections(ClientPtr clientUnused, void *closure)
 
     if (!AllocNewConnection(new_trans_conn, newconn, connect_time)) {
         ErrorConnMax(new_trans_conn);
-        _XSERVTransClose(new_trans_conn);
     }
     return TRUE;
 }
@@ -881,37 +880,27 @@ QueueNewConnections(int fd, int ready, void *data)
  *     Fail a connection due to lack of client or file descriptor space
  ************/
 
-#define BOTIMEOUT 200           /* in milliseconds */
-
 static void
-ErrorConnMax(XtransConnInfo trans_conn)
+ConnMaxNotify(int fd, int events, void *data)
 {
-    int fd = _XSERVTransGetConnectionNumber(trans_conn);
-    xConnSetupPrefix csp;
-    char pad[3] = { 0, 0, 0 };
-    struct iovec iov[3];
+    XtransConnInfo trans_conn = data;
     char order = 0;
-    int whichbyte = 1;
-    struct timeval waittime;
-    fd_set mask;
-
-    /* if these seems like a lot of trouble to go to, it probably is */
-    waittime.tv_sec = BOTIMEOUT / MILLI_PER_SECOND;
-    waittime.tv_usec = (BOTIMEOUT % MILLI_PER_SECOND) *
-        (1000000 / MILLI_PER_SECOND);
-    FD_ZERO(&mask);
-    FD_SET(fd, &mask);
-    (void) Select(fd + 1, &mask, NULL, NULL, &waittime);
+
     /* try to read the byte-order of the connection */
     (void) _XSERVTransRead(trans_conn, &order, 1);
     if (order == 'l' || order == 'B' || order == 'r' || order == 'R') {
+        xConnSetupPrefix csp;
+        char pad[3] = { 0, 0, 0 };
+        int whichbyte = 1;
+        struct iovec iov[3];
+
         csp.success = xFalse;
         csp.lengthReason = sizeof(NOROOM) - 1;
         csp.length = (sizeof(NOROOM) + 2) >> 2;
         csp.majorVersion = X_PROTOCOL;
         csp.minorVersion = X_PROTOCOL_REVISION;
-	if (((*(char *) &whichbyte) && (order == 'B' || order == 'R')) ||
-	    (!(*(char *) &whichbyte) && (order == 'l' || order == 'r'))) {
+        if (((*(char *) &whichbyte) && (order == 'B' || order == 'R')) ||
+            (!(*(char *) &whichbyte) && (order == 'l' || order == 'r'))) {
             swaps(&csp.majorVersion);
             swaps(&csp.minorVersion);
             swaps(&csp.length);
@@ -924,6 +913,15 @@ ErrorConnMax(XtransConnInfo trans_conn)
         iov[2].iov_base = pad;
         (void) _XSERVTransWritev(trans_conn, iov, 3);
     }
+    RemoveNotifyFd(trans_conn->fd);
+    _XSERVTransClose(trans_conn);
+}
+
+static void
+ErrorConnMax(XtransConnInfo trans_conn)
+{
+    if (!SetNotifyFd(trans_conn->fd, ConnMaxNotify, X_NOTIFY_READ, trans_conn))
+        _XSERVTransClose(trans_conn);
 }
 
 /************
@@ -1426,7 +1424,6 @@ AddClientOnOpenFD(int fd)
 
     if (!AllocNewConnection(ciptr, fd, connect_time)) {
         ErrorConnMax(ciptr);
-        _XSERVTransClose(ciptr);
         return FALSE;
     }
 
commit 559aac2d71250e3137aaa582e2a59a918ddf21b7
Author: Keith Packard <keithp at keithp.com>
Date:   Tue May 24 21:59:38 2016 -0700

    dmx: Switch from select(2) to poll(2) for input
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/dmx/input/lnx-ms.c b/hw/dmx/input/lnx-ms.c
index cb3b25f..c7a09ca 100644
--- a/hw/dmx/input/lnx-ms.c
+++ b/hw/dmx/input/lnx-ms.c
@@ -76,6 +76,7 @@
 #include <X11/Xos.h>
 #include <errno.h>
 #include <termios.h>
+#include <poll.h>
 
 /*****************************************************************************/
 /* Define some macros to make it easier to move this file to another
@@ -120,10 +121,11 @@ static int
 msLinuxReadBytes(int fd, unsigned char *buf, int len, int min)
 {
     int n, tot;
-    fd_set set;
-    struct timeval tv;
+    struct pollfd poll_fd;
 
     tot = 0;
+    poll_fd.fd = fd;
+    poll_fd.events = POLLIN;
     while (len) {
         n = read(fd, buf, len);
         if (n > 0) {
@@ -133,11 +135,7 @@ msLinuxReadBytes(int fd, unsigned char *buf, int len, int min)
         }
         if (tot % min == 0)
             break;
-        FD_ZERO(&set);
-        FD_SET(fd, &set);
-        tv.tv_sec = 0;
-        tv.tv_usec = 100 * 1000;
-        n = select(fd + 1, &set, 0, 0, &tv);
+        n = poll(&poll_fd, 1, 100);
         if (n <= 0)
             break;
     }
@@ -246,7 +244,8 @@ msLinuxInit(DevicePtr pDev)
     if (tcgetattr(priv->fd, &priv->tty) < 0)
         FATAL1("msLinuxInit: tcgetattr failed (%s)\n", strerror(errno));
 
-    write(priv->fd, "*n", 2);   /* 1200 baud */
+    i = write(priv->fd, "*n", 2);   /* 1200 baud */
+    (void) i;
     usleep(100000);
 }
 
@@ -256,6 +255,7 @@ msLinuxOn(DevicePtr pDev)
 {
     GETPRIV;
     struct termios nTty;
+    int i;
 
     if (priv->fd < 0)
         msLinuxInit(pDev);
@@ -273,7 +273,8 @@ msLinuxOn(DevicePtr pDev)
     cfsetospeed(&nTty, B1200);
     if (tcsetattr(priv->fd, TCSANOW, &nTty) < 0)
         FATAL1("msLinuxInit: tcsetattr failed (%s)\n", strerror(errno));
-    write(priv->fd, "*V", 2);   /* 2 button 3 byte protocol */
+    i = write(priv->fd, "*V", 2);   /* 2 button 3 byte protocol */
+    (void) i;
     return priv->fd;
 }
 
diff --git a/hw/dmx/input/lnx-ps2.c b/hw/dmx/input/lnx-ps2.c
index 9041974..00ccc01 100644
--- a/hw/dmx/input/lnx-ps2.c
+++ b/hw/dmx/input/lnx-ps2.c
@@ -73,6 +73,7 @@
 #include <X11/Xos.h>
 #include <errno.h>
 #include <termios.h>
+#include <poll.h>
 
 /*****************************************************************************/
 /* Define some macros to make it easier to move this file to another
@@ -116,9 +117,10 @@ static int
 ps2LinuxReadBytes(int fd, unsigned char *buf, int len, int min)
 {
     int n, tot;
-    fd_set set;
-    struct timeval tv;
+    struct pollfd poll_fd;
 
+    poll_fd.fd = fd;
+    poll_fd.events = POLLIN;
     tot = 0;
     while (len) {
         n = read(fd, buf, len);
@@ -129,11 +131,7 @@ ps2LinuxReadBytes(int fd, unsigned char *buf, int len, int min)
         }
         if (tot % min == 0)
             break;
-        FD_ZERO(&set);
-        FD_SET(fd, &set);
-        tv.tv_sec = 0;
-        tv.tv_usec = 100 * 1000;
-        n = select(fd + 1, &set, 0, 0, &tv);
+        n = poll(&poll_fd, 1, 100);
         if (n <= 0)
             break;
     }
commit aa6717ce213e79735c72afc5ec9cc1f9c0297e09
Author: Keith Packard <keithp at keithp.com>
Date:   Tue May 24 21:36:18 2016 -0700

    xfree86: Switch from select(2) to poll(2)
    
    xf86WaitForInput and the xf86 SIGIO handling code.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index 5db0dfb..7b9c33a 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -54,7 +54,6 @@
 #endif
 
 #include <X11/X.h>
-#include <X11/Xpoll.h>
 #include <X11/Xproto.h>
 #include <X11/Xatom.h>
 #include "misc.h"
diff --git a/hw/xfree86/os-support/shared/posix_tty.c b/hw/xfree86/os-support/shared/posix_tty.c
index 6e2af00..d5a70ba 100644
--- a/hw/xfree86/os-support/shared/posix_tty.c
+++ b/hw/xfree86/os-support/shared/posix_tty.c
@@ -57,6 +57,7 @@
 #endif
 
 #include <X11/X.h>
+#include <poll.h>
 #include "xf86.h"
 #include "xf86Priv.h"
 #include "xf86_OSlib.h"
@@ -387,26 +388,19 @@ xf86CloseSerial(int fd)
 int
 xf86WaitForInput(int fd, int timeout)
 {
-    fd_set readfds;
-    struct timeval to;
     int r;
+    struct pollfd poll_fd;
 
-    FD_ZERO(&readfds);
+    poll_fd.fd = fd;
+    poll_fd.events = POLLIN;
 
     if (fd >= 0) {
-        FD_SET(fd, &readfds);
-    }
-
-    to.tv_sec = timeout / 1000000;
-    to.tv_usec = timeout % 1000000;
-
-    if (fd >= 0) {
-        SYSCALL(r = select(FD_SETSIZE, &readfds, NULL, NULL, &to));
+        SYSCALL(r = poll(&poll_fd, 1, timeout));
     }
     else {
-        SYSCALL(r = select(FD_SETSIZE, NULL, NULL, NULL, &to));
+        SYSCALL(r = poll(&poll_fd, 0, timeout));
     }
-    xf86ErrorFVerb(9, "select returned %d\n", r);
+    xf86ErrorFVerb(9, "poll returned %d\n", r);
     return r;
 }
 
@@ -423,8 +417,7 @@ xf86SerialSendBreak(int fd, int duration)
 int
 xf86FlushInput(int fd)
 {
-    fd_set fds;
-    struct timeval timeout;
+    struct pollfd poll_fd;
     /* this needs to be big enough to flush an evdev event. */
     char c[256];
 
@@ -432,15 +425,11 @@ xf86FlushInput(int fd)
     if (tcflush(fd, TCIFLUSH) == 0)
         return 0;
 
-    timeout.tv_sec = 0;
-    timeout.tv_usec = 0;
-    FD_ZERO(&fds);
-    FD_SET(fd, &fds);
-    while (select(FD_SETSIZE, &fds, NULL, NULL, &timeout) > 0) {
+    poll_fd.fd = fd;
+    poll_fd.events = POLLIN;
+    while (poll(&poll_fd, 1, 0) > 0) {
         if (read(fd, &c, sizeof(c)) < 1)
             return 0;
-        FD_ZERO(&fds);
-        FD_SET(fd, &fds);
     }
     return 0;
 }
diff --git a/hw/xfree86/os-support/shared/sigio.c b/hw/xfree86/os-support/shared/sigio.c
index 37ef38f..949d1b4 100644
--- a/hw/xfree86/os-support/shared/sigio.c
+++ b/hw/xfree86/os-support/shared/sigio.c
@@ -57,6 +57,7 @@
 #endif
 
 #include <X11/X.h>
+#include <poll.h>
 #include "xf86.h"
 #include "xf86Priv.h"
 #include "xf86_OSlib.h"
@@ -83,8 +84,36 @@ typedef struct _xf86SigIOFunc {
 
 static Xf86SigIOFunc xf86SigIOFuncs[MAX_FUNCS];
 static int xf86SigIOMax;
-static int xf86SigIOMaxFd;
-static fd_set xf86SigIOMask;
+static struct pollfd *xf86SigIOFds;
+static int xf86SigIONum;
+
+static Bool
+xf86SigIOAdd(int fd)
+{
+    struct pollfd *n;
+
+    n = realloc(xf86SigIOFds, (xf86SigIONum + 1) * sizeof (struct pollfd));
+    if (!n)
+        return FALSE;
+
+    n[xf86SigIONum].fd = fd;
+    n[xf86SigIONum].events = POLLIN;
+    xf86SigIONum++;
+    xf86SigIOFds = n;
+    return TRUE;
+}
+
+static void
+xf86SigIORemove(int fd)
+{
+    int i;
+    for (i = 0; i < xf86SigIONum; i++)
+        if (xf86SigIOFds[i].fd == fd) {
+            memmove(&xf86SigIOFds[i], &xf86SigIOFds[i+1], (xf86SigIONum - i - 1) * sizeof (struct pollfd));
+            xf86SigIONum--;
+            break;
+        }
+}
 
 /*
  * SIGIO gives no way of discovering which fd signalled, select
@@ -93,24 +122,22 @@ static fd_set xf86SigIOMask;
 static void
 xf86SIGIO(int sig)
 {
-    int i;
-    fd_set ready;
-    struct timeval to;
+    int i, f;
     int save_errno = errno;     /* do not clobber the global errno */
     int r;
 
     inSignalContext = TRUE;
 
-    ready = xf86SigIOMask;
-    to.tv_sec = 0;
-    to.tv_usec = 0;
-    SYSCALL(r = select(xf86SigIOMaxFd, &ready, 0, 0, &to));
-    for (i = 0; r > 0 && i < xf86SigIOMax; i++)
-        if (xf86SigIOFuncs[i].f && FD_ISSET(xf86SigIOFuncs[i].fd, &ready)) {
-            (*xf86SigIOFuncs[i].f) (xf86SigIOFuncs[i].fd,
-                                    xf86SigIOFuncs[i].closure);
+    SYSCALL(r = poll(xf86SigIOFds, xf86SigIONum, 0));
+    for (f = 0; r > 0 && f < xf86SigIONum; f++) {
+        if (xf86SigIOFds[f].revents & POLLIN) {
+            for (i = 0; i < xf86SigIOMax; i++)
+                if (xf86SigIOFuncs[i].f && xf86SigIOFuncs[i].fd == xf86SigIOFds[f].fd)
+                    (*xf86SigIOFuncs[i].f) (xf86SigIOFuncs[i].fd,
+                                            xf86SigIOFuncs[i].closure);
             r--;
         }
+    }
     if (r > 0) {
         xf86Msg(X_ERROR, "SIGIO %d descriptors not handled\n", r);
     }
@@ -206,9 +233,7 @@ xf86InstallSIGIOHandler(int fd, void (*f) (int, void *), void *closure)
             xf86SigIOFuncs[i].f = f;
             if (i >= xf86SigIOMax)
                 xf86SigIOMax = i + 1;
-            if (fd >= xf86SigIOMaxFd)
-                xf86SigIOMaxFd = fd + 1;
-            FD_SET(fd, &xf86SigIOMask);
+            xf86SigIOAdd(fd);
             release_sigio();
             return 1;
         }
@@ -229,14 +254,12 @@ xf86RemoveSIGIOHandler(int fd)
     struct sigaction osa;
     int i;
     int max;
-    int maxfd;
     int ret;
 
     if (!xf86Info.useSIGIO)
         return 0;
 
     max = 0;
-    maxfd = -1;
     ret = 0;
     for (i = 0; i < MAX_FUNCS; i++) {
         if (xf86SigIOFuncs[i].f) {
@@ -244,13 +267,11 @@ xf86RemoveSIGIOHandler(int fd)
                 xf86SigIOFuncs[i].f = 0;
                 xf86SigIOFuncs[i].fd = 0;
                 xf86SigIOFuncs[i].closure = 0;
-                FD_CLR(fd, &xf86SigIOMask);
+                xf86SigIORemove(fd);
                 ret = 1;
             }
             else {
                 max = i + 1;
-                if (xf86SigIOFuncs[i].fd >= maxfd)
-                    maxfd = xf86SigIOFuncs[i].fd + 1;
             }
         }
     }
@@ -267,7 +288,6 @@ xf86RemoveSIGIOHandler(int fd)
         }
 #endif
         xf86SigIOMax = max;
-        xf86SigIOMaxFd = maxfd;
         if (!max) {
             sigemptyset(&sa.sa_mask);
             sigaddset(&sa.sa_mask, SIGIO);
commit 81135991a583b3b30a90e82ddc1d5c86d57bf00b
Author: Keith Packard <keithp at keithp.com>
Date:   Tue May 24 21:19:13 2016 -0700

    kdrive: switch from select(2) to poll(2)
    
    This avoids fd limits
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/kdrive/fake/mouse.c b/hw/kdrive/fake/mouse.c
index bb4c25e..564dae4 100644
--- a/hw/kdrive/fake/mouse.c
+++ b/hw/kdrive/fake/mouse.c
@@ -27,7 +27,6 @@
 #include <termios.h>
 #include <X11/X.h>
 #include <X11/Xproto.h>
-#include <X11/Xpoll.h>
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "kdrive.h"
diff --git a/hw/kdrive/linux/evdev.c b/hw/kdrive/linux/evdev.c
index 8415772..9590413 100644
--- a/hw/kdrive/linux/evdev.c
+++ b/hw/kdrive/linux/evdev.c
@@ -27,7 +27,6 @@
 #include <linux/input.h>
 #include <X11/X.h>
 #include <X11/Xproto.h>
-#include <X11/Xpoll.h>
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "kdrive.h"
@@ -444,6 +443,7 @@ EvdevKbdLeds(KdKeyboardInfo * ki, int leds)
 {
     struct input_event event;
     Kevdev             *ke;
+    int                i;
 
     if (!ki)
         return;
@@ -458,22 +458,26 @@ EvdevKbdLeds(KdKeyboardInfo * ki, int leds)
     event.type = EV_LED;
     event.code = LED_CAPSL;
     event.value = leds & (1 << 0) ? 1 : 0;
-    write(ke->fd, (char *) &event, sizeof(event));
+    i = write(ke->fd, (char *) &event, sizeof(event));
+    (void) i;
 
     event.type = EV_LED;
     event.code = LED_NUML;
     event.value = leds & (1 << 1) ? 1 : 0;
-    write(ke->fd, (char *) &event, sizeof(event));
+    i = write(ke->fd, (char *) &event, sizeof(event));
+    (void) i;
 
     event.type = EV_LED;
     event.code = LED_SCROLLL;
     event.value = leds & (1 << 2) ? 1 : 0;
-    write(ke->fd, (char *) &event, sizeof(event));
+    i = write(ke->fd, (char *) &event, sizeof(event));
+    (void) i;
 
     event.type = EV_LED;
     event.code = LED_COMPOSE;
     event.value = leds & (1 << 3) ? 1 : 0;
-    write(ke->fd, (char *) &event, sizeof(event));
+    i = write(ke->fd, (char *) &event, sizeof(event));
+    (void) i;
 }
 
 static void
diff --git a/hw/kdrive/linux/mouse.c b/hw/kdrive/linux/mouse.c
index 2bfe7f2..3508b17 100644
--- a/hw/kdrive/linux/mouse.c
+++ b/hw/kdrive/linux/mouse.c
@@ -27,7 +27,7 @@
 #include <termios.h>
 #include <X11/X.h>
 #include <X11/Xproto.h>
-#include <X11/Xpoll.h>
+#include <poll.h>
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "kdrive.h"
@@ -47,23 +47,15 @@ typedef struct _kbufio {
 static Bool
 MouseWaitForReadable(int fd, int timeout)
 {
-    fd_set set;
-    struct timeval tv, *tp;
+    struct pollfd poll_fd;
     int n;
     CARD32 done;
 
     done = GetTimeInMillis() + timeout;
+    poll_fd.fd = fd;
+    poll_fd.events = POLLIN;
     for (;;) {
-        FD_ZERO(&set);
-        FD_SET(fd, &set);
-        if (timeout == -1)
-            tp = 0;
-        else {
-            tv.tv_sec = timeout / 1000;
-            tv.tv_usec = (timeout % 1000) * 1000;
-            tp = &tv;
-        }
-        n = select(fd + 1, &set, 0, 0, tp);
+        n = poll(&poll_fd, 1, timeout);
         if (n > 0)
             return TRUE;
         if (n < 0 && (errno == EAGAIN || errno == EINTR)) {
@@ -139,20 +131,12 @@ MousePeekByte(Kbufio * b, int timeout)
 static Bool
 MouseWaitForWritable(int fd, int timeout)
 {
-    fd_set set;
-    struct timeval tv, *tp;
+    struct pollfd poll_fd;
     int n;
 
-    FD_ZERO(&set);
-    FD_SET(fd, &set);
-    if (timeout == -1)
-        tp = 0;
-    else {
-        tv.tv_sec = timeout / 1000;
-        tv.tv_usec = (timeout % 1000) * 1000;
-        tp = &tv;
-    }
-    n = select(fd + 1, 0, &set, 0, tp);
+    poll_fd.fd = fd;
+    poll_fd.events = POLLOUT;
+    n = poll(&poll_fd, 1, timeout);
     if (n > 0)
         return TRUE;
     return FALSE;
diff --git a/hw/kdrive/linux/ms.c b/hw/kdrive/linux/ms.c
index e82350a..79e6373 100644
--- a/hw/kdrive/linux/ms.c
+++ b/hw/kdrive/linux/ms.c
@@ -26,9 +26,9 @@ THE SOFTWARE.
 #endif
 #include <errno.h>
 #include <termios.h>
+#include <poll.h>
 #include <X11/X.h>
 #include <X11/Xproto.h>
-#include <X11/Xpoll.h>
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "kdrive.h"
@@ -37,9 +37,10 @@ static int
 MsReadBytes(int fd, char *buf, int len, int min)
 {
     int n, tot;
-    fd_set set;
-    struct timeval tv;
+    struct pollfd poll_fd;
 
+    poll_fd.fd = fd;
+    poll_fd.events = POLLIN;
     tot = 0;
     while (len) {
         n = read(fd, buf, len);
@@ -50,11 +51,7 @@ MsReadBytes(int fd, char *buf, int len, int min)
         }
         if (tot % min == 0)
             break;
-        FD_ZERO(&set);
-        FD_SET(fd, &set);
-        tv.tv_sec = 0;
-        tv.tv_usec = 100 * 1000;
-        n = select(fd + 1, &set, 0, 0, &tv);
+        n = poll(&poll_fd, 1, 100);
         if (n <= 0)
             break;
     }
diff --git a/hw/kdrive/linux/ps2.c b/hw/kdrive/linux/ps2.c
index e5417a5..5d4a8eb 100644
--- a/hw/kdrive/linux/ps2.c
+++ b/hw/kdrive/linux/ps2.c
@@ -25,7 +25,7 @@
 #endif
 #include <X11/X.h>
 #include <X11/Xproto.h>
-#include <X11/Xpoll.h>
+#include <poll.h>
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "kdrive.h"
@@ -34,10 +34,11 @@ static int
 Ps2ReadBytes(int fd, char *buf, int len, int min)
 {
     int n, tot;
-    fd_set set;
-    struct timeval tv;
+    struct pollfd poll_fd;
 
     tot = 0;
+    poll_fd.fd = fd;
+    poll_fd.events = POLLIN;
     while (len) {
         n = read(fd, buf, len);
         if (n > 0) {
@@ -47,11 +48,7 @@ Ps2ReadBytes(int fd, char *buf, int len, int min)
         }
         if (tot % min == 0)
             break;
-        FD_ZERO(&set);
-        FD_SET(fd, &set);
-        tv.tv_sec = 0;
-        tv.tv_usec = 100 * 1000;
-        n = select(fd + 1, &set, 0, 0, &tv);
+        n = poll(&poll_fd, 1, 100);
         if (n <= 0)
             break;
     }
diff --git a/hw/kdrive/linux/tslib.c b/hw/kdrive/linux/tslib.c
index 1403c79..0cdb4ea 100644
--- a/hw/kdrive/linux/tslib.c
+++ b/hw/kdrive/linux/tslib.c
@@ -36,7 +36,6 @@
 
 #include <X11/X.h>
 #include <X11/Xproto.h>
-#include <X11/Xpoll.h>
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "kdrive.h"
commit 05a793f5b3c40747d5a92a076def7f4fb673c7e7
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Sep 1 18:50:55 2015 -0700

    dix: Switch to the libXfont2 API (v2)
    
    This new libXfont API eliminates exposing internal X server symbols to
    the font library, replacing those with a struct full of the entire API
    needed to use that library.
    
    v2: Use libXfont2 instead of libXfont_2
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/Xext/xf86bigfont.c b/Xext/xf86bigfont.c
index 97596ea..f2584c2 100644
--- a/Xext/xf86bigfont.c
+++ b/Xext/xf86bigfont.c
@@ -437,7 +437,7 @@ ProcXF86BigfontQueryFont(ClientPtr client)
 #ifdef HAS_SHM
             if (pDesc && !badSysCall) {
                 *(CARD32 *) (pCI + nCharInfos) = signature;
-                if (!FontSetPrivate(pFont, FontShmdescIndex, pDesc)) {
+                if (!xfont2_font_set_private(pFont, FontShmdescIndex, pDesc)) {
                     shmdealloc(pDesc);
                     return BadAlloc;
                 }
@@ -721,7 +721,7 @@ XFree86BigfontExtensionInit(void)
             + (unsigned int) (65536.0 / (RAND_MAX + 1.0) * rand());
         /* fprintf(stderr, "signature = 0x%08X\n", signature); */
 
-        FontShmdescIndex = AllocateFontPrivateIndex();
+        FontShmdescIndex = xfont2_allocate_font_private_index();
 
 #if !defined(CSRG_BASED) && !defined(__CYGWIN__)
         pagesize = SHMLBA;
diff --git a/configure.ac b/configure.ac
index 560d382..52466d1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -833,7 +833,7 @@ LIBEGL="egl"
 LIBGBM="gbm >= 10.2.0"
 LIBGL="gl >= 7.1.0"
 LIBXEXT="xext >= 1.0.99.4"
-LIBXFONT="xfont >= 1.4.2"
+LIBXFONT="xfont2 >= 2.0.0"
 LIBXI="xi >= 1.2.99.1"
 LIBXTST="xtst >= 1.0.99.2"
 LIBPCIACCESS="pciaccess >= 0.12.901"
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 8a7eff7..a4e5358 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -108,7 +108,7 @@ int ProcInitialConnection();
 
 #include "windowstr.h"
 #include <X11/fonts/fontstruct.h>
-#include <X11/fonts/fontutil.h>
+#include <X11/fonts/libxfont2.h>
 #include "dixfontstr.h"
 #include "gcstruct.h"
 #include "selection.h"
@@ -1285,7 +1285,7 @@ ProcQueryTextExtents(ClientPtr client)
             return BadLength;
         length--;
     }
-    if (!QueryTextExtents(pFont, length, (unsigned char *) &stuff[1], &info))
+    if (!xfont2_query_text_extents(pFont, length, (unsigned char *) &stuff[1], &info))
         return BadAlloc;
     reply = (xQueryTextExtentsReply) {
         .type = X_Reply,
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index 19db141..d217d12 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -65,6 +65,7 @@ Equipment Corporation.
 #include "closestr.h"
 #include "dixfont.h"
 #include "xace.h"
+#include <X11/fonts/libxfont2.h>
 
 #ifdef XF86BIGFONT
 #include "xf86bigfontsrv.h"
@@ -75,7 +76,7 @@ extern FontPtr defaultFont;
 
 static FontPathElementPtr *font_path_elements = (FontPathElementPtr *) 0;
 static int num_fpes = 0;
-static FPEFunctions *fpe_functions = (FPEFunctions *) 0;
+static xfont2_fpe_funcs_rec const **fpe_functions;
 static int num_fpe_types = 0;
 
 static unsigned char *font_path_string;
@@ -83,7 +84,7 @@ static unsigned char *font_path_string;
 static int num_slept_fpes = 0;
 static int size_slept_fpes = 0;
 static FontPathElementPtr *slept_fpes = (FontPathElementPtr *) 0;
-static FontPatternCachePtr patternCache;
+static xfont2_pattern_cache_ptr patternCache;
 
 static int
 FontToXError(int err)
@@ -108,18 +109,18 @@ static int
 LoadGlyphs(ClientPtr client, FontPtr pfont, unsigned nchars, int item_size,
            unsigned char *data)
 {
-    if (fpe_functions[pfont->fpe->type].load_glyphs)
-        return (*fpe_functions[pfont->fpe->type].load_glyphs)
+    if (fpe_functions[pfont->fpe->type]->load_glyphs)
+        return (*fpe_functions[pfont->fpe->type]->load_glyphs)
             (client, pfont, 0, nchars, item_size, data);
     else
         return Successful;
 }
 
 void
-dixGetGlyphs(FontPtr font, unsigned long count, unsigned char *chars,
-             FontEncoding fontEncoding,
-             unsigned long *glyphcount,    /* RETURN */
-             CharInfoPtr *glyphs)          /* RETURN */
+GetGlyphs(FontPtr font, unsigned long count, unsigned char *chars,
+          FontEncoding fontEncoding,
+          unsigned long *glyphcount,    /* RETURN */
+          CharInfoPtr *glyphs)          /* RETURN */
 {
     (*font->get_glyphs) (font, count, chars, fontEncoding, glyphcount, glyphs);
 }
@@ -206,7 +207,7 @@ FontWakeup(void *data, int count, void *LastSelectMask)
     /* wake up any fpe's that may be waiting for information */
     for (i = 0; i < num_slept_fpes; i++) {
         fpe = slept_fpes[i];
-        (void) (*fpe_functions[fpe->type].wakeup_fpe) (fpe, LastSelectMask);
+        (void) (*fpe_functions[fpe->type]->wakeup_fpe) (fpe);
     }
 }
 
@@ -222,7 +223,7 @@ FreeFPE(FontPathElementPtr fpe)
 {
     fpe->refcount--;
     if (fpe->refcount == 0) {
-        (*fpe_functions[fpe->type].free_fpe) (fpe);
+        (*fpe_functions[fpe->type]->free_fpe) (fpe);
         free((void *) fpe->name);
         free(fpe);
     }
@@ -266,14 +267,14 @@ doOpenFont(ClientPtr client, OFclosurePtr c)
     if (client->clientGone) {
         if (c->current_fpe < c->num_fpes) {
             fpe = c->fpe_list[c->current_fpe];
-            (*fpe_functions[fpe->type].client_died) ((void *) client, fpe);
+            (*fpe_functions[fpe->type]->client_died) ((void *) client, fpe);
         }
         err = Successful;
         goto bail;
     }
     while (c->current_fpe < c->num_fpes) {
         fpe = c->fpe_list[c->current_fpe];
-        err = (*fpe_functions[fpe->type].open_font)
+        err = (*fpe_functions[fpe->type]->open_font)
             ((void *) client, fpe, c->flags,
              c->fontname, c->fnamelen, FontFormat,
              BitmapFormatMaskByte |
@@ -352,8 +353,8 @@ doOpenFont(ClientPtr client, OFclosurePtr c)
         goto bail;
     }
     if (patternCache && pfont != c->non_cachable_font)
-        CacheFontPattern(patternCache, c->origFontName, c->origFontNameLen,
-                         pfont);
+        xfont2_cache_font_pattern(patternCache, c->origFontName, c->origFontNameLen,
+                                  pfont);
  bail:
     if (err != Successful && c->client != serverClient) {
         SendErrorToClient(c->client, X_OpenFont, 0,
@@ -398,7 +399,7 @@ OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname,
          ** having to create another instance of a font that already exists.
          */
 
-        cached = FindCachedFontPattern(patternCache, pfontname, lenfname);
+        cached = xfont2_find_cached_font_pattern(patternCache, pfontname, lenfname);
         if (cached && cached->info.cachable) {
             if (!AddResource(fid, RT_FONT, (void *) cached))
                 return BadAlloc;
@@ -460,7 +461,7 @@ CloseFont(void *value, XID fid)
         return Success;
     if (--pfont->refcnt == 0) {
         if (patternCache)
-            RemoveCachedFontPattern(patternCache, pfont);
+            xfont2_remove_cached_font_pattern(patternCache, pfont);
         /*
          * since the last reference is gone, ask each screen to free any
          * storage it may have allocated locally for it.
@@ -476,7 +477,7 @@ CloseFont(void *value, XID fid)
         XF86BigfontFreeFontShm(pfont);
 #endif
         fpe = pfont->fpe;
-        (*fpe_functions[fpe->type].close_font) (fpe, pfont);
+        (*fpe_functions[fpe->type]->close_font) (fpe, pfont);
         FreeFPE(fpe);
     }
     return Success;
@@ -567,7 +568,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
     if (client->clientGone) {
         if (c->current.current_fpe < c->num_fpes) {
             fpe = c->fpe_list[c->current.current_fpe];
-            (*fpe_functions[fpe->type].client_died) ((void *) client, fpe);
+            (*fpe_functions[fpe->type]->client_died) ((void *) client, fpe);
         }
         err = Successful;
         goto bail;
@@ -580,10 +581,10 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
         fpe = c->fpe_list[c->current.current_fpe];
         err = Successful;
 
-        if (!fpe_functions[fpe->type].start_list_fonts_and_aliases) {
+        if (!fpe_functions[fpe->type]->start_list_fonts_and_aliases) {
             /* This FPE doesn't support/require list_fonts_and_aliases */
 
-            err = (*fpe_functions[fpe->type].list_fonts)
+            err = (*fpe_functions[fpe->type]->list_fonts)
                 ((void *) c->client, fpe, c->current.pattern,
                  c->current.patlen, c->current.max_names - c->names->nnames,
                  c->names);
@@ -608,7 +609,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
                the FPEs.  */
 
             if (!c->current.list_started) {
-                err = (*fpe_functions[fpe->type].start_list_fonts_and_aliases)
+                err = (*fpe_functions[fpe->type]->start_list_fonts_and_aliases)
                     ((void *) c->client, fpe, c->current.pattern,
                      c->current.patlen, c->current.max_names - c->names->nnames,
                      &c->current.private);
@@ -626,7 +627,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
                 char *tmpname;
 
                 name = 0;
-                err = (*fpe_functions[fpe->type].list_next_font_or_alias)
+                err = (*fpe_functions[fpe->type]->list_next_font_or_alias)
                     ((void *) c->client, fpe, &name, &namelen, &tmpname,
                      &resolvedlen, c->current.private);
                 if (err == Suspended) {
@@ -647,11 +648,11 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
             if (err == Successful) {
                 if (c->haveSaved) {
                     if (c->savedName)
-                        (void) AddFontNamesName(c->names, c->savedName,
+                        (void) xfont2_add_font_names_name(c->names, c->savedName,
                                                 c->savedNameLen);
                 }
                 else
-                    (void) AddFontNamesName(c->names, name, namelen);
+                    (void) xfont2_add_font_names_name(c->names, name, namelen);
             }
 
             /*
@@ -676,7 +677,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
                     int tmpnamelen;
 
                     tmpname = 0;
-                    (void) (*fpe_functions[fpe->type].list_next_font_or_alias)
+                    (void) (*fpe_functions[fpe->type]->list_next_font_or_alias)
                         ((void *) c->client, fpe, &tmpname, &tmpnamelen,
                          &tmpname, &tmpnamelen, c->current.private);
                     if (--aliascount <= 0) {
@@ -782,7 +783,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
         FreeFPE(c->fpe_list[i]);
     free(c->fpe_list);
     free(c->savedName);
-    FreeFontNames(names);
+    xfont2_free_font_names(names);
     free(c);
     free(resolved);
     return TRUE;
@@ -815,7 +816,7 @@ ListFonts(ClientPtr client, unsigned char *pattern, unsigned length,
         free(c);
         return BadAlloc;
     }
-    c->names = MakeFontNamesRecord(max_names < 100 ? max_names : 100);
+    c->names = xfont2_make_font_names_record(max_names < 100 ? max_names : 100);
     if (!c->names) {
         free(c->fpe_list);
         free(c);
@@ -858,7 +859,7 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c)
     if (client->clientGone) {
         if (c->current.current_fpe < c->num_fpes) {
             fpe = c->fpe_list[c->current.current_fpe];
-            (*fpe_functions[fpe->type].client_died) ((void *) client, fpe);
+            (*fpe_functions[fpe->type]->client_died) ((void *) client, fpe);
         }
         err = Successful;
         goto bail;
@@ -870,7 +871,7 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c)
         fpe = c->fpe_list[c->current.current_fpe];
         err = Successful;
         if (!c->current.list_started) {
-            err = (*fpe_functions[fpe->type].start_list_fonts_with_info)
+            err = (*fpe_functions[fpe->type]->start_list_fonts_with_info)
                 (client, fpe, c->current.pattern, c->current.patlen,
                  c->current.max_names, &c->current.private);
             if (err == Suspended) {
@@ -885,7 +886,7 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c)
         if (err == Successful) {
             name = 0;
             pFontInfo = &fontInfo;
-            err = (*fpe_functions[fpe->type].list_next_font_with_info)
+            err = (*fpe_functions[fpe->type]->list_next_font_with_info)
                 (client, fpe, &name, &namelen, &pFontInfo,
                  &numFonts, c->current.private);
             if (err == Suspended) {
@@ -915,7 +916,7 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c)
 
                 tmpname = 0;
                 tmpFontInfo = &fontInfo;
-                (void) (*fpe_functions[fpe->type].list_next_font_with_info)
+                (void) (*fpe_functions[fpe->type]->list_next_font_with_info)
                     (client, fpe, &tmpname, &tmpnamelen, &tmpFontInfo,
                      &numFonts, c->current.private);
                 if (--aliascount <= 0) {
@@ -1102,7 +1103,7 @@ doPolyText(ClientPtr client, PTclosurePtr c)
 
     if (client->clientGone) {
         fpe = c->pGC->font->fpe;
-        (*fpe_functions[fpe->type].client_died) ((void *) client, fpe);
+        (*fpe_functions[fpe->type]->client_died) ((void *) client, fpe);
 
         if (ClientIsAsleep(client)) {
             /* Client has died, but we cannot bail out right now.  We
@@ -1128,7 +1129,7 @@ doPolyText(ClientPtr client, PTclosurePtr c)
                the FPE code to clean up after client and avoid further
                rendering while we clean up after ourself.  */
             fpe = c->pGC->font->fpe;
-            (*fpe_functions[fpe->type].client_died) ((void *) client, fpe);
+            (*fpe_functions[fpe->type]->client_died) ((void *) client, fpe);
             c->pDraw = (DrawablePtr) 0;
         }
     }
@@ -1380,7 +1381,7 @@ doImageText(ClientPtr client, ITclosurePtr c)
 
     if (client->clientGone) {
         fpe = c->pGC->font->fpe;
-        (*fpe_functions[fpe->type].client_died) ((void *) client, fpe);
+        (*fpe_functions[fpe->type]->client_died) ((void *) client, fpe);
         err = Success;
         goto bail;
     }
@@ -1394,7 +1395,7 @@ doImageText(ClientPtr client, ITclosurePtr c)
             /* Our drawable has disappeared.  Treat like client died... ask
                the FPE code to clean up after client. */
             fpe = c->pGC->font->fpe;
-            (*fpe_functions[fpe->type].client_died) ((void *) client, fpe);
+            (*fpe_functions[fpe->type]->client_died) ((void *) client, fpe);
             err = Success;
             goto bail;
         }
@@ -1520,7 +1521,7 @@ DetermineFPEType(const char *pathname)
     int i;
 
     for (i = 0; i < num_fpe_types; i++) {
-        if ((*fpe_functions[i].name_check) (pathname))
+        if ((*fpe_functions[i]->name_check) (pathname))
             return i;
     }
     return -1;
@@ -1581,8 +1582,8 @@ SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist)
         return BadAlloc;
     }
     for (i = 0; i < num_fpe_types; i++) {
-        if (fpe_functions[i].set_path_hook)
-            (*fpe_functions[i].set_path_hook) ();
+        if (fpe_functions[i]->set_path_hook)
+            (*fpe_functions[i]->set_path_hook) ();
     }
     for (i = 0; i < npaths; i++) {
         len = (unsigned int) (*cp++);
@@ -1601,7 +1602,7 @@ SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist)
              */
             fpe = find_existing_fpe(font_path_elements, num_fpes, cp, len);
             if (fpe) {
-                err = (*fpe_functions[fpe->type].reset_fpe) (fpe);
+                err = (*fpe_functions[fpe->type]->reset_fpe) (fpe);
                 if (err == Successful) {
                     UseFPE(fpe);        /* since it'll be decref'd later when freed
                                          * from the old list */
@@ -1633,7 +1634,7 @@ SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist)
                 if (fpe->type == -1)
                     err = BadValue;
                 else
-                    err = (*fpe_functions[fpe->type].init_fpe) (fpe);
+                    err = (*fpe_functions[fpe->type]->init_fpe) (fpe);
                 if (err != Successful) {
                     if (persist) {
                         DebugF
@@ -1658,7 +1659,7 @@ SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist)
     FreeFontPath(font_path_elements, num_fpes, FALSE);
     font_path_elements = fplist;
     if (patternCache)
-        EmptyFontPatternCache(patternCache);
+        xfont2_empty_font_pattern_cache(patternCache);
     num_fpes = valid_paths;
 
     return Success;
@@ -1799,31 +1800,47 @@ DeleteClientFontStuff(ClientPtr client)
 
     for (i = 0; i < num_fpes; i++) {
         fpe = font_path_elements[i];
-        if (fpe_functions[fpe->type].client_died)
-            (*fpe_functions[fpe->type].client_died) ((void *) client, fpe);
+        if (fpe_functions[fpe->type]->client_died)
+            (*fpe_functions[fpe->type]->client_died) ((void *) client, fpe);
     }
 }
 
-void
-InitFonts(void)
+static int
+register_fpe_funcs(const xfont2_fpe_funcs_rec *funcs)
 {
-    patternCache = MakeFontPatternCache();
+    xfont2_fpe_funcs_rec const **new;
 
-    ResetFontPrivateIndex();
+    /* grow the list */
+    new = reallocarray(fpe_functions, num_fpe_types + 1, sizeof(xfont2_fpe_funcs_ptr));
+    if (!new)
+        return -1;
+    fpe_functions = new;
+
+    fpe_functions[num_fpe_types] = funcs;
 
-    register_fpe_functions();
+    return num_fpe_types++;
 }
 
-_X_EXPORT
-int
-GetDefaultPointSize(void)
+static unsigned long
+get_server_generation(void)
+{
+    return serverGeneration;
+}
+
+static void *
+get_server_client(void)
+{
+    return serverClient;
+}
+
+static int
+get_default_point_size(void)
 {
     return 120;
 }
 
-_X_EXPORT
-FontResolutionPtr
-GetClientResolutions(int *num)
+static FontResolutionPtr
+get_client_resolutions(int *num)
 {
     static struct _FontResolution res;
     ScreenPtr pScreen;
@@ -1848,62 +1865,11 @@ GetClientResolutions(int *num)
     return &res;
 }
 
-/*
- * returns the type index of the new fpe
- *
- * should be called (only once!) by each type of fpe when initialized
- */
-
-_X_EXPORT
-int
-RegisterFPEFunctions(NameCheckFunc name_func,
-                     InitFpeFunc init_func,
-                     FreeFpeFunc free_func,
-                     ResetFpeFunc reset_func,
-                     OpenFontFunc open_func,
-                     CloseFontFunc close_func,
-                     ListFontsFunc list_func,
-                     StartLfwiFunc start_lfwi_func,
-                     NextLfwiFunc next_lfwi_func,
-                     WakeupFpeFunc wakeup_func,
-                     ClientDiedFunc client_died,
-                     LoadGlyphsFunc load_glyphs,
-                     StartLaFunc start_list_alias_func,
-                     NextLaFunc next_list_alias_func, SetPathFunc set_path_func)
-{
-    FPEFunctions *new;
-
-    /* grow the list */
-    new = reallocarray(fpe_functions, num_fpe_types + 1, sizeof(FPEFunctions));
-    if (!new)
-        return -1;
-    fpe_functions = new;
-
-    fpe_functions[num_fpe_types].name_check = name_func;
-    fpe_functions[num_fpe_types].open_font = open_func;
-    fpe_functions[num_fpe_types].close_font = close_func;
-    fpe_functions[num_fpe_types].wakeup_fpe = wakeup_func;
-    fpe_functions[num_fpe_types].list_fonts = list_func;
-    fpe_functions[num_fpe_types].start_list_fonts_with_info = start_lfwi_func;
-    fpe_functions[num_fpe_types].list_next_font_with_info = next_lfwi_func;
-    fpe_functions[num_fpe_types].init_fpe = init_func;
-    fpe_functions[num_fpe_types].free_fpe = free_func;
-    fpe_functions[num_fpe_types].reset_fpe = reset_func;
-    fpe_functions[num_fpe_types].client_died = client_died;
-    fpe_functions[num_fpe_types].load_glyphs = load_glyphs;
-    fpe_functions[num_fpe_types].start_list_fonts_and_aliases =
-        start_list_alias_func;
-    fpe_functions[num_fpe_types].list_next_font_or_alias = next_list_alias_func;
-    fpe_functions[num_fpe_types].set_path_hook = set_path_func;
-
-    return num_fpe_types++;
-}
-
 void
 FreeFonts(void)
 {
     if (patternCache) {
-        FreeFontPatternCache(patternCache);
+        xfont2_free_font_pattern_cache(patternCache);
         patternCache = 0;
     }
     FreeFontPath(font_path_elements, num_fpes, TRUE);
@@ -1911,12 +1877,12 @@ FreeFonts(void)
     num_fpes = 0;
     free(fpe_functions);
     num_fpe_types = 0;
-    fpe_functions = (FPEFunctions *) 0;
+    fpe_functions = NULL;
 }
 
 /* convenience functions for FS interface */
 
-FontPtr
+static FontPtr
 find_old_font(XID id)
 {
     void *pFont;
@@ -1925,30 +1891,26 @@ find_old_font(XID id)
     return (FontPtr) pFont;
 }
 
-_X_EXPORT
-Font
-GetNewFontClientID(void)
+static Font
+get_new_font_client_id(void)
 {
     return FakeClientID(0);
 }
 
-_X_EXPORT
-int
-StoreFontClientFont(FontPtr pfont, Font id)
+static int
+store_font_Client_font(FontPtr pfont, Font id)
 {
     return AddResource(id, RT_NONE, (void *) pfont);
 }
 
-_X_EXPORT
-void
-DeleteFontClientID(Font id)
+static void
+delete_font_client_id(Font id)
 {
     FreeResource(id, RT_NONE);
 }
 
-_X_EXPORT
-int
-client_auth_generation(ClientPtr client)
+static int
+_client_auth_generation(ClientPtr client)
 {
     return 0;
 }
@@ -1956,9 +1918,73 @@ client_auth_generation(ClientPtr client)
 static int fs_handlers_installed = 0;
 static unsigned int last_server_gen;
 
-_X_EXPORT
-int
-init_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr block_handler)
+static void
+fs_block_handler(void *blockData, OSTimePtr timeout, void *readmask)
+{
+    FontBlockHandlerProcPtr block_handler = blockData;
+
+    (*block_handler)(timeout);
+}
+
+struct fs_fd_entry {
+    struct xorg_list            entry;
+    int                         fd;
+    void                        *data;
+    FontFdHandlerProcPtr        handler;
+};
+
+static void
+fs_fd_handler(int fd, int ready, void *data)
+{
+    struct fs_fd_entry    *entry = data;
+
+    entry->handler(fd, entry->data);
+}
+
+static struct xorg_list fs_fd_list;
+
+static int
+add_fs_fd(int fd, FontFdHandlerProcPtr handler, void *data)
+{
+    struct fs_fd_entry  *entry = calloc(1, sizeof (struct fs_fd_entry));
+
+    if (!entry)
+        return FALSE;
+
+    entry->fd = fd;
+    entry->data = data;
+    entry->handler = handler;
+    if (!SetNotifyFd(fd, fs_fd_handler, X_NOTIFY_READ, entry)) {
+        free(entry);
+        return FALSE;
+    }
+    xorg_list_add(&entry->entry, &fs_fd_list);
+    return TRUE;
+}
+
+static void
+remove_fs_fd(int fd)
+{
+    struct fs_fd_entry  *entry, *temp;
+
+    xorg_list_for_each_entry_safe(entry, temp, &fs_fd_list, entry) {
+        if (entry->fd == fd) {
+            xorg_list_del(&entry->entry);
+            free(entry);
+            break;
+        }
+    }
+    RemoveNotifyFd(fd);
+}
+
+static void
+adjust_fs_wait_for_delay(void *wt, unsigned long newdelay)
+{
+    AdjustWaitForDelay(wt, newdelay);
+}
+
+static int
+_init_fs_handlers(FontPathElementPtr fpe, FontBlockHandlerProcPtr block_handler)
 {
     /* if server has reset, make sure the b&w handlers are reinstalled */
     if (last_server_gen < serverGeneration) {
@@ -1966,26 +1992,63 @@ init_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr block_handler)
         fs_handlers_installed = 0;
     }
     if (fs_handlers_installed == 0) {
-        if (!RegisterBlockAndWakeupHandlers(block_handler,
-                                            FontWakeup, (void *) 0))
+        if (!RegisterBlockAndWakeupHandlers(fs_block_handler,
+                                            FontWakeup, (void *) block_handler))
             return AllocError;
+        xorg_list_init(&fs_fd_list);
         fs_handlers_installed++;
     }
     QueueFontWakeup(fpe);
     return Successful;
 }
 
-_X_EXPORT
-void
-remove_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr block_handler,
+static void
+_remove_fs_handlers(FontPathElementPtr fpe, FontBlockHandlerProcPtr block_handler,
                    Bool all)
 {
     if (all) {
         /* remove the handlers if no one else is using them */
         if (--fs_handlers_installed == 0) {
-            RemoveBlockAndWakeupHandlers(block_handler, FontWakeup,
-                                         (void *) 0);
+            RemoveBlockAndWakeupHandlers(fs_block_handler, FontWakeup,
+                                         (void *) block_handler);
         }
     }
     RemoveFontWakeup(fpe);
 }
+
+static const xfont2_client_funcs_rec xfont2_client_funcs = {
+    .version = XFONT2_CLIENT_FUNCS_VERSION,
+    .client_auth_generation = _client_auth_generation,
+    .client_signal = ClientSignal,
+    .delete_font_client_id = delete_font_client_id,
+    .verrorf = VErrorF,
+    .find_old_font = find_old_font,
+    .get_client_resolutions = get_client_resolutions,
+    .get_default_point_size = get_default_point_size,
+    .get_new_font_client_id = get_new_font_client_id,
+    .get_time_in_millis = GetTimeInMillis,
+    .init_fs_handlers = _init_fs_handlers,
+    .register_fpe_funcs = register_fpe_funcs,
+    .remove_fs_handlers = _remove_fs_handlers,
+    .get_server_client = get_server_client,
+    .set_font_authorizations = set_font_authorizations,
+    .store_font_client_font = store_font_Client_font,
+    .make_atom = MakeAtom,
+    .valid_atom = ValidAtom,
+    .name_for_atom = NameForAtom,
+    .get_server_generation = get_server_generation,
+    .add_fs_fd = add_fs_fd,
+    .remove_fs_fd = remove_fs_fd,
+    .adjust_fs_wait_for_delay = adjust_fs_wait_for_delay,
+};
+
+xfont2_pattern_cache_ptr fontPatternCache;
+
+void
+InitFonts(void)
+{
+    if (fontPatternCache)
+	xfont2_free_font_pattern_cache(fontPatternCache);
+    fontPatternCache = xfont2_make_font_pattern_cache();
+    xfont2_init(&xfont2_client_funcs);
+}
diff --git a/dix/main.c b/dix/main.c
index 4ba4313..0fa561e 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -96,7 +96,7 @@ Equipment Corporation.
 #include "selection.h"
 #include <X11/fonts/font.h>
 #include <X11/fonts/fontstruct.h>
-#include <X11/fonts/fontutil.h>
+#include <X11/fonts/libxfont2.h>
 #include "opaque.h"
 #include "servermd.h"
 #include "hotplug.h"
@@ -196,7 +196,7 @@ dix_main(int argc, char *argv[], char *envp[])
 
         InitAtoms();
         InitEvents();
-        InitGlyphCaching();
+        xfont2_init_glyph_caching();
         dixResetRegistry();
         InitFonts();
         InitCallbackManager();
diff --git a/glamor/glamor_font.c b/glamor/glamor_font.c
index 637e0dc..9199a35 100644
--- a/glamor/glamor_font.c
+++ b/glamor/glamor_font.c
@@ -55,7 +55,7 @@ glamor_font_get(ScreenPtr screen, FontPtr font)
         privates = calloc(glamor_font_screen_count, sizeof (glamor_font_t));
         if (!privates)
             return NULL;
-        FontSetPrivate(font, glamor_font_private_index, privates);
+        xfont2_font_set_private(font, glamor_font_private_index, privates);
     }
 
     glamor_font = &privates[screen->myNum];
@@ -201,7 +201,7 @@ glamor_unrealize_font(ScreenPtr screen, FontPtr font)
             return TRUE;
 
     free(privates);
-    FontSetPrivate(font, glamor_font_private_index, NULL);
+    xfont2_font_set_private(font, glamor_font_private_index, NULL);
     return TRUE;
 }
 
@@ -214,7 +214,7 @@ glamor_font_init(ScreenPtr screen)
         return TRUE;
 
     if (glamor_font_generation != serverGeneration) {
-        glamor_font_private_index = AllocateFontPrivateIndex();
+        glamor_font_private_index = xfont2_allocate_font_private_index();
         if (glamor_font_private_index == -1)
             return FALSE;
         glamor_font_screen_count = 0;
diff --git a/hw/dmx/dmxfont.c b/hw/dmx/dmxfont.c
index 25a04a6..addfa6a 100644
--- a/hw/dmx/dmxfont.c
+++ b/hw/dmx/dmxfont.c
@@ -46,6 +46,7 @@
 #include "dmxlog.h"
 
 #include <X11/fonts/fontstruct.h>
+#include <X11/fonts/libxfont2.h>
 #include "dixfont.h"
 #include "dixstruct.h"
 
@@ -447,7 +448,7 @@ dmxRealizeFont(ScreenPtr pScreen, FontPtr pFont)
     dmxFontPrivPtr pFontPriv;
 
     if (!(pFontPriv = FontGetPrivate(pFont, dmxFontPrivateIndex))) {
-        FontSetPrivate(pFont, dmxFontPrivateIndex, NULL);
+        xfont2_font_set_private(pFont, dmxFontPrivateIndex, NULL);
         pFontPriv = malloc(sizeof(dmxFontPrivRec));
         if (!pFontPriv)
             return FALSE;
@@ -460,7 +461,7 @@ dmxRealizeFont(ScreenPtr pScreen, FontPtr pFont)
         pFontPriv->refcnt = 0;
     }
 
-    FontSetPrivate(pFont, dmxFontPrivateIndex, (void *) pFontPriv);
+    xfont2_font_set_private(pFont, dmxFontPrivateIndex, (void *) pFontPriv);
 
     if (dmxScreen->beDisplay) {
         if (!dmxBELoadFont(pScreen, pFont))
@@ -504,7 +505,7 @@ dmxUnrealizeFont(ScreenPtr pScreen, FontPtr pFont)
         if (!pFontPriv->refcnt) {
             MAXSCREENSFREE(pFontPriv->font);
             free(pFontPriv);
-            FontSetPrivate(pFont, dmxFontPrivateIndex, NULL);
+            xfont2_font_set_private(pFont, dmxFontPrivateIndex, NULL);
         }
         else if (pFontPriv->font[pScreen->myNum]) {
             if (dmxScreen->beDisplay)
@@ -563,7 +564,7 @@ dmxUnrealizeFont(ScreenPtr pScreen, FontPtr pFont)
                 ) {
                 MAXSCREENSFREE(pFontPriv->font);
                 free(pFontPriv);
-                FontSetPrivate(pFont, dmxFontPrivateIndex, NULL);
+                xfont2_font_set_private(pFont, dmxFontPrivateIndex, NULL);
             }
         }
     }
diff --git a/hw/dmx/dmxscrinit.c b/hw/dmx/dmxscrinit.c
index 097418d..e441dce 100644
--- a/hw/dmx/dmxscrinit.c
+++ b/hw/dmx/dmxscrinit.c
@@ -58,6 +58,8 @@
 #include "mipointer.h"
 #include "micmap.h"
 
+#include <X11/fonts/libxfont2.h>
+
 extern Bool dmxCloseScreen(ScreenPtr pScreen);
 static Bool dmxSaveScreen(ScreenPtr pScreen, int what);
 
@@ -187,7 +189,7 @@ dmxScreenInit(ScreenPtr pScreen, int argc, char *argv[])
 
     if (dmxGeneration != serverGeneration) {
         /* Allocate font private index */
-        dmxFontPrivateIndex = AllocateFontPrivateIndex();
+        dmxFontPrivateIndex = xfont2_allocate_font_private_index();
         if (dmxFontPrivateIndex == -1)
             return FALSE;
 
diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index 5391b72..cf26892 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -251,7 +251,6 @@ cat > sdksyms.c << EOF
 #define _FONTPROTO_H
 #include "dixfont.h"
 #include "dixfontstr.h"
-#include "dixfontstubs.h"
 #include "dixgrabs.h"
 #include "dixstruct.h"
 #include "exevents.h"
diff --git a/hw/xnest/Font.c b/hw/xnest/Font.c
index ffdfd24..192b80f 100644
--- a/hw/xnest/Font.c
+++ b/hw/xnest/Font.c
@@ -23,6 +23,7 @@ is" without express or implied warranty.
 #include "regionstr.h"
 #include <X11/fonts/font.h>
 #include <X11/fonts/fontstruct.h>
+#include "dixfontstr.h"
 #include "scrnintstr.h"
 
 #include "Xnest.h"
@@ -42,7 +43,7 @@ xnestRealizeFont(ScreenPtr pScreen, FontPtr pFont)
     int i;
     const char *name;
 
-    FontSetPrivate(pFont, xnestFontPrivateIndex, NULL);
+    xfont2_font_set_private(pFont, xnestFontPrivateIndex, NULL);
 
     name_atom = MakeAtom("FONT", 4, True);
     value_atom = 0L;
@@ -65,7 +66,7 @@ xnestRealizeFont(ScreenPtr pScreen, FontPtr pFont)
         return False;
 
     priv = (void *) malloc(sizeof(xnestPrivFont));
-    FontSetPrivate(pFont, xnestFontPrivateIndex, priv);
+    xfont2_font_set_private(pFont, xnestFontPrivateIndex, priv);
 
     xnestFontPriv(pFont)->font_struct = XLoadQueryFont(xnestDisplay, name);
 
@@ -82,7 +83,7 @@ xnestUnrealizeFont(ScreenPtr pScreen, FontPtr pFont)
         if (xnestFontStruct(pFont))
             XFreeFont(xnestDisplay, xnestFontStruct(pFont));
         free(xnestFontPriv(pFont));
-        FontSetPrivate(pFont, xnestFontPrivateIndex, NULL);
+        xfont2_font_set_private(pFont, xnestFontPrivateIndex, NULL);
     }
     return True;
 }
diff --git a/hw/xnest/Init.c b/hw/xnest/Init.c
index d9f490b..bec2c51 100644
--- a/hw/xnest/Init.c
+++ b/hw/xnest/Init.c
@@ -26,6 +26,7 @@ is" without express or implied warranty.
 #include "servermd.h"
 #include "mi.h"
 #include <X11/fonts/fontstruct.h>
+#include "dixfontstr.h"
 
 #include "Xnest.h"
 
@@ -72,7 +73,7 @@ InitOutput(ScreenInfo * screen_info, int argc, char *argv[])
                 break;
             }
 
-    xnestFontPrivateIndex = AllocateFontPrivateIndex();
+    xnestFontPrivateIndex = xfont2_allocate_font_private_index();
 
     if (!xnestNumScreens)
         xnestNumScreens = 1;
diff --git a/include/dixfont.h b/include/dixfont.h
index b44996f..3a38d10 100644
--- a/include/dixfont.h
+++ b/include/dixfont.h
@@ -29,7 +29,6 @@ SOFTWARE.
 #include "closure.h"
 #include <X11/fonts/fontstruct.h>
 #include <X11/fonts/fontproto.h>
-#include <X11/fonts/fontutil.h>
 
 #define NullDIXFontProp ((DIXFontPropPtr)0)
 
@@ -98,16 +97,11 @@ extern _X_EXPORT void InitFonts(void);
 
 extern _X_EXPORT void FreeFonts(void);
 
-extern _X_EXPORT FontPtr find_old_font(XID /*id */ );
-
-#define GetGlyphs dixGetGlyphs
-extern _X_EXPORT void dixGetGlyphs(FontPtr /*font */ ,
-                                   unsigned long /*count */ ,
-                                   unsigned char * /*chars */ ,
-                                   FontEncoding /*fontEncoding */ ,
-                                   unsigned long * /*glyphcount */ ,
-                                   CharInfoPtr * /*glyphs */ );
-
-extern _X_EXPORT void register_fpe_functions(void);
+extern _X_EXPORT void GetGlyphs(FontPtr /*font */ ,
+                                unsigned long /*count */ ,
+                                unsigned char * /*chars */ ,
+                                FontEncoding /*fontEncoding */ ,
+                                unsigned long * /*glyphcount */ ,
+                                CharInfoPtr * /*glyphs */ );
 
 #endif                          /* DIXFONT_H */
diff --git a/include/dixfontstr.h b/include/dixfontstr.h
index ce878d0..7deb84a 100644
--- a/include/dixfontstr.h
+++ b/include/dixfontstr.h
@@ -27,6 +27,7 @@ SOFTWARE.
 #include "servermd.h"
 #include "dixfont.h"
 #include <X11/fonts/fontstruct.h>
+#include <X11/fonts/libxfont2.h>
 #include "closure.h"
 #include <X11/Xproto.h>         /* for xQueryFontReply */
 
diff --git a/include/dixfontstubs.h b/include/dixfontstubs.h
deleted file mode 100644
index 535d312..0000000
--- a/include/dixfontstubs.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef DIXFONTSTUBS_H
-#define DIXFONTSTUBS_H 1
-
-/*
- * libXfont stubs replacements
- * This header exists solely for the purpose of sdksyms generation;
- * source code should #include "dixfonts.h" instead, which pulls in these
- * declarations from <X11/fonts/fontproto.h>
- */
-extern _X_EXPORT int client_auth_generation(ClientPtr client);
-
-extern _X_EXPORT void DeleteFontClientID(Font id);
-
-extern _X_EXPORT int GetDefaultPointSize(void);
-
-extern _X_EXPORT Font GetNewFontClientID(void);
-
-extern _X_EXPORT int init_fs_handlers(FontPathElementPtr fpe,
-                                      BlockHandlerProcPtr block_handler);
-
-extern _X_EXPORT int RegisterFPEFunctions(NameCheckFunc name_func,
-                                          InitFpeFunc init_func,
-                                          FreeFpeFunc free_func,
-                                          ResetFpeFunc reset_func,
-                                          OpenFontFunc open_func,
-                                          CloseFontFunc close_func,
-                                          ListFontsFunc list_func,
-                                          StartLfwiFunc start_lfwi_func,
-                                          NextLfwiFunc next_lfwi_func,
-                                          WakeupFpeFunc wakeup_func,
-                                          ClientDiedFunc client_died,
-                                          LoadGlyphsFunc load_glyphs,
-                                          StartLaFunc start_list_alias_func,
-                                          NextLaFunc next_list_alias_func,
-                                          SetPathFunc set_path_func);
-
-extern _X_EXPORT void remove_fs_handlers(FontPathElementPtr fpe,
-                                         BlockHandlerProcPtr blockHandler,
-                                         Bool all);
-
-extern _X_EXPORT int StoreFontClientFont(FontPtr pfont, Font id);
-
-#endif
diff --git a/mi/miglblt.c b/mi/miglblt.c
index 46268ae..68be5b9 100644
--- a/mi/miglblt.c
+++ b/mi/miglblt.c
@@ -53,7 +53,7 @@ SOFTWARE.
 #include	<X11/Xproto.h>
 #include	"misc.h"
 #include	<X11/fonts/fontstruct.h>
-#include	<X11/fonts/fontutil.h>
+#include        <X11/fonts/libxfont2.h>
 #include	"dixfontstr.h"
 #include	"gcstruct.h"
 #include	"windowstr.h"
@@ -186,13 +186,13 @@ miImageGlyphBlt(DrawablePtr pDrawable, GC * pGC, int x, int y, unsigned int ngly
                 void *pglyphBase      /* start of array of glyphs */
     )
 {
-    ExtentInfoRec info;         /* used by QueryGlyphExtents() */
+    ExtentInfoRec info;         /* used by xfont2_query_glyph_extents() */
     ChangeGCVal gcvals[3];
     int oldAlu, oldFS;
     unsigned long oldFG;
     xRectangle backrect;
 
-    QueryGlyphExtents(pGC->font, ppci, (unsigned long) nglyph, &info);
+    xfont2_query_glyph_extents(pGC->font, ppci, (unsigned long) nglyph, &info);
 
     if (info.overallWidth >= 0) {
         backrect.x = x;
diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index ce1cd32..17c2abf 100644
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -32,7 +32,7 @@
 #include    <X11/fonts/font.h>
 #include    "dixfontstr.h"
 #include    <X11/fonts/fontstruct.h>
-#include    <X11/fonts/fontutil.h>
+#include    <X11/fonts/libxfont2.h>
 #include    "mi.h"
 #include    "regionstr.h"
 #include    "globals.h"
@@ -1249,7 +1249,7 @@ damageDamageChars(DrawablePtr pDrawable,
     ExtentInfoRec extents;
     BoxRec box;
 
-    QueryGlyphExtents(font, charinfo, n, &extents);
+    xfont2_query_glyph_extents(font, charinfo, n, &extents);
     if (imageblt) {
         if (extents.overallWidth > extents.overallRight)
             extents.overallRight = extents.overallWidth;
diff --git a/os/utils.c b/os/utils.c
index 5871ef8..a58603d 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -80,7 +80,7 @@ __stdcall unsigned long GetTickCount(void);
 #include <X11/Xtrans/Xtrans.h>
 #include "input.h"
 #include "dixfont.h"
-#include <X11/fonts/fontutil.h>
+#include <X11/fonts/libxfont2.h>
 #include "osdep.h"
 #include "extension.h"
 #ifdef X_POSIX_C_SOURCE
@@ -798,7 +798,7 @@ ProcessCommandLine(int argc, char *argv[])
             DPMSDisabledSwitch = TRUE;
 #endif
         else if (strcmp(argv[i], "-deferglyphs") == 0) {
-            if (++i >= argc || !ParseGlyphCachingMode(argv[i]))
+            if (++i >= argc || !xfont2_parse_glyph_caching_mode(argv[i]))
                 UseMsg();
         }
         else if (strcmp(argv[i], "-f") == 0) {


More information about the xorg-commit mailing list