Skip to content

Commit

Permalink
Add palette change logging.
Browse files Browse the repository at this point in the history
  Ref: gh-599, searching for bottle neck
  • Loading branch information
Maximus5 committed Mar 25, 2016
1 parent 8d27d3e commit 7d9c371
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/ConEmu/OptionsClass.cpp
Expand Up @@ -1455,6 +1455,12 @@ void CSettings::ChangeCurrentPalette(const ColorPalette* pPal, bool bChangeDropD
return;
}

if (gpSet->isLogging())
{
CEStr lsLog(L"Color Palette: `", pPal->pszName, L"` ChangeDropDown=", bChangeDropDown ? L"yes" : L"no");
LogString(lsLog);
}

HWND hDlg = GetPage(thi_Colors);

if (bChangeDropDown && hDlg)
Expand All @@ -1472,16 +1478,28 @@ void CSettings::ChangeCurrentPalette(const ColorPalette* pPal, bool bChangeDropD
BOOL bTextChanged = (gpSet->AppStd.nTextColorIdx != pPal->nTextColorIdx) || (gpSet->AppStd.nBackColorIdx != pPal->nBackColorIdx);
BOOL bPopupChanged = (gpSet->AppStd.nPopTextColorIdx != pPal->nPopTextColorIdx) || (gpSet->AppStd.nPopBackColorIdx != pPal->nPopBackColorIdx);

// We need to change consoles contents if TEXT attributes was changed
if (bTextChanged || bPopupChanged)
{
wchar_t szLog[128];
_wsprintf(szLog, SKIPCOUNT(szLog)
L"Color Palette: Text {%u|%u}->{%u|%u} Popup {%u|%u}->{%u|%u}",
gpSet->AppStd.nTextColorIdx, gpSet->AppStd.nBackColorIdx, pPal->nTextColorIdx, pPal->nBackColorIdx,
gpSet->AppStd.nPopTextColorIdx, gpSet->AppStd.nPopBackColorIdx, pPal->nPopTextColorIdx, pPal->nPopBackColorIdx);
LogString(szLog);

gpSet->AppStd.nTextColorIdx = pPal->nTextColorIdx;
gpSet->AppStd.nBackColorIdx = pPal->nBackColorIdx;
gpSet->AppStd.nPopTextColorIdx = pPal->nPopTextColorIdx;
gpSet->AppStd.nPopBackColorIdx = pPal->nPopBackColorIdx;
// We need to change consoles contents if TEXT attributes was changed

UpdateTextColorSettings(bTextChanged, bPopupChanged);

LogString(L"Color Palette: UpdateTextColorSettings finished");
}

LogString(L"Color Palette: Refreshing");

gpSet->AppStd.nExtendColorIdx = pPal->nExtendColorIdx;
gpSet->AppStd.isExtendColors = pPal->isExtendColors;

Expand All @@ -1497,6 +1515,8 @@ void CSettings::ChangeCurrentPalette(const ColorPalette* pPal, bool bChangeDropD
gpConEmu->InvalidateAll();
gpConEmu->Update(true);
}

LogString(L"Color Palette: Finished");
}

LRESULT CSettings::OnEditChanged(HWND hWnd2, WPARAM wParam, LPARAM lParam)
Expand Down
15 changes: 15 additions & 0 deletions src/ConEmu/RealConsole.cpp
Expand Up @@ -13933,8 +13933,23 @@ void CRealConsole::UpdateTextColorSettings(BOOL ChangeTextAttr /*= TRUE*/, BOOL
pIn->SetConColor.NewPopupAttributes = ((mn_PopBackColorIdx & 0xF) << 4) | (mn_PopTextColorIdx & 0xF);
pIn->SetConColor.ReFillConsole = !isFar();

if (mp_Log)
{
wchar_t szLog[140];
_wsprintf(szLog, SKIPCOUNT(szLog)
L"Color Palette: CECMD_SETCONCOLORS: Text(%s) {%u|%u} Popup(%s) {%u|%u} Refill=%s",
ChangeTextAttr ? L"change" : L"leave",
(pIn->SetConColor.NewTextAttributes & 0xF), ((pIn->SetConColor.NewTextAttributes & 0xF0) >> 4),
ChangePopupAttr ? L"change" : L"leave",
(pIn->SetConColor.NewPopupAttributes & 0xF), ((pIn->SetConColor.NewPopupAttributes & 0xF0) >> 4),
pIn->SetConColor.ReFillConsole ? L"yes" : L"no");
LogString(szLog);
}

CESERVER_REQ *pOut = ExecuteSrvCmd(GetServerPID(), pIn, ghWnd);

if (mp_Log) LogString(L"Color Palette: CECMD_SETCONCOLORS finished");

ExecuteFreeResult(pIn);
ExecuteFreeResult(pOut);
}
Expand Down
7 changes: 7 additions & 0 deletions src/ConEmu/VirtualConsole.cpp
Expand Up @@ -2567,6 +2567,13 @@ bool CVirtualConsole::ChangePalette(int aNewPaletteIdx)
if (!pPal)
return false;

if (gpSet->isLogging())
{
wchar_t szIndex[16];
CEStr lsLog(L"VCon[", _itow(mn_Index, szIndex, 10), L"]: Color Palette: `", pPal->pszName, L"`");
LogString(lsLog);
}

BOOL bTextChanged = (pOldPal==NULL), bPopupChanged = (pOldPal==NULL);
if (pOldPal)
{
Expand Down
4 changes: 4 additions & 0 deletions src/ConEmuCD/ConsoleMain.cpp
Expand Up @@ -6191,6 +6191,8 @@ static bool ApplyConsoleSizeBuffer(const USHORT BufferHeight, const COORD& crNew

void RefillConsoleAttributes(const CONSOLE_SCREEN_BUFFER_INFO& csbi5, WORD OldText, WORD NewText)
{
LogString(L"RefillConsoleAttributes started");

// Считать из консоли текущие атрибуты (построчно/поблочно)
// И там, где они совпадают с OldText - заменить на in.SetConColor.NewTextAttributes
DWORD nMaxLines = max(1,min((8000 / csbi5.dwSize.X),csbi5.dwSize.Y));
Expand Down Expand Up @@ -6249,6 +6251,8 @@ void RefillConsoleAttributes(const CONSOLE_SCREEN_BUFFER_INFO& csbi5, WORD OldTe
}

free(pnAttrs);

LogString(L"RefillConsoleAttributes finished");
}


Expand Down
13 changes: 12 additions & 1 deletion src/ConEmuCD/SrvCommands.cpp
Expand Up @@ -1748,11 +1748,15 @@ BOOL cmd_SetFullScreen(CESERVER_REQ& in, CESERVER_REQ** out)
return lbRc;
}

// CECMD_SETCONCOLORS
BOOL cmd_SetConColors(CESERVER_REQ& in, CESERVER_REQ** out)
{
BOOL lbRc = FALSE;
BOOL bOk = FALSE;
//ghConOut

LogString(L"CECMD_SETCONCOLORS: Received");

// Need to block all requests to output buffer in other threads
MSectionLockSimple csRead; csRead.Lock(&gpSrv->csReadConsoleInfo, LOCK_READOUTPUT_TIMEOUT);

Expand All @@ -1761,7 +1765,7 @@ BOOL cmd_SetConColors(CESERVER_REQ& in, CESERVER_REQ** out)

if ((*out) != NULL)
{
BOOL bOk = FALSE, bTextChanged = FALSE, bPopupChanged = FALSE, bNeedRepaint = TRUE;
BOOL bTextChanged = FALSE, bPopupChanged = FALSE, bNeedRepaint = TRUE;
WORD OldText = 0x07, OldPopup = 0x3E;

CONSOLE_SCREEN_BUFFER_INFO csbi5 = {};
Expand All @@ -1775,6 +1779,7 @@ BOOL cmd_SetConColors(CESERVER_REQ& in, CESERVER_REQ** out)

if (gnOsVer >= 0x600)
{
LogString(L"CECMD_SETCONCOLORS: acquiring CONSOLE_SCREEN_BUFFER_INFOEX");
MY_CONSOLE_SCREEN_BUFFER_INFOEX csbi6 = {sizeof(csbi6)};
if (apiGetConsoleScreenBufferInfoEx(ghConOut, &csbi6))
{
Expand All @@ -1797,10 +1802,12 @@ BOOL cmd_SetConColors(CESERVER_REQ& in, CESERVER_REQ** out)
if (bPopupChanged)
{
BOOL bIsVisible = IsWindowVisible(ghConWnd);
LogString(L"CECMD_SETCONCOLORS: applying CONSOLE_SCREEN_BUFFER_INFOEX");
bOk = apiSetConsoleScreenBufferInfoEx(ghConOut, &csbi6);
bNeedRepaint = FALSE;
if (!bIsVisible && IsWindowVisible(ghConWnd))
{
LogString(L"CECMD_SETCONCOLORS: RealConsole was shown unexpectedly");
apiShowWindow(ghConWnd, SW_HIDE);
}
if (bOk)
Expand All @@ -1811,6 +1818,7 @@ BOOL cmd_SetConColors(CESERVER_REQ& in, CESERVER_REQ** out)
}
else
{
LogString(L"CECMD_SETCONCOLORS: applying ConsoleTextAttributes");
bOk = SetConsoleTextAttribute(ghConOut, in.SetConColor.NewTextAttributes);
if (bOk)
{
Expand All @@ -1833,6 +1841,7 @@ BOOL cmd_SetConColors(CESERVER_REQ& in, CESERVER_REQ** out)
}
else
{
LogString(L"CECMD_SETCONCOLORS: applying ConsoleTextAttributes");
bOk = SetConsoleTextAttribute(ghConOut, in.SetConColor.NewTextAttributes);
if (bOk)
{
Expand Down Expand Up @@ -1867,6 +1876,8 @@ BOOL cmd_SetConColors(CESERVER_REQ& in, CESERVER_REQ** out)
lbRc = FALSE;
}

LogString(bOk ? L"CECMD_SETCONCOLORS: Succeeded" : L"CECMD_SETCONCOLORS: Failed");

return lbRc;
}

Expand Down

0 comments on commit 7d9c371

Please sign in to comment.