Просмотр исходного кода

tauri: disable pinch zoom on linux (#5735)

Brendan Allan 2 месяцев назад
Родитель
Сommit
0da901a188

+ 2 - 0
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]]

+ 4 - 0
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"

+ 6 - 3
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);
                 }
 

+ 34 - 0
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());
+                }
+            }
+        });
+    }
+}