Skip to content

Commit 775dcc7

Browse files
committed
Sync with core 7330aa6: window property change events (#72)
1 parent 139320c commit 775dcc7

15 files changed

Lines changed: 312 additions & 4 deletions

File tree

‎bindings/csharp/src/CNativeAPI/generated/Window.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public struct DataUnion
2121
[FieldOffset(0)] public MovedData moved;
2222
[FieldOffset(0)] public ResizedData resized;
2323
[FieldOffset(0)] public CloseRequestedData close_requested;
24+
[FieldOffset(0)] public PropertyChangedData property_changed;
2425
}
2526

2627
[StructLayout(LayoutKind.Sequential)]
@@ -40,6 +41,12 @@ public struct CloseRequestedData
4041
{
4142
public ulong request;
4243
}
44+
45+
[StructLayout(LayoutKind.Sequential)]
46+
public struct PropertyChangedData
47+
{
48+
public int property;
49+
}
4350
}
4451

4552
[StructLayout(LayoutKind.Sequential)]

‎bindings/csharp/src/NativeAPI/Window.cs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ public enum WindowCornerPreference
2323
RoundSmall = 3,
2424
}
2525

26+
public enum WindowProperty
27+
{
28+
Title = 0,
29+
Resizable = 1,
30+
Movable = 2,
31+
Minimizable = 3,
32+
Maximizable = 4,
33+
FullScreenable = 5,
34+
Closable = 6,
35+
WindowControlButtonsVisible = 7,
36+
AlwaysOnTop = 8,
37+
AlwaysOnBottom = 9,
38+
TitleBarStyle = 10,
39+
}
40+
2641
public enum VisualEffect
2742
{
2843
None = 0,
@@ -64,6 +79,7 @@ public sealed record Closed(uint WindowId) : WindowEvent;
6479
public sealed record EnteredFullScreen(uint WindowId) : WindowEvent;
6580
public sealed record ExitedFullScreen(uint WindowId) : WindowEvent;
6681
public sealed record CloseRequested(uint WindowId, EventRequest Request) : WindowEvent;
82+
public sealed record PropertyChanged(uint WindowId, WindowProperty Property) : WindowEvent;
6783

6884
internal static WindowEvent? FromRaw(in native_window_event_t raw)
6985
{
@@ -81,6 +97,7 @@ public sealed record CloseRequested(uint WindowId, EventRequest Request) : Windo
8197
case 9: return new EnteredFullScreen(raw.window_id);
8298
case 10: return new ExitedFullScreen(raw.window_id);
8399
case 11: return new CloseRequested(raw.window_id, new EventRequest(raw.data.close_requested.request, ownsHandle: false));
100+
case 12: return new PropertyChanged(raw.window_id, (WindowProperty)raw.data.property_changed.property);
84101
default: return null;
85102
}
86103
}

‎bindings/dart/cnativeapi/lib/src/bindings_generated.dart‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3429,6 +3429,20 @@ final class UnnamedStruct$18 extends ffi.Struct {
34293429
}) => $allocator<UnnamedStruct$18>()..ref.request = request;
34303430
}
34313431

3432+
final class UnnamedStruct$19 extends ffi.Struct {
3433+
@ffi.UnsignedInt()
3434+
external int propertyAsInt;
3435+
3436+
native_window_property_t get property =>
3437+
native_window_property_t.fromValue(propertyAsInt);
3438+
set property(native_window_property_t value) => propertyAsInt = value.value;
3439+
3440+
static ffi.Pointer<UnnamedStruct$19> $allocate(
3441+
ffi.Allocator $allocator, {
3442+
required native_window_property_t property,
3443+
}) => $allocator<UnnamedStruct$19>()..ref.property = property;
3444+
}
3445+
34323446
final class UnnamedStruct$2 extends ffi.Struct {
34333447
@ffi.UnsignedInt()
34343448
external int operationAsInt;
@@ -3565,6 +3579,8 @@ final class UnnamedUnion$9 extends ffi.Union {
35653579
external UnnamedStruct$17 resized;
35663580

35673581
external UnnamedStruct$18 close_requested;
3582+
3583+
external UnnamedStruct$19 property_changed;
35683584
}
35693585

35703586
typedef native_application_event_callback_t =
@@ -5466,7 +5482,8 @@ enum native_window_event_type_t {
54665482
NATIVE_WINDOW_EVENT_TYPE_CLOSED(8),
54675483
NATIVE_WINDOW_EVENT_TYPE_ENTERED_FULL_SCREEN(9),
54685484
NATIVE_WINDOW_EVENT_TYPE_EXITED_FULL_SCREEN(10),
5469-
NATIVE_WINDOW_EVENT_TYPE_CLOSE_REQUESTED(11);
5485+
NATIVE_WINDOW_EVENT_TYPE_CLOSE_REQUESTED(11),
5486+
NATIVE_WINDOW_EVENT_TYPE_PROPERTY_CHANGED(12);
54705487

54715488
final int value;
54725489
const native_window_event_type_t(this.value);
@@ -5484,6 +5501,7 @@ enum native_window_event_type_t {
54845501
9 => NATIVE_WINDOW_EVENT_TYPE_ENTERED_FULL_SCREEN,
54855502
10 => NATIVE_WINDOW_EVENT_TYPE_EXITED_FULL_SCREEN,
54865503
11 => NATIVE_WINDOW_EVENT_TYPE_CLOSE_REQUESTED,
5504+
12 => NATIVE_WINDOW_EVENT_TYPE_PROPERTY_CHANGED,
54875505
_ => throw ArgumentError(
54885506
'Unknown value for native_window_event_type_t: $value',
54895507
),
@@ -5530,6 +5548,40 @@ typedef native_window_manager_set_will_show_hook_callback_tFunction =
55305548
typedef Dartnative_window_manager_set_will_show_hook_callback_tFunction =
55315549
void Function(int arg0, ffi.Pointer<ffi.Void> user_data);
55325550

5551+
enum native_window_property_t {
5552+
NATIVE_WINDOW_PROPERTY_TITLE(0),
5553+
NATIVE_WINDOW_PROPERTY_RESIZABLE(1),
5554+
NATIVE_WINDOW_PROPERTY_MOVABLE(2),
5555+
NATIVE_WINDOW_PROPERTY_MINIMIZABLE(3),
5556+
NATIVE_WINDOW_PROPERTY_MAXIMIZABLE(4),
5557+
NATIVE_WINDOW_PROPERTY_FULL_SCREENABLE(5),
5558+
NATIVE_WINDOW_PROPERTY_CLOSABLE(6),
5559+
NATIVE_WINDOW_PROPERTY_WINDOW_CONTROL_BUTTONS_VISIBLE(7),
5560+
NATIVE_WINDOW_PROPERTY_ALWAYS_ON_TOP(8),
5561+
NATIVE_WINDOW_PROPERTY_ALWAYS_ON_BOTTOM(9),
5562+
NATIVE_WINDOW_PROPERTY_TITLE_BAR_STYLE(10);
5563+
5564+
final int value;
5565+
const native_window_property_t(this.value);
5566+
5567+
static native_window_property_t fromValue(int value) => switch (value) {
5568+
0 => NATIVE_WINDOW_PROPERTY_TITLE,
5569+
1 => NATIVE_WINDOW_PROPERTY_RESIZABLE,
5570+
2 => NATIVE_WINDOW_PROPERTY_MOVABLE,
5571+
3 => NATIVE_WINDOW_PROPERTY_MINIMIZABLE,
5572+
4 => NATIVE_WINDOW_PROPERTY_MAXIMIZABLE,
5573+
5 => NATIVE_WINDOW_PROPERTY_FULL_SCREENABLE,
5574+
6 => NATIVE_WINDOW_PROPERTY_CLOSABLE,
5575+
7 => NATIVE_WINDOW_PROPERTY_WINDOW_CONTROL_BUTTONS_VISIBLE,
5576+
8 => NATIVE_WINDOW_PROPERTY_ALWAYS_ON_TOP,
5577+
9 => NATIVE_WINDOW_PROPERTY_ALWAYS_ON_BOTTOM,
5578+
10 => NATIVE_WINDOW_PROPERTY_TITLE_BAR_STYLE,
5579+
_ => throw ArgumentError(
5580+
'Unknown value for native_window_property_t: $value',
5581+
),
5582+
};
5583+
}
5584+
55335585
/// Opaque WindowShadow handle.
55345586
///
55355587
/// A generational index into the library's handle table, NOT a pointer:

‎bindings/dart/nativeapi/CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## 0.4.1
22

3+
* `WindowPropertyChangedEvent`: a window's title, resizable / movable /
4+
minimizable / maximizable / full-screenable / closable state, control button
5+
visibility, always-on-top / on-bottom and title bar style report each change,
6+
whether a setter on any wrapper or the system or other code changed the
7+
native window. Read the new value through the getter `WindowProperty` names.
8+
39
* Apps that also target the web can depend on nativeapi again
410
(leanflutter/tray_manager#108). On the web `package:nativeapi` resolves to a
511
pure-Dart mirror without `dart:ffi`: the same classes, enums, value types and

‎bindings/dart/nativeapi/lib/src/web/window.dart‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,38 @@ enum WindowCornerPreference {
4848
};
4949
}
5050

51+
enum WindowProperty {
52+
title(0),
53+
resizable(1),
54+
movable(2),
55+
minimizable(3),
56+
maximizable(4),
57+
fullScreenable(5),
58+
closable(6),
59+
windowControlButtonsVisible(7),
60+
alwaysOnTop(8),
61+
alwaysOnBottom(9),
62+
titleBarStyle(10);
63+
64+
const WindowProperty(this.value);
65+
final int value;
66+
67+
static WindowProperty fromValue(int value) => switch (value) {
68+
0 => WindowProperty.title,
69+
1 => WindowProperty.resizable,
70+
2 => WindowProperty.movable,
71+
3 => WindowProperty.minimizable,
72+
4 => WindowProperty.maximizable,
73+
5 => WindowProperty.fullScreenable,
74+
6 => WindowProperty.closable,
75+
7 => WindowProperty.windowControlButtonsVisible,
76+
8 => WindowProperty.alwaysOnTop,
77+
9 => WindowProperty.alwaysOnBottom,
78+
10 => WindowProperty.titleBarStyle,
79+
_ => WindowProperty.title,
80+
};
81+
}
82+
5183
enum VisualEffect {
5284
none(0),
5385
blur(1),
@@ -197,6 +229,17 @@ final class WindowCloseRequestedEvent extends WindowEvent {
197229
final EventRequest request;
198230
}
199231

232+
final class WindowPropertyChangedEvent extends WindowEvent {
233+
const WindowPropertyChangedEvent({
234+
required this.windowId,
235+
required this.property,
236+
});
237+
238+
@override
239+
final WindowId windowId;
240+
final WindowProperty property;
241+
}
242+
200243
class Window {
201244
Window.fromHandle(this.nativeHandle);
202245
Window.borrowed(this.nativeHandle);

‎bindings/dart/nativeapi/lib/src/window.dart‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,41 @@ enum WindowCornerPreference {
6060
c.native_window_corner_preference_t.fromValue(value);
6161
}
6262

63+
enum WindowProperty {
64+
title(0),
65+
resizable(1),
66+
movable(2),
67+
minimizable(3),
68+
maximizable(4),
69+
fullScreenable(5),
70+
closable(6),
71+
windowControlButtonsVisible(7),
72+
alwaysOnTop(8),
73+
alwaysOnBottom(9),
74+
titleBarStyle(10);
75+
76+
const WindowProperty(this.value);
77+
final int value;
78+
79+
static WindowProperty fromValue(int value) => switch (value) {
80+
0 => WindowProperty.title,
81+
1 => WindowProperty.resizable,
82+
2 => WindowProperty.movable,
83+
3 => WindowProperty.minimizable,
84+
4 => WindowProperty.maximizable,
85+
5 => WindowProperty.fullScreenable,
86+
6 => WindowProperty.closable,
87+
7 => WindowProperty.windowControlButtonsVisible,
88+
8 => WindowProperty.alwaysOnTop,
89+
9 => WindowProperty.alwaysOnBottom,
90+
10 => WindowProperty.titleBarStyle,
91+
_ => WindowProperty.title,
92+
};
93+
94+
c.native_window_property_t get raw =>
95+
c.native_window_property_t.fromValue(value);
96+
}
97+
6398
enum VisualEffect {
6499
none(0),
65100
blur(1),
@@ -191,6 +226,18 @@ sealed class WindowEvent {
191226
request: EventRequest.borrowed(raw.data.close_requested.request),
192227
);
193228
}
229+
if (raw.typeAsInt ==
230+
c
231+
.native_window_event_type_t
232+
.NATIVE_WINDOW_EVENT_TYPE_PROPERTY_CHANGED
233+
.value) {
234+
return WindowPropertyChangedEvent(
235+
windowId: raw.window_id,
236+
property: WindowProperty.fromValue(
237+
raw.data.property_changed.propertyAsInt,
238+
),
239+
);
240+
}
194241
return null;
195242
}
196243
}
@@ -285,6 +332,17 @@ final class WindowCloseRequestedEvent extends WindowEvent {
285332
final EventRequest request;
286333
}
287334

335+
final class WindowPropertyChangedEvent extends WindowEvent {
336+
const WindowPropertyChangedEvent({
337+
required this.windowId,
338+
required this.property,
339+
});
340+
341+
@override
342+
final WindowId windowId;
343+
final WindowProperty property;
344+
}
345+
288346
class Window {
289347
/// Adopts a handle returned by the C API and releases it when this
290348
/// object becomes unreachable.

‎bindings/js/lib/window.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ export const WindowCornerPreference = {
2525
} as const;
2626
export type WindowCornerPreference = (typeof WindowCornerPreference)[keyof typeof WindowCornerPreference];
2727

28+
export const WindowProperty = {
29+
Title: 0,
30+
Resizable: 1,
31+
Movable: 2,
32+
Minimizable: 3,
33+
Maximizable: 4,
34+
FullScreenable: 5,
35+
Closable: 6,
36+
WindowControlButtonsVisible: 7,
37+
AlwaysOnTop: 8,
38+
AlwaysOnBottom: 9,
39+
TitleBarStyle: 10,
40+
} as const;
41+
export type WindowProperty = (typeof WindowProperty)[keyof typeof WindowProperty];
42+
2843
export const VisualEffect = {
2944
None: 0,
3045
Blur: 1,
@@ -61,7 +76,8 @@ export type WindowEvent =
6176
| { type: "closed"; windowId: WindowId }
6277
| { type: "enteredFullScreen"; windowId: WindowId }
6378
| { type: "exitedFullScreen"; windowId: WindowId }
64-
| { type: "closeRequested"; windowId: WindowId; request: EventRequest | null };
79+
| { type: "closeRequested"; windowId: WindowId; request: EventRequest | null }
80+
| { type: "propertyChanged"; windowId: WindowId; property: WindowProperty };
6581

6682
/** A native Window, held through an owned handle. */
6783
export class Window extends NativeObject {

‎bindings/js/src/generated/types.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,10 @@ inline Value ToValue(const native_window_event_t& event) {
472472
result.Set("type", Value::String("closeRequested"));
473473
result.Set("request", Value::BigInt(event.data.close_requested.request));
474474
break;
475+
case NATIVE_WINDOW_EVENT_TYPE_PROPERTY_CHANGED:
476+
result.Set("type", Value::String("propertyChanged"));
477+
result.Set("property", Value::Number(static_cast<double>(event.data.property_changed.property)));
478+
break;
475479
default:
476480
return Value::Null();
477481
}

‎bindings/python/nativeapi/__init__.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@
196196
WindowMaximizedEvent,
197197
WindowMinimizedEvent,
198198
WindowMovedEvent,
199+
WindowProperty,
200+
WindowPropertyChangedEvent,
199201
WindowResizedEvent,
200202
WindowRestoredEvent,
201203
)
@@ -352,6 +354,8 @@
352354
"WindowMaximizedEvent",
353355
"WindowMinimizedEvent",
354356
"WindowMovedEvent",
357+
"WindowProperty",
358+
"WindowPropertyChangedEvent",
355359
"WindowResizedEvent",
356360
"WindowRestoredEvent",
357361
"WindowShadow",

‎bindings/python/nativeapi/_capi.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ class native_window_event_close_requested_t(Structure):
137137
pass
138138

139139

140+
class native_window_event_property_changed_t(Structure):
141+
pass
142+
143+
140144
class native_window_event_data_t(Union):
141145
pass
142146

@@ -417,10 +421,14 @@ class native_window_list_t(Structure):
417421
native_window_event_close_requested_t._fields_ = [
418422
("request", c_uint64),
419423
]
424+
native_window_event_property_changed_t._fields_ = [
425+
("property", c_int),
426+
]
420427
native_window_event_data_t._fields_ = [
421428
("moved", native_window_event_moved_t),
422429
("resized", native_window_event_resized_t),
423430
("close_requested", native_window_event_close_requested_t),
431+
("property_changed", native_window_event_property_changed_t),
424432
]
425433
native_window_event_t._fields_ = [
426434
("type", c_int),

0 commit comments

Comments
 (0)