Esempio n. 1
0
void
MSWindowsHook::loadLibrary()
{
	// load library
	m_instance = LoadLibrary(g_name);
	if (m_instance == NULL) {
		LOG((CLOG_ERR "failed to load hook library, %s.dll is missing or invalid", g_name));
		throw XScreenOpenFailure();
	}

	// look up functions
	m_setSidesFunc = (SetSidesFunc)GetProcAddress(m_instance, "setSides");
	m_setZoneFunc = (SetZoneFunc)GetProcAddress(m_instance, "setZone");
	m_setModeFunc = (SetModeFunc)GetProcAddress(m_instance, "setMode");
	m_initFunc = (InitFunc)GetProcAddress(m_instance, "init");
	m_cleanupFunc = (CleanupFunc)GetProcAddress(m_instance, "cleanup");

	if (m_setSidesFunc == NULL ||
		m_setZoneFunc == NULL ||
		m_setModeFunc == NULL ||
		m_initFunc == NULL ||
		m_cleanupFunc == NULL) {
		LOG((CLOG_ERR "failed to load hook function, %s.dll could be out of date", g_name));
		throw XScreenOpenFailure();
	}

	// initialize library
	if (init(GetCurrentThreadId()) == 0) {
		LOG((CLOG_ERR "failed to init %s.dll, another program may be using it", g_name));
		LOG((CLOG_INFO "restarting your computer may solve this error"));
		throw XScreenOpenFailure();
	}
}
void
CXWindowsPrimaryScreen::createWindow()
{
	assert(m_window == None);

	// get size of screen
	SInt32 x, y, w, h;
	m_screen->getShape(x, y, w, h);

	// grab window attributes.  this window is used to capture user
	// input when the user is focused on another client.  don't let
	// the window manager mess with it.
	XSetWindowAttributes attr;
	attr.event_mask            = PointerMotionMask |
								 ButtonPressMask | ButtonReleaseMask |
								 KeyPressMask | KeyReleaseMask |
								 KeymapStateMask | PropertyChangeMask;
	attr.do_not_propagate_mask = 0;
	attr.override_redirect     = True;
	attr.cursor                = m_screen->getBlankCursor();

	{
		// create the grab window
		CDisplayLock display(m_screen);
		m_window = XCreateWindow(display, m_screen->getRoot(),
								x, y, w, h, 0, 0,
								InputOnly, CopyFromParent,
								CWDontPropagate | CWEventMask |
								CWOverrideRedirect | CWCursor,
								&attr);
		if (m_window == None) {
			throw XScreenOpenFailure();
		}
		LOG((CLOG_DEBUG "window is 0x%08x", m_window));

		// start watching for events on other windows
		selectEvents(display, m_screen->getRoot());
	}

	// tell generic screen about the window
	m_screen->setWindow(m_window);
}