Skip to content

Commit bdf675b

Browse files
authored
Merge pull request #49 from ua0lnj/master
Fixed detection of window parameters. Version 1.8.3. (Fix #11).
2 parents f714846 + f67ab40 commit bdf675b

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

mpv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "menu_options.h"
2020
#include "mpv_service.h"
2121

22-
static const char *VERSION = "1.8.1"
22+
static const char *VERSION = "1.8.3"
2323
#ifdef GIT_REV
2424
"-GIT" GIT_REV
2525
#endif

player.c

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,9 @@ void cMpvPlayer::PlayerGetWindow(string need, xcb_connection_t **connect, xcb_wi
405405
child = xcb_query_tree_children(reply);
406406

407407
xcb_query_tree_cookie_t cookie1, cookie2;
408-
xcb_query_tree_reply_t *reply1, *reply2;
408+
xcb_query_tree_reply_t *reply1 = NULL, *reply2 = NULL;
409409
xcb_window_t *child1 = NULL, *child2 = NULL;
410-
int len1, len2;
410+
int len1 = 0, len2 = 0;
411411

412412
//Gnome have 1 child, KDE have 2 child
413413
for (i = 0; i < len; i++) {
@@ -421,56 +421,53 @@ void cMpvPlayer::PlayerGetWindow(string need, xcb_connection_t **connect, xcb_wi
421421
child1 = xcb_query_tree_children(reply1);
422422
}
423423

424-
for (int p = 0; p < len1; p++) {
424+
for (int p = 0; p < (len1 ? len1 : 1); p++) {
425425
//query child of child 1
426-
cookie2 = xcb_query_tree(*connect,child1[p]);
427-
reply2 = xcb_query_tree_reply(*connect, cookie2, 0);
428-
len2 = xcb_query_tree_children_length(reply2);
426+
427+
if (len1) {
428+
cookie2 = xcb_query_tree(*connect,child1[p]);
429+
reply2 = xcb_query_tree_reply(*connect, cookie2, 0);
430+
len2 = xcb_query_tree_children_length(reply2);
431+
}
429432

430433
if (len2) {
431434
//get children of child 1
432435
child2 = xcb_query_tree_children(reply2);
433436
parent1 = child[i];
434-
} else {
435437

436-
//get child 1 property
437-
procookie = xcb_get_property(*connect, 0, len1 ? child1[p] : child[i], property, XCB_GET_PROPERTY_TYPE_ANY, 0, 1000);
438-
if (proreply = xcb_get_property_reply(*connect, procookie, NULL)) {
439-
if (xcb_get_property_value_length(proreply) > 0) {
440-
string name = (char*)xcb_get_property_value(proreply);
441-
if (name.find(need) != string::npos) {
442-
if (!len1) window = child[i];
443-
else {
444-
window = child1[p];
445-
parent1 = child[i];
438+
for (int o = 0; o < len2; o++){
439+
//get child2 property
440+
procookie = xcb_get_property(*connect, 0, child2[o], property, XCB_GET_PROPERTY_TYPE_ANY, 0, 1000);
441+
if (proreply = xcb_get_property_reply(*connect, procookie, NULL)) {
442+
if (xcb_get_property_value_length(proreply) > 0) {
443+
string name = (char*)xcb_get_property_value(proreply);
444+
if (name.find(need) != string::npos) {
445+
window = child2[o];
446+
parent2 = child1[p];
446447
}
447-
break;
448448
}
449+
free(proreply);
449450
}
450-
free(proreply);
451451
}
452-
if (window) break;
453-
}
454-
455-
for (int o = 0; o < (len2 ? len2 : 1); o++){
456-
//get child property
457-
procookie = xcb_get_property(*connect, 0, len2 ? child2[o] : child1[p], property, XCB_GET_PROPERTY_TYPE_ANY, 0, 1000);
452+
} else {
453+
//get child1/child property
454+
procookie = xcb_get_property(*connect, 0, len1 ? child1[p] : child[i], property, XCB_GET_PROPERTY_TYPE_ANY, 0, 1000);
458455
if (proreply = xcb_get_property_reply(*connect, procookie, NULL)) {
459456
if (xcb_get_property_value_length(proreply) > 0) {
460457
string name = (char*)xcb_get_property_value(proreply);
461458
if (name.find(need) != string::npos) {
462-
if (!len2) window = child1[p];
459+
if (!len1) window = child[i];
463460
else {
464-
window = child2[o];
465-
parent2 = child1[p];
461+
window = child1[p];
462+
parent1 = child[i];
466463
}
467-
break;
468464
}
469465
}
470466
free(proreply);
471467
}
472468
}
473-
free(reply2);
469+
if (len1) free(reply2);
470+
if (window) break;
474471
}
475472
free(reply1);
476473
if (window) break;

0 commit comments

Comments
 (0)