Fix webkit bg color error, add rose-nativefier

This commit is contained in:
fenze 2022-11-17 16:57:11 +00:00
parent 68ca1eb61a
commit 5e7587dd99
8 changed files with 203 additions and 179 deletions

37
.clang-format Normal file
View File

@ -0,0 +1,37 @@
# vim:ft=yaml
IndentWidth: 8
BreakBeforeBraces: Linux
UseTab: Always
AlignArrayOfStructures: Left
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: True
AlwaysBreakBeforeMultilineStrings: True
BreakBeforeTernaryOperators: True
BreakStringLiterals: True
ColumnLimit: 100
IncludeBlocks: Regroup
KeepEmptyLinesAtTheStartOfBlocks: True
RemoveBracesLLVM: True
SortIncludes: CaseInsensitive
SortUsingDeclarations: True
SpaceAfterLogicalNot: True
SpaceAfterCStyleCast: True
SpaceAfterTemplateKeyword: False
PointerAlignment: Right
SpaceBeforeAssignmentOperators: True
SpaceBeforeCaseColon: False
SpaceBeforeCpp11BracedList: True
SpaceBeforeCtorInitializerColon: False
SpaceBeforeInheritanceColon: False
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterControlStatements: True
AfterForeachMacros: True
AfterFunctionDeclarationName: False
AfterFunctionDefinitionName: False
AfterIfMacros: True
AfterOverloadedOperator: False
BeforeNonEmptyParentheses: False
SpaceBeforeRangeBasedForLoopColon: True

View File

@ -7,6 +7,7 @@
- ~400L code base - ~400L code base
- custom gtk and websites css - custom gtk and websites css
- hackable without any knowledge - hackable without any knowledge
- builtin script nativefier
# #
### 👐 Contribute ### 👐 Contribute

View File

@ -5,4 +5,7 @@ DEPS=('webkit2gtk-4.0')
INCS=`pkg-config --cflags ${DEPS[@]}` INCS=`pkg-config --cflags ${DEPS[@]}`
LIBS=`pkg-config --libs ${DEPS[@]}` LIBS=`pkg-config --libs ${DEPS[@]}`
$CC $INCS $LIBS $SRC -o rose # Optional adblocking depends on https://github.com/jun7/wyebadblock
WYEBAB='-L/usr/lib/wyebrowser/adblock.so'
$CC $INCS $LIBS $SRC $WYEBAB -o rose

27
compile_flags.txt Normal file
View File

@ -0,0 +1,27 @@
-I/usr/include/webkitgtk-4.0
-I/usr/include/glib-2.0
-I/usr/lib/glib-2.0/include
-I/usr/include/sysprof-4
-I/usr/include/gtk-3.0
-I/usr/include/pango-1.0
-I/usr/include/harfbuzz
-I/usr/include/freetype2
-I/usr/include/libpng16
-I/usr/include/libmount
-I/usr/include/blkid
-I/usr/include/fribidi
-I/usr/include/cairo
-I/usr/include/lzo
-I/usr/include/pixman-1
-I/usr/include/gdk-pixbuf-2.0
-I/usr/include/gio-unix-2.0
-I/usr/include/cloudproviders
-I/usr/include/atk-1.0
-I/usr/include/at-spi2-atk/2.0
-I/usr/include/at-spi-2.0
-I/usr/include/dbus-1.0
-I/usr/lib/dbus-1.0/include
-I/usr/include/libsoup-2.4
-I/usr/include/libxml2
-pthread

View File

@ -1,5 +1,6 @@
./build.sh && { ./build.sh && {
cp -f rose /usr/bin cp -f rose /usr/bin
mkdir -p /usr/share/themes/rose mkdir -p /usr/share/themes/rose
cp ./style.css /usr/share/themes/rose/ cp style.css /usr/share/themes/rose/
cp rose-nativefier /usr/bin
} }

BIN
rose Executable file

Binary file not shown.

9
rose-nativefier Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
test "$1" = "--help" && {
echo "usage: rose-nativefier <alias> <url>"
}
test -z "$1" || test -z "$2" || {
echo -e "#!/bin/sh\n\nrose $2" > /usr/bin/$1
}

142
rose.c
View File

@ -10,24 +10,19 @@
* Author: fenze <contact@fenze.dev> * Author: fenze <contact@fenze.dev>
*/ */
#include <webkit2/webkit2.h>
#include "config.h" #include "config.h"
#include <webkit2/webkit2.h>
#define CACHE \ #define CACHE \
"base-cache-directory", CACHE_DIR, \ "base-cache-directory", CACHE_DIR, "base-data-directory", CACHE_DIR, \
"base-data-directory", CACHE_DIR, \ "disk-cache-directory", CACHE_DIR, "dom-cache-directory", CACHE_DIR, \
"disk-cache-directory", CACHE_DIR, \ "hsts-cache-directory", CACHE_DIR, "indexeddb-directory", CACHE_DIR, "itp-directory", \
"dom-cache-directory", CACHE_DIR, \ CACHE_DIR, "local-storage-directory", CACHE_DIR, \
"hsts-cache-directory", CACHE_DIR, \
"indexeddb-directory", CACHE_DIR, \
"itp-directory", CACHE_DIR, \
"local-storage-directory", CACHE_DIR, \
"offline-application-cache-directory", CACHE_DIR, \ "offline-application-cache-directory", CACHE_DIR, \
"service-worker-registrations-directory", CACHE_DIR "service-worker-registrations-directory", CACHE_DIR
enum { enum { _SEARCH, _FIND };
_SEARCH, _FIND
};
static int entry_mode; static int entry_mode;
static GtkWindow *window; static GtkWindow *window;
@ -45,47 +40,32 @@ WebKitWebView *webview_new()
settings = webkit_settings_new_with_settings(WEBKIT, NULL); settings = webkit_settings_new_with_settings(WEBKIT, NULL);
web_context = webkit_web_context_new_with_website_data_manager( web_context = webkit_web_context_new_with_website_data_manager(
webkit_website_data_manager_new(CACHE, NULL) webkit_website_data_manager_new(CACHE, NULL));
);
contentmanager = webkit_user_content_manager_new(); contentmanager = webkit_user_content_manager_new();
cookiemanager = webkit_web_context_get_cookie_manager(web_context); cookiemanager = webkit_web_context_get_cookie_manager(web_context);
webkit_cookie_manager_set_persistent_storage( webkit_cookie_manager_set_persistent_storage(cookiemanager, CACHE_DIR "/cookies.sqlite",
cookiemanager, CACHE_DIR"/cookies.sqlite", WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE);
WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE
);
webkit_cookie_manager_set_accept_policy( webkit_cookie_manager_set_accept_policy(cookiemanager, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
cookiemanager, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS
);
webkit_web_context_set_process_model( webkit_web_context_set_process_model(web_context,
web_context, WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES
);
if (g_file_get_contents("~/.config/rose/style.css", &style, NULL, NULL)) if (g_file_get_contents("~/.config/rose/style.css", &style, NULL, NULL))
webkit_user_content_manager_add_style_sheet( webkit_user_content_manager_add_style_sheet(
contentmanager, contentmanager,
webkit_user_style_sheet_new( webkit_user_style_sheet_new(style, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
style, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
WEBKIT_USER_STYLE_LEVEL_USER, NULL, NULL)); WEBKIT_USER_STYLE_LEVEL_USER, NULL, NULL));
return g_object_new( return g_object_new(WEBKIT_TYPE_WEB_VIEW, "settings", settings, "web-context", web_context,
WEBKIT_TYPE_WEB_VIEW, "user-content-manager", contentmanager, NULL);
"settings", settings,
"web-context", web_context,
"user-content-manager", contentmanager,
NULL
);
} }
void load_uri(WebKitWebView *view, const char *uri) void load_uri(WebKitWebView *view, const char *uri)
{ {
if (g_str_has_prefix(uri, "http://") if (g_str_has_prefix(uri, "http://") || g_str_has_prefix(uri, "https://") ||
|| g_str_has_prefix(uri, "https://") g_str_has_prefix(uri, "file://") || g_str_has_prefix(uri, "about:")) {
|| g_str_has_prefix(uri, "file://")
|| g_str_has_prefix(uri, "about:")) {
webkit_web_view_load_uri(view, uri); webkit_web_view_load_uri(view, uri);
} else { } else {
char tmp[strlen(uri) + strlen(SEARCH)]; char tmp[strlen(uri) + strlen(SEARCH)];
@ -97,10 +77,8 @@ void load_uri(WebKitWebView *view, const char *uri)
void load_changed(WebKitWebView *self, WebKitLoadEvent load_event, GtkNotebook *notebook) void load_changed(WebKitWebView *self, WebKitLoadEvent load_event, GtkNotebook *notebook)
{ {
if (load_event == WEBKIT_LOAD_FINISHED) { if (load_event == WEBKIT_LOAD_FINISHED) {
gtk_notebook_set_tab_label_text( gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(self),
notebook, GTK_WIDGET(self), webkit_web_view_get_title(self));
webkit_web_view_get_title(self)
);
gtk_widget_hide(GTK_WIDGET(bar)); gtk_widget_hide(GTK_WIDGET(bar));
} }
} }
@ -122,7 +100,7 @@ void notebook_append(GtkNotebook *notebook, const char *uri)
gtk_notebook_set_tab_reorderable(notebook, GTK_WIDGET(view), true); gtk_notebook_set_tab_reorderable(notebook, GTK_WIDGET(view), true);
gtk_widget_show_all(GTK_WIDGET(window)); gtk_widget_show_all(GTK_WIDGET(window));
gtk_widget_hide(GTK_WIDGET(bar)); gtk_widget_hide(GTK_WIDGET(bar));
webkit_web_view_set_background_color(view, rgba); webkit_web_view_set_background_color(view, &rgba);
load_uri(view, (uri) ? uri : HOME); load_uri(view, (uri) ? uri : HOME);
gtk_notebook_set_current_page(notebook, n); gtk_notebook_set_current_page(notebook, n);
} }
@ -130,10 +108,7 @@ void notebook_append(GtkNotebook *notebook, const char *uri)
WebKitWebView *notebook_get_webview(GtkNotebook *notebook) WebKitWebView *notebook_get_webview(GtkNotebook *notebook)
{ {
return WEBKIT_WEB_VIEW( return WEBKIT_WEB_VIEW(
gtk_notebook_get_nth_page( gtk_notebook_get_nth_page(notebook, gtk_notebook_get_current_page(notebook)));
notebook, gtk_notebook_get_current_page(notebook)
)
);
} }
void show_bar(GtkNotebook *notebook) void show_bar(GtkNotebook *notebook)
@ -146,10 +121,7 @@ void show_bar(GtkNotebook *notebook)
gtk_window_set_focus(window, GTK_WIDGET(search)); gtk_window_set_focus(window, GTK_WIDGET(search));
} else { } else {
const char *search_text = webkit_find_controller_get_search_text( const char *search_text = webkit_find_controller_get_search_text(
webkit_web_view_get_find_controller( webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
notebook_get_webview(notebook)
)
);
if (search_text != NULL) if (search_text != NULL)
gtk_entry_buffer_set_text(search_buf, search_text, strlen(search_text)); gtk_entry_buffer_set_text(search_buf, search_text, strlen(search_text));
@ -184,32 +156,21 @@ int handle_key(func id, GtkNotebook *notebook)
break; break;
case zoomin: case zoomin:
webkit_web_view_set_zoom_level( webkit_web_view_set_zoom_level(notebook_get_webview(notebook), (zoom += ZOOM_VAL));
notebook_get_webview(notebook),
(zoom += ZOOM_VAL)
);
break; break;
case zoomout: case zoomout:
webkit_web_view_set_zoom_level( webkit_web_view_set_zoom_level(notebook_get_webview(notebook), (zoom -= ZOOM_VAL));
notebook_get_webview(notebook),
(zoom -= ZOOM_VAL)
);
break; break;
case zoom_reset: case zoom_reset:
webkit_web_view_set_zoom_level( webkit_web_view_set_zoom_level(notebook_get_webview(notebook), (zoom = ZOOM));
notebook_get_webview(notebook),
(zoom = ZOOM)
);
break; break;
case prev_tab: case prev_tab:
if (gtk_notebook_get_current_page(notebook) == 0) { if (gtk_notebook_get_current_page(notebook) == 0) {
gtk_notebook_set_current_page( gtk_notebook_set_current_page(notebook,
notebook, gtk_notebook_get_n_pages(notebook) - 1);
gtk_notebook_get_n_pages(notebook) - 1
);
} else { } else {
gtk_notebook_prev_page(notebook); gtk_notebook_prev_page(notebook);
} }
@ -217,8 +178,8 @@ int handle_key(func id, GtkNotebook *notebook)
break; break;
case next_tab: case next_tab:
if (gtk_notebook_get_current_page(notebook) if (gtk_notebook_get_current_page(notebook) ==
== gtk_notebook_get_n_pages(notebook) - 1) { gtk_notebook_get_n_pages(notebook) - 1) {
notebook_append(notebook, NULL); notebook_append(notebook, NULL);
gtk_notebook_set_show_tabs(notebook, true); gtk_notebook_set_show_tabs(notebook, true);
} else { } else {
@ -227,16 +188,14 @@ int handle_key(func id, GtkNotebook *notebook)
break; break;
case close_tab: case close_tab:
gtk_notebook_remove_page( gtk_notebook_remove_page(notebook, gtk_notebook_get_current_page(notebook));
notebook,
gtk_notebook_get_current_page(notebook)
);
switch (gtk_notebook_get_n_pages(notebook)) { switch (gtk_notebook_get_n_pages(notebook)) {
case 0: exit(0); case 0:
exit(0);
break; break;
case 1: gtk_notebook_set_show_tabs(notebook, false); case 1:
gtk_notebook_set_show_tabs(notebook, false);
break; break;
} }
@ -263,18 +222,12 @@ int handle_key(func id, GtkNotebook *notebook)
case finder_next: case finder_next:
webkit_find_controller_search_next( webkit_find_controller_search_next(
webkit_web_view_get_find_controller( webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
notebook_get_webview(notebook)
)
);
break; break;
case finder_prev: case finder_prev:
webkit_find_controller_search_previous( webkit_find_controller_search_previous(
webkit_web_view_get_find_controller( webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
notebook_get_webview(notebook)
)
);
break; break;
} }
@ -286,8 +239,7 @@ int keypress(void *self, GdkEvent *e, GtkNotebook *notebook)
(void) self; (void) self;
for (int i = 0; i < sizeof(keys) / sizeof(keys[0]); i++) for (int i = 0; i < sizeof(keys) / sizeof(keys[0]); i++)
if (e->key.keyval == keys[i].key if (e->key.keyval == keys[i].key && e->key.state == keys[i].mod)
&& e->key.state == keys[i].mod)
return handle_key(keys[i].id, notebook); return handle_key(keys[i].id, notebook);
return 0; return 0;
@ -296,18 +248,13 @@ int keypress(void *self, GdkEvent *e, GtkNotebook *notebook)
void search_activate(GtkEntry *self, GtkNotebook *notebook) void search_activate(GtkEntry *self, GtkNotebook *notebook)
{ {
if (entry_mode == _SEARCH) if (entry_mode == _SEARCH)
load_uri(notebook_get_webview(notebook), load_uri(notebook_get_webview(notebook), gtk_entry_buffer_get_text(search_buf));
gtk_entry_buffer_get_text(search_buf));
else if (entry_mode == _FIND) else if (entry_mode == _FIND)
webkit_find_controller_search( webkit_find_controller_search(
webkit_web_view_get_find_controller( webkit_web_view_get_find_controller(notebook_get_webview(notebook)),
notebook_get_webview(notebook)
),
gtk_entry_buffer_get_text(search_buf), gtk_entry_buffer_get_text(search_buf),
WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | WEBKIT_FIND_OPTIONS_WRAP_AROUND,
| WEBKIT_FIND_OPTIONS_WRAP_AROUND, G_MAXUINT);
G_MAXUINT
);
gtk_widget_hide(GTK_WIDGET(bar)); gtk_widget_hide(GTK_WIDGET(bar));
} }
@ -317,9 +264,8 @@ void window_init(GtkNotebook *notebook)
GtkCssProvider *css = gtk_css_provider_new(); GtkCssProvider *css = gtk_css_provider_new();
gtk_css_provider_load_from_path(css, "/usr/share/themes/rose/style.css", NULL); gtk_css_provider_load_from_path(css, "/usr/share/themes/rose/style.css", NULL);
gtk_style_context_add_provider_for_screen( gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(css),
gdk_screen_get_default(), 800);
GTK_STYLE_PROVIDER(css), 800);
gtk_entry_buffer_new("", 0); gtk_entry_buffer_new("", 0);
gtk_entry_set_alignment(search, 0.48); gtk_entry_set_alignment(search, 0.48);