Skip to content

Commit b072e2b

Browse files
Legend-Masterpewsheenlucasfernog
authored
feat(core): add an option for preventing window overflow (#9687)
* Add an option for preventing window overflow * Fix shadow counted as part of the width * Enable prevent overflow by default * Fix crashing when margin is bigger than screen * Config file support * Add to ts type * Add mac implementation * Should be let some * Apply suggestions from code review Co-authored-by: Jason Tsai <[email protected]> * checked_sub -> saturating_sub * Revert license header * Migrate windows 0.58 * Generate schema * Fix merge conflict * Try casting to objc2_app_kit::NSScreen * Add NSScreen feature * Use cast instead of as * fmt * Deref first * Wrong unsafe block * Add change file * Add serde alias * More docs * Disable prevent_overflow by default since we can't make breaking changes anymore right now * Remove unused default impl * Missing pub * Fix mock_runtime on ios * Match PreventOverflowMargin's description * Typo * Apply suggestions from code review * Move get_work_area_size to seperate files * Unused imports * Add prevent_overflow to WebviewWindowBuilder * Fix mac compile * MonitorExt is only for desktop * Rename to work_area * Use workarea for linux * Missing `()` * Convert size * Import MonitorExt * as u32 * Re-build API js * Fix wrong docs for work_area * Remove linux platform specific note * Remove left over linux platform specific note * Use work area API for center as well * Fix mobile * Clean up * small cleanup * fix codegen * update docs * fix generated --------- Co-authored-by: Jason Tsai <[email protected]> Co-authored-by: Lucas Nogueira <[email protected]>
1 parent 0802529 commit b072e2b

File tree

19 files changed

+603
-41
lines changed

19 files changed

+603
-41
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"tauri": "patch:feat"
3+
"tauri-utils": "patch:feat"
4+
"tauri-runtime": "patch:feat"
5+
"tauri-runtime-wry": "patch:feat"
6+
"@tauri-apps/api": "patch:feat"
7+
---
8+
9+
Add `preventOverflow` config option to prevent the window from overflowing the monitor size on creation

.changes/prevent_overflow_api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": minor:feat
3+
---
4+
5+
Add `WindowBuilder::prevent_overflow`, `WebviewWindowBuilder::prevent_overflow`, `WindowBuilder::prevent_overflow_with_margin` and `WebviewWindowBuilder::prevent_overflow_with_margin` APIs to prevent the window from overflowing the monitor size on creation.

crates/tauri-cli/config.schema.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,17 @@
319319
],
320320
"format": "double"
321321
},
322+
"preventOverflow": {
323+
"description": "Whether or not to prevent the window from overflowing the workarea\n\n ## Platform-specific\n\n - **iOS / Android:** Unsupported.",
324+
"anyOf": [
325+
{
326+
"$ref": "#/definitions/PreventOverflowConfig"
327+
},
328+
{
329+
"type": "null"
330+
}
331+
]
332+
},
322333
"resizable": {
323334
"description": "Whether the window is resizable or not. When resizable is set to false, native window's maximize button is automatically disabled.",
324335
"default": true,
@@ -573,6 +584,46 @@
573584
}
574585
]
575586
},
587+
"PreventOverflowConfig": {
588+
"description": "Prevent overflow with a margin",
589+
"anyOf": [
590+
{
591+
"description": "Enable prevent overflow or not",
592+
"type": "boolean"
593+
},
594+
{
595+
"description": "Enable prevent overflow with a margin\n so that the window's size + this margin won't overflow the workarea",
596+
"allOf": [
597+
{
598+
"$ref": "#/definitions/PreventOverflowMargin"
599+
}
600+
]
601+
}
602+
]
603+
},
604+
"PreventOverflowMargin": {
605+
"description": "Enable prevent overflow with a margin\n so that the window's size + this margin won't overflow the workarea",
606+
"type": "object",
607+
"required": [
608+
"height",
609+
"width"
610+
],
611+
"properties": {
612+
"width": {
613+
"description": "Horizontal margin in physical unit",
614+
"type": "integer",
615+
"format": "uint32",
616+
"minimum": 0.0
617+
},
618+
"height": {
619+
"description": "Vertical margin in physical unit",
620+
"type": "integer",
621+
"format": "uint32",
622+
"minimum": 0.0
623+
}
624+
},
625+
"additionalProperties": false
626+
},
576627
"Theme": {
577628
"description": "System theme.",
578629
"oneOf": [

crates/tauri-cli/schema.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,17 @@
301301
],
302302
"format": "double"
303303
},
304+
"preventOverflow": {
305+
"description": "Whether or not to prevent window overflow",
306+
"anyOf": [
307+
{
308+
"$ref": "#/definitions/PreventOverflowMarginConfig"
309+
},
310+
{
311+
"type": "null"
312+
}
313+
]
314+
},
304315
"resizable": {
305316
"description": "Whether the window is resizable or not. When resizable is set to false, native window's maximize button is automatically disabled.",
306317
"default": true,
@@ -497,6 +508,46 @@
497508
}
498509
]
499510
},
511+
"PreventOverflowMarginConfig": {
512+
"description": "Prevent overflow with a margin",
513+
"anyOf": [
514+
{
515+
"description": "Enable prevent overflow or not",
516+
"type": "boolean"
517+
},
518+
{
519+
"description": "Enable prevent overflow with a margin",
520+
"allOf": [
521+
{
522+
"$ref": "#/definitions/PreventOverflowMargin"
523+
}
524+
]
525+
}
526+
]
527+
},
528+
"PreventOverflowMargin": {
529+
"description": "Enable prevent overflow with a margin",
530+
"type": "object",
531+
"required": [
532+
"height",
533+
"width"
534+
],
535+
"properties": {
536+
"width": {
537+
"description": "Horizontal margin in physical unit",
538+
"type": "integer",
539+
"format": "uint32",
540+
"minimum": 0.0
541+
},
542+
"height": {
543+
"description": "Vertical margin in physical unit",
544+
"type": "integer",
545+
"format": "uint32",
546+
"minimum": 0.0
547+
}
548+
},
549+
"additionalProperties": false
550+
},
500551
"Theme": {
501552
"description": "System theme.",
502553
"oneOf": [

crates/tauri-cli/tauri.config.schema.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,17 @@
301301
],
302302
"format": "double"
303303
},
304+
"preventOverflow": {
305+
"description": "Whether or not to prevent window overflow",
306+
"anyOf": [
307+
{
308+
"$ref": "#/definitions/PreventOverflowMarginConfig"
309+
},
310+
{
311+
"type": "null"
312+
}
313+
]
314+
},
304315
"resizable": {
305316
"description": "Whether the window is resizable or not. When resizable is set to false, native window's maximize button is automatically disabled.",
306317
"default": true,
@@ -497,6 +508,46 @@
497508
}
498509
]
499510
},
511+
"PreventOverflowMarginConfig": {
512+
"description": "Prevent overflow with a margin",
513+
"anyOf": [
514+
{
515+
"description": "Enable prevent overflow or not",
516+
"type": "boolean"
517+
},
518+
{
519+
"description": "Enable prevent overflow with a margin",
520+
"allOf": [
521+
{
522+
"$ref": "#/definitions/PreventOverflowMargin"
523+
}
524+
]
525+
}
526+
]
527+
},
528+
"PreventOverflowMargin": {
529+
"description": "Enable prevent overflow with a margin",
530+
"type": "object",
531+
"required": [
532+
"height",
533+
"width"
534+
],
535+
"properties": {
536+
"width": {
537+
"description": "Horizontal margin in physical unit",
538+
"type": "integer",
539+
"format": "uint32",
540+
"minimum": 0.0
541+
},
542+
"height": {
543+
"description": "Vertical margin in physical unit",
544+
"type": "integer",
545+
"format": "uint32",
546+
"minimum": 0.0
547+
}
548+
},
549+
"additionalProperties": false
550+
},
500551
"Theme": {
501552
"description": "System theme.",
502553
"oneOf": [

crates/tauri-runtime-wry/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ objc2-app-kit = { version = "0.3", features = [
5757
"NSResponder",
5858
"NSView",
5959
"NSWindow",
60+
"NSScreen",
6061
"NSGraphics",
6162
] }
6263

0 commit comments

Comments
 (0)