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

Side by Side Diff: app/x11_util.h

Issue 6257006: Move a bunch of random other files to src/ui/base... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « app/view_prop_unittest.cc ('k') | app/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) 2010 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 APP_X11_UTIL_H_
6 #define APP_X11_UTIL_H_
7 #pragma once
8
9 // This file declares utility functions for X11 (Linux only).
10 //
11 // These functions do not require the Xlib headers to be included (which is why
12 // we use a void* for Visual*). The Xlib headers are highly polluting so we try
13 // hard to limit their spread into the rest of the code.
14
15 #include <string>
16 #include <vector>
17
18 #include "base/basictypes.h"
19
20 typedef struct _GdkDrawable GdkWindow;
21 typedef struct _GtkWidget GtkWidget;
22 typedef struct _GtkWindow GtkWindow;
23 typedef unsigned long XID;
24 typedef unsigned long XSharedMemoryId; // ShmSeg in the X headers.
25 typedef struct _XDisplay Display;
26
27 namespace gfx {
28 class Rect;
29 }
30
31 namespace x11_util {
32
33 // These functions use the GDK default display and this /must/ be called from
34 // the UI thread. Thus, they don't support multiple displays.
35
36 // These functions cache their results ---------------------------------
37
38 // Check if there's an open connection to an X server.
39 bool XDisplayExists();
40 // Return an X11 connection for the current, primary display.
41 Display* GetXDisplay();
42
43 // X shared memory comes in three flavors:
44 // 1) No SHM support,
45 // 2) SHM putimage,
46 // 3) SHM pixmaps + putimage.
47 enum SharedMemorySupport {
48 SHARED_MEMORY_NONE,
49 SHARED_MEMORY_PUTIMAGE,
50 SHARED_MEMORY_PIXMAP
51 };
52 // Return the shared memory type of our X connection.
53 SharedMemorySupport QuerySharedMemorySupport(Display* dpy);
54
55 // Return true iff the display supports Xrender
56 bool QueryRenderSupport(Display* dpy);
57
58 // Return the default screen number for the display
59 int GetDefaultScreen(Display* display);
60
61 // These functions do not cache their results --------------------------
62
63 // Get the X window id for the default root window
64 XID GetX11RootWindow();
65 // Returns the user's current desktop.
66 bool GetCurrentDesktop(int* desktop);
67 // Get the X window id for the given GTK widget.
68 XID GetX11WindowFromGtkWidget(GtkWidget* widget);
69 XID GetX11WindowFromGdkWindow(GdkWindow* window);
70 // Get a Visual from the given widget. Since we don't include the Xlib
71 // headers, this is returned as a void*.
72 void* GetVisualFromGtkWidget(GtkWidget* widget);
73 // Return the number of bits-per-pixel for a pixmap of the given depth
74 int BitsPerPixelForPixmapDepth(Display* display, int depth);
75 // Returns true if |window| is visible.
76 bool IsWindowVisible(XID window);
77 // Returns the bounds of |window|.
78 bool GetWindowRect(XID window, gfx::Rect* rect);
79 // Get the value of an int, int array, or string property. On
80 // success, true is returned and the value is stored in |value|.
81 bool GetIntProperty(XID window, const std::string& property_name, int* value);
82 bool GetIntArrayProperty(XID window, const std::string& property_name,
83 std::vector<int>* value);
84 bool GetStringProperty(
85 XID window, const std::string& property_name, std::string* value);
86
87 // Get |window|'s parent window, or None if |window| is the root window.
88 XID GetParentWindow(XID window);
89
90 // Walk up |window|'s hierarchy until we find a direct child of |root|.
91 XID GetHighestAncestorWindow(XID window, XID root);
92
93 static const int kAllDesktops = -1;
94 // Queries the desktop |window| is on, kAllDesktops if sticky. Returns false if
95 // property not found.
96 bool GetWindowDesktop(XID window, int* desktop);
97
98 // Implementers of this interface receive a notification for every X window of
99 // the main display.
100 class EnumerateWindowsDelegate {
101 public:
102 // |xid| is the X Window ID of the enumerated window. Return true to stop
103 // further iteration.
104 virtual bool ShouldStopIterating(XID xid) = 0;
105
106 protected:
107 virtual ~EnumerateWindowsDelegate() {}
108 };
109
110 // Enumerates all windows in the current display. Will recurse into child
111 // windows up to a depth of |max_depth|.
112 bool EnumerateAllWindows(EnumerateWindowsDelegate* delegate, int max_depth);
113
114 // Returns a list of top-level windows in top-to-bottom stacking order.
115 bool GetXWindowStack(std::vector<XID>* windows);
116
117 // Restack a window in relation to one of its siblings. If |above| is true,
118 // |window| will be stacked directly above |sibling|; otherwise it will stacked
119 // directly below it. Both windows must be immediate children of the same
120 // window.
121 void RestackWindow(XID window, XID sibling, bool above);
122
123 // Return a handle to a X ShmSeg. |shared_memory_key| is a SysV
124 // IPC key. The shared memory region must contain 32-bit pixels.
125 XSharedMemoryId AttachSharedMemory(Display* display, int shared_memory_support);
126 void DetachSharedMemory(Display* display, XSharedMemoryId shmseg);
127
128 // Return a handle to an XRender picture where |pixmap| is a handle to a
129 // pixmap containing Skia ARGB data.
130 XID CreatePictureFromSkiaPixmap(Display* display, XID pixmap);
131
132 // Draws ARGB data on the given pixmap using the given GC, converting to the
133 // server side visual depth as needed. Destination is assumed to be the same
134 // dimensions as |data| or larger. |data| is also assumed to be in row order
135 // with each line being exactly |width| * 4 bytes long.
136 void PutARGBImage(Display* display, void* visual, int depth, XID pixmap,
137 void* pixmap_gc, const uint8* data, int width, int height);
138
139 void FreePicture(Display* display, XID picture);
140 void FreePixmap(Display* display, XID pixmap);
141
142 // These functions are for performing X opertions outside of the UI thread.
143
144 // Return the Display for the secondary X connection. We keep a second
145 // connection around for making X requests outside of the UI thread.
146 // This function may only be called from the BACKGROUND_X11 thread.
147 Display* GetSecondaryDisplay();
148
149 // Since one cannot include both WebKit header and Xlib headers in the same
150 // file (due to collisions), we wrap all the Xlib functions that we need here.
151 // These functions must be called on the BACKGROUND_X11 thread since they
152 // reference GetSecondaryDisplay().
153
154 // Get the position of the given window in screen coordinates as well as its
155 // current size.
156 bool GetWindowGeometry(int* x, int* y, unsigned* width, unsigned* height,
157 XID window);
158
159 // Find the immediate parent of an X window.
160 //
161 // parent_window: (output) the parent window of |window|, or 0.
162 // parent_is_root: (output) true iff the parent of |window| is the root window.
163 bool GetWindowParent(XID* parent_window, bool* parent_is_root, XID window);
164
165 // Get the window manager name.
166 bool GetWindowManagerName(std::string* name);
167
168 // Grabs a snapshot of the designated window and stores a PNG representation
169 // into a byte vector.
170 void GrabWindowSnapshot(GtkWindow* gdk_window,
171 std::vector<unsigned char>* png_representation);
172
173 // Change desktop for |window| to the desktop of |destination| window.
174 bool ChangeWindowDesktop(XID window, XID destination);
175
176 // Enable the default X error handlers. These will log the error and abort
177 // the process if called. Use SetX11ErrorHandlers() from x11_util_internal.h
178 // to set your own error handlers.
179 void SetDefaultX11ErrorHandlers();
180
181 } // namespace x11_util
182
183 #endif // APP_X11_UTIL_H_
OLDNEW
« no previous file with comments | « app/view_prop_unittest.cc ('k') | app/x11_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698