Skip to content

Commit

Permalink
libgestures: move everything to libgestures namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
taj-ny committed Oct 17, 2024
1 parent b294cb4 commit 5b53964
Show file tree
Hide file tree
Showing 50 changed files with 401 additions and 231 deletions.
23 changes: 22 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
add_subdirectory(kwin)
add_subdirectory(libgestures)

set(libgestures_SRCS
libgestures/libgestures/actions/action.cpp
libgestures/libgestures/actions/command.cpp
libgestures/libgestures/actions/kdeglobalshortcut.cpp
libgestures/libgestures/actions/keysequence.cpp
libgestures/libgestures/gestures/gesture.cpp
libgestures/libgestures/gestures/gesturerecognizer.cpp
libgestures/libgestures/gestures/holdgesture.cpp
libgestures/libgestures/gestures/pinchgesture.cpp
libgestures/libgestures/gestures/swipegesture.cpp
libgestures/libgestures/condition.cpp
libgestures/libgestures/input.h
libgestures/libgestures/windowinfoprovider.cpp
)

add_library(libgestures STATIC ${libgestures_SRCS})
target_link_libraries(libgestures PRIVATE
Qt6::Core
Qt6::DBus
)
target_include_directories(libgestures PUBLIC libgestures)
4 changes: 2 additions & 2 deletions src/kwin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(kwin_gestures_SOURCES
config/config.cpp
impl/kwinvirtualinputdevice.cpp
impl/kwinwindowdataprovider.cpp
impl/kwininput.cpp
impl/kwinwindowinfoprovider.cpp
effect.cpp
inputfilter.cpp
main.cpp
Expand Down
68 changes: 34 additions & 34 deletions src/kwin/config/config.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "actions/command.h"
#include "actions/kdeglobalshortcut.h"
#include "actions/keysequence.h"
#include "config.h"
#include "gestures/holdgesture.h"
#include "gestures/pinchgesture.h"
#include "gestures/swipegesture.h"
#include <KConfig>

void Config::read(std::shared_ptr<GestureInputEventFilter> filter, std::shared_ptr<VirtualInputDevice> virtualInputDevice, std::shared_ptr<WindowDataProvider> windowDataProvider)
#include "libgestures/actions/command.h"
#include "libgestures/actions/kdeglobalshortcut.h"
#include "libgestures/actions/keysequence.h"
#include "libgestures/gestures/holdgesture.h"
#include "libgestures/gestures/pinchgesture.h"
#include "libgestures/gestures/swipegesture.h"

void Config::read(std::shared_ptr<GestureInputEventFilter> filter, std::shared_ptr<libgestures::Input> input, std::shared_ptr<libgestures::WindowInfoProvider> windowInfoProvider)
{
filter->unregisterGestures();

Expand Down Expand Up @@ -37,14 +37,14 @@ void Config::read(std::shared_ptr<GestureInputEventFilter> filter, std::shared_p
const bool triggerWhenThresholdReached = gestureGroup.readEntry("TriggerWhenThresholdReached", false);
const bool triggerOneActionOnly = gestureGroup.readEntry("TriggerOneActionOnly", false);

std::shared_ptr<Gesture> gesture;
std::shared_ptr<libgestures::Gesture> gesture;
if (gestureType == "Hold")
{
const auto holdGestureGroup = gestureGroup.group("Hold");

const auto threshold = holdGestureGroup.readEntry("Threshold", 0);

const auto holdGesture = std::make_shared<HoldGesture>(triggerWhenThresholdReached, minimumFingers, maximumFingers, triggerOneActionOnly, threshold);
const auto holdGesture = std::make_shared<libgestures::HoldGesture>(triggerWhenThresholdReached, minimumFingers, maximumFingers, triggerOneActionOnly, threshold);
filter->registerTouchpadGesture(holdGesture);
gesture = holdGesture;
}
Expand All @@ -53,14 +53,14 @@ void Config::read(std::shared_ptr<GestureInputEventFilter> filter, std::shared_p
const auto pinchGestureGroup = gestureGroup.group("Pinch");

const auto directionStr = pinchGestureGroup.readEntry("Direction", "");
PinchDirection direction = PinchDirection::Any;
libgestures::PinchDirection direction = libgestures::PinchDirection::Any;
if (directionStr == "Contracting")
direction = PinchDirection::Contracting;
direction = libgestures::PinchDirection::Contracting;
else if (directionStr == "Expanding")
direction = PinchDirection::Expanding;
direction = libgestures::PinchDirection::Expanding;
const qreal threshold = pinchGestureGroup.readEntry("Threshold", 1.0);

const auto pinchGesture = std::make_shared<PinchGesture>(triggerWhenThresholdReached, minimumFingers, maximumFingers, triggerOneActionOnly, threshold, direction);
const auto pinchGesture = std::make_shared<libgestures::PinchGesture>(triggerWhenThresholdReached, minimumFingers, maximumFingers, triggerOneActionOnly, threshold, direction);
filter->registerTouchpadGesture(pinchGesture);
gesture = pinchGesture;
}
Expand All @@ -69,21 +69,21 @@ void Config::read(std::shared_ptr<GestureInputEventFilter> filter, std::shared_p
const auto swipeGestureGroup = gestureGroup.group("Swipe");

const auto directionString = swipeGestureGroup.readEntry("Direction", "Left");
auto direction = SwipeDirection::Left;
auto direction = libgestures::SwipeDirection::Left;
if (directionString == "Right")
direction = SwipeDirection::Right;
direction = libgestures::SwipeDirection::Right;
else if (directionString == "Up")
direction = SwipeDirection::Up;
direction = libgestures::SwipeDirection::Up;
else if (directionString == "Down")
direction = SwipeDirection::Down;
direction = libgestures::SwipeDirection::Down;
else if (directionString == "LeftRight")
direction = SwipeDirection::LeftRight;
direction = libgestures::SwipeDirection::LeftRight;
else if (directionString == "UpDown")
direction = SwipeDirection::UpDown;
direction = libgestures::SwipeDirection::UpDown;

const qreal threshold = swipeGestureGroup.readEntry("Threshold", 0.0);

const auto swipeGesture = std::make_shared<SwipeGesture>(triggerWhenThresholdReached, minimumFingers, maximumFingers, triggerOneActionOnly, threshold, direction);
const auto swipeGesture = std::make_shared<libgestures::SwipeGesture>(triggerWhenThresholdReached, minimumFingers, maximumFingers, triggerOneActionOnly, threshold, direction);
filter->registerTouchpadGesture(swipeGesture);
gesture = swipeGesture;
}
Expand All @@ -98,67 +98,67 @@ void Config::read(std::shared_ptr<GestureInputEventFilter> filter, std::shared_p
const auto actionType = actionGroup.readEntry("Type", "");
const auto repeatInterval = actionGroup.readEntry("RepeatInterval", 0.0);

std::shared_ptr<GestureAction> action;
std::shared_ptr<libgestures::GestureAction> action;
if (actionType == "Command")
{
const auto commandActionGroup = actionGroup.group("Command");
const auto command = commandActionGroup.readEntry("Command", "");
action = std::make_shared<CommandGestureAction>(repeatInterval, command);
action = std::make_shared<libgestures::CommandGestureAction>(repeatInterval, command);
}
else if (actionType == "GlobalShortcut")
{
const auto globalShortcutActionGroup = actionGroup.group("GlobalShortcut");
const auto component = globalShortcutActionGroup.readEntry("Component", "");
const auto shortcut = globalShortcutActionGroup.readEntry("Shortcut", "");
action = std::make_shared<KDEGlobalShortcutGestureAction>(repeatInterval, component, shortcut);
action = std::make_shared<libgestures::KDEGlobalShortcutGestureAction>(repeatInterval, component, shortcut);
}
else if (actionType == "KeySequence")
{
const auto keySequenceActionGroup = actionGroup.group("KeySequence");
const auto script = keySequenceActionGroup.readEntry("Sequence", "");
action = std::make_shared<KeySequenceGestureAction>(repeatInterval, virtualInputDevice, script);
action = std::make_shared<libgestures::KeySequenceGestureAction>(repeatInterval, input, script);
}

if (!action)
continue;

const auto &conditions = readConditions(actionGroup.group("Conditions"), windowDataProvider);
const auto &conditions = readConditions(actionGroup.group("Conditions"), windowInfoProvider);
for (const auto &condition : conditions)
action->addCondition(condition);

gesture->addAction(action);
}

const auto &conditions = readConditions(gestureGroup.group("Conditions"), windowDataProvider);
const auto &conditions = readConditions(gestureGroup.group("Conditions"), windowInfoProvider);
for (const auto &condition : conditions)
gesture->addCondition(condition);
}
}
}

std::vector<Condition> Config::readConditions(const KConfigGroup &group, std::shared_ptr<WindowDataProvider> windowDataProvider)
std::vector<libgestures::Condition> Config::readConditions(const KConfigGroup &group, std::shared_ptr<libgestures::WindowInfoProvider> windowInfoProvider)
{
std::vector<Condition> conditions;
std::vector<libgestures::Condition> conditions;
for (const auto &conditionGroupName : group.groupList())
{
const auto conditionGroup = group.group(conditionGroupName);

Condition condition(windowDataProvider);
libgestures::Condition condition(windowInfoProvider);
condition.setNegate(conditionGroup.readEntry("Negate", false));

const auto windowClassRegex = conditionGroup.readEntry("WindowClassRegex", "");
if (windowClassRegex != "")
condition.setWindowClassRegex(QRegularExpression(windowClassRegex));

auto windowState = WindowState::Unimportant;
std::optional<WindowState> windowStateOpt;
auto windowState = libgestures::WindowState::Unimportant;
std::optional<libgestures::WindowState> windowStateOpt;
const auto windowStateStr = conditionGroup.readEntry("WindowState", "");
for (const auto &windowStateFlag : windowStateStr.split("|"))
{
if (windowStateFlag == "Fullscreen")
windowState = windowState | WindowState::Fullscreen;
windowState = windowState | libgestures::WindowState::Fullscreen;
else if (windowStateFlag == "Maximized")
windowState = windowState | WindowState::Maximized;
windowState = windowState | libgestures::WindowState::Maximized;
}
if (windowState)
condition.setWindowState(windowState);
Expand Down
10 changes: 4 additions & 6 deletions src/kwin/config/config.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#pragma once

#include "condition.h"
#include "gestures.h"
#include "inputfilter.h"
#include <KConfigGroup>
#include "virtualinputdevice.h"
#include "windowdataprovider.h"
#include "libgestures/condition.h"
#include "libgestures/input.h"

class Config
{
Expand All @@ -18,11 +16,11 @@ class Config

~Config() = default;

void read(std::shared_ptr<GestureInputEventFilter> filter, std::shared_ptr<VirtualInputDevice> virtualInputDevice, std::shared_ptr<WindowDataProvider> windowDataProvider);
void read(std::shared_ptr<GestureInputEventFilter> filter, std::shared_ptr<libgestures::Input> input, std::shared_ptr<libgestures::WindowInfoProvider> windowInfoProvider);

private:
Config() = default;

static std::vector<Condition> readConditions(const KConfigGroup &group, std::shared_ptr<WindowDataProvider> windowDataProvider);
static std::vector<libgestures::Condition> readConditions(const KConfigGroup &group, std::shared_ptr<libgestures::WindowInfoProvider> windowInfoProvider);
static std::vector<int> stringIntListToSortedIntVector(const QList<QString> &list);
};
3 changes: 1 addition & 2 deletions src/kwin/effect.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "config/config.h"
#include "effect.h"
#include "input.h"

Effect::Effect()
{
Expand All @@ -22,5 +21,5 @@ void Effect::reconfigure(ReconfigureFlags flags)
{
Q_UNUSED(flags)

Config::instance().read(m_inputEventFilter, m_virtualInputDevice, m_windowDataProvider);
Config::instance().read(m_inputEventFilter, m_input, m_windowInfoProvider);
}
8 changes: 4 additions & 4 deletions src/kwin/effect.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "effect/effect.h"
#include "impl/kwinvirtualinputdevice.h"
#include "impl/kwinwindowdataprovider.h"
#include "impl/kwininput.h"
#include "impl/kwinwindowinfoprovider.h"
#include "inputfilter.h"

class Effect : public KWin::Effect
Expand All @@ -17,6 +17,6 @@ class Effect : public KWin::Effect
void reconfigure(ReconfigureFlags flags) override;
private:
std::shared_ptr<GestureInputEventFilter> m_inputEventFilter = std::make_shared<GestureInputEventFilter>();
std::shared_ptr<VirtualInputDevice> m_virtualInputDevice = std::make_shared<KWinVirtualInputDevice>();
std::shared_ptr<WindowDataProvider> m_windowDataProvider = std::make_shared<KWinWindowDataProvider>();
std::shared_ptr<libgestures::Input> m_input = std::make_shared<KWinInput>();
std::shared_ptr<libgestures::WindowInfoProvider> m_windowInfoProvider = std::make_shared<KWinWindowInfoProvider>();
};
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
#include "input_event.h"
#include "input_event_spy.h"
#include "keyboard_input.h"
#include "kwinvirtualinputdevice.h"
#include "kwininput.h"
#include "wayland/keyboard.h"
#include "xkb.h"

KWinVirtualInputDevice::KWinVirtualInputDevice()
KWinInput::KWinInput()
: m_device(std::make_unique<InputDevice>())
{
KWin::input()->addInputDevice(m_device.get());
}

KWinVirtualInputDevice::~KWinVirtualInputDevice()
KWinInput::~KWinInput()
{
KWin::input()->removeInputDevice(m_device.get());
}

void KWinVirtualInputDevice::keyboardPress(const uint32_t &key) const
void KWinInput::keyboardPress(const uint32_t &key) const
{
sendKey(key, KWin::InputRedirection::KeyboardKeyState::KeyboardKeyPressed);
}

void KWinVirtualInputDevice::keyboardRelease(const uint32_t &key) const
void KWinInput::keyboardRelease(const uint32_t &key) const
{
sendKey(key, KWin::InputRedirection::KeyboardKeyState::KeyboardKeyReleased);
}

void KWinVirtualInputDevice::sendKey(const uint32_t &key, const KWin::InputRedirection::KeyboardKeyState &state) const
void KWinInput::sendKey(const uint32_t &key, const KWin::InputRedirection::KeyboardKeyState &state) const
{
// https://invent.kde.org/plasma/kwin/-/blob/Plasma/6.2/src/keyboard_input.cpp
const auto xkb = KWin::input()->keyboard()->xkb();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "core/inputdevice.h"
#include "virtualinputdevice.h"
#include "libgestures/input.h"

class InputDevice : public KWin::InputDevice
{
Expand All @@ -22,11 +22,11 @@ class InputDevice : public KWin::InputDevice
bool isLidSwitch() const override;
};

class KWinVirtualInputDevice : public VirtualInputDevice
class KWinInput : public libgestures::Input
{
public:
KWinVirtualInputDevice();
~KWinVirtualInputDevice() override;
KWinInput();
~KWinInput() override;

void keyboardPress(const uint32_t &key) const override;
void keyboardRelease(const uint32_t &key) const override;
Expand Down
18 changes: 0 additions & 18 deletions src/kwin/impl/kwinwindowdataprovider.cpp

This file was deleted.

11 changes: 0 additions & 11 deletions src/kwin/impl/kwinwindowdataprovider.h

This file was deleted.

18 changes: 18 additions & 0 deletions src/kwin/impl/kwinwindowinfoprovider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "effect/effecthandler.h"
#include "kwinwindowinfoprovider.h"
#include "window.h"

std::optional<const libgestures::WindowInfo> KWinWindowInfoProvider::activeWindow() const
{
const auto window = KWin::effects->activeWindow();
if (!window)
return std::nullopt;

libgestures::WindowState state = libgestures::WindowState::Unimportant;
if (window->isFullScreen())
state = state | libgestures::WindowState::Fullscreen;
if (window->frameGeometry() == KWin::effects->clientArea(KWin::MaximizeArea, KWin::effects->activeScreen(), KWin::effects->currentDesktop()))
state = state | libgestures::WindowState::Maximized;

return libgestures::WindowInfo(window->caption(), window->window()->resourceClass(), window->window()->resourceName(), state);
}
11 changes: 11 additions & 0 deletions src/kwin/impl/kwinwindowinfoprovider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "libgestures/windowinfoprovider.h"

class KWinWindowInfoProvider : public libgestures::WindowInfoProvider
{
public:
KWinWindowInfoProvider() = default;

[[nodiscard]] std::optional<const libgestures::WindowInfo> activeWindow() const override;
};
Loading

0 comments on commit 5b53964

Please sign in to comment.