Skip to content

Commit

Permalink
Add Icon to themes + Dark TitleBar (x64dbg#2611)
Browse files Browse the repository at this point in the history
* Add Icon to themes

* Fix formatting

* Dark Titlebar Test

* Fix Formatting

* Hopefully fixed errors

* Test Dark-Mode

* Potentially fix issue

* Try linking library

* Test Dark-Mode (Round 2)

* Fix Formatting

* Test Dark-Mode (Round 3)

* Working Dark Titlebar

* Fixed Icon on toolbar

* Exclude .vscode/ Directory

* Dark Mode Config: Bool -> Int

* Made error not sound backwards

* Some updates to dark title bar

* Fix crash in 32-bit

* Get Windows 10 NtBuildNumber from KUSER_SHARED_DATA instead

* Add hack that fixed the redrawing issue

Co-authored-by: Duncan Ogilvie <[email protected]>
  • Loading branch information
Yakov5776 and mrexodia authored Mar 19, 2021
1 parent 4feff86 commit 19069dc
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ COV/
minidump/
CppDependOut/
.vs/
.vscode/

# Global filetypes to ignore
*.depend
Expand Down
1 change: 1 addition & 0 deletions bin/themes/Dark/style.ini
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,4 @@ ThreadCurrentColor=#FFFFFF
WatchTriggeredBackgroundColor=#XXXXXX
WatchTriggeredColor=#EF5350
LinkColor=#89A2F6
DarkTitleBar=1
35 changes: 34 additions & 1 deletion src/gui/Src/Gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ MainWindow::MainWindow(QWidget* parent)
mCpuWidget->setDisasmFocus();

QTimer::singleShot(0, this, SLOT(loadWindowSettings()));

updateDarkTitleBar();
}

MainWindow::~MainWindow()
Expand Down Expand Up @@ -518,6 +520,7 @@ void MainWindow::themeTriggeredSlot()
QString name = dir.mid(nameIdx + 1);
BridgeSettingSet("Theme", "Selected", name.toUtf8().constData());
loadSelectedStyle();
updateDarkTitleBar();
}

void MainWindow::setupThemesMenu()
Expand Down Expand Up @@ -1090,6 +1093,34 @@ void MainWindow::updateWindowTitleSlot(QString filename)
}
}

void MainWindow::updateDarkTitleBar()
{
// https://www.vergiliusproject.com/kernels/x64/Windows%2010%20%7C%202016/2009%2020H2%20(October%202020%20Update)/_KUSER_SHARED_DATA
uint32_t NtBuildNumber = *(uint32_t*)(0x7FFE0000 + 0x260);

if(NtBuildNumber == 0 /* pre Windows-10 */ || NtBuildNumber < 17763)
return;

duint darkTitleBar = 0;
BridgeSettingGetUint("Colors", "DarkTitleBar", &darkTitleBar);

static auto hdwmapi = LoadLibraryW(L"dwmapi.dll");
if(hdwmapi)
{
typedef int(WINAPI * DWMSETWINDOWATTRIBUTE)(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute);
static auto DwmSetWindowAttribute = (DWMSETWINDOWATTRIBUTE)GetProcAddress(hdwmapi, "DwmSetWindowAttribute");
auto hwnd = (HWND)this->winId();
DwmSetWindowAttribute(hwnd, (NtBuildNumber >= 18985) ? 20 : 19, &darkTitleBar, sizeof(uint32_t));

// HACK: Create a 1x1 pixel frameless window on top of the title bar to force Windows to redraw it
auto w = new QWidget(nullptr, Qt::FramelessWindowHint);
w->resize(1, 1);
w->move(this->pos());
w->show();
delete w;
}
}

// Used by View->CPU
void MainWindow::displayCpuWidgetShowCpu()
{
Expand Down Expand Up @@ -1594,7 +1625,7 @@ void MainWindow::patchWindow()
{
if(!DbgIsDebugging())
{
SimpleErrorBox(this, tr("Error!"), tr("Patches cannot be shown when not debugging..."));
SimpleErrorBox(this, tr("Error!"), tr("Patches can only be shown while debugging..."));
return;
}
GuiUpdatePatches();
Expand Down Expand Up @@ -2330,11 +2361,13 @@ void MainWindow::on_actionDefaultTheme_triggered()
// Reset [Colors] to default
Config()->Colors = Config()->defaultColors;
Config()->writeColors();
BridgeSettingSetUint("Colors", "DarkTitleBar", 0);
// Reset [Fonts] to default
//Config()->Fonts = Config()->defaultFonts;
//Config()->writeFonts();
// Remove custom colors
BridgeSettingSet("Colors", "CustomColorCount", nullptr);
updateDarkTitleBar();
}

void MainWindow::updateStyle()
Expand Down
1 change: 1 addition & 0 deletions src/gui/Src/Gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public slots:

QAction* actionManageFavourites;

void updateDarkTitleBar();
void updateMRUMenu();
void setupLanguagesMenu();
void setupThemesMenu();
Expand Down
4 changes: 4 additions & 0 deletions src/gui/Src/Gui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@
<property name="title">
<string>&amp;Theme</string>
</property>
<property name="icon">
<iconset resource="../../resource.qrc">
<normaloff>:/icons/images/themes.png</normaloff>:/icons/images/themes.png</iconset>
</property>
<addaction name="actionDefaultTheme"/>
</widget>
<addaction name="actionSettings"/>
Expand Down
Binary file added src/gui/images/themes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/gui/resource.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
<file>images/breakpoint_exception_add.png</file>
<file>images/breakpoint_module_add.png</file>
<file>images/importsettings.png</file>
<file>images/themes.png</file>
<file>images/initscript.png</file>
<file>images/struct.png</file>
<file>images/removestruct.png</file>
Expand Down

0 comments on commit 19069dc

Please sign in to comment.