Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into api/dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Sep 28, 2022
2 parents ff2d2bb + eedfa5e commit eaa58dd
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 37 deletions.
11 changes: 11 additions & 0 deletions core/tauri-runtime-wry/src/lib.rs
Expand Up @@ -1051,6 +1051,7 @@ pub enum WindowMessage {
SetCursorVisible(bool),
SetCursorIcon(CursorIcon),
SetCursorPosition(Position),
SetIgnoreCursorEvents(bool),
DragWindow,
UpdateMenuItem(u16, MenuUpdate),
RequestRedraw,
Expand Down Expand Up @@ -1493,6 +1494,13 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
)
}

fn set_ignore_cursor_events(&self, ignore: bool) -> crate::Result<()> {
send_user_message(
&self.context,
Message::Window(self.window_id, WindowMessage::SetIgnoreCursorEvents(ignore)),
)
}

fn start_dragging(&self) -> Result<()> {
send_user_message(
&self.context,
Expand Down Expand Up @@ -2342,6 +2350,9 @@ fn handle_user_message<T: UserEvent>(
WindowMessage::SetCursorPosition(position) => {
let _ = window.set_cursor_position(PositionWrapper::from(position).0);
}
WindowMessage::SetIgnoreCursorEvents(ignore) => {
let _ = window.set_ignore_cursor_events(ignore);
}
WindowMessage::DragWindow => {
let _ = window.drag_window();
}
Expand Down
3 changes: 3 additions & 0 deletions core/tauri-runtime/src/lib.rs
Expand Up @@ -630,6 +630,9 @@ pub trait Dispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static
/// Changes the position of the cursor in window coordinates.
fn set_cursor_position<Pos: Into<Position>>(&self, position: Pos) -> Result<()>;

/// Ignores the window cursor events.
fn set_ignore_cursor_events(&self, ignore: bool) -> Result<()>;

/// Starts dragging the window.
fn start_dragging(&self) -> Result<()>;

Expand Down
10 changes: 10 additions & 0 deletions core/tauri-utils/src/config.rs
Expand Up @@ -1338,6 +1338,9 @@ pub struct WindowAllowlistConfig {
/// Allows setting the cursor position.
#[serde(default, alias = "set-cursor-position")]
pub set_cursor_position: bool,
/// Allows ignoring cursor events.
#[serde(default, alias = "set-ignore-cursor-events")]
pub set_ignore_cursor_events: bool,
/// Allows start dragging on the window.
#[serde(default, alias = "start-dragging")]
pub start_dragging: bool,
Expand Down Expand Up @@ -1376,6 +1379,7 @@ impl Allowlist for WindowAllowlistConfig {
set_cursor_visible: true,
set_cursor_icon: true,
set_cursor_position: true,
set_ignore_cursor_events: true,
start_dragging: true,
print: true,
};
Expand Down Expand Up @@ -1435,6 +1439,12 @@ impl Allowlist for WindowAllowlistConfig {
set_cursor_position,
"window-set-cursor-position"
);
check_feature!(
self,
features,
set_ignore_cursor_events,
"window-set-ignore-cursor-events"
);
check_feature!(self, features, start_dragging, "window-start-dragging");
check_feature!(self, features, print, "window-print");
features
Expand Down
2 changes: 2 additions & 0 deletions core/tauri/Cargo.toml
Expand Up @@ -250,6 +250,7 @@ window-all = [
"window-set-cursor-visible",
"window-set-cursor-icon",
"window-set-cursor-position",
"window-set-ignore-cursor-events",
"window-start-dragging",
"window-print"
]
Expand Down Expand Up @@ -279,6 +280,7 @@ window-set-cursor-grab = [ ]
window-set-cursor-visible = [ ]
window-set-cursor-icon = [ ]
window-set-cursor-position = [ ]
window-set-ignore-cursor-events = [ ]
window-start-dragging = [ ]
window-print = [ ]
config-json5 = [ "tauri-macros/config-json5" ]
Expand Down
1 change: 1 addition & 0 deletions core/tauri/build.rs
Expand Up @@ -93,6 +93,7 @@ fn main() {
"set-cursor-visible",
"set-cursor-icon",
"set-cursor-position",
"set-ignore-cursor-events",
"start-dragging",
"print",
],
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/scripts/bundle.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions core/tauri/src/endpoints/window.rs
Expand Up @@ -127,6 +127,8 @@ pub enum WindowManagerCmd {
SetCursorIcon(CursorIcon),
#[cfg(window_set_cursor_position)]
SetCursorPosition(Position),
#[cfg(window_set_ignore_cursor_events)]
SetIgnoreCursorEvents(bool),
#[cfg(window_start_dragging)]
StartDragging,
#[cfg(window_print)]
Expand Down Expand Up @@ -173,6 +175,9 @@ pub fn into_allowlist_error(variant: &str) -> crate::Error {
"setCursorPosition" => {
crate::Error::ApiNotAllowlisted("window > setCursorPosition".to_string())
}
"setIgnoreCursorEvents" => {
crate::Error::ApiNotAllowlisted("window > setIgnoreCursorEvents".to_string())
}
"startDragging" => crate::Error::ApiNotAllowlisted("window > startDragging".to_string()),
"print" => crate::Error::ApiNotAllowlisted("window > print".to_string()),
"internalToggleMaximize" => {
Expand Down Expand Up @@ -314,6 +319,10 @@ impl Cmd {
WindowManagerCmd::SetCursorIcon(icon) => window.set_cursor_icon(icon)?,
#[cfg(window_set_cursor_position)]
WindowManagerCmd::SetCursorPosition(position) => window.set_cursor_position(position)?,
#[cfg(window_set_ignore_cursor_events)]
WindowManagerCmd::SetIgnoreCursorEvents(ignore_cursor) => {
window.set_ignore_cursor_events(ignore_cursor)?
}
#[cfg(window_start_dragging)]
WindowManagerCmd::StartDragging => window.start_dragging()?,
#[cfg(window_print)]
Expand Down
1 change: 1 addition & 0 deletions core/tauri/src/lib.rs
Expand Up @@ -145,6 +145,7 @@
//! - **window-set-cursor-visible**: Enables the [`setCursorVisible` API](https://tauri.app/en/docs/api/js/classes/window.WebviewWindow#setcursorvisible).
//! - **window-set-cursor-icon**: Enables the [`setCursorIcon` API](https://tauri.app/en/docs/api/js/classes/window.WebviewWindow#setcursoricon).
//! - **window-set-cursor-position**: Enables the [`setCursorPosition` API](https://tauri.app/en/docs/api/js/classes/window.WebviewWindow#setcursorposition).
//! - **window-set-ignore-cursor-events**: Enables the [`setIgnoreCursorEvents` API](https://tauri.app/en/docs/api/js/classes/window.WebviewWindow#setignorecursorevents).
//! - **window-start-dragging**: Enables the [`startDragging` API](https://tauri.app/en/docs/api/js/classes/window.WebviewWindow#startdragging).
//! - **window-print**: Enables the [`print` API](https://tauri.app/en/docs/api/js/classes/window.WebviewWindow#print).

Expand Down
4 changes: 4 additions & 0 deletions core/tauri/src/test/mock_runtime.rs
Expand Up @@ -500,6 +500,10 @@ impl<T: UserEvent> Dispatch<T> for MockDispatcher {
Ok(())
}

fn set_ignore_cursor_events(&self, ignore: bool) -> Result<()> {
Ok(())
}

fn start_dragging(&self) -> Result<()> {
Ok(())
}
Expand Down
9 changes: 9 additions & 0 deletions core/tauri/src/window.rs
Expand Up @@ -1175,6 +1175,15 @@ impl<R: Runtime> Window<R> {
.map_err(Into::into)
}

/// Ignores the window cursor events.
pub fn set_ignore_cursor_events(&self, ignore: bool) -> crate::Result<()> {
self
.window
.dispatcher
.set_ignore_cursor_events(ignore)
.map_err(Into::into)
}

/// Starts dragging the window.
pub fn start_dragging(&self) -> crate::Result<()> {
self.window.dispatcher.start_dragging().map_err(Into::into)
Expand Down
73 changes: 37 additions & 36 deletions examples/api/dist/assets/index.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions examples/api/src/views/Window.svelte
Expand Up @@ -87,6 +87,7 @@
let cursorX = null
let cursorY = null
let cursorIcon = 'default'
let cursorIgnoreEvents = false
let windowTitle = 'Awesome Tauri Example!'
function openUrl() {
Expand Down Expand Up @@ -212,6 +213,7 @@
windowMap[selectedWindow]?.setCursorPosition(
new PhysicalPosition(cursorX, cursorY)
)
$: windowMap[selectedWindow]?.setIgnoreCursorEvents(cursorIgnoreEvents)
</script>
<div class="flex flex-col children:grow gap-2">
Expand Down Expand Up @@ -413,6 +415,10 @@
<input type="checkbox" bind:checked={cursorVisible} />
Visible
</label>
<label>
<input type="checkbox" bind:checked={cursorIgnoreEvents} />
Ignore events
</label>
</div>
<div class="flex gap-2">
<label>
Expand Down
29 changes: 29 additions & 0 deletions tooling/api/src/window.ts
Expand Up @@ -40,6 +40,7 @@
* "setCursorVisible": true,
* "setCursorIcon": true,
* "setCursorPosition": true,
* "setIgnoreCursorEvents": true,
* "startDragging": true,
* "print": true
* }
Expand Down Expand Up @@ -1510,6 +1511,34 @@ class WindowManager extends WebviewWindowHandle {
})
}

/**
* Changes the cursor events behavior.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setIgnoreCursorEvents(true);
* ```
*
* @param ignore `true` to ignore the cursor events; `false` to process them as usual.
* @returns A promise indicating the success or failure of the operation.
*/
async setIgnoreCursorEvents(ignore: boolean): Promise<void> {
return invokeTauriCommand({
__tauriModule: 'Window',
message: {
cmd: 'manage',
data: {
label: this.label,
cmd: {
type: 'setIgnoreCursorEvents',
payload: ignore
}
}
}
})
}

/**
* Starts dragging the window.
* @example
Expand Down
8 changes: 8 additions & 0 deletions tooling/cli/schema.json
Expand Up @@ -108,6 +108,7 @@
"setFocus": false,
"setFullscreen": false,
"setIcon": false,
"setIgnoreCursorEvents": false,
"setMaxSize": false,
"setMinSize": false,
"setPosition": false,
Expand Down Expand Up @@ -375,6 +376,7 @@
"setFocus": false,
"setFullscreen": false,
"setIcon": false,
"setIgnoreCursorEvents": false,
"setMaxSize": false,
"setMinSize": false,
"setPosition": false,
Expand Down Expand Up @@ -1552,6 +1554,7 @@
"setFocus": false,
"setFullscreen": false,
"setIcon": false,
"setIgnoreCursorEvents": false,
"setMaxSize": false,
"setMinSize": false,
"setPosition": false,
Expand Down Expand Up @@ -1940,6 +1943,11 @@
"default": false,
"type": "boolean"
},
"setIgnoreCursorEvents": {
"description": "Allows ignoring cursor events.",
"default": false,
"type": "boolean"
},
"startDragging": {
"description": "Allows start dragging on the window.",
"default": false,
Expand Down

0 comments on commit eaa58dd

Please sign in to comment.