#define I_NEED_OS2_H
#define NEED_EVENTS
#include "X.h"
#include "input.h"
#include "scrnintstr.h"
#define INCL_WINSWITCHLIST
#define INCL_VIO
#define INCL_KBD
#define INCL_DOSPROCESS
#define INCL_DOSSEMAPHORES
#define INCL_DOSERRORS
#undef RT_FONT
#include "xf86.h"
#include "xf86Priv.h"
#include "xf86_OSlib.h"
#include "atKeynames.h"
BOOL SwitchedToWPS=FALSE;
BOOL WaitingForAccess=FALSE;
void os2PostKbdEvent();
HEV hevServerHasFocus;
HEV hevSwitchRequested;
HEV hevErrorPopupDetected;
extern HEV hevPopupPending;
extern HEV hSwitchToSem;
BOOL os2PopupErrorPending=FALSE;
Bool xf86VTSwitchPending()
{
return(xf86Info.vtRequestsPending ? TRUE : FALSE);
}
Bool xf86VTSwitchAway()
{
APIRET rc;
ULONG drive;
xf86Info.vtRequestsPending=FALSE;
SwitchedToWPS=TRUE;
rc = DosQuerySysInfo(5,5,&drive,sizeof(drive));
rc = DosSuppressPopUps(0x0000L,drive+96);
DosPostEventSem(hevSwitchRequested);
usleep(30000);
return(TRUE);
}
Bool xf86VTSwitchTo()
{
APIRET rc;
ULONG drive,postCount;
xf86Info.vtRequestsPending=FALSE;
SwitchedToWPS=FALSE;
rc = DosResetEventSem(hSwitchToSem,&postCount);
DosPostEventSem(hevSwitchRequested);
rc = DosQuerySysInfo(5,5,&drive,sizeof(drive));
rc = DosSuppressPopUps(0x0001L,drive+96);
os2PostKbdEvent(KEY_LCtrl,1);
os2PostKbdEvent(KEY_LCtrl,0);
os2PostKbdEvent(KEY_RCtrl,1);
os2PostKbdEvent(KEY_RCtrl,0);
os2PostKbdEvent(KEY_Alt,1);
os2PostKbdEvent(KEY_Alt,0);
return(TRUE);
}
void os2VideoNotify(arg)
void * arg;
{
USHORT Indic;
USHORT NotifyType;
APIRET rc;
ULONG postCount;
Bool FirstTime=TRUE;
int timeout_count;
rc=DosCreateEventSem(NULL,&hevServerHasFocus,0L,FALSE);
rc=DosPostEventSem(hevServerHasFocus);
rc=DosCreateEventSem(NULL,&hevSwitchRequested,0L,FALSE);
rc=DosPostEventSem(hevSwitchRequested);
while(1) {
Indic=0;
rc=VioSavRedrawWait(Indic,&NotifyType,(HVIO)0);
if(NotifyType==0) rc=DosResetEventSem(hevServerHasFocus,&postCount);
if(FirstTime){
FirstTime=FALSE;
if(NotifyType==1) NotifyType=65535;
}
if(NotifyType==1){
rc=DosPostEventSem(hSwitchToSem);
if (rc) xf86Msg(X_ERROR,"Post SwitchToSem returned %d\n");
if (!SwitchedToWPS) {
xf86Msg(X_ERROR,
"Abnormal switching back to server detected\n");
}
}
if((NotifyType!=65535)&&(!WaitingForAccess)) {
rc=DosResetEventSem(hevSwitchRequested,&postCount);
xf86Info.vtRequestsPending=TRUE;
timeout_count=0;
rc=DosSetPriority(2,3,0,1);
do {
rc=DosWaitEventSem(hevSwitchRequested,1000L);
if(rc==ERROR_TIMEOUT){
timeout_count++;
if(timeout_count>25){
xf86Msg(X_ERROR,
"Server timeout on VT switch request. Server was killed\n");
DosExit(1L,0);
}
if(WaitingForAccess) {
DosPostEventSem(hevSwitchRequested);
xf86Info.vtRequestsPending=FALSE;
}
}
} while (rc==ERROR_TIMEOUT);
rc=DosSetPriority(2,2,0,1);
}
if(NotifyType==1) rc=DosPostEventSem(hevServerHasFocus);
if((NotifyType==0)&&(!SwitchedToWPS))
xf86Msg(X_ERROR,
"Abnormal switching away from server!\n");
}
}
void os2HardErrorNotify(arg)
void * arg;
{
USHORT Indic;
USHORT NotifyType;
APIRET rc;
ULONG postCount;
rc=DosCreateEventSem(NULL,&hevErrorPopupDetected,0L,FALSE);
rc=DosPostEventSem(hevErrorPopupDetected);
os2PopupErrorPending=FALSE;
while(1) {
Indic=0;
rc=VioModeWait(Indic,&NotifyType,(HVIO)0);
if(NotifyType==0){
os2PopupErrorPending=TRUE;
rc=DosPostEventSem(hSwitchToSem);
rc=DosResetEventSem(hevErrorPopupDetected,&postCount);
rc=DosWaitEventSem(hevErrorPopupDetected,20000L);
if(rc==ERROR_TIMEOUT) GiveUp(0);
}
}
}
static BOOL is_redirected = FALSE;
static void
redirect_output(void)
{
char buf[20],dr[3];
ULONG drive;
APIRET rc;
if (is_redirected) return;
if ((rc = DosQuerySysInfo(5,5,&drive,sizeof(drive))) != 0)
dr[0] = 0;
else {
dr[0] = drive+96;
dr[1] = ':';
dr[2] = 0;
}
sprintf(buf,"%s\\xf86log.os2",dr);
ErrorF("\nThis is the XFree86/OS2-4.0 server\n");
ErrorF("\nAll output from now on will be redirected to %s\n",buf);
freopen(buf,"w",stderr);
is_redirected = TRUE;
}
void
os2ServerVideoAccess()
{
APIRET rc;
ULONG fgSession;
ULONG length=4;
CHAR Status;
if(serverGeneration==1){
rc=VioScrLock(0, &Status, (HVIO)0);
while(Status != 0){
rc=VioScrLock(0, &Status, (HVIO)0);
DosSleep(1000);
}
VioScrUnLock((HVIO)0);
return;
}
WaitingForAccess=TRUE;
rc=DosWaitEventSem(hevServerHasFocus,SEM_INDEFINITE_WAIT);
WaitingForAccess=FALSE;
SwitchedToWPS=FALSE;
}
void os2RecoverFromPopup()
{
int j;
ULONG postCount;
if (os2PopupErrorPending) {
#if 0
for (j = 0; j < screenInfo.numScreens; j++)
(XF86SCRNINFO(screenInfo.screens[j])->EnterLeaveVT)(LEAVE, j);
for (j = 0; j < screenInfo.numScreens; j++)
(XF86SCRNINFO(screenInfo.screens[j])->EnterLeaveVT)(ENTER, j);
#endif
DosResetEventSem(hSwitchToSem,&postCount);
for (j = 0; j < xf86NumScreens; j++) {
if (xf86Screens[j]->EnableDisableFBAccess)
(*xf86Screens[j]->EnableDisableFBAccess)(j, FALSE);
}
xf86EnterServerState(SETUP);
for (j = 0; j < xf86NumScreens; j++)
xf86Screens[j]->LeaveVT(j, 0);
for (j = 0; j < xf86NumScreens; j++) {
xf86Screens[j]->EnterVT(j, 0);
}
xf86EnterServerState(OPERATING);
for (j = 0; j < xf86NumScreens; j++) {
if (xf86Screens[j]->EnableDisableFBAccess)
(*xf86Screens[j]->EnableDisableFBAccess)(j, TRUE);
}
os2PostKbdEvent(KEY_LCtrl,1);
os2PostKbdEvent(KEY_LCtrl,0);
os2PostKbdEvent(KEY_RCtrl,1);
os2PostKbdEvent(KEY_RCtrl,0);
os2PostKbdEvent(KEY_Alt,1);
os2PostKbdEvent(KEY_Alt,0);
SaveScreens(SCREEN_SAVER_FORCER,ScreenSaverReset);
os2PopupErrorPending=FALSE;
DosPostEventSem(hevErrorPopupDetected);
}
}
void os2CheckPopupPending()
{
int j;
ULONG postCount;
return;
#if 0
DosQueryEventSem(hevPopupPending,&postCount);
if (postCount==0) {
#if 0
for (j = 0; j < screenInfo.numScreens; j++)
(XF86SCRNINFO(screenInfo.screens[j])->EnterLeaveVT)(LEAVE, j);
#endif
DosPostEventSem(hevPopupPending);
}
#endif
}