OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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. |
| 4 |
| 5 #include "chrome/browser/fullscreen.h" |
| 6 |
| 7 #include <gdk/gdk.h> |
| 8 #include <gdk/gdkx.h> |
| 9 |
| 10 #include <algorithm> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/basictypes.h" |
| 14 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 15 #include "gfx/rect.h" |
| 16 #include "ui/base/x/x11_util.h" |
| 17 |
| 18 namespace { |
| 19 |
| 20 class TopMostWindowFinder : public ui::EnumerateWindowsDelegate { |
| 21 public: |
| 22 TopMostWindowFinder() |
| 23 : top_most_window_(None) {} |
| 24 |
| 25 XID top_most_window() const { return top_most_window_; } |
| 26 |
| 27 protected: |
| 28 virtual bool ShouldStopIterating(XID window) { |
| 29 if (!ui::IsWindowVisible(window)) |
| 30 return false; |
| 31 top_most_window_ = window; |
| 32 return true; |
| 33 } |
| 34 |
| 35 private: |
| 36 XID top_most_window_; |
| 37 |
| 38 DISALLOW_COPY_AND_ASSIGN(TopMostWindowFinder); |
| 39 }; |
| 40 |
| 41 bool IsTopMostWindowFullScreen() { |
| 42 // Find the topmost window. |
| 43 TopMostWindowFinder finder; |
| 44 gtk_util::EnumerateTopLevelWindows(&finder); |
| 45 XID window = finder.top_most_window(); |
| 46 if (window == None) |
| 47 return false; |
| 48 |
| 49 // Make sure it is not the desktop window. |
| 50 static Atom atom = gdk_x11_get_xatom_by_name_for_display( |
| 51 gdk_display_get_default(), "_NET_WM_WINDOW_TYPE_DESKTOP"); |
| 52 |
| 53 std::vector<Atom> atom_properties; |
| 54 if (ui::GetAtomArrayProperty(window, |
| 55 "_NET_WM_WINDOW_TYPE", |
| 56 &atom_properties) && |
| 57 std::find(atom_properties.begin(), atom_properties.end(), atom) |
| 58 != atom_properties.end()) |
| 59 return false; |
| 60 |
| 61 // If it is a GDK window, check it using gdk function. |
| 62 GdkWindow* gwindow = gdk_window_lookup(window); |
| 63 if (gwindow && window != GDK_ROOT_WINDOW()) |
| 64 return gdk_window_get_state(gwindow) == GDK_WINDOW_STATE_FULLSCREEN; |
| 65 |
| 66 // Otherwise, do the check via xlib function. |
| 67 return ui::IsX11WindowFullScreen(window); |
| 68 } |
| 69 |
| 70 } |
| 71 |
| 72 bool IsFullScreenMode() { |
| 73 gdk_error_trap_push(); |
| 74 bool result = IsTopMostWindowFullScreen(); |
| 75 bool got_error = gdk_error_trap_pop(); |
| 76 return result && !got_error; |
| 77 } |
OLD | NEW |