OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/services/native_viewport/native_viewport.h" | 5 #include "mojo/services/native_viewport/native_viewport.h" |
6 | 6 |
7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
8 #include <X11/Xutil.h> | 8 #include <X11/Xutil.h> |
9 | 9 |
10 #include "base/command_line.h" | |
10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "mojo/shell/switches.h" | |
11 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
12 #include "ui/events/event_utils.h" | 14 #include "ui/events/event_utils.h" |
13 #include "ui/events/platform/platform_event_dispatcher.h" | 15 #include "ui/events/platform/platform_event_dispatcher.h" |
14 #include "ui/events/platform/platform_event_source.h" | 16 #include "ui/events/platform/platform_event_source.h" |
15 #include "ui/events/platform/x11/x11_event_source.h" | 17 #include "ui/events/platform/x11/x11_event_source.h" |
16 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
17 #include "ui/gfx/x/x11_types.h" | 19 #include "ui/gfx/x/x11_types.h" |
18 | 20 |
19 namespace mojo { | 21 namespace mojo { |
20 namespace services { | 22 namespace services { |
(...skipping 19 matching lines...) Expand all Loading... | |
40 : delegate_(delegate) { | 42 : delegate_(delegate) { |
41 } | 43 } |
42 | 44 |
43 virtual ~NativeViewportX11() { | 45 virtual ~NativeViewportX11() { |
44 event_source_->RemovePlatformEventDispatcher(this); | 46 event_source_->RemovePlatformEventDispatcher(this); |
45 | 47 |
46 XDestroyWindow(gfx::GetXDisplay(), window_); | 48 XDestroyWindow(gfx::GetXDisplay(), window_); |
47 } | 49 } |
48 | 50 |
49 private: | 51 private: |
52 void InitWindowManagerState(XDisplay* display) { | |
53 // TODO(hansmuller): should not be processing the shell's commad line here. | |
jamesr
2014/07/02 18:12:49
I think it'd be better to split this part into a s
| |
54 CommandLine* cmd = CommandLine::ForCurrentProcess(); | |
55 bool fullscreen = cmd->HasSwitch("start-fullscreen"); | |
56 bool maximized = cmd->HasSwitch("start-maximized"); | |
57 if (!(fullscreen || maximized)) | |
58 return; | |
59 | |
60 XEvent xevent; | |
61 memset(&xevent, 0, sizeof(xevent)); | |
62 xevent.type = ClientMessage; | |
63 xevent.xclient.window = window_; | |
64 xevent.xclient.message_type = XInternAtom(display, "_NET_WM_STATE", False); | |
65 xevent.xclient.format = 32; | |
66 xevent.xclient.data.l[0] = 1; // NET_WM_STATE_ADD | |
67 | |
68 if (maximized) { | |
69 xevent.xclient.data.l[1] = | |
70 XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); | |
71 xevent.xclient.data.l[2] = | |
72 XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_VERT", False); | |
73 } else { | |
74 xevent.xclient.data.l[1] = | |
75 XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", False); | |
76 } | |
77 | |
78 // TODO(hansmuller): rationalize the value of event_mask; | |
79 long event_mask = SubstructureNotifyMask | SubstructureRedirectMask; | |
80 XSendEvent(display, DefaultRootWindow(display), False, event_mask, &xevent); | |
81 } | |
82 | |
50 // Overridden from NativeViewport: | 83 // Overridden from NativeViewport: |
51 virtual void Init(const gfx::Rect& bounds) OVERRIDE { | 84 virtual void Init(const gfx::Rect& bounds) OVERRIDE { |
52 XDisplay* display = gfx::GetXDisplay(); | 85 XDisplay* display = gfx::GetXDisplay(); |
53 | 86 |
54 XSetWindowAttributes swa; | 87 XSetWindowAttributes swa; |
55 memset(&swa, 0, sizeof(swa)); | 88 memset(&swa, 0, sizeof(swa)); |
56 swa.override_redirect = override_redirect ? True : False; | 89 swa.override_redirect = override_redirect ? True : False; |
57 | 90 |
58 bounds_ = bounds; | 91 bounds_ = bounds; |
59 window_ = XCreateWindow( | 92 window_ = XCreateWindow( |
(...skipping 17 matching lines...) Expand all Loading... | |
77 long event_mask = ButtonPressMask | ButtonReleaseMask | FocusChangeMask | | 110 long event_mask = ButtonPressMask | ButtonReleaseMask | FocusChangeMask | |
78 KeyPressMask | KeyReleaseMask | EnterWindowMask | LeaveWindowMask | | 111 KeyPressMask | KeyReleaseMask | EnterWindowMask | LeaveWindowMask | |
79 ExposureMask | VisibilityChangeMask | StructureNotifyMask | | 112 ExposureMask | VisibilityChangeMask | StructureNotifyMask | |
80 PropertyChangeMask | PointerMotionMask; | 113 PropertyChangeMask | PointerMotionMask; |
81 XSelectInput(display, window_, event_mask); | 114 XSelectInput(display, window_, event_mask); |
82 | 115 |
83 // We need a WM_CLIENT_MACHINE and WM_LOCALE_NAME value so we integrate with | 116 // We need a WM_CLIENT_MACHINE and WM_LOCALE_NAME value so we integrate with |
84 // the desktop environment. | 117 // the desktop environment. |
85 XSetWMProperties(display, window_, NULL, NULL, NULL, 0, NULL, NULL, NULL); | 118 XSetWMProperties(display, window_, NULL, NULL, NULL, 0, NULL, NULL, NULL); |
86 | 119 |
120 InitWindowManagerState(display); | |
121 | |
87 // TODO(aa): Setup xinput2 events. | 122 // TODO(aa): Setup xinput2 events. |
88 // See desktop_aura/desktop_window_tree_host_x11.cc. | 123 // See desktop_aura/desktop_window_tree_host_x11.cc. |
89 | 124 |
90 delegate_->OnAcceleratedWidgetAvailable(window_); | 125 delegate_->OnAcceleratedWidgetAvailable(window_); |
91 } | 126 } |
92 | 127 |
93 virtual void Show() OVERRIDE { | 128 virtual void Show() OVERRIDE { |
94 XDisplay* display = gfx::GetXDisplay(); | 129 XDisplay* display = gfx::GetXDisplay(); |
95 XMapWindow(display, window_); | 130 XMapWindow(display, window_); |
96 static_cast<ui::X11EventSource*>( | 131 static_cast<ui::X11EventSource*>( |
(...skipping 29 matching lines...) Expand all Loading... | |
126 // ui::PlatformEventDispatcher: | 161 // ui::PlatformEventDispatcher: |
127 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE { | 162 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE { |
128 // TODO(aa): This is going to have to be thought through more carefully. | 163 // TODO(aa): This is going to have to be thought through more carefully. |
129 // Which events are appropriate to pass to clients? | 164 // Which events are appropriate to pass to clients? |
130 switch (event->type) { | 165 switch (event->type) { |
131 case KeyPress: | 166 case KeyPress: |
132 case KeyRelease: | 167 case KeyRelease: |
133 case ButtonPress: | 168 case ButtonPress: |
134 case ButtonRelease: | 169 case ButtonRelease: |
135 case MotionNotify: | 170 case MotionNotify: |
171 case ConfigureNotify: | |
136 return true; | 172 return true; |
137 case ClientMessage: | 173 case ClientMessage: |
138 return event->xclient.message_type == atom_wm_protocols_; | 174 return event->xclient.message_type == atom_wm_protocols_; |
139 default: | 175 default: |
140 return false; | 176 return false; |
141 } | 177 } |
142 } | 178 } |
143 | 179 |
144 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE { | 180 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE { |
145 if (event->type == ClientMessage) { | 181 if (event->type == ClientMessage) { |
146 Atom protocol = static_cast<Atom>(event->xclient.data.l[0]); | 182 Atom protocol = static_cast<Atom>(event->xclient.data.l[0]); |
147 if (protocol == atom_wm_delete_window_) | 183 if (protocol == atom_wm_delete_window_) |
148 delegate_->OnDestroyed(); | 184 delegate_->OnDestroyed(); |
149 } else if (event->type == KeyPress || event->type == KeyRelease) { | 185 } else if (event->type == KeyPress || event->type == KeyRelease) { |
150 ui::KeyEvent key_event(event, false); | 186 ui::KeyEvent key_event(event, false); |
151 delegate_->OnEvent(&key_event); | 187 delegate_->OnEvent(&key_event); |
152 } else if (event->type == ButtonPress || event->type == ButtonRelease || | 188 } else if (event->type == ButtonPress || event->type == ButtonRelease || |
153 event->type == MotionNotify) { | 189 event->type == MotionNotify) { |
154 ui::EventType event_type = ui::EventTypeFromNative(event); | 190 ui::EventType event_type = ui::EventTypeFromNative(event); |
155 if (event_type == ui::ET_MOUSEWHEEL) { | 191 if (event_type == ui::ET_MOUSEWHEEL) { |
156 ui::MouseWheelEvent mouse_event(event); | 192 ui::MouseWheelEvent mouse_event(event); |
157 delegate_->OnEvent(&mouse_event); | 193 delegate_->OnEvent(&mouse_event); |
158 } else { | 194 } else { |
159 ui::MouseEvent mouse_event(event); | 195 ui::MouseEvent mouse_event(event); |
160 delegate_->OnEvent(&mouse_event); | 196 delegate_->OnEvent(&mouse_event); |
161 } | 197 } |
198 } else if (event->type == ConfigureNotify) { | |
jamesr
2014/07/02 18:12:49
nit: i think you have two spaces between 'else' an
| |
199 bounds_ = gfx::Rect(event->xconfigure.width, event->xconfigure.height); | |
200 delegate_->OnBoundsChanged(bounds_); | |
162 } | 201 } |
163 return ui::POST_DISPATCH_NONE; | 202 return ui::POST_DISPATCH_NONE; |
164 } | 203 } |
165 | 204 |
166 scoped_ptr<ui::PlatformEventSource> event_source_; | 205 scoped_ptr<ui::PlatformEventSource> event_source_; |
167 NativeViewportDelegate* delegate_; | 206 NativeViewportDelegate* delegate_; |
168 gfx::Rect bounds_; | 207 gfx::Rect bounds_; |
169 XID window_; | 208 XID window_; |
170 Atom atom_wm_protocols_; | 209 Atom atom_wm_protocols_; |
171 Atom atom_wm_delete_window_; | 210 Atom atom_wm_delete_window_; |
172 | 211 |
173 DISALLOW_COPY_AND_ASSIGN(NativeViewportX11); | 212 DISALLOW_COPY_AND_ASSIGN(NativeViewportX11); |
174 }; | 213 }; |
175 | 214 |
176 // static | 215 // static |
177 scoped_ptr<NativeViewport> NativeViewport::Create( | 216 scoped_ptr<NativeViewport> NativeViewport::Create( |
178 shell::Context* context, | 217 shell::Context* context, |
179 NativeViewportDelegate* delegate) { | 218 NativeViewportDelegate* delegate) { |
180 return scoped_ptr<NativeViewport>(new NativeViewportX11(delegate)).Pass(); | 219 return scoped_ptr<NativeViewport>(new NativeViewportX11(delegate)).Pass(); |
181 } | 220 } |
182 | 221 |
183 } // namespace services | 222 } // namespace services |
184 } // namespace mojo | 223 } // namespace mojo |
OLD | NEW |