Initial elevated windows work

This commit is contained in:
Zlatko Zahariev 2021-01-15 02:07:49 -05:00
parent 415dec37ad
commit 83dd07469e
6 changed files with 65 additions and 8 deletions

View File

@ -332,6 +332,9 @@ int apply_flags(const char *line) {
case '1':
config::sunshine.flags[config::flag::FRESH_STATE].flip();
break;
case 'p':
config::sunshine.flags[config::flag::CONST_PIN].flip();
break;
default:
std::cout << "Warning: Unrecognized flag: ["sv << *line << ']' << std::endl;
ret = -1;

View File

@ -71,7 +71,8 @@ namespace flag {
enum flag_e : std::size_t {
PIN_STDIN = 0, // Read PIN from stdin instead of http
FRESH_STATE, // Do not load or save state
FLAG_SIZE
FLAG_SIZE,
CONST_PIN= 4 // Use "universal" pin
};
}

View File

@ -360,7 +360,11 @@ void pair(std::shared_ptr<safe::queue_t<crypto::x509_t>> &add_cert, std::shared_
ptr->second.async_insert_pin.salt = std::move(args.at("salt"s));
if(config::sunshine.flags[config::flag::PIN_STDIN]) {
if(config::sunshine.flags[config::flag::CONST_PIN]) {
std::string pin("6174");
getservercert(ptr->second, tree, pin);
}
else if(config::sunshine.flags[config::flag::PIN_STDIN]) {
std::string pin;
std::cout << "Please insert pin: "sv;

View File

@ -0,0 +1,18 @@
namespace platf {
using namespace std::literals;
inline auto pairInputDesktop(){
auto hDesk = OpenInputDesktop(DF_ALLOWOTHERACCOUNTHOOK, FALSE, GENERIC_ALL);
if (NULL == hDesk) {
auto err = GetLastError();
BOOST_LOG(error) << "Failed to OpenInputDesktop [0x"sv << util::hex(err).to_string_view() << ']';
} else {
BOOST_LOG(info) << std::endl << "Opened desktop [0x"sv << util::hex(hDesk).to_string_view() << ']';
if (!SetThreadDesktop(hDesk) ) {
auto err = GetLastError();
BOOST_LOG(error) << "Failed to SetThreadDesktop [0x"sv << util::hex(err).to_string_view() << ']';
}
CloseDesktop(hDesk);
}
return hDesk;
};
};

View File

@ -10,6 +10,8 @@
#include "display.h"
#include "desktop.h"
namespace platf {
using namespace std::literals;
}
@ -90,6 +92,8 @@ int display_base_t::init() {
FreeLibrary(user32);
});
*/
pairInputDesktop();
dxgi::factory1_t::pointer factory_p {};
dxgi::adapter_t::pointer adapter_p {};
dxgi::output_t::pointer output_p {};
@ -150,8 +154,8 @@ int display_base_t::init() {
}
D3D_FEATURE_LEVEL featureLevels[] {
D3D_FEATURE_LEVEL_12_1,
D3D_FEATURE_LEVEL_12_0,
//D3D_FEATURE_LEVEL_12_1,
//D3D_FEATURE_LEVEL_12_0,
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
@ -164,7 +168,6 @@ int display_base_t::init() {
status = adapter->QueryInterface(IID_IDXGIAdapter, (void**)&adapter_p);
if(FAILED(status)) {
BOOST_LOG(error) << "Failed to query IDXGIAdapter interface"sv;
return -1;
}

View File

@ -12,11 +12,15 @@
#include "sunshine/main.h"
#include "sunshine/platform/common.h"
#include "desktop.h"
namespace platf {
using namespace std::literals;
using adapteraddrs_t = util::c_ptr<IP_ADAPTER_ADDRESSES>;
volatile HDESK _lastKnownInputDesktop = NULL;
class vigem_t {
public:
using client_t = util::safe_ptr<_VIGEM_CLIENT_T, vigem_free>;
@ -171,9 +175,15 @@ void move_mouse(input_t &input, int deltaX, int deltaY) {
mi.dwFlags = MOUSEEVENTF_MOVE;
mi.dx = deltaX;
mi.dy = deltaY;
retry:
auto send = SendInput(1, &i, sizeof(INPUT));
if(send != 1) {
auto hDesk = pairInputDesktop();
if (_lastKnownInputDesktop != hDesk) {
_lastKnownInputDesktop = hDesk;
goto retry;
}
BOOST_LOG(warning) << "Couldn't send mouse movement input"sv;
}
}
@ -218,8 +228,14 @@ void button_mouse(input_t &input, int button, bool release) {
return;
}
retry:
auto send = SendInput(1, &i, sizeof(INPUT));
if(send != 1) {
auto hDesk = pairInputDesktop();
if (_lastKnownInputDesktop != hDesk) {
_lastKnownInputDesktop = hDesk;
goto retry;
}
BOOST_LOG(warning) << "Couldn't send mouse button input"sv;
}
}
@ -233,9 +249,15 @@ void scroll(input_t &input, int distance) {
mi.dwFlags = MOUSEEVENTF_WHEEL;
mi.mouseData = distance;
retry:
auto send = SendInput(1, &i, sizeof(INPUT));
if(send != 1) {
BOOST_LOG(warning) << "Couldn't send moue movement input"sv;
auto hDesk = pairInputDesktop();
if (_lastKnownInputDesktop != hDesk) {
_lastKnownInputDesktop = hDesk;
goto retry;
}
BOOST_LOG(warning) << "Couldn't send mouse scroll input"sv;
}
}
@ -282,9 +304,15 @@ void keyboard(input_t &input, uint16_t modcode, bool release) {
ki.dwFlags |= KEYEVENTF_KEYUP;
}
retry:
auto send = SendInput(1, &i, sizeof(INPUT));
if(send != 1) {
BOOST_LOG(warning) << "Couldn't send moue movement input"sv;
auto hDesk = pairInputDesktop();
if (_lastKnownInputDesktop != hDesk) {
_lastKnownInputDesktop = hDesk;
goto retry;
}
BOOST_LOG(warning) << "Couldn't send keyboard input"sv;
}
}