libevdevxx 0.5.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) 2025 Daniel K. O.
5 * SPDX-License-Identifier: MIT
6 */
7
8#ifndef LIBEVDEVXX_EVENT_HPP
9#define LIBEVDEVXX_EVENT_HPP
10
11
12#include <compare>
13#include <cstddef>
14#include <cstdint>
15#include <iosfwd>
16#include <string>
17#include <string_view>
18#include <utility>
19
20#include <libevdev/libevdev.h>
21
22#include "Code.hpp"
23#include "Type.hpp"
24
25
26namespace evdev {
27
28 struct Event {
29
30 // Same fields as ::input_event, but not same memory layout.
31 decltype(::input_event::input_event_sec) sec{};
32 decltype(::input_event::input_event_usec) usec{};
35 std::int32_t value{};
36
37
38 constexpr
40 noexcept = default;
41
42
43 constexpr
44 Event(const ::input_event& e)
45 noexcept :
46 sec{e.input_event_sec},
47 usec{e.input_event_usec},
48 type{e.type},
49 code{e.code},
50 value{e.value}
51 {}
52
53
54 constexpr
55 Event&
56 operator =(const ::input_event& e)
57 noexcept
58 {
59 sec = e.input_event_sec;
60 usec = e.input_event_usec;
61 type = Type{e.type};
62 code = Code{e.code};
63 value = e.value;
64 return *this;
65 }
66
67
68 operator ::input_event()
69 const noexcept
70 {
72 r.input_event_sec = sec;
73 r.input_event_usec = usec;
74 r.type = type;
75 r.code = code;
76 r.value = value;
77 return r;
78 }
79
80 }; // class event
81
82
83
84 std::string
85 to_string(const Event& e);
86
87
88 std::ostream&
89 operator <<(std::ostream& out,
90 const Event& e);
91
92} // namespace evdev
93
94#endif
Definition Type.hpp:26
The namespace of libevdevxx.
Definition AbsInfo.hpp:18
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:30
Definition Event.hpp:28
decltype(::input_event::input_event_sec) sec
Definition Event.hpp:31
operator::input_event() const noexcept
Definition Event.hpp:68
constexpr Event & operator=(const ::input_event &e) noexcept
Definition Event.hpp:56
Type type
Definition Event.hpp:33
constexpr Event() noexcept=default
decltype(::input_event::input_event_usec) usec
Definition Event.hpp:32
std::int32_t value
Definition Event.hpp:35
Code code
Definition Event.hpp:34