fix(info): use alternative method to gather active window on X11
This commit is contained in:
parent
c85e063e71
commit
40ad3c8551
|
@ -88,6 +88,22 @@ char *xwm_get_win_title(Display *disp, Window win)
|
||||||
return nwname ? nwname : (wname ? wname : NULL);
|
return nwname ? nwname : (wname ? wname : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function taken from the wmctrl tool source code
|
||||||
|
Window get_active_window(Display *disp) {
|
||||||
|
char *prop;
|
||||||
|
unsigned long size;
|
||||||
|
Window ret = (Window)0;
|
||||||
|
|
||||||
|
prop = get_property(disp, DefaultRootWindow(disp), XA_WINDOW,
|
||||||
|
"_NET_ACTIVE_WINDOW", &size);
|
||||||
|
if (prop) {
|
||||||
|
ret = *((Window*)prop);
|
||||||
|
XFree(prop);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t info_get_title(char *buffer, int32_t buffer_size)
|
int32_t info_get_title(char *buffer, int32_t buffer_size)
|
||||||
{
|
{
|
||||||
Display *display = XOpenDisplay(0);
|
Display *display = XOpenDisplay(0);
|
||||||
|
@ -97,14 +113,12 @@ int32_t info_get_title(char *buffer, int32_t buffer_size)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window focused;
|
Window focused = get_active_window(display);
|
||||||
int revert_to;
|
|
||||||
int ret = XGetInputFocus(display, &focused, &revert_to);
|
|
||||||
|
|
||||||
int result = 1;
|
int result = 1;
|
||||||
if (!ret)
|
if (!focused)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "xdo_get_active_window reported an error\n");
|
fprintf(stderr, "get_active_window reported an error\n");
|
||||||
result = -2;
|
result = -2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -130,14 +144,12 @@ int32_t info_get_exec(char *buffer, int32_t buffer_size)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window focused;
|
Window focused = get_active_window(display);
|
||||||
int revert_to;
|
|
||||||
int ret = XGetInputFocus(display, &focused, &revert_to);
|
|
||||||
|
|
||||||
int result = 1;
|
int result = 1;
|
||||||
if (!ret)
|
if (!focused)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "xdo_get_active_window reported an error\n");
|
fprintf(stderr, "get_active_window reported an error\n");
|
||||||
result = -2;
|
result = -2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -176,14 +188,12 @@ int32_t info_get_class(char *buffer, int32_t buffer_size)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window focused;
|
Window focused = get_active_window(display);
|
||||||
int revert_to;
|
|
||||||
int ret = XGetInputFocus(display, &focused, &revert_to);
|
|
||||||
|
|
||||||
int result = 1;
|
int result = 1;
|
||||||
if (!ret)
|
if (!focused)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "xdo_get_active_window reported an error\n");
|
fprintf(stderr, "get_active_window reported an error\n");
|
||||||
result = -2;
|
result = -2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user