Skip to content

Commit

Permalink
Fixed mac scaling issue for mouse coords
Browse files Browse the repository at this point in the history
  • Loading branch information
smasherprog committed Aug 30, 2017
1 parent 61b0e11 commit d55c75e
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/rat_core/ServerDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

#include <atomic>

#ifdef __APPLE__
#include <ApplicationServices/ApplicationServices.h>
#endif

namespace SL {
namespace RAT {

Expand Down Expand Up @@ -60,7 +64,42 @@ namespace RAT {
void onMousePosition(const std::shared_ptr<WS_LITE::IWSocket> &socket, const unsigned char *data, size_t len)
{
if (len == sizeof(Point)) {
return IServerDriver_->onMousePosition(socket, *reinterpret_cast<const Point *>(data));
auto p =*reinterpret_cast<const Point *>(data);

#ifdef __APPLE__

CGDisplayCount count=0;
CGGetActiveDisplayList(0, 0, &count);
std::vector<CGDirectDisplayID> displays;
displays.resize(count);
CGGetActiveDisplayList(count, displays.data(), &count);

for(auto i = 0; i < count; i++) {
//only include non-mirrored displays
if(CGDisplayMirrorsDisplay(displays[i]) == kCGNullDirectDisplay){

auto dismode =CGDisplayCopyDisplayMode(displays[i]);
auto scaledsize = CGDisplayBounds(displays[i]);

auto pixelwidth = CGDisplayModeGetPixelWidth(dismode);
auto pixelheight = CGDisplayModeGetPixelHeight(dismode);

CGDisplayModeRelease(dismode);

if(scaledsize.size.width !=pixelwidth){//scaling going on!
p.X = static_cast<float>(p.X) * static_cast<float>(scaledsize.size.width)/static_cast<float>(pixelwidth);
}
if(scaledsize.size.height !=pixelheight){//scaling going on!
p.Y = static_cast<float>(p.Y) * static_cast<float>(scaledsize.size.height)/static_cast<float>(pixelheight);
}
break;
}
}

#endif


return IServerDriver_->onMousePosition(socket, p);
}
socket->close(1000, "Received invalid onMouseDown Event");
}
Expand Down

0 comments on commit d55c75e

Please sign in to comment.