Browse Source

Add makefile/example cde for webkit and gtk

master
blackle 3 years ago
commit
af16eb5f0b
2 changed files with 80 additions and 0 deletions
  1. +27
    -0
      Makefile
  2. +53
    -0
      gtk-webkit.c

+ 27
- 0
Makefile View File

@ -0,0 +1,27 @@
all : gtk-webkit_opt.elf.xz
gtk-webkit.elf : gtk-webkit.c Makefile
gcc -o $@ $< `pkg-config --cflags webkit2gtk-4.0` -lgobject-2.0 -lgtk-3 -lwebkit2gtk-4.0 -no-pie -fno-plt -Os -std=gnu11 -nostartfiles -nostdlib
%_opt.elf : %.elf Makefile
cp $< $@
strip $@
strip -R .note -R .comment -R .eh_frame -R .eh_frame_hdr -R .note.gnu.build-id -R .got -R .got.plt -R .gnu.version -R .rela.dyn -R .shstrtab $@
#remove section header
/home/blackle/Code/Projects/section-stripper/section-stripper.py $@
#clear out useless bits
sed -i 's/_edata/\x00\x00\x00\x00\x00\x00/g' $@;
sed -i 's/__bss_start/\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/g' $@;
sed -i 's/_end/\x00\x00\x00\x00/g' $@;
wc -c $@
chmod +x $@
%.xz : % Makefile
-rm $@
lzma --format=lzma -9 --extreme --lzma1=preset=9,lc=1,lp=0,pb=1,nice=270,depth=64,dict=16384 --keep --stdout $< > $@
wc -c $@
clean :

+ 53
- 0
gtk-webkit.c View File

@ -0,0 +1,53 @@
#define GL_GLEXT_PROTOTYPES why
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>
#include<stdint.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <webkit2/webkit2.h>
#define CANVAS_WIDTH 1920
#define CANVAS_HEIGHT 1080
gboolean on_load_changed(WebKitWebView *web_view, WebKitLoadEvent load_event, GtkWindow* window)
{
if (load_event == WEBKIT_LOAD_FINISHED) {
gtk_widget_show_all(GTK_WIDGET(window));
gtk_window_fullscreen(window);
}
return TRUE;
}
static char* html = "<style>html{cursor:none;overflow:hidden}body{transform:translateY(460px) rotate(20deg);font-family:FreeSans;font-size:150}</style>this is an html page! 😊<br><i style=\"font-size:50px;margin-left:100\">with webgl!</i>";
void _start() {
asm volatile("sub $8, %rsp\n");
typedef void (*voidWithOneParam)(int*);
voidWithOneParam gtk_init_one_param = (voidWithOneParam)gtk_init;
(*gtk_init_one_param)(NULL);
GtkWidget *win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
WebKitSettings *webSettings = webkit_settings_new_with_settings("enable-webgl", TRUE, NULL);
WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new_with_settings(webSettings));
webkit_web_view_load_html(webView, html, NULL);
gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(webView));
g_signal_connect(win, "destroy", gtk_main_quit, NULL);
g_signal_connect(webView, "load-changed", G_CALLBACK(on_load_changed), (GtkWindow*)(win));
gtk_main();
asm volatile(".intel_syntax noprefix");
asm volatile("push 231"); //exit_group
asm volatile("pop rax");
// asm volatile("xor edi, edi");
asm volatile("syscall");
asm volatile(".att_syntax prefix");
__builtin_unreachable();
}

Loading…
Cancel
Save