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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 #include <sys/sysctl.h> | 54 #include <sys/sysctl.h> |
55 #include <sys/types.h> | 55 #include <sys/types.h> |
56 #endif | 56 #endif |
57 | 57 |
58 #if defined(USE_AURA) | 58 #if defined(USE_AURA) |
59 #include <X11/Xcursor/Xcursor.h> | 59 #include <X11/Xcursor/Xcursor.h> |
60 #include "skia/ext/image_operations.h" | 60 #include "skia/ext/image_operations.h" |
61 #include "ui/gfx/skia_util.h" | 61 #include "ui/gfx/skia_util.h" |
62 #endif | 62 #endif |
63 | 63 |
64 #if defined(TOOLKIT_GTK) | |
65 #include <gdk/gdk.h> | |
66 #include <gtk/gtk.h> | |
67 #include "ui/gfx/gdk_compat.h" | |
68 #include "ui/gfx/gtk_compat.h" | |
69 #endif | |
70 | |
71 namespace ui { | 64 namespace ui { |
72 | 65 |
73 namespace { | 66 namespace { |
74 | 67 |
75 // Used to cache the XRenderPictFormat for a visual/display pair. | 68 // Used to cache the XRenderPictFormat for a visual/display pair. |
76 struct CachedPictFormat { | 69 struct CachedPictFormat { |
77 bool equals(XDisplay* display, Visual* visual) const { | 70 bool equals(XDisplay* display, Visual* visual) const { |
78 return display == this->display && visual == this->visual; | 71 return display == this->display && visual == this->visual; |
79 } | 72 } |
80 | 73 |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 } | 516 } |
524 | 517 |
525 XID GetX11RootWindow() { | 518 XID GetX11RootWindow() { |
526 return DefaultRootWindow(gfx::GetXDisplay()); | 519 return DefaultRootWindow(gfx::GetXDisplay()); |
527 } | 520 } |
528 | 521 |
529 bool GetCurrentDesktop(int* desktop) { | 522 bool GetCurrentDesktop(int* desktop) { |
530 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop); | 523 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop); |
531 } | 524 } |
532 | 525 |
533 #if defined(TOOLKIT_GTK) | |
534 XID GetX11WindowFromGtkWidget(GtkWidget* widget) { | |
535 return GDK_WINDOW_XID(gtk_widget_get_window(widget)); | |
536 } | |
537 | |
538 XID GetX11WindowFromGdkWindow(GdkWindow* window) { | |
539 return GDK_WINDOW_XID(window); | |
540 } | |
541 | |
542 GtkWindow* GetGtkWindowFromX11Window(XID xid) { | |
543 GdkWindow* gdk_window = | |
544 gdk_x11_window_lookup_for_display(gdk_display_get_default(), xid); | |
545 if (!gdk_window) | |
546 return NULL; | |
547 GtkWindow* gtk_window = NULL; | |
548 gdk_window_get_user_data(gdk_window, | |
549 reinterpret_cast<gpointer*>(>k_window)); | |
550 if (!gtk_window) | |
551 return NULL; | |
552 return gtk_window; | |
553 } | |
554 | |
555 void* GetVisualFromGtkWidget(GtkWidget* widget) { | |
556 return GDK_VISUAL_XVISUAL(gtk_widget_get_visual(widget)); | |
557 } | |
558 #endif // defined(TOOLKIT_GTK) | |
559 | |
560 void SetHideTitlebarWhenMaximizedProperty(XID window, | 526 void SetHideTitlebarWhenMaximizedProperty(XID window, |
561 HideTitlebarWhenMaximized property) { | 527 HideTitlebarWhenMaximized property) { |
562 // XChangeProperty() expects "hide" to be long. | 528 // XChangeProperty() expects "hide" to be long. |
563 unsigned long hide = property; | 529 unsigned long hide = property; |
564 XChangeProperty(gfx::GetXDisplay(), | 530 XChangeProperty(gfx::GetXDisplay(), |
565 window, | 531 window, |
566 GetAtom("_GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED"), | 532 GetAtom("_GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED"), |
567 XA_CARDINAL, | 533 XA_CARDINAL, |
568 32, // size in bits | 534 32, // size in bits |
569 PropModeReplace, | 535 PropModeReplace, |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 property, | 932 property, |
967 type, | 933 type, |
968 8, | 934 8, |
969 PropModeReplace, | 935 PropModeReplace, |
970 reinterpret_cast<const unsigned char*>(value.c_str()), | 936 reinterpret_cast<const unsigned char*>(value.c_str()), |
971 value.size()); | 937 value.size()); |
972 return !err_tracker.FoundNewError(); | 938 return !err_tracker.FoundNewError(); |
973 } | 939 } |
974 | 940 |
975 Atom GetAtom(const char* name) { | 941 Atom GetAtom(const char* name) { |
976 #if defined(TOOLKIT_GTK) | |
977 return gdk_x11_get_xatom_by_name_for_display( | |
978 gdk_display_get_default(), name); | |
979 #else | |
980 // TODO(derat): Cache atoms to avoid round-trips to the server. | 942 // TODO(derat): Cache atoms to avoid round-trips to the server. |
981 return XInternAtom(gfx::GetXDisplay(), name, false); | 943 return XInternAtom(gfx::GetXDisplay(), name, false); |
982 #endif | |
983 } | 944 } |
984 | 945 |
985 void SetWindowClassHint(XDisplay* display, | 946 void SetWindowClassHint(XDisplay* display, |
986 XID window, | 947 XID window, |
987 const std::string& res_name, | 948 const std::string& res_name, |
988 const std::string& res_class) { | 949 const std::string& res_class) { |
989 XClassHint class_hints; | 950 XClassHint class_hints; |
990 // const_cast is safe because XSetClassHint does not modify the strings. | 951 // const_cast is safe because XSetClassHint does not modify the strings. |
991 // Just to be safe, the res_name and res_class parameters are local copies, | 952 // Just to be safe, the res_name and res_class parameters are local copies, |
992 // not const references. | 953 // not const references. |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 return std::find(atom_properties.begin(), atom_properties.end(), atom) | 1348 return std::find(atom_properties.begin(), atom_properties.end(), atom) |
1388 != atom_properties.end(); | 1349 != atom_properties.end(); |
1389 } | 1350 } |
1390 } | 1351 } |
1391 } | 1352 } |
1392 | 1353 |
1393 gfx::Rect window_rect; | 1354 gfx::Rect window_rect; |
1394 if (!ui::GetWindowRect(window, &window_rect)) | 1355 if (!ui::GetWindowRect(window, &window_rect)) |
1395 return false; | 1356 return false; |
1396 | 1357 |
1397 #if defined(TOOLKIT_GTK) | |
1398 // As the last resort, check if the window size is as large as the main | |
1399 // screen. | |
1400 GdkRectangle monitor_rect; | |
1401 gdk_screen_get_monitor_geometry(gdk_screen_get_default(), 0, &monitor_rect); | |
1402 | |
1403 return monitor_rect.x == window_rect.x() && | |
1404 monitor_rect.y == window_rect.y() && | |
1405 monitor_rect.width == window_rect.width() && | |
1406 monitor_rect.height == window_rect.height(); | |
1407 #else | |
1408 // We can't use gfx::Screen here because we don't have an aura::Window. So | 1358 // We can't use gfx::Screen here because we don't have an aura::Window. So |
1409 // instead just look at the size of the default display. | 1359 // instead just look at the size of the default display. |
1410 // | 1360 // |
1411 // TODO(erg): Actually doing this correctly would require pulling out xrandr, | 1361 // TODO(erg): Actually doing this correctly would require pulling out xrandr, |
1412 // which we don't even do in the desktop screen yet. | 1362 // which we don't even do in the desktop screen yet. |
1413 ::XDisplay* display = gfx::GetXDisplay(); | 1363 ::XDisplay* display = gfx::GetXDisplay(); |
1414 ::Screen* screen = DefaultScreenOfDisplay(display); | 1364 ::Screen* screen = DefaultScreenOfDisplay(display); |
1415 int width = WidthOfScreen(screen); | 1365 int width = WidthOfScreen(screen); |
1416 int height = HeightOfScreen(screen); | 1366 int height = HeightOfScreen(screen); |
1417 return window_rect.size() == gfx::Size(width, height); | 1367 return window_rect.size() == gfx::Size(width, height); |
1418 #endif | |
1419 } | 1368 } |
1420 | 1369 |
1421 const unsigned char* XRefcountedMemory::front() const { | 1370 const unsigned char* XRefcountedMemory::front() const { |
1422 return x11_data_; | 1371 return x11_data_; |
1423 } | 1372 } |
1424 | 1373 |
1425 size_t XRefcountedMemory::size() const { | 1374 size_t XRefcountedMemory::size() const { |
1426 return length_; | 1375 return length_; |
1427 } | 1376 } |
1428 | 1377 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1537 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1589 << "minor_code " << static_cast<int>(error_event.minor_code) | 1538 << "minor_code " << static_cast<int>(error_event.minor_code) |
1590 << " (" << request_str << ")"; | 1539 << " (" << request_str << ")"; |
1591 } | 1540 } |
1592 | 1541 |
1593 // ---------------------------------------------------------------------------- | 1542 // ---------------------------------------------------------------------------- |
1594 // End of x11_util_internal.h | 1543 // End of x11_util_internal.h |
1595 | 1544 |
1596 | 1545 |
1597 } // namespace ui | 1546 } // namespace ui |
OLD | NEW |