Skip to content

Commit 45b6156

Browse files
committed
Update Piet to v0.7.0-cairo18.
1 parent b831b5f commit 45b6156

File tree

8 files changed

+48
-56
lines changed

8 files changed

+48
-56
lines changed

druid-shell/Cargo.toml

+8-17
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,21 @@ cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
1818

1919
[features]
2020
default = ["gtk"]
21-
gtk = ["gdk-sys", "glib-sys", "gtk-sys", "gtk-rs"]
21+
gtk = ["gtk-rs"]
2222
x11 = [
2323
"ashpd",
2424
"bindgen",
25-
"cairo-sys-rs",
2625
"futures",
2726
"nix",
2827
"pkg-config",
2928
"x11rb",
29+
"cairo-rs/xcb",
3030
]
3131
wayland = [
3232
"wayland-client",
3333
"wayland-protocols/client",
3434
"wayland-protocols/unstable_protocols",
3535
"nix",
36-
"cairo-sys-rs",
3736
"rand",
3837
"calloop",
3938
"wayland-cursor",
@@ -50,7 +49,6 @@ raw-win-handle = ["raw-window-handle"]
5049
image = ["piet-common/image"]
5150
image_png = ["piet-common/image_png"]
5251
jpeg = ["piet-common/jpeg"]
53-
jpeg_rayon = ["piet-common/jpeg_rayon"]
5452
gif = ["piet-common/gif"]
5553
bmp = ["piet-common/bmp"]
5654
ico = ["piet-common/ico"]
@@ -59,13 +57,11 @@ webp = ["piet-common/webp"]
5957
pnm = ["piet-common/pnm"]
6058
dds = ["piet-common/dds"]
6159
tga = ["piet-common/tga"]
62-
farbfeld = ["piet-common/farbfeld"]
63-
dxt = ["piet-common/dxt"]
6460
hdr = ["piet-common/hdr"]
6561
serde = ["piet-common/serde"]
6662

6763
[dependencies]
68-
piet-common = "0.6.2"
64+
piet-common = { version = "=0.7.0-cairo18" }
6965

7066
tracing = "0.1.40"
7167
once_cell = "1.20.2"
@@ -93,21 +89,16 @@ features = ["d2d1_1", "dwrite", "winbase", "libloaderapi", "errhandlingapi", "wi
9389
block = "0.1.6"
9490
cocoa = "0.24.1"
9591
objc = "0.2.7"
96-
core-graphics = "0.22.3"
97-
foreign-types = "0.3.2"
92+
core-graphics = "0.24.0"
93+
foreign-types = "0.5.0"
9894
bitflags = "1.3.2"
9995

10096
[target.'cfg(any(target_os = "freebsd", target_os="linux", target_os="openbsd"))'.dependencies]
10197
ashpd = { version = "0.3.2", optional = true }
102-
# TODO(x11/dependencies): only use feature "xcb" if using X11
103-
cairo-rs = { version = "0.16.7", default-features = false, features = ["xcb"] }
104-
cairo-sys-rs = { version = "0.16.3", default-features = false, optional = true }
98+
cairo-rs = { version = "0.18.5", default-features = false }
10599
futures = { version = "0.3.31", optional = true, features = ["executor"]}
106-
gdk-sys = { version = "0.16.0", optional = true }
107100
# `gtk` gets renamed to `gtk-rs` so that we can use `gtk` as the feature name.
108-
gtk-rs = { version = "0.16.2", package = "gtk", optional = true }
109-
glib-sys = { version = "0.16.3", optional = true }
110-
gtk-sys = { version = "0.16.0", optional = true }
101+
gtk-rs = { version = "0.18.1", package = "gtk", optional = true }
111102
nix = { version = "0.24.3", optional = true }
112103
x11rb = { version = "0.10.1", features = ["allow-unsafe-code", "present", "render", "randr", "xfixes", "xkb", "resource_manager", "cursor"], optional = true }
113104
wayland-client = { version = "0.29.5", optional = true }
@@ -127,7 +118,7 @@ version = "0.3.72"
127118
features = ["Window", "MouseEvent", "CssStyleDeclaration", "WheelEvent", "KeyEvent", "KeyboardEvent", "Navigator"]
128119

129120
[dev-dependencies]
130-
piet-common = { version = "0.6.2", features = ["png"] }
121+
piet-common = { version = "=0.7.0-cairo18", features = ["png"] }
131122
static_assertions = "1.1.0"
132123
test-log = { version = "0.2.16", features = ["trace"], default-features = false }
133124
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

druid-shell/src/backend/gtk/dialog.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@ pub(crate) fn get_file_dialog_path(
5959
if let Some(file_types) = &options.allowed_types {
6060
for f in file_types {
6161
let filter = file_filter(f);
62-
dialog.add_filter(&filter);
62+
// We need to clone filter, because we may need it again for the default filter.
63+
// It has to be the same FileFilter instance and can't be a new file_filter() call.
64+
dialog.add_filter(filter.clone());
6365

6466
if let Some(default) = &options.default_type {
6567
if default == f {
66-
// Note that we're providing the same FileFilter object to
67-
// add_filter and set_filter, because gtk checks them for
68-
// identity, not structural equality.
6968
dialog.set_filter(&filter);
7069
found_default_filter = true;
7170
}

druid-shell/src/backend/gtk/screen.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use crate::kurbo::{Point, Rect, Size};
77
use crate::screen::Monitor;
88
use gtk::gdk::{Display, DisplayManager, Rectangle};
9+
use gtk::prelude::MonitorExt as _;
910

1011
fn translate_gdk_rectangle(r: Rectangle) -> Rect {
1112
Rect::from_origin_size(

druid-shell/src/backend/gtk/window.rs

+27-26
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ use std::slice;
1313
use std::sync::{Arc, Mutex, Weak};
1414
use std::time::Instant;
1515

16+
use gtk::gdk::ffi::GdkKeymapKey;
1617
use gtk::gdk_pixbuf::Colorspace::Rgb;
1718
use gtk::gdk_pixbuf::Pixbuf;
18-
use gtk::glib::source::Continue;
1919
use gtk::glib::translate::FromGlib;
20+
use gtk::glib::{ControlFlow, Propagation};
2021
use gtk::prelude::*;
21-
use gtk::traits::SettingsExt;
2222
use gtk::{AccelGroup, ApplicationWindow, DrawingArea};
2323

24-
use gdk_sys::GdkKeymapKey;
25-
2624
use anyhow::anyhow;
2725
use cairo::Surface;
2826
use gtk::gdk::{
@@ -416,7 +414,7 @@ impl WindowBuilder {
416414
.connect_enter_notify_event(|widget, _| {
417415
widget.grab_focus();
418416

419-
Inhibit(true)
417+
Propagation::Stop
420418
});
421419

422420
// Set the minimum size
@@ -528,7 +526,7 @@ impl WindowBuilder {
528526
}
529527
}
530528

531-
Inhibit(false)
529+
Propagation::Proceed
532530
}));
533531

534532
win_state.drawing_area.connect_screen_changed(
@@ -584,7 +582,7 @@ impl WindowBuilder {
584582
});
585583
}
586584

587-
Inhibit(true)
585+
Propagation::Stop
588586
}));
589587

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

614-
Inhibit(true)
612+
Propagation::Stop
615613
}));
616614

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

635-
Inhibit(true)
633+
Propagation::Stop
636634
}),
637635
);
638636

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

645-
Inhibit(true)
643+
Propagation::Stop
646644
}),
647645
);
648646

@@ -698,7 +696,7 @@ impl WindowBuilder {
698696
}
699697
}
700698

701-
Inhibit(true)
699+
Propagation::Stop
702700
}));
703701

704702
win_state
@@ -716,7 +714,7 @@ impl WindowBuilder {
716714
);
717715
}
718716

719-
Inhibit(true)
717+
Propagation::Stop
720718
}));
721719

722720
win_state
@@ -734,7 +732,7 @@ impl WindowBuilder {
734732
);
735733
}
736734

737-
Inhibit(true)
735+
Propagation::Stop
738736
}));
739737

740738
win_state
@@ -743,7 +741,7 @@ impl WindowBuilder {
743741
if let Some(state) = handle.state.upgrade() {
744742
state.with_handler(|h| h.got_focus());
745743
}
746-
Inhibit(true)
744+
Propagation::Stop
747745
}));
748746

749747
win_state
@@ -752,17 +750,20 @@ impl WindowBuilder {
752750
if let Some(state) = handle.state.upgrade() {
753751
state.with_handler(|h| h.lost_focus());
754752
}
755-
Inhibit(true)
753+
Propagation::Stop
756754
}));
757755

758756
win_state
759757
.window
760758
.connect_delete_event(clone!(handle => move |_widget, _ev| {
761759
if let Some(state) = handle.state.upgrade() {
762760
state.with_handler(|h| h.request_close());
763-
Inhibit(!state.closing.get())
761+
match state.closing.get() {
762+
true => Propagation::Proceed,
763+
false => Propagation::Stop,
764+
}
764765
} else {
765-
Inhibit(false)
766+
Propagation::Proceed
766767
}
767768
}));
768769

@@ -1218,9 +1219,9 @@ impl WindowHandle {
12181219
if let Some(state) = self.state.upgrade() {
12191220
gtk::glib::timeout_add(interval, move || {
12201221
if state.with_handler(|h| h.timer(token)).is_some() {
1221-
return Continue(false);
1222+
return ControlFlow::Break;
12221223
}
1223-
Continue(true)
1224+
ControlFlow::Continue
12241225
});
12251226
}
12261227
token
@@ -1379,7 +1380,7 @@ impl IdleHandle {
13791380
}
13801381
}
13811382

1382-
fn run_idle(state: &Arc<WindowState>) -> Continue {
1383+
fn run_idle(state: &Arc<WindowState>) -> ControlFlow {
13831384
util::assert_main_thread();
13841385
let result = state.with_handler(|handler| {
13851386
let queue: Vec<_> = std::mem::take(&mut state.idle_queue.lock().unwrap());
@@ -1401,7 +1402,7 @@ fn run_idle(state: &Arc<WindowState>) -> Continue {
14011402
let timeout = Duration::from_millis(16);
14021403
gtk::glib::timeout_add(timeout, move || run_idle(&state));
14031404
}
1404-
Continue(false)
1405+
ControlFlow::Break
14051406
}
14061407

14071408
fn make_gdk_cursor(cursor: &Cursor, gdk_window: &Window) -> Option<gtk::gdk::Cursor> {
@@ -1501,7 +1502,7 @@ fn make_key_event(key: &EventKey, repeat: bool, state: KeyState) -> KeyEvent {
15011502
let keyval = key.keyval();
15021503
let hardware_keycode = key.hardware_keycode();
15031504

1504-
let keycode = hardware_keycode_to_keyval(hardware_keycode).unwrap_or_else(|| keyval.clone());
1505+
let keycode = hardware_keycode_to_keyval(hardware_keycode).unwrap_or(keyval);
15051506

15061507
let text = keyval.to_unicode();
15071508
let mods = get_modifiers(key.state());
@@ -1535,14 +1536,14 @@ fn make_key_event(key: &EventKey, repeat: bool, state: KeyState) -> KeyEvent {
15351536
/// keyval with the lowest group and level
15361537
fn hardware_keycode_to_keyval(keycode: u16) -> Option<keycodes::RawKey> {
15371538
unsafe {
1538-
let keymap = gdk_sys::gdk_keymap_get_default();
1539+
let keymap = gtk::gdk::ffi::gdk_keymap_get_default();
15391540

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

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

15651566
// notify glib to free the allocated arrays
1566-
glib_sys::g_free(keyvals as *mut c_void);
1567-
glib_sys::g_free(keys as *mut c_void);
1567+
gtk::glib::ffi::g_free(keyvals as *mut c_void);
1568+
gtk::glib::ffi::g_free(keys as *mut c_void);
15681569

15691570
resolved_keyval
15701571
} else {

druid-shell/src/backend/wayland/surfaces/surface.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,10 @@ impl Data {
500500
tracing::trace!("invalidate_rect initiated {:?}", rect);
501501
// Quick check to see if we can skip the rect entirely (if it is outside the visible
502502
// screen).
503-
if rect.intersect(self.logical_size.get().to_rect()).is_empty() {
503+
if rect
504+
.intersect(self.logical_size.get().to_rect())
505+
.is_zero_area()
506+
{
504507
return;
505508
}
506509
/* this would be useful for debugging over-keen invalidation by clients.

druid-shell/src/backend/x11/window.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,14 @@ impl WindowBuilder {
192192
let conn = self.app.connection();
193193
let cairo_xcb_connection = unsafe {
194194
CairoXCBConnection::from_raw_none(
195-
conn.get_raw_xcb_connection() as *mut cairo_sys::xcb_connection_t
195+
conn.get_raw_xcb_connection() as *mut cairo::ffi::xcb_connection_t
196196
)
197197
};
198198
let cairo_drawable = XCBDrawable(window_id);
199199
let mut xcb_visual = xcb_visualtype_t::from(*visual_type);
200200
let cairo_visual_type = unsafe {
201201
XCBVisualType::from_raw_none(
202-
&mut xcb_visual as *mut xcb_visualtype_t as *mut cairo_sys::xcb_visualtype_t,
202+
&mut xcb_visual as *mut xcb_visualtype_t as *mut cairo::ffi::xcb_visualtype_t,
203203
)
204204
};
205205
let cairo_surface = XCBSurface::create(

druid/Cargo.toml

+2-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ raw-win-handle = ["druid-shell/raw-win-handle"]
3434
# support decoding, and that's all we use `Image` for.
3535
png = ["druid-shell/image_png"]
3636
jpeg = ["druid-shell/jpeg"]
37-
jpeg_rayon = ["druid-shell/jpeg_rayon"]
3837
gif = ["druid-shell/gif"]
3938
bmp = ["druid-shell/bmp"]
4039
ico = ["druid-shell/ico"]
@@ -43,12 +42,10 @@ webp = ["druid-shell/webp"]
4342
pnm = ["druid-shell/pnm"]
4443
dds = ["druid-shell/dds"]
4544
tga = ["druid-shell/tga"]
46-
farbfeld = ["druid-shell/farbfeld"]
47-
dxt = ["druid-shell/dxt"]
4845
hdr = ["druid-shell/hdr"]
4946

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

5350
[dependencies]
5451
druid-shell = { version = "0.8.3", default-features = false, path = "../druid-shell" }
@@ -79,7 +76,7 @@ console_error_panic_hook = { version = "0.1.7" }
7976
[dev-dependencies]
8077
float-cmp = { version = "0.9.0", features = ["std"], default-features = false }
8178
tempfile = "3.13.0"
82-
piet-common = { version = "0.6.2", features = ["png"] }
79+
piet-common = { version = "=0.7.0-cairo18", features = ["png"] }
8380
pulldown-cmark = { version = "0.8.0", default-features = false }
8481
test-log = { version = "0.2.16", features = ["trace"], default-features = false }
8582
# test-env-log needs it

druid/src/widget/image.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl<T: Data> Widget<T> for Image {
221221
self.paint_data
222222
.get_or_insert_with(|| image_data.to_image(ctx.render_ctx))
223223
};
224-
if piet_image.size().is_empty() {
224+
if piet_image.size().is_zero_area() {
225225
// zero-sized image = nothing to draw
226226
return;
227227
}

0 commit comments

Comments
 (0)