Fix theme apply timeout and add full HiDPI scaling for gtkTtk and GTK2

This commit is contained in:
Luxferre committed 2026-11-25 22:11:12 +02:00
1 parent 983d529ec3
commit 3ea7d35aba
28 files changed
+919 -299

No files matched your search

+65 -17
View File
@@ -1129,38 +1129,87 @@ int gemui_read_file_line(const char *path, char *buf, size_t sz) {
int gemui_run_cmd_timeout(const char *const argv[], char *out, size_t out_sz, int timeout_ms) {
if (!argv || !argv[0]) return -1;
int pfd[2];
if (pipe(pfd) < 0) return -1;
bool capture = (out != NULL && out_sz > 0);
int pfd[2] = {-1, -1};
if (capture && pipe(pfd) < 0) return -1;
pid_t pid = fork();
if (pid < 0) {
close(pfd[0]);
close(pfd[1]);
if (capture) {
close(pfd[0]);
close(pfd[1]);
}
return -1;
}
if (pid == 0) {
setpgid(0, 0);
int devnull = open("/dev/null", O_RDONLY);
if (devnull >= 0) {
dup2(devnull, STDIN_FILENO);
if (devnull > 2) close(devnull);
int devnull_r = open("/dev/null", O_RDONLY);
if (devnull_r >= 0) {
dup2(devnull_r, STDIN_FILENO);
if (devnull_r > 2) close(devnull_r);
} else {
close(STDIN_FILENO);
}
close(pfd[0]);
dup2(pfd[1], STDOUT_FILENO);
dup2(pfd[1], STDERR_FILENO);
if (pfd[1] > 2) close(pfd[1]);
if (capture) {
close(pfd[0]);
dup2(pfd[1], STDOUT_FILENO);
dup2(pfd[1], STDERR_FILENO);
if (pfd[1] > 2) close(pfd[1]);
} else {
int devnull_w = open("/dev/null", O_WRONLY);
if (devnull_w >= 0) {
dup2(devnull_w, STDOUT_FILENO);
dup2(devnull_w, STDERR_FILENO);
if (devnull_w > 2) close(devnull_w);
} else {
close(STDOUT_FILENO);
close(STDERR_FILENO);
}
}
execvp(argv[0], (char *const *)argv);
_exit(127);
}
uint64_t deadline = (timeout_ms > 0) ? (gemui_now_ms() + (uint64_t)timeout_ms) : UINT64_MAX;
bool timed_out = false;
int status = 0;
if (!capture) {
while (1) {
pid_t wp = waitpid(pid, &status, WNOHANG);
if (wp == pid) return WIFEXITED(status) ? WEXITSTATUS(status) : 1;
if (wp < 0) {
if (errno == EINTR) continue;
return -1;
}
int step_ms = 15;
if (timeout_ms > 0) {
uint64_t now = gemui_now_ms();
if (now >= deadline) {
timed_out = true;
break;
}
uint64_t rem = deadline - now;
if (rem < (uint64_t)step_ms) step_ms = (int)rem;
}
poll(NULL, 0, step_ms);
}
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
while (waitpid(pid, &status, 0) < 0) {
if (errno != EINTR) return 124;
}
return 124;
}
close(pfd[1]);
int fl = fcntl(pfd[0], F_GETFL, 0);
if (fl >= 0) fcntl(pfd[0], F_SETFL, fl | O_NONBLOCK);
int fdfl = fcntl(pfd[0], F_GETFD, 0);
if (fdfl >= 0) fcntl(pfd[0], F_SETFD, fdfl | FD_CLOEXEC);
size_t off = 0;
char tmp[512];
uint64_t deadline = (timeout_ms > 0) ? (gemui_now_ms() + (uint64_t)timeout_ms) : UINT64_MAX;
bool timed_out = false;
bool eof = false;
while (!eof) {
@@ -1187,7 +1236,7 @@ int gemui_run_cmd_timeout(const char *const argv[], char *out, size_t out_sz, in
while (1) {
ssize_t n = read(pfd[0], tmp, sizeof(tmp));
if (n > 0) {
if (out && off + 1 < out_sz) {
if (off + 1 < out_sz) {
size_t cp = (size_t)n;
if (cp > out_sz - 1 - off) cp = out_sz - 1 - off;
memcpy(out + off, tmp, cp);
@@ -1204,13 +1253,12 @@ int gemui_run_cmd_timeout(const char *const argv[], char *out, size_t out_sz, in
}
}
}
if (out && out_sz > 0) out[off] = '\0';
out[off] = '\0';
close(pfd[0]);
if (timed_out) {
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
}
int status = 0;
while (waitpid(pid, &status, 0) < 0) {
if (errno != EINTR) return timed_out ? 124 : -1;
}