dpms.c revision f7df2e56
1/***************************************************************** 2 3Copyright (c) 1996 Digital Equipment Corporation, Maynard, Massachusetts. 4 5Permission is hereby granted, free of charge, to any person obtaining a copy 6of this software and associated documentation files (the "Software"), to deal 7in the Software without restriction, including without limitation the rights 8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9copies of the Software. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, 18BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, 19WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 20IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22Except as contained in this notice, the name of Digital Equipment Corporation 23shall not be used in advertising or otherwise to promote the sale, use or other 24dealings in this Software without prior written authorization from Digital 25Equipment Corporation. 26 27******************************************************************/ 28 29#ifdef HAVE_DIX_CONFIG_H 30#include <dix-config.h> 31#endif 32 33#include <X11/X.h> 34#include <X11/Xproto.h> 35#include "misc.h" 36#include "os.h" 37#include "dixstruct.h" 38#include "extnsionst.h" 39#include "opaque.h" 40#include <X11/extensions/dpmsproto.h> 41#include "dpmsproc.h" 42#include "extinit.h" 43 44static int 45ProcDPMSGetVersion(ClientPtr client) 46{ 47 /* REQUEST(xDPMSGetVersionReq); */ 48 xDPMSGetVersionReply rep = { 49 .type = X_Reply, 50 .sequenceNumber = client->sequence, 51 .length = 0, 52 .majorVersion = DPMSMajorVersion, 53 .minorVersion = DPMSMinorVersion 54 }; 55 56 REQUEST_SIZE_MATCH(xDPMSGetVersionReq); 57 58 if (client->swapped) { 59 swaps(&rep.sequenceNumber); 60 swaps(&rep.majorVersion); 61 swaps(&rep.minorVersion); 62 } 63 WriteToClient(client, sizeof(xDPMSGetVersionReply), &rep); 64 return Success; 65} 66 67static int 68ProcDPMSCapable(ClientPtr client) 69{ 70 /* REQUEST(xDPMSCapableReq); */ 71 xDPMSCapableReply rep = { 72 .type = X_Reply, 73 .sequenceNumber = client->sequence, 74 .length = 0, 75 .capable = DPMSCapableFlag 76 }; 77 78 REQUEST_SIZE_MATCH(xDPMSCapableReq); 79 80 if (client->swapped) { 81 swaps(&rep.sequenceNumber); 82 } 83 WriteToClient(client, sizeof(xDPMSCapableReply), &rep); 84 return Success; 85} 86 87static int 88ProcDPMSGetTimeouts(ClientPtr client) 89{ 90 /* REQUEST(xDPMSGetTimeoutsReq); */ 91 xDPMSGetTimeoutsReply rep = { 92 .type = X_Reply, 93 .sequenceNumber = client->sequence, 94 .length = 0, 95 .standby = DPMSStandbyTime / MILLI_PER_SECOND, 96 .suspend = DPMSSuspendTime / MILLI_PER_SECOND, 97 .off = DPMSOffTime / MILLI_PER_SECOND 98 }; 99 100 REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq); 101 102 if (client->swapped) { 103 swaps(&rep.sequenceNumber); 104 swaps(&rep.standby); 105 swaps(&rep.suspend); 106 swaps(&rep.off); 107 } 108 WriteToClient(client, sizeof(xDPMSGetTimeoutsReply), &rep); 109 return Success; 110} 111 112static int 113ProcDPMSSetTimeouts(ClientPtr client) 114{ 115 REQUEST(xDPMSSetTimeoutsReq); 116 117 REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq); 118 119 if ((stuff->off != 0) && (stuff->off < stuff->suspend)) { 120 client->errorValue = stuff->off; 121 return BadValue; 122 } 123 if ((stuff->suspend != 0) && (stuff->suspend < stuff->standby)) { 124 client->errorValue = stuff->suspend; 125 return BadValue; 126 } 127 128 DPMSStandbyTime = stuff->standby * MILLI_PER_SECOND; 129 DPMSSuspendTime = stuff->suspend * MILLI_PER_SECOND; 130 DPMSOffTime = stuff->off * MILLI_PER_SECOND; 131 SetScreenSaverTimer(); 132 133 return Success; 134} 135 136static int 137ProcDPMSEnable(ClientPtr client) 138{ 139 Bool was_enabled = DPMSEnabled; 140 141 REQUEST_SIZE_MATCH(xDPMSEnableReq); 142 143 if (DPMSCapableFlag) { 144 DPMSEnabled = TRUE; 145 if (!was_enabled) 146 SetScreenSaverTimer(); 147 } 148 149 return Success; 150} 151 152static int 153ProcDPMSDisable(ClientPtr client) 154{ 155 /* REQUEST(xDPMSDisableReq); */ 156 157 REQUEST_SIZE_MATCH(xDPMSDisableReq); 158 159 DPMSSet(client, DPMSModeOn); 160 161 DPMSEnabled = FALSE; 162 163 return Success; 164} 165 166static int 167ProcDPMSForceLevel(ClientPtr client) 168{ 169 REQUEST(xDPMSForceLevelReq); 170 171 REQUEST_SIZE_MATCH(xDPMSForceLevelReq); 172 173 if (!DPMSEnabled) 174 return BadMatch; 175 176 if (stuff->level != DPMSModeOn && 177 stuff->level != DPMSModeStandby && 178 stuff->level != DPMSModeSuspend && stuff->level != DPMSModeOff) { 179 client->errorValue = stuff->level; 180 return BadValue; 181 } 182 183 DPMSSet(client, stuff->level); 184 185 return Success; 186} 187 188static int 189ProcDPMSInfo(ClientPtr client) 190{ 191 /* REQUEST(xDPMSInfoReq); */ 192 xDPMSInfoReply rep = { 193 .type = X_Reply, 194 .sequenceNumber = client->sequence, 195 .length = 0, 196 .power_level = DPMSPowerLevel, 197 .state = DPMSEnabled 198 }; 199 200 REQUEST_SIZE_MATCH(xDPMSInfoReq); 201 202 if (client->swapped) { 203 swaps(&rep.sequenceNumber); 204 swaps(&rep.power_level); 205 } 206 WriteToClient(client, sizeof(xDPMSInfoReply), &rep); 207 return Success; 208} 209 210static int 211ProcDPMSDispatch(ClientPtr client) 212{ 213 REQUEST(xReq); 214 215 switch (stuff->data) { 216 case X_DPMSGetVersion: 217 return ProcDPMSGetVersion(client); 218 case X_DPMSCapable: 219 return ProcDPMSCapable(client); 220 case X_DPMSGetTimeouts: 221 return ProcDPMSGetTimeouts(client); 222 case X_DPMSSetTimeouts: 223 return ProcDPMSSetTimeouts(client); 224 case X_DPMSEnable: 225 return ProcDPMSEnable(client); 226 case X_DPMSDisable: 227 return ProcDPMSDisable(client); 228 case X_DPMSForceLevel: 229 return ProcDPMSForceLevel(client); 230 case X_DPMSInfo: 231 return ProcDPMSInfo(client); 232 default: 233 return BadRequest; 234 } 235} 236 237static int 238SProcDPMSGetVersion(ClientPtr client) 239{ 240 REQUEST(xDPMSGetVersionReq); 241 242 swaps(&stuff->length); 243 REQUEST_SIZE_MATCH(xDPMSGetVersionReq); 244 swaps(&stuff->majorVersion); 245 swaps(&stuff->minorVersion); 246 return ProcDPMSGetVersion(client); 247} 248 249static int 250SProcDPMSCapable(ClientPtr client) 251{ 252 REQUEST(xDPMSCapableReq); 253 254 swaps(&stuff->length); 255 REQUEST_SIZE_MATCH(xDPMSCapableReq); 256 257 return ProcDPMSCapable(client); 258} 259 260static int 261SProcDPMSGetTimeouts(ClientPtr client) 262{ 263 REQUEST(xDPMSGetTimeoutsReq); 264 265 swaps(&stuff->length); 266 REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq); 267 268 return ProcDPMSGetTimeouts(client); 269} 270 271static int 272SProcDPMSSetTimeouts(ClientPtr client) 273{ 274 REQUEST(xDPMSSetTimeoutsReq); 275 276 swaps(&stuff->length); 277 REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq); 278 279 swaps(&stuff->standby); 280 swaps(&stuff->suspend); 281 swaps(&stuff->off); 282 return ProcDPMSSetTimeouts(client); 283} 284 285static int 286SProcDPMSEnable(ClientPtr client) 287{ 288 REQUEST(xDPMSEnableReq); 289 290 swaps(&stuff->length); 291 REQUEST_SIZE_MATCH(xDPMSEnableReq); 292 293 return ProcDPMSEnable(client); 294} 295 296static int 297SProcDPMSDisable(ClientPtr client) 298{ 299 REQUEST(xDPMSDisableReq); 300 301 swaps(&stuff->length); 302 REQUEST_SIZE_MATCH(xDPMSDisableReq); 303 304 return ProcDPMSDisable(client); 305} 306 307static int 308SProcDPMSForceLevel(ClientPtr client) 309{ 310 REQUEST(xDPMSForceLevelReq); 311 312 swaps(&stuff->length); 313 REQUEST_SIZE_MATCH(xDPMSForceLevelReq); 314 315 swaps(&stuff->level); 316 317 return ProcDPMSForceLevel(client); 318} 319 320static int 321SProcDPMSInfo(ClientPtr client) 322{ 323 REQUEST(xDPMSInfoReq); 324 325 swaps(&stuff->length); 326 REQUEST_SIZE_MATCH(xDPMSInfoReq); 327 328 return ProcDPMSInfo(client); 329} 330 331static int 332SProcDPMSDispatch(ClientPtr client) 333{ 334 REQUEST(xReq); 335 switch (stuff->data) { 336 case X_DPMSGetVersion: 337 return SProcDPMSGetVersion(client); 338 case X_DPMSCapable: 339 return SProcDPMSCapable(client); 340 case X_DPMSGetTimeouts: 341 return SProcDPMSGetTimeouts(client); 342 case X_DPMSSetTimeouts: 343 return SProcDPMSSetTimeouts(client); 344 case X_DPMSEnable: 345 return SProcDPMSEnable(client); 346 case X_DPMSDisable: 347 return SProcDPMSDisable(client); 348 case X_DPMSForceLevel: 349 return SProcDPMSForceLevel(client); 350 case X_DPMSInfo: 351 return SProcDPMSInfo(client); 352 default: 353 return BadRequest; 354 } 355} 356 357void 358DPMSExtensionInit(void) 359{ 360 AddExtension(DPMSExtensionName, 0, 0, 361 ProcDPMSDispatch, SProcDPMSDispatch, 362 NULL, StandardMinorOpcode); 363} 364