michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:expandtab:shiftwidth=2:tabstop=8: michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #include michael@0: #include "nsQtRemoteService.h" michael@0: michael@0: #include "mozilla/ModuleUtils.h" michael@0: #include "mozilla/X11Util.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsIAppShellService.h" michael@0: michael@0: #include "nsCOMPtr.h" michael@0: michael@0: /** michael@0: Helper class which is used to receive notification about property changes michael@0: */ michael@0: class MozQRemoteEventHandlerWidget: public QWindow { michael@0: public: michael@0: /** michael@0: Constructor michael@0: @param aRemoteService remote service, which is notified about atom change michael@0: */ michael@0: MozQRemoteEventHandlerWidget(nsQtRemoteService &aRemoteService); michael@0: virtual ~MozQRemoteEventHandlerWidget() {} michael@0: michael@0: protected: michael@0: /** michael@0: Event filter, which receives all XEvents michael@0: @return false which continues event handling michael@0: */ michael@0: bool x11Event(XEvent *); michael@0: michael@0: private: michael@0: /** michael@0: Service which is notified about property change michael@0: */ michael@0: nsQtRemoteService &mRemoteService; michael@0: }; michael@0: michael@0: MozQRemoteEventHandlerWidget::MozQRemoteEventHandlerWidget(nsQtRemoteService &aRemoteService) michael@0: :mRemoteService(aRemoteService) michael@0: { michael@0: } michael@0: michael@0: bool michael@0: MozQRemoteEventHandlerWidget::x11Event(XEvent *aEvt) michael@0: { michael@0: if (aEvt->type == PropertyNotify && aEvt->xproperty.state == PropertyNewValue) michael@0: mRemoteService.PropertyNotifyEvent(aEvt); michael@0: michael@0: return false; michael@0: } michael@0: michael@0: NS_IMPL_ISUPPORTS(nsQtRemoteService, michael@0: nsIRemoteService, michael@0: nsIObserver) michael@0: michael@0: nsQtRemoteService::nsQtRemoteService(): michael@0: mServerWindow(0) michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsQtRemoteService::Startup(const char* aAppName, const char* aProfileName) michael@0: { michael@0: if (mServerWindow) return NS_ERROR_ALREADY_INITIALIZED; michael@0: NS_ASSERTION(aAppName, "Don't pass a null appname!"); michael@0: michael@0: XRemoteBaseStartup(aAppName,aProfileName); michael@0: michael@0: //Create window, which is not shown. michael@0: mServerWindow = new MozQRemoteEventHandlerWidget(*this); michael@0: michael@0: HandleCommandsFor(mServerWindow->winId()); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsQtRemoteService::RegisterWindow(nsIDOMWindow* aWindow) michael@0: { michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsQtRemoteService::Shutdown() michael@0: { michael@0: if (!mServerWindow) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: michael@0: delete mServerWindow; michael@0: mServerWindow = nullptr; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: void michael@0: nsQtRemoteService::PropertyNotifyEvent(XEvent *aEvt) michael@0: { michael@0: HandleNewProperty(aEvt->xproperty.window, michael@0: mozilla::DefaultXDisplay(), michael@0: aEvt->xproperty.time, michael@0: aEvt->xproperty.atom, michael@0: 0); michael@0: } michael@0: michael@0: void michael@0: nsQtRemoteService::SetDesktopStartupIDOrTimestamp(const nsACString& aDesktopStartupID, michael@0: uint32_t aTimestamp) michael@0: { michael@0: } michael@0: michael@0: // {C0773E90-5799-4eff-AD03-3EBCD85624AC} michael@0: #define NS_REMOTESERVICE_CID \ michael@0: { 0xc0773e90, 0x5799, 0x4eff, { 0xad, 0x3, 0x3e, 0xbc, 0xd8, 0x56, 0x24, 0xac } } michael@0: michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsQtRemoteService) michael@0: NS_DEFINE_NAMED_CID(NS_REMOTESERVICE_CID); michael@0: michael@0: static const mozilla::Module::CIDEntry kRemoteCIDs[] = { michael@0: { &kNS_REMOTESERVICE_CID, false, nullptr, nsQtRemoteServiceConstructor }, michael@0: { nullptr } michael@0: }; michael@0: michael@0: static const mozilla::Module::ContractIDEntry kRemoteContracts[] = { michael@0: { "@mozilla.org/toolkit/remote-service;1", &kNS_REMOTESERVICE_CID }, michael@0: { nullptr } michael@0: }; michael@0: michael@0: static const mozilla::Module kRemoteModule = { michael@0: mozilla::Module::kVersion, michael@0: kRemoteCIDs, michael@0: kRemoteContracts michael@0: }; michael@0: michael@0: NSMODULE_DEFN(RemoteServiceModule) = &kRemoteModule;