-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Window Manager Information should not require wmctrl
#9
Comments
wmctrl
wmctrl
I took a look at this. wm_info function
static int wm_info (Display *disp) {/*{{{*/
Window *sup_window = NULL;
gchar *wm_name = NULL;
gchar *wm_class = NULL;
unsigned long *wm_pid = NULL;
unsigned long *showing_desktop = NULL;
gboolean name_is_utf8 = TRUE;
gchar *name_out;
gchar *class_out;
if (! (sup_window = (Window *)get_property(disp, DefaultRootWindow(disp),
XA_WINDOW, "_NET_SUPPORTING_WM_CHECK", NULL))) {
if (! (sup_window = (Window *)get_property(disp, DefaultRootWindow(disp),
XA_CARDINAL, "_WIN_SUPPORTING_WM_CHECK", NULL))) {
fputs("Cannot get window manager info properties.\n"
"(_NET_SUPPORTING_WM_CHECK or _WIN_SUPPORTING_WM_CHECK)\n", stderr);
return EXIT_FAILURE;
}
}
/* WM_NAME */
if (! (wm_name = get_property(disp, *sup_window,
XInternAtom(disp, "UTF8_STRING", False), "_NET_WM_NAME", NULL))) {
name_is_utf8 = FALSE;
if (! (wm_name = get_property(disp, *sup_window,
XA_STRING, "_NET_WM_NAME", NULL))) {
p_verbose("Cannot get name of the window manager (_NET_WM_NAME).\n");
}
}
name_out = get_output_str(wm_name, name_is_utf8);
/* WM_CLASS */
if (! (wm_class = get_property(disp, *sup_window,
XInternAtom(disp, "UTF8_STRING", False), "WM_CLASS", NULL))) {
name_is_utf8 = FALSE;
if (! (wm_class = get_property(disp, *sup_window,
XA_STRING, "WM_CLASS", NULL))) {
p_verbose("Cannot get class of the window manager (WM_CLASS).\n");
}
}
class_out = get_output_str(wm_class, name_is_utf8);
/* WM_PID */
if (! (wm_pid = (unsigned long *)get_property(disp, *sup_window,
XA_CARDINAL, "_NET_WM_PID", NULL))) {
p_verbose("Cannot get pid of the window manager (_NET_WM_PID).\n");
}
/* _NET_SHOWING_DESKTOP */
if (! (showing_desktop = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
XA_CARDINAL, "_NET_SHOWING_DESKTOP", NULL))) {
p_verbose("Cannot get the _NET_SHOWING_DESKTOP property.\n");
}
/* print out the info */
printf("Name: %s\n", name_out ? name_out : "N/A");
printf("Class: %s\n", class_out ? class_out : "N/A");
if (wm_pid) {
printf("PID: %lu\n", *wm_pid);
}
else {
printf("PID: N/A\n");
}
if (showing_desktop) {
printf("Window manager's \"showing the desktop\" mode: %s\n",
*showing_desktop == 1 ? "ON" : "OFF");
}
else {
printf("Window manager's \"showing the desktop\" mode: N/A\n");
}
g_free(name_out);
g_free(sup_window);
g_free(wm_name);
g_free(wm_class);
g_free(wm_pid);
g_free(showing_desktop);
return EXIT_SUCCESS;
}/*}}}*/ Will also have to handle the wayland stuff seperately. |
I've taken a look at wmctrl's source code before, and although simple, it scared me a bit. But I'll give it another go.
We can try to establish a connection with the X server, and if that fails, we can then try and check if the user is running Wayland, so we don't necessarily have to handle them separately. If both checks fail, we can safely assume the user is in a TTY session, so we fail the readout. |
Yeah C code is really intimidating and hard to read.
This might fail if the user is running xwayland since many applications aren't supported. But I'm not sure. |
I totally forgot about xwayland. I'll have to invest some time to get some knowledge on xwayland just enough to be able to dive in and start hacking a new implementation together. |
Good luck ! |
@grtcdr What if you compiled |
I wouldn't know how to do that, and wmctrl does a lot more than what we need from it. Wait, like a .so file? |
Like an
It contains all the references to all the code of your program but hasn't been linked into any library yet by the linker. We can remove most of the stuff other that wm_info and make it return a pointer to a struct or something. But If you can use rust to make the x11 calls all this won't be necessary, however I find x11 programming extremely confusing so that's why I suggested this. |
Now to try and tackle this problem. No idea how xlib and xcb actually work but I would guess it is similar to xprop. |
libmacchina currently fetches the window manager name through
wmctrl
, this call is expensive compared to accessing it through more efficient means.A new implementation must return the window manager name for X and Wayland.
Why?
Not requiring
wmctrl
is one less dependency to worry about, and it's always faster not to call commands.The text was updated successfully, but these errors were encountered: