summaryrefslogtreecommitdiffstats
path: root/base/wayland/wayland_event.h
blob: 1d6808de25cca0f014219bfb098bfc72d7f698bd (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
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
// 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.

#ifndef BASE_WAYLAND_WAYLAND_EVENT_H_
#define BASE_WAYLAND_WAYLAND_EVENT_H_

#include <stdint.h>

// Wayland event information is being passed in as arguments to the callbacks.
// (See wayland_input_device.{h,cc} for information on the callbacks and how
// events are processed.)
// In order to provide a more generic look for events we wrap these arguments
// in specific event structs. Then define a WaylandEvent as a union of all
// types of events that Wayland will send.
//
// The following fields are common for most event types and their use is
// similar:
// - time:
//    The time of the event. This should be monotonically increasing.
// - state:
//    The value of the button event as given by evdev. This is 0 if button
//    isn't pressed.
// - modifiers:
//    Stores all the keyboard modifiers (Ctrl, Alt, Shift, ...) currently
//    active. The modifiers are values as defined by xkbcommon.

namespace base {
namespace wayland {

// Types of events Wayland will send
enum WaylandEventType {
  WAYLAND_BUTTON,
  WAYLAND_KEY,
  WAYLAND_MOTION,
  WAYLAND_POINTER_FOCUS,
  WAYLAND_KEYBOARD_FOCUS,
  WAYLAND_GEOMETRY_CHANGE,
};

struct WaylandEventButton {
  WaylandEventType type;
  uint32_t time;
  // WaylandEventButtonType defines some of the values button can take
  uint32_t button;
  uint32_t state;
  uint32_t modifiers;
  int32_t x;
  int32_t y;
};

struct WaylandEventKey {
  WaylandEventType type;
  uint32_t time;
  // The raw key value that evdev returns.
  uint32_t key;
  // The key symbol returned by processing the raw key using the xkbcommon
  // library.
  uint32_t sym;
  uint32_t state;
  uint32_t modifiers;
};

// Triggered when there is a motion event. The motion event is triggered
// only if there is a window under focus.
struct WaylandEventMotion {
  WaylandEventType type;
  uint32_t time;
  uint32_t modifiers;
  int32_t x;
  int32_t y;
};

// Triggered when a window enters/exits pointer focus. The state tells us
// if the window lost focus (state == 0) or gained focus (state != 0).
struct WaylandEventPointerFocus {
  WaylandEventType type;
  uint32_t time;
  uint32_t state;
  int32_t x;
  int32_t y;
};

// Triggered when a window enters/exits keyboard focus. The state tells us
// if the window lost focus (state == 0) or gained focus (state != 0).
struct WaylandEventKeyboardFocus {
  WaylandEventType type;
  uint32_t time;
  uint32_t state;
  uint32_t modifiers;
};

// Event triggered when a window's geometry changes. The event contains the
// position and dimensions of the window.
struct WaylandEventGeometryChange {
  WaylandEventType type;
  uint32_t time;
  int32_t x;
  int32_t y;
  int32_t width;
  int32_t height;
};

union WaylandEvent {
  WaylandEventType            type;
  WaylandEventButton          button;
  WaylandEventKey             key;
  WaylandEventMotion          motion;
  WaylandEventPointerFocus    pointer_focus;
  WaylandEventKeyboardFocus   keyboard_focus;
  WaylandEventGeometryChange  geometry_change;
};

}  // namespace wayland
}  // namespace base

#endif  // BASE_WAYLAND_WAYLAND_EVENT_H_