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
=== modified file 'include/core/CMakeLists.txt'
--- include/core/CMakeLists.txt 2012-01-19 18:25:05 +0000
+++ include/core/CMakeLists.txt 2012-01-19 18:25:06 +0000
@@ -12,6 +12,7 @@
12 icon.h12 icon.h
13 match.h13 match.h
14 modifierhandler.h14 modifierhandler.h
15 managedstatebit.h
15 object.h16 object.h
16 option.h17 option.h
17 output.h18 output.h
1819
=== modified file 'include/core/asynchronous-container.h'
--- include/core/asynchronous-container.h 2012-01-19 18:25:05 +0000
+++ include/core/asynchronous-container.h 2012-01-19 18:25:06 +0000
@@ -42,7 +42,7 @@
42class ReadServerConnection;42class ReadServerConnection;
4343
44class AsynchronousContainer :44class AsynchronousContainer :
45 public AsynchronousObject,45 virtual public AsynchronousObject,
46 public Container46 public Container
47{47{
48 public:48 public:
@@ -76,6 +76,12 @@
76 void receiveInsertion (const Object::Ptr &);76 void receiveInsertion (const Object::Ptr &);
77 void receiveRemoval (const Object::Ptr &);77 void receiveRemoval (const Object::Ptr &);
7878
79 virtual void onReceiveInsertion (const Object::Ptr &) {};
80 virtual void onReceiveRemoval (const Object::Ptr &) {};
81
82 virtual void onSendInsertion (const Object::Ptr &) {};
83 virtual void onSendRemoval (const Object::Ptr &) {};
84
79 void addSentInsertion (const Object::Ptr &);85 void addSentInsertion (const Object::Ptr &);
80 Object::Ptr addSentRemoval (const Object::Ptr &);86 Object::Ptr addSentRemoval (const Object::Ptr &);
8187
8288
=== modified file 'include/core/asynchronous-object.h'
--- include/core/asynchronous-object.h 2012-01-19 18:25:05 +0000
+++ include/core/asynchronous-object.h 2012-01-19 18:25:06 +0000
@@ -66,18 +66,35 @@
66 /* Most recent sent positions */66 /* Most recent sent positions */
67 const compiz::window::Geometry &sentGeometry () const;67 const compiz::window::Geometry &sentGeometry () const;
68 const compiz::window::StackPosition &sentStackPosition () const;68 const compiz::window::StackPosition &sentStackPosition () const;
69 const uint64_t &sendState () const;
6970
70 void sendGeometry (const compiz::window::Geometry &);71 void sendGeometry (const compiz::window::Geometry &);
71 void sendStackPosition (const compiz::window::StackPosition &);72 void sendStackPosition (const compiz::window::StackPosition &);
73 void sendAddState (uint64_t state);
74 void sendRemoveState (uint64_t state);
7275
73 protected:76 protected:
7477
75 void receiveGeometry (const compiz::window::Geometry &);78 void receiveGeometry (const compiz::window::Geometry &);
76 void receiveStackPosition (const compiz::window::StackPosition &);79 void receiveStackPosition (const compiz::window::StackPosition &);
77 //void receiveMap ();80 void receiveState (uint64_t addState, uint64_t removeState);
7881
79 void addSentGeometry (const compiz::window::Geometry &);82 void addSentGeometry (const compiz::window::Geometry &);
80 void addSentStackPosition (const compiz::window::StackPosition &);83 void addSentStackPosition (const compiz::window::StackPosition &);
84 void addSentAddedState (uint64_t aState);
85 void addSentRemovedState (uint64_t rState);
86
87 virtual void onReceiveGeometry (const compiz::window::Geometry &) {};
88 virtual void onReceiveStackPosition (const compiz::window::StackPosition &) {};
89 virtual void onReceiveDeletion () {};
90 virtual void onReceiveAddState (uint64_t) {}
91 virtual void onReceiveRemoveState (uint64_t) {}
92
93 virtual void onSendGeometry (const compiz::window::Geometry &) {};
94 virtual void onSendStackPosition (const compiz::window::StackPosition &) {};
95 virtual void onSendDeletion () {};
96 virtual void onSendAddState (uint64_t) {}
97 virtual void onSendRemoveState (uint64_t) {}
8198
82 boost::shared_ptr <WriteServerConnection> mWriteConnection;99 boost::shared_ptr <WriteServerConnection> mWriteConnection;
83100
@@ -87,6 +104,7 @@
87104
88 compiz::window::Geometry mSentGeometry;105 compiz::window::Geometry mSentGeometry;
89 compiz::window::StackPosition mSentStackPosition;106 compiz::window::StackPosition mSentStackPosition;
107 uint64_t mSentState;
90};108};
91}109}
92}110}
93111
=== modified file 'include/core/asynchronous-server.h'
--- include/core/asynchronous-server.h 2012-01-19 18:25:05 +0000
+++ include/core/asynchronous-server.h 2012-01-19 18:25:06 +0000
@@ -36,6 +36,7 @@
36#include <core/stackposition.h>36#include <core/stackposition.h>
37#include <core/object.h>37#include <core/object.h>
38#include <glibmm/main.h>38#include <glibmm/main.h>
39#include <stdint.h>
3940
40namespace compiz41namespace compiz
41{42{
@@ -44,9 +45,20 @@
4445
45class WriteServerConnection;46class WriteServerConnection;
4647
48class ObjectCreationRequest
49{
50 public:
51
52 typedef boost::shared_ptr <ObjectCreationRequest> Ptr;
53 virtual ~ObjectCreationRequest ();
54 protected:
55
56 ObjectCreationRequest ();
57};
58
59
47class AsynchronousServer :60class AsynchronousServer :
48 public Server,61 public Server
49 public boost::enable_shared_from_this <AsynchronousServer>
50{62{
51 public:63 public:
5264
@@ -54,8 +66,11 @@
5466
55 virtual ~AsynchronousServer ();67 virtual ~AsynchronousServer ();
5668
69 static const unsigned int BlockUntilCompletion = (1 << 0);
70 static const unsigned int DiscardGeneratedEvents = (1 << 0);
71
57 boost::shared_ptr <WriteServerConnection> connect ();72 boost::shared_ptr <WriteServerConnection> connect ();
5873 void flush (unsigned int);
59 protected:74 protected:
6075
61 AsynchronousServer ();76 AsynchronousServer ();
@@ -67,10 +82,21 @@
67 virtual void sendParent (const ObjectIdentifier::Ptr &,82 virtual void sendParent (const ObjectIdentifier::Ptr &,
68 const ObjectIdentifier::Ptr &) = 0;83 const ObjectIdentifier::Ptr &) = 0;
6984
85 virtual void sendCreateObject (const boost::shared_ptr <ObjectCreationRequest> &) = 0;
86 virtual void sendDeleteObject (const ObjectIdentifier::Ptr &) = 0;
87 virtual void sendState (const ObjectIdentifier::Ptr &, uint64_t aState, uint64_t rState) = 0;
88
89 virtual void dispatchRequests (unsigned int) = 0;
90
91 void setEventSource (const Glib::RefPtr <Glib::Source> &);
92
70 compiz::window::ReadServerConnection::Ptr mReadConnection;93 compiz::window::ReadServerConnection::Ptr mReadConnection;
94
95 friend class WriteServerConnection;
96
97 private:
98
71 Glib::RefPtr <Glib::Source> mEventSource;99 Glib::RefPtr <Glib::Source> mEventSource;
72
73 friend class WriteServerConnection;
74};100};
75101
76}102}
77103
=== modified file 'include/core/container.h'
--- include/core/container.h 2012-01-19 18:25:05 +0000
+++ include/core/container.h 2012-01-19 18:25:06 +0000
@@ -38,7 +38,8 @@
38{38{
3939
40class Container :40class Container :
41 virtual public Object41 virtual public Object,
42 public boost::enable_shared_from_this <Container>
42{43{
43 public:44 public:
4445
4546
=== added file 'include/core/managedstatebit.h'
--- include/core/managedstatebit.h 1970-01-01 00:00:00 +0000
+++ include/core/managedstatebit.h 2012-01-19 18:25:06 +0000
@@ -0,0 +1,114 @@
1/*
2 * Copyright © 2011 Canonical Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Dennis Kasprzyk not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Dennis Kasprzyk makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
24 * David Reveman <davidr@novell.com>
25 */
26
27#ifndef _COMPIZ_MANAGED_STATE_BIT_H
28#define _COMPIZ_MANAGED_STATE_BIT_H
29
30#include <stdint.h>
31#include <boost/noncopyable.hpp>
32#include <vector>
33
34namespace compiz
35{
36namespace window
37{
38
39/**
40 * Static class of managed states
41 */
42class ManagedStates
43{
44 public:
45
46 static bool registerState (uint64_t &stateBit);
47 static bool unregisterState (uint64_t &stateBit);
48
49 private:
50
51 ManagedStates () {};
52 ~ManagedStates () {};
53
54 /* singleton state bit base
55 * use this to determine the number
56 * of state bits remaining for implementations
57 * to use. The protected functions registerState
58 * and unregisterState will manage free space
59 * in the state bits */
60 static uint64_t stateBase;
61
62 /* The vector keeps track of pointers to all
63 * of the state bit identifiers, they are modified
64 * at runtime depending on free space within
65 * the state base */
66 static std::vector <uint64_t *> managedStateBits;
67};
68
69/**
70 * An RAII managed state bit definition class,
71 * by holding an instance of this class, a unique
72 * bitmask is registered with the singleton list
73 * in Object which is used to identify a particular
74 * state of the object. The actual value of the
75 * underlying bitmask can change depending on the free
76 * space in the total number of bits available in Object */
77class ManagedStateBit :
78 boost::noncopyable
79{
80 public:
81
82 ManagedStateBit ();
83 ~ManagedStateBit ();
84
85 inline uint64_t operator~ () const;
86 inline uint64_t operator& (const uint64_t &i) const;
87 inline uint64_t operator& (const ManagedStateBit &b) const;
88 inline uint64_t operator| (const uint64_t &i) const;
89 inline uint64_t operator| (const ManagedStateBit &b) const;
90 inline uint64_t operator^ (const uint64_t &i) const;
91 inline uint64_t operator^ (const ManagedStateBit &b) const;
92
93 inline uint64_t operator&= (const uint64_t &i);
94 inline uint64_t operator&= (const ManagedStateBit &b);
95 inline uint64_t operator|= (const uint64_t &i);
96 inline uint64_t operator|= (const ManagedStateBit &b);
97 inline uint64_t operator^= (const uint64_t &i);
98 inline uint64_t operator^= (const ManagedStateBit &b);
99
100 inline bool operator== (const uint64_t &i) const;
101 inline bool operator== (const ManagedStateBit &b) const;
102 inline bool operator!= (const uint64_t &i) const;
103 inline bool operator!= (const ManagedStateBit &b) const;
104
105 operator uint64_t () const;
106 private:
107
108 uint64_t mStateBit;
109};
110
111}
112}
113
114#endif
0115
=== modified file 'include/core/object.h'
--- include/core/object.h 2012-01-19 18:25:05 +0000
+++ include/core/object.h 2012-01-19 18:25:06 +0000
@@ -30,7 +30,9 @@
30#include <boost/shared_ptr.hpp>30#include <boost/shared_ptr.hpp>
31#include <core/windowgeometry.h>31#include <core/windowgeometry.h>
32#include <core/stackposition.h>32#include <core/stackposition.h>
33#include <core/managedstatebit.h>
33#include <boost/enable_shared_from_this.hpp>34#include <boost/enable_shared_from_this.hpp>
35#include <stdint.h>
3436
35namespace compiz37namespace compiz
36{38{
@@ -65,16 +67,16 @@
65 bool operator== (const ObjectIdentifier::Ptr &) const;67 bool operator== (const ObjectIdentifier::Ptr &) const;
66 bool operator!= (const ObjectIdentifier::Ptr &) const;68 bool operator!= (const ObjectIdentifier::Ptr &) const;
6769
68 bool equal (const ObjectIdentifier::Ptr &) const;70 bool equal (const ObjectIdentifier::Ptr &) const;
6971
70 const boost::shared_ptr <Object> & operator() ();72 boost::shared_ptr <Object> operator() ();
71 const boost::shared_ptr <Object> & operator() () const;73 boost::shared_ptr <Object> operator() () const;
7274
73 protected:75 protected:
7476
75 virtual bool compare (const ObjectIdentifier::Ptr &) const = 0;77 virtual bool compare (const ObjectIdentifier::Ptr &) const = 0;
76 virtual ObjectType getType () const = 0;78 virtual ObjectType getType () const = 0;
77 virtual const boost::shared_ptr <Object> & lookup () const = 0;79 virtual boost::shared_ptr <Object> lookup () const = 0;
7880
79 /* Either fully resolved or looked up81 /* Either fully resolved or looked up
80 * at runtime in the repository */82 * at runtime in the repository */
@@ -83,12 +85,35 @@
83 friend class Server;85 friend class Server;
84};86};
8587
86class Object88class ObjectKey
89{
90};
91
92class Object :
93 boost::noncopyable
87{94{
88 public:95 public:
8996
90 typedef boost::shared_ptr <Object> Ptr;97 typedef boost::shared_ptr <Object> Ptr;
9198
99 class Visitor :
100 boost::noncopyable
101 {
102 public:
103
104 Visitor (ObjectKey const &, const compiz::window::Object::Ptr &o);
105 virtual ~Visitor ();
106
107 protected:
108 bool setStackPosition (const StackPosition &);
109 bool setGeometry (const Geometry &);
110 bool setContainer (const boost::shared_ptr <Container> &);
111 bool addState (const uint64_t &state);
112 bool removeState (const uint64_t &state);
113 private:
114 compiz::window::Object::Ptr mObject;
115 };
116
92 Object (const ObjectIdentifier::Ptr &);117 Object (const ObjectIdentifier::Ptr &);
93 Object (const ObjectIdentifier::Ptr &,118 Object (const ObjectIdentifier::Ptr &,
94 const compiz::window::Geometry &);119 const compiz::window::Geometry &);
@@ -106,16 +131,23 @@
106 const ObjectIdentifier::Ptr & id () const;131 const ObjectIdentifier::Ptr & id () const;
107 const compiz::window::Geometry & geometry () const;132 const compiz::window::Geometry & geometry () const;
108 const compiz::window::StackPosition & stackPosition () const;133 const compiz::window::StackPosition & stackPosition () const;
134 const uint64_t & state () const;
109135
110 bool operator== (const Object &) const;136 bool operator== (const Object &) const;
111 bool operator!= (const Object &) const;137 bool operator!= (const Object &) const;
112138
139 /* state bits for this */
140 static ManagedStateBit StateMapped;
141
113 protected:142 protected:
114143
144 /* Returns true if anything was actually changed */
115 bool setStackPosition (const StackPosition &);145 bool setStackPosition (const StackPosition &);
116 bool setGeometry (const Geometry &);146 bool setGeometry (const Geometry &);
117 //virtual bool show () = 0;147 bool setContainer (const boost::shared_ptr <Container> &);
118 //virtual bool hide () = 0;148 bool setVisible (bool);
149 bool addState (const uint64_t &state);
150 bool removeState (const uint64_t &state);
119151
120 private:152 private:
121153
@@ -123,6 +155,9 @@
123 compiz::window::Geometry mGeometry;155 compiz::window::Geometry mGeometry;
124 compiz::window::StackPosition mStackPosition;156 compiz::window::StackPosition mStackPosition;
125 boost::shared_ptr <Container> mContainer;157 boost::shared_ptr <Container> mContainer;
158 uint64_t mState;
159
160
126};161};
127162
128class SynchronousObject :163class SynchronousObject :
@@ -146,6 +181,7 @@
146181
147 bool setStackPosition (const StackPosition &);182 bool setStackPosition (const StackPosition &);
148 bool setGeometry (const Geometry &);183 bool setGeometry (const Geometry &);
184 bool setState (const uint64_t &state);
149};185};
150186
151}187}
152188
=== modified file 'include/core/server-read.h'
--- include/core/server-read.h 2012-01-19 18:25:05 +0000
+++ include/core/server-read.h 2012-01-19 18:25:06 +0000
@@ -34,6 +34,7 @@
34#include <core/object.h>34#include <core/object.h>
35#include <core/asynchronous-object.h>35#include <core/asynchronous-object.h>
36#include <core/asynchronous-container.h>36#include <core/asynchronous-container.h>
37#include <stdint.h>
3738
38namespace compiz39namespace compiz
39{40{
@@ -58,6 +59,10 @@
5859
59 void receiveParent (const AsynchronousObject::Ptr &,60 void receiveParent (const AsynchronousObject::Ptr &,
60 const AsynchronousContainer::Ptr &);61 const AsynchronousContainer::Ptr &);
62
63 void receiveState (const AsynchronousObject::Ptr &,
64 uint64_t addState,
65 uint64_t removeState);
61 protected:66 protected:
6267
63 ReadServerConnection ();68 ReadServerConnection ();
6469
=== modified file 'include/core/server-write.h'
--- include/core/server-write.h 2012-01-19 18:25:05 +0000
+++ include/core/server-write.h 2012-01-19 18:25:06 +0000
@@ -39,6 +39,8 @@
39namespace window39namespace window
40{40{
4141
42class ObjectCreationRequest;
43
42class WriteServerConnection :44class WriteServerConnection :
43 public boost::noncopyable45 public boost::noncopyable
44{46{
@@ -55,6 +57,15 @@
5557
56 void sendParent (const ObjectIdentifier::Ptr &id,58 void sendParent (const ObjectIdentifier::Ptr &id,
57 const ObjectIdentifier::Ptr &parent);59 const ObjectIdentifier::Ptr &parent);
60
61 void sendCreateObject (const ObjectCreationRequest::Ptr &req);
62
63 void sendDeleteObject (const ObjectIdentifier::Ptr &id);
64
65 void sendState (const ObjectIdentifier::Ptr &id,
66 uint64_t aState,
67 uint64_t rState);
68
58 private:69 private:
5970
60 WriteServerConnection (const compiz::window::AsynchronousServer::Ptr &);71 WriteServerConnection (const compiz::window::AsynchronousServer::Ptr &);
6172
=== modified file 'include/core/server.h'
--- include/core/server.h 2012-01-19 18:25:05 +0000
+++ include/core/server.h 2012-01-19 18:25:06 +0000
@@ -29,7 +29,9 @@
2929
30#include <boost/shared_ptr.hpp>30#include <boost/shared_ptr.hpp>
31#include <boost/noncopyable.hpp>31#include <boost/noncopyable.hpp>
32#include <boost/enable_shared_from_this.hpp>
32#include <core/object.h>33#include <core/object.h>
34#include <core/container.h>
3335
34namespace compiz36namespace compiz
35{37{
@@ -37,6 +39,7 @@
37{39{
3840
39class Server :41class Server :
42 public boost::enable_shared_from_this <Server>,
40 public boost::noncopyable43 public boost::noncopyable
41{44{
42 public:45 public:
@@ -45,18 +48,30 @@
45 virtual ~Server ();48 virtual ~Server ();
4649
47 const Object::Ptr & root ();50 const Object::Ptr & root ();
48 virtual const Object::Ptr & lookup (const boost::shared_ptr <const ObjectIdentifier> &id) = 0;51 virtual Object::Ptr lookup (const boost::shared_ptr <const ObjectIdentifier> &id) const = 0;
4952
50 static Server::Ptr Default ();53 static Server::Ptr Default ();
5154
52 protected:55 protected:
5356
54 Server ();57 Server ();
58 static void SetDefault (Server::Ptr s);
59
60 void setRoot (const compiz::window::Object::Ptr &root);
61
62 virtual compiz::window::Object::Ptr
63 createObject (const compiz::window::ObjectIdentifier::Ptr &id,
64 const compiz::window::Geometry &g = compiz::window::Geometry (),
65 const compiz::window::StackPosition &sp = compiz::window::StackPosition (),
66 const compiz::window::Container::Ptr &c = boost::shared_polymorphic_cast <compiz::window::Container> (Server::Default ()->root ())) = 0;
67
68 virtual void
69 removeObject (const compiz::window::ObjectIdentifier::Ptr &) = 0;
5570
56 private:71 private:
5772
73 static Server::Ptr mDefault;
58 Object::Ptr mRoot;74 Object::Ptr mRoot;
59 static Server::Ptr mDefault;
60};75};
6176
62}77}
6378
=== added file 'include/core/x11-object.h'
--- include/core/x11-object.h 1970-01-01 00:00:00 +0000
+++ include/core/x11-object.h 2012-01-19 18:25:06 +0000
@@ -0,0 +1,116 @@
1/*
2 * Copyright © 2011 Canonical Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Dennis Kasprzyk not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Dennis Kasprzyk makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
24 * David Reveman <davidr@novell.com>
25 */
26
27#ifndef _COMPIZ_X11_OBJECT_H
28#define _COMPIZ_X11_OBJECT_H
29
30#include <core/object.h>
31#include <core/asynchronous-object.h>
32#include <core/asynchronous-container.h>
33#include <core/windowgeometry.h>
34#include <X11/Xlib.h>
35#include <boost/shared_ptr.hpp>
36
37namespace compiz
38{
39namespace window
40{
41
42class X11Server;
43class X11ObjectIdentifier;
44class WriteServerConnection;
45
46class X11ObjectIdentifier :
47 public ObjectIdentifier
48{
49 public:
50
51 typedef boost::shared_ptr <X11ObjectIdentifier> Ptr;
52 typedef boost::shared_ptr <const X11ObjectIdentifier> ConstPtr;
53
54 X11ObjectIdentifier (Window id);
55 ~X11ObjectIdentifier ();
56
57 void print ();
58
59 protected:
60
61 compiz::window::ObjectIdentifier::ObjectType getType () const;
62 bool compare (const ObjectIdentifier::Ptr &) const;
63 compiz::window::Object::Ptr lookup () const;
64
65 private:
66
67 Window mId;
68
69 friend class X11Server;
70};
71
72
73class X11Object :
74 virtual public AsynchronousObject
75{
76 public:
77
78 typedef boost::shared_ptr <X11Object> Ptr;
79
80 virtual ~X11Object ();
81
82 protected:
83
84 X11Object (const ObjectIdentifier::Ptr &,
85 const boost::shared_ptr <WriteServerConnection> &,
86 const compiz::window::Geometry &,
87 const boost::shared_ptr <Container> &);
88
89 friend class X11Server;
90};
91
92class X11Container :
93 public AsynchronousContainer,
94 public X11Object
95{
96 public:
97
98 typedef boost::shared_ptr <X11Container> Ptr;
99
100 virtual ~X11Container ();
101
102 protected:
103
104 X11Container (const ObjectIdentifier::Ptr &,
105 const boost::shared_ptr <WriteServerConnection> &,
106 const compiz::window::Geometry &,
107 const boost::shared_ptr <Container> &);
108
109 friend class X11Server;
110
111};
112
113}
114}
115
116#endif
0117
=== added file 'include/core/x11-server.h'
--- include/core/x11-server.h 1970-01-01 00:00:00 +0000
+++ include/core/x11-server.h 2012-01-19 18:25:06 +0000
@@ -0,0 +1,140 @@
1/*
2 * Copyright © 2011 Canonical Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Dennis Kasprzyk not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Dennis Kasprzyk makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
24 * David Reveman <davidr@novell.com>
25 */
26
27#ifndef _COMPIZ_X11_SERVER_H
28#define _COMPIZ_X11_SERVER_H
29
30#include <core/server.h>
31#include <core/asynchronous-server.h>
32#include <core/x11-object.h>
33#include <boost/shared_ptr.hpp>
34#include <boost/unordered_map.hpp>
35#include <boost/functional/hash.hpp>
36#include <X11/Xlib.h>
37
38
39namespace compiz
40{
41namespace window
42{
43void populateXWindowChanges (const compiz::window::Geometry &g,
44 unsigned int mask,
45 XWindowChanges &xwc);
46
47void populateXWindowChanges (const compiz::window::StackPosition &sp,
48 unsigned int mask,
49 XWindowChanges &xwc);
50
51class X11ObjectCreationRequest :
52 public compiz::window::ObjectCreationRequest
53{
54 public:
55
56 typedef boost::shared_ptr <X11ObjectCreationRequest> Ptr;
57
58 X11ObjectCreationRequest (XSetWindowAttributes &attr,
59 const compiz::window::Geometry &g,
60 unsigned int cclass,
61 unsigned int depth,
62 const compiz::window::X11ObjectIdentifier::Ptr &parent,
63 unsigned int attrValueMask,
64 Visual *vis);
65
66 virtual ~X11ObjectCreationRequest ();
67
68 inline XSetWindowAttributes & attributes () const;
69 inline const compiz::window::Geometry & geometry () const;
70 inline const unsigned int & cclass () const;
71 inline const unsigned int & depth () const;
72 inline const compiz::window::X11ObjectIdentifier::Ptr & parent () const;
73 inline const unsigned int & attrValueMask () const;
74 inline Visual * visual () const;
75
76 private:
77
78 mutable XSetWindowAttributes mAttr;
79 compiz::window::Geometry mGeometry;
80 unsigned int mClass;
81 unsigned int mDepth;
82 compiz::window::X11ObjectIdentifier::Ptr mParent;
83 unsigned int mAttrValueMask;
84 Visual *mVis;
85};
86
87class X11Server :
88 public AsynchronousServer
89{
90 public:
91
92 typedef boost::shared_ptr <X11Server> Ptr;
93
94 virtual ~X11Server ();
95
96 Object::Ptr lookup (const boost::shared_ptr <const ObjectIdentifier> &id) const;
97
98 protected:
99
100 X11Server ();
101 X11Server (const char *);
102 X11Server (Display *);
103
104 void sendGeometry (const ObjectIdentifier::Ptr &,
105 const compiz::window::Geometry &);
106
107 void sendStackPosition (const ObjectIdentifier::Ptr &,
108 const compiz::window::StackPosition &);
109
110 void sendParent (const ObjectIdentifier::Ptr &child,
111 const ObjectIdentifier::Ptr &parent);
112
113 void sendCreateObject (const boost::shared_ptr <ObjectCreationRequest> &req);
114
115 void sendDeleteObject (const ObjectIdentifier::Ptr &id);
116
117 void sendState (const ObjectIdentifier::Ptr &id, uint64_t aState, uint64_t rState);
118
119 void dispatchRequests (unsigned int);
120
121 void setupEventSource ();
122 void setRoot (Window root, const Geometry &);
123
124 void addObjectToTree (const std::pair <X11ObjectIdentifier::Ptr,
125 X11Object::Ptr > &);
126 void removeKeyFromTree (const ObjectIdentifier::Ptr &);
127
128 private:
129
130 void dispatchEvent (XEvent *);
131 void queueEvents ();
132
133 boost::unordered_map <Window, X11Object::Ptr> mObjectTree;
134 Display *mDisplay;
135};
136
137}
138}
139
140#endif
0141
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2012-01-19 18:25:05 +0000
+++ src/CMakeLists.txt 2012-01-19 18:25:06 +0000
@@ -110,6 +110,10 @@
110 ${CMAKE_CURRENT_SOURCE_DIR}/server-write.cpp110 ${CMAKE_CURRENT_SOURCE_DIR}/server-write.cpp
111 ${CMAKE_CURRENT_SOURCE_DIR}/stack.cpp111 ${CMAKE_CURRENT_SOURCE_DIR}/stack.cpp
112 ${CMAKE_CURRENT_SOURCE_DIR}/asynchronous-stack.cpp112 ${CMAKE_CURRENT_SOURCE_DIR}/asynchronous-stack.cpp
113 ${CMAKE_CURRENT_SOURCE_DIR}/x11-object.cpp
114 ${CMAKE_CURRENT_SOURCE_DIR}/x11-container.cpp
115 ${CMAKE_CURRENT_SOURCE_DIR}/x11-server.cpp
116 ${CMAKE_CURRENT_SOURCE_DIR}/managedstatebit.cpp
113 ${_bcop_sources}117 ${_bcop_sources}
114)118)
115119
116120
=== modified file 'src/asynchronous-container.cpp'
--- src/asynchronous-container.cpp 2012-01-19 18:25:05 +0000
+++ src/asynchronous-container.cpp 2012-01-19 18:25:06 +0000
@@ -27,11 +27,28 @@
27#include <core/server-write.h>27#include <core/server-write.h>
28#include <core/server.h>28#include <core/server.h>
2929
30class AsynchronousObjectContainerVisitor :
31 public compiz::window::Object::Visitor
32{
33 public:
34 AsynchronousObjectContainerVisitor (const compiz::window::ObjectKey &k,
35 const compiz::window::Object::Ptr &p) :
36 compiz::window::Object::Visitor (k, p)
37 {
38 }
39
40 inline bool changeContainer (const compiz::window::Container::Ptr & c)
41 {
42 return setContainer (c);
43 }
44};
45
30compiz::window::AsynchronousContainer::AsynchronousContainer (const compiz::window::ObjectIdentifier::Ptr &id,46compiz::window::AsynchronousContainer::AsynchronousContainer (const compiz::window::ObjectIdentifier::Ptr &id,
31 const compiz::window::WriteServerConnection::Ptr &writer) :47 const compiz::window::WriteServerConnection::Ptr &writer) :
32 Object::Object (id),48 Object::Object (id),
33 AsynchronousObject::AsynchronousObject (id, writer),49 AsynchronousObject::AsynchronousObject (id, writer),
34 Container::Container (id)50 Container::Container (id),
51 mWriteConnection (writer)
35{52{
36}53}
3754
@@ -40,7 +57,8 @@
40 const compiz::window::WriteServerConnection::Ptr &writer) :57 const compiz::window::WriteServerConnection::Ptr &writer) :
41 Object::Object (id, g),58 Object::Object (id, g),
42 AsynchronousObject::AsynchronousObject (id, g, writer),59 AsynchronousObject::AsynchronousObject (id, g, writer),
43 Container::Container (id, g)60 Container::Container (id, g),
61 mWriteConnection (writer)
44{62{
45}63}
4664
@@ -50,7 +68,8 @@
50 const compiz::window::WriteServerConnection::Ptr &writer) :68 const compiz::window::WriteServerConnection::Ptr &writer) :
51 Object::Object (id, g, sp),69 Object::Object (id, g, sp),
52 AsynchronousObject::AsynchronousObject (id, g, sp, writer),70 AsynchronousObject::AsynchronousObject (id, g, sp, writer),
53 Container::Container (id, g, sp)71 Container::Container (id, g, sp),
72 mWriteConnection (writer)
54{73{
55}74}
5675
@@ -61,7 +80,8 @@
61 const compiz::window::WriteServerConnection::Ptr &writer) :80 const compiz::window::WriteServerConnection::Ptr &writer) :
62 Object::Object (id, g, sp, c),81 Object::Object (id, g, sp, c),
63 AsynchronousObject::AsynchronousObject (id, g, sp , c, writer),82 AsynchronousObject::AsynchronousObject (id, g, sp , c, writer),
64 Container::Container (id, g, sp, c)83 Container::Container (id, g, sp, c),
84 mWriteConnection (writer)
65{85{
66}86}
6787
@@ -72,6 +92,8 @@
72void92void
73compiz::window::AsynchronousContainer::sendInsertion (const Object::Ptr &o)93compiz::window::AsynchronousContainer::sendInsertion (const Object::Ptr &o)
74{94{
95 onSendInsertion (o);
96
75 mWriteConnection->sendParent (o->id (), id ());97 mWriteConnection->sendParent (o->id (), id ());
7698
77 addSentInsertion (o);99 addSentInsertion (o);
@@ -80,23 +102,35 @@
80compiz::window::Object::Ptr102compiz::window::Object::Ptr
81compiz::window::AsynchronousContainer::sendRemoval (const Object::Ptr &o)103compiz::window::AsynchronousContainer::sendRemoval (const Object::Ptr &o)
82{104{
105 onSendRemoval (o);
106
107 mWriteConnection->sendParent (o->id (), Server::Default ()->root ()->id ());
108
83 Object::Ptr p = addSentRemoval (o);109 Object::Ptr p = addSentRemoval (o);
84110
85 mWriteConnection->sendParent (o->id (), Server::Default ()->root ()->id ());
86
87 return p;111 return p;
88}112}
89113
90void114void
91compiz::window::AsynchronousContainer::receiveInsertion (const Object::Ptr &o)115compiz::window::AsynchronousContainer::receiveInsertion (const Object::Ptr &o)
92{116{
117 compiz::window::ObjectKey k;
118 AsynchronousObjectContainerVisitor v (k, o);
119 onReceiveInsertion (o);
120
93 Container::insert (o);121 Container::insert (o);
122 v.changeContainer (Container::shared_from_this ());
94}123}
95124
96void125void
97compiz::window::AsynchronousContainer::receiveRemoval (const Object::Ptr &o)126compiz::window::AsynchronousContainer::receiveRemoval (const Object::Ptr &o)
98{127{
128 compiz::window::ObjectKey k;
129 AsynchronousObjectContainerVisitor v (k, o);
130 onReceiveRemoval (o);
131
99 Container::remove (o);132 Container::remove (o);
133 v.changeContainer (Container::Ptr ());
100}134}
101135
102void136void
103137
=== modified file 'src/asynchronous-object.cpp'
--- src/asynchronous-object.cpp 2012-01-19 18:25:05 +0000
+++ src/asynchronous-object.cpp 2012-01-19 18:25:06 +0000
@@ -76,9 +76,17 @@
76 return mSentStackPosition;76 return mSentStackPosition;
77}77}
7878
79const uint64_t &
80compiz::window::AsynchronousObject::sendState () const
81{
82 return mSentState;
83}
84
79void85void
80compiz::window::AsynchronousObject::sendGeometry (const compiz::window::Geometry &g)86compiz::window::AsynchronousObject::sendGeometry (const compiz::window::Geometry &g)
81{87{
88 onSendGeometry (g);
89
82 mWriteConnection->sendGeometry (id (), g);90 mWriteConnection->sendGeometry (id (), g);
8391
84 addSentGeometry (g);92 addSentGeometry (g);
@@ -87,24 +95,61 @@
87void95void
88compiz::window::AsynchronousObject::sendStackPosition (const compiz::window::StackPosition &sp)96compiz::window::AsynchronousObject::sendStackPosition (const compiz::window::StackPosition &sp)
89{97{
98 onSendStackPosition (sp);
99
90 mWriteConnection->sendStackPosition (id (), sp);100 mWriteConnection->sendStackPosition (id (), sp);
91101
92 addSentStackPosition (sp);102 addSentStackPosition (sp);
93}103}
94104
95void105void
106compiz::window::AsynchronousObject::sendAddState (uint64_t aState)
107{
108 onSendAddState (aState);
109
110 mWriteConnection->sendState (id (), aState & ~mSentState, 0);
111
112 addSentAddedState (aState);
113}
114
115void
116compiz::window::AsynchronousObject::sendRemoveState (uint64_t rState)
117{
118 onSendRemoveState (rState);
119
120 mWriteConnection->sendState (id (), 0, rState & mSentState);
121
122 addSentRemovedState (rState);
123}
124
125void
96compiz::window::AsynchronousObject::receiveGeometry (const compiz::window::Geometry &g)126compiz::window::AsynchronousObject::receiveGeometry (const compiz::window::Geometry &g)
97{127{
128 onReceiveGeometry (g);
129
98 Object::setGeometry (g);130 Object::setGeometry (g);
99}131}
100132
101void133void
102compiz::window::AsynchronousObject::receiveStackPosition (const compiz::window::StackPosition &sp)134compiz::window::AsynchronousObject::receiveStackPosition (const compiz::window::StackPosition &sp)
103{135{
136 onReceiveStackPosition (sp);
137
104 Object::setStackPosition (sp);138 Object::setStackPosition (sp);
105}139}
106140
107void141void
142compiz::window::AsynchronousObject::receiveState (uint64_t addState,
143 uint64_t removeState)
144{
145 onReceiveAddState (addState);
146 onReceiveRemoveState (removeState);
147
148 Object::addState (addState);
149 Object::removeState (removeState);
150}
151
152void
108compiz::window::AsynchronousObject::addSentGeometry (const compiz::window::Geometry &g)153compiz::window::AsynchronousObject::addSentGeometry (const compiz::window::Geometry &g)
109{154{
110 mSentGeometry = g;155 mSentGeometry = g;
@@ -115,3 +160,15 @@
115{160{
116 mSentStackPosition = sp;161 mSentStackPosition = sp;
117}162}
163
164void
165compiz::window::AsynchronousObject::addSentAddedState (uint64_t aState)
166{
167 mSentState |= aState;
168}
169
170void
171compiz::window::AsynchronousObject::addSentRemovedState (uint64_t rState)
172{
173 mSentState &= ~rState;
174}
118175
=== modified file 'src/asynchronous-server.cpp'
--- src/asynchronous-server.cpp 2012-01-19 18:25:05 +0000
+++ src/asynchronous-server.cpp 2012-01-19 18:25:06 +0000
@@ -26,6 +26,14 @@
26#include <core/asynchronous-server.h>26#include <core/asynchronous-server.h>
27#include <core/server-write.h>27#include <core/server-write.h>
2828
29compiz::window::ObjectCreationRequest::ObjectCreationRequest ()
30{
31}
32
33compiz::window::ObjectCreationRequest::~ObjectCreationRequest ()
34{
35}
36
29compiz::window::AsynchronousServer::AsynchronousServer () :37compiz::window::AsynchronousServer::AsynchronousServer () :
30 Server::Server (),38 Server::Server (),
31 mReadConnection (new compiz::window::ReadServerConnection)39 mReadConnection (new compiz::window::ReadServerConnection)
@@ -36,10 +44,26 @@
36{44{
37}45}
3846
47void
48compiz::window::AsynchronousServer::setEventSource (const Glib::RefPtr <Glib::Source> &source)
49{
50 const Glib::RefPtr <Glib::MainContext> &mc = Glib::MainContext::get_default ();
51 mEventSource = source;
52
53 mEventSource->attach (mc);
54}
55
39compiz::window::WriteServerConnection::Ptr56compiz::window::WriteServerConnection::Ptr
40compiz::window::AsynchronousServer::connect ()57compiz::window::AsynchronousServer::connect ()
41{58{
42 compiz::window::AsynchronousServer::Ptr t = shared_from_this ();59 compiz::window::AsynchronousServer::Ptr t =
60 boost::shared_static_cast <compiz::window::AsynchronousServer> (shared_from_this ());
43 return compiz::window::WriteServerConnection::Ptr (new compiz::window::WriteServerConnection (t));61 return compiz::window::WriteServerConnection::Ptr (new compiz::window::WriteServerConnection (t));
44}62}
4563
64void
65compiz::window::AsynchronousServer::flush (unsigned int flags)
66{
67 dispatchRequests (flags);
68}
69
4670
=== modified file 'src/container.cpp'
--- src/container.cpp 2012-01-19 18:25:05 +0000
+++ src/container.cpp 2012-01-19 18:25:06 +0000
@@ -78,7 +78,9 @@
78 if (it != mChildren.end ())78 if (it != mChildren.end ())
79 return false;79 return false;
80 else80 else
81 {
81 mChildren.insert (it, o);82 mChildren.insert (it, o);
83 }
8284
83 return true;85 return true;
84}86}
8587
=== modified file 'src/eventsource.cpp'
--- src/eventsource.cpp 2012-01-19 18:25:05 +0000
+++ src/eventsource.cpp 2012-01-19 18:25:06 +0000
@@ -68,6 +68,7 @@
68CompEventSource::callback ()68CompEventSource::callback ()
69{69{
70 mProcEvents ();70 mProcEvents ();
71 XFlush (mDpy);
71 return true;72 return true;
72}73}
7374
7475
=== added file 'src/managedstatebit.cpp'
--- src/managedstatebit.cpp 1970-01-01 00:00:00 +0000
+++ src/managedstatebit.cpp 2012-01-19 18:25:06 +0000
@@ -0,0 +1,173 @@
1/*
2 * Copyright © 2010 Canonical Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Canonical Ltd. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Canonical Ltd. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
24 */
25
26#include <core/managedstatebit.h>
27#include <core/object.h>
28#include <boost/bind.hpp>
29
30uint64_t compiz::window::ManagedStates::stateBase = (1 << 0);
31std::vector <uint64_t *> compiz::window::ManagedStates::managedStateBits = std::vector <uint64_t *> ();
32
33bool
34compiz::window::ManagedStates::registerState (uint64_t &state)
35{
36 managedStateBits.push_back (&state);
37 state = stateBase;
38 stateBase <<= 1;
39
40 /* FIXME: check for overflow */
41 return true;
42}
43
44static bool
45findIfMatchingUINT64Ptr (uint64_t *p,
46 const uint64_t &v)
47{
48 return *p == v;
49}
50
51bool
52compiz::window::ManagedStates::unregisterState (uint64_t &state)
53{
54 std::vector <uint64_t *>::iterator it = std::find_if (managedStateBits.begin (),
55 managedStateBits.end (),
56 boost::bind (findIfMatchingUINT64Ptr, _1, state));
57
58 if (it != managedStateBits.end ())
59 {
60 it = managedStateBits.erase (it);
61
62 /* Shift all other bits down one */
63 while (it != managedStateBits.end ())
64 {
65 (*(*it)) >>= 1;
66 it++;
67 }
68
69 return true;
70 }
71
72 return false;
73}
74
75compiz::window::ManagedStateBit::ManagedStateBit ()
76{
77 compiz::window::ManagedStates::registerState (mStateBit);
78}
79
80compiz::window::ManagedStateBit::~ManagedStateBit ()
81{
82 compiz::window::ManagedStates::unregisterState (mStateBit);
83}
84
85uint64_t compiz::window::ManagedStateBit::operator~ () const
86{
87 return ~mStateBit;
88}
89
90uint64_t compiz::window::ManagedStateBit::operator& (const uint64_t &i) const
91{
92 return mStateBit & i;
93}
94
95uint64_t compiz::window::ManagedStateBit::operator& (const ManagedStateBit &b) const
96{
97 return mStateBit & b.mStateBit;
98}
99
100uint64_t compiz::window::ManagedStateBit::operator| (const uint64_t &i) const
101{
102 return mStateBit | i;
103}
104
105uint64_t compiz::window::ManagedStateBit::operator| (const ManagedStateBit &b) const
106{
107 return mStateBit | b.mStateBit;
108}
109
110uint64_t compiz::window::ManagedStateBit::operator^ (const uint64_t &i) const
111{
112 return mStateBit ^ i;
113}
114
115uint64_t compiz::window::ManagedStateBit::operator^ (const ManagedStateBit &b) const
116{
117 return mStateBit ^ b.mStateBit;
118}
119
120uint64_t compiz::window::ManagedStateBit::operator&= (const uint64_t &i)
121{
122 return mStateBit |= i;
123}
124
125uint64_t compiz::window::ManagedStateBit::operator&= (const ManagedStateBit &b)
126{
127 return mStateBit |= b.mStateBit;
128}
129
130uint64_t compiz::window::ManagedStateBit::operator|= (const uint64_t &i)
131{
132 return mStateBit |= i;
133}
134
135uint64_t compiz::window::ManagedStateBit::operator|= (const ManagedStateBit &b)
136{
137 return mStateBit |= b.mStateBit;
138}
139
140uint64_t compiz::window::ManagedStateBit::operator^= (const uint64_t &i)
141{
142 return mStateBit ^= i;
143}
144
145uint64_t compiz::window::ManagedStateBit::operator^= (const ManagedStateBit &b)
146{
147 return mStateBit ^= b.mStateBit;
148}
149
150bool compiz::window::ManagedStateBit::operator== (const uint64_t &i) const
151{
152 return mStateBit == i;
153}
154
155bool compiz::window::ManagedStateBit::operator!= (const uint64_t &i) const
156{
157 return mStateBit != i;
158}
159
160bool compiz::window::ManagedStateBit::operator== (const ManagedStateBit &b) const
161{
162 return mStateBit == b.mStateBit;
163}
164
165bool compiz::window::ManagedStateBit::operator!= (const ManagedStateBit &b) const
166{
167 return mStateBit != b.mStateBit;
168}
169
170compiz::window::ManagedStateBit::operator uint64_t() const
171{
172 return mStateBit;
173}
0174
=== modified file 'src/object.cpp'
--- src/object.cpp 2012-01-19 18:25:05 +0000
+++ src/object.cpp 2012-01-19 18:25:06 +0000
@@ -24,6 +24,47 @@
24 */24 */
2525
26#include <core/object.h>26#include <core/object.h>
27#include <core/managedstatebit.h>
28#include <boost/bind.hpp>
29
30compiz::window::Object::Visitor::Visitor (const ObjectKey &, const compiz::window::Object::Ptr &o) :
31 mObject (o)
32{
33}
34
35compiz::window::Object::Visitor::~Visitor ()
36{
37}
38
39bool
40compiz::window::Object::Visitor::setGeometry (const Geometry &g)
41{
42 return mObject->setGeometry (g);
43}
44
45bool
46compiz::window::Object::Visitor::setStackPosition (const StackPosition &sp)
47{
48 return mObject->setStackPosition (sp);
49}
50
51bool
52compiz::window::Object::Visitor::setContainer (const boost::shared_ptr <compiz::window::Container> &c)
53{
54 return mObject->setContainer (c);
55}
56
57bool
58compiz::window::Object::Visitor::addState (const uint64_t &state)
59{
60 return mObject->addState (state);
61}
62
63bool
64compiz::window::Object::Visitor::removeState (const uint64_t &state)
65{
66 return mObject->removeState (state);
67}
2768
28compiz::window::Object::Object (const compiz::window::ObjectIdentifier::Ptr &id) :69compiz::window::Object::Object (const compiz::window::ObjectIdentifier::Ptr &id) :
29 mId (id)70 mId (id)
@@ -96,6 +137,12 @@
96 return mStackPosition;137 return mStackPosition;
97}138}
98139
140const uint64_t &
141compiz::window::Object::state () const
142{
143 return mState;
144}
145
99const compiz::window::ObjectIdentifier::Ptr &146const compiz::window::ObjectIdentifier::Ptr &
100compiz::window::Object::id () const147compiz::window::Object::id () const
101{148{
@@ -124,6 +171,41 @@
124}171}
125172
126bool173bool
174compiz::window::Object::setContainer (const boost::shared_ptr <Container> &c)
175{
176 mContainer = c;
177}
178
179bool
180compiz::window::Object::addState (const uint64_t &aState)
181{
182 if ((aState & mState) == mState)
183 return false;
184 mState |= aState;
185 return true;
186}
187
188bool
189compiz::window::Object::removeState (const uint64_t &aState)
190{
191 if ((aState & mState) == 0)
192 return false;
193 mState |= ~aState;
194 return true;
195}
196
197compiz::window::ManagedStateBit compiz::window::Object::StateMapped;
198
199bool
200compiz::window::Object::setVisible (bool visible)
201{
202 if (visible)
203 return addState (StateMapped);
204
205 return removeState (StateMapped);
206}
207
208bool
127compiz::window::Object::setStackPosition (const StackPosition &sp)209compiz::window::Object::setStackPosition (const StackPosition &sp)
128{210{
129 mStackPosition = sp;211 mStackPosition = sp;
@@ -176,7 +258,15 @@
176 return Object::setStackPosition (sp);258 return Object::setStackPosition (sp);
177}259}
178260
179const boost::shared_ptr <compiz::window::Object> &261bool
262compiz::window::SynchronousObject::setState (const uint64_t &sState)
263{
264 bool ret = Object::addState (sState & ~(state ()));
265 ret |= Object::removeState (~sState & state ());
266 return ret;
267}
268
269boost::shared_ptr <compiz::window::Object>
180compiz::window::ObjectIdentifier::operator() ()270compiz::window::ObjectIdentifier::operator() ()
181{271{
182 if (mObj)272 if (mObj)
@@ -188,7 +278,7 @@
188 }278 }
189}279}
190280
191const boost::shared_ptr <compiz::window::Object> &281boost::shared_ptr <compiz::window::Object>
192compiz::window::ObjectIdentifier::operator() () const282compiz::window::ObjectIdentifier::operator() () const
193{283{
194 if (mObj)284 if (mObj)
195285
=== modified file 'src/server-read.cpp'
--- src/server-read.cpp 2012-01-19 18:25:05 +0000
+++ src/server-read.cpp 2012-01-19 18:25:06 +0000
@@ -55,6 +55,16 @@
55 const compiz::window::AsynchronousContainer::Ptr &parent)55 const compiz::window::AsynchronousContainer::Ptr &parent)
56{56{
57 compiz::window::AsynchronousContainer::Ptr lastParent = boost::shared_static_cast <compiz::window::AsynchronousContainer> (child->container ());57 compiz::window::AsynchronousContainer::Ptr lastParent = boost::shared_static_cast <compiz::window::AsynchronousContainer> (child->container ());
58 lastParent->receiveRemoval (boost::shared_static_cast <compiz::window::Object> (child));58
59 if (lastParent)
60 lastParent->receiveRemoval (boost::shared_static_cast <compiz::window::Object> (child));
59 parent->receiveInsertion (boost::shared_static_cast <compiz::window::Object> (child));61 parent->receiveInsertion (boost::shared_static_cast <compiz::window::Object> (child));
60}62}
63
64void
65compiz::window::ReadServerConnection::receiveState (const AsynchronousObject::Ptr &ao,
66 uint64_t addState,
67 uint64_t removeState)
68{
69 ao->receiveState (addState, removeState);
70}
6171
=== modified file 'src/server-write.cpp'
--- src/server-write.cpp 2012-01-19 18:25:05 +0000
+++ src/server-write.cpp 2012-01-19 18:25:06 +0000
@@ -55,5 +55,23 @@
55 mServer->sendParent (id, pid);55 mServer->sendParent (id, pid);
56}56}
5757
5858void
59compiz::window::WriteServerConnection::sendCreateObject (const ObjectCreationRequest::Ptr &req)
60{
61 mServer->sendCreateObject (req);
62}
63
64void
65compiz::window::WriteServerConnection::sendDeleteObject (const ObjectIdentifier::Ptr &id)
66{
67 mServer->sendDeleteObject (id);
68}
69
70void
71compiz::window::WriteServerConnection::sendState (const ObjectIdentifier::Ptr &id,
72 uint64_t addState,
73 uint64_t removeState)
74{
75 mServer->sendState (id, addState, removeState);
76}
5977
6078
=== modified file 'src/server.cpp'
--- src/server.cpp 2012-01-19 18:25:05 +0000
+++ src/server.cpp 2012-01-19 18:25:06 +0000
@@ -40,8 +40,21 @@
40 return mDefault;40 return mDefault;
41}41}
4242
43void
44compiz::window::Server::SetDefault (Server::Ptr s)
45{
46 mDefault = s;
47}
48
43const compiz::window::Object::Ptr &49const compiz::window::Object::Ptr &
44compiz::window::Server::root ()50compiz::window::Server::root ()
45{51{
46 return mRoot;52 return mRoot;
47}53}
54
55void
56compiz::window::Server::setRoot (const compiz::window::Object::Ptr &root)
57{
58 assert (!mRoot);
59 mRoot = root;
60}
4861
=== added file 'src/x11-container.cpp'
--- src/x11-container.cpp 1970-01-01 00:00:00 +0000
+++ src/x11-container.cpp 2012-01-19 18:25:06 +0000
@@ -0,0 +1,48 @@
1/*
2 * Copyright © 2010 Canonical Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Canonical Ltd. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Canonical Ltd. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
24 */
25
26#include <core/container.h>
27#include <core/object.h>
28#include <core/x11-object.h>
29#include <boost/bind.hpp>
30#include <core/server-write.h>
31#include <core/windowgeometry.h>
32#include <core/stackposition.h>
33
34compiz::window::X11Container::X11Container (const ObjectIdentifier::Ptr &id,
35 const WriteServerConnection::Ptr &writer,
36 const compiz::window::Geometry &g,
37 const boost::shared_ptr <Container> &c) :
38 compiz::window::Object::Object (id, g, compiz::window::StackPosition (), c),
39 compiz::window::AsynchronousObject::AsynchronousObject (id, g, compiz::window::StackPosition (), c, writer),
40 compiz::window::AsynchronousContainer (id, g, compiz::window::StackPosition (), c, writer),
41 compiz::window::X11Object (id, writer, g, c)
42{
43}
44
45compiz::window::X11Container::~X11Container ()
46{
47}
48
049
=== added file 'src/x11-object.cpp'
--- src/x11-object.cpp 1970-01-01 00:00:00 +0000
+++ src/x11-object.cpp 2012-01-19 18:25:06 +0000
@@ -0,0 +1,84 @@
1/*
2 * Copyright © 2010 Canonical Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Canonical Ltd. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Canonical Ltd. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
24 */
25
26#include <core/x11-object.h>
27#include <core/x11-server.h>
28#include <core/server-write.h>
29#include <core/windowgeometry.h>
30#include <core/stackposition.h>
31#include <iostream>
32#include <cstdio>
33
34compiz::window::X11Object::X11Object (const ObjectIdentifier::Ptr &id,
35 const WriteServerConnection::Ptr &writer,
36 const compiz::window::Geometry &g,
37 const boost::shared_ptr <Container> &c) :
38 compiz::window::Object::Object (id, g, compiz::window::StackPosition (), c),
39 compiz::window::AsynchronousObject (id, g, compiz::window::StackPosition (), c, writer)
40{
41}
42
43compiz::window::X11Object::~X11Object ()
44{
45}
46
47compiz::window::X11ObjectIdentifier::X11ObjectIdentifier (Window id) :
48 compiz::window::ObjectIdentifier::ObjectIdentifier (),
49 mId (id)
50{
51}
52
53void
54compiz::window::X11ObjectIdentifier::print ()
55{
56 std::cout << "0x" << std::hex << mId;
57}
58
59compiz::window::X11ObjectIdentifier::~X11ObjectIdentifier ()
60{
61}
62
63compiz::window::ObjectIdentifier::ObjectType
64compiz::window::X11ObjectIdentifier::getType () const
65{
66 return X11;
67}
68
69bool
70compiz::window::X11ObjectIdentifier::compare (const ObjectIdentifier::Ptr &id) const
71{
72 const X11ObjectIdentifier::Ptr &xid = boost::shared_static_cast <X11ObjectIdentifier> (id);
73
74 return xid->mId == mId;
75}
76
77boost::shared_ptr <compiz::window::Object>
78compiz::window::X11ObjectIdentifier::lookup () const
79{
80 X11Server::Ptr server = boost::shared_static_cast <X11Server> (Server::Default ());
81 const boost::shared_ptr <const ObjectIdentifier> &ptr = boost::shared_static_cast <const ObjectIdentifier> (shared_from_this ());
82
83 return server->lookup (ptr);
84}
085
=== added file 'src/x11-server.cpp'
--- src/x11-server.cpp 1970-01-01 00:00:00 +0000
+++ src/x11-server.cpp 2012-01-19 18:25:06 +0000
@@ -0,0 +1,456 @@
1/*
2 * Copyright © 2010 Canonical Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Canonical Ltd. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Canonical Ltd. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
24 */
25
26#include <core/x11-server.h>
27#include <core/x11-object.h>
28#include <privateeventsource.h>
29#include <boost/bind.hpp>
30#include <sys/poll.h>
31
32compiz::window::X11ObjectCreationRequest::X11ObjectCreationRequest (XSetWindowAttributes &attr,
33 const compiz::window::Geometry &g,
34 unsigned int cclass,
35 unsigned int depth,
36 const compiz::window::X11ObjectIdentifier::Ptr &parent,
37 unsigned int attrValueMask,
38 Visual *vis) :
39 mAttr (attr),
40 mGeometry (g),
41 mClass (cclass),
42 mDepth (depth),
43 mParent (parent),
44 mAttrValueMask (attrValueMask),
45 mVis (vis)
46{
47}
48
49compiz::window::X11ObjectCreationRequest::~X11ObjectCreationRequest ()
50{
51}
52
53XSetWindowAttributes &
54compiz::window::X11ObjectCreationRequest::attributes () const
55{
56 return mAttr;
57}
58
59const compiz::window::Geometry &
60compiz::window::X11ObjectCreationRequest::geometry () const
61{
62 return mGeometry;
63}
64
65const unsigned int &
66compiz::window::X11ObjectCreationRequest::cclass () const
67{
68 return mClass;
69}
70
71const unsigned int &
72compiz::window::X11ObjectCreationRequest::depth () const
73{
74 return mDepth;
75}
76
77const compiz::window::X11ObjectIdentifier::Ptr &
78compiz::window::X11ObjectCreationRequest::parent () const
79{
80 return mParent;
81}
82
83const unsigned int &
84compiz::window::X11ObjectCreationRequest::attrValueMask () const
85{
86 return mAttrValueMask;
87}
88
89Visual *
90compiz::window::X11ObjectCreationRequest::visual () const
91{
92 return mVis;
93}
94
95compiz::window::X11Server::X11Server () :
96 compiz::window::AsynchronousServer::AsynchronousServer (),
97 mDisplay (XOpenDisplay (NULL))
98{
99 if (!mDisplay)
100 throw std::exception ();
101
102 setupEventSource ();
103}
104
105compiz::window::X11Server::X11Server (const char *dname) :
106 compiz::window::AsynchronousServer::AsynchronousServer (),
107 mDisplay (XOpenDisplay (dname))
108{
109 if (!mDisplay)
110 throw std::exception ();
111
112 setupEventSource ();
113}
114
115compiz::window::X11Server::X11Server (Display *dpy) :
116 compiz::window::AsynchronousServer::AsynchronousServer (),
117 mDisplay (dpy)
118{
119 setupEventSource ();
120}
121
122void
123compiz::window::X11Server::setupEventSource ()
124{
125 CompEventSource *ev = CompEventSource::create (mDisplay,
126 boost::bind (&X11Server::queueEvents, this));
127 Glib::RefPtr <Glib::Source> evrp = Glib::RefPtr <Glib::Source>::cast_static (Glib::RefPtr <CompEventSource> (ev));
128
129 setEventSource (evrp);
130}
131
132void
133compiz::window::X11Server::setRoot (Window root, const compiz::window::Geometry &g)
134{
135 compiz::window::X11ObjectIdentifier::Ptr rootId =
136 compiz::window::X11ObjectIdentifier::Ptr (new compiz::window::X11ObjectIdentifier (root));
137 const compiz::window::ObjectIdentifier::Ptr &genericRootId = boost::shared_static_cast <compiz::window::ObjectIdentifier> (rootId);
138 const compiz::window::Object::Ptr &rootObj = createObject (genericRootId, g, compiz::window::StackPosition (), compiz::window::Container::Ptr ());
139
140 Server::setRoot (rootObj);
141
142 XSetWindowAttributes xwa;
143
144 xwa.event_mask = StructureNotifyMask |
145 SubstructureNotifyMask |
146 SubstructureRedirectMask |
147 ButtonPressMask |
148 ButtonReleaseMask |
149 KeyPressMask |
150 KeyReleaseMask;
151
152 XChangeWindowAttributes (mDisplay, rootId->mId, CWEventMask, &xwa);
153 XSync (mDisplay, 0);
154}
155
156compiz::window::X11Server::~X11Server ()
157{
158 XCloseDisplay (mDisplay);
159}
160
161void
162compiz::window::populateXWindowChanges (const compiz::window::Geometry &g,
163 unsigned int mask,
164 XWindowChanges &xwc)
165{
166 if (mask & CWX)
167 xwc.x = g.x ();
168 if (mask & CWY)
169 xwc.y = g.y ();
170 if (mask & CWWidth)
171 xwc.width = g.width ();
172 if (mask & CWHeight)
173 xwc.height = g.height ();
174 if (mask & CWBorderWidth)
175 xwc.border_width = g.border ();
176}
177
178void
179compiz::window::populateXWindowChanges (const compiz::window::StackPosition &sp,
180 unsigned int mask,
181 XWindowChanges &xwc)
182{
183 if (mask & CWStackMode)
184 xwc.stack_mode = Above;
185 if (mask & CWSibling) {}
186 /* TODO:
187 xwc.sibling = sp */
188}
189
190void
191compiz::window::X11Server::sendGeometry (const ObjectIdentifier::Ptr &id,
192 const compiz::window::Geometry &g)
193{
194 Object::Ptr o = (*id) ();
195 unsigned int mask = g.changeMask (o->geometry ());
196 XWindowChanges xwc;
197
198 populateXWindowChanges (g, mask, xwc);
199
200 XConfigureWindow (mDisplay, (boost::static_pointer_cast<X11ObjectIdentifier> (id))->mId, mask, &xwc);
201}
202
203void
204compiz::window::X11Server::sendStackPosition (const ObjectIdentifier::Ptr &id,
205 const compiz::window::StackPosition &sp)
206{
207 XWindowChanges xwc;
208 unsigned int mask = CWStackMode | CWSibling;
209
210 populateXWindowChanges (sp, mask, xwc);
211
212 XConfigureWindow (mDisplay, (boost::static_pointer_cast<X11ObjectIdentifier> (id))->mId, mask, &xwc);
213}
214
215void
216compiz::window::X11Server::sendParent (const ObjectIdentifier::Ptr &child,
217 const ObjectIdentifier::Ptr &parent)
218{
219 Window xchild = (boost::static_pointer_cast<X11ObjectIdentifier> (child))->mId;
220 Window xparent = (boost::static_pointer_cast<X11ObjectIdentifier> (parent))->mId;
221
222 XReparentWindow (mDisplay, xchild, xparent, 0, 0);
223}
224
225void
226compiz::window::X11Server::sendCreateObject (const boost::shared_ptr <compiz::window::ObjectCreationRequest> &req)
227{
228 const compiz::window::X11ObjectCreationRequest::Ptr &xobjcreq =
229 boost::shared_static_cast <compiz::window::X11ObjectCreationRequest> (req);
230
231 XCreateWindow (mDisplay, xobjcreq->parent ()->mId, xobjcreq->geometry ().x (),
232 xobjcreq->geometry ().y (), xobjcreq->geometry ().width (),
233 xobjcreq->geometry ().height (), xobjcreq->geometry ().border (),
234 xobjcreq->depth (),
235 xobjcreq->cclass (),
236 xobjcreq->visual (),
237 xobjcreq->attrValueMask (),
238 &xobjcreq->attributes ());
239}
240
241void
242compiz::window::X11Server::sendDeleteObject (const ObjectIdentifier::Ptr &id)
243{
244 const compiz::window::X11ObjectIdentifier::Ptr xid =
245 boost::shared_static_cast <compiz::window::X11ObjectIdentifier> (id);
246
247 XDestroyWindow (mDisplay, xid->mId);
248}
249
250void
251compiz::window::X11Server::sendState (const ObjectIdentifier::Ptr &id,
252 uint64_t addState,
253 uint64_t removeState)
254{
255 const compiz::window::X11ObjectIdentifier::Ptr xid =
256 boost::shared_static_cast <compiz::window::X11ObjectIdentifier> (id);
257
258 /* If something is being added and removed
259 * then clear both operations */
260 addState &= ~removeState;
261 removeState &= ~addState;
262
263 if (addState & compiz::window::Object::StateMapped)
264 XMapWindow (mDisplay, xid->mId);
265 else if (removeState & compiz::window::Object::StateMapped)
266 XUnmapWindow (mDisplay, xid->mId);
267
268 return;
269}
270
271void
272compiz::window::X11Server::dispatchRequests (unsigned int flags)
273{
274 if (flags & compiz::window::AsynchronousServer::BlockUntilCompletion)
275 XSync (mDisplay, flags & compiz::window::AsynchronousServer::DiscardGeneratedEvents ? true : false);
276 else
277 XFlush (mDisplay);
278}
279
280compiz::window::Object::Ptr compiz::window::X11Server::lookup (const boost::shared_ptr <const ObjectIdentifier> &id) const
281{
282 const X11ObjectIdentifier::ConstPtr &xid = boost::shared_static_cast <const X11ObjectIdentifier> (id);
283
284 const boost::unordered_map <Window, X11Object::Ptr>::const_iterator &it = mObjectTree.find (xid->mId);
285
286 if (it != mObjectTree.end ())
287 return mObjectTree.at (xid->mId);
288
289 return compiz::window::Object::Ptr ();
290}
291
292void
293compiz::window::X11Server::dispatchEvent (XEvent *event)
294{
295 /* FIXME: We're using boost::shared_polymorphic_cast here because
296 * Object is virtually inherited by AsynchronousObject and AsynchronousContainer
297 * as well as X11Object. Since there is no way that the compiler can know
298 * what the offset of X11Object is going to be here, we need to use a runtime
299 * cast */
300 switch (event->type)
301 {
302 case ConfigureNotify:
303 {
304 compiz::window::X11ObjectIdentifier::Ptr id =
305 compiz::window::X11ObjectIdentifier::Ptr (
306 new compiz::window::X11ObjectIdentifier (event->xconfigure.window));
307
308 const compiz::window::X11Object::Ptr &xo = boost::shared_polymorphic_cast <compiz::window::X11Object> ((*id) ());
309 compiz::window::Geometry g (event->xconfigure.x,
310 event->xconfigure.y,
311 event->xconfigure.width,
312 event->xconfigure.height,
313 event->xconfigure.border_width);
314 compiz::window::StackPosition sp;
315
316 mReadConnection->receiveGeometry (xo, g);
317 mReadConnection->receiveStackPosition (xo, sp);
318 }
319 break;
320 case ReparentNotify:
321 {
322 compiz::window::X11ObjectIdentifier::Ptr childId =
323 compiz::window::X11ObjectIdentifier::Ptr (
324 new compiz::window::X11ObjectIdentifier (event->xreparent.window));
325 compiz::window::X11ObjectIdentifier::Ptr parentId =
326 compiz::window::X11ObjectIdentifier::Ptr (
327 new compiz::window::X11ObjectIdentifier (event->xreparent.parent));
328
329 compiz::window::X11Object::Ptr child = boost::shared_polymorphic_cast <compiz::window::X11Object> ((*childId) ());
330 compiz::window::X11Container::Ptr parent = boost::shared_polymorphic_cast <compiz::window::X11Container> ((*parentId) ());
331
332 mReadConnection->receiveParent (child, parent);
333 }
334 break;
335 case CreateNotify:
336 {
337 compiz::window::X11ObjectIdentifier::Ptr childId =
338 compiz::window::X11ObjectIdentifier::Ptr (
339 new compiz::window::X11ObjectIdentifier (event->xcreatewindow.window));
340 compiz::window::X11ObjectIdentifier::Ptr parentId =
341 compiz::window::X11ObjectIdentifier::Ptr (
342 new compiz::window::X11ObjectIdentifier (event->xcreatewindow.parent));
343
344 /* Need to create the child first */
345 compiz::window::X11Container::Ptr parent = boost::shared_polymorphic_cast <compiz::window::X11Container> ((*parentId) ());
346 compiz::window::X11Object::Ptr child =
347 boost::shared_polymorphic_cast <compiz::window::X11Object> (createObject (boost::shared_static_cast <compiz::window::ObjectIdentifier> (childId),
348 compiz::window::Geometry (event->xcreatewindow.x,
349 event->xcreatewindow.y,
350 event->xcreatewindow.width,
351 event->xcreatewindow.height,
352 event->xcreatewindow.border_width),
353 compiz::window::StackPosition (),
354 parent));
355
356 mReadConnection->receiveParent (child, parent);
357 }
358 break;
359 case DestroyNotify:
360 {
361 compiz::window::X11ObjectIdentifier::Ptr windowId =
362 compiz::window::X11ObjectIdentifier::Ptr (
363 new compiz::window::X11ObjectIdentifier (event->xdestroywindow.window));
364 compiz::window::X11Object::Ptr window = boost::shared_polymorphic_cast <compiz::window::X11Object> ((*windowId) ());
365 compiz::window::X11Container::Ptr newParent = compiz::window::X11Container::Ptr ();
366
367 mReadConnection->receiveParent (window, newParent);
368 }
369 break;
370 case MapNotify:
371 {
372 compiz::window::X11ObjectIdentifier::Ptr windowId =
373 compiz::window::X11ObjectIdentifier::Ptr (
374 new compiz::window::X11ObjectIdentifier (event->xdestroywindow.window));
375 compiz::window::X11Object::Ptr window = boost::shared_polymorphic_cast <compiz::window::X11Object> ((*windowId) ());
376
377 mReadConnection->receiveState (window, compiz::window::Object::StateMapped, 0);
378 }
379 break;
380 case UnmapNotify:
381 {
382 compiz::window::X11ObjectIdentifier::Ptr windowId =
383 compiz::window::X11ObjectIdentifier::Ptr (
384 new compiz::window::X11ObjectIdentifier (event->xdestroywindow.window));
385 compiz::window::X11Object::Ptr window = boost::shared_polymorphic_cast <compiz::window::X11Object> ((*windowId) ());
386
387 mReadConnection->receiveState (window, 0, compiz::window::Object::StateMapped);
388 }
389 break;
390 default:
391 break;
392
393 }
394}
395
396void
397compiz::window::X11Server::queueEvents ()
398{
399 std::vector <XEvent> events;
400
401 while (XPending (mDisplay))
402 {
403 XEvent event, peekEvent;
404 XNextEvent (mDisplay, &event);
405
406 /* Skip to the last MotionNotify
407 * event in this sequence */
408 if (event.type == MotionNotify)
409 {
410 while (XPending (mDisplay))
411 {
412 XPeekEvent (mDisplay, &peekEvent);
413
414 if (peekEvent.type != MotionNotify)
415 break;
416
417 XNextEvent (mDisplay, &event);
418 }
419 }
420
421 events.push_back (event);
422 }
423
424 for (std::vector <XEvent>::iterator it = events.begin ();
425 it != events.end ();
426 it++)
427 dispatchEvent (&(*it));
428}
429
430void
431compiz::window::X11Server::addObjectToTree (const std::pair <compiz::window::X11ObjectIdentifier::Ptr,
432 compiz::window::X11Object::Ptr> &keyValue)
433{
434 if (mObjectTree.find (keyValue.first->mId) != mObjectTree.end ())
435 throw std::exception ();
436
437 XSetWindowAttributes xwa;
438
439 xwa.event_mask = SubstructureNotifyMask |
440 ButtonPressMask |
441 ButtonReleaseMask |
442 KeyPressMask |
443 KeyReleaseMask;
444
445 XSynchronize (mDisplay, true);
446 XChangeWindowAttributes (mDisplay, keyValue.first->mId, CWEventMask, &xwa);
447
448 mObjectTree[keyValue.first->mId] = keyValue.second;
449}
450
451void
452compiz::window::X11Server::removeKeyFromTree (const ObjectIdentifier::Ptr &id)
453{
454 const compiz::window::X11ObjectIdentifier::Ptr &xid = boost::shared_static_cast <compiz::window::X11ObjectIdentifier> (id);
455 mObjectTree.erase (xid->mId);
456}
0457
=== added directory 'tests/standalone'
=== added file 'tests/standalone/CMakeLists.txt'
--- tests/standalone/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/standalone/CMakeLists.txt 2012-01-19 18:25:06 +0000
@@ -0,0 +1,1 @@
1add_subdirectory (objects)
02
=== added directory 'tests/standalone/objects'
=== added file 'tests/standalone/objects/CMakeLists.txt'
--- tests/standalone/objects/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/standalone/objects/CMakeLists.txt 2012-01-19 18:25:06 +0000
@@ -0,0 +1,23 @@
1find_package (Boost REQUIRED)
2
3pkg_check_modules (COMPIZ_OBJECTS_STANDALONE_TEST glibmm-2.4 x11)
4
5if (COMPIZ_OBJECTS_STANDALONE_TEST_FOUND)
6
7 set (COMPIZ_OBJECTS_STANDALONE_TEST_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
8 set (COMPIZ_OBJECTS_STANDALONE_TEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
9
10 include_directories (${COMPIZ_OBJECTS_STANDALONE_TEST_INCLUDE_DIRS}
11 ${CMAKE_CURRENT_SOURCE_DIR}
12 ${compiz_SOURCE_DIR}/src
13 ${compiz_SOURCE_DIR}/include
14 ${Boost_INCLUDE_DIRS})
15 link_directories (${COMPIZ_OBJECT_STANDALONE_TEST_LINK_DIRS}
16 ${Boost_LINK_DIRS})
17 add_library (commandparser STATIC ${CMAKE_CURRENT_SOURCE_DIR}/command-parser.cpp)
18
19 target_link_libraries (commandparser ${COMPIZ_OBJECTS_STANDALONE_TEST_LIBRARIES} ${Boost_LIBRARIES})
20
21 add_subdirectory (x11)
22
23endif (COMPIZ_OBJECTS_STANDALONE_TEST_FOUND)
024
=== added file 'tests/standalone/objects/command-parser.cpp'
--- tests/standalone/objects/command-parser.cpp 1970-01-01 00:00:00 +0000
+++ tests/standalone/objects/command-parser.cpp 2012-01-19 18:25:06 +0000
@@ -0,0 +1,449 @@
1/*
2 * Copyright © 2010 Canonical Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Canonical Ltd. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Canonical Ltd. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
24 */
25
26#include <command-parser.h>
27
28Glib::RefPtr <StdinSource>
29StdinSource::create (const Glib::RefPtr <Glib::MainLoop> &ml)
30{
31 return Glib::RefPtr <StdinSource> (new StdinSource (ml));
32}
33
34StdinSource::StdinSource (const Glib::RefPtr <Glib::MainLoop> &ml) :
35 Glib::IOSource (STDIN_FILENO, Glib::IO_IN | Glib::IO_HUP),
36 mMainLoop (ml)
37{
38 connect (sigc::mem_fun <Glib::IOCondition, bool, StdinSource> (this, &StdinSource::callback));
39 attach (Glib::MainContext::get_default ());
40}
41
42Parser::Parser (const std::string &token, std::string::const_iterator begin, std::string::const_iterator end) :
43 mBegin (begin),
44 mEnd (end),
45 mAdvanceLength (token.size ())
46{
47}
48
49Parser::Parser (unsigned int n, std::string::const_iterator begin, std::string::const_iterator end) :
50 mBegin (begin),
51 mEnd (end),
52 mAdvanceLength (n)
53{
54}
55
56Parser::~Parser ()
57{
58}
59
60void
61Parser::advance ()
62{
63 std::advance (mBegin, mAdvanceLength);
64}
65
66void
67Parser::advance (unsigned int n)
68{
69 std::advance (mBegin, n);
70}
71
72void
73Parser::parse (boost::spirit::unused_type r, boost::spirit::unused_type, bool &)
74{
75 r = parseStringIterators (mBegin, mEnd);
76}
77
78GeometryParser::GeometryParser (std::string::const_iterator begin, std::string::const_iterator end, const compiz::window::Geometry &old) :
79 Parser ("geometry", begin, end),
80 mGeometry (old)
81{
82}
83
84GeometryParser::~GeometryParser ()
85{
86}
87
88bool
89GeometryParser::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end)
90{
91 advance ();
92 int x, y;
93 unsigned int width, height, border;
94
95 using boost::spirit::qi::uint_;
96 using boost::spirit::qi::int_;
97 using boost::spirit::qi::_1;
98 using boost::spirit::qi::phrase_parse;
99 using boost::spirit::ascii::space;
100 using boost::phoenix::ref;
101
102 advance (1);
103 if (boost::spirit::qi::parse (mBegin, mEnd,
104 '(' >> int_[ref (x) = _1] >> ", " >>
105 int_[ref (y) = _1] >> ", " >>
106 uint_[ref (width) = _1] >> ", " >>
107 uint_[ref (height) = _1] >> ", " >>
108 uint_[ref (border) = _1] >> ')'))
109 {
110 mGeometry.set (x, y, width, height, border);
111 return true;
112 }
113
114 std::cout << "geometry (" << mGeometry.x () << ", "
115 << mGeometry.y () << ", "
116 << mGeometry.width () << ", "
117 << mGeometry.height () << ", "
118 << mGeometry.border () << ")" << std::endl;
119 return false;
120}
121
122ObjectsParser::ObjectsParser (std::string::const_iterator begin, std::string::const_iterator end, const compiz::window::Container::Children &old) :
123 Parser ("objects", begin, end),
124 mChildren (old)
125{
126}
127
128ObjectsParser::~ObjectsParser ()
129{
130}
131
132bool
133ObjectsParser::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end)
134{
135 advance ();
136 std::vector <unsigned int> v (0);
137
138 using boost::spirit::qi::hex;
139 using boost::spirit::qi::_1;
140 using boost::spirit::qi::phrase_parse;
141 using boost::spirit::ascii::space;
142 using boost::phoenix::ref;
143 using boost::phoenix::push_back;
144
145 advance (1);
146 if (boost::spirit::qi::parse (mBegin, mEnd,
147 "(0x" >> hex[push_back (ref (v), _1)]
148 >> *(",0x" >> hex[push_back (ref (v), _1)]) >> ")"
149 ))
150 {
151 mChildren.clear ();
152 for (std::vector <unsigned int>::iterator it = v.begin ();
153 it != v.end ();
154 it++)
155 {
156 compiz::window::X11ObjectIdentifier::Ptr xid = compiz::window::X11ObjectIdentifier::Ptr (new compiz::window::X11ObjectIdentifier ((*it)));
157 const compiz::window::Object::Ptr &obj = (*xid) ();
158 mChildren.push_back (obj);
159 }
160 return true;
161 }
162
163 std::cout << "objects -" << std::endl;
164 for (compiz::window::Container::Children::iterator it = mChildren.begin ();
165 it != mChildren.end ();
166 it++)
167 {
168 compiz::window::Object::Ptr obj = (*it);
169 const compiz::window::ObjectIdentifier::Ptr &id = obj->id ();
170 const compiz::window::X11ObjectIdentifier::Ptr xid = boost::shared_static_cast <compiz::window::X11ObjectIdentifier> (id);
171
172 std::cout << " - id: ";
173 xid->print ();
174 std::cout << std::endl;
175 }
176
177 mChildren.clear ();
178
179 return false;
180}
181
182CreateParser::CreateParser (std::string::const_iterator begin, std::string::const_iterator end) :
183 Parser ("create", begin, end)
184{
185}
186
187CreateParser::~CreateParser ()
188{
189}
190
191bool
192CreateParser::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end)
193{
194 advance ();
195 bool input;
196 bool override = false;
197 unsigned int parent;
198 int x, y;
199 unsigned int width, height, border;
200
201 using boost::spirit::qi::hex;
202 using boost::spirit::qi::uint_;
203 using boost::spirit::qi::int_;
204 using boost::spirit::qi::bool_;
205 using boost::spirit::qi::_1;
206 using boost::spirit::qi::phrase_parse;
207 using boost::spirit::ascii::space;
208 using boost::phoenix::ref;
209 using boost::phoenix::push_back;
210
211 advance (1);
212 if (boost::spirit::qi::parse (mBegin, mEnd,
213 "(0x" >> hex[ref (parent) = _1]
214 >> ", (" >> int_[ref (x) = _1] >> ", " >>
215 int_[ref (y) = _1] >> ", " >>
216 uint_[ref (width) = _1] >> ", " >>
217 uint_[ref (height) = _1] >> ", " >>
218 uint_[ref (border) = _1] >> "), " >>
219 bool_[ref (input) = _1] >> ", " >>
220 bool_[ref (override) = _1] >> ")"))
221 {
222 XSetWindowAttributes childAttr;
223 unsigned int mask = 0;
224 compiz::window::X11ObjectIdentifier::Ptr parentId = compiz::window::X11ObjectIdentifier::Ptr (new compiz::window::X11ObjectIdentifier (parent));
225
226 if (override)
227 {
228 childAttr.override_redirect = 1;
229 mask |= CWOverrideRedirect;
230 }
231
232
233 mXcreq = compiz::window::X11ObjectCreationRequest::Ptr (new compiz::window::X11ObjectCreationRequest (childAttr, compiz::window::Geometry (x, y, width, height, border),
234 input ? InputOnly : InputOutput, CopyFromParent,
235 parentId,
236 mask, CopyFromParent));
237
238 return true;
239 }
240 else
241 std::cout << "USAGE: create (parentId, (x,y,width,height,border), input_only, override)" << std::endl;
242
243
244 return false;
245}
246
247StackPositionParser::StackPositionParser (std::string::const_iterator begin, std::string::const_iterator end, const compiz::window::StackPosition &old) :
248 Parser ("stackposition", begin, end),
249 mStackPosition (old)
250{
251}
252
253StackPositionParser::~StackPositionParser ()
254{
255}
256
257bool
258StackPositionParser::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end)
259{
260 return false;
261}
262
263PropertyParser::PropertyParser (std::string::const_iterator begin, std::string::const_iterator end, uint64_t old) :
264 Parser ("property", begin, end),
265 mProperties (old)
266{
267}
268
269PropertyParser::~PropertyParser ()
270{
271}
272
273bool
274PropertyParser::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end)
275{
276 return false;
277}
278
279XidParser::XidParser (std::string::const_iterator begin, std::string::const_iterator end) :
280 Parser (2, begin, end)
281{
282}
283
284XidParser::~XidParser ()
285{
286}
287
288bool
289XidParser::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end)
290{
291 advance ();
292 using boost::spirit::qi::hex;
293 using boost::spirit::qi::_1;
294 using boost::spirit::qi::phrase_parse;
295 using boost::spirit::ascii::space;
296 using boost::phoenix::ref;
297 unsigned int uxid = 0;
298
299 if (boost::spirit::qi::parse (mBegin, mEnd, hex[ref(uxid) = _1], space))
300 {
301 compiz::window::X11ObjectIdentifier::Ptr xid = compiz::window::X11ObjectIdentifier::Ptr (new compiz::window::X11ObjectIdentifier (uxid));
302 compiz::window::Object::Ptr o = (*xid) ();
303 const compiz::window::X11Container::Ptr &xc = boost::shared_dynamic_cast <compiz::window::X11Container> (o);
304 if (!o)
305 return false;
306 else
307 {
308 std::advance (mBegin, 1);
309 GeometryParser gp (mBegin, mEnd, o->geometry ());
310 StackPositionParser sp (mBegin, mEnd, o->stackPosition ());
311 PropertyParser pp (mBegin, mEnd, o->state ());
312 ObjectsParser op (mBegin, mEnd, xc ? xc->children () : compiz::window::Container::Children (0));
313 if (boost::spirit::qi::parse (mBegin, mEnd,
314 boost::spirit::qi::lit ("geometry")[boost::bind (&GeometryParser::parse, &gp, _1, _2, _3)]))
315 {
316 /* Send new geometry */
317 const compiz::window::X11Server::Ptr &serverp = boost::shared_static_cast <compiz::window::X11Server> (compiz::window::Server::Default ());
318 compiz::window::WriteServerConnection::Ptr conn = serverp->connect ();
319 conn->sendGeometry (o->id (), gp.geometry ());
320 serverp->flush (0);
321 return true;
322 }
323 else if (boost::spirit::qi::parse (mBegin, mEnd,
324 boost::spirit::qi::lit ("stackposition")[boost::bind (&StackPositionParser::parse, &sp, _1, _2, _3)]))
325 {
326 return true;
327 }
328 else if (boost::spirit::qi::parse (mBegin, mEnd,
329 boost::spirit::qi::lit ("properties")[boost::bind (&PropertyParser::parse, &pp, 1, _2, _3)]))
330 {
331 return true;
332 }
333 else if (boost::spirit::qi::parse (mBegin, mEnd,
334 boost::spirit::qi::lit ("objects")[boost::bind (&ObjectsParser::parse, &op, 1, _2, _3)]))
335 {
336 /* Send removal of any children from parents and send insertion
337 * to this parent */
338 if (xc)
339 {
340 for (compiz::window::Container::Children::const_iterator it = op.children ().begin ();
341 it != op.children ().end ();
342 it++)
343 {
344 const compiz::window::Object::Ptr &oc = (*it);
345 const compiz::window::Container::Ptr &pc = oc->container ();
346 const compiz::window::AsynchronousContainer::Ptr &apc = boost::shared_dynamic_cast <compiz::window::AsynchronousContainer> (pc);
347
348 if (apc)
349 {
350 apc->sendRemoval (oc);
351 xc->sendInsertion (oc);
352 }
353 }
354 }
355 return true;
356 }
357 else
358 return false;
359 }
360 }
361
362 return false;
363}
364
365ListMatcher::ListMatcher (std::string::const_iterator begin, std::string::const_iterator end) :
366 Parser::Parser ("list", begin, end)
367{
368}
369
370ListMatcher::~ListMatcher ()
371{
372}
373
374bool
375ListMatcher::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end)
376{
377 /* on "list" just print out the toplevel trees
378 * like the root object id */
379
380 const compiz::window::X11Object::Ptr &rt = boost::shared_polymorphic_cast <compiz::window::X11Object> (compiz::window::Server::Default ()->root ());
381 const compiz::window::ObjectIdentifier::Ptr &id = rt->id ();
382 const compiz::window::X11ObjectIdentifier::Ptr &xid = boost::shared_static_cast <compiz::window::X11ObjectIdentifier> (id);
383
384 std::cout << "Root Object: ";
385 xid->print ();
386 std::cout << std::endl;
387 return false;
388}
389
390ObjectMatcher::ObjectMatcher (std::string::const_iterator begin, std::string::const_iterator end) :
391 Parser::Parser ("object", begin, end)
392{
393}
394
395ObjectMatcher::~ObjectMatcher ()
396{
397}
398
399bool
400ObjectMatcher::parseStringIterators (std::string::const_iterator begin, std::string::const_iterator end)
401{
402 advance ();
403 advance (1);
404 XidParser xp (mBegin, mEnd);
405
406 return boost::spirit::qi::parse (mBegin, mEnd,
407 boost::spirit::qi::lit ("0x") [boost::bind (&XidParser::parse, &xp, _1, _2, _3)]);
408}
409
410bool
411StdinSource::callback (Glib::IOCondition cond)
412{
413 if (cond & Glib::IO_IN)
414 {
415 std::string str;
416 std::getline (std::cin, str);
417 std::string::const_iterator b = str.begin ();
418 std::string::const_iterator e = str.end ();
419 ObjectMatcher op (b, e);
420 ListMatcher lp (b, e);
421 CreateParser cp (b, e);
422 if (boost::spirit::qi::parse (b, e, boost::spirit::qi::lit ("object")[boost::bind (&ObjectMatcher::parse, &op, _1, _2, _3)]))
423 {
424 }
425 else if (boost::spirit::qi::parse (b, e, boost::spirit::qi::lit ("list")[boost::bind (&ListMatcher::parse, &lp, _1, _2, _3)]))
426 {
427 }
428 else if (boost::spirit::qi::parse (b, e, boost::spirit::qi::lit ("create")[boost::bind (&CreateParser::parse, &cp, _1, _2, _3)]))
429 {
430 compiz::window::WriteServerConnection::Ptr w = boost::shared_static_cast <compiz::window::AsynchronousServer> (compiz::window::Server::Default ())->connect ();
431
432 if (cp.xcreq ())
433 w->sendCreateObject (cp.xcreq ());
434 }
435 else if (boost::spirit::qi::parse (b, e, boost::spirit::qi::lit ("quit")))
436 {
437 mMainLoop->quit ();
438 return false;
439 }
440
441 std::cout << ">> ";
442 }
443
444 return true;
445}
446
447StdinSource::~StdinSource ()
448{
449}
0450
=== added file 'tests/standalone/objects/command-parser.h'
--- tests/standalone/objects/command-parser.h 1970-01-01 00:00:00 +0000
+++ tests/standalone/objects/command-parser.h 2012-01-19 18:25:06 +0000
@@ -0,0 +1,190 @@
1/*
2 * Copyright © 2010 Canonical Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Canonical Ltd. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Canonical Ltd. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
24 */
25
26#include <core/x11-server.h>
27#include <core/x11-object.h>
28#include <X11/Xlib.h>
29#include <boost/shared_ptr.hpp>
30#include <cairo/cairo.h>
31#include <cairo/cairo-xlib.h>
32#include <core/object.h>
33#include <core/container.h>
34#include <core/server-write.h>
35#include <sys/poll.h>
36#include <boost/spirit/include/qi.hpp>
37#include <boost/spirit/include/phoenix_core.hpp>
38#include <boost/spirit/include/phoenix_operator.hpp>
39#include <boost/spirit/include/phoenix_object.hpp>
40#include <boost/spirit/include/phoenix_stl.hpp>
41#include <boost/fusion/include/adapt_struct.hpp>
42#include <boost/fusion/include/io.hpp>
43#include <boost/spirit/include/qi_uint.hpp>
44
45#include <boost/bind.hpp>
46
47class StdinSource :
48 public Glib::IOSource
49{
50 public:
51
52 static Glib::RefPtr <StdinSource> create (const Glib::RefPtr <Glib::MainLoop> &ml);
53 ~StdinSource ();
54
55 private:
56
57 bool callback (Glib::IOCondition);
58
59 StdinSource (const Glib::RefPtr <Glib::MainLoop> &ml);
60 Glib::RefPtr <Glib::MainLoop> mMainLoop;
61};
62
63class Parser
64{
65 public:
66 virtual ~Parser ();
67 void parse (boost::spirit::unused_type, boost::spirit::unused_type, bool &);
68 protected:
69 virtual bool parseStringIterators (std::string::const_iterator begin,
70 std::string::const_iterator end) = 0;
71
72 Parser (const std::string &token, std::string::const_iterator begin, std::string::const_iterator end);
73 Parser (unsigned int, std::string::const_iterator begin, std::string::const_iterator end);
74
75 void advance ();
76 void advance (unsigned int);
77
78 mutable std::string::const_iterator mBegin;
79 mutable std::string::const_iterator mEnd;
80 private:
81 unsigned int mAdvanceLength;
82};
83
84class ObjectMatcher :
85 public Parser
86{
87 public:
88 ObjectMatcher (std::string::const_iterator begin, std::string::const_iterator end);
89 ~ObjectMatcher ();
90 protected:
91 bool parseStringIterators (std::string::const_iterator begin,
92 std::string::const_iterator end);
93
94 private:
95
96 mutable compiz::window::Object::Ptr mObj;
97};
98
99class ListMatcher :
100 public Parser
101{
102 public:
103 ListMatcher (std::string::const_iterator begin, std::string::const_iterator end);
104 ~ListMatcher ();
105 protected:
106 bool parseStringIterators (std::string::const_iterator begin,
107 std::string::const_iterator end);
108};
109
110class XidParser :
111 public Parser
112{
113 public:
114 XidParser (std::string::const_iterator begin, std::string::const_iterator end);
115 ~XidParser ();
116 protected:
117 bool parseStringIterators (std::string::const_iterator begin,
118 std::string::const_iterator end);
119 private:
120 mutable compiz::window::X11ObjectIdentifier::Ptr mXid;
121};
122
123class GeometryParser :
124 public Parser
125{
126 public:
127 GeometryParser (std::string::const_iterator begin, std::string::const_iterator end, const compiz::window::Geometry &old);
128 ~GeometryParser ();
129 const compiz::window::Geometry & geometry () { return mGeometry; };
130 protected:
131 bool parseStringIterators (std::string::const_iterator begin,
132 std::string::const_iterator end);
133 private:
134 compiz::window::Geometry mGeometry;
135};
136
137class ObjectsParser :
138 public Parser
139{
140 public:
141 ObjectsParser (std::string::const_iterator begin, std::string::const_iterator end, const compiz::window::Container::Children &old);
142 ~ObjectsParser ();
143 const compiz::window::Container::Children & children () { return mChildren; };
144 protected:
145 bool parseStringIterators (std::string::const_iterator begin,
146 std::string::const_iterator end);
147 private:
148 compiz::window::Container::Children mChildren;
149};
150
151class CreateParser :
152 public Parser
153{
154 public:
155 CreateParser (std::string::const_iterator begin, std::string::const_iterator end);
156 ~CreateParser ();
157 const compiz::window::X11ObjectCreationRequest::Ptr & xcreq () { return mXcreq; }
158 protected:
159 bool parseStringIterators (std::string::const_iterator begin,
160 std::string::const_iterator end);
161 private:
162 compiz::window::X11ObjectCreationRequest::Ptr mXcreq;
163};
164
165class StackPositionParser :
166 public Parser
167{
168 public:
169 StackPositionParser (std::string::const_iterator begin, std::string::const_iterator end, const compiz::window::StackPosition &old);
170 ~StackPositionParser ();
171 protected:
172 bool parseStringIterators (std::string::const_iterator begin,
173 std::string::const_iterator end);
174 private:
175 mutable compiz::window::StackPosition mStackPosition;
176};
177
178class PropertyParser :
179 public Parser
180{
181 public:
182 PropertyParser (std::string::const_iterator begin, std::string::const_iterator end, uint64_t old);
183 ~PropertyParser ();
184 protected:
185 bool parseStringIterators (std::string::const_iterator begin,
186 std::string::const_iterator end);
187 private:
188 mutable uint64_t mProperties;
189};
190
0191
=== added directory 'tests/standalone/objects/mockwire'
=== added directory 'tests/standalone/objects/x11'
=== added file 'tests/standalone/objects/x11/CMakeLists.txt'
--- tests/standalone/objects/x11/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/standalone/objects/x11/CMakeLists.txt 2012-01-19 18:25:06 +0000
@@ -0,0 +1,43 @@
1pkg_check_modules (X11_OBJECT_TREE_STANDALONE REQUIRED x11 glibmm-2.4 cairo cairo-xlib)
2
3if (X11_OBJECT_TREE_STANDALONE_FOUND)
4
5 include_directories (${X11_OBJECT_TREE_STANDALONE_INCLUDE_DIRS}
6 ${COMPIZ_OBJECTS_STANDALONE_TEST_BASE_DIR}
7 ${compiz_SOURCE_DIR}/src/
8 ${compiz_SOURCE_DIR}/include/
9 # Module specific include dirs
10
11 ${compiz_SOURCE_DIR}/src/timer/include
12 ${compiz_SOURCE_DIR}/src/timer/src)
13
14 link_directories (${X11_OBJECT_TREE_STANDALONE_LIBRARY_DIRS}
15 ${COMPIZ_OBJECTS_STANDALONE_TEST_BINARY_DIR})
16
17 add_executable (compiz-x11-object-tree-standalone
18 compiz-x11-object-tree-standalone.cpp
19 ${compiz_SOURCE_DIR}/src/x11-server.cpp
20 ${compiz_SOURCE_DIR}/src/asynchronous-server.cpp
21 ${compiz_SOURCE_DIR}/src/server.cpp
22 ${compiz_SOURCE_DIR}/src/server-read.cpp
23 ${compiz_SOURCE_DIR}/src/server-write.cpp
24 ${compiz_SOURCE_DIR}/src/object.cpp
25 ${compiz_SOURCE_DIR}/src/container.cpp
26 ${compiz_SOURCE_DIR}/src/asynchronous-object.cpp
27 ${compiz_SOURCE_DIR}/src/asynchronous-container.cpp
28 ${compiz_SOURCE_DIR}/src/x11-object.cpp
29 ${compiz_SOURCE_DIR}/src/x11-container.cpp
30 ${compiz_SOURCE_DIR}/src/windowgeometry.cpp
31 ${compiz_SOURCE_DIR}/src/stackposition.cpp
32 ${compiz_SOURCE_DIR}/src/stack.cpp
33 ${compiz_SOURCE_DIR}/src/asynchronous-stack.cpp
34 ${compiz_SOURCE_DIR}/src/rect.cpp
35 ${compiz_SOURCE_DIR}/src/eventsource.cpp
36 ${compiz_SOURCE_DIR}/src/point.cpp
37 ${compiz_SOURCE_DIR}/src/managedstatebit.cpp)
38
39 target_link_libraries (compiz-x11-object-tree-standalone
40 commandparser
41 ${X11_OBJECT_TREE_STANDALONE_LIBRARIES})
42
43endif (X11_OBJECT_TREE_STANDALONE_FOUND)
044
=== added file 'tests/standalone/objects/x11/compiz-x11-object-tree-standalone.cpp'
--- tests/standalone/objects/x11/compiz-x11-object-tree-standalone.cpp 1970-01-01 00:00:00 +0000
+++ tests/standalone/objects/x11/compiz-x11-object-tree-standalone.cpp 2012-01-19 18:25:06 +0000
@@ -0,0 +1,338 @@
1/*
2 * Copyright © 2010 Canonical Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Canonical Ltd. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Canonical Ltd. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
24 */
25
26#include <core/x11-server.h>
27#include <core/x11-object.h>
28#include <X11/Xlib.h>
29#include <boost/shared_ptr.hpp>
30#include <cairo/cairo.h>
31#include <cairo/cairo-xlib.h>
32#include <core/object.h>
33#include <core/container.h>
34#include <core/server-write.h>
35#include <command-parser.h>
36
37#include <boost/bind.hpp>
38
39class MockX11Server :
40 public compiz::window::X11Server
41{
42 public:
43
44 typedef boost::shared_ptr <MockX11Server> Ptr;
45
46 void setRoot (Window root, const compiz::window::Geometry &);
47
48 compiz::window::Object::Ptr
49 createObject (const compiz::window::ObjectIdentifier::Ptr &id,
50 const compiz::window::Geometry &g,
51 const compiz::window::StackPosition &sp,
52 const compiz::window::Container::Ptr &c);
53
54 void
55 removeObject (const compiz::window::ObjectIdentifier::Ptr &id);
56
57 MockX11Server (Display *, Glib::RefPtr <Glib::MainLoop> &ml);
58 ~MockX11Server ();
59};
60
61class MockX11Object :
62 public compiz::window::X11Container
63{
64 public:
65
66 typedef boost::shared_ptr <MockX11Object> Ptr;
67
68 virtual ~MockX11Object ();
69
70 protected:
71
72 void onReceiveGeometry (const compiz::window::Geometry &g);
73 void onReceiveStackPosition (const compiz::window::StackPosition &sp);
74 void onReceiveInsertion (const compiz::window::Object::Ptr &o);
75 void onReceiveRemoval (const compiz::window::Object::Ptr &o);
76 void onReceiveDeletion ();
77 void onReceiveAddState (uint64_t state);
78 void onReceiveRemoveState (uint64_t state);
79
80 void onSendGeometry (const compiz::window::Geometry &g);
81 void onSendStackPosition (const compiz::window::StackPosition &sp);
82 void onSendInsertion (const compiz::window::Object::Ptr &o);
83 void onSendRemoval (const compiz::window::Object::Ptr &o);
84 void onSendDeletion ();
85 void onSendAddState (uint64_t state);
86 void onSendRemoveState (uint64_t state);
87
88 private:
89
90 MockX11Object (const compiz::window::ObjectIdentifier::Ptr &,
91 const boost::shared_ptr <compiz::window::WriteServerConnection> &,
92 const compiz::window::Geometry &,
93 const boost::shared_ptr <compiz::window::Container> &);
94
95 friend class MockX11Server;
96};
97
98MockX11Object::MockX11Object (const compiz::window::ObjectIdentifier::Ptr &id,
99 const boost::shared_ptr <compiz::window::WriteServerConnection> &write,
100 const compiz::window::Geometry &g,
101 const boost::shared_ptr <compiz::window::Container> &c) :
102 Object (id, g),
103 AsynchronousObject (id, g, write),
104 X11Container (id, write, g, c)
105{
106}
107
108void
109MockX11Object::onReceiveGeometry (const compiz::window::Geometry &g)
110{
111 std::cout << "DEBUG: " << __func__ << " g: " << g.x () << " "
112 << g.y () << " "
113 << g.width () << " "
114 << g.height () << " "
115 << g.border () << std::endl;
116}
117
118void
119MockX11Object::onReceiveStackPosition (const compiz::window::StackPosition &sp)
120{
121 std::cout << "DEBUG: " << __func__ << std::endl;
122}
123
124void
125MockX11Object::onReceiveInsertion (const compiz::window::Object::Ptr &o)
126{
127 std::cout << "DEBUG: " << __func__ << std::endl;
128}
129
130void
131MockX11Object::onReceiveRemoval (const compiz::window::Object::Ptr &o)
132{
133 std::cout << "DEBUG: " << __func__ << std::endl;
134}
135
136void
137MockX11Object::onReceiveDeletion ()
138{
139 std::cout << "DEBUG: " << __func__ << std::endl;
140}
141
142void
143MockX11Object::onReceiveAddState (uint64_t state)
144{
145 std::cout << "DEBUG: " << __func__ << std::hex << state << std::dec << std::endl;
146}
147
148void
149MockX11Object::onReceiveRemoveState (uint64_t state)
150{
151 std::cout << "DEBUG: " << __func__ << std::hex << state << std::dec << std::endl;
152}
153
154void
155MockX11Object::onSendGeometry (const compiz::window::Geometry &g)
156{
157 std::cout << "DEBUG: " << __func__ << " g: " << g.x () << " "
158 << g.y () << " "
159 << g.width () << " "
160 << g.height () << " "
161 << g.border () << std::endl;
162}
163
164void
165MockX11Object::onSendStackPosition (const compiz::window::StackPosition &sp)
166{
167 std::cout << "DEBUG: " << __func__ << std::endl;
168}
169
170void
171MockX11Object::onSendInsertion (const compiz::window::Object::Ptr &o)
172{
173 std::cout << "DEBUG: " << __func__ << std::endl;
174}
175
176void
177MockX11Object::onSendRemoval (const compiz::window::Object::Ptr &o)
178{
179 std::cout << "DEBUG: " << __func__ << std::endl;
180}
181
182void
183MockX11Object::onSendDeletion ()
184{
185 std::cout << "DEBUG: " << __func__ << std::endl;
186}
187
188void
189MockX11Object::onSendAddState (uint64_t state)
190{
191 std::cout << "DEBUG: " << __func__ << std::hex << state << std::dec << std::endl;
192}
193
194void
195MockX11Object::onSendRemoveState (uint64_t state)
196{
197 std::cout << "DEBUG: " << __func__ << std::hex << state << std::dec << std::endl;
198}
199
200MockX11Object::~MockX11Object ()
201{
202}
203
204MockX11Server::MockX11Server (Display *d, Glib::RefPtr <Glib::MainLoop> &ml) :
205 X11Server (ml, d)
206{
207}
208
209MockX11Server::~MockX11Server ()
210{
211}
212
213void
214MockX11Server::setRoot (Window root, const compiz::window::Geometry &g)
215{
216 Server::SetDefault (shared_from_this ());
217 X11Server::setRoot (root, g);
218}
219
220compiz::window::Object::Ptr
221MockX11Server::createObject (const compiz::window::ObjectIdentifier::Ptr &id,
222 const compiz::window::Geometry &g,
223 const compiz::window::StackPosition &sp,
224 const boost::shared_ptr <compiz::window::Container> &c)
225{
226 compiz::window::X11ObjectIdentifier::Ptr xid = boost::shared_static_cast <compiz::window::X11ObjectIdentifier> (id);
227 MockX11Object::Ptr mxobj = MockX11Object::Ptr (new MockX11Object (id, connect (), g, c));
228 const compiz::window::X11Object::Ptr &xobj = boost::shared_static_cast <compiz::window::X11Object> (mxobj);
229 std::pair <compiz::window::X11ObjectIdentifier::Ptr, compiz::window::X11Object::Ptr> keyValue (xid, xobj);
230
231 addObjectToTree (keyValue);
232 return (*xid) ();
233}
234
235void
236MockX11Server::removeObject (const compiz::window::ObjectIdentifier::Ptr &id)
237{
238 removeKeyFromTree (id);
239}
240
241Window create_virtual_root (Display *display,
242 compiz::window::Geometry &g)
243{
244 XSetWindowAttributes attr;
245 g.set (0, 0, 800, 600, 0);
246 Window root = XCreateWindow (display, DefaultRootWindow (display),
247 0, 0, g.width (), g.height (), 0, CopyFromParent,
248 InputOutput, CopyFromParent,
249 0, &attr);
250 XSelectInput (display, root, ExposureMask);
251 XMapWindow (display, root);
252
253 while (1)
254 {
255 XEvent ev;
256 bool out = false;
257
258 XNextEvent (display, &ev);
259
260 switch (ev.type)
261 {
262 case Expose:
263
264 if (ev.xexpose.window == root)
265 {
266 /* The window is visible, clear it
267 * with white */
268 Visual *vis = DefaultVisual (display, DefaultScreen (display));
269 cairo_surface_t *xlib_surface = cairo_xlib_surface_create (display,
270 root,
271 vis,
272 800,
273 600);
274 cairo_t *cr = cairo_create (xlib_surface);
275
276 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
277 cairo_paint (cr);
278
279 cairo_destroy (cr);
280 cairo_surface_destroy (xlib_surface);
281
282 out = 1;
283 }
284 break;
285 default:
286 break;
287 }
288
289 if (out)
290 break;
291 }
292
293 XSync (display, false);
294
295 return root;
296}
297
298int main (int argc, char **argv)
299{
300 Glib::RefPtr <Glib::MainContext> mc = Glib::MainContext::get_default ();
301 Glib::RefPtr <Glib::MainLoop> ml = Glib::MainLoop::create (mc, false);
302 Glib::RefPtr <StdinSource> ss = StdinSource::create (ml);
303 Display *display = XOpenDisplay (NULL);
304 Window root = 0;
305 compiz::window::Geometry rg;
306 MockX11Server::Ptr server = MockX11Server::Ptr (new MockX11Server (display, ml));
307
308 for (int i = 0; i < argc; i++)
309 if (std::string (argv[i]) == "-c" ||
310 std::string (argv[i]) == "--create")
311 root = create_virtual_root (display, rg);
312
313 if (!root)
314 {
315 unsigned int width, height;
316 unsigned int uid;
317 Window wd;
318 int id;
319
320 root = DefaultRootWindow (display);
321 if (XGetGeometry (display, root, &wd, &id, &id, &width, &height, &uid, &uid))
322 {
323 rg.setWidth (width);
324 rg.setHeight (height);
325 }
326 }
327
328 server->setRoot (root, rg);
329
330 server->flush (0);
331 std::cout << ">> " << std::endl;
332 ml->run ();
333
334 XDestroyWindow (display, root);
335 XCloseDisplay (display);
336
337 return 0;
338}

Subscribers

People subscribed via source and target branches