diff options
Diffstat (limited to 'src/mingwMain/kotlin/moe')
-rw-r--r-- | src/mingwMain/kotlin/moe/yuuta/aero/Aero.kt | 73 | ||||
-rw-r--r-- | src/mingwMain/kotlin/moe/yuuta/aero/WinApi.kt | 43 | ||||
-rw-r--r-- | src/mingwMain/kotlin/moe/yuuta/aero/WinCompat.kt | 9 |
3 files changed, 60 insertions, 65 deletions
diff --git a/src/mingwMain/kotlin/moe/yuuta/aero/Aero.kt b/src/mingwMain/kotlin/moe/yuuta/aero/Aero.kt index 44c184e..e9f47b4 100644 --- a/src/mingwMain/kotlin/moe/yuuta/aero/Aero.kt +++ b/src/mingwMain/kotlin/moe/yuuta/aero/Aero.kt @@ -29,38 +29,23 @@ fun main() { null ) - val forceDialogEnv = WinApi.getenv("AERO_DEMO_FORCE_DIALOG") + if (hwnd == null) { + MessageBoxA(null, + "The system returns an empty dialog (${GetLastError()})", + "Aero", + (MB_OK or MB_ICONERROR).convert()) + return + } - if (hwnd == null || (forceDialogEnv == "true")) { - if (hwnd == null) { - MessageBoxA(null, - "The system returns an empty dialog (${GetLastError()})", - "Aero", - (MB_OK or MB_ICONERROR).convert()) - } - memScoped { - // Fallback - val dlgImpl = cValue<DLGTEMPLATE> { - style = (WS_OVERLAPPEDWINDOW or - DS_CENTER or - DS_MODALFRAME).convert() - dwExtendedStyle = 0.convert() - cdit = 0.convert() - x = 0 - y = 0 - cx = 400 - cy = 200 - } - return@memScoped DialogBoxIndirectParamW(WinCompat.hInstance, - dlgImpl.ptr, - null, - staticCFunction(::dlgProc), - 0) - } - } else { - ShowWindow(hwnd, WinCompat.nCmdShow) - WinApi.msgLoop() + val result = DwmEnableComposition(DWM_EC_ENABLECOMPOSITION) and 0xFFFF + if (result != 0) { + MessageBoxA(hwnd, + "DwmEnableComposition() fail (0x${result.toString(16)})", + "Aero", + (MB_OK or MB_ICONERROR).convert()) } + ShowWindow(hwnd, WinCompat.nCmdShow) + WinApi.msgLoop() } fun windowProc(hwnd: HWND?, @@ -69,13 +54,17 @@ fun windowProc(hwnd: HWND?, lParam: LPARAM): LRESULT { return when (uMsg.convert<Int>()) { WM_CREATE -> { - WinApi.setAero(hwnd) + WinApi.setAero10(hwnd) 1 } WM_DESTROY -> { PostQuitMessage(0) 1 } + WM_ACTIVATE -> { + WinApi.setAero7(hwnd) + 1 + } WM_PAINT -> { val ps = nativeHeap.alloc<PAINTSTRUCT>() val hdc = BeginPaint(hwnd, ps.ptr) @@ -90,26 +79,4 @@ fun windowProc(hwnd: HWND?, DefWindowProcA(hwnd, uMsg, wParam, lParam) } } -} - -fun dlgProc(hDlg: HWND?, - message: UINT, - wParam: WPARAM, - lParam: LPARAM): INT_PTR { - when (message.convert<Int>()) { - WM_INITDIALOG -> { - WinApi.setAero(hDlg) - return true.toByte().toLong() - } - WM_COMMAND -> { - EndDialog(hDlg, wParam.convert()) - return true.toByte().toLong() - } - WM_CTLCOLORDLG -> { - return GetStockObject(BLACK_BRUSH).rawValue.toLong() - } - else -> { - return false.toByte().toLong() - } - } }
\ No newline at end of file diff --git a/src/mingwMain/kotlin/moe/yuuta/aero/WinApi.kt b/src/mingwMain/kotlin/moe/yuuta/aero/WinApi.kt index 381f002..75453ef 100644 --- a/src/mingwMain/kotlin/moe/yuuta/aero/WinApi.kt +++ b/src/mingwMain/kotlin/moe/yuuta/aero/WinApi.kt @@ -5,19 +5,10 @@ import aero.WINDOWCOMPOSITIONATTRIBDATA import aero.pfnSetWindowCompositionAttribute import kotlinx.cinterop.* import platform.windows.* +import versionhelper.IsWindows10OrGreater +import versionhelper.IsWindowsVistaOrGreater object WinApi { - fun getenv(name: String): String = memScoped { - val buffer = nativeHeap.allocArray<CHARVar>(MAX_PATH) - GetEnvironmentVariableA(name, - buffer, - MAX_PATH - ) - val env = buffer.toKString() - nativeHeap.free(buffer) - return@memScoped env - } - fun msgLoop() { memScoped { val msg = nativeHeap.alloc<MSG>() @@ -33,7 +24,7 @@ object WinApi { } } - fun setAero(hwnd: HWND?) { + private fun _setAero10(hwnd: HWND?) { val hUser = GetModuleHandleW("user32.dll") ?: return val setWindowCompositionAttribute = GetProcAddress(hUser, "SetWindowCompositionAttribute") @@ -53,4 +44,32 @@ object WinApi { setWindowCompositionAttribute(hwnd, data.ptr) } } + + fun setAero10(hwnd: HWND?) { + if (IsWindows10OrGreater() == 1) { + _setAero10(hwnd) + } + } + + private fun _setAero7(hwnd: HWND?): Int { + val margins = cValue<MARGINS> { + cxLeftWidth = -1 + } + return memScoped { + return@memScoped DwmExtendFrameIntoClientArea(hwnd, margins.ptr) + } + } + + fun setAero7(hwnd: HWND?) { + if (IsWindowsVistaOrGreater() == 1 && + WinCompat.DwmIsCompositionEnabled()) { + val result = _setAero7(hwnd) + if (result != 0) { + MessageBoxA(hwnd, + "Cannot extend the aero glass (0x${result.toString(16)})", + "Aero", + (MB_OK or MB_ICONERROR).convert()) + } + } + } }
\ No newline at end of file diff --git a/src/mingwMain/kotlin/moe/yuuta/aero/WinCompat.kt b/src/mingwMain/kotlin/moe/yuuta/aero/WinCompat.kt index 29c78fb..029e9a2 100644 --- a/src/mingwMain/kotlin/moe/yuuta/aero/WinCompat.kt +++ b/src/mingwMain/kotlin/moe/yuuta/aero/WinCompat.kt @@ -3,6 +3,7 @@ package moe.yuuta.aero import kotlinx.cinterop.* import platform.windows.GetModuleHandleA import platform.windows.GetStartupInfoA +import platform.windows.WINBOOLVar import platform.windows._STARTUPINFOA object WinCompat { @@ -16,4 +17,12 @@ object WinCompat { } val hInstance get() = GetModuleHandleA(null) + + fun DwmIsCompositionEnabled(): Boolean { + val enable = nativeHeap.alloc<WINBOOLVar>() + platform.windows.DwmIsCompositionEnabled(enable.ptr) + val result = enable.value + nativeHeap.free(enable) + return result > 0 + } }
\ No newline at end of file |