pax_global_header00006660000000000000000000000064135447055170014525gustar00rootroot0000000000000052 comment=19ff218870311206c8fa47a3fcbe174d72373c8c ydotool-0.1.8/000077500000000000000000000000001354470551700132245ustar00rootroot00000000000000ydotool-0.1.8/.gitlab-ci.yml000066400000000000000000000046431354470551700156670ustar00rootroot00000000000000before_script: - apt update - apt install -y build-essential cmake wget rpm libboost-program-options-dev build:debian:9: stage: build image: debian:9 artifacts: untracked: true script: - mkdir build - cd build - wget -O libuInputPlus.deb 'https://gitlab.com/ReimuNotMoe/libuInputPlus/-/jobs/artifacts/master/raw/build/libuInputPlus_0.1.3_.deb?job=package:debian:9' - wget -O libevdevPlus.deb 'https://gitlab.com/ReimuNotMoe/libevdevPlus/-/jobs/artifacts/master/raw/build/libevdevPlus_0.1.0_.deb?job=package:debian:9' - dpkg -i libuInputPlus.deb && dpkg -i libevdevPlus.deb - cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS='-O1 -g' .. - make package:debian:9: stage: deploy dependencies: - build:debian:9 script: - cd build && make package artifacts: paths: - "build/*.deb" - "build/ydotool_static" build:ubuntu:18.04: stage: build image: ubuntu:18.04 artifacts: untracked: true script: - mkdir build - cd build - wget -O libuInputPlus.deb 'https://gitlab.com/ReimuNotMoe/libuInputPlus/-/jobs/artifacts/master/raw/build/libuInputPlus_0.1.3_.deb?job=package:ubuntu:18.04' - wget -O libevdevPlus.deb 'https://gitlab.com/ReimuNotMoe/libevdevPlus/-/jobs/artifacts/master/raw/build/libevdevPlus_0.1.0_.deb?job=package:ubuntu:18.04' - dpkg -i libuInputPlus.deb && dpkg -i libevdevPlus.deb - cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS='-O1 -g' .. - make package:ubuntu:18.04: stage: deploy dependencies: - build:ubuntu:18.04 script: - cd build && make package artifacts: paths: - "build/*.deb" - "build/ydotool_static" build:ubuntu:19.04: stage: build image: ubuntu:19.04 artifacts: untracked: true script: - mkdir build - cd build - wget -O libuInputPlus.deb 'https://gitlab.com/ReimuNotMoe/libuInputPlus/-/jobs/artifacts/master/raw/build/libuInputPlus_0.1.3_.deb?job=package:ubuntu:19.04' - wget -O libevdevPlus.deb 'https://gitlab.com/ReimuNotMoe/libevdevPlus/-/jobs/artifacts/master/raw/build/libevdevPlus_0.1.0_.deb?job=package:ubuntu:19.04' - dpkg -i libuInputPlus.deb && dpkg -i libevdevPlus.deb - cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS='-O1 -g' .. - make package:ubuntu:19.04: stage: deploy dependencies: - build:ubuntu:19.04 script: - cd build && make package artifacts: paths: - "build/*.deb" - "build/ydotool_static" ydotool-0.1.8/CMakeLists.txt000066400000000000000000000077031354470551700157730ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.0) project(ydotool) set(CMAKE_CXX_STANDARD 14) set(PROJECT_VERSION "0.1.5") set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) set(CPACK_PACKAGE_VERSION_MAJOR "0") set(CPACK_PACKAGE_VERSION_MINOR "1") set(CPACK_PACKAGE_VERSION_PATCH "5") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Generic Linux command-line automation tool (no X!)") set(CPACK_PACKAGE_CONTACT "Reimu NotMoe ") set(CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/ReimuNotMoe/ydotool") set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CMAKE_PROJECT_HOMEPAGE_URL}) set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.14), libstdc++6 (>= 5.2), libuinputplus (>= 0.1.3), libevdevplus (>= 0.1.0)") set(CPACK_PACKAGE_FILE_NAME ${PROJECT_NAME}_${PROJECT_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}) set(CPACK_DEBIAN_DEBUGINFO_PACKAGE yes) set(CPACK_DEBIAN_COMPRESSION_TYPE "xz") set(CPACK_GENERATOR "DEB;RPM;TXZ") set(CPACK_SOURCE_GENERATOR "DEB;RPM;TXZ") include(CPack) include(GNUInstallDirs) set(SOURCE_FILES_LIBRARY CommonIncludes.hpp Library/libydotool.cpp Library/libydotool.hpp Library/Tool.hpp Library/Tool.cpp # Library/Transport.cpp Library/Transport.hpp Library/Instance.cpp Library/Instance.hpp Library/Utils.cpp Library/Utils.hpp Tools/Tools.hpp Tools/MouseMove/MouseMove.hpp Tools/MouseMove/MouseMove.cpp Tools/Key/Key.hpp Tools/Key/Key.cpp Tools/Click/Click.hpp Tools/Click/Click.cpp Tools/Type/Type.hpp Tools/Type/Type.cpp Tools/Recorder/Recorder.cpp Tools/Recorder/Recorder.hpp ) # Library/Transports/UnixSocket.cpp Library/Transports/UnixSocket.hpp ) set(SOURCE_FILES_DAEMON CommonIncludes.hpp Daemon/ydotoold.cpp Daemon/ydotoold.hpp) set(SOURCE_FILES_CLIENT CommonIncludes.hpp Client/ydotool.cpp Client/ydotool.hpp) add_library(ydotool_library SHARED ${SOURCE_FILES_LIBRARY}) set_target_properties(ydotool_library PROPERTIES OUTPUT_NAME ydotool) add_library(ydotool_library_static STATIC ${SOURCE_FILES_LIBRARY}) set_target_properties(ydotool_library_static PROPERTIES OUTPUT_NAME ydotool) target_link_libraries(ydotool_library dl boost_program_options uInputPlus evdevPlus) target_link_libraries(ydotool_library_static dl boost_program_options uInputPlus evdevPlus) link_libraries(-L.) add_executable(ydotoold ${SOURCE_FILES_DAEMON}) target_link_libraries(ydotoold ydotool_library dl pthread boost_program_options uInputPlus evdevPlus) add_executable(ydotool_client ${SOURCE_FILES_CLIENT}) target_link_libraries(ydotool_client ydotool_library boost_program_options pthread uInputPlus evdevPlus) set_target_properties(ydotool_client PROPERTIES OUTPUT_NAME ydotool) add_executable(ydotool_client_static ${SOURCE_FILES_CLIENT}) target_link_libraries(ydotool_client_static ydotool_library_static boost_program_options pthread uInputPlus evdevPlus -static) set_target_properties(ydotool_client_static PROPERTIES OUTPUT_NAME ydotool_static) #add_library(mousemove SHARED Tools/MouseMove/MouseMove.hpp Tools/MouseMove/MouseMove.cpp) #target_link_libraries(mousemove ydotool_library boost_program_options uInputPlus evdevPlus) # #add_library(key SHARED Tools/Key/Key.hpp Tools/Key/Key.cpp) #target_link_libraries(key ydotool_library boost_program_options uInputPlus evdevPlus) # #add_library(click SHARED Tools/Click/Click.hpp Tools/Click/Click.cpp) #target_link_libraries(click ydotool_library boost_program_options uInputPlus evdevPlus) # #add_library(type SHARED Tools/Type/Type.hpp Tools/Type/Type.cpp) #target_link_libraries(type ydotool_library boost_program_options uInputPlus evdevPlus) # #add_library(recorder SHARED Tools/Recorder/Recorder.cpp Tools/Recorder/Recorder.hpp) #target_link_libraries(recorder ydotool_library boost_program_options uInputPlus evdevPlus) install(TARGETS ydotool_library ydotool_library_static DESTINATION lib) #install(TARGETS mousemove key click type recorder DESTINATION lib/ydotool) install(TARGETS ydotoold ydotool_client DESTINATION bin)ydotool-0.1.8/Client/000077500000000000000000000000001354470551700144425ustar00rootroot00000000000000ydotool-0.1.8/Client/ydotool.cpp000066400000000000000000000066351354470551700166510ustar00rootroot00000000000000/* This file is part of ydotool. Copyright (C) 2018-2019 ReimuNotMoe This program is free software: you can redistribute it and/or modify it under the terms of the MIT License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include "ydotool.hpp" using namespace ydotool; using namespace uInputPlus; uInput *myuInput = nullptr; Tool::ToolManager tool_mgr; static void ShowHelp() { std::cerr << "Usage: ydotool \n" "Available commands:\n"; for (auto &it : tool_mgr.init_funcs) { std::cerr << " " << it.first << std::endl; } } int InituInput() { if (!myuInput) { uInputSetup us({"ydotool virtual device"}); myuInput = new uInput({us}); } return 0; } std::vector explode(const std::string& str, char delim) { std::vector result; std::istringstream iss(str); for (std::string token; std::getline(iss, token, delim); ) { result.push_back(std::move(token)); } return result; } int connect_socket(const char *path_socket) { int fd_client = socket(AF_UNIX, SOCK_STREAM, 0); if (fd_client == -1) { std::cerr << "ydotool: " << "failed to create socket: " << strerror(errno) << "\n"; return -2; } sockaddr_un addr{0}; memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, path_socket, sizeof(addr.sun_path)-1); if (connect(fd_client, reinterpret_cast(&addr), sizeof(addr))) return -1; return fd_client; } int socket_callback(uint16_t type, uint16_t code, int32_t val, void *userp) { uInputRawData buf{0}; buf.type = type; buf.code = code; buf.value = val; int fd = (intptr_t)userp; send(fd, &buf, sizeof(buf), 0); return 0; } const char default_library_path[] = "/usr/local/lib/ydotool:/usr/lib/ydotool:/usr/lib/x86_64-linux-gnu/ydotool:/usr/lib/i386-linux-gnu/ydotool"; int main(int argc, const char **argv) { const char *library_path = default_library_path; // std::cerr << "ydotool: library search path: " << library_path << "\n"; // for (auto &it : explode(library_path, ':')) { // tool_mgr.ScanPath(it); // } if (argc < 2) { ShowHelp(); exit(1); } if (strncmp(argv[1], "-h", 2) == 0 || strncmp(argv[1], "--h", 3) == 0 || strcmp(argv[1], "help") == 0) { ShowHelp(); exit(1); } auto it_cmd = tool_mgr.init_funcs.find(argv[1]); if (it_cmd == tool_mgr.init_funcs.end()) { std::cerr << "ydotool: Unknown tool: " << argv[1] << "\n" << "Run 'ydotool help' if you want a tools list" << std::endl; exit(1); } auto instance = std::make_shared(); const char path_socket[] = "/tmp/.ydotool_socket"; int fd_client = connect_socket(path_socket); if (fd_client > 0) { std::cerr << "ydotool: notice: Using ydotoold backend\n"; instance->uInputContext = std::make_unique(); instance->uInputContext->Init(&socket_callback, (void *)(intptr_t)fd_client); } else { std::cerr << "ydotool: notice: ydotoold backend unavailable (may have latency+delay issues)\n"; instance->Init(); } auto tool_constructor = (void *(*)())it_cmd->second; auto *this_tool = static_cast(tool_constructor()); // std::cerr << "ydotool: debug: tool `" << this_tool->Name() << "' constructed at " << std::hex << this_tool << std::dec << std::endl; this_tool->Init(instance); int rc = this_tool->Exec(argc-1, &argv[1]); }ydotool-0.1.8/Client/ydotool.hpp000066400000000000000000000010451354470551700166440ustar00rootroot00000000000000/* This file is part of ydotool. Copyright (C) 2018-2019 ReimuNotMoe This program is free software: you can redistribute it and/or modify it under the terms of the MIT License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef YDOTOOL_YDOTOOL_HPP #define YDOTOOL_YDOTOOL_HPP #include "../CommonIncludes.hpp" #include "../Library/libydotool.hpp" #endif //YDOTOOL_YDOTOOL_HPP ydotool-0.1.8/CommonIncludes.hpp000066400000000000000000000020421354470551700166520ustar00rootroot00000000000000/* This file is part of ydotool. Copyright (C) 2018-2019 ReimuNotMoe This program is free software: you can redistribute it and/or modify it under the terms of the MIT License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef YDOTOOL_COMMONINCLUDES_HPP #define YDOTOOL_COMMONINCLUDES_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif //YDOTOOL_COMMONINCLUDES_HPP ydotool-0.1.8/Daemon/000077500000000000000000000000001354470551700144275ustar00rootroot00000000000000ydotool-0.1.8/Daemon/ydotoold.cpp000066400000000000000000000037631354470551700170010ustar00rootroot00000000000000/* This file is part of ydotool. Copyright (C) 2018-2019 ReimuNotMoe This program is free software: you can redistribute it and/or modify it under the terms of the MIT License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include "ydotoold.hpp" using namespace ydotool; //struct ep_ctx { // size_t bufpos_read = 0; // uint8_t buf_read[8]; //}; // //void fd_set_nonblocking(int fd) { // int flag = fcntl(fd, F_GETFL) | O_NONBLOCK; // fcntl(fd, F_SETFL, flag); //} Instance instance; static int client_handler(int fd) { uInputRawData buf{0}; while (true) { int rc = recv(fd, &buf, sizeof(buf), MSG_WAITALL); if (rc == sizeof(buf)) { instance.uInputContext->Emit(buf.type, buf.code, buf.value); } else { return 0; } } } int main(int argc, char **argv) { const char path_socket[] = "/tmp/.ydotool_socket"; unlink(path_socket); int fd_listener = socket(AF_UNIX, SOCK_STREAM, 0); if (fd_listener == -1) { std::cerr << "ydotoold: " << "failed to create socket: " << strerror(errno) << "\n"; abort(); } sockaddr_un addr{0}; memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, path_socket, sizeof(addr.sun_path)-1); if (bind(fd_listener, (struct sockaddr *)&addr, sizeof(addr))) { std::cerr << "ydotoold: " << "failed to bind to socket [" << path_socket << "]: " << strerror(errno) << "\n"; abort(); } if (listen(fd_listener, 16)) { std::cerr << "ydotoold: " << "failed to listen on socket [" << path_socket << "]: " << strerror(errno) << "\n"; abort(); } chmod(path_socket, 0600); std::cerr << "ydotoold: " << "listening on socket " << path_socket << "\n"; instance.Init("ydotoold virtual device"); while (int fd_client = accept(fd_listener, nullptr, nullptr)) { std::cerr << "ydotoold: accepted client\n"; std::thread thd(client_handler, fd_client); thd.detach(); } }ydotool-0.1.8/Daemon/ydotoold.hpp000066400000000000000000000010341354470551700167730ustar00rootroot00000000000000/* This file is part of ydotool. Copyright (C) 2018-2019 ReimuNotMoe This program is free software: you can redistribute it and/or modify it under the terms of the MIT License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef YDOTOOL_DAEMON_HPP #define YDOTOOL_DAEMON_HPP #include "../CommonIncludes.hpp" #include "../Library/Tool.hpp" #endif //YDOTOOL_DAEMON_HPP ydotool-0.1.8/LICENSE000066400000000000000000000020551354470551700142330ustar00rootroot00000000000000MIT License Copyright (c) 2018 Reimu NotMoe Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ydotool-0.1.8/Library/000077500000000000000000000000001354470551700146305ustar00rootroot00000000000000ydotool-0.1.8/Library/Instance.cpp000066400000000000000000000012721354470551700171020ustar00rootroot00000000000000/* This file is part of ydotool. Copyright (C) 2018-2019 ReimuNotMoe This program is free software: you can redistribute it and/or modify it under the terms of the MIT License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include "Instance.hpp" using namespace ydotool; void Instance::Init() { Init("ydotool virtual device"); } void Instance::Init(const std::string &device_name) { // uInputDeviceInfo ud(device_name); uInputSetup us(device_name); uInputContext = std::make_unique(); uInputContext->Init({us}); } ydotool-0.1.8/Library/Instance.hpp000066400000000000000000000013371354470551700171110ustar00rootroot00000000000000/* This file is part of ydotool. Copyright (C) 2018-2019 ReimuNotMoe This program is free software: you can redistribute it and/or modify it under the terms of the MIT License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef YDOTOOL_LIB_INSTANCE_HPP #define YDOTOOL_LIB_INSTANCE_HPP #include "../CommonIncludes.hpp" using namespace uInputPlus; namespace ydotool { class Instance { public: std::unique_ptr uInputContext; Instance() = default; void Init(); void Init(const std::string& device_name); }; } #endif //YDOTOOL_LIB_INSTANCE_HPP ydotool-0.1.8/Library/Tool.cpp000066400000000000000000000035571354470551700162630ustar00rootroot00000000000000/* This file is part of ydotool. Copyright (C) 2018-2019 ReimuNotMoe This program is free software: you can redistribute it and/or modify it under the terms of the MIT License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include "Tool.hpp" #include "Utils.hpp" #include "../Tools/Tools.hpp" using namespace ydotool::Tool; void ToolTemplate::Init(std::shared_ptr &__ydotool_instance) { ydotool_instance = __ydotool_instance; uInputContext = ydotool_instance->uInputContext.get(); } void ToolManager::ScanPath(const std::string &__path) { try { Utils::dir_foreach(__path, [this](const std::string &path_base, struct dirent *ent) { if (ent->d_type != DT_REG && ent->d_type != DT_LNK) return 1; std::string fullpath = path_base + "/" + std::string(ent->d_name); TryDlOpen(fullpath); return 0; }); } catch (...) { } } void ToolManager::TryDlOpen(const std::string &__path) { void *handle = dlopen(__path.c_str(), RTLD_LAZY); if (!handle) { std::cerr << "ydotool: dlopen failed: " << dlerror() << "\n"; return; } auto tool_name = (const char *)dlsym(handle, "ydotool_tool_name"); auto tool_fptr = dlsym(handle, "ydotool_tool_construct"); if (!tool_name || !tool_fptr) { dlclose(handle); return; } // std::cerr << "ToolManager: debug: tool found: " << tool_name << " at " << __path << "\n"; dl_handles[tool_name] = handle; init_funcs[tool_name] = tool_fptr; } ToolManager::ToolManager() { auto &i = init_funcs; i["click"] = (void *)&Tools::Click::construct; i["key"] = (void *)&Tools::Key::construct; i["mousemove"] = (void *)&Tools::MouseMove::construct; i["recorder"] = (void *)&Tools::Recorder::construct; i["type"] = (void *)&Tools::Type::construct; } ydotool-0.1.8/Library/Tool.hpp000066400000000000000000000022651354470551700162630ustar00rootroot00000000000000/* This file is part of ydotool. Copyright (C) 2018-2019 ReimuNotMoe This program is free software: you can redistribute it and/or modify it under the terms of the MIT License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef YDOTOOL_LIB_COMMANDS_HPP #define YDOTOOL_LIB_COMMANDS_HPP #include "../CommonIncludes.hpp" #include "Instance.hpp" namespace ydotool { namespace Tool { class ToolTemplate { public: std::shared_ptr ydotool_instance; uInput* uInputContext = nullptr; ToolTemplate() = default; ~ToolTemplate() = default; void Init(std::shared_ptr& __ydotool_instance); virtual const char *Name() = 0; virtual int Exec(int argc, const char **argv) = 0; }; class ToolManager { public: ToolManager(); std::unordered_map dl_handles; std::unordered_map init_funcs; void TryDlOpen(const std::string& __path); void ScanPath(const std::string& __path); }; } } #endif //YDOTOOL_LIB_COMMANDS_HPP ydotool-0.1.8/Library/Utils.cpp000066400000000000000000000026151354470551700164400ustar00rootroot00000000000000// // Created by root on 9/2/19. // #include "Utils.hpp" using namespace ydotool; void Utils::timespec_diff(struct timespec *start, struct timespec *stop, struct timespec *result) { if ((stop->tv_nsec - start->tv_nsec) < 0) { result->tv_sec = stop->tv_sec - start->tv_sec - 1; result->tv_nsec = stop->tv_nsec - start->tv_nsec + 1000000000; } else { result->tv_sec = stop->tv_sec - start->tv_sec; result->tv_nsec = stop->tv_nsec - start->tv_nsec; } } void Utils::dir_foreach(const std::string &path, const std::function& callback, bool recursive) { DIR *dir; struct dirent *ent; if ((dir = opendir(path.c_str()))) { int dotdot_flag = 0; while ((ent = readdir(dir))) { if (dotdot_flag != 2) { if (strcmp(ent->d_name, ".") == 0) { dotdot_flag++; continue; } if (strcmp(ent->d_name, "..") == 0) { dotdot_flag++; continue; } } int rc = callback(path, ent); if (rc == 1) continue; else if (rc == 2) break; if (recursive) { if (ent->d_type == DT_DIR) dir_foreach(path + "/" + std::string(ent->d_name), callback, recursive); } } closedir(dir); } else { throw std::system_error(errno, std::system_category(), strerror(errno)); } } uint32_t Utils::crc32(const void *buf, size_t len) { boost::crc_32_type result; result.process_bytes(buf, len); return result.checksum(); } ydotool-0.1.8/Library/Utils.hpp000066400000000000000000000010031354470551700164330ustar00rootroot00000000000000// // Created by root on 9/2/19. // #ifndef YDOTOOL_LIB_UTILS_HPP #define YDOTOOL_LIB_UTILS_HPP #include "../CommonIncludes.hpp" namespace ydotool { class Utils { public: static void timespec_diff(struct timespec *start, struct timespec *stop, struct timespec *result); static void dir_foreach(const std::string& path, const std::function& callback, bool recursive=false); static uint32_t crc32(const void *buf, size_t len); }; } #endif //YDOTOOL_LIB_UTILS_HPP ydotool-0.1.8/Library/libydotool.cpp000066400000000000000000000006411354470551700175150ustar00rootroot00000000000000/* This file is part of ydotool. Copyright (C) 2018-2019 ReimuNotMoe This program is free software: you can redistribute it and/or modify it under the terms of the MIT License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include "libydotool.hpp" ydotool-0.1.8/Library/libydotool.hpp000066400000000000000000000011141354470551700175160ustar00rootroot00000000000000/* This file is part of ydotool. Copyright (C) 2018-2019 ReimuNotMoe This program is free software: you can redistribute it and/or modify it under the terms of the MIT License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef YDOTOOL_LIBYDOTOOL_HPP #define YDOTOOL_LIBYDOTOOL_HPP #include "../CommonIncludes.hpp" #include "Instance.hpp" #include "Tool.hpp" namespace ydotool { } #endif //YDOTOOL_LIBYDOTOOL_HPP ydotool-0.1.8/README.md000066400000000000000000000052651354470551700145130ustar00rootroot00000000000000# ydotool Generic Linux command-line automation tool (no X!) #### Contents - [Usage](#usage) - [Examples](#examples) - [Technical Notes](#technical-notes) - [Packages](#packages) - [Build](#build) ## Usage In most times, replace `x` with `y`. :P Currently implemented command(s): - `type` - Type a string - `key` - Press keys - `mousemove` - Move mouse pointer to absolute position - `mousemove_relative` - Move mouse pointer to relative position - `click` - Click on mouse buttons ## Examples Type some words: ydotool type 'Hey guys. This is Austin.' Switch to tty1: ydotool key ctrl+alt+f1 Close a window in graphical environment: ydotool key Alt+F4 Move mouse pointer to 100,100: ydotool mousemove 100 100 Relatively move mouse pointer to -100,100: ydotool mousemove_relative -- -100 100 Mouse right click: ydotool click 2 ## Technical Notes #### Runtime This program requires access to `/dev/uinput`. This usually requires root permissions. You can use it on anything as long as it accepts keyboard/mouse/whatever input. For example, wayland, text console, etc. #### About the --delay option ydotool works differently from xdotool. xdotool sends X events directly to X server, while ydotool uses the uinput framework of Linux kernel to emulate an input device. When ydotool runs and creates an virtual input device, it will take some time for your graphical environment (X11/Wayland) to recognize and enable the virtual input device. (Usually done by udev) So, if the delay was too short, the virtual input device may not got recognized & enabled by your graphical environment in time. In order to solve this problem, I made a persistent background service, ydotoold, to hold a persistent virtual device, and accept input from ydotool. When ydotoold is unavailable, ydotool will work without it. #### New modular design Now everyone can write their own tool to use with ydotool. Have a look at the `Tool` folder. I will write some documents for this when I have time. ## Packages Arch Linux: [AUR](https://aur.archlinux.org/packages/ydotool-git/) (Thanks @[Depau](https://github.com/Depau)) (Currently I don't have time to make a PPA for Debian-like distros, if anyone wants to help, feel free to contact me.) ## Build ### Dependencies - [uInputPlus](https://github.com/YukiWorkshop/libuInputPlus) - [libevdevPlus](https://github.com/YukiWorkshop/libevdevPlus) - boost::program_options ### Compile Nearly all my projects use CMake. It's very simple: mkdir build cd build cmake .. make -j `nproc` ## Note As of May, 2019, searching `wayland xdotool replacement` online won't get much useful results. If you find this project useful, please consider to spread it. ydotool-0.1.8/Tools/000077500000000000000000000000001354470551700143245ustar00rootroot00000000000000ydotool-0.1.8/Tools/Click/000077500000000000000000000000001354470551700153515ustar00rootroot00000000000000ydotool-0.1.8/Tools/Click/Click.cpp000066400000000000000000000044051354470551700171050ustar00rootroot00000000000000/* This file is part of ydotool. Copyright (C) 2018-2019 ReimuNotMoe This program is free software: you can redistribute it and/or modify it under the terms of the MIT License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include "Click.hpp" static const char ydotool_tool_name[] = "click"; using namespace ydotool::Tools; const char *Click::Name() { return ydotool_tool_name; } static void ShowHelp(){ std::cerr << "Usage: click [--delay ]