make sure we stay in game bindings

also removed the userwindow and always show the console (for now?)
UWP_Overlay
Peter Repukat 8 years ago
parent 6cf0397902
commit 6eda0595e3

@ -21,7 +21,7 @@ SteamTargetRenderer::SteamTargetRenderer()
{ {
getSteamOverlay(); getSteamOverlay();
openUserWindow(); //openUserWindow();
#ifndef NDEBUG #ifndef NDEBUG
bDrawDebugEdges = true; bDrawDebugEdges = true;
#endif // NDEBUG #endif // NDEBUG
@ -34,17 +34,13 @@ SteamTargetRenderer::SteamTargetRenderer()
if (childkey == "bDrawDebugEdges") if (childkey == "bDrawDebugEdges")
{ {
bDrawDebugEdges = settings.value(childkey).toBool(); bDrawDebugEdges = settings.value(childkey).toBool();
} else if (childkey == "bShowDebugConsole") { //} else if (childkey == "bShowDebugConsole") {
bShowDebugConsole = settings.value(childkey).toBool(); // bShowDebugConsole = settings.value(childkey).toBool();
} else if (childkey == "bEnableOverlay") { } else if (childkey == "bEnableOverlay") {
bDrawOverlay = settings.value(childkey).toBool(); bDrawOverlay = settings.value(childkey).toBool();
} else if (childkey == "bEnableControllers") { } else if (childkey == "bEnableControllers") {
bEnableControllers = settings.value(childkey).toBool(); bEnableControllers = settings.value(childkey).toBool();
} /*else if (childkey == "bEnableVsync") { }
bVsync = settings.value(childkey).toBool();
} else if (childkey == "iRefreshRate") {
iRefreshRate = settings.value(childkey).toInt();
}*/
} }
settings.endGroup(); settings.endGroup();
@ -62,12 +58,12 @@ SteamTargetRenderer::SteamTargetRenderer()
sfWindow.setActive(false); sfWindow.setActive(false);
consoleHwnd = GetConsoleWindow(); //We need a console for a dirty hack to make sure we stay in game bindings - Also useful for debugging consoleHwnd = GetConsoleWindow(); //We need a console for a dirty hack to make sure we stay in game bindings - Also useful for debugging
LONG_PTR style = GetWindowLongPtr(consoleHwnd, GWL_STYLE); //LONG_PTR style = GetWindowLongPtr(consoleHwnd, GWL_STYLE);
SetWindowLongPtr(consoleHwnd, GWL_STYLE, style & ~WS_SYSMENU); //SetWindowLongPtr(consoleHwnd, GWL_STYLE, style & ~WS_SYSMENU);
if(!bShowDebugConsole) { /*if(!bShowDebugConsole) {
ShowWindow(consoleHwnd, SW_HIDE); //Hide the console window; it just confuses the user; ShowWindow(consoleHwnd, SW_HIDE); //Hide the console window; it just confuses the user;
} }*/
if (bEnableControllers) if (bEnableControllers)
controllerThread.run(); controllerThread.run();
@ -81,12 +77,15 @@ SteamTargetRenderer::~SteamTargetRenderer()
renderThread.join(); renderThread.join();
if (controllerThread.isRunning()) if (controllerThread.isRunning())
controllerThread.stop(); controllerThread.stop();
qpUserWindow->kill(); //qpUserWindow->kill();
delete qpUserWindow; //delete qpUserWindow;
} }
void SteamTargetRenderer::run() void SteamTargetRenderer::run()
{ {
/*QTimer::singleShot(500, this, [this]() {
focusSwitchNeeded = true;
});*/
renderThread = std::thread(&SteamTargetRenderer::RunSfWindowLoop, this); renderThread = std::thread(&SteamTargetRenderer::RunSfWindowLoop, this);
} }
@ -95,22 +94,25 @@ void SteamTargetRenderer::RunSfWindowLoop()
if (!bRunLoop) if (!bRunLoop)
return; return;
sfWindow.setActive(true); sfWindow.setActive(true);
DWORD result;
bool focusSwitchNeeded = true;
sf::Clock reCheckControllerTimer;
sf::Clock reCheckControllerTimer;
bool focusSwitchNeeded = true;
if (!bDrawOverlay) if (!bDrawOverlay)
{ {
ShowWindow(consoleHwnd, SW_HIDE); ShowWindow(consoleHwnd, SW_HIDE);
} }
while (sfWindow.isOpen() && bRunLoop)
{
if (bDrawOverlay) if (bDrawOverlay)
{ {
SetWindowPos(sfWindow.getSystemHandle(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); SetWindowPos(sfWindow.getSystemHandle(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_ASYNCWINDOWPOS);
} else {
ShowWindow(consoleHwnd, SW_HIDE);
} }
while (sfWindow.isOpen() && bRunLoop)
{
sf::Event event; sf::Event event;
while (sfWindow.pollEvent(event)) while (sfWindow.pollEvent(event))
{ {
@ -133,7 +135,11 @@ void SteamTargetRenderer::RunSfWindowLoop()
{ {
focusSwitchNeeded = false; focusSwitchNeeded = false;
SetFocus(consoleHwnd); SetFocus(consoleHwnd);
SetForegroundWindow(consoleHwnd); sf::Clock clock;
while (!SetForegroundWindow(consoleHwnd) && clock.getElapsedTime().asMilliseconds() < 1000) //try to forcefully set foreground window
{
Sleep(1);
}
} }
//Dirty hack to make the steamoverlay work properly and still keep Apps Controllerconfig when closing overlay. //Dirty hack to make the steamoverlay work properly and still keep Apps Controllerconfig when closing overlay.
@ -149,35 +155,39 @@ void SteamTargetRenderer::RunSfWindowLoop()
hwForeGroundWindow = GetForegroundWindow(); hwForeGroundWindow = GetForegroundWindow();
std::cout << "ForegorundWindow HWND: " << hwForeGroundWindow << std::endl; std::cout << "Saving current ForegorundWindow HWND: " << hwForeGroundWindow << std::endl;
std::cout << "Activating OverlayWindow" << std::endl;
SetFocus(consoleHwnd); SetWindowLong(sfWindow.getSystemHandle(), GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TOOLWINDOW); //make overlay window clickable
SetForegroundWindow(consoleHwnd);
//Actually activate the overlaywindow
SetFocus(sfWindow.getSystemHandle()); SetFocus(sfWindow.getSystemHandle());
SetForegroundWindow(sfWindow.getSystemHandle());
SetWindowLong(sfWindow.getSystemHandle(), GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TOOLWINDOW);
//by activating the consolewindow **and bringing it to the foreground** we can trick steam so the controller stays in game bindings
SetFocus(consoleHwnd); SetFocus(consoleHwnd);
SetForegroundWindow(consoleHwnd); sf::Clock clock;
while (!SetForegroundWindow(consoleHwnd) && clock.getElapsedTime().asMilliseconds() < 1000) //try to forcefully set foreground window
{
Sleep(1);
} }
} }
else { } else {
if (bNeedFocusSwitch) if (bNeedFocusSwitch)
{ {
std::cout << "Deactivating OverlayWindow" << std::endl;
SetFocus(sfWindow.getSystemHandle()); //make overlaywindow clickthrough - WS_EX_TRANSPARENT - again
SetForegroundWindow(sfWindow.getSystemHandle()); SetWindowLong(sfWindow.getSystemHandle(), GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW);
SetWindowLong(sfWindow.getSystemHandle(), GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST | WS_EX_TOOLWINDOW);
SetFocus(consoleHwnd); std::cout << "Switching to previously focused window" << std::endl;
SetForegroundWindow(consoleHwnd);
//switch back the the previosly focused window
SetFocus(hwForeGroundWindow); SetFocus(hwForeGroundWindow);
SetForegroundWindow(hwForeGroundWindow); sf::Clock clock;
while (!SetForegroundWindow(hwForeGroundWindow) && clock.getElapsedTime().asMilliseconds() < 1000) //try to forcefully set foreground window
{
Sleep(1);
}
bNeedFocusSwitch = false; bNeedFocusSwitch = false;
} }
} }
@ -208,7 +218,7 @@ void SteamTargetRenderer::makeSfWindowTransparent(sf::RenderWindow & window)
margins.cxLeftWidth = -1; margins.cxLeftWidth = -1;
DwmExtendFrameIntoClientArea(hwnd, &margins); DwmExtendFrameIntoClientArea(hwnd, &margins);
SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER); SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
window.clear(sf::Color::Transparent); window.clear(sf::Color::Transparent);
window.display(); window.display();
@ -227,25 +237,25 @@ void SteamTargetRenderer::drawDebugEdges()
} }
void SteamTargetRenderer::openUserWindow() //void SteamTargetRenderer::openUserWindow()
{ //{
qpUserWindow = new QProcess(this); // qpUserWindow = new QProcess(this);
qpUserWindow->start("SteamTargetUserWindow.exe", QStringList(), QProcess::ReadWrite); // qpUserWindow->start("SteamTargetUserWindow.exe", QStringList(), QProcess::ReadWrite);
qpUserWindow->waitForStarted(); // qpUserWindow->waitForStarted();
connect(qpUserWindow, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), // connect(qpUserWindow, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
this, &SteamTargetRenderer::userWindowFinished); // this, &SteamTargetRenderer::userWindowFinished);
connect(qpUserWindow, SIGNAL(readyRead()) , this,SLOT(readChildProcess())); // connect(qpUserWindow, SIGNAL(readyRead()) , this,SLOT(readChildProcess()));
} //}
//
void SteamTargetRenderer::userWindowFinished() //void SteamTargetRenderer::userWindowFinished()
{ //{
delete qpUserWindow; // delete qpUserWindow;
bRunLoop = false; // bRunLoop = false;
renderThread.join(); // renderThread.join();
if (controllerThread.isRunning()) // if (controllerThread.isRunning())
controllerThread.stop(); // controllerThread.stop();
exit(0); // exit(0);
} //}
void SteamTargetRenderer::launchApp() void SteamTargetRenderer::launchApp()
{ {
@ -301,59 +311,59 @@ void SteamTargetRenderer::launchApp()
} }
} }
void SteamTargetRenderer::readChildProcess() //void SteamTargetRenderer::readChildProcess()
{ //{
QString message(qpUserWindow->readLine()); // QString message(qpUserWindow->readLine());
if (message.contains("ResetControllers")) // if (message.contains("ResetControllers"))
{ // {
if (controllerThread.isRunning()) // if (controllerThread.isRunning())
{ // {
controllerThread.stop(); // controllerThread.stop();
controllerThread.run(); // controllerThread.run();
} // }
} else if (message.contains("ShowConsole")) { // } else if (message.contains("ShowConsole")) {
message.chop(1); // message.chop(1);
message.remove("ShowConsole "); // message.remove("ShowConsole ");
int showConsole = message.toInt(); // int showConsole = message.toInt();
if (showConsole > 0) // if (showConsole > 0)
{ // {
bShowDebugConsole = true; // bShowDebugConsole = true;
ShowWindow(consoleHwnd, SW_SHOW); // ShowWindow(consoleHwnd, SW_SHOW);
SetFocus(consoleHwnd); // SetFocus(consoleHwnd);
SetForegroundWindow(consoleHwnd); // SetForegroundWindow(consoleHwnd);
} else { // } else {
bShowDebugConsole = false; // bShowDebugConsole = false;
ShowWindow(consoleHwnd, SW_HIDE); // ShowWindow(consoleHwnd, SW_HIDE);
SetFocus(consoleHwnd); // SetFocus(consoleHwnd);
SetForegroundWindow(consoleHwnd); // SetForegroundWindow(consoleHwnd);
} // }
} else if (message.contains("ShowOverlay")) { // } else if (message.contains("ShowOverlay")) {
message.chop(1); // message.chop(1);
message.remove("ShowOverlay "); // message.remove("ShowOverlay ");
int showOverlay = message.toInt(); // int showOverlay = message.toInt();
if (showOverlay > 0) // if (showOverlay > 0)
{ // {
ShowWindow(sfWindow.getSystemHandle(), SW_SHOW); // ShowWindow(sfWindow.getSystemHandle(), SW_SHOW);
SetFocus(consoleHwnd); // SetFocus(consoleHwnd);
SetForegroundWindow(consoleHwnd); // SetForegroundWindow(consoleHwnd);
} else { // } else {
ShowWindow(sfWindow.getSystemHandle(), SW_HIDE); // ShowWindow(sfWindow.getSystemHandle(), SW_HIDE);
SetFocus(consoleHwnd); // SetFocus(consoleHwnd);
SetForegroundWindow(consoleHwnd); // SetForegroundWindow(consoleHwnd);
} // }
} else if (message.contains("EnableControllers")) { // } else if (message.contains("EnableControllers")) {
message.chop(1); // message.chop(1);
message.remove("EnableControllers "); // message.remove("EnableControllers ");
int enableControllers = message.toInt(); // int enableControllers = message.toInt();
if (enableControllers > 0) // if (enableControllers > 0)
{ // {
bEnableControllers = true; // bEnableControllers = true;
if (!controllerThread.isRunning()) // if (!controllerThread.isRunning())
controllerThread.run(); // controllerThread.run();
} else { // } else {
bEnableControllers = false; // bEnableControllers = false;
if (controllerThread.isRunning()) // if (controllerThread.isRunning())
controllerThread.stop(); // controllerThread.stop();
} // }
} // }
} //}

@ -46,18 +46,18 @@ public:
private: private:
bool bRunLoop = true; bool bRunLoop = true;
bool bDrawDebugEdges = false; //TODO: init from .ini ; make default false bool bDrawDebugEdges = false;
bool bDrawOverlay = true; bool bDrawOverlay = true;
bool bVsync = false; bool bVsync = false;
int iRefreshRate = 60; int iRefreshRate = 60;
sf::CircleShape sfCshape; sf::CircleShape sfCshape;
sf::RenderWindow sfWindow; sf::RenderWindow sfWindow;
QProcess *qpUserWindow; //QProcess *qpUserWindow;
std::thread renderThread; std::thread renderThread;
bool bShowDebugConsole = true; //bool bShowDebugConsole = true;
HWND consoleHwnd; HWND consoleHwnd;
HMODULE hmodGameOverlayRenderer; HMODULE hmodGameOverlayRenderer;
@ -74,11 +74,11 @@ private:
void makeSfWindowTransparent(sf::RenderWindow& window); void makeSfWindowTransparent(sf::RenderWindow& window);
void drawDebugEdges(); void drawDebugEdges();
void openUserWindow(); //void openUserWindow();
private slots: private slots:
void userWindowFinished(); //void userWindowFinished();
void launchApp(); void launchApp();
void readChildProcess(); //void readChildProcess();
}; };

Loading…
Cancel
Save