From 8e96ec340bee0b8279e3776c8cba1c3e37e7a956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 14 Sep 2015 20:27:22 +0200 Subject: [PATCH] BWindow::MoveOnScreen() now has a flags field. * You can now specify whether or not you want to resize the window, and move it on screen, or center it. * Removed PulseWindow::MoveOnScreen() method. --- headers/os/interface/Window.h | 8 +++++++- src/apps/haikudepot/ui/MainWindow.cpp | 2 +- src/apps/pulse/PulseApp.cpp | 2 +- src/apps/pulse/PulseWindow.cpp | 23 ++--------------------- src/apps/pulse/PulseWindow.h | 1 - src/apps/terminal/TermWindow.cpp | 3 ++- src/kits/interface/Window.cpp | 8 +++++--- 7 files changed, 18 insertions(+), 29 deletions(-) diff --git a/headers/os/interface/Window.h b/headers/os/interface/Window.h index b423e57cd7..586bfb7f06 100644 --- a/headers/os/interface/Window.h +++ b/headers/os/interface/Window.h @@ -83,6 +83,12 @@ enum { #define B_CURRENT_WORKSPACE 0 #define B_ALL_WORKSPACES 0xffffffff +// MoveOnScreen() flags +enum { + B_DO_NOT_RESIZE_TO_FIT = 0x0001, + B_MOVE_IF_PARTIALLY_OFFSCREEN = 0x0002 +}; + class BWindow : public BLooper { public: @@ -170,7 +176,7 @@ public: void CenterIn(const BRect& rect); void CenterOnScreen(); void CenterOnScreen(screen_id id); - void MoveOnScreen(bool resize = false); + void MoveOnScreen(uint32 flags = 0); virtual void Show(); virtual void Hide(); diff --git a/src/apps/haikudepot/ui/MainWindow.cpp b/src/apps/haikudepot/ui/MainWindow.cpp index 099f81ca82..b9f7529428 100644 --- a/src/apps/haikudepot/ui/MainWindow.cpp +++ b/src/apps/haikudepot/ui/MainWindow.cpp @@ -671,7 +671,7 @@ MainWindow::_RestoreWindowFrame(const BMessage& settings) ResizeTo(frame.Width(), frame.Height()); if (fromSettings) - MoveOnScreen(true); + MoveOnScreen(); else CenterOnScreen(); } diff --git a/src/apps/pulse/PulseApp.cpp b/src/apps/pulse/PulseApp.cpp index ad0fada538..75445e7771 100644 --- a/src/apps/pulse/PulseApp.cpp +++ b/src/apps/pulse/PulseApp.cpp @@ -143,7 +143,7 @@ PulseApp::BuildPulse() else pulseWindow = new PulseWindow(prefs->normal_window_rect); - pulseWindow->MoveOnScreen(); + pulseWindow->MoveOnScreen(B_MOVE_IF_PARTIALLY_OFFSCREEN); pulseWindow->Show(); } diff --git a/src/apps/pulse/PulseWindow.cpp b/src/apps/pulse/PulseWindow.cpp index 332a49cbfa..c27d4ad3f2 100644 --- a/src/apps/pulse/PulseWindow.cpp +++ b/src/apps/pulse/PulseWindow.cpp @@ -123,25 +123,6 @@ PulseWindow::MessageReceived(BMessage *message) } -void -PulseWindow::MoveOnScreen() -{ - // check if the window is on screen, and move it if not - BRect frame = Frame(); - BRect screenFrame = BScreen().Frame(); - - if (frame.left > screenFrame.right) - MoveBy(screenFrame.right - frame.right - 10, 0); - else if (frame.right < 0) - MoveTo(10, frame.top); - - if (frame.top > screenFrame.bottom) - MoveBy(0, screenFrame.bottom - frame.bottom - 10); - else if (frame.bottom < 0) - MoveTo(frame.left, 10); -} - - void PulseWindow::SetMode(int newmode) { @@ -163,7 +144,7 @@ PulseWindow::SetMode(int newmode) pulseapp->prefs->normal_window_rect.IntegerHeight()); MoveTo(pulseapp->prefs->normal_window_rect.left, pulseapp->prefs->normal_window_rect.top); - MoveOnScreen(); + MoveOnScreen(B_MOVE_IF_PARTIALLY_OFFSCREEN); break; case PV_MINI_MODE: @@ -183,7 +164,7 @@ PulseWindow::SetMode(int newmode) pulseapp->prefs->mini_window_rect.IntegerHeight()); MoveTo(pulseapp->prefs->mini_window_rect.left, pulseapp->prefs->mini_window_rect.top); - MoveOnScreen(); + MoveOnScreen(B_MOVE_IF_PARTIALLY_OFFSCREEN); break; case PV_DESKBAR_MODE: diff --git a/src/apps/pulse/PulseWindow.h b/src/apps/pulse/PulseWindow.h index 4896db7bde..0f9b35186a 100644 --- a/src/apps/pulse/PulseWindow.h +++ b/src/apps/pulse/PulseWindow.h @@ -27,7 +27,6 @@ class PulseWindow : public BWindow { virtual bool QuitRequested(); virtual void MessageReceived(BMessage *message); - void MoveOnScreen(); void SetMode(int newmode); private: diff --git a/src/apps/terminal/TermWindow.cpp b/src/apps/terminal/TermWindow.cpp index 71513675c1..5a233e8411 100644 --- a/src/apps/terminal/TermWindow.cpp +++ b/src/apps/terminal/TermWindow.cpp @@ -13,6 +13,7 @@ * Siarzhuk Zharski, zharik@gmx.li */ + #include "TermWindow.h" #include @@ -231,7 +232,7 @@ TermWindow::TermWindow(const BString& title, Arguments* args) ResizeTo(frame.Width(), frame.Height()); MoveTo(frame.LeftTop()); - MoveOnScreen(); + MoveOnScreen(B_MOVE_IF_PARTIALLY_OFFSCREEN); SetWorkspaces(workspaces); } else { diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index b1d61bfbd3..1979b9e247 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -2569,7 +2569,7 @@ BWindow::CenterOnScreen(screen_id id) void -BWindow::MoveOnScreen(bool resize) +BWindow::MoveOnScreen(uint32 flags) { // Set size limits now if needed UpdateSizeLimits(); @@ -2584,7 +2584,7 @@ BWindow::MoveOnScreen(bool resize) frame.InsetBy(-borderWidth, -borderWidth); frame.top -= tabHeight; - if (resize) { + if ((flags & B_DO_NOT_RESIZE_TO_FIT) == 0) { // Make sure the window fits on the screen if (frame.Width() > screenFrame.Width()) frame.right -= frame.Width() - screenFrame.Width(); @@ -2594,7 +2594,9 @@ BWindow::MoveOnScreen(bool resize) ResizeTo(frame.Width(), frame.Height()); } - if (!frame.Intersects(screenFrame)) { + if ((flags & B_MOVE_IF_PARTIALLY_OFFSCREEN) == 0 + && !screenFrame.Contains(frame) + || !frame.Intersects(screenFrame)) { // Off and away CenterOnScreen(); return;