mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-05 18:42:29 +01:00
Fix godot wallpaper setuip
This commit is contained in:
parent
067b953526
commit
6e4d34c7b0
@ -56,13 +56,17 @@ void ScreenPlayGodotWallpaper::hideFromTaskbar(HWND hwnd)
|
||||
|
||||
bool ScreenPlayGodotWallpaper::configureWindowGeometry()
|
||||
{
|
||||
if (!m_windowsIntegration->searchWorkerWindowToParentTo()) {
|
||||
if (!m_windowsIntegration.searchWorkerWindowToParentTo()) {
|
||||
UtilityFunctions::print("No worker window found");
|
||||
return false;
|
||||
}
|
||||
if (!IsWindow(m_windowsIntegration.windowHandleWorker())) {
|
||||
UtilityFunctions::print("Could not get a valid window handle worker!");
|
||||
return false;
|
||||
}
|
||||
// WARNING: Setting Window flags must be called *here*!
|
||||
SetWindowLongPtr(m_windowsIntegration->windowHandle(), GWL_EXSTYLE, WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT);
|
||||
SetWindowLongPtr(m_windowsIntegration->windowHandle(), GWL_STYLE, WS_POPUPWINDOW);
|
||||
SetWindowLongPtr(m_windowsIntegration.windowHandle(), GWL_EXSTYLE, WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT);
|
||||
SetWindowLongPtr(m_windowsIntegration.windowHandle(), GWL_STYLE, WS_POPUPWINDOW);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -70,28 +74,65 @@ bool ScreenPlayGodotWallpaper::configureWindowGeometry()
|
||||
bool ScreenPlayGodotWallpaper::init(int activeScreen)
|
||||
{
|
||||
auto* displayServer = DisplayServer::get_singleton();
|
||||
int64_t handle_int = displayServer->window_get_native_handle(godot::DisplayServer::HandleType::WINDOW_HANDLE, activeScreen);
|
||||
HWND hwnd = reinterpret_cast<HWND>(static_cast<intptr_t>(handle_int));
|
||||
m_windowsIntegration = std::make_unique<WindowsIntegration>();
|
||||
m_windowsIntegration->setWindowHandle(hwnd);
|
||||
hideFromTaskbar(hwnd);
|
||||
{
|
||||
int64_t handle_int = displayServer->window_get_native_handle(godot::DisplayServer::HandleType::WINDOW_HANDLE, activeScreen);
|
||||
HWND hwnd = reinterpret_cast<HWND>(static_cast<intptr_t>(handle_int));
|
||||
m_windowsIntegration.setWindowHandle(hwnd);
|
||||
}
|
||||
hideFromTaskbar(m_windowsIntegration.windowHandle());
|
||||
|
||||
if (!configureWindowGeometry()) {
|
||||
return false;
|
||||
}
|
||||
ShowWindow(m_windowsIntegration->windowHandle(), SW_HIDE);
|
||||
ShowWindow(m_windowsIntegration.windowHandle(), SW_HIDE);
|
||||
|
||||
WindowsIntegration windowsIntegration;
|
||||
auto updateWindowSize = [&displayServer](const int width, const int height) {
|
||||
displayServer->window_set_size(godot::Vector2((real_t)width, (real_t)height));
|
||||
};
|
||||
|
||||
const std::optional<Monitor> monitor = windowsIntegration.setupWallpaperForOneScreen(activeScreen, updateWindowSize);
|
||||
if (!monitor.has_value())
|
||||
WindowsIntegration::MonitorResult monitor = m_windowsIntegration.setupWallpaperForOneScreen(activeScreen, updateWindowSize);
|
||||
if (monitor.status != WindowsIntegration::MonitorResultStatus::Ok) {
|
||||
UtilityFunctions::print("setupWallpaperForOneScreen failed status: ", (int)monitor.status);
|
||||
return false;
|
||||
}
|
||||
displayServer->window_set_size(godot::Vector2((real_t)monitor.monitor->size.cx, (real_t)monitor.monitor->size.cy));
|
||||
|
||||
const std::string windowTitle = "ScreenPlayWallpaperGodot";
|
||||
SetWindowText(hwnd, windowTitle.c_str());
|
||||
ShowWindow(m_windowsIntegration->windowHandle(), SW_SHOW);
|
||||
SetWindowText(m_windowsIntegration.windowHandle(), windowTitle.c_str());
|
||||
ShowWindow(m_windowsIntegration.windowHandle(), SW_SHOW);
|
||||
|
||||
m_windowsIntegration.setupWindowMouseHook();
|
||||
// Set up the mouse event handler
|
||||
m_windowsIntegration.setMouseEventHandler([this](DWORD mouseButton, UINT type, POINT p) {
|
||||
Ref<InputEventMouseButton> mouse_event;
|
||||
Ref<InputEventMouseMotion> motion_event;
|
||||
switch (type) {
|
||||
case WM_LBUTTONDOWN:
|
||||
case WM_LBUTTONUP:
|
||||
case WM_RBUTTONDOWN:
|
||||
case WM_RBUTTONUP:
|
||||
mouse_event.instantiate();
|
||||
mouse_event->set_position(Vector2(p.x, p.y));
|
||||
mouse_event->set_global_position(Vector2(p.x, p.y)); // Assuming global == local for this context
|
||||
mouse_event->set_button_index(
|
||||
type == WM_LBUTTONDOWN || type == WM_LBUTTONUP ? MOUSE_BUTTON_LEFT : MOUSE_BUTTON_RIGHT);
|
||||
mouse_event->set_pressed(type == WM_LBUTTONDOWN || type == WM_RBUTTONDOWN);
|
||||
break;
|
||||
case WM_MOUSEMOVE:
|
||||
motion_event.instantiate();
|
||||
motion_event->set_position(Vector2(p.x, p.y));
|
||||
motion_event->set_global_position(Vector2(p.x, p.y));
|
||||
break;
|
||||
// Add more cases as needed
|
||||
}
|
||||
|
||||
if (mouse_event.is_valid()) {
|
||||
get_tree()->get_root()->get_viewport()->push_input(mouse_event);
|
||||
}
|
||||
if (motion_event.is_valid()) {
|
||||
get_tree()->get_root()->get_viewport()->push_input(motion_event);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -197,15 +238,13 @@ bool ScreenPlayGodotWallpaper::exit()
|
||||
{
|
||||
// Somehow this gets called at editor startup
|
||||
// so just return if not initialized
|
||||
if (m_windowsIntegration) {
|
||||
|
||||
ShowWindow(m_windowsIntegration->windowHandle(), SW_HIDE);
|
||||
ShowWindow(m_windowsIntegration.windowHandle(), SW_HIDE);
|
||||
|
||||
// Force refresh so that we display the regular
|
||||
// desktop wallpaper again
|
||||
ShowWindow(m_windowsIntegration->windowHandleWorker(), SW_SHOW);
|
||||
ShowWindow(m_windowsIntegration->windowHandleWorker(), SW_HIDE);
|
||||
}
|
||||
// Force refresh so that we display the regular
|
||||
// desktop wallpaper again
|
||||
ShowWindow(m_windowsIntegration.windowHandleWorker(), SW_SHOW);
|
||||
ShowWindow(m_windowsIntegration.windowHandleWorker(), SW_HIDE);
|
||||
return true;
|
||||
}
|
||||
bool ScreenPlayGodotWallpaper::get_checkWallpaperVisible() const
|
||||
|
@ -6,11 +6,19 @@
|
||||
#endif
|
||||
|
||||
#include "godot_cpp/classes/control.hpp"
|
||||
#include "godot_cpp/classes/engine.hpp"
|
||||
#include "godot_cpp/classes/global_constants.hpp"
|
||||
#include "godot_cpp/classes/input_event_key.hpp"
|
||||
#include "godot_cpp/classes/input_event_mouse_button.hpp"
|
||||
#include "godot_cpp/classes/input_event_mouse_motion.hpp"
|
||||
#include "godot_cpp/classes/node.hpp"
|
||||
#include "godot_cpp/classes/scene_tree.hpp"
|
||||
#include "godot_cpp/classes/timer.hpp"
|
||||
#include "godot_cpp/classes/viewport.hpp"
|
||||
#include "godot_cpp/classes/window.hpp"
|
||||
#include "godot_cpp/core/binder_common.hpp"
|
||||
#include "godot_cpp/variant/string.hpp"
|
||||
#include "godot_cpp/variant/vector2.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@ -62,7 +70,7 @@ private:
|
||||
|
||||
godot::String m_appID = "";
|
||||
godot::String m_projectPath = "";
|
||||
std::unique_ptr<WindowsIntegration> m_windowsIntegration;
|
||||
WindowsIntegration m_windowsIntegration;
|
||||
double m_timesinceLastRead = 0.0;
|
||||
bool m_pipeConnected = false;
|
||||
bool m_screenPlayConnected = false;
|
||||
|
@ -43,26 +43,6 @@ float WindowsIntegration::getScaling(const int monitorIndex) const
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns true of at least one monitor has active scaling enabled.
|
||||
*/
|
||||
bool WindowsIntegration::hasWindowScaling() const
|
||||
{
|
||||
auto enumMonitorCallback = [](HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) -> BOOL {
|
||||
int scaling = GetDeviceCaps(hdcMonitor, LOGPIXELSX) / 96;
|
||||
if (scaling != 1) {
|
||||
*(bool*)dwData = true;
|
||||
return false; // Stop enumeration
|
||||
}
|
||||
return true; // Continue enumeration
|
||||
};
|
||||
|
||||
bool hasScaling = false;
|
||||
EnumDisplayMonitors(NULL, NULL, enumMonitorCallback, (LPARAM)&hasScaling);
|
||||
|
||||
return hasScaling;
|
||||
}
|
||||
|
||||
bool WindowsIntegration::searchWorkerWindowToParentTo()
|
||||
{
|
||||
HWND progman_hwnd = FindWindowW(L"Progman", L"Program Manager");
|
||||
@ -158,8 +138,18 @@ bool WindowsIntegration::checkForFullScreenWindow(HWND windowHandle)
|
||||
* scale factors.
|
||||
*/
|
||||
|
||||
std::optional<Monitor> WindowsIntegration::setupWallpaperForOneScreen(const int activeScreen, std::function<void(int, int)> updateWindowSize)
|
||||
WindowsIntegration::MonitorResult WindowsIntegration::setupWallpaperForOneScreen(const int activeScreen, std::function<void(int, int)> updateWindowSize)
|
||||
{
|
||||
if (!IsWindow(m_windowHandle)) {
|
||||
std::cout << "Could not get a valid window handle !";
|
||||
return { std::nullopt, MonitorResultStatus::WindowHandleInvalidError };
|
||||
}
|
||||
|
||||
if (!IsWindow(m_windowHandleWorker)) {
|
||||
std::cout << "Could not get a valid window handle wroker!";
|
||||
return { std::nullopt, MonitorResultStatus::WorkerWindowHandleInvalidError };
|
||||
}
|
||||
|
||||
std::vector<Monitor> monitors = GetAllMonitors();
|
||||
for (const auto& monitor : monitors) {
|
||||
monitor.print();
|
||||
@ -197,9 +187,9 @@ std::optional<Monitor> WindowsIntegration::setupWallpaperForOneScreen(const int
|
||||
std::cout << "Calculated New Size: (" << newWidth << "x" << newHeight << ")" << std::endl;
|
||||
|
||||
SetWindowPos(m_windowHandle, NULL, newX, newY, newWidth, newHeight, SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
return { monitor };
|
||||
return { monitor, MonitorResultStatus::Ok };
|
||||
}
|
||||
return std::nullopt;
|
||||
return { std::nullopt, MonitorResultStatus::MonitorIterationError };
|
||||
}
|
||||
/**
|
||||
* Spans the window across multiple monitors.
|
||||
@ -341,11 +331,6 @@ void WindowsIntegration::setWindowHandle(HWND windowHandle)
|
||||
m_windowHandle = windowHandle;
|
||||
}
|
||||
|
||||
void WindowsIntegration::setWindowHandleWorker(HWND windowHandleWorker)
|
||||
{
|
||||
m_windowHandleWorker = windowHandleWorker;
|
||||
}
|
||||
|
||||
BOOL GetMonitorByHandle(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
|
||||
{
|
||||
|
||||
|
@ -83,11 +83,10 @@ struct sEnumInfo {
|
||||
HMONITOR hMonitor;
|
||||
};
|
||||
|
||||
// Define the type for the mouse event handler function
|
||||
using MouseEventHandler = std::function<void(DWORD mouseButton, UINT type, POINT p)>;
|
||||
static MouseEventHandler m_mouseEventHandler;
|
||||
static HHOOK m_mouseHook;
|
||||
// Define a callback type for keyboard events
|
||||
|
||||
typedef std::function<void(UINT vkCode, bool keyDown)> KeyboardEventHandler;
|
||||
static HHOOK m_keyboardHook;
|
||||
static KeyboardEventHandler m_keyboardEventHandler;
|
||||
@ -99,21 +98,28 @@ public:
|
||||
int height = 0;
|
||||
bool success = false;
|
||||
};
|
||||
enum class MonitorResultStatus {
|
||||
Ok,
|
||||
WindowHandleInvalidError,
|
||||
WorkerWindowHandleInvalidError,
|
||||
MonitorIterationError,
|
||||
};
|
||||
struct MonitorResult {
|
||||
std::optional<Monitor> monitor;
|
||||
MonitorResultStatus status = MonitorResultStatus::Ok;
|
||||
};
|
||||
|
||||
bool searchWorkerWindowToParentTo();
|
||||
float getScaling(const int monitorIndex) const;
|
||||
bool hasWindowScaling() const;
|
||||
std::vector<Monitor> GetAllMonitors();
|
||||
int GetMonitorIndex(HMONITOR hMonitor);
|
||||
bool checkForFullScreenWindow(HWND windowHandle);
|
||||
std::optional<Monitor> setupWallpaperForOneScreen(const int activeScreen, std::function<void(int, int)> updateWindowSize);
|
||||
WindowsIntegration::MonitorResult setupWallpaperForOneScreen(const int activeScreen, std::function<void(int, int)> updateWindowSize);
|
||||
SpanResult setupWallpaperForMultipleScreens(const std::vector<int>& activeScreens);
|
||||
SpanResult setupWallpaperForAllScreens();
|
||||
HWND windowHandle() const;
|
||||
HWND windowHandleWorker() const;
|
||||
void setWindowHandle(HWND windowHandle);
|
||||
void setWindowHandleWorker(HWND windowHandleWorker);
|
||||
|
||||
void setupWindowMouseHook();
|
||||
void unhookMouse();
|
||||
void setMouseEventHandler(MouseEventHandler handler);
|
||||
|
@ -3,8 +3,6 @@
|
||||
#include "windowsintegration.h"
|
||||
#include <QGuiApplication>
|
||||
#include <QtQml>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <shellscalingapi.h>
|
||||
#include <vector>
|
||||
#include <windows.h>
|
||||
@ -171,7 +169,7 @@ void WinWindow::setupWallpaperForOneScreen(int activeScreen)
|
||||
m_window.setWidth(width);
|
||||
m_window.setHeight(height);
|
||||
};
|
||||
std::optional<Monitor> monitor = m_windowsIntegration.setupWallpaperForOneScreen(activeScreen, updateWindowSize);
|
||||
WindowsIntegration::MonitorResult monitor = m_windowsIntegration.setupWallpaperForOneScreen(activeScreen, updateWindowSize);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -115,8 +115,9 @@ def main():
|
||||
vcpkg_path = project_source_parent_path.joinpath("vcpkg").resolve()
|
||||
vcpkg_packages_list = defines.VCPKG_BASE_PACKAGES
|
||||
|
||||
if not setup_godot.execute():
|
||||
raise RuntimeError("Unable to download godot")
|
||||
if system() == "Windows":
|
||||
if not setup_godot.execute():
|
||||
raise RuntimeError("Unable to download godot")
|
||||
|
||||
if not download_ffmpeg.execute():
|
||||
raise RuntimeError("Unable to download ffmpeg")
|
||||
|
Loading…
Reference in New Issue
Block a user