Skip to content

Commit

Permalink
feat(window): add option to disable controls (#406)
Browse files Browse the repository at this point in the history
Co-authored-by: Amr Bashir <[email protected]>
  • Loading branch information
lucasfernog and amrbashir authored Jun 19, 2023
1 parent 83abea3 commit a79d6d9
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/disable-window-controls-api-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"window-js": "minor:feat"
---

Added the `maximizable`, `minimizable` and `closable` fields on `WindowOptions`.
6 changes: 6 additions & 0 deletions .changes/disable-window-controls-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"window": "minor:feat"
"window-js": "minor:feat"
---

Added the `setMaximizable`, `setMinimizable`, `setClosable`, `isMaximizable`, `isMinimizable` and `isClosable` methods.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions examples/api/src/views/Window.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
let urlValue = "https://tauri.app";
let resizable = true;
let maximizable = true;
let minimizable = true;
let closable = true;
let maximized = false;
let decorations = true;
let alwaysOnTop = false;
Expand Down Expand Up @@ -231,6 +234,9 @@
loadWindowSize();
}
$: windowMap[selectedWindow]?.setResizable(resizable);
$: windowMap[selectedWindow]?.setMaximizable(maximizable);
$: windowMap[selectedWindow]?.setMinimizable(minimizable);
$: windowMap[selectedWindow]?.setClosable(closable);
$: maximized
? windowMap[selectedWindow]?.maximize()
: windowMap[selectedWindow]?.unmaximize();
Expand Down Expand Up @@ -333,6 +339,18 @@
Resizable
<input type="checkbox" bind:checked={resizable} />
</label>
<label>
Maximizable
<input type="checkbox" bind:checked={maximizable} />
</label>
<label>
Minimizable
<input type="checkbox" bind:checked={minimizable} />
</label>
<label>
Closable
<input type="checkbox" bind:checked={closable} />
</label>
<label>
Has decorations
<input type="checkbox" bind:checked={decorations} />
Expand Down
149 changes: 148 additions & 1 deletion plugins/window/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,69 @@ class WindowManager extends WebviewWindowHandle {
});
}

/**
* Gets the window’s native maximize button state.
*
* #### Platform-specific
*
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/plugin-window';
* const maximizable = await appWindow.isMaximizable();
* ```
*
* @returns Whether the window's native maximize button is enabled or not.
* */
async isMaximizable(): Promise<boolean> {
return window.__TAURI_INVOKE__("plugin:window|is_maximizable", {
label: this.label,
});
}

/**
* Gets the window’s native minimize button state.
*
* #### Platform-specific
*
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/plugin-window';
* const minimizable = await appWindow.isMinimizable();
* ```
*
* @returns Whether the window's native minimize button is enabled or not.
* */
async isMinimizable(): Promise<boolean> {
return window.__TAURI_INVOKE__("plugin:window|is_minimizable", {
label: this.label,
});
}

/**
* Gets the window’s native close button state.
*
* #### Platform-specific
*
* - **iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/plugin-window';
* const closable = await appWindow.isClosable();
* ```
*
* @returns Whether the window's native close button is enabled or not.
* */
async isClosable(): Promise<boolean> {
return window.__TAURI_INVOKE__("plugin:window|is_closable", {
label: this.label,
});
}

/**
* Gets the window's current visible state.
* @example
Expand Down Expand Up @@ -713,7 +776,7 @@ class WindowManager extends WebviewWindowHandle {
* await appWindow.requestUserAttention();
* ```
*
* @param resizable
* @param requestType
* @returns A promise indicating the success or failure of the operation.
*
* @since 2.0.0
Expand Down Expand Up @@ -756,6 +819,78 @@ class WindowManager extends WebviewWindowHandle {
});
}

/**
* Sets whether the window's native maximize button is enabled or not.
* If resizable is set to false, this setting is ignored.
*
* #### Platform-specific
*
* - **macOS:** Disables the "zoom" button in the window titlebar, which is also used to enter fullscreen mode.
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/plugin-window';
* await appWindow.setMaximizable(false);
* ```
*
* @param maximizable
* @returns A promise indicating the success or failure of the operation.
*/
async setMaximizable(maximizable: boolean): Promise<void> {
return window.__TAURI_INVOKE__("plugin:window|set_maximizable", {
label: this.label,
value: maximizable,
});
}

/**
* Sets whether the window's native minimize button is enabled or not.
*
* #### Platform-specific
*
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/plugin-window';
* await appWindow.setMinimizable(false);
* ```
*
* @param minimizable
* @returns A promise indicating the success or failure of the operation.
*/
async setMinimizable(minimizable: boolean): Promise<void> {
return window.__TAURI_INVOKE__("plugin:window|set_minimizable", {
label: this.label,
value: minimizable,
});
}

/**
* Sets whether the window's native close button is enabled or not.
*
* #### Platform-specific
*
* - **Linux:** GTK+ will do its best to convince the window manager not to show a close button. Depending on the system, this function may not have any effect when called on a window that is already visible
* - **iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/plugin-window';
* await appWindow.setClosable(false);
* ```
*
* @param closable
* @returns A promise indicating the success or failure of the operation.
*/
async setClosable(closable: boolean): Promise<void> {
return window.__TAURI_INVOKE__("plugin:window|set_closable", {
label: this.label,
value: closable,
});
}

/**
* Sets the window title.
* @example
Expand Down Expand Up @@ -2123,6 +2258,18 @@ interface WindowOptions {
* - **Android:** Unsupported.
*/
incognito?: boolean;
/**
* Whether the window's native maximize button is enabled or not. Defaults to `true`.
*/
maximizable?: boolean;
/**
* Whether the window's native minimize button is enabled or not. Defaults to `true`.
*/
minimizable?: boolean;
/**
* Whether the window's native close button is enabled or not. Defaults to `true`.
*/
closable?: boolean;
}

function mapMonitor(m: Monitor | null): Monitor | null {
Expand Down
Loading

0 comments on commit a79d6d9

Please sign in to comment.