Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update all gtk crates to 18.x #2391

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions druid-shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -100,14 +100,14 @@ 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 }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to explicitly depend on this, you can get it from cairo::ffi

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 }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from gtk, you can go to gtk::gdk::ffi for example, all those dependencies are not needed. You could just depend on gtk except for cairo where you enable xcb feature

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 }
Expand All @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion druid-shell/src/backend/gtk/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions druid-shell/src/backend/gtk/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
44 changes: 24 additions & 20 deletions druid-shell/src/backend/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use gtk::traits::GtkSettingsExt;

already part of the prelude

use gtk::{AccelGroup, ApplicationWindow, DrawingArea};

use gdk_sys::GdkKeymapKey;
Expand Down Expand Up @@ -427,7 +427,7 @@ impl WindowBuilder {
.connect_enter_notify_event(|widget, _| {
widget.grab_focus();

Inhibit(true)
cairo::glib::Propagation::Stop

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you imported it above

});

// Set the minimum size
Expand Down Expand Up @@ -539,7 +539,7 @@ impl WindowBuilder {
}
}

Inhibit(false)
cairo::glib::Propagation::Proceed
}));

win_state.drawing_area.connect_screen_changed(
Expand Down Expand Up @@ -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| {
Expand All @@ -622,7 +622,7 @@ impl WindowBuilder {
});
}

Inhibit(true)
cairo::glib::Propagation::Stop
}));

win_state.drawing_area.connect_motion_notify_event(
Expand All @@ -643,7 +643,7 @@ impl WindowBuilder {
state.with_handler(|h| h.mouse_move(&mouse_event));
}

Inhibit(true)
cairo::glib::Propagation::Stop
}),
);

Expand All @@ -653,7 +653,7 @@ impl WindowBuilder {
state.with_handler(|h| h.mouse_leave());
}

Inhibit(true)
cairo::glib::Propagation::Stop
}),
);

Expand Down Expand Up @@ -709,7 +709,7 @@ impl WindowBuilder {
}
}

Inhibit(true)
cairo::glib::Propagation::Stop
}));

win_state
Expand All @@ -727,7 +727,7 @@ impl WindowBuilder {
);
}

Inhibit(true)
cairo::glib::Propagation::Stop
}));

win_state
Expand All @@ -745,7 +745,7 @@ impl WindowBuilder {
);
}

Inhibit(true)
cairo::glib::Propagation::Stop
}));

win_state
Expand All @@ -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
Expand All @@ -763,17 +763,21 @@ impl WindowBuilder {
if let Some(state) = handle.state.upgrade() {
state.with_handler(|h| h.lost_focus());
}
Inhibit(true)
cairo::glib::Propagation::Stop
}));

win_state
.window
.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
}
}));

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1382,7 +1386,7 @@ impl IdleHandle {
}
}

fn run_idle(state: &Arc<WindowState>) -> Continue {
fn run_idle(state: &Arc<WindowState>) -> ControlFlow {
util::assert_main_thread();
let result = state.with_handler(|handler| {
let queue: Vec<_> = std::mem::take(&mut state.idle_queue.lock().unwrap());
Expand All @@ -1404,7 +1408,7 @@ fn run_idle(state: &Arc<WindowState>) -> 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<gtk::gdk::Cursor> {
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion druid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions druid/src/widget/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> =
[[0, 0, 0, 255].repeat(200), [255, 255, 255, 255].repeat(200)].concat();
let expecting: Vec<u8> = [
[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.
Expand Down
4 changes: 2 additions & 2 deletions druid/src/widget/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ impl SvgData {
pub fn empty() -> Self {
use std::str::FromStr;

let empty_svg = r###"
let empty_svg = r#"
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
<g fill="none">
</g>
</svg>
"###;
"#;

SvgData::from_str(empty_svg).unwrap()
}
Expand Down
Loading