#5186 Remove Dpi calculation code

This commit is contained in:
Jerry (Xinyu Hou) 2016-10-28 04:50:06 -07:00
parent c62c4d503d
commit cf397a0d6f
7 changed files with 14 additions and 244 deletions

View File

@ -800,25 +800,6 @@ bool MainWindow::serverArgs(QStringList& args, QString& app)
args << "--serial-key" << appConfig().serialKey(); 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; return true;
} }

View File

@ -31,7 +31,6 @@
#include "synergy/App.h" #include "synergy/App.h"
#include "synergy/ArgsBase.h" #include "synergy/ArgsBase.h"
#include "synergy/ClientApp.h" #include "synergy/ClientApp.h"
#include "synergy/DpiHelper.h"
#include "mt/Lock.h" #include "mt/Lock.h"
#include "mt/Thread.h" #include "mt/Thread.h"
#include "arch/win32/ArchMiscWindows.h" #include "arch/win32/ArchMiscWindows.h"
@ -146,10 +145,6 @@ MSWindowsScreen::MSWindowsScreen(
stopOnDeskSwitch); stopOnDeskSwitch);
m_keyState = new MSWindowsKeyState(m_desks, getEventTarget(), m_events); m_keyState = new MSWindowsKeyState(m_desks, getEventTarget(), m_events);
DpiHelper::calculateDpi(
GetSystemMetrics(SM_CXVIRTUALSCREEN),
GetSystemMetrics(SM_CYVIRTUALSCREEN));
updateScreenShape(); updateScreenShape();
m_class = createWindowClass(); m_class = createWindowClass();
m_window = createWindow(m_class, "Synergy"); m_window = createWindow(m_class, "Synergy");
@ -348,8 +343,7 @@ MSWindowsScreen::leave()
// warp to center // warp to center
LOG((CLOG_DEBUG1 "warping cursor to center: %+d, %+d", m_xCenter, m_yCenter)); LOG((CLOG_DEBUG1 "warping cursor to center: %+d, %+d", m_xCenter, m_yCenter));
float dpi = DpiHelper::getDpi(); warpCursor(m_xCenter, m_yCenter);
warpCursor(m_xCenter / dpi, m_yCenter / dpi);
// disable special key sequences on win95 family // disable special key sequences on win95 family
enableSpecialKeys(false); enableSpecialKeys(false);
@ -1369,20 +1363,10 @@ MSWindowsScreen::onMouseButton(WPARAM wParam, LPARAM lParam)
bool bool
MSWindowsScreen::onMouseMove(SInt32 mx, SInt32 my) 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 // compute motion delta (relative to the last known
// mouse position) // mouse position)
float x = scaledMX - m_xCursor; float x = (float)mx - m_xCursor;
float y = scaledMY - m_yCursor; float y = (float)my - m_yCursor;
LOG((CLOG_DEBUG3 LOG((CLOG_DEBUG3
"mouse move - motion delta: %+d=(%+d - %+d),%+d=(%+d - %+d)", "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 // save position to compute delta of next motion
saveMousePosition((SInt32)scaledMX, (SInt32)scaledMY); saveMousePosition(mx, my);
if (m_isOnScreen) { if (m_isOnScreen) {
// motion on primary screen // motion on primary screen
sendEvent( sendEvent(
m_events->forIPrimaryScreen().motionOnPrimary(), m_events->forIPrimaryScreen().motionOnPrimary(),
MotionInfo::alloc(originalMX, originalMY)); MotionInfo::alloc(m_xCursor, m_yCursor));
if (m_buttons[kButtonLeft] == true && m_draggingStarted == false) { if (m_buttons[kButtonLeft] == true && m_draggingStarted == false) {
m_draggingStarted = true; m_draggingStarted = true;
@ -1415,8 +1399,7 @@ MSWindowsScreen::onMouseMove(SInt32 mx, SInt32 my)
// will always try to return to the original entry point on the // will always try to return to the original entry point on the
// secondary screen. // secondary screen.
LOG((CLOG_DEBUG5 "warping server cursor to center: %+d,%+d", m_xCenter, m_yCenter)); LOG((CLOG_DEBUG5 "warping server cursor to center: %+d,%+d", m_xCenter, m_yCenter));
float dpi = DpiHelper::getDpi(); warpCursorNoFlush(m_xCenter, m_yCenter);
warpCursorNoFlush(m_xCenter / dpi, m_yCenter / dpi);
// examine the motion. if it's about the distance // examine the motion. if it's about the distance
// from the center of the screen to an edge then // from the center of the screen to an edge then
@ -1424,10 +1407,10 @@ MSWindowsScreen::onMouseMove(SInt32 mx, SInt32 my)
// ignore (see warpCursorNoFlush() for a further // ignore (see warpCursorNoFlush() for a further
// description). // description).
static SInt32 bogusZoneSize = 10; static SInt32 bogusZoneSize = 10;
if (-x + bogusZoneSize > (m_xCenter - m_x) / dpi || if (-x + bogusZoneSize > m_xCenter - m_x ||
x + bogusZoneSize > (m_x + m_w - m_xCenter) / dpi || x + bogusZoneSize > m_x + m_w - m_xCenter ||
-y + bogusZoneSize > (m_yCenter - m_y) / dpi || -y + bogusZoneSize > m_yCenter - m_y ||
y + bogusZoneSize > (m_y + m_h - m_yCenter) / dpi) { y + bogusZoneSize > m_y + m_h - m_yCenter) {
LOG((CLOG_DEBUG "dropped bogus delta motion: %+d,%+d", x, y)); LOG((CLOG_DEBUG "dropped bogus delta motion: %+d,%+d", x, y));
} }
@ -1623,22 +1606,11 @@ void
MSWindowsScreen::updateScreenShape() MSWindowsScreen::updateScreenShape()
{ {
// get shape and center // 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;
// 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_w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
m_h = GetSystemMetrics(SM_CYVIRTUALSCREEN); m_h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
m_xCenter = GetSystemMetrics(SM_CXSCREEN) >> 1; m_xCenter = GetSystemMetrics(SM_CXSCREEN) >> 1;
m_yCenter = GetSystemMetrics(SM_CYSCREEN) >> 1; m_yCenter = GetSystemMetrics(SM_CYSCREEN) >> 1;
}
// get position // get position
m_x = GetSystemMetrics(SM_XVIRTUALSCREEN); m_x = GetSystemMetrics(SM_XVIRTUALSCREEN);

View File

@ -33,7 +33,6 @@
#include "synergy/KeyState.h" #include "synergy/KeyState.h"
#include "synergy/Screen.h" #include "synergy/Screen.h"
#include "synergy/PacketStreamFilter.h" #include "synergy/PacketStreamFilter.h"
#include "synergy/DpiHelper.h"
#include "net/TCPSocket.h" #include "net/TCPSocket.h"
#include "net/IDataSocket.h" #include "net/IDataSocket.h"
#include "net/IListenSocket.h" #include "net/IListenSocket.h"
@ -2004,14 +2003,6 @@ Server::onMouseMoveSecondary(SInt32 dx, SInt32 dy)
SInt32 newX = m_x; SInt32 newX = m_x;
SInt32 newY = m_y; 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 // switch screens
switchScreen(newScreen, newX, newY, false); switchScreen(newScreen, newX, newY, false);
} }

View File

@ -23,7 +23,6 @@
#include "synergy/ClientArgs.h" #include "synergy/ClientArgs.h"
#include "synergy/ToolArgs.h" #include "synergy/ToolArgs.h"
#include "synergy/ArgsBase.h" #include "synergy/ArgsBase.h"
#include "synergy/DpiHelper.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/String.h" #include "base/String.h"
@ -58,18 +57,6 @@ ArgParser::parseServerArgs(ServerArgs& args, int argc, const char* const* argv)
// save configuration file path // save configuration file path
args.m_configFile = argv[++i]; 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)) { else if (isArg(i, argc, argv, "", "--serial-key", 1)) {
args.m_serial = SerialKey(argv[++i]); args.m_serial = SerialKey(argv[++i]);
} }

View File

@ -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));
}
}
}

View File

@ -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;
};

View File

@ -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);
}