Skip to content

Commit 94f6934

Browse files
committed
fix window size bug when maximized and return correct size and position.
1 parent dcd9f48 commit 94f6934

File tree

12 files changed

+109
-30
lines changed

12 files changed

+109
-30
lines changed

Assets/uWindowCapture/Editor/UwcWindowTextureEditor.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ void DrawWindowInformation()
181181
EditorGUILayout.IntField("Window Width", window.width);
182182
EditorGUILayout.IntField("Window Height", window.height);
183183
EditorGUILayout.IntField("Window Z-Order", window.zOrder);
184-
EditorGUILayout.IntField("Buffer Width", window.bufferWidth);
185-
EditorGUILayout.IntField("Buffer Height", window.bufferHeight);
186184
EditorGUILayout.Toggle("Alt-Tab Window", window.isAltTabWindow);
187185
EditorGUILayout.Toggle("Minimized", window.isMinimized);
188186
EditorGUILayout.Toggle("Maximized", window.isMaximized);

Assets/uWindowCapture/Examples/GetPixels/UwcGetPixelsExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void Update()
3535
CreateTextureIfNeeded();
3636

3737
var window = uwcTexture.window;
38-
if (window == null || window.bufferWidth == 0) return;
38+
if (window == null || window.width == 0) return;
3939

4040
// GetPixels() can be run in another thread
4141
if (window.GetPixels(colors, x, y, w, h)) {

Assets/uWindowCapture/Examples/Window List/UwcWindowListItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ void Update()
4343
var windowTitle = window.title;
4444
title.text = string.IsNullOrEmpty(windowTitle) ? "-No Name-" : windowTitle;
4545

46-
x.text = window.x.ToString();
47-
y.text = window.y.ToString();
46+
x.text = window.isMinimized ? "-" : window.x.ToString();
47+
y.text = window.isMinimized ? "-" : window.y.ToString();
4848
z.text = window.zOrder.ToString();
4949

5050
width.text = window.width.ToString();
512 Bytes
Binary file not shown.
512 Bytes
Binary file not shown.

Assets/uWindowCapture/Scripts/UwcLib.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,14 @@ public static class Lib
123123
public static extern int GetWindowZOrder(int id);
124124
[DllImport(name, EntryPoint = "UwcGetWindowBuffer")]
125125
public static extern IntPtr GetWindowBuffer(int id);
126-
[DllImport(name, EntryPoint = "UwcGetWindowBufferWidth")]
127-
public static extern int GetWindowBufferWidth(int id);
128-
[DllImport(name, EntryPoint = "UwcGetWindowBufferHeight")]
129-
public static extern int GetWindowBufferHeight(int id);
126+
[DllImport(name, EntryPoint = "UwcGetWindowTextureWidth")]
127+
public static extern int GetWindowTextureWidth(int id);
128+
[DllImport(name, EntryPoint = "UwcGetWindowTextureHeight")]
129+
public static extern int GetWindowTextureHeight(int id);
130+
[DllImport(name, EntryPoint = "UwcGetWindowTextureOffsetX")]
131+
public static extern int GetWindowTextureOffsetX(int id);
132+
[DllImport(name, EntryPoint = "UwcGetWindowTextureOffsetY")]
133+
public static extern int GetWindowTextureOffsetY(int id);
130134
[DllImport(name, EntryPoint = "UwcGetWindowIconWidth")]
131135
public static extern int GetWindowIconWidth(int id);
132136
[DllImport(name, EntryPoint = "UwcGetWindowIconHeight")]

Assets/uWindowCapture/Scripts/UwcWindow.cs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,26 +161,46 @@ public string className
161161
get { return Lib.GetWindowClassName(id); }
162162
}
163163

164-
public int x
164+
public int rawX
165165
{
166166
get { return Lib.GetWindowX(id); }
167167
}
168168

169-
public int y
169+
public int rawY
170170
{
171171
get { return Lib.GetWindowY(id); }
172172
}
173173

174-
public int width
174+
public int rawWidth
175175
{
176176
get { return Lib.GetWindowWidth(id); }
177177
}
178178

179-
public int height
179+
public int rawHeight
180180
{
181181
get { return Lib.GetWindowHeight(id); }
182182
}
183183

184+
public int x
185+
{
186+
get { return rawX + Lib.GetWindowTextureOffsetX(id); }
187+
}
188+
189+
public int y
190+
{
191+
get { return rawY + Lib.GetWindowTextureOffsetY(id); }
192+
}
193+
194+
public int width
195+
{
196+
get { return Lib.GetWindowTextureWidth(id); }
197+
}
198+
199+
public int height
200+
{
201+
get { return Lib.GetWindowTextureHeight(id); }
202+
}
203+
184204
public int zOrder
185205
{
186206
get { return Lib.GetWindowZOrder(id); }
@@ -191,14 +211,14 @@ public System.IntPtr buffer
191211
get { return Lib.GetWindowBuffer(id); }
192212
}
193213

194-
public int bufferWidth
214+
public int textureOffsetX
195215
{
196-
get { return Lib.GetWindowBufferWidth(id); }
216+
get { return Lib.GetWindowTextureOffsetX(id); }
197217
}
198218

199-
public int bufferHeight
219+
public int textureOffsetY
200220
{
201-
get { return Lib.GetWindowBufferHeight(id); }
221+
get { return Lib.GetWindowTextureOffsetY(id); }
202222
}
203223

204224
public int iconWidth
@@ -317,8 +337,8 @@ void OnIconCaptured()
317337

318338
void CreateWindowTexture()
319339
{
320-
var w = bufferWidth;
321-
var h = bufferHeight;
340+
var w = width;
341+
var h = height;
322342
if (w == 0 || h == 0) return;
323343

324344
if (!texture || texture.width != w || texture.height != h) {

Plugins/uWindowCapture/uWindowCapture/Main.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,20 +291,38 @@ extern "C"
291291
return nullptr;
292292
}
293293

294-
UNITY_INTERFACE_EXPORT UINT UNITY_INTERFACE_API UwcGetWindowBufferWidth(int id)
294+
UNITY_INTERFACE_EXPORT UINT UNITY_INTERFACE_API UwcGetWindowTextureWidth(int id)
295295
{
296296
if (auto window = GetWindow(id))
297297
{
298-
return window->GetBufferWidth();
298+
return window->GetTextureWidth();
299299
}
300300
return 0;
301301
}
302302

303-
UNITY_INTERFACE_EXPORT UINT UNITY_INTERFACE_API UwcGetWindowBufferHeight(int id)
303+
UNITY_INTERFACE_EXPORT UINT UNITY_INTERFACE_API UwcGetWindowTextureHeight(int id)
304304
{
305305
if (auto window = GetWindow(id))
306306
{
307-
return window->GetBufferHeight();
307+
return window->GetTextureHeight();
308+
}
309+
return 0;
310+
}
311+
312+
UNITY_INTERFACE_EXPORT UINT UNITY_INTERFACE_API UwcGetWindowTextureOffsetX(int id)
313+
{
314+
if (auto window = GetWindow(id))
315+
{
316+
return window->GetTextureOffsetX();
317+
}
318+
return 0;
319+
}
320+
321+
UNITY_INTERFACE_EXPORT UINT UNITY_INTERFACE_API UwcGetWindowTextureOffsetY(int id)
322+
{
323+
if (auto window = GetWindow(id))
324+
{
325+
return window->GetTextureOffsetY();
308326
}
309327
return 0;
310328
}

Plugins/uWindowCapture/uWindowCapture/Window.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,18 +205,30 @@ BYTE* Window::GetBuffer() const
205205
}
206206

207207

208-
UINT Window::GetBufferWidth() const
208+
UINT Window::GetTextureWidth() const
209209
{
210210
return windowTexture_->GetWidth();
211211
}
212212

213213

214-
UINT Window::GetBufferHeight() const
214+
UINT Window::GetTextureHeight() const
215215
{
216216
return windowTexture_->GetHeight();
217217
}
218218

219219

220+
UINT Window::GetTextureOffsetX() const
221+
{
222+
return windowTexture_->GetOffsetX();
223+
}
224+
225+
226+
UINT Window::GetTextureOffsetY() const
227+
{
228+
return windowTexture_->GetOffsetY();
229+
}
230+
231+
220232
UINT Window::GetIconWidth() const
221233
{
222234
return iconTexture_->GetWidth();

Plugins/uWindowCapture/uWindowCapture/Window.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ friend class WindowManager;
6464
UINT GetClientHeight() const;
6565
UINT GetZOrder() const;
6666
BYTE* GetBuffer() const;
67-
UINT GetBufferWidth() const;
68-
UINT GetBufferHeight() const;
67+
UINT GetTextureWidth() const;
68+
UINT GetTextureHeight() const;
69+
UINT GetTextureOffsetX() const;
70+
UINT GetTextureOffsetY() const;
6971
UINT GetIconWidth() const;
7072
UINT GetIconHeight() const;
7173

0 commit comments

Comments
 (0)