summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2012-03-12 16:36:31 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2012-03-22 13:12:56 +1000
commitd645edd11e7482f98c8b7e0d6c8693285c484907 (patch)
treea70bc2534b0f26f64a580cfd7f7fa630eb9383bc
parent6aef209ebc2e54f5465da505a780f7b4cc273ee0 (diff)
Xext: Add per-device SyncCounters
Previously, we only had one idle alarm that was triggered for all devices, whenever the user used any device, came back from suspend, etc. Add system SyncCounters for each device (named "DEVICEIDLETIME x", with x being the device id) that trigger on that device only. This allows for enabling/disabling devices based on interaction with other devices. Popular use-case: disable the touchpad when the keyboard just above the touchpad stops being idle. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com> Reviewed-by: Jamey Sharp <jamey@minilop.net> Reviewed-by: James Jones <jajones@nvidia.com>
-rw-r--r--Xext/sync.c48
-rw-r--r--Xext/syncsrv.h3
-rw-r--r--dix/devices.c8
-rw-r--r--include/inputstr.h2
4 files changed, 56 insertions, 5 deletions
diff --git a/Xext/sync.c b/Xext/sync.c
index 8217e7662..91968e498 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -69,6 +69,7 @@ PERFORMANCE OF THIS SOFTWARE.
#include "syncsrv.h"
#include "syncsdk.h"
#include "protocol-versions.h"
+#include "inputstr.h"
#include <stdio.h>
#if !defined(WIN32)
@@ -2594,13 +2595,23 @@ SyncInitServerTime(void)
typedef struct {
XSyncValue *value_less;
XSyncValue *value_greater;
+ int deviceid;
} IdleCounterPriv;
static void
IdleTimeQueryValue(pointer pCounter, CARD64 * pValue_return)
{
- CARD32 idle = GetTimeInMillis() - lastDeviceEventTime[XIAllDevices].milliseconds;
+ int deviceid;
+ CARD32 idle;
+ if (pCounter) {
+ SyncCounter *counter = pCounter;
+ IdleCounterPriv *priv = SysCounterGetPrivate(counter);
+ deviceid = priv->deviceid;
+ }
+ else
+ deviceid = XIAllDevices;
+ idle = GetTimeInMillis() - lastDeviceEventTime[deviceid].milliseconds;
XSyncIntsToValue(pValue_return, idle, 0);
}
@@ -2692,7 +2703,7 @@ IdleTimeWakeupHandler(pointer pCounter, int rc, pointer LastSelectMask)
if (!less && !greater)
return;
- IdleTimeQueryValue(NULL, &idle);
+ IdleTimeQueryValue(pCounter, &idle);
if ((greater && XSyncValueGreaterOrEqual(idle, *greater)) ||
(less && XSyncValueLessOrEqual(idle, *less))) {
@@ -2723,8 +2734,8 @@ IdleTimeBracketValues(pointer pCounter, CARD64 * pbracket_less,
priv->value_less = pbracket_less;
}
-static void
-SyncInitIdleTime(void)
+static SyncCounter*
+init_system_idle_counter(const char *name, int deviceid)
{
CARD64 resolution;
XSyncValue idle;
@@ -2734,12 +2745,39 @@ SyncInitIdleTime(void)
IdleTimeQueryValue(NULL, &idle);
XSyncIntToValue(&resolution, 4);
- idle_time_counter = SyncCreateSystemCounter("IDLETIME", idle, resolution,
+ idle_time_counter = SyncCreateSystemCounter(name, idle, resolution,
XSyncCounterUnrestricted,
IdleTimeQueryValue,
IdleTimeBracketValues);
+ priv->deviceid = deviceid;
priv->value_less = priv->value_greater = NULL;
idle_time_counter->pSysCounterInfo->private = priv;
+
+ return idle_time_counter;
+}
+
+static void
+SyncInitIdleTime(void)
+{
+ init_system_idle_counter("IDLETIME", XIAllDevices);
+}
+
+SyncCounter*
+SyncInitDeviceIdleTime(DeviceIntPtr dev)
+{
+ char timer_name[64];
+ sprintf(timer_name, "DEVICEIDLETIME %d", dev->id);
+
+ return init_system_idle_counter(timer_name, dev->id);
+}
+
+void SyncRemoveDeviceIdleTime(SyncCounter *counter)
+{
+ /* FreeAllResources() frees all system counters before the devices are
+ shut down, check if there are any left before freeing the device's
+ counter */
+ if (!xorg_list_is_empty(&SysCounterList))
+ xorg_list_del(&counter->pSysCounterInfo->entry);
}
diff --git a/Xext/syncsrv.h b/Xext/syncsrv.h
index d29c361cc..dbed476f2 100644
--- a/Xext/syncsrv.h
+++ b/Xext/syncsrv.h
@@ -135,4 +135,7 @@ extern void SyncChangeCounter(SyncCounter *pCounter,
extern void SyncDestroySystemCounter(pointer pCounter);
extern void SyncExtensionInit(void);
+
+extern SyncCounter *SyncInitDeviceIdleTime(DeviceIntPtr dev);
+extern void SyncRemoveDeviceIdleTime(SyncCounter *counter);
#endif /* _SYNCSRV_H_ */
diff --git a/dix/devices.c b/dix/devices.c
index 012550443..600f8b738 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -84,6 +84,7 @@ SOFTWARE.
#include "enterleave.h" /* for EnterWindow() */
#include "xserver-properties.h"
#include "xichangehierarchy.h" /* For XISendDeviceHierarchyEvent */
+#include "syncsrv.h"
/** @file
* This file handles input device-related stuff.
@@ -406,9 +407,13 @@ EnableDevice(DeviceIntPtr dev, BOOL sendevent)
RecalculateMasterButtons(dev);
+ /* initialise an idle timer for this device*/
+ dev->idle_counter = SyncInitDeviceIdleTime(dev);
+
return TRUE;
}
+
/**
* Switch a device off through the driver and push it onto the off_devices
* list. A device will not send events while disabled. All clients are
@@ -432,6 +437,9 @@ DisableDevice(DeviceIntPtr dev, BOOL sendevent)
if (*prev != dev)
return FALSE;
+ SyncRemoveDeviceIdleTime(dev->idle_counter);
+ dev->idle_counter = NULL;
+
/* float attached devices */
if (IsMaster(dev)) {
for (other = inputInfo.devices; other; other = other->next) {
diff --git a/include/inputstr.h b/include/inputstr.h
index 841e8052b..5a38924de 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -591,6 +591,8 @@ typedef struct _DeviceIntRec {
/* XTest related master device id */
int xtest_master_id;
+
+ struct _SyncCounter *idle_counter;
} DeviceIntRec;
typedef struct {