imported irssi.
[silc.git] / apps / irssi / src / fe-text / gui-readline.c
1 /*
2  gui-readline.c : irssi
3
4     Copyright (C) 1999 Timo Sirainen
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "module.h"
22 #include "signals.h"
23 #include "misc.h"
24 #include "settings.h"
25 #include "special-vars.h"
26
27 #include "completion.h"
28 #include "command-history.h"
29 #include "keyboard.h"
30 #include "translation.h"
31
32 #include "screen.h"
33 #include "gui-entry.h"
34 #include "gui-windows.h"
35
36 #include <signal.h>
37
38 typedef void (*ENTRY_REDIRECT_KEY_FUNC) (int key, void *data, SERVER_REC *server, WI_ITEM_REC *item);
39 typedef void (*ENTRY_REDIRECT_ENTRY_FUNC) (const char *line, void *data, SERVER_REC *server, WI_ITEM_REC *item);
40
41 typedef struct {
42         SIGNAL_FUNC func;
43         int flags;
44         void *data;
45 } ENTRY_REDIRECT_REC;
46
47 static KEYBOARD_REC *keyboard;
48 static ENTRY_REDIRECT_REC *redir;
49
50 char *cutbuffer;
51 static int readtag;
52 static time_t idle_time;
53
54 static void handle_key_redirect(int key)
55 {
56         ENTRY_REDIRECT_KEY_FUNC func;
57         void *data;
58
59         func = (ENTRY_REDIRECT_KEY_FUNC) redir->func;
60         data = redir->data;
61         g_free_and_null(redir);
62
63         if (func != NULL)
64                 func(key, data, active_win->active_server, active_win->active);
65
66         gui_entry_remove_perm_prompt();
67         window_update_prompt();
68 }
69
70 static void handle_entry_redirect(const char *line)
71 {
72         ENTRY_REDIRECT_ENTRY_FUNC func;
73         void *data;
74
75         gui_entry_set_hidden(FALSE);
76
77         func = (ENTRY_REDIRECT_ENTRY_FUNC) redir->func;
78         data = redir->data;
79         g_free_and_null(redir);
80
81         if (func != NULL) {
82                 func(line, data, active_win->active_server,
83                      active_win->active);
84         }
85
86         gui_entry_remove_perm_prompt();
87         window_update_prompt();
88 }
89
90 static int get_scroll_count(void)
91 {
92         const char *str;
93         double count;
94
95         str = settings_get_str("scroll_page_count");
96         count = atof(str + (*str == '/'));
97         if (count <= 0)
98                 count = 1;
99         else if (count < 1)
100                 count = 1.0/count;
101
102         if (*str == '/')
103                 count = WINDOW_GUI(active_win)->parent->height/count;
104         return (int)count;
105 }
106
107 static void window_prev_page(void)
108 {
109         gui_window_scroll(active_win, -get_scroll_count());
110 }
111
112 static void window_next_page(void)
113 {
114         gui_window_scroll(active_win, get_scroll_count());
115 }
116
117 void handle_key(int key)
118 {
119         char str[3];
120
121         idle_time = time(NULL);
122
123         if (redir != NULL && redir->flags & ENTRY_REDIRECT_FLAG_HOTKEY) {
124                 handle_key_redirect(key);
125                 return;
126         }
127
128         if (key >= 0 && key < 32) {
129                 /* control key */
130                 str[0] = '^';
131                 str[1] = key+'@';
132                 str[2] = '\0';
133         } else if (key == 127) {
134                 str[0] = '^';
135                 str[1] = '?';
136                 str[2] = '\0';
137         } else {
138                 str[0] = key;
139                 str[1] = '\0';
140         }
141
142         if (!key_pressed(keyboard, str)) {
143                 /* key wasn't used for anything, print it */
144                 gui_entry_insert_char((char) key);
145         }
146 }
147
148 static void key_send_line(void)
149 {
150         int add_history;
151         char *str;
152
153         str = gui_entry_get_text();
154         if (*str == '\0') return;
155
156         translate_output(str);
157
158         add_history = TRUE;
159         if (redir == NULL) {
160                 signal_emit("send command", 3, str,
161                             active_win->active_server,
162                             active_win->active);
163         } else {
164                 if (redir->flags & ENTRY_REDIRECT_FLAG_HIDDEN)
165                         add_history = FALSE;
166                 handle_entry_redirect(str);
167         }
168
169         if (add_history) {
170                 command_history_add(active_win, gui_entry_get_text(),
171                                     FALSE);
172         }
173         gui_entry_set_text("");
174         command_history_clear_pos(active_win);
175 }
176
177 static void key_combo(void)
178 {
179 }
180
181 static void key_backward_history(void)
182 {
183         const char *text;
184
185         text = command_history_prev(active_win, gui_entry_get_text());
186         gui_entry_set_text(text);
187 }
188
189 static void key_forward_history(void)
190 {
191         const char *text;
192
193         text = command_history_next(active_win, gui_entry_get_text());
194         gui_entry_set_text(text);
195 }
196
197 static void key_beginning_of_line(void)
198 {
199         gui_entry_set_pos(0);
200 }
201
202 static void key_end_of_line(void)
203 {
204         gui_entry_set_pos(strlen(gui_entry_get_text()));
205 }
206
207 static void key_backward_character(void)
208 {
209         gui_entry_move_pos(-1);
210 }
211
212 static void key_forward_character(void)
213 {
214         gui_entry_move_pos(1);
215 }
216
217 static void key_backward_word(void)
218 {
219         gui_entry_move_words(-1);
220 }
221
222 static void key_forward_word(void)
223 {
224         gui_entry_move_words(1);
225 }
226
227 static void key_erase_line(void)
228 {
229         g_free_not_null(cutbuffer);
230         cutbuffer = g_strdup(gui_entry_get_text());
231
232         gui_entry_set_text("");
233 }
234
235 static void key_erase_to_beg_of_line(void)
236 {
237         int pos;
238
239         pos = gui_entry_get_pos();
240         g_free_not_null(cutbuffer);
241         cutbuffer = g_strndup(gui_entry_get_text(), pos);
242
243         gui_entry_erase(pos);
244 }
245
246 static void key_erase_to_end_of_line(void)
247 {
248         int pos;
249
250         pos = gui_entry_get_pos();
251         g_free_not_null(cutbuffer);
252         cutbuffer = g_strdup(gui_entry_get_text()+pos);
253
254         gui_entry_set_pos(strlen(gui_entry_get_text()));
255         gui_entry_erase(strlen(gui_entry_get_text()) - pos);
256 }
257
258 static void key_yank_from_cutbuffer(void)
259 {
260         if (cutbuffer != NULL)
261                 gui_entry_insert_text(cutbuffer);
262 }
263
264 static void key_transpose_characters(void)
265 {
266         char *line, c;
267         int pos;
268
269         pos = gui_entry_get_pos();
270         line = gui_entry_get_text();
271         if (pos == 0 || strlen(line) < 2)
272                 return;
273
274         if (line[pos] != '\0')
275                 gui_entry_move_pos(1);
276         c = line[gui_entry_get_pos()-1];
277         gui_entry_erase(1);
278         gui_entry_move_pos(-1);
279         gui_entry_insert_char(c);
280         gui_entry_set_pos(pos);
281 }
282
283 static void key_delete_character(void)
284 {
285         if (gui_entry_get_pos() < (int)strlen(gui_entry_get_text())) {
286                 gui_entry_move_pos(1);
287                 gui_entry_erase(1);
288         }
289 }
290
291 static void key_backspace(void)
292 {
293         gui_entry_erase(1);
294 }
295
296 static void key_delete_previous_word(void)
297 {
298   gui_entry_erase_word();
299 }
300
301 static void key_delete_next_word(void)
302 {
303         gui_entry_erase_next_word();
304 }
305
306 static void key_delete_to_previous_space(void)
307 {
308         gui_entry_erase_word();
309 }
310
311 void readline(void)
312 {
313         int key;
314
315         for (;;) {
316                 key = getch();
317                 if (key == ERR
318 #ifdef KEY_RESIZE
319                     || key == KEY_RESIZE
320 #endif
321                    ) break;
322
323                 handle_key(key);
324         }
325 }
326
327 time_t get_idle_time(void)
328 {
329         return idle_time;
330 }
331
332 static void key_scroll_backward(void)
333 {
334         window_prev_page();
335 }
336
337 static void key_scroll_forward(void)
338 {
339         window_next_page();
340 }
341
342 static void key_scroll_start(void)
343 {
344         signal_emit("command scrollback home", 3, NULL, active_win->active_server, active_win->active);
345 }
346
347 static void key_scroll_end(void)
348 {
349         signal_emit("command scrollback end", 3, NULL, active_win->active_server, active_win->active);
350 }
351
352 static void key_change_window(const char *data)
353 {
354         signal_emit("command window goto", 3, data, active_win->active_server, active_win->active);
355 }
356
357 static void key_word_completion(void)
358 {
359         char *line;
360         int pos;
361
362         pos = gui_entry_get_pos();
363
364         line = word_complete(active_win, gui_entry_get_text(), &pos);
365         if (line != NULL) {
366                 gui_entry_set_text(line);
367                 gui_entry_set_pos(pos);
368                 g_free(line);
369         }
370 }
371
372 static void key_check_replaces(void)
373 {
374         char *line;
375         int pos;
376
377         pos = gui_entry_get_pos();
378
379         line = auto_word_complete(gui_entry_get_text(), &pos);
380         if (line != NULL) {
381                 gui_entry_set_text(line);
382                 gui_entry_set_pos(pos);
383                 g_free(line);
384         }
385 }
386
387 static void key_previous_window(void)
388 {
389         signal_emit("command window previous", 3, "", active_win->active_server, active_win->active);
390 }
391
392 static void key_next_window(void)
393 {
394         signal_emit("command window next", 3, "", active_win->active_server, active_win->active);
395 }
396
397 static void key_left_window(void)
398 {
399         signal_emit("command window left", 3, "", active_win->active_server, active_win->active);
400 }
401
402 static void key_right_window(void)
403 {
404         signal_emit("command window right", 3, "", active_win->active_server, active_win->active);
405 }
406
407 static void key_upper_window(void)
408 {
409         signal_emit("command window up", 3, "", active_win->active_server, active_win->active);
410 }
411
412 static void key_lower_window(void)
413 {
414         signal_emit("command window down", 3, "", active_win->active_server, active_win->active);
415 }
416
417 static void key_active_window(void)
418 {
419         signal_emit("command window goto", 3, "active", active_win->active_server, active_win->active);
420 }
421
422 static void key_previous_window_item(void)
423 {
424         SERVER_REC *server;
425         GSList *pos;
426
427         if (active_win->items != NULL)
428                 signal_emit("command window item prev", 3, "", active_win->active_server, active_win->active);
429         else if (servers != NULL) {
430                 /* change server */
431                 if (active_win->active_server == NULL)
432                         server = servers->data;
433                 else {
434                         pos = g_slist_find(servers, active_win->active_server);
435                         server = pos->next != NULL ? pos->next->data : servers->data;
436                 }
437                 signal_emit("command window server", 3, server->tag, active_win->active_server, active_win->active);
438         }
439 }
440
441 static void key_next_window_item(void)
442 {
443         SERVER_REC *server;
444         int index;
445
446         if (active_win->items != NULL) {
447                 signal_emit("command window item next", 3, "",
448                             active_win->active_server, active_win->active);
449         }
450         else if (servers != NULL) {
451                 /* change server */
452                 if (active_win->active_server == NULL)
453                         server = servers->data;
454                 else {
455                         index = g_slist_index(servers, active_win->active_server);
456                         server = index > 0 ? g_slist_nth(servers, index-1)->data :
457                                 g_slist_last(servers)->data;
458                 }
459                 signal_emit("command window server", 3, server->tag,
460                             active_win->active_server, active_win->active);
461         }
462 }
463
464 static void key_insert_text(const char *data)
465 {
466         char *str;
467
468         str = parse_special_string(data, active_win->active_server,
469                                    active_win->active, "", NULL, 0);
470         gui_entry_insert_text(str);
471         g_free(str);
472 }
473
474 static void sig_window_auto_changed(void)
475 {
476         command_history_next(active_win, gui_entry_get_text());
477         gui_entry_set_text("");
478 }
479
480 static void sig_gui_entry_redirect(SIGNAL_FUNC func, const char *entry,
481                                    void *flags, void *data)
482 {
483         redir = g_new0(ENTRY_REDIRECT_REC, 1);
484         redir->func = func;
485         redir->flags = GPOINTER_TO_INT(flags);
486         redir->data = data;
487
488         if (redir->flags & ENTRY_REDIRECT_FLAG_HIDDEN)
489                 gui_entry_set_hidden(TRUE);
490         gui_entry_set_perm_prompt(entry);
491 }
492
493 void gui_readline_init(void)
494 {
495         static char changekeys[] = "1234567890qwertyuio";
496         char *key, data[MAX_INT_STRLEN];
497         int n;
498
499         cutbuffer = NULL;
500         redir = NULL;
501         idle_time = time(NULL);
502         readtag = g_input_add_full(g_io_channel_unix_new(0),
503                                    G_PRIORITY_HIGH, G_INPUT_READ,
504                                    (GInputFunction) readline, NULL);
505
506         settings_add_str("history", "scroll_page_count", "/2");
507
508         keyboard = keyboard_create(NULL);
509         key_configure_freeze();
510
511         key_bind("key", NULL, "^M", "return", (SIGNAL_FUNC) key_combo);
512         key_bind("key", NULL, "^J", "return", (SIGNAL_FUNC) key_combo);
513
514         /* meta */
515         key_bind("key", NULL, "^[", "meta", (SIGNAL_FUNC) key_combo);
516         key_bind("key", NULL, "meta-[", "meta2", (SIGNAL_FUNC) key_combo);
517         key_bind("key", NULL, "meta-O", "meta2", (SIGNAL_FUNC) key_combo);
518         key_bind("key", NULL, "meta-[O", "meta2", (SIGNAL_FUNC) key_combo);
519
520         /* arrow keys */
521         key_bind("key", NULL, "meta2-A", "up", (SIGNAL_FUNC) key_combo);
522         key_bind("key", NULL, "meta2-B", "down", (SIGNAL_FUNC) key_combo);
523         key_bind("key", NULL, "meta2-C", "right", (SIGNAL_FUNC) key_combo);
524         key_bind("key", NULL, "meta2-D", "left", (SIGNAL_FUNC) key_combo);
525
526         key_bind("key", NULL, "meta2-1~", "home", (SIGNAL_FUNC) key_combo);
527         key_bind("key", NULL, "meta2-7~", "home", (SIGNAL_FUNC) key_combo);
528         key_bind("key", NULL, "meta2-H", "home", (SIGNAL_FUNC) key_combo);
529
530         key_bind("key", NULL, "meta2-4~", "end", (SIGNAL_FUNC) key_combo);
531         key_bind("key", NULL, "meta2-8~", "end", (SIGNAL_FUNC) key_combo);
532         key_bind("key", NULL, "meta2-F", "end", (SIGNAL_FUNC) key_combo);
533
534         key_bind("key", NULL, "meta2-5~", "prior", (SIGNAL_FUNC) key_combo);
535         key_bind("key", NULL, "meta2-I", "prior", (SIGNAL_FUNC) key_combo);
536         key_bind("key", NULL, "meta2-6~", "next", (SIGNAL_FUNC) key_combo);
537         key_bind("key", NULL, "meta2-G", "next", (SIGNAL_FUNC) key_combo);
538
539         key_bind("key", NULL, "meta2-2~", "insert", (SIGNAL_FUNC) key_combo);
540         key_bind("key", NULL, "meta2-3~", "delete", (SIGNAL_FUNC) key_combo);
541
542         /* cursor movement */
543         key_bind("backward_character", "", "left", NULL, (SIGNAL_FUNC) key_backward_character);
544         key_bind("forward_character", "", "right", NULL, (SIGNAL_FUNC) key_forward_character);
545         key_bind("backward_word", "", "meta2-d", NULL, (SIGNAL_FUNC) key_backward_word);
546         key_bind("forward_word", "", "meta2-c", NULL, (SIGNAL_FUNC) key_forward_word);
547         key_bind("beginning_of_line", "", "home", NULL, (SIGNAL_FUNC) key_beginning_of_line);
548         key_bind("beginning_of_line", NULL, "^A", NULL, (SIGNAL_FUNC) key_beginning_of_line);
549         key_bind("end_of_line", "", "end", NULL, (SIGNAL_FUNC) key_end_of_line);
550         key_bind("end_of_line", NULL, "^E", NULL, (SIGNAL_FUNC) key_end_of_line);
551
552         /* history */
553         key_bind("backward_history", "", "up", NULL, (SIGNAL_FUNC) key_backward_history);
554         key_bind("forward_history", "", "down", NULL, (SIGNAL_FUNC) key_forward_history);
555
556         /* line editing */
557         key_bind("backspace", "", "^H", NULL, (SIGNAL_FUNC) key_backspace);
558         key_bind("backspace", "", "^?", NULL, (SIGNAL_FUNC) key_backspace);
559         key_bind("delete_character", "", "delete", NULL, (SIGNAL_FUNC) key_delete_character);
560         key_bind("delete_character", NULL, "^D", NULL, (SIGNAL_FUNC) key_delete_character);
561         key_bind("delete_next_word", "", NULL, NULL, (SIGNAL_FUNC) key_delete_next_word);
562         key_bind("delete_previous_word", "", NULL, NULL, (SIGNAL_FUNC) key_delete_previous_word);
563         key_bind("delete_to_previous_space", "", "^W", NULL, (SIGNAL_FUNC) key_delete_to_previous_space);
564         key_bind("erase_line", "", "^U", NULL, (SIGNAL_FUNC) key_erase_line);
565         key_bind("erase_to_beg_of_line", "", NULL, NULL, (SIGNAL_FUNC) key_erase_to_beg_of_line);
566         key_bind("erase_to_end_of_line", "", "^K", NULL, (SIGNAL_FUNC) key_erase_to_end_of_line);
567         key_bind("yank_from_cutbuffer", "", "^Y", NULL, (SIGNAL_FUNC) key_yank_from_cutbuffer);
568         key_bind("transpose_characters", "Swap current and previous character", "^T", NULL, (SIGNAL_FUNC) key_transpose_characters);
569
570         /* line transmitting */
571         key_bind("send_line", "Execute the input line", "return", NULL, (SIGNAL_FUNC) key_send_line);
572         key_bind("word_completion", "", "^I", NULL, (SIGNAL_FUNC) key_word_completion);
573         key_bind("check_replaces", "Check word replaces", " ", NULL, (SIGNAL_FUNC) key_check_replaces);
574         key_bind("check_replaces", NULL, NULL, NULL, (SIGNAL_FUNC) key_check_replaces);
575
576         /* window managing */
577         key_bind("previous_window", "Previous window", "^P", NULL, (SIGNAL_FUNC) key_previous_window);
578         key_bind("left_window", "Window in left", "meta-left", NULL, (SIGNAL_FUNC) key_left_window);
579         key_bind("next_window", "Next window", "^N", NULL, (SIGNAL_FUNC) key_next_window);
580         key_bind("right_window", "Window in right", "meta-right", NULL, (SIGNAL_FUNC) key_right_window);
581         key_bind("upper_window", "Upper window", "meta-up", NULL, (SIGNAL_FUNC) key_upper_window);
582         key_bind("lower_window", "Lower window", "meta-down", NULL, (SIGNAL_FUNC) key_lower_window);
583         key_bind("active_window", "Go to next window with the highest activity", "meta-a", NULL, (SIGNAL_FUNC) key_active_window);
584         key_bind("next_window_item", "Next channel/query", "^X", NULL, (SIGNAL_FUNC) key_next_window_item);
585         key_bind("previous_window_item", "Previous channel/query", NULL, NULL, (SIGNAL_FUNC) key_previous_window_item);
586
587         key_bind("refresh_screen", "Redraw screen", "^L", NULL, (SIGNAL_FUNC) irssi_redraw);
588         key_bind("scroll_backward", "Previous page", "prior", NULL, (SIGNAL_FUNC) key_scroll_backward);
589         key_bind("scroll_backward", NULL, "meta-p", NULL, (SIGNAL_FUNC) key_scroll_backward);
590         key_bind("scroll_forward", "Next page", "next", NULL, (SIGNAL_FUNC) key_scroll_forward);
591         key_bind("scroll_forward", NULL, "meta-n", NULL, (SIGNAL_FUNC) key_scroll_forward);
592         key_bind("scroll_start", "Beginning of the window", "", NULL, (SIGNAL_FUNC) key_scroll_start);
593         key_bind("scroll_end", "End of the window", "", NULL, (SIGNAL_FUNC) key_scroll_end);
594
595         /* inserting special input characters to line.. */
596         key_bind("insert_text", "Append text to line", NULL, NULL, (SIGNAL_FUNC) key_insert_text);
597
598         key_bind("multi", NULL, "return", "check_replaces;send_line", NULL);
599
600         for (n = 0; changekeys[n] != '\0'; n++) {
601                 key = g_strdup_printf("meta-%c", changekeys[n]);
602                 ltoa(data, n+1);
603                 key_bind("change_window", "Change window", key, data, (SIGNAL_FUNC) key_change_window);
604                 g_free(key);
605         }
606
607         key_configure_thaw();
608
609         signal_add("window changed automatic", (SIGNAL_FUNC) sig_window_auto_changed);
610         signal_add("gui entry redirect", (SIGNAL_FUNC) sig_gui_entry_redirect);
611 }
612
613 void gui_readline_deinit(void)
614 {
615         g_free_not_null(cutbuffer);
616         g_source_remove(readtag);
617
618         key_configure_freeze();
619
620         key_unbind("backward_character", (SIGNAL_FUNC) key_backward_character);
621         key_unbind("forward_character", (SIGNAL_FUNC) key_forward_character);
622         key_unbind("backward_word", (SIGNAL_FUNC) key_backward_word);
623         key_unbind("forward_word", (SIGNAL_FUNC) key_forward_word);
624         key_unbind("beginning_of_line", (SIGNAL_FUNC) key_beginning_of_line);
625         key_unbind("end_of_line", (SIGNAL_FUNC) key_end_of_line);
626
627         key_unbind("backward_history", (SIGNAL_FUNC) key_backward_history);
628         key_unbind("forward_history", (SIGNAL_FUNC) key_forward_history);
629
630         key_unbind("backspace", (SIGNAL_FUNC) key_backspace);
631         key_unbind("delete_character", (SIGNAL_FUNC) key_delete_character);
632         key_unbind("delete_next_word", (SIGNAL_FUNC) key_delete_next_word);
633         key_unbind("delete_previous_word", (SIGNAL_FUNC) key_delete_previous_word);
634         key_unbind("delete_to_previous_space", (SIGNAL_FUNC) key_delete_to_previous_space);
635         key_unbind("erase_line", (SIGNAL_FUNC) key_erase_line);
636         key_unbind("erase_to_beg_of_line", (SIGNAL_FUNC) key_erase_to_beg_of_line);
637         key_unbind("erase_to_end_of_line", (SIGNAL_FUNC) key_erase_to_end_of_line);
638         key_unbind("yank_from_cutbuffer", (SIGNAL_FUNC) key_yank_from_cutbuffer);
639         key_unbind("transpose_characters", (SIGNAL_FUNC) key_transpose_characters);
640
641         key_unbind("word_completion", (SIGNAL_FUNC) key_word_completion);
642         key_unbind("check_replaces", (SIGNAL_FUNC) key_check_replaces);
643
644         key_unbind("previous_window", (SIGNAL_FUNC) key_previous_window);
645         key_unbind("next_window", (SIGNAL_FUNC) key_next_window);
646         key_unbind("upper_window", (SIGNAL_FUNC) key_upper_window);
647         key_unbind("lower_window", (SIGNAL_FUNC) key_lower_window);
648         key_unbind("active_window", (SIGNAL_FUNC) key_active_window);
649         key_unbind("next_window_item", (SIGNAL_FUNC) key_next_window_item);
650         key_unbind("previous_window_item", (SIGNAL_FUNC) key_previous_window_item);
651
652         key_unbind("refresh_screen", (SIGNAL_FUNC) irssi_redraw);
653         key_unbind("scroll_backward", (SIGNAL_FUNC) key_scroll_backward);
654         key_unbind("scroll_forward", (SIGNAL_FUNC) key_scroll_forward);
655         key_unbind("scroll_start", (SIGNAL_FUNC) key_scroll_start);
656         key_unbind("scroll_end", (SIGNAL_FUNC) key_scroll_end);
657
658         key_unbind("insert_text", (SIGNAL_FUNC) key_insert_text);
659         key_unbind("change_window", (SIGNAL_FUNC) key_change_window);
660         keyboard_destroy(keyboard);
661
662         key_configure_thaw();
663
664         signal_remove("window changed automatic", (SIGNAL_FUNC) sig_window_auto_changed);
665         signal_remove("gui entry redirect", (SIGNAL_FUNC) sig_gui_entry_redirect);
666 }