| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_WM_IPC_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_WM_IPC_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <gtk/gtk.h> | |
| 10 #include <map> | |
| 11 #include <set> | |
| 12 #include <string> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "base/logging.h" | |
| 16 #include "third_party/cros_system_api/window_manager/chromeos_wm_ipc_enums.h" | |
| 17 | |
| 18 typedef unsigned long Atom; | |
| 19 typedef unsigned long XID; | |
| 20 | |
| 21 namespace base { | |
| 22 template <typename T> struct DefaultLazyInstanceTraits; | |
| 23 } | |
| 24 namespace gfx { | |
| 25 class Rect; | |
| 26 } | |
| 27 | |
| 28 namespace chromeos { | |
| 29 | |
| 30 class WmIpc { | |
| 31 public: | |
| 32 enum AtomType { | |
| 33 ATOM_CHROME_LAYOUT_MODE = 0, | |
| 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. | |
| 94 static WmIpc* instance(); | |
| 95 | |
| 96 WmIpcLayoutMode layout_mode() const { return layout_mode_; } | |
| 97 | |
| 98 // Gets or sets a property describing a window's type. | |
| 99 // WmIpcMessageType is defined in chromeos_wm_ipc_enums.h. Type-specific | |
| 100 // parameters may also be supplied. The caller is responsible for trapping | |
| 101 // errors from the X server. | |
| 102 bool SetWindowType(GtkWidget* widget, | |
| 103 WmIpcWindowType type, | |
| 104 const std::vector<int>* params); | |
| 105 | |
| 106 // Gets the string name of an atom from the AtomType enum. | |
| 107 std::string GetAtomName(AtomType type) const; | |
| 108 | |
| 109 // Gets the type of the window, and any associated parameters. The | |
| 110 // caller is responsible for trapping errors from the X server. If | |
| 111 // the parameters are not interesting to the caller, NULL may be | |
| 112 // passed for |params|. | |
| 113 WmIpcWindowType GetWindowType(GtkWidget* widget, std::vector<int>* params); | |
| 114 | |
| 115 // Gets the set of atoms contained in a window's _CHROME_STATE property. | |
| 116 // Returns false if the property isn't set. | |
| 117 bool GetWindowState(GtkWidget* widget, std::set<AtomType>* atom_types); | |
| 118 | |
| 119 // Sends a message to the WM. | |
| 120 void SendMessage(const Message& msg); | |
| 121 | |
| 122 // 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 bool DecodeMessage(const GdkEventClient& event, Message* msg); | |
| 125 | |
| 126 // Handles ClientMessage events that weren't decodable using DecodeMessage(). | |
| 127 // 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()). | |
| 129 // See ICCCM 2.8 for more info about MANAGER selections. | |
| 130 void HandleNonChromeClientMessageEvent(const GdkEventClient& event); | |
| 131 | |
| 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 | |
| 136 // the user is currently logged in or not. | |
| 137 void SetLoggedInProperty(bool logged_in); | |
| 138 | |
| 139 // Sets a _CHROME_STATUS_BOUNDS property on toplevel window |widget| | |
| 140 // describing the status area's bounds within the window. | |
| 141 void SetStatusBoundsProperty(GtkWidget* widget, const gfx::Rect& bounds); | |
| 142 | |
| 143 // Sends a message to the window manager notifying it that we're signing out. | |
| 144 void NotifyAboutSignout(); | |
| 145 | |
| 146 private: | |
| 147 friend struct base::DefaultLazyInstanceTraits<WmIpc>; | |
| 148 | |
| 149 WmIpc(); | |
| 150 ~WmIpc(); | |
| 151 | |
| 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 | |
| 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 | |
| 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. | |
| 174 WmIpcLayoutMode layout_mode_; | |
| 175 | |
| 176 DISALLOW_COPY_AND_ASSIGN(WmIpc); | |
| 177 }; | |
| 178 | |
| 179 } // namespace chromeos | |
| 180 | |
| 181 #endif // CHROME_BROWSER_CHROMEOS_WM_IPC_H_ | |
| OLD | NEW |