@@ -275,11 +275,24 @@ export default class EntryAbility extends RustAbility {
275275 });
276276 RustModule.registerArktsFunction('set_decorations_ohos', async (err: Error, arg: string): Promise<string> => {
277277 const req: SetDecorationsArg = JSON.parse(arg);
278+ const mainWin = windowStage.getMainWindowSync();
278279 try {
279- await windowStage.getMainWindowSync().setWindowDecorVisible(req.visible);
280+ // Showing native title buttons makes HarmonyOS fall back to hover-only
281+ // window decorations. Re-apply the same custom title-bar configuration
282+ // used at startup after restoring the buttons.
283+ await mainWin.setWindowTitleButtonVisible(
284+ req.visible,
285+ req.visible,
286+ req.visible,
287+ );
288+ if (req.visible) {
289+ mainWin.setWindowDecorHeight(44);
290+ mainWin.setWindowTitleMoveEnabled(false);
291+ mainWin.setWindowDecorVisible(false);
292+ }
280293 } catch (e) {
281294 const be = e as BusinessError;
282- hilog.warn(DOMAIN, TAG, `setWindowDecorVisible failed: ${be.message}`);
295+ hilog.warn(DOMAIN, TAG, `setWindowTitleButtonVisible failed: ${be.message}`);
283296 }
284297 return '';
285298 });
@@ -334,17 +347,27 @@ export default class EntryAbility extends RustAbility {
334347 dispWidth = disp.width;
335348 dispHeight = disp.height;
336349 scale = disp.densityPixels > 0 ? disp.densityPixels : 1;
350+ // A floating window may not intersect the system bar when this query
351+ // runs, in which case getWindowAvoidArea() reports zero. The display's
352+ // available bounds still exclude the desktop bar, so keep that
353+ // right/bottom reservation as a monitor-level fallback.
354+ if (disp.availableWidth > 0 && disp.availableWidth <= disp.width) {
355+ avoidRight = Math.max(avoidRight, disp.width - disp.availableWidth);
356+ }
357+ if (disp.availableHeight > 0 && disp.availableHeight <= disp.height) {
358+ avoidBottom = Math.max(avoidBottom, disp.height - disp.availableHeight);
359+ }
337360 } catch (e) {
338361 const be = e as BusinessError;
339362 hilog.warn(DOMAIN, TAG, `getDefaultDisplaySync failed: ${be.message}`);
340363 }
341364 try {
342365 const avoidArea = windowStage.getMainWindowSync()
343366 .getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
344- avoidTop = avoidArea.topRect.height;
345- avoidBottom = avoidArea.bottomRect.height;
346- avoidLeft = avoidArea.leftRect.width;
347- avoidRight = avoidArea.rightRect.width;
367+ avoidTop = Math.max(avoidTop, avoidArea.topRect.height) ;
368+ avoidBottom = Math.max(avoidBottom, avoidArea.bottomRect.height) ;
369+ avoidLeft = Math.max(avoidLeft, avoidArea.leftRect.width) ;
370+ avoidRight = Math.max(avoidRight, avoidArea.rightRect.width) ;
348371 } catch (e) {
349372 const be = e as BusinessError;
350373 hilog.warn(DOMAIN, TAG, `getWindowAvoidArea failed: ${be.message}`);
@@ -389,7 +412,7 @@ export default class EntryAbility extends RustAbility {
389412 });
390413 RustModule.registerArktsFunction('maximize_ohos', async (err: Error, arg: string): Promise<string> => {
391414 try {
392- await windowStage.getMainWindowSync().maximize();
415+ await windowStage.getMainWindowSync().maximize(window.MaximizePresentation.EXIT_IMMERSIVE );
393416 } catch (e) {
394417 const be = e as BusinessError;
395418 hilog.warn(DOMAIN, TAG, `maximize failed: ${be.message}`);
0 commit comments