Skip to content

Commit

Permalink
gtk: Use glib enums instead of bools where it makes sense
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelmoussaoui committed Oct 14, 2023
1 parent 07a28d8 commit b55f5ec
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 28 deletions.
1 change: 1 addition & 0 deletions gdk4/src/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub trait SurfaceExtManual: sealed::Sealed + IsA<Surface> + 'static {
}
}

// Returns true if the coordinates were successfully translated
#[doc(alias = "gdk_surface_translate_coordinates")]
fn translate_coordinates(&self, to: &Surface, mut x: f64, mut y: f64) -> bool {
unsafe {
Expand Down
6 changes: 3 additions & 3 deletions gsk4/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use glib::translate::*;

impl Path {
#[doc(alias = "gsk_path_foreach")]
pub fn foreach<P: FnMut(&PathOperation, &graphene::Point, usize, f32) -> bool>(
pub fn foreach<P: FnMut(&PathOperation, &graphene::Point, usize, f32) -> glib::ControlFlow>(
&self,
flags: PathForeachFlags,
func: P,
) -> bool {
) -> glib::ControlFlow {
let func_data: P = func;
unsafe extern "C" fn func_func<
P: FnMut(&PathOperation, &graphene::Point, usize, f32) -> bool,
P: FnMut(&PathOperation, &graphene::Point, usize, f32) -> glib::ControlFlow,
>(
op: ffi::GskPathOperation,
pts: *const graphene::ffi::graphene_point_t,
Expand Down
1 change: 1 addition & 0 deletions gtk4/src/drop_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl DropTarget {
}
}

// Returns true if the drop was accepted
pub fn connect_drop<F: Fn(&DropTarget, &glib::Value, f64, f64) -> bool + 'static>(
&self,
f: F,
Expand Down
22 changes: 11 additions & 11 deletions gtk4/src/shortcuts_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@ use glib::{
use std::mem::transmute;

impl ShortcutsSection {
// todo: figure out what the bool return value here corresponds to
pub fn connect_change_current_page<F: Fn(&ShortcutsSection, i32) -> bool + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe {
unsafe extern "C" fn change_current_page_trampoline<
F: Fn(&ShortcutsSection, i32) -> bool + 'static,
>(
this: *mut ffi::GtkShortcutsSection,
object: libc::c_int,
f: glib::ffi::gpointer,
) -> glib::ffi::gboolean {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), object).into_glib()
}
let f = Box::new(f);
connect_raw(
self.as_ptr() as *mut _,
Expand All @@ -27,14 +38,3 @@ impl ShortcutsSection {
self.emit_by_name("change-current-page", &[&object])
}
}

unsafe extern "C" fn change_current_page_trampoline<
F: Fn(&ShortcutsSection, i32) -> bool + 'static,
>(
this: *mut ffi::GtkShortcutsSection,
object: libc::c_int,
f: glib::ffi::gpointer,
) -> glib::ffi::gboolean {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), object).into_glib()
}
1 change: 1 addition & 0 deletions gtk4/src/subclass/accessible_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod sealed {
}

pub trait AccessibleRangeImplExt: sealed::Sealed + ObjectSubclass {
// Returns true if the operation was performed, false otherwise
fn parent_set_current_value(&self, accessible_range: &Self::Type, value: f64) -> bool {
unsafe {
let type_data = Self::type_data();
Expand Down
15 changes: 8 additions & 7 deletions gtk4/src/subclass/cell_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ pub struct CellCallback {
}

impl CellCallback {
pub fn call<R: IsA<CellRenderer>>(&self, cell_renderer: &R) -> bool {
pub fn call<R: IsA<CellRenderer>>(&self, cell_renderer: &R) -> glib::ControlFlow {
unsafe {
if let Some(callback) = self.callback {
from_glib(callback(
cell_renderer.as_ref().to_glib_none().0,
self.user_data,
))
} else {
// true to stop iterating over cells
true
glib::ControlFlow::Break
}
}
}
Expand All @@ -44,7 +43,7 @@ impl CellCallbackAllocate {
cell_renderer: &R,
cell_area: &gdk::Rectangle,
cell_background: &gdk::Rectangle,
) -> bool {
) -> glib::ControlFlow {
unsafe {
if let Some(callback) = self.callback {
from_glib(callback(
Expand All @@ -54,8 +53,7 @@ impl CellCallbackAllocate {
self.user_data,
))
} else {
// true to stop iterating over cells
true
glib::ControlFlow::Break
}
}
}
Expand Down Expand Up @@ -227,6 +225,7 @@ mod sealed {
#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
#[allow(deprecated)]
pub trait CellAreaImplExt: sealed::Sealed + ObjectSubclass {
// Returns true if the area was successfully activated
fn parent_activate<P: IsA<CellAreaContext>, W: IsA<Widget>>(
&self,
context: &P,
Expand Down Expand Up @@ -317,6 +316,7 @@ pub trait CellAreaImplExt: sealed::Sealed + ObjectSubclass {
}
}

// returns true only if the event is handled
fn parent_event<W: IsA<Widget>, P: IsA<CellAreaContext>>(
&self,
context: &P,
Expand All @@ -338,7 +338,6 @@ pub trait CellAreaImplExt: sealed::Sealed + ObjectSubclass {
flags.into_glib(),
))
} else {
// returns true only if the event is handled
false
}
}
Expand Down Expand Up @@ -396,6 +395,7 @@ pub trait CellAreaImplExt: sealed::Sealed + ObjectSubclass {
}
}

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

// TRUE if focus remains inside area as a result of this call.
fn parent_focus(&self, direction_type: DirectionType) -> bool {
unsafe {
let data = Self::type_data();
Expand Down
1 change: 1 addition & 0 deletions gtk4/src/subclass/cell_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ pub trait CellRendererImplExt: sealed::Sealed + ObjectSubclass {
}
}

// Returns true if the event was consumed/handled
fn parent_activate<P: IsA<Widget>>(
&self,
event: Option<&gdk::Event>,
Expand Down
1 change: 1 addition & 0 deletions gtk4/src/subclass/font_chooser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct FilterCallback {
}

impl FilterCallback {
// true if the font should be displayed
pub fn call(&self, font_family: &FontFamily, font_face: &FontFace) -> bool {
unsafe {
if let Some(filter_func) = self.filter_func {
Expand Down
4 changes: 2 additions & 2 deletions gtk4/src/subclass/gl_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub trait GLAreaImpl: GLAreaImplExt + WidgetImpl {
self.parent_create_context()
}

fn render(&self, context: &GLContext) -> bool {
fn render(&self, context: &GLContext) -> glib::Propagation {
self.parent_render(context)
}

Expand Down Expand Up @@ -44,7 +44,7 @@ pub trait GLAreaImplExt: sealed::Sealed + ObjectSubclass {
}
}

fn parent_render(&self, context: &GLContext) -> bool {
fn parent_render(&self, context: &GLContext) -> glib::Propagation {
unsafe {
let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GtkGLAreaClass;
Expand Down
6 changes: 3 additions & 3 deletions gtk4/src/subclass/im_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub trait IMContextImplExt: sealed::Sealed + ObjectSubclass {
}
}

// Returns true if the signal was handled
fn parent_delete_surrounding(&self, offset: i32, n_chars: i32) -> bool {
unsafe {
let data = Self::type_data();
Expand All @@ -99,12 +100,12 @@ pub trait IMContextImplExt: sealed::Sealed + ObjectSubclass {
n_chars,
))
} else {
// Returns true if the signal was handled
false
}
}
}

// Returns true if the event was consumed
fn parent_filter_keypress(&self, event: &gdk::Event) -> bool {
unsafe {
let data = Self::type_data();
Expand All @@ -115,7 +116,6 @@ pub trait IMContextImplExt: sealed::Sealed + ObjectSubclass {
event.to_glib_none().0,
))
} else {
// Returns true if the event was consumed
false
}
}
Expand Down Expand Up @@ -225,6 +225,7 @@ pub trait IMContextImplExt: sealed::Sealed + ObjectSubclass {
}
}

// Returns true if the signal was handled
fn parent_retrieve_surrounding(&self) -> bool {
unsafe {
let data = Self::type_data();
Expand All @@ -236,7 +237,6 @@ pub trait IMContextImplExt: sealed::Sealed + ObjectSubclass {
.to_glib_none()
.0))
} else {
// Returns true if the signal was handled
false
}
}
Expand Down
1 change: 1 addition & 0 deletions gtk4/src/subclass/media_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub trait MediaStreamImplExt: sealed::Sealed + ObjectSubclass {
}
}

// Returns true if successfully started playing
fn parent_play(&self) -> bool {
unsafe {
let data = Self::type_data();
Expand Down
2 changes: 2 additions & 0 deletions gtk4/src/subclass/print_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ pub trait PrintOperationImplExt: sealed::Sealed + ObjectSubclass {
}
}

// Returns true if pagination is complete
fn parent_paginate(&self, context: &PrintContext) -> bool {
unsafe {
let data = Self::type_data();
Expand All @@ -183,6 +184,7 @@ pub trait PrintOperationImplExt: sealed::Sealed + ObjectSubclass {
}
}

// true if the listener wants to take over control of the preview.
fn parent_preview(
&self,
preview: &PrintOperationPreview,
Expand Down
4 changes: 2 additions & 2 deletions gtk4/src/subclass/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait RangeImpl: RangeImplExt + WidgetImpl {
self.parent_adjust_bounds(new_value)
}

fn change_value(&self, scroll_type: ScrollType, new_value: f64) -> bool {
fn change_value(&self, scroll_type: ScrollType, new_value: f64) -> glib::Propagation {
self.parent_change_value(scroll_type, new_value)
}

Expand Down Expand Up @@ -48,7 +48,7 @@ pub trait RangeImplExt: sealed::Sealed + ObjectSubclass {
}
}

fn parent_change_value(&self, scroll_type: ScrollType, new_value: f64) -> bool {
fn parent_change_value(&self, scroll_type: ScrollType, new_value: f64) -> glib::Propagation {
unsafe {
let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GtkRangeClass;
Expand Down
2 changes: 2 additions & 0 deletions gtk4/src/subclass/tree_drag_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod sealed {
#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
#[allow(deprecated)]
pub trait TreeDragSourceImplExt: sealed::Sealed + ObjectSubclass {
// Returns true if the row can be dragged
fn parent_row_draggable(&self, path: &TreePath) -> bool {
unsafe {
let type_data = Self::type_data();
Expand Down Expand Up @@ -65,6 +66,7 @@ pub trait TreeDragSourceImplExt: sealed::Sealed + ObjectSubclass {
}
}

// True if the row was successfully deleted
fn parent_drag_data_delete(&self, path: &TreePath) -> bool {
unsafe {
let type_data = Self::type_data();
Expand Down
1 change: 1 addition & 0 deletions gtk4/src/subclass/tree_model_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ mod sealed {
#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
#[allow(deprecated)]
pub trait TreeModelFilterImplExt: sealed::Sealed + ObjectSubclass {
// Whether the row indicated by iter is visible
fn parent_visible<M: IsA<TreeModel>>(&self, child_model: &M, iter: &TreeIter) -> bool {
unsafe {
let data = Self::type_data();
Expand Down
6 changes: 6 additions & 0 deletions gtk4/src/subclass/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ pub trait WidgetImplExt: sealed::Sealed + ObjectSubclass {
}
}

// true if the widget contains (x, y)
fn parent_contains(&self, x: f64, y: f64) -> bool {
unsafe {
let data = Self::type_data();
Expand Down Expand Up @@ -259,6 +260,7 @@ pub trait WidgetImplExt: sealed::Sealed + ObjectSubclass {
}
}

// Returns true if focus ended up inside widget
fn parent_focus(&self, direction_type: DirectionType) -> bool {
unsafe {
let data = Self::type_data();
Expand All @@ -285,6 +287,7 @@ pub trait WidgetImplExt: sealed::Sealed + ObjectSubclass {
}
}

// Returns true if focus ended up inside widget
fn parent_grab_focus(&self) -> bool {
unsafe {
let data = Self::type_data();
Expand All @@ -309,6 +312,8 @@ pub trait WidgetImplExt: sealed::Sealed + ObjectSubclass {
}
}

// TRUE if stopping keyboard navigation is fine,
// FALSE if the emitting widget should try to handle the keyboard navigation attempt in its parent container(s).
fn parent_keynav_failed(&self, direction_type: DirectionType) -> bool {
unsafe {
let data = Self::type_data();
Expand Down Expand Up @@ -360,6 +365,7 @@ pub trait WidgetImplExt: sealed::Sealed + ObjectSubclass {
}
}

// True if the signal has been handled
fn parent_mnemonic_activate(&self, group_cycling: bool) -> bool {
unsafe {
let data = Self::type_data();
Expand Down
1 change: 1 addition & 0 deletions gtk4/src/subclass/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub trait WindowImplExt: sealed::Sealed + ObjectSubclass {
}
}

// Returns true if debugging (inspector) should be enabled, false otherwise
fn parent_enable_debugging(&self, toggle: bool) -> bool {
unsafe {
let data = Self::type_data();
Expand Down

0 comments on commit b55f5ec

Please sign in to comment.