{
ASSERT(uiElements.size() == requiredArguments);
auto coord = uiElements.front()->getScanningCoordinates();
- return utils::EventGenerator::generateTapGesture(coord.x, coord.y, DerivedType::hold_time);
+ return utils::generateTapGesture(coord.x, coord.y, DerivedType::hold_time);
}
};
auto from = getStartPoint();
auto to = getEndPoint();
- return utils::EventGenerator::generateDragGesture(from.x, from.y, to.x, to.y, DEFAULT_STEPS_NUMBER, NO_DELAY);
+ return utils::generateDragGesture(from.x, from.y, to.x, to.y, DEFAULT_STEPS_NUMBER, NO_DELAY);
}
protected:
auto from = uiElements.front()->getScanningCoordinates();
auto to = uiElements.back()->getScanningCoordinates();
- return utils::EventGenerator::generateDragGesture(from.x, from.y, to.x, to.y, DerivedType::steps, DerivedType::hold_time);
+ return utils::generateDragGesture(from.x, from.y, to.x, to.y, DerivedType::steps, DerivedType::hold_time);
}
};
ASSERT(GestureDispatcher<DerivedType>::uiElements.size() == requiredArguments);
auto coord = GestureDispatcher<DerivedType>::uiElements.front()->getScanningCoordinates();
- return utils::EventGenerator::generatePinchGesture(coord.x, coord.y, DerivedType::radius_change, DEFAULT_STEPS_NUMBER);
+ return utils::generatePinchGesture(coord.x, coord.y, DerivedType::radius_change, DEFAULT_STEPS_NUMBER);
}
};
namespace utils
{
- class EflKeyInputGenerator
+ DBus::ValueOrError<void> generateKeyPress(const std::string &keyId, unsigned multiplicity, double hold_time)
{
- public:
- EflKeyInputGenerator()
- : handler(nullptr, efl_util_input_deinitialize_generator)
- {
- auto h = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_KEYBOARD);
+ DEBUG("Key event, name: %s, multiplicity: %d, hold_time: %lf", keyId.c_str(), multiplicity, hold_time);
- if (!h)
- ERROR("No input generator");
-
- handler.reset(h);
- }
-
- void generateKeyDown(const std::string &id)
- {
- auto ret = efl_util_input_generate_key(handler.get(), id.c_str(), KEY_DOWN);
-
- if (ret != EFL_UTIL_ERROR_NONE)
- ERROR("Event cannot be generated because %s", ret == EFL_UTIL_ERROR_INVALID_PARAMETER ? "invalid parameter" : "permission denied");
- }
-
- void generateKeyUp(const std::string &id)
- {
- auto ret = efl_util_input_generate_key(handler.get(), id.c_str(), KEY_UP);
-
- if (ret != EFL_UTIL_ERROR_NONE)
- ERROR("Event cannot be generated because %s", ret == EFL_UTIL_ERROR_INVALID_PARAMETER ? "invalid parameter" : "permission denied");
- }
-
- private:
- static constexpr int KEY_DOWN = 1;
- static constexpr int KEY_UP = 0;
-
- std::unique_ptr<_efl_util_inputgen_h, int(*)(_efl_util_inputgen_h *)> handler;
- };
-
- ecore::Timer EventGenerator::timer = {};
-
- void EventGenerator::generateKeyPress(const std::string &keyId, DoneCallback doneCb, unsigned multiplicity, PressType type)
- {
- DEBUG("key: %s, multiplicity: %d", keyId.c_str(), multiplicity);
-
- auto delay = 0.0;
- switch (type) {
- case PressType::SHORT:
- delay = SHORT_DELAY;
- break;
-
- case PressType::LONG:
- delay = LONG_DELAY;
- break;
-
- default:
- ASSERT(0, "Invalid press type");
- }
-
- GeneratorData genData{keyId, multiplicity, delay};
-
- timer.reset(NO_DELAY, [genData, doneCb = std::move(doneCb)]() {
- return createKeyDownEvent(genData, std::move(doneCb));
- });
+ DBus::DBusClient dbus {dbusLocators::accessibilityEMod::BUS,
+ dbusLocators::accessibilityEMod::OBJ_PATH,
+ dbusLocators::accessibilityEMod::INTERFACE,
+ DBus::ConnectionType::SYSTEM};
+ return dbus.method<void(std::string, int, double)>("DispatchKeyEvent").call(keyId, static_cast<int>(multiplicity), hold_time);
}
- DBus::ValueOrError<void> EventGenerator::generateTapGesture(int x, int y, double press_time)
+ DBus::ValueOrError<void> generateTapGesture(int x, int y, double press_time)
{
DEBUG("Tap with drag gesture, x: %d, y: %d, press time: %lf", x, y, press_time);
return dbus.method<void(int, int, int, int, int, double)>("DispatchDragEvent").call(x, y, x, y, tap_steps, press_time);
}
- DBus::ValueOrError<void> EventGenerator::generateDragGesture(int from_x, int from_y, int to_x, int to_y, int steps, double hold_time)
+ DBus::ValueOrError<void> generateDragGesture(int from_x, int from_y, int to_x, int to_y, int steps, double hold_time)
{
DEBUG("Drag gesture, from (x, y): (%d, %d), to (x, y): (%d, %d), steps: %d, hold on first time: %lf", from_x, from_y, to_x, to_y, steps, hold_time);
return dbus.method<void(int, int, int, int, int, double)>("DispatchDragEvent").call(from_x, from_y, to_x, to_y, steps, hold_time);
}
- DBus::ValueOrError<void> EventGenerator::generatePinchGesture(int x, int y, int radius_change, int steps)
+ DBus::ValueOrError<void> generatePinchGesture(int x, int y, int radius_change, int steps)
{
DEBUG("Pinch gesture, x: %d, y: %d, radius change: %d, steps: %d", x, y, radius_change, steps);
return dbus.method<void(int, int, int, int)>("DispatchPinchEvent").call(x, y, radius_change, steps);
}
- ecore::TimerRepetitionPolicy EventGenerator::createKeyDownEvent(GeneratorData genData, DoneCallback doneCb)
- {
- DEBUG("invoked");
-
- EflKeyInputGenerator inputgen;
- inputgen.generateKeyDown(genData.key);
-
- timer.reset(genData.releaseDelay, [genData, doneCb = std::move(doneCb)]() {
- return createKeyUpEvent(genData, std::move(doneCb));
- });
-
- return ecore::TimerRepetitionPolicy::cancel;
- }
-
- ecore::TimerRepetitionPolicy EventGenerator::createKeyUpEvent(GeneratorData genData, DoneCallback doneCb)
- {
- DEBUG("invoked");
-
- EflKeyInputGenerator inputgen;
- inputgen.generateKeyUp(genData.key);
-
- --(genData.multiplicity);
- if (genData.multiplicity > 0)
- timer.reset(SHORT_DELAY, [genData, doneCb = std::move(doneCb)]() {
- return createKeyDownEvent(genData, std::move(doneCb));
- });
-
- return ecore::TimerRepetitionPolicy::cancel;
- }
-
std::array<Optional<std::string>, (size_t)Argument::_count> parseArguments(int argc, char **argv)
{
auto b = std::unique_ptr<bundle, int(*)(bundle *)>(bundle_import_from_argv(argc, argv), bundle_free);
return v;
}
- class EventGenerator
- {
- public:
- enum class PressType {
- SHORT,
- LONG
- };
-
- struct GeneratorData {
- std::string key;
- unsigned multiplicity;
- double releaseDelay;
- };
-
- static void generateKeyPress(const std::string &keyId, DoneCallback doneCb, unsigned multiplicity = SINGLE_PRESS,
- PressType type = PressType::SHORT);
-
- static DBus::ValueOrError<void> generateTapGesture(int x, int y, double press_time);
- static DBus::ValueOrError<void> generateDragGesture(int from_x, int from_y, int to_x, int to_y, int steps, double hold_time);
- static DBus::ValueOrError<void> generatePinchGesture(int x, int y, int radius_change, int steps);
-
- private:
- static ecore::TimerRepetitionPolicy createKeyDownEvent(GeneratorData genData, DoneCallback doneCb);
- static ecore::TimerRepetitionPolicy createKeyUpEvent(GeneratorData genData, DoneCallback doneCb);
-
- static ecore::Timer timer;
-
- static constexpr unsigned SINGLE_PRESS = 1;
- static constexpr double SHORT_DELAY = 0.1;
- static constexpr double LONG_DELAY = 1.0;
- static constexpr double NO_DELAY = 0.0;
- };
+ DBus::ValueOrError<void> generateKeyPress(const std::string &keyId, unsigned multiplicity = 1, double hold_time = 0.0);
+ DBus::ValueOrError<void> generateTapGesture(int x, int y, double press_time);
+ DBus::ValueOrError<void> generateDragGesture(int from_x, int from_y, int to_x, int to_y, int steps, double hold_time);
+ DBus::ValueOrError<void> generatePinchGesture(int x, int y, int radius_change, int steps);
/**
* @brief Enum representing allowed arguments