nmap F hint-link-new
nmap ;o hint-input-open
nmap ;t hint-input-tabopen
+nmap y yank-uri
+nmap Y yank-selection
cmap <tab> complete
cmap <shift-tab> complete-back
hmap <tab> hint-focus-next
{"hint-input-tabopen", command_hints, {HINTS_TYPE_LINK | HINTS_TARGET_BLANK | HINTS_PROCESS | HINTS_PROCESS_INPUT, ";t"}, VP_MODE_HINTING},
{"hint-focus-next", command_hints_focus, {0}, VP_MODE_HINTING},
{"hint-focus-prev", command_hints_focus, {1}, VP_MODE_HINTING},
+ {"yank-uri", command_yank, {COMMAND_YANK_PRIMARY | COMMAND_YANK_SECONDARY | COMMAND_YANK_URI}, VP_MODE_NORMAL},
+ {"yank-selection", command_yank, {COMMAND_YANK_PRIMARY | COMMAND_YANK_SECONDARY | COMMAND_YANK_SELECTION}, VP_MODE_NORMAL},
};
static void command_write_input(const gchar* str);
gboolean command_yank(const Arg* arg)
{
- const gchar* uri = CURRENT_URL();
- if (!uri) {
- return TRUE;
- }
+ if (arg->i & COMMAND_YANK_SELECTION) {
+ gchar* text = NULL;
+ /* copy current selection to clipboard */
+ webkit_web_view_copy_clipboard(vp.gui.webview);
+ text = gtk_clipboard_wait_for_text(PRIMARY_CLIPBOARD());
+ if (!text) {
+ text = gtk_clipboard_wait_for_text(SECONDARY_CLIPBOARD());
+ }
+ if (text) {
+ vp_echo(VP_MSG_NORMAL, FALSE, "Yanked: %s", text);
+ g_free(text);
- vp_set_clipboard(uri, arg->i);
+ return TRUE;
+ }
+ } else {
+ /* use current arg.s a new clipboard content */
+ Arg a = {arg->i, arg->s};
+ if (arg->i & COMMAND_YANK_URI) {
+ /* yank current url */
+ a.s = (gchar*)CURRENT_URL();
+ }
+ if (vp_set_clipboard(&a)) {
+ vp_echo(VP_MSG_NORMAL, FALSE, "Yanked: %s", a.s);
- return TRUE;
+ return TRUE;
+ }
+ }
+ return FALSE;
}
static void command_write_input(const gchar* str)
#ifndef COMMAND_H
#define COMMAND_H
+enum {
+ COMMAND_YANK_PRIMARY = VP_CLIPBOARD_PRIMARY,
+ COMMAND_YANK_SECONDARY = VP_CLIPBOARD_SECONDARY,
+ COMMAND_YANK_URI = (COMMAND_YANK_SECONDARY<<1),
+ COMMAND_YANK_SELECTION = (COMMAND_YANK_SECONDARY<<2)
+};
+
typedef gboolean (*Command)(const Arg* arg);
typedef struct {
gboolean command_inspect(const Arg* arg);
gboolean command_hints(const Arg* arg);
gboolean command_hints_focus(const Arg* arg);
+gboolean command_yank(const Arg* arg);
#endif /* end of include guard: COMMAND_H */
vp_echo(VP_MSG_NORMAL, FALSE, "");
}
+gboolean vp_set_clipboard(const Arg* arg)
+{
+ gboolean result = FALSE;
+ if (!arg->s) {
+ return result;
+ }
+
+ if (arg->i & VP_CLIPBOARD_PRIMARY) {
+ gtk_clipboard_set_text(PRIMARY_CLIPBOARD(), arg->s, -1);
+ result = TRUE;
+ }
+ if (arg->i & VP_CLIPBOARD_SECONDARY) {
+ gtk_clipboard_set_text(SECONDARY_CLIPBOARD(), arg->s, -1);
+ result = TRUE;
+ }
+
+ return result;
+}
+
static gboolean vp_hide_message(void)
{
vp_echo(VP_MSG_NORMAL, FALSE, "");
#define GET_CLEAN_MODE() (CLEAN_MODE(vp.state.mode))
#define CLEAR_INPUT() (vp_echo(VP_MSG_NORMAL, ""))
#define CURRENT_URL() webkit_web_view_get_uri(vp.gui.webview)
+#define PRIMARY_CLIPBOARD() gtk_clipboard_get(GDK_SELECTION_PRIMARY)
+#define SECONDARY_CLIPBOARD() gtk_clipboard_get(GDK_NONE)
#define IS_ESCAPE_KEY(k, s) ((k == GDK_Escape && s == 0) || (k == GDK_c && s == GDK_CONTROL_MASK))
#define CLEAN_STATE_WITH_SHIFT(e) ((e)->state & (GDK_MOD1_MASK|GDK_MOD4_MASK|GDK_SHIFT_MASK|GDK_CONTROL_MASK))
TYPE_COLOR,
} Type;
+enum {
+ VP_CLIPBOARD_PRIMARY = (1<<0),
+ VP_CLIPBOARD_SECONDARY = (1<<1)
+};
+
/* structs */
typedef struct {
gint i;
gboolean vp_load_uri(const Arg* arg);
void vp_clean_up(void);
void vp_clean_input(void);
+gboolean vp_set_clipboard(const Arg* arg);
#endif /* end of include guard: MAIN_H */