summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWeng Xuetian <[email protected]>2017-04-05 13:41:30 -0700
committerWeng Xuetian <[email protected]>2017-04-05 13:48:26 -0700
commita418979bf1073c1a0b2b825d31d6abf495cb242a (patch)
tree6fd06b3c4128cc2086a10025ea0a445c96f6d1fd
parent6e03b6f5465a5df6135be1795b33f8fd50483ced (diff)
kimpanel: be prepared for plasma shell with highdpi flag.
-rw-r--r--applets/kimpanel/package/contents/ui/InputPanel.qml7
-rw-r--r--applets/kimpanel/plugin/screen.cpp32
-rw-r--r--applets/kimpanel/plugin/screen.h1
3 files changed, 34 insertions, 6 deletions
diff --git a/applets/kimpanel/package/contents/ui/InputPanel.qml b/applets/kimpanel/package/contents/ui/InputPanel.qml
index 6f9d7a7..d7f232d 100644
--- a/applets/kimpanel/package/contents/ui/InputPanel.qml
+++ b/applets/kimpanel/package/contents/ui/InputPanel.qml
@@ -241,8 +241,11 @@ PlasmaCore.Dialog {
}
}
- inputpanel.x = x;
- inputpanel.y = y;
+ var newRect = screen.geometryForPoint(x, y);
+ var devicePerPixelRatio = screen.devicePixelRatioForPoint(x, y);
+
+ inputpanel.x = newRect.x + (x - newRect.x) / devicePerPixelRatio;;
+ inputpanel.y = newRect.y + (y - newRect.y) / devicePerPixelRatio;;
}
function action(key) {
diff --git a/applets/kimpanel/plugin/screen.cpp b/applets/kimpanel/plugin/screen.cpp
index 603ada3..279c48e 100644
--- a/applets/kimpanel/plugin/screen.cpp
+++ b/applets/kimpanel/plugin/screen.cpp
@@ -48,13 +48,14 @@ Screen::~Screen()
{
}
-QRect Screen::geometryForPoint(int x, int y)
-{
+QScreen *screenForPoint(int x, int y) {
auto screens = qApp->screens();
QScreen* closestScreen = nullptr;
int shortestDistance = INT_MAX;
foreach(QScreen* screen, screens) {
- int thisDistance = pointToRect(x, y, screen->availableGeometry());
+ auto rect = screen->availableGeometry();
+ rect.setSize(rect.size() * screen->devicePixelRatio());
+ int thisDistance = pointToRect(x, y, rect);
if (thisDistance < shortestDistance) {
shortestDistance = thisDistance;
closestScreen = screen;
@@ -65,5 +66,28 @@ QRect Screen::geometryForPoint(int x, int y)
closestScreen = qApp->primaryScreen();
}
- return closestScreen ? closestScreen->availableGeometry() : QRect();
+ return closestScreen;
+}
+
+QRect Screen::geometryForPoint(int x, int y)
+{
+ auto closestScreen = screenForPoint(x, y);
+
+ if (closestScreen) {
+ auto rect = closestScreen->availableGeometry();
+ rect.setSize(rect.size() * closestScreen->devicePixelRatio());
+ return rect;
+ }
+ return QRect();
+}
+
+qreal Screen::devicePixelRatioForPoint(int x, int y)
+{
+ auto closestScreen = screenForPoint(x, y);
+
+ if (closestScreen) {
+ return closestScreen->devicePixelRatio();
+ }
+ return 1.0;
}
+
diff --git a/applets/kimpanel/plugin/screen.h b/applets/kimpanel/plugin/screen.h
index 3159560..34ac74b 100644
--- a/applets/kimpanel/plugin/screen.h
+++ b/applets/kimpanel/plugin/screen.h
@@ -32,6 +32,7 @@ public:
~Screen();
Q_INVOKABLE QRect geometryForPoint(int x, int y);
+ Q_INVOKABLE qreal devicePixelRatioForPoint(int x, int y);
};
#endif