From 566633d2033c02ab2e08ca20c35e1a17e38c3066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mon=20ou=C3=AFe?= Date: Fri, 1 Dec 2023 10:32:46 +0100 Subject: Move code to update the overlay title to a separate function --- src/main.cpp | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index f1fea64..4e1f7e2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -220,6 +220,8 @@ public: void RenderCompanionWindow(); void RenderScene( vr::Hmd_Eye nEye ); + void UpdateOverlayTitle(); + glm::mat4 GetHMDMatrixProjectionEye( vr::Hmd_Eye nEye ); glm::mat4 GetHMDMatrixPoseEye( vr::Hmd_Eye nEye ); glm::mat4 GetCurrentViewProjectionMatrix( vr::Hmd_Eye nEye ); @@ -1502,22 +1504,7 @@ bool CMainApplication::HandleInput() vr::HmdVector2_t scale = {(float)window_width, (float)window_height}; vr::VROverlay()->SetOverlayMouseScale(overlay_handle, &scale); - unsigned char *name = nullptr; - int name_len = 0; - int name_type = 0; - xdo_get_window_name(overlay_xdo, src_window_id, - &name, &name_len, &name_type); - - if (name && name_len > 0) { - std::string name_str; - name_str.resize(name_len); - for (int i = 0; i < name_len; i++) - name_str[i] = name[i]; - - vr::VROverlay()->SetOverlayName(overlay_handle, name_str.c_str()); - } - - XFree(name); + UpdateOverlayTitle(); unsigned long offset = 0; unsigned long best_offset = (unsigned long)-1; @@ -3005,6 +2992,27 @@ void CMainApplication::RenderCompanionWindow() } +//----------------------------------------------------------------------------- +// Purpose: Copy the title of the source X11 window as the overlay title +//----------------------------------------------------------------------------- +void CMainApplication::UpdateOverlayTitle() { + unsigned char *name = nullptr; + int name_len = 0; + int name_type = 0; + xdo_get_window_name(overlay_xdo, src_window_id, + &name, &name_len, &name_type); + + if (!name) return; + + std::string name_str; + name_str.resize(name_len); + for (int i = 0; i < name_len; i++) + name_str[i] = name[i]; + + vr::VROverlay()->SetOverlayName(overlay_handle, name_str.c_str()); + XFree(name); +} + //----------------------------------------------------------------------------- // Purpose: Gets a Matrix Projection Eye with respect to nEye. //----------------------------------------------------------------------------- -- cgit v1.2.3