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.
5 #include "ui/base/gtk/gtk_screen_util.h"
7 #include "base/logging.h"
11 bool IsScreenComposited() {
12 GdkScreen* screen = gdk_screen_get_default();
13 return gdk_screen_is_composited(screen) == TRUE;
16 gfx::Point ScreenPoint(GtkWidget* widget) {
18 gdk_display_get_pointer(gtk_widget_get_display(widget), NULL, &x, &y,
20 return gfx::Point(x, y);
23 gfx::Point ClientPoint(GtkWidget* widget) {
25 gtk_widget_get_pointer(widget, &x, &y);
26 return gfx::Point(x, y);
29 gfx::Vector2d GetWidgetScreenOffset(GtkWidget* widget) {
30 GdkWindow* window = gtk_widget_get_window(widget);
33 NOTREACHED() << "Must only be called on realized widgets.";
34 return gfx::Vector2d(0, 0);
38 gdk_window_get_origin(window, &x, &y);
40 if (!gtk_widget_get_has_window(widget)) {
41 GtkAllocation allocation;
42 gtk_widget_get_allocation(widget, &allocation);
47 return gfx::Vector2d(x, y);
50 gfx::Rect GetWidgetScreenBounds(GtkWidget* widget) {
51 GtkAllocation allocation;
52 gtk_widget_get_allocation(widget, &allocation);
54 return gfx::Rect(PointAtOffsetFromOrigin(GetWidgetScreenOffset(widget)),
55 gfx::Size(allocation.width, allocation.height));