From 8ecae7402ccfea7b8f951213bb680a9e9d7fbfd7 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Mon, 21 Jan 2019 22:35:44 +0800 Subject: [PATCH] fix bug that window has wrong position if it has an ancestor --- source/gui/detail/native_window_interface.cpp | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/source/gui/detail/native_window_interface.cpp b/source/gui/detail/native_window_interface.cpp index fcf7f695..cf01e33d 100644 --- a/source/gui/detail/native_window_interface.cpp +++ b/source/gui/detail/native_window_interface.cpp @@ -1,7 +1,7 @@ /* * Platform Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -29,6 +29,7 @@ #include "../../paint/image_accessor.hpp" + namespace nana{ namespace detail{ @@ -199,7 +200,7 @@ namespace nana{ namespace x11_wait { static Bool configure(Display *disp, XEvent *evt, char *arg) - { + { return disp && evt && arg && (evt->type == ConfigureNotify) && (evt->xconfigure.window == *reinterpret_cast(arg)); } @@ -1019,15 +1020,11 @@ namespace nana{ auto const owner = restrict::spec.get_owner(wd); if(owner && (owner != reinterpret_cast(restrict::spec.root_window()))) { - auto origin = window_position(owner); -#if 0 - x += origin.x; - y += origin.y; -#else - auto owner_extents = window_frame_extents(owner); - x += origin.x + owner_extents.left; - y += origin.y + owner_extents.top; -#endif + int origin_x, origin_y; + Window child_useless_for_API; + ::XTranslateCoordinates(disp, reinterpret_cast(owner), restrict::spec.root_window(), 0, 0, &origin_x, &origin_y, &child_useless_for_API); + x += origin_x; + y += origin_y; } ::XMoveWindow(disp, reinterpret_cast(wd), x, y); @@ -1074,7 +1071,6 @@ namespace nana{ XSizeHints hints; nana::detail::platform_scope_guard psg; - //Returns if the requested rectangle is same with the current rectangle. //In some X-Server versions/implementations, XMapWindow() doesn't generate //a ConfigureNotify if the requested rectangle is same with the current rectangle. @@ -1114,11 +1110,11 @@ namespace nana{ auto const owner = restrict::spec.get_owner(wd); if(owner && (owner != reinterpret_cast(restrict::spec.root_window()))) { - auto origin = window_position(owner); - - auto owner_extents = window_frame_extents(owner); - x += origin.x + owner_extents.left; - y += origin.y + owner_extents.top; + int origin_x, origin_y; + Window child_useless_for_API; + ::XTranslateCoordinates(disp, reinterpret_cast(owner), restrict::spec.root_window(), 0, 0, &origin_x, &origin_y, &child_useless_for_API); + x += origin_x; + y += origin_y; } ::XMoveResizeWindow(disp, reinterpret_cast(wd), x, y, r.width, r.height);