[PATCH 3/3] dix: ddx: Lift input handling duties from xf86 to dix

Fernando Carrijo fcarrijo.lists at gmail.com
Tue Aug 31 12:00:14 PDT 2010


From: Fernando Carrijo <fcarrijo at freedesktop.org>

Signed-off-by: Fernando Carrijo <fcarrijo at freedesktop.org>
Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
---
 dix/inputhandler.c             |  109 ++++++++++++++++++++++++++++++++++--
 hw/xfree86/common/xf86Events.c |  122 +++-------------------------------------
 2 files changed, 112 insertions(+), 119 deletions(-)

diff --git a/dix/inputhandler.c b/dix/inputhandler.c
index b6dd9e9..57fba05 100644
--- a/dix/inputhandler.c
+++ b/dix/inputhandler.c
@@ -5,54 +5,153 @@ IHPtr InputHandlers = NULL;
 static pointer
 addInputHandler(int fd, InputHandlerProc proc, pointer data)
 {
-    return NULL;
+    IHPtr ih;
+
+    if (fd < 0 || !proc)
+	return NULL;
+
+    ih = calloc(sizeof(*ih), 1);
+    if (!ih)
+	return NULL;
+
+    ih->fd = fd;
+    ih->ihproc = proc;
+    ih->data = data;
+    ih->enabled = TRUE;
+
+    ih->next = InputHandlers;
+    InputHandlers = ih;
+
+    return ih;
 }
 
 pointer
 AddInputHandler(int fd, InputHandlerProc proc, pointer data)
 {
-    return NULL;
+    IHPtr ih = addInputHandler(fd, proc, data);
+
+    if (ih)
+        AddEnabledDevice(fd);
+    return ih;
 }
 
 pointer
 AddGeneralHandler(int fd, InputHandlerProc proc, pointer data)
 {
-    return NULL;
+    IHPtr ih = addInputHandler(fd, proc, data);
+
+    if (ih)
+        AddGeneralSocket(fd);
+    return ih;
 }
 
 static void
 removeInputHandler(IHPtr ih)
 {
+    IHPtr p;
+
+    if (ih == InputHandlers)
+	InputHandlers = ih->next;
+    else {
+	p = InputHandlers;
+	while (p && p->next != ih)
+	    p = p->next;
+	if (ih)
+	    p->next = ih->next;
+    }
+    free(ih);
 }
 
 int
 RemoveInputHandler(pointer handler)
 {
-    return 0;
+    IHPtr ih;
+    int fd;
+
+    if (!handler)
+	return -1;
+
+    ih = handler;
+    fd = ih->fd;
+
+    if (ih->fd >= 0)
+	RemoveEnabledDevice(ih->fd);
+    removeInputHandler(ih);
+
+    return fd;
 }
 
 int
 RemoveGeneralHandler(pointer handler)
 {
-    return 0;
+    IHPtr ih;
+    int fd;
+
+    if (!handler)
+	return -1;
+
+    ih = handler;
+    fd = ih->fd;
+
+    if (ih->fd >= 0)
+	RemoveGeneralSocket(ih->fd);
+    removeInputHandler(ih);
+
+    return fd;
 }
 
 void
 DisableInputHandler(pointer handler)
 {
+    IHPtr ih;
+
+    if (!handler)
+	return;
+
+    ih = handler;
+    ih->enabled = FALSE;
+    if (ih->fd >= 0)
+	RemoveEnabledDevice(ih->fd);
 }
 
 void
 DisableGeneralHandler(pointer handler)
 {
+    IHPtr ih;
+
+    if (!handler)
+	return;
+
+    ih = handler;
+    ih->enabled = FALSE;
+    if (ih->fd >= 0)
+	RemoveGeneralSocket(ih->fd);
 }
 
 void
 EnableInputHandler(pointer handler)
 {
+    IHPtr ih;
+
+    if (!handler)
+	return;
+
+    ih = handler;
+    ih->enabled = TRUE;
+    if (ih->fd >= 0)
+	AddEnabledDevice(ih->fd);
 }
 
 void
 EnableGeneralHandler(pointer handler)
 {
+    IHPtr ih;
+
+    if (!handler)
+	return;
+
+    ih = handler;
+    ih->enabled = TRUE;
+    if (ih->fd >= 0)
+	AddGeneralSocket(ih->fd);
 }
diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index c7d97cb..d939dcb 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -559,158 +559,52 @@ xf86VTSwitch(void)
 
 /* Input handler registration */
 
-static pointer
-addInputHandler(int fd, InputHandlerProc proc, pointer data)
-{
-    IHPtr ih;
-
-    if (fd < 0 || !proc)
-	return NULL;
-
-    ih = calloc(sizeof(*ih), 1);
-    if (!ih)
-	return NULL;
-
-    ih->fd = fd;
-    ih->ihproc = proc;
-    ih->data = data;
-    ih->enabled = TRUE;
-
-    ih->next = InputHandlers;
-    InputHandlers = ih;
-
-    return ih;
-}
-
 pointer
 xf86AddInputHandler(int fd, InputHandlerProc proc, pointer data)
 {
-    IHPtr ih = addInputHandler(fd, proc, data);
-
-    if (ih)
-        AddEnabledDevice(fd);
-    return ih;
+    return AddInputHandler(fd, proc, data);
 }
 
 pointer
 xf86AddGeneralHandler(int fd, InputHandlerProc proc, pointer data)
 {
-    IHPtr ih = addInputHandler(fd, proc, data);
-
-    if (ih)
-        AddGeneralSocket(fd);
-    return ih;
-}
-
-static void
-removeInputHandler(IHPtr ih)
-{
-    IHPtr p;
-
-    if (ih == InputHandlers)
-	InputHandlers = ih->next;
-    else {
-	p = InputHandlers;
-	while (p && p->next != ih)
-	    p = p->next;
-	if (ih)
-	    p->next = ih->next;
-    }
-    free(ih);
+    return AddGeneralHandler(fd, proc, data);
 }
 
 int
 xf86RemoveInputHandler(pointer handler)
 {
-    IHPtr ih;
-    int fd;
-
-    if (!handler)
-	return -1;
-
-    ih = handler;
-    fd = ih->fd;
-
-    if (ih->fd >= 0)
-	RemoveEnabledDevice(ih->fd);
-    removeInputHandler(ih);
-
-    return fd;
+    return RemoveInputHandler(handler);
 }
 
 int
 xf86RemoveGeneralHandler(pointer handler)
 {
-    IHPtr ih;
-    int fd;
-
-    if (!handler)
-	return -1;
-
-    ih = handler;
-    fd = ih->fd;
-
-    if (ih->fd >= 0)
-	RemoveGeneralSocket(ih->fd);
-    removeInputHandler(ih);
-
-    return fd;
+    return RemoveGeneralHandler(handler);
 }
 
 void
 xf86DisableInputHandler(pointer handler)
 {
-    IHPtr ih;
-
-    if (!handler)
-	return;
-
-    ih = handler;
-    ih->enabled = FALSE;
-    if (ih->fd >= 0)
-	RemoveEnabledDevice(ih->fd);
+    return DisableInputHandler(handler);
 }
 
 void
 xf86DisableGeneralHandler(pointer handler)
 {
-    IHPtr ih;
-
-    if (!handler)
-	return;
-
-    ih = handler;
-    ih->enabled = FALSE;
-    if (ih->fd >= 0)
-	RemoveGeneralSocket(ih->fd);
+    return DisableGeneralHandler(handler);
 }
 
 void
 xf86EnableInputHandler(pointer handler)
 {
-    IHPtr ih;
-
-    if (!handler)
-	return;
-
-    ih = handler;
-    ih->enabled = TRUE;
-    if (ih->fd >= 0)
-	AddEnabledDevice(ih->fd);
+    return EnableInputHandler(handler);
 }
 
 void
 xf86EnableGeneralHandler(pointer handler)
 {
-    IHPtr ih;
-
-    if (!handler)
-	return;
-
-    ih = handler;
-    ih->enabled = TRUE;
-    if (ih->fd >= 0)
-	AddGeneralSocket(ih->fd);
+    return EnableGeneralHandler(handler);
 }
 
 /*
-- 
1.7.0.4



More information about the xorg-devel mailing list