예제 #1
0
	KviIpcSentinel::KviIpcSentinel()
	: QWidget(0)
	{
		setObjectName("kvirc4_ipc_sentinel");
#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
		setWindowTitle("kvirc4_ipc_sentinel");
		setWindowFlags(Qt::FramelessWindowHint);
#else
	#if defined(COMPILE_X11_SUPPORT) && defined(COMPILE_QX11INFO_SUPPORT)
		kvi_ipcLoadAtoms();

		XChangeProperty(kvi_ipc_get_xdisplay(),winId(),kvi_atom_ipc_sentinel_window,XA_STRING,8,
			PropModeReplace,(const unsigned char *)kvi_sentinel_id.ptr(),kvi_sentinel_id.len());

		kvi_ipcSetRemoteCommand(winId(),"");
	#endif //!COMPILE_NO_X
#endif

		move(-50,-50);
		resize(1,1);
#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
		// we need to show the window once otherwise it will never get "realized"
		// and we will not be able to find it via FindWindow()
		show();
#endif
		hide();

	}
예제 #2
0
	bool kvi_sendIpcMessage(const char * message)
	{
#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)

		HWND hSentinel = kvi_win_findIpcSentinel();
		if(hSentinel != NULL)
		{
			COPYDATASTRUCT cpd;
			cpd.cbData = strlen(message)+1;
			cpd.dwData = KVI_WINDOWS_IPC_MESSAGE;
			cpd.lpData = (void *)message;
			DWORD_PTR dwResult;

			if(!::SendMessageTimeout(hSentinel,WM_COPYDATA,(WPARAM)NULL,(LPARAM)&cpd,SMTO_BLOCK,1000,&dwResult))
			{
				qDebug("Failed to send IPC message: error code 0x%x",::GetLastError());
			}
			return true;
		}
#else
	#if defined(COMPILE_X11_SUPPORT) && defined(COMPILE_QX11INFO_SUPPORT)

		kvi_ipcLoadAtoms();

		Window sentinel = kvi_x11_findIpcSentinel(kvi_ipc_get_xrootwin());
		if(sentinel != 0)
		{
//			XChangeProperty(kvi_ipc_get_xdisplay(),sentinel,kvi_atom_ipc_remote_command,XA_STRING,8,
//				PropModeReplace,(const unsigned char *)message,kvi_strLen(message));
			kvi_ipcSetRemoteCommand(sentinel,message);

#if (QT_VERSION < 0x050000)

			XEvent e;
			KviMemory::set(&e,0,sizeof(XEvent));
			e.type = ClientMessage;
			e.xclient.display = kvi_ipc_get_xdisplay();
			e.xclient.window = sentinel;
			e.xclient.message_type = kvi_atom_ipc_remote_message;
			e.xclient.format = 8;

			Status ret = XSendEvent(kvi_ipc_get_xdisplay(),sentinel,False,0,&e);
#else
			// On Qt5 the ClientMessage events aren't propagated at all.. we have to rely on the property change only
#endif

			return true;
		}
	#endif //!COMPILE_NO_X
#endif
		return false;
	}
예제 #3
0
bool kvi_sendIpcMessage(const char * message)
{
#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
	HWND hSentinel = ::FindWindow(TEXT("Qt5QWindowIcon"), TEXT("kvirc4_ipc_sentinel"));
	if(hSentinel != nullptr)
	{
		COPYDATASTRUCT cpd;
		cpd.cbData = strlen(message) + 1;
		cpd.dwData = KVI_WINDOWS_IPC_MESSAGE;
		cpd.lpData = (void *)message;
		DWORD_PTR dwResult;

		if(!::SendMessageTimeout(hSentinel, WM_COPYDATA, (WPARAM)nullptr, (LPARAM)&cpd, SMTO_BLOCK, 1000, &dwResult))
		{
			DWORD errorMessageID = ::GetLastError();
			if (errorMessageID)
			{
				LPSTR messageBuffer = nullptr;
				size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
											 nullptr, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, nullptr);

				std::string winMessage(messageBuffer, size);

				//Free the buffer.
				LocalFree(messageBuffer);
				qDebug("Failed to send IPC message: %s", winMessage.c_str());
			}
			else
			{
				qDebug("Failed to send IPC message.");
			}
		}
		return true;
	}
#elif defined(COMPILE_X11_SUPPORT) && defined(COMPILE_QX11INFO_SUPPORT)

	kvi_ipcLoadAtoms();

	Window sentinel = kvi_x11_findIpcSentinel(kvi_ipc_get_xrootwin());
	if(sentinel != 0)
	{
		kvi_ipcSetRemoteCommand(sentinel, message);
		return true;
	}
#endif //!COMPILE_NO_X && COMPILE_ON_WINDOWS
	return false;
}