diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index 321caa61..b2a49c5b 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -2287,6 +2287,14 @@ AdvSceneSwitcher.tempVar.scene.position="Position in scenes list" AdvSceneSwitcher.tempVar.window.window="Window title" AdvSceneSwitcher.tempVar.window.window.description="The window title of the matching window." +AdvSceneSwitcher.tempVar.window.windowX="Window X position" +AdvSceneSwitcher.tempVar.window.windowX.description="The X position (left edge) of the matching window in screen coordinates." +AdvSceneSwitcher.tempVar.window.windowY="Window Y position" +AdvSceneSwitcher.tempVar.window.windowY.description="The Y position (top edge) of the matching window in screen coordinates." +AdvSceneSwitcher.tempVar.window.windowWidth="Window width" +AdvSceneSwitcher.tempVar.window.windowWidth.description="The width of the matching window in pixels." +AdvSceneSwitcher.tempVar.window.windowHeight="Window height" +AdvSceneSwitcher.tempVar.window.windowHeight.description="The height of the matching window in pixels." AdvSceneSwitcher.tempVar.window.windowClass="Window class" AdvSceneSwitcher.tempVar.window.windowClass.description="The window class of the matching window." AdvSceneSwitcher.tempVar.window.windowText="Window text" diff --git a/lib/linux/advanced-scene-switcher-nix.cpp b/lib/linux/advanced-scene-switcher-nix.cpp index 665f3d31..b7afa73f 100644 --- a/lib/linux/advanced-scene-switcher-nix.cpp +++ b/lib/linux/advanced-scene-switcher-nix.cpp @@ -352,6 +352,41 @@ std::optional GetTextInWindow(const std::string &) return {}; } +std::optional GetWindowGeometry(const std::string &title) +{ + auto display = disp(); + if (!display) { + return {}; + } + + for (auto window : getTopLevelWindows()) { + if (getWindowName(window) != title) { + continue; + } + + XWindowAttributes attrs; + if (!XGetWindowAttributes(display, window, &attrs)) { + return {}; + } + + int x = 0; + int y = 0; + Window child; + XTranslateCoordinates(display, window, + DefaultRootWindow(display), 0, 0, &x, &y, + &child); + + WindowGeometry geo; + geo.x = x; + geo.y = y; + geo.width = attrs.width; + geo.height = attrs.height; + return geo; + } + + return {}; +} + static void getProcessListProcps(QStringList &processes) { #ifdef PROCPS_AVAILABLE diff --git a/lib/platform-funcs.hpp b/lib/platform-funcs.hpp index 6d024a2e..620d07f0 100644 --- a/lib/platform-funcs.hpp +++ b/lib/platform-funcs.hpp @@ -11,11 +11,20 @@ namespace advss { enum class HotkeyType; +struct WindowGeometry { + int x = 0; + int y = 0; + int width = 0; + int height = 0; +}; + EXPORT std::vector GetWindowList(); EXPORT std::string GetCurrentWindowTitle(); EXPORT bool IsFullscreen(const std::string &title); EXPORT bool IsMaximized(const std::string &title); EXPORT std::optional GetTextInWindow(const std::string &window); +EXPORT std::optional +GetWindowGeometry(const std::string &title); EXPORT int SecondsSinceLastInput(); EXPORT QStringList GetProcessList(); EXPORT std::string GetForegroundProcessName(); diff --git a/lib/win/advanced-scene-switcher-win.cpp b/lib/win/advanced-scene-switcher-win.cpp index 530a3c05..4359f70f 100644 --- a/lib/win/advanced-scene-switcher-win.cpp +++ b/lib/win/advanced-scene-switcher-win.cpp @@ -345,6 +345,26 @@ bool IsFullscreen(const std::string &title) return false; } +std::optional GetWindowGeometry(const std::string &title) +{ + HWND hwnd = getHWNDfromTitle(title); + if (!hwnd) { + return {}; + } + + RECT rect; + if (!GetWindowRect(hwnd, &rect)) { + return {}; + } + + WindowGeometry geo; + geo.x = rect.left; + geo.y = rect.top; + geo.width = rect.right - rect.left; + geo.height = rect.bottom - rect.top; + return geo; +} + QStringList GetProcessList() { QStringList processes; diff --git a/plugins/base/macro-condition-window.cpp b/plugins/base/macro-condition-window.cpp index 37d72023..70fcbaa7 100644 --- a/plugins/base/macro-condition-window.cpp +++ b/plugins/base/macro-condition-window.cpp @@ -107,6 +107,15 @@ void MacroConditionWindow::SetVariableValueBasedOnMatch( const std::string &matchWindow) { SetTempVarValue("window", matchWindow); + + const auto geo = GetWindowGeometry(matchWindow); + if (geo) { + SetTempVarValue("windowX", std::to_string(geo->x)); + SetTempVarValue("windowY", std::to_string(geo->y)); + SetTempVarValue("windowWidth", std::to_string(geo->width)); + SetTempVarValue("windowHeight", std::to_string(geo->height)); + } + #ifdef _WIN32 SetTempVarValue("windowClass", GetWindowClassByWindowTitle(matchWindow)); @@ -201,6 +210,26 @@ void MacroConditionWindow::SetupTempVars() obs_module_text("AdvSceneSwitcher.tempVar.window.window"), obs_module_text( "AdvSceneSwitcher.tempVar.window.window.description")); + AddTempvar( + "windowX", + obs_module_text("AdvSceneSwitcher.tempVar.window.windowX"), + obs_module_text( + "AdvSceneSwitcher.tempVar.window.windowX.description")); + AddTempvar( + "windowY", + obs_module_text("AdvSceneSwitcher.tempVar.window.windowY"), + obs_module_text( + "AdvSceneSwitcher.tempVar.window.windowY.description")); + AddTempvar( + "windowWidth", + obs_module_text("AdvSceneSwitcher.tempVar.window.windowWidth"), + obs_module_text( + "AdvSceneSwitcher.tempVar.window.windowWidth.description")); + AddTempvar( + "windowHeight", + obs_module_text("AdvSceneSwitcher.tempVar.window.windowHeight"), + obs_module_text( + "AdvSceneSwitcher.tempVar.window.windowHeight.description")); #ifdef _WIN32 AddTempvar( "windowClass",