performance improvements, add zoom functionality

This commit is contained in:
fenze 2022-05-12 22:33:09 +02:00
parent e397b14dbe
commit b132abcd23
5 changed files with 56 additions and 17 deletions

View File

@ -12,6 +12,8 @@ static Key keys[] = {
{ MODKEY, GDK_KEY_l, goforward },
{ MODKEY, GDK_KEY_y, copy_url },
{ MODKEY, GDK_KEY_p, paste_url },
{ MODKEY, GDK_KEY_e, search },
{ MODKEY, GDK_KEY_equal, zoomin },
{ MODKEY, GDK_KEY_minus, zoomout },
{ 0, GDK_KEY_F11, fullscreen },
{ MODKEY, GDK_KEY_e, search }
};

View File

@ -18,5 +18,7 @@ enum {
paste_url,
fullscreen,
inspector,
search
search,
zoomin,
zoomout
};

View File

@ -1,9 +1,24 @@
CC = clang
CFLAGS = `pkg-config --cflags gtk4 webkit2gtk-5.0 x11 `
LIBS = `pkg-config --libs gtk4 webkit2gtk-5.0 x11`
GTKFLAGS = -Dgtk_doc=false -Dintrospection=false \
-DG_DISABLE_CAST_CHECKS \
-Dcloudproviders=false \
-DGTK_DISABLE_DEPRECATED \
-GDK_PIXBUF_DISABLE_DEPRECATED \
-G_DISABLE_DEPRECATED -DENABLE_GLES2=ON \
-DENABLE_GEOLOCATION=OFF -DENABLE_PLUGIN_PROCESS_GTK2=OFF \
-DPORT=GTK \
-Dforce_posix_threads=true \
-Dman=false \
-Dxinerama=false \
-Dcolord=false \
-Db_coverage=false \
-Ddebug=false
all:
${CC} -fPIC -O3 -o rose *.c $(CFLAGS) $(LIBS)
${CC} -fPIC -Os -o rose *.c $(CFLAGS) $(LIBS) $(GTKFLAGS)
strip ./rose
install: all

View File

@ -113,12 +113,16 @@ GtkWidget* rose_webview_new()
WebKitUserContentManager *contentmanager;
WebKitSettings *settings = webkit_settings_new_with_settings(
"auto-load-images", true,
"enable-back-forward-navigation-gestures", true,
"enable-developer-extras", true,
"enable-media-stream", true,
"auto-load-images", TRUE,
"enable-back-forward-navigation-gestures", TRUE,
"enable-developer-extras", TRUE,
"enable-media-stream", TRUE,
"enable-plugins", FALSE,
"enable-dns-prefetching", TRUE,
"enable-smooth-scrolling", TRUE,
"media-content-types-requiring-hardware-support", "video:/mp4;codecs=\"H.264-encoded\"",
"hardware-acceleration-policy", WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS,
"javascript-can-access-clipboard", true, NULL);
"javascript-can-access-clipboard", TRUE, NULL);
WebKitWebContext *context = webkit_web_context_new_with_website_data_manager(
webkit_website_data_manager_new(
@ -129,7 +133,6 @@ GtkWidget* rose_webview_new()
webkit_settings_set_user_agent_with_application_details(
settings, "Mini", "0.1");
webkit_web_context_set_process_model(context, WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
webkit_web_context_set_cache_model(context, WEBKIT_CACHE_MODEL_WEB_BROWSER);
contentmanager = webkit_user_content_manager_new();
cookiemanager = webkit_web_context_get_cookie_manager(context);

View File

@ -20,6 +20,8 @@ enum {
PROP_ACTIVE_CHILD
};
static float zoom = 1.0;
G_DEFINE_TYPE(RoseWindow, rose_window, GTK_TYPE_APPLICATION_WINDOW)
static void read_clipboard(GObject *object,
@ -85,10 +87,20 @@ static gboolean key_press_callback(RoseWindow *window,
webkit_web_view_load_uri(window->webview, getatom(AtomGo));
}
}
case zoomin:
zoom += 0.1;
webkit_web_view_set_zoom_level(window->webview, zoom);
break;
case zoomout:
zoom -= 0.1;
webkit_web_view_set_zoom_level(window->webview, zoom);
break;
}
}
}
printf("%i\n", keyval);
puts("");
return GDK_EVENT_PROPAGATE;
}
@ -105,7 +117,12 @@ static void rose_window_init(RoseWindow *window)
guint rose_window_show(GtkApplication *app, RoseWindow *window, const char *url)
{
GtkWidget *w = gtk_application_window_new(app);
gtk_application_set_menubar(app, FALSE);
GtkWidget *webview = rose_webview_new();
gtk_widget_set_has_tooltip(webview, FALSE);
gtk_widget_has_default(webview);
gtk_window_set_destroy_with_parent(GTK_WINDOW(w), TRUE);
window->webview = WEBKIT_WEB_VIEW(webview);
if (url)