OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_LEGACY_WINDOW_MANAGER_WM_IPC_H_ | 5 #ifndef VIEWS_WIDGET_WM_IPC_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LEGACY_WINDOW_MANAGER_WM_IPC_H_ | 6 #define VIEWS_WIDGET_WM_IPC_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
10 #include <map> | 10 #include <map> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "third_party/cros_system_api/window_manager/chromeos_wm_ipc_enums.h" | 16 #include "third_party/cros_system_api/window_manager/chromeos_wm_ipc_enums.h" |
17 | 17 |
18 typedef unsigned long Atom; | 18 typedef unsigned long Atom; |
19 typedef unsigned long XID; | 19 typedef unsigned long XID; |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 template <typename T> struct DefaultLazyInstanceTraits; | 22 template <typename T> struct DefaultLazyInstanceTraits; |
23 } | 23 } |
24 namespace gfx { | 24 namespace gfx { |
25 class Rect; | 25 class Rect; |
26 } | 26 } |
27 | 27 |
| 28 namespace views { |
| 29 |
28 namespace chromeos { | 30 namespace chromeos { |
29 | 31 |
30 class WmIpc { | 32 class WmIpc { |
31 public: | 33 public: |
32 enum AtomType { | 34 enum AtomType { |
33 ATOM_CHROME_LAYOUT_MODE = 0, | 35 ATOM_CHROME_LAYOUT_MODE = 0, |
34 ATOM_CHROME_LOGGED_IN, | 36 ATOM_CHROME_LOGGED_IN, |
35 ATOM_CHROME_STATE, | 37 ATOM_CHROME_STATE, |
36 ATOM_CHROME_STATE_COLLAPSED_PANEL, | 38 ATOM_CHROME_STATE_COLLAPSED_PANEL, |
37 ATOM_CHROME_STATE_STATUS_HIDDEN, | 39 ATOM_CHROME_STATE_STATUS_HIDDEN, |
38 ATOM_CHROME_STATUS_BOUNDS, | 40 ATOM_CHROME_STATUS_BOUNDS, |
39 ATOM_CHROME_WINDOW_TYPE, | 41 ATOM_CHROME_WINDOW_TYPE, |
40 ATOM_CHROME_WM_MESSAGE, | 42 ATOM_CHROME_WM_MESSAGE, |
41 ATOM_MANAGER, | 43 ATOM_MANAGER, |
42 ATOM_STRING, | 44 ATOM_STRING, |
43 ATOM_UTF8_STRING, | 45 ATOM_UTF8_STRING, |
44 ATOM_WM_S0, | 46 ATOM_WM_S0, |
45 kNumAtoms, | 47 kNumAtoms, |
46 }; | 48 }; |
47 | 49 |
48 struct Message { | 50 struct Message { |
49 public: | 51 public: |
50 Message() { | 52 Message() { |
51 Init(WM_IPC_MESSAGE_UNKNOWN); | 53 Init(::chromeos::WM_IPC_MESSAGE_UNKNOWN); |
52 } | 54 } |
53 // WmIpcMessageType is defined in chromeos_wm_ipc_enums.h. | 55 // WmIpcMessageType is defined in chromeos_wm_ipc_enums.h. |
54 explicit Message(WmIpcMessageType type) { | 56 explicit Message(::chromeos::WmIpcMessageType type) { |
55 Init(type); | 57 Init(type); |
56 } | 58 } |
57 | 59 |
58 WmIpcMessageType type() const { return type_; } | 60 ::chromeos::WmIpcMessageType type() const { return type_; } |
59 void set_type(WmIpcMessageType type) { type_ = type; } | 61 void set_type(::chromeos::WmIpcMessageType type) { type_ = type; } |
60 | 62 |
61 inline int max_params() const { | 63 inline int max_params() const { |
62 return arraysize(params_); | 64 return arraysize(params_); |
63 } | 65 } |
64 long param(int index) const { | 66 long param(int index) const { |
65 DCHECK_GE(index, 0); | 67 DCHECK_GE(index, 0); |
66 DCHECK_LT(index, max_params()); | 68 DCHECK_LT(index, max_params()); |
67 return params_[index]; | 69 return params_[index]; |
68 } | 70 } |
69 void set_param(int index, long value) { | 71 void set_param(int index, long value) { |
70 DCHECK_GE(index, 0); | 72 DCHECK_GE(index, 0); |
71 DCHECK_LT(index, max_params()); | 73 DCHECK_LT(index, max_params()); |
72 params_[index] = value; | 74 params_[index] = value; |
73 } | 75 } |
74 | 76 |
75 private: | 77 private: |
76 // Common initialization code shared between constructors. | 78 // Common initialization code shared between constructors. |
77 void Init(WmIpcMessageType type) { | 79 void Init(::chromeos::WmIpcMessageType type) { |
78 set_type(type); | 80 set_type(type); |
79 for (int i = 0; i < max_params(); ++i) { | 81 for (int i = 0; i < max_params(); ++i) { |
80 set_param(i, 0); | 82 set_param(i, 0); |
81 } | 83 } |
82 } | 84 } |
83 | 85 |
84 // Type of message that was sent. | 86 // Type of message that was sent. |
85 WmIpcMessageType type_; | 87 ::chromeos::WmIpcMessageType type_; |
86 | 88 |
87 // Type-specific data. This is bounded by the number of 32-bit values | 89 // Type-specific data. This is bounded by the number of 32-bit values |
88 // that we can pack into a ClientMessageEvent -- it holds five, but we | 90 // that we can pack into a ClientMessageEvent -- it holds five, but we |
89 // use the first one to store the message type. | 91 // use the first one to store the message type. |
90 long params_[4]; | 92 long params_[4]; |
91 }; | 93 }; |
92 | 94 |
93 // Returns the single instance of WmIpc. | 95 // Returns the single instance of WmIpc. |
94 static WmIpc* instance(); | 96 static WmIpc* instance(); |
95 | 97 |
96 WmIpcLayoutMode layout_mode() const { return layout_mode_; } | |
97 | |
98 // Gets or sets a property describing a window's type. | 98 // Gets or sets a property describing a window's type. |
99 // WmIpcMessageType is defined in chromeos_wm_ipc_enums.h. Type-specific | 99 // WmIpcMessageType is defined in chromeos_wm_ipc_enums.h. Type-specific |
100 // parameters may also be supplied. The caller is responsible for trapping | 100 // parameters may also be supplied. The caller is responsible for trapping |
101 // errors from the X server. | 101 // errors from the X server. |
102 bool SetWindowType(GtkWidget* widget, | 102 bool SetWindowType(GtkWidget* widget, |
103 WmIpcWindowType type, | 103 ::chromeos::WmIpcWindowType type, |
104 const std::vector<int>* params); | 104 const std::vector<int>* params); |
105 | 105 |
106 // Gets the string name of an atom from the AtomType enum. | 106 // Gets the string name of an atom from the AtomType enum. |
107 std::string GetAtomName(AtomType type) const; | 107 std::string GetAtomName(AtomType type) const; |
108 | 108 |
109 // Gets the type of the window, and any associated parameters. The | 109 // Gets the type of the window, and any associated parameters. The |
110 // caller is responsible for trapping errors from the X server. If | 110 // caller is responsible for trapping errors from the X server. If |
111 // the parameters are not interesting to the caller, NULL may be | 111 // the parameters are not interesting to the caller, NULL may be |
112 // passed for |params|. | 112 // passed for |params|. |
113 WmIpcWindowType GetWindowType(GtkWidget* widget, std::vector<int>* params); | 113 ::chromeos::WmIpcWindowType GetWindowType(GtkWidget* widget, |
| 114 std::vector<int>* params); |
114 | 115 |
115 // Gets the set of atoms contained in a window's _CHROME_STATE property. | 116 // Gets the set of atoms contained in a window's _CHROME_STATE property. |
116 // Returns false if the property isn't set. | 117 // Returns false if the property isn't set. |
117 bool GetWindowState(GtkWidget* widget, std::set<AtomType>* atom_types); | 118 bool GetWindowState(GtkWidget* widget, std::set<AtomType>* atom_types); |
118 | 119 |
119 // Sends a message to the WM. | 120 // Sends a message to the WM. |
120 void SendMessage(const Message& msg); | 121 void SendMessage(const views::chromeos::WmIpc::Message& msg); |
121 | 122 |
122 // If |event| is a valid Message it is decoded into |msg| and true is | 123 // If |event| is a valid Message it is decoded into |msg| and true is |
123 // returned. If false is returned, |event| is not a valid Message. | 124 // returned. If false is returned, |event| is not a valid Message. |
124 bool DecodeMessage(const GdkEventClient& event, Message* msg); | 125 bool DecodeMessage(const GdkEventClient& event, |
| 126 views::chromeos::WmIpc::Message* msg); |
125 | 127 |
126 // Handles ClientMessage events that weren't decodable using DecodeMessage(). | 128 // Handles ClientMessage events that weren't decodable using DecodeMessage(). |
127 // Specifically, this catches messages about the WM_S0 selection that get sent | 129 // Specifically, this catches messages about the WM_S0 selection that get sent |
128 // when a window manager process starts (so that we can re-run InitWmInfo()). | 130 // when a window manager process starts (so that we can re-run InitWmInfo()). |
129 // See ICCCM 2.8 for more info about MANAGER selections. | 131 // See ICCCM 2.8 for more info about MANAGER selections. |
130 void HandleNonChromeClientMessageEvent(const GdkEventClient& event); | 132 void HandleNonChromeClientMessageEvent(const GdkEventClient& event); |
131 | 133 |
132 // Handle an event reporting a property change on the root window. | |
133 void HandleRootWindowPropertyEvent(const GdkEventProperty& event); | |
134 | |
135 // Sets a _CHROME_LOGGED_IN property on the root window describing whether | 134 // Sets a _CHROME_LOGGED_IN property on the root window describing whether |
136 // the user is currently logged in or not. | 135 // the user is currently logged in or not. |
137 void SetLoggedInProperty(bool logged_in); | 136 void SetLoggedInProperty(bool logged_in); |
138 | 137 |
139 // Sets a _CHROME_STATUS_BOUNDS property on toplevel window |widget| | 138 // Sets a _CHROME_STATUS_BOUNDS property on toplevel window |widget| |
140 // describing the status area's bounds within the window. | 139 // describing the status area's bounds within the window. |
141 void SetStatusBoundsProperty(GtkWidget* widget, const gfx::Rect& bounds); | 140 void SetStatusBoundsProperty(GtkWidget* widget, const gfx::Rect& bounds); |
142 | 141 |
143 // Sends a message to the window manager notifying it that we're signing out. | 142 // Sends a message to the window manager notifying it that we're signing out. |
144 void NotifyAboutSignout(); | 143 void NotifyAboutSignout(); |
145 | 144 |
| 145 // Accessor for type_to_atom map |
| 146 std::map<AtomType, Atom>* type_to_atom() { |
| 147 return &type_to_atom_; |
| 148 } |
| 149 |
146 private: | 150 private: |
147 friend struct base::DefaultLazyInstanceTraits<WmIpc>; | 151 friend struct base::DefaultLazyInstanceTraits<WmIpc>; |
148 | 152 |
149 WmIpc(); | 153 WmIpc(); |
150 ~WmIpc(); | 154 ~WmIpc(); |
151 | 155 |
152 // Initializes 'wm_' and sends the window manager a message telling it the | 156 // Initializes 'wm_' and sends the window manager a message telling it the |
153 // version of the IPC protocol that we support. This is called in our | 157 // version of the IPC protocol that we support. This is called in our |
154 // constructor, but needs to be re-run if the window manager gets restarted. | 158 // constructor, but needs to be re-run if the window manager gets restarted. |
155 void InitWmInfo(); | 159 void InitWmInfo(); |
156 | 160 |
157 // Updates |layout_mode_| based on the current value of the root window's | |
158 // _CHROME_LAYOUT_MODE property. | |
159 void FetchLayoutModeProperty(); | |
160 | |
161 // Maps between our Atom enum and the X server's atom IDs and from the | 161 // Maps between our Atom enum and the X server's atom IDs and from the |
162 // server's IDs to atoms' string names. | 162 // server's IDs to atoms' string names. |
163 std::map<AtomType, Atom> type_to_atom_; | 163 std::map<AtomType, Atom> type_to_atom_; |
164 std::map<Atom, AtomType> atom_to_type_; | 164 std::map<Atom, AtomType> atom_to_type_; |
165 std::map<Atom, std::string> atom_to_string_; | 165 std::map<Atom, std::string> atom_to_string_; |
166 | 166 |
167 // Cached value of type_to_atom_[ATOM_CHROME_WM_MESSAGE]. | 167 // Cached value of type_to_atom_[ATOM_CHROME_WM_MESSAGE]. |
168 Atom wm_message_atom_; | 168 Atom wm_message_atom_; |
169 | 169 |
170 // Handle to the WM. Used for sending messages. | 170 // Handle to the WM. Used for sending messages. |
171 XID wm_; | 171 XID wm_; |
172 | 172 |
173 // The current value of the root window's _CHROME_LAYOUT_MODE property. | |
174 WmIpcLayoutMode layout_mode_; | |
175 | |
176 DISALLOW_COPY_AND_ASSIGN(WmIpc); | 173 DISALLOW_COPY_AND_ASSIGN(WmIpc); |
177 }; | 174 }; |
178 | 175 |
179 } // namespace chromeos | 176 } // namespace chromeos |
180 | 177 |
| 178 } // namespace views |
| 179 |
181 #endif // CHROME_BROWSER_CHROMEOS_LEGACY_WINDOW_MANAGER_WM_IPC_H_ | 180 #endif // CHROME_BROWSER_CHROMEOS_LEGACY_WINDOW_MANAGER_WM_IPC_H_ |
OLD | NEW |