| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/chromeos/wm_ipc.h" | 5 #include "chrome/browser/chromeos/wm_ipc.h" |
| 6 | 6 |
| 7 #include <gdk/gdkx.h> | 7 #include <gdk/gdkx.h> |
| 8 extern "C" { | 8 extern "C" { |
| 9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
| 10 } | 10 } |
| 11 | 11 |
| 12 #include "app/x11_util.h" | 12 #include "app/x11_util.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/singleton.h" | 14 #include "base/singleton.h" |
| 15 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
| 16 | 16 |
| 17 namespace chromeos { | 17 namespace chromeos { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // A value from the Atom enum and the actual name that should be used to | 21 // A value from the Atom enum and the actual name that should be used to |
| 22 // look up its ID on the X server. | 22 // look up its ID on the X server. |
| 23 struct AtomInfo { | 23 struct AtomInfo { |
| 24 WmIpc::AtomType atom; | 24 WmIpc::AtomType atom; |
| 25 const char* name; | 25 const char* name; |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 // Each value from the Atom enum must be present here. | 28 // Each value from the Atom enum must be present here. |
| 29 static const AtomInfo kAtomInfos[] = { | 29 static const AtomInfo kAtomInfos[] = { |
| 30 { WmIpc::ATOM_CHROME_LOGGED_IN, "_CHROME_LOGGED_IN" }, |
| 30 { WmIpc::ATOM_CHROME_WINDOW_TYPE, "_CHROME_WINDOW_TYPE" }, | 31 { WmIpc::ATOM_CHROME_WINDOW_TYPE, "_CHROME_WINDOW_TYPE" }, |
| 31 { WmIpc::ATOM_CHROME_WM_MESSAGE, "_CHROME_WM_MESSAGE" }, | 32 { WmIpc::ATOM_CHROME_WM_MESSAGE, "_CHROME_WM_MESSAGE" }, |
| 32 { WmIpc::ATOM_MANAGER, "MANAGER" }, | 33 { WmIpc::ATOM_MANAGER, "MANAGER" }, |
| 33 { WmIpc::ATOM_NET_SUPPORTING_WM_CHECK, "_NET_SUPPORTING_WM_CHECK" }, | |
| 34 { WmIpc::ATOM_NET_WM_NAME, "_NET_WM_NAME" }, | |
| 35 { WmIpc::ATOM_PRIMARY, "PRIMARY" }, | |
| 36 { WmIpc::ATOM_STRING, "STRING" }, | 34 { WmIpc::ATOM_STRING, "STRING" }, |
| 37 { WmIpc::ATOM_UTF8_STRING, "UTF8_STRING" }, | 35 { WmIpc::ATOM_UTF8_STRING, "UTF8_STRING" }, |
| 38 { WmIpc::ATOM_WM_NORMAL_HINTS, "WM_NORMAL_HINTS" }, | |
| 39 { WmIpc::ATOM_WM_S0, "WM_S0" }, | 36 { WmIpc::ATOM_WM_S0, "WM_S0" }, |
| 40 { WmIpc::ATOM_WM_STATE, "WM_STATE" }, | |
| 41 { WmIpc::ATOM_WM_TRANSIENT_FOR, "WM_TRANSIENT_FOR" }, | |
| 42 { WmIpc::ATOM_WM_SYSTEM_METRICS, "WM_SYSTEM_METRICS" }, | 37 { WmIpc::ATOM_WM_SYSTEM_METRICS, "WM_SYSTEM_METRICS" }, |
| 43 }; | 38 }; |
| 44 | 39 |
| 45 bool SetIntProperty(XID xid, Atom xatom, const std::vector<int>& values) { | 40 bool SetIntProperty(XID xid, Atom xatom, const std::vector<int>& values) { |
| 46 DCHECK(!values.empty()); | 41 DCHECK(!values.empty()); |
| 47 | 42 |
| 48 // XChangeProperty expects values of type 32 to be longs. | 43 // XChangeProperty expects values of type 32 to be longs. |
| 49 scoped_array<long> data(new long[values.size()]); | 44 scoped_array<long> data(new long[values.size()]); |
| 50 for (size_t i = 0; i < values.size(); ++i) | 45 for (size_t i = 0; i < values.size(); ++i) |
| 51 data[i] = values[i]; | 46 data[i] = values[i]; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 static GdkAtom manager_gdk_atom = | 203 static GdkAtom manager_gdk_atom = |
| 209 gdk_x11_xatom_to_atom(type_to_atom_[ATOM_MANAGER]); | 204 gdk_x11_xatom_to_atom(type_to_atom_[ATOM_MANAGER]); |
| 210 static Atom wm_s0_atom = type_to_atom_[ATOM_WM_S0]; | 205 static Atom wm_s0_atom = type_to_atom_[ATOM_WM_S0]; |
| 211 | 206 |
| 212 if (event.message_type == manager_gdk_atom && | 207 if (event.message_type == manager_gdk_atom && |
| 213 static_cast<Atom>(event.data.l[1]) == wm_s0_atom) { | 208 static_cast<Atom>(event.data.l[1]) == wm_s0_atom) { |
| 214 InitWmInfo(); | 209 InitWmInfo(); |
| 215 } | 210 } |
| 216 } | 211 } |
| 217 | 212 |
| 213 void WmIpc::SetLoggedInProperty(bool logged_in) { |
| 214 std::vector<int> values; |
| 215 values.push_back(static_cast<int>(logged_in)); |
| 216 SetIntProperty(gdk_x11_get_default_root_xwindow(), |
| 217 type_to_atom_[ATOM_CHROME_LOGGED_IN], |
| 218 values); |
| 219 } |
| 220 |
| 218 WmIpc::WmIpc() { | 221 WmIpc::WmIpc() { |
| 219 scoped_array<char*> names(new char*[kNumAtoms]); | 222 scoped_array<char*> names(new char*[kNumAtoms]); |
| 220 scoped_array<Atom> atoms(new Atom[kNumAtoms]); | 223 scoped_array<Atom> atoms(new Atom[kNumAtoms]); |
| 221 | 224 |
| 222 for (int i = 0; i < kNumAtoms; ++i) { | 225 for (int i = 0; i < kNumAtoms; ++i) { |
| 223 // Need to const_cast because XInternAtoms() wants a char**. | 226 // Need to const_cast because XInternAtoms() wants a char**. |
| 224 names[i] = const_cast<char*>(kAtomInfos[i].name); | 227 names[i] = const_cast<char*>(kAtomInfos[i].name); |
| 225 } | 228 } |
| 226 | 229 |
| 227 XInternAtoms(x11_util::GetXDisplay(), names.get(), kNumAtoms, | 230 XInternAtoms(x11_util::GetXDisplay(), names.get(), kNumAtoms, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 252 // Let the window manager know which version of the IPC messages we support. | 255 // Let the window manager know which version of the IPC messages we support. |
| 253 Message msg(chromeos::WM_IPC_MESSAGE_WM_NOTIFY_IPC_VERSION); | 256 Message msg(chromeos::WM_IPC_MESSAGE_WM_NOTIFY_IPC_VERSION); |
| 254 // TODO: The version number is the latest listed in wm_ipc.h -- | 257 // TODO: The version number is the latest listed in wm_ipc.h -- |
| 255 // ideally, once this header is shared between Chrome and the Chrome OS window | 258 // ideally, once this header is shared between Chrome and the Chrome OS window |
| 256 // manager, we'll just define the version statically in the header. | 259 // manager, we'll just define the version statically in the header. |
| 257 msg.set_param(0, 1); | 260 msg.set_param(0, 1); |
| 258 SendMessage(msg); | 261 SendMessage(msg); |
| 259 } | 262 } |
| 260 | 263 |
| 261 } // namespace chromeos | 264 } // namespace chromeos |
| OLD | NEW |