@gtkx/ffi 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/dist/codegen/ffi-generator.d.ts +8 -0
  2. package/dist/codegen/ffi-generator.js +100 -35
  3. package/dist/generated/gdk/content-provider.d.ts +1 -2
  4. package/dist/generated/gdk/content-provider.js +5 -7
  5. package/dist/generated/gdk/functions.d.ts +1 -1
  6. package/dist/generated/gdk/functions.js +5 -7
  7. package/dist/generated/gdk/monitor.d.ts +2 -2
  8. package/dist/generated/gdk/monitor.js +5 -7
  9. package/dist/generated/gdk/rectangle.d.ts +2 -3
  10. package/dist/generated/gdk/rectangle.js +10 -14
  11. package/dist/generated/gio/action-group.d.ts +1 -1
  12. package/dist/generated/gio/action-group.js +10 -1
  13. package/dist/generated/gio/application.d.ts +1 -1
  14. package/dist/generated/gio/application.js +10 -1
  15. package/dist/generated/gio/dbus-action-group.d.ts +1 -1
  16. package/dist/generated/gio/dbus-action-group.js +10 -1
  17. package/dist/generated/gio/dbus-connection.d.ts +2 -2
  18. package/dist/generated/gio/dbus-connection.js +4 -0
  19. package/dist/generated/gio/dbus-proxy.d.ts +2 -2
  20. package/dist/generated/gio/dbus-proxy.js +4 -0
  21. package/dist/generated/gio/dtls-connection.d.ts +2 -2
  22. package/dist/generated/gio/dtls-connection.js +5 -7
  23. package/dist/generated/gio/file-enumerator.d.ts +1 -1
  24. package/dist/generated/gio/file-enumerator.js +4 -0
  25. package/dist/generated/gio/file.d.ts +1 -1
  26. package/dist/generated/gio/file.js +1 -0
  27. package/dist/generated/gio/functions.d.ts +5 -4
  28. package/dist/generated/gio/functions.js +9 -7
  29. package/dist/generated/gio/menu-attribute-iter.d.ts +1 -1
  30. package/dist/generated/gio/menu-attribute-iter.js +4 -1
  31. package/dist/generated/gio/menu-link-iter.d.ts +1 -1
  32. package/dist/generated/gio/menu-link-iter.js +4 -1
  33. package/dist/generated/gio/simple-action-group.d.ts +1 -1
  34. package/dist/generated/gio/simple-action-group.js +10 -1
  35. package/dist/generated/gio/socket-listener.d.ts +5 -5
  36. package/dist/generated/gio/socket-listener.js +10 -0
  37. package/dist/generated/gio/socket.d.ts +3 -3
  38. package/dist/generated/gio/socket.js +6 -0
  39. package/dist/generated/gio/subprocess.d.ts +2 -2
  40. package/dist/generated/gio/subprocess.js +8 -0
  41. package/dist/generated/gio/task.d.ts +1 -2
  42. package/dist/generated/gio/task.js +5 -7
  43. package/dist/generated/gio/tls-connection.d.ts +2 -2
  44. package/dist/generated/gio/tls-connection.js +5 -7
  45. package/dist/generated/glib/bookmark-file.d.ts +1 -1
  46. package/dist/generated/glib/bookmark-file.js +2 -0
  47. package/dist/generated/glib/functions.d.ts +3 -3
  48. package/dist/generated/glib/functions.js +6 -0
  49. package/dist/generated/glib/regex.d.ts +5 -4
  50. package/dist/generated/glib/regex.js +12 -2
  51. package/dist/generated/gobject/closure.d.ts +1 -2
  52. package/dist/generated/gobject/closure.js +5 -7
  53. package/dist/generated/gobject/functions.d.ts +1 -1
  54. package/dist/generated/gobject/functions.js +1 -0
  55. package/dist/generated/graphene/box.d.ts +11 -10
  56. package/dist/generated/graphene/box.js +50 -70
  57. package/dist/generated/graphene/euler.d.ts +4 -5
  58. package/dist/generated/graphene/euler.js +20 -28
  59. package/dist/generated/graphene/matrix.d.ts +24 -23
  60. package/dist/generated/graphene/matrix.js +135 -189
  61. package/dist/generated/graphene/plane.d.ts +4 -5
  62. package/dist/generated/graphene/plane.js +20 -28
  63. package/dist/generated/graphene/point.d.ts +2 -2
  64. package/dist/generated/graphene/point.js +10 -14
  65. package/dist/generated/graphene/point3d.d.ts +7 -8
  66. package/dist/generated/graphene/point3d.js +35 -49
  67. package/dist/generated/graphene/quad.d.ts +1 -2
  68. package/dist/generated/graphene/quad.js +5 -7
  69. package/dist/generated/graphene/quaternion.d.ts +9 -9
  70. package/dist/generated/graphene/quaternion.js +45 -63
  71. package/dist/generated/graphene/ray.d.ts +4 -4
  72. package/dist/generated/graphene/ray.js +20 -28
  73. package/dist/generated/graphene/rect.d.ts +15 -15
  74. package/dist/generated/graphene/rect.js +75 -105
  75. package/dist/generated/graphene/size.d.ts +2 -3
  76. package/dist/generated/graphene/size.js +10 -14
  77. package/dist/generated/graphene/sphere.d.ts +4 -4
  78. package/dist/generated/graphene/sphere.js +15 -21
  79. package/dist/generated/graphene/triangle.d.ts +10 -9
  80. package/dist/generated/graphene/triangle.js +60 -84
  81. package/dist/generated/graphene/vec2.d.ts +10 -10
  82. package/dist/generated/graphene/vec2.js +50 -70
  83. package/dist/generated/graphene/vec3.d.ts +18 -16
  84. package/dist/generated/graphene/vec3.js +80 -112
  85. package/dist/generated/graphene/vec4.d.ts +12 -12
  86. package/dist/generated/graphene/vec4.js +60 -84
  87. package/dist/generated/gsk/functions.d.ts +2 -1
  88. package/dist/generated/gsk/functions.js +3 -1
  89. package/dist/generated/gsk/path-measure.d.ts +2 -2
  90. package/dist/generated/gsk/path-measure.js +5 -7
  91. package/dist/generated/gsk/path-point.d.ts +4 -4
  92. package/dist/generated/gsk/path-point.js +15 -21
  93. package/dist/generated/gsk/path.d.ts +6 -5
  94. package/dist/generated/gsk/path.js +25 -35
  95. package/dist/generated/gsk/render-node.d.ts +3 -3
  96. package/dist/generated/gsk/render-node.js +10 -14
  97. package/dist/generated/gsk/transform.d.ts +4 -4
  98. package/dist/generated/gsk/transform.js +18 -22
  99. package/dist/generated/gtk/bitset-iter.d.ts +3 -3
  100. package/dist/generated/gtk/bitset-iter.js +15 -21
  101. package/dist/generated/gtk/builder.d.ts +2 -3
  102. package/dist/generated/gtk/builder.js +10 -14
  103. package/dist/generated/gtk/cell-area.d.ts +3 -3
  104. package/dist/generated/gtk/cell-area.js +15 -21
  105. package/dist/generated/gtk/cell-renderer.d.ts +3 -2
  106. package/dist/generated/gtk/cell-renderer.js +15 -21
  107. package/dist/generated/gtk/color-button.d.ts +1 -2
  108. package/dist/generated/gtk/color-button.js +5 -7
  109. package/dist/generated/gtk/color-chooser-dialog.d.ts +1 -2
  110. package/dist/generated/gtk/color-chooser-dialog.js +5 -7
  111. package/dist/generated/gtk/color-chooser-widget.d.ts +1 -2
  112. package/dist/generated/gtk/color-chooser-widget.js +5 -7
  113. package/dist/generated/gtk/color-chooser.d.ts +1 -2
  114. package/dist/generated/gtk/color-chooser.js +5 -7
  115. package/dist/generated/gtk/column-view.d.ts +2 -2
  116. package/dist/generated/gtk/column-view.js +5 -7
  117. package/dist/generated/gtk/combo-box.d.ts +1 -2
  118. package/dist/generated/gtk/combo-box.js +5 -7
  119. package/dist/generated/gtk/entry.d.ts +1 -1
  120. package/dist/generated/gtk/entry.js +5 -7
  121. package/dist/generated/gtk/font-dialog.d.ts +2 -2
  122. package/dist/generated/gtk/functions.d.ts +5 -4
  123. package/dist/generated/gtk/functions.js +21 -22
  124. package/dist/generated/gtk/gesture.d.ts +1 -1
  125. package/dist/generated/gtk/gesture.js +5 -7
  126. package/dist/generated/gtk/icon-view.d.ts +9 -7
  127. package/dist/generated/gtk/icon-view.js +39 -25
  128. package/dist/generated/gtk/imcontext.d.ts +2 -1
  129. package/dist/generated/gtk/imcontext.js +1 -0
  130. package/dist/generated/gtk/list-base.d.ts +2 -2
  131. package/dist/generated/gtk/list-base.js +5 -7
  132. package/dist/generated/gtk/list-store.d.ts +13 -13
  133. package/dist/generated/gtk/list-store.js +65 -91
  134. package/dist/generated/gtk/overlay.js +1 -10
  135. package/dist/generated/gtk/popover.d.ts +1 -1
  136. package/dist/generated/gtk/popover.js +5 -7
  137. package/dist/generated/gtk/range.d.ts +2 -1
  138. package/dist/generated/gtk/range.js +5 -7
  139. package/dist/generated/gtk/recent-info.d.ts +1 -1
  140. package/dist/generated/gtk/recent-info.js +3 -1
  141. package/dist/generated/gtk/scrollable.d.ts +2 -2
  142. package/dist/generated/gtk/scrollable.js +5 -7
  143. package/dist/generated/gtk/style-context.d.ts +6 -6
  144. package/dist/generated/gtk/style-context.js +25 -35
  145. package/dist/generated/gtk/text-buffer.d.ts +10 -11
  146. package/dist/generated/gtk/text-buffer.js +60 -84
  147. package/dist/generated/gtk/text-iter.d.ts +2 -3
  148. package/dist/generated/gtk/text-iter.js +21 -29
  149. package/dist/generated/gtk/text-view.d.ts +8 -7
  150. package/dist/generated/gtk/text-view.js +40 -56
  151. package/dist/generated/gtk/text.d.ts +2 -1
  152. package/dist/generated/gtk/text.js +10 -14
  153. package/dist/generated/gtk/tree-model-filter.d.ts +9 -10
  154. package/dist/generated/gtk/tree-model-filter.js +45 -63
  155. package/dist/generated/gtk/tree-model-sort.d.ts +9 -9
  156. package/dist/generated/gtk/tree-model-sort.js +45 -63
  157. package/dist/generated/gtk/tree-model.d.ts +8 -8
  158. package/dist/generated/gtk/tree-model.js +35 -49
  159. package/dist/generated/gtk/tree-selection.d.ts +3 -2
  160. package/dist/generated/gtk/tree-selection.js +13 -9
  161. package/dist/generated/gtk/tree-store.d.ts +13 -13
  162. package/dist/generated/gtk/tree-store.js +65 -91
  163. package/dist/generated/gtk/tree-view.d.ts +11 -10
  164. package/dist/generated/gtk/tree-view.js +55 -40
  165. package/dist/generated/gtk/viewport.d.ts +2 -2
  166. package/dist/generated/gtk/viewport.js +5 -7
  167. package/dist/generated/gtk/widget.d.ts +6 -5
  168. package/dist/generated/gtk/widget.js +30 -42
  169. package/dist/generated/gtksource/buffer.d.ts +4 -4
  170. package/dist/generated/gtksource/buffer.js +12 -4
  171. package/dist/generated/gtksource/completion-context.d.ts +2 -2
  172. package/dist/generated/gtksource/completion-context.js +10 -14
  173. package/dist/generated/gtksource/gutter-lines.d.ts +1 -1
  174. package/dist/generated/gtksource/gutter-lines.js +5 -7
  175. package/dist/generated/gtksource/hover-context.d.ts +3 -3
  176. package/dist/generated/gtksource/hover-context.js +15 -21
  177. package/dist/generated/gtksource/indenter.d.ts +1 -1
  178. package/dist/generated/gtksource/indenter.js +2 -1
  179. package/dist/generated/gtksource/mark-attributes.d.ts +1 -2
  180. package/dist/generated/gtksource/mark-attributes.js +5 -7
  181. package/dist/generated/gtksource/region.d.ts +1 -1
  182. package/dist/generated/gtksource/region.js +10 -14
  183. package/dist/generated/gtksource/search-context.d.ts +4 -4
  184. package/dist/generated/gtksource/search-context.js +40 -56
  185. package/dist/generated/harfbuzz/functions.d.ts +16 -16
  186. package/dist/generated/harfbuzz/functions.js +100 -140
  187. package/dist/generated/pango/attr-iterator.d.ts +2 -1
  188. package/dist/generated/pango/attr-iterator.js +2 -0
  189. package/dist/generated/pango/functions.d.ts +7 -6
  190. package/dist/generated/pango/functions.js +24 -28
  191. package/dist/registry.d.ts +4 -4
  192. package/package.json +3 -3
@@ -107,10 +107,18 @@ export declare class CodeGenerator {
107
107
  private generateIndex;
108
108
  private generateParameterList;
109
109
  private generateCallArguments;
110
+ private identifyGtkAllocatesRefs;
111
+ private generateRefRewrapCode;
110
112
  private generateErrorArgument;
111
113
  private generateErrorCheck;
112
114
  private generateTypeDescriptor;
113
115
  private generateImports;
114
116
  private formatCode;
117
+ private generateCyclicTypeReturn;
118
+ /**
119
+ * Adds a catch-all signal handler overload.
120
+ * Uses `any` for TypeScript compatibility with typed overloads.
121
+ */
122
+ private addSignalCatchAllOverload;
115
123
  }
116
124
  export {};
@@ -201,7 +201,22 @@ const parseParentReference = (parent, classMap) => {
201
201
  }
202
202
  return { hasParent: false, isCrossNamespace: false, className: "", extendsClause: "" };
203
203
  };
204
- const hasOutParameter = (params) => params.some((p) => p.direction === "out" || p.direction === "inout");
204
+ const hasRefParameter = (params, typeMapper) => {
205
+ const savedSameNamespace = typeMapper.getSameNamespaceClassUsageCallback();
206
+ const savedExternal = typeMapper.getExternalTypeUsageCallback();
207
+ const savedRecord = typeMapper.getRecordUsageCallback();
208
+ const savedEnum = typeMapper.getEnumUsageCallback();
209
+ typeMapper.setSameNamespaceClassUsageCallback(null);
210
+ typeMapper.setExternalTypeUsageCallback(null);
211
+ typeMapper.setRecordUsageCallback(null);
212
+ typeMapper.setEnumUsageCallback(null);
213
+ const result = params.some((p) => typeMapper.mapParameter(p).ts.startsWith("Ref<"));
214
+ typeMapper.setSameNamespaceClassUsageCallback(savedSameNamespace);
215
+ typeMapper.setExternalTypeUsageCallback(savedExternal);
216
+ typeMapper.setRecordUsageCallback(savedRecord);
217
+ typeMapper.setEnumUsageCallback(savedEnum);
218
+ return result;
219
+ };
205
220
  const isVararg = (param) => param.name === "..." || param.name === "";
206
221
  const cTypeToGetTypeFunc = (cType) => {
207
222
  const snakeCase = cType.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
@@ -385,10 +400,10 @@ export class CodeGenerator {
385
400
  const syncMethods = filteredClassMethods.filter((m) => !asyncMethods.has(m.name) && !finishMethods.has(m.name));
386
401
  const syncInterfaceMethods = interfaceMethods.filter((m) => !asyncMethods.has(m.name) && !finishMethods.has(m.name));
387
402
  this.usesRef =
388
- syncMethods.some((m) => hasOutParameter(m.parameters)) ||
389
- cls.constructors.some((c) => hasOutParameter(c.parameters)) ||
390
- cls.functions.some((f) => hasOutParameter(f.parameters)) ||
391
- syncInterfaceMethods.some((m) => hasOutParameter(m.parameters));
403
+ syncMethods.some((m) => hasRefParameter(m.parameters, this.typeMapper)) ||
404
+ cls.constructors.some((c) => hasRefParameter(c.parameters, this.typeMapper)) ||
405
+ cls.functions.some((f) => hasRefParameter(f.parameters, this.typeMapper)) ||
406
+ syncInterfaceMethods.some((m) => hasRefParameter(m.parameters, this.typeMapper));
392
407
  const hasNonVarargConstructor = cls.constructors.some((c) => !c.parameters.some(isVararg));
393
408
  const needsGObjectNewFallback = !hasNonVarargConstructor && !!cls.parent && !!cls.cType;
394
409
  this.usesCall =
@@ -735,6 +750,7 @@ ${args}
735
750
  const resultVarName = hasResultParam ? "_result" : "result";
736
751
  const needsCast = rawReturnType !== "void" && rawReturnType !== "unknown";
737
752
  const hasReturnValue = rawReturnType !== "void";
753
+ const gtkAllocatesRefs = this.identifyGtkAllocatesRefs(func.parameters);
738
754
  const lines = [];
739
755
  const funcDoc = formatMethodDoc(func.doc, func.parameters);
740
756
  if (funcDoc) {
@@ -760,10 +776,13 @@ ${allArgs ? `${allArgs},` : ""}
760
776
  if (func.throws) {
761
777
  lines.push(this.generateErrorCheck());
762
778
  }
779
+ lines.push(...this.generateRefRewrapCode(gtkAllocatesRefs));
763
780
  lines.push(` return getObject(ptr) as ${className};`);
764
781
  }
765
782
  else {
766
- const callPrefix = func.throws
783
+ const hasRefRewrap = gtkAllocatesRefs.length > 0;
784
+ const needsResultVar = func.throws || hasRefRewrap;
785
+ const callPrefix = needsResultVar
767
786
  ? hasReturnValue
768
787
  ? `const ${resultVarName} = `
769
788
  : ""
@@ -780,9 +799,10 @@ ${allArgs ? `${allArgs},` : ""}
780
799
  )${needsCast ? ` as ${rawReturnType}` : ""};`);
781
800
  if (func.throws) {
782
801
  lines.push(this.generateErrorCheck());
783
- if (hasReturnValue) {
784
- lines.push(` return ${resultVarName};`);
785
- }
802
+ }
803
+ lines.push(...this.generateRefRewrapCode(gtkAllocatesRefs));
804
+ if (needsResultVar && hasReturnValue) {
805
+ lines.push(` return ${resultVarName};`);
786
806
  }
787
807
  }
788
808
  lines.push(` }`);
@@ -828,12 +848,6 @@ ${allArgs ? `${allArgs},` : ""}
828
848
  const finishMethod = this.findFinishMethod(method, allMethods);
829
849
  if (!finishMethod)
830
850
  return null;
831
- let methodName = toCamelCase(method.name);
832
- if (className) {
833
- const renamed = getRenamedMethod(this.options.namespace, className, methodName);
834
- if (renamed)
835
- methodName = renamed;
836
- }
837
851
  const paramsWithoutCallback = method.parameters.filter((p, i) => !isVararg(p) &&
838
852
  p.type.name !== "Gio.AsyncReadyCallback" &&
839
853
  !this.typeMapper.isClosureTarget(i, method.parameters));
@@ -849,6 +863,12 @@ ${allArgs ? `${allArgs},` : ""}
849
863
  if (hasRequiredAfterOptional) {
850
864
  return null;
851
865
  }
866
+ let methodName = toCamelCase(method.name);
867
+ if (className) {
868
+ const renamed = getRenamedMethod(this.options.namespace, className, methodName);
869
+ if (renamed)
870
+ methodName = renamed;
871
+ }
852
872
  const params = paramsWithoutCallback
853
873
  .map((p) => {
854
874
  const mapped = this.typeMapper.mapParameter(p);
@@ -1072,7 +1092,7 @@ ${allArgs ? `${allArgs},` : ""}
1072
1092
  returnTypeMapping.ffi.itemType?.type === "gobject" &&
1073
1093
  baseReturnType.endsWith("[]");
1074
1094
  const hasReturnValue = returnTypeMapping.ts !== "void";
1075
- // For records (boxed types), use "boxed" type with innerType; for classes, use "gobject"
1095
+ const gtkAllocatesRefs = this.identifyGtkAllocatesRefs(method.parameters);
1076
1096
  const selfTypeDescriptor = isRecord && className
1077
1097
  ? `{ type: "boxed", borrowed: true, innerType: "${className}", lib: "${sharedLibrary}" }`
1078
1098
  : `{ type: "gobject" }`;
@@ -1105,13 +1125,12 @@ ${allArgs ? `${allArgs},` : ""}
1105
1125
  if (method.throws) {
1106
1126
  lines.push(this.generateErrorCheck());
1107
1127
  }
1128
+ lines.push(...this.generateRefRewrapCode(gtkAllocatesRefs));
1108
1129
  if (isNullable) {
1109
1130
  lines.push(` if (ptr === null) return null;`);
1110
1131
  }
1111
1132
  if (isCyclic) {
1112
- // For cyclic types, return a minimal NativeObject wrapper. Cast is necessary
1113
- // because the full type interface isn't available without circular imports.
1114
- lines.push(` return { id: ptr } as unknown as ${baseReturnType};`);
1133
+ lines.push(this.generateCyclicTypeReturn(baseReturnType));
1115
1134
  }
1116
1135
  else {
1117
1136
  this.usesGetObject = true;
@@ -1136,10 +1155,13 @@ ${allArgs ? `${allArgs},` : ""}
1136
1155
  if (method.throws) {
1137
1156
  lines.push(this.generateErrorCheck());
1138
1157
  }
1158
+ lines.push(...this.generateRefRewrapCode(gtkAllocatesRefs));
1139
1159
  lines.push(` return ptrs.map(ptr => getObject(ptr) as ${elementType});`);
1140
1160
  }
1141
1161
  else {
1142
- const callPrefix = method.throws
1162
+ const hasRefRewrap = gtkAllocatesRefs.length > 0;
1163
+ const needsResultVar = method.throws || hasRefRewrap;
1164
+ const callPrefix = needsResultVar
1143
1165
  ? hasReturnValue
1144
1166
  ? `const ${resultVarName} = `
1145
1167
  : ""
@@ -1161,9 +1183,10 @@ ${allArgs ? `${allArgs},` : ""}
1161
1183
  )${needsCast ? ` as ${tsReturnType}` : ""};`);
1162
1184
  if (method.throws) {
1163
1185
  lines.push(this.generateErrorCheck());
1164
- if (hasReturnValue) {
1165
- lines.push(` return ${resultVarName};`);
1166
- }
1186
+ }
1187
+ lines.push(...this.generateRefRewrapCode(gtkAllocatesRefs));
1188
+ if (needsResultVar && hasReturnValue) {
1189
+ lines.push(` return ${resultVarName};`);
1167
1190
  }
1168
1191
  }
1169
1192
  lines.push(` }`);
@@ -1263,9 +1286,7 @@ ${allArgs ? `${allArgs},` : ""}
1263
1286
  kind: "class",
1264
1287
  });
1265
1288
  }
1266
- // Signal handler catch-all overload must use `any` for compatibility with typed overloads.
1267
- // The typed overloads have specific return types, and unknown is not assignable to them.
1268
- signalOverloads.push(` ${methodName}(signal: string, handler: (...args: any[]) => any, after?: boolean): number;`);
1289
+ this.addSignalCatchAllOverload(signalOverloads, methodName);
1269
1290
  this.usesType = true;
1270
1291
  this.usesGetObject = true;
1271
1292
  if (signalMetadata.length > 0) {
@@ -1323,7 +1344,7 @@ ${allArgs ? `${allArgs},` : ""}
1323
1344
  const interfaceName = toPascalCase(iface.name);
1324
1345
  const sections = [];
1325
1346
  this.usesCall = iface.methods.length > 0;
1326
- this.usesRef = iface.methods.some((m) => hasOutParameter(m.parameters));
1347
+ this.usesRef = iface.methods.some((m) => hasRefParameter(m.parameters, this.typeMapper));
1327
1348
  if (iface.doc) {
1328
1349
  sections.push(formatDoc(iface.doc));
1329
1350
  }
@@ -1350,9 +1371,9 @@ ${allArgs ? `${allArgs},` : ""}
1350
1371
  async generateRecord(record, sharedLibrary) {
1351
1372
  this.resetState();
1352
1373
  this.usesRef =
1353
- record.methods.some((m) => hasOutParameter(m.parameters)) ||
1354
- record.constructors.some((c) => hasOutParameter(c.parameters)) ||
1355
- record.functions.some((f) => hasOutParameter(f.parameters));
1374
+ record.methods.some((m) => hasRefParameter(m.parameters, this.typeMapper)) ||
1375
+ record.constructors.some((c) => hasRefParameter(c.parameters, this.typeMapper)) ||
1376
+ record.functions.some((f) => hasRefParameter(f.parameters, this.typeMapper));
1356
1377
  this.usesCall = record.methods.length > 0 || record.constructors.length > 0 || record.functions.length > 0;
1357
1378
  const hasReadableFields = record.fields.some((f) => f.readable !== false && !f.private);
1358
1379
  if (hasReadableFields) {
@@ -1671,7 +1692,7 @@ ${args}
1671
1692
  }
1672
1693
  async generateFunctions(functions, sharedLibrary) {
1673
1694
  this.resetState();
1674
- this.usesRef = functions.some((f) => hasOutParameter(f.parameters));
1695
+ this.usesRef = functions.some((f) => hasRefParameter(f.parameters, this.typeMapper));
1675
1696
  this.usesCall = functions.length > 0;
1676
1697
  const sections = [];
1677
1698
  for (const func of functions) {
@@ -1694,6 +1715,7 @@ ${args}
1694
1715
  returnTypeMapping.ts !== "unknown" &&
1695
1716
  returnTypeMapping.kind !== "interface";
1696
1717
  const hasReturnValue = returnTypeMapping.ts !== "void";
1718
+ const gtkAllocatesRefs = this.identifyGtkAllocatesRefs(func.parameters);
1697
1719
  const lines = [];
1698
1720
  const funcDoc = formatMethodDoc(func.doc, func.parameters, "");
1699
1721
  if (funcDoc) {
@@ -1706,6 +1728,7 @@ ${args}
1706
1728
  const args = this.generateCallArguments(func.parameters, " ");
1707
1729
  const errorArg = func.throws ? this.generateErrorArgument(" ") : "";
1708
1730
  const allArgs = errorArg ? args + (args ? ",\n" : "") + errorArg : args;
1731
+ const refRewrapCode = this.generateRefRewrapCode(gtkAllocatesRefs).map((line) => line.replace(/^ {4}/, " "));
1709
1732
  if (needsObjectWrap && hasReturnValue) {
1710
1733
  this.usesGetObject = true;
1711
1734
  lines.push(` const ptr = call("${sharedLibrary}", "${func.cIdentifier}", [
@@ -1714,13 +1737,16 @@ ${allArgs ? `${allArgs},` : ""}
1714
1737
  if (func.throws) {
1715
1738
  lines.push(this.generateErrorCheck(""));
1716
1739
  }
1740
+ lines.push(...refRewrapCode);
1717
1741
  if (isNullable) {
1718
1742
  lines.push(` if (ptr === null) return null;`);
1719
1743
  }
1720
1744
  lines.push(` return getObject(ptr) as ${baseReturnType};`);
1721
1745
  }
1722
1746
  else {
1723
- const callPrefix = func.throws
1747
+ const hasRefRewrap = gtkAllocatesRefs.length > 0;
1748
+ const needsResultVar = func.throws || hasRefRewrap;
1749
+ const callPrefix = needsResultVar
1724
1750
  ? hasReturnValue
1725
1751
  ? `const ${resultVarName} = `
1726
1752
  : ""
@@ -1733,9 +1759,10 @@ ${allArgs ? `${allArgs},` : ""}
1733
1759
  ], ${this.generateTypeDescriptor(returnTypeMapping.ffi)})${needsCast ? ` as ${returnTypeMapping.ts}` : ""};`);
1734
1760
  if (func.throws) {
1735
1761
  lines.push(this.generateErrorCheck(""));
1736
- if (hasReturnValue) {
1737
- lines.push(` return ${resultVarName};`);
1738
- }
1762
+ }
1763
+ lines.push(...refRewrapCode);
1764
+ if (needsResultVar && hasReturnValue) {
1765
+ lines.push(` return ${resultVarName};`);
1739
1766
  }
1740
1767
  }
1741
1768
  lines.push(`};`);
@@ -1790,6 +1817,34 @@ ${allArgs ? `${allArgs},` : ""}
1790
1817
  })
1791
1818
  .join(",\n");
1792
1819
  }
1820
+ identifyGtkAllocatesRefs(parameters) {
1821
+ return parameters
1822
+ .filter((p, i) => !isVararg(p) && !this.typeMapper.isClosureTarget(i, parameters))
1823
+ .map((param) => {
1824
+ const mapped = this.typeMapper.mapParameter(param);
1825
+ if (mapped.ffi.type === "ref" &&
1826
+ typeof mapped.ffi.innerType === "object" &&
1827
+ (mapped.ffi.innerType.type === "boxed" || mapped.ffi.innerType.type === "gobject")) {
1828
+ const innerTsType = mapped.ts.slice(4, -1);
1829
+ return {
1830
+ paramName: toValidIdentifier(toCamelCase(param.name)),
1831
+ innerType: innerTsType,
1832
+ nullable: this.typeMapper.isNullable(param),
1833
+ };
1834
+ }
1835
+ return null;
1836
+ })
1837
+ .filter((x) => x !== null);
1838
+ }
1839
+ generateRefRewrapCode(gtkAllocatesRefs) {
1840
+ if (gtkAllocatesRefs.length === 0) {
1841
+ return [];
1842
+ }
1843
+ this.usesGetObject = true;
1844
+ return gtkAllocatesRefs.map((ref) => ref.nullable
1845
+ ? ` if (${ref.paramName}) ${ref.paramName}.value = getObject(${ref.paramName}.value) as ${ref.innerType};`
1846
+ : ` ${ref.paramName}.value = getObject(${ref.paramName}.value) as ${ref.innerType};`);
1847
+ }
1793
1848
  generateErrorArgument(indent = " ") {
1794
1849
  return `${indent} {\n${indent} type: { type: "ref", innerType: { type: "boxed", innerType: "GError", lib: "libglib-2.0.so.0" } },\n${indent} value: error,\n${indent} }`;
1795
1850
  }
@@ -1952,4 +2007,14 @@ ${indent} }`;
1952
2007
  return code;
1953
2008
  }
1954
2009
  }
2010
+ generateCyclicTypeReturn(baseReturnType) {
2011
+ return ` return { id: ptr } as unknown as ${baseReturnType};`;
2012
+ }
2013
+ /**
2014
+ * Adds a catch-all signal handler overload.
2015
+ * Uses `any` for TypeScript compatibility with typed overloads.
2016
+ */
2017
+ addSignalCatchAllOverload(signalOverloads, methodName) {
2018
+ signalOverloads.push(` ${methodName}(signal: string, handler: (...args: any[]) => any, after?: boolean): number;`);
2019
+ }
1955
2020
  }
@@ -1,4 +1,3 @@
1
- import { Ref } from "@gtkx/native";
2
1
  import { ContentFormats } from "./content-formats.js";
3
2
  import * as GLib from "../glib/index.js";
4
3
  import * as GObject from "../gobject/index.js";
@@ -53,7 +52,7 @@ export declare class ContentProvider extends GObject.GObject {
53
52
  * `G_IO_ERROR_NOT_SUPPORTED` will be reported.
54
53
  * @param value - the `GValue` to fill
55
54
  */
56
- getValue(value: Ref<unknown>): boolean;
55
+ getValue(value: GObject.Value): boolean;
57
56
  /**
58
57
  * Gets the formats that the provider can provide its current contents in.
59
58
  */
@@ -118,14 +118,12 @@ export class ContentProvider extends GObject.GObject {
118
118
  },
119
119
  {
120
120
  type: {
121
- type: "ref",
122
- innerType: {
123
- type: "boxed",
124
- innerType: "GValue",
125
- lib: "libgtk-4.so.1",
126
- },
121
+ type: "boxed",
122
+ borrowed: true,
123
+ innerType: "GValue",
124
+ lib: "libgtk-4.so.1",
127
125
  },
128
- value: value,
126
+ value: value?.id ?? value,
129
127
  },
130
128
  {
131
129
  type: {
@@ -159,7 +159,7 @@ export declare const contentDeserializeAsync: (stream: Gio.InputStream, mimeType
159
159
  * @param result - the `GAsyncResult`
160
160
  * @param value - return location for the result of the operation
161
161
  */
162
- export declare const contentDeserializeFinish: (result: Gio.AsyncResult, value: Ref<unknown>) => boolean;
162
+ export declare const contentDeserializeFinish: (result: Gio.AsyncResult, value: GObject.Value) => boolean;
163
163
  /**
164
164
  * Parses the given `string` into `GdkContentFormats` and
165
165
  * returns the formats.
@@ -386,14 +386,12 @@ export const contentDeserializeFinish = (result, value) => {
386
386
  },
387
387
  {
388
388
  type: {
389
- type: "ref",
390
- innerType: {
391
- type: "boxed",
392
- innerType: "GValue",
393
- lib: "libgtk-4.so.1",
394
- },
389
+ type: "boxed",
390
+ borrowed: true,
391
+ innerType: "GValue",
392
+ lib: "libgtk-4.so.1",
395
393
  },
396
- value: value,
394
+ value: value?.id ?? value,
397
395
  },
398
396
  {
399
397
  type: {
@@ -1,5 +1,5 @@
1
- import { Ref } from "@gtkx/native";
2
1
  import { SubpixelLayout } from "./enums.js";
2
+ import { Rectangle } from "./rectangle.js";
3
3
  import { Display } from "./display.js";
4
4
  import * as GObject from "../gobject/index.js";
5
5
  export declare class Monitor extends GObject.GObject {
@@ -32,7 +32,7 @@ export declare class Monitor extends GObject.GObject {
32
32
  * ”device pixels” (see [method@Gdk.Monitor.get_scale]).
33
33
  * @param geometry - a `GdkRectangle` to be filled with the monitor geometry
34
34
  */
35
- getGeometry(geometry: Ref<unknown>): void;
35
+ getGeometry(geometry: Rectangle): void;
36
36
  /**
37
37
  * Gets the height in millimeters of the monitor.
38
38
  */
@@ -83,14 +83,12 @@ export class Monitor extends GObject.GObject {
83
83
  },
84
84
  {
85
85
  type: {
86
- type: "ref",
87
- innerType: {
88
- type: "boxed",
89
- innerType: "GdkRectangle",
90
- lib: "libgtk-4.so.1",
91
- },
86
+ type: "boxed",
87
+ borrowed: true,
88
+ innerType: "GdkRectangle",
89
+ lib: "libgtk-4.so.1",
92
90
  },
93
- value: geometry,
91
+ value: geometry?.id ?? geometry,
94
92
  },
95
93
  ], { type: "undefined" });
96
94
  }
@@ -1,4 +1,3 @@
1
- import { Ref } from "@gtkx/native";
2
1
  export interface RectangleInit {
3
2
  x?: number;
4
3
  y?: number;
@@ -49,7 +48,7 @@ export declare class Rectangle {
49
48
  * @param src2 - a `GdkRectangle`
50
49
  * @param dest - return location for the
51
50
  */
52
- intersect(src2: Rectangle, dest?: Ref<unknown> | null): boolean;
51
+ intersect(src2: Rectangle, dest?: Rectangle | null): boolean;
53
52
  /**
54
53
  * Calculates the union of two rectangles.
55
54
  *
@@ -62,7 +61,7 @@ export declare class Rectangle {
62
61
  * @param src2 - a `GdkRectangle`
63
62
  * @param dest - return location for the union of `src1` and @src2
64
63
  */
65
- union(src2: Rectangle, dest: Ref<unknown>): void;
64
+ union(src2: Rectangle, dest: Rectangle): void;
66
65
  /** the x coordinate of the top left corner */
67
66
  get x(): number;
68
67
  set x(value: number);
@@ -120,14 +120,12 @@ export class Rectangle {
120
120
  },
121
121
  {
122
122
  type: {
123
- type: "ref",
124
- innerType: {
125
- type: "boxed",
126
- innerType: "GdkRectangle",
127
- lib: "libgtk-4.so.1",
128
- },
123
+ type: "boxed",
124
+ borrowed: true,
125
+ innerType: "GdkRectangle",
126
+ lib: "libgtk-4.so.1",
129
127
  },
130
- value: dest,
128
+ value: dest?.id ?? dest,
131
129
  optional: true,
132
130
  },
133
131
  ], { type: "boolean" });
@@ -166,14 +164,12 @@ export class Rectangle {
166
164
  },
167
165
  {
168
166
  type: {
169
- type: "ref",
170
- innerType: {
171
- type: "boxed",
172
- innerType: "GdkRectangle",
173
- lib: "libgtk-4.so.1",
174
- },
167
+ type: "boxed",
168
+ borrowed: true,
169
+ innerType: "GdkRectangle",
170
+ lib: "libgtk-4.so.1",
175
171
  },
176
- value: dest,
172
+ value: dest?.id ?? dest,
177
173
  },
178
174
  ], { type: "undefined" });
179
175
  }
@@ -261,5 +261,5 @@ export declare class ActionGroup {
261
261
  * @param stateHint - the state hint, or `NULL` if none
262
262
  * @param state - the current state, or `NULL` if stateless
263
263
  */
264
- queryAction(actionName: string, enabled: Ref<boolean>, parameterType?: Ref<unknown> | null, stateType?: Ref<unknown> | null, stateHint?: Ref<unknown> | null, state?: Ref<unknown> | null): boolean;
264
+ queryAction(actionName: string, enabled: Ref<boolean>, parameterType?: Ref<GLib.VariantType> | null, stateType?: Ref<GLib.VariantType> | null, stateHint?: Ref<GLib.Variant> | null, state?: Ref<GLib.Variant> | null): boolean;
265
265
  }
@@ -468,7 +468,7 @@ export class ActionGroup {
468
468
  * @param state - the current state, or `NULL` if stateless
469
469
  */
470
470
  queryAction(actionName, enabled, parameterType, stateType, stateHint, state) {
471
- return call("libgio-2.0.so.0", "g_action_group_query_action", [
471
+ const result = call("libgio-2.0.so.0", "g_action_group_query_action", [
472
472
  {
473
473
  type: { type: "gobject" },
474
474
  value: this.id,
@@ -530,5 +530,14 @@ export class ActionGroup {
530
530
  optional: true,
531
531
  },
532
532
  ], { type: "boolean" });
533
+ if (parameterType)
534
+ parameterType.value = getObject(parameterType.value);
535
+ if (stateType)
536
+ stateType.value = getObject(stateType.value);
537
+ if (stateHint)
538
+ stateHint.value = getObject(stateHint.value);
539
+ if (state)
540
+ state.value = getObject(state.value);
541
+ return result;
533
542
  }
534
543
  }
@@ -879,7 +879,7 @@ export declare class Application extends GObject.GObject {
879
879
  * @param stateHint - the state hint, or `NULL` if none
880
880
  * @param state - the current state, or `NULL` if stateless
881
881
  */
882
- queryAction(actionName: string, enabled: Ref<boolean>, parameterType?: Ref<unknown> | null, stateType?: Ref<unknown> | null, stateHint?: Ref<unknown> | null, state?: Ref<unknown> | null): boolean;
882
+ queryAction(actionName: string, enabled: Ref<boolean>, parameterType?: Ref<GLib.VariantType> | null, stateType?: Ref<GLib.VariantType> | null, stateHint?: Ref<GLib.Variant> | null, state?: Ref<GLib.Variant> | null): boolean;
883
883
  /**
884
884
  * Adds an action to the @action_map.
885
885
  *
@@ -1655,7 +1655,7 @@ export class Application extends GObject.GObject {
1655
1655
  * @param state - the current state, or `NULL` if stateless
1656
1656
  */
1657
1657
  queryAction(actionName, enabled, parameterType, stateType, stateHint, state) {
1658
- return call("libgio-2.0.so.0", "g_action_group_query_action", [
1658
+ const result = call("libgio-2.0.so.0", "g_action_group_query_action", [
1659
1659
  {
1660
1660
  type: { type: "gobject" },
1661
1661
  value: this.id,
@@ -1717,6 +1717,15 @@ export class Application extends GObject.GObject {
1717
1717
  optional: true,
1718
1718
  },
1719
1719
  ], { type: "boolean" });
1720
+ if (parameterType)
1721
+ parameterType.value = getObject(parameterType.value);
1722
+ if (stateType)
1723
+ stateType.value = getObject(stateType.value);
1724
+ if (stateHint)
1725
+ stateHint.value = getObject(stateHint.value);
1726
+ if (state)
1727
+ state.value = getObject(state.value);
1728
+ return result;
1720
1729
  }
1721
1730
  /**
1722
1731
  * Adds an action to the @action_map.
@@ -242,7 +242,7 @@ export declare class DBusActionGroup extends GObject.GObject {
242
242
  * @param stateHint - the state hint, or `NULL` if none
243
243
  * @param state - the current state, or `NULL` if stateless
244
244
  */
245
- queryAction(actionName: string, enabled: Ref<boolean>, parameterType?: Ref<unknown> | null, stateType?: Ref<unknown> | null, stateHint?: Ref<unknown> | null, state?: Ref<unknown> | null): boolean;
245
+ queryAction(actionName: string, enabled: Ref<boolean>, parameterType?: Ref<GLib.VariantType> | null, stateType?: Ref<GLib.VariantType> | null, stateHint?: Ref<GLib.Variant> | null, state?: Ref<GLib.Variant> | null): boolean;
246
246
  /**
247
247
  * Activates the remote action.
248
248
  *
@@ -473,7 +473,7 @@ export class DBusActionGroup extends GObject.GObject {
473
473
  * @param state - the current state, or `NULL` if stateless
474
474
  */
475
475
  queryAction(actionName, enabled, parameterType, stateType, stateHint, state) {
476
- return call("libgio-2.0.so.0", "g_action_group_query_action", [
476
+ const result = call("libgio-2.0.so.0", "g_action_group_query_action", [
477
477
  {
478
478
  type: { type: "gobject" },
479
479
  value: this.id,
@@ -535,6 +535,15 @@ export class DBusActionGroup extends GObject.GObject {
535
535
  optional: true,
536
536
  },
537
537
  ], { type: "boolean" });
538
+ if (parameterType)
539
+ parameterType.value = getObject(parameterType.value);
540
+ if (stateType)
541
+ stateType.value = getObject(stateType.value);
542
+ if (stateHint)
543
+ stateHint.value = getObject(stateHint.value);
544
+ if (state)
545
+ state.value = getObject(state.value);
546
+ return result;
538
547
  }
539
548
  /**
540
549
  * Activates the remote action.
@@ -321,7 +321,7 @@ export declare class DBusConnection extends GObject.GObject {
321
321
  * @param outFdList - return location for a #GUnixFDList or %NULL
322
322
  * @param res - a #GAsyncResult obtained from the #GAsyncReadyCallback passed to
323
323
  */
324
- callWithUnixFdListFinish(res: AsyncResult, outFdList?: Ref<unknown> | null): GLib.Variant;
324
+ callWithUnixFdListFinish(res: AsyncResult, outFdList?: Ref<UnixFDList> | null): GLib.Variant;
325
325
  /**
326
326
  * Like g_dbus_connection_call_sync() but also takes and returns #GUnixFDList objects.
327
327
  * See g_dbus_connection_call_with_unix_fd_list() and
@@ -340,7 +340,7 @@ export declare class DBusConnection extends GObject.GObject {
340
340
  * @param outFdList - return location for a #GUnixFDList or %NULL
341
341
  * @param cancellable - a #GCancellable or %NULL
342
342
  */
343
- callWithUnixFdListSync(objectPath: string, interfaceName: string, methodName: string, flags: DBusCallFlags, timeoutMsec: number, busName?: string | null, parameters?: GLib.Variant | null, replyType?: GLib.VariantType | null, fdList?: UnixFDList | null, outFdList?: Ref<unknown> | null, cancellable?: Cancellable | null): GLib.Variant;
343
+ callWithUnixFdListSync(objectPath: string, interfaceName: string, methodName: string, flags: DBusCallFlags, timeoutMsec: number, busName?: string | null, parameters?: GLib.Variant | null, replyType?: GLib.VariantType | null, fdList?: UnixFDList | null, outFdList?: Ref<UnixFDList> | null, cancellable?: Cancellable | null): GLib.Variant;
344
344
  /**
345
345
  * Closes @connection. Note that this never causes the process to
346
346
  * exit (this might only happen if the other end of a shared message
@@ -806,6 +806,8 @@ export class DBusConnection extends GObject.GObject {
806
806
  if (error.value !== null) {
807
807
  throw new NativeError(error.value);
808
808
  }
809
+ if (outFdList)
810
+ outFdList.value = getObject(outFdList.value);
809
811
  return getObject(ptr);
810
812
  }
811
813
  /**
@@ -913,6 +915,8 @@ export class DBusConnection extends GObject.GObject {
913
915
  if (error.value !== null) {
914
916
  throw new NativeError(error.value);
915
917
  }
918
+ if (outFdList)
919
+ outFdList.value = getObject(outFdList.value);
916
920
  return getObject(ptr);
917
921
  }
918
922
  /**
@@ -239,7 +239,7 @@ export declare class DBusProxy extends GObject.GObject {
239
239
  * @param outFdList - Return location for a #GUnixFDList or %NULL.
240
240
  * @param res - A #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_proxy_call_with_unix_fd_list().
241
241
  */
242
- callWithUnixFdListFinish(res: AsyncResult, outFdList?: Ref<unknown> | null): GLib.Variant;
242
+ callWithUnixFdListFinish(res: AsyncResult, outFdList?: Ref<UnixFDList> | null): GLib.Variant;
243
243
  /**
244
244
  * Like g_dbus_proxy_call_sync() but also takes and returns #GUnixFDList objects.
245
245
  *
@@ -252,7 +252,7 @@ export declare class DBusProxy extends GObject.GObject {
252
252
  * @param outFdList - Return location for a #GUnixFDList or %NULL.
253
253
  * @param cancellable - A #GCancellable or %NULL.
254
254
  */
255
- callWithUnixFdListSync(methodName: string, flags: DBusCallFlags, timeoutMsec: number, parameters?: GLib.Variant | null, fdList?: UnixFDList | null, outFdList?: Ref<unknown> | null, cancellable?: Cancellable | null): GLib.Variant;
255
+ callWithUnixFdListSync(methodName: string, flags: DBusCallFlags, timeoutMsec: number, parameters?: GLib.Variant | null, fdList?: UnixFDList | null, outFdList?: Ref<UnixFDList> | null, cancellable?: Cancellable | null): GLib.Variant;
256
256
  /**
257
257
  * Looks up the value for a property from the cache. This call does no
258
258
  * blocking IO.