guys there is a json option actually for hyprctl
This commit is contained in:
@@ -28,23 +28,14 @@ async function execCommand(command) {
|
||||
}
|
||||
|
||||
/** @type(String) */
|
||||
let result = await execCommand('hyprctl monitors all');
|
||||
let monitors = {};
|
||||
let currentMonitor = null;
|
||||
|
||||
result.split('\n').forEach(line => {
|
||||
if (line.includes('Monitor')) {
|
||||
let parts = line.split(' ');
|
||||
let name = parts[1];
|
||||
monitors[name] = { name };
|
||||
currentMonitor = name;
|
||||
}
|
||||
if (line.includes('availableModes:')) {
|
||||
line = line.trim();
|
||||
let start = line.indexOf(":") + 2;
|
||||
let modes = line.substring(start).split(' ');
|
||||
monitors[currentMonitor].availableModes = modes;
|
||||
}
|
||||
let result = await execCommand('hyprctl -j monitors all');
|
||||
result = JSON.parse(result);
|
||||
result.forEach(monitor => {
|
||||
monitors[monitor.name] = {
|
||||
name: monitor.name,
|
||||
availableModes: monitor.availableModes
|
||||
};
|
||||
});
|
||||
console.log(monitors);
|
||||
let zenity_monitors = Object.keys(monitors).join(' \\\n');
|
||||
|
||||
51
.config/hypr/test.c
Normal file
51
.config/hypr/test.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(void) {
|
||||
char *sig = getenv("HYPRLAND_INSTANCE_SIGNATURE");
|
||||
char *runtime_dir = getenv("XDG_RUNTIME_DIR");
|
||||
struct sockaddr_un addr;
|
||||
int sockfd;
|
||||
if (!sig) {
|
||||
printf("HYPRLAND_INSTANCE_SIGNATURE not set\n");
|
||||
return 1;
|
||||
}
|
||||
if (!runtime_dir) {
|
||||
printf("XDG_RUNTIME_DIR not set\n");
|
||||
return 1;
|
||||
}
|
||||
char *path;
|
||||
asprintf(&path, "%s/hypr/%s/.socket.sock", runtime_dir, sig);
|
||||
printf("Opening %s\n", path);
|
||||
if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
|
||||
perror("socket");
|
||||
return 1;
|
||||
}
|
||||
memset(&addr, 0, sizeof(struct sockaddr_un));
|
||||
addr.sun_family = AF_UNIX;
|
||||
strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
|
||||
|
||||
if (connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
|
||||
perror("connect");
|
||||
close(sockfd);
|
||||
return 1;
|
||||
}
|
||||
printf("Connected to %s\n", path);
|
||||
char* command = "monitors";
|
||||
write(sockfd, command, strlen(command));
|
||||
char buf[1024];
|
||||
while (1) {
|
||||
int n = read(sockfd, buf, sizeof(buf) - 1);
|
||||
if (n <= 0)
|
||||
break;
|
||||
buf[n] = '\0';
|
||||
printf("%s", buf);
|
||||
}
|
||||
close(sockfd);
|
||||
}
|
||||
Reference in New Issue
Block a user