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

Side by Side Diff: app/active_window_watcher_x.cc

Issue 6257006: Move a bunch of random other files to src/ui/base... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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
« no previous file with comments | « app/active_window_watcher_x.h ('k') | app/bidi_line_iterator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 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 <X11/Xlib.h>
6 #include <gdk/gdk.h>
7 #include <gdk/gdkx.h>
8
9 #include "app/active_window_watcher_x.h"
10
11 static Atom kNetActiveWindowAtom = None;
12
13 // static
14 ActiveWindowWatcherX* ActiveWindowWatcherX::GetInstance() {
15 return Singleton<ActiveWindowWatcherX>::get();
16 }
17
18 // static
19 void ActiveWindowWatcherX::AddObserver(Observer* observer) {
20 GetInstance()->observers_.AddObserver(observer);
21 }
22
23 // static
24 void ActiveWindowWatcherX::RemoveObserver(Observer* observer) {
25 GetInstance()->observers_.RemoveObserver(observer);
26 }
27
28 ActiveWindowWatcherX::ActiveWindowWatcherX() {
29 Init();
30 }
31
32 ActiveWindowWatcherX::~ActiveWindowWatcherX() {
33 }
34
35 void ActiveWindowWatcherX::Init() {
36 GdkAtom kNetActiveWindow = gdk_atom_intern("_NET_ACTIVE_WINDOW", FALSE);
37 kNetActiveWindowAtom = gdk_x11_atom_to_xatom_for_display(
38 gdk_screen_get_display(gdk_screen_get_default()), kNetActiveWindow);
39
40 GdkWindow* root = gdk_get_default_root_window();
41
42 // Set up X Event filter to listen for PropertyChange X events. These events
43 // tell us when the active window changes.
44 // Don't use XSelectInput directly here, as gdk internally seems to cache the
45 // mask and reapply XSelectInput after this, resetting any mask we set here.
46 gdk_window_set_events(root,
47 static_cast<GdkEventMask>(gdk_window_get_events(root) |
48 GDK_PROPERTY_CHANGE_MASK));
49 gdk_window_add_filter(NULL, &ActiveWindowWatcherX::OnWindowXEvent, this);
50 }
51
52 void ActiveWindowWatcherX::NotifyActiveWindowChanged() {
53 // We don't use gdk_screen_get_active_window() because it caches
54 // whether or not the window manager supports _NET_ACTIVE_WINDOW.
55 // This causes problems at startup for chromiumos.
56 Atom type = None;
57 int format = 0; // size in bits of each item in 'property'
58 long unsigned int num_items = 0, remaining_bytes = 0;
59 unsigned char* property = NULL;
60
61 XGetWindowProperty(gdk_x11_get_default_xdisplay(),
62 GDK_WINDOW_XID(gdk_get_default_root_window()),
63 kNetActiveWindowAtom,
64 0, // offset into property data to read
65 1, // length to get in 32-bit quantities
66 False, // deleted
67 AnyPropertyType,
68 &type,
69 &format,
70 &num_items,
71 &remaining_bytes,
72 &property);
73
74 // Check that the property was set and contained a single 32-bit item (we
75 // don't check that remaining_bytes is 0, though, as XFCE's window manager
76 // seems to actually store two values in the property for some unknown
77 // reason.)
78 if (format == 32 && num_items == 1) {
79 int xid = *reinterpret_cast<int*>(property);
80 GdkWindow* active_window = gdk_window_lookup(xid);
81 FOR_EACH_OBSERVER(
82 Observer,
83 observers_,
84 ActiveWindowChanged(active_window));
85 }
86 if (property)
87 XFree(property);
88 }
89
90 GdkFilterReturn ActiveWindowWatcherX::OnWindowXEvent(GdkXEvent* xevent,
91 GdkEvent* event, gpointer window_watcher) {
92 ActiveWindowWatcherX* watcher = reinterpret_cast<ActiveWindowWatcherX*>(
93 window_watcher);
94 XEvent* xev = static_cast<XEvent*>(xevent);
95
96 if (xev->xany.type == PropertyNotify &&
97 xev->xproperty.atom == kNetActiveWindowAtom) {
98 watcher->NotifyActiveWindowChanged();
99 }
100
101 return GDK_FILTER_CONTINUE;
102 }
OLDNEW
« no previous file with comments | « app/active_window_watcher_x.h ('k') | app/bidi_line_iterator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698