dpms.c revision 4642e01f
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/* 30 * HISTORY 31 * 32 * @(#)RCSfile: dpms.c,v Revision: 1.1.4.5 (DEC) Date: 1996/03/04 15:27:00 33 */ 34 35 36#ifdef HAVE_DIX_CONFIG_H 37#include <dix-config.h> 38#endif 39 40#include <X11/X.h> 41#include <X11/Xproto.h> 42#include "misc.h" 43#include "os.h" 44#include "dixstruct.h" 45#include "extnsionst.h" 46#include "opaque.h" 47#define DPMS_SERVER 48#include <X11/extensions/dpms.h> 49#include <X11/extensions/dpmsstr.h> 50#include "dpmsproc.h" 51#include "modinit.h" 52 53static DISPATCH_PROC(ProcDPMSDispatch); 54static DISPATCH_PROC(SProcDPMSDispatch); 55static DISPATCH_PROC(ProcDPMSGetVersion); 56static DISPATCH_PROC(SProcDPMSGetVersion); 57static DISPATCH_PROC(ProcDPMSGetTimeouts); 58static DISPATCH_PROC(SProcDPMSGetTimeouts); 59static DISPATCH_PROC(ProcDPMSSetTimeouts); 60static DISPATCH_PROC(SProcDPMSSetTimeouts); 61static DISPATCH_PROC(ProcDPMSEnable); 62static DISPATCH_PROC(SProcDPMSEnable); 63static DISPATCH_PROC(ProcDPMSDisable); 64static DISPATCH_PROC(SProcDPMSDisable); 65static DISPATCH_PROC(ProcDPMSForceLevel); 66static DISPATCH_PROC(SProcDPMSForceLevel); 67static DISPATCH_PROC(ProcDPMSInfo); 68static DISPATCH_PROC(SProcDPMSInfo); 69static DISPATCH_PROC(ProcDPMSCapable); 70static DISPATCH_PROC(SProcDPMSCapable); 71 72void 73DPMSExtensionInit(INITARGS) 74{ 75 AddExtension(DPMSExtensionName, 0, 0, 76 ProcDPMSDispatch, SProcDPMSDispatch, 77 NULL, StandardMinorOpcode); 78} 79 80static int 81ProcDPMSGetVersion(client) 82 ClientPtr client; 83{ 84 /* REQUEST(xDPMSGetVersionReq); */ 85 xDPMSGetVersionReply rep; 86 int n; 87 88 REQUEST_SIZE_MATCH(xDPMSGetVersionReq); 89 90 rep.type = X_Reply; 91 rep.length = 0; 92 rep.sequenceNumber = client->sequence; 93 rep.majorVersion = DPMSMajorVersion; 94 rep.minorVersion = DPMSMinorVersion; 95 if (client->swapped) { 96 swaps(&rep.sequenceNumber, n); 97 swaps(&rep.majorVersion, n); 98 swaps(&rep.minorVersion, n); 99 } 100 WriteToClient(client, sizeof(xDPMSGetVersionReply), (char *)&rep); 101 return(client->noClientException); 102} 103 104static int 105ProcDPMSCapable(ClientPtr client) 106{ 107 /* REQUEST(xDPMSCapableReq); */ 108 xDPMSCapableReply rep; 109 int n; 110 111 REQUEST_SIZE_MATCH(xDPMSCapableReq); 112 113 rep.type = X_Reply; 114 rep.length = 0; 115 rep.sequenceNumber = client->sequence; 116 rep.capable = DPMSCapableFlag; 117 118 if (client->swapped) { 119 swaps(&rep.sequenceNumber, n); 120 } 121 WriteToClient(client, sizeof(xDPMSCapableReply), (char *)&rep); 122 return(client->noClientException); 123} 124 125static int 126ProcDPMSGetTimeouts(client) 127 ClientPtr client; 128{ 129 /* REQUEST(xDPMSGetTimeoutsReq); */ 130 xDPMSGetTimeoutsReply rep; 131 int n; 132 133 REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq); 134 135 rep.type = X_Reply; 136 rep.length = 0; 137 rep.sequenceNumber = client->sequence; 138 rep.standby = DPMSStandbyTime / MILLI_PER_SECOND; 139 rep.suspend = DPMSSuspendTime / MILLI_PER_SECOND; 140 rep.off = DPMSOffTime / MILLI_PER_SECOND; 141 142 if (client->swapped) { 143 swaps(&rep.sequenceNumber, n); 144 swaps(&rep.standby, n); 145 swaps(&rep.suspend, n); 146 swaps(&rep.off, n); 147 } 148 WriteToClient(client, sizeof(xDPMSGetTimeoutsReply), (char *)&rep); 149 return(client->noClientException); 150} 151 152static int 153ProcDPMSSetTimeouts(client) 154 ClientPtr client; 155{ 156 REQUEST(xDPMSSetTimeoutsReq); 157 158 REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq); 159 160 if ((stuff->off != 0)&&(stuff->off < stuff->suspend)) 161 { 162 client->errorValue = stuff->off; 163 return BadValue; 164 } 165 if ((stuff->suspend != 0)&&(stuff->suspend < stuff->standby)) 166 { 167 client->errorValue = stuff->suspend; 168 return BadValue; 169 } 170 171 DPMSStandbyTime = stuff->standby * MILLI_PER_SECOND; 172 DPMSSuspendTime = stuff->suspend * MILLI_PER_SECOND; 173 DPMSOffTime = stuff->off * MILLI_PER_SECOND; 174 SetScreenSaverTimer(); 175 176 return(client->noClientException); 177} 178 179static int 180ProcDPMSEnable(client) 181 ClientPtr client; 182{ 183 Bool was_enabled = DPMSEnabled; 184 185 REQUEST_SIZE_MATCH(xDPMSEnableReq); 186 187 if (DPMSCapableFlag) { 188 DPMSEnabled = TRUE; 189 if (!was_enabled) 190 SetScreenSaverTimer(); 191 } 192 193 return(client->noClientException); 194} 195 196static int 197ProcDPMSDisable(client) 198 ClientPtr client; 199{ 200 /* REQUEST(xDPMSDisableReq); */ 201 202 REQUEST_SIZE_MATCH(xDPMSDisableReq); 203 204 DPMSSet(client, DPMSModeOn); 205 206 DPMSEnabled = FALSE; 207 208 return(client->noClientException); 209} 210 211static int 212ProcDPMSForceLevel(client) 213 ClientPtr client; 214{ 215 REQUEST(xDPMSForceLevelReq); 216 217 REQUEST_SIZE_MATCH(xDPMSForceLevelReq); 218 219 if (!DPMSEnabled) 220 return BadMatch; 221 222 if (stuff->level == DPMSModeOn) { 223 lastDeviceEventTime.milliseconds = 224 GetTimeInMillis(); 225 } else if (stuff->level == DPMSModeStandby) { 226 lastDeviceEventTime.milliseconds = 227 GetTimeInMillis() - DPMSStandbyTime; 228 } else if (stuff->level == DPMSModeSuspend) { 229 lastDeviceEventTime.milliseconds = 230 GetTimeInMillis() - DPMSSuspendTime; 231 } else if (stuff->level == DPMSModeOff) { 232 lastDeviceEventTime.milliseconds = 233 GetTimeInMillis() - DPMSOffTime; 234 } else { 235 client->errorValue = stuff->level; 236 return BadValue; 237 } 238 239 DPMSSet(client, stuff->level); 240 241 return(client->noClientException); 242} 243 244static int 245ProcDPMSInfo(ClientPtr client) 246{ 247 /* REQUEST(xDPMSInfoReq); */ 248 xDPMSInfoReply rep; 249 int n; 250 251 REQUEST_SIZE_MATCH(xDPMSInfoReq); 252 253 rep.type = X_Reply; 254 rep.length = 0; 255 rep.sequenceNumber = client->sequence; 256 rep.power_level = DPMSPowerLevel; 257 rep.state = DPMSEnabled; 258 259 if (client->swapped) { 260 swaps(&rep.sequenceNumber, n); 261 swaps(&rep.power_level, n); 262 } 263 WriteToClient(client, sizeof(xDPMSInfoReply), (char *)&rep); 264 return(client->noClientException); 265} 266 267static int 268ProcDPMSDispatch (client) 269 ClientPtr client; 270{ 271 REQUEST(xReq); 272 273 switch (stuff->data) 274 { 275 case X_DPMSGetVersion: 276 return ProcDPMSGetVersion(client); 277 case X_DPMSCapable: 278 return ProcDPMSCapable(client); 279 case X_DPMSGetTimeouts: 280 return ProcDPMSGetTimeouts(client); 281 case X_DPMSSetTimeouts: 282 return ProcDPMSSetTimeouts(client); 283 case X_DPMSEnable: 284 return ProcDPMSEnable(client); 285 case X_DPMSDisable: 286 return ProcDPMSDisable(client); 287 case X_DPMSForceLevel: 288 return ProcDPMSForceLevel(client); 289 case X_DPMSInfo: 290 return ProcDPMSInfo(client); 291 default: 292 return BadRequest; 293 } 294} 295 296static int 297SProcDPMSGetVersion(client) 298 ClientPtr client; 299{ 300 int n; 301 REQUEST(xDPMSGetVersionReq); 302 303 swaps(&stuff->length, n); 304 REQUEST_SIZE_MATCH(xDPMSGetVersionReq); 305 swaps(&stuff->majorVersion, n); 306 swaps(&stuff->minorVersion, n); 307 return ProcDPMSGetVersion(client); 308} 309 310static int 311SProcDPMSCapable(ClientPtr client) 312{ 313 REQUEST(xDPMSCapableReq); 314 int n; 315 316 swaps(&stuff->length, n); 317 REQUEST_SIZE_MATCH(xDPMSCapableReq); 318 319 return ProcDPMSCapable(client); 320} 321 322static int 323SProcDPMSGetTimeouts(client) 324 ClientPtr client; 325{ 326 REQUEST(xDPMSGetTimeoutsReq); 327 int n; 328 329 swaps(&stuff->length, n); 330 REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq); 331 332 return ProcDPMSGetTimeouts(client); 333} 334 335static int 336SProcDPMSSetTimeouts(client) 337 ClientPtr client; 338{ 339 REQUEST(xDPMSSetTimeoutsReq); 340 int n; 341 342 swaps(&stuff->length, n); 343 REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq); 344 345 swaps(&stuff->standby, n); 346 swaps(&stuff->suspend, n); 347 swaps(&stuff->off, n); 348 return ProcDPMSSetTimeouts(client); 349} 350 351static int 352SProcDPMSEnable(client) 353 ClientPtr client; 354{ 355 REQUEST(xDPMSEnableReq); 356 int n; 357 358 swaps(&stuff->length, n); 359 REQUEST_SIZE_MATCH(xDPMSEnableReq); 360 361 return ProcDPMSEnable(client); 362} 363 364static int 365SProcDPMSDisable(client) 366 ClientPtr client; 367{ 368 REQUEST(xDPMSDisableReq); 369 int n; 370 371 swaps(&stuff->length, n); 372 REQUEST_SIZE_MATCH(xDPMSDisableReq); 373 374 return ProcDPMSDisable(client); 375} 376 377static int 378SProcDPMSForceLevel(client) 379 ClientPtr client; 380{ 381 REQUEST(xDPMSForceLevelReq); 382 int n; 383 384 swaps(&stuff->length, n); 385 REQUEST_SIZE_MATCH(xDPMSForceLevelReq); 386 387 swaps(&stuff->level, n); 388 389 return ProcDPMSForceLevel(client); 390} 391 392static int 393SProcDPMSInfo(client) 394 ClientPtr client; 395{ 396 REQUEST(xDPMSInfoReq); 397 int n; 398 399 swaps(&stuff->length, n); 400 REQUEST_SIZE_MATCH(xDPMSInfoReq); 401 402 return ProcDPMSInfo(client); 403} 404 405static int 406SProcDPMSDispatch (client) 407 ClientPtr client; 408{ 409 REQUEST(xReq); 410 switch (stuff->data) 411 { 412 case X_DPMSGetVersion: 413 return SProcDPMSGetVersion(client); 414 case X_DPMSCapable: 415 return SProcDPMSCapable(client); 416 case X_DPMSGetTimeouts: 417 return SProcDPMSGetTimeouts(client); 418 case X_DPMSSetTimeouts: 419 return SProcDPMSSetTimeouts(client); 420 case X_DPMSEnable: 421 return SProcDPMSEnable(client); 422 case X_DPMSDisable: 423 return SProcDPMSDisable(client); 424 case X_DPMSForceLevel: 425 return SProcDPMSForceLevel(client); 426 case X_DPMSInfo: 427 return SProcDPMSInfo(client); 428 default: 429 return BadRequest; 430 } 431} 432