From bf83843b92ce21d11f6ff1a407ff3d014e017c9b Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Thu, 19 Dec 2013 14:10:18 +0100 Subject: [PATCH] xf86Events: add Enable/DisableInputDeviceForVTSwitch functions Factor this code out into functions so that it can be re-used for the systemd-logind device pause/resume paths. Signed-off-by: Hans de Goede Reviewed-by: Peter Hutterer --- hw/xfree86/common/xf86.h | 4 +++ hw/xfree86/common/xf86Events.c | 52 ++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h index 537d1d12a..cec31354e 100644 --- a/hw/xfree86/common/xf86.h +++ b/hw/xfree86/common/xf86.h @@ -215,6 +215,8 @@ extern _X_EXPORT xf86SetDGAModeProc xf86SetDGAMode; /* xf86Events.c */ +typedef struct _InputInfoRec *InputInfoPtr; + extern _X_EXPORT void SetTimeSinceLastInputEvent(void); extern _X_EXPORT void *xf86AddInputHandler(int fd, InputHandlerProc proc, void *data); @@ -236,6 +238,8 @@ extern _X_EXPORT void xf86PrintBacktrace(void); extern _X_EXPORT Bool xf86VTOwner(void); extern _X_EXPORT void xf86VTLeave(void); extern _X_EXPORT void xf86VTEnter(void); +extern _X_EXPORT void xf86EnableInputDeviceForVTSwitch(InputInfoPtr pInfo); +extern _X_EXPORT void xf86DisableInputDeviceForVTSwitch(InputInfoPtr pInfo); /* xf86Helper.c */ diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c index e0ec76825..7b53949fa 100644 --- a/hw/xfree86/common/xf86Events.c +++ b/hw/xfree86/common/xf86Events.c @@ -407,6 +407,28 @@ xf86ReleaseKeys(DeviceIntPtr pDev) } } +void +xf86DisableInputDeviceForVTSwitch(InputInfoPtr pInfo) +{ + if (!pInfo->dev) + return; + + if (!pInfo->dev->enabled) + pInfo->flags |= XI86_DEVICE_DISABLED; + + xf86ReleaseKeys(pInfo->dev); + ProcessInputEvents(); + DisableDevice(pInfo->dev, TRUE); +} + +void +xf86EnableInputDeviceForVTSwitch(InputInfoPtr pInfo) +{ + if (pInfo->dev && (pInfo->flags & XI86_DEVICE_DISABLED) == 0) + EnableDevice(pInfo->dev, TRUE); + pInfo->flags &= ~XI86_DEVICE_DISABLED; +} + void xf86VTLeave(void) { @@ -436,15 +458,8 @@ xf86VTLeave(void) else xf86DisableGeneralHandler(ih); } - for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) { - if (pInfo->dev) { - if (!pInfo->dev->enabled) - pInfo->flags |= XI86_DEVICE_DISABLED; - xf86ReleaseKeys(pInfo->dev); - ProcessInputEvents(); - DisableDevice(pInfo->dev, TRUE); - } - } + for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) + xf86DisableInputDeviceForVTSwitch(pInfo); OsBlockSIGIO(); for (i = 0; i < xf86NumScreens; i++) @@ -494,13 +509,8 @@ switch_failed: } dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); - pInfo = xf86InputDevs; - while (pInfo) { - if (pInfo->dev && (pInfo->flags & XI86_DEVICE_DISABLED) == 0) - EnableDevice(pInfo->dev, TRUE); - pInfo->flags &= ~XI86_DEVICE_DISABLED; - pInfo = pInfo->next; - } + for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) + xf86EnableInputDeviceForVTSwitch(pInfo); for (ih = InputHandlers; ih; ih = ih->next) { if (ih->is_input) xf86EnableInputHandler(ih); @@ -546,14 +556,8 @@ xf86VTEnter(void) /* Turn screen saver off when switching back */ dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); - pInfo = xf86InputDevs; - while (pInfo) { - if (pInfo->dev && (pInfo->flags & XI86_DEVICE_DISABLED) == 0) - EnableDevice(pInfo->dev, TRUE); - pInfo->flags &= ~XI86_DEVICE_DISABLED; - pInfo = pInfo->next; - } - + for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) + xf86EnableInputDeviceForVTSwitch(pInfo); for (ih = InputHandlers; ih; ih = ih->next) { if (ih->is_input) xf86EnableInputHandler(ih);