Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: ui/base/x/x11_util.h

Issue 860873002: Continue deleting code in ui/. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 2015 Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/x/OWNERS ('k') | ui/base/x/x11_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #ifndef UI_BASE_X_X11_UTIL_H_
6 #define UI_BASE_X_X11_UTIL_H_
7
8 // This file declares utility functions for X11 (Linux only).
9 //
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
12 // hard to limit their spread into the rest of the code.
13
14 #include <string>
15 #include <vector>
16
17 #include "base/basictypes.h"
18 #include "base/event_types.h"
19 #include "base/memory/ref_counted_memory.h"
20 #include "ui/base/ui_base_export.h"
21 #include "ui/events/event_constants.h"
22 #include "ui/events/keycodes/keyboard_codes.h"
23 #include "ui/gfx/x/x11_types.h"
24
25 typedef unsigned long XSharedMemoryId; // ShmSeg in the X headers.
26 typedef unsigned long Cursor;
27 typedef struct _XcursorImage XcursorImage;
28 typedef union _XEvent XEvent;
29
30 namespace gfx {
31 class Canvas;
32 class Insets;
33 class Point;
34 class Rect;
35 }
36 class SkBitmap;
37
38 namespace ui {
39
40 // These functions use the default display and this /must/ be called from
41 // the UI thread. Thus, they don't support multiple displays.
42
43 // These functions cache their results ---------------------------------
44
45 // Returns true if the system supports XINPUT2.
46 UI_BASE_EXPORT bool IsXInput2Available();
47
48 // X shared memory comes in three flavors:
49 // 1) No SHM support,
50 // 2) SHM putimage,
51 // 3) SHM pixmaps + putimage.
52 enum SharedMemorySupport {
53 SHARED_MEMORY_NONE,
54 SHARED_MEMORY_PUTIMAGE,
55 SHARED_MEMORY_PIXMAP
56 };
57 // Return the shared memory type of our X connection.
58 UI_BASE_EXPORT SharedMemorySupport QuerySharedMemorySupport(XDisplay* dpy);
59
60 // Return true iff the display supports Xrender
61 UI_BASE_EXPORT bool QueryRenderSupport(XDisplay* dpy);
62
63 // Returns an X11 Cursor, sharable across the process.
64 // |cursor_shape| is an X font cursor shape, see XCreateFontCursor().
65 UI_BASE_EXPORT ::Cursor GetXCursor(int cursor_shape);
66
67 // Creates a custom X cursor from the image. This takes ownership of image. The
68 // caller must not free/modify the image. The refcount of the newly created
69 // cursor is set to 1.
70 UI_BASE_EXPORT ::Cursor CreateReffedCustomXCursor(XcursorImage* image);
71
72 // Increases the refcount of the custom cursor.
73 UI_BASE_EXPORT void RefCustomXCursor(::Cursor cursor);
74
75 // Decreases the refcount of the custom cursor, and destroys it if it reaches 0.
76 UI_BASE_EXPORT void UnrefCustomXCursor(::Cursor cursor);
77
78 // Creates a XcursorImage and copies the SkBitmap |bitmap| on it. |bitmap|
79 // should be non-null. Caller owns the returned object.
80 UI_BASE_EXPORT XcursorImage* SkBitmapToXcursorImage(const SkBitmap* bitmap,
81 const gfx::Point& hotspot);
82
83 // Coalesce all pending motion events (touch or mouse) that are at the top of
84 // the queue, and return the number eliminated, storing the last one in
85 // |last_event|.
86 UI_BASE_EXPORT int CoalescePendingMotionEvents(const XEvent* xev,
87 XEvent* last_event);
88
89 // Hides the host cursor.
90 UI_BASE_EXPORT void HideHostCursor();
91
92 // Returns an invisible cursor.
93 UI_BASE_EXPORT ::Cursor CreateInvisibleCursor();
94
95 // Sets whether |window| should use the OS window frame.
96 UI_BASE_EXPORT void SetUseOSWindowFrame(XID window, bool use_os_window_frame);
97
98 // These functions do not cache their results --------------------------
99
100 // Returns true if the shape extension is supported.
101 UI_BASE_EXPORT bool IsShapeExtensionAvailable();
102
103 // Get the X window id for the default root window
104 UI_BASE_EXPORT XID GetX11RootWindow();
105
106 // Returns the user's current desktop.
107 UI_BASE_EXPORT bool GetCurrentDesktop(int* desktop);
108
109 enum HideTitlebarWhenMaximized {
110 SHOW_TITLEBAR_WHEN_MAXIMIZED = 0,
111 HIDE_TITLEBAR_WHEN_MAXIMIZED = 1,
112 };
113 // Sets _GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED on |window|.
114 UI_BASE_EXPORT void SetHideTitlebarWhenMaximizedProperty(
115 XID window,
116 HideTitlebarWhenMaximized property);
117
118 // Clears all regions of X11's default root window by filling black pixels.
119 UI_BASE_EXPORT void ClearX11DefaultRootWindow();
120
121 // Returns true if |window| is visible.
122 UI_BASE_EXPORT bool IsWindowVisible(XID window);
123
124 // Returns the inner bounds of |window| (excluding the non-client area).
125 UI_BASE_EXPORT bool GetInnerWindowBounds(XID window, gfx::Rect* rect);
126
127 // Returns the non-client area extents of |window|. This is a negative inset; it
128 // represents the negative size of the window border on all sides.
129 // InnerWindowBounds.Inset(WindowExtents) = OuterWindowBounds.
130 // Returns false if the window manager does not provide extents information.
131 UI_BASE_EXPORT bool GetWindowExtents(XID window, gfx::Insets* extents);
132
133 // Returns the outer bounds of |window| (including the non-client area).
134 UI_BASE_EXPORT bool GetOuterWindowBounds(XID window, gfx::Rect* rect);
135
136 // Returns true if |window| contains the point |screen_loc|.
137 UI_BASE_EXPORT bool WindowContainsPoint(XID window, gfx::Point screen_loc);
138
139 // Return true if |window| has any property with |property_name|.
140 UI_BASE_EXPORT bool PropertyExists(XID window,
141 const std::string& property_name);
142
143 // Returns the raw bytes from a property with minimal
144 // interpretation. |out_data| should be freed by XFree() after use.
145 UI_BASE_EXPORT bool GetRawBytesOfProperty(
146 XID window,
147 XAtom property,
148 scoped_refptr<base::RefCountedMemory>* out_data,
149 size_t* out_data_items,
150 XAtom* out_type);
151
152 // Get the value of an int, int array, atom array or string property. On
153 // success, true is returned and the value is stored in |value|.
154 //
155 // TODO(erg): Once we remove the gtk port and are 100% aura, all of these
156 // should accept an XAtom instead of a string.
157 UI_BASE_EXPORT bool GetIntProperty(XID window,
158 const std::string& property_name,
159 int* value);
160 UI_BASE_EXPORT bool GetXIDProperty(XID window,
161 const std::string& property_name,
162 XID* value);
163 UI_BASE_EXPORT bool GetIntArrayProperty(XID window,
164 const std::string& property_name,
165 std::vector<int>* value);
166 UI_BASE_EXPORT bool GetAtomArrayProperty(XID window,
167 const std::string& property_name,
168 std::vector<XAtom>* value);
169 UI_BASE_EXPORT bool GetStringProperty(XID window,
170 const std::string& property_name,
171 std::string* value);
172
173 // These setters all make round trips.
174 UI_BASE_EXPORT bool SetIntProperty(XID window,
175 const std::string& name,
176 const std::string& type,
177 int value);
178 UI_BASE_EXPORT bool SetIntArrayProperty(XID window,
179 const std::string& name,
180 const std::string& type,
181 const std::vector<int>& value);
182 UI_BASE_EXPORT bool SetAtomProperty(XID window,
183 const std::string& name,
184 const std::string& type,
185 XAtom value);
186 UI_BASE_EXPORT bool SetAtomArrayProperty(XID window,
187 const std::string& name,
188 const std::string& type,
189 const std::vector<XAtom>& value);
190 UI_BASE_EXPORT bool SetStringProperty(XID window,
191 XAtom property,
192 XAtom type,
193 const std::string& value);
194
195 // Gets the X atom for default display corresponding to atom_name.
196 UI_BASE_EXPORT XAtom GetAtom(const char* atom_name);
197
198 // Sets the WM_CLASS attribute for a given X11 window.
199 UI_BASE_EXPORT void SetWindowClassHint(XDisplay* display,
200 XID window,
201 const std::string& res_name,
202 const std::string& res_class);
203
204 // Sets the WM_WINDOW_ROLE attribute for a given X11 window.
205 UI_BASE_EXPORT void SetWindowRole(XDisplay* display,
206 XID window,
207 const std::string& role);
208
209 // Determine whether we should default to native decorations or the custom
210 // frame based on the currently-running window manager.
211 UI_BASE_EXPORT bool GetCustomFramePrefDefault();
212
213 static const int kAllDesktops = -1;
214 // Queries the desktop |window| is on, kAllDesktops if sticky. Returns false if
215 // property not found.
216 bool GetWindowDesktop(XID window, int* desktop);
217
218 // Translates an X11 error code into a printable string.
219 UI_BASE_EXPORT std::string GetX11ErrorString(XDisplay* display, int err);
220
221 // Returns all children windows of a given window in top-to-bottom stacking
222 // order.
223 UI_BASE_EXPORT bool GetXWindowStack(XID window, std::vector<XID>* windows);
224
225 enum WindowManagerName {
226 WM_UNKNOWN,
227
228 WM_AWESOME,
229 WM_BLACKBOX,
230 WM_COMPIZ,
231 WM_ENLIGHTENMENT,
232 WM_I3,
233 WM_ICE_WM,
234 WM_ION3,
235 WM_KWIN,
236 WM_MATCHBOX,
237 WM_METACITY,
238 WM_MUFFIN,
239 WM_MUTTER,
240 WM_NOTION,
241 WM_OPENBOX,
242 WM_QTILE,
243 WM_RATPOISON,
244 WM_STUMPWM,
245 WM_WMII,
246 WM_XFWM4,
247 };
248 // Attempts to guess the window maager. Returns WM_UNKNOWN if we can't
249 // determine it for one reason or another.
250 UI_BASE_EXPORT WindowManagerName GuessWindowManager();
251
252 // The same as GuessWindowManager(), but returns the raw string. If we
253 // can't determine it, return "Unknown".
254 UI_BASE_EXPORT std::string GuessWindowManagerName();
255
256 // Enable the default X error handlers. These will log the error and abort
257 // the process if called. Use SetX11ErrorHandlers() from x11_util_internal.h
258 // to set your own error handlers.
259 UI_BASE_EXPORT void SetDefaultX11ErrorHandlers();
260
261 // Returns true if a given window is in full-screen mode.
262 UI_BASE_EXPORT bool IsX11WindowFullScreen(XID window);
263
264 // Returns true if the window manager supports the given hint.
265 UI_BASE_EXPORT bool WmSupportsHint(XAtom atom);
266
267 // Manages a piece of X11 allocated memory as a RefCountedMemory segment. This
268 // object takes ownership over the passed in memory and will free it with the
269 // X11 allocator when done.
270 class UI_BASE_EXPORT XRefcountedMemory : public base::RefCountedMemory {
271 public:
272 XRefcountedMemory(unsigned char* x11_data, size_t length)
273 : x11_data_(length ? x11_data : NULL), length_(length) {}
274
275 // Overridden from RefCountedMemory:
276 virtual const unsigned char* front() const override;
277 virtual size_t size() const override;
278
279 private:
280 virtual ~XRefcountedMemory();
281
282 unsigned char* x11_data_;
283 size_t length_;
284
285 DISALLOW_COPY_AND_ASSIGN(XRefcountedMemory);
286 };
287
288 // Keeps track of a string returned by an X function (e.g. XGetAtomName) and
289 // makes sure it's XFree'd.
290 class UI_BASE_EXPORT XScopedString {
291 public:
292 explicit XScopedString(char* str) : string_(str) {}
293 ~XScopedString();
294
295 const char* string() const { return string_; }
296
297 private:
298 char* string_;
299
300 DISALLOW_COPY_AND_ASSIGN(XScopedString);
301 };
302
303 // Keeps track of an image returned by an X function (e.g. XGetImage) and
304 // makes sure it's XDestroyImage'd.
305 class UI_BASE_EXPORT XScopedImage {
306 public:
307 explicit XScopedImage(XImage* image) : image_(image) {}
308 ~XScopedImage();
309
310 XImage* get() const { return image_; }
311
312 XImage* operator->() const { return image_; }
313
314 void reset(XImage* image);
315
316 private:
317 XImage* image_;
318
319 DISALLOW_COPY_AND_ASSIGN(XScopedImage);
320 };
321
322 // Keeps track of a cursor returned by an X function and makes sure it's
323 // XFreeCursor'd.
324 class UI_BASE_EXPORT XScopedCursor {
325 public:
326 // Keeps track of |cursor| created with |display|.
327 XScopedCursor(::Cursor cursor, XDisplay* display);
328 ~XScopedCursor();
329
330 ::Cursor get() const;
331 void reset(::Cursor cursor);
332
333 private:
334 ::Cursor cursor_;
335 XDisplay* display_;
336
337 DISALLOW_COPY_AND_ASSIGN(XScopedCursor);
338 };
339
340 namespace test {
341 // Resets the cache used by GetXCursor(). Only useful for tests that may delete
342 // the display.
343 UI_BASE_EXPORT void ResetXCursorCache();
344
345 // Returns the cached XcursorImage for |cursor|.
346 UI_BASE_EXPORT const XcursorImage* GetCachedXcursorImage(::Cursor cursor);
347
348 } // namespace test
349
350 } // namespace ui
351
352 #endif // UI_BASE_X_X11_UTIL_H_
OLDNEW
« no previous file with comments | « ui/base/x/OWNERS ('k') | ui/base/x/x11_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698