Skip to content

Commit 012bd22

Browse files
committed
add touchscreen stuff
1 parent f45537b commit 012bd22

File tree

7 files changed

+125
-0
lines changed

7 files changed

+125
-0
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_library(libinput-cpp STATIC
99
libinput-cpp/LibinputKeyboardEvent.cpp
1010
libinput-cpp/LibinputPathContext.cpp
1111
libinput-cpp/LibinputPointerEvent.cpp
12+
libinput-cpp/LibinputTouchEvent.cpp
1213
libinput-cpp/UdevDevice.cpp
1314
)
1415
target_link_libraries(libinput-cpp PUBLIC

src/libinput-cpp/LibinputDevice.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ QString LibinputDevice::sysName() const
4848
return libinput_device_get_sysname(m_device);
4949
}
5050

51+
QSizeF LibinputDevice::size() const
52+
{
53+
double width;
54+
double height;
55+
if (libinput_device_get_size(m_device, &width, &height)) {
56+
return {};
57+
}
58+
59+
return {width, height};
60+
}
61+
5162
std::unique_ptr<UdevDevice> LibinputDevice::udevDevice() const
5263
{
5364
return std::make_unique<UdevDevice>(libinput_device_get_udev_device(m_device));

src/libinput-cpp/LibinputDevice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#pragma once
2020

21+
#include <QSizeF>
2122
#include <QString>
2223
#include <QtClassHelperMacros>
2324

@@ -47,6 +48,11 @@ class LibinputDevice
4748
*/
4849
QString sysName() const;
4950

51+
/**
52+
* @see libinput_device_get_size
53+
*/
54+
QSizeF size() const;
55+
5056
/**
5157
* @see libinput_device_get_udev_device
5258
*/

src/libinput-cpp/LibinputEvent.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "LibinputGestureEvent.h"
2121
#include "LibinputKeyboardEvent.h"
2222
#include "LibinputPointerEvent.h"
23+
#include "LibinputTouchEvent.h"
2324

2425
namespace InputActions
2526
{
@@ -69,4 +70,14 @@ std::optional<LibinputPointerEvent> LibinputEvent::pointerEvent() const
6970
return LibinputPointerEvent(event);
7071
}
7172

73+
std::optional<LibinputTouchEvent> LibinputEvent::touchEvent() const
74+
{
75+
auto *event = libinput_event_get_touch_event(m_event);
76+
if (!event) {
77+
return {};
78+
}
79+
80+
return LibinputTouchEvent(event);
81+
}
82+
7283
}

src/libinput-cpp/LibinputEvent.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace InputActions
2828
class LibinputGestureEvent;
2929
class LibinputKeyboardEvent;
3030
class LibinputPointerEvent;
31+
class LibinputTouchEvent;
3132

3233
class LibinputEvent
3334
{
@@ -54,6 +55,11 @@ class LibinputEvent
5455
* @see libinput_event_get_pointer_event
5556
*/
5657
std::optional<LibinputPointerEvent> pointerEvent() const;
58+
/**
59+
* @return The touch event or std::nullopt if this event is not a touch event. The returned object becomes invalid when its parent is deleted.
60+
* @see libinput_event_get_touch_event
61+
*/
62+
std::optional<LibinputTouchEvent> touchEvent() const;
5763

5864
private:
5965
libinput_event *m_event;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
libevdev-cpp - Minimal C++ libinput wrapper for InputActions
3+
Copyright (C) 2026 Marcin Woźniak
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include "LibinputTouchEvent.h"
20+
#include <libinput.h>
21+
22+
namespace InputActions
23+
{
24+
25+
LibinputTouchEvent::LibinputTouchEvent(libinput_event_touch *event)
26+
: m_event(event)
27+
{
28+
}
29+
30+
int32_t LibinputTouchEvent::slot() const
31+
{
32+
return libinput_event_touch_get_slot(m_event);
33+
}
34+
35+
QPointF LibinputTouchEvent::position() const
36+
{
37+
return {libinput_event_touch_get_x(m_event), libinput_event_touch_get_y(m_event)};
38+
}
39+
40+
41+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
libevdev-cpp - Minimal C++ libinput wrapper for InputActions
3+
Copyright (C) 2026 Marcin Woźniak
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
#pragma once
20+
21+
#include <cstdint>
22+
#include <QPointF>
23+
24+
struct libinput_event_touch;
25+
26+
namespace InputActions
27+
{
28+
29+
class LibinputTouchEvent
30+
{
31+
public:
32+
LibinputTouchEvent(libinput_event_touch *event);
33+
34+
/**
35+
* @see libinput_event_touch_get_slot
36+
*/
37+
int32_t slot() const;
38+
39+
/**
40+
* @see libinput_event_touch_get_x
41+
* @see libinput_event_touch_get_y
42+
*/
43+
QPointF position() const;
44+
45+
private:
46+
libinput_event_touch *m_event;
47+
};
48+
49+
}

0 commit comments

Comments
 (0)