| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 UI_BASE_X_X11_UTIL_H_ | 5 #ifndef UI_BASE_X_X11_UTIL_H_ |
| 6 #define UI_BASE_X_X11_UTIL_H_ | 6 #define UI_BASE_X_X11_UTIL_H_ |
| 7 | 7 |
| 8 // This file declares utility functions for X11 (Linux only). | 8 // This file declares utility functions for X11 (Linux only). |
| 9 // | 9 // |
| 10 // These functions do not require the Xlib headers to be included (which is why | 10 // These functions do not require the Xlib headers to be included (which is why |
| 11 // we use a void* for Visual*). The Xlib headers are highly polluting so we try | 11 // we use a void* for Visual*). The Xlib headers are highly polluting so we try |
| 12 // hard to limit their spread into the rest of the code. | 12 // hard to limit their spread into the rest of the code. |
| 13 | 13 |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 18 #include "base/event_types.h" | 18 #include "base/event_types.h" |
| 19 #include "base/memory/ref_counted_memory.h" | 19 #include "base/memory/ref_counted_memory.h" |
| 20 #include "ui/base/ui_base_export.h" | 20 #include "ui/base/ui_base_export.h" |
| 21 #include "ui/events/event_constants.h" | 21 #include "ui/events/event_constants.h" |
| 22 #include "ui/events/keycodes/keyboard_codes.h" | 22 #include "ui/events/keycodes/keyboard_codes.h" |
| 23 #include "ui/gfx/point.h" | 23 #include "ui/gfx/point.h" |
| 24 #include "ui/gfx/x/x11_types.h" | 24 #include "ui/gfx/x/x11_types.h" |
| 25 | 25 |
| 26 typedef unsigned long Atom; | |
| 27 typedef unsigned long XSharedMemoryId; // ShmSeg in the X headers. | 26 typedef unsigned long XSharedMemoryId; // ShmSeg in the X headers. |
| 28 typedef unsigned long Cursor; | 27 typedef unsigned long Cursor; |
| 29 typedef struct _XcursorImage XcursorImage; | 28 typedef struct _XcursorImage XcursorImage; |
| 30 typedef union _XEvent XEvent; | 29 typedef union _XEvent XEvent; |
| 31 | 30 |
| 32 namespace gfx { | 31 namespace gfx { |
| 33 class Canvas; | 32 class Canvas; |
| 34 class Point; | 33 class Point; |
| 35 class Rect; | 34 class Rect; |
| 36 } | 35 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 UI_BASE_EXPORT bool WindowContainsPoint(XID window, gfx::Point screen_loc); | 128 UI_BASE_EXPORT bool WindowContainsPoint(XID window, gfx::Point screen_loc); |
| 130 | 129 |
| 131 // Return true if |window| has any property with |property_name|. | 130 // Return true if |window| has any property with |property_name|. |
| 132 UI_BASE_EXPORT bool PropertyExists(XID window, | 131 UI_BASE_EXPORT bool PropertyExists(XID window, |
| 133 const std::string& property_name); | 132 const std::string& property_name); |
| 134 | 133 |
| 135 // Returns the raw bytes from a property with minimal | 134 // Returns the raw bytes from a property with minimal |
| 136 // interpretation. |out_data| should be freed by XFree() after use. | 135 // interpretation. |out_data| should be freed by XFree() after use. |
| 137 UI_BASE_EXPORT bool GetRawBytesOfProperty( | 136 UI_BASE_EXPORT bool GetRawBytesOfProperty( |
| 138 XID window, | 137 XID window, |
| 139 Atom property, | 138 XAtom property, |
| 140 scoped_refptr<base::RefCountedMemory>* out_data, | 139 scoped_refptr<base::RefCountedMemory>* out_data, |
| 141 size_t* out_data_items, | 140 size_t* out_data_items, |
| 142 Atom* out_type); | 141 XAtom* out_type); |
| 143 | 142 |
| 144 // Get the value of an int, int array, atom array or string property. On | 143 // Get the value of an int, int array, atom array or string property. On |
| 145 // success, true is returned and the value is stored in |value|. | 144 // success, true is returned and the value is stored in |value|. |
| 146 // | 145 // |
| 147 // TODO(erg): Once we remove the gtk port and are 100% aura, all of these | 146 // TODO(erg): Once we remove the gtk port and are 100% aura, all of these |
| 148 // should accept an Atom instead of a string. | 147 // should accept an XAtom instead of a string. |
| 149 UI_BASE_EXPORT bool GetIntProperty(XID window, | 148 UI_BASE_EXPORT bool GetIntProperty(XID window, |
| 150 const std::string& property_name, | 149 const std::string& property_name, |
| 151 int* value); | 150 int* value); |
| 152 UI_BASE_EXPORT bool GetXIDProperty(XID window, | 151 UI_BASE_EXPORT bool GetXIDProperty(XID window, |
| 153 const std::string& property_name, | 152 const std::string& property_name, |
| 154 XID* value); | 153 XID* value); |
| 155 UI_BASE_EXPORT bool GetIntArrayProperty(XID window, | 154 UI_BASE_EXPORT bool GetIntArrayProperty(XID window, |
| 156 const std::string& property_name, | 155 const std::string& property_name, |
| 157 std::vector<int>* value); | 156 std::vector<int>* value); |
| 158 UI_BASE_EXPORT bool GetAtomArrayProperty(XID window, | 157 UI_BASE_EXPORT bool GetAtomArrayProperty(XID window, |
| 159 const std::string& property_name, | 158 const std::string& property_name, |
| 160 std::vector<Atom>* value); | 159 std::vector<XAtom>* value); |
| 161 UI_BASE_EXPORT bool GetStringProperty(XID window, | 160 UI_BASE_EXPORT bool GetStringProperty(XID window, |
| 162 const std::string& property_name, | 161 const std::string& property_name, |
| 163 std::string* value); | 162 std::string* value); |
| 164 | 163 |
| 165 // These setters all make round trips. | 164 // These setters all make round trips. |
| 166 UI_BASE_EXPORT bool SetIntProperty(XID window, | 165 UI_BASE_EXPORT bool SetIntProperty(XID window, |
| 167 const std::string& name, | 166 const std::string& name, |
| 168 const std::string& type, | 167 const std::string& type, |
| 169 int value); | 168 int value); |
| 170 UI_BASE_EXPORT bool SetIntArrayProperty(XID window, | 169 UI_BASE_EXPORT bool SetIntArrayProperty(XID window, |
| 171 const std::string& name, | 170 const std::string& name, |
| 172 const std::string& type, | 171 const std::string& type, |
| 173 const std::vector<int>& value); | 172 const std::vector<int>& value); |
| 174 UI_BASE_EXPORT bool SetAtomProperty(XID window, | 173 UI_BASE_EXPORT bool SetAtomProperty(XID window, |
| 175 const std::string& name, | 174 const std::string& name, |
| 176 const std::string& type, | 175 const std::string& type, |
| 177 Atom value); | 176 XAtom value); |
| 178 UI_BASE_EXPORT bool SetAtomArrayProperty(XID window, | 177 UI_BASE_EXPORT bool SetAtomArrayProperty(XID window, |
| 179 const std::string& name, | 178 const std::string& name, |
| 180 const std::string& type, | 179 const std::string& type, |
| 181 const std::vector<Atom>& value); | 180 const std::vector<XAtom>& value); |
| 182 UI_BASE_EXPORT bool SetStringProperty(XID window, | 181 UI_BASE_EXPORT bool SetStringProperty(XID window, |
| 183 Atom property, | 182 XAtom property, |
| 184 Atom type, | 183 XAtom type, |
| 185 const std::string& value); | 184 const std::string& value); |
| 186 | 185 |
| 187 // Gets the X atom for default display corresponding to atom_name. | 186 // Gets the X atom for default display corresponding to atom_name. |
| 188 UI_BASE_EXPORT Atom GetAtom(const char* atom_name); | 187 UI_BASE_EXPORT XAtom GetAtom(const char* atom_name); |
| 189 | 188 |
| 190 // Sets the WM_CLASS attribute for a given X11 window. | 189 // Sets the WM_CLASS attribute for a given X11 window. |
| 191 UI_BASE_EXPORT void SetWindowClassHint(XDisplay* display, | 190 UI_BASE_EXPORT void SetWindowClassHint(XDisplay* display, |
| 192 XID window, | 191 XID window, |
| 193 const std::string& res_name, | 192 const std::string& res_name, |
| 194 const std::string& res_class); | 193 const std::string& res_class); |
| 195 | 194 |
| 196 // Sets the WM_WINDOW_ROLE attribute for a given X11 window. | 195 // Sets the WM_WINDOW_ROLE attribute for a given X11 window. |
| 197 UI_BASE_EXPORT void SetWindowRole(XDisplay* display, | 196 UI_BASE_EXPORT void SetWindowRole(XDisplay* display, |
| 198 XID window, | 197 XID window, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 264 |
| 266 // Enable the default X error handlers. These will log the error and abort | 265 // Enable the default X error handlers. These will log the error and abort |
| 267 // the process if called. Use SetX11ErrorHandlers() from x11_util_internal.h | 266 // the process if called. Use SetX11ErrorHandlers() from x11_util_internal.h |
| 268 // to set your own error handlers. | 267 // to set your own error handlers. |
| 269 UI_BASE_EXPORT void SetDefaultX11ErrorHandlers(); | 268 UI_BASE_EXPORT void SetDefaultX11ErrorHandlers(); |
| 270 | 269 |
| 271 // Returns true if a given window is in full-screen mode. | 270 // Returns true if a given window is in full-screen mode. |
| 272 UI_BASE_EXPORT bool IsX11WindowFullScreen(XID window); | 271 UI_BASE_EXPORT bool IsX11WindowFullScreen(XID window); |
| 273 | 272 |
| 274 // Returns true if the window manager supports the given hint. | 273 // Returns true if the window manager supports the given hint. |
| 275 UI_BASE_EXPORT bool WmSupportsHint(Atom atom); | 274 UI_BASE_EXPORT bool WmSupportsHint(XAtom atom); |
| 276 | 275 |
| 277 // Manages a piece of X11 allocated memory as a RefCountedMemory segment. This | 276 // Manages a piece of X11 allocated memory as a RefCountedMemory segment. This |
| 278 // object takes ownership over the passed in memory and will free it with the | 277 // object takes ownership over the passed in memory and will free it with the |
| 279 // X11 allocator when done. | 278 // X11 allocator when done. |
| 280 class UI_BASE_EXPORT XRefcountedMemory : public base::RefCountedMemory { | 279 class UI_BASE_EXPORT XRefcountedMemory : public base::RefCountedMemory { |
| 281 public: | 280 public: |
| 282 XRefcountedMemory(unsigned char* x11_data, size_t length) | 281 XRefcountedMemory(unsigned char* x11_data, size_t length) |
| 283 : x11_data_(length ? x11_data : NULL), length_(length) {} | 282 : x11_data_(length ? x11_data : NULL), length_(length) {} |
| 284 | 283 |
| 285 // Overridden from RefCountedMemory: | 284 // Overridden from RefCountedMemory: |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 UI_BASE_EXPORT void ResetXCursorCache(); | 352 UI_BASE_EXPORT void ResetXCursorCache(); |
| 354 | 353 |
| 355 // Returns the cached XcursorImage for |cursor|. | 354 // Returns the cached XcursorImage for |cursor|. |
| 356 UI_BASE_EXPORT const XcursorImage* GetCachedXcursorImage(::Cursor cursor); | 355 UI_BASE_EXPORT const XcursorImage* GetCachedXcursorImage(::Cursor cursor); |
| 357 | 356 |
| 358 } // namespace test | 357 } // namespace test |
| 359 | 358 |
| 360 } // namespace ui | 359 } // namespace ui |
| 361 | 360 |
| 362 #endif // UI_BASE_X_X11_UTIL_H_ | 361 #endif // UI_BASE_X_X11_UTIL_H_ |
| OLD | NEW |