aboutsummaryrefslogtreecommitdiff
path: root/include/saffronwebkit.h
blob: a90a7c30c5fbe75eabe56dc6ef3fd9ad0dee37fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (C) 2026 Arslaan Pathan
// This code contains excerpts from wpe-sdl-simple, which is released under MIT.
// The original source code is available here: https://github.com/aperezdc/wpe-sdl-simple
// See external_licenses/COPYING_wpe-sdl-simple.txt
#ifndef SAFFRONWEBKIT_H
#define SAFFRONWEBKIT_H

#include "wpe/wpe-platform.h"
#include <saffron.h>
#include <wpe/webkit.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_egl.h>
#include <SDL3/SDL_opengles2.h>

// The web content area - view that renders to SDL
struct _WPEViewSDL3 {
	WPEView parent;
	void* userdata;
};

// Window/toplevel container that owns all the web views - tab/window manager 
struct _WPEToplevelSDL3 {
	WPEToplevel parent;
	WPEView *view;
	SDL_Texture *texture;
};

// Manages EGL/SDL display - global WPE context
struct _WPEDisplaySDL3 {
	WPEDisplay parent;

	SDL_InitFlags init_flags;

	SDL_Window *hidden_window;
	SDL_GLContext gl_context;

	EGLDisplay egl_display;

	PFNEGLDESTROYIMAGEKHRPROC destroyImage;
	PFNGLEGLIMAGETARGETTEXTURE2DOESPROC imageTargetTexture2DOES;
};

typedef struct {
	GMainContext* main_context;
	WPEDisplay* display;
} SFWKContext;

typedef struct {
	SaffronWidget base;
	SFWKContext* context;
	SaffronWindow* window; // just for the GL context
	char* url;
	int w, h;

	struct {
		WPEToplevel* toplevel;
		WPEView* wpeview;
		WebKitWebView* wkwebview;
		gboolean initialized;

		EGLDisplay egl_display;
		EGLContext egl_context;
		EGLSurface egl_dummy_surface;
	} wpe;

	SDL_Renderer* renderer;
} SFWKWebView;

SFWKContext* sfwk_init(); // can return NULL! be careful!

bool sfwk_process_event(SFWKContext* context, SFWKWebView* webview, SDL_Event* event); // the user needs to attach this to a saffron_hook_sdl_all_events
SFWKWebView* sfwk_webview_new(SFWKContext* context, const char* url, int w, int h);
WebKitWebView* sfwk_webview_get_wkwebview(SFWKWebView* webview);

#endif