Merge lp:~smspillaz/compiz-core/compiz-core.fix_900580 into lp:compiz-core/0.9.5
- compiz-core.fix_900580
- Merge into 0.9.5
Status: | Superseded |
---|---|
Proposed branch: | lp:~smspillaz/compiz-core/compiz-core.fix_900580 |
Merge into: | lp:compiz-core/0.9.5 |
Prerequisite: | lp:~smspillaz/compiz-core/compiz-core.merge_894639 |
Diff against target: |
3148 lines (+2575/-28) 32 files modified
include/core/CMakeLists.txt (+1/-0) include/core/asynchronous-container.h (+7/-1) include/core/asynchronous-object.h (+19/-1) include/core/asynchronous-server.h (+31/-5) include/core/container.h (+2/-1) include/core/managedstatebit.h (+114/-0) include/core/object.h (+43/-7) include/core/server-read.h (+5/-0) include/core/server-write.h (+11/-0) include/core/server.h (+17/-2) include/core/x11-object.h (+116/-0) include/core/x11-server.h (+140/-0) src/CMakeLists.txt (+4/-0) src/asynchronous-container.cpp (+40/-6) src/asynchronous-object.cpp (+57/-0) src/asynchronous-server.cpp (+25/-1) src/container.cpp (+2/-0) src/eventsource.cpp (+1/-0) src/managedstatebit.cpp (+173/-0) src/object.cpp (+92/-2) src/server-read.cpp (+11/-1) src/server-write.cpp (+19/-1) src/server.cpp (+13/-0) src/x11-container.cpp (+48/-0) src/x11-object.cpp (+84/-0) src/x11-server.cpp (+456/-0) tests/standalone/CMakeLists.txt (+1/-0) tests/standalone/objects/CMakeLists.txt (+23/-0) tests/standalone/objects/command-parser.cpp (+449/-0) tests/standalone/objects/command-parser.h (+190/-0) tests/standalone/objects/x11/CMakeLists.txt (+43/-0) tests/standalone/objects/x11/compiz-x11-object-tree-standalone.cpp (+338/-0) |
To merge this branch: | bzr merge lp:~smspillaz/compiz-core/compiz-core.fix_900580 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alan Griffiths | Needs Fixing | ||
Review via email: mp+88498@code.launchpad.net |
This proposal supersedes a proposal from 2011-12-14.
This proposal has been superseded by a proposal from 2012-01-21.
Commit message
Description of the change
Adds a parser and scriptable standalone wm part for testing
Next pipe: lp:~smspillaz/compiz-core/fix-903529
Alan Griffiths (alan-griffiths) wrote : Posted in a previous version of this proposal | # |
Alan Griffiths (alan-griffiths) wrote : | # |
The issues with src/managedstat
- 2996. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580.
Alan Griffiths (alan-griffiths) wrote : | # |
> The class ManagedStateBit is strange:
> o there are inline functions defined in the .cpp file - so is the class usable elsewhere?
> o in general, symmetric operators should be non-member functions.
> o are all these operators needed? The implicit conversion uint64_t to ought to cover most uses?
> o why isn't operator uint64_t() inline? (and in the header?)
Looked a bit closer:
The mutating operators do not need ManagedStateBit overloads as the "operator uint64_t() const" (which should be inline and in the header) and the corresponding uint64_t overloads provide the same functionality. The non-mutating operators are not needed as the uint64_t conversion operator with normal operations on uint64_t provide the same functionality.
(With that change there are no symmetric ops left to make non-members.)
On the face of it there is only ever one instance of this class - a public, static member variable of Object. Global data is usually a bad idea - and I don't see what justifies this case.
- 2997. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 2998. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 2999. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 3000. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 3001. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 3002. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 3003. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 3004. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 3005. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 3006. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 3007. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580.
Unmerged revisions
- 3007. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 3006. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 3005. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 3004. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 3003. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 3002. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 3001. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 3000. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 2999. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580. - 2998. By Sam Spilsbury
-
Merged compiz-
core.merge_ 894639 into compiz- core.fix_ 900580.
Preview Diff
1 | === modified file 'include/core/CMakeLists.txt' | |||
2 | --- include/core/CMakeLists.txt 2012-01-19 18:25:05 +0000 | |||
3 | +++ include/core/CMakeLists.txt 2012-01-19 18:25:06 +0000 | |||
4 | @@ -12,6 +12,7 @@ | |||
5 | 12 | icon.h | 12 | icon.h |
6 | 13 | match.h | 13 | match.h |
7 | 14 | modifierhandler.h | 14 | modifierhandler.h |
8 | 15 | managedstatebit.h | ||
9 | 15 | object.h | 16 | object.h |
10 | 16 | option.h | 17 | option.h |
11 | 17 | output.h | 18 | output.h |
12 | 18 | 19 | ||
13 | === modified file 'include/core/asynchronous-container.h' | |||
14 | --- include/core/asynchronous-container.h 2012-01-19 18:25:05 +0000 | |||
15 | +++ include/core/asynchronous-container.h 2012-01-19 18:25:06 +0000 | |||
16 | @@ -42,7 +42,7 @@ | |||
17 | 42 | class ReadServerConnection; | 42 | class ReadServerConnection; |
18 | 43 | 43 | ||
19 | 44 | class AsynchronousContainer : | 44 | class AsynchronousContainer : |
21 | 45 | public AsynchronousObject, | 45 | virtual public AsynchronousObject, |
22 | 46 | public Container | 46 | public Container |
23 | 47 | { | 47 | { |
24 | 48 | public: | 48 | public: |
25 | @@ -76,6 +76,12 @@ | |||
26 | 76 | void receiveInsertion (const Object::Ptr &); | 76 | void receiveInsertion (const Object::Ptr &); |
27 | 77 | void receiveRemoval (const Object::Ptr &); | 77 | void receiveRemoval (const Object::Ptr &); |
28 | 78 | 78 | ||
29 | 79 | virtual void onReceiveInsertion (const Object::Ptr &) {}; | ||
30 | 80 | virtual void onReceiveRemoval (const Object::Ptr &) {}; | ||
31 | 81 | |||
32 | 82 | virtual void onSendInsertion (const Object::Ptr &) {}; | ||
33 | 83 | virtual void onSendRemoval (const Object::Ptr &) {}; | ||
34 | 84 | |||
35 | 79 | void addSentInsertion (const Object::Ptr &); | 85 | void addSentInsertion (const Object::Ptr &); |
36 | 80 | Object::Ptr addSentRemoval (const Object::Ptr &); | 86 | Object::Ptr addSentRemoval (const Object::Ptr &); |
37 | 81 | 87 | ||
38 | 82 | 88 | ||
39 | === modified file 'include/core/asynchronous-object.h' | |||
40 | --- include/core/asynchronous-object.h 2012-01-19 18:25:05 +0000 | |||
41 | +++ include/core/asynchronous-object.h 2012-01-19 18:25:06 +0000 | |||
42 | @@ -66,18 +66,35 @@ | |||
43 | 66 | /* Most recent sent positions */ | 66 | /* Most recent sent positions */ |
44 | 67 | const compiz::window::Geometry &sentGeometry () const; | 67 | const compiz::window::Geometry &sentGeometry () const; |
45 | 68 | const compiz::window::StackPosition &sentStackPosition () const; | 68 | const compiz::window::StackPosition &sentStackPosition () const; |
46 | 69 | const uint64_t &sendState () const; | ||
47 | 69 | 70 | ||
48 | 70 | void sendGeometry (const compiz::window::Geometry &); | 71 | void sendGeometry (const compiz::window::Geometry &); |
49 | 71 | void sendStackPosition (const compiz::window::StackPosition &); | 72 | void sendStackPosition (const compiz::window::StackPosition &); |
50 | 73 | void sendAddState (uint64_t state); | ||
51 | 74 | void sendRemoveState (uint64_t state); | ||
52 | 72 | 75 | ||
53 | 73 | protected: | 76 | protected: |
54 | 74 | 77 | ||
55 | 75 | void receiveGeometry (const compiz::window::Geometry &); | 78 | void receiveGeometry (const compiz::window::Geometry &); |
56 | 76 | void receiveStackPosition (const compiz::window::StackPosition &); | 79 | void receiveStackPosition (const compiz::window::StackPosition &); |
58 | 77 | //void receiveMap (); | 80 | void receiveState (uint64_t addState, uint64_t removeState); |
59 | 78 | 81 | ||
60 | 79 | void addSentGeometry (const compiz::window::Geometry &); | 82 | void addSentGeometry (const compiz::window::Geometry &); |
61 | 80 | void addSentStackPosition (const compiz::window::StackPosition &); | 83 | void addSentStackPosition (const compiz::window::StackPosition &); |
62 | 84 | void addSentAddedState (uint64_t aState); | ||
63 | 85 | void addSentRemovedState (uint64_t rState); | ||
64 | 86 | |||
65 | 87 | virtual void onReceiveGeometry (const compiz::window::Geometry &) {}; | ||
66 | 88 | virtual void onReceiveStackPosition (const compiz::window::StackPosition &) {}; | ||
67 | 89 | virtual void onReceiveDeletion () {}; | ||
68 | 90 | virtual void onReceiveAddState (uint64_t) {} | ||
69 | 91 | virtual void onReceiveRemoveState (uint64_t) {} | ||
70 | 92 | |||
71 | 93 | virtual void onSendGeometry (const compiz::window::Geometry &) {}; | ||
72 | 94 | virtual void onSendStackPosition (const compiz::window::StackPosition &) {}; | ||
73 | 95 | virtual void onSendDeletion () {}; | ||
74 | 96 | virtual void onSendAddState (uint64_t) {} | ||
75 | 97 | virtual void onSendRemoveState (uint64_t) {} | ||
76 | 81 | 98 | ||
77 | 82 | boost::shared_ptr <WriteServerConnection> mWriteConnection; | 99 | boost::shared_ptr <WriteServerConnection> mWriteConnection; |
78 | 83 | 100 | ||
79 | @@ -87,6 +104,7 @@ | |||
80 | 87 | 104 | ||
81 | 88 | compiz::window::Geometry mSentGeometry; | 105 | compiz::window::Geometry mSentGeometry; |
82 | 89 | compiz::window::StackPosition mSentStackPosition; | 106 | compiz::window::StackPosition mSentStackPosition; |
83 | 107 | uint64_t mSentState; | ||
84 | 90 | }; | 108 | }; |
85 | 91 | } | 109 | } |
86 | 92 | } | 110 | } |
87 | 93 | 111 | ||
88 | === modified file 'include/core/asynchronous-server.h' | |||
89 | --- include/core/asynchronous-server.h 2012-01-19 18:25:05 +0000 | |||
90 | +++ include/core/asynchronous-server.h 2012-01-19 18:25:06 +0000 | |||
91 | @@ -36,6 +36,7 @@ | |||
92 | 36 | #include <core/stackposition.h> | 36 | #include <core/stackposition.h> |
93 | 37 | #include <core/object.h> | 37 | #include <core/object.h> |
94 | 38 | #include <glibmm/main.h> | 38 | #include <glibmm/main.h> |
95 | 39 | #include <stdint.h> | ||
96 | 39 | 40 | ||
97 | 40 | namespace compiz | 41 | namespace compiz |
98 | 41 | { | 42 | { |
99 | @@ -44,9 +45,20 @@ | |||
100 | 44 | 45 | ||
101 | 45 | class WriteServerConnection; | 46 | class WriteServerConnection; |
102 | 46 | 47 | ||
103 | 48 | class ObjectCreationRequest | ||
104 | 49 | { | ||
105 | 50 | public: | ||
106 | 51 | |||
107 | 52 | typedef boost::shared_ptr <ObjectCreationRequest> Ptr; | ||
108 | 53 | virtual ~ObjectCreationRequest (); | ||
109 | 54 | protected: | ||
110 | 55 | |||
111 | 56 | ObjectCreationRequest (); | ||
112 | 57 | }; | ||
113 | 58 | |||
114 | 59 | |||
115 | 47 | class AsynchronousServer : | 60 | class AsynchronousServer : |
118 | 48 | public Server, | 61 | public Server |
117 | 49 | public boost::enable_shared_from_this <AsynchronousServer> | ||
119 | 50 | { | 62 | { |
120 | 51 | public: | 63 | public: |
121 | 52 | 64 | ||
122 | @@ -54,8 +66,11 @@ | |||
123 | 54 | 66 | ||
124 | 55 | virtual ~AsynchronousServer (); | 67 | virtual ~AsynchronousServer (); |
125 | 56 | 68 | ||
126 | 69 | static const unsigned int BlockUntilCompletion = (1 << 0); | ||
127 | 70 | static const unsigned int DiscardGeneratedEvents = (1 << 0); | ||
128 | 71 | |||
129 | 57 | boost::shared_ptr <WriteServerConnection> connect (); | 72 | boost::shared_ptr <WriteServerConnection> connect (); |
131 | 58 | 73 | void flush (unsigned int); | |
132 | 59 | protected: | 74 | protected: |
133 | 60 | 75 | ||
134 | 61 | AsynchronousServer (); | 76 | AsynchronousServer (); |
135 | @@ -67,10 +82,21 @@ | |||
136 | 67 | virtual void sendParent (const ObjectIdentifier::Ptr &, | 82 | virtual void sendParent (const ObjectIdentifier::Ptr &, |
137 | 68 | const ObjectIdentifier::Ptr &) = 0; | 83 | const ObjectIdentifier::Ptr &) = 0; |
138 | 69 | 84 | ||
139 | 85 | virtual void sendCreateObject (const boost::shared_ptr <ObjectCreationRequest> &) = 0; | ||
140 | 86 | virtual void sendDeleteObject (const ObjectIdentifier::Ptr &) = 0; | ||
141 | 87 | virtual void sendState (const ObjectIdentifier::Ptr &, uint64_t aState, uint64_t rState) = 0; | ||
142 | 88 | |||
143 | 89 | virtual void dispatchRequests (unsigned int) = 0; | ||
144 | 90 | |||
145 | 91 | void setEventSource (const Glib::RefPtr <Glib::Source> &); | ||
146 | 92 | |||
147 | 70 | compiz::window::ReadServerConnection::Ptr mReadConnection; | 93 | compiz::window::ReadServerConnection::Ptr mReadConnection; |
148 | 94 | |||
149 | 95 | friend class WriteServerConnection; | ||
150 | 96 | |||
151 | 97 | private: | ||
152 | 98 | |||
153 | 71 | Glib::RefPtr <Glib::Source> mEventSource; | 99 | Glib::RefPtr <Glib::Source> mEventSource; |
154 | 72 | |||
155 | 73 | friend class WriteServerConnection; | ||
156 | 74 | }; | 100 | }; |
157 | 75 | 101 | ||
158 | 76 | } | 102 | } |
159 | 77 | 103 | ||
160 | === modified file 'include/core/container.h' | |||
161 | --- include/core/container.h 2012-01-19 18:25:05 +0000 | |||
162 | +++ include/core/container.h 2012-01-19 18:25:06 +0000 | |||
163 | @@ -38,7 +38,8 @@ | |||
164 | 38 | { | 38 | { |
165 | 39 | 39 | ||
166 | 40 | class Container : | 40 | class Container : |
168 | 41 | virtual public Object | 41 | virtual public Object, |
169 | 42 | public boost::enable_shared_from_this <Container> | ||
170 | 42 | { | 43 | { |
171 | 43 | public: | 44 | public: |
172 | 44 | 45 | ||
173 | 45 | 46 | ||
174 | === added file 'include/core/managedstatebit.h' | |||
175 | --- include/core/managedstatebit.h 1970-01-01 00:00:00 +0000 | |||
176 | +++ include/core/managedstatebit.h 2012-01-19 18:25:06 +0000 | |||
177 | @@ -0,0 +1,114 @@ | |||
178 | 1 | /* | ||
179 | 2 | * Copyright © 2011 Canonical Ltd. | ||
180 | 3 | * | ||
181 | 4 | * Permission to use, copy, modify, distribute, and sell this software | ||
182 | 5 | * and its documentation for any purpose is hereby granted without | ||
183 | 6 | * fee, provided that the above copyright notice appear in all copies | ||
184 | 7 | * and that both that copyright notice and this permission notice | ||
185 | 8 | * appear in supporting documentation, and that the name of | ||
186 | 9 | * Dennis Kasprzyk not be used in advertising or publicity pertaining to | ||
187 | 10 | * distribution of the software without specific, written prior permission. | ||
188 | 11 | * Dennis Kasprzyk makes no representations about the suitability of this | ||
189 | 12 | * software for any purpose. It is provided "as is" without express or | ||
190 | 13 | * implied warranty. | ||
191 | 14 | * | ||
192 | 15 | * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
193 | 16 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN | ||
194 | 17 | * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
195 | 18 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
196 | 19 | * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | ||
197 | 20 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | ||
198 | 21 | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
199 | 22 | * | ||
200 | 23 | * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org> | ||
201 | 24 | * David Reveman <davidr@novell.com> | ||
202 | 25 | */ | ||
203 | 26 | |||
204 | 27 | #ifndef _COMPIZ_MANAGED_STATE_BIT_H | ||
205 | 28 | #define _COMPIZ_MANAGED_STATE_BIT_H | ||
206 | 29 | |||
207 | 30 | #include <stdint.h> | ||
208 | 31 | #include <boost/noncopyable.hpp> | ||
209 | 32 | #include <vector> | ||
210 | 33 | |||
211 | 34 | namespace compiz | ||
212 | 35 | { | ||
213 | 36 | namespace window | ||
214 | 37 | { | ||
215 | 38 | |||
216 | 39 | /** | ||
217 | 40 | * Static class of managed states | ||
218 | 41 | */ | ||
219 | 42 | class ManagedStates | ||
220 | 43 | { | ||
221 | 44 | public: | ||
222 | 45 | |||
223 | 46 | static bool registerState (uint64_t &stateBit); | ||
224 | 47 | static bool unregisterState (uint64_t &stateBit); | ||
225 | 48 | |||
226 | 49 | private: | ||
227 | 50 | |||
228 | 51 | ManagedStates () {}; | ||
229 | 52 | ~ManagedStates () {}; | ||
230 | 53 | |||
231 | 54 | /* singleton state bit base | ||
232 | 55 | * use this to determine the number | ||
233 | 56 | * of state bits remaining for implementations | ||
234 | 57 | * to use. The protected functions registerState | ||
235 | 58 | * and unregisterState will manage free space | ||
236 | 59 | * in the state bits */ | ||
237 | 60 | static uint64_t stateBase; | ||
238 | 61 | |||
239 | 62 | /* The vector keeps track of pointers to all | ||
240 | 63 | * of the state bit identifiers, they are modified | ||
241 | 64 | * at runtime depending on free space within | ||
242 | 65 | * the state base */ | ||
243 | 66 | static std::vector <uint64_t *> managedStateBits; | ||
244 | 67 | }; | ||
245 | 68 | |||
246 | 69 | /** | ||
247 | 70 | * An RAII managed state bit definition class, | ||
248 | 71 | * by holding an instance of this class, a unique | ||
249 | 72 | * bitmask is registered with the singleton list | ||
250 | 73 | * in Object which is used to identify a particular | ||
251 | 74 | * state of the object. The actual value of the | ||
252 | 75 | * underlying bitmask can change depending on the free | ||
253 | 76 | * space in the total number of bits available in Object */ | ||
254 | 77 | class ManagedStateBit : | ||
255 | 78 | boost::noncopyable | ||
256 | 79 | { | ||
257 | 80 | public: | ||
258 | 81 | |||
259 | 82 | ManagedStateBit (); | ||
260 | 83 | ~ManagedStateBit (); | ||
261 | 84 | |||
262 | 85 | inline uint64_t operator~ () const; | ||
263 | 86 | inline uint64_t operator& (const uint64_t &i) const; | ||
264 | 87 | inline uint64_t operator& (const ManagedStateBit &b) const; | ||
265 | 88 | inline uint64_t operator| (const uint64_t &i) const; | ||
266 | 89 | inline uint64_t operator| (const ManagedStateBit &b) const; | ||
267 | 90 | inline uint64_t operator^ (const uint64_t &i) const; | ||
268 | 91 | inline uint64_t operator^ (const ManagedStateBit &b) const; | ||
269 | 92 | |||
270 | 93 | inline uint64_t operator&= (const uint64_t &i); | ||
271 | 94 | inline uint64_t operator&= (const ManagedStateBit &b); | ||
272 | 95 | inline uint64_t operator|= (const uint64_t &i); | ||
273 | 96 | inline uint64_t operator|= (const ManagedStateBit &b); | ||
274 | 97 | inline uint64_t operator^= (const uint64_t &i); | ||
275 | 98 | inline uint64_t operator^= (const ManagedStateBit &b); | ||
276 | 99 | |||
277 | 100 | inline bool operator== (const uint64_t &i) const; | ||
278 | 101 | inline bool operator== (const ManagedStateBit &b) const; | ||
279 | 102 | inline bool operator!= (const uint64_t &i) const; | ||
280 | 103 | inline bool operator!= (const ManagedStateBit &b) const; | ||
281 | 104 | |||
282 | 105 | operator uint64_t () const; | ||
283 | 106 | private: | ||
284 | 107 | |||
285 | 108 | uint64_t mStateBit; | ||
286 | 109 | }; | ||
287 | 110 | |||
288 | 111 | } | ||
289 | 112 | } | ||
290 | 113 | |||
291 | 114 | #endif | ||
292 | 0 | 115 | ||
293 | === modified file 'include/core/object.h' | |||
294 | --- include/core/object.h 2012-01-19 18:25:05 +0000 | |||
295 | +++ include/core/object.h 2012-01-19 18:25:06 +0000 | |||
296 | @@ -30,7 +30,9 @@ | |||
297 | 30 | #include <boost/shared_ptr.hpp> | 30 | #include <boost/shared_ptr.hpp> |
298 | 31 | #include <core/windowgeometry.h> | 31 | #include <core/windowgeometry.h> |
299 | 32 | #include <core/stackposition.h> | 32 | #include <core/stackposition.h> |
300 | 33 | #include <core/managedstatebit.h> | ||
301 | 33 | #include <boost/enable_shared_from_this.hpp> | 34 | #include <boost/enable_shared_from_this.hpp> |
302 | 35 | #include <stdint.h> | ||
303 | 34 | 36 | ||
304 | 35 | namespace compiz | 37 | namespace compiz |
305 | 36 | { | 38 | { |
306 | @@ -65,16 +67,16 @@ | |||
307 | 65 | bool operator== (const ObjectIdentifier::Ptr &) const; | 67 | bool operator== (const ObjectIdentifier::Ptr &) const; |
308 | 66 | bool operator!= (const ObjectIdentifier::Ptr &) const; | 68 | bool operator!= (const ObjectIdentifier::Ptr &) const; |
309 | 67 | 69 | ||
311 | 68 | bool equal (const ObjectIdentifier::Ptr &) const; | 70 | bool equal (const ObjectIdentifier::Ptr &) const; |
312 | 69 | 71 | ||
315 | 70 | const boost::shared_ptr <Object> & operator() (); | 72 | boost::shared_ptr <Object> operator() (); |
316 | 71 | const boost::shared_ptr <Object> & operator() () const; | 73 | boost::shared_ptr <Object> operator() () const; |
317 | 72 | 74 | ||
318 | 73 | protected: | 75 | protected: |
319 | 74 | 76 | ||
320 | 75 | virtual bool compare (const ObjectIdentifier::Ptr &) const = 0; | 77 | virtual bool compare (const ObjectIdentifier::Ptr &) const = 0; |
321 | 76 | virtual ObjectType getType () const = 0; | 78 | virtual ObjectType getType () const = 0; |
323 | 77 | virtual const boost::shared_ptr <Object> & lookup () const = 0; | 79 | virtual boost::shared_ptr <Object> lookup () const = 0; |
324 | 78 | 80 | ||
325 | 79 | /* Either fully resolved or looked up | 81 | /* Either fully resolved or looked up |
326 | 80 | * at runtime in the repository */ | 82 | * at runtime in the repository */ |
327 | @@ -83,12 +85,35 @@ | |||
328 | 83 | friend class Server; | 85 | friend class Server; |
329 | 84 | }; | 86 | }; |
330 | 85 | 87 | ||
332 | 86 | class Object | 88 | class ObjectKey |
333 | 89 | { | ||
334 | 90 | }; | ||
335 | 91 | |||
336 | 92 | class Object : | ||
337 | 93 | boost::noncopyable | ||
338 | 87 | { | 94 | { |
339 | 88 | public: | 95 | public: |
340 | 89 | 96 | ||
341 | 90 | typedef boost::shared_ptr <Object> Ptr; | 97 | typedef boost::shared_ptr <Object> Ptr; |
342 | 91 | 98 | ||
343 | 99 | class Visitor : | ||
344 | 100 | boost::noncopyable | ||
345 | 101 | { | ||
346 | 102 | public: | ||
347 | 103 | |||
348 | 104 | Visitor (ObjectKey const &, const compiz::window::Object::Ptr &o); | ||
349 | 105 | virtual ~Visitor (); | ||
350 | 106 | |||
351 | 107 | protected: | ||
352 | 108 | bool setStackPosition (const StackPosition &); | ||
353 | 109 | bool setGeometry (const Geometry &); | ||
354 | 110 | bool setContainer (const boost::shared_ptr <Container> &); | ||
355 | 111 | bool addState (const uint64_t &state); | ||
356 | 112 | bool removeState (const uint64_t &state); | ||
357 | 113 | private: | ||
358 | 114 | compiz::window::Object::Ptr mObject; | ||
359 | 115 | }; | ||
360 | 116 | |||
361 | 92 | Object (const ObjectIdentifier::Ptr &); | 117 | Object (const ObjectIdentifier::Ptr &); |
362 | 93 | Object (const ObjectIdentifier::Ptr &, | 118 | Object (const ObjectIdentifier::Ptr &, |
363 | 94 | const compiz::window::Geometry &); | 119 | const compiz::window::Geometry &); |
364 | @@ -106,16 +131,23 @@ | |||
365 | 106 | const ObjectIdentifier::Ptr & id () const; | 131 | const ObjectIdentifier::Ptr & id () const; |
366 | 107 | const compiz::window::Geometry & geometry () const; | 132 | const compiz::window::Geometry & geometry () const; |
367 | 108 | const compiz::window::StackPosition & stackPosition () const; | 133 | const compiz::window::StackPosition & stackPosition () const; |
368 | 134 | const uint64_t & state () const; | ||
369 | 109 | 135 | ||
370 | 110 | bool operator== (const Object &) const; | 136 | bool operator== (const Object &) const; |
371 | 111 | bool operator!= (const Object &) const; | 137 | bool operator!= (const Object &) const; |
372 | 112 | 138 | ||
373 | 139 | /* state bits for this */ | ||
374 | 140 | static ManagedStateBit StateMapped; | ||
375 | 141 | |||
376 | 113 | protected: | 142 | protected: |
377 | 114 | 143 | ||
378 | 144 | /* Returns true if anything was actually changed */ | ||
379 | 115 | bool setStackPosition (const StackPosition &); | 145 | bool setStackPosition (const StackPosition &); |
380 | 116 | bool setGeometry (const Geometry &); | 146 | bool setGeometry (const Geometry &); |
383 | 117 | //virtual bool show () = 0; | 147 | bool setContainer (const boost::shared_ptr <Container> &); |
384 | 118 | //virtual bool hide () = 0; | 148 | bool setVisible (bool); |
385 | 149 | bool addState (const uint64_t &state); | ||
386 | 150 | bool removeState (const uint64_t &state); | ||
387 | 119 | 151 | ||
388 | 120 | private: | 152 | private: |
389 | 121 | 153 | ||
390 | @@ -123,6 +155,9 @@ | |||
391 | 123 | compiz::window::Geometry mGeometry; | 155 | compiz::window::Geometry mGeometry; |
392 | 124 | compiz::window::StackPosition mStackPosition; | 156 | compiz::window::StackPosition mStackPosition; |
393 | 125 | boost::shared_ptr <Container> mContainer; | 157 | boost::shared_ptr <Container> mContainer; |
394 | 158 | uint64_t mState; | ||
395 | 159 | |||
396 | 160 | |||
397 | 126 | }; | 161 | }; |
398 | 127 | 162 | ||
399 | 128 | class SynchronousObject : | 163 | class SynchronousObject : |
400 | @@ -146,6 +181,7 @@ | |||
401 | 146 | 181 | ||
402 | 147 | bool setStackPosition (const StackPosition &); | 182 | bool setStackPosition (const StackPosition &); |
403 | 148 | bool setGeometry (const Geometry &); | 183 | bool setGeometry (const Geometry &); |
404 | 184 | bool setState (const uint64_t &state); | ||
405 | 149 | }; | 185 | }; |
406 | 150 | 186 | ||
407 | 151 | } | 187 | } |
408 | 152 | 188 | ||
409 | === modified file 'include/core/server-read.h' | |||
410 | --- include/core/server-read.h 2012-01-19 18:25:05 +0000 | |||
411 | +++ include/core/server-read.h 2012-01-19 18:25:06 +0000 | |||
412 | @@ -34,6 +34,7 @@ | |||
413 | 34 | #include <core/object.h> | 34 | #include <core/object.h> |
414 | 35 | #include <core/asynchronous-object.h> | 35 | #include <core/asynchronous-object.h> |
415 | 36 | #include <core/asynchronous-container.h> | 36 | #include <core/asynchronous-container.h> |
416 | 37 | #include <stdint.h> | ||
417 | 37 | 38 | ||
418 | 38 | namespace compiz | 39 | namespace compiz |
419 | 39 | { | 40 | { |
420 | @@ -58,6 +59,10 @@ | |||
421 | 58 | 59 | ||
422 | 59 | void receiveParent (const AsynchronousObject::Ptr &, | 60 | void receiveParent (const AsynchronousObject::Ptr &, |
423 | 60 | const AsynchronousContainer::Ptr &); | 61 | const AsynchronousContainer::Ptr &); |
424 | 62 | |||
425 | 63 | void receiveState (const AsynchronousObject::Ptr &, | ||
426 | 64 | uint64_t addState, | ||
427 | 65 | uint64_t removeState); | ||
428 | 61 | protected: | 66 | protected: |
429 | 62 | 67 | ||
430 | 63 | ReadServerConnection (); | 68 | ReadServerConnection (); |
431 | 64 | 69 | ||
432 | === modified file 'include/core/server-write.h' | |||
433 | --- include/core/server-write.h 2012-01-19 18:25:05 +0000 | |||
434 | +++ include/core/server-write.h 2012-01-19 18:25:06 +0000 | |||
435 | @@ -39,6 +39,8 @@ | |||
436 | 39 | namespace window | 39 | namespace window |
437 | 40 | { | 40 | { |
438 | 41 | 41 | ||
439 | 42 | class ObjectCreationRequest; | ||
440 | 43 | |||
441 | 42 | class WriteServerConnection : | 44 | class WriteServerConnection : |
442 | 43 | public boost::noncopyable | 45 | public boost::noncopyable |
443 | 44 | { | 46 | { |
444 | @@ -55,6 +57,15 @@ | |||
445 | 55 | 57 | ||
446 | 56 | void sendParent (const ObjectIdentifier::Ptr &id, | 58 | void sendParent (const ObjectIdentifier::Ptr &id, |
447 | 57 | const ObjectIdentifier::Ptr &parent); | 59 | const ObjectIdentifier::Ptr &parent); |
448 | 60 | |||
449 | 61 | void sendCreateObject (const ObjectCreationRequest::Ptr &req); | ||
450 | 62 | |||
451 | 63 | void sendDeleteObject (const ObjectIdentifier::Ptr &id); | ||
452 | 64 | |||
453 | 65 | void sendState (const ObjectIdentifier::Ptr &id, | ||
454 | 66 | uint64_t aState, | ||
455 | 67 | uint64_t rState); | ||
456 | 68 | |||
457 | 58 | private: | 69 | private: |
458 | 59 | 70 | ||
459 | 60 | WriteServerConnection (const compiz::window::AsynchronousServer::Ptr &); | 71 | WriteServerConnection (const compiz::window::AsynchronousServer::Ptr &); |
460 | 61 | 72 | ||
461 | === modified file 'include/core/server.h' | |||
462 | --- include/core/server.h 2012-01-19 18:25:05 +0000 | |||
463 | +++ include/core/server.h 2012-01-19 18:25:06 +0000 | |||
464 | @@ -29,7 +29,9 @@ | |||
465 | 29 | 29 | ||
466 | 30 | #include <boost/shared_ptr.hpp> | 30 | #include <boost/shared_ptr.hpp> |
467 | 31 | #include <boost/noncopyable.hpp> | 31 | #include <boost/noncopyable.hpp> |
468 | 32 | #include <boost/enable_shared_from_this.hpp> | ||
469 | 32 | #include <core/object.h> | 33 | #include <core/object.h> |
470 | 34 | #include <core/container.h> | ||
471 | 33 | 35 | ||
472 | 34 | namespace compiz | 36 | namespace compiz |
473 | 35 | { | 37 | { |
474 | @@ -37,6 +39,7 @@ | |||
475 | 37 | { | 39 | { |
476 | 38 | 40 | ||
477 | 39 | class Server : | 41 | class Server : |
478 | 42 | public boost::enable_shared_from_this <Server>, | ||
479 | 40 | public boost::noncopyable | 43 | public boost::noncopyable |
480 | 41 | { | 44 | { |
481 | 42 | public: | 45 | public: |
482 | @@ -45,18 +48,30 @@ | |||
483 | 45 | virtual ~Server (); | 48 | virtual ~Server (); |
484 | 46 | 49 | ||
485 | 47 | const Object::Ptr & root (); | 50 | const Object::Ptr & root (); |
487 | 48 | virtual const Object::Ptr & lookup (const boost::shared_ptr <const ObjectIdentifier> &id) = 0; | 51 | virtual Object::Ptr lookup (const boost::shared_ptr <const ObjectIdentifier> &id) const = 0; |
488 | 49 | 52 | ||
489 | 50 | static Server::Ptr Default (); | 53 | static Server::Ptr Default (); |
490 | 51 | 54 | ||
491 | 52 | protected: | 55 | protected: |
492 | 53 | 56 | ||
493 | 54 | Server (); | 57 | Server (); |
494 | 58 | static void SetDefault (Server::Ptr s); | ||
495 | 59 | |||
496 | 60 | void setRoot (const compiz::window::Object::Ptr &root); | ||
497 | 61 | |||
498 | 62 | virtual compiz::window::Object::Ptr | ||
499 | 63 | createObject (const compiz::window::ObjectIdentifier::Ptr &id, | ||
500 | 64 | const compiz::window::Geometry &g = compiz::window::Geometry (), | ||
501 | 65 | const compiz::window::StackPosition &sp = compiz::window::StackPosition (), | ||
502 | 66 | const compiz::window::Container::Ptr &c = boost::shared_polymorphic_cast <compiz::window::Container> (Server::Default ()->root ())) = 0; | ||
503 | 67 | |||
504 | 68 | virtual void | ||
505 | 69 | removeObject (const compiz::window::ObjectIdentifier::Ptr &) = 0; | ||
506 | 55 | 70 | ||
507 | 56 | private: | 71 | private: |
508 | 57 | 72 | ||
509 | 73 | static Server::Ptr mDefault; | ||
510 | 58 | Object::Ptr mRoot; | 74 | Object::Ptr mRoot; |
511 | 59 | static Server::Ptr mDefault; | ||
512 | 60 | }; | 75 | }; |
513 | 61 | 76 | ||
514 | 62 | } | 77 | } |
515 | 63 | 78 | ||
516 | === added file 'include/core/x11-object.h' | |||
517 | --- include/core/x11-object.h 1970-01-01 00:00:00 +0000 | |||
518 | +++ include/core/x11-object.h 2012-01-19 18:25:06 +0000 | |||
519 | @@ -0,0 +1,116 @@ | |||
520 | 1 | /* | ||
521 | 2 | * Copyright © 2011 Canonical Ltd. | ||
522 | 3 | * | ||
523 | 4 | * Permission to use, copy, modify, distribute, and sell this software | ||
524 | 5 | * and its documentation for any purpose is hereby granted without | ||
525 | 6 | * fee, provided that the above copyright notice appear in all copies | ||
526 | 7 | * and that both that copyright notice and this permission notice | ||
527 | 8 | * appear in supporting documentation, and that the name of | ||
528 | 9 | * Dennis Kasprzyk not be used in advertising or publicity pertaining to | ||
529 | 10 | * distribution of the software without specific, written prior permission. | ||
530 | 11 | * Dennis Kasprzyk makes no representations about the suitability of this | ||
531 | 12 | * software for any purpose. It is provided "as is" without express or | ||
532 | 13 | * implied warranty. | ||
533 | 14 | * | ||
534 | 15 | * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
535 | 16 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN | ||
536 | 17 | * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
537 | 18 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
538 | 19 | * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | ||
539 | 20 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | ||
540 | 21 | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
541 | 22 | * | ||
542 | 23 | * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org> | ||
543 | 24 | * David Reveman <davidr@novell.com> | ||
544 | 25 | */ | ||
545 | 26 | |||
546 | 27 | #ifndef _COMPIZ_X11_OBJECT_H | ||
547 | 28 | #define _COMPIZ_X11_OBJECT_H | ||
548 | 29 | |||
549 | 30 | #include <core/object.h> | ||
550 | 31 | #include <core/asynchronous-object.h> | ||
551 | 32 | #include <core/asynchronous-container.h> | ||
552 | 33 | #include <core/windowgeometry.h> | ||
553 | 34 | #include <X11/Xlib.h> | ||
554 | 35 | #include <boost/shared_ptr.hpp> | ||
555 | 36 | |||
556 | 37 | namespace compiz | ||
557 | 38 | { | ||
558 | 39 | namespace window | ||
559 | 40 | { | ||
560 | 41 | |||
561 | 42 | class X11Server; | ||
562 | 43 | class X11ObjectIdentifier; | ||
563 | 44 | class WriteServerConnection; | ||
564 | 45 | |||
565 | 46 | class X11ObjectIdentifier : | ||
566 | 47 | public ObjectIdentifier | ||
567 | 48 | { | ||
568 | 49 | public: | ||
569 | 50 | |||
570 | 51 | typedef boost::shared_ptr <X11ObjectIdentifier> Ptr; | ||
571 | 52 | typedef boost::shared_ptr <const X11ObjectIdentifier> ConstPtr; | ||
572 | 53 | |||
573 | 54 | X11ObjectIdentifier (Window id); | ||
574 | 55 | ~X11ObjectIdentifier (); | ||
575 | 56 | |||
576 | 57 | void print (); | ||
577 | 58 | |||
578 | 59 | protected: | ||
579 | 60 | |||
580 | 61 | compiz::window::ObjectIdentifier::ObjectType getType () const; | ||
581 | 62 | bool compare (const ObjectIdentifier::Ptr &) const; | ||
582 | 63 | compiz::window::Object::Ptr lookup () const; | ||
583 | 64 | |||
584 | 65 | private: | ||
585 | 66 | |||
586 | 67 | Window mId; | ||
587 | 68 | |||
588 | 69 | friend class X11Server; | ||
589 | 70 | }; | ||
590 | 71 | |||
591 | 72 | |||
592 | 73 | class X11Object : | ||
593 | 74 | virtual public AsynchronousObject | ||
594 | 75 | { | ||
595 | 76 | public: | ||
596 | 77 | |||
597 | 78 | typedef boost::shared_ptr <X11Object> Ptr; | ||
598 | 79 | |||
599 | 80 | virtual ~X11Object (); | ||
600 | 81 | |||
601 | 82 | protected: | ||
602 | 83 | |||
603 | 84 | X11Object (const ObjectIdentifier::Ptr &, | ||
604 | 85 | const boost::shared_ptr <WriteServerConnection> &, | ||
605 | 86 | const compiz::window::Geometry &, | ||
606 | 87 | const boost::shared_ptr <Container> &); | ||
607 | 88 | |||
608 | 89 | friend class X11Server; | ||
609 | 90 | }; | ||
610 | 91 | |||
611 | 92 | class X11Container : | ||
612 | 93 | public AsynchronousContainer, | ||
613 | 94 | public X11Object | ||
614 | 95 | { | ||
615 | 96 | public: | ||
616 | 97 | |||
617 | 98 | typedef boost::shared_ptr <X11Container> Ptr; | ||
618 | 99 | |||
619 | 100 | virtual ~X11Container (); | ||
620 | 101 | |||
621 | 102 | protected: | ||
622 | 103 | |||
623 | 104 | X11Container (const ObjectIdentifier::Ptr &, | ||
624 | 105 | const boost::shared_ptr <WriteServerConnection> &, | ||
625 | 106 | const compiz::window::Geometry &, | ||
626 | 107 | const boost::shared_ptr <Container> &); | ||
627 | 108 | |||
628 | 109 | friend class X11Server; | ||
629 | 110 | |||
630 | 111 | }; | ||
631 | 112 | |||
632 | 113 | } | ||
633 | 114 | } | ||
634 | 115 | |||
635 | 116 | #endif | ||
636 | 0 | 117 | ||
637 | === added file 'include/core/x11-server.h' | |||
638 | --- include/core/x11-server.h 1970-01-01 00:00:00 +0000 | |||
639 | +++ include/core/x11-server.h 2012-01-19 18:25:06 +0000 | |||
640 | @@ -0,0 +1,140 @@ | |||
641 | 1 | /* | ||
642 | 2 | * Copyright © 2011 Canonical Ltd. | ||
643 | 3 | * | ||
644 | 4 | * Permission to use, copy, modify, distribute, and sell this software | ||
645 | 5 | * and its documentation for any purpose is hereby granted without | ||
646 | 6 | * fee, provided that the above copyright notice appear in all copies | ||
647 | 7 | * and that both that copyright notice and this permission notice | ||
648 | 8 | * appear in supporting documentation, and that the name of | ||
649 | 9 | * Dennis Kasprzyk not be used in advertising or publicity pertaining to | ||
650 | 10 | * distribution of the software without specific, written prior permission. | ||
651 | 11 | * Dennis Kasprzyk makes no representations about the suitability of this | ||
652 | 12 | * software for any purpose. It is provided "as is" without express or | ||
653 | 13 | * implied warranty. | ||
654 | 14 | * | ||
655 | 15 | * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
656 | 16 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN | ||
657 | 17 | * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
658 | 18 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
659 | 19 | * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | ||
660 | 20 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | ||
661 | 21 | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
662 | 22 | * | ||
663 | 23 | * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org> | ||
664 | 24 | * David Reveman <davidr@novell.com> | ||
665 | 25 | */ | ||
666 | 26 | |||
667 | 27 | #ifndef _COMPIZ_X11_SERVER_H | ||
668 | 28 | #define _COMPIZ_X11_SERVER_H | ||
669 | 29 | |||
670 | 30 | #include <core/server.h> | ||
671 | 31 | #include <core/asynchronous-server.h> | ||
672 | 32 | #include <core/x11-object.h> | ||
673 | 33 | #include <boost/shared_ptr.hpp> | ||
674 | 34 | #include <boost/unordered_map.hpp> | ||
675 | 35 | #include <boost/functional/hash.hpp> | ||
676 | 36 | #include <X11/Xlib.h> | ||
677 | 37 | |||
678 | 38 | |||
679 | 39 | namespace compiz | ||
680 | 40 | { | ||
681 | 41 | namespace window | ||
682 | 42 | { | ||
683 | 43 | void populateXWindowChanges (const compiz::window::Geometry &g, | ||
684 | 44 | unsigned int mask, | ||
685 | 45 | XWindowChanges &xwc); | ||
686 | 46 | |||
687 | 47 | void populateXWindowChanges (const compiz::window::StackPosition &sp, | ||
688 | 48 | unsigned int mask, | ||
689 | 49 | XWindowChanges &xwc); | ||
690 | 50 | |||
691 | 51 | class X11ObjectCreationRequest : | ||
692 | 52 | public compiz::window::ObjectCreationRequest | ||
693 | 53 | { | ||
694 | 54 | public: | ||
695 | 55 | |||
696 | 56 | typedef boost::shared_ptr <X11ObjectCreationRequest> Ptr; | ||
697 | 57 | |||
698 | 58 | X11ObjectCreationRequest (XSetWindowAttributes &attr, | ||
699 | 59 | const compiz::window::Geometry &g, | ||
700 | 60 | unsigned int cclass, | ||
701 | 61 | unsigned int depth, | ||
702 | 62 | const compiz::window::X11ObjectIdentifier::Ptr &parent, | ||
703 | 63 | unsigned int attrValueMask, | ||
704 | 64 | Visual *vis); | ||
705 | 65 | |||
706 | 66 | virtual ~X11ObjectCreationRequest (); | ||
707 | 67 | |||
708 | 68 | inline XSetWindowAttributes & attributes () const; | ||
709 | 69 | inline const compiz::window::Geometry & geometry () const; | ||
710 | 70 | inline const unsigned int & cclass () const; | ||
711 | 71 | inline const unsigned int & depth () const; | ||
712 | 72 | inline const compiz::window::X11ObjectIdentifier::Ptr & parent () const; | ||
713 | 73 | inline const unsigned int & attrValueMask () const; | ||
714 | 74 | inline Visual * visual () const; | ||
715 | 75 | |||
716 | 76 | private: | ||
717 | 77 | |||
718 | 78 | mutable XSetWindowAttributes mAttr; | ||
719 | 79 | compiz::window::Geometry mGeometry; | ||
720 | 80 | unsigned int mClass; | ||
721 | 81 | unsigned int mDepth; | ||
722 | 82 | compiz::window::X11ObjectIdentifier::Ptr mParent; | ||
723 | 83 | unsigned int mAttrValueMask; | ||
724 | 84 | Visual *mVis; | ||
725 | 85 | }; | ||
726 | 86 | |||
727 | 87 | class X11Server : | ||
728 | 88 | public AsynchronousServer | ||
729 | 89 | { | ||
730 | 90 | public: | ||
731 | 91 | |||
732 | 92 | typedef boost::shared_ptr <X11Server> Ptr; | ||
733 | 93 | |||
734 | 94 | virtual ~X11Server (); | ||
735 | 95 | |||
736 | 96 | Object::Ptr lookup (const boost::shared_ptr <const ObjectIdentifier> &id) const; | ||
737 | 97 | |||
738 | 98 | protected: | ||
739 | 99 | |||
740 | 100 | X11Server (); | ||
741 | 101 | X11Server (const char *); | ||
742 | 102 | X11Server (Display *); | ||
743 | 103 | |||
744 | 104 | void sendGeometry (const ObjectIdentifier::Ptr &, | ||
745 | 105 | const compiz::window::Geometry &); | ||
746 | 106 | |||
747 | 107 | void sendStackPosition (const ObjectIdentifier::Ptr &, | ||
748 | 108 | const compiz::window::StackPosition &); | ||
749 | 109 | |||
750 | 110 | void sendParent (const ObjectIdentifier::Ptr &child, | ||
751 | 111 | const ObjectIdentifier::Ptr &parent); | ||
752 | 112 | |||
753 | 113 | void sendCreateObject (const boost::shared_ptr <ObjectCreationRequest> &req); | ||
754 | 114 | |||
755 | 115 | void sendDeleteObject (const ObjectIdentifier::Ptr &id); | ||
756 | 116 | |||
757 | 117 | void sendState (const ObjectIdentifier::Ptr &id, uint64_t aState, uint64_t rState); | ||
758 | 118 | |||
759 | 119 | void dispatchRequests (unsigned int); | ||
760 | 120 | |||
761 | 121 | void setupEventSource (); | ||
762 | 122 | void setRoot (Window root, const Geometry &); | ||
763 | 123 | |||
764 | 124 | void addObjectToTree (const std::pair <X11ObjectIdentifier::Ptr, | ||
765 | 125 | X11Object::Ptr > &); | ||
766 | 126 | void removeKeyFromTree (const ObjectIdentifier::Ptr &); | ||
767 | 127 | |||
768 | 128 | private: | ||
769 | 129 | |||
770 | 130 | void dispatchEvent (XEvent *); | ||
771 | 131 | void queueEvents (); | ||
772 | 132 | |||
773 | 133 | boost::unordered_map <Window, X11Object::Ptr> mObjectTree; | ||
774 | 134 | Display *mDisplay; | ||
775 | 135 | }; | ||
776 | 136 | |||
777 | 137 | } | ||
778 | 138 | } | ||
779 | 139 | |||
780 | 140 | #endif | ||
781 | 0 | 141 | ||
782 | === modified file 'src/CMakeLists.txt' | |||
783 | --- src/CMakeLists.txt 2012-01-19 18:25:05 +0000 | |||
784 | +++ src/CMakeLists.txt 2012-01-19 18:25:06 +0000 | |||
785 | @@ -110,6 +110,10 @@ | |||
786 | 110 | ${CMAKE_CURRENT_SOURCE_DIR}/server-write.cpp | 110 | ${CMAKE_CURRENT_SOURCE_DIR}/server-write.cpp |
787 | 111 | ${CMAKE_CURRENT_SOURCE_DIR}/stack.cpp | 111 | ${CMAKE_CURRENT_SOURCE_DIR}/stack.cpp |
788 | 112 | ${CMAKE_CURRENT_SOURCE_DIR}/asynchronous-stack.cpp | 112 | ${CMAKE_CURRENT_SOURCE_DIR}/asynchronous-stack.cpp |
789 | 113 | ${CMAKE_CURRENT_SOURCE_DIR}/x11-object.cpp | ||
790 | 114 | ${CMAKE_CURRENT_SOURCE_DIR}/x11-container.cpp | ||
791 | 115 | ${CMAKE_CURRENT_SOURCE_DIR}/x11-server.cpp | ||
792 | 116 | ${CMAKE_CURRENT_SOURCE_DIR}/managedstatebit.cpp | ||
793 | 113 | ${_bcop_sources} | 117 | ${_bcop_sources} |
794 | 114 | ) | 118 | ) |
795 | 115 | 119 | ||
796 | 116 | 120 | ||
797 | === modified file 'src/asynchronous-container.cpp' | |||
798 | --- src/asynchronous-container.cpp 2012-01-19 18:25:05 +0000 | |||
799 | +++ src/asynchronous-container.cpp 2012-01-19 18:25:06 +0000 | |||
800 | @@ -27,11 +27,28 @@ | |||
801 | 27 | #include <core/server-write.h> | 27 | #include <core/server-write.h> |
802 | 28 | #include <core/server.h> | 28 | #include <core/server.h> |
803 | 29 | 29 | ||
804 | 30 | class AsynchronousObjectContainerVisitor : | ||
805 | 31 | public compiz::window::Object::Visitor | ||
806 | 32 | { | ||
807 | 33 | public: | ||
808 | 34 | AsynchronousObjectContainerVisitor (const compiz::window::ObjectKey &k, | ||
809 | 35 | const compiz::window::Object::Ptr &p) : | ||
810 | 36 | compiz::window::Object::Visitor (k, p) | ||
811 | 37 | { | ||
812 | 38 | } | ||
813 | 39 | |||
814 | 40 | inline bool changeContainer (const compiz::window::Container::Ptr & c) | ||
815 | 41 | { | ||
816 | 42 | return setContainer (c); | ||
817 | 43 | } | ||
818 | 44 | }; | ||
819 | 45 | |||
820 | 30 | compiz::window::AsynchronousContainer::AsynchronousContainer (const compiz::window::ObjectIdentifier::Ptr &id, | 46 | compiz::window::AsynchronousContainer::AsynchronousContainer (const compiz::window::ObjectIdentifier::Ptr &id, |
821 | 31 | const compiz::window::WriteServerConnection::Ptr &writer) : | 47 | const compiz::window::WriteServerConnection::Ptr &writer) : |
822 | 32 | Object::Object (id), | 48 | Object::Object (id), |
823 | 33 | AsynchronousObject::AsynchronousObject (id, writer), | 49 | AsynchronousObject::AsynchronousObject (id, writer), |
825 | 34 | Container::Container (id) | 50 | Container::Container (id), |
826 | 51 | mWriteConnection (writer) | ||
827 | 35 | { | 52 | { |
828 | 36 | } | 53 | } |
829 | 37 | 54 | ||
830 | @@ -40,7 +57,8 @@ | |||
831 | 40 | const compiz::window::WriteServerConnection::Ptr &writer) : | 57 | const compiz::window::WriteServerConnection::Ptr &writer) : |
832 | 41 | Object::Object (id, g), | 58 | Object::Object (id, g), |
833 | 42 | AsynchronousObject::AsynchronousObject (id, g, writer), | 59 | AsynchronousObject::AsynchronousObject (id, g, writer), |
835 | 43 | Container::Container (id, g) | 60 | Container::Container (id, g), |
836 | 61 | mWriteConnection (writer) | ||
837 | 44 | { | 62 | { |
838 | 45 | } | 63 | } |
839 | 46 | 64 | ||
840 | @@ -50,7 +68,8 @@ | |||
841 | 50 | const compiz::window::WriteServerConnection::Ptr &writer) : | 68 | const compiz::window::WriteServerConnection::Ptr &writer) : |
842 | 51 | Object::Object (id, g, sp), | 69 | Object::Object (id, g, sp), |
843 | 52 | AsynchronousObject::AsynchronousObject (id, g, sp, writer), | 70 | AsynchronousObject::AsynchronousObject (id, g, sp, writer), |
845 | 53 | Container::Container (id, g, sp) | 71 | Container::Container (id, g, sp), |
846 | 72 | mWriteConnection (writer) | ||
847 | 54 | { | 73 | { |
848 | 55 | } | 74 | } |
849 | 56 | 75 | ||
850 | @@ -61,7 +80,8 @@ | |||
851 | 61 | const compiz::window::WriteServerConnection::Ptr &writer) : | 80 | const compiz::window::WriteServerConnection::Ptr &writer) : |
852 | 62 | Object::Object (id, g, sp, c), | 81 | Object::Object (id, g, sp, c), |
853 | 63 | AsynchronousObject::AsynchronousObject (id, g, sp , c, writer), | 82 | AsynchronousObject::AsynchronousObject (id, g, sp , c, writer), |
855 | 64 | Container::Container (id, g, sp, c) | 83 | Container::Container (id, g, sp, c), |
856 | 84 | mWriteConnection (writer) | ||
857 | 65 | { | 85 | { |
858 | 66 | } | 86 | } |
859 | 67 | 87 | ||
860 | @@ -72,6 +92,8 @@ | |||
861 | 72 | void | 92 | void |
862 | 73 | compiz::window::AsynchronousContainer::sendInsertion (const Object::Ptr &o) | 93 | compiz::window::AsynchronousContainer::sendInsertion (const Object::Ptr &o) |
863 | 74 | { | 94 | { |
864 | 95 | onSendInsertion (o); | ||
865 | 96 | |||
866 | 75 | mWriteConnection->sendParent (o->id (), id ()); | 97 | mWriteConnection->sendParent (o->id (), id ()); |
867 | 76 | 98 | ||
868 | 77 | addSentInsertion (o); | 99 | addSentInsertion (o); |
869 | @@ -80,23 +102,35 @@ | |||
870 | 80 | compiz::window::Object::Ptr | 102 | compiz::window::Object::Ptr |
871 | 81 | compiz::window::AsynchronousContainer::sendRemoval (const Object::Ptr &o) | 103 | compiz::window::AsynchronousContainer::sendRemoval (const Object::Ptr &o) |
872 | 82 | { | 104 | { |
873 | 105 | onSendRemoval (o); | ||
874 | 106 | |||
875 | 107 | mWriteConnection->sendParent (o->id (), Server::Default ()->root ()->id ()); | ||
876 | 108 | |||
877 | 83 | Object::Ptr p = addSentRemoval (o); | 109 | Object::Ptr p = addSentRemoval (o); |
878 | 84 | 110 | ||
879 | 85 | mWriteConnection->sendParent (o->id (), Server::Default ()->root ()->id ()); | ||
880 | 86 | |||
881 | 87 | return p; | 111 | return p; |
882 | 88 | } | 112 | } |
883 | 89 | 113 | ||
884 | 90 | void | 114 | void |
885 | 91 | compiz::window::AsynchronousContainer::receiveInsertion (const Object::Ptr &o) | 115 | compiz::window::AsynchronousContainer::receiveInsertion (const Object::Ptr &o) |
886 | 92 | { | 116 | { |
887 | 117 | compiz::window::ObjectKey k; | ||
888 | 118 | AsynchronousObjectContainerVisitor v (k, o); | ||
889 | 119 | onReceiveInsertion (o); | ||
890 | 120 | |||
891 | 93 | Container::insert (o); | 121 | Container::insert (o); |
892 | 122 | v.changeContainer (Container::shared_from_this ()); | ||
893 | 94 | } | 123 | } |
894 | 95 | 124 | ||
895 | 96 | void | 125 | void |
896 | 97 | compiz::window::AsynchronousContainer::receiveRemoval (const Object::Ptr &o) | 126 | compiz::window::AsynchronousContainer::receiveRemoval (const Object::Ptr &o) |
897 | 98 | { | 127 | { |
898 | 128 | compiz::window::ObjectKey k; | ||
899 | 129 | AsynchronousObjectContainerVisitor v (k, o); | ||
900 | 130 | onReceiveRemoval (o); | ||
901 | 131 | |||
902 | 99 | Container::remove (o); | 132 | Container::remove (o); |
903 | 133 | v.changeContainer (Container::Ptr ()); | ||
904 | 100 | } | 134 | } |
905 | 101 | 135 | ||
906 | 102 | void | 136 | void |
907 | 103 | 137 | ||
908 | === modified file 'src/asynchronous-object.cpp' | |||
909 | --- src/asynchronous-object.cpp 2012-01-19 18:25:05 +0000 | |||
910 | +++ src/asynchronous-object.cpp 2012-01-19 18:25:06 +0000 | |||
911 | @@ -76,9 +76,17 @@ | |||
912 | 76 | return mSentStackPosition; | 76 | return mSentStackPosition; |
913 | 77 | } | 77 | } |
914 | 78 | 78 | ||
915 | 79 | const uint64_t & | ||
916 | 80 | compiz::window::AsynchronousObject::sendState () const | ||
917 | 81 | { | ||
918 | 82 | return mSentState; | ||
919 | 83 | } | ||
920 | 84 | |||
921 | 79 | void | 85 | void |
922 | 80 | compiz::window::AsynchronousObject::sendGeometry (const compiz::window::Geometry &g) | 86 | compiz::window::AsynchronousObject::sendGeometry (const compiz::window::Geometry &g) |
923 | 81 | { | 87 | { |
924 | 88 | onSendGeometry (g); | ||
925 | 89 | |||
926 | 82 | mWriteConnection->sendGeometry (id (), g); | 90 | mWriteConnection->sendGeometry (id (), g); |
927 | 83 | 91 | ||
928 | 84 | addSentGeometry (g); | 92 | addSentGeometry (g); |
929 | @@ -87,24 +95,61 @@ | |||
930 | 87 | void | 95 | void |
931 | 88 | compiz::window::AsynchronousObject::sendStackPosition (const compiz::window::StackPosition &sp) | 96 | compiz::window::AsynchronousObject::sendStackPosition (const compiz::window::StackPosition &sp) |
932 | 89 | { | 97 | { |
933 | 98 | onSendStackPosition (sp); | ||
934 | 99 | |||
935 | 90 | mWriteConnection->sendStackPosition (id (), sp); | 100 | mWriteConnection->sendStackPosition (id (), sp); |
936 | 91 | 101 | ||
937 | 92 | addSentStackPosition (sp); | 102 | addSentStackPosition (sp); |
938 | 93 | } | 103 | } |
939 | 94 | 104 | ||
940 | 95 | void | 105 | void |
941 | 106 | compiz::window::AsynchronousObject::sendAddState (uint64_t aState) | ||
942 | 107 | { | ||
943 | 108 | onSendAddState (aState); | ||
944 | 109 | |||
945 | 110 | mWriteConnection->sendState (id (), aState & ~mSentState, 0); | ||
946 | 111 | |||
947 | 112 | addSentAddedState (aState); | ||
948 | 113 | } | ||
949 | 114 | |||
950 | 115 | void | ||
951 | 116 | compiz::window::AsynchronousObject::sendRemoveState (uint64_t rState) | ||
952 | 117 | { | ||
953 | 118 | onSendRemoveState (rState); | ||
954 | 119 | |||
955 | 120 | mWriteConnection->sendState (id (), 0, rState & mSentState); | ||
956 | 121 | |||
957 | 122 | addSentRemovedState (rState); | ||
958 | 123 | } | ||
959 | 124 | |||
960 | 125 | void | ||
961 | 96 | compiz::window::AsynchronousObject::receiveGeometry (const compiz::window::Geometry &g) | 126 | compiz::window::AsynchronousObject::receiveGeometry (const compiz::window::Geometry &g) |
962 | 97 | { | 127 | { |
963 | 128 | onReceiveGeometry (g); | ||
964 | 129 | |||
965 | 98 | Object::setGeometry (g); | 130 | Object::setGeometry (g); |
966 | 99 | } | 131 | } |
967 | 100 | 132 | ||
968 | 101 | void | 133 | void |
969 | 102 | compiz::window::AsynchronousObject::receiveStackPosition (const compiz::window::StackPosition &sp) | 134 | compiz::window::AsynchronousObject::receiveStackPosition (const compiz::window::StackPosition &sp) |
970 | 103 | { | 135 | { |
971 | 136 | onReceiveStackPosition (sp); | ||
972 | 137 | |||
973 | 104 | Object::setStackPosition (sp); | 138 | Object::setStackPosition (sp); |
974 | 105 | } | 139 | } |
975 | 106 | 140 | ||
976 | 107 | void | 141 | void |
977 | 142 | compiz::window::AsynchronousObject::receiveState (uint64_t addState, | ||
978 | 143 | uint64_t removeState) | ||
979 | 144 | { | ||
980 | 145 | onReceiveAddState (addState); | ||
981 | 146 | onReceiveRemoveState (removeState); | ||
982 | 147 | |||
983 | 148 | Object::addState (addState); | ||
984 | 149 | Object::removeState (removeState); | ||
985 | 150 | } | ||
986 | 151 | |||
987 | 152 | void | ||
988 | 108 | compiz::window::AsynchronousObject::addSentGeometry (const compiz::window::Geometry &g) | 153 | compiz::window::AsynchronousObject::addSentGeometry (const compiz::window::Geometry &g) |
989 | 109 | { | 154 | { |
990 | 110 | mSentGeometry = g; | 155 | mSentGeometry = g; |
991 | @@ -115,3 +160,15 @@ | |||
992 | 115 | { | 160 | { |
993 | 116 | mSentStackPosition = sp; | 161 | mSentStackPosition = sp; |
994 | 117 | } | 162 | } |
995 | 163 | |||
996 | 164 | void | ||
997 | 165 | compiz::window::AsynchronousObject::addSentAddedState (uint64_t aState) | ||
998 | 166 | { | ||
999 | 167 | mSentState |= aState; | ||
1000 | 168 | } | ||
1001 | 169 | |||
1002 | 170 | void | ||
1003 | 171 | compiz::window::AsynchronousObject::addSentRemovedState (uint64_t rState) | ||
1004 | 172 | { | ||
1005 | 173 | mSentState &= ~rState; | ||
1006 | 174 | } | ||
1007 | 118 | 175 | ||
1008 | === modified file 'src/asynchronous-server.cpp' | |||
1009 | --- src/asynchronous-server.cpp 2012-01-19 18:25:05 +0000 | |||
1010 | +++ src/asynchronous-server.cpp 2012-01-19 18:25:06 +0000 | |||
1011 | @@ -26,6 +26,14 @@ | |||
1012 | 26 | #include <core/asynchronous-server.h> | 26 | #include <core/asynchronous-server.h> |
1013 | 27 | #include <core/server-write.h> | 27 | #include <core/server-write.h> |
1014 | 28 | 28 | ||
1015 | 29 | compiz::window::ObjectCreationRequest::ObjectCreationRequest () | ||
1016 | 30 | { | ||
1017 | 31 | } | ||
1018 | 32 | |||
1019 | 33 | compiz::window::ObjectCreationRequest::~ObjectCreationRequest () | ||
1020 | 34 | { | ||
1021 | 35 | } | ||
1022 | 36 | |||
1023 | 29 | compiz::window::AsynchronousServer::AsynchronousServer () : | 37 | compiz::window::AsynchronousServer::AsynchronousServer () : |
1024 | 30 | Server::Server (), | 38 | Server::Server (), |
1025 | 31 | mReadConnection (new compiz::window::ReadServerConnection) | 39 | mReadConnection (new compiz::window::ReadServerConnection) |
1026 | @@ -36,10 +44,26 @@ | |||
1027 | 36 | { | 44 | { |
1028 | 37 | } | 45 | } |
1029 | 38 | 46 | ||
1030 | 47 | void | ||
1031 | 48 | compiz::window::AsynchronousServer::setEventSource (const Glib::RefPtr <Glib::Source> &source) | ||
1032 | 49 | { | ||
1033 | 50 | const Glib::RefPtr <Glib::MainContext> &mc = Glib::MainContext::get_default (); | ||
1034 | 51 | mEventSource = source; | ||
1035 | 52 | |||
1036 | 53 | mEventSource->attach (mc); | ||
1037 | 54 | } | ||
1038 | 55 | |||
1039 | 39 | compiz::window::WriteServerConnection::Ptr | 56 | compiz::window::WriteServerConnection::Ptr |
1040 | 40 | compiz::window::AsynchronousServer::connect () | 57 | compiz::window::AsynchronousServer::connect () |
1041 | 41 | { | 58 | { |
1043 | 42 | compiz::window::AsynchronousServer::Ptr t = shared_from_this (); | 59 | compiz::window::AsynchronousServer::Ptr t = |
1044 | 60 | boost::shared_static_cast <compiz::window::AsynchronousServer> (shared_from_this ()); | ||
1045 | 43 | return compiz::window::WriteServerConnection::Ptr (new compiz::window::WriteServerConnection (t)); | 61 | return compiz::window::WriteServerConnection::Ptr (new compiz::window::WriteServerConnection (t)); |
1046 | 44 | } | 62 | } |
1047 | 45 | 63 | ||
1048 | 64 | void | ||
1049 | 65 | compiz::window::AsynchronousServer::flush (unsigned int flags) | ||
1050 | 66 | { | ||
1051 | 67 | dispatchRequests (flags); | ||
1052 | 68 | } | ||
1053 | 69 | |||
1054 | 46 | 70 | ||
1055 | === modified file 'src/container.cpp' | |||
1056 | --- src/container.cpp 2012-01-19 18:25:05 +0000 | |||
1057 | +++ src/container.cpp 2012-01-19 18:25:06 +0000 | |||
1058 | @@ -78,7 +78,9 @@ | |||
1059 | 78 | if (it != mChildren.end ()) | 78 | if (it != mChildren.end ()) |
1060 | 79 | return false; | 79 | return false; |
1061 | 80 | else | 80 | else |
1062 | 81 | { | ||
1063 | 81 | mChildren.insert (it, o); | 82 | mChildren.insert (it, o); |
1064 | 83 | } | ||
1065 | 82 | 84 | ||
1066 | 83 | return true; | 85 | return true; |
1067 | 84 | } | 86 | } |
1068 | 85 | 87 | ||
1069 | === modified file 'src/eventsource.cpp' | |||
1070 | --- src/eventsource.cpp 2012-01-19 18:25:05 +0000 | |||
1071 | +++ src/eventsource.cpp 2012-01-19 18:25:06 +0000 | |||
1072 | @@ -68,6 +68,7 @@ | |||
1073 | 68 | CompEventSource::callback () | 68 | CompEventSource::callback () |
1074 | 69 | { | 69 | { |
1075 | 70 | mProcEvents (); | 70 | mProcEvents (); |
1076 | 71 | XFlush (mDpy); | ||
1077 | 71 | return true; | 72 | return true; |
1078 | 72 | } | 73 | } |
1079 | 73 | 74 | ||
1080 | 74 | 75 | ||
1081 | === added file 'src/managedstatebit.cpp' | |||
1082 | --- src/managedstatebit.cpp 1970-01-01 00:00:00 +0000 | |||
1083 | +++ src/managedstatebit.cpp 2012-01-19 18:25:06 +0000 | |||
1084 | @@ -0,0 +1,173 @@ | |||
1085 | 1 | /* | ||
1086 | 2 | * Copyright © 2010 Canonical Ltd. | ||
1087 | 3 | * | ||
1088 | 4 | * Permission to use, copy, modify, distribute, and sell this software | ||
1089 | 5 | * and its documentation for any purpose is hereby granted without | ||
1090 | 6 | * fee, provided that the above copyright notice appear in all copies | ||
1091 | 7 | * and that both that copyright notice and this permission notice | ||
1092 | 8 | * appear in supporting documentation, and that the name of | ||
1093 | 9 | * Canonical Ltd. not be used in advertising or publicity pertaining to | ||
1094 | 10 | * distribution of the software without specific, written prior permission. | ||
1095 | 11 | * Canonical Ltd. makes no representations about the suitability of this | ||
1096 | 12 | * software for any purpose. It is provided "as is" without express or | ||
1097 | 13 | * implied warranty. | ||
1098 | 14 | * | ||
1099 | 15 | * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
1100 | 16 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN | ||
1101 | 17 | * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
1102 | 18 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
1103 | 19 | * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | ||
1104 | 20 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | ||
1105 | 21 | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
1106 | 22 | * | ||
1107 | 23 | * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> | ||
1108 | 24 | */ | ||
1109 | 25 | |||
1110 | 26 | #include <core/managedstatebit.h> | ||
1111 | 27 | #include <core/object.h> | ||
1112 | 28 | #include <boost/bind.hpp> | ||
1113 | 29 | |||
1114 | 30 | uint64_t compiz::window::ManagedStates::stateBase = (1 << 0); | ||
1115 | 31 | std::vector <uint64_t *> compiz::window::ManagedStates::managedStateBits = std::vector <uint64_t *> (); | ||
1116 | 32 | |||
1117 | 33 | bool | ||
1118 | 34 | compiz::window::ManagedStates::registerState (uint64_t &state) | ||
1119 | 35 | { | ||
1120 | 36 | managedStateBits.push_back (&state); | ||
1121 | 37 | state = stateBase; | ||
1122 | 38 | stateBase <<= 1; | ||
1123 | 39 | |||
1124 | 40 | /* FIXME: check for overflow */ | ||
1125 | 41 | return true; | ||
1126 | 42 | } | ||
1127 | 43 | |||
1128 | 44 | static bool | ||
1129 | 45 | findIfMatchingUINT64Ptr (uint64_t *p, | ||
1130 | 46 | const uint64_t &v) | ||
1131 | 47 | { | ||
1132 | 48 | return *p == v; | ||
1133 | 49 | } | ||
1134 | 50 | |||
1135 | 51 | bool | ||
1136 | 52 | compiz::window::ManagedStates::unregisterState (uint64_t &state) | ||
1137 | 53 | { | ||
1138 | 54 | std::vector <uint64_t *>::iterator it = std::find_if (managedStateBits.begin (), | ||
1139 | 55 | managedStateBits.end (), | ||
1140 | 56 | boost::bind (findIfMatchingUINT64Ptr, _1, state)); | ||
1141 | 57 | |||
1142 | 58 | if (it != managedStateBits.end ()) | ||
1143 | 59 | { | ||
1144 | 60 | it = managedStateBits.erase (it); | ||
1145 | 61 | |||
1146 | 62 | /* Shift all other bits down one */ | ||
1147 | 63 | while (it != managedStateBits.end ()) | ||
1148 | 64 | { | ||
1149 | 65 | (*(*it)) >>= 1; | ||
1150 | 66 | it++; | ||
1151 | 67 | } | ||
1152 | 68 | |||
1153 | 69 | return true; | ||
1154 | 70 | } | ||
1155 | 71 | |||
1156 | 72 | return false; | ||
1157 | 73 | } | ||
1158 | 74 | |||
1159 | 75 | compiz::window::ManagedStateBit::ManagedStateBit () | ||
1160 | 76 | { | ||
1161 | 77 | compiz::window::ManagedStates::registerState (mStateBit); | ||
1162 | 78 | } | ||
1163 | 79 | |||
1164 | 80 | compiz::window::ManagedStateBit::~ManagedStateBit () | ||
1165 | 81 | { | ||
1166 | 82 | compiz::window::ManagedStates::unregisterState (mStateBit); | ||
1167 | 83 | } | ||
1168 | 84 | |||
1169 | 85 | uint64_t compiz::window::ManagedStateBit::operator~ () const | ||
1170 | 86 | { | ||
1171 | 87 | return ~mStateBit; | ||
1172 | 88 | } | ||
1173 | 89 | |||
1174 | 90 | uint64_t compiz::window::ManagedStateBit::operator& (const uint64_t &i) const | ||
1175 | 91 | { | ||
1176 | 92 | return mStateBit & i; | ||
1177 | 93 | } | ||
1178 | 94 | |||
1179 | 95 | uint64_t compiz::window::ManagedStateBit::operator& (const ManagedStateBit &b) const | ||
1180 | 96 | { | ||
1181 | 97 | return mStateBit & b.mStateBit; | ||
1182 | 98 | } | ||
1183 | 99 | |||
1184 | 100 | uint64_t compiz::window::ManagedStateBit::operator| (const uint64_t &i) const | ||
1185 | 101 | { | ||
1186 | 102 | return mStateBit | i; | ||
1187 | 103 | } | ||
1188 | 104 | |||
1189 | 105 | uint64_t compiz::window::ManagedStateBit::operator| (const ManagedStateBit &b) const | ||
1190 | 106 | { | ||
1191 | 107 | return mStateBit | b.mStateBit; | ||
1192 | 108 | } | ||
1193 | 109 | |||
1194 | 110 | uint64_t compiz::window::ManagedStateBit::operator^ (const uint64_t &i) const | ||
1195 | 111 | { | ||
1196 | 112 | return mStateBit ^ i; | ||
1197 | 113 | } | ||
1198 | 114 | |||
1199 | 115 | uint64_t compiz::window::ManagedStateBit::operator^ (const ManagedStateBit &b) const | ||
1200 | 116 | { | ||
1201 | 117 | return mStateBit ^ b.mStateBit; | ||
1202 | 118 | } | ||
1203 | 119 | |||
1204 | 120 | uint64_t compiz::window::ManagedStateBit::operator&= (const uint64_t &i) | ||
1205 | 121 | { | ||
1206 | 122 | return mStateBit |= i; | ||
1207 | 123 | } | ||
1208 | 124 | |||
1209 | 125 | uint64_t compiz::window::ManagedStateBit::operator&= (const ManagedStateBit &b) | ||
1210 | 126 | { | ||
1211 | 127 | return mStateBit |= b.mStateBit; | ||
1212 | 128 | } | ||
1213 | 129 | |||
1214 | 130 | uint64_t compiz::window::ManagedStateBit::operator|= (const uint64_t &i) | ||
1215 | 131 | { | ||
1216 | 132 | return mStateBit |= i; | ||
1217 | 133 | } | ||
1218 | 134 | |||
1219 | 135 | uint64_t compiz::window::ManagedStateBit::operator|= (const ManagedStateBit &b) | ||
1220 | 136 | { | ||
1221 | 137 | return mStateBit |= b.mStateBit; | ||
1222 | 138 | } | ||
1223 | 139 | |||
1224 | 140 | uint64_t compiz::window::ManagedStateBit::operator^= (const uint64_t &i) | ||
1225 | 141 | { | ||
1226 | 142 | return mStateBit ^= i; | ||
1227 | 143 | } | ||
1228 | 144 | |||
1229 | 145 | uint64_t compiz::window::ManagedStateBit::operator^= (const ManagedStateBit &b) | ||
1230 | 146 | { | ||
1231 | 147 | return mStateBit ^= b.mStateBit; | ||
1232 | 148 | } | ||
1233 | 149 | |||
1234 | 150 | bool compiz::window::ManagedStateBit::operator== (const uint64_t &i) const | ||
1235 | 151 | { | ||
1236 | 152 | return mStateBit == i; | ||
1237 | 153 | } | ||
1238 | 154 | |||
1239 | 155 | bool compiz::window::ManagedStateBit::operator!= (const uint64_t &i) const | ||
1240 | 156 | { | ||
1241 | 157 | return mStateBit != i; | ||
1242 | 158 | } | ||
1243 | 159 | |||
1244 | 160 | bool compiz::window::ManagedStateBit::operator== (const ManagedStateBit &b) const | ||
1245 | 161 | { | ||
1246 | 162 | return mStateBit == b.mStateBit; | ||
1247 | 163 | } | ||
1248 | 164 | |||
1249 | 165 | bool compiz::window::ManagedStateBit::operator!= (const ManagedStateBit &b) const | ||
1250 | 166 | { | ||
1251 | 167 | return mStateBit != b.mStateBit; | ||
1252 | 168 | } | ||
1253 | 169 | |||
1254 | 170 | compiz::window::ManagedStateBit::operator uint64_t() const | ||
1255 | 171 | { | ||
1256 | 172 | return mStateBit; | ||
1257 | 173 | } | ||
1258 | 0 | 174 | ||
1259 | === modified file 'src/object.cpp' | |||
1260 | --- src/object.cpp 2012-01-19 18:25:05 +0000 | |||
1261 | +++ src/object.cpp 2012-01-19 18:25:06 +0000 | |||
1262 | @@ -24,6 +24,47 @@ | |||
1263 | 24 | */ | 24 | */ |
1264 | 25 | 25 | ||
1265 | 26 | #include <core/object.h> | 26 | #include <core/object.h> |
1266 | 27 | #include <core/managedstatebit.h> | ||
1267 | 28 | #include <boost/bind.hpp> | ||
1268 | 29 | |||
1269 | 30 | compiz::window::Object::Visitor::Visitor (const ObjectKey &, const compiz::window::Object::Ptr &o) : | ||
1270 | 31 | mObject (o) | ||
1271 | 32 | { | ||
1272 | 33 | } | ||
1273 | 34 | |||
1274 | 35 | compiz::window::Object::Visitor::~Visitor () | ||
1275 | 36 | { | ||
1276 | 37 | } | ||
1277 | 38 | |||
1278 | 39 | bool | ||
1279 | 40 | compiz::window::Object::Visitor::setGeometry (const Geometry &g) | ||
1280 | 41 | { | ||
1281 | 42 | return mObject->setGeometry (g); | ||
1282 | 43 | } | ||
1283 | 44 | |||
1284 | 45 | bool | ||
1285 | 46 | compiz::window::Object::Visitor::setStackPosition (const StackPosition &sp) | ||
1286 | 47 | { | ||
1287 | 48 | return mObject->setStackPosition (sp); | ||
1288 | 49 | } | ||
1289 | 50 | |||
1290 | 51 | bool | ||
1291 | 52 | compiz::window::Object::Visitor::setContainer (const boost::shared_ptr <compiz::window::Container> &c) | ||
1292 | 53 | { | ||
1293 | 54 | return mObject->setContainer (c); | ||
1294 | 55 | } | ||
1295 | 56 | |||
1296 | 57 | bool | ||
1297 | 58 | compiz::window::Object::Visitor::addState (const uint64_t &state) | ||
1298 | 59 | { | ||
1299 | 60 | return mObject->addState (state); | ||
1300 | 61 | } | ||
1301 | 62 | |||
1302 | 63 | bool | ||
1303 | 64 | compiz::window::Object::Visitor::removeState (const uint64_t &state) | ||
1304 | 65 | { | ||
1305 | 66 | return mObject->removeState (state); | ||
1306 | 67 | } | ||
1307 | 27 | 68 | ||
1308 | 28 | compiz::window::Object::Object (const compiz::window::ObjectIdentifier::Ptr &id) : | 69 | compiz::window::Object::Object (const compiz::window::ObjectIdentifier::Ptr &id) : |
1309 | 29 | mId (id) | 70 | mId (id) |
1310 | @@ -96,6 +137,12 @@ | |||
1311 | 96 | return mStackPosition; | 137 | return mStackPosition; |
1312 | 97 | } | 138 | } |
1313 | 98 | 139 | ||
1314 | 140 | const uint64_t & | ||
1315 | 141 | compiz::window::Object::state () const | ||
1316 | 142 | { | ||
1317 | 143 | return mState; | ||
1318 | 144 | } | ||
1319 | 145 | |||
1320 | 99 | const compiz::window::ObjectIdentifier::Ptr & | 146 | const compiz::window::ObjectIdentifier::Ptr & |
1321 | 100 | compiz::window::Object::id () const | 147 | compiz::window::Object::id () const |
1322 | 101 | { | 148 | { |
1323 | @@ -124,6 +171,41 @@ | |||
1324 | 124 | } | 171 | } |
1325 | 125 | 172 | ||
1326 | 126 | bool | 173 | bool |
1327 | 174 | compiz::window::Object::setContainer (const boost::shared_ptr <Container> &c) | ||
1328 | 175 | { | ||
1329 | 176 | mContainer = c; | ||
1330 | 177 | } | ||
1331 | 178 | |||
1332 | 179 | bool | ||
1333 | 180 | compiz::window::Object::addState (const uint64_t &aState) | ||
1334 | 181 | { | ||
1335 | 182 | if ((aState & mState) == mState) | ||
1336 | 183 | return false; | ||
1337 | 184 | mState |= aState; | ||
1338 | 185 | return true; | ||
1339 | 186 | } | ||
1340 | 187 | |||
1341 | 188 | bool | ||
1342 | 189 | compiz::window::Object::removeState (const uint64_t &aState) | ||
1343 | 190 | { | ||
1344 | 191 | if ((aState & mState) == 0) | ||
1345 | 192 | return false; | ||
1346 | 193 | mState |= ~aState; | ||
1347 | 194 | return true; | ||
1348 | 195 | } | ||
1349 | 196 | |||
1350 | 197 | compiz::window::ManagedStateBit compiz::window::Object::StateMapped; | ||
1351 | 198 | |||
1352 | 199 | bool | ||
1353 | 200 | compiz::window::Object::setVisible (bool visible) | ||
1354 | 201 | { | ||
1355 | 202 | if (visible) | ||
1356 | 203 | return addState (StateMapped); | ||
1357 | 204 | |||
1358 | 205 | return removeState (StateMapped); | ||
1359 | 206 | } | ||
1360 | 207 | |||
1361 | 208 | bool | ||
1362 | 127 | compiz::window::Object::setStackPosition (const StackPosition &sp) | 209 | compiz::window::Object::setStackPosition (const StackPosition &sp) |
1363 | 128 | { | 210 | { |
1364 | 129 | mStackPosition = sp; | 211 | mStackPosition = sp; |
1365 | @@ -176,7 +258,15 @@ | |||
1366 | 176 | return Object::setStackPosition (sp); | 258 | return Object::setStackPosition (sp); |
1367 | 177 | } | 259 | } |
1368 | 178 | 260 | ||
1370 | 179 | const boost::shared_ptr <compiz::window::Object> & | 261 | bool |
1371 | 262 | compiz::window::SynchronousObject::setState (const uint64_t &sState) | ||
1372 | 263 | { | ||
1373 | 264 | bool ret = Object::addState (sState & ~(state ())); | ||
1374 | 265 | ret |= Object::removeState (~sState & state ()); | ||
1375 | 266 | return ret; | ||
1376 | 267 | } | ||
1377 | 268 | |||
1378 | 269 | boost::shared_ptr <compiz::window::Object> | ||
1379 | 180 | compiz::window::ObjectIdentifier::operator() () | 270 | compiz::window::ObjectIdentifier::operator() () |
1380 | 181 | { | 271 | { |
1381 | 182 | if (mObj) | 272 | if (mObj) |
1382 | @@ -188,7 +278,7 @@ | |||
1383 | 188 | } | 278 | } |
1384 | 189 | } | 279 | } |
1385 | 190 | 280 | ||
1387 | 191 | const boost::shared_ptr <compiz::window::Object> & | 281 | boost::shared_ptr <compiz::window::Object> |
1388 | 192 | compiz::window::ObjectIdentifier::operator() () const | 282 | compiz::window::ObjectIdentifier::operator() () const |
1389 | 193 | { | 283 | { |
1390 | 194 | if (mObj) | 284 | if (mObj) |
1391 | 195 | 285 | ||
1392 | === modified file 'src/server-read.cpp' | |||
1393 | --- src/server-read.cpp 2012-01-19 18:25:05 +0000 | |||
1394 | +++ src/server-read.cpp 2012-01-19 18:25:06 +0000 | |||
1395 | @@ -55,6 +55,16 @@ | |||
1396 | 55 | const compiz::window::AsynchronousContainer::Ptr &parent) | 55 | const compiz::window::AsynchronousContainer::Ptr &parent) |
1397 | 56 | { | 56 | { |
1398 | 57 | compiz::window::AsynchronousContainer::Ptr lastParent = boost::shared_static_cast <compiz::window::AsynchronousContainer> (child->container ()); | 57 | compiz::window::AsynchronousContainer::Ptr lastParent = boost::shared_static_cast <compiz::window::AsynchronousContainer> (child->container ()); |
1400 | 58 | lastParent->receiveRemoval (boost::shared_static_cast <compiz::window::Object> (child)); | 58 | |
1401 | 59 | if (lastParent) | ||
1402 | 60 | lastParent->receiveRemoval (boost::shared_static_cast <compiz::window::Object> (child)); | ||
1403 | 59 | parent->receiveInsertion (boost::shared_static_cast <compiz::window::Object> (child)); | 61 | parent->receiveInsertion (boost::shared_static_cast <compiz::window::Object> (child)); |
1404 | 60 | } | 62 | } |
1405 | 63 | |||
1406 | 64 | void | ||
1407 | 65 | compiz::window::ReadServerConnection::receiveState (const AsynchronousObject::Ptr &ao, | ||
1408 | 66 | uint64_t addState, | ||
1409 | 67 | uint64_t removeState) | ||
1410 | 68 | { | ||
1411 | 69 | ao->receiveState (addState, removeState); | ||
1412 | 70 | } | ||
1413 | 61 | 71 | ||
1414 | === modified file 'src/server-write.cpp' | |||
1415 | --- src/server-write.cpp 2012-01-19 18:25:05 +0000 | |||
1416 | +++ src/server-write.cpp 2012-01-19 18:25:06 +0000 | |||
1417 | @@ -55,5 +55,23 @@ | |||
1418 | 55 | mServer->sendParent (id, pid); | 55 | mServer->sendParent (id, pid); |
1419 | 56 | } | 56 | } |
1420 | 57 | 57 | ||
1422 | 58 | 58 | void | |
1423 | 59 | compiz::window::WriteServerConnection::sendCreateObject (const ObjectCreationRequest::Ptr &req) | ||
1424 | 60 | { | ||
1425 | 61 | mServer->sendCreateObject (req); | ||
1426 | 62 | } | ||
1427 | 63 | |||
1428 | 64 | void | ||
1429 | 65 | compiz::window::WriteServerConnection::sendDeleteObject (const ObjectIdentifier::Ptr &id) | ||
1430 | 66 | { | ||
1431 | 67 | mServer->sendDeleteObject (id); | ||
1432 | 68 | } | ||
1433 | 69 | |||
1434 | 70 | void | ||
1435 | 71 | compiz::window::WriteServerConnection::sendState (const ObjectIdentifier::Ptr &id, | ||
1436 | 72 | uint64_t addState, | ||
1437 | 73 | uint64_t removeState) | ||
1438 | 74 | { | ||
1439 | 75 | mServer->sendState (id, addState, removeState); | ||
1440 | 76 | } | ||
1441 | 59 | 77 | ||
1442 | 60 | 78 | ||
1443 | === modified file 'src/server.cpp' | |||
1444 | --- src/server.cpp 2012-01-19 18:25:05 +0000 | |||
1445 | +++ src/server.cpp 2012-01-19 18:25:06 +0000 | |||
1446 | @@ -40,8 +40,21 @@ | |||
1447 | 40 | return mDefault; | 40 | return mDefault; |
1448 | 41 | } | 41 | } |
1449 | 42 | 42 | ||
1450 | 43 | void | ||
1451 | 44 | compiz::window::Server::SetDefault (Server::Ptr s) | ||
1452 | 45 | { | ||
1453 | 46 | mDefault = s; | ||
1454 | 47 | } | ||
1455 | 48 | |||
1456 | 43 | const compiz::window::Object::Ptr & | 49 | const compiz::window::Object::Ptr & |
1457 | 44 | compiz::window::Server::root () | 50 | compiz::window::Server::root () |
1458 | 45 | { | 51 | { |
1459 | 46 | return mRoot; | 52 | return mRoot; |
1460 | 47 | } | 53 | } |
1461 | 54 | |||
1462 | 55 | void | ||
1463 | 56 | compiz::window::Server::setRoot (const compiz::window::Object::Ptr &root) | ||
1464 | 57 | { | ||
1465 | 58 | assert (!mRoot); | ||
1466 | 59 | mRoot = root; | ||
1467 | 60 | } | ||
1468 | 48 | 61 | ||
1469 | === added file 'src/x11-container.cpp' | |||
1470 | --- src/x11-container.cpp 1970-01-01 00:00:00 +0000 | |||
1471 | +++ src/x11-container.cpp 2012-01-19 18:25:06 +0000 | |||
1472 | @@ -0,0 +1,48 @@ | |||
1473 | 1 | /* | ||
1474 | 2 | * Copyright © 2010 Canonical Ltd. | ||
1475 | 3 | * | ||
1476 | 4 | * Permission to use, copy, modify, distribute, and sell this software | ||
1477 | 5 | * and its documentation for any purpose is hereby granted without | ||
1478 | 6 | * fee, provided that the above copyright notice appear in all copies | ||
1479 | 7 | * and that both that copyright notice and this permission notice | ||
1480 | 8 | * appear in supporting documentation, and that the name of | ||
1481 | 9 | * Canonical Ltd. not be used in advertising or publicity pertaining to | ||
1482 | 10 | * distribution of the software without specific, written prior permission. | ||
1483 | 11 | * Canonical Ltd. makes no representations about the suitability of this | ||
1484 | 12 | * software for any purpose. It is provided "as is" without express or | ||
1485 | 13 | * implied warranty. | ||
1486 | 14 | * | ||
1487 | 15 | * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
1488 | 16 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN | ||
1489 | 17 | * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
1490 | 18 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
1491 | 19 | * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | ||
1492 | 20 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | ||
1493 | 21 | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
1494 | 22 | * | ||
1495 | 23 | * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> | ||
1496 | 24 | */ | ||
1497 | 25 | |||
1498 | 26 | #include <core/container.h> | ||
1499 | 27 | #include <core/object.h> | ||
1500 | 28 | #include <core/x11-object.h> | ||
1501 | 29 | #include <boost/bind.hpp> | ||
1502 | 30 | #include <core/server-write.h> | ||
1503 | 31 | #include <core/windowgeometry.h> | ||
1504 | 32 | #include <core/stackposition.h> | ||
1505 | 33 | |||
1506 | 34 | compiz::window::X11Container::X11Container (const ObjectIdentifier::Ptr &id, | ||
1507 | 35 | const WriteServerConnection::Ptr &writer, | ||
1508 | 36 | const compiz::window::Geometry &g, | ||
1509 | 37 | const boost::shared_ptr <Container> &c) : | ||
1510 | 38 | compiz::window::Object::Object (id, g, compiz::window::StackPosition (), c), | ||
1511 | 39 | compiz::window::AsynchronousObject::AsynchronousObject (id, g, compiz::window::StackPosition (), c, writer), | ||
1512 | 40 | compiz::window::AsynchronousContainer (id, g, compiz::window::StackPosition (), c, writer), | ||
1513 | 41 | compiz::window::X11Object (id, writer, g, c) | ||
1514 | 42 | { | ||
1515 | 43 | } | ||
1516 | 44 | |||
1517 | 45 | compiz::window::X11Container::~X11Container () | ||
1518 | 46 | { | ||
1519 | 47 | } | ||
1520 | 48 | |||
1521 | 0 | 49 | ||
1522 | === added file 'src/x11-object.cpp' | |||
1523 | --- src/x11-object.cpp 1970-01-01 00:00:00 +0000 | |||
1524 | +++ src/x11-object.cpp 2012-01-19 18:25:06 +0000 | |||
1525 | @@ -0,0 +1,84 @@ | |||
1526 | 1 | /* | ||
1527 | 2 | * Copyright © 2010 Canonical Ltd. | ||
1528 | 3 | * | ||
1529 | 4 | * Permission to use, copy, modify, distribute, and sell this software | ||
1530 | 5 | * and its documentation for any purpose is hereby granted without | ||
1531 | 6 | * fee, provided that the above copyright notice appear in all copies | ||
1532 | 7 | * and that both that copyright notice and this permission notice | ||
1533 | 8 | * appear in supporting documentation, and that the name of | ||
1534 | 9 | * Canonical Ltd. not be used in advertising or publicity pertaining to | ||
1535 | 10 | * distribution of the software without specific, written prior permission. | ||
1536 | 11 | * Canonical Ltd. makes no representations about the suitability of this | ||
1537 | 12 | * software for any purpose. It is provided "as is" without express or | ||
1538 | 13 | * implied warranty. | ||
1539 | 14 | * | ||
1540 | 15 | * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
1541 | 16 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN | ||
1542 | 17 | * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
1543 | 18 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
1544 | 19 | * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | ||
1545 | 20 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | ||
1546 | 21 | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
1547 | 22 | * | ||
1548 | 23 | * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> | ||
1549 | 24 | */ | ||
1550 | 25 | |||
1551 | 26 | #include <core/x11-object.h> | ||
1552 | 27 | #include <core/x11-server.h> | ||
1553 | 28 | #include <core/server-write.h> | ||
1554 | 29 | #include <core/windowgeometry.h> | ||
1555 | 30 | #include <core/stackposition.h> | ||
1556 | 31 | #include <iostream> | ||
1557 | 32 | #include <cstdio> | ||
1558 | 33 | |||
1559 | 34 | compiz::window::X11Object::X11Object (const ObjectIdentifier::Ptr &id, | ||
1560 | 35 | const WriteServerConnection::Ptr &writer, | ||
1561 | 36 | const compiz::window::Geometry &g, | ||
1562 | 37 | const boost::shared_ptr <Container> &c) : | ||
1563 | 38 | compiz::window::Object::Object (id, g, compiz::window::StackPosition (), c), | ||
1564 | 39 | compiz::window::AsynchronousObject (id, g, compiz::window::StackPosition (), c, writer) | ||
1565 | 40 | { | ||
1566 | 41 | } | ||
1567 | 42 | |||
1568 | 43 | compiz::window::X11Object::~X11Object () | ||
1569 | 44 | { | ||
1570 | 45 | } | ||
1571 | 46 | |||
1572 | 47 | compiz::window::X11ObjectIdentifier::X11ObjectIdentifier (Window id) : | ||
1573 | 48 | compiz::window::ObjectIdentifier::ObjectIdentifier (), | ||
1574 | 49 | mId (id) | ||
1575 | 50 | { | ||
1576 | 51 | } | ||
1577 | 52 | |||
1578 | 53 | void | ||
1579 | 54 | compiz::window::X11ObjectIdentifier::print () | ||
1580 | 55 | { | ||
1581 | 56 | std::cout << "0x" << std::hex << mId; | ||
1582 | 57 | } | ||
1583 | 58 | |||
1584 | 59 | compiz::window::X11ObjectIdentifier::~X11ObjectIdentifier () | ||
1585 | 60 | { | ||
1586 | 61 | } | ||
1587 | 62 | |||
1588 | 63 | compiz::window::ObjectIdentifier::ObjectType | ||
1589 | 64 | compiz::window::X11ObjectIdentifier::getType () const | ||
1590 | 65 | { | ||
1591 | 66 | return X11; | ||
1592 | 67 | } | ||
1593 | 68 | |||
1594 | 69 | bool | ||
1595 | 70 | compiz::window::X11ObjectIdentifier::compare (const ObjectIdentifier::Ptr &id) const | ||
1596 | 71 | { | ||
1597 | 72 | const X11ObjectIdentifier::Ptr &xid = boost::shared_static_cast <X11ObjectIdentifier> (id); | ||
1598 | 73 | |||
1599 | 74 | return xid->mId == mId; | ||
1600 | 75 | } | ||
1601 | 76 | |||
1602 | 77 | boost::shared_ptr <compiz::window::Object> | ||
1603 | 78 | compiz::window::X11ObjectIdentifier::lookup () const | ||
1604 | 79 | { | ||
1605 | 80 | X11Server::Ptr server = boost::shared_static_cast <X11Server> (Server::Default ()); | ||
1606 | 81 | const boost::shared_ptr <const ObjectIdentifier> &ptr = boost::shared_static_cast <const ObjectIdentifier> (shared_from_this ()); | ||
1607 | 82 | |||
1608 | 83 | return server->lookup (ptr); | ||
1609 | 84 | } | ||
1610 | 0 | 85 | ||
1611 | === added file 'src/x11-server.cpp' | |||
1612 | --- src/x11-server.cpp 1970-01-01 00:00:00 +0000 | |||
1613 | +++ src/x11-server.cpp 2012-01-19 18:25:06 +0000 | |||
1614 | @@ -0,0 +1,456 @@ | |||
1615 | 1 | /* | ||
1616 | 2 | * Copyright © 2010 Canonical Ltd. | ||
1617 | 3 | * | ||
1618 | 4 | * Permission to use, copy, modify, distribute, and sell this software | ||
1619 | 5 | * and its documentation for any purpose is hereby granted without | ||
1620 | 6 | * fee, provided that the above copyright notice appear in all copies | ||
1621 | 7 | * and that both that copyright notice and this permission notice | ||
1622 | 8 | * appear in supporting documentation, and that the name of | ||
1623 | 9 | * Canonical Ltd. not be used in advertising or publicity pertaining to | ||
1624 | 10 | * distribution of the software without specific, written prior permission. | ||
1625 | 11 | * Canonical Ltd. makes no representations about the suitability of this | ||
1626 | 12 | * software for any purpose. It is provided "as is" without express or | ||
1627 | 13 | * implied warranty. | ||
1628 | 14 | * | ||
1629 | 15 | * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
1630 | 16 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN | ||
1631 | 17 | * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
1632 | 18 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
1633 | 19 | * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | ||
1634 | 20 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | ||
1635 | 21 | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
1636 | 22 | * | ||
1637 | 23 | * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> | ||
1638 | 24 | */ | ||
1639 | 25 | |||
1640 | 26 | #include <core/x11-server.h> | ||
1641 | 27 | #include <core/x11-object.h> | ||
1642 | 28 | #include <privateeventsource.h> | ||
1643 | 29 | #include <boost/bind.hpp> | ||
1644 | 30 | #include <sys/poll.h> | ||
1645 | 31 | |||
1646 | 32 | compiz::window::X11ObjectCreationRequest::X11ObjectCreationRequest (XSetWindowAttributes &attr, | ||
1647 | 33 | const compiz::window::Geometry &g, | ||
1648 | 34 | unsigned int cclass, | ||
1649 | 35 | unsigned int depth, | ||
1650 | 36 | const compiz::window::X11ObjectIdentifier::Ptr &parent, | ||
1651 | 37 | unsigned int attrValueMask, | ||
1652 | 38 | Visual *vis) : | ||
1653 | 39 | mAttr (attr), | ||
1654 | 40 | mGeometry (g), | ||
1655 | 41 | mClass (cclass), | ||
1656 | 42 | mDepth (depth), | ||
1657 | 43 | mParent (parent), | ||
1658 | 44 | mAttrValueMask (attrValueMask), | ||
1659 | 45 | mVis (vis) | ||
1660 | 46 | { | ||
1661 | 47 | } | ||
1662 | 48 | |||
1663 | 49 | compiz::window::X11ObjectCreationRequest::~X11ObjectCreationRequest () | ||
1664 | 50 | { | ||
1665 | 51 | } | ||
1666 | 52 | |||
1667 | 53 | XSetWindowAttributes & | ||
1668 | 54 | compiz::window::X11ObjectCreationRequest::attributes () const | ||
1669 | 55 | { | ||
1670 | 56 | return mAttr; | ||
1671 | 57 | } | ||
1672 | 58 | |||
1673 | 59 | const compiz::window::Geometry & | ||
1674 | 60 | compiz::window::X11ObjectCreationRequest::geometry () const | ||
1675 | 61 | { | ||
1676 | 62 | return mGeometry; | ||
1677 | 63 | } | ||
1678 | 64 | |||
1679 | 65 | const unsigned int & | ||
1680 | 66 | compiz::window::X11ObjectCreationRequest::cclass () const | ||
1681 | 67 | { | ||
1682 | 68 | return mClass; | ||
1683 | 69 | } | ||
1684 | 70 | |||
1685 | 71 | const unsigned int & | ||
1686 | 72 | compiz::window::X11ObjectCreationRequest::depth () const | ||
1687 | 73 | { | ||
1688 | 74 | return mDepth; | ||
1689 | 75 | } | ||
1690 | 76 | |||
1691 | 77 | const compiz::window::X11ObjectIdentifier::Ptr & | ||
1692 | 78 | compiz::window::X11ObjectCreationRequest::parent () const | ||
1693 | 79 | { | ||
1694 | 80 | return mParent; | ||
1695 | 81 | } | ||
1696 | 82 | |||
1697 | 83 | const unsigned int & | ||
1698 | 84 | compiz::window::X11ObjectCreationRequest::attrValueMask () const | ||
1699 | 85 | { | ||
1700 | 86 | return mAttrValueMask; | ||
1701 | 87 | } | ||
1702 | 88 | |||
1703 | 89 | Visual * | ||
1704 | 90 | compiz::window::X11ObjectCreationRequest::visual () const | ||
1705 | 91 | { | ||
1706 | 92 | return mVis; | ||
1707 | 93 | } | ||
1708 | 94 | |||
1709 | 95 | compiz::window::X11Server::X11Server () : | ||
1710 | 96 | compiz::window::AsynchronousServer::AsynchronousServer (), | ||
1711 | 97 | mDisplay (XOpenDisplay (NULL)) | ||
1712 | 98 | { | ||
1713 | 99 | if (!mDisplay) | ||
1714 | 100 | throw std::exception (); | ||
1715 | 101 | |||
1716 | 102 | setupEventSource (); | ||
1717 | 103 | } | ||
1718 | 104 | |||
1719 | 105 | compiz::window::X11Server::X11Server (const char *dname) : | ||
1720 | 106 | compiz::window::AsynchronousServer::AsynchronousServer (), | ||
1721 | 107 | mDisplay (XOpenDisplay (dname)) | ||
1722 | 108 | { | ||
1723 | 109 | if (!mDisplay) | ||
1724 | 110 | throw std::exception (); | ||
1725 | 111 | |||
1726 | 112 | setupEventSource (); | ||
1727 | 113 | } | ||
1728 | 114 | |||
1729 | 115 | compiz::window::X11Server::X11Server (Display *dpy) : | ||
1730 | 116 | compiz::window::AsynchronousServer::AsynchronousServer (), | ||
1731 | 117 | mDisplay (dpy) | ||
1732 | 118 | { | ||
1733 | 119 | setupEventSource (); | ||
1734 | 120 | } | ||
1735 | 121 | |||
1736 | 122 | void | ||
1737 | 123 | compiz::window::X11Server::setupEventSource () | ||
1738 | 124 | { | ||
1739 | 125 | CompEventSource *ev = CompEventSource::create (mDisplay, | ||
1740 | 126 | boost::bind (&X11Server::queueEvents, this)); | ||
1741 | 127 | Glib::RefPtr <Glib::Source> evrp = Glib::RefPtr <Glib::Source>::cast_static (Glib::RefPtr <CompEventSource> (ev)); | ||
1742 | 128 | |||
1743 | 129 | setEventSource (evrp); | ||
1744 | 130 | } | ||
1745 | 131 | |||
1746 | 132 | void | ||
1747 | 133 | compiz::window::X11Server::setRoot (Window root, const compiz::window::Geometry &g) | ||
1748 | 134 | { | ||
1749 | 135 | compiz::window::X11ObjectIdentifier::Ptr rootId = | ||
1750 | 136 | compiz::window::X11ObjectIdentifier::Ptr (new compiz::window::X11ObjectIdentifier (root)); | ||
1751 | 137 | const compiz::window::ObjectIdentifier::Ptr &genericRootId = boost::shared_static_cast <compiz::window::ObjectIdentifier> (rootId); | ||
1752 | 138 | const compiz::window::Object::Ptr &rootObj = createObject (genericRootId, g, compiz::window::StackPosition (), compiz::window::Container::Ptr ()); | ||
1753 | 139 | |||
1754 | 140 | Server::setRoot (rootObj); | ||
1755 | 141 | |||
1756 | 142 | XSetWindowAttributes xwa; | ||
1757 | 143 | |||
1758 | 144 | xwa.event_mask = StructureNotifyMask | | ||
1759 | 145 | SubstructureNotifyMask | | ||
1760 | 146 | SubstructureRedirectMask | | ||
1761 | 147 | ButtonPressMask | | ||
1762 | 148 | ButtonReleaseMask | | ||
1763 | 149 | KeyPressMask | | ||
1764 | 150 | KeyReleaseMask; | ||
1765 | 151 | |||
1766 | 152 | XChangeWindowAttributes (mDisplay, rootId->mId, CWEventMask, &xwa); | ||
1767 | 153 | XSync (mDisplay, 0); | ||
1768 | 154 | } | ||
1769 | 155 | |||
1770 | 156 | compiz::window::X11Server::~X11Server () | ||
1771 | 157 | { | ||
1772 | 158 | XCloseDisplay (mDisplay); | ||
1773 | 159 | } | ||
1774 | 160 | |||
1775 | 161 | void | ||
1776 | 162 | compiz::window::populateXWindowChanges (const compiz::window::Geometry &g, | ||
1777 | 163 | unsigned int mask, | ||
1778 | 164 | XWindowChanges &xwc) | ||
1779 | 165 | { | ||
1780 | 166 | if (mask & CWX) | ||
1781 | 167 | xwc.x = g.x (); | ||
1782 | 168 | if (mask & CWY) | ||
1783 | 169 | xwc.y = g.y (); | ||
1784 | 170 | if (mask & CWWidth) | ||
1785 | 171 | xwc.width = g.width (); | ||
1786 | 172 | if (mask & CWHeight) | ||
1787 | 173 | xwc.height = g.height (); | ||
1788 | 174 | if (mask & CWBorderWidth) | ||
1789 | 175 | xwc.border_width = g.border (); | ||
1790 | 176 | } | ||
1791 | 177 | |||
1792 | 178 | void | ||
1793 | 179 | compiz::window::populateXWindowChanges (const compiz::window::StackPosition &sp, | ||
1794 | 180 | unsigned int mask, | ||
1795 | 181 | XWindowChanges &xwc) | ||
1796 | 182 | { | ||
1797 | 183 | if (mask & CWStackMode) | ||
1798 | 184 | xwc.stack_mode = Above; | ||
1799 | 185 | if (mask & CWSibling) {} | ||
1800 | 186 | /* TODO: | ||
1801 | 187 | xwc.sibling = sp */ | ||
1802 | 188 | } | ||
1803 | 189 | |||
1804 | 190 | void | ||
1805 | 191 | compiz::window::X11Server::sendGeometry (const ObjectIdentifier::Ptr &id, | ||
1806 | 192 | const compiz::window::Geometry &g) | ||
1807 | 193 | { | ||
1808 | 194 | Object::Ptr o = (*id) (); | ||
1809 | 195 | unsigned int mask = g.changeMask (o->geometry ()); | ||
1810 | 196 | XWindowChanges xwc; | ||
1811 | 197 | |||
1812 | 198 | populateXWindowChanges (g, mask, xwc); | ||
1813 | 199 | |||
1814 | 200 | XConfigureWindow (mDisplay, (boost::static_pointer_cast<X11ObjectIdentifier> (id))->mId, mask, &xwc); | ||
1815 | 201 | } | ||
1816 | 202 | |||
1817 | 203 | void | ||
1818 | 204 | compiz::window::X11Server::sendStackPosition (const ObjectIdentifier::Ptr &id, | ||
1819 | 205 | const compiz::window::StackPosition &sp) | ||
1820 | 206 | { | ||
1821 | 207 | XWindowChanges xwc; | ||
1822 | 208 | unsigned int mask = CWStackMode | CWSibling; | ||
1823 | 209 | |||
1824 | 210 | populateXWindowChanges (sp, mask, xwc); | ||
1825 | 211 | |||
1826 | 212 | XConfigureWindow (mDisplay, (boost::static_pointer_cast<X11ObjectIdentifier> (id))->mId, mask, &xwc); | ||
1827 | 213 | } | ||
1828 | 214 | |||
1829 | 215 | void | ||
1830 | 216 | compiz::window::X11Server::sendParent (const ObjectIdentifier::Ptr &child, | ||
1831 | 217 | const ObjectIdentifier::Ptr &parent) | ||
1832 | 218 | { | ||
1833 | 219 | Window xchild = (boost::static_pointer_cast<X11ObjectIdentifier> (child))->mId; | ||
1834 | 220 | Window xparent = (boost::static_pointer_cast<X11ObjectIdentifier> (parent))->mId; | ||
1835 | 221 | |||
1836 | 222 | XReparentWindow (mDisplay, xchild, xparent, 0, 0); | ||
1837 | 223 | } | ||
1838 | 224 | |||
1839 | 225 | void | ||
1840 | 226 | compiz::window::X11Server::sendCreateObject (const boost::shared_ptr <compiz::window::ObjectCreationRequest> &req) | ||
1841 | 227 | { | ||
1842 | 228 | const compiz::window::X11ObjectCreationRequest::Ptr &xobjcreq = | ||
1843 | 229 | boost::shared_static_cast <compiz::window::X11ObjectCreationRequest> (req); | ||
1844 | 230 | |||
1845 | 231 | XCreateWindow (mDisplay, xobjcreq->parent ()->mId, xobjcreq->geometry ().x (), | ||
1846 | 232 | xobjcreq->geometry ().y (), xobjcreq->geometry ().width (), | ||
1847 | 233 | xobjcreq->geometry ().height (), xobjcreq->geometry ().border (), | ||
1848 | 234 | xobjcreq->depth (), | ||
1849 | 235 | xobjcreq->cclass (), | ||
1850 | 236 | xobjcreq->visual (), | ||
1851 | 237 | xobjcreq->attrValueMask (), | ||
1852 | 238 | &xobjcreq->attributes ()); | ||
1853 | 239 | } | ||
1854 | 240 | |||
1855 | 241 | void | ||
1856 | 242 | compiz::window::X11Server::sendDeleteObject (const ObjectIdentifier::Ptr &id) | ||
1857 | 243 | { | ||
1858 | 244 | const compiz::window::X11ObjectIdentifier::Ptr xid = | ||
1859 | 245 | boost::shared_static_cast <compiz::window::X11ObjectIdentifier> (id); | ||
1860 | 246 | |||
1861 | 247 | XDestroyWindow (mDisplay, xid->mId); | ||
1862 | 248 | } | ||
1863 | 249 | |||
1864 | 250 | void | ||
1865 | 251 | compiz::window::X11Server::sendState (const ObjectIdentifier::Ptr &id, | ||
1866 | 252 | uint64_t addState, | ||
1867 | 253 | uint64_t removeState) | ||
1868 | 254 | { | ||
1869 | 255 | const compiz::window::X11ObjectIdentifier::Ptr xid = | ||
1870 | 256 | boost::shared_static_cast <compiz::window::X11ObjectIdentifier> (id); | ||
1871 | 257 | |||
1872 | 258 | /* If something is being added and removed | ||
1873 | 259 | * then clear both operations */ | ||
1874 | 260 | addState &= ~removeState; | ||
1875 | 261 | removeState &= ~addState; | ||
1876 | 262 | |||
1877 | 263 | if (addState & compiz::window::Object::StateMapped) | ||
1878 | 264 | XMapWindow (mDisplay, xid->mId); | ||
1879 | 265 | else if (removeState & compiz::window::Object::StateMapped) | ||
1880 | 266 | XUnmapWindow (mDisplay, xid->mId); | ||
1881 | 267 | |||
1882 | 268 | return; | ||
1883 | 269 | } | ||
1884 | 270 | |||
1885 | 271 | void | ||
1886 | 272 | compiz::window::X11Server::dispatchRequests (unsigned int flags) | ||
1887 | 273 | { | ||
1888 | 274 | if (flags & compiz::window::AsynchronousServer::BlockUntilCompletion) | ||
1889 | 275 | XSync (mDisplay, flags & compiz::window::AsynchronousServer::DiscardGeneratedEvents ? true : false); | ||
1890 | 276 | else | ||
1891 | 277 | XFlush (mDisplay); | ||
1892 | 278 | } | ||
1893 | 279 | |||
1894 | 280 | compiz::window::Object::Ptr compiz::window::X11Server::lookup (const boost::shared_ptr <const ObjectIdentifier> &id) const | ||
1895 | 281 | { | ||
1896 | 282 | const X11ObjectIdentifier::ConstPtr &xid = boost::shared_static_cast <const X11ObjectIdentifier> (id); | ||
1897 | 283 | |||
1898 | 284 | const boost::unordered_map <Window, X11Object::Ptr>::const_iterator &it = mObjectTree.find (xid->mId); | ||
1899 | 285 | |||
1900 | 286 | if (it != mObjectTree.end ()) | ||
1901 | 287 | return mObjectTree.at (xid->mId); | ||
1902 | 288 | |||
1903 | 289 | return compiz::window::Object::Ptr (); | ||
1904 | 290 | } | ||
1905 | 291 | |||
1906 | 292 | void | ||
1907 | 293 | compiz::window::X11Server::dispatchEvent (XEvent *event) | ||
1908 | 294 | { | ||
1909 | 295 | /* FIXME: We're using boost::shared_polymorphic_cast here because | ||
1910 | 296 | * Object is virtually inherited by AsynchronousObject and AsynchronousContainer | ||
1911 | 297 | * as well as X11Object. Since there is no way that the compiler can know | ||
1912 | 298 | * what the offset of X11Object is going to be here, we need to use a runtime | ||
1913 | 299 | * cast */ | ||
1914 | 300 | switch (event->type) | ||
1915 | 301 | { | ||
1916 | 302 | case ConfigureNotify: | ||
1917 | 303 | { | ||
1918 | 304 | compiz::window::X11ObjectIdentifier::Ptr id = | ||
1919 | 305 | compiz::window::X11ObjectIdentifier::Ptr ( | ||
1920 | 306 | new compiz::window::X11ObjectIdentifier (event->xconfigure.window)); | ||
1921 | 307 | |||
1922 | 308 | const compiz::window::X11Object::Ptr &xo = boost::shared_polymorphic_cast <compiz::window::X11Object> ((*id) ()); | ||
1923 | 309 | compiz::window::Geometry g (event->xconfigure.x, | ||
1924 | 310 | event->xconfigure.y, | ||
1925 | 311 | event->xconfigure.width, | ||
1926 | 312 | event->xconfigure.height, | ||
1927 | 313 | event->xconfigure.border_width); | ||
1928 | 314 | compiz::window::StackPosition sp; | ||
1929 | 315 | |||
1930 | 316 | mReadConnection->receiveGeometry (xo, g); | ||
1931 | 317 | mReadConnection->receiveStackPosition (xo, sp); | ||
1932 | 318 | } | ||
1933 | 319 | break; | ||
1934 | 320 | case ReparentNotify: | ||
1935 | 321 | { | ||
1936 | 322 | compiz::window::X11ObjectIdentifier::Ptr childId = | ||
1937 | 323 | compiz::window::X11ObjectIdentifier::Ptr ( | ||
1938 | 324 | new compiz::window::X11ObjectIdentifier (event->xreparent.window)); | ||
1939 | 325 | compiz::window::X11ObjectIdentifier::Ptr parentId = | ||
1940 | 326 | compiz::window::X11ObjectIdentifier::Ptr ( | ||
1941 | 327 | new compiz::window::X11ObjectIdentifier (event->xreparent.parent)); | ||
1942 | 328 | |||
1943 | 329 | compiz::window::X11Object::Ptr child = boost::shared_polymorphic_cast <compiz::window::X11Object> ((*childId) ()); | ||
1944 | 330 | compiz::window::X11Container::Ptr parent = boost::shared_polymorphic_cast <compiz::window::X11Container> ((*parentId) ()); | ||
1945 | 331 | |||
1946 | 332 | mReadConnection->receiveParent (child, parent); | ||
1947 | 333 | } | ||
1948 | 334 | break; | ||
1949 | 335 | case CreateNotify: | ||
1950 | 336 | { | ||
1951 | 337 | compiz::window::X11ObjectIdentifier::Ptr childId = | ||
1952 | 338 | compiz::window::X11ObjectIdentifier::Ptr ( | ||
1953 | 339 | new compiz::window::X11ObjectIdentifier (event->xcreatewindow.window)); | ||
1954 | 340 | compiz::window::X11ObjectIdentifier::Ptr parentId = | ||
1955 | 341 | compiz::window::X11ObjectIdentifier::Ptr ( | ||
1956 | 342 | new compiz::window::X11ObjectIdentifier (event->xcreatewindow.parent)); | ||
1957 | 343 | |||
1958 | 344 | /* Need to create the child first */ | ||
1959 | 345 | compiz::window::X11Container::Ptr parent = boost::shared_polymorphic_cast <compiz::window::X11Container> ((*parentId) ()); | ||
1960 | 346 | compiz::window::X11Object::Ptr child = | ||
1961 | 347 | boost::shared_polymorphic_cast <compiz::window::X11Object> (createObject (boost::shared_static_cast <compiz::window::ObjectIdentifier> (childId), | ||
1962 | 348 | compiz::window::Geometry (event->xcreatewindow.x, | ||
1963 | 349 | event->xcreatewindow.y, | ||
1964 | 350 | event->xcreatewindow.width, | ||
1965 | 351 | event->xcreatewindow.height, | ||
1966 | 352 | event->xcreatewindow.border_width), | ||
1967 | 353 | compiz::window::StackPosition (), | ||
1968 | 354 | parent)); | ||
1969 | 355 | |||
1970 | 356 | mReadConnection->receiveParent (child, parent); | ||
1971 | 357 | } | ||
1972 | 358 | break; | ||
1973 | 359 | case DestroyNotify: | ||
1974 | 360 | { | ||
1975 | 361 | compiz::window::X11ObjectIdentifier::Ptr windowId = | ||
1976 | 362 | compiz::window::X11ObjectIdentifier::Ptr ( | ||
1977 | 363 | new compiz::window::X11ObjectIdentifier (event->xdestroywindow.window)); | ||
1978 | 364 | compiz::window::X11Object::Ptr window = boost::shared_polymorphic_cast <compiz::window::X11Object> ((*windowId) ()); | ||
1979 | 365 | compiz::window::X11Container::Ptr newParent = compiz::window::X11Container::Ptr (); | ||
1980 | 366 | |||
1981 | 367 | mReadConnection->receiveParent (window, newParent); | ||
1982 | 368 | } | ||
1983 | 369 | break; | ||
1984 | 370 | case MapNotify: | ||
1985 | 371 | { | ||
1986 | 372 | compiz::window::X11ObjectIdentifier::Ptr windowId = | ||
1987 | 373 | compiz::window::X11ObjectIdentifier::Ptr ( | ||
1988 | 374 | new compiz::window::X11ObjectIdentifier (event->xdestroywindow.window)); | ||
1989 | 375 | compiz::window::X11Object::Ptr window = boost::shared_polymorphic_cast <compiz::window::X11Object> ((*windowId) ()); | ||
1990 | 376 | |||
1991 | 377 | mReadConnection->receiveState (window, compiz::window::Object::StateMapped, 0); | ||
1992 | 378 | } | ||
1993 | 379 | break; | ||
1994 | 380 | case UnmapNotify: | ||
1995 | 381 | { | ||
1996 | 382 | compiz::window::X11ObjectIdentifier::Ptr windowId = | ||
1997 | 383 | compiz::window::X11ObjectIdentifier::Ptr ( | ||
1998 | 384 | new compiz::window::X11ObjectIdentifier (event->xdestroywindow.window)); | ||
1999 | 385 | compiz::window::X11Object::Ptr window = boost::shared_polymorphic_cast <compiz::window::X11Object> ((*windowId) ()); | ||
2000 | 386 | |||
2001 | 387 | mReadConnection->receiveState (window, 0, compiz::window::Object::StateMapped); | ||
2002 | 388 | } | ||
2003 | 389 | break; | ||
2004 | 390 | default: | ||
2005 | 391 | break; | ||
2006 | 392 | |||
2007 | 393 | } | ||
2008 | 394 | } | ||
2009 | 395 | |||
2010 | 396 | void | ||
2011 | 397 | compiz::window::X11Server::queueEvents () | ||
2012 | 398 | { | ||
2013 | 399 | std::vector <XEvent> events; | ||
2014 | 400 | |||
2015 | 401 | while (XPending (mDisplay)) | ||
2016 | 402 | { | ||
2017 | 403 | XEvent event, peekEvent; | ||
2018 | 404 | XNextEvent (mDisplay, &event); | ||
2019 | 405 | |||
2020 | 406 | /* Skip to the last MotionNotify | ||
2021 | 407 | * event in this sequence */ | ||
2022 | 408 | if (event.type == MotionNotify) | ||
2023 | 409 | { | ||
2024 | 410 | while (XPending (mDisplay)) | ||
2025 | 411 | { | ||
2026 | 412 | XPeekEvent (mDisplay, &peekEvent); | ||
2027 | 413 | |||
2028 | 414 | if (peekEvent.type != MotionNotify) | ||
2029 | 415 | break; | ||
2030 | 416 | |||
2031 | 417 | XNextEvent (mDisplay, &event); | ||
2032 | 418 | } | ||
2033 | 419 | } | ||
2034 | 420 | |||
2035 | 421 | events.push_back (event); | ||
2036 | 422 | } | ||
2037 | 423 | |||
2038 | 424 | for (std::vector <XEvent>::iterator it = events.begin (); | ||
2039 | 425 | it != events.end (); | ||
2040 | 426 | it++) | ||
2041 | 427 | dispatchEvent (&(*it)); | ||
2042 | 428 | } | ||
2043 | 429 | |||
2044 | 430 | void | ||
2045 | 431 | compiz::window::X11Server::addObjectToTree (const std::pair <compiz::window::X11ObjectIdentifier::Ptr, | ||
2046 | 432 | compiz::window::X11Object::Ptr> &keyValue) | ||
2047 | 433 | { | ||
2048 | 434 | if (mObjectTree.find (keyValue.first->mId) != mObjectTree.end ()) | ||
2049 | 435 | throw std::exception (); | ||
2050 | 436 | |||
2051 | 437 | XSetWindowAttributes xwa; | ||
2052 | 438 | |||
2053 | 439 | xwa.event_mask = SubstructureNotifyMask | | ||
2054 | 440 | ButtonPressMask | | ||
2055 | 441 | ButtonReleaseMask | | ||
2056 | 442 | KeyPressMask | | ||
2057 | 443 | KeyReleaseMask; | ||
2058 | 444 | |||
2059 | 445 | XSynchronize (mDisplay, true); | ||
2060 | 446 | XChangeWindowAttributes (mDisplay, keyValue.first->mId, CWEventMask, &xwa); | ||
2061 | 447 | |||
2062 | 448 | mObjectTree[keyValue.first->mId] = keyValue.second; | ||
2063 | 449 | } | ||
2064 | 450 | |||
2065 | 451 | void | ||
2066 | 452 | compiz::window::X11Server::removeKeyFromTree (const ObjectIdentifier::Ptr &id) | ||
2067 | 453 | { | ||
2068 | 454 | const compiz::window::X11ObjectIdentifier::Ptr &xid = boost::shared_static_cast <compiz::window::X11ObjectIdentifier> (id); | ||
2069 | 455 | mObjectTree.erase (xid->mId); | ||
2070 | 456 | } | ||
2071 | 0 | 457 | ||
2072 | === added directory 'tests/standalone' | |||
2073 | === added file 'tests/standalone/CMakeLists.txt' | |||
2074 | --- tests/standalone/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
2075 | +++ tests/standalone/CMakeLists.txt 2012-01-19 18:25:06 +0000 | |||
2076 | @@ -0,0 +1,1 @@ | |||
2077 | 1 | add_subdirectory (objects) | ||
2078 | 0 | 2 | ||
2079 | === added directory 'tests/standalone/objects' | |||
2080 | === added file 'tests/standalone/objects/CMakeLists.txt' | |||
2081 | --- tests/standalone/objects/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
2082 | +++ tests/standalone/objects/CMakeLists.txt 2012-01-19 18:25:06 +0000 | |||
2083 | @@ -0,0 +1,23 @@ | |||
2084 | 1 | find_package (Boost REQUIRED) | ||
2085 | 2 | |||
2086 | 3 | pkg_check_modules (COMPIZ_OBJECTS_STANDALONE_TEST glibmm-2.4 x11) | ||
2087 | 4 | |||
2088 | 5 | if (COMPIZ_OBJECTS_STANDALONE_TEST_FOUND) | ||
2089 | 6 | |||
2090 | 7 | set (COMPIZ_OBJECTS_STANDALONE_TEST_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
2091 | 8 | set (COMPIZ_OBJECTS_STANDALONE_TEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) | ||
2092 | 9 | |||
2093 | 10 | include_directories (${COMPIZ_OBJECTS_STANDALONE_TEST_INCLUDE_DIRS} | ||
2094 | 11 | ${CMAKE_CURRENT_SOURCE_DIR} | ||
2095 | 12 | ${compiz_SOURCE_DIR}/src | ||
2096 | 13 | ${compiz_SOURCE_DIR}/include | ||
2097 | 14 | ${Boost_INCLUDE_DIRS}) | ||
2098 | 15 | link_directories (${COMPIZ_OBJECT_STANDALONE_TEST_LINK_DIRS} | ||
2099 | 16 | ${Boost_LINK_DIRS}) | ||
2100 | 17 | add_library (commandparser STATIC ${CMAKE_CURRENT_SOURCE_DIR}/command-parser.cpp) | ||
2101 | 18 | |||
2102 | 19 | target_link_libraries (commandparser ${COMPIZ_OBJECTS_STANDALONE_TEST_LIBRARIES} ${Boost_LIBRARIES}) | ||
2103 | 20 | |||
2104 | 21 | add_subdirectory (x11) | ||
2105 | 22 | |||
2106 | 23 | endif (COMPIZ_OBJECTS_STANDALONE_TEST_FOUND) | ||
2107 | 0 | 24 | ||
2108 | === added file 'tests/standalone/objects/command-parser.cpp' | |||
2109 | --- tests/standalone/objects/command-parser.cpp 1970-01-01 00:00:00 +0000 | |||
2110 | +++ tests/standalone/objects/command-parser.cpp 2012-01-19 18:25:06 +0000 | |||
2111 | @@ -0,0 +1,449 @@ | |||
2112 | 1 | /* | ||
2113 | 2 | * Copyright © 2010 Canonical Ltd. | ||
2114 | 3 | * | ||
2115 | 4 | * Permission to use, copy, modify, distribute, and sell this software | ||
2116 | 5 | * and its documentation for any purpose is hereby granted without | ||
2117 | 6 | * fee, provided that the above copyright notice appear in all copies | ||
2118 | 7 | * and that both that copyright notice and this permission notice | ||
2119 | 8 | * appear in supporting documentation, and that the name of | ||
2120 | 9 | * Canonical Ltd. not be used in advertising or publicity pertaining to | ||
2121 | 10 | * distribution of the software without specific, written prior permission. | ||
2122 | 11 | * Canonical Ltd. makes no representations about the suitability of this | ||
2123 | 12 | * software for any purpose. It is provided "as is" without express or | ||
2124 | 13 | * implied warranty. | ||
2125 | 14 | * | ||
2126 | 15 | * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
2127 | 16 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN | ||
2128 | 17 | * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
2129 | 18 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
2130 | 19 | * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | ||
2131 | 20 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | ||
2132 | 21 | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
2133 | 22 | * | ||
2134 | 23 | * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> | ||
2135 | 24 | */ | ||
2136 | 25 | |||
2137 | 26 | #include <command-parser.h> | ||
2138 | 27 | |||
2139 | 28 | Glib::RefPtr <StdinSource> | ||
2140 | 29 | StdinSource::create (const Glib::RefPtr <Glib::MainLoop> &ml) | ||
2141 | 30 | { | ||
2142 | 31 | return Glib::RefPtr <StdinSource> (new StdinSource (ml)); | ||
2143 | 32 | } | ||
2144 | 33 | |||
2145 | 34 | StdinSource::StdinSource (const Glib::RefPtr <Glib::MainLoop> &ml) : | ||
2146 | 35 | Glib::IOSource (STDIN_FILENO, Glib::IO_IN | Glib::IO_HUP), | ||
2147 | 36 | mMainLoop (ml) | ||
2148 | 37 | { | ||
2149 | 38 | connect (sigc::mem_fun <Glib::IOCondition, bool, StdinSource> (this, &StdinSource::callback)); | ||
2150 | 39 | attach (Glib::MainContext::get_default ()); | ||
2151 | 40 | } | ||
2152 | 41 | |||
2153 | 42 | Parser::Parser (const std::string &token, std::string::const_iterator begin, std::string::const_iterator end) : | ||
2154 | 43 | mBegin (begin), | ||
2155 | 44 | mEnd (end), | ||
2156 | 45 | mAdvanceLength (token.size ()) | ||
2157 | 46 | { | ||
2158 | 47 | } | ||
2159 | 48 | |||
2160 | 49 | Parser::Parser (unsigned int n, std::string::const_iterator begin, std::string::const_iterator end) : | ||
2161 | 50 | mBegin (begin), | ||
2162 | 51 | mEnd (end), | ||
2163 | 52 | mAdvanceLength (n) | ||
2164 | 53 | { | ||
2165 | 54 | } | ||
2166 | 55 | |||
2167 | 56 | Parser::~Parser () | ||
2168 | 57 | { | ||
2169 | 58 | } | ||
2170 | 59 | |||
2171 | 60 | void | ||
2172 | 61 | Parser::advance () | ||
2173 | 62 | { | ||
2174 | 63 | std::advance (mBegin, mAdvanceLength); | ||
2175 | 64 | } | ||
2176 | 65 | |||
2177 | 66 | void | ||
2178 | 67 | Parser::advance (unsigned int n) | ||
2179 | 68 | { | ||
2180 | 69 | std::advance (mBegin, n); | ||
2181 | 70 | } | ||
2182 | 71 | |||
2183 | 72 | void | ||
2184 | 73 | Parser::parse (boost::spirit::unused_type r, boost::spirit::unused_type, bool &) | ||
2185 | 74 | { | ||
2186 | 75 | r = parseStringIterators (mBegin, mEnd); | ||
2187 | 76 | } | ||
2188 | 77 | |||
2189 | 78 | GeometryParser::GeometryParser (std::string::const_iterator begin, std::string::const_iterator end, const compiz::window::Geometry &old) : | ||
2190 | 79 | Parser ("geometry", begin, end), | ||
2191 | 80 | mGeometry (old) | ||
2192 | 81 | { | ||
2193 | 82 | } | ||
2194 | 83 | |||
2195 | 84 | GeometryParser::~GeometryParser () | ||
2196 | 85 | { | ||
2197 | 86 | } | ||
2198 | 87 | |||
2199 | 88 | bool | ||
2200 | 89 | GeometryParser::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end) | ||
2201 | 90 | { | ||
2202 | 91 | advance (); | ||
2203 | 92 | int x, y; | ||
2204 | 93 | unsigned int width, height, border; | ||
2205 | 94 | |||
2206 | 95 | using boost::spirit::qi::uint_; | ||
2207 | 96 | using boost::spirit::qi::int_; | ||
2208 | 97 | using boost::spirit::qi::_1; | ||
2209 | 98 | using boost::spirit::qi::phrase_parse; | ||
2210 | 99 | using boost::spirit::ascii::space; | ||
2211 | 100 | using boost::phoenix::ref; | ||
2212 | 101 | |||
2213 | 102 | advance (1); | ||
2214 | 103 | if (boost::spirit::qi::parse (mBegin, mEnd, | ||
2215 | 104 | '(' >> int_[ref (x) = _1] >> ", " >> | ||
2216 | 105 | int_[ref (y) = _1] >> ", " >> | ||
2217 | 106 | uint_[ref (width) = _1] >> ", " >> | ||
2218 | 107 | uint_[ref (height) = _1] >> ", " >> | ||
2219 | 108 | uint_[ref (border) = _1] >> ')')) | ||
2220 | 109 | { | ||
2221 | 110 | mGeometry.set (x, y, width, height, border); | ||
2222 | 111 | return true; | ||
2223 | 112 | } | ||
2224 | 113 | |||
2225 | 114 | std::cout << "geometry (" << mGeometry.x () << ", " | ||
2226 | 115 | << mGeometry.y () << ", " | ||
2227 | 116 | << mGeometry.width () << ", " | ||
2228 | 117 | << mGeometry.height () << ", " | ||
2229 | 118 | << mGeometry.border () << ")" << std::endl; | ||
2230 | 119 | return false; | ||
2231 | 120 | } | ||
2232 | 121 | |||
2233 | 122 | ObjectsParser::ObjectsParser (std::string::const_iterator begin, std::string::const_iterator end, const compiz::window::Container::Children &old) : | ||
2234 | 123 | Parser ("objects", begin, end), | ||
2235 | 124 | mChildren (old) | ||
2236 | 125 | { | ||
2237 | 126 | } | ||
2238 | 127 | |||
2239 | 128 | ObjectsParser::~ObjectsParser () | ||
2240 | 129 | { | ||
2241 | 130 | } | ||
2242 | 131 | |||
2243 | 132 | bool | ||
2244 | 133 | ObjectsParser::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end) | ||
2245 | 134 | { | ||
2246 | 135 | advance (); | ||
2247 | 136 | std::vector <unsigned int> v (0); | ||
2248 | 137 | |||
2249 | 138 | using boost::spirit::qi::hex; | ||
2250 | 139 | using boost::spirit::qi::_1; | ||
2251 | 140 | using boost::spirit::qi::phrase_parse; | ||
2252 | 141 | using boost::spirit::ascii::space; | ||
2253 | 142 | using boost::phoenix::ref; | ||
2254 | 143 | using boost::phoenix::push_back; | ||
2255 | 144 | |||
2256 | 145 | advance (1); | ||
2257 | 146 | if (boost::spirit::qi::parse (mBegin, mEnd, | ||
2258 | 147 | "(0x" >> hex[push_back (ref (v), _1)] | ||
2259 | 148 | >> *(",0x" >> hex[push_back (ref (v), _1)]) >> ")" | ||
2260 | 149 | )) | ||
2261 | 150 | { | ||
2262 | 151 | mChildren.clear (); | ||
2263 | 152 | for (std::vector <unsigned int>::iterator it = v.begin (); | ||
2264 | 153 | it != v.end (); | ||
2265 | 154 | it++) | ||
2266 | 155 | { | ||
2267 | 156 | compiz::window::X11ObjectIdentifier::Ptr xid = compiz::window::X11ObjectIdentifier::Ptr (new compiz::window::X11ObjectIdentifier ((*it))); | ||
2268 | 157 | const compiz::window::Object::Ptr &obj = (*xid) (); | ||
2269 | 158 | mChildren.push_back (obj); | ||
2270 | 159 | } | ||
2271 | 160 | return true; | ||
2272 | 161 | } | ||
2273 | 162 | |||
2274 | 163 | std::cout << "objects -" << std::endl; | ||
2275 | 164 | for (compiz::window::Container::Children::iterator it = mChildren.begin (); | ||
2276 | 165 | it != mChildren.end (); | ||
2277 | 166 | it++) | ||
2278 | 167 | { | ||
2279 | 168 | compiz::window::Object::Ptr obj = (*it); | ||
2280 | 169 | const compiz::window::ObjectIdentifier::Ptr &id = obj->id (); | ||
2281 | 170 | const compiz::window::X11ObjectIdentifier::Ptr xid = boost::shared_static_cast <compiz::window::X11ObjectIdentifier> (id); | ||
2282 | 171 | |||
2283 | 172 | std::cout << " - id: "; | ||
2284 | 173 | xid->print (); | ||
2285 | 174 | std::cout << std::endl; | ||
2286 | 175 | } | ||
2287 | 176 | |||
2288 | 177 | mChildren.clear (); | ||
2289 | 178 | |||
2290 | 179 | return false; | ||
2291 | 180 | } | ||
2292 | 181 | |||
2293 | 182 | CreateParser::CreateParser (std::string::const_iterator begin, std::string::const_iterator end) : | ||
2294 | 183 | Parser ("create", begin, end) | ||
2295 | 184 | { | ||
2296 | 185 | } | ||
2297 | 186 | |||
2298 | 187 | CreateParser::~CreateParser () | ||
2299 | 188 | { | ||
2300 | 189 | } | ||
2301 | 190 | |||
2302 | 191 | bool | ||
2303 | 192 | CreateParser::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end) | ||
2304 | 193 | { | ||
2305 | 194 | advance (); | ||
2306 | 195 | bool input; | ||
2307 | 196 | bool override = false; | ||
2308 | 197 | unsigned int parent; | ||
2309 | 198 | int x, y; | ||
2310 | 199 | unsigned int width, height, border; | ||
2311 | 200 | |||
2312 | 201 | using boost::spirit::qi::hex; | ||
2313 | 202 | using boost::spirit::qi::uint_; | ||
2314 | 203 | using boost::spirit::qi::int_; | ||
2315 | 204 | using boost::spirit::qi::bool_; | ||
2316 | 205 | using boost::spirit::qi::_1; | ||
2317 | 206 | using boost::spirit::qi::phrase_parse; | ||
2318 | 207 | using boost::spirit::ascii::space; | ||
2319 | 208 | using boost::phoenix::ref; | ||
2320 | 209 | using boost::phoenix::push_back; | ||
2321 | 210 | |||
2322 | 211 | advance (1); | ||
2323 | 212 | if (boost::spirit::qi::parse (mBegin, mEnd, | ||
2324 | 213 | "(0x" >> hex[ref (parent) = _1] | ||
2325 | 214 | >> ", (" >> int_[ref (x) = _1] >> ", " >> | ||
2326 | 215 | int_[ref (y) = _1] >> ", " >> | ||
2327 | 216 | uint_[ref (width) = _1] >> ", " >> | ||
2328 | 217 | uint_[ref (height) = _1] >> ", " >> | ||
2329 | 218 | uint_[ref (border) = _1] >> "), " >> | ||
2330 | 219 | bool_[ref (input) = _1] >> ", " >> | ||
2331 | 220 | bool_[ref (override) = _1] >> ")")) | ||
2332 | 221 | { | ||
2333 | 222 | XSetWindowAttributes childAttr; | ||
2334 | 223 | unsigned int mask = 0; | ||
2335 | 224 | compiz::window::X11ObjectIdentifier::Ptr parentId = compiz::window::X11ObjectIdentifier::Ptr (new compiz::window::X11ObjectIdentifier (parent)); | ||
2336 | 225 | |||
2337 | 226 | if (override) | ||
2338 | 227 | { | ||
2339 | 228 | childAttr.override_redirect = 1; | ||
2340 | 229 | mask |= CWOverrideRedirect; | ||
2341 | 230 | } | ||
2342 | 231 | |||
2343 | 232 | |||
2344 | 233 | mXcreq = compiz::window::X11ObjectCreationRequest::Ptr (new compiz::window::X11ObjectCreationRequest (childAttr, compiz::window::Geometry (x, y, width, height, border), | ||
2345 | 234 | input ? InputOnly : InputOutput, CopyFromParent, | ||
2346 | 235 | parentId, | ||
2347 | 236 | mask, CopyFromParent)); | ||
2348 | 237 | |||
2349 | 238 | return true; | ||
2350 | 239 | } | ||
2351 | 240 | else | ||
2352 | 241 | std::cout << "USAGE: create (parentId, (x,y,width,height,border), input_only, override)" << std::endl; | ||
2353 | 242 | |||
2354 | 243 | |||
2355 | 244 | return false; | ||
2356 | 245 | } | ||
2357 | 246 | |||
2358 | 247 | StackPositionParser::StackPositionParser (std::string::const_iterator begin, std::string::const_iterator end, const compiz::window::StackPosition &old) : | ||
2359 | 248 | Parser ("stackposition", begin, end), | ||
2360 | 249 | mStackPosition (old) | ||
2361 | 250 | { | ||
2362 | 251 | } | ||
2363 | 252 | |||
2364 | 253 | StackPositionParser::~StackPositionParser () | ||
2365 | 254 | { | ||
2366 | 255 | } | ||
2367 | 256 | |||
2368 | 257 | bool | ||
2369 | 258 | StackPositionParser::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end) | ||
2370 | 259 | { | ||
2371 | 260 | return false; | ||
2372 | 261 | } | ||
2373 | 262 | |||
2374 | 263 | PropertyParser::PropertyParser (std::string::const_iterator begin, std::string::const_iterator end, uint64_t old) : | ||
2375 | 264 | Parser ("property", begin, end), | ||
2376 | 265 | mProperties (old) | ||
2377 | 266 | { | ||
2378 | 267 | } | ||
2379 | 268 | |||
2380 | 269 | PropertyParser::~PropertyParser () | ||
2381 | 270 | { | ||
2382 | 271 | } | ||
2383 | 272 | |||
2384 | 273 | bool | ||
2385 | 274 | PropertyParser::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end) | ||
2386 | 275 | { | ||
2387 | 276 | return false; | ||
2388 | 277 | } | ||
2389 | 278 | |||
2390 | 279 | XidParser::XidParser (std::string::const_iterator begin, std::string::const_iterator end) : | ||
2391 | 280 | Parser (2, begin, end) | ||
2392 | 281 | { | ||
2393 | 282 | } | ||
2394 | 283 | |||
2395 | 284 | XidParser::~XidParser () | ||
2396 | 285 | { | ||
2397 | 286 | } | ||
2398 | 287 | |||
2399 | 288 | bool | ||
2400 | 289 | XidParser::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end) | ||
2401 | 290 | { | ||
2402 | 291 | advance (); | ||
2403 | 292 | using boost::spirit::qi::hex; | ||
2404 | 293 | using boost::spirit::qi::_1; | ||
2405 | 294 | using boost::spirit::qi::phrase_parse; | ||
2406 | 295 | using boost::spirit::ascii::space; | ||
2407 | 296 | using boost::phoenix::ref; | ||
2408 | 297 | unsigned int uxid = 0; | ||
2409 | 298 | |||
2410 | 299 | if (boost::spirit::qi::parse (mBegin, mEnd, hex[ref(uxid) = _1], space)) | ||
2411 | 300 | { | ||
2412 | 301 | compiz::window::X11ObjectIdentifier::Ptr xid = compiz::window::X11ObjectIdentifier::Ptr (new compiz::window::X11ObjectIdentifier (uxid)); | ||
2413 | 302 | compiz::window::Object::Ptr o = (*xid) (); | ||
2414 | 303 | const compiz::window::X11Container::Ptr &xc = boost::shared_dynamic_cast <compiz::window::X11Container> (o); | ||
2415 | 304 | if (!o) | ||
2416 | 305 | return false; | ||
2417 | 306 | else | ||
2418 | 307 | { | ||
2419 | 308 | std::advance (mBegin, 1); | ||
2420 | 309 | GeometryParser gp (mBegin, mEnd, o->geometry ()); | ||
2421 | 310 | StackPositionParser sp (mBegin, mEnd, o->stackPosition ()); | ||
2422 | 311 | PropertyParser pp (mBegin, mEnd, o->state ()); | ||
2423 | 312 | ObjectsParser op (mBegin, mEnd, xc ? xc->children () : compiz::window::Container::Children (0)); | ||
2424 | 313 | if (boost::spirit::qi::parse (mBegin, mEnd, | ||
2425 | 314 | boost::spirit::qi::lit ("geometry")[boost::bind (&GeometryParser::parse, &gp, _1, _2, _3)])) | ||
2426 | 315 | { | ||
2427 | 316 | /* Send new geometry */ | ||
2428 | 317 | const compiz::window::X11Server::Ptr &serverp = boost::shared_static_cast <compiz::window::X11Server> (compiz::window::Server::Default ()); | ||
2429 | 318 | compiz::window::WriteServerConnection::Ptr conn = serverp->connect (); | ||
2430 | 319 | conn->sendGeometry (o->id (), gp.geometry ()); | ||
2431 | 320 | serverp->flush (0); | ||
2432 | 321 | return true; | ||
2433 | 322 | } | ||
2434 | 323 | else if (boost::spirit::qi::parse (mBegin, mEnd, | ||
2435 | 324 | boost::spirit::qi::lit ("stackposition")[boost::bind (&StackPositionParser::parse, &sp, _1, _2, _3)])) | ||
2436 | 325 | { | ||
2437 | 326 | return true; | ||
2438 | 327 | } | ||
2439 | 328 | else if (boost::spirit::qi::parse (mBegin, mEnd, | ||
2440 | 329 | boost::spirit::qi::lit ("properties")[boost::bind (&PropertyParser::parse, &pp, 1, _2, _3)])) | ||
2441 | 330 | { | ||
2442 | 331 | return true; | ||
2443 | 332 | } | ||
2444 | 333 | else if (boost::spirit::qi::parse (mBegin, mEnd, | ||
2445 | 334 | boost::spirit::qi::lit ("objects")[boost::bind (&ObjectsParser::parse, &op, 1, _2, _3)])) | ||
2446 | 335 | { | ||
2447 | 336 | /* Send removal of any children from parents and send insertion | ||
2448 | 337 | * to this parent */ | ||
2449 | 338 | if (xc) | ||
2450 | 339 | { | ||
2451 | 340 | for (compiz::window::Container::Children::const_iterator it = op.children ().begin (); | ||
2452 | 341 | it != op.children ().end (); | ||
2453 | 342 | it++) | ||
2454 | 343 | { | ||
2455 | 344 | const compiz::window::Object::Ptr &oc = (*it); | ||
2456 | 345 | const compiz::window::Container::Ptr &pc = oc->container (); | ||
2457 | 346 | const compiz::window::AsynchronousContainer::Ptr &apc = boost::shared_dynamic_cast <compiz::window::AsynchronousContainer> (pc); | ||
2458 | 347 | |||
2459 | 348 | if (apc) | ||
2460 | 349 | { | ||
2461 | 350 | apc->sendRemoval (oc); | ||
2462 | 351 | xc->sendInsertion (oc); | ||
2463 | 352 | } | ||
2464 | 353 | } | ||
2465 | 354 | } | ||
2466 | 355 | return true; | ||
2467 | 356 | } | ||
2468 | 357 | else | ||
2469 | 358 | return false; | ||
2470 | 359 | } | ||
2471 | 360 | } | ||
2472 | 361 | |||
2473 | 362 | return false; | ||
2474 | 363 | } | ||
2475 | 364 | |||
2476 | 365 | ListMatcher::ListMatcher (std::string::const_iterator begin, std::string::const_iterator end) : | ||
2477 | 366 | Parser::Parser ("list", begin, end) | ||
2478 | 367 | { | ||
2479 | 368 | } | ||
2480 | 369 | |||
2481 | 370 | ListMatcher::~ListMatcher () | ||
2482 | 371 | { | ||
2483 | 372 | } | ||
2484 | 373 | |||
2485 | 374 | bool | ||
2486 | 375 | ListMatcher::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end) | ||
2487 | 376 | { | ||
2488 | 377 | /* on "list" just print out the toplevel trees | ||
2489 | 378 | * like the root object id */ | ||
2490 | 379 | |||
2491 | 380 | const compiz::window::X11Object::Ptr &rt = boost::shared_polymorphic_cast <compiz::window::X11Object> (compiz::window::Server::Default ()->root ()); | ||
2492 | 381 | const compiz::window::ObjectIdentifier::Ptr &id = rt->id (); | ||
2493 | 382 | const compiz::window::X11ObjectIdentifier::Ptr &xid = boost::shared_static_cast <compiz::window::X11ObjectIdentifier> (id); | ||
2494 | 383 | |||
2495 | 384 | std::cout << "Root Object: "; | ||
2496 | 385 | xid->print (); | ||
2497 | 386 | std::cout << std::endl; | ||
2498 | 387 | return false; | ||
2499 | 388 | } | ||
2500 | 389 | |||
2501 | 390 | ObjectMatcher::ObjectMatcher (std::string::const_iterator begin, std::string::const_iterator end) : | ||
2502 | 391 | Parser::Parser ("object", begin, end) | ||
2503 | 392 | { | ||
2504 | 393 | } | ||
2505 | 394 | |||
2506 | 395 | ObjectMatcher::~ObjectMatcher () | ||
2507 | 396 | { | ||
2508 | 397 | } | ||
2509 | 398 | |||
2510 | 399 | bool | ||
2511 | 400 | ObjectMatcher::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end) | ||
2512 | 401 | { | ||
2513 | 402 | advance (); | ||
2514 | 403 | advance (1); | ||
2515 | 404 | XidParser xp (mBegin, mEnd); | ||
2516 | 405 | |||
2517 | 406 | return boost::spirit::qi::parse (mBegin, mEnd, | ||
2518 | 407 | boost::spirit::qi::lit ("0x") [boost::bind (&XidParser::parse, &xp, _1, _2, _3)]); | ||
2519 | 408 | } | ||
2520 | 409 | |||
2521 | 410 | bool | ||
2522 | 411 | StdinSource::callback (Glib::IOCondition cond) | ||
2523 | 412 | { | ||
2524 | 413 | if (cond & Glib::IO_IN) | ||
2525 | 414 | { | ||
2526 | 415 | std::string str; | ||
2527 | 416 | std::getline (std::cin, str); | ||
2528 | 417 | std::string::const_iterator b = str.begin (); | ||
2529 | 418 | std::string::const_iterator e = str.end (); | ||
2530 | 419 | ObjectMatcher op (b, e); | ||
2531 | 420 | ListMatcher lp (b, e); | ||
2532 | 421 | CreateParser cp (b, e); | ||
2533 | 422 | if (boost::spirit::qi::parse (b, e, boost::spirit::qi::lit ("object")[boost::bind (&ObjectMatcher::parse, &op, _1, _2, _3)])) | ||
2534 | 423 | { | ||
2535 | 424 | } | ||
2536 | 425 | else if (boost::spirit::qi::parse (b, e, boost::spirit::qi::lit ("list")[boost::bind (&ListMatcher::parse, &lp, _1, _2, _3)])) | ||
2537 | 426 | { | ||
2538 | 427 | } | ||
2539 | 428 | else if (boost::spirit::qi::parse (b, e, boost::spirit::qi::lit ("create")[boost::bind (&CreateParser::parse, &cp, _1, _2, _3)])) | ||
2540 | 429 | { | ||
2541 | 430 | compiz::window::WriteServerConnection::Ptr w = boost::shared_static_cast <compiz::window::AsynchronousServer> (compiz::window::Server::Default ())->connect (); | ||
2542 | 431 | |||
2543 | 432 | if (cp.xcreq ()) | ||
2544 | 433 | w->sendCreateObject (cp.xcreq ()); | ||
2545 | 434 | } | ||
2546 | 435 | else if (boost::spirit::qi::parse (b, e, boost::spirit::qi::lit ("quit"))) | ||
2547 | 436 | { | ||
2548 | 437 | mMainLoop->quit (); | ||
2549 | 438 | return false; | ||
2550 | 439 | } | ||
2551 | 440 | |||
2552 | 441 | std::cout << ">> "; | ||
2553 | 442 | } | ||
2554 | 443 | |||
2555 | 444 | return true; | ||
2556 | 445 | } | ||
2557 | 446 | |||
2558 | 447 | StdinSource::~StdinSource () | ||
2559 | 448 | { | ||
2560 | 449 | } | ||
2561 | 0 | 450 | ||
2562 | === added file 'tests/standalone/objects/command-parser.h' | |||
2563 | --- tests/standalone/objects/command-parser.h 1970-01-01 00:00:00 +0000 | |||
2564 | +++ tests/standalone/objects/command-parser.h 2012-01-19 18:25:06 +0000 | |||
2565 | @@ -0,0 +1,190 @@ | |||
2566 | 1 | /* | ||
2567 | 2 | * Copyright © 2010 Canonical Ltd. | ||
2568 | 3 | * | ||
2569 | 4 | * Permission to use, copy, modify, distribute, and sell this software | ||
2570 | 5 | * and its documentation for any purpose is hereby granted without | ||
2571 | 6 | * fee, provided that the above copyright notice appear in all copies | ||
2572 | 7 | * and that both that copyright notice and this permission notice | ||
2573 | 8 | * appear in supporting documentation, and that the name of | ||
2574 | 9 | * Canonical Ltd. not be used in advertising or publicity pertaining to | ||
2575 | 10 | * distribution of the software without specific, written prior permission. | ||
2576 | 11 | * Canonical Ltd. makes no representations about the suitability of this | ||
2577 | 12 | * software for any purpose. It is provided "as is" without express or | ||
2578 | 13 | * implied warranty. | ||
2579 | 14 | * | ||
2580 | 15 | * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
2581 | 16 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN | ||
2582 | 17 | * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
2583 | 18 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
2584 | 19 | * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | ||
2585 | 20 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | ||
2586 | 21 | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
2587 | 22 | * | ||
2588 | 23 | * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> | ||
2589 | 24 | */ | ||
2590 | 25 | |||
2591 | 26 | #include <core/x11-server.h> | ||
2592 | 27 | #include <core/x11-object.h> | ||
2593 | 28 | #include <X11/Xlib.h> | ||
2594 | 29 | #include <boost/shared_ptr.hpp> | ||
2595 | 30 | #include <cairo/cairo.h> | ||
2596 | 31 | #include <cairo/cairo-xlib.h> | ||
2597 | 32 | #include <core/object.h> | ||
2598 | 33 | #include <core/container.h> | ||
2599 | 34 | #include <core/server-write.h> | ||
2600 | 35 | #include <sys/poll.h> | ||
2601 | 36 | #include <boost/spirit/include/qi.hpp> | ||
2602 | 37 | #include <boost/spirit/include/phoenix_core.hpp> | ||
2603 | 38 | #include <boost/spirit/include/phoenix_operator.hpp> | ||
2604 | 39 | #include <boost/spirit/include/phoenix_object.hpp> | ||
2605 | 40 | #include <boost/spirit/include/phoenix_stl.hpp> | ||
2606 | 41 | #include <boost/fusion/include/adapt_struct.hpp> | ||
2607 | 42 | #include <boost/fusion/include/io.hpp> | ||
2608 | 43 | #include <boost/spirit/include/qi_uint.hpp> | ||
2609 | 44 | |||
2610 | 45 | #include <boost/bind.hpp> | ||
2611 | 46 | |||
2612 | 47 | class StdinSource : | ||
2613 | 48 | public Glib::IOSource | ||
2614 | 49 | { | ||
2615 | 50 | public: | ||
2616 | 51 | |||
2617 | 52 | static Glib::RefPtr <StdinSource> create (const Glib::RefPtr <Glib::MainLoop> &ml); | ||
2618 | 53 | ~StdinSource (); | ||
2619 | 54 | |||
2620 | 55 | private: | ||
2621 | 56 | |||
2622 | 57 | bool callback (Glib::IOCondition); | ||
2623 | 58 | |||
2624 | 59 | StdinSource (const Glib::RefPtr <Glib::MainLoop> &ml); | ||
2625 | 60 | Glib::RefPtr <Glib::MainLoop> mMainLoop; | ||
2626 | 61 | }; | ||
2627 | 62 | |||
2628 | 63 | class Parser | ||
2629 | 64 | { | ||
2630 | 65 | public: | ||
2631 | 66 | virtual ~Parser (); | ||
2632 | 67 | void parse (boost::spirit::unused_type, boost::spirit::unused_type, bool &); | ||
2633 | 68 | protected: | ||
2634 | 69 | virtual bool parseStringIterators (std::string::const_iterator begin, | ||
2635 | 70 | std::string::const_iterator end) = 0; | ||
2636 | 71 | |||
2637 | 72 | Parser (const std::string &token, std::string::const_iterator begin, std::string::const_iterator end); | ||
2638 | 73 | Parser (unsigned int, std::string::const_iterator begin, std::string::const_iterator end); | ||
2639 | 74 | |||
2640 | 75 | void advance (); | ||
2641 | 76 | void advance (unsigned int); | ||
2642 | 77 | |||
2643 | 78 | mutable std::string::const_iterator mBegin; | ||
2644 | 79 | mutable std::string::const_iterator mEnd; | ||
2645 | 80 | private: | ||
2646 | 81 | unsigned int mAdvanceLength; | ||
2647 | 82 | }; | ||
2648 | 83 | |||
2649 | 84 | class ObjectMatcher : | ||
2650 | 85 | public Parser | ||
2651 | 86 | { | ||
2652 | 87 | public: | ||
2653 | 88 | ObjectMatcher (std::string::const_iterator begin, std::string::const_iterator end); | ||
2654 | 89 | ~ObjectMatcher (); | ||
2655 | 90 | protected: | ||
2656 | 91 | bool parseStringIterators (std::string::const_iterator begin, | ||
2657 | 92 | std::string::const_iterator end); | ||
2658 | 93 | |||
2659 | 94 | private: | ||
2660 | 95 | |||
2661 | 96 | mutable compiz::window::Object::Ptr mObj; | ||
2662 | 97 | }; | ||
2663 | 98 | |||
2664 | 99 | class ListMatcher : | ||
2665 | 100 | public Parser | ||
2666 | 101 | { | ||
2667 | 102 | public: | ||
2668 | 103 | ListMatcher (std::string::const_iterator begin, std::string::const_iterator end); | ||
2669 | 104 | ~ListMatcher (); | ||
2670 | 105 | protected: | ||
2671 | 106 | bool parseStringIterators (std::string::const_iterator begin, | ||
2672 | 107 | std::string::const_iterator end); | ||
2673 | 108 | }; | ||
2674 | 109 | |||
2675 | 110 | class XidParser : | ||
2676 | 111 | public Parser | ||
2677 | 112 | { | ||
2678 | 113 | public: | ||
2679 | 114 | XidParser (std::string::const_iterator begin, std::string::const_iterator end); | ||
2680 | 115 | ~XidParser (); | ||
2681 | 116 | protected: | ||
2682 | 117 | bool parseStringIterators (std::string::const_iterator begin, | ||
2683 | 118 | std::string::const_iterator end); | ||
2684 | 119 | private: | ||
2685 | 120 | mutable compiz::window::X11ObjectIdentifier::Ptr mXid; | ||
2686 | 121 | }; | ||
2687 | 122 | |||
2688 | 123 | class GeometryParser : | ||
2689 | 124 | public Parser | ||
2690 | 125 | { | ||
2691 | 126 | public: | ||
2692 | 127 | GeometryParser (std::string::const_iterator begin, std::string::const_iterator end, const compiz::window::Geometry &old); | ||
2693 | 128 | ~GeometryParser (); | ||
2694 | 129 | const compiz::window::Geometry & geometry () { return mGeometry; }; | ||
2695 | 130 | protected: | ||
2696 | 131 | bool parseStringIterators (std::string::const_iterator begin, | ||
2697 | 132 | std::string::const_iterator end); | ||
2698 | 133 | private: | ||
2699 | 134 | compiz::window::Geometry mGeometry; | ||
2700 | 135 | }; | ||
2701 | 136 | |||
2702 | 137 | class ObjectsParser : | ||
2703 | 138 | public Parser | ||
2704 | 139 | { | ||
2705 | 140 | public: | ||
2706 | 141 | ObjectsParser (std::string::const_iterator begin, std::string::const_iterator end, const compiz::window::Container::Children &old); | ||
2707 | 142 | ~ObjectsParser (); | ||
2708 | 143 | const compiz::window::Container::Children & children () { return mChildren; }; | ||
2709 | 144 | protected: | ||
2710 | 145 | bool parseStringIterators (std::string::const_iterator begin, | ||
2711 | 146 | std::string::const_iterator end); | ||
2712 | 147 | private: | ||
2713 | 148 | compiz::window::Container::Children mChildren; | ||
2714 | 149 | }; | ||
2715 | 150 | |||
2716 | 151 | class CreateParser : | ||
2717 | 152 | public Parser | ||
2718 | 153 | { | ||
2719 | 154 | public: | ||
2720 | 155 | CreateParser (std::string::const_iterator begin, std::string::const_iterator end); | ||
2721 | 156 | ~CreateParser (); | ||
2722 | 157 | const compiz::window::X11ObjectCreationRequest::Ptr & xcreq () { return mXcreq; } | ||
2723 | 158 | protected: | ||
2724 | 159 | bool parseStringIterators (std::string::const_iterator begin, | ||
2725 | 160 | std::string::const_iterator end); | ||
2726 | 161 | private: | ||
2727 | 162 | compiz::window::X11ObjectCreationRequest::Ptr mXcreq; | ||
2728 | 163 | }; | ||
2729 | 164 | |||
2730 | 165 | class StackPositionParser : | ||
2731 | 166 | public Parser | ||
2732 | 167 | { | ||
2733 | 168 | public: | ||
2734 | 169 | StackPositionParser (std::string::const_iterator begin, std::string::const_iterator end, const compiz::window::StackPosition &old); | ||
2735 | 170 | ~StackPositionParser (); | ||
2736 | 171 | protected: | ||
2737 | 172 | bool parseStringIterators (std::string::const_iterator begin, | ||
2738 | 173 | std::string::const_iterator end); | ||
2739 | 174 | private: | ||
2740 | 175 | mutable compiz::window::StackPosition mStackPosition; | ||
2741 | 176 | }; | ||
2742 | 177 | |||
2743 | 178 | class PropertyParser : | ||
2744 | 179 | public Parser | ||
2745 | 180 | { | ||
2746 | 181 | public: | ||
2747 | 182 | PropertyParser (std::string::const_iterator begin, std::string::const_iterator end, uint64_t old); | ||
2748 | 183 | ~PropertyParser (); | ||
2749 | 184 | protected: | ||
2750 | 185 | bool parseStringIterators (std::string::const_iterator begin, | ||
2751 | 186 | std::string::const_iterator end); | ||
2752 | 187 | private: | ||
2753 | 188 | mutable uint64_t mProperties; | ||
2754 | 189 | }; | ||
2755 | 190 | |||
2756 | 0 | 191 | ||
2757 | === added directory 'tests/standalone/objects/mockwire' | |||
2758 | === added directory 'tests/standalone/objects/x11' | |||
2759 | === added file 'tests/standalone/objects/x11/CMakeLists.txt' | |||
2760 | --- tests/standalone/objects/x11/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
2761 | +++ tests/standalone/objects/x11/CMakeLists.txt 2012-01-19 18:25:06 +0000 | |||
2762 | @@ -0,0 +1,43 @@ | |||
2763 | 1 | pkg_check_modules (X11_OBJECT_TREE_STANDALONE REQUIRED x11 glibmm-2.4 cairo cairo-xlib) | ||
2764 | 2 | |||
2765 | 3 | if (X11_OBJECT_TREE_STANDALONE_FOUND) | ||
2766 | 4 | |||
2767 | 5 | include_directories (${X11_OBJECT_TREE_STANDALONE_INCLUDE_DIRS} | ||
2768 | 6 | ${COMPIZ_OBJECTS_STANDALONE_TEST_BASE_DIR} | ||
2769 | 7 | ${compiz_SOURCE_DIR}/src/ | ||
2770 | 8 | ${compiz_SOURCE_DIR}/include/ | ||
2771 | 9 | # Module specific include dirs | ||
2772 | 10 | |||
2773 | 11 | ${compiz_SOURCE_DIR}/src/timer/include | ||
2774 | 12 | ${compiz_SOURCE_DIR}/src/timer/src) | ||
2775 | 13 | |||
2776 | 14 | link_directories (${X11_OBJECT_TREE_STANDALONE_LIBRARY_DIRS} | ||
2777 | 15 | ${COMPIZ_OBJECTS_STANDALONE_TEST_BINARY_DIR}) | ||
2778 | 16 | |||
2779 | 17 | add_executable (compiz-x11-object-tree-standalone | ||
2780 | 18 | compiz-x11-object-tree-standalone.cpp | ||
2781 | 19 | ${compiz_SOURCE_DIR}/src/x11-server.cpp | ||
2782 | 20 | ${compiz_SOURCE_DIR}/src/asynchronous-server.cpp | ||
2783 | 21 | ${compiz_SOURCE_DIR}/src/server.cpp | ||
2784 | 22 | ${compiz_SOURCE_DIR}/src/server-read.cpp | ||
2785 | 23 | ${compiz_SOURCE_DIR}/src/server-write.cpp | ||
2786 | 24 | ${compiz_SOURCE_DIR}/src/object.cpp | ||
2787 | 25 | ${compiz_SOURCE_DIR}/src/container.cpp | ||
2788 | 26 | ${compiz_SOURCE_DIR}/src/asynchronous-object.cpp | ||
2789 | 27 | ${compiz_SOURCE_DIR}/src/asynchronous-container.cpp | ||
2790 | 28 | ${compiz_SOURCE_DIR}/src/x11-object.cpp | ||
2791 | 29 | ${compiz_SOURCE_DIR}/src/x11-container.cpp | ||
2792 | 30 | ${compiz_SOURCE_DIR}/src/windowgeometry.cpp | ||
2793 | 31 | ${compiz_SOURCE_DIR}/src/stackposition.cpp | ||
2794 | 32 | ${compiz_SOURCE_DIR}/src/stack.cpp | ||
2795 | 33 | ${compiz_SOURCE_DIR}/src/asynchronous-stack.cpp | ||
2796 | 34 | ${compiz_SOURCE_DIR}/src/rect.cpp | ||
2797 | 35 | ${compiz_SOURCE_DIR}/src/eventsource.cpp | ||
2798 | 36 | ${compiz_SOURCE_DIR}/src/point.cpp | ||
2799 | 37 | ${compiz_SOURCE_DIR}/src/managedstatebit.cpp) | ||
2800 | 38 | |||
2801 | 39 | target_link_libraries (compiz-x11-object-tree-standalone | ||
2802 | 40 | commandparser | ||
2803 | 41 | ${X11_OBJECT_TREE_STANDALONE_LIBRARIES}) | ||
2804 | 42 | |||
2805 | 43 | endif (X11_OBJECT_TREE_STANDALONE_FOUND) | ||
2806 | 0 | 44 | ||
2807 | === added file 'tests/standalone/objects/x11/compiz-x11-object-tree-standalone.cpp' | |||
2808 | --- tests/standalone/objects/x11/compiz-x11-object-tree-standalone.cpp 1970-01-01 00:00:00 +0000 | |||
2809 | +++ tests/standalone/objects/x11/compiz-x11-object-tree-standalone.cpp 2012-01-19 18:25:06 +0000 | |||
2810 | @@ -0,0 +1,338 @@ | |||
2811 | 1 | /* | ||
2812 | 2 | * Copyright © 2010 Canonical Ltd. | ||
2813 | 3 | * | ||
2814 | 4 | * Permission to use, copy, modify, distribute, and sell this software | ||
2815 | 5 | * and its documentation for any purpose is hereby granted without | ||
2816 | 6 | * fee, provided that the above copyright notice appear in all copies | ||
2817 | 7 | * and that both that copyright notice and this permission notice | ||
2818 | 8 | * appear in supporting documentation, and that the name of | ||
2819 | 9 | * Canonical Ltd. not be used in advertising or publicity pertaining to | ||
2820 | 10 | * distribution of the software without specific, written prior permission. | ||
2821 | 11 | * Canonical Ltd. makes no representations about the suitability of this | ||
2822 | 12 | * software for any purpose. It is provided "as is" without express or | ||
2823 | 13 | * implied warranty. | ||
2824 | 14 | * | ||
2825 | 15 | * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
2826 | 16 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN | ||
2827 | 17 | * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
2828 | 18 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
2829 | 19 | * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | ||
2830 | 20 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | ||
2831 | 21 | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
2832 | 22 | * | ||
2833 | 23 | * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> | ||
2834 | 24 | */ | ||
2835 | 25 | |||
2836 | 26 | #include <core/x11-server.h> | ||
2837 | 27 | #include <core/x11-object.h> | ||
2838 | 28 | #include <X11/Xlib.h> | ||
2839 | 29 | #include <boost/shared_ptr.hpp> | ||
2840 | 30 | #include <cairo/cairo.h> | ||
2841 | 31 | #include <cairo/cairo-xlib.h> | ||
2842 | 32 | #include <core/object.h> | ||
2843 | 33 | #include <core/container.h> | ||
2844 | 34 | #include <core/server-write.h> | ||
2845 | 35 | #include <command-parser.h> | ||
2846 | 36 | |||
2847 | 37 | #include <boost/bind.hpp> | ||
2848 | 38 | |||
2849 | 39 | class MockX11Server : | ||
2850 | 40 | public compiz::window::X11Server | ||
2851 | 41 | { | ||
2852 | 42 | public: | ||
2853 | 43 | |||
2854 | 44 | typedef boost::shared_ptr <MockX11Server> Ptr; | ||
2855 | 45 | |||
2856 | 46 | void setRoot (Window root, const compiz::window::Geometry &); | ||
2857 | 47 | |||
2858 | 48 | compiz::window::Object::Ptr | ||
2859 | 49 | createObject (const compiz::window::ObjectIdentifier::Ptr &id, | ||
2860 | 50 | const compiz::window::Geometry &g, | ||
2861 | 51 | const compiz::window::StackPosition &sp, | ||
2862 | 52 | const compiz::window::Container::Ptr &c); | ||
2863 | 53 | |||
2864 | 54 | void | ||
2865 | 55 | removeObject (const compiz::window::ObjectIdentifier::Ptr &id); | ||
2866 | 56 | |||
2867 | 57 | MockX11Server (Display *, Glib::RefPtr <Glib::MainLoop> &ml); | ||
2868 | 58 | ~MockX11Server (); | ||
2869 | 59 | }; | ||
2870 | 60 | |||
2871 | 61 | class MockX11Object : | ||
2872 | 62 | public compiz::window::X11Container | ||
2873 | 63 | { | ||
2874 | 64 | public: | ||
2875 | 65 | |||
2876 | 66 | typedef boost::shared_ptr <MockX11Object> Ptr; | ||
2877 | 67 | |||
2878 | 68 | virtual ~MockX11Object (); | ||
2879 | 69 | |||
2880 | 70 | protected: | ||
2881 | 71 | |||
2882 | 72 | void onReceiveGeometry (const compiz::window::Geometry &g); | ||
2883 | 73 | void onReceiveStackPosition (const compiz::window::StackPosition &sp); | ||
2884 | 74 | void onReceiveInsertion (const compiz::window::Object::Ptr &o); | ||
2885 | 75 | void onReceiveRemoval (const compiz::window::Object::Ptr &o); | ||
2886 | 76 | void onReceiveDeletion (); | ||
2887 | 77 | void onReceiveAddState (uint64_t state); | ||
2888 | 78 | void onReceiveRemoveState (uint64_t state); | ||
2889 | 79 | |||
2890 | 80 | void onSendGeometry (const compiz::window::Geometry &g); | ||
2891 | 81 | void onSendStackPosition (const compiz::window::StackPosition &sp); | ||
2892 | 82 | void onSendInsertion (const compiz::window::Object::Ptr &o); | ||
2893 | 83 | void onSendRemoval (const compiz::window::Object::Ptr &o); | ||
2894 | 84 | void onSendDeletion (); | ||
2895 | 85 | void onSendAddState (uint64_t state); | ||
2896 | 86 | void onSendRemoveState (uint64_t state); | ||
2897 | 87 | |||
2898 | 88 | private: | ||
2899 | 89 | |||
2900 | 90 | MockX11Object (const compiz::window::ObjectIdentifier::Ptr &, | ||
2901 | 91 | const boost::shared_ptr <compiz::window::WriteServerConnection> &, | ||
2902 | 92 | const compiz::window::Geometry &, | ||
2903 | 93 | const boost::shared_ptr <compiz::window::Container> &); | ||
2904 | 94 | |||
2905 | 95 | friend class MockX11Server; | ||
2906 | 96 | }; | ||
2907 | 97 | |||
2908 | 98 | MockX11Object::MockX11Object (const compiz::window::ObjectIdentifier::Ptr &id, | ||
2909 | 99 | const boost::shared_ptr <compiz::window::WriteServerConnection> &write, | ||
2910 | 100 | const compiz::window::Geometry &g, | ||
2911 | 101 | const boost::shared_ptr <compiz::window::Container> &c) : | ||
2912 | 102 | Object (id, g), | ||
2913 | 103 | AsynchronousObject (id, g, write), | ||
2914 | 104 | X11Container (id, write, g, c) | ||
2915 | 105 | { | ||
2916 | 106 | } | ||
2917 | 107 | |||
2918 | 108 | void | ||
2919 | 109 | MockX11Object::onReceiveGeometry (const compiz::window::Geometry &g) | ||
2920 | 110 | { | ||
2921 | 111 | std::cout << "DEBUG: " << __func__ << " g: " << g.x () << " " | ||
2922 | 112 | << g.y () << " " | ||
2923 | 113 | << g.width () << " " | ||
2924 | 114 | << g.height () << " " | ||
2925 | 115 | << g.border () << std::endl; | ||
2926 | 116 | } | ||
2927 | 117 | |||
2928 | 118 | void | ||
2929 | 119 | MockX11Object::onReceiveStackPosition (const compiz::window::StackPosition &sp) | ||
2930 | 120 | { | ||
2931 | 121 | std::cout << "DEBUG: " << __func__ << std::endl; | ||
2932 | 122 | } | ||
2933 | 123 | |||
2934 | 124 | void | ||
2935 | 125 | MockX11Object::onReceiveInsertion (const compiz::window::Object::Ptr &o) | ||
2936 | 126 | { | ||
2937 | 127 | std::cout << "DEBUG: " << __func__ << std::endl; | ||
2938 | 128 | } | ||
2939 | 129 | |||
2940 | 130 | void | ||
2941 | 131 | MockX11Object::onReceiveRemoval (const compiz::window::Object::Ptr &o) | ||
2942 | 132 | { | ||
2943 | 133 | std::cout << "DEBUG: " << __func__ << std::endl; | ||
2944 | 134 | } | ||
2945 | 135 | |||
2946 | 136 | void | ||
2947 | 137 | MockX11Object::onReceiveDeletion () | ||
2948 | 138 | { | ||
2949 | 139 | std::cout << "DEBUG: " << __func__ << std::endl; | ||
2950 | 140 | } | ||
2951 | 141 | |||
2952 | 142 | void | ||
2953 | 143 | MockX11Object::onReceiveAddState (uint64_t state) | ||
2954 | 144 | { | ||
2955 | 145 | std::cout << "DEBUG: " << __func__ << std::hex << state << std::dec << std::endl; | ||
2956 | 146 | } | ||
2957 | 147 | |||
2958 | 148 | void | ||
2959 | 149 | MockX11Object::onReceiveRemoveState (uint64_t state) | ||
2960 | 150 | { | ||
2961 | 151 | std::cout << "DEBUG: " << __func__ << std::hex << state << std::dec << std::endl; | ||
2962 | 152 | } | ||
2963 | 153 | |||
2964 | 154 | void | ||
2965 | 155 | MockX11Object::onSendGeometry (const compiz::window::Geometry &g) | ||
2966 | 156 | { | ||
2967 | 157 | std::cout << "DEBUG: " << __func__ << " g: " << g.x () << " " | ||
2968 | 158 | << g.y () << " " | ||
2969 | 159 | << g.width () << " " | ||
2970 | 160 | << g.height () << " " | ||
2971 | 161 | << g.border () << std::endl; | ||
2972 | 162 | } | ||
2973 | 163 | |||
2974 | 164 | void | ||
2975 | 165 | MockX11Object::onSendStackPosition (const compiz::window::StackPosition &sp) | ||
2976 | 166 | { | ||
2977 | 167 | std::cout << "DEBUG: " << __func__ << std::endl; | ||
2978 | 168 | } | ||
2979 | 169 | |||
2980 | 170 | void | ||
2981 | 171 | MockX11Object::onSendInsertion (const compiz::window::Object::Ptr &o) | ||
2982 | 172 | { | ||
2983 | 173 | std::cout << "DEBUG: " << __func__ << std::endl; | ||
2984 | 174 | } | ||
2985 | 175 | |||
2986 | 176 | void | ||
2987 | 177 | MockX11Object::onSendRemoval (const compiz::window::Object::Ptr &o) | ||
2988 | 178 | { | ||
2989 | 179 | std::cout << "DEBUG: " << __func__ << std::endl; | ||
2990 | 180 | } | ||
2991 | 181 | |||
2992 | 182 | void | ||
2993 | 183 | MockX11Object::onSendDeletion () | ||
2994 | 184 | { | ||
2995 | 185 | std::cout << "DEBUG: " << __func__ << std::endl; | ||
2996 | 186 | } | ||
2997 | 187 | |||
2998 | 188 | void | ||
2999 | 189 | MockX11Object::onSendAddState (uint64_t state) | ||
3000 | 190 | { | ||
3001 | 191 | std::cout << "DEBUG: " << __func__ << std::hex << state << std::dec << std::endl; | ||
3002 | 192 | } | ||
3003 | 193 | |||
3004 | 194 | void | ||
3005 | 195 | MockX11Object::onSendRemoveState (uint64_t state) | ||
3006 | 196 | { | ||
3007 | 197 | std::cout << "DEBUG: " << __func__ << std::hex << state << std::dec << std::endl; | ||
3008 | 198 | } | ||
3009 | 199 | |||
3010 | 200 | MockX11Object::~MockX11Object () | ||
3011 | 201 | { | ||
3012 | 202 | } | ||
3013 | 203 | |||
3014 | 204 | MockX11Server::MockX11Server (Display *d, Glib::RefPtr <Glib::MainLoop> &ml) : | ||
3015 | 205 | X11Server (ml, d) | ||
3016 | 206 | { | ||
3017 | 207 | } | ||
3018 | 208 | |||
3019 | 209 | MockX11Server::~MockX11Server () | ||
3020 | 210 | { | ||
3021 | 211 | } | ||
3022 | 212 | |||
3023 | 213 | void | ||
3024 | 214 | MockX11Server::setRoot (Window root, const compiz::window::Geometry &g) | ||
3025 | 215 | { | ||
3026 | 216 | Server::SetDefault (shared_from_this ()); | ||
3027 | 217 | X11Server::setRoot (root, g); | ||
3028 | 218 | } | ||
3029 | 219 | |||
3030 | 220 | compiz::window::Object::Ptr | ||
3031 | 221 | MockX11Server::createObject (const compiz::window::ObjectIdentifier::Ptr &id, | ||
3032 | 222 | const compiz::window::Geometry &g, | ||
3033 | 223 | const compiz::window::StackPosition &sp, | ||
3034 | 224 | const boost::shared_ptr <compiz::window::Container> &c) | ||
3035 | 225 | { | ||
3036 | 226 | compiz::window::X11ObjectIdentifier::Ptr xid = boost::shared_static_cast <compiz::window::X11ObjectIdentifier> (id); | ||
3037 | 227 | MockX11Object::Ptr mxobj = MockX11Object::Ptr (new MockX11Object (id, connect (), g, c)); | ||
3038 | 228 | const compiz::window::X11Object::Ptr &xobj = boost::shared_static_cast <compiz::window::X11Object> (mxobj); | ||
3039 | 229 | std::pair <compiz::window::X11ObjectIdentifier::Ptr, compiz::window::X11Object::Ptr> keyValue (xid, xobj); | ||
3040 | 230 | |||
3041 | 231 | addObjectToTree (keyValue); | ||
3042 | 232 | return (*xid) (); | ||
3043 | 233 | } | ||
3044 | 234 | |||
3045 | 235 | void | ||
3046 | 236 | MockX11Server::removeObject (const compiz::window::ObjectIdentifier::Ptr &id) | ||
3047 | 237 | { | ||
3048 | 238 | removeKeyFromTree (id); | ||
3049 | 239 | } | ||
3050 | 240 | |||
3051 | 241 | Window create_virtual_root (Display *display, | ||
3052 | 242 | compiz::window::Geometry &g) | ||
3053 | 243 | { | ||
3054 | 244 | XSetWindowAttributes attr; | ||
3055 | 245 | g.set (0, 0, 800, 600, 0); | ||
3056 | 246 | Window root = XCreateWindow (display, DefaultRootWindow (display), | ||
3057 | 247 | 0, 0, g.width (), g.height (), 0, CopyFromParent, | ||
3058 | 248 | InputOutput, CopyFromParent, | ||
3059 | 249 | 0, &attr); | ||
3060 | 250 | XSelectInput (display, root, ExposureMask); | ||
3061 | 251 | XMapWindow (display, root); | ||
3062 | 252 | |||
3063 | 253 | while (1) | ||
3064 | 254 | { | ||
3065 | 255 | XEvent ev; | ||
3066 | 256 | bool out = false; | ||
3067 | 257 | |||
3068 | 258 | XNextEvent (display, &ev); | ||
3069 | 259 | |||
3070 | 260 | switch (ev.type) | ||
3071 | 261 | { | ||
3072 | 262 | case Expose: | ||
3073 | 263 | |||
3074 | 264 | if (ev.xexpose.window == root) | ||
3075 | 265 | { | ||
3076 | 266 | /* The window is visible, clear it | ||
3077 | 267 | * with white */ | ||
3078 | 268 | Visual *vis = DefaultVisual (display, DefaultScreen (display)); | ||
3079 | 269 | cairo_surface_t *xlib_surface = cairo_xlib_surface_create (display, | ||
3080 | 270 | root, | ||
3081 | 271 | vis, | ||
3082 | 272 | 800, | ||
3083 | 273 | 600); | ||
3084 | 274 | cairo_t *cr = cairo_create (xlib_surface); | ||
3085 | 275 | |||
3086 | 276 | cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); | ||
3087 | 277 | cairo_paint (cr); | ||
3088 | 278 | |||
3089 | 279 | cairo_destroy (cr); | ||
3090 | 280 | cairo_surface_destroy (xlib_surface); | ||
3091 | 281 | |||
3092 | 282 | out = 1; | ||
3093 | 283 | } | ||
3094 | 284 | break; | ||
3095 | 285 | default: | ||
3096 | 286 | break; | ||
3097 | 287 | } | ||
3098 | 288 | |||
3099 | 289 | if (out) | ||
3100 | 290 | break; | ||
3101 | 291 | } | ||
3102 | 292 | |||
3103 | 293 | XSync (display, false); | ||
3104 | 294 | |||
3105 | 295 | return root; | ||
3106 | 296 | } | ||
3107 | 297 | |||
3108 | 298 | int main (int argc, char **argv) | ||
3109 | 299 | { | ||
3110 | 300 | Glib::RefPtr <Glib::MainContext> mc = Glib::MainContext::get_default (); | ||
3111 | 301 | Glib::RefPtr <Glib::MainLoop> ml = Glib::MainLoop::create (mc, false); | ||
3112 | 302 | Glib::RefPtr <StdinSource> ss = StdinSource::create (ml); | ||
3113 | 303 | Display *display = XOpenDisplay (NULL); | ||
3114 | 304 | Window root = 0; | ||
3115 | 305 | compiz::window::Geometry rg; | ||
3116 | 306 | MockX11Server::Ptr server = MockX11Server::Ptr (new MockX11Server (display, ml)); | ||
3117 | 307 | |||
3118 | 308 | for (int i = 0; i < argc; i++) | ||
3119 | 309 | if (std::string (argv[i]) == "-c" || | ||
3120 | 310 | std::string (argv[i]) == "--create") | ||
3121 | 311 | root = create_virtual_root (display, rg); | ||
3122 | 312 | |||
3123 | 313 | if (!root) | ||
3124 | 314 | { | ||
3125 | 315 | unsigned int width, height; | ||
3126 | 316 | unsigned int uid; | ||
3127 | 317 | Window wd; | ||
3128 | 318 | int id; | ||
3129 | 319 | |||
3130 | 320 | root = DefaultRootWindow (display); | ||
3131 | 321 | if (XGetGeometry (display, root, &wd, &id, &id, &width, &height, &uid, &uid)) | ||
3132 | 322 | { | ||
3133 | 323 | rg.setWidth (width); | ||
3134 | 324 | rg.setHeight (height); | ||
3135 | 325 | } | ||
3136 | 326 | } | ||
3137 | 327 | |||
3138 | 328 | server->setRoot (root, rg); | ||
3139 | 329 | |||
3140 | 330 | server->flush (0); | ||
3141 | 331 | std::cout << ">> " << std::endl; | ||
3142 | 332 | ml->run (); | ||
3143 | 333 | |||
3144 | 334 | XDestroyWindow (display, root); | ||
3145 | 335 | XCloseDisplay (display); | ||
3146 | 336 | |||
3147 | 337 | return 0; | ||
3148 | 338 | } |
The class ManagedStateBit is strange:
o there are inline functions defined in the .cpp file - so is the class usable elsewhere?
o in general, symmetric operators should be non-member functions.
o are all these operators needed? The implicit conversion uint64_t to ought to cover most uses?
o why isn't operator uint64_t() inline? (and in the header?)
What is the purpose of the Visitor class:
o it clearly isn't part of a GOF "Visitor" pattern;
o it doesn't appear to be used; and,
o it just provides a level of indirection to calling similarly named functions on it's member.