summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBrendan Allan <[email protected]>2025-12-18 19:13:09 +0800
committerGitHub <[email protected]>2025-12-18 05:13:09 -0600
commit0da901a18845adef20bca5011e0c001387c415d5 (patch)
tree25013ee618ac4e17e06dd77d9a15aa38e97212f2
parent17221e6ffe6bd389522a7d705b1b9aa5bb7edec9 (diff)
downloadopencode-0da901a18845adef20bca5011e0c001387c415d5.tar.gz
opencode-0da901a18845adef20bca5011e0c001387c415d5.zip
tauri: disable pinch zoom on linux (#5735)
-rw-r--r--packages/tauri/src-tauri/Cargo.lock2
-rw-r--r--packages/tauri/src-tauri/Cargo.toml4
-rw-r--r--packages/tauri/src-tauri/src/lib.rs9
-rw-r--r--packages/tauri/src-tauri/src/window_customizer.rs34
4 files changed, 46 insertions, 3 deletions
diff --git a/packages/tauri/src-tauri/Cargo.lock b/packages/tauri/src-tauri/Cargo.lock
index 647421b05..fc578470b 100644
--- a/packages/tauri/src-tauri/Cargo.lock
+++ b/packages/tauri/src-tauri/Cargo.lock
@@ -2677,6 +2677,7 @@ dependencies = [
name = "opencode-desktop"
version = "0.0.0"
dependencies = [
+ "gtk",
"listeners",
"serde",
"serde_json",
@@ -2692,6 +2693,7 @@ dependencies = [
"tauri-plugin-updater",
"tauri-plugin-window-state",
"tokio",
+ "webkit2gtk",
]
[[package]]
diff --git a/packages/tauri/src-tauri/Cargo.toml b/packages/tauri/src-tauri/Cargo.toml
index 4cb82d94d..58b3d107b 100644
--- a/packages/tauri/src-tauri/Cargo.toml
+++ b/packages/tauri/src-tauri/Cargo.toml
@@ -33,3 +33,7 @@ serde_json = "1"
tokio = "1.48.0"
listeners = "0.3"
tauri-plugin-os = "2"
+
+[target.'cfg(target_os = "linux")'.dependencies]
+gtk = "0.18.2"
+webkit2gtk = "=2.0.1"
diff --git a/packages/tauri/src-tauri/src/lib.rs b/packages/tauri/src-tauri/src/lib.rs
index e9d9ed44c..1bf1427a2 100644
--- a/packages/tauri/src-tauri/src/lib.rs
+++ b/packages/tauri/src-tauri/src/lib.rs
@@ -1,11 +1,11 @@
+mod window_customizer;
+
use std::{
collections::VecDeque,
net::{SocketAddr, TcpListener},
sync::{Arc, Mutex},
time::{Duration, Instant},
};
-#[cfg(target_os = "macos")]
-use tauri::TitleBarStyle;
use tauri::{AppHandle, LogicalSize, Manager, RunEvent, WebviewUrl, WebviewWindow};
use tauri_plugin_clipboard_manager::ClipboardExt;
use tauri_plugin_dialog::{DialogExt, MessageDialogButtons, MessageDialogResult};
@@ -13,6 +13,8 @@ use tauri_plugin_shell::process::{CommandChild, CommandEvent};
use tauri_plugin_shell::ShellExt;
use tokio::net::TcpSocket;
+use crate::window_customizer::PinchZoomDisablePlugin;
+
#[derive(Clone)]
struct ServerState(Arc<Mutex<Option<CommandChild>>>);
@@ -188,6 +190,7 @@ pub fn run() {
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_clipboard_manager::init())
+ .plugin(PinchZoomDisablePlugin)
.invoke_handler(tauri::generate_handler![
kill_sidecar,
copy_logs_to_clipboard,
@@ -268,7 +271,7 @@ pub fn run() {
#[cfg(target_os = "macos")]
{
window_builder = window_builder
- .title_bar_style(TitleBarStyle::Overlay)
+ .title_bar_style(tauri::TitleBarStyle::Overlay)
.hidden_title(true);
}
diff --git a/packages/tauri/src-tauri/src/window_customizer.rs b/packages/tauri/src-tauri/src/window_customizer.rs
new file mode 100644
index 000000000..cd42fd029
--- /dev/null
+++ b/packages/tauri/src-tauri/src/window_customizer.rs
@@ -0,0 +1,34 @@
+use tauri::{plugin::Plugin, Manager, Runtime, Window};
+
+pub struct PinchZoomDisablePlugin;
+
+impl Default for PinchZoomDisablePlugin {
+ fn default() -> Self {
+ Self
+ }
+}
+
+impl<R: Runtime> Plugin<R> for PinchZoomDisablePlugin {
+ fn name(&self) -> &'static str {
+ "Does not matter here"
+ }
+
+ fn window_created(&mut self, window: Window<R>) {
+ let Some(webview_window) = window.get_webview_window(window.label()) else {
+ return;
+ };
+
+ let _ = webview_window.with_webview(|_webview| {
+ #[cfg(target_os = "linux")]
+ unsafe {
+ use gtk::glib::ObjectExt;
+ use gtk::GestureZoom;
+ use webkit2gtk::glib::gobject_ffi;
+
+ if let Some(data) = _webview.inner().data::<GestureZoom>("wk-view-zoom-gesture") {
+ gobject_ffi::g_signal_handlers_destroy(data.as_ptr().cast());
+ }
+ }
+ });
+ }
+}