]> code.delx.au - refind/blobdiff - refind/screen.c
Merge https://github.com/falstaff84/rEFInd
[refind] / refind / screen.c
index 4656e0190be0ce09ec784ac035ef23b3b016f697..2ac7cebc506cbcabe56db986744741a2ae921d79 100644 (file)
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+/*
+ * Modifications copyright (c) 2012 Roderick W. Smith
+ *
+ * Modifications distributed under the terms of the GNU General Public
+ * License (GPL) version 3 (GPLv3), a copy of which must be distributed
+ * with this source code or binaries made from it.
+ *
+ */
 
 #include "global.h"
 #include "screen.h"
@@ -108,18 +116,37 @@ VOID InitScreen(VOID)
 
     PrepareBlankLine();
 
-    // show the banner (even when in graphics mode)
-    DrawScreenHeader(L"Initializing...");
+    // show the banner if in text mode
+    if (GlobalConfig.TextOnly)
+       DrawScreenHeader(L"Initializing...");
 }
 
 VOID SetupScreen(VOID)
 {
-    GlobalConfig.RequestedTextMode = egSetTextMode(GlobalConfig.RequestedTextMode);
+    UINTN NewWidth, NewHeight;
 
-    if ((GlobalConfig.RequestedScreenWidth > 0) &&
-        (egSetScreenSize(&GlobalConfig.RequestedScreenWidth, &GlobalConfig.RequestedScreenHeight))) {
-          UGAWidth = GlobalConfig.RequestedScreenWidth;
-          UGAHeight = GlobalConfig.RequestedScreenHeight;
+    if ((GlobalConfig.RequestedScreenWidth > 0) && (GlobalConfig.RequestedScreenHeight > 0)) {
+       UGAWidth = (UGAWidth < GlobalConfig.RequestedScreenWidth) ? UGAWidth : GlobalConfig.RequestedScreenWidth;
+       UGAHeight = (UGAHeight < GlobalConfig.RequestedScreenHeight) ? UGAHeight : GlobalConfig.RequestedScreenHeight;
+    }
+    if (egSetTextMode(GlobalConfig.RequestedTextMode)) {
+       egGetScreenSize(&NewWidth, &NewHeight);
+       if ((NewWidth > UGAWidth) || (NewHeight > UGAHeight)) {
+          UGAWidth = NewWidth;
+          UGAHeight = NewHeight;
+       }
+       if (UGAWidth > GlobalConfig.RequestedScreenWidth) {
+           // Requested text mode forces us to use a bigger graphics mode
+           // TODO: Convert single mode # to width & height to check it
+           GlobalConfig.RequestedScreenWidth = UGAWidth;
+           GlobalConfig.RequestedScreenHeight = UGAHeight;
+       } // if
+    }
+
+    if (GlobalConfig.RequestedScreenWidth > 0) {
+       if (!egSetScreenSize(&GlobalConfig.RequestedScreenWidth, &GlobalConfig.RequestedScreenHeight))
+          Print(L"Error setting screen size!\n");
+       egGetScreenSize(&UGAWidth, &UGAHeight);
     } // if user requested a particular screen resolution
 
     if (GlobalConfig.TextOnly) {
@@ -133,7 +160,7 @@ VOID SetupScreen(VOID)
         SwitchToGraphics();
         BltClearScreen(TRUE);
     }
-}
+} // VOID SetupScreen()
 
 VOID SwitchToText(IN BOOLEAN CursorEnabled)
 {
@@ -189,15 +216,10 @@ VOID BeginExternalScreen(IN BOOLEAN UseGraphicsMode, IN CHAR16 *Title)
         SwitchToGraphics();
         BltClearScreen(FALSE);
     } else {
-       egClearScreen(&DarkBackgroundPixel);
-       DrawScreenHeader(Title);
-    } // if/else
-
-    // show the header
-//    DrawScreenHeader(Title);
-
-    if (!UseGraphicsMode)
+        egClearScreen(&DarkBackgroundPixel);
+        DrawScreenHeader(Title);
         SwitchToText(TRUE);
+    }
 
     // reset error flag
     haveError = FALSE;
@@ -205,9 +227,6 @@ VOID BeginExternalScreen(IN BOOLEAN UseGraphicsMode, IN CHAR16 *Title)
 
 VOID FinishExternalScreen(VOID)
 {
-    // Reset the screen resolution, in case external program changed it....
-    SetupScreen();
-
     // make sure we clean up later
     GraphicsScreenDirty = TRUE;
 
@@ -216,6 +235,9 @@ VOID FinishExternalScreen(VOID)
         PauseForKey();
     }
 
+    // Reset the screen resolution, in case external program changed it....
+    SetupScreen();
+
     // reset error flag
     haveError = FALSE;
 }