Fix File > Open initial position when multiple monitors are used

With this patch we removed the ui::get_desktop_size() function
too (now we can get the workarea of the display's screen).
This commit is contained in:
David Capello 2021-04-21 17:01:43 -03:00
parent 64b5a0175d
commit 1f5b6980d3
10 changed files with 43 additions and 34 deletions

View File

@ -336,7 +336,13 @@ void update_screen_for_document(const Doc* document)
void load_window_pos(Window* window, const char* section,
const bool limitMinSize)
{
Size desktopSize = ui::get_desktop_size();
Display* parentDisplay =
(window->display() ? window->display():
window->manager()->display());
Rect workarea =
(get_multiple_displays() ?
parentDisplay->nativeWindow()->screen()->workarea():
parentDisplay->bounds());
// Default position
Rect origPos = window->bounds();
@ -345,23 +351,23 @@ void load_window_pos(Window* window, const char* section,
Rect pos = get_config_rect(section, "WindowPos", origPos);
if (limitMinSize) {
pos.w = base::clamp(pos.w, origPos.w, desktopSize.w);
pos.h = base::clamp(pos.h, origPos.h, desktopSize.h);
pos.w = base::clamp(pos.w, origPos.w, workarea.w);
pos.h = base::clamp(pos.h, origPos.h, workarea.h);
}
else {
pos.w = std::min(pos.w, desktopSize.w);
pos.h = std::min(pos.h, desktopSize.h);
pos.w = std::min(pos.w, workarea.w);
pos.h = std::min(pos.h, workarea.h);
}
pos.setOrigin(Point(base::clamp(pos.x, 0, desktopSize.w-pos.w),
base::clamp(pos.y, 0, desktopSize.h-pos.h)));
pos.setOrigin(Point(base::clamp(pos.x, workarea.x, workarea.x2()-pos.w),
base::clamp(pos.y, workarea.y, workarea.y2()-pos.h)));
window->setBounds(pos);
if (get_multiple_displays()) {
Rect frame = get_config_rect(section, "WindowFrame", gfx::Rect());
if (!frame.isEmpty()) {
limit_with_workarea(frame);
limit_with_workarea(parentDisplay, frame);
window->loadNativeFrame(frame);
}
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -421,8 +421,11 @@ bool FileSelector::show(
FILESEL_TRACE("FILESEL: Start folder '%s' (%p)\n", start_folder_path.c_str(), start_folder);
gfx::Size displaySize = ui::get_desktop_size();
setMinSize(gfx::Size(displaySize.w*9/10, displaySize.h*9/10));
{
const gfx::Size workareaSize = ui::Manager::getDefault()->display()->workareaSizeUIScale();
setMinSize(workareaSize*9/10);
}
remapWindow();
centerWindow();

View File

@ -11,6 +11,7 @@
#include "ui/display.h"
#include "base/debug.h"
#include "ui/system.h"
#include "ui/widget.h"
#include "ui/window.h"
@ -113,4 +114,16 @@ void Display::handleWindowZOrder(Window* window)
}
}
gfx::Size Display::workareaSizeUIScale()
{
if (get_multiple_displays()) {
return
nativeWindow()->screen()->workarea().size() /
nativeWindow()->scale();
}
else {
return size();
}
}
} // namespace ui

View File

@ -73,6 +73,8 @@ namespace ui {
void handleWindowZOrder(Window* window);
const std::vector<Window*>& getWindows() const { return m_windows; }
gfx::Size Display::workareaSizeUIScale();
private:
Display* m_parentDisplay;
os::WindowRef m_nativeWindow;

View File

@ -16,6 +16,7 @@
#include "os/draw_text.h"
#include "os/font.h"
#include "os/system.h"
#include "ui/display.h"
#include "ui/menu.h"
#include "ui/message.h"
#include "ui/scale.h"
@ -451,7 +452,7 @@ gfx::Size Entry::sizeHintWithText(Entry* entry,
+ 2*entry->theme()->getEntryCaretSize(entry).w
+ entry->border().width();
w = std::min(w, ui::get_desktop_size().w/2);
w = std::min(w, entry->display()->workareaSizeUIScale().w/2);
int h =
+ entry->font()->height()
@ -470,7 +471,7 @@ void Entry::onSizeHint(SizeHintEvent& ev)
+ trailing
+ border().width();
w = std::min(w, ui::get_desktop_size().w/2);
w = std::min(w, display()->workareaSizeUIScale().w/2);
int h =
+ font()->height()

View File

@ -154,17 +154,14 @@ void fit_bounds(Display* parentDisplay,
// resize it, because workareas can form an irregular shape
// (not rectangular) the calculation is a little more
// complex
void limit_with_workarea(gfx::Rect& frame)
void limit_with_workarea(Display* parentDisplay, gfx::Rect& frame)
{
if (!get_multiple_displays())
return;
gfx::Region wa = get_workarea_region();
ASSERT(parentDisplay);
// TODO use a "visibleFrameRegion = frame & wa" to check the
// visible regions and calculate if we should move the frame
// position
gfx::Rect waBounds = wa.bounds();
gfx::Rect waBounds = parentDisplay->nativeWindow()->screen()->workarea();
if (frame.x < waBounds.x) frame.x = waBounds.x;
if (frame.y < waBounds.y) frame.y = waBounds.y;
if (frame.x2() > waBounds.x2()) frame.w -= frame.x2() - waBounds.x2();

View File

@ -38,7 +38,7 @@ namespace ui {
std::function<gfx::Rect(Widget*)> getWidgetBounds)> fitLogic = nullptr);
// The "frame" is a native windows frame bounds.
void limit_with_workarea(gfx::Rect& frame);
void limit_with_workarea(Display* parentDisplay, gfx::Rect& frame);
} // namespace ui

View File

@ -1317,7 +1317,7 @@ void Manager::_openWindow(Window* window, bool center)
frame.offset(relativeToFrame.origin());
}
limit_with_workarea(frame);
limit_with_workarea(parentDisplay, frame);
spec.position(os::WindowSpec::Position::Frame);
spec.frame(frame);

View File

@ -265,18 +265,6 @@ bool get_multiple_displays()
return multi_displays;
}
gfx::Size get_desktop_size()
{
if (get_multiple_displays()) {
return
os::instance()->mainScreen()->workarea().size() /
Manager::getDefault()->display()->nativeWindow()->scale();
}
else {
return Manager::getDefault()->display()->size();
}
}
void set_clipboard_text(const std::string& text)
{
ASSERT(g_instance);

View File

@ -42,7 +42,6 @@ namespace ui {
void set_multiple_displays(bool multi);
bool get_multiple_displays();
gfx::Size get_desktop_size();
void set_clipboard_text(const std::string& text);
bool get_clipboard_text(std::string& text);