Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@ jobs:

- name: Archive artifacts (Linux)
if: matrix.runner == 'ubuntu'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: bitsdojo_window_example_${{ matrix.runner }}
path: bitsdojo_window/example/build/linux/x64/release/bundle/

- name: Archive artifacts (Windows)
if: matrix.runner == 'windows'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: bitsdojo_window_example_${{ matrix.runner }}
path: bitsdojo_window/example/build/windows/runner/Release/bitsdojo_window_example.exe

- name: Archive artifacts (macOS)
if: matrix.runner == 'macos'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: bitsdojo_window_example_${{ matrix.runner }}
path: bitsdojo_window/example/build/macos/Build/Products/Release/bitsdojo_window_example.app
7 changes: 6 additions & 1 deletion bitsdojo_window/example/windows/flutter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ include(${EPHEMERAL_DIR}/generated_config.cmake)
# https://github.com/flutter/flutter/issues/57146.
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")

# Set fallback configurations for older versions of the flutter tool.
if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
set(FLUTTER_TARGET_PLATFORM "windows-x64")
endif()

# === Flutter Library ===
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")

Expand Down Expand Up @@ -91,7 +96,7 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
windows-x64 $<CONFIG>
${FLUTTER_TARGET_PLATFORM} $<CONFIG>
VERBATIM
)
add_custom_target(flutter_assemble DEPENDS
Expand Down
10 changes: 5 additions & 5 deletions bitsdojo_window/example/windows/runner/Runner.rc
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ IDI_APP_ICON ICON "resources\\app_icon.ico"
// Version
//

#ifdef FLUTTER_BUILD_NUMBER
#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD)
#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD
#else
#define VERSION_AS_NUMBER 1,0,0
#define VERSION_AS_NUMBER 1,0,0,0
#endif

#ifdef FLUTTER_BUILD_NAME
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME
#if defined(FLUTTER_VERSION)
#define VERSION_AS_STRING FLUTTER_VERSION
#else
#define VERSION_AS_STRING "1.0.0"
#endif
Expand Down
6 changes: 3 additions & 3 deletions bitsdojo_window/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ dependencies:
^0.1.2
#path: ../bitsdojo_window_platform_interface
bitsdojo_window_windows:
^0.1.6
#path: ../bitsdojo_window_windows
# ^0.1.6
path: ../bitsdojo_window_windows
bitsdojo_window_macos:
^0.1.4
#path: ../bitsdojo_window_macos
bitsdojo_window_linux:
^0.1.4
#path: ../bitsdojo_window_linux
#path: ../bitsdojo_window_linux
45 changes: 26 additions & 19 deletions bitsdojo_window_windows/lib/src/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ bool isValidHandle(int? handle, String operation) {
}

Rect getScreenRectForWindow(int handle) {
int monitor = MonitorFromWindow(handle, MONITOR_DEFAULTTONEAREST);
final monitor =
MonitorFromWindow(hWndFromInt(handle), MONITOR_DEFAULTTONEAREST);
final monitorInfo = calloc<MONITORINFO>()..ref.cbSize = sizeOf<MONITORINFO>();
final result = GetMonitorInfo(monitor, monitorInfo);
if (result == TRUE) {
if (result) {
return Rect.fromLTRB(
monitorInfo.ref.rcWork.left.toDouble(),
monitorInfo.ref.rcWork.top.toDouble(),
Expand Down Expand Up @@ -55,7 +56,7 @@ class WinWindow extends WinDesktopWindow {
Rect get rect {
if (!isValidHandle(handle, "get rectangle")) return Rect.zero;
final winRect = calloc<RECT>();
GetWindowRect(handle!, winRect);
GetWindowRect(hWndFromInt(handle!), winRect);
Rect result = winRect.ref.toRect;
calloc.free(winRect);
return result;
Expand Down Expand Up @@ -87,8 +88,10 @@ class WinWindow extends WinDesktopWindow {
double systemMetric(int metric, {int dpiToUse = 0}) {
final windowDpi = dpiToUse != 0 ? dpiToUse : this.dpi;
double result = dpiAware
? GetSystemMetricsForDpi(metric, windowDpi).toDouble()
: GetSystemMetrics(metric).toDouble();
? GetSystemMetricsForDpi(SYSTEM_METRICS_INDEX(metric), windowDpi)
.value
.toDouble()
: GetSystemMetrics(SYSTEM_METRICS_INDEX(metric)).toDouble();
return result;
}

Expand All @@ -98,7 +101,7 @@ class WinWindow extends WinDesktopWindow {

int get dpi {
if (!dpiAware || !isValidHandle(handle, "get dpi")) return 96;
return GetDpiForWindow(handle!);
return GetDpiForWindow(hWndFromInt(handle!));
}

double get scaleFactor {
Expand Down Expand Up @@ -201,8 +204,8 @@ class WinWindow extends WinDesktopWindow {
Size sizeToSet = Size(width, height);
_sizeSetFromDart = sizeToSet;
if (_alignment == null) {
SetWindowPos(handle!, 0, 0, 0, sizeToSet.width.toInt(),
sizeToSet.height.toInt(), SWP_NOMOVE);
SetWindowPos(hWndFromInt(handle!), null, 0, 0,
sizeToSet.width.toInt(), sizeToSet.height.toInt(), SWP_NOMOVE);
} else {
final sizeOnScreen = getSizeOnScreen((sizeToSet));
final screenRect = getScreenRectForWindow(handle!);
Expand All @@ -212,7 +215,7 @@ class WinWindow extends WinDesktopWindow {

bool get isMaximized {
if (!isValidHandle(handle, "get isMaximized")) return false;
return (IsZoomed(handle!) == 1);
return IsZoomed(hWndFromInt(handle!));
}

@Deprecated("use isVisible instead")
Expand All @@ -221,7 +224,7 @@ class WinWindow extends WinDesktopWindow {
}

bool get isVisible {
return (IsWindowVisible(handle!) == 1);
return IsWindowVisible(hWndFromInt(handle!));
}

Offset get position {
Expand All @@ -231,8 +234,8 @@ class WinWindow extends WinDesktopWindow {

set position(Offset newPosition) {
if (!isValidHandle(handle, "set position")) return;
SetWindowPos(handle!, 0, newPosition.dx.toInt(), newPosition.dy.toInt(), 0,
0, SWP_NOSIZE);
SetWindowPos(hWndFromInt(handle!), null, newPosition.dx.toInt(),
newPosition.dy.toInt(), 0, 0, SWP_NOSIZE);
}

void show() {
Expand All @@ -244,8 +247,8 @@ class WinWindow extends WinDesktopWindow {

void hide() {
if (!isValidHandle(handle, "hide")) return;
SetWindowPos(
handle!, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_HIDEWINDOW);
SetWindowPos(hWndFromInt(handle!), null, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_HIDEWINDOW);
}

@Deprecated("use show()/hide() instead")
Expand All @@ -259,28 +262,32 @@ class WinWindow extends WinDesktopWindow {

void close() {
if (!isValidHandle(handle, "close")) return;
PostMessage(handle!, WM_SYSCOMMAND, SC_CLOSE, 0);
PostMessage(
hWndFromInt(handle!), WM_SYSCOMMAND, WPARAM(SC_CLOSE), LPARAM(0));
}

void maximize() {
if (!isValidHandle(handle, "maximize")) return;
PostMessage(handle!, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
PostMessage(
hWndFromInt(handle!), WM_SYSCOMMAND, WPARAM(SC_MAXIMIZE), LPARAM(0));
}

void minimize() {
if (!isValidHandle(handle, "minimize")) return;

PostMessage(handle!, WM_SYSCOMMAND, SC_MINIMIZE, 0);
PostMessage(
hWndFromInt(handle!), WM_SYSCOMMAND, WPARAM(SC_MINIMIZE), LPARAM(0));
}

void restore() {
if (!isValidHandle(handle, "restore")) return;
PostMessage(handle!, WM_SYSCOMMAND, SC_RESTORE, 0);
PostMessage(
hWndFromInt(handle!), WM_SYSCOMMAND, WPARAM(SC_RESTORE), LPARAM(0));
}

void maximizeOrRestore() {
if (!isValidHandle(handle, "maximizeOrRestore")) return;
if (IsZoomed(handle!) == 1) {
if (IsZoomed(hWndFromInt(handle!))) {
this.restore();
} else {
this.maximize();
Expand Down
11 changes: 8 additions & 3 deletions bitsdojo_window_windows/lib/src/window_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const BDW_SETWINDOWPOS = 1;
const BDW_SETWINDOWTEXT = 2;
const BDW_FORCECHILDREFRESH = 3;

HWND hWndFromInt(int hWnd) => HWND(Pointer.fromAddress(hWnd));

class SWPParam extends Struct {
@Int32()
external int x, y, cx, cy, uFlags;
Expand All @@ -22,7 +24,8 @@ void setWindowPos(
..cx = cx
..cy = cy
..uFlags = uFlags;
PostMessage(hWnd, WM_BDW_ACTION, BDW_SETWINDOWPOS, param.address);
PostMessage(hWndFromInt(hWnd), WM_BDW_ACTION, WPARAM(BDW_SETWINDOWPOS),
LPARAM(param.address));
}

class SWTParam extends Struct {
Expand All @@ -32,9 +35,11 @@ class SWTParam extends Struct {
void setWindowText(int hWnd, String text) {
final param = calloc<SWTParam>();
param.ref.text = text.toNativeUtf16();
PostMessage(hWnd, WM_BDW_ACTION, BDW_SETWINDOWTEXT, param.address);
PostMessage(hWndFromInt(hWnd), WM_BDW_ACTION, WPARAM(BDW_SETWINDOWTEXT),
LPARAM(param.address));
}

void forceChildRefresh(int hWnd) {
PostMessage(hWnd, WM_BDW_ACTION, BDW_FORCECHILDREFRESH, 0);
PostMessage(hWndFromInt(hWnd), WM_BDW_ACTION, WPARAM(BDW_FORCECHILDREFRESH),
LPARAM(0));
}
2 changes: 1 addition & 1 deletion bitsdojo_window_windows/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
bitsdojo_window_platform_interface:
^0.1.2
#path: ../bitsdojo_window_platform_interface
win32: ^5.1.1
win32: ^6.3.0
ffi: ^2.0.0

dev_dependencies:
Expand Down