libevdevxx 0.4.0
A C++ wrapper for libevdev.
Loading...
Searching...
No Matches
Event.hpp
Go to the documentation of this file.
1/*
2 * libevdevxx - a C++ wrapper for libevdev
3 *
4 * Copyright (C) 2021-2023 Daniel K. O.
5 * SPDX-License-Identifier: MIT
6 */
7
8
9#ifndef LIBEVDEVXX_EVENT_HPP
10#define LIBEVDEVXX_EVENT_HPP
11
12
13#include <compare>
14#include <cstddef>
15#include <cstdint>
16#include <iosfwd>
17#include <string>
18#include <string_view>
19#include <utility>
20
21#include <libevdev/libevdev.h>
22
23#include "Code.hpp"
24#include "Type.hpp"
25
26
27namespace evdev {
28
30 struct Event {
31
32 // same as ::input_event
33 std::uint32_t sec{};
34 std::uint32_t usec{};
37 std::int32_t value{};
38
39
40 constexpr
42 noexcept = default;
43
44
45 constexpr
46 Event(const ::input_event& e)
47 noexcept :
48 sec{e.input_event_sec},
49 usec{e.input_event_usec},
50 type{e.type},
51 code{e.code},
52 value{e.value}
53 {}
54
55
56 constexpr
57 Event&
58 operator =(const ::input_event& e)
59 noexcept
60 {
61 sec = e.input_event_sec;
62 usec = e.input_event_usec;
63 type = Type{e.type};
64 code = Code{e.code};
65 value = e.value;
66 return *this;
67 }
68
69
70 operator ::input_event() const noexcept
71 {
73 r.input_event_sec = sec;
74 r.input_event_usec = usec;
75 r.type = type;
76 r.code = code;
77 r.value = value;
78 return r;
79 }
80
81 }; // class event
82
83
84
85 std::string
86 to_string(const Event& e);
87
88
89 std::ostream&
90 operator <<(std::ostream& out,
91 const Event& e);
92
93
94}
95
96#endif
Definition: Type.hpp:28
The namespace of libevdevxx.
Definition: AbsInfo.hpp:20
std::string to_string(const AbsInfo &info)
std::ostream & operator<<(std::ostream &out, const AbsInfo &info)
Type-safe class for evdev codes (KEY_*, BTN_*, REL_*, etc).
Definition: Code.hpp:32
Definition: Event.hpp:30
operator::input_event() const noexcept
Definition: Event.hpp:70
std::uint32_t sec
Definition: Event.hpp:33
constexpr Event & operator=(const ::input_event &e) noexcept
Definition: Event.hpp:58
std::uint32_t usec
Definition: Event.hpp:34
Type type
Definition: Event.hpp:35
constexpr Event() noexcept=default
std::int32_t value
Definition: Event.hpp:37
Code code
Definition: Event.hpp:36