misc
This commit is contained in:
@@ -5,11 +5,6 @@
|
|||||||
// platform includes
|
// platform includes
|
||||||
#include <dxgi1_2.h>
|
#include <dxgi1_2.h>
|
||||||
|
|
||||||
// local includes
|
|
||||||
#include "display.h"
|
|
||||||
#include "misc.h"
|
|
||||||
#include "src/logging.h"
|
|
||||||
|
|
||||||
// Gross hack to work around MINGW-packages#22160
|
// Gross hack to work around MINGW-packages#22160
|
||||||
#define ____FIReference_1_boolean_INTERFACE_DEFINED__
|
#define ____FIReference_1_boolean_INTERFACE_DEFINED__
|
||||||
|
|
||||||
@@ -18,6 +13,11 @@
|
|||||||
#include <winrt/windows.foundation.metadata.h>
|
#include <winrt/windows.foundation.metadata.h>
|
||||||
#include <winrt/windows.graphics.directx.direct3d11.h>
|
#include <winrt/windows.graphics.directx.direct3d11.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "display.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "src/logging.h"
|
||||||
|
|
||||||
namespace platf {
|
namespace platf {
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1744,7 +1744,7 @@ namespace platf {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring from_utf8(const std::string &string) {
|
std::wstring from_utf8(const std::string_view &string) {
|
||||||
// No conversion needed if the string is empty
|
// No conversion needed if the string is empty
|
||||||
if (string.empty()) {
|
if (string.empty()) {
|
||||||
return {};
|
return {};
|
||||||
@@ -1770,7 +1770,7 @@ namespace platf {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string to_utf8(const std::wstring &string) {
|
std::string to_utf8(const std::wstring_view &string) {
|
||||||
// No conversion needed if the string is empty
|
// No conversion needed if the string is empty
|
||||||
if (string.empty()) {
|
if (string.empty()) {
|
||||||
return {};
|
return {};
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ namespace platf {
|
|||||||
* @param string The UTF-8 string.
|
* @param string The UTF-8 string.
|
||||||
* @return The converted UTF-16 wide string.
|
* @return The converted UTF-16 wide string.
|
||||||
*/
|
*/
|
||||||
std::wstring from_utf8(const std::string &string);
|
std::wstring from_utf8(const std::string_view &string);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Convert a UTF-16 wide string into a UTF-8 string.
|
* @brief Convert a UTF-16 wide string into a UTF-8 string.
|
||||||
* @param string The UTF-16 wide string.
|
* @param string The UTF-16 wide string.
|
||||||
* @return The converted UTF-8 string.
|
* @return The converted UTF-8 string.
|
||||||
*/
|
*/
|
||||||
std::string to_utf8(const std::wstring &string);
|
std::string to_utf8(const std::wstring_view &string);
|
||||||
} // namespace platf
|
} // namespace platf
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ using namespace SUDOVDA;
|
|||||||
|
|
||||||
namespace VDISPLAY {
|
namespace VDISPLAY {
|
||||||
// {dff7fd29-5b75-41d1-9731-b32a17a17104}
|
// {dff7fd29-5b75-41d1-9731-b32a17a17104}
|
||||||
static const GUID DEFAULT_DISPLAY_GUID = { 0xdff7fd29, 0x5b75, 0x41d1, { 0x97, 0x31, 0xb3, 0x2a, 0x17, 0xa1, 0x71, 0x04 } };
|
// static const GUID DEFAULT_DISPLAY_GUID = { 0xdff7fd29, 0x5b75, 0x41d1, { 0x97, 0x31, 0xb3, 0x2a, 0x17, 0xa1, 0x71, 0x04 } };
|
||||||
|
|
||||||
HANDLE SUDOVDA_DRIVER_HANDLE = INVALID_HANDLE_VALUE;
|
HANDLE SUDOVDA_DRIVER_HANDLE = INVALID_HANDLE_VALUE;
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ LONG changeDisplaySettings2(const wchar_t* deviceName, int width, int height, in
|
|||||||
sourceName.header.size = sizeof(sourceName);
|
sourceName.header.size = sizeof(sourceName);
|
||||||
sourceName.header.adapterId = pathArray[i].sourceInfo.adapterId;
|
sourceName.header.adapterId = pathArray[i].sourceInfo.adapterId;
|
||||||
sourceName.header.id = pathArray[i].sourceInfo.id;
|
sourceName.header.id = pathArray[i].sourceInfo.id;
|
||||||
bAtVirtualDisplay = false;
|
bAtVirtualDisplay = false;
|
||||||
|
|
||||||
if (DisplayConfigGetDeviceInfo(&sourceName.header) != ERROR_SUCCESS) {
|
if (DisplayConfigGetDeviceInfo(&sourceName.header) != ERROR_SUCCESS) {
|
||||||
continue;
|
continue;
|
||||||
@@ -116,7 +116,7 @@ LONG changeDisplaySettings2(const wchar_t* deviceName, int width, int height, in
|
|||||||
auto* sourceMode = &modeArray[j].sourceMode;
|
auto* sourceMode = &modeArray[j].sourceMode;
|
||||||
|
|
||||||
wprintf(L"[SUDOVDA] Current mode found: [%dx%dx%d]\n", sourceMode->width, sourceMode->height, targetInfo->refreshRate);
|
wprintf(L"[SUDOVDA] Current mode found: [%dx%dx%d]\n", sourceMode->width, sourceMode->height, targetInfo->refreshRate);
|
||||||
|
|
||||||
pCurrentElement = new (struct positionwidthheight);
|
pCurrentElement = new (struct positionwidthheight);
|
||||||
|
|
||||||
pCurrentElement->position.x = modeArray[j].sourceMode.position.x;
|
pCurrentElement->position.x = modeArray[j].sourceMode.position.x;
|
||||||
@@ -152,7 +152,7 @@ LONG changeDisplaySettings2(const wchar_t* deviceName, int width, int height, in
|
|||||||
int xdifference, ydifference = 0;
|
int xdifference, ydifference = 0;
|
||||||
for (iIndex = 0; iIndex < displayArray.size(); iIndex += 1)
|
for (iIndex = 0; iIndex < displayArray.size(); iIndex += 1)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Find the primary display and get the offset to apply to all of the displays to keep the same primary
|
// Find the primary display and get the offset to apply to all of the displays to keep the same primary
|
||||||
if( modeArray[(displayArray[iIndex]->modeindex)].sourceMode.position.x == 0 &&
|
if( modeArray[(displayArray[iIndex]->modeindex)].sourceMode.position.x == 0 &&
|
||||||
modeArray[(displayArray[iIndex]->modeindex)].sourceMode.position.y == 0 )
|
modeArray[(displayArray[iIndex]->modeindex)].sourceMode.position.y == 0 )
|
||||||
@@ -162,7 +162,7 @@ LONG changeDisplaySettings2(const wchar_t* deviceName, int width, int height, in
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set all of the OS Displays to their new locations; Do not change the primary
|
// Set all of the OS Displays to their new locations; Do not change the primary
|
||||||
// Update the real vector for the system call
|
// Update the real vector for the system call
|
||||||
for (iIndex = 0; iIndex < displayArray.size(); iIndex += 1)
|
for (iIndex = 0; iIndex < displayArray.size(); iIndex += 1)
|
||||||
@@ -263,7 +263,7 @@ LONG changeDisplaySettings2(const wchar_t* deviceName, int width, int height, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
LONG changeDisplaySettings(const wchar_t* deviceName, int width, int height, int refresh_rate) {
|
LONG changeDisplaySettings(const wchar_t* deviceName, int width, int height, int refresh_rate) {
|
||||||
DEVMODEW devMode = {0};
|
DEVMODEW devMode = {};
|
||||||
devMode.dmSize = sizeof(devMode);
|
devMode.dmSize = sizeof(devMode);
|
||||||
|
|
||||||
// Old method to set at least baseline refresh rate
|
// Old method to set at least baseline refresh rate
|
||||||
@@ -725,7 +725,7 @@ std::string printAllDisplays(std::vector< struct positionwidthheight*> displays)
|
|||||||
return sOutput;
|
return sOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method for the rearrangeVirtualDisplayForLowerRight() method to move the unknown unconnected display to be connected to the
|
// Helper method for the rearrangeVirtualDisplayForLowerRight() method to move the unknown unconnected display to be connected to the
|
||||||
// second display which is assumed to be already connected
|
// second display which is assumed to be already connected
|
||||||
//
|
//
|
||||||
// It will return the move that the unknown display would need to perform
|
// It will return the move that the unknown display would need to perform
|
||||||
@@ -914,7 +914,7 @@ std::vector < struct coordinates > moveToBeConnected(std::vector < struct coordi
|
|||||||
std::vector< struct positionwidthheight*>rearrangeVirtualDisplayForLowerRight(std::vector< struct positionwidthheight*> displays) {
|
std::vector< struct positionwidthheight*>rearrangeVirtualDisplayForLowerRight(std::vector< struct positionwidthheight*> displays) {
|
||||||
|
|
||||||
// Make a temporary connected List based on the current Displays
|
// Make a temporary connected List based on the current Displays
|
||||||
// Here connected means that the displays are "touching" by either the
|
// Here connected means that the displays are "touching" by either the
|
||||||
// vertical axis or a horizontal axis or a corner.
|
// vertical axis or a horizontal axis or a corner.
|
||||||
int count = displays.size();
|
int count = displays.size();
|
||||||
std::vector< int > vConnected(count, 0);
|
std::vector< int > vConnected(count, 0);
|
||||||
@@ -969,7 +969,7 @@ std::vector< struct positionwidthheight*>rearrangeVirtualDisplayForLowerRight(st
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the location, width and height of the window that is moving
|
// Get the location, width and height of the window that is moving
|
||||||
// Make sure the correct display is set to 0,0.
|
// Make sure the correct display is set to 0,0.
|
||||||
for (int index = 0; index < count; index++) {
|
for (int index = 0; index < count; index++) {
|
||||||
if (index == changeIndex) {
|
if (index == changeIndex) {
|
||||||
@@ -1068,7 +1068,7 @@ std::vector< struct positionwidthheight*>rearrangeVirtualDisplayForLowerRight(st
|
|||||||
// The result of this may not be used as there may be a closer display when we go through the list
|
// The result of this may not be used as there may be a closer display when we go through the list
|
||||||
std::vector < struct coordinates > sToMove = moveToBeConnected(secondboxpoints, connectedboxpoints);
|
std::vector < struct coordinates > sToMove = moveToBeConnected(secondboxpoints, connectedboxpoints);
|
||||||
|
|
||||||
// No movement necessary
|
// No movement necessary
|
||||||
if (sToMove[0].x == 0 && sToMove[0].y == 0) {
|
if (sToMove[0].x == 0 && sToMove[0].y == 0) {
|
||||||
vConnected[secondboxindex] = 1;
|
vConnected[secondboxindex] = 1;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20)
|
|||||||
|
|
||||||
project(sunshine_tools)
|
project(sunshine_tools)
|
||||||
|
|
||||||
include_directories("${CMAKE_SOURCE_DIR}")
|
include_directories(${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
add_executable(dxgi-info dxgi.cpp)
|
add_executable(dxgi-info dxgi.cpp)
|
||||||
set_target_properties(dxgi-info PROPERTIES CXX_STANDARD 20)
|
set_target_properties(dxgi-info PROPERTIES CXX_STANDARD 20)
|
||||||
@@ -12,7 +12,7 @@ target_link_libraries(dxgi-info
|
|||||||
${PLATFORM_LIBRARIES})
|
${PLATFORM_LIBRARIES})
|
||||||
target_compile_options(dxgi-info PRIVATE ${SUNSHINE_COMPILE_OPTIONS})
|
target_compile_options(dxgi-info PRIVATE ${SUNSHINE_COMPILE_OPTIONS})
|
||||||
|
|
||||||
add_executable(audio-info audio.cpp)
|
add_executable(audio-info audio.cpp utils.cpp)
|
||||||
set_target_properties(audio-info PROPERTIES CXX_STANDARD 20)
|
set_target_properties(audio-info PROPERTIES CXX_STANDARD 20)
|
||||||
target_link_libraries(audio-info
|
target_link_libraries(audio-info
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
#define INITGUID
|
#define INITGUID
|
||||||
#include "src/utility.h"
|
#include "src/utility.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <audioclient.h>
|
#include <audioclient.h>
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
@@ -46,8 +47,6 @@ namespace audio {
|
|||||||
|
|
||||||
using handle_t = util::safe_ptr_v2<void, BOOL, CloseHandle>;
|
using handle_t = util::safe_ptr_v2<void, BOOL, CloseHandle>;
|
||||||
|
|
||||||
static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter;
|
|
||||||
|
|
||||||
class prop_var_t {
|
class prop_var_t {
|
||||||
public:
|
public:
|
||||||
prop_var_t() {
|
prop_var_t() {
|
||||||
@@ -206,7 +205,7 @@ namespace audio {
|
|||||||
// so we can take the first match as the current format to display.
|
// so we can take the first match as the current format to display.
|
||||||
auto audio_client = make_audio_client(device, format);
|
auto audio_client = make_audio_client(device, format);
|
||||||
if (audio_client) {
|
if (audio_client) {
|
||||||
current_format = converter.from_bytes(format.name.data());
|
current_format = from_utf8(format.name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
55
tools/utils.cpp
Normal file
55
tools/utils.cpp
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
std::wstring from_utf8(const std::string_view &string) {
|
||||||
|
// No conversion needed if the string is empty
|
||||||
|
if (string.empty()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the output size required to store the string
|
||||||
|
auto output_size = MultiByteToWideChar(CP_UTF8, 0, string.data(), string.size(), nullptr, 0);
|
||||||
|
if (output_size == 0) {
|
||||||
|
// auto winerr = GetLastError();
|
||||||
|
// BOOST_LOG(error) << "Failed to get UTF-16 buffer size: "sv << winerr;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the conversion
|
||||||
|
std::wstring output(output_size, L'\0');
|
||||||
|
output_size = MultiByteToWideChar(CP_UTF8, 0, string.data(), string.size(), output.data(), output.size());
|
||||||
|
if (output_size == 0) {
|
||||||
|
// auto winerr = GetLastError();
|
||||||
|
// BOOST_LOG(error) << "Failed to convert string to UTF-16: "sv << winerr;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string to_utf8(const std::wstring_view &string) {
|
||||||
|
// No conversion needed if the string is empty
|
||||||
|
if (string.empty()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the output size required to store the string
|
||||||
|
auto output_size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string.data(), string.size(), nullptr, 0, nullptr, nullptr);
|
||||||
|
if (output_size == 0) {
|
||||||
|
// auto winerr = GetLastError();
|
||||||
|
// BOOST_LOG(error) << "Failed to get UTF-8 buffer size: "sv << winerr;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the conversion
|
||||||
|
std::string output(output_size, '\0');
|
||||||
|
output_size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string.data(), string.size(), output.data(), output.size(), nullptr, nullptr);
|
||||||
|
if (output_size == 0) {
|
||||||
|
// auto winerr = GetLastError();
|
||||||
|
// BOOST_LOG(error) << "Failed to convert string to UTF-8: "sv << winerr;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
15
tools/utils.h
Normal file
15
tools/utils.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#include <string>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert a UTF-8 string into a UTF-16 wide string.
|
||||||
|
* @param string The UTF-8 string.
|
||||||
|
* @return The converted UTF-16 wide string.
|
||||||
|
*/
|
||||||
|
std::wstring from_utf8(const std::string_view &string);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert a UTF-16 wide string into a UTF-8 string.
|
||||||
|
* @param string The UTF-16 wide string.
|
||||||
|
* @return The converted UTF-8 string.
|
||||||
|
*/
|
||||||
|
std::string to_utf8(const std::wstring_view &string);
|
||||||
Reference in New Issue
Block a user