xref: /OK3568_Linux_fs/external/xserver/hw/xwin/winblock.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  *Permission is hereby granted, free of charge, to any person obtaining
5*4882a593Smuzhiyun  * a copy of this software and associated documentation files (the
6*4882a593Smuzhiyun  *"Software"), to deal in the Software without restriction, including
7*4882a593Smuzhiyun  *without limitation the rights to use, copy, modify, merge, publish,
8*4882a593Smuzhiyun  *distribute, sublicense, and/or sell copies of the Software, and to
9*4882a593Smuzhiyun  *permit persons to whom the Software is furnished to do so, subject to
10*4882a593Smuzhiyun  *the following conditions:
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  *The above copyright notice and this permission notice shall be
13*4882a593Smuzhiyun  *included in all copies or substantial portions of the Software.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16*4882a593Smuzhiyun  *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17*4882a593Smuzhiyun  *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18*4882a593Smuzhiyun  *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
19*4882a593Smuzhiyun  *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20*4882a593Smuzhiyun  *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21*4882a593Smuzhiyun  *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  *Except as contained in this notice, the name of Harold L Hunt II
24*4882a593Smuzhiyun  *shall not be used in advertising or otherwise to promote the sale, use
25*4882a593Smuzhiyun  *or other dealings in this Software without prior written authorization
26*4882a593Smuzhiyun  *from Harold L Hunt II.
27*4882a593Smuzhiyun  *
28*4882a593Smuzhiyun  * Authors:	Harold L Hunt II
29*4882a593Smuzhiyun  */
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #ifdef HAVE_XWIN_CONFIG_H
32*4882a593Smuzhiyun #include <xwin-config.h>
33*4882a593Smuzhiyun #endif
34*4882a593Smuzhiyun #include "win.h"
35*4882a593Smuzhiyun #include "winmsg.h"
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun /* See Porting Layer Definition - p. 6 */
38*4882a593Smuzhiyun void
winBlockHandler(ScreenPtr pScreen,void * pTimeout)39*4882a593Smuzhiyun winBlockHandler(ScreenPtr pScreen, void *pTimeout)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun     winScreenPriv(pScreen);
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun #ifndef HAS_DEVWINDOWS
44*4882a593Smuzhiyun     struct timeval **tvp = pTimeout;
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun     if (*tvp != NULL) {
47*4882a593Smuzhiyun       if (GetQueueStatus(QS_ALLINPUT | QS_ALLPOSTMESSAGE) != 0) {
48*4882a593Smuzhiyun         /* If there are still messages to process on the Windows message
49*4882a593Smuzhiyun            queue, make sure select() just polls rather than blocking.
50*4882a593Smuzhiyun         */
51*4882a593Smuzhiyun         (*tvp)->tv_sec = 0;
52*4882a593Smuzhiyun         (*tvp)->tv_usec = 0;
53*4882a593Smuzhiyun       }
54*4882a593Smuzhiyun       else {
55*4882a593Smuzhiyun         /* Otherwise, lacking /dev/windows, we must wake up again in
56*4882a593Smuzhiyun            a reasonable time to check the Windows message queue. without
57*4882a593Smuzhiyun            noticeable delay.
58*4882a593Smuzhiyun          */
59*4882a593Smuzhiyun         (*tvp)->tv_sec = 0;
60*4882a593Smuzhiyun         (*tvp)->tv_usec = 100;
61*4882a593Smuzhiyun       }
62*4882a593Smuzhiyun     }
63*4882a593Smuzhiyun #endif
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun     /* Signal threaded modules to begin */
66*4882a593Smuzhiyun     if (pScreenPriv != NULL && !pScreenPriv->fServerStarted) {
67*4882a593Smuzhiyun         int iReturn;
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun         winDebug("winBlockHandler - pthread_mutex_unlock()\n");
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun         /* Flag that modules are to be started */
72*4882a593Smuzhiyun         pScreenPriv->fServerStarted = TRUE;
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun         /* Unlock the mutex for threaded modules */
75*4882a593Smuzhiyun         iReturn = pthread_mutex_unlock(&pScreenPriv->pmServerStarted);
76*4882a593Smuzhiyun         if (iReturn != 0) {
77*4882a593Smuzhiyun             ErrorF("winBlockHandler - pthread_mutex_unlock () failed: %d\n",
78*4882a593Smuzhiyun                    iReturn);
79*4882a593Smuzhiyun         }
80*4882a593Smuzhiyun         else {
81*4882a593Smuzhiyun             winDebug("winBlockHandler - pthread_mutex_unlock () returned\n");
82*4882a593Smuzhiyun         }
83*4882a593Smuzhiyun     }
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun   /*
86*4882a593Smuzhiyun     At least one X client has asked to suspend the screensaver, so
87*4882a593Smuzhiyun     reset Windows' display idle timer
88*4882a593Smuzhiyun   */
89*4882a593Smuzhiyun #ifdef SCREENSAVER
90*4882a593Smuzhiyun   if (screenSaverSuspended)
91*4882a593Smuzhiyun     SetThreadExecutionState(ES_DISPLAY_REQUIRED);
92*4882a593Smuzhiyun #endif
93*4882a593Smuzhiyun }
94