libevdevxx 0.5.3
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#include <compare>
12#include <cstddef>
13#include <cstdint>
14#include <iosfwd>
15#include <string>
16#include <string_view>
17#include <utility>
18
19#include <libevdev/libevdev.h>
20
21#include "Code.hpp"
22#include "Type.hpp"
23
24
25namespace evdev {
26
27 struct Event {
28
29 // Same fields as ::input_event, but not same memory layout.
30 decltype(::input_event::input_event_sec) sec{};
31 decltype(::input_event::input_event_usec) usec{};
34 std::int32_t value{};
35
36
37 constexpr
39 noexcept = default;
40
41
42 constexpr
43 Event(const ::input_event& e)
44 noexcept :
45 sec{e.input_event_sec},
46 usec{e.input_event_usec},
47 type{e.type},
48 code{e.code},
49 value{e.value}
50 {}
51
52
53 constexpr
54 Event&
55 operator =(const ::input_event& e)
56 noexcept
57 {
58 sec = e.input_event_sec;
59 usec = e.input_event_usec;
60 type = Type{e.type};
61 code = Code{e.code};
62 value = e.value;
63 return *this;
64 }
65
66
67 operator ::input_event()
68 const noexcept
69 {
71 r.input_event_sec = sec;
72 r.input_event_usec = usec;
73 r.type = type;
74 r.code = code;
75 r.value = value;
76 return r;
77 }
78
79 }; // class event
80
81
82
83 [[nodiscard]]
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:27
decltype(::input_event::input_event_sec) sec
Definition Event.hpp:30
operator::input_event() const noexcept
Definition Event.hpp:67
constexpr Event & operator=(const ::input_event &e) noexcept
Definition Event.hpp:55
Type type
Definition Event.hpp:32
constexpr Event() noexcept=default
decltype(::input_event::input_event_usec) usec
Definition Event.hpp:31
std::int32_t value
Definition Event.hpp:34
Code code
Definition Event.hpp:33