Skip to content

Commit

Permalink
feat: double-click tauri-drag-region to maximize, closes #1839 (#2106)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Jun 28, 2021
1 parent 2a6cfbf commit 8b7ac1a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .changes/dblclick-tauri-drag-maximize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"tauri": patch
---
Double clicking a `data-tauri-drag-region` element will toggle the window maximized state.
31 changes: 23 additions & 8 deletions core/tauri/scripts/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,29 @@ if (!String.prototype.startsWith) {

// drag region
document.addEventListener('mousedown', (e) => {
// start dragging if the element has a `tauri-drag-region` data attribute
if (e.target.hasAttribute('data-tauri-drag-region') && e.buttons === 1) {
window.__TAURI__._invoke('tauri', {
__tauriModule: "Window",
message: {
cmd: "startDragging",
}
}, _KEY_VALUE_)
if (e.target.hasAttribute("data-tauri-drag-region") && e.buttons === 1) {
// start dragging if the element has a `tauri-drag-region` data attribute and maximize on double-clicking it
e.detail === 2
? window.__TAURI__._invoke(
"tauri",
{
__tauriModule: "Window",
message: {
cmd: "toggleMaximize",
},
},
_KEY_VALUE_
)
: window.__TAURI__._invoke(
"tauri",
{
__tauriModule: "Window",
message: {
cmd: "startDragging",
},
},
_KEY_VALUE_
);
}
})

Expand Down
5 changes: 5 additions & 0 deletions core/tauri/src/endpoints/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub enum Cmd {
SetTitle(String),
Maximize,
Unmaximize,
ToggleMaximize,
Minimize,
Unminimize,
Show,
Expand Down Expand Up @@ -152,6 +153,10 @@ impl Cmd {
Self::SetTitle(title) => window.set_title(&title)?,
Self::Maximize => window.maximize()?,
Self::Unmaximize => window.unmaximize()?,
Self::ToggleMaximize => match window.is_maximized()? {
true => window.unmaximize()?,
false => window.maximize()?,
},
Self::Minimize => window.minimize()?,
Self::Unminimize => window.unminimize()?,
Self::Show => window.show()?,
Expand Down

0 comments on commit 8b7ac1a

Please sign in to comment.