Browse Source

Make WindowStateWatcher X11 only

On Windows we need to take another way of detecting window state events.
Cheng Zhao 10 years ago
parent
commit
588cc3c7ab

+ 2 - 2
atom.gyp

@@ -175,12 +175,12 @@
       'atom/browser/ui/views/submenu_button.h',
       'atom/browser/ui/views/win_frame_view.cc',
       'atom/browser/ui/views/win_frame_view.h',
-      'atom/browser/ui/views/window_state_watcher.cc',
-      'atom/browser/ui/views/window_state_watcher.h',
       'atom/browser/ui/win/notify_icon_host.cc',
       'atom/browser/ui/win/notify_icon_host.h',
       'atom/browser/ui/win/notify_icon.cc',
       'atom/browser/ui/win/notify_icon.h',
+      'atom/browser/ui/x/window_state_watcher.cc',
+      'atom/browser/ui/x/window_state_watcher.h',
       'atom/browser/ui/x/x_window_utils.cc',
       'atom/browser/ui/x/x_window_utils.h',
       'atom/browser/web_view/web_view_manager.cc',

+ 2 - 2
atom/browser/native_window_views.cc

@@ -13,7 +13,6 @@
 
 #include "atom/browser/ui/views/menu_bar.h"
 #include "atom/browser/ui/views/menu_layout.h"
-#include "atom/browser/ui/views/window_state_watcher.h"
 #include "atom/common/draggable_region.h"
 #include "atom/common/options_switches.h"
 #include "base/strings/utf_string_conversions.h"
@@ -33,6 +32,7 @@
 #include "atom/browser/browser.h"
 #include "atom/browser/ui/views/global_menu_bar_x11.h"
 #include "atom/browser/ui/views/frameless_view.h"
+#include "atom/browser/ui/x/window_state_watcher.h"
 #include "atom/browser/ui/x/x_window_utils.h"
 #include "base/environment.h"
 #include "base/nix/xdg_util.h"
@@ -189,10 +189,10 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
 
   window_->Init(params);
 
+#if defined(USE_X11)
   // Start monitoring window states.
   window_state_watcher_.reset(new WindowStateWatcher(this));
 
-#if defined(USE_X11)
   // Set _GTK_THEME_VARIANT to dark if we have "dark-theme" option set.
   bool use_dark_theme = false;
   if (options.Get(switches::kDarkTheme, &use_dark_theme) && use_dark_theme) {

+ 1 - 1
atom/browser/native_window_views.h

@@ -145,10 +145,10 @@ class NativeWindowViews : public NativeWindow,
 
 #if defined(USE_X11)
   scoped_ptr<GlobalMenuBarX11> global_menu_bar_;
-#endif
 
   // Handles window state events.
   scoped_ptr<WindowStateWatcher> window_state_watcher_;
+#endif
 
   // Handles unhandled keyboard messages coming back from the renderer process.
   scoped_ptr<views::UnhandledKeyboardEventHandler> keyboard_event_handler_;

+ 1 - 9
atom/browser/ui/views/window_state_watcher.cc → atom/browser/ui/x/window_state_watcher.cc

@@ -2,11 +2,9 @@
 // Use of this source code is governed by the MIT license that can be
 // found in the LICENSE file.
 
-#include "atom/browser/ui/views/window_state_watcher.h"
+#include "atom/browser/ui/x/window_state_watcher.h"
 
-#if defined(USE_X11)
 #include <X11/Xlib.h>
-#endif
 
 #include "ui/events/platform/platform_event_source.h"
 
@@ -24,9 +22,7 @@ const char* kAtomsToCache[] = {
 WindowStateWatcher::WindowStateWatcher(NativeWindowViews* window)
     : window_(window),
       widget_(window->GetAcceleratedWidget()),
-#if defined(USE_X11)
       atom_cache_(gfx::GetXDisplay(), kAtomsToCache),
-#endif
       was_minimized_(false),
       was_maximized_(false) {
   ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this);
@@ -73,14 +69,10 @@ void WindowStateWatcher::DidProcessEvent(const ui::PlatformEvent& event) {
 }
 
 bool WindowStateWatcher::IsWindowStateEvent(const ui::PlatformEvent& event) {
-#if defined(USE_X11)
   ::Atom changed_atom = event->xproperty.atom;
   return (changed_atom == atom_cache_.GetAtom("_NET_WM_STATE") &&
           event->type == PropertyNotify &&
           event->xproperty.window == widget_);
-#else
-  return false;
-#endif
 }
 
 }  // namespace atom

+ 5 - 5
atom/browser/ui/views/window_state_watcher.h → atom/browser/ui/x/window_state_watcher.h

@@ -2,13 +2,13 @@
 // Use of this source code is governed by the MIT license that can be
 // found in the LICENSE file.
 
+#ifndef ATOM_BROWSER_UI_X_WINDOW_STATE_WATCHER_H_
+#define ATOM_BROWSER_UI_X_WINDOW_STATE_WATCHER_H_
+
 #include "ui/events/platform/platform_event_observer.h"
 
 #include "atom/browser/native_window_views.h"
-
-#if defined(USE_X11)
 #include "ui/gfx/x/x11_atom_cache.h"
-#endif
 
 namespace atom {
 
@@ -28,9 +28,7 @@ class WindowStateWatcher : public ui::PlatformEventObserver {
   NativeWindowViews* window_;
   gfx::AcceleratedWidget widget_;
 
-#if defined(USE_X11)
   ui::X11AtomCache atom_cache_;
-#endif
 
   bool was_minimized_;
   bool was_maximized_;
@@ -39,3 +37,5 @@ class WindowStateWatcher : public ui::PlatformEventObserver {
 };
 
 }  // namespace atom
+
+#endif  // ATOM_BROWSER_UI_X_WINDOW_STATE_WATCHER_H_