diff --git a/src/app/modules/gui.cpp b/src/app/modules/gui.cpp index af645c337..7690aae04 100644 --- a/src/app/modules/gui.cpp +++ b/src/app/modules/gui.cpp @@ -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); } } diff --git a/src/app/ui/file_selector.cpp b/src/app/ui/file_selector.cpp index 06eb04302..37ac5d1b7 100644 --- a/src/app/ui/file_selector.cpp +++ b/src/app/ui/file_selector.cpp @@ -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(); diff --git a/src/ui/display.cpp b/src/ui/display.cpp index 2dd242206..b26617ebe 100644 --- a/src/ui/display.cpp +++ b/src/ui/display.cpp @@ -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 diff --git a/src/ui/display.h b/src/ui/display.h index 544411f5d..be4b97b72 100644 --- a/src/ui/display.h +++ b/src/ui/display.h @@ -73,6 +73,8 @@ namespace ui { void handleWindowZOrder(Window* window); const std::vector& getWindows() const { return m_windows; } + gfx::Size Display::workareaSizeUIScale(); + private: Display* m_parentDisplay; os::WindowRef m_nativeWindow; diff --git a/src/ui/entry.cpp b/src/ui/entry.cpp index 90b82a5fb..9be1ea0d4 100644 --- a/src/ui/entry.cpp +++ b/src/ui/entry.cpp @@ -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() diff --git a/src/ui/fit_bounds.cpp b/src/ui/fit_bounds.cpp index 25262e063..7205c17ac 100644 --- a/src/ui/fit_bounds.cpp +++ b/src/ui/fit_bounds.cpp @@ -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(); diff --git a/src/ui/fit_bounds.h b/src/ui/fit_bounds.h index 876ef066e..0faff541e 100644 --- a/src/ui/fit_bounds.h +++ b/src/ui/fit_bounds.h @@ -38,7 +38,7 @@ namespace ui { std::function 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 diff --git a/src/ui/manager.cpp b/src/ui/manager.cpp index 8923d7782..8d0a2579e 100644 --- a/src/ui/manager.cpp +++ b/src/ui/manager.cpp @@ -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); diff --git a/src/ui/system.cpp b/src/ui/system.cpp index db02de74e..4cedf4790 100644 --- a/src/ui/system.cpp +++ b/src/ui/system.cpp @@ -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); diff --git a/src/ui/system.h b/src/ui/system.h index 7f307ef0b..1b5c8abfb 100644 --- a/src/ui/system.h +++ b/src/ui/system.h @@ -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);