diff options
author | Ulrich Sibiller <uli42@gmx.de> | 2017-10-21 01:47:40 +0200 |
---|---|---|
committer | Mihai Moldovan <ionic@ionic.de> | 2018-02-07 23:15:57 +0100 |
commit | 4ab18725cd088cbb401ef63e93ef41d8d7c78b2a (patch) | |
tree | d55148c500dde99d2f178e23466af8d18d72e4ee /nx-X11/programs/Xserver/Xext | |
parent | cbdae3b71bfc654cfc0c81b1ddf51975bcb93146 (diff) | |
download | nx-libs-4ab18725cd088cbb401ef63e93ef41d8d7c78b2a.tar.gz nx-libs-4ab18725cd088cbb401ef63e93ef41d8d7c78b2a.tar.bz2 nx-libs-4ab18725cd088cbb401ef63e93ef41d8d7c78b2a.zip |
Xext: lift screensaver extension to XORG-7_1 state
Diffstat (limited to 'nx-X11/programs/Xserver/Xext')
-rw-r--r-- | nx-X11/programs/Xserver/Xext/saver.c | 149 |
1 files changed, 147 insertions, 2 deletions
diff --git a/nx-X11/programs/Xserver/Xext/saver.c b/nx-X11/programs/Xserver/Xext/saver.c index 066dffed0..0b79a002b 100644 --- a/nx-X11/programs/Xserver/Xext/saver.c +++ b/nx-X11/programs/Xserver/Xext/saver.c @@ -51,7 +51,10 @@ in this Software without prior written authorization from the X Consortium. #include "panoramiX.h" #include "panoramiXsrv.h" #endif - +#ifdef DPMSExtension +#define DPMS_SERVER +#include <nx-X11/extensions/dpms.h> +#endif #include <stdio.h> @@ -68,12 +71,14 @@ static DISPATCH_PROC(ProcScreenSaverQueryVersion); static DISPATCH_PROC(ProcScreenSaverSelectInput); static DISPATCH_PROC(ProcScreenSaverSetAttributes); static DISPATCH_PROC(ProcScreenSaverUnsetAttributes); +static DISPATCH_PROC(ProcScreenSaverSuspend); static DISPATCH_PROC(SProcScreenSaverDispatch); static DISPATCH_PROC(SProcScreenSaverQueryInfo); static DISPATCH_PROC(SProcScreenSaverQueryVersion); static DISPATCH_PROC(SProcScreenSaverSelectInput); static DISPATCH_PROC(SProcScreenSaverSetAttributes); static DISPATCH_PROC(SProcScreenSaverUnsetAttributes); +static DISPATCH_PROC(SProcScreenSaverSuspend); static Bool ScreenSaverHandle ( ScreenPtr /* pScreen */, @@ -110,6 +115,32 @@ static void ScreenSaverResetProc ( ExtensionEntry * /* extEntry */ ); +static RESTYPE SuspendType; /* resource type for suspension records */ + +typedef struct _ScreenSaverSuspension *ScreenSaverSuspensionPtr; + +/* List of clients that are suspending the screensaver. */ +static ScreenSaverSuspensionPtr suspendingClients = NULL; + +/* + * clientResource is a resource ID that's added when the record is + * allocated, so the record is freed and the screensaver resumed when + * the client disconnects. count is the number of times the client has + * requested the screensaver be suspended. + */ +typedef struct _ScreenSaverSuspension +{ + ScreenSaverSuspensionPtr next; + ClientPtr pClient; + XID clientResource; + int count; +} ScreenSaverSuspensionRec; + +static int ScreenSaverFreeSuspend( + pointer /*value */, + XID /* id */ +); + /* * each screen has a list of clients requesting * ScreenSaverNotify events. Each client has a resource @@ -227,13 +258,15 @@ ScreenSaverExtensionInit(void) AttrType = CreateNewResourceType(ScreenSaverFreeAttr); EventType = CreateNewResourceType(ScreenSaverFreeEvents); + SuspendType = CreateNewResourceType(ScreenSaverFreeSuspend); ScreenPrivateIndex = AllocateScreenPrivateIndex (); + for (i = 0; i < screenInfo.numScreens; i++) { pScreen = screenInfo.screens[i]; SetScreenPrivate (pScreen, NULL); } - if (AttrType && EventType && ScreenPrivateIndex != -1 && + if (AttrType && EventType && SuspendType && ScreenPrivateIndex != -1 && (extEntry = AddExtension(ScreenSaverName, ScreenSaverNumberEvents, 0, ProcScreenSaverDispatch, SProcScreenSaverDispatch, ScreenSaverResetProc, StandardMinorOpcode))) @@ -427,6 +460,45 @@ ScreenSaverFreeAttr (value, id) return TRUE; } +static int +ScreenSaverFreeSuspend (pointer value, XID id) +{ + ScreenSaverSuspensionPtr data = (ScreenSaverSuspensionPtr) value; + ScreenSaverSuspensionPtr *prev, this; + + /* Unlink and free the suspension record for the client */ + for (prev = &suspendingClients; (this = *prev); prev = &this->next) + { + if (this == data) + { + *prev = this->next; + free (this); + break; + } + } + + /* Reenable the screensaver if this was the last client suspending it. */ + if (screenSaverSuspended && suspendingClients == NULL) + { + screenSaverSuspended = FALSE; + + /* The screensaver could be active, since suspending it (by design) + doesn't prevent it from being forceably activated */ +#ifdef DPMSExtension + if (screenIsSaved != SCREEN_SAVER_ON && DPMSPowerLevel == DPMSModeOn) +#else + if (screenIsSaved != SCREEN_SAVER_ON) +#endif + { + UpdateCurrentTimeIf(); + lastDeviceEventTime = currentTime; + SetScreenSaverTimer(); + } + } + + return Success; +} + static void SendScreenSaverNotify (pScreen, state, forced) ScreenPtr pScreen; @@ -1286,12 +1358,73 @@ ProcScreenSaverUnsetAttributes (ClientPtr client) return ScreenSaverUnsetAttributes(client); } +static int +ProcScreenSaverSuspend (ClientPtr client) +{ + ScreenSaverSuspensionPtr *prev, this; + + REQUEST(xScreenSaverSuspendReq); + REQUEST_SIZE_MATCH(xScreenSaverSuspendReq); + + /* Check if this client is suspending the screensaver */ + for (prev = &suspendingClients; (this = *prev); prev = &this->next) + if (this->pClient == client) + break; + + if (this) + { + if (stuff->suspend == TRUE) + this->count++; + else if (--this->count == 0) + FreeResource (this->clientResource, RT_NONE); + + return Success; + } + + /* If we get to this point, this client isn't suspending the screensaver */ + if (stuff->suspend == FALSE) + return Success; + + /* + * Allocate a suspension record for the client, and stop the screensaver + * if it isn't already suspended by another client. We attach a resource ID + * to the record, so the screensaver will be reenabled and the record freed + * if the client disconnects without reenabling it first. + */ + this = (ScreenSaverSuspensionPtr) malloc (sizeof (ScreenSaverSuspensionRec)); + + if (!this) + return BadAlloc; + + memset(this, 0, sizeof (ScreenSaverSuspensionRec)); + this->next = NULL; + this->pClient = client; + this->count = 1; + this->clientResource = FakeClientID (client->index); + + if (!AddResource (this->clientResource, SuspendType, (pointer) this)) + { + free (this); + return BadAlloc; + } + + *prev = this; + if (!screenSaverSuspended) + { + screenSaverSuspended = TRUE; + FreeScreenSaverTimer(); + } + + return (client->noClientException); +} + static DISPATCH_PROC((*NormalVector[])) = { ProcScreenSaverQueryVersion, ProcScreenSaverQueryInfo, ProcScreenSaverSelectInput, ProcScreenSaverSetAttributes, ProcScreenSaverUnsetAttributes, + ProcScreenSaverSuspend, }; #define NUM_REQUESTS ((sizeof NormalVector) / (sizeof NormalVector[0])) @@ -1375,12 +1508,24 @@ SProcScreenSaverUnsetAttributes (client) return ProcScreenSaverUnsetAttributes (client); } +static int +SProcScreenSaverSuspend (ClientPtr client) +{ + REQUEST(xScreenSaverSuspendReq); + + swaps(&stuff->length); + REQUEST_SIZE_MATCH(xScreenSaverSuspendReq); + swapl(&stuff->suspend); + return ProcScreenSaverSuspend (client); +} + static DISPATCH_PROC((*SwappedVector[])) = { SProcScreenSaverQueryVersion, SProcScreenSaverQueryInfo, SProcScreenSaverSelectInput, SProcScreenSaverSetAttributes, SProcScreenSaverUnsetAttributes, + SProcScreenSaverSuspend, }; static int |