Skip to content

Commit 7649aad

Browse files
committed
fix(cef): fix start_window_dragging on Windows
1 parent 1f2b96a commit 7649aad

File tree

4 files changed

+92
-331
lines changed

4 files changed

+92
-331
lines changed

crates/tauri-runtime-cef/src/cef_impl.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::{
3030
};
3131

3232
mod cookie;
33-
mod drag_handler;
33+
mod drag_window;
3434
mod request_handler;
3535

3636
use cookie::{CollectAllCookiesVisitor, CollectUrlCookiesVisitor};
@@ -644,10 +644,6 @@ wrap_client! {
644644
))
645645
}
646646

647-
fn drag_handler(&self) -> Option<DragHandler> {
648-
Some(drag_handler::BrowserDragHandler::new(drag_handler::BrowserDragHandlerData::new()))
649-
}
650-
651647
fn life_span_handler(&self) -> Option<LifeSpanHandler> {
652648
Some(BrowserLifeSpanHandler::new(self.window_kind, self.window_id, self.context.clone()))
653649
}
@@ -830,9 +826,9 @@ wrap_window_delegate! {
830826
fn on_window_created(&self, window: Option<&mut Window>) {
831827
if let Some(window) = window {
832828

833-
// Setup handling for `app-region: drag`
829+
// Setup necessary handling for `start_window_dragging` to work on Windows
834830
#[cfg(windows)]
835-
drag_handler::windows::subclass_window_for_dragging(window);
831+
drag_window::windows::subclass_window_for_dragging(window);
836832

837833
let a = self.attributes.borrow();
838834
if let Some(icon) = a.icon.clone() {
@@ -1895,16 +1891,28 @@ fn start_window_dragging(window: &cef::Window) {
18951891

18961892
#[cfg(windows)]
18971893
fn start_window_dragging(window: &cef::Window) {
1898-
use windows::Win32::Foundation::HWND;
1899-
use windows::Win32::UI::WindowsAndMessaging::{SendMessageW, HTCAPTION, WM_NCLBUTTONDOWN};
1894+
use windows::Win32::Foundation::*;
1895+
use windows::Win32::UI::Input::KeyboardAndMouse::*;
1896+
use windows::Win32::UI::WindowsAndMessaging::*;
19001897

19011898
unsafe {
19021899
let hwnd = window.window_handle();
1903-
let _ = SendMessageW(
1904-
HWND(hwnd.0 as _),
1900+
1901+
let mut pos = std::mem::zeroed();
1902+
let _ = GetCursorPos(&mut pos);
1903+
1904+
let points = POINTS {
1905+
x: pos.x as i16,
1906+
y: pos.y as i16,
1907+
};
1908+
1909+
let _ = ReleaseCapture();
1910+
1911+
let _ = PostMessageW(
1912+
Some(HWND(hwnd.0 as _)),
19051913
WM_NCLBUTTONDOWN,
1906-
Some(windows::Win32::Foundation::WPARAM(HTCAPTION as usize)),
1907-
Some(windows::Win32::Foundation::LPARAM(0)),
1914+
WPARAM(HTCAPTION as usize),
1915+
LPARAM(&points as *const _ as isize),
19081916
);
19091917
}
19101918
}

crates/tauri-runtime-cef/src/cef_impl/drag_handler.rs

Lines changed: 0 additions & 39 deletions
This file was deleted.

crates/tauri-runtime-cef/src/cef_impl/drag_handler/windows.rs

Lines changed: 0 additions & 279 deletions
This file was deleted.

0 commit comments

Comments
 (0)