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

Side by Side Diff: chrome/common/x11_util.cc

Issue 100145: WIP: X clipboard stuff (Closed)
Patch Set: Created 11 years, 7 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 | « chrome/browser/renderer_host/resource_message_filter_gtk.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 // This file defines utility functions for X11 (Linux only). This code has been 5 // This file defines utility functions for X11 (Linux only). This code has been
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support
7 // remains woefully incomplete. 7 // remains woefully incomplete.
8 8
9 #include "base/message_loop.h"
10 #include "base/message_pump_libevent.h"
9 #include "base/thread.h" 11 #include "base/thread.h"
10 #include "chrome/common/x11_util.h" 12 #include "chrome/common/x11_util.h"
11 #include "chrome/common/x11_util_internal.h" 13 #include "chrome/common/x11_util_internal.h"
12 14
13 #include <string.h> 15 #include <string.h>
14 16
15 #include <gdk/gdk.h> 17 #include <gdk/gdk.h>
16 #include <gdk/gdkx.h> 18 #include <gdk/gdkx.h>
17 #include <gtk/gtk.h> 19 #include <gtk/gtk.h>
18 20
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 223 }
222 224
223 void FreePicture(Display* display, XID picture) { 225 void FreePicture(Display* display, XID picture) {
224 XRenderFreePicture(display, picture); 226 XRenderFreePicture(display, picture);
225 } 227 }
226 228
227 void FreePixmap(Display* display, XID pixmap) { 229 void FreePixmap(Display* display, XID pixmap) {
228 XFreePixmap(display, pixmap); 230 XFreePixmap(display, pixmap);
229 } 231 }
230 232
233 // This class gets callbacks when the X file descriptor is ready for reading.
234 class XEventHandler : public base::MessagePumpLibevent::Watcher {
235 public:
236 XEventHandler(Display* display, int x_fd)
237 : display_(display),
238 x_fd_(x_fd) {
239 }
240
241 void OnFileCanReadWithoutBlocking(int fd) {
242 DCHECK_EQ(fd, x_fd_);
243
244 while (true) {
245 XEvent event;
246 if (!XCheckMaskEvent(
247 display_, 0x8fffffff /* all ones, but still positive in 32-bits */,
248 &event)) {
249 return;
250 }
251
252 LOG(INFO) << "Got X event";
253 }
254 }
255
256 void OnFileCanWriteWithoutBlocking(int fd) {
257 CHECK(false);
258 }
259
260 private:
261 Display* const display_;
262 const int x_fd_;
263 };
264
231 // Called on BACKGROUND_X11 thread. 265 // Called on BACKGROUND_X11 thread.
232 Display* GetSecondaryDisplay() { 266 Display* GetSecondaryDisplay() {
233 static Display* display = NULL; 267 static Display* display = NULL;
268 static base::MessagePumpLibevent::FileDescriptorWatcher* watcher = NULL;
269 static XEventHandler* x_event_handler = NULL;
270
234 if (!display) { 271 if (!display) {
235 display = XOpenDisplay(NULL); 272 display = XOpenDisplay(NULL);
236 CHECK(display); 273 CHECK(display);
274
275 watcher = new base::MessagePumpLibevent::FileDescriptorWatcher;
276 const int x_fd = XConnectionNumber(display);
277 x_event_handler = new XEventHandler(display, x_fd);
278
279 MessageLoopForIO::current()->WatchFileDescriptor(
280 x_fd, true, MessageLoopForIO::WATCH_READ, watcher,
281 x_event_handler);
237 } 282 }
238 283
239 return display; 284 return display;
240 } 285 }
241 286
242 // Called on BACKGROUND_X11 thread. 287 // Called on BACKGROUND_X11 thread.
243 bool GetWindowGeometry(int* x, int* y, unsigned* width, unsigned* height, 288 bool GetWindowGeometry(int* x, int* y, unsigned* width, unsigned* height,
244 XID window) { 289 XID window) {
245 Window root_window, child_window; 290 Window root_window, child_window;
246 unsigned border_width, depth; 291 unsigned border_width, depth;
(...skipping 21 matching lines...) Expand all
268 return false; 313 return false;
269 314
270 if (children) 315 if (children)
271 XFree(children); 316 XFree(children);
272 317
273 *parent_is_root = root_window == *parent_window; 318 *parent_is_root = root_window == *parent_window;
274 return true; 319 return true;
275 } 320 }
276 321
277 } // namespace x11_util 322 } // namespace x11_util
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/resource_message_filter_gtk.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698