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_export.h" | 20 #include "ui/base/ui_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 | 25 |
25 typedef unsigned long Atom; | 26 typedef unsigned long Atom; |
26 typedef unsigned long XID; | |
27 typedef unsigned long XSharedMemoryId; // ShmSeg in the X headers. | 27 typedef unsigned long XSharedMemoryId; // ShmSeg in the X headers. |
28 typedef struct _XDisplay Display; | |
sky
2013/09/19 00:11:39
I believe this was Display to match X, see http://
sky
2013/09/19 00:13:50
I guess this is no different than a typedef of Dis
| |
29 typedef unsigned long Cursor; | 28 typedef unsigned long Cursor; |
30 typedef struct _XcursorImage XcursorImage; | 29 typedef struct _XcursorImage XcursorImage; |
31 typedef union _XEvent XEvent; | 30 typedef union _XEvent XEvent; |
32 typedef struct _XImage XImage; | |
33 typedef struct _XGC *GC; | |
34 | 31 |
35 #if defined(TOOLKIT_GTK) | 32 #if defined(TOOLKIT_GTK) |
36 typedef struct _GdkDrawable GdkWindow; | 33 typedef struct _GdkDrawable GdkWindow; |
37 typedef struct _GtkWidget GtkWidget; | 34 typedef struct _GtkWidget GtkWidget; |
38 typedef struct _GtkWindow GtkWindow; | 35 typedef struct _GtkWindow GtkWindow; |
39 #endif | 36 #endif |
40 | 37 |
41 namespace gfx { | 38 namespace gfx { |
42 class Canvas; | 39 class Canvas; |
43 class Point; | 40 class Point; |
44 class Rect; | 41 class Rect; |
45 } | 42 } |
46 class SkBitmap; | 43 class SkBitmap; |
47 | 44 |
48 namespace ui { | 45 namespace ui { |
49 | 46 |
50 // These functions use the default display and this /must/ be called from | 47 // These functions use the default display and this /must/ be called from |
51 // the UI thread. Thus, they don't support multiple displays. | 48 // the UI thread. Thus, they don't support multiple displays. |
52 | 49 |
53 // These functions cache their results --------------------------------- | 50 // These functions cache their results --------------------------------- |
54 | 51 |
55 // Check if there's an open connection to an X server. | 52 // Check if there's an open connection to an X server. |
56 UI_EXPORT bool XDisplayExists(); | 53 UI_EXPORT bool XDisplayExists(); |
57 // Return an X11 connection for the current, primary display. | 54 // Return an X11 connection for the current, primary display. |
58 | 55 |
59 // TODO(oshima|evan): This assume there is one display and dosn't work | |
60 // undef mutiple displays/monitor environment. Remove this and change the | |
61 // chrome codebase to get the display from window. | |
62 UI_EXPORT Display* GetXDisplay(); | |
63 | |
64 // X shared memory comes in three flavors: | 56 // X shared memory comes in three flavors: |
65 // 1) No SHM support, | 57 // 1) No SHM support, |
66 // 2) SHM putimage, | 58 // 2) SHM putimage, |
67 // 3) SHM pixmaps + putimage. | 59 // 3) SHM pixmaps + putimage. |
68 enum SharedMemorySupport { | 60 enum SharedMemorySupport { |
69 SHARED_MEMORY_NONE, | 61 SHARED_MEMORY_NONE, |
70 SHARED_MEMORY_PUTIMAGE, | 62 SHARED_MEMORY_PUTIMAGE, |
71 SHARED_MEMORY_PIXMAP | 63 SHARED_MEMORY_PIXMAP |
72 }; | 64 }; |
73 // Return the shared memory type of our X connection. | 65 // Return the shared memory type of our X connection. |
74 UI_EXPORT SharedMemorySupport QuerySharedMemorySupport(Display* dpy); | 66 UI_EXPORT SharedMemorySupport QuerySharedMemorySupport(XDisplay* dpy); |
75 | 67 |
76 // Return true iff the display supports Xrender | 68 // Return true iff the display supports Xrender |
77 UI_EXPORT bool QueryRenderSupport(Display* dpy); | 69 UI_EXPORT bool QueryRenderSupport(XDisplay* dpy); |
78 | 70 |
79 // Return the default screen number for the display | 71 // Return the default screen number for the display |
80 int GetDefaultScreen(Display* display); | 72 int GetDefaultScreen(XDisplay* display); |
81 | 73 |
82 // Returns an X11 Cursor, sharable across the process. | 74 // Returns an X11 Cursor, sharable across the process. |
83 // |cursor_shape| is an X font cursor shape, see XCreateFontCursor(). | 75 // |cursor_shape| is an X font cursor shape, see XCreateFontCursor(). |
84 UI_EXPORT ::Cursor GetXCursor(int cursor_shape); | 76 UI_EXPORT ::Cursor GetXCursor(int cursor_shape); |
85 | 77 |
86 // Resets the cache used by GetXCursor(). Only useful for tests that may delete | 78 // Resets the cache used by GetXCursor(). Only useful for tests that may delete |
87 // the display. | 79 // the display. |
88 UI_EXPORT void ResetXCursorCache(); | 80 UI_EXPORT void ResetXCursorCache(); |
89 | 81 |
90 #if defined(USE_AURA) | 82 #if defined(USE_AURA) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 }; | 138 }; |
147 // Sets _GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED on |window|. | 139 // Sets _GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED on |window|. |
148 UI_EXPORT void SetHideTitlebarWhenMaximizedProperty( | 140 UI_EXPORT void SetHideTitlebarWhenMaximizedProperty( |
149 XID window, | 141 XID window, |
150 HideTitlebarWhenMaximized property); | 142 HideTitlebarWhenMaximized property); |
151 | 143 |
152 // Clears all regions of X11's default root window by filling black pixels. | 144 // Clears all regions of X11's default root window by filling black pixels. |
153 UI_EXPORT void ClearX11DefaultRootWindow(); | 145 UI_EXPORT void ClearX11DefaultRootWindow(); |
154 | 146 |
155 // Return the number of bits-per-pixel for a pixmap of the given depth | 147 // Return the number of bits-per-pixel for a pixmap of the given depth |
156 UI_EXPORT int BitsPerPixelForPixmapDepth(Display* display, int depth); | 148 UI_EXPORT int BitsPerPixelForPixmapDepth(XDisplay* display, int depth); |
157 | 149 |
158 // Returns true if |window| is visible. | 150 // Returns true if |window| is visible. |
159 UI_EXPORT bool IsWindowVisible(XID window); | 151 UI_EXPORT bool IsWindowVisible(XID window); |
160 | 152 |
161 // Returns the bounds of |window|. | 153 // Returns the bounds of |window|. |
162 UI_EXPORT bool GetWindowRect(XID window, gfx::Rect* rect); | 154 UI_EXPORT bool GetWindowRect(XID window, gfx::Rect* rect); |
163 | 155 |
164 // Returns true if |window| contains the point |screen_loc|. | 156 // Returns true if |window| contains the point |screen_loc|. |
165 UI_EXPORT bool WindowContainsPoint(XID window, gfx::Point screen_loc); | 157 UI_EXPORT bool WindowContainsPoint(XID window, gfx::Point screen_loc); |
166 | 158 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 const std::vector<int>& value); | 197 const std::vector<int>& value); |
206 UI_EXPORT bool SetAtomArrayProperty(XID window, | 198 UI_EXPORT bool SetAtomArrayProperty(XID window, |
207 const std::string& name, | 199 const std::string& name, |
208 const std::string& type, | 200 const std::string& type, |
209 const std::vector<Atom>& value); | 201 const std::vector<Atom>& value); |
210 | 202 |
211 // Gets the X atom for default display corresponding to atom_name. | 203 // Gets the X atom for default display corresponding to atom_name. |
212 Atom GetAtom(const char* atom_name); | 204 Atom GetAtom(const char* atom_name); |
213 | 205 |
214 // Sets the WM_CLASS attribute for a given X11 window. | 206 // Sets the WM_CLASS attribute for a given X11 window. |
215 UI_EXPORT void SetWindowClassHint(Display* display, | 207 UI_EXPORT void SetWindowClassHint(XDisplay* display, |
216 XID window, | 208 XID window, |
217 std::string res_name, | 209 std::string res_name, |
218 std::string res_class); | 210 std::string res_class); |
219 | 211 |
220 // Get |window|'s parent window, or None if |window| is the root window. | 212 // Get |window|'s parent window, or None if |window| is the root window. |
221 UI_EXPORT XID GetParentWindow(XID window); | 213 UI_EXPORT XID GetParentWindow(XID window); |
222 | 214 |
223 // Walk up |window|'s hierarchy until we find a direct child of |root|. | 215 // Walk up |window|'s hierarchy until we find a direct child of |root|. |
224 XID GetHighestAncestorWindow(XID window, XID root); | 216 XID GetHighestAncestorWindow(XID window, XID root); |
225 | 217 |
226 static const int kAllDesktops = -1; | 218 static const int kAllDesktops = -1; |
227 // Queries the desktop |window| is on, kAllDesktops if sticky. Returns false if | 219 // Queries the desktop |window| is on, kAllDesktops if sticky. Returns false if |
228 // property not found. | 220 // property not found. |
229 bool GetWindowDesktop(XID window, int* desktop); | 221 bool GetWindowDesktop(XID window, int* desktop); |
230 | 222 |
231 // Translates an X11 error code into a printable string. | 223 // Translates an X11 error code into a printable string. |
232 UI_EXPORT std::string GetX11ErrorString(Display* display, int err); | 224 UI_EXPORT std::string GetX11ErrorString(XDisplay* display, int err); |
233 | 225 |
234 // Implementers of this interface receive a notification for every X window of | 226 // Implementers of this interface receive a notification for every X window of |
235 // the main display. | 227 // the main display. |
236 class EnumerateWindowsDelegate { | 228 class EnumerateWindowsDelegate { |
237 public: | 229 public: |
238 // |xid| is the X Window ID of the enumerated window. Return true to stop | 230 // |xid| is the X Window ID of the enumerated window. Return true to stop |
239 // further iteration. | 231 // further iteration. |
240 virtual bool ShouldStopIterating(XID xid) = 0; | 232 virtual bool ShouldStopIterating(XID xid) = 0; |
241 | 233 |
242 protected: | 234 protected: |
(...skipping 13 matching lines...) Expand all Loading... | |
256 UI_EXPORT bool GetXWindowStack(XID window, std::vector<XID>* windows); | 248 UI_EXPORT bool GetXWindowStack(XID window, std::vector<XID>* windows); |
257 | 249 |
258 // Restack a window in relation to one of its siblings. If |above| is true, | 250 // Restack a window in relation to one of its siblings. If |above| is true, |
259 // |window| will be stacked directly above |sibling|; otherwise it will stacked | 251 // |window| will be stacked directly above |sibling|; otherwise it will stacked |
260 // directly below it. Both windows must be immediate children of the same | 252 // directly below it. Both windows must be immediate children of the same |
261 // window. | 253 // window. |
262 void RestackWindow(XID window, XID sibling, bool above); | 254 void RestackWindow(XID window, XID sibling, bool above); |
263 | 255 |
264 // Return a handle to a X ShmSeg. |shared_memory_key| is a SysV | 256 // Return a handle to a X ShmSeg. |shared_memory_key| is a SysV |
265 // IPC key. The shared memory region must contain 32-bit pixels. | 257 // IPC key. The shared memory region must contain 32-bit pixels. |
266 UI_EXPORT XSharedMemoryId AttachSharedMemory(Display* display, | 258 UI_EXPORT XSharedMemoryId AttachSharedMemory(XDisplay* display, |
267 int shared_memory_support); | 259 int shared_memory_support); |
268 UI_EXPORT void DetachSharedMemory(Display* display, XSharedMemoryId shmseg); | 260 UI_EXPORT void DetachSharedMemory(XDisplay* display, XSharedMemoryId shmseg); |
269 | 261 |
270 // Copies |source_bounds| from |drawable| to |canvas| at offset |dest_offset|. | 262 // Copies |source_bounds| from |drawable| to |canvas| at offset |dest_offset|. |
271 // |source_bounds| is in physical pixels, while |dest_offset| is relative to | 263 // |source_bounds| is in physical pixels, while |dest_offset| is relative to |
272 // the canvas's scale. Note that this function is slow since it uses | 264 // the canvas's scale. Note that this function is slow since it uses |
273 // XGetImage() to copy the data from the X server to this process before | 265 // XGetImage() to copy the data from the X server to this process before |
274 // copying it to |canvas|. | 266 // copying it to |canvas|. |
275 UI_EXPORT bool CopyAreaToCanvas(XID drawable, | 267 UI_EXPORT bool CopyAreaToCanvas(XID drawable, |
276 gfx::Rect source_bounds, | 268 gfx::Rect source_bounds, |
277 gfx::Point dest_offset, | 269 gfx::Point dest_offset, |
278 gfx::Canvas* canvas); | 270 gfx::Canvas* canvas); |
279 | 271 |
280 // Return a handle to an XRender picture where |pixmap| is a handle to a | 272 // Return a handle to an XRender picture where |pixmap| is a handle to a |
281 // pixmap containing Skia ARGB data. | 273 // pixmap containing Skia ARGB data. |
282 UI_EXPORT XID CreatePictureFromSkiaPixmap(Display* display, XID pixmap); | 274 UI_EXPORT XID CreatePictureFromSkiaPixmap(XDisplay* display, XID pixmap); |
283 | 275 |
284 // Draws ARGB data on the given pixmap using the given GC, converting to the | 276 // Draws ARGB data on the given pixmap using the given GC, converting to the |
285 // server side visual depth as needed. Destination is assumed to be the same | 277 // server side visual depth as needed. Destination is assumed to be the same |
286 // dimensions as |data| or larger. |data| is also assumed to be in row order | 278 // dimensions as |data| or larger. |data| is also assumed to be in row order |
287 // with each line being exactly |width| * 4 bytes long. | 279 // with each line being exactly |width| * 4 bytes long. |
288 UI_EXPORT void PutARGBImage(Display* display, | 280 UI_EXPORT void PutARGBImage(XDisplay* display, |
289 void* visual, int depth, | 281 void* visual, int depth, |
290 XID pixmap, void* pixmap_gc, | 282 XID pixmap, void* pixmap_gc, |
291 const uint8* data, | 283 const uint8* data, |
292 int width, int height); | 284 int width, int height); |
293 | 285 |
294 // Same as above only more general: | 286 // Same as above only more general: |
295 // - |data_width| and |data_height| refer to the data image | 287 // - |data_width| and |data_height| refer to the data image |
296 // - |src_x|, |src_y|, |copy_width| and |copy_height| define source region | 288 // - |src_x|, |src_y|, |copy_width| and |copy_height| define source region |
297 // - |dst_x|, |dst_y|, |copy_width| and |copy_height| define destination region | 289 // - |dst_x|, |dst_y|, |copy_width| and |copy_height| define destination region |
298 UI_EXPORT void PutARGBImage(Display* display, | 290 UI_EXPORT void PutARGBImage(XDisplay* display, |
299 void* visual, int depth, | 291 void* visual, int depth, |
300 XID pixmap, void* pixmap_gc, | 292 XID pixmap, void* pixmap_gc, |
301 const uint8* data, | 293 const uint8* data, |
302 int data_width, int data_height, | 294 int data_width, int data_height, |
303 int src_x, int src_y, | 295 int src_x, int src_y, |
304 int dst_x, int dst_y, | 296 int dst_x, int dst_y, |
305 int copy_width, int copy_height); | 297 int copy_width, int copy_height); |
306 | 298 |
307 void FreePicture(Display* display, XID picture); | 299 void FreePicture(XDisplay* display, XID picture); |
308 void FreePixmap(Display* display, XID pixmap); | 300 void FreePixmap(XDisplay* display, XID pixmap); |
309 | 301 |
310 enum WindowManagerName { | 302 enum WindowManagerName { |
311 WM_UNKNOWN, | 303 WM_UNKNOWN, |
312 WM_BLACKBOX, | 304 WM_BLACKBOX, |
313 WM_CHROME_OS, | 305 WM_CHROME_OS, |
314 WM_COMPIZ, | 306 WM_COMPIZ, |
315 WM_ENLIGHTENMENT, | 307 WM_ENLIGHTENMENT, |
316 WM_ICE_WM, | 308 WM_ICE_WM, |
317 WM_KWIN, | 309 WM_KWIN, |
318 WM_METACITY, | 310 WM_METACITY, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 XImage* image_; | 404 XImage* image_; |
413 | 405 |
414 DISALLOW_COPY_AND_ASSIGN(XScopedImage); | 406 DISALLOW_COPY_AND_ASSIGN(XScopedImage); |
415 }; | 407 }; |
416 | 408 |
417 // Keeps track of a cursor returned by an X function and makes sure it's | 409 // Keeps track of a cursor returned by an X function and makes sure it's |
418 // XFreeCursor'd. | 410 // XFreeCursor'd. |
419 class UI_EXPORT XScopedCursor { | 411 class UI_EXPORT XScopedCursor { |
420 public: | 412 public: |
421 // Keeps track of |cursor| created with |display|. | 413 // Keeps track of |cursor| created with |display|. |
422 XScopedCursor(::Cursor cursor, Display* display); | 414 XScopedCursor(::Cursor cursor, XDisplay* display); |
423 ~XScopedCursor(); | 415 ~XScopedCursor(); |
424 | 416 |
425 ::Cursor get() const; | 417 ::Cursor get() const; |
426 void reset(::Cursor cursor); | 418 void reset(::Cursor cursor); |
427 | 419 |
428 private: | 420 private: |
429 ::Cursor cursor_; | 421 ::Cursor cursor_; |
430 Display* display_; | 422 XDisplay* display_; |
431 | 423 |
432 DISALLOW_COPY_AND_ASSIGN(XScopedCursor); | 424 DISALLOW_COPY_AND_ASSIGN(XScopedCursor); |
433 }; | 425 }; |
434 | 426 |
435 } // namespace ui | 427 } // namespace ui |
436 | 428 |
437 #endif // UI_BASE_X_X11_UTIL_H_ | 429 #endif // UI_BASE_X_X11_UTIL_H_ |
OLD | NEW |