add history support
This commit is contained in:
parent
7e0ec6d195
commit
88efc15704
9
config.h
9
config.h
|
@ -6,9 +6,9 @@ OPTIONS {
|
|||
};
|
||||
|
||||
APPERANCE {
|
||||
[HEIGHT] = 600,
|
||||
[WIDTH] = 800,
|
||||
[DARKMODE] = true
|
||||
[HEIGHT] = DEFAULT,
|
||||
[WIDTH] = DEFAULT,
|
||||
[DARKMODE] = TRUE
|
||||
};
|
||||
|
||||
KEYBINDS {
|
||||
|
@ -28,5 +28,6 @@ KEYBINDS {
|
|||
{ MODSFT, GDK_KEY_N, findprev },
|
||||
{ MODKEY, GDK_KEY_r, reload },
|
||||
{ MODSFT, GDK_KEY_R, reloadforce },
|
||||
{ NOMODK, GDK_KEY_F11, fullscreen }
|
||||
{ NOMODK, GDK_KEY_F11, fullscreen },
|
||||
{ MODSFT, GDK_KEY_H, history }
|
||||
};
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#define CACHE 0
|
||||
#define HOMEPAGE 1
|
||||
|
||||
#define DEFAULT NULL
|
||||
#define DEFAULT 0
|
||||
|
||||
#define HEIGHT 0
|
||||
#define WIDTH 1
|
||||
|
@ -46,5 +46,5 @@ enum {
|
|||
up,
|
||||
reload,
|
||||
reloadforce,
|
||||
LAST_FUNC
|
||||
history
|
||||
};
|
||||
|
|
|
@ -21,7 +21,7 @@ search()
|
|||
|
||||
[ -z "$SEARCH" ] && exit
|
||||
|
||||
ROSE_GO=$(xprop -id "$CURRENT_ID" | grep _ROSE_URI)
|
||||
ROSE_GO=$(xprop -id "$CURRENT_ID" | grep rose)
|
||||
|
||||
[ -z "$1" ] || ROSE_GO=''
|
||||
|
||||
|
@ -31,7 +31,7 @@ search()
|
|||
exit
|
||||
} || {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -48,11 +48,21 @@ find()
|
|||
{
|
||||
FIND=$(printf "" | dmenu -p Find:)
|
||||
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"
|
||||
}
|
||||
|
||||
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 || {
|
||||
INSTALL_PATH=/usr/local/bin/dmenu_rose
|
||||
case "$1" in
|
||||
|
@ -61,5 +71,6 @@ find()
|
|||
add_bookmark) echo "$2" >> $BOOKMARKS_PATH;;
|
||||
new_window) search new;;
|
||||
find) find;;
|
||||
history) history;
|
||||
esac
|
||||
}
|
||||
|
|
24
webview.c
24
webview.c
|
@ -106,6 +106,30 @@ void rose_webview_load_url(WebKitWebView *webview, const char *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)
|
||||
{
|
||||
char *cmd = calloc(1, sizeof(char) * strlen(uri) + 1);
|
||||
|
|
|
@ -25,4 +25,7 @@ RoseWebViewNavigationFlags rose_webview_get_navigation_flags(RoseWebView *webvie
|
|||
void rose_webview_go_back(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);
|
||||
|
|
28
window.c
28
window.c
|
@ -162,6 +162,25 @@ static gboolean key_press_callback(RoseWindow *window,
|
|||
case reloadforce:
|
||||
webkit_web_view_reload_bypass_cache(window->webview);
|
||||
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_CALLBACK(destroy), window);
|
||||
|
||||
g_signal_connect(G_OBJECT(window->webview), "load-changed",
|
||||
G_CALLBACK(rose_load_changed_callback), window);
|
||||
|
||||
if (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]);
|
||||
|
|
Loading…
Reference in New Issue
Block a user