Created
April 15, 2021 03:29
-
-
Save jld/99a18a3ad469726e215898299ef6cfde to your computer and use it in GitHub Desktop.
Print how many clients the X server has (including this one)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Link with -lXRes -lX11 */ | |
#include <X11/Xlib.h> | |
#include <X11/extensions/XRes.h> | |
#include <stdio.h> | |
int main() { | |
Display *display = NULL; | |
XResClient *clients = NULL; | |
int num_client = 0; | |
int ret = 1; | |
int event_base, error_base; | |
display = XOpenDisplay(NULL); | |
if (!display) { | |
fprintf(stderr, "Failed to open display.\n"); | |
goto out; | |
} | |
if (!XResQueryExtension(display, &event_base, &error_base)) { | |
fprintf(stderr, "XRes not supported.\n"); | |
goto out; | |
} | |
if (!XResQueryClients(display, &num_client, &clients)) { | |
fprintf(stderr, "QueryClients failed.\n"); | |
goto out; | |
} | |
printf("%d\n", num_client); | |
ret = 0; | |
out: | |
XFree(clients); | |
if (display) { | |
XCloseDisplay(display); | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment