Merge lp:~smspillaz/compiz-core/compiz-core.fix_900580 into lp:compiz-core/0.9.5

Proposed by Sam Spilsbury
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
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.

Description of the change

Adds a parser and scriptable standalone wm part for testing

Next pipe: lp:~smspillaz/compiz-core/fix-903529

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) wrote : Posted in a previous version of this proposal

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.

review: Needs Information
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

The issues with src/managedstatebit.cpp are unchanged.

review: Needs Fixing
2996. By Sam Spilsbury

Merged compiz-core.merge_894639 into compiz-core.fix_900580.

Revision history for this message
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.

review: Needs Fixing
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

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

Subscribers

People subscribed via source and target branches