diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/x11_util.cc | 25 | ||||
-rw-r--r-- | app/x11_util.h | 7 |
2 files changed, 30 insertions, 2 deletions
diff --git a/app/x11_util.cc b/app/x11_util.cc index 934e824..101815a 100644 --- a/app/x11_util.cc +++ b/app/x11_util.cc @@ -159,6 +159,10 @@ XID GetX11RootWindow() { return GDK_WINDOW_XID(gdk_get_default_root_window()); } +bool GetCurrentDesktop(int* desktop) { + return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop); +} + XID GetX11WindowFromGtkWidget(GtkWidget* widget) { return GDK_WINDOW_XID(widget->window); } @@ -192,7 +196,15 @@ int BitsPerPixelForPixmapDepth(Display* dpy, int depth) { bool IsWindowVisible(XID window) { XWindowAttributes win_attributes; XGetWindowAttributes(GetXDisplay(), window, &win_attributes); - return (win_attributes.map_state == IsViewable); + if (win_attributes.map_state != IsViewable) + return false; + // Some compositing window managers (notably kwin) do not actually unmap + // windows on desktop switch, so we also must check the current desktop. + int window_desktop, current_desktop; + return (!GetWindowDesktop(window, &window_desktop) || + !GetCurrentDesktop(¤t_desktop) || + window_desktop == kAllDesktops || + window_desktop == current_desktop); } bool GetWindowRect(XID window, gfx::Rect* rect) { @@ -342,6 +354,10 @@ XID GetHighestAncestorWindow(XID window, XID root) { } } +bool GetWindowDesktop(XID window, int* desktop) { + return GetIntProperty(window, "_NET_WM_DESKTOP", desktop); +} + // Returns true if |window| is a named window. bool IsWindowNamed(XID window) { XTextProperty prop; @@ -787,7 +803,12 @@ void GrabWindowSnapshot(GtkWindow* gtk_window, bool ChangeWindowDesktop(XID window, XID destination) { int desktop; - if (!GetIntProperty(destination, "_NET_WM_DESKTOP", &desktop)) + if (!GetWindowDesktop(destination, &desktop)) + return false; + + // If |window| is sticky, use the current desktop. + if (desktop == kAllDesktops && + !GetCurrentDesktop(&desktop)) return false; XEvent event; diff --git a/app/x11_util.h b/app/x11_util.h index b85061c..62881f0 100644 --- a/app/x11_util.h +++ b/app/x11_util.h @@ -66,6 +66,8 @@ int GetDefaultScreen(Display* display); // Get the X window id for the default root window XID GetX11RootWindow(); +// Returns the user's current desktop. +bool GetCurrentDesktop(int* desktop); // Get the X window id for the given GTK widget. XID GetX11WindowFromGtkWidget(GtkWidget* widget); XID GetX11WindowFromGdkWindow(GdkWindow* window); @@ -92,6 +94,11 @@ XID GetParentWindow(XID window); // Walk up |window|'s hierarchy until we find a direct child of |root|. XID GetHighestAncestorWindow(XID window, XID root); +static const int kAllDesktops = -1; +// Queries the desktop |window| is on, kAllDesktops if sticky. Returns false if +// property not found. +bool GetWindowDesktop(XID window, int* desktop); + // Implementers of this interface receive a notification for every X window of // the main display. class EnumerateWindowsDelegate { |