Skip to content

Commit a7d9f5d

Browse files
gtk: Use glib enums instead of bools where it makes sense
1 parent 0333c9e commit a7d9f5d

File tree

19 files changed

+51
-32
lines changed

19 files changed

+51
-32
lines changed

examples/femtovg_area/femtovg_area/imp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl GLAreaImpl for FemtoVGArea {
8080
self.obj().scale_factor() as f32,
8181
);
8282
}
83-
fn render(&self, _context: &gtk::gdk::GLContext) -> bool {
83+
fn render(&self, _context: &gtk::gdk::GLContext) -> glib::Propagation {
8484
use femtovg::{Color, Paint, Path};
8585

8686
self.ensure_canvas();
@@ -126,7 +126,7 @@ impl GLAreaImpl for FemtoVGArea {
126126
canvas.stroke_path(&mut path, &paint);
127127
canvas.flush();
128128

129-
true
129+
glib::Propagation::Stop
130130
}
131131
}
132132
impl FemtoVGArea {

examples/glium_gl_area/glium_gl_area/imp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ impl WidgetImpl for GliumGLArea {
171171
}
172172

173173
impl GLAreaImpl for GliumGLArea {
174-
fn render(&self, _context: &gtk::gdk::GLContext) -> bool {
174+
fn render(&self, _context: &gtk::gdk::GLContext) -> glib::Propagation {
175175
self.renderer.borrow().as_ref().unwrap().draw();
176176

177-
true
177+
glib::Propagation::Stop
178178
}
179179
}

gdk4/src/surface.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub trait SurfaceExtManual: sealed::Sealed + IsA<Surface> + 'static {
2828
}
2929
}
3030

31+
// Returns true if the coordinates were successfully translated
3132
#[doc(alias = "gdk_surface_translate_coordinates")]
3233
fn translate_coordinates(&self, to: &Surface, mut x: f64, mut y: f64) -> bool {
3334
unsafe {

gsk4/src/path.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use glib::translate::*;
55

66
impl Path {
77
#[doc(alias = "gsk_path_foreach")]
8-
pub fn foreach<P: FnMut(&PathOperation, &graphene::Point, usize, f32) -> bool>(
8+
pub fn foreach<P: FnMut(&PathOperation, &graphene::Point, usize, f32) -> glib::ControlFlow>(
99
&self,
1010
flags: PathForeachFlags,
1111
func: P,
12-
) -> bool {
12+
) -> glib::ControlFlow {
1313
let func_data: P = func;
1414
unsafe extern "C" fn func_func<
15-
P: FnMut(&PathOperation, &graphene::Point, usize, f32) -> bool,
15+
P: FnMut(&PathOperation, &graphene::Point, usize, f32) -> glib::ControlFlow,
1616
>(
1717
op: ffi::GskPathOperation,
1818
pts: *const graphene::ffi::graphene_point_t,

gtk4/src/drop_target.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl DropTarget {
4545
}
4646
}
4747

48+
// Returns true if the drop was accepted
4849
pub fn connect_drop<F: Fn(&DropTarget, &glib::Value, f64, f64) -> bool + 'static>(
4950
&self,
5051
f: F,

gtk4/src/shortcuts_section.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,22 @@ use glib::{
88
use std::mem::transmute;
99

1010
impl ShortcutsSection {
11+
// todo: figure out what the bool return value here corresponds to
1112
pub fn connect_change_current_page<F: Fn(&ShortcutsSection, i32) -> bool + 'static>(
1213
&self,
1314
f: F,
1415
) -> SignalHandlerId {
1516
unsafe {
17+
unsafe extern "C" fn change_current_page_trampoline<
18+
F: Fn(&ShortcutsSection, i32) -> bool + 'static,
19+
>(
20+
this: *mut ffi::GtkShortcutsSection,
21+
object: libc::c_int,
22+
f: glib::ffi::gpointer,
23+
) -> glib::ffi::gboolean {
24+
let f: &F = &*(f as *const F);
25+
f(&from_glib_borrow(this), object).into_glib()
26+
}
1627
let f = Box::new(f);
1728
connect_raw(
1829
self.as_ptr() as *mut _,
@@ -27,14 +38,3 @@ impl ShortcutsSection {
2738
self.emit_by_name("change-current-page", &[&object])
2839
}
2940
}
30-
31-
unsafe extern "C" fn change_current_page_trampoline<
32-
F: Fn(&ShortcutsSection, i32) -> bool + 'static,
33-
>(
34-
this: *mut ffi::GtkShortcutsSection,
35-
object: libc::c_int,
36-
f: glib::ffi::gpointer,
37-
) -> glib::ffi::gboolean {
38-
let f: &F = &*(f as *const F);
39-
f(&from_glib_borrow(this), object).into_glib()
40-
}

gtk4/src/subclass/accessible_range.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mod sealed {
1818
}
1919

2020
pub trait AccessibleRangeImplExt: sealed::Sealed + ObjectSubclass {
21+
// Returns true if the operation was performed, false otherwise
2122
fn parent_set_current_value(&self, accessible_range: &Self::Type, value: f64) -> bool {
2223
unsafe {
2324
let type_data = Self::type_data();

gtk4/src/subclass/cell_area.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@ pub struct CellCallback {
1717
}
1818

1919
impl CellCallback {
20-
pub fn call<R: IsA<CellRenderer>>(&self, cell_renderer: &R) -> bool {
20+
pub fn call<R: IsA<CellRenderer>>(&self, cell_renderer: &R) -> glib::ControlFlow {
2121
unsafe {
2222
if let Some(callback) = self.callback {
2323
from_glib(callback(
2424
cell_renderer.as_ref().to_glib_none().0,
2525
self.user_data,
2626
))
2727
} else {
28-
// true to stop iterating over cells
29-
true
28+
glib::ControlFlow::Break
3029
}
3130
}
3231
}
@@ -44,7 +43,7 @@ impl CellCallbackAllocate {
4443
cell_renderer: &R,
4544
cell_area: &gdk::Rectangle,
4645
cell_background: &gdk::Rectangle,
47-
) -> bool {
46+
) -> glib::ControlFlow {
4847
unsafe {
4948
if let Some(callback) = self.callback {
5049
from_glib(callback(
@@ -54,8 +53,7 @@ impl CellCallbackAllocate {
5453
self.user_data,
5554
))
5655
} else {
57-
// true to stop iterating over cells
58-
true
56+
glib::ControlFlow::Break
5957
}
6058
}
6159
}
@@ -227,6 +225,7 @@ mod sealed {
227225
#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
228226
#[allow(deprecated)]
229227
pub trait CellAreaImplExt: sealed::Sealed + ObjectSubclass {
228+
// Returns true if the area was successfully activated
230229
fn parent_activate<P: IsA<CellAreaContext>, W: IsA<Widget>>(
231230
&self,
232231
context: &P,
@@ -317,6 +316,7 @@ pub trait CellAreaImplExt: sealed::Sealed + ObjectSubclass {
317316
}
318317
}
319318

319+
// returns true only if the event is handled
320320
fn parent_event<W: IsA<Widget>, P: IsA<CellAreaContext>>(
321321
&self,
322322
context: &P,
@@ -338,7 +338,6 @@ pub trait CellAreaImplExt: sealed::Sealed + ObjectSubclass {
338338
flags.into_glib(),
339339
))
340340
} else {
341-
// returns true only if the event is handled
342341
false
343342
}
344343
}
@@ -396,6 +395,7 @@ pub trait CellAreaImplExt: sealed::Sealed + ObjectSubclass {
396395
}
397396
}
398397

398+
// Whether the cell is activatable
399399
fn parent_is_activatable(&self) -> bool {
400400
unsafe {
401401
let data = Self::type_data();
@@ -408,6 +408,7 @@ pub trait CellAreaImplExt: sealed::Sealed + ObjectSubclass {
408408
}
409409
}
410410

411+
// TRUE if focus remains inside area as a result of this call.
411412
fn parent_focus(&self, direction_type: DirectionType) -> bool {
412413
unsafe {
413414
let data = Self::type_data();

gtk4/src/subclass/cell_renderer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ pub trait CellRendererImplExt: sealed::Sealed + ObjectSubclass {
257257
}
258258
}
259259

260+
// Returns true if the event was consumed/handled
260261
fn parent_activate<P: IsA<Widget>>(
261262
&self,
262263
event: Option<&gdk::Event>,

gtk4/src/subclass/font_chooser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct FilterCallback {
1717
}
1818

1919
impl FilterCallback {
20+
// true if the font should be displayed
2021
pub fn call(&self, font_family: &FontFamily, font_face: &FontFace) -> bool {
2122
unsafe {
2223
if let Some(filter_func) = self.filter_func {

0 commit comments

Comments
 (0)