Skip to content

Commit f777dc2

Browse files
committed
Add content bounds support to Window API
Introduces getter and setter for window content bounds in the Window class, updates FFI bindings to support native content bounds operations, and modifies context menu positioning to use content bounds. Also updates submodule for native API implementation.
1 parent 7680aee commit f777dc2

4 files changed

Lines changed: 55 additions & 11 deletions

File tree

packages/cnativeapi/lib/src/bindings_generated.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,35 @@ class CNativeApiBindings {
473473
_native_window_get_content_sizePtr
474474
.asFunction<native_size_t Function(native_window_t)>();
475475

476+
void native_window_set_content_bounds(
477+
native_window_t window,
478+
native_rectangle_t bounds,
479+
) {
480+
return _native_window_set_content_bounds(window, bounds);
481+
}
482+
483+
late final _native_window_set_content_boundsPtr =
484+
_lookup<
485+
ffi.NativeFunction<
486+
ffi.Void Function(native_window_t, native_rectangle_t)
487+
>
488+
>('native_window_set_content_bounds');
489+
late final _native_window_set_content_bounds =
490+
_native_window_set_content_boundsPtr
491+
.asFunction<void Function(native_window_t, native_rectangle_t)>();
492+
493+
native_rectangle_t native_window_get_content_bounds(native_window_t window) {
494+
return _native_window_get_content_bounds(window);
495+
}
496+
497+
late final _native_window_get_content_boundsPtr =
498+
_lookup<ffi.NativeFunction<native_rectangle_t Function(native_window_t)>>(
499+
'native_window_get_content_bounds',
500+
);
501+
late final _native_window_get_content_bounds =
502+
_native_window_get_content_boundsPtr
503+
.asFunction<native_rectangle_t Function(native_window_t)>();
504+
476505
void native_window_set_minimum_size(
477506
native_window_t window,
478507
double width,

packages/nativeapi/lib/src/widgets/context_menu_region.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class _ContextMenuRegionState extends State<ContextMenuRegion> {
8181
// Open the menu at the click position using relative positioning
8282
widget.menu.open(
8383
PositioningStrategy.relative(
84-
_activeWindow!.bounds,
84+
_activeWindow!.contentBounds,
8585
Offset(event.position.dx, event.position.dy),
8686
),
8787
widget.placement,

packages/nativeapi/lib/src/window.dart

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,28 @@ class Window
157157
);
158158
}
159159

160+
/// Sets the window's content bounds (position and size).
161+
set contentBounds(Rect bounds) {
162+
final nativeBounds = ffi.calloc<native_rectangle_t>();
163+
nativeBounds.ref.x = bounds.left;
164+
nativeBounds.ref.y = bounds.top;
165+
nativeBounds.ref.width = bounds.width;
166+
nativeBounds.ref.height = bounds.height;
167+
}
168+
169+
/// Gets the window's content bounds (position and size).
170+
Rect get contentBounds {
171+
final nativeBounds = bindings.native_window_get_content_bounds(
172+
_nativeHandle,
173+
);
174+
return Rect.fromLTWH(
175+
nativeBounds.x,
176+
nativeBounds.y,
177+
nativeBounds.width,
178+
nativeBounds.height,
179+
);
180+
}
181+
160182
/// Sets the window's size.
161183
///
162184
/// If [animate] is true, the resize will be animated (platform-dependent).
@@ -290,10 +312,7 @@ class Window
290312
set title(String value) {
291313
final titleUtf8 = value.toNativeUtf8();
292314
try {
293-
bindings.native_window_set_title(
294-
_nativeHandle,
295-
titleUtf8.cast<Char>(),
296-
);
315+
bindings.native_window_set_title(_nativeHandle, titleUtf8.cast<Char>());
297316
} finally {
298317
ffi.malloc.free(titleUtf8);
299318
}
@@ -332,10 +351,7 @@ class Window
332351

333352
/// Sets whether the window is visible on all workspaces.
334353
set isVisibleOnAllWorkspaces(bool value) {
335-
bindings.native_window_set_visible_on_all_workspaces(
336-
_nativeHandle,
337-
value,
338-
);
354+
bindings.native_window_set_visible_on_all_workspaces(_nativeHandle, value);
339355
}
340356

341357
/// Checks if the window is visible on all workspaces.
@@ -393,4 +409,3 @@ class Window
393409
// any destroy function here. The manager handles cleanup.
394410
}
395411
}
396-

0 commit comments

Comments
 (0)