Compare commits
137 Commits
v0.7.1-rc1
...
master
Author | SHA1 | Date |
---|---|---|
jackun | 4a34502aeb | 12 hours ago |
flightlessmango | 4307450c02 | 3 days ago |
flightlessmango | a4393e0e42 | 3 days ago |
flightlessmango | 511b7a6f2a | 4 days ago |
Leopard1907 | 391c52271c | 4 days ago |
Leopard1907 | e6b7304ec5 | 4 days ago |
João Batista | b217d75917 | 6 days ago |
flightlessmango | 7b80f733b6 | 7 days ago |
flightlessmango | 038478a96a | 1 week ago |
flightlessmango | f22d3221a3 | 1 week ago |
flightlessmango | d8ed2331c3 | 1 week ago |
flightlessmango | 6312c46663 | 1 week ago |
flightlessmango | 78a892e1af | 1 week ago |
flightlessmango | 63eaf1489a | 1 week ago |
flightlessmango | 4cbcec30b8 | 1 week ago |
flightlessmango | dc7ec94549 | 2 weeks ago |
flightlessmango | faa3b1c22f | 2 weeks ago |
flightlessmango | 0caded833e | 2 weeks ago |
Alex Maese | 872a564889 | 2 weeks ago |
Alex Maese | 5c1fe0a5e6 | 2 weeks ago |
Alex Maese | 6ab4624cfb | 2 weeks ago |
Bill Li | f0407636d3 | 3 weeks ago |
Alesh Slovak | 5d744d328a | 3 weeks ago |
Gonçalo Negrier Duarte | 4ee8a9aac4 | 3 weeks ago |
flightlessmango | 31f2ca5e30 | 3 weeks ago |
Alessandro Toia | 57cd928c63 | 3 weeks ago |
Arias800 | 32c6cf0ebd | 3 weeks ago |
flightlessmango | ec1b9c017f | 3 weeks ago |
flightlessmango | 55712618fa | 3 weeks ago |
flightlessmango | a0a31b4f64 | 1 month ago |
Etaash Mathamsetty | 4cad060334 | 1 month ago |
Błażej Szczygieł | 121cf54d9b | 1 month ago |
Alessandro Toia | 7497b1da3f | 1 month ago |
Etaash Mathamsetty | 0e92ec4790 | 1 month ago |
Milos Tijanic | 44eb25e10e | 1 month ago |
flightlessmango | 046b6cecdd | 2 months ago |
flightlessmango | b6291a51e6 | 2 months ago |
flightlessmango | ba220022d0 | 2 months ago |
flightlessmango | 8491ff5aa9 | 2 months ago |
flightlessmango | c363c96cd5 | 2 months ago |
flightlessmango | 23a2d53a3b | 2 months ago |
flightlessmango | 4f43b260cc | 2 months ago |
Etaash Mathamsetty | 6ec1f8c80e | 2 months ago |
Etaash Mathamsetty | d23b4cde8c | 2 months ago |
Sefa Eyeoglu | 4d0b1e1fb8 | 2 months ago |
Etaash Mathamsetty | 366c1a233f | 2 months ago |
Etaash Mathamsetty | 86668eeb96 | 2 months ago |
Etaash Mathamsetty | e99284aadd | 2 months ago |
Etaash Mathamsetty | 5912cce19f | 2 months ago |
flightlessmango | 1e13c385fe | 2 months ago |
flightlessmango | 291ffd263c | 2 months ago |
flightlessmango | ffff9b83b2 | 2 months ago |
flightlessmango | 14b1d87ad8 | 2 months ago |
flightlessmango | f7d291bbe9 | 2 months ago |
Etaash Mathamsetty | c39984da9e | 2 months ago |
Etaash Mathamsetty | a65d1d8a2b | 2 months ago |
Etaash Mathamsetty | 054f4cc9e3 | 2 months ago |
flightlessmango | 66b103ac55 | 2 months ago |
flightlessmango | 33b8924384 | 2 months ago |
flightlessmango | 4aa92187a7 | 2 months ago |
flightlessmango | 976ae0f75a | 2 months ago |
flightlessmango | 77d6244cea | 2 months ago |
flightlessmango | cdd8043489 | 2 months ago |
flightlessman | fb0b559d04 | 2 months ago |
flightlessmango | 7f439879e0 | 2 months ago |
flightlessmango | a41e8e0d1f | 2 months ago |
flightlessmango | 01b81d068b | 2 months ago |
flightlessmango | 6e5581ba79 | 2 months ago |
Alessandro Toia | dbf0c91f47 | 2 months ago |
flightlessmango | bcaccc8bd4 | 2 months ago |
flightlessmango | ad1d03d257 | 2 months ago |
flightlessmango | 94449aa324 | 2 months ago |
flightlessmango | 325498d1d6 | 2 months ago |
flightlessmango | 3c743a9e92 | 2 months ago |
flightlessmango | bdd2a02a10 | 2 months ago |
flightlessmango | 3f0ecf769d | 2 months ago |
flightlessmango | 8732ada5a6 | 2 months ago |
flightlessmango | 12151d2ae2 | 2 months ago |
flightlessmango | 4eb75cf4fb | 2 months ago |
flightlessmango | bbf2872486 | 2 months ago |
flightlessmango | 5b233be2f8 | 2 months ago |
flightlessmango | 6edb590b9a | 2 months ago |
flightlessmango | 1baecfc493 | 2 months ago |
flightlessmango | a4862f5461 | 2 months ago |
flightlessmango | 66d5ce43d2 | 2 months ago |
Joshua Ashton | baa06da2ad | 2 months ago |
Joshua Ashton | 7c7cb9a1dc | 2 months ago |
Alessandro Toia | a7a73afdad | 3 months ago |
flightlessmango | c368f1491e | 3 months ago |
Alessandro Toia | 83af57a9b3 | 3 months ago |
Alex Maese | 2aa604278e | 3 months ago |
Alessandro Toia | 5598fda8f4 | 3 months ago |
Joshua Ashton | 7349a1cf29 | 3 months ago |
Alessandro Toia | 54df529eba | 3 months ago |
flightlessmango | 2e0197718b | 3 months ago |
Alessandro Toia | d1d44f94c9 | 3 months ago |
Etaash Mathamsetty | c058a38168 | 3 months ago |
Etaash Mathamsetty | 732629e5a0 | 3 months ago |
FlightlessMango | 98e442ba7f | 3 months ago |
FlightlessMango | c80c2093cc | 3 months ago |
FlightlessMango | 3dfd772363 | 3 months ago |
FlightlessMango | 45671161c4 | 4 months ago |
FlightlessMango | ab3b22ec12 | 4 months ago |
FlightlessMango | 46b6fa7fed | 4 months ago |
FlightlessMango | d2b9458a46 | 4 months ago |
Alesh Slovak | 388113ff62 | 4 months ago |
FlightlessMango | 95141de657 | 4 months ago |
PedroHLC ☭ | cba217ffaf | 4 months ago |
FlightlessMango | e64e4788ef | 4 months ago |
FlightlessMango | bd37645dfd | 4 months ago |
FlightlessMango | eca65e611f | 4 months ago |
FlightlessMango | 48d84262cd | 4 months ago |
FlightlessMango | 0ab4c25343 | 4 months ago |
FlightlessMango | 2bc323b2ed | 4 months ago |
flightlessmango | fc54f48257 | 4 months ago |
FlightlessMango | 62fee600d1 | 4 months ago |
FlightlessMango | 4969eed348 | 4 months ago |
Bill Li | dc60dc71ec | 4 months ago |
Bill Li | 9ba6c8de10 | 4 months ago |
FlightlessMango | 6648143c48 | 4 months ago |
FlightlessMango | 2fa6ff7cb3 | 4 months ago |
e2dk4r | d30cf162c1 | 4 months ago |
flightlessmango | 3cee6f15de | 4 months ago |
flightlessmango | d4a66ccf7e | 5 months ago |
John Zimmermann | cfc51ec99f | 5 months ago |
John Zimmermann | a4332733c3 | 5 months ago |
Alessandro Toia | 733fbe03fa | 5 months ago |
Ryan Houdek | 267a431eef | 5 months ago |
Ryan Houdek | 511f4fc303 | 5 months ago |
flightlessmango | 38cec48f93 | 5 months ago |
flightlessmango | c33ce2b734 | 5 months ago |
flightlessmango | 86e49da174 | 5 months ago |
flightlessmango | c8c987dadb | 5 months ago |
flightlessmango | 971791d5da | 5 months ago |
flightlessmango | 53281f3f2c | 5 months ago |
flightlessmango | 1d357e17c8 | 5 months ago |
flightlessmango | adbafe1450 | 5 months ago |
@ -1,12 +0,0 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: FlightlessMango
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: https://www.paypal.me/flightlessmango
|
@ -1,7 +1,7 @@
|
||||
DEPS_ARCH="gcc,meson,pkgconf,python-mako,glslang,libglvnd,lib32-libglvnd,libxnvctrl,libdrm,python-numpy,python-matplotlib"
|
||||
DEPS_FEDORA="meson,gcc,gcc-c++,libX11-devel,glslang,python3-mako,mesa-libGL-devel,libXNVCtrl-devel,dbus-devel,python3-numpy,python3-matplotlib,libstdc++-static,libstdc++-static.i686"
|
||||
DEPS_DEBIAN="gcc,g++,gcc-multilib,g++-multilib,ninja-build,python3-pip,python3-setuptools,python3-wheel,pkg-config,mesa-common-dev,libx11-dev,libxnvctrl-dev,libdbus-1-dev,python3-numpy,python3-matplotlib"
|
||||
DEPS_SOLUS="mesalib-32bit-devel,glslang,libstdc++-32bit,glibc-32bit-devel,mako,numpy,matplotlib"
|
||||
DEPS_ARCH="gcc,meson,pkgconf,python-mako,glslang,libglvnd,lib32-libglvnd,libxnvctrl,libdrm,python-numpy,python-matplotlib,libxkbcommon"
|
||||
DEPS_FEDORA="meson,gcc,gcc-c++,libX11-devel,glslang,python3-mako,mesa-libGL-devel,libXNVCtrl-devel,dbus-devel,python3-numpy,python3-matplotlib,libstdc++-static,libstdc++-static.i686,libxkbcommon-devel,wayland-devel"
|
||||
DEPS_DEBIAN="gcc,g++,gcc-multilib,g++-multilib,ninja-build,python3-pip,python3-setuptools,python3-wheel,pkg-config,mesa-common-dev,libx11-dev,libxnvctrl-dev,libdbus-1-dev,python3-numpy,python3-matplotlib,libxkbcommon-dev,libxkbcommon-dev:i386,libwayland-dev,libwayland-dev:i386"
|
||||
DEPS_SOLUS="mesalib-32bit-devel,glslang,libstdc++-32bit,glibc-32bit-devel,mako,numpy,matplotlib,libxkbcommon-devel"
|
||||
|
||||
DEPS_SUSE="gcc-c++,gcc-c++-32bit,libpkgconf-devel,ninja,python3-pip,python3-Mako,libX11-devel,glslang-devel,glibc-devel,glibc-devel-32bit,libstdc++-devel,libstdc++-devel-32bit,Mesa-libGL-devel,dbus-1-devel,python-numpy,python-matplotlib"
|
||||
DEPS_SUSE="gcc-c++,gcc-c++-32bit,libpkgconf-devel,ninja,python3-pip,python3-Mako,libX11-devel,glslang-devel,glibc-devel,glibc-devel-32bit,libstdc++-devel,libstdc++-devel-32bit,Mesa-libGL-devel,dbus-1-devel,python-numpy,python-matplotlib,libxkbcommon-devel"
|
||||
DEPS_SUSE_EXTRA="libXNVCtrl-devel"
|
||||
|
@ -0,0 +1,79 @@
|
||||
#include <filesystem.h>
|
||||
#include <mesa/util/os_time.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "msm.h"
|
||||
std::unique_ptr<MSM> msm;
|
||||
namespace fs = ghc::filesystem;
|
||||
|
||||
uint64_t MSM::get_gpu_time() {
|
||||
char line[256];
|
||||
uint64_t total_val = 0;
|
||||
for (auto fd : fdinfo) {
|
||||
rewind(fd);
|
||||
fflush(fd);
|
||||
uint64_t val = 0;
|
||||
while (fgets(line, sizeof(line), fd)){
|
||||
if (sscanf(line, "drm-engine-gpu: %" SCNu64 " ns", &val) == 1) {
|
||||
total_val += val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return total_val;
|
||||
}
|
||||
|
||||
void MSM::find_fd() {
|
||||
DIR* dir = opendir("/proc/self/fdinfo");
|
||||
if (!dir) {
|
||||
perror("Failed to open directory");
|
||||
}
|
||||
|
||||
for (const auto& entry : fs::directory_iterator("/proc/self/fdinfo")){
|
||||
FILE* file = fopen(entry.path().string().c_str(), "r");
|
||||
|
||||
if (!file) continue;
|
||||
|
||||
char line[256];
|
||||
bool found_driver = false;
|
||||
while (fgets(line, sizeof(line), file)) {
|
||||
if (strstr(line, "msm") != NULL)
|
||||
found_driver = true;
|
||||
|
||||
if (found_driver) {
|
||||
if(strstr(line, "drm-engine-gpu")) {
|
||||
fdinfo.push_back(file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found_driver)
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
void MSM::get_fdinfo() {
|
||||
static uint64_t previous_gpu_time, previous_time, now, gpu_time_now;
|
||||
gpu_time_now = get_gpu_time();
|
||||
now = os_time_get_nano();
|
||||
|
||||
if (previous_time && previous_gpu_time && gpu_time_now > previous_gpu_time){
|
||||
float time_since_last = now - previous_time;
|
||||
float gpu_since_last = gpu_time_now - previous_gpu_time;
|
||||
auto result = int((gpu_since_last / time_since_last) * 100);
|
||||
if (result > 100)
|
||||
result = 100;
|
||||
|
||||
gpu_info_msm.load = result;
|
||||
previous_gpu_time = gpu_time_now;
|
||||
previous_time = now;
|
||||
} else {
|
||||
previous_gpu_time = gpu_time_now;
|
||||
previous_time = now;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "gpu.h"
|
||||
|
||||
class MSM {
|
||||
private:
|
||||
struct gpuInfo gpu_info_msm {};
|
||||
std::vector<FILE*> fdinfo;
|
||||
void find_fd();
|
||||
uint64_t get_gpu_time();
|
||||
void get_fdinfo();
|
||||
|
||||
public:
|
||||
MSM() {
|
||||
find_fd();
|
||||
}
|
||||
|
||||
~MSM() {
|
||||
for (size_t i = 0; i < fdinfo.size(); i++) {
|
||||
fclose(fdinfo[i]);
|
||||
}
|
||||
fdinfo.clear();
|
||||
}
|
||||
|
||||
void update() {
|
||||
if (!fdinfo.empty())
|
||||
get_fdinfo();
|
||||
|
||||
gpu_info = gpu_info_msm;
|
||||
}
|
||||
};
|
||||
|
||||
extern std::unique_ptr<MSM> msm;
|
@ -0,0 +1,58 @@
|
||||
#include "net.h"
|
||||
#include "hud_elements.h"
|
||||
|
||||
Net::Net() {
|
||||
should_reset = false;
|
||||
fs::path net_dir(NETDIR);
|
||||
if (fs::exists(net_dir) && fs::is_directory(net_dir)) {
|
||||
for (const auto& entry : fs::directory_iterator(net_dir)) {
|
||||
if (fs::is_directory(entry.status())) {
|
||||
auto val = entry.path().filename().string();
|
||||
if (val == "lo")
|
||||
continue;
|
||||
|
||||
if (!HUDElements.params->network.empty() && HUDElements.params->network.front() == "1") {
|
||||
interfaces.push_back({entry.path().filename().string(), 0, 0});
|
||||
} else if (!HUDElements.params->network.empty()){
|
||||
auto it = std::find(HUDElements.params->network.begin(), HUDElements.params->network.end(), val);
|
||||
if (it != HUDElements.params->network.end())
|
||||
interfaces.push_back({entry.path().filename().string(), 0, 0});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (interfaces.empty())
|
||||
SPDLOG_ERROR("Network: couldn't find any interfaces");
|
||||
}
|
||||
|
||||
void Net::update() {
|
||||
if (!interfaces.empty()) {
|
||||
for (auto& iface : interfaces) {
|
||||
// path to tx_bytes and rx_bytes
|
||||
std::string txfile = (NETDIR + iface.name + TXFILE);
|
||||
std::string rxfile = (NETDIR + iface.name + RXFILE);
|
||||
|
||||
// amount of bytes at previous update
|
||||
uint64_t prevTx = iface.txBytes;
|
||||
uint64_t prevRx = iface.rxBytes;
|
||||
|
||||
// current amount of bytes
|
||||
iface.txBytes = std::stoll(read_line(txfile));
|
||||
iface.rxBytes = std::stoll(read_line(rxfile));
|
||||
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
// calculate the bytes per second since last update
|
||||
iface.txBps = calculateThroughput(iface.txBytes, prevTx, iface.previousTime, now);
|
||||
iface.rxBps = calculateThroughput(iface.rxBytes, prevRx, iface.previousTime, now);
|
||||
iface.previousTime = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t Net::calculateThroughput(long long currentBytes, long long previousBytes,
|
||||
std::chrono::steady_clock::time_point previousTime,
|
||||
std::chrono::steady_clock::time_point currentTime) {
|
||||
std::chrono::duration<double> elapsed = (currentTime - previousTime);
|
||||
return static_cast<long long>((currentBytes - previousBytes) / elapsed.count());
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include "filesystem.h"
|
||||
#include "file_utils.h"
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace fs = ghc::filesystem;
|
||||
|
||||
#ifndef NETDIR
|
||||
#define NETDIR "/sys/class/net/"
|
||||
#endif
|
||||
|
||||
#ifndef TXFILE
|
||||
#define TXFILE "/statistics/tx_bytes"
|
||||
#endif
|
||||
|
||||
#ifndef RXFILE
|
||||
#define RXFILE "/statistics/rx_bytes"
|
||||
#endif
|
||||
|
||||
class Net {
|
||||
public:
|
||||
bool should_reset = false;
|
||||
struct networkInterface {
|
||||
std::string name;
|
||||
uint64_t txBytes;
|
||||
uint64_t rxBytes;
|
||||
uint64_t txBps;
|
||||
uint64_t rxBps;
|
||||
std::chrono::steady_clock::time_point previousTime;
|
||||
};
|
||||
|
||||
Net();
|
||||
void update();
|
||||
std::vector<networkInterface> interfaces = {};
|
||||
|
||||
private:
|
||||
uint64_t calculateThroughput(long long currentBytes, long long previousBytes,
|
||||
std::chrono::steady_clock::time_point previousTime,
|
||||
std::chrono::steady_clock::time_point currentTime);
|
||||
};
|
||||
|
||||
extern std::unique_ptr<Net> net;
|
@ -0,0 +1,92 @@
|
||||
#include "shell.h"
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
#include <sys/wait.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include "string_utils.h"
|
||||
#include <array>
|
||||
|
||||
std::string Shell::readOutput() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
|
||||
std::array<char, 128> buffer;
|
||||
std::string result;
|
||||
ssize_t count;
|
||||
while ((count = ::read(from_shell[0], buffer.data(), buffer.size())) > 0) {
|
||||
result.append(buffer.data(), count);
|
||||
}
|
||||
|
||||
// Split the result into lines and return the last line
|
||||
std::istringstream stream(result);
|
||||
std::string line;
|
||||
std::string last_line;
|
||||
while (std::getline(stream, line)) {
|
||||
last_line = line;
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("Shell: recieved output: {}", last_line);
|
||||
return last_line;
|
||||
}
|
||||
|
||||
Shell::Shell() {
|
||||
static bool failed;
|
||||
if (pipe(to_shell) == -1) {
|
||||
SPDLOG_ERROR("Failed to create to_shell pipe: {}", strerror(errno));
|
||||
failed = true;
|
||||
}
|
||||
|
||||
if (pipe(from_shell) == -1) {
|
||||
SPDLOG_ERROR("Failed to create from_shell pipe: {}", strerror(errno));
|
||||
failed = true;
|
||||
}
|
||||
|
||||
// if either pipe fails, there's no point in continuing.
|
||||
if (failed){
|
||||
SPDLOG_ERROR("Shell has failed, will not be able to use exec");
|
||||
return;
|
||||
}
|
||||
|
||||
shell_pid = fork();
|
||||
|
||||
if (shell_pid == 0) { // Child process
|
||||
close(to_shell[1]);
|
||||
close(from_shell[0]);
|
||||
|
||||
dup2(to_shell[0], STDIN_FILENO);
|
||||
dup2(from_shell[1], STDOUT_FILENO);
|
||||
dup2(from_shell[1], STDERR_FILENO);
|
||||
execl("/bin/sh", "sh", nullptr);
|
||||
exit(1); // Exit if execl fails
|
||||
} else {
|
||||
close(to_shell[0]);
|
||||
close(from_shell[1]);
|
||||
|
||||
// Set the read end of the from_shell pipe to non-blocking
|
||||
setNonBlocking(from_shell[0]);
|
||||
}
|
||||
success = true;
|
||||
}
|
||||
|
||||
std::string Shell::exec(std::string cmd) {
|
||||
if (!success)
|
||||
return "";
|
||||
|
||||
writeCommand(cmd);
|
||||
return readOutput();
|
||||
}
|
||||
|
||||
void Shell::writeCommand(std::string command) {
|
||||
if (write(to_shell[1], command.c_str(), command.length()) == -1)
|
||||
SPDLOG_ERROR("Failed to write to shell");
|
||||
|
||||
trim(command);
|
||||
SPDLOG_DEBUG("Shell: wrote command: {}", command);
|
||||
}
|
||||
|
||||
Shell::~Shell() {
|
||||
if (write(to_shell[1], "exit\n", 5) == -1)
|
||||
SPDLOG_ERROR("Failed exit shell");
|
||||
close(to_shell[1]);
|
||||
close(from_shell[0]);
|
||||
waitpid(shell_pid, nullptr, 0);
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#ifdef __linux__
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
class Shell {
|
||||
private:
|
||||
int to_shell[2];
|
||||
int from_shell[2];
|
||||
pid_t shell_pid;
|
||||
bool success;
|
||||
|
||||
#ifdef __linux__
|
||||
void setNonBlocking(int fd) {
|
||||
int flags = fcntl(fd, F_GETFL, 0);
|
||||
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
||||
}
|
||||
#endif
|
||||
|
||||
void writeCommand(std::string command);
|
||||
std::string readOutput();
|
||||
|
||||
public:
|
||||
Shell();
|
||||
~Shell();
|
||||
std::string exec(std::string cmd);
|
||||
|
||||
};
|
||||
|
||||
extern std::unique_ptr<Shell> shell;
|
@ -0,0 +1,63 @@
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
#include <dlfcn.h>
|
||||
#include <cstdio>
|
||||
#include "real_dlsym.h"
|
||||
#include "wayland_hook.h"
|
||||
|
||||
EXPORT_C_(struct wl_display*) wl_display_connect(const char *name);
|
||||
EXPORT_C_(struct wl_display*) wl_display_connect_to_fd(int fd);
|
||||
|
||||
typedef struct wl_display* (*pwl_display_connect)(const char *name);
|
||||
typedef struct wl_display* (*pwl_display_connect_to_fd)(int fd);
|
||||
|
||||
pwl_display_connect wl_display_connect_ptr = nullptr;
|
||||
pwl_display_connect_to_fd wl_display_connect_to_fd_ptr = nullptr;
|
||||
void* wl_handle = nullptr;
|
||||
struct wl_display* wl_display_ptr = nullptr;
|
||||
|
||||
EXPORT_C_(struct wl_display*) wl_display_connect(const char *name)
|
||||
{
|
||||
struct wl_display *ret = nullptr;
|
||||
|
||||
if (!wl_handle) {
|
||||
wl_handle = real_dlopen("libwayland-client.so", RTLD_LAZY);
|
||||
}
|
||||
|
||||
if (wl_handle) {
|
||||
wl_display_connect_ptr = (pwl_display_connect)real_dlsym(wl_handle, "wl_display_connect");
|
||||
wl_display_connect_to_fd_ptr = (pwl_display_connect_to_fd)real_dlsym(wl_handle, "wl_display_connect_to_fd");
|
||||
|
||||
ret = wl_display_connect_ptr(name);
|
||||
|
||||
if (!wl_display_ptr) {
|
||||
wl_display_ptr = ret;
|
||||
init_wayland_data();
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
EXPORT_C_(struct wl_display*) wl_display_connect_to_fd(int fd)
|
||||
{
|
||||
struct wl_display *ret = nullptr;
|
||||
|
||||
if (!wl_handle) {
|
||||
wl_handle = real_dlopen("libwayland-client.so", RTLD_LAZY);
|
||||
}
|
||||
|
||||
if (wl_handle) {
|
||||
wl_display_connect_to_fd_ptr = (pwl_display_connect_to_fd)real_dlsym(wl_handle, "wl_display_connect_to_fd");
|
||||
wl_display_connect_ptr = (pwl_display_connect)real_dlsym(wl_handle, "wl_display_connect");
|
||||
|
||||
ret = wl_display_connect_to_fd_ptr(fd);
|
||||
|
||||
if (!wl_display_ptr) {
|
||||
wl_display_ptr = ret;
|
||||
init_wayland_data();
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
#include <wayland-client.h>
|
||||
#include <vector>
|
||||
|
||||
#ifndef KeySym
|
||||
typedef unsigned long KeySym;
|
||||
#endif
|
||||
|
||||
extern void* wl_handle;
|
||||
extern struct wl_display* wl_display_ptr;
|
||||
extern std::vector<KeySym> wl_pressed_keys;
|
||||
|
||||
void init_wayland_data();
|
||||
void update_wl_queue();
|
@ -0,0 +1,118 @@
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <wayland-client.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include <sys/mman.h>
|
||||
#include "wayland_hook.h"
|
||||
#include "timing.hpp"
|
||||
#include "keybinds.h"
|
||||
|
||||
struct wl_seat* seat = nullptr;
|
||||
struct wl_keyboard* keyboard = nullptr;
|
||||
struct xkb_context *context_xkb = nullptr;
|
||||
struct xkb_keymap *keymap_xkb = nullptr;
|
||||
struct xkb_state *state_xkb = nullptr;
|
||||
struct wl_event_queue* queue = nullptr;
|
||||
std::vector<KeySym> wl_pressed_keys {};
|
||||
|
||||
static void registry_handle_global(void *data, struct wl_registry* registry, uint32_t name, const char *interface, uint32_t version)
|
||||
{
|
||||
if(strcmp(interface, wl_seat_interface.name) == 0)
|
||||
{
|
||||
seat = (struct wl_seat*)wl_registry_bind(registry, name, &wl_seat_interface, 7);
|
||||
}
|
||||
}
|
||||
|
||||
static void registry_handle_global_remove(void *data, struct wl_registry *registry, uint32_t name){}
|
||||
|
||||
static void wl_keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, uint32_t format, int32_t fd, uint32_t size)
|
||||
{
|
||||
char* map_shm = (char*)mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
|
||||
if(!context_xkb)
|
||||
context_xkb = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||
|
||||
if(keymap_xkb && state_xkb)
|
||||
{
|
||||
xkb_keymap_unref(keymap_xkb);
|
||||
xkb_state_unref(state_xkb);
|
||||
}
|
||||
|
||||
keymap_xkb = xkb_keymap_new_from_string(
|
||||
context_xkb, map_shm, XKB_KEYMAP_FORMAT_TEXT_V1,
|
||||
XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
|
||||
state_xkb = xkb_state_new(keymap_xkb);
|
||||
|
||||
munmap((void*)map_shm, size);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void wl_keyboard_enter(void *user_data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys){}
|
||||
|
||||
static void wl_keyboard_leave(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface)
|
||||
{
|
||||
wl_pressed_keys.clear();
|
||||
}
|
||||
|
||||
static void wl_keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
|
||||
{
|
||||
xkb_keycode_t keycode = key + 8;
|
||||
xkb_keysym_t keysym = xkb_state_key_get_one_sym(state_xkb, keycode);
|
||||
|
||||
if(state)
|
||||
{
|
||||
wl_pressed_keys.push_back(keysym);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto it = std::find(wl_pressed_keys.begin(), wl_pressed_keys.end(), keysym);
|
||||
if(it != wl_pressed_keys.end())
|
||||
wl_pressed_keys.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
static void wl_keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group){}
|
||||
|
||||
static void wl_keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard, int32_t rate, int32_t delay){}
|
||||
|
||||
struct wl_registry_listener registry_listener {
|
||||
.global = registry_handle_global,
|
||||
.global_remove = registry_handle_global_remove
|
||||
};
|
||||
|
||||
struct wl_keyboard_listener keyboard_listener {
|
||||
.keymap = wl_keyboard_keymap,
|
||||
.enter = wl_keyboard_enter,
|
||||
.leave = wl_keyboard_leave,
|
||||
.key = wl_keyboard_key,
|
||||
.modifiers = wl_keyboard_modifiers,
|
||||
.repeat_info = wl_keyboard_repeat_info
|
||||
};
|
||||
|
||||
void update_wl_queue()
|
||||
{
|
||||
wl_display_roundtrip_queue(wl_display_ptr, queue);
|
||||
}
|
||||
|
||||
void init_wayland_data()
|
||||
{
|
||||
if (!wl_display_ptr)
|
||||
return;
|
||||
|
||||
struct wl_display *display_wrapped = (struct wl_display*)wl_proxy_create_wrapper(wl_display_ptr);
|
||||
queue = wl_display_create_queue(wl_display_ptr);
|
||||
wl_proxy_set_queue((struct wl_proxy*)display_wrapped, queue);
|
||||
wl_registry *registry = wl_display_get_registry(display_wrapped);
|
||||
wl_proxy_wrapper_destroy(display_wrapped);
|
||||
wl_registry_add_listener(registry, ®istry_listener, NULL);
|
||||
update_wl_queue();
|
||||
update_wl_queue();
|
||||
keyboard = wl_seat_get_keyboard(seat);
|
||||
wl_keyboard_add_listener(keyboard, &keyboard_listener, NULL);
|
||||
update_wl_queue();
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
#include "file_utils.h"
|
||||
#include <filesystem.h>
|
||||
#include <string>
|
||||
|
||||
namespace fs = ghc::filesystem;
|
||||
|
||||
class WineSync {
|
||||
private:
|
||||
enum syncMethods {
|
||||
NONE,
|
||||
WINESERVER,
|
||||
ESYNC,
|
||||
FSYNC,
|
||||
NTSYNC
|
||||
};
|
||||
|
||||
int method = 0;
|
||||
bool inside_wine = true;
|
||||
|
||||
const char* methods[5] = {
|
||||
"NONE",
|
||||
"Wserver",
|
||||
"Esync",
|
||||
"Fsync",
|
||||
"NTsync"
|
||||
};
|
||||
|
||||
public:
|
||||
WineSync() {
|
||||
#ifdef __linux__
|
||||
// check that's were inside wine
|
||||
std::string wineProcess = get_exe_path();
|
||||
auto n = wineProcess.find_last_of('/');
|
||||
std::string preloader = wineProcess.substr(n + 1);
|
||||
if (preloader != "wine-preloader" && preloader != "wine64-preloader"){
|
||||
inside_wine = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const char* paths[2] {
|
||||
"/proc/self/map_files",
|
||||
"/proc/self/fd"
|
||||
};
|
||||
|
||||
// check which sync wine is using, if any.
|
||||
fs::path path;
|
||||
for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) {
|
||||
path = paths[i];
|
||||
for (auto& p : fs::directory_iterator(path)) {
|
||||
auto filepath = p.path().string();
|
||||
const char* filename = filepath.c_str();
|
||||
auto sym = read_symlink(filename);
|
||||
if (sym.find("winesync") != std::string::npos)
|
||||
method = syncMethods::NTSYNC;
|
||||
else if (sym.find("fsync") != std::string::npos)
|
||||
method = syncMethods::FSYNC;
|
||||
else if (sym.find("ntsync") != std::string::npos)
|
||||
method = syncMethods::NTSYNC;
|
||||
else if (sym.find("esync") != std::string::npos)
|
||||
method = syncMethods::ESYNC;
|
||||
|
||||
if (method)
|
||||
break;
|
||||
|
||||
}
|
||||
if (method)
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
bool valid() {
|
||||
return inside_wine;
|
||||
}
|
||||
|
||||
// return sync method as display name
|
||||
std::string get_method() {
|
||||
return methods[method];
|
||||
}
|
||||
};
|
||||
|
||||
extern std::unique_ptr<WineSync> winesync_ptr;
|
@ -1,13 +1,13 @@
|
||||
[wrap-file]
|
||||
directory = spdlog-1.12.0
|
||||
source_url = https://github.com/gabime/spdlog/archive/refs/tags/v1.12.0.tar.gz
|
||||
source_filename = spdlog-1.12.0.tar.gz
|
||||
source_hash = 4dccf2d10f410c1e2feaff89966bfc49a1abb29ef6f08246335b110e001e09a9
|
||||
patch_filename = spdlog_1.12.0-1_patch.zip
|
||||
patch_url = https://wrapdb.mesonbuild.com/v2/spdlog_1.12.0-1/get_patch
|
||||
patch_hash = 0515906db7324df0e439bdd018bf019a60304430f6af8f1725910652e30ebe69
|
||||
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/spdlog_1.12.0-1/spdlog-1.12.0.tar.gz
|
||||
wrapdb_version = 1.12.0-1
|
||||
directory = spdlog-1.14.1
|
||||
source_url = https://github.com/gabime/spdlog/archive/refs/tags/v1.14.1.tar.gz
|
||||
source_filename = spdlog-1.14.1.tar.gz
|
||||
source_hash = 1586508029a7d0670dfcb2d97575dcdc242d3868a259742b69f100801ab4e16b
|
||||
patch_filename = spdlog_1.14.1-1_patch.zip
|
||||
patch_url = https://wrapdb.mesonbuild.com/v2/spdlog_1.14.1-1/get_patch
|
||||
patch_hash = ae878e732330ea1048f90d7e117c40c0cd2a6fb8ae5492c7955818ce3aaade6c
|
||||
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/spdlog_1.14.1-1/spdlog-1.14.1.tar.gz
|
||||
wrapdb_version = 1.14.1-1
|
||||
|
||||
[provide]
|
||||
spdlog = spdlog_dep
|
||||
|
Loading…
Reference in New Issue