embedding a webview in an fltk app (some issues)

66 views
Skip to first unread message

Mo_Al_

unread,
May 13, 2021, 3:23:28 AM5/13/21
to fltk.general
Hello

I've been experimenting with embedding a webview (https://github.com/webview/webview) in an fltk application.
This works by just passing an fl_xid of an Fl_Window to the webview_create function which accepts an opaque pointer to either a HWND, NSWindow or GtkWindow depending on the platform.

- On Windows, things work fine.

- On MacOS, any manipulation of the embedded window throws an objc exception (doesn't crash) of unrecognized selector "did_view_resolution_change" to WKWebView.
"did_view_resolution_change" is a method of FLView which inherits NSView (in fl_cocoa.mm). I'm not entirely sure why it's being automatically triggered here or if there's a way to override it or "swizzle" it (I'm not familiar with Objective-C).

- On linux, I'm getting the idea that trying to construct GtkWindow from an Fl_Window is quite complex. Apparently it's possible to construct a GdkWindow from an XID, however getting a GtkWindow from a GdkWindow is not possible. I'm not sure of any other way to do it. I would appreciate any insight on the feasibility of doing this.

Thank you

Albrecht Schlosser

unread,
May 13, 2021, 3:49:46 AM5/13/21
to fltkg...@googlegroups.com
On 5/13/21 5:51 AM schrieb Mo_Al_ wrote:

> I've been experimenting with embedding a webview
> (https://github.com/webview/webview) in an fltk application.
> This works by just passing an fl_xid of an Fl_Window to the
> webview_create function which accepts an opaque pointer to either a
> HWND, NSWindow or GtkWindow depending on the platform.
>
> - On Windows, things work fine.
>
> - On MacOS, any manipulation of the embedded window throws an objc
> exception (doesn't crash) of unrecognized selector
> "did_view_resolution_change" to WKWebView.
> "did_view_resolution_change" is a method of FLView which inherits NSView
> (in fl_cocoa.mm). I'm not entirely sure why it's being automatically
> triggered here or if there's a way to override it or "swizzle" it (I'm
> not familiar with Objective-C).

I can't say anything to that part since I don't know the internals.

> - On linux, I'm getting the idea that trying to construct GtkWindow from
> an Fl_Window is quite complex. Apparently it's possible to construct a
> GdkWindow from an XID, however getting a GtkWindow from a GdkWindow is
> not possible. I'm not sure of any other way to do it. I would appreciate
> any insight on the feasibility of doing this.

The only information I can offer is that the XID of the FLTK window is
nothing but the X11 Window (id), i.e. the type 'Window', but you seem to
know that already.

Maybe someone here has experience with your specific question, but
generally I'd say this is the wrong group to ask, you should better ask
in a Gtk related user group/forum.

Mo_Al_

unread,
May 23, 2021, 9:26:45 PM5/23/21
to fltk.general
Thank you. I finally got around this using reparenting on both MacOS (removeFromSuperview, addSubview) and Gtk (XReparentWindow). Gtk required running gtk_main_iteration inside Fl::set_idle. Macos no longer throws on did_view_resolution_change, but I still have to manage passing mouse input to the subview.

Mo_Al_

unread,
May 25, 2021, 1:42:47 AM5/25/21
to fltk.general
A proof of concept repo:
Suggestions are welcome

On windows the dll's from here are required:

On linux, libwebkit2gkt-4.0-dev(el) is required.

Reply all
Reply to author
Forward
0 new messages