This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

#5186 Remove Dpi calculation code

  • Loading branch information...
Jerry (Xinyu Hou)
Jerry (Xinyu Hou) committed Oct 28, 2016
1 parent c62c4d5 commit cf397a0d6f4cce4d8527730f849208453a22a97d
View
@@ -800,25 +800,6 @@ bool MainWindow::serverArgs(QStringList& args, QString& app)
args << "--serial-key" << appConfig().serialKey();
}
-#if defined(Q_OS_WIN)
- // pass in physical resolution and primary screen center
- // TODO: get this information in the core binary even when
- // high DPI is used
- int height = QApplication::desktop()->height();
- int width = QApplication::desktop()->width();
-
- QRect rec = QApplication::desktop()->screenGeometry();
- int heightCenter = rec.height() / 2;
- int widthCenter = rec.width() / 2;
-
- appendLogDebug(tr("screen resolution: %1 %2 primary screen center: %3 %4")
- .arg(width).arg(height).arg(widthCenter).arg(heightCenter));
-
- args << "--res-w" << QString::number(width);
- args << "--res-h" << QString::number(height);
- args << "--prm-wc" << QString::number(widthCenter);
- args << "--prm-hc" << QString::number(heightCenter);
- #endif
return true;
}
@@ -31,7 +31,6 @@
#include "synergy/App.h"
#include "synergy/ArgsBase.h"
#include "synergy/ClientApp.h"
-#include "synergy/DpiHelper.h"
#include "mt/Lock.h"
#include "mt/Thread.h"
#include "arch/win32/ArchMiscWindows.h"
@@ -146,10 +145,6 @@ MSWindowsScreen::MSWindowsScreen(
stopOnDeskSwitch);
m_keyState = new MSWindowsKeyState(m_desks, getEventTarget(), m_events);
- DpiHelper::calculateDpi(
- GetSystemMetrics(SM_CXVIRTUALSCREEN),
- GetSystemMetrics(SM_CYVIRTUALSCREEN));
-
updateScreenShape();
m_class = createWindowClass();
m_window = createWindow(m_class, "Synergy");
@@ -348,8 +343,7 @@ MSWindowsScreen::leave()
// warp to center
LOG((CLOG_DEBUG1 "warping cursor to center: %+d, %+d", m_xCenter, m_yCenter));
- float dpi = DpiHelper::getDpi();
- warpCursor(m_xCenter / dpi, m_yCenter / dpi);
+ warpCursor(m_xCenter, m_yCenter);
// disable special key sequences on win95 family
enableSpecialKeys(false);
@@ -1369,20 +1363,10 @@ MSWindowsScreen::onMouseButton(WPARAM wParam, LPARAM lParam)
bool
MSWindowsScreen::onMouseMove(SInt32 mx, SInt32 my)
{
- SInt32 originalMX = mx;
- SInt32 originalMY = my;
- float scaledMX = (float)mx;
- float scaledMY = (float)my;
-
- if (DpiHelper::s_dpiScaled) {
- scaledMX /= DpiHelper::getDpi();
- scaledMY /= DpiHelper::getDpi();
- }
-
// compute motion delta (relative to the last known
// mouse position)
- float x = scaledMX - m_xCursor;
- float y = scaledMY - m_yCursor;
+ float x = (float)mx - m_xCursor;
+ float y = (float)my - m_yCursor;
LOG((CLOG_DEBUG3
"mouse move - motion delta: %+d=(%+d - %+d),%+d=(%+d - %+d)",
@@ -1395,14 +1379,14 @@ MSWindowsScreen::onMouseMove(SInt32 mx, SInt32 my)
}
// save position to compute delta of next motion
- saveMousePosition((SInt32)scaledMX, (SInt32)scaledMY);
+ saveMousePosition(mx, my);
if (m_isOnScreen) {
// motion on primary screen
sendEvent(
m_events->forIPrimaryScreen().motionOnPrimary(),
- MotionInfo::alloc(originalMX, originalMY));
+ MotionInfo::alloc(m_xCursor, m_yCursor));
if (m_buttons[kButtonLeft] == true && m_draggingStarted == false) {
m_draggingStarted = true;
@@ -1415,19 +1399,18 @@ MSWindowsScreen::onMouseMove(SInt32 mx, SInt32 my)
// will always try to return to the original entry point on the
// secondary screen.
LOG((CLOG_DEBUG5 "warping server cursor to center: %+d,%+d", m_xCenter, m_yCenter));
- float dpi = DpiHelper::getDpi();
- warpCursorNoFlush(m_xCenter / dpi, m_yCenter / dpi);
+ warpCursorNoFlush(m_xCenter, m_yCenter);
// examine the motion. if it's about the distance
// from the center of the screen to an edge then
// it's probably a bogus motion that we want to
// ignore (see warpCursorNoFlush() for a further
// description).
static SInt32 bogusZoneSize = 10;
- if (-x + bogusZoneSize > (m_xCenter - m_x) / dpi ||
- x + bogusZoneSize > (m_x + m_w - m_xCenter) / dpi ||
- -y + bogusZoneSize > (m_yCenter - m_y) / dpi ||
- y + bogusZoneSize > (m_y + m_h - m_yCenter) / dpi) {
+ if (-x + bogusZoneSize > m_xCenter - m_x ||
+ x + bogusZoneSize > m_x + m_w - m_xCenter ||
+ -y + bogusZoneSize > m_yCenter - m_y ||
+ y + bogusZoneSize > m_y + m_h - m_yCenter) {
LOG((CLOG_DEBUG "dropped bogus delta motion: %+d,%+d", x, y));
}
@@ -1623,22 +1606,11 @@ void
MSWindowsScreen::updateScreenShape()
{
// get shape and center
- if (DpiHelper::s_dpiScaled) {
- // use the original resolution size for width and height
- m_w = (SInt32)DpiHelper::s_resolutionWidth;
- m_h = (SInt32)DpiHelper::s_resolutionHeight;
+ m_w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
+ m_h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
- // calculate center position according to the original size
- m_xCenter = (SInt32)DpiHelper::s_primaryWidthCenter;
- m_yCenter = (SInt32)DpiHelper::s_primaryHeightCenter;
- }
- else {
- m_w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
- m_h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
-
- m_xCenter = GetSystemMetrics(SM_CXSCREEN) >> 1;
- m_yCenter = GetSystemMetrics(SM_CYSCREEN) >> 1;
- }
+ m_xCenter = GetSystemMetrics(SM_CXSCREEN) >> 1;
+ m_yCenter = GetSystemMetrics(SM_CYSCREEN) >> 1;
// get position
m_x = GetSystemMetrics(SM_XVIRTUALSCREEN);
@@ -33,7 +33,6 @@
#include "synergy/KeyState.h"
#include "synergy/Screen.h"
#include "synergy/PacketStreamFilter.h"
-#include "synergy/DpiHelper.h"
#include "net/TCPSocket.h"
#include "net/IDataSocket.h"
#include "net/IListenSocket.h"
@@ -2004,14 +2003,6 @@ Server::onMouseMoveSecondary(SInt32 dx, SInt32 dy)
SInt32 newX = m_x;
SInt32 newY = m_y;
- if (DpiHelper::s_dpiScaled) {
- // only scale if it's going back to server
- if (newScreen->isPrimary()) {
- newX = (SInt32)(newX / DpiHelper::getDpi());
- newY = (SInt32)(newY / DpiHelper::getDpi());
- }
- }
-
// switch screens
switchScreen(newScreen, newX, newY, false);
}
@@ -23,7 +23,6 @@
#include "synergy/ClientArgs.h"
#include "synergy/ToolArgs.h"
#include "synergy/ArgsBase.h"
-#include "synergy/DpiHelper.h"
#include "base/Log.h"
#include "base/String.h"
@@ -58,18 +57,6 @@ ArgParser::parseServerArgs(ServerArgs& args, int argc, const char* const* argv)
// save configuration file path
args.m_configFile = argv[++i];
}
- else if (isArg(i, argc, argv, "", "--res-w", 1)) {
- DpiHelper::s_resolutionWidth = synergy::string::stringToSizeType(argv[++i]);
- }
- else if (isArg(i, argc, argv, "", "--res-h", 1)) {
- DpiHelper::s_resolutionHeight = synergy::string::stringToSizeType(argv[++i]);
- }
- else if (isArg(i, argc, argv, "", "--prm-wc", 1)) {
- DpiHelper::s_primaryWidthCenter = synergy::string::stringToSizeType(argv[++i]);
- }
- else if (isArg(i, argc, argv, "", "--prm-hc", 1)) {
- DpiHelper::s_primaryHeightCenter = synergy::string::stringToSizeType(argv[++i]);
- }
else if (isArg(i, argc, argv, "", "--serial-key", 1)) {
args.m_serial = SerialKey(argv[++i]);
}
@@ -1,53 +0,0 @@
-/*
- * synergy -- mouse and keyboard sharing utility
- * Copyright (C) 2015 Synergy Seamless Inc.
- *
- * This package is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * found in the file LICENSE that should have accompanied this file.
- *
- * This package is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "synergy/DpiHelper.h"
-#include "base/Log.h"
-
-#include <assert.h>
-
-size_t DpiHelper::s_dpi = kDefaultDpi;
-bool DpiHelper::s_dpiScaled = false;
-size_t DpiHelper::s_resolutionWidth = 0;
-size_t DpiHelper::s_resolutionHeight = 0;
-size_t DpiHelper::s_primaryWidthCenter = 0;
-size_t DpiHelper::s_primaryHeightCenter = 0;
-
-void DpiHelper::calculateDpi(size_t width, size_t height)
-{
- if (s_resolutionWidth == 0 ||
- s_resolutionHeight == 0 ||
- s_primaryWidthCenter == 0 ||
- s_primaryHeightCenter == 0) {
- return;
- }
-
- size_t dpiTest1 = s_resolutionWidth * 100 / width;
- size_t dpiTest2 = s_resolutionHeight * 100 / height;
-
- if (dpiTest1 == dpiTest2) {
- s_dpi = dpiTest1;
-
- if (s_dpi != kDefaultDpi) {
- s_dpiScaled = true;
-
- LOG((CLOG_DEBUG "DPI: %d%%", s_dpi));
- LOG((CLOG_DEBUG "physical resolution: %d, %d scaled resolution: %d, %d",
- s_resolutionWidth, s_resolutionHeight, width, height));
- }
- }
-}
@@ -1,38 +0,0 @@
-/*
- * synergy -- mouse and keyboard sharing utility
- * Copyright (C) 2015 Synergy Seamless Inc.
- *
- * This package is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * found in the file LICENSE that should have accompanied this file.
- *
- * This package is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-#include "common/common.h"
-
-class DpiHelper {
-public:
- enum EDpi {
- kDefaultDpi = 100
- };
-
- static void calculateDpi(size_t width, size_t height);
- static float getDpi() { return (float)(s_dpi / 100.0f); }
-
-public:
- static size_t s_dpi;
- static bool s_dpiScaled;
- static size_t s_resolutionWidth;
- static size_t s_resolutionHeight;
- static size_t s_primaryWidthCenter;
- static size_t s_primaryHeightCenter;
-};
@@ -1,70 +0,0 @@
-/*
- * synergy -- mouse and keyboard sharing utility
- * Copyright (C) 2015 Synergy Seamless Inc.
- *
- * This package is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * found in the file LICENSE that should have accompanied this file.
- *
- * This package is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "synergy/DpiHelper.h"
-
-#include "test/global/gtest.h"
-
-void resetStaticVariables()
-{
- DpiHelper::s_resolutionWidth = 0;
- DpiHelper::s_resolutionHeight = 0;
- DpiHelper::s_primaryWidthCenter = 0;
- DpiHelper::s_primaryHeightCenter = 0;
- DpiHelper::s_dpi = DpiHelper::kDefaultDpi;
- DpiHelper::s_dpiScaled = false;
-}
-
-TEST(DpiHelperTests, calculateDpi_samePhysicalAndVirtualResolutions_defaultDpi)
-{
- resetStaticVariables();
-
- DpiHelper::s_resolutionWidth = 1920;
- DpiHelper::s_resolutionHeight = 1080;
- DpiHelper::s_primaryWidthCenter = 960;
- DpiHelper::s_primaryHeightCenter = 540;
-
- DpiHelper::calculateDpi(1920, 1080);
-
- EXPECT_FALSE(DpiHelper::s_dpiScaled);
- EXPECT_EQ(DpiHelper::kDefaultDpi, DpiHelper::s_dpi);
-}
-
-TEST(DpiHelperTests, calculateDpi_differentPhysicalAndVirtualResolutions_scaledDpi)
-{
- resetStaticVariables();
-
- DpiHelper::s_resolutionWidth = 1920;
- DpiHelper::s_resolutionHeight = 1080;
- DpiHelper::s_primaryWidthCenter = 960;
- DpiHelper::s_primaryHeightCenter = 540;
-
- DpiHelper::calculateDpi(960, 540);
-
- EXPECT_TRUE(DpiHelper::s_dpiScaled);
- EXPECT_EQ(200, DpiHelper::s_dpi);
-}
-
-TEST(DpiHelperTests, calculateDpi_defaultStaticValues_defaultDpi)
-{
- resetStaticVariables();
-
- DpiHelper::calculateDpi(1920, 1080);
-
- EXPECT_FALSE(DpiHelper::s_dpiScaled);
- EXPECT_EQ(DpiHelper::kDefaultDpi, DpiHelper::s_dpi);
-}

0 comments on commit cf397a0

Please sign in to comment.