add history support

This commit is contained in:
fenze 2022-05-13 20:37:50 +02:00
parent 7e0ec6d195
commit 88efc15704
6 changed files with 78 additions and 11 deletions

View File

@ -1,14 +1,14 @@
#include "keyconf.h" #include "keyconf.h"
OPTIONS { OPTIONS {
[CACHE] = DEFAULT, [CACHE] = DEFAULT,
[HOMEPAGE] = DEFAULT, [HOMEPAGE] = DEFAULT,
}; };
APPERANCE { APPERANCE {
[HEIGHT] = 600, [HEIGHT] = DEFAULT,
[WIDTH] = 800, [WIDTH] = DEFAULT,
[DARKMODE] = true [DARKMODE] = TRUE
}; };
KEYBINDS { KEYBINDS {
@ -28,5 +28,6 @@ KEYBINDS {
{ MODSFT, GDK_KEY_N, findprev }, { MODSFT, GDK_KEY_N, findprev },
{ MODKEY, GDK_KEY_r, reload }, { MODKEY, GDK_KEY_r, reload },
{ MODSFT, GDK_KEY_R, reloadforce }, { MODSFT, GDK_KEY_R, reloadforce },
{ NOMODK, GDK_KEY_F11, fullscreen } { NOMODK, GDK_KEY_F11, fullscreen },
{ MODSFT, GDK_KEY_H, history }
}; };

View File

@ -11,7 +11,7 @@
#define CACHE 0 #define CACHE 0
#define HOMEPAGE 1 #define HOMEPAGE 1
#define DEFAULT NULL #define DEFAULT 0
#define HEIGHT 0 #define HEIGHT 0
#define WIDTH 1 #define WIDTH 1
@ -46,5 +46,5 @@ enum {
up, up,
reload, reload,
reloadforce, reloadforce,
LAST_FUNC history
}; };

View File

@ -21,7 +21,7 @@ search()
[ -z "$SEARCH" ] && exit [ -z "$SEARCH" ] && exit
ROSE_GO=$(xprop -id "$CURRENT_ID" | grep _ROSE_URI) ROSE_GO=$(xprop -id "$CURRENT_ID" | grep rose)
[ -z "$1" ] || ROSE_GO='' [ -z "$1" ] || ROSE_GO=''
@ -31,7 +31,7 @@ search()
exit exit
} || { } || {
FULL_URL=$(printf "$BOOKMARKS" | grep -w "$SEARCH" | sed 's/ /\./g') FULL_URL=$(printf "$BOOKMARKS" | grep -w "$SEARCH" | sed 's/ /\./g')
xprop -id "$CURRENT_ID" -f "_ROSE_GO" 8u -set "_ROSE_GO" $FULL_URL xprop -id "$CURRENT_ID" -f "_ROSE_GO" 8u -set "_ROSE_GO" https://$FULL_URL
exit exit
} }
} }
@ -48,11 +48,21 @@ find()
{ {
FIND=$(printf "" | dmenu -p Find:) FIND=$(printf "" | dmenu -p Find:)
CURRENT_ID=$(xdotool getactivewindow) CURRENT_ID=$(xdotool getactivewindow)
ROSE_FIND=$(xprop -id "$CURRENT_ID" | grep _ROSE_URI) ROSE_FIND=$(xprop -id "$CURRENT_ID" | grep rose)
[ -z "$ROSE_FIND" ] || xprop -id "$CURRENT_ID" -f "_ROSE_FIND" 8u -set "_ROSE_FIND" "$FIND" [ -z "$ROSE_FIND" ] || xprop -id "$CURRENT_ID" -f "_ROSE_FIND" 8u -set "_ROSE_FIND" "$FIND"
} }
history()
{
CHOOSE=$(tac ~/.cache/rose/history | dmenu -p History:);
CURRENT_ID=$(xdotool getactivewindow)
ROSE_GO=$(xprop -id "$CURRENT_ID" | grep rose)
[ -z "$ROSE_GO" ] || xprop -id "$CURRENT_ID" -f "_ROSE_GO" 8u -set "_ROSE_GO" "$CHOOSE"
}
[ -z "$1" ] && search || { [ -z "$1" ] && search || {
INSTALL_PATH=/usr/local/bin/dmenu_rose INSTALL_PATH=/usr/local/bin/dmenu_rose
case "$1" in case "$1" in
@ -61,5 +71,6 @@ find()
add_bookmark) echo "$2" >> $BOOKMARKS_PATH;; add_bookmark) echo "$2" >> $BOOKMARKS_PATH;;
new_window) search new;; new_window) search new;;
find) find;; find) find;;
history) history;
esac esac
} }

View File

@ -106,6 +106,30 @@ void rose_webview_load_url(WebKitWebView *webview, const char *url)
setatom(AtomUri, url); setatom(AtomUri, url);
} }
void rose_load_changed_callback(WebKitWebView *webview,
WebKitLoadEvent event)
{
if (event == WEBKIT_LOAD_FINISHED) {
const char *uri = webkit_web_view_get_uri(webview);
char *cookiefile = calloc(1, sizeof(char) * (strlen(options[CACHE]) + 32) + 1);
sprintf(cookiefile, "%s/history", options[CACHE]);
FILE *f = fopen(cookiefile, "r");
if (!f) {
fclose(f);
FILE *f = fopen(cookiefile, "w");
fclose(f);
} else {
fclose(f);
}
FILE *cookie = fopen(cookiefile, "a");
fprintf(f, "%s\n", uri);
fclose(cookie);
free(cookiefile);
}
}
static void rose_download(const char* uri) static void rose_download(const char* uri)
{ {
char *cmd = calloc(1, sizeof(char) * strlen(uri) + 1); char *cmd = calloc(1, sizeof(char) * strlen(uri) + 1);

View File

@ -25,4 +25,7 @@ RoseWebViewNavigationFlags rose_webview_get_navigation_flags(RoseWebView *webvie
void rose_webview_go_back(RoseWebView *window); void rose_webview_go_back(RoseWebView *window);
void rose_webview_go_forward(RoseWebView *window); void rose_webview_go_forward(RoseWebView *window);
void rose_load_changed_callback(WebKitWebView *webview,
WebKitLoadEvent event);
const char* rose_webview_get_address(RoseWebView *webview); const char* rose_webview_get_address(RoseWebView *webview);

View File

@ -162,6 +162,25 @@ static gboolean key_press_callback(RoseWindow *window,
case reloadforce: case reloadforce:
webkit_web_view_reload_bypass_cache(window->webview); webkit_web_view_reload_bypass_cache(window->webview);
break; break;
case history: {
int id = fork();
if (id == 0) {
close(spair[0]);
close(spair[1]);
setsid();
char* argument_list[] = { "/bin/sh", "-c", "dmenu_rose\thistory", NULL};
execvp("/bin/sh", argument_list);
perror(" failed");
exit(1);
} else {
wait(&id);
char *uri;
if (strcmp((uri = (char*)getatom(AtomGo)), ""))
rose_webview_load_url(window->webview, uri);
}
} break;
} }
} }
} }
@ -202,8 +221,17 @@ guint rose_window_show(GtkApplication *app, RoseWindow *window, const char *url)
g_signal_connect(G_OBJECT(window->webview), "web-process-terminated", g_signal_connect(G_OBJECT(window->webview), "web-process-terminated",
G_CALLBACK(destroy), window); G_CALLBACK(destroy), window);
g_signal_connect(G_OBJECT(window->webview), "load-changed",
G_CALLBACK(rose_load_changed_callback), window);
if (url) { if (url) {
rose_webview_load_url(WEBKIT_WEB_VIEW(webview), url); rose_webview_load_url(WEBKIT_WEB_VIEW(webview), url);
setatom(AtomUri, url);
}
if (!(appearance[WIDTH] && appearance[HEIGHT])) {
appearance[WIDTH] = 1280;
appearance[HEIGHT] = 720;
} }
gtk_window_set_default_size(GTK_WINDOW(w), appearance[WIDTH], appearance[HEIGHT]); gtk_window_set_default_size(GTK_WINDOW(w), appearance[WIDTH], appearance[HEIGHT]);