Fix webkit bg color error, add rose-nativefier
This commit is contained in:
parent
68ca1eb61a
commit
5e7587dd99
37
.clang-format
Normal file
37
.clang-format
Normal 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
|
|
@ -7,6 +7,7 @@
|
|||
- ~400L code base
|
||||
- custom gtk and websites css
|
||||
- hackable without any knowledge
|
||||
- builtin script nativefier
|
||||
|
||||
#
|
||||
### 👐 Contribute
|
||||
|
|
5
build.sh
5
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
|
||||
|
|
27
compile_flags.txt
Normal file
27
compile_flags.txt
Normal 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
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
9
rose-nativefier
Executable file
9
rose-nativefier
Executable 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
142
rose.c
|
@ -10,24 +10,19 @@
|
|||
* Author: fenze <contact@fenze.dev>
|
||||
*/
|
||||
|
||||
#include <webkit2/webkit2.h>
|
||||
#include "config.h"
|
||||
|
||||
#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, \
|
||||
"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
|
||||
};
|
||||
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_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
|
||||
);
|
||||
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)];
|
||||
|
@ -97,10 +77,8 @@ void load_uri(WebKitWebView *view, const char *uri)
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +100,7 @@ void notebook_append(GtkNotebook *notebook, const char *uri)
|
|||
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));
|
||||
|
@ -184,32 +156,21 @@ int handle_key(func id, GtkNotebook *notebook)
|
|||
break;
|
||||
|
||||
case zoomin:
|
||||
webkit_web_view_set_zoom_level(
|
||||
notebook_get_webview(notebook),
|
||||
(zoom += ZOOM_VAL)
|
||||
);
|
||||
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)
|
||||
);
|
||||
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)
|
||||
);
|
||||
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
|
||||
);
|
||||
gtk_notebook_set_current_page(notebook,
|
||||
gtk_notebook_get_n_pages(notebook) - 1);
|
||||
} else {
|
||||
gtk_notebook_prev_page(notebook);
|
||||
}
|
||||
|
@ -217,8 +178,8 @@ int handle_key(func id, GtkNotebook *notebook)
|
|||
break;
|
||||
|
||||
case next_tab:
|
||||
if (gtk_notebook_get_current_page(notebook)
|
||||
== gtk_notebook_get_n_pages(notebook) - 1) {
|
||||
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 {
|
||||
|
@ -227,16 +188,14 @@ int handle_key(func id, GtkNotebook *notebook)
|
|||
break;
|
||||
|
||||
case close_tab:
|
||||
gtk_notebook_remove_page(
|
||||
notebook,
|
||||
gtk_notebook_get_current_page(notebook)
|
||||
);
|
||||
|
||||
gtk_notebook_remove_page(notebook, gtk_notebook_get_current_page(notebook));
|
||||
|
||||
switch (gtk_notebook_get_n_pages(notebook)) {
|
||||
case 0: exit(0);
|
||||
case 0:
|
||||
exit(0);
|
||||
break;
|
||||
case 1: gtk_notebook_set_show_tabs(notebook, false);
|
||||
case 1:
|
||||
gtk_notebook_set_show_tabs(notebook, false);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -263,18 +222,12 @@ int handle_key(func id, GtkNotebook *notebook)
|
|||
|
||||
case finder_next:
|
||||
webkit_find_controller_search_next(
|
||||
webkit_web_view_get_find_controller(
|
||||
notebook_get_webview(notebook)
|
||||
)
|
||||
);
|
||||
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)
|
||||
)
|
||||
);
|
||||
webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
),
|
||||
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_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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user