summaryrefslogtreecommitdiffstats
path: root/ui/platform_window/x11/x11_window_ozone.cc
blob: 3a370dcc934e6a5a543a9eb9843e801b38d88e48 (plain)
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
// Copyright 2016 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/platform_window/x11/x11_window_ozone.h"

#include <X11/Xlib.h>

#include "ui/events/event.h"
#include "ui/events/ozone/events_ozone.h"
#include "ui/events/platform/x11/x11_event_source.h"
#include "ui/gfx/geometry/point.h"
#include "ui/platform_window/x11/x11_cursor_ozone.h"

namespace ui {

X11WindowOzone::X11WindowOzone(X11EventSourceLibevent* event_source,
                               PlatformWindowDelegate* delegate)
    : X11WindowBase(delegate), event_source_(event_source) {
  DCHECK(event_source_);
  event_source_->AddPlatformEventDispatcher(this);
  event_source_->AddXEventDispatcher(this);
}

X11WindowOzone::~X11WindowOzone() {
  event_source_->RemovePlatformEventDispatcher(this);
  event_source_->RemoveXEventDispatcher(this);
}

void X11WindowOzone::SetCursor(PlatformCursor cursor) {
  X11CursorOzone* cursor_ozone = static_cast<X11CursorOzone*>(cursor);
  XDefineCursor(xdisplay(), xwindow(), cursor_ozone->xcursor());
}

bool X11WindowOzone::DispatchXEvent(XEvent* xev) {
  if (!IsEventForXWindow(*xev))
    return false;

  ProcessXWindowEvent(xev);
  return true;
}

bool X11WindowOzone::CanDispatchEvent(const PlatformEvent& event) {
  // TODO(kylechar): This is broken, there is no way to include XID of XWindow
  // in ui::Event. Fix or use similar hack to DrmWindowHost.
  return xwindow() != None;
}

uint32_t X11WindowOzone::DispatchEvent(const PlatformEvent& platform_event) {
  // This is unfortunately needed otherwise events that depend on global state
  // (eg. double click) are broken.
  DispatchEventFromNativeUiEvent(
      platform_event, base::Bind(&PlatformWindowDelegate::DispatchEvent,
                                 base::Unretained(delegate())));
  return POST_DISPATCH_STOP_PROPAGATION;
}

}  // namespace ui