Skip to content

Commit 1d3509d

Browse files
committed
initial commit
0 parents  commit 1d3509d

19 files changed

Lines changed: 1650 additions & 0 deletions

.clang-format

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Language: Cpp
2+
Standard: c++20
3+
4+
ColumnLimit: 160
5+
IndentWidth: 4
6+
7+
AllowShortBlocksOnASingleLine: Never
8+
AllowShortFunctionsOnASingleLine: Inline
9+
AllowShortLambdasOnASingleLine: Empty
10+
11+
AlignAfterOpenBracket: Align
12+
AllowAllArgumentsOnNextLine: true
13+
AlignEscapedNewlines: LeftWithLastLine
14+
AlignOperands: AlignAfterOperator
15+
AlignTrailingComments: false
16+
17+
BreakBeforeBinaryOperators: All
18+
BreakBeforeBraces: Custom
19+
BraceWrapping:
20+
AfterClass: true
21+
AfterEnum: true
22+
AfterExternBlock: true
23+
AfterFunction: true
24+
AfterNamespace: true
25+
AfterStruct: true
26+
AfterUnion: true
27+
BreakBeforeTernaryOperators: true
28+
BreakConstructorInitializers: BeforeComma
29+
BreakInheritanceList: BeforeComma
30+
BreakTemplateDeclarations: Yes
31+
32+
AccessModifierOffset: -4
33+
IndentAccessModifiers: false
34+
35+
IncludeBlocks: Merge
36+
FixNamespaceComments: false
37+
38+
AllowAllConstructorInitializersOnNextLine: true
39+
BinPackArguments: false
40+
IndentCaseLabels: true
41+
SpaceAfterTemplateKeyword: false
42+
43+
PenaltyBreakAssignment: 10000
44+
PenaltyBreakBeforeFirstCallParameter: 0
45+
PenaltyBreakOpenParenthesis: 10000
46+
PenaltyBreakScopeResolution: 10000

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
result*
2+
.idea
3+
cmake-build-debug
4+
build
5+
Testing

CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required(VERSION 3.16.0)
2+
3+
project(libinput-cpp)
4+
set(PROJECT_VERSION "0.0.1")
5+
6+
set(QT_MIN_VERSION "6.6.0")
7+
set(QT_MAJOR_VERSION 6)
8+
9+
set(CMAKE_CXX_STANDARD 23)
10+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
11+
set(CMAKE_CXX_EXTENSIONS ON)
12+
13+
find_package(ECM REQUIRED NO_MODULE)
14+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
15+
16+
include(KDEInstallDirs)
17+
include(KDECMakeSettings)
18+
19+
find_package(Qt6 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
20+
Core
21+
)
22+
23+
add_subdirectory(src)

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

src/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
find_package(PkgConfig REQUIRED)
2+
pkg_search_module(LIBINPUT REQUIRED libinput)
3+
pkg_search_module(LIBUDEV REQUIRED libudev)
4+
5+
add_library(libinput-cpp STATIC
6+
libinput-cpp/LibinputDevice.cpp
7+
libinput-cpp/LibinputEvent.cpp
8+
libinput-cpp/LibinputGestureEvent.cpp
9+
libinput-cpp/LibinputKeyboardEvent.cpp
10+
libinput-cpp/LibinputPathContext.cpp
11+
libinput-cpp/LibinputPointerEvent.cpp
12+
libinput-cpp/UdevDevice.cpp
13+
)
14+
target_link_libraries(libinput-cpp PUBLIC
15+
Qt6::Core
16+
${LIBINPUT_LIBRARIES}
17+
${LIBUDEV_LIBRARIES}
18+
)
19+
target_compile_options(libinput-cpp PUBLIC -fPIC)
20+
21+
target_include_directories(libinput-cpp PRIVATE ${LIBEVDEV_INCLUDE_DIRS} ${LIBINPUT_INCLUDE_DIRS})
22+
target_include_directories(libinput-cpp PUBLIC libinput-cpp)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 "LibinputDevice.h"
20+
#include "UdevDevice.h"
21+
#include <libinput.h>
22+
23+
namespace InputActions
24+
{
25+
26+
LibinputDevice::LibinputDevice(libinput_device *device)
27+
: m_device(device)
28+
{
29+
}
30+
31+
LibinputDevice::~LibinputDevice()
32+
{
33+
libinput_device_unref(m_device);
34+
}
35+
36+
void LibinputDevice::configTapSetEnabled(bool value)
37+
{
38+
libinput_device_config_tap_set_enabled(m_device, value ? LIBINPUT_CONFIG_TAP_ENABLED : LIBINPUT_CONFIG_TAP_DISABLED);
39+
}
40+
41+
QString LibinputDevice::name() const
42+
{
43+
return libinput_device_get_name(m_device);
44+
}
45+
46+
QString LibinputDevice::sysName() const
47+
{
48+
return libinput_device_get_sysname(m_device);
49+
}
50+
51+
std::unique_ptr<UdevDevice> LibinputDevice::udevDevice() const
52+
{
53+
return std::make_unique<UdevDevice>(libinput_device_get_udev_device(m_device));
54+
}
55+
56+
}

src/libinput-cpp/LibinputDevice.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 <QString>
22+
#include <QtClassHelperMacros>
23+
24+
struct libinput_device;
25+
26+
namespace InputActions
27+
{
28+
29+
class UdevDevice;
30+
31+
class LibinputDevice
32+
{
33+
public:
34+
LibinputDevice(libinput_device *device);
35+
~LibinputDevice();
36+
37+
Q_DISABLE_COPY_MOVE(LibinputDevice);
38+
39+
libinput_device *raw() { return m_device; }
40+
41+
/**
42+
* @see libinput_device_get_name
43+
*/
44+
QString name() const;
45+
/**
46+
* @see libinput_device_get_sysname
47+
*/
48+
QString sysName() const;
49+
50+
/**
51+
* @see libinput_device_get_udev_device
52+
*/
53+
std::unique_ptr<UdevDevice> udevDevice() const;
54+
55+
/**
56+
* @param value true - LIBINPUT_CONFIG_TAP_ENABLED, false - LIBINPUT_CONFIG_TAP_DISABLED
57+
* @see libinput_device_config_tap_set_enabled
58+
*/
59+
void configTapSetEnabled(bool value);
60+
61+
private:
62+
libinput_device *m_device;
63+
};
64+
65+
}

src/libinput-cpp/LibinputEvent.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 "LibinputEvent.h"
20+
#include "LibinputGestureEvent.h"
21+
#include "LibinputKeyboardEvent.h"
22+
#include "LibinputPointerEvent.h"
23+
24+
namespace InputActions
25+
{
26+
27+
LibinputEvent::LibinputEvent(libinput_event *event)
28+
: m_event(event)
29+
{
30+
}
31+
32+
LibinputEvent::~LibinputEvent()
33+
{
34+
libinput_event_destroy(m_event);
35+
}
36+
37+
libinput_event_type LibinputEvent::type() const
38+
{
39+
return libinput_event_get_type(m_event);
40+
}
41+
42+
std::optional<LibinputGestureEvent> LibinputEvent::gestureEvent() const
43+
{
44+
auto *event = libinput_event_get_gesture_event(m_event);
45+
if (!event) {
46+
return {};
47+
}
48+
49+
return LibinputGestureEvent(event);
50+
}
51+
52+
std::optional<LibinputKeyboardEvent> LibinputEvent::keyboardEvent() const
53+
{
54+
auto *event = libinput_event_get_keyboard_event(m_event);
55+
if (!event) {
56+
return {};
57+
}
58+
59+
return LibinputKeyboardEvent(event);
60+
}
61+
62+
std::optional<LibinputPointerEvent> LibinputEvent::pointerEvent() const
63+
{
64+
auto *event = libinput_event_get_pointer_event(m_event);
65+
if (!event) {
66+
return {};
67+
}
68+
69+
return LibinputPointerEvent(event);
70+
}
71+
72+
}

src/libinput-cpp/LibinputEvent.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 <QtClassHelperMacros>
22+
#include <libinput.h>
23+
#include <optional>
24+
25+
namespace InputActions
26+
{
27+
28+
class LibinputGestureEvent;
29+
class LibinputKeyboardEvent;
30+
class LibinputPointerEvent;
31+
32+
class LibinputEvent
33+
{
34+
public:
35+
LibinputEvent(libinput_event *event);
36+
~LibinputEvent();
37+
38+
Q_DISABLE_COPY_MOVE(LibinputEvent);
39+
40+
libinput_event_type type() const;
41+
42+
/**
43+
* @return The gesture event or std::nullopt if this event is not a gesture event. The returned object becomes invalid when its parent is deleted.
44+
* @see libinput_event_get_gesture_event
45+
*/
46+
std::optional<LibinputGestureEvent> gestureEvent() const;
47+
/**
48+
* @return The keyboard event or std::nullopt if this event is not a keyboard event. The returned object becomes invalid when its parent is deleted.
49+
* @see libinput_event_get_keyboard_event
50+
*/
51+
std::optional<LibinputKeyboardEvent> keyboardEvent() const;
52+
/**
53+
* @return The pointer event or std::nullopt if this event is not a pointer event. The returned object becomes invalid when its parent is deleted.
54+
* @see libinput_event_get_pointer_event
55+
*/
56+
std::optional<LibinputPointerEvent> pointerEvent() const;
57+
58+
private:
59+
libinput_event *m_event;
60+
};
61+
62+
}

0 commit comments

Comments
 (0)