winblock.c revision 35c4bbdf
105b261ecSmrg/*
205b261ecSmrg *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved.
305b261ecSmrg *
405b261ecSmrg *Permission is hereby granted, free of charge, to any person obtaining
505b261ecSmrg * a copy of this software and associated documentation files (the
605b261ecSmrg *"Software"), to deal in the Software without restriction, including
705b261ecSmrg *without limitation the rights to use, copy, modify, merge, publish,
805b261ecSmrg *distribute, sublicense, and/or sell copies of the Software, and to
905b261ecSmrg *permit persons to whom the Software is furnished to do so, subject to
1005b261ecSmrg *the following conditions:
1105b261ecSmrg *
1205b261ecSmrg *The above copyright notice and this permission notice shall be
1305b261ecSmrg *included in all copies or substantial portions of the Software.
1405b261ecSmrg *
1505b261ecSmrg *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1605b261ecSmrg *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1705b261ecSmrg *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1805b261ecSmrg *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
1905b261ecSmrg *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
2005b261ecSmrg *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2105b261ecSmrg *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2205b261ecSmrg *
2305b261ecSmrg *Except as contained in this notice, the name of Harold L Hunt II
2405b261ecSmrg *shall not be used in advertising or otherwise to promote the sale, use
2505b261ecSmrg *or other dealings in this Software without prior written authorization
2605b261ecSmrg *from Harold L Hunt II.
2705b261ecSmrg *
2805b261ecSmrg * Authors:	Harold L Hunt II
2905b261ecSmrg */
3005b261ecSmrg
3105b261ecSmrg#ifdef HAVE_XWIN_CONFIG_H
3205b261ecSmrg#include <xwin-config.h>
3305b261ecSmrg#endif
3405b261ecSmrg#include "win.h"
3505b261ecSmrg#include "winmsg.h"
3605b261ecSmrg
3705b261ecSmrg/* See Porting Layer Definition - p. 6 */
3805b261ecSmrgvoid
3935c4bbdfSmrgwinBlockHandler(ScreenPtr pScreen,
4035c4bbdfSmrg                void *pTimeout, void *pReadMask)
4105b261ecSmrg{
4205b261ecSmrg#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
4335c4bbdfSmrg    winScreenPriv(pScreen);
4405b261ecSmrg#endif
4535c4bbdfSmrg
4605b261ecSmrg#ifndef HAS_DEVWINDOWS
4735c4bbdfSmrg    struct timeval **tvp = pTimeout;
4835c4bbdfSmrg
4935c4bbdfSmrg    if (*tvp != NULL) {
5035c4bbdfSmrg      if (GetQueueStatus(QS_ALLINPUT | QS_ALLPOSTMESSAGE) != 0) {
5135c4bbdfSmrg        /* If there are still messages to process on the Windows message
5235c4bbdfSmrg           queue, make sure select() just polls rather than blocking.
5335c4bbdfSmrg        */
5435c4bbdfSmrg        (*tvp)->tv_sec = 0;
5535c4bbdfSmrg        (*tvp)->tv_usec = 0;
5635c4bbdfSmrg      }
5735c4bbdfSmrg      else {
5835c4bbdfSmrg        /* Otherwise, lacking /dev/windows, we must wake up again in
5935c4bbdfSmrg           a reasonable time to check the Windows message queue. without
6035c4bbdfSmrg           noticeable delay.
6135c4bbdfSmrg         */
6235c4bbdfSmrg        (*tvp)->tv_sec = 0;
6335c4bbdfSmrg        (*tvp)->tv_usec = 100;
6435c4bbdfSmrg      }
6535c4bbdfSmrg    }
6605b261ecSmrg#endif
6705b261ecSmrg
6805b261ecSmrg#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
6935c4bbdfSmrg    /* Signal threaded modules to begin */
7035c4bbdfSmrg    if (pScreenPriv != NULL && !pScreenPriv->fServerStarted) {
7135c4bbdfSmrg        int iReturn;
7205b261ecSmrg
7335c4bbdfSmrg        ErrorF("winBlockHandler - pthread_mutex_unlock()\n");
7405b261ecSmrg
7535c4bbdfSmrg        /* Flag that modules are to be started */
7635c4bbdfSmrg        pScreenPriv->fServerStarted = TRUE;
7705b261ecSmrg
7835c4bbdfSmrg        /* Unlock the mutex for threaded modules */
7935c4bbdfSmrg        iReturn = pthread_mutex_unlock(&pScreenPriv->pmServerStarted);
8035c4bbdfSmrg        if (iReturn != 0) {
8135c4bbdfSmrg            ErrorF("winBlockHandler - pthread_mutex_unlock () failed: %d\n",
8235c4bbdfSmrg                   iReturn);
8335c4bbdfSmrg        }
8435c4bbdfSmrg        else {
8535c4bbdfSmrg            winDebug("winBlockHandler - pthread_mutex_unlock () returned\n");
8635c4bbdfSmrg        }
8705b261ecSmrg    }
8805b261ecSmrg#endif
8905b261ecSmrg
9035c4bbdfSmrg  /*
9135c4bbdfSmrg    At least one X client has asked to suspend the screensaver, so
9235c4bbdfSmrg    reset Windows' display idle timer
9335c4bbdfSmrg  */
9435c4bbdfSmrg#ifdef SCREENSAVER
9535c4bbdfSmrg  if (screenSaverSuspended)
9635c4bbdfSmrg    SetThreadExecutionState(ES_DISPLAY_REQUIRED);
9735c4bbdfSmrg#endif
9805b261ecSmrg}
99