-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Threading.Tasks; | ||
using UnityEngine; | ||
|
||
namespace AquaMai.Utils; | ||
|
||
public class WindowState | ||
{ | ||
private const int GWL_STYLE = -16; | ||
private const int WS_WHATEVER = 0x14CF0000; | ||
|
||
private static IntPtr hwnd = IntPtr.Zero; | ||
|
||
public static void Execute() | ||
{ | ||
if (AquaMai.AppConfig.Utils.Windowed) | ||
{ | ||
var alreadyWindowed = Screen.fullScreenMode == FullScreenMode.Windowed; | ||
if (AquaMai.AppConfig.Utils.Width == 0 || AquaMai.AppConfig.Utils.Height == 0) | ||
{ | ||
Screen.fullScreenMode = FullScreenMode.Windowed; | ||
} | ||
else | ||
{ | ||
alreadyWindowed = false; | ||
Screen.SetResolution(AquaMai.AppConfig.Utils.Width, AquaMai.AppConfig.Utils.Height, FullScreenMode.Windowed); | ||
} | ||
|
||
hwnd = GetWindowHandle(); | ||
if(alreadyWindowed) | ||
{ | ||
SetResizeable(); | ||
} | ||
else | ||
{ | ||
Task.Run(async () => | ||
{ | ||
await Task.Delay(3000); | ||
// Screen.SetResolution has delay | ||
SetResizeable(); | ||
}); | ||
} | ||
} | ||
else | ||
{ | ||
var width = AquaMai.AppConfig.Utils.Width == 0 ? Display.main.systemWidth : AquaMai.AppConfig.Utils.Width; | ||
var height = AquaMai.AppConfig.Utils.Height == 0 ? Display.main.systemHeight : AquaMai.AppConfig.Utils.Height; | ||
Screen.SetResolution(width, height, FullScreenMode.FullScreenWindow); | ||
} | ||
} | ||
|
||
public static void SetResizeable() | ||
{ | ||
if (hwnd == IntPtr.Zero) return; | ||
SetWindowLongPtr(hwnd, GWL_STYLE, WS_WHATEVER); | ||
} | ||
|
||
private delegate bool EnumThreadDelegate(IntPtr hwnd, IntPtr lParam); | ||
|
||
[DllImport("user32.dll")] | ||
static extern bool EnumThreadWindows(int dwThreadId, EnumThreadDelegate lpfn, IntPtr lParam); | ||
|
||
[DllImport("Kernel32.dll")] | ||
static extern int GetCurrentThreadId(); | ||
|
||
static IntPtr GetWindowHandle() | ||
{ | ||
IntPtr returnHwnd = IntPtr.Zero; | ||
var threadId = GetCurrentThreadId(); | ||
EnumThreadWindows(threadId, | ||
(hWnd, lParam) => | ||
{ | ||
if (returnHwnd == IntPtr.Zero) returnHwnd = hWnd; | ||
return true; | ||
}, IntPtr.Zero); | ||
return returnHwnd; | ||
} | ||
|
||
[DllImport("user32.dll")] | ||
static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, int dwNewLong); | ||
} |