diff --git a/Makefile.pl b/Makefile.pl index 604c43e..a97dcfe 100755 --- a/Makefile.pl +++ b/Makefile.pl @@ -203,7 +203,8 @@ foreach my $l (@examples_targets) { } print(OUT "\n"); print(OUT "clean:\n"); -print( OUT " rm -f */*.o */*/*.o */*/*/*.o */*.exe */*/*.exe */*/*/*.exe src/*.so src/*.dll src/*.a " +print(OUT +" rm -f */*.o */*/*.o */*/*/*.o */*.exe */*/*.exe */*/*/*.exe src/*.so src/*.dll src/*.a " . join(" ", @examples_targets) . "\n"); print(OUT "\n"); diff --git a/src/backend/x11.c b/src/backend/x11.c index 22b91a8..a7f32aa 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -87,24 +87,27 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) { XVisualInfo* xvi; unsigned long n = 1; int i; + int px = x, py = y; r = malloc(sizeof(*r)); MwLLCreateCommon(r); - if(x == MwDEFAULT) x = 0; - if(y == MwDEFAULT) y = 0; + if(px == MwDEFAULT) px = 0; + if(py == MwDEFAULT) py = 0; if(width < 1) width = 1; if(height < 1) height = 1; if(parent == NULL) { r->display = XOpenDisplay(NULL); p = XRootWindow(r->display, XDefaultScreen(r->display)); + r->top = 1; } else { r->display = parent->display; p = parent->window; + r->top = 0; } - r->window = XCreateSimpleWindow(r->display, p, x, y, width, height, 0, 0, WhitePixel(r->display, DefaultScreen(r->display))); + r->window = XCreateSimpleWindow(r->display, p, px, py, width, height, 0, 0, WhitePixel(r->display, DefaultScreen(r->display))); xvi = get_visual_info(r->display); @@ -167,6 +170,15 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) { XSync(r->display, False); wait_map(r); + if(x != MwDEFAULT || y != MwDEFAULT) { + MwLLGetXYWH(r, &px, &py, &width, &height); + + if(x == MwDEFAULT) x = px; + if(y == MwDEFAULT) y = py; + + MwLLSetXY(r, x, y); + } + return r; } @@ -237,10 +249,21 @@ void MwLLColorUpdate(MwLL handle, MwLLColor c, int r, int g, int b) { c->blue = b; } void MwLLGetXYWH(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h) { - Window root; + Window root, parent; + Window child; unsigned int border, depth; XGetGeometry(handle->display, handle->window, &root, x, y, w, h, &border, &depth); + if(handle->top) { + int rx, ry; + Window child; + XWindowAttributes xwa; + + XTranslateCoordinates(handle->display, handle->window, root, 0, 0, &rx, &ry, &child); + + *x += rx; + *y += ry; + } } void MwLLSetXY(MwLL handle, int x, int y) { @@ -709,6 +732,8 @@ void MwLLDetach(MwLL handle, MwPoint* point) { Window* children; unsigned int nchild; + handle->top = 1; + XQueryTree(handle->display, handle->window, &root, &parent, &children, &nchild); if(children != NULL) XFree(children); diff --git a/src/backend/x11.h b/src/backend/x11.h index b4e4e5e..7d7157f 100644 --- a/src/backend/x11.h +++ b/src/backend/x11.h @@ -30,6 +30,7 @@ struct _MwLL { MwLLHandler handler; + int top; int grabbed; unsigned long red_mask;