Skip to content

Commit

Permalink
sfjsh
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisotura committed Dec 27, 2023
1 parent cbd65a1 commit 5a08118
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
80 changes: 80 additions & 0 deletions qt-wayland-scale-hack.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
diff --git a/src/frontend/qt_sdl/Screen.cpp b/src/frontend/qt_sdl/Screen.cpp
index d8af6624..019ce246 100644
--- a/src/frontend/qt_sdl/Screen.cpp
+++ b/src/frontend/qt_sdl/Screen.cpp
@@ -30,6 +30,7 @@
#include <QPaintEvent>
#include <QPainter>
#include <QDebug>
+#include <QApplication>
#ifndef _WIN32
#ifndef APPLE
#include <qpa/qplatformnativeinterface.h>
@@ -596,23 +597,20 @@ void ScreenPanelGL::drawScreenGL()
glContext->SwapBuffers();
}

-qreal ScreenPanelGL::devicePixelRatioFromScreen() const
+qreal ScreenPanelGL::devicePixelRatioFromWindow() const
{
- const QScreen* screen_for_ratio = window()->windowHandle()->screen();
- if (!screen_for_ratio)
- screen_for_ratio = QGuiApplication::primaryScreen();
-
- return screen_for_ratio ? screen_for_ratio->devicePixelRatio() : static_cast<qreal>(1);
+ QWindow* window = windowHandle();
+ return window->devicePixelRatio();
}

int ScreenPanelGL::scaledWindowWidth() const
{
- return std::max(static_cast<int>(std::ceil(static_cast<qreal>(width()) * devicePixelRatioFromScreen())), 1);
+ return std::max(static_cast<int>(std::ceil(static_cast<qreal>(width()) * devicePixelRatioFromWindow())), 1);
}

int ScreenPanelGL::scaledWindowHeight() const
{
- return std::max(static_cast<int>(std::ceil(static_cast<qreal>(height()) * devicePixelRatioFromScreen())), 1);
+ return std::max(static_cast<int>(std::ceil(static_cast<qreal>(height()) * devicePixelRatioFromWindow())), 1);
}

std::optional<WindowInfo> ScreenPanelGL::getWindowInfo()
@@ -644,6 +642,7 @@ std::optional<WindowInfo> ScreenPanelGL::getWindowInfo()

wi.display_connection = pni->nativeResourceForWindow("display", handle);
wi.window_handle = pni->nativeResourceForWindow("surface", handle);
+ qApp->processEvents();
}
else
{
@@ -654,7 +653,7 @@ std::optional<WindowInfo> ScreenPanelGL::getWindowInfo()

wi.surface_width = static_cast<u32>(scaledWindowWidth());
wi.surface_height = static_cast<u32>(scaledWindowHeight());
- wi.surface_scale = static_cast<float>(devicePixelRatioFromScreen());
+ wi.surface_scale = static_cast<float>(devicePixelRatioFromWindow());

return wi;
}
diff --git a/src/frontend/qt_sdl/Screen.h b/src/frontend/qt_sdl/Screen.h
index b11df29b..79889a3f 100644
--- a/src/frontend/qt_sdl/Screen.h
+++ b/src/frontend/qt_sdl/Screen.h
@@ -23,6 +23,8 @@
#include "FrontendUtil.h"
#include "duckstation/gl/context.h"

+#include <optional>
+
#include <QWidget>
#include <QWindow>
#include <QMainWindow>
@@ -133,7 +135,7 @@ public:
void transferLayout();
protected:

- qreal devicePixelRatioFromScreen() const;
+ qreal devicePixelRatioFromWindow() const;
int scaledWindowWidth() const;
int scaledWindowHeight() const;

2 changes: 2 additions & 0 deletions src/frontend/qt_sdl/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef SCREEN_H
#define SCREEN_H

#include <optional>

#include "glad/glad.h"
#include "FrontendUtil.h"
#include "duckstation/gl/context.h"
Expand Down

0 comments on commit 5a08118

Please sign in to comment.