Merged 0.7.99 irssi.
[crypto.git] / apps / irssi / src / fe-common / core / window-commands.c
1 /*
2  window-commands.c : irssi
3
4     Copyright (C) 2000 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 "module-formats.h"
23 #include "signals.h"
24 #include "commands.h"
25 #include "misc.h"
26 #include "servers.h"
27
28 #include "levels.h"
29
30 #include "themes.h"
31 #include "fe-windows.h"
32 #include "window-items.h"
33 #include "windows-layout.h"
34 #include "printtext.h"
35
36 static void window_print_binds(WINDOW_REC *win)
37 {
38         GSList *tmp;
39
40         printformat_window(win, MSGLEVEL_CLIENTCRAP,
41                            TXT_WINDOW_INFO_BOUND_ITEMS_HEADER);
42         for (tmp = win->bound_items; tmp != NULL; tmp = tmp->next) {
43                 WINDOW_BIND_REC *bind = tmp->data;
44
45                 printformat_window(win, MSGLEVEL_CLIENTCRAP,
46                                    TXT_WINDOW_INFO_BOUND_ITEM,
47                                    bind->name, bind->servertag,
48                                    bind->sticky ? "sticky" : "");
49         }
50         printformat_window(win, MSGLEVEL_CLIENTCRAP,
51                            TXT_WINDOW_INFO_BOUND_ITEMS_FOOTER);
52 }
53
54 static void window_print_items(WINDOW_REC *win)
55 {
56         GSList *tmp;
57         const char *type;
58
59         printformat_window(win, MSGLEVEL_CLIENTCRAP,
60                            TXT_WINDOW_INFO_ITEMS_HEADER);
61         for (tmp = win->items; tmp != NULL; tmp = tmp->next) {
62                 WI_ITEM_REC *item = tmp->data;
63
64                 type = module_find_id_str("WINDOW ITEM TYPE", item->type);
65                 printformat_window(win, MSGLEVEL_CLIENTCRAP,
66                                    TXT_WINDOW_INFO_ITEM,
67                                    type == NULL ? "??" : type, item->name,
68                                    item->server == NULL ? "" :
69                                    item->server->tag);
70         }
71         printformat_window(win, MSGLEVEL_CLIENTCRAP,
72                            TXT_WINDOW_INFO_ITEMS_FOOTER);
73 }
74
75 static void cmd_window_info(WINDOW_REC *win)
76 {
77         char *levelstr;
78
79         printformat_window(win, MSGLEVEL_CLIENTCRAP,
80                            TXT_WINDOW_INFO_HEADER);
81
82         /* Window reference number + sticky status */
83         if (!win->sticky_refnum) {
84                 printformat_window(win, MSGLEVEL_CLIENTCRAP,
85                                    TXT_WINDOW_INFO_REFNUM, win->refnum);
86         } else {
87                 printformat_window(win, MSGLEVEL_CLIENTCRAP,
88                                    TXT_WINDOW_INFO_REFNUM_STICKY, win->refnum);
89         }
90
91         /* Window name */
92         if (win->name != NULL) {
93                 printformat_window(win, MSGLEVEL_CLIENTCRAP,
94                                    TXT_WINDOW_INFO_NAME, win->name);
95         }
96
97         /* Window history name */
98         if (win->history_name != NULL) {
99                 printformat_window(win, MSGLEVEL_CLIENTCRAP,
100                                    TXT_WINDOW_INFO_HISTORY, win->history_name);
101         }
102
103         /* Window width / height */
104         printformat_window(win, MSGLEVEL_CLIENTCRAP, TXT_WINDOW_INFO_SIZE,
105                            win->width, win->height);
106
107         /* Window level */
108         levelstr = win->level == 0 ?
109                 g_strdup("NONE") : bits2level(win->level);
110         printformat_window(win, MSGLEVEL_CLIENTCRAP, TXT_WINDOW_INFO_LEVEL,
111                            levelstr);
112         g_free(levelstr);
113
114         /* Active window server + sticky status */
115         if (win->servertag == NULL) {
116                 printformat_window(win, MSGLEVEL_CLIENTCRAP,
117                                    TXT_WINDOW_INFO_SERVER,
118                                    win->active_server != NULL ?
119                                    win->active_server->tag : "NONE");
120         } else {
121                 if (win->active_server != NULL &&
122                     strcmp(win->active_server->tag, win->servertag) != 0)
123                         g_warning("Active server isn't the sticky server!");
124
125                 printformat_window(win, MSGLEVEL_CLIENTCRAP,
126                                    TXT_WINDOW_INFO_SERVER_STICKY,
127                                    win->servertag);
128         }
129
130         /* Window theme + error status */
131         if (win->theme_name != NULL) {
132                 printformat_window(win, MSGLEVEL_CLIENTCRAP,
133                                    TXT_WINDOW_INFO_THEME, win->theme_name,
134                                    win->theme != NULL ? "" : "(not loaded)");
135         }
136
137         /* Bound items in window */
138         if (win->bound_items != NULL)
139                 window_print_binds(win);
140
141         /* Item */
142         if (win->items != NULL)
143                 window_print_items(win);
144
145         signal_emit("window print info", 1, win);
146
147         printformat_window(win, MSGLEVEL_CLIENTCRAP,
148                            TXT_WINDOW_INFO_FOOTER);
149 }
150
151 static void cmd_window(const char *data, void *server, WI_ITEM_REC *item)
152 {
153         while (*data == ' ') data++;
154
155         if (*data == '\0')
156                 cmd_window_info(active_win);
157         else if (is_numeric(data, 0))
158                 signal_emit("command window refnum", 3, data, server, item);
159         else
160                 command_runsub("window", data, server, item);
161 }
162
163 /* SYNTAX: WINDOW NEW [hide] */
164 static void cmd_window_new(const char *data, void *server, WI_ITEM_REC *item)
165 {
166         WINDOW_REC *window;
167         int type;
168
169         g_return_if_fail(data != NULL);
170
171         type = (g_strncasecmp(data, "hid", 3) == 0 || g_strcasecmp(data, "tab") == 0) ? 1 :
172                 (g_strcasecmp(data, "split") == 0 ? 2 : 0);
173         signal_emit("gui window create override", 1, GINT_TO_POINTER(type));
174
175         window = window_create(NULL, FALSE);
176         window_change_server(window, server);
177 }
178
179 /* SYNTAX: WINDOW CLOSE [<first> [<last>] */
180 static void cmd_window_close(const char *data)
181 {
182         GSList *tmp, *destroys;
183         char *first, *last;
184         int first_num, last_num;
185         void *free_arg;
186
187         if (!cmd_get_params(data, &free_arg, 2, &first, &last))
188                 return;
189
190         if ((*first != '\0' && !is_numeric(first, '\0')) ||
191             ((*last != '\0') && !is_numeric(last, '\0'))) {
192                 cmd_params_free(free_arg);
193                 return;
194         }
195
196         first_num = *first == '\0' ? active_win->refnum : atoi(first);
197         last_num = *last == '\0' ? first_num : atoi(last);
198
199         /* get list of windows to destroy */
200         destroys = NULL;
201         for (tmp = windows; tmp != NULL; tmp = tmp->next) {
202                 WINDOW_REC *rec = tmp->data;
203
204                 if (rec->refnum >= first_num && rec->refnum <= last_num)
205                         destroys = g_slist_append(destroys, rec);
206         }
207
208         /* really destroy the windows */
209         while (destroys != NULL) {
210                 WINDOW_REC *rec = destroys->data;
211
212                 if (windows->next != NULL)
213                         window_destroy(rec);
214
215                 destroys = g_slist_remove(destroys, rec);
216         }
217
218         cmd_params_free(free_arg);
219 }
220
221 /* SYNTAX: WINDOW REFNUM <number> */
222 static void cmd_window_refnum(const char *data)
223 {
224         WINDOW_REC *window;
225
226         if (!is_numeric(data, 0))
227                 return;
228
229         window = window_find_refnum(atoi(data));
230         if (window != NULL)
231                 window_set_active(window);
232 }
233
234 /* return the first window number with the highest activity */
235 static WINDOW_REC *window_highest_activity(WINDOW_REC *window)
236 {
237         WINDOW_REC *rec, *max_win;
238         GSList *tmp;
239         int max_act, through;
240
241         g_return_val_if_fail(window != NULL, NULL);
242
243         max_win = NULL; max_act = 0; through = FALSE;
244
245         tmp = g_slist_find(windows, window);
246         for (;; tmp = tmp->next) {
247                 if (tmp == NULL) {
248                         tmp = windows;
249                         through = TRUE;
250                 }
251
252                 if (through && tmp->data == window)
253                         break;
254
255                 rec = tmp->data;
256
257                 if (rec->data_level > 0 && max_act < rec->data_level) {
258                         max_act = rec->data_level;
259                         max_win = rec;
260                 }
261         }
262
263         return max_win;
264 }
265
266 /* SYNTAX: WINDOW GOTO active|<number>|<name> */
267 static void cmd_window_goto(const char *data)
268 {
269         WINDOW_REC *window;
270
271         g_return_if_fail(data != NULL);
272
273         if (is_numeric(data, 0)) {
274                 cmd_window_refnum(data);
275                 return;
276         }
277
278         if (g_strcasecmp(data, "active") == 0)
279                 window = window_highest_activity(active_win);
280         else
281                 window = window_find_item(active_win->active_server, data);
282
283         if (window != NULL)
284                 window_set_active(window);
285 }
286
287 /* SYNTAX: WINDOW NEXT */
288 static void cmd_window_next(void)
289 {
290         int num;
291
292         num = window_refnum_next(active_win->refnum, TRUE);
293         if (num < 1) num = windows_refnum_last();
294
295         window_set_active(window_find_refnum(num));
296 }
297
298 /* SYNTAX: WINDOW LAST */
299 static void cmd_window_last(void)
300 {
301         if (windows->next != NULL)
302                 window_set_active(windows->next->data);
303 }
304
305 /* SYNTAX: WINDOW PREVIOUS */
306 static void cmd_window_previous(void)
307 {
308         int num;
309
310         num = window_refnum_prev(active_win->refnum, TRUE);
311         if (num < 1) num = window_refnum_next(0, TRUE);
312
313         window_set_active(window_find_refnum(num));
314 }
315
316 /* SYNTAX: WINDOW LEVEL [<level>] */
317 static void cmd_window_level(const char *data)
318 {
319         char *level;
320
321         g_return_if_fail(data != NULL);
322
323         window_set_level(active_win, combine_level(active_win->level, data));
324
325         level = active_win->level == 0 ? g_strdup("NONE") :
326                 bits2level(active_win->level);
327         printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
328                            TXT_WINDOW_LEVEL, level);
329         g_free(level);
330 }
331
332 /* SYNTAX: WINDOW SERVER [-sticky | -unsticky] <tag> */
333 static void cmd_window_server(const char *data)
334 {
335         GHashTable *optlist;
336         SERVER_REC *server;
337         char *tag;
338         void *free_arg;
339
340         if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
341                             "window server", &optlist, &tag))
342                 return;
343
344         if (*tag == '\0' && active_win->active_server != NULL &&
345             (g_hash_table_lookup(optlist, "sticky") != NULL ||
346              g_hash_table_lookup(optlist, "unsticky") != NULL)) {
347                 tag = active_win->active_server->tag;
348         }
349
350         if (*tag == '\0')
351                 cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
352         server = server_find_tag(tag);
353
354         if (g_hash_table_lookup(optlist, "unsticky") != NULL &&
355             active_win->servertag != NULL) {
356                 g_free_and_null(active_win->servertag);
357                 printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
358                                    TXT_UNSET_SERVER_STICKY);
359         }
360
361         if (active_win->servertag != NULL &&
362             g_hash_table_lookup(optlist, "sticky") == NULL) {
363                 printformat_window(active_win, MSGLEVEL_CLIENTERROR,
364                                    TXT_ERROR_SERVER_STICKY);
365         } else if (server == NULL) {
366                 printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
367                                    TXT_UNKNOWN_SERVER_TAG, tag);
368         } else if (active_win->active == NULL) {
369                 window_change_server(active_win, server);
370                 if (g_hash_table_lookup(optlist, "sticky") != NULL) {
371                         g_free_not_null(active_win->servertag);
372                         active_win->servertag = g_strdup(server->tag);
373                         printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
374                                            TXT_SET_SERVER_STICKY, server->tag);
375                 }
376                 printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
377                                    TXT_SERVER_CHANGED,
378                                    server->tag, server->connrec->address,
379                                    server->connrec->chatnet == NULL ? "" :
380                                    server->connrec->chatnet);
381         }
382
383         cmd_params_free(free_arg);
384 }
385
386 static void cmd_window_item(const char *data, void *server, WI_ITEM_REC *item)
387 {
388         command_runsub("window item", data, server, item);
389 }
390
391 /* SYNTAX: WINDOW ITEM PREV */
392 static void cmd_window_item_prev(void)
393 {
394         window_item_prev(active_win);
395 }
396
397 /* SYNTAX: WINDOW ITEM NEXT */
398 static void cmd_window_item_next(void)
399 {
400         window_item_next(active_win);
401 }
402
403 /* SYNTAX: WINDOW ITEM GOTO <name> */
404 static void cmd_window_item_goto(const char *data, SERVER_REC *server)
405 {
406         WI_ITEM_REC *item;
407
408         item = window_item_find_window(active_win, server, data);
409         if (item != NULL)
410                 window_item_set_active(active_win, item);
411 }
412
413 /* SYNTAX: WINDOW ITEM MOVE <number>|<name> */
414 static void cmd_window_item_move(const char *data, SERVER_REC *server,
415                                  WI_ITEM_REC *item)
416 {
417         WINDOW_REC *window;
418         void *free_arg;
419         char *target;
420
421         if (!cmd_get_params(data, &free_arg, 1, &target))
422                 return;
423
424         if (is_numeric(target, '\0')) {
425                 /* move current window item to specified window */
426                 window = window_find_refnum(atoi(target));
427         } else {
428                 /* move specified window item to current window */
429                 item = window_item_find(server, target);
430                 window = active_win;
431         }
432         if (window != NULL && item != NULL)
433                 window_item_set_active(window, item);
434
435         cmd_params_free(free_arg);
436 }
437
438 /* SYNTAX: WINDOW NUMBER [-sticky] <number> */
439 static void cmd_window_number(const char *data)
440 {
441         GHashTable *optlist;
442         char *refnum;
443         void *free_arg;
444         int num;
445
446         if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
447                             "window number", &optlist, &refnum))
448                 return;
449
450         if (*refnum == '\0')
451                 cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
452
453         num = atoi(refnum);
454         if (num < 1) {
455                 printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
456                                    TXT_REFNUM_TOO_LOW);
457         } else {
458                 window_set_refnum(active_win, num);
459                 active_win->sticky_refnum =
460                         g_hash_table_lookup(optlist, "sticky") != NULL;
461         }
462
463         cmd_params_free(free_arg);
464 }
465
466 /* SYNTAX: WINDOW NAME <name> */
467 static void cmd_window_name(const char *data)
468 {
469         if (window_find_name(data) == NULL)
470                 window_set_name(active_win, data);
471         else {
472                 printformat_window(active_win, MSGLEVEL_CLIENTERROR,
473                                    TXT_WINDOW_NAME_NOT_UNIQUE, data);
474         }
475 }
476
477 /* SYNTAX: WINDOW HISTORY <name> */
478 void cmd_window_history(const char *data)
479 {
480         window_set_history(active_win, data);
481 }
482
483 /* we're moving the first window to last - move the first contiguous block
484    of refnums to left. Like if there's windows 1..5 and 7..10, move 1 to
485    11, 2..5 to 1..4 and leave 7..10 alone */
486 static void window_refnums_move_left(WINDOW_REC *move_window)
487 {
488         WINDOW_REC *window;
489         int refnum, new_refnum;
490
491         new_refnum = windows_refnum_last();
492         for (refnum = move_window->refnum+1; refnum <= new_refnum; refnum++) {
493                 window = window_find_refnum(refnum);
494                 if (window == NULL) {
495                         new_refnum++;
496                         break;
497                 }
498
499                 window_set_refnum(window, refnum-1);
500         }
501
502         window_set_refnum(move_window, new_refnum);
503 }
504
505 /* we're moving the last window to first - make some space so we can use the
506    refnum 1 */
507 static void window_refnums_move_right(WINDOW_REC *move_window)
508 {
509         WINDOW_REC *window;
510         int refnum, new_refnum;
511
512         new_refnum = 1;
513         if (window_find_refnum(new_refnum) == NULL) {
514                 window_set_refnum(move_window, new_refnum);
515                 return;
516         }
517
518         /* find the first unused refnum, like if there's windows
519            1..5 and 7..10, we only need to move 1..5 to 2..6 */
520         refnum = new_refnum;
521         while (move_window->refnum == refnum ||
522                window_find_refnum(refnum) != NULL) refnum++;
523         refnum--;
524
525         while (refnum >= new_refnum) {
526                 window = window_find_refnum(refnum);
527                 window_set_refnum(window, refnum+1);
528
529                 refnum--;
530         }
531
532         window_set_refnum(move_window, new_refnum);
533 }
534
535 /* SYNTAX: WINDOW MOVE PREV */
536 static void cmd_window_move_prev(void)
537 {
538         int refnum;
539
540         refnum = window_refnum_prev(active_win->refnum, FALSE);
541         if (refnum != -1) {
542                 window_set_refnum(active_win, refnum);
543                 return;
544         }
545
546         window_refnums_move_left(active_win);
547 }
548
549 /* SYNTAX: WINDOW MOVE NEXT */
550 static void cmd_window_move_next(void)
551 {
552         int refnum;
553
554         refnum = window_refnum_next(active_win->refnum, FALSE);
555         if (refnum != -1) {
556                 window_set_refnum(active_win, refnum);
557                 return;
558         }
559
560         window_refnums_move_right(active_win);
561 }
562
563 /* SYNTAX: WINDOW MOVE <number>|<direction> */
564 static void cmd_window_move(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
565 {
566         int new_refnum, refnum;
567
568         if (!is_numeric(data, 0)) {
569                 command_runsub("window move", data, server, item);
570                 return;
571         }
572
573         new_refnum = atoi(data);
574         if (new_refnum > active_win->refnum) {
575                 for (;;) {
576                         refnum = window_refnum_next(active_win->refnum, FALSE);
577                         if (refnum == -1 || refnum > new_refnum)
578                                 break;
579
580                         window_set_refnum(active_win, refnum);
581                 }
582         } else {
583                 for (;;) {
584                         refnum = window_refnum_prev(active_win->refnum, FALSE);
585                         if (refnum == -1 || refnum < new_refnum)
586                                 break;
587
588                         window_set_refnum(active_win, refnum);
589                 }
590         }
591 }
592
593 /* SYNTAX: WINDOW LIST */
594 static void cmd_window_list(void)
595 {
596         GSList *tmp, *sorted;
597         char *levelstr;
598
599         sorted = windows_get_sorted();
600         printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_WINDOWLIST_HEADER);
601         for (tmp = sorted; tmp != NULL; tmp = tmp->next) {
602                 WINDOW_REC *rec = tmp->data;
603
604                 levelstr = bits2level(rec->level);
605                 printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_WINDOWLIST_LINE,
606                             rec->refnum, rec->name == NULL ? "" : rec->name,
607                             rec->active == NULL ? "" : rec->active->name,
608                             rec->active_server == NULL ? "" : ((SERVER_REC *) rec->active_server)->tag,
609                             levelstr);
610                 g_free(levelstr);
611         }
612         g_slist_free(sorted);
613         printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_WINDOWLIST_FOOTER);
614 }
615
616 /* SYNTAX: WINDOW THEME [-delete] [<name>] */
617 static void cmd_window_theme(const char *data)
618 {
619         THEME_REC *theme;
620         GHashTable *optlist;
621         char *name;
622         void *free_arg;
623
624         if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
625                             "window theme", &optlist, &name))
626                 return;
627
628         if (g_hash_table_lookup(optlist, "delete") != NULL) {
629                 g_free_and_null(active_win->theme_name);
630
631                 printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
632                                    TXT_WINDOW_THEME_REMOVED);
633         } else if (*name == '\0') {
634                 if (active_win->theme == NULL) {
635                         printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
636                                            TXT_WINDOW_THEME_DEFAULT);
637                 } else {
638                         theme = active_win->theme;
639                         printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
640                                            TXT_WINDOW_THEME,
641                                            theme->name, theme->path);
642                 }
643         } else {
644                 g_free_not_null(active_win->theme_name);
645                 active_win->theme_name = g_strdup(data);
646
647                 active_win->theme = theme = theme_load(data);
648                 if (theme != NULL) {
649                         printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
650                                            TXT_WINDOW_THEME_CHANGED,
651                                            theme->name, theme->path);
652                 } else {
653                         printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
654                                            TXT_THEME_NOT_FOUND, data);
655                 }
656         }
657
658         cmd_params_free(free_arg);
659 }
660
661 static void cmd_layout(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
662 {
663         command_runsub("layout", data, server, item);
664 }
665
666 /* SYNTAX: FOREACH WINDOW <command> */
667 static void cmd_foreach_window(const char *data)
668 {
669         WINDOW_REC *old;
670         GSList *list;
671
672         old = active_win;
673
674         list = g_slist_copy(windows);
675         while (list != NULL) {
676                 WINDOW_REC *rec = list->data;
677
678                 active_win = rec;
679                 signal_emit("send command", 3, data, rec->active_server,
680                             rec->active);
681                 list = g_slist_remove(list, list->data);
682         }
683
684         active_win = old;
685 }
686
687 void window_commands_init(void)
688 {
689         command_bind("window", NULL, (SIGNAL_FUNC) cmd_window);
690         command_bind("window new", NULL, (SIGNAL_FUNC) cmd_window_new);
691         command_bind("window close", NULL, (SIGNAL_FUNC) cmd_window_close);
692         command_bind("window kill", NULL, (SIGNAL_FUNC) cmd_window_close);
693         command_bind("window server", NULL, (SIGNAL_FUNC) cmd_window_server);
694         command_bind("window refnum", NULL, (SIGNAL_FUNC) cmd_window_refnum);
695         command_bind("window goto", NULL, (SIGNAL_FUNC) cmd_window_goto);
696         command_bind("window previous", NULL, (SIGNAL_FUNC) cmd_window_previous);
697         command_bind("window next", NULL, (SIGNAL_FUNC) cmd_window_next);
698         command_bind("window last", NULL, (SIGNAL_FUNC) cmd_window_last);
699         command_bind("window level", NULL, (SIGNAL_FUNC) cmd_window_level);
700         command_bind("window item", NULL, (SIGNAL_FUNC) cmd_window_item);
701         command_bind("window item prev", NULL, (SIGNAL_FUNC) cmd_window_item_prev);
702         command_bind("window item next", NULL, (SIGNAL_FUNC) cmd_window_item_next);
703         command_bind("window item goto", NULL, (SIGNAL_FUNC) cmd_window_item_goto);
704         command_bind("window item move", NULL, (SIGNAL_FUNC) cmd_window_item_move);
705         command_bind("window number", NULL, (SIGNAL_FUNC) cmd_window_number);
706         command_bind("window name", NULL, (SIGNAL_FUNC) cmd_window_name);
707         command_bind("window history", NULL, (SIGNAL_FUNC) cmd_window_history);
708         command_bind("window move", NULL, (SIGNAL_FUNC) cmd_window_move);
709         command_bind("window move prev", NULL, (SIGNAL_FUNC) cmd_window_move_prev);
710         command_bind("window move next", NULL, (SIGNAL_FUNC) cmd_window_move_next);
711         command_bind("window list", NULL, (SIGNAL_FUNC) cmd_window_list);
712         command_bind("window theme", NULL, (SIGNAL_FUNC) cmd_window_theme);
713         command_bind("layout", NULL, (SIGNAL_FUNC) cmd_layout);
714         /* SYNTAX: LAYOUT SAVE */
715         command_bind("layout save", NULL, (SIGNAL_FUNC) windows_layout_save);
716         /* SYNTAX: LAYOUT RESET */
717         command_bind("layout reset", NULL, (SIGNAL_FUNC) windows_layout_reset);
718         command_bind("foreach window", NULL, (SIGNAL_FUNC) cmd_foreach_window);
719
720         command_set_options("window number", "sticky");
721         command_set_options("window server", "sticky unsticky");
722         command_set_options("window theme", "delete");
723 }
724
725 void window_commands_deinit(void)
726 {
727         command_unbind("window", (SIGNAL_FUNC) cmd_window);
728         command_unbind("window new", (SIGNAL_FUNC) cmd_window_new);
729         command_unbind("window close", (SIGNAL_FUNC) cmd_window_close);
730         command_unbind("window kill", (SIGNAL_FUNC) cmd_window_close);
731         command_unbind("window server", (SIGNAL_FUNC) cmd_window_server);
732         command_unbind("window refnum", (SIGNAL_FUNC) cmd_window_refnum);
733         command_unbind("window goto", (SIGNAL_FUNC) cmd_window_goto);
734         command_unbind("window previous", (SIGNAL_FUNC) cmd_window_previous);
735         command_unbind("window next", (SIGNAL_FUNC) cmd_window_next);
736         command_unbind("window last", (SIGNAL_FUNC) cmd_window_last);
737         command_unbind("window level", (SIGNAL_FUNC) cmd_window_level);
738         command_unbind("window item", (SIGNAL_FUNC) cmd_window_item);
739         command_unbind("window item prev", (SIGNAL_FUNC) cmd_window_item_prev);
740         command_unbind("window item next", (SIGNAL_FUNC) cmd_window_item_next);
741         command_unbind("window item goto", (SIGNAL_FUNC) cmd_window_item_goto);
742         command_unbind("window item move", (SIGNAL_FUNC) cmd_window_item_move);
743         command_unbind("window number", (SIGNAL_FUNC) cmd_window_number);
744         command_unbind("window name", (SIGNAL_FUNC) cmd_window_name);
745         command_unbind("window history", (SIGNAL_FUNC) cmd_window_history);
746         command_unbind("window move", (SIGNAL_FUNC) cmd_window_move);
747         command_unbind("window move prev", (SIGNAL_FUNC) cmd_window_move_prev);
748         command_unbind("window move next", (SIGNAL_FUNC) cmd_window_move_next);
749         command_unbind("window list", (SIGNAL_FUNC) cmd_window_list);
750         command_unbind("window theme", (SIGNAL_FUNC) cmd_window_theme);
751         command_unbind("layout", (SIGNAL_FUNC) cmd_layout);
752         command_unbind("layout save", (SIGNAL_FUNC) windows_layout_save);
753         command_unbind("layout reset", (SIGNAL_FUNC) windows_layout_reset);
754         command_unbind("foreach window", (SIGNAL_FUNC) cmd_foreach_window);
755 }