From 7e8b08476613f8588d698e145b73ba205f56171b Mon Sep 17 00:00:00 2001 From: Iain Laird Date: Wed, 15 Nov 2023 19:22:26 +0000 Subject: [PATCH 1/3] Update all gtk crates to 18.0 --- druid-shell/Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/druid-shell/Cargo.toml b/druid-shell/Cargo.toml index 43846647e..b22141894 100755 --- a/druid-shell/Cargo.toml +++ b/druid-shell/Cargo.toml @@ -103,11 +103,11 @@ ashpd = { version = "0.3.2", optional = true } cairo-rs = { version = "0.16.7", default-features = false, features = ["xcb"] } cairo-sys-rs = { version = "0.16.3", default-features = false, optional = true } futures = { version = "0.3.26", optional = true, features = ["executor"]} -gdk-sys = { version = "0.16.0", optional = true } +gdk-sys = { version = "0.18.0", optional = true } # `gtk` gets renamed to `gtk-rs` so that we can use `gtk` as the feature name. -gtk-rs = { version = "0.16.2", package = "gtk", optional = true } -glib-sys = { version = "0.16.3", optional = true } -gtk-sys = { version = "0.16.0", optional = true } +gtk-rs = { version = "0.18.0", package = "gtk", optional = true } +glib-sys = { version = "0.18.0", optional = true } +gtk-sys = { version = "0.18.0", optional = true } nix = { version = "0.24.3", optional = true } x11rb = { version = "0.10.1", features = ["allow-unsafe-code", "present", "render", "randr", "xfixes", "xkb", "resource_manager", "cursor"], optional = true } wayland-client = { version = "0.29.5", optional = true } From e8d014fad05dfa233d13d1bf68c3fcdfba538e6c Mon Sep 17 00:00:00 2001 From: Iain Laird Date: Thu, 16 Nov 2023 17:13:09 +0000 Subject: [PATCH 2/3] Update piet and fix breaking changes --- druid-shell/Cargo.toml | 8 ++--- druid-shell/src/backend/gtk/dialog.rs | 2 +- druid-shell/src/backend/gtk/screen.rs | 1 + druid-shell/src/backend/gtk/window.rs | 44 +++++++++++++++------------ druid/Cargo.toml | 2 +- 5 files changed, 31 insertions(+), 26 deletions(-) diff --git a/druid-shell/Cargo.toml b/druid-shell/Cargo.toml index b22141894..fa4465848 100755 --- a/druid-shell/Cargo.toml +++ b/druid-shell/Cargo.toml @@ -65,7 +65,7 @@ hdr = ["piet-common/hdr"] serde = ["piet-common/serde"] [dependencies] -piet-common = "0.6.2" +piet-common = { git = "https://github.com/linebender/piet.git", rev = "303b9a932de61cca5a12a8a1ecfbba742638dc52" } tracing = "0.1.37" once_cell = "1.17.1" @@ -100,8 +100,8 @@ bitflags = "1.3.2" [target.'cfg(any(target_os = "freebsd", target_os="linux", target_os="openbsd"))'.dependencies] ashpd = { version = "0.3.2", optional = true } # TODO(x11/dependencies): only use feature "xcb" if using X11 -cairo-rs = { version = "0.16.7", default-features = false, features = ["xcb"] } -cairo-sys-rs = { version = "0.16.3", default-features = false, optional = true } +cairo-rs = { version = "0.18.0", default-features = false, features = ["xcb"] } +cairo-sys-rs = { version = "0.18.0", default-features = false, optional = true } futures = { version = "0.3.26", optional = true, features = ["executor"]} gdk-sys = { version = "0.18.0", optional = true } # `gtk` gets renamed to `gtk-rs` so that we can use `gtk` as the feature name. @@ -127,7 +127,7 @@ version = "0.3.61" features = ["Window", "MouseEvent", "CssStyleDeclaration", "WheelEvent", "KeyEvent", "KeyboardEvent", "Navigator"] [dev-dependencies] -piet-common = { version = "0.6.2", features = ["png"] } +piet-common = { git = "https://github.com/linebender/piet.git", rev = "303b9a932de61cca5a12a8a1ecfbba742638dc52", features = ["png"] } static_assertions = "1.1.0" test-log = { version = "0.2.11", features = ["trace"], default-features = false } tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } diff --git a/druid-shell/src/backend/gtk/dialog.rs b/druid-shell/src/backend/gtk/dialog.rs index 7114e4dc2..2fb3eafc5 100644 --- a/druid-shell/src/backend/gtk/dialog.rs +++ b/druid-shell/src/backend/gtk/dialog.rs @@ -70,7 +70,7 @@ pub(crate) fn get_file_dialog_path( if let Some(file_types) = &options.allowed_types { for f in file_types { let filter = file_filter(f); - dialog.add_filter(&filter); + dialog.add_filter(filter.clone()); if let Some(default) = &options.default_type { if default == f { diff --git a/druid-shell/src/backend/gtk/screen.rs b/druid-shell/src/backend/gtk/screen.rs index 03333ba53..8dad0dfeb 100644 --- a/druid-shell/src/backend/gtk/screen.rs +++ b/druid-shell/src/backend/gtk/screen.rs @@ -17,6 +17,7 @@ use crate::kurbo::{Point, Rect, Size}; use crate::screen::Monitor; use gtk::gdk::{Display, DisplayManager, Rectangle}; +use gtk_rs::prelude::MonitorExt as _; fn translate_gdk_rectangle(r: Rectangle) -> Rect { Rect::from_origin_size( diff --git a/druid-shell/src/backend/gtk/window.rs b/druid-shell/src/backend/gtk/window.rs index 5e3ae2ff0..51fc78508 100644 --- a/druid-shell/src/backend/gtk/window.rs +++ b/druid-shell/src/backend/gtk/window.rs @@ -24,12 +24,12 @@ use std::slice; use std::sync::{Arc, Mutex, Weak}; use std::time::Instant; +use cairo::glib::{Propagation, ControlFlow}; use gtk::gdk_pixbuf::Colorspace::Rgb; use gtk::gdk_pixbuf::Pixbuf; -use gtk::glib::source::Continue; use gtk::glib::translate::FromGlib; use gtk::prelude::*; -use gtk::traits::SettingsExt; +use gtk::traits::GtkSettingsExt; use gtk::{AccelGroup, ApplicationWindow, DrawingArea}; use gdk_sys::GdkKeymapKey; @@ -427,7 +427,7 @@ impl WindowBuilder { .connect_enter_notify_event(|widget, _| { widget.grab_focus(); - Inhibit(true) + cairo::glib::Propagation::Stop }); // Set the minimum size @@ -539,7 +539,7 @@ impl WindowBuilder { } } - Inhibit(false) + cairo::glib::Propagation::Proceed })); win_state.drawing_area.connect_screen_changed( @@ -595,7 +595,7 @@ impl WindowBuilder { }); } - Inhibit(true) + cairo::glib::Propagation::Stop })); win_state.drawing_area.connect_button_release_event(clone!(handle => move |_widget, event| { @@ -622,7 +622,7 @@ impl WindowBuilder { }); } - Inhibit(true) + cairo::glib::Propagation::Stop })); win_state.drawing_area.connect_motion_notify_event( @@ -643,7 +643,7 @@ impl WindowBuilder { state.with_handler(|h| h.mouse_move(&mouse_event)); } - Inhibit(true) + cairo::glib::Propagation::Stop }), ); @@ -653,7 +653,7 @@ impl WindowBuilder { state.with_handler(|h| h.mouse_leave()); } - Inhibit(true) + cairo::glib::Propagation::Stop }), ); @@ -709,7 +709,7 @@ impl WindowBuilder { } } - Inhibit(true) + cairo::glib::Propagation::Stop })); win_state @@ -727,7 +727,7 @@ impl WindowBuilder { ); } - Inhibit(true) + cairo::glib::Propagation::Stop })); win_state @@ -745,7 +745,7 @@ impl WindowBuilder { ); } - Inhibit(true) + cairo::glib::Propagation::Stop })); win_state @@ -754,7 +754,7 @@ impl WindowBuilder { if let Some(state) = handle.state.upgrade() { state.with_handler(|h| h.got_focus()); } - Inhibit(true) + cairo::glib::Propagation::Stop })); win_state @@ -763,7 +763,7 @@ impl WindowBuilder { if let Some(state) = handle.state.upgrade() { state.with_handler(|h| h.lost_focus()); } - Inhibit(true) + cairo::glib::Propagation::Stop })); win_state @@ -771,9 +771,13 @@ impl WindowBuilder { .connect_delete_event(clone!(handle => move |_widget, _ev| { if let Some(state) = handle.state.upgrade() { state.with_handler(|h| h.request_close()); - Inhibit(!state.closing.get()) + if !state.closing.get() { + Propagation::Stop + } else { + Propagation::Proceed + } } else { - Inhibit(false) + cairo::glib::Propagation::Proceed } })); @@ -1221,9 +1225,9 @@ impl WindowHandle { if let Some(state) = self.state.upgrade() { gtk::glib::timeout_add(interval, move || { if state.with_handler(|h| h.timer(token)).is_some() { - return Continue(false); + return ControlFlow::Break; } - Continue(true) + ControlFlow::Continue }); } token @@ -1382,7 +1386,7 @@ impl IdleHandle { } } -fn run_idle(state: &Arc) -> Continue { +fn run_idle(state: &Arc) -> ControlFlow { util::assert_main_thread(); let result = state.with_handler(|handler| { let queue: Vec<_> = std::mem::take(&mut state.idle_queue.lock().unwrap()); @@ -1404,7 +1408,7 @@ fn run_idle(state: &Arc) -> Continue { let timeout = Duration::from_millis(16); gtk::glib::timeout_add(timeout, move || run_idle(&state)); } - Continue(false) + ControlFlow::Break } fn make_gdk_cursor(cursor: &Cursor, gdk_window: &Window) -> Option { @@ -1504,7 +1508,7 @@ fn make_key_event(key: &EventKey, repeat: bool, state: KeyState) -> KeyEvent { let keyval = key.keyval(); let hardware_keycode = key.hardware_keycode(); - let keycode = hardware_keycode_to_keyval(hardware_keycode).unwrap_or_else(|| keyval.clone()); + let keycode = hardware_keycode_to_keyval(hardware_keycode).unwrap_or(keyval); let text = keyval.to_unicode(); let mods = get_modifiers(key.state()); diff --git a/druid/Cargo.toml b/druid/Cargo.toml index 7376a2e7c..bfce8ccab 100644 --- a/druid/Cargo.toml +++ b/druid/Cargo.toml @@ -79,7 +79,7 @@ console_error_panic_hook = { version = "0.1.7" } [dev-dependencies] float-cmp = { version = "0.9.0", features = ["std"], default-features = false } tempfile = "3.4.0" -piet-common = { version = "0.6.2", features = ["png"] } +piet-common = { git = "https://github.com/linebender/piet.git", rev = "303b9a932de61cca5a12a8a1ecfbba742638dc52", features = ["png"] } pulldown-cmark = { version = "0.8.0", default-features = false } test-log = { version = "0.2.11", features = ["trace"], default-features = false } # test-env-log needs it From cc7cb62b6129bf45c6fd822ed8ae7917607fa1fe Mon Sep 17 00:00:00 2001 From: Iain Laird Date: Fri, 17 Nov 2023 14:40:56 +0000 Subject: [PATCH 3/3] Fix lints --- druid/src/widget/image.rs | 7 +++++-- druid/src/widget/svg.rs | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/druid/src/widget/image.rs b/druid/src/widget/image.rs index 04e3e4135..e4d30715e 100644 --- a/druid/src/widget/image.rs +++ b/druid/src/widget/image.rs @@ -318,8 +318,11 @@ mod tests { // the padding color and the middle rows will not have any padding. // Check that the middle row 400 pix wide is 200 black then 200 white. - let expecting: Vec = - [[0, 0, 0, 255].repeat(200), [255, 255, 255, 255].repeat(200)].concat(); + let expecting: Vec = [ + [0, 0, 0, 255].repeat(200), + [255, 255, 255, 255].repeat(200), + ] + .concat(); assert_eq!(raw_pixels[400 * 300 * 4..400 * 301 * 4], expecting[..]); // Check that all of the last 100 rows are all the background color. diff --git a/druid/src/widget/svg.rs b/druid/src/widget/svg.rs index 1975dfc88..bb5aab9c7 100644 --- a/druid/src/widget/svg.rs +++ b/druid/src/widget/svg.rs @@ -132,12 +132,12 @@ impl SvgData { pub fn empty() -> Self { use std::str::FromStr; - let empty_svg = r###" + let empty_svg = r#" - "###; + "#; SvgData::from_str(empty_svg).unwrap() }