1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/base/gtk/gtk_screen_util.h"
#include "base/logging.h"
namespace ui {
bool IsScreenComposited() {
GdkScreen* screen = gdk_screen_get_default();
return gdk_screen_is_composited(screen) == TRUE;
}
gfx::Point ScreenPoint(GtkWidget* widget) {
int x, y;
gdk_display_get_pointer(gtk_widget_get_display(widget), NULL, &x, &y,
NULL);
return gfx::Point(x, y);
}
gfx::Point ClientPoint(GtkWidget* widget) {
int x, y;
gtk_widget_get_pointer(widget, &x, &y);
return gfx::Point(x, y);
}
gfx::Point GetWidgetScreenPosition(GtkWidget* widget) {
GdkWindow* window = gtk_widget_get_window(widget);
if (!window) {
NOTREACHED() << "Must only be called on realized widgets.";
return gfx::Point(0, 0);
}
gint x, y;
gdk_window_get_origin(window, &x, &y);
if (!gtk_widget_get_has_window(widget)) {
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
x += allocation.x;
y += allocation.y;
}
return gfx::Point(x, y);
}
gfx::Rect GetWidgetScreenBounds(GtkWidget* widget) {
gfx::Point position = GetWidgetScreenPosition(widget);
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
return gfx::Rect(position.x(), position.y(),
allocation.width, allocation.height);
}
} // namespace ui
|