add function to fetch left/right/top/bottom/rotation.
This commit is contained in:
@@ -9,6 +9,8 @@ public class MultipleMonitorCreator : MonoBehaviour
|
||||
void Start()
|
||||
{
|
||||
var monitors = uDesktopDuplication.Manager.monitors;
|
||||
monitors.Sort((a, b) => a.left - b.left);
|
||||
|
||||
var n = monitors.Count;
|
||||
|
||||
var totalWidth = 0f;
|
||||
@@ -24,6 +26,7 @@ public class MultipleMonitorCreator : MonoBehaviour
|
||||
totalWidth += width * scaleX;
|
||||
}
|
||||
|
||||
|
||||
totalWidth += margin * (n - 1);
|
||||
var x = -totalWidth / 2;
|
||||
for (int i = 0 ; i < n; ++i) {
|
||||
|
||||
Binary file not shown.
@@ -18,6 +18,15 @@ public enum CursorShapeType
|
||||
MaskedColor = 4,
|
||||
}
|
||||
|
||||
public enum MonitorRotation
|
||||
{
|
||||
Unspecified = 0,
|
||||
Identity = 1,
|
||||
Rotate90 = 2,
|
||||
Rotate180 = 3,
|
||||
Rotate270 = 4
|
||||
}
|
||||
|
||||
public static class Lib
|
||||
{
|
||||
public delegate void MessageHandler(Message message);
|
||||
@@ -33,16 +42,30 @@ public static class Lib
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetMonitorCount();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetTotalWidth();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetTotalHeight();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void SetTimeout(int timeout);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern IntPtr GetRenderEventFunc();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void GetName(int id, StringBuilder buf, int len);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetLeft(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetRight(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetTop(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetBottom(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetWidth(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetHeight(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern MonitorRotation GetRotation(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern bool IsPrimary(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern bool IsCursorVisible(int id);
|
||||
|
||||
@@ -31,6 +31,26 @@ public class Monitor
|
||||
get { return Lib.IsPrimary(id); }
|
||||
}
|
||||
|
||||
public int left
|
||||
{
|
||||
get { return Lib.GetLeft(id); }
|
||||
}
|
||||
|
||||
public int right
|
||||
{
|
||||
get { return Lib.GetRight(id); }
|
||||
}
|
||||
|
||||
public int top
|
||||
{
|
||||
get { return Lib.GetTop(id); }
|
||||
}
|
||||
|
||||
public int bottom
|
||||
{
|
||||
get { return Lib.GetBottom(id); }
|
||||
}
|
||||
|
||||
public int width
|
||||
{
|
||||
get { return Lib.GetWidth(id); }
|
||||
@@ -41,6 +61,11 @@ public class Monitor
|
||||
get { return Lib.GetHeight(id); }
|
||||
}
|
||||
|
||||
public MonitorRotation rotation
|
||||
{
|
||||
get { return Lib.GetRotation(id); }
|
||||
}
|
||||
|
||||
public float aspect
|
||||
{
|
||||
get { return (float)width / height; }
|
||||
|
||||
@@ -52,6 +52,7 @@ public class Texture : MonoBehaviour
|
||||
{
|
||||
monitor.shouldBeUpdated = true;
|
||||
UpdateMaterial();
|
||||
Debug.Log(Lib.GetTotalWidth() + " " + Lib.GetTotalHeight());
|
||||
}
|
||||
|
||||
void UpdateMaterial()
|
||||
|
||||
@@ -49,9 +49,9 @@ Pass
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma shader_feature ___ INVERT_X
|
||||
#pragma shader_feature ___ INVERT_Y
|
||||
#pragma shader_feature ___ VERTICAL
|
||||
#pragma multi_compile ___ INVERT_X
|
||||
#pragma multi_compile ___ INVERT_Y
|
||||
#pragma multi_compile ___ VERTICAL
|
||||
#pragma shader_feature ___ USE_BEND
|
||||
ENDCG
|
||||
}
|
||||
|
||||
@@ -141,6 +141,36 @@ bool Monitor::IsPrimary() const
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetLeft() const
|
||||
{
|
||||
return outputDesc_.DesktopCoordinates.left;
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetRight() const
|
||||
{
|
||||
return outputDesc_.DesktopCoordinates.right;
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetTop() const
|
||||
{
|
||||
return outputDesc_.DesktopCoordinates.top;
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetBottom() const
|
||||
{
|
||||
return outputDesc_.DesktopCoordinates.bottom;
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetRotation() const
|
||||
{
|
||||
return static_cast<int>(outputDesc_.Rotation);
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetWidth() const
|
||||
{
|
||||
const auto rect = monitorInfo_.rcMonitor;
|
||||
|
||||
@@ -18,8 +18,13 @@ public:
|
||||
ID3D11Texture2D* GetUnityTexture() const;
|
||||
void GetName(char* buf, int len) const;
|
||||
bool IsPrimary() const;
|
||||
int GetLeft() const;
|
||||
int GetRight() const;
|
||||
int GetTop() const;
|
||||
int GetBottom() const;
|
||||
int GetWidth() const;
|
||||
int GetHeight() const;
|
||||
int GetRotation() const;
|
||||
IDXGIOutputDuplication* GetDeskDupl();
|
||||
const std::unique_ptr<Cursor>& GetCursor();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <dxgi1_2.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
#include "IUnityInterface.h"
|
||||
#include "IUnityGraphicsD3D11.h"
|
||||
@@ -129,6 +130,32 @@ int MonitorManager::GetMonitorCount() const
|
||||
return static_cast<int>(monitors_.size());
|
||||
}
|
||||
|
||||
int MonitorManager::GetTotalWidth() const
|
||||
{
|
||||
std::vector<int> lefts, rights;
|
||||
for (const auto& monitor : monitors_)
|
||||
{
|
||||
lefts.push_back(monitor->GetLeft());
|
||||
rights.push_back(monitor->GetRight());
|
||||
}
|
||||
const auto minLeft = *std::min_element(lefts.begin(), lefts.end());
|
||||
const auto maxRight = *std::max_element(rights.begin(), rights.end());
|
||||
return maxRight - minLeft;
|
||||
}
|
||||
|
||||
int MonitorManager::GetTotalHeight() const
|
||||
{
|
||||
std::vector<int> tops, bottoms;
|
||||
for (const auto& monitor : monitors_)
|
||||
{
|
||||
tops.push_back(monitor->GetTop());
|
||||
bottoms.push_back(monitor->GetBottom());
|
||||
}
|
||||
const auto minTop = *std::min_element(tops.begin(), tops.end());
|
||||
const auto maxBottom = *std::max_element(bottoms.begin(), bottoms.end());
|
||||
return maxBottom - minTop;
|
||||
}
|
||||
|
||||
|
||||
void MonitorManager::GetName(int id, char* buf, int len) const
|
||||
{
|
||||
@@ -149,6 +176,46 @@ bool MonitorManager::IsPrimary(int id) const
|
||||
}
|
||||
|
||||
|
||||
int MonitorManager::GetLeft(int id) const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
{
|
||||
return monitor->GetLeft();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int MonitorManager::GetRight(int id) const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
{
|
||||
return monitor->GetRight();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int MonitorManager::GetTop(int id) const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
{
|
||||
return monitor->GetTop();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int MonitorManager::GetBottom(int id) const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
{
|
||||
return monitor->GetBottom();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int MonitorManager::GetWidth(int id) const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
@@ -169,6 +236,16 @@ int MonitorManager::GetHeight(int id) const
|
||||
}
|
||||
|
||||
|
||||
int MonitorManager::GetRotation(int id) const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
{
|
||||
return monitor->GetRotation();
|
||||
}
|
||||
return DXGI_MODE_ROTATION_UNSPECIFIED;
|
||||
}
|
||||
|
||||
|
||||
bool MonitorManager::IsCursorVisible(int id) const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
|
||||
@@ -36,10 +36,17 @@ public:
|
||||
// Getters from Unity
|
||||
public:
|
||||
int GetMonitorCount() const;
|
||||
int GetTotalWidth() const;
|
||||
int GetTotalHeight() const;
|
||||
void GetName(int id, char* buf, int len) const;
|
||||
bool IsPrimary(int id) const;
|
||||
int GetLeft(int id) const;
|
||||
int GetRight(int id) const;
|
||||
int GetTop(int id) const;
|
||||
int GetBottom(int id) const;
|
||||
int GetWidth(int id) const;
|
||||
int GetHeight(int id) const;
|
||||
int GetRotation(int id) const;
|
||||
bool IsCursorVisible(int id) const;
|
||||
int GetCursorX(int id) const;
|
||||
int GetCursorY(int id) const;
|
||||
|
||||
@@ -106,6 +106,18 @@ extern "C"
|
||||
return g_manager->GetMonitorCount();
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetTotalWidth()
|
||||
{
|
||||
if (!g_manager) return 0;
|
||||
return g_manager->GetTotalWidth();
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetTotalHeight()
|
||||
{
|
||||
if (!g_manager) return 0;
|
||||
return g_manager->GetTotalHeight();
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetTimeout(int timeout)
|
||||
{
|
||||
if (!g_manager) return;
|
||||
@@ -124,6 +136,30 @@ extern "C"
|
||||
return g_manager->IsPrimary(id);
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetLeft(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetLeft(id);
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetRight(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetRight(id);
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetTop(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetTop(id);
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetBottom(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetBottom(id);
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetWidth(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
@@ -136,6 +172,12 @@ extern "C"
|
||||
return g_manager->GetHeight(id);
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetRotation(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetRotation(id);
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT bool UNITY_INTERFACE_API IsCursorVisible(int id)
|
||||
{
|
||||
if (!g_manager) return false;
|
||||
|
||||
Reference in New Issue
Block a user