separate data in global config

Signed-off-by: Sergey Isakov <isakov-sl@bk.ru>
This commit is contained in:
Sergey Isakov 2020-03-27 19:50:17 +03:00
parent e5beea2f1b
commit 8f2c4b5efd
11 changed files with 211 additions and 51 deletions

View File

@ -1007,8 +1007,8 @@ typedef struct {
// GUI parameters
BOOLEAN Debug;
BOOLEAN Proportional;
// UINT8 Pad22[1];
// BOOLEAN Proportional; //never used
UINT8 Pad22[1];
UINT32 DefaultBackgroundColor;
//ACPI

View File

@ -109,14 +109,87 @@ extern INTN ScrollBarDecorationsHeight;
extern INTN ScrollScrollDecorationsHeight;
extern EFI_AUDIO_IO_PROTOCOL *AudioIo;
//extern INTN OldChosenAudio;
/*
typedef struct {
INTN Timeout;
UINTN DisableFlags;
#if !USE_XTHEME
UINTN HideBadges;
UINTN HideUIFlags;
#endif
BOOLEAN TextOnly;
BOOLEAN Quiet;
BOOLEAN LegacyFirst;
BOOLEAN NoLegacy;
BOOLEAN DebugLog;
BOOLEAN FastBoot;
BOOLEAN NeverHibernate;
BOOLEAN StrictHibernate;
BOOLEAN RtcHibernateAware;
BOOLEAN HibernationFixup;
BOOLEAN SignatureFixup;
#if !USE_XTHEME
FONT_TYPE Font;
INTN CharWidth;
UINTN SelectionColor;
CHAR16 *FontFileName;
CHAR16 *Theme;
CHAR16 *BannerFileName;
CHAR16 *SelectionSmallFileName;
CHAR16 *SelectionBigFileName;
CHAR16 *SelectionIndicatorName;
CHAR16 *DefaultSelection;
#endif
CHAR16 *ScreenResolution;
INTN ConsoleMode;
BOOLEAN CustomIcons;
#if !USE_XTHEME
CHAR16 *BackgroundName;
SCALING BackgroundScale;
UINTN BackgroundSharp;
BOOLEAN BackgroundDark;
BOOLEAN SelectionOnTop;
BOOLEAN BootCampStyle;
INTN BadgeOffsetX;
INTN BadgeOffsetY;
INTN BadgeScale;
INTN ThemeDesignWidth;
INTN ThemeDesignHeight;
INTN BannerPosX;
INTN BannerPosY;
INTN BannerEdgeHorizontal;
INTN BannerEdgeVertical;
INTN BannerNudgeX;
INTN BannerNudgeY;
BOOLEAN VerticalLayout;
BOOLEAN NonSelectedGrey;
INTN MainEntriesSize;
INTN TileXSpace;
INTN TileYSpace;
#endif
INTN IconFormat;
BOOLEAN NoEarlyProgress;
INT32 Timezone;
BOOLEAN ShowOptimus;
#if !USE_XTHEME
BOOLEAN Proportional;
BOOLEAN DarkEmbedded;
BOOLEAN TypeSVG;
INTN Codepage;
INTN CodepageSize;
float Scale;
float CentreShift;
#endif
} REFIT_CONFIG;
*/
// global configuration with default values
REFIT_CONFIG GlobalConfig = {
-1, // INTN Timeout;
0, // UINTN DisableFlags;
#if !USE_XTHEME
0, // UINTN HideBadges;
0, // UINTN HideUIFlags;
#endif
FALSE, // BOOLEAN TextOnly;
TRUE, // BOOLEAN Quiet;
FALSE, // BOOLEAN LegacyFirst;
@ -126,6 +199,10 @@ REFIT_CONFIG GlobalConfig = {
FALSE, // BOOLEAN NeverHibernate;
FALSE, // BOOLEAN StrictHibernate;
FALSE, // BOOLEAN RtcHibernateAware;
FALSE, // BOOLEAN HibernationFixup;
FALSE, // BOOLEAN SignatureFixup;
#if !USE_XTHEME
FONT_GRAY, // FONT_TYPE Font; //Welcome should be white
9, // INTN CharWidth;
0xFFFFFF80, // UINTN SelectionColor;
@ -136,13 +213,15 @@ REFIT_CONFIG GlobalConfig = {
NULL, // CHAR16 *SelectionBigFileName;
NULL, // CHAR16 *SelectionIndicatorName;
NULL, // CHAR16 *DefaultSelection;
#endif
NULL, // CHAR16 *ScreenResolution;
0, // INTN ConsoleMode;
FALSE, // BOOLEAN CustomIcons;
#if !USE_XTHEME
NULL, // CHAR16 *BackgroundName;
imNone, // SCALING BackgroundScale;
0, // UINTN BackgroundSharp;
FALSE, // BOOLEAN BackgroundDark;
FALSE, // BOOLEAN CustomIcons;
FALSE, // BOOLEAN SelectionOnTop;
FALSE, // BOOLEAN BootCampStyle;
0, // INTN BadgeOffsetX;
@ -161,19 +240,20 @@ REFIT_CONFIG GlobalConfig = {
128, // INTN MainEntriesSize;
8, // INTN TileXSpace;
24, // INTN TileYSpace;
#endif
ICON_FORMAT_DEF, // INTN IconFormat;
FALSE, // BOOLEAN Proportional;
FALSE, // BOOLEAN NoEarlyProgress;
0, // INT32 Timezone;
FALSE, // BOOLEAN ShowOptimus;
FALSE, // BOOLEAN HibernationFixup;
FALSE, // BOOLEAN SignatureFixup;
#if !USE_XTHEME
FALSE, // BOOLEAN Proportional;
FALSE, // BOOLEAN DarkEmbedded;
FALSE, // BOOLEAN TypeSVG;
0, // INT32 Timezone;
0xC0, // INTN Codepage;
0xC0, // INTN CodepageSize; //extended latin
1.0f, // float Scale;
0.0f, // float CentreShift;
#endif
};
static struct FIX_CONFIG { const CHAR8* oldName; const CHAR8* newName; UINT32 bitData; } FixesConfig[] =
@ -2979,23 +3059,12 @@ GetEarlyUserSettings (
gSettings.PlayAsync = IsPropertyTrue (Prop);
// CustomIcons
#if USE_XTHEME
Prop = GetProperty (DictPointer, "CustomIcons");
ThemeX.CustomIcons = IsPropertyTrue(Prop);
Prop = GetProperty (DictPointer, "ShowOptimus");
ThemeX.ShowOptimus = IsPropertyTrue (Prop);
Prop = GetProperty (DictPointer, "TextOnly");
ThemeX.TextOnly = IsPropertyTrue (Prop);
#else
Prop = GetProperty (DictPointer, "CustomIcons");
GlobalConfig.CustomIcons = IsPropertyTrue(Prop);
Prop = GetProperty (DictPointer, "ShowOptimus");
GlobalConfig.ShowOptimus = IsPropertyTrue (Prop);
Prop = GetProperty (DictPointer, "TextOnly");
GlobalConfig.TextOnly = IsPropertyTrue (Prop);
#endif
Prop = GetProperty (DictPointer, "ShowOptimus");
GlobalConfig.ShowOptimus = IsPropertyTrue (Prop);
Prop = GetProperty (DictPointer, "ScreenResolution");
if (Prop != NULL) {
@ -3923,7 +3992,7 @@ XTheme::GetThemeTagSettings (void* DictP)
Dict2 = GetProperty (Dict, "Tools");
if (Dict2 && Dict2->type == kTagTypeFalse) {
DisableFlags |= HIDEUI_FLAG_TOOLS;
HideUIFlags |= HIDEUI_FLAG_TOOLS;
}
Dict2 = GetProperty (Dict, "Label");
@ -4012,7 +4081,17 @@ XTheme::GetThemeTagSettings (void* DictP)
FontFileName.takeValueFrom(Dict2->string);
}
}
#if USE_XTHEME
Dict2 = GetProperty (Dict, "CharWidth");
ThemeX.CharWidth = (UINTN)GetPropertyInteger (Dict2, ThemeX.CharWidth);
if (ThemeX.CharWidth & 1) {
MsgLog("Warning! Character width %lld should be even!\n", ThemeX.CharWidth);
}
Dict2 = GetProperty (Dict, "Proportional");
ThemeX.Proportional = IsPropertyTrue (Dict2);
#else
Dict2 = GetProperty (Dict, "CharWidth");
CharWidth = (UINTN)GetPropertyInteger (Dict2, CharWidth);
if (GlobalConfig.CharWidth & 1) {
@ -4020,7 +4099,10 @@ XTheme::GetThemeTagSettings (void* DictP)
}
Dict2 = GetProperty (Dict, "Proportional");
Proportional = IsPropertyTrue (Dict2);
GlobalConfig.Proportional = IsPropertyTrue (Dict2);
#endif
}
Dict = GetProperty (DictPointer, "Anime");
@ -4410,7 +4492,7 @@ GetThemeTagSettings (
Dict2 = GetProperty (Dict, "Tools");
if (Dict2 && Dict2->type == kTagTypeFalse) {
GlobalConfig.DisableFlags |= HIDEUI_FLAG_TOOLS;
GlobalConfig.HideUIFlags |= HIDEUI_FLAG_TOOLS;
}
Dict2 = GetProperty (Dict, "Label");
@ -7228,7 +7310,18 @@ GetUserSettings(
} else {
//DBG("\n ConfigName: %ls n", gSettings.ConfigName);
}
#if USE_XTHEME
if (gThemeChanged && ThemeX.Theme) {
DictPointer = GetProperty (Dict, "GUI");
if (DictPointer != NULL) {
Prop = GetProperty (DictPointer, "Theme");
if ((Prop != NULL) && (Prop->type == kTagTypeString) && Prop->string) {
ThemeX.Theme.takeValueFrom(Prop->string);
DBG ("Theme from new config: %ls\n", ThemeX.Theme.data());
}
}
}
#else
if (gThemeChanged && GlobalConfig.Theme) {
DictPointer = GetProperty (Dict, "GUI");
if (DictPointer != NULL) {
@ -7240,6 +7333,7 @@ GetUserSettings(
}
}
}
#endif
SaveSettings();
}

View File

@ -100,8 +100,10 @@ wchar_t * XStringW::forgetDataWithoutFreeing()
const XStringW& XStringW::takeValueFrom(const wchar_t* S)
{
if ( !S ) {
DebugLog(2, "takeValueFrom(const wchar_t* S) called with NULL. Use setEmpty()\n");
panic();
// DebugLog(2, "takeValueFrom(const wchar_t* S) called with NULL. Use setEmpty()\n");
// panic();
Init(0);
return *this;
}
Init(wcslen(S));
StrCpy(S);

View File

@ -689,8 +689,8 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST CHAR16 *LoaderPath,
// get custom volume icon if present
#if USE_XTHEME
if (ThemeX.CustomIcons && FileExists(Volume->RootDir, L"\\.VolumeIcon.icns")){
Entry->Image = LoadIcns(Volume->RootDir, L"\\.VolumeIcon.icns", 128);
if (GlobalConfig.CustomIcons && FileExists(Volume->RootDir, L"\\.VolumeIcon.icns")){
Entry->Image.LoadIcns(Volume->RootDir, L"\\.VolumeIcon.icns", 128);
DBG("using VolumeIcon.icns image from Volume\n");
} else if (Image) {
Entry->Image.FromEGImage(Image);

View File

@ -102,6 +102,7 @@ public:
// will be used instead of old egLoadImage
EFI_STATUS LoadXImage(EFI_FILE *Dir, const XStringW& FileName); //for example LoadImage(ThemeDir, L"icons\\" + Name);
EFI_STATUS LoadXImage(EFI_FILE *Dir, const char* IconName);
EFI_STATUS LoadIcns(IN EFI_FILE *Dir, IN CONST CHAR16 *FileName, IN UINTN PixelSize);
void EnsureImageSize(IN UINTN Width, IN UINTN Height, IN CONST EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color);
void DummyImage(IN UINTN PixelSize);

View File

@ -108,7 +108,7 @@ XTheme::~XTheme() {
void XTheme::Init()
{
DisableFlags = 0;
// DisableFlags = 0;
HideBadges = 0;
HideUIFlags = 0;
TextOnly = FALSE;
@ -126,7 +126,7 @@ void XTheme::Init()
BackgroundScale = imNone; // SCALING
BackgroundSharp = 0;
BackgroundDark = FALSE; //TODO should be set to true if Night theme
CustomIcons = FALSE; //TODO don't know how to handle with SVG theme
// CustomIcons = FALSE; //TODO don't know how to handle with SVG theme
SelectionOnTop = FALSE;
BootCampStyle = FALSE;
BadgeOffsetX = 0;
@ -147,7 +147,7 @@ void XTheme::Init()
TileYSpace = 24;
// IconFormat = ICON_FORMAT_DEF;
Proportional = FALSE;
ShowOptimus = FALSE;
// ShowOptimus = FALSE;
DarkEmbedded = FALSE; //looks like redundant, we always check Night or Daylight
TypeSVG = FALSE;
Codepage = 0xC0; //this is for PNG theme

View File

@ -31,7 +31,7 @@ public:
XObjArray<Icon> Icons;
EFI_FILE *ThemeDir;
UINTN DisableFlags;
// UINTN DisableFlags;
UINTN HideBadges;
UINTN HideUIFlags;
BOOLEAN TextOnly;
@ -49,7 +49,7 @@ public:
SCALING BackgroundScale;
INTN BackgroundSharp;
BOOLEAN BackgroundDark;
BOOLEAN CustomIcons;
// BOOLEAN CustomIcons;
BOOLEAN SelectionOnTop;
BOOLEAN BootCampStyle;
INTN BadgeOffsetX;
@ -70,7 +70,7 @@ public:
INTN TileYSpace;
// INTN IconFormat;
BOOLEAN Proportional;
BOOLEAN ShowOptimus;
// BOOLEAN ShowOptimus;
BOOLEAN DarkEmbedded;
BOOLEAN TypeSVG;
INTN Codepage;

View File

@ -52,7 +52,7 @@
//
// well-known icons
//
#if !USE_XTHEME
BUILTIN_ICON BuiltinIconTable[] = {
{ NULL, L"icons\\func_about" , L"png", /*48*/32 },
{ NULL, L"icons\\func_options" , L"png", /*48*/32 },
@ -128,7 +128,9 @@ CHAR16 * GetIconsExt(IN CONST CHAR16 *Icon, IN CONST CHAR16 *Def)
{
return PoolPrint(L"%s.%s", Icon, ((GlobalConfig.IconFormat != ICON_FORMAT_DEF) && (IconFormat != NULL)) ? IconFormat : Def);
}
#endif
#if !USE_XTHEME
EG_IMAGE * BuiltinIcon(IN UINTN Id)
{
INTN Size;
@ -292,11 +294,11 @@ EG_IMAGE * BuiltinIcon(IN UINTN Id)
return BuiltinIconTable[Id].Image;
}
#endif
//
// Load an icon for an operating system
//
#if !USE_XTHEME
EG_IMAGE * LoadOSIcon(IN CONST CHAR16 *OSIconName OPTIONAL, IN CONST CHAR16 *FallbackIconName, IN UINTN PixelSize, IN BOOLEAN BootLogo, IN BOOLEAN WantDummy)
{
EG_IMAGE *Image;
@ -373,11 +375,38 @@ EG_IMAGE * LoadOSIcon(IN CONST CHAR16 *OSIconName OPTIONAL, IN CONST CHAR16 *Fal
return DummyImage(PixelSize);
}
#endif
//
// Load an image from a .icns file
//
#if USE_XTHEME
EFI_STATUS XImage::LoadIcns(IN EFI_FILE_HANDLE BaseDir, IN CONST CHAR16 *FileName, IN UINTN PixelSize)
{
if (GlobalConfig.TextOnly) // skip loading if it's not used anyway
return EFI_SUCCESS;
if (BaseDir) {
EFI_STATUS Status = EFI_NOT_FOUND;
UINT8 *FileData = NULL;
UINTN FileDataLength = 0;
EG_IMAGE *NewImage;
// load file
Status = egLoadFile(BaseDir, FileName, &FileData, &FileDataLength);
if (EFI_ERROR(Status)) {
return Status;
}
// decode it
NewImage = egDecodeICNS(FileData, FileDataLength, PixelSize, TRUE);
Status = FromEGImage(NewImage);
FreePool(FileData);
return Status;
}
return EFI_NOT_FOUND;
}
#else
EG_IMAGE * LoadIcns(IN EFI_FILE_HANDLE BaseDir, IN CONST CHAR16 *FileName, IN UINTN PixelSize)
{
if (GlobalConfig.TextOnly) // skip loading if it's not used anyway
@ -393,18 +422,21 @@ EG_IMAGE * LoadIcns(IN EFI_FILE_HANDLE BaseDir, IN CONST CHAR16 *FileName, IN UI
if (EFI_ERROR(Status)) {
return NULL;
}
// decode it
NewImage = egDecodeICNS(FileData, FileDataLength, PixelSize, TRUE);
FreePool(FileData);
return NewImage;
}
return DummyImage(PixelSize);
}
#endif
#if !USE_XTHEME
EG_IMAGE * DummyImage(IN UINTN PixelSize)
{
EG_IMAGE *Image;
@ -448,3 +480,4 @@ EG_IMAGE * LoadIcnsFallback(IN EFI_FILE_HANDLE BaseDir, IN CONST CHAR16 *FileNam
// Image = DummyImage(PixelSize);
return Image;
}
#endif

View File

@ -70,8 +70,11 @@ extern XTheme ThemeX; //global variable defined in lib.cpp
#endif
#define REFIT_DEBUG (2)
#if USE_XTHEME
#define Print if ((!GlobalConfig.Quiet) || (ThemeX.TextOnly)) Print
#else
#define Print if ((!GlobalConfig.Quiet) || (GlobalConfig.TextOnly)) Print
//#include "GenericBdsLib.h"
#endif
#ifdef __cplusplus
extern "C" {
@ -313,8 +316,10 @@ extern INTN ScrollbarYMovement;
typedef struct {
INTN Timeout;
UINTN DisableFlags;
#if !USE_XTHEME
UINTN HideBadges;
UINTN HideUIFlags;
#endif
BOOLEAN TextOnly;
BOOLEAN Quiet;
BOOLEAN LegacyFirst;
@ -324,6 +329,9 @@ typedef struct {
BOOLEAN NeverHibernate;
BOOLEAN StrictHibernate;
BOOLEAN RtcHibernateAware;
BOOLEAN HibernationFixup;
BOOLEAN SignatureFixup;
#if !USE_XTHEME
FONT_TYPE Font;
INTN CharWidth;
UINTN SelectionColor;
@ -334,13 +342,15 @@ typedef struct {
CHAR16 *SelectionBigFileName;
CHAR16 *SelectionIndicatorName;
CHAR16 *DefaultSelection;
#endif
CHAR16 *ScreenResolution;
INTN ConsoleMode;
BOOLEAN CustomIcons;
#if !USE_XTHEME
CHAR16 *BackgroundName;
SCALING BackgroundScale;
UINTN BackgroundSharp;
BOOLEAN BackgroundDark;
BOOLEAN CustomIcons;
BOOLEAN SelectionOnTop;
BOOLEAN BootCampStyle;
INTN BadgeOffsetX;
@ -359,19 +369,20 @@ typedef struct {
INTN MainEntriesSize;
INTN TileXSpace;
INTN TileYSpace;
#endif
INTN IconFormat;
BOOLEAN Proportional;
BOOLEAN NoEarlyProgress;
INT32 Timezone;
BOOLEAN ShowOptimus;
BOOLEAN HibernationFixup;
BOOLEAN SignatureFixup;
#if !USE_XTHEME
BOOLEAN Proportional;
BOOLEAN DarkEmbedded;
BOOLEAN TypeSVG;
INT32 Timezone;
INTN Codepage;
INTN CodepageSize;
float Scale;
float CentreShift;
#endif
} REFIT_CONFIG;
// types

View File

@ -2584,7 +2584,8 @@ RefitMain (IN EFI_HANDLE ImageHandle,
}
// fixed other menu entries
if (!(GlobalConfig.DisableFlags & HIDEUI_FLAG_TOOLS)) {
#if USE_XTHEME
if (!(ThemeX.HideUIFlags & HIDEUI_FLAG_TOOLS)) {
AddCustomTool();
if (!gSettings.DisableToolScan) {
ScanTool();
@ -2594,8 +2595,26 @@ RefitMain (IN EFI_HANDLE ImageHandle,
#endif // ENABLE_SECURE_BOOT
}
}
#else
if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_TOOLS)) {
AddCustomTool();
if (!gSettings.DisableToolScan) {
ScanTool();
#ifdef ENABLE_SECURE_BOOT
// Check for secure boot setup mode
AddSecureBootTool();
#endif // ENABLE_SECURE_BOOT
}
}
#endif
#if USE_XTHEME
MenuEntryOptions.Image = ThemeX.GetIcon(BUILTIN_ICON_FUNC_OPTIONS);
#else
MenuEntryOptions.Image = BuiltinIcon(BUILTIN_ICON_FUNC_OPTIONS);
#endif
if (gSettings.DisableCloverHotkeys)
MenuEntryOptions.ShortcutLetter = 0x00;
MainMenu.AddMenuEntry(&MenuEntryOptions, false);

View File

@ -4625,7 +4625,7 @@ VOID DrawTextCorner(UINTN TextC, UINT8 Align)
// HIDEUI_ALL - included
((TextC == TEXT_CORNER_REVISION) && ((ThemeX.HideUIFlags & HIDEUI_FLAG_REVISION) != 0)) ||
((TextC == TEXT_CORNER_HELP) && ((ThemeX.HideUIFlags & HIDEUI_FLAG_HELP) != 0)) ||
((TextC == TEXT_CORNER_OPTIMUS) && (ThemeX.ShowOptimus == FALSE))
((TextC == TEXT_CORNER_OPTIMUS) && (GlobalConfig.ShowOptimus == FALSE))
) {
return;
}