Skip to content

Commit e0650ce

Browse files
authored
Merge branch 'master' into fix/joining-paths-same-pointids
2 parents dda1de6 + c2a2947 commit e0650ce

File tree

11 files changed

+300
-136
lines changed

11 files changed

+300
-136
lines changed

desktop/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ windows = { version = "0.58.0", features = [
5555
"Win32_Graphics_Gdi",
5656
"Win32_System_LibraryLoader",
5757
"Win32_System_Com",
58+
"Win32_System_Console",
5859
"Win32_UI_Controls",
5960
"Win32_UI_WindowsAndMessaging",
6061
"Win32_UI_HiDpi",

desktop/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ pub fn start() {
9393
let mut app = App::new(Box::new(cef_context), cef_view_info_sender, wgpu_context, app_event_receiver, app_event_scheduler, cli.files);
9494

9595
event_loop.run_app(&mut app).unwrap();
96+
97+
// Workaround for a Windows-specific exception that occurs when `app` is dropped.
98+
// The issue causes the window to hang for a few seconds before closing.
99+
// Appears to be related to CEF object destruction order.
100+
// Calling `exit` bypasses rust teardown and lets Windows perform process cleanup.
101+
// TODO: Identify and fix the underlying CEF shutdown issue so this workaround can be removed.
102+
#[cfg(target_os = "windows")]
103+
exit(0);
96104
}
97105

98106
pub fn start_helper() {

desktop/src/window.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ pub(crate) struct Window {
4141
#[allow(dead_code)]
4242
native_handle: native::NativeWindowImpl,
4343
custom_cursors: HashMap<CustomCursorSource, CustomCursor>,
44-
clipboard: window_clipboard::Clipboard,
44+
clipboard: Option<window_clipboard::Clipboard>,
45+
}
46+
impl Drop for Window {
47+
fn drop(&mut self) {
48+
// Clipboard must be dropped before `winit_window`
49+
drop(self.clipboard.take());
50+
}
4551
}
4652

4753
impl Window {
@@ -62,7 +68,7 @@ impl Window {
6268

6369
let winit_window = event_loop.create_window(attributes).unwrap();
6470
let native_handle = native::NativeWindowImpl::new(winit_window.as_ref(), app_event_scheduler);
65-
let clipboard = unsafe { window_clipboard::Clipboard::connect(&winit_window) }.expect("failed to create clipboard");
71+
let clipboard = unsafe { window_clipboard::Clipboard::connect(&winit_window) }.ok();
6672
Self {
6773
winit_window: winit_window.into(),
6874
native_handle,
@@ -158,7 +164,11 @@ impl Window {
158164
}
159165

160166
pub(crate) fn clipboard_read(&self) -> Option<String> {
161-
match self.clipboard.read() {
167+
let Some(clipboard) = &self.clipboard else {
168+
tracing::error!("Clipboard not available");
169+
return None;
170+
};
171+
match clipboard.read() {
162172
Ok(data) => Some(data),
163173
Err(e) => {
164174
tracing::error!("Failed to read from clipboard: {e}");
@@ -168,7 +178,11 @@ impl Window {
168178
}
169179

170180
pub(crate) fn clipboard_write(&mut self, data: String) {
171-
if let Err(e) = self.clipboard.write(data) {
181+
let Some(clipboard) = &mut self.clipboard else {
182+
tracing::error!("Clipboard not available");
183+
return;
184+
};
185+
if let Err(e) = clipboard.write(data) {
172186
tracing::error!("Failed to write to clipboard: {e}")
173187
}
174188
}

desktop/src/window/win.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use windows::Win32::System::Com::{COINIT_APARTMENTTHREADED, CoInitializeEx};
2+
use windows::Win32::System::Console::{ATTACH_PARENT_PROCESS, AttachConsole};
23
use windows::Win32::UI::Shell::SetCurrentProcessExplicitAppUserModelID;
34
use windows::core::HSTRING;
45
use winit::event_loop::ActiveEventLoop;
@@ -13,6 +14,12 @@ pub(super) struct NativeWindowImpl {
1314

1415
impl super::NativeWindow for NativeWindowImpl {
1516
fn init() {
17+
// Attach to parent console if launched from a terminal (no-op otherwise)
18+
unsafe {
19+
let _ = AttachConsole(ATTACH_PARENT_PROCESS);
20+
}
21+
22+
// Set stable app ID
1623
let app_id = HSTRING::from(APP_ID);
1724
unsafe {
1825
let _ = CoInitializeEx(None, COINIT_APARTMENTTHREADED).ok();

desktop/src/window/win/native_handle.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl NativeWindowHandle {
6161
0,
6262
0,
6363
0,
64-
None,
64+
main,
6565
None,
6666
HINSTANCE(std::ptr::null_mut()),
6767
// Pass the main window's HWND to WM_NCCREATE so the helper can store it.
@@ -118,7 +118,7 @@ impl NativeWindowHandle {
118118
}
119119

120120
// Force window update
121-
let _ = unsafe { SetWindowPos(main, None, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER) };
121+
let _ = unsafe { SetWindowPos(main, None, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE) };
122122

123123
native_handle
124124
}
@@ -325,20 +325,20 @@ unsafe fn position_helper(main: HWND, helper: HWND) {
325325
let w = (r.right - r.left) + RESIZE_BAND_THICKNESS * 2;
326326
let h = (r.bottom - r.top) + RESIZE_BAND_THICKNESS * 2;
327327

328-
let _ = unsafe { SetWindowPos(helper, main, x, y, w, h, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING) };
328+
let _ = unsafe { SetWindowPos(helper, main, x, y, w, h, SWP_NOACTIVATE | SWP_NOSENDCHANGING) };
329329
}
330330

331331
unsafe fn calculate_hit(helper: HWND, lparam: LPARAM) -> u32 {
332-
let x = (lparam.0 & 0xFFFF) as i16 as u32;
333-
let y = ((lparam.0 >> 16) & 0xFFFF) as i16 as u32;
332+
let x = (lparam.0 & 0xFFFF) as i16 as i32;
333+
let y = ((lparam.0 >> 16) & 0xFFFF) as i16 as i32;
334334

335335
let mut r = RECT::default();
336336
let _ = unsafe { GetWindowRect(helper, &mut r) };
337337

338-
let on_top = y < (r.top + RESIZE_BAND_THICKNESS) as u32;
339-
let on_right = x >= (r.right - RESIZE_BAND_THICKNESS) as u32;
340-
let on_bottom = y >= (r.bottom - RESIZE_BAND_THICKNESS) as u32;
341-
let on_left = x < (r.left + RESIZE_BAND_THICKNESS) as u32;
338+
let on_top = y < (r.top + RESIZE_BAND_THICKNESS) as i32;
339+
let on_right = x >= (r.right - RESIZE_BAND_THICKNESS) as i32;
340+
let on_bottom = y >= (r.bottom - RESIZE_BAND_THICKNESS) as i32;
341+
let on_left = x < (r.left + RESIZE_BAND_THICKNESS) as i32;
342342

343343
match (on_top, on_right, on_bottom, on_left) {
344344
(true, _, _, true) => HTTOPLEFT,

node-graph/graph-craft/src/document/value.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,19 @@ tagged_value! {
189189
// TABLE TYPES
190190
// ===========
191191
GraphicUnused(Graphic), // TODO: This is unused but removing it causes `cargo test` to infinitely recurse its type solving; figure out why and then remove this
192-
#[cfg_attr(target_family = "wasm", serde(deserialize_with = "graphic_types::migrations::migrate_vector"))] // TODO: Eventually remove this migration document upgrade code
192+
#[serde(deserialize_with = "graphic_types::migrations::migrate_vector")] // TODO: Eventually remove this migration document upgrade code
193193
#[serde(alias = "VectorData")]
194194
Vector(Table<Vector>),
195-
#[cfg_attr(target_family = "wasm", serde(deserialize_with = "graphic_types::raster_types::image::migrate_image_frame"))] // TODO: Eventually remove this migration document upgrade code
195+
#[serde(deserialize_with = "graphic_types::raster_types::image::migrate_image_frame")] // TODO: Eventually remove this migration document upgrade code
196196
#[serde(alias = "ImageFrame", alias = "RasterData", alias = "Image")]
197197
Raster(Table<Raster<CPU>>),
198-
#[cfg_attr(target_family = "wasm", serde(deserialize_with = "graphic_types::graphic::migrate_graphic"))] // TODO: Eventually remove this migration document upgrade code
198+
#[serde(deserialize_with = "graphic_types::graphic::migrate_graphic")] // TODO: Eventually remove this migration document upgrade code
199199
#[serde(alias = "GraphicGroup", alias = "Group")]
200200
Graphic(Table<Graphic>),
201-
#[cfg_attr(target_family = "wasm", serde(deserialize_with = "graphic_types::artboard::migrate_artboard"))] // TODO: Eventually remove this migration document upgrade code
201+
#[serde(deserialize_with = "graphic_types::artboard::migrate_artboard")] // TODO: Eventually remove this migration document upgrade code
202202
#[serde(alias = "ArtboardGroup")]
203203
Artboard(Table<Artboard>),
204-
#[cfg_attr(target_family = "wasm", serde(deserialize_with = "core_types::misc::migrate_color"))] // TODO: Eventually remove this migration document upgrade code
204+
#[serde(deserialize_with = "core_types::misc::migrate_color")] // TODO: Eventually remove this migration document upgrade code
205205
#[serde(alias = "ColorTable", alias = "OptionalColor")]
206206
Color(Table<Color>),
207207
GradientTable(Table<GradientStops>),

0 commit comments

Comments
 (0)