aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-format37
-rw-r--r--README.md3
-rwxr-xr-xbuild.sh5
-rw-r--r--compile_flags.txt27
-rwxr-xr-xinstall.sh3
-rwxr-xr-xrosebin0 -> 38760 bytes
-rwxr-xr-xrose-nativefier9
-rw-r--r--rose.c316
8 files changed, 212 insertions, 188 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..69e6656
--- /dev/null
+++ b/.clang-format
@@ -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
diff --git a/README.md b/README.md
index 4ece966..454067a 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,8 @@
- ~400L code base
- custom gtk and websites css
- hackable without any knowledge
-
+ - builtin script nativefier
+
#
### 👐 Contribute
See [contributing.md](https://github.com/mini-rose/rose/.github/contributing.md).
diff --git a/build.sh b/build.sh
index 9bb339f..cffe9d5 100755
--- a/build.sh
+++ b/build.sh
@@ -5,4 +5,7 @@ DEPS=('webkit2gtk-4.0')
INCS=`pkg-config --cflags ${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
diff --git a/compile_flags.txt b/compile_flags.txt
new file mode 100644
index 0000000..7fd8daf
--- /dev/null
+++ b/compile_flags.txt
@@ -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
+
diff --git a/install.sh b/install.sh
index c04c668..ffed296 100755
--- a/install.sh
+++ b/install.sh
@@ -1,5 +1,6 @@
./build.sh && {
cp -f rose /usr/bin
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
}
diff --git a/rose b/rose
new file mode 100755
index 0000000..3dde429
--- /dev/null
+++ b/rose
Binary files differ
diff --git a/rose-nativefier b/rose-nativefier
new file mode 100755
index 0000000..cc15fe4
--- /dev/null
+++ b/rose-nativefier
@@ -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
+}
diff --git a/rose.c b/rose.c
index 2b6a2d1..8914048 100644
--- a/rose.c
+++ b/rose.c
@@ -10,24 +10,19 @@
* Author: fenze <contact@fenze.dev>
*/
-#include <webkit2/webkit2.h>
#include "config.h"
-#define CACHE \
- "base-cache-directory", CACHE_DIR, \
- "base-data-directory", CACHE_DIR, \
- "disk-cache-directory", CACHE_DIR, \
- "dom-cache-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, \
- "service-worker-registrations-directory", CACHE_DIR
-
-enum {
- _SEARCH, _FIND
-};
+#include <webkit2/webkit2.h>
+
+#define CACHE \
+ "base-cache-directory", CACHE_DIR, "base-data-directory", CACHE_DIR, \
+ "disk-cache-directory", CACHE_DIR, "dom-cache-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, \
+ "service-worker-registrations-directory", CACHE_DIR
+
+enum { _SEARCH, _FIND };
static int entry_mode;
static GtkWindow *window;
@@ -45,47 +40,32 @@ WebKitWebView *webview_new()
settings = webkit_settings_new_with_settings(WEBKIT, NULL);
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();
cookiemanager = webkit_web_context_get_cookie_manager(web_context);
- webkit_cookie_manager_set_persistent_storage(
- cookiemanager, CACHE_DIR"/cookies.sqlite",
- WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE
- );
+ webkit_cookie_manager_set_persistent_storage(cookiemanager, CACHE_DIR "/cookies.sqlite",
+ WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE);
- webkit_cookie_manager_set_accept_policy(
- cookiemanager, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS
- );
+ webkit_cookie_manager_set_accept_policy(cookiemanager, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
- webkit_web_context_set_process_model(
- web_context,
- WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES
- );
+ webkit_web_context_set_process_model(web_context,
+ WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
if (g_file_get_contents("~/.config/rose/style.css", &style, NULL, NULL))
webkit_user_content_manager_add_style_sheet(
- contentmanager,
- webkit_user_style_sheet_new(
- style, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
- WEBKIT_USER_STYLE_LEVEL_USER, NULL, NULL));
-
- return g_object_new(
- WEBKIT_TYPE_WEB_VIEW,
- "settings", settings,
- "web-context", web_context,
- "user-content-manager", contentmanager,
- NULL
- );
+ contentmanager,
+ webkit_user_style_sheet_new(style, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
+ WEBKIT_USER_STYLE_LEVEL_USER, NULL, NULL));
+
+ return g_object_new(WEBKIT_TYPE_WEB_VIEW, "settings", settings, "web-context", web_context,
+ "user-content-manager", contentmanager, NULL);
}
void load_uri(WebKitWebView *view, const char *uri)
{
- if (g_str_has_prefix(uri, "http://")
- || g_str_has_prefix(uri, "https://")
- || g_str_has_prefix(uri, "file://")
- || g_str_has_prefix(uri, "about:")) {
+ if (g_str_has_prefix(uri, "http://") || g_str_has_prefix(uri, "https://") ||
+ g_str_has_prefix(uri, "file://") || g_str_has_prefix(uri, "about:")) {
webkit_web_view_load_uri(view, uri);
} else {
char tmp[strlen(uri) + strlen(SEARCH)];
@@ -94,13 +74,11 @@ 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) {
- gtk_notebook_set_tab_label_text(
- notebook, GTK_WIDGET(self),
- webkit_web_view_get_title(self)
- );
+ gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(self),
+ webkit_web_view_get_title(self));
gtk_widget_hide(GTK_WIDGET(bar));
}
}
@@ -115,14 +93,14 @@ void notebook_append(GtkNotebook *notebook, const char *uri)
WebKitWebView *view = webview_new();
- gtk_widget_set_visual (GTK_WIDGET (window), rgba_visual);
+ gtk_widget_set_visual(GTK_WIDGET(window), rgba_visual);
g_signal_connect(view, "load_changed", G_CALLBACK(load_changed), notebook);
int n = gtk_notebook_append_page(notebook, GTK_WIDGET(view), NULL);
gtk_notebook_set_tab_reorderable(notebook, GTK_WIDGET(view), true);
gtk_widget_show_all(GTK_WIDGET(window));
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);
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)
{
return WEBKIT_WEB_VIEW(
- gtk_notebook_get_nth_page(
- notebook, gtk_notebook_get_current_page(notebook)
- )
- );
+ gtk_notebook_get_nth_page(notebook, gtk_notebook_get_current_page(notebook)));
}
void show_bar(GtkNotebook *notebook)
@@ -146,10 +121,7 @@ void show_bar(GtkNotebook *notebook)
gtk_window_set_focus(window, GTK_WIDGET(search));
} else {
const char *search_text = webkit_find_controller_get_search_text(
- webkit_web_view_get_find_controller(
- notebook_get_webview(notebook)
- )
- );
+ webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
if (search_text != NULL)
gtk_entry_buffer_set_text(search_buf, search_text, strlen(search_text));
@@ -165,117 +137,98 @@ int handle_key(func id, GtkNotebook *notebook)
static bool is_fullscreen = 0;
switch (id) {
- case goback:
- webkit_web_view_go_back(notebook_get_webview(notebook));
+ case goback:
+ webkit_web_view_go_back(notebook_get_webview(notebook));
+ break;
+ case goforward:
+ webkit_web_view_go_forward(notebook_get_webview(notebook));
+ break;
+
+ case refresh:
+ webkit_web_view_reload(notebook_get_webview(notebook));
+ break;
+ case refresh_force:
+ webkit_web_view_reload_bypass_cache(notebook_get_webview(notebook));
+ break;
+
+ case back_to_home:
+ load_uri(notebook_get_webview(notebook), HOME);
+ break;
+
+ case zoomin:
+ webkit_web_view_set_zoom_level(notebook_get_webview(notebook), (zoom += ZOOM_VAL));
+ break;
+
+ case zoomout:
+ webkit_web_view_set_zoom_level(notebook_get_webview(notebook), (zoom -= ZOOM_VAL));
+ break;
+
+ case zoom_reset:
+ webkit_web_view_set_zoom_level(notebook_get_webview(notebook), (zoom = ZOOM));
+ break;
+
+ case prev_tab:
+ if (gtk_notebook_get_current_page(notebook) == 0) {
+ gtk_notebook_set_current_page(notebook,
+ gtk_notebook_get_n_pages(notebook) - 1);
+ } else {
+ gtk_notebook_prev_page(notebook);
+ }
+
+ break;
+
+ case next_tab:
+ if (gtk_notebook_get_current_page(notebook) ==
+ gtk_notebook_get_n_pages(notebook) - 1) {
+ notebook_append(notebook, NULL);
+ gtk_notebook_set_show_tabs(notebook, true);
+ } else {
+ gtk_notebook_next_page(notebook);
+ }
+ break;
+
+ case close_tab:
+ gtk_notebook_remove_page(notebook, gtk_notebook_get_current_page(notebook));
+
+ switch (gtk_notebook_get_n_pages(notebook)) {
+ case 0:
+ exit(0);
break;
- case goforward:
- webkit_web_view_go_forward(notebook_get_webview(notebook));
- break;
-
- case refresh:
- webkit_web_view_reload(notebook_get_webview(notebook));
- break;
- case refresh_force:
- webkit_web_view_reload_bypass_cache(notebook_get_webview(notebook));
- break;
-
- case back_to_home:
- load_uri(notebook_get_webview(notebook), HOME);
- break;
-
- case zoomin:
- webkit_web_view_set_zoom_level(
- notebook_get_webview(notebook),
- (zoom += ZOOM_VAL)
- );
- break;
-
- case zoomout:
- webkit_web_view_set_zoom_level(
- notebook_get_webview(notebook),
- (zoom -= ZOOM_VAL)
- );
- break;
-
- case zoom_reset:
- webkit_web_view_set_zoom_level(
- notebook_get_webview(notebook),
- (zoom = ZOOM)
- );
- break;
-
- case prev_tab:
- if (gtk_notebook_get_current_page(notebook) == 0) {
- gtk_notebook_set_current_page(
- notebook,
- gtk_notebook_get_n_pages(notebook) - 1
- );
- } else {
- gtk_notebook_prev_page(notebook);
- }
-
- break;
-
- case next_tab:
- if (gtk_notebook_get_current_page(notebook)
- == gtk_notebook_get_n_pages(notebook) - 1) {
- notebook_append(notebook, NULL);
- gtk_notebook_set_show_tabs(notebook, true);
- } else {
- gtk_notebook_next_page(notebook);
- }
- break;
-
- case close_tab:
- gtk_notebook_remove_page(
- notebook,
- gtk_notebook_get_current_page(notebook)
- );
-
-
- switch (gtk_notebook_get_n_pages(notebook)) {
- case 0: exit(0);
- break;
- case 1: gtk_notebook_set_show_tabs(notebook, false);
- break;
- }
-
- break;
-
- case toggle_fullscreen:
- if (is_fullscreen)
- gtk_window_unfullscreen(window);
- else
- gtk_window_fullscreen(window);
-
- is_fullscreen = !is_fullscreen;
- break;
-
- case show_searchbar:
- entry_mode = _SEARCH;
- show_bar(notebook);
- break;
-
- case show_finder:
- entry_mode = _FIND;
- show_bar(notebook);
- break;
-
- case finder_next:
- webkit_find_controller_search_next(
- webkit_web_view_get_find_controller(
- notebook_get_webview(notebook)
- )
- );
- break;
-
- case finder_prev:
- webkit_find_controller_search_previous(
- webkit_web_view_get_find_controller(
- notebook_get_webview(notebook)
- )
- );
+ case 1:
+ gtk_notebook_set_show_tabs(notebook, false);
break;
+ }
+
+ break;
+
+ case toggle_fullscreen:
+ if (is_fullscreen)
+ gtk_window_unfullscreen(window);
+ else
+ gtk_window_fullscreen(window);
+
+ is_fullscreen = ! is_fullscreen;
+ break;
+
+ case show_searchbar:
+ entry_mode = _SEARCH;
+ show_bar(notebook);
+ break;
+
+ case show_finder:
+ entry_mode = _FIND;
+ show_bar(notebook);
+ break;
+
+ case finder_next:
+ webkit_find_controller_search_next(
+ webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
+ break;
+
+ case finder_prev:
+ webkit_find_controller_search_previous(
+ webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
+ break;
}
return 1;
@@ -286,8 +239,7 @@ int keypress(void *self, GdkEvent *e, GtkNotebook *notebook)
(void) self;
for (int i = 0; i < sizeof(keys) / sizeof(keys[0]); i++)
- if (e->key.keyval == keys[i].key
- && e->key.state == keys[i].mod)
+ if (e->key.keyval == keys[i].key && e->key.state == keys[i].mod)
return handle_key(keys[i].id, notebook);
return 0;
@@ -296,18 +248,13 @@ int keypress(void *self, GdkEvent *e, GtkNotebook *notebook)
void search_activate(GtkEntry *self, GtkNotebook *notebook)
{
if (entry_mode == _SEARCH)
- load_uri(notebook_get_webview(notebook),
- gtk_entry_buffer_get_text(search_buf));
+ load_uri(notebook_get_webview(notebook), gtk_entry_buffer_get_text(search_buf));
else if (entry_mode == _FIND)
webkit_find_controller_search(
- webkit_web_view_get_find_controller(
- notebook_get_webview(notebook)
- ),
- gtk_entry_buffer_get_text(search_buf),
- WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE
- | WEBKIT_FIND_OPTIONS_WRAP_AROUND,
- G_MAXUINT
- );
+ webkit_web_view_get_find_controller(notebook_get_webview(notebook)),
+ gtk_entry_buffer_get_text(search_buf),
+ WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | WEBKIT_FIND_OPTIONS_WRAP_AROUND,
+ G_MAXUINT);
gtk_widget_hide(GTK_WIDGET(bar));
}
@@ -317,9 +264,8 @@ void window_init(GtkNotebook *notebook)
GtkCssProvider *css = gtk_css_provider_new();
gtk_css_provider_load_from_path(css, "/usr/share/themes/rose/style.css", NULL);
- gtk_style_context_add_provider_for_screen(
- gdk_screen_get_default(),
- GTK_STYLE_PROVIDER(css), 800);
+ gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(css),
+ 800);
gtk_entry_buffer_new("", 0);
gtk_entry_set_alignment(search, 0.48);
@@ -339,7 +285,7 @@ void notebook_init(GtkNotebook *notebook, const char *uri)
notebook_append(notebook, uri);
}
-void setup(GtkNotebook *notebook, const char* uri)
+void setup(GtkNotebook *notebook, const char *uri)
{
window = GTK_WINDOW(gtk_window_new(0));
notebook = GTK_NOTEBOOK(gtk_notebook_new());