mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 02:38:11 +00:00
LibGUI: Don't center dialog within parent if window is not visible
Windows have an initial off-screen rect, so when a dialog is created and shown before its parent window, in which it is centered, it would be invisible to the user. Fixes #3172.
This commit is contained in:
parent
115c124a77
commit
55bd54f91f
1 changed files with 8 additions and 5 deletions
|
@ -25,7 +25,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibCore/EventLoop.h>
|
#include <LibCore/EventLoop.h>
|
||||||
#include <LibGUI/Desktop.h>
|
|
||||||
#include <LibGUI/Dialog.h>
|
#include <LibGUI/Dialog.h>
|
||||||
#include <LibGUI/Event.h>
|
#include <LibGUI/Event.h>
|
||||||
|
|
||||||
|
@ -45,14 +44,18 @@ int Dialog::exec()
|
||||||
{
|
{
|
||||||
ASSERT(!m_event_loop);
|
ASSERT(!m_event_loop);
|
||||||
m_event_loop = make<Core::EventLoop>();
|
m_event_loop = make<Core::EventLoop>();
|
||||||
auto new_rect = rect();
|
|
||||||
if (parent() && parent()->is_window()) {
|
if (parent() && parent()->is_window()) {
|
||||||
auto& parent_window = *static_cast<Window*>(parent());
|
auto& parent_window = *static_cast<Window*>(parent());
|
||||||
new_rect.center_within(parent_window.rect());
|
if (parent_window.is_visible()) {
|
||||||
|
auto new_rect = rect();
|
||||||
|
new_rect.center_within(parent_window.rect());
|
||||||
|
set_rect(new_rect);
|
||||||
|
} else {
|
||||||
|
center_on_screen();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
new_rect.center_within(Desktop::the().rect());
|
center_on_screen();
|
||||||
}
|
}
|
||||||
set_rect(new_rect);
|
|
||||||
show();
|
show();
|
||||||
auto result = m_event_loop->exec();
|
auto result = m_event_loop->exec();
|
||||||
m_event_loop = nullptr;
|
m_event_loop = nullptr;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue