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>
This commit is contained in:
parent
6aef209ebc
commit
d645edd11e
48
Xext/sync.c
48
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);
|
||||
}
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -591,6 +591,8 @@ typedef struct _DeviceIntRec {
|
|||
|
||||
/* XTest related master device id */
|
||||
int xtest_master_id;
|
||||
|
||||
struct _SyncCounter *idle_counter;
|
||||
} DeviceIntRec;
|
||||
|
||||
typedef struct {
|
||||
|
|
Loading…
Reference in New Issue