Example #1
0
HRESULT
    CUSBSimEndpoint::Init (CUSBSimDevice * pDevice,
                           USBENDPOINTDESC * pEndpointDesc)
{
    HRESULT hr;

    hr = CoCreateInstance (CLSID_SoftUSBEndpoint, NULL, CLSCTX_INPROC_SERVER,
                           __uuidof (ISoftUSBEndpoint),
                           reinterpret_cast < void **>(&m_pSoftUSBEndpoint));
    if (FAILED (hr)) {
        TRACE_ERR ("CoCreateInstance", hr);
    } else {
        m_pSoftUSBEndpoint->put_EndpointAddress (pEndpointDesc->Address.Byte);
        m_pSoftUSBEndpoint->put_Attributes (pEndpointDesc->Attributes.Byte);
        m_pSoftUSBEndpoint->put_MaxPacketSize (pEndpointDesc->MaxPacket.Word);
        m_pSoftUSBEndpoint->put_Interval (pEndpointDesc->bInterval);
        hr = InitEvents ();
        if (SUCCEEDED (hr)) {
            m_pDevice = pDevice;
            hr = InitPipe (pEndpointDesc->Address.Byte,
                           pEndpointDesc->Attributes.Bits.TransferType,
                           pEndpointDesc->MaxPacket.Bits.Size);
        }
    }
    return hr;
}
Example #2
0
extern "C" int __declspec(dllexport) Load(PLUGINLINK *link)
{
#if _MSC_VER >= 1300
	Log("%s", "Entering function " __FUNCTION__);
#endif
	pluginLink = link;
	mir_getLP(&pluginInfo);
	mir_getMMI(&mmi);
	
	Log("%s", "Creating service functions ...");
	InitServices();
	InitEvents();
	
#ifdef _DEBUG	
	hTestPlugin = CreateServiceFunction(MS_FOLDERS_TEST_PLUGIN, TestPlugin);
	CLISTMENUITEM mi = {0};
	
	mi.cbSize=sizeof(mi);
	mi.position=300050000;
	mi.flags=0;
	mi.hIcon=0;
	mi.pszName=Translate("Test folders");
	mi.pszService=MS_FOLDERS_TEST_PLUGIN;
	CallService(MS_CLIST_ADDMAINMENUITEM,0,(LPARAM)&mi);
#endif
#if _MSC_VER >= 1300
	Log("%s", "Hooking events ...");	
#endif
	HookEvents();
#if _MSC_VER >= 1300
	Log("%s", "Leaving function " __FUNCTION__);
#endif
	return 0;
}
 void EnterCombat(Unit* who) {
     InitEvents();
     if (oaf) {
         oaf->GetMotionMaster()->Clear();
         oaf->AddThreat(who, 10.0f); 
         oaf->Attack(who, false);
     }
 }
Example #4
0
extern "C" __declspec(dllexport) int Load(void)
{
	mir_getLP(&pluginInfo);

	InitServices();
	InitEvents();
	InitOptions();
	return 0;
}
Example #5
0
	MainFrame::MainFrame (wxWindow* parent) : MainFrameBase (parent),
		ListItemRightClickEventPending (false),
		SelectedItemIndex (-1),
		SelectedSlotNumber (0),
		ShowRequestFifo (-1)
	{
		wxBusyCursor busy;

		SetName (Application::GetName());
		SetTitle (Application::GetName());
		SetIcon (Resources::GetTrueCrypt64Icon());

#if defined(TC_UNIX) && !defined(TC_MACOSX)
		try
		{
			string fifoPath = GetShowRequestFifoPath();

			remove (fifoPath.c_str());
			throw_sys_if (mkfifo (fifoPath.c_str(), S_IRUSR | S_IWUSR) == -1);

			ShowRequestFifo = open (fifoPath.c_str(), O_RDONLY | O_NONBLOCK);
			throw_sys_if (ShowRequestFifo == -1);
		}
		catch (...)
		{
#ifdef DEBUG
			throw;
#endif
		}
#endif

		InitControls();
		InitPreferences();
		InitTaskBarIcon();
		InitEvents();
		InitMessageFilter();

		if (!GetPreferences().SecurityTokenModule.IsEmpty() && !SecurityToken::IsInitialized())
		{
			try
			{
				Gui->InitSecurityTokenLibrary();
			}
			catch (exception &e)
			{
				Gui->ShowError (e);
			}
		}
	}
Example #6
0
int WINAPI _tWinMain 
(
	 HINSTANCE hinstExe
	,HINSTANCE //hinstPrev
	,LPTSTR    //pszCmdLine
	,int       //nCmdShow
) 
{
	InitEvents () ;

	DialogBox
	(
		hinstExe, 
		MAKEINTRESOURCE(IDD_DLGHUSK), 
		NULL, 
		(DLGPROC)DlgProc // WEIRD: I didn't used to have to cast this to DLGPROC
	);
	return(0);
}
Example #7
0
HRESULT
    CUSBSimEndpoint::Init (CUSBSimDevice * pDevice,
                           ISoftUSBEndpoint * pSoftUSBEndpoint)
{
    HRESULT hr;

    hr = pSoftUSBEndpoint->QueryInterface (__uuidof (ISoftUSBEndpoint),
                                           reinterpret_cast <
                                           void **>(&m_pSoftUSBEndpoint));
    if (FAILED (hr)) {
        TRACE_ERR ("QueryInterface", hr);
    } else {
        hr = InitEvents ();
        if (SUCCEEDED (hr)) {
            m_pDevice = pDevice;
            hr = InitPipe (0, CONTROL_ENDPOINT, 64);
        }
    }
    return hr;
}
void OgreApplication::Init(void){

	/* Set default values for the variables */
	animating_ = false;
	space_down_ = false;
	animation_state_ = NULL;
	input_manager_ = NULL;
	keyboard_ = NULL;
	mouse_ = NULL;

	/* Run all initialization steps */
    InitRootNode();
    InitPlugins();
    InitRenderSystem();
    InitWindow();
    InitViewport();
	InitEvents();
	InitOIS();
	LoadMaterials();
}
Example #9
0
CMPTutorial::CMPTutorial()
: m_initialised(false)
, m_currentBriefingEvent(eTE_StartGame)
, m_entityCheckTimer(0.0f)
, m_baseCheckTimer(ENTITY_CHECK_TIME / 2.0f)
, m_wasInVehicle(false)
{
	// initialise everything even if disabled - we might be enabled later?
	int enabled = g_pGameCVars->g_PSTutorial_Enabled;
	m_enabled = (enabled != 0);

	m_currentEvent.Reset();

	// blank out all the events initially, and assign their names
	InitEvents();

	// get entity classes we'll need later
	InitEntityClasses();

	// add console command
	gEnv->pConsole->AddCommand("g_psTutorial_TriggerEvent", ForceTriggerEvent, VF_CHEAT, "Trigger an MP tutorial event by name");
	gEnv->pConsole->AddCommand("g_psTutorial_Reset", ResetAllEvents, VF_CHEAT, "Reset powerstruggle tutorial");
}
Example #10
0
//////////////////
//Init Functions//
/////////////////
void AsteroidGame::Init(void){
	input_manager_ = NULL;
	keyboard_ = NULL;
	mouse_ = NULL;

	/* Run all initialization steps */
    InitRootNode();
    InitPlugins();
    InitRenderSystem();
    InitWindow();
    InitViewport();
	InitEvents();
	InitOIS();
	LoadMaterials();

	InitManagers();
	


	iAsteroidManager->createAsteroidField();

	iGameState = GameState::Running;
}
int LoadDatabaseModule(void)
{
	InitializeCriticalSection(&csDbAccess);
	log0("DB logging running");
	{
		DWORD dummy=0;
		hDbFile=CreateFileA(szDbPath,GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
		if ( hDbFile == INVALID_HANDLE_VALUE ) {
			return 1;
		}
		if ( !ReadFile(hDbFile,&dbHeader,sizeof(dbHeader),&dummy,NULL) ) {
			CloseHandle(hDbFile);
			return 1;
		}
	}
	//if(ParseCommandLine()) return 1;
	if(InitCache()) return 1;
	if(InitModuleNames()) return 1;
	if(InitContacts()) return 1;
	if(InitSettings()) return 1;
	if(InitEvents()) return 1;
	if(InitCrypt()) return 1;
	return 0;
}
Example #12
0
extern "C" __declspec(dllexport) int Load(PLUGINLINK *link)
{
	pluginLink = link;
	mir_getMMI(&mmi);
	mir_getLI(&li);
	mir_getMD5I(&md5i);
	mir_getUTFI(&utfi);
#else
extern "C" __declspec(dllexport) int Load(void)
{
	mir_getLP(&pluginInfoEx);

	InitServices();
#endif

	db_set_b(NULL, MODNAME, "NeedRestart", 0);

	DWORD dwLen = GetTempPath( SIZEOF(tszTempPath), tszTempPath);
	if (tszTempPath[dwLen-1] == '\\')
		tszTempPath[dwLen-1] = 0;

	LoadOptions();
	InitPopupList();
	InitNetlib();
	InitIcoLib();

	// Add cheking update menu item
	InitCheck();
	CLISTMENUITEM mi = { sizeof(mi) };
	mi.position = 400010000;
	mi.icolibItem = Skin_GetIconHandle("check_update");
	mi.pszName = LPGEN("Check for updates");
	mi.pszService = MODNAME"/CheckUpdates";
	Menu_AddMainMenuItem(&mi);

#if MIRANDA_VER >= 0x0A00
	InitListNew();

	mi.position++;
	mi.icolibItem = Skin_GetIconHandle("plg_list");
	mi.pszName = LPGEN("Available components list");
	mi.pszService = MODNAME"/ShowList";
	Menu_AddMainMenuItem(&mi);

	InitOptions();
#endif

	// Add hotkey
	HOTKEYDESC hkd = { sizeof(hkd) };
	hkd.pszName = "Check for updates";
	hkd.pszDescription = "Check for updates";
	hkd.pszSection = "Plugin Updater";
	hkd.pszService = MODNAME"/CheckUpdates";
	hkd.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL, VK_F10) | HKF_MIRANDA_LOCAL;
	hkd.lParam = FALSE;
	Hotkey_Register(&hkd);

	InitEvents();

	//add sounds
	SkinAddNewSoundEx("updatecompleted",LPGEN("Plugin Updater"),LPGEN("Update completed"));
	SkinAddNewSoundEx("updatefailed",LPGEN("Plugin Updater"),LPGEN("Update failed"));
	return 0;
}
PIN_GameControllerManager::PIN_GameControllerManager(PIN_ControlType* controlType, PIN_MappingList* mappingList, PIN_ControllerBaseList* masterControllerList )
    : PIN_ManagerBase(controlType, mappingList, masterControllerList)
{
    InitEvents();

    std::string strKeyList(/*"\\b(?:"*/"");
    std::string strAxisList("");

    bool firstItem = true;
    for(int x = SDL_CONTROLLER_BUTTON_A; x < SDL_CONTROLLER_BUTTON_MAX; x++)
    {
        PIN_String strButton = SDL_GameControllerGetStringForButton((SDL_GameControllerButton)x);
        if(!boost::equals(strButton,""))
        {
            if(!firstItem)
            {
                strKeyList += "|";
            }
            else
            {
                firstItem = false;
            }
            std::string strCode(strButton);
            strCode = PAUX_Extensors::regex_escape(strCode);
            strKeyList+= "(?:\\b" + strCode + "\\b)";
        }
    }

    firstItem = true;

    for(int x = SDL_CONTROLLER_AXIS_LEFTX; x < SDL_CONTROLLER_AXIS_MAX; x++)
    {
        PIN_String strAxis = SDL_GameControllerGetStringForAxis((SDL_GameControllerAxis)x);
        if(!boost::equals(strAxis,""))
        {
            strKeyList += "|";

            if(!firstItem)
            {
                strAxisList += "|";
            }
            else
            {
                firstItem = false;
            }
            std::string strCode(strAxis);

            strCode = PAUX_Extensors::regex_escape(strCode);
            strCode = "(?:(?<func>POS|NEG)\\()?(?<axis>\\b"+strCode+"\\b)\\)?";//
            //strCode = "(?:(?:(<func>POS|NEG)\\()?(<axis>" + strCode + ")(?'func'\\))?)";

            //printf("Axis code: %s\n",strCode.c_str());

            strAxisList += strCode;
            strKeyList+= strCode;
        }
    }

    //strKeyList+=")\\b";

    _keyListRegex = boost::regex(strKeyList,boost::regex::perl|boost::regex::icase);

    _regexAxisString = boost::regex(strAxisList,boost::regex::perl|boost::regex::icase);

    //printf("Main regex: %s\n",_keyListRegex.str().c_str());
    //printf("Axis regex: %s\n",_regexAxisString.str().c_str());
}
Example #14
0
int
main(int argc, char *argv[], char *envp[])
#endif
{
    int i;
    HWEventQueueType alwaysCheckForInput[2];

    display = "0";

    InitRegions();

    CheckUserParameters(argc, argv, envp);

    CheckUserAuthorization();

    InitConnectionLimits();

    ProcessCommandLine(argc, argv);

    alwaysCheckForInput[0] = 0;
    alwaysCheckForInput[1] = 1;
    while (1) {
        serverGeneration++;
        ScreenSaverTime = defaultScreenSaverTime;
        ScreenSaverInterval = defaultScreenSaverInterval;
        ScreenSaverBlanking = defaultScreenSaverBlanking;
        ScreenSaverAllowExposures = defaultScreenSaverAllowExposures;
#ifdef DPMSExtension
        DPMSStandbyTime = DPMSSuspendTime = DPMSOffTime = ScreenSaverTime;
        DPMSEnabled = TRUE;
        DPMSPowerLevel = 0;
#endif
        InitBlockAndWakeupHandlers();
        /* Perform any operating system dependent initializations you'd like */
        OsInit();
        if (serverGeneration == 1) {
            CreateWellKnownSockets();
            for (i = 1; i < MAXCLIENTS; i++)
                clients[i] = NullClient;
            serverClient = calloc(sizeof(ClientRec), 1);
            if (!serverClient)
                FatalError("couldn't create server client");
            InitClient(serverClient, 0, (pointer) NULL);
        }
        else
            ResetWellKnownSockets();
        clients[0] = serverClient;
        currentMaxClients = 1;

        /* Initialize privates before first allocation */
        dixResetPrivates();

        /* Initialize server client devPrivates, to be reallocated as
         * more client privates are registered
         */
        if (!dixAllocatePrivates(&serverClient->devPrivates, PRIVATE_CLIENT))
            FatalError("failed to create server client privates");

        if (!InitClientResources(serverClient)) /* for root resources */
            FatalError("couldn't init server resources");

        SetInputCheck(&alwaysCheckForInput[0], &alwaysCheckForInput[1]);
        screenInfo.numScreens = 0;

        InitAtoms();
        InitEvents();
        InitSelections();
        InitGlyphCaching();
        dixResetRegistry();
        ResetFontPrivateIndex();
        InitCallbackManager();
        InitOutput(&screenInfo, argc, argv);

        if (screenInfo.numScreens < 1)
            FatalError("no screens found");
        InitExtensions(argc, argv);

        for (i = 0; i < screenInfo.numGPUScreens; i++) {
            ScreenPtr pScreen = screenInfo.gpuscreens[i];
            if (!CreateScratchPixmapsForScreen(pScreen))
                FatalError("failed to create scratch pixmaps");
        }

        for (i = 0; i < screenInfo.numScreens; i++) {
            ScreenPtr pScreen = screenInfo.screens[i];

            if (!CreateScratchPixmapsForScreen(pScreen))
                FatalError("failed to create scratch pixmaps");
            if (pScreen->CreateScreenResources &&
                !(*pScreen->CreateScreenResources) (pScreen))
                FatalError("failed to create screen resources");
            if (!CreateGCperDepth(i))
                FatalError("failed to create scratch GCs");
            if (!CreateDefaultStipple(i))
                FatalError("failed to create default stipple");
            if (!CreateRootWindow(pScreen))
                FatalError("failed to create root window");
        }

        InitFonts();
        if (SetDefaultFontPath(defaultFontPath) != Success) {
            ErrorF("[dix] failed to set default font path '%s'",
                   defaultFontPath);
        }
        if (!SetDefaultFont(defaultTextFont)) {
            FatalError("could not open default font '%s'", defaultTextFont);
        }

        if (!(rootCursor = CreateRootCursor(NULL, 0))) {
            FatalError("could not open default cursor font '%s'",
                       defaultCursorFont);
        }

#ifdef DPMSExtension
        /* check all screens, looking for DPMS Capabilities */
        DPMSCapableFlag = DPMSSupported();
        if (!DPMSCapableFlag)
            DPMSEnabled = FALSE;
#endif

#ifdef PANORAMIX
        /*
         * Consolidate window and colourmap information for each screen
         */
        if (!noPanoramiXExtension)
            PanoramiXConsolidate();
#endif

        for (i = 0; i < screenInfo.numScreens; i++)
            InitRootWindow(screenInfo.screens[i]->root);

        InitCoreDevices();
        InitInput(argc, argv);
        InitAndStartDevices();
        ReserveClientIds(serverClient);

        dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);

#ifdef PANORAMIX
        if (!noPanoramiXExtension) {
            if (!PanoramiXCreateConnectionBlock()) {
                FatalError("could not create connection block info");
            }
        }
        else
#endif
        {
            if (!CreateConnectionBlock()) {
                FatalError("could not create connection block info");
            }
        }

#ifdef XQUARTZ
        /* Let the other threads know the server is done with its init */
        pthread_mutex_lock(&serverRunningMutex);
        serverRunning = TRUE;
        pthread_cond_broadcast(&serverRunningCond);
        pthread_mutex_unlock(&serverRunningMutex);
#endif

        NotifyParentProcess();

        Dispatch();

#ifdef XQUARTZ
        /* Let the other threads know the server is no longer running */
        pthread_mutex_lock(&serverRunningMutex);
        serverRunning = FALSE;
        pthread_mutex_unlock(&serverRunningMutex);
#endif

        UndisplayDevices();
        DisableAllDevices();

        /* Now free up whatever must be freed */
        if (screenIsSaved == SCREEN_SAVER_ON)
            dixSaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
        FreeScreenSaverTimer();
        CloseDownExtensions();

#ifdef PANORAMIX
        {
            Bool remember_it = noPanoramiXExtension;

            noPanoramiXExtension = TRUE;
            FreeAllResources();
            noPanoramiXExtension = remember_it;
        }
#else
        FreeAllResources();
#endif

        CloseInput();

        for (i = 0; i < screenInfo.numScreens; i++)
            screenInfo.screens[i]->root = NullWindow;

        CloseDownDevices();

        CloseDownEvents();

        for (i = screenInfo.numGPUScreens - 1; i >= 0; i--) {
            ScreenPtr pScreen = screenInfo.gpuscreens[i];
            FreeScratchPixmapsForScreen(pScreen);
            (*pScreen->CloseScreen) (pScreen);
            dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN);
            free(pScreen);
            screenInfo.numGPUScreens = i;
        }

        for (i = screenInfo.numScreens - 1; i >= 0; i--) {
            FreeScratchPixmapsForScreen(screenInfo.screens[i]);
            FreeGCperDepth(i);
            FreeDefaultStipple(i);
            dixFreeScreenSpecificPrivates(screenInfo.screens[i]);
            (*screenInfo.screens[i]->CloseScreen) (screenInfo.screens[i]);
            dixFreePrivates(screenInfo.screens[i]->devPrivates, PRIVATE_SCREEN);
            free(screenInfo.screens[i]);
            screenInfo.numScreens = i;
        }

        ReleaseClientIds(serverClient);
        dixFreePrivates(serverClient->devPrivates, PRIVATE_CLIENT);
        serverClient->devPrivates = NULL;

        FreeFonts();

        FreeAuditTimer();

        if (dispatchException & DE_TERMINATE) {
            CloseWellKnownConnections();
        }

        OsCleanup((dispatchException & DE_TERMINATE) != 0);

        if (dispatchException & DE_TERMINATE) {
            ddxGiveUp(EXIT_NO_ERROR);
            break;
        }

        free(ConnectionInfo);
        ConnectionInfo = NULL;
    }
    return 0;
}
Example #15
0
File: main.c Project: theqvd/vcxsrv
int
dix_main(int argc, char *argv[], char *envp[])
{
    int i;
    HWEventQueueType alwaysCheckForInput[2];
    #ifdef _DEBUG
    //int TmpFlag=_CrtSetDbgFlag( _CRTDBG_REPORT_FLAG);
    
    //TmpFlag|=_CRTDBG_ALLOC_MEM_DF;
    //TmpFlag|=_CRTDBG_DELAY_FREE_MEM_DF;
    //TmpFlag|=_CRTDBG_CHECK_ALWAYS_DF;
    //TmpFlag|=_CRTDBG_CHECK_CRT_DF;
    //TmpFlag|=_CRTDBG_LEAK_CHECK_DF;
    
    //_CrtSetDbgFlag(TmpFlag);
    #endif

    ptw32_processInitialize();
    display = "0";

    #ifdef WIN32

    if (InitWSA()<0)
    {
      printf("Error initialising WSA\n");
      return -1;
    }
    /* In Win32 we have different threads call Xlib functions (depending
       on the commandline options given).
       XInitThreads has to be called before
       any xlib function is called (aoccording to the man page) */
    XInitThreads();
    /* change the current directory to the directory where the vcxsrv.exe executable is installed.
       This is needed because the font directories are relative to the current directory.
     */
     {
       char ModuleFilename[MAX_PATH];
       char *pSlash;
       GetModuleFileName(NULL,ModuleFilename,sizeof(ModuleFilename));
       pSlash=strrchr(ModuleFilename,'\\');
       if (pSlash)
       {
         *pSlash='\0';
         chdir(ModuleFilename);
       }
     }
    OsVendorPreInit(argc, argv);
    #endif

    InitRegions();

    CheckUserParameters(argc, argv, envp);

    CheckUserAuthorization();

    InitConnectionLimits();

    ProcessCommandLine(argc, argv);

    alwaysCheckForInput[0] = 0;
    alwaysCheckForInput[1] = 1;
    while (1) {
        serverGeneration++;
        ScreenSaverTime = defaultScreenSaverTime;
        ScreenSaverInterval = defaultScreenSaverInterval;
        ScreenSaverBlanking = defaultScreenSaverBlanking;
        ScreenSaverAllowExposures = defaultScreenSaverAllowExposures;
#ifdef DPMSExtension
        DPMSStandbyTime = DPMSSuspendTime = DPMSOffTime = ScreenSaverTime;
        DPMSEnabled = TRUE;
        DPMSPowerLevel = 0;
#endif
        InitBlockAndWakeupHandlers();
        /* Perform any operating system dependent initializations you'd like */
        if (serverGeneration == 1) {
            CreateWellKnownSockets();
            for (i = 1; i < MAXCLIENTS; i++)
                clients[i] = NullClient;
            serverClient = calloc(sizeof(ClientRec), 1);
            if (!serverClient)
                FatalError("couldn't create server client");
            InitClient(serverClient, 0, (void *) NULL);
        }
        else
            ResetWellKnownSockets();
        clients[0] = serverClient;
        currentMaxClients = 1;
        OsInit();

        /* clear any existing selections */
        InitSelections();

        /* Initialize privates before first allocation */
        dixResetPrivates();

        /* Initialize server client devPrivates, to be reallocated as
         * more client privates are registered
         */
        if (!dixAllocatePrivates(&serverClient->devPrivates, PRIVATE_CLIENT))
            FatalError("failed to create server client privates");

        if (!InitClientResources(serverClient)) /* for root resources */
            FatalError("couldn't init server resources");

        SetInputCheck(&alwaysCheckForInput[0], &alwaysCheckForInput[1]);
        screenInfo.numScreens = 0;

        InitAtoms();
        InitEvents();
        InitGlyphCaching();
        dixResetRegistry();
        ResetFontPrivateIndex();
        InitCallbackManager();
        InitOutput(&screenInfo, argc, argv);

        if (screenInfo.numScreens < 1)
            FatalError("no screens found");
        InitExtensions(argc, argv);

        for (i = 0; i < screenInfo.numGPUScreens; i++) {
            ScreenPtr pScreen = screenInfo.gpuscreens[i];
            if (!CreateScratchPixmapsForScreen(pScreen))
                FatalError("failed to create scratch pixmaps");
            if (pScreen->CreateScreenResources &&
                !(*pScreen->CreateScreenResources) (pScreen))
                FatalError("failed to create screen resources");
        }

        for (i = 0; i < screenInfo.numScreens; i++) {
            ScreenPtr pScreen = screenInfo.screens[i];

            if (!CreateScratchPixmapsForScreen(pScreen))
                FatalError("failed to create scratch pixmaps");
            if (pScreen->CreateScreenResources &&
                !(*pScreen->CreateScreenResources) (pScreen))
                FatalError("failed to create screen resources");
            if (!CreateGCperDepth(i))
                FatalError("failed to create scratch GCs");
            if (!CreateDefaultStipple(i))
                FatalError("failed to create default stipple");
            if (!CreateRootWindow(pScreen))
                FatalError("failed to create root window");
        }

        InitFonts();
        if (SetDefaultFontPath(defaultFontPath) != Success) {
            ErrorF("[dix] failed to set default font path '%s'",
                   defaultFontPath);
        }
        if (!SetDefaultFont(defaultTextFont)) {
            FatalError("could not open default font '%s'", defaultTextFont);
        }

        if (!(rootCursor = CreateRootCursor(NULL, 0))) {
            FatalError("could not open default cursor font '%s'",
                       defaultCursorFont);
        }

#ifdef DPMSExtension
        /* check all screens, looking for DPMS Capabilities */
        DPMSCapableFlag = DPMSSupported();
        if (!DPMSCapableFlag)
            DPMSEnabled = FALSE;
#endif

#ifdef PANORAMIX
        /*
         * Consolidate window and colourmap information for each screen
         */
        if (!noPanoramiXExtension)
            PanoramiXConsolidate();
#endif

        for (i = 0; i < screenInfo.numScreens; i++)
            InitRootWindow(screenInfo.screens[i]->root);

        InitCoreDevices();
        InitInput(argc, argv);
        InitAndStartDevices();
        ReserveClientIds(serverClient);

        dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);

        dixCloseRegistry();

#ifdef PANORAMIX
        if (!noPanoramiXExtension) {
            if (!PanoramiXCreateConnectionBlock()) {
                FatalError("could not create connection block info");
            }
        }
        else
#endif
        {
            if (!CreateConnectionBlock()) {
                FatalError("could not create connection block info");
            }
        }

#ifdef XQUARTZ
        /* Let the other threads know the server is done with its init */
        pthread_mutex_lock(&serverRunningMutex);
        serverRunning = TRUE;
        pthread_cond_broadcast(&serverRunningCond);
        pthread_mutex_unlock(&serverRunningMutex);
#endif

        NotifyParentProcess();

        #ifdef _MSC_VER
        // initialise here because doing it in InitInput failes because keyboard device is not started yet then
        winInitializeModeKeyStates ();
        #endif

        Dispatch();

#ifdef XQUARTZ
        /* Let the other threads know the server is no longer running */
        pthread_mutex_lock(&serverRunningMutex);
        serverRunning = FALSE;
        pthread_mutex_unlock(&serverRunningMutex);
#endif

        UndisplayDevices();
        DisableAllDevices();

        /* Now free up whatever must be freed */
        if (screenIsSaved == SCREEN_SAVER_ON)
            dixSaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
        FreeScreenSaverTimer();
        CloseDownExtensions();

#ifdef PANORAMIX
        {
            Bool remember_it = noPanoramiXExtension;

            noPanoramiXExtension = TRUE;
            FreeAllResources();
            noPanoramiXExtension = remember_it;
        }
#else
        FreeAllResources();
#endif

        CloseInput();

        for (i = 0; i < screenInfo.numScreens; i++)
            screenInfo.screens[i]->root = NullWindow;

        CloseDownDevices();

        CloseDownEvents();

        for (i = screenInfo.numGPUScreens - 1; i >= 0; i--) {
            ScreenPtr pScreen = screenInfo.gpuscreens[i];
            FreeScratchPixmapsForScreen(pScreen);
            (*pScreen->CloseScreen) (pScreen);
            dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN);
            free(pScreen);
            screenInfo.numGPUScreens = i;
        }

        for (i = screenInfo.numScreens - 1; i >= 0; i--) {
            FreeScratchPixmapsForScreen(screenInfo.screens[i]);
            FreeGCperDepth(i);
            FreeDefaultStipple(i);
            dixFreeScreenSpecificPrivates(screenInfo.screens[i]);
            (*screenInfo.screens[i]->CloseScreen) (screenInfo.screens[i]);
            dixFreePrivates(screenInfo.screens[i]->devPrivates, PRIVATE_SCREEN);
            free(screenInfo.screens[i]);
            screenInfo.numScreens = i;
        }

        ReleaseClientIds(serverClient);
        dixFreePrivates(serverClient->devPrivates, PRIVATE_CLIENT);
        serverClient->devPrivates = NULL;

	dixFreeRegistry();

        FreeFonts();

        FreeAllAtoms();

        FreeAuditTimer();

        DeleteCallbackManager();

        if (dispatchException & DE_TERMINATE) {
            CloseWellKnownConnections();
        }

        OsCleanup((dispatchException & DE_TERMINATE) != 0);

        if (dispatchException & DE_TERMINATE) {
            ddxGiveUp(EXIT_NO_ERROR);
            break;
        }

        free(ConnectionInfo);
        ConnectionInfo = NULL;
    }
    return 0;
}