Skip to content

Commit

Permalink
Update Piet to v0.7.0-cairo18.
Browse files Browse the repository at this point in the history
  • Loading branch information
xStrom committed Oct 26, 2024
1 parent b831b5f commit 45b6156
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 56 deletions.
25 changes: 8 additions & 17 deletions druid-shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]

[features]
default = ["gtk"]
gtk = ["gdk-sys", "glib-sys", "gtk-sys", "gtk-rs"]
gtk = ["gtk-rs"]
x11 = [
"ashpd",
"bindgen",
"cairo-sys-rs",
"futures",
"nix",
"pkg-config",
"x11rb",
"cairo-rs/xcb",
]
wayland = [
"wayland-client",
"wayland-protocols/client",
"wayland-protocols/unstable_protocols",
"nix",
"cairo-sys-rs",
"rand",
"calloop",
"wayland-cursor",
Expand All @@ -50,7 +49,6 @@ raw-win-handle = ["raw-window-handle"]
image = ["piet-common/image"]
image_png = ["piet-common/image_png"]
jpeg = ["piet-common/jpeg"]
jpeg_rayon = ["piet-common/jpeg_rayon"]
gif = ["piet-common/gif"]
bmp = ["piet-common/bmp"]
ico = ["piet-common/ico"]
Expand All @@ -59,13 +57,11 @@ webp = ["piet-common/webp"]
pnm = ["piet-common/pnm"]
dds = ["piet-common/dds"]
tga = ["piet-common/tga"]
farbfeld = ["piet-common/farbfeld"]
dxt = ["piet-common/dxt"]
hdr = ["piet-common/hdr"]
serde = ["piet-common/serde"]

[dependencies]
piet-common = "0.6.2"
piet-common = { version = "=0.7.0-cairo18" }

tracing = "0.1.40"
once_cell = "1.20.2"
Expand Down Expand Up @@ -93,21 +89,16 @@ features = ["d2d1_1", "dwrite", "winbase", "libloaderapi", "errhandlingapi", "wi
block = "0.1.6"
cocoa = "0.24.1"
objc = "0.2.7"
core-graphics = "0.22.3"
foreign-types = "0.3.2"
core-graphics = "0.24.0"
foreign-types = "0.5.0"
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.5", default-features = false }
futures = { version = "0.3.31", optional = true, features = ["executor"]}
gdk-sys = { version = "0.16.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.1", package = "gtk", 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 +118,7 @@ version = "0.3.72"
features = ["Window", "MouseEvent", "CssStyleDeclaration", "WheelEvent", "KeyEvent", "KeyboardEvent", "Navigator"]

[dev-dependencies]
piet-common = { version = "0.6.2", features = ["png"] }
piet-common = { version = "=0.7.0-cairo18", features = ["png"] }
static_assertions = "1.1.0"
test-log = { version = "0.2.16", features = ["trace"], default-features = false }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
Expand Down
7 changes: 3 additions & 4 deletions druid-shell/src/backend/gtk/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ 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);
// We need to clone filter, because we may need it again for the default filter.
// It has to be the same FileFilter instance and can't be a new file_filter() call.
dialog.add_filter(filter.clone());

if let Some(default) = &options.default_type {
if default == f {
// Note that we're providing the same FileFilter object to
// add_filter and set_filter, because gtk checks them for
// identity, not structural equality.
dialog.set_filter(&filter);
found_default_filter = true;
}
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 @@ -6,6 +6,7 @@
use crate::kurbo::{Point, Rect, Size};
use crate::screen::Monitor;
use gtk::gdk::{Display, DisplayManager, Rectangle};
use gtk::prelude::MonitorExt as _;

fn translate_gdk_rectangle(r: Rectangle) -> Rect {
Rect::from_origin_size(
Expand Down
53 changes: 27 additions & 26 deletions druid-shell/src/backend/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ use std::slice;
use std::sync::{Arc, Mutex, Weak};
use std::time::Instant;

use gtk::gdk::ffi::GdkKeymapKey;
use gtk::gdk_pixbuf::Colorspace::Rgb;
use gtk::gdk_pixbuf::Pixbuf;
use gtk::glib::source::Continue;
use gtk::glib::translate::FromGlib;
use gtk::glib::{ControlFlow, Propagation};
use gtk::prelude::*;
use gtk::traits::SettingsExt;
use gtk::{AccelGroup, ApplicationWindow, DrawingArea};

use gdk_sys::GdkKeymapKey;

use anyhow::anyhow;
use cairo::Surface;
use gtk::gdk::{
Expand Down Expand Up @@ -416,7 +414,7 @@ impl WindowBuilder {
.connect_enter_notify_event(|widget, _| {
widget.grab_focus();

Inhibit(true)
Propagation::Stop
});

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

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

win_state.drawing_area.connect_screen_changed(
Expand Down Expand Up @@ -584,7 +582,7 @@ impl WindowBuilder {
});
}

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

win_state.drawing_area.connect_button_release_event(clone!(handle => move |_widget, event| {
Expand All @@ -611,7 +609,7 @@ impl WindowBuilder {
});
}

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

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

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

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

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

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

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

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

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

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

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

win_state
Expand All @@ -743,7 +741,7 @@ impl WindowBuilder {
if let Some(state) = handle.state.upgrade() {
state.with_handler(|h| h.got_focus());
}
Inhibit(true)
Propagation::Stop
}));

win_state
Expand All @@ -752,17 +750,20 @@ impl WindowBuilder {
if let Some(state) = handle.state.upgrade() {
state.with_handler(|h| h.lost_focus());
}
Inhibit(true)
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())
match state.closing.get() {
true => Propagation::Proceed,
false => Propagation::Stop,
}
} else {
Inhibit(false)
Propagation::Proceed
}
}));

Expand Down Expand Up @@ -1218,9 +1219,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 @@ -1379,7 +1380,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 @@ -1401,7 +1402,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 @@ -1501,7 +1502,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 Expand Up @@ -1535,14 +1536,14 @@ fn make_key_event(key: &EventKey, repeat: bool, state: KeyState) -> KeyEvent {
/// keyval with the lowest group and level
fn hardware_keycode_to_keyval(keycode: u16) -> Option<keycodes::RawKey> {
unsafe {
let keymap = gdk_sys::gdk_keymap_get_default();
let keymap = gtk::gdk::ffi::gdk_keymap_get_default();

let mut nkeys = 0;
let mut keys: *mut GdkKeymapKey = ptr::null_mut();
let mut keyvals: *mut c_uint = ptr::null_mut();

// call into gdk to retrieve the keyvals and keymap keys
gdk_sys::gdk_keymap_get_entries_for_keycode(
gtk::gdk::ffi::gdk_keymap_get_entries_for_keycode(
keymap,
c_uint::from(keycode),
&mut keys as *mut *mut GdkKeymapKey,
Expand All @@ -1563,8 +1564,8 @@ fn hardware_keycode_to_keyval(keycode: u16) -> Option<keycodes::RawKey> {
});

// notify glib to free the allocated arrays
glib_sys::g_free(keyvals as *mut c_void);
glib_sys::g_free(keys as *mut c_void);
gtk::glib::ffi::g_free(keyvals as *mut c_void);
gtk::glib::ffi::g_free(keys as *mut c_void);

resolved_keyval
} else {
Expand Down
5 changes: 4 additions & 1 deletion druid-shell/src/backend/wayland/surfaces/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,10 @@ impl Data {
tracing::trace!("invalidate_rect initiated {:?}", rect);
// Quick check to see if we can skip the rect entirely (if it is outside the visible
// screen).
if rect.intersect(self.logical_size.get().to_rect()).is_empty() {
if rect
.intersect(self.logical_size.get().to_rect())
.is_zero_area()
{
return;
}
/* this would be useful for debugging over-keen invalidation by clients.
Expand Down
4 changes: 2 additions & 2 deletions druid-shell/src/backend/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ impl WindowBuilder {
let conn = self.app.connection();
let cairo_xcb_connection = unsafe {
CairoXCBConnection::from_raw_none(
conn.get_raw_xcb_connection() as *mut cairo_sys::xcb_connection_t
conn.get_raw_xcb_connection() as *mut cairo::ffi::xcb_connection_t
)
};
let cairo_drawable = XCBDrawable(window_id);
let mut xcb_visual = xcb_visualtype_t::from(*visual_type);
let cairo_visual_type = unsafe {
XCBVisualType::from_raw_none(
&mut xcb_visual as *mut xcb_visualtype_t as *mut cairo_sys::xcb_visualtype_t,
&mut xcb_visual as *mut xcb_visualtype_t as *mut cairo::ffi::xcb_visualtype_t,
)
};
let cairo_surface = XCBSurface::create(
Expand Down
7 changes: 2 additions & 5 deletions druid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ raw-win-handle = ["druid-shell/raw-win-handle"]
# support decoding, and that's all we use `Image` for.
png = ["druid-shell/image_png"]
jpeg = ["druid-shell/jpeg"]
jpeg_rayon = ["druid-shell/jpeg_rayon"]
gif = ["druid-shell/gif"]
bmp = ["druid-shell/bmp"]
ico = ["druid-shell/ico"]
Expand All @@ -43,12 +42,10 @@ webp = ["druid-shell/webp"]
pnm = ["druid-shell/pnm"]
dds = ["druid-shell/dds"]
tga = ["druid-shell/tga"]
farbfeld = ["druid-shell/farbfeld"]
dxt = ["druid-shell/dxt"]
hdr = ["druid-shell/hdr"]

# Remember to update this when changing an image feature.
image-all = ["image", "svg", "png", "jpeg", "jpeg_rayon", "gif", "bmp", "ico", "tiff", "webp", "pnm", "dds", "tga", "farbfeld", "dxt", "hdr"]
image-all = ["image", "svg", "png", "jpeg", "gif", "bmp", "ico", "tiff", "webp", "pnm", "dds", "tga", "hdr"]

[dependencies]
druid-shell = { version = "0.8.3", default-features = false, path = "../druid-shell" }
Expand Down Expand Up @@ -79,7 +76,7 @@ console_error_panic_hook = { version = "0.1.7" }
[dev-dependencies]
float-cmp = { version = "0.9.0", features = ["std"], default-features = false }
tempfile = "3.13.0"
piet-common = { version = "0.6.2", features = ["png"] }
piet-common = { version = "=0.7.0-cairo18", features = ["png"] }
pulldown-cmark = { version = "0.8.0", default-features = false }
test-log = { version = "0.2.16", features = ["trace"], default-features = false }
# test-env-log needs it
Expand Down
2 changes: 1 addition & 1 deletion druid/src/widget/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl<T: Data> Widget<T> for Image {
self.paint_data
.get_or_insert_with(|| image_data.to_image(ctx.render_ctx))
};
if piet_image.size().is_empty() {
if piet_image.size().is_zero_area() {
// zero-sized image = nothing to draw
return;
}
Expand Down

0 comments on commit 45b6156

Please sign in to comment.