From 9a7463857a3784f0435f133ae01e08fd0d670d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 16 Nov 2009 18:40:45 +0000 Subject: [PATCH] Window size handling is now a bit more robust (all this affects audio only and empty windows only): * New windows use the width from the window that was last resized by the user. * The first window uses the stored window position and size. * When switching from video content to audio content, the last window width from previous audio-only content is restored. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34078 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/mediaplayer/MainWin.cpp | 31 +++++++++++++++++++++++-------- src/apps/mediaplayer/MainWin.h | 11 +++++++---- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp index df7050dd40..3f1538d59b 100644 --- a/src/apps/mediaplayer/MainWin.cpp +++ b/src/apps/mediaplayer/MainWin.cpp @@ -57,6 +57,10 @@ #define MIN_WIDTH 250 +int +MainWin::sNoVideoWidth = MIN_WIDTH; + + // XXX TODO: why is lround not defined? #define lround(a) ((int)(0.99999 + (a))) @@ -127,18 +131,26 @@ MainWin::MainWin(bool isFirstWindow) fMouseDownTracking(false), fGlobalSettingsListener(this) { + // Handle window position and size depending on whether this is the + // first window or not. Use the window size from the window that was + // last resized by the user. static int pos = 0; MoveBy(pos * 25, pos * 25); pos = (pos + 1) % 15; - if (isFirstWindow) { - BRect frame = Settings::Default() - ->CurrentSettings().audioPlayerWindowFrame; - if (frame.IsValid()) { + BRect frame = Settings::Default()->CurrentSettings() + .audioPlayerWindowFrame; + if (frame.IsValid()) { + if (isFirstWindow) { MoveTo(frame.LeftTop()); ResizeTo(frame.Width(), frame.Height()); } + if (sNoVideoWidth == MIN_WIDTH) + sNoVideoWidth = frame.IntegerWidth(); + } else if (sNoVideoWidth > MIN_WIDTH) { + ResizeTo(sNoVideoWidth, Bounds().Height()); } + fNoVideoWidth = sNoVideoWidth; BRect rect = Bounds(); @@ -260,6 +272,9 @@ MainWin::FrameResized(float newWidth, float newHeight) // printf("FrameResized enter: newWidth %.0f, newHeight %.0f\n", // newWidth, newHeight); + if (!fHasVideo) + sNoVideoWidth = fNoVideoWidth = (int)newWidth; + int maxVideoWidth = int(newWidth) + 1; int maxVideoHeight = int(newHeight) + 1 - (noMenu ? 0 : fMenuBarHeight) @@ -719,7 +734,7 @@ MainWin::QuitRequested() BAutolock controllerLocker(fController); playlistArchive.AddInt64("position", fController->TimePosition()); controllerLocker.Unlock(); - + BAutolock playlistLocker(fPlaylist); if (fPlaylist->Archive(&playlistArchive) != B_OK || message.AddMessage("playlist", &playlistArchive) != B_OK) { @@ -1210,7 +1225,7 @@ MainWin::_CurrentVideoSizeInPercent() const void -MainWin::_ResizeWindow(int percent, bool keepWidth, bool stayOnScreen) +MainWin::_ResizeWindow(int percent, bool useNoVideoWidth, bool stayOnScreen) { // Get required window size int videoWidth; @@ -1226,8 +1241,8 @@ MainWin::_ResizeWindow(int percent, bool keepWidth, bool stayOnScreen) _GetMinimumWindowSize(width, height); width = max_c(width, videoWidth) - 1; - if (keepWidth) - width = max_c(width, (int)Frame().Width()); + if (useNoVideoWidth) + width = max_c(width, fNoVideoWidth); height = height + videoHeight - 1; if (stayOnScreen) { diff --git a/src/apps/mediaplayer/MainWin.h b/src/apps/mediaplayer/MainWin.h index 979859403b..1a40412920 100644 --- a/src/apps/mediaplayer/MainWin.h +++ b/src/apps/mediaplayer/MainWin.h @@ -86,7 +86,7 @@ private: int& videoHeight) const; int _CurrentVideoSizeInPercent() const; void _ResizeWindow(int percent, - bool keepWidth = false, + bool useNoVideoWidth = false, bool stayOnScreen = false); void _ResizeVideoView(int x, int y, int width, int height); @@ -142,9 +142,9 @@ private: PlaylistObserver* fPlaylistObserver; Controller* fController; ControllerObserver* fControllerObserver; - volatile bool fIsFullscreen; - volatile bool fAlwaysOnTop; - volatile bool fNoInterface; + volatile bool fIsFullscreen; + volatile bool fAlwaysOnTop; + volatile bool fNoInterface; int fSourceWidth; int fSourceHeight; int fWidthAspect; @@ -153,6 +153,7 @@ private: int fMenuBarHeight; int fControlsHeight; int fControlsWidth; + int fNoVideoWidth; BRect fSavedFrame; bool fMouseDownTracking; BPoint fMouseDownMousePos; @@ -161,6 +162,8 @@ private: ListenerAdapter fGlobalSettingsListener; bool fCloseWhenDonePlayingMovie; bool fCloseWhenDonePlayingSound; + + static int sNoVideoWidth; }; #endif // __MAIN_WIN_H