GTK4: Continue updating, tweak makefile

This commit is contained in:
NunoSempere 2024-07-21 11:09:33 -04:00
parent 6fd0a9e40f
commit 258aa8dd3c
11 changed files with 101 additions and 104 deletions

View File

@ -10,12 +10,12 @@ Rosenrot is a small browser forked from an earlier version of [rose](https://git
### Installation and usage
You can see detailed instructions [here](./user-scripts/debian-12/install-with-dependencies.sh), for Debian 12 in particular—though they should generalize easily to other distributions.
You can see detailed instructions [here](./user-scripts/debian-12/), for Debian 12 in particular—though they should generalize easily to other distributions.
The general steps are to install dependencies, and then
```
make build
make build # by default using webkitgtk6/gtk4; see also build3
make install # or sudo make install
rose
```
@ -44,6 +44,7 @@ You can also create a rose.desktop file so that it will show up in your desktop
- Custom style: Override the css of predetermined websites
- Max number of tabs (by default 8), configurable.
- Stand in plugin: Mimick function definitions which do nothing for the above plugins so that they can be quickly removed
- For now, both GTK3 and GTK4-based versions—eventually only the GTK4 version will remain
You can see some screenshots in the [images](./images) folder.
@ -66,14 +67,14 @@ Here are projects with their own rendering engines which could appeal to users o
- [lynx](https://lynx.invisible-island.net/) (links, elinks), [w3m](https://w3m.sourceforge.net/): command line browsers.
- [dillo](https://github.com/dillo-browser/dillo/). Has its own rendering engine, and no javascript.
- [Ladybird](https://github.com/SerenityOS/serenity/tree/master/Ladybird). SerenityOS. Uses its own html and javascript engine. Compiling it on a mainstream Linux distribution, and documenting instructions could be an interesting project, but the few times I've tried that I've failed.
- [Ladybird](https://github.com/LadybirdBrowser/ladybird). Initially from the InitialSerenityOS, it later became its own project. Uses its own html and javascript engine. Compiling it on a mainstream linux distribution is now doable.
- [servo](https://github.com/servo/servo). Firefox/Mozilla. An in-development browser engine written in Rust, meant to replace Gecko. Could be extremely cool once it is ready, but it has been many years in development.
### Relationship with [rose](https://github.com/mini-rose/rose)
- Rose is a small browser based on webkit2gtk. Previously, it described itself as aiming to be a "basement for creating your own browser using [the] gtk and webkit libraries". It has since diverged into a more featureful small browser with lua bindings, and rebased its history. You can see the original, minimal version [here](https://github.com/NunoSempere/rosenrot-browser/blob/a45d1c70f58586fed97df70650e5d066b73d0a0d/rose.c).
- The current version offers compilation with both GTK3 and GTK4, and an up to date version of webkit.
- Rosenrot is my (@NunoSempere's) fork from that earlier minimal rose. It has accumulated quality of life features and, honestly, cruft, that I like, like a "readability" plugin that simplifies annoying websites like [Matt Levine's Money Stuff newsletter](https://www.bloomberg.com/opinion/articles/2022-10-18/matt-levine-s-money-stuff-credit-suisse-was-a-reverse-meme-stock). It also incorporates ad-blocking.
- Rosenrot is my (@NunoSempere's) fork from that earlier minimal rose, the GTK 3 version. It has accumulated quality of life features and, honestly, cruft, that I like, like a "readability" plugin that simplifies annoying websites like [Matt Levine's Money Stuff newsletter](https://www.bloomberg.com/opinion/articles/2022-10-18/matt-levine-s-money-stuff-credit-suisse-was-a-reverse-meme-stock). It also incorporates ad-blocking.
- rose updated to allow compilation with an up-to-date version of both GTK3 and GTK4 earlier, though rosenrot now offers this as well.
- Rosenrot is also a song by the German hardcore rock band [Rammstein](https://www.youtube.com/watch?v=af59U2BRRAU).
### Comparison with [surf](https://git.suckless.org/surf/file/surf.c.html)
@ -85,9 +86,8 @@ Here are projects with their own rendering engines which could appeal to users o
- Anecdotically, surf feels slower, though I haven't tested this rigorously.
- surf has a larger community, with patches and modifications.
- surf is more opinionated, but also less amateurish.
- Like rosenrot until very recently, it [uses](https://git.suckless.org/surf/file/config.mk.html#l15) an obsolete & deprecated version of [webkit](https://blogs.gnome.org/mcatanzaro/2023/03/21/webkitgtk-api-for-gtk-4-is-now-stable/)
- My recommendation would be to use rosenrot, and if you find some feature missing, either look how surf does it and import it to rose, or move to surf.
- But then again, I've built rosenrot to cater to my own tastes, so I'd say that.
- Like rosenrot until not so long ago, it [uses](https://git.suckless.org/surf/file/config.mk.html#l15) an obsolete & deprecated version of [webkit](https://blogs.gnome.org/mcatanzaro/2023/03/21/webkitgtk-api-for-gtk-4-is-now-stable/) (2.40, with GTK3)
- My recommendation would be to use rosenrot, and if you find some feature missing, either look how surf does it and import it to rose, or move to surf. But then again, I've built rosenrot to cater to my own tastes, so I'd say that.
## Folk wisdom
@ -109,7 +109,7 @@ See [this blog post](https://blogs.gnome.org/mcatanzaro/2023/03/21/webkitgtk-api
Migration instructions for migration to webkit2gtk-6 and GTK4 can be seen [here](https://github.com/WebKit/WebKit/blob/ed1422596dce5ff012e64a38faf402ac1674fc7e/Source/WebKit/gtk/migrating-to-webkitgtk-6.0.md) and [here](https://docs.gtk.org/gtk4/migrating-3to4.html).
Rosenrot is currently on the stable webkit2gtk-4.1 release using GTK3, and has removed deprecated webkit apis. It has plans to eventually migrate to webkit2gtk-6.0 eventually but not soon, because the GTK4 rewrite seems onerous.
Rosenrot currently supports both the stable webkit2gtk-4.1/GTK3 release, and a newer release using webkit2gtk-6.0/GTK4. Eventually the later will become the only version. Readers might want to look through the history to see a bit about the updating process.
### Ubuntu 20.04

25
TODO.md
View File

@ -8,14 +8,8 @@
- [ ] This time, use something other than Whatsapp as an example syslink.
- [ ] Fix bug about distorted audio. Maybe related to [this pipewire issue](<https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1547>)?
- See whether it even exists at all
- [ ] Upgrade to GTK-4 / Webkitgtk 6.0? Will take a fair amount of time, since GTK4 redesigns the application model somewhat.
- Instructions for webkit-6.0 [here](https://github.com/WebKit/WebKit/blob/ed1422596dce5ff012e64a38faf402ac1674fc7e/Source/WebKit/gtk/migrating-to-webkitgtk-6.0.md)
- Instructions for GTK-4 [here](https://docs.gtk.org/gtk4/migrating-3to4.html)
- [ ] Prepare for GTK-3 to GTK-4 transition
- [ ] Understand wtf is going on with signals and events: <https://docs.gtk.org/gtk4/migrating-3to4.html#stop-using-gtkwidget-event-signals>. <https://github.com/mini-rose/rose-browser/blob/288bf060d095c4895946669ae50d14193168b69c/src/window.c#L42>
- [ ] Stop using direct access to GdkEvent structs
- [ ] Remove webkit2gtk-4.1 and download webkit2gtk-6.0
- [ ] Attempt to compile
- [ ] Finish cleaning up GTK4 version
- [ ] Think about best way of having GTK4 version alongside
# Previously done
@ -59,4 +53,17 @@
- Useful for opening links in new tab when clicking on them and selecting that option
- And for actually opening links with the href new_tab option.
- Links: [1](<https://docs.gtk.org/gobject/func.signal_connect.html>), [2](<https://webkitgtk.org/reference/webkit2gtk/2.37.90/signal.AutomationSession.create-web-view.html>), [3](<https://webkitgtk.org/reference/webkit2gtk/2.26.0/WebKitWebView.html#WebKitWebView-create>), [4](<https://stackoverflow.com/questions/40180757/webkit2gtk-get-new-window-link>)
- [x] Upgrade to GTK-4 / Webkitgtk 6.0? Will take a fair amount of time, since GTK4 redesigns the application model somewhat.
- Instructions for webkit-6.0 [here](https://github.com/WebKit/WebKit/blob/ed1422596dce5ff012e64a38faf402ac1674fc7e/Source/WebKit/gtk/migrating-to-webkitgtk-6.0.md)
- Instructions for GTK-4 [here](https://docs.gtk.org/gtk4/migrating-3to4.html)
- [x] Prepare for GTK-3 to GTK-4 transition
- [x] Understand wtf is going on with signals and events: <https://docs.gtk.org/gtk4/migrating-3to4.html#stop-using-gtkwidget-event-signals>. <https://github.com/mini-rose/rose-browser/blob/288bf060d095c4895946669ae50d14193168b69c/src/window.c#L42>
- [x] Stop using direct access to GdkEvent structs
- [ ] ~~Remove webkit2gtk-4.1 and download webkit2gtk-6.0~~ => Actually just use both
- [x] Attempt to compile
- Notes for others:
- Searching github
- Creating a minimal version, e.g., having only one signal going on
- Looking at how https://github.com/mini-rose/rose-browser/ does things
- Printf statements
- GTK ressources: https://docs.gtk.org/gtk4, https://docs.gtk.org/gobject/, https://docs.gtk.org/gdk4/

View File

@ -3,7 +3,7 @@ CC=gcc # alternatives: tcc, clang, zig cc
WARNINGS=-Wall
OPTIMIZED_SOME=-O3
OPTIMIZED_MORE=-Ofast -march=native -funit-at-a-time -flto # binary will not be compatible with other computers, but may be much faster
DEBUG=
DEBUG=#-g
STD=-std=c99 # maybe consider moving to c11 and using safer string handling
# Dependencies for WebkitGTK4/GTK3
@ -17,7 +17,7 @@ SRC_4=rosenrot4.c
DEPS_4='webkitgtk-6.0'
INCS_4=`pkg-config --cflags ${DEPS_4}` `pkg-config --cflags gtk4`
LIBS_4=`pkg-config --libs ${DEPS_4}` `pkg-config --libs gtk4`
# DEPRECATION_FLAGS=-DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED
DEPRECATION_FLAGS=-DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED
# User config
CONFIG=config.h
@ -37,20 +37,36 @@ MAINTAINER_CACHE_DIR=/home/nuno/.cache/rosenrot
USER_CACHE_DIR=/home/`whoami`/.cache/rosenrot
RUNTIME_FILES_DIR=/opt/rosenrot/
# Start 3 to 4 transition
# https://docs.gtk.org/gtk4/migrating-3to4.html
# https://github.com/WebKit/WebKit/blob/ed1422596dce5ff012e64a38faf402ac1674fc7e/Source/WebKit/gtk/migrating-to-webkitgtk-6.0.md
build: $(SRC_3) $(PLUGINS) $(CONFIG) constants user_cache
build3: $(SRC_3) $(PLUGINS) $(CONFIG) constants user_cache
$(CC) $(STD) $(WARNINGS) $(OPTIMIZED_MORE) $(DEBUG) $(INCS_3) $(PLUGINS) $(SRC_3) -o rosenrot $(LIBS_3) $(ADBLOCK)
@echo
build4: $(SRC_4) $(PLUGINS) $(CONFIG) constants user_cache
build: $(SRC_4) $(PLUGINS) $(CONFIG) constants user_cache
$(CC) $(STD) $(WARNINGS) $(DEPRECATION_FLAGS) $(OPTIMIZED_MORE) $(DEBUG) $(INCS_4) $(PLUGINS) $(SRC_4) -o rosenrot $(LIBS_4) $(ADBLOCK)
@echo
diagnose:
G_ENABLE_DIAGNOSTIC=1 ./rosenrot
format: $(SRC_3) $(SRC_4) $(PLUGINS)
$(FORMATTER_C) $(SRC_3) $(PLUGINS) $(config.h)
$(FORMATTER_C) $(SRC_4_greenfield) $(PLUGINS) $(config.h)
$(FORMATTER_JS) plugins/readability/readability.js
$(FORMATTER_JS) plugins/style/style.js
# Installation
install: rosenrot runtime_files
cp -f rosenrot /usr/bin
cp rosenrot-mklink /usr/bin
@echo
uninstall:
rm -r /opt/rosenrot
rm /usr/bin/rosenrot
rm /usr/bin/rosenrot-mklink
rm $(USER_CACHE_DIR)
clean:
rm rosenrot
rm $(USER_CACHE_DIR)
constants:
@echo
@ -70,45 +86,25 @@ user_cache:
runtime_files:
@echo
sudo mkdir -p /opt/rosenrot/
sudo cp style-gtk3.css /opt/rosenrot/style.css
sudo cp styles-gtk/style-gtk3.css /opt/rosenrot/
sudo cp styles-gtk/style-gtk4.css /opt/rosenrot/
sudo cp -r images/flower-imgs /opt/rosenrot/
sudo cp plugins/style/style.js /opt/rosenrot/
sudo cp plugins/readability/readability.js /opt/rosenrot/
install: rosenrot runtime_files
cp -f rosenrot /usr/bin
cp rosenrot-mklink /usr/bin
@echo
uninstall:
rm -r /opt/rosenrot
rm /usr/bin/rosenrot
rm /usr/bin/rosenrot-mklink
rm $(USER_CACHE_DIR)
clean:
rm rosenrot
rm $(USER_CACHE_DIR)
format: $(SRC) $(PLUGINS)
$(FORMATTER_C) $(SRC) $(PLUGINS) $(rosenrot.h)
$(FORMATTER_C) $(SRC_4) $(PLUGINS) $(rosenrot.h)
$(FORMATTER_C) $(SRC_4_greenfield) $(PLUGINS) $(rosenrot.h)
$(FORMATTER_JS) plugins/readability/readability.js
$(FORMATTER_JS) plugins/style/style.js
# More misc recipes
lint:
clang-tidy $(SRC) $(PLUGINS) -- -Wall -O3 $(INCS) -o rosenrot $(LIBS)
## A few more commands:
fast: $(SRC) $(PLUGINS) $(CONFIG)
rm -f *.gcda
GIO_MODULE_DIR=/usr/lib/x86_64-linux-gnu/gio/modules/
$(CC) $(WARNINGS) $(OPTIMIZED_MORE) -fprofile-generate $(INCS) $(PLUGINS) $(SRC) -o rosenrot $(LIBS) $(ADBLOCK)
$(CC) $(WARNINGS) $(OPTIMIZED_MORE) -fprofile-generate $(INCS_4) $(PLUGINS) $(SRC_4) -o rosenrot $(LIBS_4) $(ADBLOCK)
@echo "Now use the browser for a while to gather some profiling data"
sleep 2
./rosenrot
$(CC) $(WARNINGS) $(OPTIMIZED_MORE) -fprofile-use $(INCS) $(PLUGINS) $(SRC) -o rosenrot $(LIBS) $(ADBLOCK)
$(CC) $(WARNINGS) $(OPTIMIZED_MORE) -fprofile-use $(INCS_4) $(PLUGINS) $(SRC_4) -o rosenrot $(LIBS_4) $(ADBLOCK)
rm -f *.gcda
inspect: rosenrot
@ -123,5 +119,3 @@ view-gtk3-version:
twitter:
sudo mkdir -p /usr/bin/rosenrot-browser
sudo cp rosenrot /usr/bin/rosenrot-browser/twitter
# COMPILETIME_DEPRECATION_WARNINGS=#-DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED # turns out that webkit2gtk-4.1 is using some deprecated stuff, lol

View File

@ -390,7 +390,7 @@ int main(int argc, char** argv)
gtk_init(NULL, NULL); // https://docs.gtk.org/gtk3/func.init.html
g_object_set(gtk_settings_get_default(), GTK_SETTINGS_CONFIG_H, NULL); // https://docs.gtk.org/gobject/method.Object.set.html
GtkCssProvider* css = gtk_css_provider_new();
gtk_css_provider_load_from_path(css, "/opt/rosenrot/style.css", NULL);
gtk_css_provider_load_from_path(css, "/opt/rosenrot/style-gtk3.css", NULL);
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(css), 800); /* might change with GTK4/webkitgtk6.0 */
/* Initialize GTK objects. These are declared as static globals at the top of this file */

View File

@ -399,7 +399,7 @@ int main(int argc, char** argv)
gtk_init();
g_object_set(gtk_settings_get_default(), GTK_SETTINGS_CONFIG_H, NULL); // https://docs.gtk.org/gobject/method.Object.set.html
GtkCssProvider* css = gtk_css_provider_new();
gtk_css_provider_load_from_path(css, "/opt/rosenrot/style.css");
gtk_css_provider_load_from_path(css, "/opt/rosenrot/style-gtk4.css");
gtk_style_context_add_provider_for_display(gdk_display_get_default(), GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_USER);
// Create the main window

View File

@ -1,2 +0,0 @@
build:
gcc -std=c99 -Wall `pkg-config --cflags gtk4` test.c -o rosenrot `pkg-config --libs gtk4`

View File

@ -1,42 +0,0 @@
#include <gtk/gtk.h>
#define WIDTH 1920 // 960 for half-width, 1920 for full width
// #define HEIGHT 1080
#define HEIGHT 1080
static GtkNotebook* notebook;
int
main (int argc, char **argv)
{
GtkWidget *window;
// Initialize i18n support with bindtextdomain(), etc.
// ...
// Initialize the widget set
gtk_init ();
// Create the main window
window = gtk_window_new ();
gtk_window_set_default_size(GTK_WINDOW(window), WIDTH, HEIGHT);
// Set up our GUI elements
notebook = GTK_NOTEBOOK(gtk_notebook_new());
gtk_notebook_set_show_tabs(notebook, false);
gtk_notebook_set_show_border(notebook, false);
// ...
// Show the application window
gtk_window_present (GTK_WINDOW (window));
gtk_window_set_child(GTK_WINDOW(window), GTK_WIDGET(notebook));
// Enter the main event loop, and wait for user interaction
while (!0)
g_main_context_iteration (NULL, TRUE);
// The user lost interest
return 0;
}

View File

@ -1,8 +1,6 @@
# Key dependencies
sudo apt install git vim gcc make
sudo apt install libwebkit2gtk-4.1-dev
# sudo apt install libwebkitgtk-6.0-dev
# sudo apt install libgtk-4-dev
# Optional adblock
git clone https://github.com/jun7/wyebadblock
@ -18,7 +16,7 @@ wget https://easylist.to/easylist/easylist.txt
cd -
cd ../..
make build # or just make
make build3 # or just make
sudo make install
cd -

View File

@ -0,0 +1,42 @@
# Key dependencies
sudo apt install libwebkitgtk-6.0-dev
sudo apt install libgtk-4-dev
# Optional adblock
git clone https://github.com/jun7/wyebadblock
cd wyebadblock
sudo apt install gstreamer1.0-plugins-good gstreamer1.0-libav
WEBKITVER=4.1 make
sudo WEBKITVER=4.1 make install
cd ..
mkdir -p ~/.config/wyebadblock
cd ~/.config/wyebadblock
wget https://easylist.to/easylist/easylist.txt
cd -
cd ../..
make build4
sudo make install
cd -
# Debian desktop icon
chmod +x rosenrot.desktop
sudo cp rosenrot.desktop /usr/share/applications
mkdir -p /opt/rosenrot
sudo cp rosenrot-desktop-icon.png /opt/rosenrot/
# Optionally, set a shortcut (within GNOME)
# https://askubuntu.com/questions/597395/how-to-set-custom-keyboard-shortcuts-from-terminal/1007035#1007035
name="rose"
binding="<CTRL><SHIFT>W"
action="/usr/bin/rosenrot"
media_keys=org.gnome.settings-daemon.plugins.media-keys
custom_kbd=org.gnome.settings-daemon.plugins.media-keys.custom-keybinding
kbd_path=/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/$name/
new_bindings=`gsettings get $media_keys custom-keybindings | sed -e"s>'\]>','$kbd_path']>"| sed -e"s>@as \[\]>['$kbd_path']>"`
gsettings set $media_keys custom-keybindings "$new_bindings"
gsettings set $custom_kbd:$kbd_path name "$name"
gsettings set $custom_kbd:$kbd_path binding "$binding"
gsettings set $custom_kbd:$kbd_path command "$action"