fix position issue on Linux

This commit is contained in:
Jinhao 2017-01-30 18:12:50 +08:00
parent 3f5d2fa0c5
commit f11c54e513
3 changed files with 35 additions and 13 deletions

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-2016 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2017 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
@ -197,6 +197,13 @@ namespace nana{
return rectangle{ primary_monitor_size() }; return rectangle{ primary_monitor_size() };
} }
#ifdef NANA_X11
//The XMoveWindow and XMoveResizeWindow don't take effect if the specified window is
//unmapped, and the members x and y of XSetSizeHints is obsoluted. So the position that
//set to a unmapped windows should be kept and use the position when the window is mapped.
std::map<Window, ::nana::point> exposed_positions; //locked by platform_scope_guard
#endif
//platform-dependent //platform-dependent
native_interface::window_result native_interface::create_window(native_window_type owner, bool nested, const rectangle& r, const appearance& app) native_interface::window_result native_interface::create_window(native_window_type owner, bool nested, const rectangle& r, const appearance& app)
{ {
@ -289,6 +296,7 @@ namespace nana{
{ {
win_attr.save_under = True; win_attr.save_under = True;
attr_mask |= CWSaveUnder; attr_mask |= CWSaveUnder;
parent = restrict::spec.root_window(); parent = restrict::spec.root_window();
calc_screen_point(owner, pos); calc_screen_point(owner, pos);
} }
@ -303,7 +311,12 @@ namespace nana{
{ {
//make owner if it is a popup window //make owner if it is a popup window
if((!nested) && owner) if((!nested) && owner)
{
restrict::spec.make_owner(owner, reinterpret_cast<native_window_type>(handle)); restrict::spec.make_owner(owner, reinterpret_cast<native_window_type>(handle));
exposed_positions[handle] = pos;
}
XChangeWindowAttributes(disp, handle, attr_mask, &win_attr);
XTextProperty name; XTextProperty name;
char text[] = "Nana Window"; char text[] = "Nana Window";
@ -655,6 +668,14 @@ namespace nana{
if(show) if(show)
{ {
::XMapWindow(disp, reinterpret_cast<Window>(wd)); ::XMapWindow(disp, reinterpret_cast<Window>(wd));
auto i = exposed_positions.find(reinterpret_cast<Window>(wd));
if(i != exposed_positions.end())
{
::XMoveWindow(disp, reinterpret_cast<Window>(wd), i->second.x, i->second.y);
exposed_positions.erase(i);
}
Window grab = restrict::spec.grab(0); Window grab = restrict::spec.grab(0);
if(grab == reinterpret_cast<Window>(wd)) if(grab == reinterpret_cast<Window>(wd))
capture_window(wd, true); capture_window(wd, true);
@ -882,13 +903,7 @@ namespace nana{
XWindowAttributes attr; XWindowAttributes attr;
::XGetWindowAttributes(disp, reinterpret_cast<Window>(wd), &attr); ::XGetWindowAttributes(disp, reinterpret_cast<Window>(wd), &attr);
if(attr.map_state == IsUnmapped) if(attr.map_state == IsUnmapped)
{ exposed_positions[reinterpret_cast<Window>(wd)] = ::nana::point{x, y};
XSizeHints hints;
hints.flags = USPosition;
hints.x = x;
hints.y = y;
::XSetWMNormalHints(disp, reinterpret_cast<Window>(wd), &hints);
}
::XMoveWindow(disp, reinterpret_cast<Window>(wd), x, y); ::XMoveWindow(disp, reinterpret_cast<Window>(wd), x, y);
#endif #endif
@ -959,11 +974,11 @@ namespace nana{
::XGetWindowAttributes(disp, reinterpret_cast<Window>(wd), &attr); ::XGetWindowAttributes(disp, reinterpret_cast<Window>(wd), &attr);
if(attr.map_state == IsUnmapped) if(attr.map_state == IsUnmapped)
{ {
hints.flags |= (USPosition | USSize); hints.flags |= USSize;
hints.x = x;
hints.y = y;
hints.width = r.width; hints.width = r.width;
hints.height = r.height; hints.height = r.height;
exposed_positions[reinterpret_cast<Window>(wd)] = point{x, y};
} }
if(hints.flags) if(hints.flags)

View File

@ -618,7 +618,7 @@ namespace nana
place_.field_display(img_fields[i], false); place_.field_display(img_fields[i], false);
} }
size({desc_extent.width, height }); move(API::make_center(this->owner(), desc_extent.width, height));
caption(title); caption(title);
} }

View File

@ -1141,7 +1141,14 @@ namespace nana
throw std::out_of_range("menu: a new item inserted to an invalid position"); throw std::out_of_range("menu: a new item inserted to an invalid position");
std::unique_ptr<item_type> item{ new item_type{ std::move(text_utf8), handler } }; std::unique_ptr<item_type> item{ new item_type{ std::move(text_utf8), handler } };
impl_->mbuilder.data().items.emplace(impl_->mbuilder.data().items.cbegin() + pos, item.get());
items.emplace(
#ifdef _MSC_VER
items.cbegin() + pos,
#else
items.begin() + pos,
#endif
item.get());
return item_proxy{ pos, *item.release() }; return item_proxy{ pos, *item.release() };
} }