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 "ui/base/x/root_window_property_watcher_x.h" |
| 6 |
| 7 #include <gdk/gdk.h> |
| 8 #include <gdk/gdkx.h> |
| 9 |
| 10 #include "ui/base/x/active_window_watcher_x.h" |
| 11 #include "ui/base/x/work_area_watcher_x.h" |
| 12 |
| 13 namespace ui { |
| 14 |
| 15 namespace internal { |
| 16 |
| 17 // static |
| 18 RootWindowPropertyWatcherX* RootWindowPropertyWatcherX::GetInstance() { |
| 19 return Singleton<RootWindowPropertyWatcherX>::get(); |
| 20 } |
| 21 |
| 22 RootWindowPropertyWatcherX::RootWindowPropertyWatcherX() { |
| 23 GdkWindow* root = gdk_get_default_root_window(); |
| 24 |
| 25 // Set up X Event filter to listen for PropertyChange X events. |
| 26 // Don't use XSelectInput directly here, as gdk internally seems to cache the |
| 27 // mask and reapply XSelectInput after this, resetting any mask we set here. |
| 28 gdk_window_set_events(root, |
| 29 static_cast<GdkEventMask>(gdk_window_get_events(root) | |
| 30 GDK_PROPERTY_CHANGE_MASK)); |
| 31 gdk_window_add_filter(root, |
| 32 &RootWindowPropertyWatcherX::OnWindowXEventThunk, |
| 33 this); |
| 34 } |
| 35 |
| 36 RootWindowPropertyWatcherX::~RootWindowPropertyWatcherX() { |
| 37 gdk_window_remove_filter(NULL, |
| 38 &RootWindowPropertyWatcherX::OnWindowXEventThunk, |
| 39 this); |
| 40 } |
| 41 |
| 42 GdkFilterReturn RootWindowPropertyWatcherX::OnWindowXEvent( |
| 43 GdkXEvent* xevent, GdkEvent* event) { |
| 44 XEvent* xev = static_cast<XEvent*>(xevent); |
| 45 |
| 46 if (xev->xany.type == PropertyNotify) { |
| 47 if (xev->xproperty.atom == ActiveWindowWatcherX::GetPropertyAtom()) |
| 48 ActiveWindowWatcherX::Notify(); |
| 49 else if (xev->xproperty.atom == WorkAreaWatcherX::GetPropertyAtom()) |
| 50 WorkAreaWatcherX::Notify(); |
| 51 } |
| 52 |
| 53 return GDK_FILTER_CONTINUE; |
| 54 } |
| 55 |
| 56 } // namespace internal |
| 57 |
| 58 } // namespace ui |
OLD | NEW |