diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h index 458750007..51125304e 100644 --- a/hw/xfree86/common/xf86.h +++ b/hw/xfree86/common/xf86.h @@ -222,6 +222,10 @@ pointer xf86AddInputHandler(int fd, InputHandlerProc proc, pointer data); int xf86RemoveInputHandler(pointer handler); void xf86DisableInputHandler(pointer handler); void xf86EnableInputHandler(pointer handler); +pointer xf86AddGeneralHandler(int fd, InputHandlerProc proc, pointer data); +int xf86RemoveGeneralHandler(pointer handler); +void xf86DisableGeneralHandler(pointer handler); +void xf86EnableGeneralHandler(pointer handler); void xf86InterceptSignals(int *signo); void xf86InterceptSigIll(void (*sigillhandler)(void)); Bool xf86EnableVTSwitch(Bool new); diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c index 831c68ad8..b1ee1e93e 100644 --- a/hw/xfree86/common/xf86Events.c +++ b/hw/xfree86/common/xf86Events.c @@ -1636,8 +1636,8 @@ xf86VTSwitch() /* Input handler registration */ -_X_EXPORT pointer -xf86AddInputHandler(int fd, InputHandlerProc proc, pointer data) +static pointer +addInputHandler(int fd, InputHandlerProc proc, pointer data) { IHPtr ih; @@ -1656,25 +1656,33 @@ xf86AddInputHandler(int fd, InputHandlerProc proc, pointer data) ih->next = InputHandlers; InputHandlers = ih; - AddEnabledDevice(fd); - return ih; } -_X_EXPORT int -xf86RemoveInputHandler(pointer handler) -{ - IHPtr ih, p; - int fd; - - if (!handler) - return -1; +_X_EXPORT pointer +xf86AddInputHandler(int fd, InputHandlerProc proc, pointer data) +{ + IHPtr ih = addInputHandler(fd, proc, data); - ih = handler; - fd = ih->fd; - - if (ih->fd >= 0) - RemoveEnabledDevice(ih->fd); + if (ih) + AddEnabledDevice(fd); + return ih; +} + +_X_EXPORT 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; @@ -1686,6 +1694,43 @@ xf86RemoveInputHandler(pointer handler) p->next = ih->next; } xfree(ih); +} + +_X_EXPORT 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; +} + +_X_EXPORT 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; } @@ -1703,6 +1748,20 @@ xf86DisableInputHandler(pointer handler) RemoveEnabledDevice(ih->fd); } +_X_EXPORT void +xf86DisableGeneralHandler(pointer handler) +{ + IHPtr ih; + + if (!handler) + return; + + ih = handler; + ih->enabled = FALSE; + if (ih->fd >= 0) + RemoveGeneralSocket(ih->fd); +} + _X_EXPORT void xf86EnableInputHandler(pointer handler) { @@ -1717,6 +1776,20 @@ xf86EnableInputHandler(pointer handler) AddEnabledDevice(ih->fd); } +_X_EXPORT void +xf86EnableGeneralHandler(pointer handler) +{ + IHPtr ih; + + if (!handler) + return; + + ih = handler; + ih->enabled = TRUE; + if (ih->fd >= 0) + AddGeneralSocket(ih->fd); +} + /* * As used currently by the DRI, the return value is ignored. */ diff --git a/hw/xfree86/os-support/linux/lnx_acpi.c b/hw/xfree86/os-support/linux/lnx_acpi.c index eca76dbf3..aa30e72c2 100644 --- a/hw/xfree86/os-support/linux/lnx_acpi.c +++ b/hw/xfree86/os-support/linux/lnx_acpi.c @@ -163,7 +163,7 @@ lnxACPIOpen(void) xf86PMGetEventFromOs = lnxACPIGetEventFromOs; xf86PMConfirmEventToOs = lnxACPIConfirmEventToOs; - ACPIihPtr = xf86AddInputHandler(fd,xf86HandlePMEvents,NULL); + ACPIihPtr = xf86AddGeneralHandler(fd,xf86HandlePMEvents,NULL); xf86MsgVerb(X_INFO,3,"Open ACPI successful (%s)\n", ACPI_SOCKET); return lnxCloseACPI; @@ -178,7 +178,7 @@ lnxCloseACPI(void) ErrorF("ACPI: Closing device\n"); #endif if (ACPIihPtr) { - fd = xf86RemoveInputHandler(ACPIihPtr); + fd = xf86RemoveGeneralHandler(ACPIihPtr); shutdown(fd, 2); close(fd); ACPIihPtr = NULL; diff --git a/include/os.h b/include/os.h index 4c4967164..fbe1592a1 100644 --- a/include/os.h +++ b/include/os.h @@ -147,6 +147,10 @@ extern void CheckConnections(void); extern void CloseDownConnection(ClientPtr /*client*/); +extern void AddGeneralSocket(int /*fd*/); + +extern void RemoveGeneralSocket(int /*fd*/); + extern void AddEnabledDevice(int /*fd*/); extern void RemoveEnabledDevice(int /*fd*/); diff --git a/os/connection.c b/os/connection.c index 6ca4010e2..daad2ac8a 100644 --- a/os/connection.c +++ b/os/connection.c @@ -1047,22 +1047,34 @@ CloseDownConnection(ClientPtr client) AuditF("client %d disconnected\n", client->index); } +_X_EXPORT void +AddGeneralSocket(int fd) +{ + FD_SET(fd, &AllSockets); + if (GrabInProgress) + FD_SET(fd, &SavedAllSockets); +} + _X_EXPORT void AddEnabledDevice(int fd) { FD_SET(fd, &EnabledDevices); - FD_SET(fd, &AllSockets); + AddGeneralSocket(fd); +} + +_X_EXPORT void +RemoveGeneralSocket(int fd) +{ + FD_CLR(fd, &AllSockets); if (GrabInProgress) - FD_SET(fd, &SavedAllSockets); + FD_CLR(fd, &SavedAllSockets); } _X_EXPORT void RemoveEnabledDevice(int fd) { FD_CLR(fd, &EnabledDevices); - FD_CLR(fd, &AllSockets); - if (GrabInProgress) - FD_CLR(fd, &SavedAllSockets); + RemoveGeneralSocket(fd); } /*****************