fix bug that window has wrong position if it has an ancestor

This commit is contained in:
Jinhao 2019-01-21 22:35:44 +08:00
parent 5935ce2036
commit 8ecae7402c

View File

@ -1,7 +1,7 @@
/* /*
* Platform Implementation * Platform Implementation
* Nana C++ Library(http://www.nanapro.org) * 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. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
@ -29,6 +29,7 @@
#include "../../paint/image_accessor.hpp" #include "../../paint/image_accessor.hpp"
namespace nana{ namespace nana{
namespace detail{ namespace detail{
@ -199,7 +200,7 @@ namespace nana{
namespace x11_wait namespace x11_wait
{ {
static Bool configure(Display *disp, XEvent *evt, char *arg) static Bool configure(Display *disp, XEvent *evt, char *arg)
{ {
return disp && evt && arg && (evt->type == ConfigureNotify) && (evt->xconfigure.window == *reinterpret_cast<Window*>(arg)); return disp && evt && arg && (evt->type == ConfigureNotify) && (evt->xconfigure.window == *reinterpret_cast<Window*>(arg));
} }
@ -1019,15 +1020,11 @@ namespace nana{
auto const owner = restrict::spec.get_owner(wd); auto const owner = restrict::spec.get_owner(wd);
if(owner && (owner != reinterpret_cast<native_window_type>(restrict::spec.root_window()))) if(owner && (owner != reinterpret_cast<native_window_type>(restrict::spec.root_window())))
{ {
auto origin = window_position(owner); int origin_x, origin_y;
#if 0 Window child_useless_for_API;
x += origin.x; ::XTranslateCoordinates(disp, reinterpret_cast<Window>(owner), restrict::spec.root_window(), 0, 0, &origin_x, &origin_y, &child_useless_for_API);
y += origin.y; x += origin_x;
#else y += origin_y;
auto owner_extents = window_frame_extents(owner);
x += origin.x + owner_extents.left;
y += origin.y + owner_extents.top;
#endif
} }
::XMoveWindow(disp, reinterpret_cast<Window>(wd), x, y); ::XMoveWindow(disp, reinterpret_cast<Window>(wd), x, y);
@ -1074,7 +1071,6 @@ namespace nana{
XSizeHints hints; XSizeHints hints;
nana::detail::platform_scope_guard psg; nana::detail::platform_scope_guard psg;
//Returns if the requested rectangle is same with the current rectangle. //Returns if the requested rectangle is same with the current rectangle.
//In some X-Server versions/implementations, XMapWindow() doesn't generate //In some X-Server versions/implementations, XMapWindow() doesn't generate
//a ConfigureNotify if the requested rectangle is same with the current rectangle. //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); auto const owner = restrict::spec.get_owner(wd);
if(owner && (owner != reinterpret_cast<native_window_type>(restrict::spec.root_window()))) if(owner && (owner != reinterpret_cast<native_window_type>(restrict::spec.root_window())))
{ {
auto origin = window_position(owner); int origin_x, origin_y;
Window child_useless_for_API;
auto owner_extents = window_frame_extents(owner); ::XTranslateCoordinates(disp, reinterpret_cast<Window>(owner), restrict::spec.root_window(), 0, 0, &origin_x, &origin_y, &child_useless_for_API);
x += origin.x + owner_extents.left; x += origin_x;
y += origin.y + owner_extents.top; y += origin_y;
} }
::XMoveResizeWindow(disp, reinterpret_cast<Window>(wd), x, y, r.width, r.height); ::XMoveResizeWindow(disp, reinterpret_cast<Window>(wd), x, y, r.width, r.height);