Initial commit.
This commit is contained in:
25
.gitignore
vendored
Normal file
25
.gitignore
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
bin/
|
||||
.cache/
|
||||
|
||||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
CMakeUserPresets.json
|
||||
|
||||
# Binary itself
|
||||
hyprevents
|
||||
|
||||
# CLion
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#cmake-build-*
|
||||
23
CMakeLists.txt
Normal file
23
CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
|
||||
project(
|
||||
hyprevents
|
||||
DESCRIPTION "React on hyprland events"
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS, 1)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-Wall -Wextra -W")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
add_custom_target(run
|
||||
COMMAND hyprevents
|
||||
DEPENDS hyprevents
|
||||
WORKING_DIRECTORY src
|
||||
)
|
||||
2
src/CMakeLists.txt
Normal file
2
src/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
add_executable(hyprevents main.cpp)
|
||||
install(TARGETS hyprevents)
|
||||
48
src/main.cpp
Normal file
48
src/main.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include <cstdlib>
|
||||
#include <hyprutils/signal/Listener.hpp>
|
||||
#include <print>
|
||||
#include <string>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
std::string instanceSignature;
|
||||
|
||||
std::string getRuntimeDir() {
|
||||
const auto XDG = getenv("XDG_RUNTIME_DIR");
|
||||
|
||||
if (!XDG) {
|
||||
const std::string USERID = std::to_string(getuid());
|
||||
return "/run/user/" + USERID + "/hypr";
|
||||
}
|
||||
|
||||
return std::string(XDG) + "/hypr";
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto runtimeDir = getRuntimeDir();
|
||||
instanceSignature = std::string(std::getenv("HYPRLAND_INSTANCE_SIGNATURE"));
|
||||
if (instanceSignature.empty()) {
|
||||
std::println("Hyprland instance isn't running.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto socket_fpath = runtimeDir + "/" + instanceSignature + "/.socket.sock";
|
||||
std::println("Found socket file path: {}", socket_fpath);
|
||||
|
||||
sockaddr *socket_address = new sockaddr();
|
||||
socket_address->sa_family = AF_UNIX;
|
||||
|
||||
auto hypr_socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (hypr_socket < 1) {
|
||||
std::println("Cannot create socket (1).");
|
||||
return 1;
|
||||
}
|
||||
auto timeout = timeval{.tv_sec = 5, .tv_usec = 0};
|
||||
if (setsockopt(hypr_socket, SOL_SOCKET, SO_RCVTIMEO, &timeout,
|
||||
sizeof(struct timeval)) < 0) {
|
||||
std::println("Cannot set timeout for a socket (2).");
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user