diff options
author | Marco Peereboom <marco@conformal.com> | 2010-12-29 20:32:02 +0000 |
---|---|---|
committer | Marco Peereboom <marco@conformal.com> | 2010-12-29 20:32:02 +0000 |
commit | 554aa0d8f0bae36b6a7a14d754c4493c4927be88 (patch) | |
tree | 7af2e34d47a072c92ffed07684e089c95c9657f7 | |
parent | 36d34db688effafd4bea58d5a5b23f26350fecee (diff) | |
download | xombrero-554aa0d8f0bae36b6a7a14d754c4493c4927be88.tar.gz |
Add yank and paste from Stevan Andjelkovic <stevan@student.chalmers.se>
-rw-r--r-- | xxxterm.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/xxxterm.c b/xxxterm.c index b214bd5..a02696f 100644 --- a/xxxterm.c +++ b/xxxterm.c @@ -316,6 +316,9 @@ struct karg { #define XT_SEARCH_NEXT (1) #define XT_SEARCH_PREV (2) +#define XT_PASTE_CURRENT_TAB (0) +#define XT_PASTE_NEW_TAB (1) + #define XT_FONT_SET (0) #define XT_JS_TOGGLE (0) @@ -1343,6 +1346,68 @@ save_tabs_and_quit(struct tab *t, struct karg *args) } int +yank_uri(struct tab *t, struct karg *args) +{ + WebKitWebFrame *frame; + const gchar *uri; + GtkClipboard *clipboard; + + frame = webkit_web_view_get_main_frame(t->wv); + uri = webkit_web_frame_get_uri(frame); + if (!uri) + return (1); + + clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); + gtk_clipboard_set_text(clipboard, uri, -1); + + return (0); +} + +struct paste_args { + struct tab *t; + int i; +}; + +void +paste_uri_cb(GtkClipboard *clipboard, const gchar *text, gpointer data) +{ + struct paste_args *pap; + + if (data == NULL) + return; + + pap = (struct paste_args *)data; + + switch(pap->i) { + case XT_PASTE_CURRENT_TAB: + webkit_web_view_load_uri(pap->t->wv, text); + break; + case XT_PASTE_NEW_TAB: + create_new_tab((char *)text, 1); + break; + } + + g_free(pap); +} + +int +paste_uri(struct tab *t, struct karg *args) +{ + GtkClipboard *clipboard; + struct paste_args *pap; + + pap = g_malloc(sizeof(struct paste_args)); + + pap->t = t; + pap->i = args->i; + + clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); + gtk_clipboard_request_text(clipboard, paste_uri_cb, pap); + + return (0); +} + +int toggle_js(struct tab *t, struct karg *args) { int es, i; @@ -2790,6 +2855,9 @@ struct key { { GDK_CONTROL_MASK, 0, GDK_q, quit, {0} }, { GDK_CONTROL_MASK, 0, GDK_j, toggle_js, {.i = XT_JS_TOGGLE} }, { GDK_CONTROL_MASK, 0, GDK_s, toggle_src, {0} }, + { 0, 0, GDK_y, yank_uri, {0} }, + { 0, 0, GDK_p, paste_uri, {.i = XT_PASTE_CURRENT_TAB} }, + { GDK_SHIFT_MASK, 0, GDK_P, paste_uri, {.i = XT_PASTE_NEW_TAB} }, /* search */ { 0, 0, GDK_n, search, {.i = XT_SEARCH_NEXT} }, |