Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/Development'
Browse files Browse the repository at this point in the history
  • Loading branch information
smasherprog committed May 6, 2016
2 parents 3249059 + 4e8f61d commit f402bd1
Show file tree
Hide file tree
Showing 22 changed files with 599 additions and 281 deletions.
1 change: 0 additions & 1 deletion Core/ApplicationDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ std::string executable_path(const char *argv0)
}
#else


#include <stdio.h>
#include <stdlib.h>
#include <boost/filesystem/operations.hpp>
Expand Down
26 changes: 6 additions & 20 deletions Core/ClientNetworkDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ namespace SL {
std::shared_ptr<Network::WebSocket<socket>> _Socket;
std::unique_ptr<IO_Runner> _IO_Runner;
std::string _dst_host, _dst_port;


void MouseImage(const std::shared_ptr<ISocket>& socket, std::shared_ptr<Packet>& p) {
auto imgsize = (Utilities::Point*)p->Payload;
auto img(Utilities::Image::CreateImage(imgsize->Y, imgsize->X, p->Payload + sizeof(Utilities::Rect), 4));
_IClientDriver->OnReceive_MouseImage(socket, img);
}

void MousePos(const std::shared_ptr<ISocket>& socket, std::shared_ptr<Packet>& p) {
assert(p->Payload_Length == sizeof(Utilities::Point));
_IClientDriver->OnReceive_MousePos(socket, (Utilities::Point*)p->Payload);
Expand Down Expand Up @@ -111,17 +110,9 @@ namespace SL {
}

}
void SendMouse(Utilities::Point& pos) {
Packet p(static_cast<unsigned int>(PACKET_TYPES::MOUSEPOS), sizeof(pos));
auto dst = (unsigned char*)p.Payload;
memcpy(dst, &pos, sizeof(pos));
_Socket->send(p);
}
void SendMouse(Input::MouseEvents ev, Input::MousePress press) {
Packet p(static_cast<unsigned int>(PACKET_TYPES::MOUSEEVENT), sizeof(press)+ sizeof(ev));
auto dst = (unsigned char*)p.Payload;
*dst++ = ev;
*dst++ = press;
void SendMouse(const Input::MouseEvent& m) {
Packet p(static_cast<unsigned int>(PACKET_TYPES::MOUSEEVENT), sizeof(m));
memcpy(p.Payload, &m, sizeof(m));
_Socket->send(p);
}
};
Expand Down Expand Up @@ -150,12 +141,7 @@ void SL::Remote_Access_Library::Network::ClientNetworkDriver::Stop()
_ClientNetworkDriverImpl->Stop();
}

void SL::Remote_Access_Library::Network::ClientNetworkDriver::SendMouse(Utilities::Point & pos)
{
_ClientNetworkDriverImpl->SendMouse(pos);
}

void SL::Remote_Access_Library::Network::ClientNetworkDriver::SendMouse(Input::MouseEvents ev, Input::MousePress press)
void SL::Remote_Access_Library::Network::ClientNetworkDriver::SendMouse(const Input::MouseEvent& m)
{
_ClientNetworkDriverImpl->SendMouse(ev, press);
_ClientNetworkDriverImpl->SendMouse(m);
}
5 changes: 2 additions & 3 deletions Core/ClientNetworkDriver.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "IBaseNetworkDriver.h"
#include <memory>
#include "MouseInput.h"
#include "Mouse.h"

namespace SL {
namespace Remote_Access_Library {
Expand All @@ -24,8 +24,7 @@ namespace SL {
//Before calling Stop, you must ensure that any external references to shared_ptr<ISocket> have been released
void Stop();

void SendMouse(Utilities::Point& pos);
void SendMouse(Input::MouseEvents ev, Input::MousePress press);
void SendMouse(const Input::MouseEvent& m);
};
}
}
Expand Down
9 changes: 7 additions & 2 deletions Core/Core.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
<ClInclude Include="$(MSBuildThisFileDirectory)Logging.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)MediaTypes.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)Mouse.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)MouseInput.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)Packet.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)Screen.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)Server.h" />
Expand All @@ -108,7 +107,13 @@
<ClInclude Include="$(MSBuildThisFileDirectory)WebSocketListener.h" />
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\wwwroot\Core.ts" />
<None Include="$(MSBuildThisFileDirectory)..\wwwroot\Core.ts">
<FileType>Document</FileType>
<Command>tsc $(SolutionDir)wwwroot\Core.ts</Command>
<Outputs>$(OutDir)wwwroot\Core.js</Outputs>
<TreatOutputAsContent>true</TreatOutputAsContent>
<LinkObjects>false</LinkObjects>
</None>
<None Include="$(MSBuildThisFileDirectory)..\wwwroot\index.html" />
</ItemGroup>
<Import Project="$(MSBuildThisFileDirectory)copydeps.targets" />
Expand Down
4 changes: 0 additions & 4 deletions Core/Core.vcxitems.filters
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
<Filter Include="wwwroot">
<UniqueIdentifier>{486bb838-570a-425a-aaa3-9d059b12d301}</UniqueIdentifier>
</Filter>
<Filter Include="Input">
<UniqueIdentifier>{ccaac4c1-f65a-4e95-a385-603275123ebb}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)Mouse.cpp">
Expand Down Expand Up @@ -232,7 +229,6 @@
<ClInclude Include="$(MSBuildThisFileDirectory)Compression\fse_static.h">
<Filter>Compression</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)MouseInput.h" />
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\wwwroot\index.html">
Expand Down
1 change: 1 addition & 0 deletions Core/HttpHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace SL {
}
}


std::unordered_map<std::string, std::string> SL::Remote_Access_Library::Network::HttpHeader::Parse(std::string defaultheaderversion, std::istream& stream)
{
std::unordered_map<std::string, std::string> header;
Expand Down
4 changes: 3 additions & 1 deletion Core/IClientDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

namespace SL {
namespace Remote_Access_Library {

namespace Utilities {
class Image;
class Point;
}
namespace Network {
class Rect;
class IClientDriver : public IBaseNetworkDriver {
public:
IClientDriver() {}
Expand All @@ -16,6 +17,7 @@ namespace SL {
virtual void OnReceive_Image(const std::shared_ptr<ISocket>& socket,std::shared_ptr<Utilities::Image>& img) = 0;
virtual void OnReceive_MouseImage(const std::shared_ptr<ISocket>& socket, std::shared_ptr<Utilities::Image>& img) = 0;
virtual void OnReceive_MousePos(const std::shared_ptr<ISocket>& socket, Utilities::Point* pos) = 0;

};
}
}
Expand Down
8 changes: 5 additions & 3 deletions Core/IServerDriver.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#pragma once
#include "IBaseNetworkDriver.h"
#include "MouseInput.h"


namespace SL {
namespace Remote_Access_Library {
namespace Input {
struct MouseEvent;
}
namespace Utilities {
class Point;
}
Expand All @@ -17,8 +20,7 @@ namespace SL {
virtual ~IServerDriver() {}


virtual void OnMouse(Utilities::Point& pos) = 0;
virtual void OnMouse(Input::MouseEvents ev, Input::MousePress press) = 0;
virtual void OnMouse(Input::MouseEvent* m) = 0;

};
}
Expand Down
65 changes: 46 additions & 19 deletions Core/Mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include <thread>
#include "Logging.h"

#if __linux__
#include <X11/Xlib.h>
#include <X11/extensions/Xfixes.h>
#endif

namespace SL
{
namespace Remote_Access_Library
Expand Down Expand Up @@ -127,10 +132,10 @@ namespace SL

#error Applie specific implementation of CaptureMouse has not been written yet. You can help out by writing it!
#elif __ANDROID__

std::shared_ptr<Utilities::Image> CaptureMouseImage()
{
//this should never be ran
//this should never be ran
assert(true);
return Utilities::Image::CreateImage(0, 0);
}
Expand All @@ -141,8 +146,7 @@ namespace SL
return Utilities::Point(0, 0);
}
#elif __linux__
#include <X11/Xlib.h>
#include <X11/extensions/Xfixes.h>

std::shared_ptr<Utilities::Image> CaptureMouseImage()
{
auto display = XOpenDisplay(NULL);
Expand Down Expand Up @@ -181,33 +185,56 @@ namespace SL
return Utilities::Point(x, y);
}
#endif
bool SetCursorPosition(Utilities::Point p)
{


void SetMouseEvent(const Input::MouseEvent& m) {
//SL_RAT_LOG(std::string("SetMouseEvent EventData:") + std::to_string(m.EventData) + std::string(" ScrollDelta: ") + std::to_string(m.ScrollDelta) + std::string(" PressData: ") + std::to_string(m.PressData), Utilities::Logging_Levels::INFO_log_level);
#if defined _WIN32
return SetCursorPos(p.X, p.Y) == TRUE;

INPUT input;
input.type = INPUT_MOUSE;
input.mi.mouseData = m.ScrollDelta / 120;
input.mi.dx = static_cast<LONG>(static_cast<float>(m.Pos.X)*(65536.0f / static_cast<float>(GetSystemMetrics(SM_CXSCREEN))));//x being coord in pixels
input.mi.dy = static_cast<LONG>(static_cast<float>(m.Pos.Y)*(65536.0f / static_cast<float>(GetSystemMetrics(SM_CYSCREEN))));//y being coord in pixels
input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;

switch (m.EventData) {
case Input::MouseEvents::LEFT:
input.mi.dwFlags |= m.PressData == Input::MousePress::UP ? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_LEFTDOWN;
break;
case Input::MouseEvents::MIDDLE:
input.mi.dwFlags |= m.PressData == Input::MousePress::UP ? MOUSEEVENTF_MIDDLEUP : MOUSEEVENTF_MIDDLEDOWN;
break;
case Input::MouseEvents::RIGHT:
input.mi.dwFlags |= m.PressData == Input::MousePress::UP ? MOUSEEVENTF_RIGHTUP : MOUSEEVENTF_RIGHTDOWN;
break;
case Input::MouseEvents::SCROLL:
input.mi.dwFlags |= MOUSEEVENTF_WHEEL;
break;
default:
break;
}

//SendInput(1, &input, sizeof(input));

#elif defined __APPLE__
CGPoint new_pos;
CGEventErr err;
new_pos.x = p.X;
new_pos.y = p.Y;
return !CGWarpMouseCursorPosition(new_pos);
#elif __ANDROID__
return true;
new_pos.x = m.Pos.X;
new_pos.y = m.Pos.Y;
!CGWarpMouseCursorPosition(new_pos);
#elif __linux__
#include <X11/Xlib.h>

auto display = XOpenDisplay(NULL);
auto root = DefaultRootWindow(display);

XWarpPointer(display, None, root, 0, 0, 0, 0, p.X, p.Y);

XWarpPointer(display, None, root, 0, 0, 0, 0, m.Pos.X, m.Pos.Y);
XCloseDisplay(display);
return true;
#else
return false; // Fail

#endif

}


}
namespace INTERNAL
{
Expand Down
25 changes: 23 additions & 2 deletions Core/Mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,26 @@

namespace SL {
namespace Remote_Access_Library {

namespace Input {
enum MouseEvents : unsigned int {
LEFT,
RIGHT,
MIDDLE,
SCROLL,
NO_EVENTDATA
};
enum MousePress : unsigned int {
UP,
DOWN,
NO_PRESS_DATA
};
struct MouseEvent {
MouseEvents EventData;
Utilities::Point Pos;
int ScrollDelta;
MousePress PressData;
};
}
namespace Utilities {
class Image;
}
Expand All @@ -20,7 +39,9 @@ namespace SL {
Mouse(std::function<void(std::shared_ptr<Utilities::Image>)> img_func, std::function<void(Utilities::Point)> pos_func, int img_dely = 1000, int pos_dely = 20);
~Mouse();
};
bool SetCursorPosition(Utilities::Point p);

void SetMouseEvent(const Input::MouseEvent& m);
}

}
}
16 changes: 0 additions & 16 deletions Core/MouseInput.h

This file was deleted.

Loading

0 comments on commit f402bd1

Please sign in to comment.