OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 #include "ui/base/x/x11_atom_cache.h" |
| 6 |
| 7 #include <X11/Xatom.h> |
| 8 |
| 9 #include "base/message_pump_x.h" |
| 10 |
| 11 namespace ui { |
| 12 |
| 13 namespace { |
| 14 |
| 15 // A list of atoms that we'll intern on host creation to save roundtrips to the |
| 16 // X11 server. Must be kept in sync with AtomCache::AtomName |
| 17 struct AtomInfo { |
| 18 ui::AtomName id; |
| 19 const char* name; |
| 20 } const kAtomList[] = { |
| 21 { ATOM_WM_DELETE_WINDOW, "WM_DELETE_WINDOW" }, |
| 22 { ATOM__NET_WM_MOVERESIZE, "_NET_WM_MOVERESIZE" }, |
| 23 { ATOM__NET_WM_PING, "_NET_WM_PING" }, |
| 24 { ATOM__NET_WM_PID, "_NET_WM_PID" }, |
| 25 { ATOM_WM_S0, "WM_S0" }, |
| 26 { ATOM__MOTIF_WM_HINTS, "_MOTIF_WM_HINTS" } |
| 27 }; |
| 28 |
| 29 // Our lists need to stay in sync here. |
| 30 COMPILE_ASSERT(arraysize(kAtomList) == ui::ATOM_COUNT, |
| 31 atom_lists_are_same_size); |
| 32 |
| 33 } // namespace |
| 34 |
| 35 X11AtomCache* X11AtomCache::GetInstance() { |
| 36 return Singleton<X11AtomCache>::get(); |
| 37 } |
| 38 |
| 39 ::Atom X11AtomCache::GetAtom(AtomName name) const { |
| 40 std::map<AtomName, ::Atom>::const_iterator it = cached_atoms_.find(name); |
| 41 DCHECK(it != cached_atoms_.end()); |
| 42 return it->second; |
| 43 } |
| 44 |
| 45 X11AtomCache::X11AtomCache() { |
| 46 const char* all_names[ATOM_COUNT]; |
| 47 ::Atom cached_atoms[ATOM_COUNT]; |
| 48 |
| 49 for (int i = 0; i < ATOM_COUNT; ++i) |
| 50 all_names[i] = kAtomList[i].name; |
| 51 |
| 52 // Grab all the atoms we need now to minimize roundtrips to the X11 server. |
| 53 XInternAtoms(base::MessagePumpX::GetDefaultXDisplay(), |
| 54 const_cast<char**>(all_names), ATOM_COUNT, False, |
| 55 cached_atoms); |
| 56 |
| 57 for (int i = 0; i < ATOM_COUNT; ++i) |
| 58 cached_atoms_.insert(std::make_pair(kAtomList[i].id, cached_atoms[i])); |
| 59 } |
| 60 |
| 61 X11AtomCache::~X11AtomCache() {} |
| 62 |
| 63 } // namespace ui |
| 64 |
| 65 |
OLD | NEW |