Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: ui/base/x/active_window_watcher_x.cc

Issue 7981030: aura: Have aura and aura_demo build and run without gtk on linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/x/active_window_watcher_x.h"
6
5 #include <X11/Xlib.h> 7 #include <X11/Xlib.h>
8
9 #include "ui/base/x/x11_util.h"
10
11 #if defined(TOOLKIT_USES_GTK)
Daniel Erat 2011/09/21 20:27:08 nit: move this above the x11_util.h include
sadrul 2011/09/21 21:56:18 I just realized that this file shouldn't be necess
6 #include <gdk/gdk.h> 12 #include <gdk/gdk.h>
7 #include <gdk/gdkx.h> 13 #include <gdk/gdkx.h>
8 14 #endif
9 #include "ui/base/x/active_window_watcher_x.h"
10 15
11 namespace ui { 16 namespace ui {
12 17
13 static Atom g_net_active_window_atom = None; 18 static Atom g_net_active_window_atom = None;
14 19
15 // static 20 // static
16 ActiveWindowWatcherX* ActiveWindowWatcherX::GetInstance() { 21 ActiveWindowWatcherX* ActiveWindowWatcherX::GetInstance() {
17 return Singleton<ActiveWindowWatcherX>::get(); 22 return Singleton<ActiveWindowWatcherX>::get();
18 } 23 }
19 24
20 // static 25 // static
21 void ActiveWindowWatcherX::AddObserver(Observer* observer) { 26 void ActiveWindowWatcherX::AddObserver(Observer* observer) {
22 GetInstance()->observers_.AddObserver(observer); 27 GetInstance()->observers_.AddObserver(observer);
23 } 28 }
24 29
25 // static 30 // static
26 void ActiveWindowWatcherX::RemoveObserver(Observer* observer) { 31 void ActiveWindowWatcherX::RemoveObserver(Observer* observer) {
27 GetInstance()->observers_.RemoveObserver(observer); 32 GetInstance()->observers_.RemoveObserver(observer);
28 } 33 }
29 34
30 // static 35 // static
31 bool ActiveWindowWatcherX::WMSupportsActivation() { 36 bool ActiveWindowWatcherX::WMSupportsActivation() {
37 #if defined(TOOLKIT_USES_GTK)
32 return gdk_x11_screen_supports_net_wm_hint( 38 return gdk_x11_screen_supports_net_wm_hint(
33 gdk_screen_get_default(), 39 gdk_screen_get_default(),
34 gdk_atom_intern_static_string("_NET_ACTIVE_WINDOW")); 40 gdk_atom_intern_static_string("_NET_ACTIVE_WINDOW"));
41 #else
42 NOTIMPLEMENTED();
43 return false;
Daniel Erat 2011/09/21 20:27:08 true may be a better default for us; WMs that don'
44 #endif
35 } 45 }
36 46
37 ActiveWindowWatcherX::ActiveWindowWatcherX() { 47 ActiveWindowWatcherX::ActiveWindowWatcherX() {
38 Init(); 48 Init();
39 } 49 }
40 50
41 ActiveWindowWatcherX::~ActiveWindowWatcherX() { 51 ActiveWindowWatcherX::~ActiveWindowWatcherX() {
42 } 52 }
43 53
44 void ActiveWindowWatcherX::Init() { 54 void ActiveWindowWatcherX::Init() {
55 #if defined(TOOLKIT_USES_GTK)
45 GdkAtom net_active_window = 56 GdkAtom net_active_window =
46 gdk_atom_intern_static_string("_NET_ACTIVE_WINDOW"); 57 gdk_atom_intern_static_string("_NET_ACTIVE_WINDOW");
47 g_net_active_window_atom = gdk_x11_atom_to_xatom_for_display( 58 g_net_active_window_atom = gdk_x11_atom_to_xatom_for_display(
48 gdk_screen_get_display(gdk_screen_get_default()), net_active_window); 59 gdk_screen_get_display(gdk_screen_get_default()), net_active_window);
49 60
50 GdkWindow* root = gdk_get_default_root_window(); 61 GdkWindow* root = gdk_get_default_root_window();
51 62
52 // Set up X Event filter to listen for PropertyChange X events. These events 63 // Set up X Event filter to listen for PropertyChange X events. These events
53 // tell us when the active window changes. 64 // tell us when the active window changes.
54 // Don't use XSelectInput directly here, as gdk internally seems to cache the 65 // Don't use XSelectInput directly here, as gdk internally seems to cache the
55 // mask and reapply XSelectInput after this, resetting any mask we set here. 66 // mask and reapply XSelectInput after this, resetting any mask we set here.
56 gdk_window_set_events(root, 67 gdk_window_set_events(root,
57 static_cast<GdkEventMask>(gdk_window_get_events(root) | 68 static_cast<GdkEventMask>(gdk_window_get_events(root) |
58 GDK_PROPERTY_CHANGE_MASK)); 69 GDK_PROPERTY_CHANGE_MASK));
59 gdk_window_add_filter(NULL, &ActiveWindowWatcherX::OnWindowXEventThunk, this); 70 gdk_window_add_filter(NULL, &ActiveWindowWatcherX::OnWindowXEventThunk, this);
71 #endif
60 } 72 }
61 73
62 void ActiveWindowWatcherX::NotifyActiveWindowChanged() { 74 void ActiveWindowWatcherX::NotifyActiveWindowChanged() {
63 // We don't use gdk_screen_get_active_window() because it caches 75 // We don't use gdk_screen_get_active_window() because it caches
64 // whether or not the window manager supports _NET_ACTIVE_WINDOW. 76 // whether or not the window manager supports _NET_ACTIVE_WINDOW.
65 // This causes problems at startup for chromiumos. 77 // This causes problems at startup for chromiumos.
66 Atom type = None; 78 Atom type = None;
67 int format = 0; // size in bits of each item in 'property' 79 int format = 0; // size in bits of each item in 'property'
68 long unsigned int num_items = 0, remaining_bytes = 0; 80 long unsigned int num_items = 0, remaining_bytes = 0;
69 unsigned char* property = NULL; 81 unsigned char* property = NULL;
70 82
71 XGetWindowProperty(gdk_x11_get_default_xdisplay(), 83 XGetWindowProperty(GetXDisplay(),
72 GDK_WINDOW_XID(gdk_get_default_root_window()), 84 GetX11RootWindow(),
73 g_net_active_window_atom, 85 g_net_active_window_atom,
74 0, // offset into property data to read 86 0, // offset into property data to read
75 1, // length to get in 32-bit quantities 87 1, // length to get in 32-bit quantities
76 False, // deleted 88 False, // deleted
77 AnyPropertyType, 89 AnyPropertyType,
78 &type, 90 &type,
79 &format, 91 &format,
80 &num_items, 92 &num_items,
81 &remaining_bytes, 93 &remaining_bytes,
82 &property); 94 &property);
83 95
96 #if defined(TOOLKIT_USES_GTK)
84 // Check that the property was set and contained a single 32-bit item (we 97 // Check that the property was set and contained a single 32-bit item (we
85 // don't check that remaining_bytes is 0, though, as XFCE's window manager 98 // don't check that remaining_bytes is 0, though, as XFCE's window manager
86 // seems to actually store two values in the property for some unknown 99 // seems to actually store two values in the property for some unknown
87 // reason.) 100 // reason.)
88 if (format == 32 && num_items == 1) { 101 if (format == 32 && num_items == 1) {
89 int xid = *reinterpret_cast<int*>(property); 102 int xid = *reinterpret_cast<int*>(property);
90 GdkWindow* active_window = gdk_window_lookup(xid); 103 GdkWindow* active_window = gdk_window_lookup(xid);
91 FOR_EACH_OBSERVER( 104 FOR_EACH_OBSERVER(
Daniel Erat 2011/09/21 20:27:08 ifdef-ing this out essentially makes this class do
92 Observer, 105 Observer,
93 observers_, 106 observers_,
94 ActiveWindowChanged(active_window)); 107 ActiveWindowChanged(active_window));
95 } 108 }
109 #endif
110
96 if (property) 111 if (property)
97 XFree(property); 112 XFree(property);
98 } 113 }
99 114
115 #if defined(TOOLKIT_USES_GTK)
100 GdkFilterReturn ActiveWindowWatcherX::OnWindowXEvent(GdkXEvent* xevent, 116 GdkFilterReturn ActiveWindowWatcherX::OnWindowXEvent(GdkXEvent* xevent,
101 GdkEvent* event) { 117 GdkEvent* event) {
102 XEvent* xev = static_cast<XEvent*>(xevent); 118 XEvent* xev = static_cast<XEvent*>(xevent);
103 119
104 if (xev->xany.type == PropertyNotify && 120 if (xev->xany.type == PropertyNotify &&
105 xev->xproperty.atom == g_net_active_window_atom) { 121 xev->xproperty.atom == g_net_active_window_atom) {
106 NotifyActiveWindowChanged(); 122 NotifyActiveWindowChanged();
107 } 123 }
108 124
109 return GDK_FILTER_CONTINUE; 125 return GDK_FILTER_CONTINUE;
110 } 126 }
127 #endif
111 128
112 } // namespace ui 129 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/x/active_window_watcher_x.h ('k') | ui/base/x/x11_util.h » ('j') | ui/base/x/x11_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698