MoAlyousef / cfltk

C Bindings for FLTK
MIT License
79 stars 21 forks source link

not possible to interact with platform-specified API #220

Closed mokurin000 closed 1 year ago

mokurin000 commented 1 year ago

I am writing an OSD lyrics app for wayland with fltk-rs, which uses fltk-sys generated from cfltk As cfltk does not expose fl_wl_surface, it's really a headache to correctly link same fltk lib

MoAlyousef commented 1 year ago

When you call window.raw_handle() on a window on wayland, it returns the wl_surface pointer. Similarly you can use the raw-window-handle crate with fltk-rs which can give you the wl_surface. Is that not enough? It's also not clear to me how this affects linking.

mokurin000 commented 1 year ago

oh.. really sorry for that I thought I need to link to fl_wl_surface and have no another way to get wl_surface pointer Also, much thanks to your help

mokurin000 commented 1 year ago

btw, I guess I should tell fltk-rs to mention wl_surface to their RawHandle comment, thus I could search wl_surface and locate RawHandle. https://github.com/fltk-rs/fltk-rs/pull/1392

mokurin000 commented 1 year ago

No... according to FLTK 1.4 os issue, you cannot get a wl_surface * with fl_xid(wind) you should use fl_wl_surface(fl_wl_xid(wind))

MoAlyousef commented 1 year ago

This should be fixed here: https://github.com/MoAlyousef/cfltk/blob/b04709c276dd6d83f618bf0e43b3fa08894fb838/src/cfl_window.cpp#L267

Can you try with:

[depenendencies]
fltk = { git = "https://github.com/fltk-rs/fltk-rs", features = ["use-wayland"] } 
MoAlyousef commented 1 year ago

I've pushed a second fix, can you try it by adding fltk-rs as a git dependency and running cargo update?

mokurin000 commented 1 year ago

I've pushed a second fix, can you try it by adding fltk-rs as a git dependency and running cargo update?

oh. sorry I am doing army training (as a Chinese student), I forgot to push my code. may you could test with evcxr_repl and use wayland_backend with feature client_system and obtain on ObjectId with from_ptr

Update: asked my friend if he could help me with code below:

cargo new test_wl_handler &&
cd test_wl_handler &&
cargo add wayland-client &&
cargo add wayland-backend -F client_system &&
cargo add --git https://github.com/fltk-rs/fltk-rs -F use-wayland -p fltk &&
cat > src/main.rs <<EOF &&
fn main() {
    let wind = window::Window::new(100, 100, 400, 300, "My Window");
    wind.end();
    wind.show();
let ptr = wind.raw_handle() as _;
unsafe { wayland_client::backend::ObjectId::from_ptr(wayland_client::protocol::wl_surface::WlSurface::interface(), ptr).unwrap()} ;
}
EOF
cargo run
MoAlyousef commented 1 year ago

I tried the lastest build with the following code:

use fltk::{prelude::*, *};
use wayland_client::Proxy;

fn main() {
    let a = app::App::default();
    let mut wind = window::Window::new(100, 100, 400, 300, "My Window");
    wind.end();
    wind.show();
    let ptr = wind.raw_handle() as _;
    let val = unsafe { wayland_client::backend::ObjectId::from_ptr(wayland_client::protocol::wl_surface::WlSurface::interface(), ptr).unwrap()} ;
    dbg!(val);
    a.run().unwrap();
}

And it prints:

[fltk/examples/temp.rs:11] val = ObjectId(wl_surface@11)
mokurin000 commented 1 year ago

seems working properly