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
|
#include "glib.h"
#include "saffron_widget.h"
#include <SDL3/SDL_hints.h>
#include <saffron.h>
#include <saffronwebkit.h>
// store globals because yes
SFWKContext* ctx;
SFWKWebView* webview;
bool hook_callback(SDL_Event* event) {
return sfwk_process_event(ctx, webview, event);
}
void btn_callback(SaffronButton* btn) {
// do nothing
}
int main() {
SDL_SetHint(SDL_HINT_GPU_DRIVER, "opengles2");
SDL_SetHint(SDL_HINT_VIDEO_FORCE_EGL, "true");
saffron_init();
const char* driver = SDL_GetCurrentVideoDriver();
printf("SDL is using driver: %s\n", driver); // please say x11
// make a button to prove the layout engine can move the webview around
SaffronButton* button = saffron_button_new(true, btn_callback, 200, 150);
SaffronWindow* window = saffron_window_new("SaffronWebKit (SFWK) Test", 1024, 768);
window->root->theme = SF_MACRO_DEFAULT_THEME;
ctx = sfwk_init();
if (!ctx) return 1;
webview = sfwk_webview_new(ctx, "https://arslaancodes.com", 900, 600);
saffron_widget_add_child(window->root, (SaffronWidget*)button);
saffron_widget_add_child(window->root, (SaffronWidget*)webview);
webview->window = window; // so the webview can access the GL context
((SaffronWidget*)webview)->width_mode = SAFFRON_SIZE_STRETCH;
((SaffronWidget*)webview)->height_mode = SAFFRON_SIZE_STRETCH;
saffron_hook_sdl_all_events(window, hook_callback, 999);
saffron_window_main(window);
saffron_window_free(window);
saffron_quit();
return 0;
}
|