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 // 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 "ui/base/x/x11_util.h" | 9 #include "ui/base/x/x11_util.h" |
10 | 10 |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 memcpy(image->pixels, | 446 memcpy(image->pixels, |
447 bitmap->getPixels(), | 447 bitmap->getPixels(), |
448 bitmap->width() * bitmap->height() * 4); | 448 bitmap->width() * bitmap->height() * 4); |
449 bitmap->unlockPixels(); | 449 bitmap->unlockPixels(); |
450 } | 450 } |
451 | 451 |
452 return image; | 452 return image; |
453 } | 453 } |
454 #endif | 454 #endif |
455 | 455 |
| 456 void HideHostCursor() { |
| 457 CR_DEFINE_STATIC_LOCAL(XScopedCursor, invisible_cursor, |
| 458 (CreateInvisibleCursor(), ui::GetXDisplay())); |
| 459 XDefineCursor(ui::GetXDisplay(), DefaultRootWindow(ui::GetXDisplay()), |
| 460 invisible_cursor.get()); |
| 461 } |
| 462 |
| 463 ::Cursor CreateInvisibleCursor() { |
| 464 Display* xdisplay = ui::GetXDisplay(); |
| 465 ::Cursor invisible_cursor; |
| 466 char nodata[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 467 XColor black; |
| 468 black.red = black.green = black.blue = 0; |
| 469 Pixmap blank = XCreateBitmapFromData(xdisplay, |
| 470 DefaultRootWindow(xdisplay), |
| 471 nodata, 8, 8); |
| 472 invisible_cursor = XCreatePixmapCursor(xdisplay, blank, blank, |
| 473 &black, &black, 0, 0); |
| 474 XFreePixmap(xdisplay, blank); |
| 475 return invisible_cursor; |
| 476 } |
| 477 |
456 XID GetX11RootWindow() { | 478 XID GetX11RootWindow() { |
457 return DefaultRootWindow(GetXDisplay()); | 479 return DefaultRootWindow(GetXDisplay()); |
458 } | 480 } |
459 | 481 |
460 bool GetCurrentDesktop(int* desktop) { | 482 bool GetCurrentDesktop(int* desktop) { |
461 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop); | 483 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop); |
462 } | 484 } |
463 | 485 |
464 #if defined(TOOLKIT_GTK) | 486 #if defined(TOOLKIT_GTK) |
465 XID GetX11WindowFromGtkWidget(GtkWidget* widget) { | 487 XID GetX11WindowFromGtkWidget(GtkWidget* widget) { |
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1345 key_event.keycode = XKeyEventKeyCode(key_code, flags, display); | 1367 key_event.keycode = XKeyEventKeyCode(key_code, flags, display); |
1346 key_event.same_screen = 1; | 1368 key_event.same_screen = 1; |
1347 event->type = key_event.type; | 1369 event->type = key_event.type; |
1348 event->xkey = key_event; | 1370 event->xkey = key_event; |
1349 } | 1371 } |
1350 | 1372 |
1351 XScopedString::~XScopedString() { | 1373 XScopedString::~XScopedString() { |
1352 XFree(string_); | 1374 XFree(string_); |
1353 } | 1375 } |
1354 | 1376 |
| 1377 XScopedCursor::XScopedCursor(::Cursor cursor, Display* display) |
| 1378 : cursor_(cursor), |
| 1379 display_(display) { |
| 1380 } |
| 1381 |
| 1382 XScopedCursor::~XScopedCursor() { |
| 1383 reset(0U); |
| 1384 } |
| 1385 |
| 1386 ::Cursor XScopedCursor::get() const { |
| 1387 return cursor_; |
| 1388 } |
| 1389 |
| 1390 void XScopedCursor::reset(::Cursor cursor) { |
| 1391 if (cursor_) |
| 1392 XFreeCursor(display_, cursor_); |
| 1393 cursor_ = cursor; |
| 1394 } |
| 1395 |
1355 // ---------------------------------------------------------------------------- | 1396 // ---------------------------------------------------------------------------- |
1356 // These functions are declared in x11_util_internal.h because they require | 1397 // These functions are declared in x11_util_internal.h because they require |
1357 // XLib.h to be included, and it conflicts with many other headers. | 1398 // XLib.h to be included, and it conflicts with many other headers. |
1358 XRenderPictFormat* GetRenderARGB32Format(Display* dpy) { | 1399 XRenderPictFormat* GetRenderARGB32Format(Display* dpy) { |
1359 static XRenderPictFormat* pictformat = NULL; | 1400 static XRenderPictFormat* pictformat = NULL; |
1360 if (pictformat) | 1401 if (pictformat) |
1361 return pictformat; | 1402 return pictformat; |
1362 | 1403 |
1363 // First look for a 32-bit format which ignores the alpha value | 1404 // First look for a 32-bit format which ignores the alpha value |
1364 XRenderPictFormat templ; | 1405 XRenderPictFormat templ; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1516 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1476 << "minor_code " << static_cast<int>(error_event.minor_code) | 1517 << "minor_code " << static_cast<int>(error_event.minor_code) |
1477 << " (" << request_str << ")"; | 1518 << " (" << request_str << ")"; |
1478 } | 1519 } |
1479 | 1520 |
1480 // ---------------------------------------------------------------------------- | 1521 // ---------------------------------------------------------------------------- |
1481 // End of x11_util_internal.h | 1522 // End of x11_util_internal.h |
1482 | 1523 |
1483 | 1524 |
1484 } // namespace ui | 1525 } // namespace ui |
OLD | NEW |