Merge pull request #5293 from lemondrops/win11-corners

Disable Windows 11 rounded window corners when they cover the emulated screen
This commit is contained in:
Miran Grča
2025-03-07 07:21:03 +01:00
committed by GitHub
3 changed files with 34 additions and 0 deletions

View File

@@ -181,6 +181,9 @@ MainWindow::MainWindow(QWidget *parent)
status->setSoundGainAction(ui->actionSound_gain);
ui->stackedWidget->setMouseTracking(true);
statusBar()->setVisible(!hide_status_bar);
#ifdef Q_OS_WINDOWS
util::setWin11RoundedCorners(this->winId(), (hide_status_bar ? false : true));
#endif
statusBar()->setStyleSheet("QStatusBar::item {border: None; } QStatusBar QLabel { margin-right: 2px; margin-bottom: 1px; }");
this->centralWidget()->setStyleSheet("background-color: black;");
ui->toolBar->setVisible(!hide_tool_bar);
@@ -799,6 +802,9 @@ MainWindow::initRendererMonitorSlot(int monitor_index)
if (vid_resize == 2)
secondaryRenderer->setFixedSize(fixed_size_x, fixed_size_y);
secondaryRenderer->setWindowIcon(this->windowIcon());
#ifdef Q_OS_WINDOWS
util::setWin11RoundedCorners(secondaryRenderer->winId(), false);
#endif
if (show_second_monitors) {
secondaryRenderer->show();
if (window_remember) {
@@ -1833,6 +1839,9 @@ MainWindow::on_actionHide_status_bar_triggered()
hide_status_bar ^= 1;
ui->actionHide_status_bar->setChecked(hide_status_bar);
statusBar()->setVisible(!hide_status_bar);
#ifdef Q_OS_WINDOWS
util::setWin11RoundedCorners(main_window->winId(), (hide_status_bar ? false : true));
#endif
if (vid_resize >= 2) {
setFixedSize(fixed_size_x, fixed_size_y + menuBar()->height() + (hide_status_bar ? 0 : statusBar()->height()) + (hide_tool_bar ? 0 : ui->toolBar->height()));
} else {

View File

@@ -26,6 +26,19 @@
#include <QUuid>
#include "qt_util.hpp"
#ifdef Q_OS_WINDOWS
# include <dwmapi.h>
# ifndef DWMWA_WINDOW_CORNER_PREFERENCE
# define DWMWA_WINDOW_CORNER_PREFERENCE 33
# endif
# ifndef DWMWCP_DEFAULT
# define DWMWCP_DEFAULT 0
# endif
# ifndef DWMWCP_DONOTROUND
# define DWMWCP_DONOTROUND 1
# endif
#endif
extern "C" {
#include <86box/86box.h>
#include <86box/config.h>
@@ -48,6 +61,15 @@ screenOfWidget(QWidget *widget)
#endif
}
#ifdef Q_OS_WINDOWS
void
setWin11RoundedCorners(WId hwnd, bool enable)
{
auto cornerPreference = (enable ? DWMWCP_DEFAULT : DWMWCP_DONOTROUND);
DwmSetWindowAttribute((HWND) hwnd, DWMWA_WINDOW_CORNER_PREFERENCE, (LPCVOID) &cornerPreference, sizeof(cornerPreference));
}
#endif
QString
DlgFilter(std::initializer_list<QString> extensions, bool last)
{

View File

@@ -13,6 +13,9 @@ static constexpr auto UUID_MIN_LENGTH = 36;
QString DlgFilter(std::initializer_list<QString> extensions, bool last = false);
/* Returns screen the widget is on */
QScreen *screenOfWidget(QWidget *widget);
#ifdef Q_OS_WINDOWS
void setWin11RoundedCorners(WId hwnd, bool enable);
#endif
QString currentUuid();
void storeCurrentUuid();
bool compareUuid();