This issue has been solved. Basically for some reason when calling XGrabPointer with the Window to confine it in as the one created for that purpose as in
Code:
XGrabPointer(display, iconwin, True, 0, GrabModeAsync, GrabModeAsync, iconwin, None, CurrentTime);
it wouldn't work (threw a "invalid Window" error, I believe), but I replaced it with:
Code:
XGrabPointer(display, event.xbutton.window, True, 0, GrabModeAsync, GrabModeAsync, event.xbutton.window, None, CurrentTime);
Now it works perfectly.
The thing that still confuses me is that I use XQueryPointer elsewhere as follows
Code:
XQueryPointer(display, iconwin, &rr, &cr, &rx, &ry, &x, &y, &mr);
where rr, cr, rx, ry, mr are dummy variables for the return values, and it works fine so I know that iconwin is a valid Window. Furthermore the program worked fine outside of Gnome/KDE/XFCE4.
Anyway, at least it's working now!