summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/dock_info_gtk.cc25
-rw-r--r--chrome/common/gtk_util.cc17
-rw-r--r--chrome/common/gtk_util.h13
-rw-r--r--chrome/common/x11_util.cc24
-rw-r--r--chrome/common/x11_util.h12
5 files changed, 49 insertions, 42 deletions
diff --git a/chrome/browser/dock_info_gtk.cc b/chrome/browser/dock_info_gtk.cc
index e55022b..c54e4ba 100644
--- a/chrome/browser/dock_info_gtk.cc
+++ b/chrome/browser/dock_info_gtk.cc
@@ -12,14 +12,14 @@
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/gtk/browser_window_gtk.h"
-#include "chrome/common/x11_util.h"
+#include "chrome/common/gtk_util.h"
////////////////////////////////////////////////////////////////////////////////
// BaseWindowFinder
//
// Base class used to locate a window. A subclass need only override
// ShouldStopIterating to determine when iteration should stop.
-class BaseWindowFinder : public x11_util::EnumerateWindowsDelegate {
+class BaseWindowFinder : public gtk_util::EnumerateWindowsDelegate {
public:
explicit BaseWindowFinder(const std::set<GtkWidget*>& ignore) {
std::set<GtkWidget*>::iterator iter;
@@ -32,9 +32,14 @@ class BaseWindowFinder : public x11_util::EnumerateWindowsDelegate {
virtual ~BaseWindowFinder() {}
protected:
+ // Returns true if |window| is in the ignore list.
+ bool ShouldIgnoreWindow(XID window) {
+ return (ignore_.find(window) != ignore_.end());
+ }
+
// Returns true if iteration should stop, false otherwise.
virtual bool ShouldStopIterating(XID window) {
- return (ignore_.find(window) != ignore_.end());
+ return false;
}
private:
@@ -61,8 +66,8 @@ class TopMostFinder : public BaseWindowFinder {
protected:
virtual bool ShouldStopIterating(XID window) {
- if (BaseWindowFinder::ShouldStopIterating(window))
- return true;
+ if (BaseWindowFinder::ShouldIgnoreWindow(window))
+ return false;
if (window == target_) {
// Window is topmost, stop iterating.
@@ -95,8 +100,7 @@ class TopMostFinder : public BaseWindowFinder {
target_(window),
screen_loc_(screen_loc),
is_top_most_(false) {
- XID root = x11_util::GetX11RootWindow();
- x11_util::EnumerateChildWindows(root, this);
+ gtk_util::EnumerateChildWindows(this);
}
// The window we're looking for.
@@ -134,8 +138,8 @@ class LocalProcessWindowFinder : public BaseWindowFinder {
protected:
virtual bool ShouldStopIterating(XID window) {
- if (BaseWindowFinder::ShouldStopIterating(window))
- return true;
+ if (BaseWindowFinder::ShouldIgnoreWindow(window))
+ return false;
// Check if this window is in our process.
if (!BrowserWindowGtk::GetBrowserWindowForXID(window))
@@ -159,8 +163,7 @@ class LocalProcessWindowFinder : public BaseWindowFinder {
: BaseWindowFinder(ignore),
screen_loc_(screen_loc),
result_(0) {
- XID root = x11_util::GetX11RootWindow();
- x11_util::EnumerateChildWindows(root, this);
+ gtk_util::EnumerateChildWindows(this);
}
// Position of the mouse.
diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc
index c3369d9..95fe87b 100644
--- a/chrome/common/gtk_util.cc
+++ b/chrome/common/gtk_util.cc
@@ -5,6 +5,7 @@
#include "chrome/common/gtk_util.h"
#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
#include "base/linux_util.h"
#include "base/logging.h"
@@ -164,4 +165,20 @@ bool IsScreenComposited() {
return gdk_screen_is_composited(screen) == TRUE;
}
+void EnumerateChildWindows(EnumerateWindowsDelegate* delegate) {
+ GdkScreen* screen = gdk_screen_get_default();
+ GList* stack = gdk_screen_get_window_stack(screen);
+ DCHECK(stack);
+
+ for (GList* iter = g_list_last(stack); iter; iter = iter->prev) {
+ GdkWindow* window = static_cast<GdkWindow*>(iter->data);
+ XID xid = GDK_WINDOW_XID(window);
+ if (delegate->ShouldStopIterating(xid))
+ break;
+ }
+
+ g_list_foreach(stack, (GFunc)g_object_unref, NULL);
+ g_list_free(stack);
+}
+
} // namespace gtk_util
diff --git a/chrome/common/gtk_util.h b/chrome/common/gtk_util.h
index 4f42380..52629d3 100644
--- a/chrome/common/gtk_util.h
+++ b/chrome/common/gtk_util.h
@@ -10,6 +10,7 @@
#include "base/gfx/point.h"
#include "base/gfx/rect.h"
+#include "chrome/common/x11_util.h"
#include "webkit/glue/window_open_disposition.h"
typedef struct _GtkWidget GtkWidget;
@@ -79,6 +80,18 @@ std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label);
// Returns true if the screen is composited, false otherwise.
bool IsScreenComposited();
+// Implementers of this interface receive a notification for every top-level
+// gdk window of the current display.
+class EnumerateWindowsDelegate {
+ public:
+ // |xid| is the X Window ID of the enumerated window. Return true to stop
+ // further iteration.
+ virtual bool ShouldStopIterating(XID xid) = 0;
+};
+
+// Enumerates the top-level gdk windows of the current display.
+void EnumerateChildWindows(EnumerateWindowsDelegate* delegate);
+
} // namespace gtk_util
#endif // CHROME_COMMON_GTK_UTIL_H_
diff --git a/chrome/common/x11_util.cc b/chrome/common/x11_util.cc
index b1a24bf..522921f 100644
--- a/chrome/common/x11_util.cc
+++ b/chrome/common/x11_util.cc
@@ -144,34 +144,20 @@ bool IsWindowVisible(XID window) {
}
bool GetWindowRect(XID window, gfx::Rect* rect) {
- Window root_window;
+ Window root, child;
int x, y;
unsigned int width, height;
unsigned int border_width, depth;
- if (!XGetGeometry(GetXDisplay(), window, &root_window, &x, &y,
+ if (!XGetGeometry(GetXDisplay(), window, &root, &x, &y,
&width, &height, &border_width, &depth))
return false;
- *rect = gfx::Rect(x, y, width, height);
- return true;
-}
-
-bool EnumerateChildWindows(XID root, EnumerateWindowsDelegate* delegate) {
- XID parent;
- XID* children;
- unsigned int num_children;
- int status = XQueryTree(GetXDisplay(), root, &root, &parent,
- &children, &num_children);
- if (status == 0)
+ if (!XTranslateCoordinates(GetSecondaryDisplay(), window, root,
+ 0, 0, &x, &y, &child))
return false;
- for (unsigned int i = 0; i < num_children; i++) {
- if (delegate->ShouldStopIterating(children[i]))
- break;
- }
-
- XFree(children);
+ *rect = gfx::Rect(x, y, width, height);
return true;
}
diff --git a/chrome/common/x11_util.h b/chrome/common/x11_util.h
index d177800..012b020 100644
--- a/chrome/common/x11_util.h
+++ b/chrome/common/x11_util.h
@@ -60,18 +60,6 @@ bool IsWindowVisible(XID window);
// Returns the bounds of |window|.
bool GetWindowRect(XID window, gfx::Rect* rect);
-// Implementers of this interface receive a notification for every X window of
-// the main display.
-class EnumerateWindowsDelegate {
- public:
- // |xid| is the X Window ID of the enumerated window. Return true to stop
- // further iteration.
- virtual bool ShouldStopIterating(XID xid) = 0;
-};
-
-// Enumerates the child windows of |root|.
-bool EnumerateChildWindows(XID root, EnumerateWindowsDelegate* delegate);
-
// Return a handle to a server side pixmap. |shared_memory_key| is a SysV
// IPC key. The shared memory region must contain 32-bit pixels.
XID AttachSharedMemory(Display* display, int shared_memory_support);