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

gtk: Use glib enums instead of bools where it makes sense #1512

Merged
merged 7 commits into from
Oct 15, 2023
Merged
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
4 changes: 2 additions & 2 deletions examples/femtovg_area/femtovg_area/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl GLAreaImpl for FemtoVGArea {
self.obj().scale_factor() as f32,
);
}
fn render(&self, _context: &gtk::gdk::GLContext) -> bool {
fn render(&self, _context: &gtk::gdk::GLContext) -> glib::Propagation {
use femtovg::{Color, Paint, Path};

self.ensure_canvas();
Expand Down Expand Up @@ -126,7 +126,7 @@ impl GLAreaImpl for FemtoVGArea {
canvas.stroke_path(&mut path, &paint);
canvas.flush();

true
glib::Propagation::Stop
}
}
impl FemtoVGArea {
Expand Down
4 changes: 2 additions & 2 deletions examples/glium_gl_area/glium_gl_area/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ impl WidgetImpl for GliumGLArea {
}

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

true
glib::Propagation::Stop
}
}
2 changes: 1 addition & 1 deletion examples/list_box_model/list_box_row/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl ObjectImpl for ListBoxRow {
.build();
content_area.append(&spin_button);

dialog.show()
dialog.present()
}));
hbox.append(&edit_button);

Expand Down
2 changes: 1 addition & 1 deletion examples/list_box_model/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn build_ui(application: &gtk::Application) {
dialog.close();
}));

dialog.show()
dialog.present()
}));

hbox.append(&add_button);
Expand Down
4 changes: 2 additions & 2 deletions gdk4-wayland/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ gdk = {path = "../gdk4", package = "gdk4", version = "0.8"}
gio = {git = "https://github.com/gtk-rs/gtk-rs-core", version = "0.19", features = ["v2_66"]}
glib = {git = "https://github.com/gtk-rs/gtk-rs-core", version = "0.19", features = ["v2_66"]}
libc = "0.2"
wayland-client = {version = "0.30.0", optional = true}
wayland-backend = {version = "0.1.0", optional = true, features = ["client_system"]}
wayland-client = {version = "0.31.0", optional = true}
wayland-backend = {version = "0.3.0", optional = true, features = ["client_system"]}
khronos-egl = {version = "6.0", optional = true}
xkb = {version = "0.3", optional = true}

Expand Down
4 changes: 2 additions & 2 deletions gdk4-wayland/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ 428c880ecf0b)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
4 changes: 2 additions & 2 deletions gdk4-wayland/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ 428c880ecf0b)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
4 changes: 2 additions & 2 deletions gdk4-win32/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ 428c880ecf0b)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
4 changes: 2 additions & 2 deletions gdk4-win32/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ 428c880ecf0b)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
4 changes: 2 additions & 2 deletions gdk4-x11/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ 428c880ecf0b)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
4 changes: 2 additions & 2 deletions gdk4-x11/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ 428c880ecf0b)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
4 changes: 2 additions & 2 deletions gdk4/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ 428c880ecf0b)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
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
4 changes: 2 additions & 2 deletions gdk4/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ 428c880ecf0b)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
2 changes: 1 addition & 1 deletion gir
Submodule gir updated 2 files
+10 −10 Cargo.lock
+1 −1 Cargo.toml
2 changes: 1 addition & 1 deletion gir-files
Submodule gir-files updated 2 files
+4 −1 Gsk-4.0.gir
+12 −7 Gtk-4.0.gir
4 changes: 2 additions & 2 deletions gsk4/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ 428c880ecf0b)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
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
4 changes: 2 additions & 2 deletions gsk4/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ 428c880ecf0b)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
4 changes: 2 additions & 2 deletions gtk4/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ 428c880ecf0b)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
3 changes: 3 additions & 0 deletions gtk4/src/auto/window.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
#![allow(deprecated)]

use crate::{
Accessible, AccessibleRole, Align, Application, Buildable, ConstraintTarget, LayoutManager,
Expand Down Expand Up @@ -717,6 +718,8 @@ pub trait GtkWindowExt: IsA<Window> + sealed::Sealed + 'static {
}
}

#[cfg_attr(feature = "v4_14", deprecated = "Since 4.14")]
#[allow(deprecated)]
#[doc(alias = "gtk_window_present_with_time")]
fn present_with_time(&self, timestamp: u32) {
unsafe {
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
Loading
Loading