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

Side by Side Diff: ui/views/widget/x11_desktop_handler.cc

Issue 11369220: Move the desktop aura classes into a desktop subdir to make the gyp simpler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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 | « ui/views/widget/x11_desktop_handler.h ('k') | ui/views/widget/x11_desktop_window_move_client.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) 2012 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/views/widget/x11_desktop_handler.h"
6
7 #include "base/message_loop.h"
8 #include "ui/aura/env.h"
9 #include "ui/aura/focus_manager.h"
10 #include "ui/aura/root_window.h"
11 #include "ui/base/x/x11_util.h"
12 #include "ui/views/widget/desktop_aura/desktop_activation_client.h"
13
14 #if !defined(OS_CHROMEOS)
15 #include "ui/views/ime/input_method.h"
16 #include "ui/views/widget/desktop_root_window_host_linux.h"
17 #endif
18
19 namespace {
20
21 const char* kAtomsToCache[] = {
22 "_NET_ACTIVE_WINDOW",
23 NULL
24 };
25
26 // Our global instance. Deleted when our Env() is deleted.
27 views::X11DesktopHandler* g_handler = NULL;
28
29 } // namespace
30
31 namespace views {
32
33 // static
34 X11DesktopHandler* X11DesktopHandler::get() {
35 if (!g_handler)
36 g_handler = new X11DesktopHandler;
37
38 return g_handler;
39 }
40
41 X11DesktopHandler::X11DesktopHandler()
42 : xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()),
43 x_root_window_(DefaultRootWindow(xdisplay_)),
44 current_window_(None),
45 atom_cache_(xdisplay_, kAtomsToCache) {
46 base::MessagePumpAuraX11::Current()->AddDispatcherForRootWindow(this);
47 aura::Env::GetInstance()->AddObserver(this);
48
49 XWindowAttributes attr;
50 XGetWindowAttributes(xdisplay_, x_root_window_, &attr);
51 XSelectInput(xdisplay_, x_root_window_,
52 attr.your_event_mask | PropertyChangeMask |
53 StructureNotifyMask | SubstructureNotifyMask);
54 }
55
56 X11DesktopHandler::~X11DesktopHandler() {
57 aura::Env::GetInstance()->RemoveObserver(this);
58 base::MessagePumpAuraX11::Current()->RemoveDispatcherForRootWindow(this);
59 }
60
61 void X11DesktopHandler::ActivateWindow(::Window window) {
62 XEvent xclient;
63 memset(&xclient, 0, sizeof(xclient));
64 xclient.type = ClientMessage;
65 xclient.xclient.window = window;
66 xclient.xclient.message_type = atom_cache_.GetAtom("_NET_ACTIVE_WINDOW");
67 xclient.xclient.format = 32;
68 xclient.xclient.data.l[0] = 1; // Specified we are an app.
69 xclient.xclient.data.l[1] = CurrentTime;
70 xclient.xclient.data.l[2] = None;
71 xclient.xclient.data.l[3] = 0;
72 xclient.xclient.data.l[4] = 0;
73
74 XSendEvent(xdisplay_, x_root_window_, False,
75 SubstructureRedirectMask | SubstructureNotifyMask,
76 &xclient);
77 }
78
79 bool X11DesktopHandler::IsActiveWindow(::Window window) const {
80 return window == current_window_;
81 }
82
83 bool X11DesktopHandler::Dispatch(const base::NativeEvent& event) {
84 // Check for a change to the active window.
85 switch (event->type) {
86 case PropertyNotify: {
87 ::Atom active_window = atom_cache_.GetAtom("_NET_ACTIVE_WINDOW");
88
89 if (event->xproperty.window == x_root_window_ &&
90 event->xproperty.atom == active_window) {
91 int window;
92 if (ui::GetIntProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &window) &&
93 window) {
94 OnActiveWindowChanged(static_cast< ::Window>(window));
95 }
96 }
97 break;
98 }
99 }
100
101 return true;
102 }
103
104 void X11DesktopHandler::OnWindowInitialized(aura::Window* window) {
105 }
106
107 void X11DesktopHandler::OnWillDestroyEnv() {
108 g_handler = NULL;
109 delete this;
110 }
111
112 void X11DesktopHandler::OnActiveWindowChanged(::Window xid) {
113 DesktopRootWindowHostLinux* old_host =
114 views::DesktopRootWindowHostLinux::GetHostForXID(current_window_);
115 if (old_host)
116 old_host->HandleNativeWidgetActivationChanged(false);
117
118 DesktopRootWindowHostLinux* new_host =
119 views::DesktopRootWindowHostLinux::GetHostForXID(xid);
120 if (new_host)
121 new_host->HandleNativeWidgetActivationChanged(true);
122
123 current_window_ = xid;
124 }
125
126 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/x11_desktop_handler.h ('k') | ui/views/widget/x11_desktop_window_move_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698