|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:expandtab:shiftwidth=2:tabstop=8: |
|
3 */ |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 #include <QWindow> |
|
8 #include "nsQtRemoteService.h" |
|
9 |
|
10 #include "mozilla/ModuleUtils.h" |
|
11 #include "mozilla/X11Util.h" |
|
12 #include "nsIServiceManager.h" |
|
13 #include "nsIAppShellService.h" |
|
14 |
|
15 #include "nsCOMPtr.h" |
|
16 |
|
17 /** |
|
18 Helper class which is used to receive notification about property changes |
|
19 */ |
|
20 class MozQRemoteEventHandlerWidget: public QWindow { |
|
21 public: |
|
22 /** |
|
23 Constructor |
|
24 @param aRemoteService remote service, which is notified about atom change |
|
25 */ |
|
26 MozQRemoteEventHandlerWidget(nsQtRemoteService &aRemoteService); |
|
27 virtual ~MozQRemoteEventHandlerWidget() {} |
|
28 |
|
29 protected: |
|
30 /** |
|
31 Event filter, which receives all XEvents |
|
32 @return false which continues event handling |
|
33 */ |
|
34 bool x11Event(XEvent *); |
|
35 |
|
36 private: |
|
37 /** |
|
38 Service which is notified about property change |
|
39 */ |
|
40 nsQtRemoteService &mRemoteService; |
|
41 }; |
|
42 |
|
43 MozQRemoteEventHandlerWidget::MozQRemoteEventHandlerWidget(nsQtRemoteService &aRemoteService) |
|
44 :mRemoteService(aRemoteService) |
|
45 { |
|
46 } |
|
47 |
|
48 bool |
|
49 MozQRemoteEventHandlerWidget::x11Event(XEvent *aEvt) |
|
50 { |
|
51 if (aEvt->type == PropertyNotify && aEvt->xproperty.state == PropertyNewValue) |
|
52 mRemoteService.PropertyNotifyEvent(aEvt); |
|
53 |
|
54 return false; |
|
55 } |
|
56 |
|
57 NS_IMPL_ISUPPORTS(nsQtRemoteService, |
|
58 nsIRemoteService, |
|
59 nsIObserver) |
|
60 |
|
61 nsQtRemoteService::nsQtRemoteService(): |
|
62 mServerWindow(0) |
|
63 { |
|
64 } |
|
65 |
|
66 NS_IMETHODIMP |
|
67 nsQtRemoteService::Startup(const char* aAppName, const char* aProfileName) |
|
68 { |
|
69 if (mServerWindow) return NS_ERROR_ALREADY_INITIALIZED; |
|
70 NS_ASSERTION(aAppName, "Don't pass a null appname!"); |
|
71 |
|
72 XRemoteBaseStartup(aAppName,aProfileName); |
|
73 |
|
74 //Create window, which is not shown. |
|
75 mServerWindow = new MozQRemoteEventHandlerWidget(*this); |
|
76 |
|
77 HandleCommandsFor(mServerWindow->winId()); |
|
78 return NS_OK; |
|
79 } |
|
80 |
|
81 NS_IMETHODIMP |
|
82 nsQtRemoteService::RegisterWindow(nsIDOMWindow* aWindow) |
|
83 { |
|
84 return NS_ERROR_NOT_IMPLEMENTED; |
|
85 } |
|
86 |
|
87 NS_IMETHODIMP |
|
88 nsQtRemoteService::Shutdown() |
|
89 { |
|
90 if (!mServerWindow) |
|
91 return NS_ERROR_NOT_INITIALIZED; |
|
92 |
|
93 delete mServerWindow; |
|
94 mServerWindow = nullptr; |
|
95 |
|
96 return NS_OK; |
|
97 } |
|
98 |
|
99 void |
|
100 nsQtRemoteService::PropertyNotifyEvent(XEvent *aEvt) |
|
101 { |
|
102 HandleNewProperty(aEvt->xproperty.window, |
|
103 mozilla::DefaultXDisplay(), |
|
104 aEvt->xproperty.time, |
|
105 aEvt->xproperty.atom, |
|
106 0); |
|
107 } |
|
108 |
|
109 void |
|
110 nsQtRemoteService::SetDesktopStartupIDOrTimestamp(const nsACString& aDesktopStartupID, |
|
111 uint32_t aTimestamp) |
|
112 { |
|
113 } |
|
114 |
|
115 // {C0773E90-5799-4eff-AD03-3EBCD85624AC} |
|
116 #define NS_REMOTESERVICE_CID \ |
|
117 { 0xc0773e90, 0x5799, 0x4eff, { 0xad, 0x3, 0x3e, 0xbc, 0xd8, 0x56, 0x24, 0xac } } |
|
118 |
|
119 NS_GENERIC_FACTORY_CONSTRUCTOR(nsQtRemoteService) |
|
120 NS_DEFINE_NAMED_CID(NS_REMOTESERVICE_CID); |
|
121 |
|
122 static const mozilla::Module::CIDEntry kRemoteCIDs[] = { |
|
123 { &kNS_REMOTESERVICE_CID, false, nullptr, nsQtRemoteServiceConstructor }, |
|
124 { nullptr } |
|
125 }; |
|
126 |
|
127 static const mozilla::Module::ContractIDEntry kRemoteContracts[] = { |
|
128 { "@mozilla.org/toolkit/remote-service;1", &kNS_REMOTESERVICE_CID }, |
|
129 { nullptr } |
|
130 }; |
|
131 |
|
132 static const mozilla::Module kRemoteModule = { |
|
133 mozilla::Module::kVersion, |
|
134 kRemoteCIDs, |
|
135 kRemoteContracts |
|
136 }; |
|
137 |
|
138 NSMODULE_DEFN(RemoteServiceModule) = &kRemoteModule; |