Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / aura / test / x11_event_sender.cc
blobbc58502d18a91c2c0c051b7dc5c0807ef3f5c70c
1 // Copyright 2014 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.
5 #include "ui/aura/test/x11_event_sender.h"
7 #include <X11/Xlib.h>
9 #include "ui/aura/window_tree_host.h"
10 #include "ui/gfx/geometry/point.h"
12 namespace aura {
13 namespace test {
15 void PostEventToWindowTreeHost(const XEvent& xevent, WindowTreeHost* host) {
16 XDisplay* xdisplay = gfx::GetXDisplay();
17 XID xwindow = host->GetAcceleratedWidget();
18 XEvent event = xevent;
19 event.xany.display = xdisplay;
20 event.xany.window = xwindow;
22 switch (event.type) {
23 case EnterNotify:
24 case LeaveNotify:
25 case MotionNotify:
26 case KeyPress:
27 case KeyRelease:
28 case ButtonPress:
29 case ButtonRelease: {
30 // The fields used below are in the same place for all of events
31 // above. Using xmotion from XEvent's unions to avoid repeating
32 // the code.
33 event.xmotion.root = DefaultRootWindow(event.xany.display);
34 event.xmotion.time = CurrentTime;
36 gfx::Point point(event.xmotion.x, event.xmotion.y);
37 host->ConvertPointToNativeScreen(&point);
38 event.xmotion.x_root = point.x();
39 event.xmotion.y_root = point.y();
41 default:
42 break;
44 XSendEvent(xdisplay, xwindow, False, 0, &event);
45 XFlush(xdisplay);
48 } // namespace test
49 } // namespace aura