1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:58:11 +00:00

LibGUI+WindowServer: Provide default placement to windows

This prevents windows from being opened directly on top of eachother,
and provides default behavior for when window position is not specified.

The new behavior is as follows:
- Windows that have been created without a set position are assigned one
  by WindowServer.
- The assigned position is either offset from the last window that is
  still in an assigned position, or a default position if no such window
  is available.
This commit is contained in:
Peter Elliott 2020-07-30 19:52:45 -06:00 committed by Andreas Kling
parent 586ada7a14
commit 5ae9eee4a3
8 changed files with 62 additions and 4 deletions

View file

@ -442,6 +442,7 @@ void WindowManager::start_window_move(Window& window, const MouseEvent& event)
#endif
move_to_front_and_make_active(window);
m_move_window = window.make_weak_ptr();
m_move_window->set_default_positioned(false);
m_move_origin = event.position();
m_move_window_origin = window.position();
window.invalidate();
@ -479,6 +480,10 @@ void WindowManager::start_window_resize(Window& window, const Gfx::IntPoint& pos
m_resize_window_original_rect = window.rect();
window.invalidate();
if (hot_area_row == 0 || hot_area_column == 0) {
m_resize_window->set_default_positioned(false);
}
}
void WindowManager::start_window_resize(Window& window, const MouseEvent& event)
@ -1428,4 +1433,34 @@ void WindowManager::maximize_windows(Window& window, bool maximized)
});
}
Gfx::IntPoint WindowManager::get_recommended_window_position(const Gfx::IntPoint& desired)
{
// FIXME: Find a better source for the width and height to shift by.
Gfx::IntPoint shift(8, palette().window_title_height() + 10);
// FIXME: Find a better source for this.
int taskbar_height = 28;
int menubar_height = MenuManager::the().menubar_rect().height();
const Window* overlap_window = nullptr;
for_each_visible_window_of_type_from_front_to_back(WindowType::Normal, [&](Window& window) {
if (window.default_positioned() && (!overlap_window || overlap_window->window_id() < window.window_id())) {
overlap_window = &window;
}
return IterationDecision::Continue;
});
Gfx::IntPoint point;
if (overlap_window) {
point = overlap_window->position() + shift;
point = { point.x() % Screen::the().width(),
(point.y() >= (Screen::the().height() - taskbar_height))
? menubar_height + palette().window_title_height()
: point.y() };
} else {
point = desired;
}
return point;
}
}