1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
/*
* Copyright (c) 2010-2012 Stefan Bolte <portix@gmx.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <string.h>
#include "dwb.h"
#include "completion.h"
#include "commands.h"
#include "entry.h"
#include "scripts.h"
#include "util.h"
/* dwb_entry_keyrelease_cb {{{*/
gboolean
callback_entry_insert_text(GtkWidget* entry, char *new_text, int length, gpointer position) {
const char *text = GET_TEXT();
int newlen = strlen(text) + length + 1;
char buffer[newlen];
snprintf(buffer, newlen, "%s%s", text, new_text);
if (dwb.state.mode == QUICK_MARK_OPEN) {
return dwb_update_find_quickmark(buffer);
}
return false;
}
gboolean
callback_find_timeout(char *text) {
if (!g_strcmp0(text, GET_TEXT()))
dwb_update_search();
g_free(text);
return false;
}
gboolean
callback_entry_key_release(GtkWidget* entry, GdkEventKey *e) {
if (dwb.state.mode == HINT_MODE) {
if (e->keyval == GDK_KEY_BackSpace) {
return dwb_update_hints(e);
}
}
if (dwb.state.mode == FIND_MODE) {
if (dwb.misc.find_delay > 0)
g_timeout_add(dwb.misc.find_delay, (GSourceFunc)callback_find_timeout, g_strdup(GET_TEXT()));
else
dwb_update_search();
}
return false;
}/*}}}*/
/* dwb_entry_keypress_cb(GtkWidget* entry, GdkEventKey *e) {{{*/
gboolean
callback_entry_key_press(GtkWidget* entry, GdkEventKey *e) {
Mode mode = dwb.state.mode;
gboolean ret = false;
gboolean complete = (mode == DOWNLOAD_GET_PATH || (mode & COMPLETE_PATH));
gboolean set_text = false;
char *text = NULL;
char *buffer, *back;
if (dwb.state.mode & QUICK_MARK_OPEN)
set_text = true;
/* Handled by activate-callback */
if (e->keyval == GDK_KEY_Return)
return dwb_entry_activate(e);
/* Insert primary selection on shift-insert */
if (e->keyval == GDK_KEY_Insert && e->state == GDK_SHIFT_MASK) {
if ((text = dwb_clipboard_get_text(GDK_SELECTION_PRIMARY))) {
buffer = back = g_strdup(text);
while (*buffer) {
if (*buffer == '\n' || *buffer == '\r')
*buffer = ' ';
buffer++;
}
entry_insert_text(back);
g_free(back);
FREE0(text);
}
return true;
}
if (mode == QUICK_MARK_SAVE)
return false;
else if (mode & COMPLETE_BUFFER) {
completion_buffer_key_press(e);
return true;
}
else if (mode & COMPLETE_SCRIPTS && !DWB_COMPLETE_KEY(e)) {
return dwb.state.script_comp_readonly;
}
else if (e->keyval == GDK_KEY_BackSpace && !complete) {
return false;
}
else if (mode == HINT_MODE) {
return dwb_update_hints(e);
}
else if (mode == SEARCH_FIELD_MODE) {
if (DWB_TAB_KEY(e)) {
dwb_update_hints(e);
return true;
}
else if (e->keyval == GDK_KEY_Return) {
return false;
}
}
else if (!e->is_modifier && complete) {
if (DWB_TAB_KEY(e)) {
completion_complete_path(e->state & GDK_SHIFT_MASK);
return true;
}
else {
completion_clean_path_completion();
}
}
else if (mode & COMPLETION_MODE && !DWB_COMPLETE_KEY(e) && !e->is_modifier && !CLEAN_STATE(e)) {
completion_clean_completion(set_text);
}
else if (mode == FIND_MODE) {
return false;
}
else if (DWB_COMPLETE_KEY(e)) {
completion_complete(dwb_eval_completion_type(), e->state & GDK_SHIFT_MASK || e->keyval == GDK_KEY_Up);
return true;
}
if (dwb_eval_override_key(e, CP_OVERRIDE_ENTRY)) {
ret = true;
}
return ret;
}/*}}}*/
/* dwb_delete_event_cb {{{*/
gboolean
callback_delete_event(GtkWidget *w) {
dwb_end();
return true;
}/*}}}*/
/* dwb_key_press_cb(GtkWidget *w, GdkEventKey *e, View *v) {{{*/
gboolean
callback_key_press(GtkWidget *w, GdkEventKey *e) {
gboolean ret = false;
Mode mode = CLEAN_MODE(dwb.state.mode);
if (EMIT_SCRIPT(KEY_PRESS)) {
char *json = util_create_json(5, UINTEGER, "state", e->state,
UINTEGER, "keyVal", e->keyval, UINTEGER, "keyCode", e->hardware_keycode,
BOOLEAN, "isModifier", e->is_modifier, CHAR, "name", gdk_keyval_name(e->keyval));
ScriptSignal signal = { SCRIPTS_WV(dwb.state.fview), SCRIPTS_SIG_META(json, KEY_PRESS, 0) };
SCRIPTS_EMIT_RETURN(signal, json);
}
if (e->keyval == GDK_KEY_Escape) {
if (dwb.state.mode & COMPLETION_MODE) {
completion_clean_completion(true);
}
else
dwb_change_mode(NORMAL_MODE, true);
ret = false;
}
else if (dwb_eval_override_key(e, CP_OVERRIDE_ALL))
ret = true;
else if (mode & INSERT_MODE) {
ret = dwb_eval_override_key(e, CP_OVERRIDE_INSERT);
}
else if (gtk_widget_has_focus(dwb.gui.entry) || mode & COMPLETION_MODE) {
ret = false;
}
else if (webkit_web_view_has_selection(CURRENT_WEBVIEW()) && e->keyval == GDK_KEY_Return) {
dwb_follow_selection();
}
else if (dwb.state.mode & AUTO_COMPLETE && DWB_TAB_KEY(e)) {
completion_autocomplete(dwb.keymap, e);
ret = true;
}
else {
if (mode & AUTO_COMPLETE) {
if (DWB_TAB_KEY(e)) {
completion_autocomplete(NULL, e);
}
else if (e->keyval == GDK_KEY_Return) {
completion_eval_autocompletion();
return true;
}
}
ret = dwb_eval_key(e);
}
return ret;
}/*}}}*/
/* dwb_key_release_cb {{{*/
gboolean
callback_key_release(GtkWidget *w, GdkEventKey *e) {
if (EMIT_SCRIPT(KEY_RELEASE)) {
char *json = util_create_json(5, UINTEGER, "state", e->state,
UINTEGER, "keyVal", e->keyval, UINTEGER, "keyCode", e->hardware_keycode,
BOOLEAN, "isModifier", e->is_modifier, CHAR, "name", gdk_keyval_name(e->keyval));
ScriptSignal signal = { SCRIPTS_WV(dwb.state.fview), SCRIPTS_SIG_META(json, KEY_RELEASE, 0) };
SCRIPTS_EMIT_RETURN(signal, json);
}
//SCRIPTS_EMIT_RETURN(SCRIPT(dwb.state.fview), KEY_RELEASE, 5, UINTEGER, "state", e->state,
// UINTEGER, "keyVal", e->keyval, UINTEGER, "keyCode", e->hardware_keycode,
// BOOLEAN, "isModifier", e->is_modifier, CHAR, "name", gdk_keyval_name(e->keyval));
if (DWB_TAB_KEY(e)) {
return true;
}
return false;
}/*}}}*/
#ifdef WITH_LIBSOUP_2_38
void
callback_dns_resolve(SoupAddress *address, guint status, GList *gl) {
char *uri = NULL;
View *v = VIEW(gl);
if (status == SOUP_STATUS_OK)
uri = g_strconcat("http://", v->status->request_uri, NULL);
else
uri = dwb_get_searchengine(v->status->request_uri);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(v->web), uri);
g_free(uri);
g_free(v->status->request_uri);
v->status->request_uri = NULL;
}
#endif
|