OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 5 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
6 | 6 |
7 #include <X11/extensions/shape.h> | 7 #include <X11/extensions/shape.h> |
8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
9 #include <X11/Xatom.h> | 9 #include <X11/Xatom.h> |
10 #include <X11/Xregion.h> | 10 #include <X11/Xregion.h> |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 window_parent_(NULL), | 158 window_parent_(NULL), |
159 custom_window_shape_(false), | 159 custom_window_shape_(false), |
160 urgency_hint_set_(false), | 160 urgency_hint_set_(false), |
161 has_pointer_grab_(false), | 161 has_pointer_grab_(false), |
162 activatable_(true), | 162 activatable_(true), |
163 has_pointer_(false), | 163 has_pointer_(false), |
164 has_window_focus_(false), | 164 has_window_focus_(false), |
165 has_pointer_focus_(false), | 165 has_pointer_focus_(false), |
166 modal_dialog_counter_(0), | 166 modal_dialog_counter_(0), |
167 close_widget_factory_(this), | 167 close_widget_factory_(this), |
168 weak_factory_(this) {} | 168 weak_factory_(this) { |
| 169 display::Screen::GetScreen()->AddObserver(this); |
| 170 } |
169 | 171 |
170 DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() { | 172 DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() { |
171 window()->ClearProperty(kHostForRootWindow); | 173 window()->ClearProperty(kHostForRootWindow); |
172 wm::SetWindowMoveClient(window(), NULL); | 174 wm::SetWindowMoveClient(window(), NULL); |
173 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); | 175 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); |
174 DestroyDispatcher(); | 176 DestroyDispatcher(); |
| 177 display::Screen::GetScreen()->RemoveObserver(this); |
175 } | 178 } |
176 | 179 |
177 // static | 180 // static |
178 aura::Window* DesktopWindowTreeHostX11::GetContentWindowForXID(XID xid) { | 181 aura::Window* DesktopWindowTreeHostX11::GetContentWindowForXID(XID xid) { |
179 aura::WindowTreeHost* host = | 182 aura::WindowTreeHost* host = |
180 aura::WindowTreeHost::GetForAcceleratedWidget(xid); | 183 aura::WindowTreeHost::GetForAcceleratedWidget(xid); |
181 return host ? host->window()->GetProperty(kViewsWindowForRootWindow) : NULL; | 184 return host ? host->window()->GetProperty(kViewsWindowForRootWindow) : NULL; |
182 } | 185 } |
183 | 186 |
184 // static | 187 // static |
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1283 bounds_in_pixels_.x() + location_in_pixels.x(), | 1286 bounds_in_pixels_.x() + location_in_pixels.x(), |
1284 bounds_in_pixels_.y() + location_in_pixels.y()); | 1287 bounds_in_pixels_.y() + location_in_pixels.y()); |
1285 } | 1288 } |
1286 | 1289 |
1287 void DesktopWindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) { | 1290 void DesktopWindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) { |
1288 // TODO(erg): Conditional on us enabling touch on desktop linux builds, do | 1291 // TODO(erg): Conditional on us enabling touch on desktop linux builds, do |
1289 // the same tap-to-click disabling here that chromeos does. | 1292 // the same tap-to-click disabling here that chromeos does. |
1290 } | 1293 } |
1291 | 1294 |
1292 //////////////////////////////////////////////////////////////////////////////// | 1295 //////////////////////////////////////////////////////////////////////////////// |
| 1296 // DesktopWindowTreeHostX11, display::DisplayObserver implementation: |
| 1297 |
| 1298 void DesktopWindowTreeHostX11::OnDisplayAdded( |
| 1299 const display::Display& new_display) {} |
| 1300 |
| 1301 void DesktopWindowTreeHostX11::OnDisplayRemoved( |
| 1302 const display::Display& old_display) {} |
| 1303 |
| 1304 void DesktopWindowTreeHostX11::OnDisplayMetricsChanged( |
| 1305 const display::Display& display, |
| 1306 uint32_t changed_metrics) { |
| 1307 if ((changed_metrics & DISPLAY_METRIC_DEVICE_SCALE_FACTOR) && |
| 1308 display::Screen::GetScreen()->GetDisplayNearestWindow(window()).id() == |
| 1309 display.id()) { |
| 1310 // When the scale factor changes, also pretend that a resize |
| 1311 // occured so that the window layout will be refreshed and a |
| 1312 // compositor redraw will be scheduled. This is weird, but works. |
| 1313 // TODO(thomasanderson): Figure out a more direct way of doing |
| 1314 // this. |
| 1315 RestartDelayedResizeTask(); |
| 1316 } |
| 1317 } |
| 1318 |
| 1319 //////////////////////////////////////////////////////////////////////////////// |
1293 // DesktopWindowTreeHostX11, private: | 1320 // DesktopWindowTreeHostX11, private: |
1294 | 1321 |
1295 void DesktopWindowTreeHostX11::InitX11Window( | 1322 void DesktopWindowTreeHostX11::InitX11Window( |
1296 const Widget::InitParams& params) { | 1323 const Widget::InitParams& params) { |
1297 unsigned long attribute_mask = CWBackPixmap | CWBitGravity; | 1324 unsigned long attribute_mask = CWBackPixmap | CWBitGravity; |
1298 XSetWindowAttributes swa; | 1325 XSetWindowAttributes swa; |
1299 memset(&swa, 0, sizeof(swa)); | 1326 memset(&swa, 0, sizeof(swa)); |
1300 swa.background_pixmap = None; | 1327 swa.background_pixmap = None; |
1301 swa.bit_gravity = NorthWestGravity; | 1328 swa.bit_gravity = NorthWestGravity; |
1302 | 1329 |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1989 xev->xconfigure.width, xev->xconfigure.height); | 2016 xev->xconfigure.width, xev->xconfigure.height); |
1990 bool size_changed = bounds_in_pixels_.size() != bounds_in_pixels.size(); | 2017 bool size_changed = bounds_in_pixels_.size() != bounds_in_pixels.size(); |
1991 bool origin_changed = | 2018 bool origin_changed = |
1992 bounds_in_pixels_.origin() != bounds_in_pixels.origin(); | 2019 bounds_in_pixels_.origin() != bounds_in_pixels.origin(); |
1993 previous_bounds_in_pixels_ = bounds_in_pixels_; | 2020 previous_bounds_in_pixels_ = bounds_in_pixels_; |
1994 bounds_in_pixels_ = bounds_in_pixels; | 2021 bounds_in_pixels_ = bounds_in_pixels; |
1995 | 2022 |
1996 if (origin_changed) | 2023 if (origin_changed) |
1997 OnHostMovedInPixels(bounds_in_pixels_.origin()); | 2024 OnHostMovedInPixels(bounds_in_pixels_.origin()); |
1998 | 2025 |
1999 if (size_changed) { | 2026 if (size_changed) |
2000 delayed_resize_task_.Reset(base::Bind( | 2027 RestartDelayedResizeTask(); |
2001 &DesktopWindowTreeHostX11::DelayedResize, | |
2002 close_widget_factory_.GetWeakPtr(), bounds_in_pixels.size())); | |
2003 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
2004 FROM_HERE, delayed_resize_task_.callback()); | |
2005 } | |
2006 break; | 2028 break; |
2007 } | 2029 } |
2008 case GenericEvent: { | 2030 case GenericEvent: { |
2009 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 2031 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
2010 if (!factory->ShouldProcessXI2Event(xev)) | 2032 if (!factory->ShouldProcessXI2Event(xev)) |
2011 break; | 2033 break; |
2012 | 2034 |
2013 XIEnterEvent* enter_event = static_cast<XIEnterEvent*>(xev->xcookie.data); | 2035 XIEnterEvent* enter_event = static_cast<XIEnterEvent*>(xev->xcookie.data); |
2014 switch (static_cast<XIEvent*>(xev->xcookie.data)->evtype) { | 2036 switch (static_cast<XIEvent*>(xev->xcookie.data)->evtype) { |
2015 case XI_Enter: | 2037 case XI_Enter: |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2268 &DesktopWindowTreeHostX11::EnableEventListening, | 2290 &DesktopWindowTreeHostX11::EnableEventListening, |
2269 weak_factory_.GetWeakPtr())); | 2291 weak_factory_.GetWeakPtr())); |
2270 } | 2292 } |
2271 | 2293 |
2272 void DesktopWindowTreeHostX11::EnableEventListening() { | 2294 void DesktopWindowTreeHostX11::EnableEventListening() { |
2273 DCHECK_GT(modal_dialog_counter_, 0UL); | 2295 DCHECK_GT(modal_dialog_counter_, 0UL); |
2274 if (!--modal_dialog_counter_) | 2296 if (!--modal_dialog_counter_) |
2275 targeter_for_modal_.reset(); | 2297 targeter_for_modal_.reset(); |
2276 } | 2298 } |
2277 | 2299 |
| 2300 void DesktopWindowTreeHostX11::RestartDelayedResizeTask() { |
| 2301 delayed_resize_task_.Reset( |
| 2302 base::Bind(&DesktopWindowTreeHostX11::DelayedResize, |
| 2303 close_widget_factory_.GetWeakPtr(), bounds_in_pixels_.size())); |
| 2304 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 2305 FROM_HERE, delayed_resize_task_.callback()); |
| 2306 } |
| 2307 |
2278 //////////////////////////////////////////////////////////////////////////////// | 2308 //////////////////////////////////////////////////////////////////////////////// |
2279 // DesktopWindowTreeHost, public: | 2309 // DesktopWindowTreeHost, public: |
2280 | 2310 |
2281 // static | 2311 // static |
2282 DesktopWindowTreeHost* DesktopWindowTreeHost::Create( | 2312 DesktopWindowTreeHost* DesktopWindowTreeHost::Create( |
2283 internal::NativeWidgetDelegate* native_widget_delegate, | 2313 internal::NativeWidgetDelegate* native_widget_delegate, |
2284 DesktopNativeWidgetAura* desktop_native_widget_aura) { | 2314 DesktopNativeWidgetAura* desktop_native_widget_aura) { |
2285 return new DesktopWindowTreeHostX11(native_widget_delegate, | 2315 return new DesktopWindowTreeHostX11(native_widget_delegate, |
2286 desktop_native_widget_aura); | 2316 desktop_native_widget_aura); |
2287 } | 2317 } |
2288 | 2318 |
2289 } // namespace views | 2319 } // namespace views |
OLD | NEW |