1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/aura/desktop_host.h"
#include "base/message_loop.h"
#include "base/message_pump_x.h"
#include "ui/aura/desktop.h"
#include "ui/aura/event.h"
#include <X11/Xlib.h>
namespace aura {
namespace {
class DesktopHostLinux : public DesktopHost {
public:
explicit DesktopHostLinux(const gfx::Rect& bounds);
virtual ~DesktopHostLinux();
private:
// base::MessageLoop::Dispatcher Override.
virtual DispatchStatus Dispatch(XEvent* xev) OVERRIDE;
// DesktopHost Overrides.
virtual void SetDesktop(Desktop* desktop) OVERRIDE;
virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
virtual void Show() OVERRIDE;
virtual gfx::Size GetSize() const OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
virtual void SetCursor(gfx::NativeCursor cursor_type) OVERRIDE;
Desktop* desktop_;
// The display and the native X window hosting the desktop.
Display* xdisplay_;
::Window xwindow_;
Cursor xcursor_;
// The size of |xwindow_|.
gfx::Rect bounds_;
DISALLOW_COPY_AND_ASSIGN(DesktopHostLinux);
};
DesktopHostLinux::DesktopHostLinux(const gfx::Rect& bounds)
: desktop_(NULL),
xdisplay_(NULL),
xwindow_(0),
xcursor_(0),
bounds_(bounds) {
// This assumes that the message-pump creates and owns the display.
xdisplay_ = base::MessagePumpX::GetDefaultXDisplay();
xwindow_ = XCreateSimpleWindow(xdisplay_, DefaultRootWindow(xdisplay_),
bounds.x(), bounds.y(),
bounds.width(), bounds.height(),
0, 0, 0);
XMapWindow(xdisplay_, xwindow_);
long event_mask = ButtonPressMask | ButtonReleaseMask |
KeyPressMask | KeyReleaseMask |
ExposureMask | VisibilityChangeMask |
StructureNotifyMask | PropertyChangeMask |
PointerMotionMask;
XSelectInput(xdisplay_, xwindow_, event_mask);
XFlush(xdisplay_);
}
DesktopHostLinux::~DesktopHostLinux() {
XDestroyWindow(xdisplay_, xwindow_);
}
base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch(
XEvent* xev) {
bool handled = false;
switch (xev->type) {
case Expose:
desktop_->Draw();
handled = true;
break;
case KeyPress:
case KeyRelease: {
KeyEvent keyev(xev);
handled = desktop_->OnKeyEvent(keyev);
break;
}
case ButtonPress:
case ButtonRelease:
case MotionNotify: {
MouseEvent mouseev(xev);
handled = desktop_->OnMouseEvent(mouseev);
break;
}
case ConfigureNotify: {
DCHECK_EQ(xdisplay_, xev->xconfigure.display);
DCHECK_EQ(xwindow_, xev->xconfigure.window);
DCHECK_EQ(xwindow_, xev->xconfigure.event);
desktop_->OnHostResized(gfx::Size(xev->xconfigure.width,
xev->xconfigure.height));
handled = true;
break;
}
}
return handled ? EVENT_PROCESSED : EVENT_IGNORED;
}
void DesktopHostLinux::SetDesktop(Desktop* desktop) {
desktop_ = desktop;
}
gfx::AcceleratedWidget DesktopHostLinux::GetAcceleratedWidget() {
return xwindow_;
}
void DesktopHostLinux::Show() {
}
gfx::Size DesktopHostLinux::GetSize() const {
return bounds_.size();
}
void DesktopHostLinux::SetSize(const gfx::Size& size) {
if (bounds_.size() == size)
return;
bounds_.set_size(size);
XResizeWindow(xdisplay_, xwindow_, size.width(), size.height());
}
void DesktopHostLinux::SetCursor(gfx::NativeCursor cursor_type) {
if (xcursor_ == cursor_type)
return;
xcursor_ = cursor_type;
XDefineCursor(xdisplay_, xwindow_, cursor_type);
}
} // namespace
// static
DesktopHost* DesktopHost::Create(const gfx::Rect& bounds) {
return new DesktopHostLinux(bounds);
}
} // namespace aura
|