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 CHROME_BROWSER_CHROMEOS_LEGACY_WINDOW_MANAGER_WM_IPC_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LEGACY_WINDOW_MANAGER_WM_IPC_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LEGACY_WINDOW_MANAGER_WM_IPC_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
10 #include <map> | |
11 #include <set> | 10 #include <set> |
12 #include <string> | 11 #include <string> |
13 #include <vector> | 12 #include <vector> |
14 | 13 |
15 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "views/widget/wm_ipc.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; | |
19 typedef unsigned long XID; | |
20 | |
21 namespace base { | 18 namespace base { |
22 template <typename T> struct DefaultLazyInstanceTraits; | 19 template <typename T> struct DefaultLazyInstanceTraits; |
23 } | 20 } |
24 namespace gfx { | 21 namespace gfx { |
25 class Rect; | 22 class Rect; |
26 } | 23 } |
27 | 24 |
28 namespace chromeos { | 25 namespace chromeos { |
29 | 26 |
30 class WmIpc { | 27 class WmIpc { |
31 public: | 28 public: |
32 enum AtomType { | 29 typedef views::chromeos::WmIpc::AtomType AtomType; |
33 ATOM_CHROME_LAYOUT_MODE = 0, | 30 typedef views::chromeos::WmIpc::Message Message; |
34 ATOM_CHROME_LOGGED_IN, | |
35 ATOM_CHROME_STATE, | |
36 ATOM_CHROME_STATE_COLLAPSED_PANEL, | |
37 ATOM_CHROME_STATE_STATUS_HIDDEN, | |
38 ATOM_CHROME_STATUS_BOUNDS, | |
39 ATOM_CHROME_WINDOW_TYPE, | |
40 ATOM_CHROME_WM_MESSAGE, | |
41 ATOM_MANAGER, | |
42 ATOM_STRING, | |
43 ATOM_UTF8_STRING, | |
44 ATOM_WM_S0, | |
45 kNumAtoms, | |
46 }; | |
47 | |
48 struct Message { | |
49 public: | |
50 Message() { | |
51 Init(WM_IPC_MESSAGE_UNKNOWN); | |
52 } | |
53 // WmIpcMessageType is defined in chromeos_wm_ipc_enums.h. | |
54 explicit Message(WmIpcMessageType type) { | |
55 Init(type); | |
56 } | |
57 | |
58 WmIpcMessageType type() const { return type_; } | |
59 void set_type(WmIpcMessageType type) { type_ = type; } | |
60 | |
61 inline int max_params() const { | |
62 return arraysize(params_); | |
63 } | |
64 long param(int index) const { | |
65 DCHECK_GE(index, 0); | |
66 DCHECK_LT(index, max_params()); | |
67 return params_[index]; | |
68 } | |
69 void set_param(int index, long value) { | |
70 DCHECK_GE(index, 0); | |
71 DCHECK_LT(index, max_params()); | |
72 params_[index] = value; | |
73 } | |
74 | |
75 private: | |
76 // Common initialization code shared between constructors. | |
77 void Init(WmIpcMessageType type) { | |
78 set_type(type); | |
79 for (int i = 0; i < max_params(); ++i) { | |
80 set_param(i, 0); | |
81 } | |
82 } | |
83 | |
84 // Type of message that was sent. | |
85 WmIpcMessageType type_; | |
86 | |
87 // 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 | |
89 // use the first one to store the message type. | |
90 long params_[4]; | |
91 }; | |
92 | |
93 // Returns the single instance of WmIpc. | 31 // Returns the single instance of WmIpc. |
94 static WmIpc* instance(); | 32 static WmIpc* instance(); |
95 | 33 |
96 WmIpcLayoutMode layout_mode() const { return layout_mode_; } | 34 WmIpcLayoutMode layout_mode() const { return layout_mode_; } |
97 | 35 |
98 // Gets or sets a property describing a window's type. | 36 // Gets or sets a property describing a window's type. |
99 // WmIpcMessageType is defined in chromeos_wm_ipc_enums.h. Type-specific | 37 // WmIpcMessageType is defined in chromeos_wm_ipc_enums.h. Type-specific |
100 // parameters may also be supplied. The caller is responsible for trapping | 38 // parameters may also be supplied. The caller is responsible for trapping |
101 // errors from the X server. | 39 // errors from the X server. |
102 bool SetWindowType(GtkWidget* widget, | 40 bool SetWindowType(GtkWidget* widget, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 80 |
143 // Sends a message to the window manager notifying it that we're signing out. | 81 // Sends a message to the window manager notifying it that we're signing out. |
144 void NotifyAboutSignout(); | 82 void NotifyAboutSignout(); |
145 | 83 |
146 private: | 84 private: |
147 friend struct base::DefaultLazyInstanceTraits<WmIpc>; | 85 friend struct base::DefaultLazyInstanceTraits<WmIpc>; |
148 | 86 |
149 WmIpc(); | 87 WmIpc(); |
150 ~WmIpc(); | 88 ~WmIpc(); |
151 | 89 |
152 // 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 | |
154 // constructor, but needs to be re-run if the window manager gets restarted. | |
155 void InitWmInfo(); | |
156 | |
157 // Updates |layout_mode_| based on the current value of the root window's | 90 // Updates |layout_mode_| based on the current value of the root window's |
158 // _CHROME_LAYOUT_MODE property. | 91 // _CHROME_LAYOUT_MODE property. |
159 void FetchLayoutModeProperty(); | 92 void FetchLayoutModeProperty(); |
160 | 93 |
161 // Maps between our Atom enum and the X server's atom IDs and from the | |
162 // server's IDs to atoms' string names. | |
163 std::map<AtomType, Atom> type_to_atom_; | |
164 std::map<Atom, AtomType> atom_to_type_; | |
165 std::map<Atom, std::string> atom_to_string_; | |
166 | |
167 // Cached value of type_to_atom_[ATOM_CHROME_WM_MESSAGE]. | |
168 Atom wm_message_atom_; | |
169 | |
170 // Handle to the WM. Used for sending messages. | |
171 XID wm_; | |
172 | |
173 // The current value of the root window's _CHROME_LAYOUT_MODE property. | 94 // The current value of the root window's _CHROME_LAYOUT_MODE property. |
174 WmIpcLayoutMode layout_mode_; | 95 WmIpcLayoutMode layout_mode_; |
175 | 96 |
176 DISALLOW_COPY_AND_ASSIGN(WmIpc); | 97 DISALLOW_COPY_AND_ASSIGN(WmIpc); |
177 }; | 98 }; |
178 | 99 |
179 } // namespace chromeos | 100 } // namespace chromeos |
180 | 101 |
181 #endif // CHROME_BROWSER_CHROMEOS_LEGACY_WINDOW_MANAGER_WM_IPC_H_ | 102 #endif // CHROME_BROWSER_CHROMEOS_LEGACY_WINDOW_MANAGER_WM_IPC_H_ |
OLD | NEW |