2000-05-15 04:25:45 -04:00
|
|
|
/*
|
|
|
|
window-commands.c : irssi
|
|
|
|
|
|
|
|
Copyright (C) 2000 Timo Sirainen
|
|
|
|
|
|
|
|
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 2 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "module-formats.h"
|
|
|
|
#include "signals.h"
|
|
|
|
#include "commands.h"
|
|
|
|
#include "misc.h"
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "servers.h"
|
2000-05-15 04:25:45 -04:00
|
|
|
|
|
|
|
#include "levels.h"
|
|
|
|
|
2000-07-31 17:16:09 -04:00
|
|
|
#include "themes.h"
|
2000-11-17 11:27:14 -05:00
|
|
|
#include "fe-windows.h"
|
2000-05-15 04:25:45 -04:00
|
|
|
#include "window-items.h"
|
2001-02-21 14:19:24 -05:00
|
|
|
#include "windows-layout.h"
|
2000-10-28 16:14:19 -04:00
|
|
|
#include "printtext.h"
|
2000-05-15 04:25:45 -04:00
|
|
|
|
2001-08-03 16:04:39 -04:00
|
|
|
static void window_print_binds(WINDOW_REC *win)
|
2000-05-15 04:25:45 -04:00
|
|
|
{
|
2001-08-03 16:04:39 -04:00
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
|
|
|
TXT_WINDOW_INFO_BOUND_ITEMS_HEADER);
|
|
|
|
for (tmp = win->bound_items; tmp != NULL; tmp = tmp->next) {
|
|
|
|
WINDOW_BIND_REC *bind = tmp->data;
|
|
|
|
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
|
|
|
TXT_WINDOW_INFO_BOUND_ITEM,
|
|
|
|
bind->name, bind->servertag,
|
|
|
|
bind->sticky ? "sticky" : "");
|
|
|
|
}
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
|
|
|
TXT_WINDOW_INFO_BOUND_ITEMS_FOOTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void window_print_items(WINDOW_REC *win)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
const char *type;
|
|
|
|
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
|
|
|
TXT_WINDOW_INFO_ITEMS_HEADER);
|
|
|
|
for (tmp = win->items; tmp != NULL; tmp = tmp->next) {
|
|
|
|
WI_ITEM_REC *item = tmp->data;
|
|
|
|
|
|
|
|
type = module_find_id_str("WINDOW ITEM TYPE", item->type);
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
|
|
|
TXT_WINDOW_INFO_ITEM,
|
|
|
|
type == NULL ? "??" : type, item->name,
|
|
|
|
item->server == NULL ? "" :
|
|
|
|
item->server->tag);
|
|
|
|
}
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
|
|
|
TXT_WINDOW_INFO_ITEMS_FOOTER);
|
|
|
|
}
|
|
|
|
|
2001-08-03 16:50:34 -04:00
|
|
|
static void cmd_window_info(WINDOW_REC *win)
|
2001-08-03 16:04:39 -04:00
|
|
|
{
|
|
|
|
char *levelstr;
|
|
|
|
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
|
|
|
TXT_WINDOW_INFO_HEADER);
|
|
|
|
|
|
|
|
/* Window reference number + sticky status */
|
|
|
|
if (!win->sticky_refnum) {
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
|
|
|
TXT_WINDOW_INFO_REFNUM, win->refnum);
|
|
|
|
} else {
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
|
|
|
TXT_WINDOW_INFO_REFNUM_STICKY, win->refnum);
|
2000-11-25 21:53:50 -05:00
|
|
|
}
|
|
|
|
|
2001-08-03 16:04:39 -04:00
|
|
|
/* Window name */
|
|
|
|
if (win->name != NULL) {
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
|
|
|
TXT_WINDOW_INFO_NAME, win->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Window width / height */
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP, TXT_WINDOW_INFO_SIZE,
|
|
|
|
win->width, win->height);
|
|
|
|
|
|
|
|
/* Window level */
|
|
|
|
levelstr = win->level == 0 ?
|
|
|
|
g_strdup("NONE") : bits2level(win->level);
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP, TXT_WINDOW_INFO_LEVEL,
|
|
|
|
levelstr);
|
|
|
|
g_free(levelstr);
|
|
|
|
|
|
|
|
/* Active window server + sticky status */
|
|
|
|
if (win->servertag == NULL) {
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
|
|
|
TXT_WINDOW_INFO_SERVER,
|
|
|
|
win->active_server != NULL ?
|
|
|
|
win->active_server->tag : "NONE");
|
|
|
|
} else {
|
|
|
|
if (win->active_server != NULL &&
|
|
|
|
strcmp(win->active_server->tag, win->servertag) != 0)
|
|
|
|
g_warning("Active server isn't the sticky server!");
|
|
|
|
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
|
|
|
TXT_WINDOW_INFO_SERVER_STICKY,
|
|
|
|
win->servertag);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Window theme + error status */
|
|
|
|
if (win->theme_name != NULL) {
|
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
|
|
|
TXT_WINDOW_INFO_THEME, win->theme_name,
|
|
|
|
win->theme != NULL ? "" : "(not loaded)");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bound items in window */
|
|
|
|
if (win->bound_items != NULL)
|
|
|
|
window_print_binds(win);
|
|
|
|
|
|
|
|
/* Item */
|
|
|
|
if (win->items != NULL)
|
|
|
|
window_print_items(win);
|
|
|
|
|
2001-08-03 18:54:08 -04:00
|
|
|
signal_emit("window print info", 1, win);
|
|
|
|
|
2001-08-03 16:04:39 -04:00
|
|
|
printformat_window(win, MSGLEVEL_CLIENTCRAP,
|
|
|
|
TXT_WINDOW_INFO_FOOTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cmd_window(const char *data, void *server, WI_ITEM_REC *item)
|
|
|
|
{
|
|
|
|
while (*data == ' ') data++;
|
|
|
|
|
|
|
|
if (*data == '\0')
|
2001-08-03 16:50:34 -04:00
|
|
|
cmd_window_info(active_win);
|
2001-08-03 16:04:39 -04:00
|
|
|
else if (is_numeric(data, 0))
|
|
|
|
signal_emit("command window refnum", 3, data, server, item);
|
|
|
|
else
|
|
|
|
command_runsub("window", data, server, item);
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW NEW [hide] */
|
2000-05-15 04:25:45 -04:00
|
|
|
static void cmd_window_new(const char *data, void *server, WI_ITEM_REC *item)
|
|
|
|
{
|
|
|
|
WINDOW_REC *window;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
|
|
|
type = (g_strncasecmp(data, "hid", 3) == 0 || g_strcasecmp(data, "tab") == 0) ? 1 :
|
|
|
|
(g_strcasecmp(data, "split") == 0 ? 2 : 0);
|
|
|
|
signal_emit("gui window create override", 1, GINT_TO_POINTER(type));
|
|
|
|
|
|
|
|
window = window_create(NULL, FALSE);
|
|
|
|
window_change_server(window, server);
|
|
|
|
}
|
|
|
|
|
2001-03-15 16:05:40 -05:00
|
|
|
/* SYNTAX: WINDOW CLOSE [<first> [<last>] */
|
2000-05-15 04:25:45 -04:00
|
|
|
static void cmd_window_close(const char *data)
|
|
|
|
{
|
2001-03-15 16:05:40 -05:00
|
|
|
GSList *tmp, *destroys;
|
|
|
|
char *first, *last;
|
|
|
|
int first_num, last_num;
|
|
|
|
void *free_arg;
|
|
|
|
|
|
|
|
if (!cmd_get_params(data, &free_arg, 2, &first, &last))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((*first != '\0' && !is_numeric(first, '\0')) ||
|
|
|
|
((*last != '\0') && !is_numeric(last, '\0'))) {
|
|
|
|
cmd_params_free(free_arg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
first_num = *first == '\0' ? active_win->refnum : atoi(first);
|
2001-08-12 09:05:57 -04:00
|
|
|
last_num = *last == '\0' ? first_num : atoi(last);
|
2001-03-15 16:05:40 -05:00
|
|
|
|
|
|
|
/* get list of windows to destroy */
|
|
|
|
destroys = NULL;
|
|
|
|
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
if (rec->refnum >= first_num && rec->refnum <= last_num)
|
|
|
|
destroys = g_slist_append(destroys, rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* really destroy the windows */
|
|
|
|
while (destroys != NULL) {
|
|
|
|
WINDOW_REC *rec = destroys->data;
|
|
|
|
|
|
|
|
if (windows->next != NULL)
|
|
|
|
window_destroy(rec);
|
|
|
|
|
|
|
|
destroys = g_slist_remove(destroys, rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd_params_free(free_arg);
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW REFNUM <number> */
|
2000-05-15 04:25:45 -04:00
|
|
|
static void cmd_window_refnum(const char *data)
|
|
|
|
{
|
|
|
|
WINDOW_REC *window;
|
|
|
|
|
|
|
|
if (!is_numeric(data, 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
window = window_find_refnum(atoi(data));
|
|
|
|
if (window != NULL)
|
|
|
|
window_set_active(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return the first window number with the highest activity */
|
|
|
|
static WINDOW_REC *window_highest_activity(WINDOW_REC *window)
|
|
|
|
{
|
|
|
|
WINDOW_REC *rec, *max_win;
|
|
|
|
GSList *tmp;
|
|
|
|
int max_act, through;
|
|
|
|
|
|
|
|
g_return_val_if_fail(window != NULL, NULL);
|
|
|
|
|
|
|
|
max_win = NULL; max_act = 0; through = FALSE;
|
|
|
|
|
|
|
|
tmp = g_slist_find(windows, window);
|
|
|
|
for (;; tmp = tmp->next) {
|
|
|
|
if (tmp == NULL) {
|
|
|
|
tmp = windows;
|
|
|
|
through = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (through && tmp->data == window)
|
|
|
|
break;
|
|
|
|
|
|
|
|
rec = tmp->data;
|
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
if (rec->data_level > 0 && max_act < rec->data_level) {
|
|
|
|
max_act = rec->data_level;
|
2000-05-15 04:25:45 -04:00
|
|
|
max_win = rec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return max_win;
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW GOTO active|<number>|<name> */
|
2000-05-15 04:25:45 -04:00
|
|
|
static void cmd_window_goto(const char *data)
|
|
|
|
{
|
|
|
|
WINDOW_REC *window;
|
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
|
|
|
if (is_numeric(data, 0)) {
|
|
|
|
cmd_window_refnum(data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_strcasecmp(data, "active") == 0)
|
|
|
|
window = window_highest_activity(active_win);
|
|
|
|
else
|
2000-12-02 14:08:21 -05:00
|
|
|
window = window_find_item(active_win->active_server, data);
|
2000-05-15 04:25:45 -04:00
|
|
|
|
|
|
|
if (window != NULL)
|
|
|
|
window_set_active(window);
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW NEXT */
|
2000-05-15 04:25:45 -04:00
|
|
|
static void cmd_window_next(void)
|
|
|
|
{
|
|
|
|
int num;
|
|
|
|
|
2000-06-12 18:57:53 -04:00
|
|
|
num = window_refnum_next(active_win->refnum, TRUE);
|
2000-05-15 04:25:45 -04:00
|
|
|
if (num < 1) num = windows_refnum_last();
|
|
|
|
|
|
|
|
window_set_active(window_find_refnum(num));
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW LAST */
|
2000-07-22 13:07:27 -04:00
|
|
|
static void cmd_window_last(void)
|
|
|
|
{
|
|
|
|
if (windows->next != NULL)
|
|
|
|
window_set_active(windows->next->data);
|
|
|
|
}
|
|
|
|
|
2001-02-27 03:39:04 -05:00
|
|
|
/* SYNTAX: WINDOW PREVIOUS */
|
|
|
|
static void cmd_window_previous(void)
|
2000-05-15 04:25:45 -04:00
|
|
|
{
|
|
|
|
int num;
|
|
|
|
|
2000-06-12 18:57:53 -04:00
|
|
|
num = window_refnum_prev(active_win->refnum, TRUE);
|
|
|
|
if (num < 1) num = window_refnum_next(0, TRUE);
|
2000-05-15 04:25:45 -04:00
|
|
|
|
|
|
|
window_set_active(window_find_refnum(num));
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW LEVEL [<level>] */
|
2000-05-15 04:25:45 -04:00
|
|
|
static void cmd_window_level(const char *data)
|
|
|
|
{
|
2000-06-04 16:54:33 -04:00
|
|
|
char *level;
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
|
|
|
window_set_level(active_win, combine_level(active_win->level, data));
|
2000-06-04 16:54:33 -04:00
|
|
|
|
2000-09-26 17:44:20 -04:00
|
|
|
level = active_win->level == 0 ? g_strdup("NONE") :
|
|
|
|
bits2level(active_win->level);
|
2001-01-27 22:52:29 -05:00
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_WINDOW_LEVEL, level);
|
2000-06-04 16:54:33 -04:00
|
|
|
g_free(level);
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
|
|
|
|
2001-02-09 22:10:30 -05:00
|
|
|
/* SYNTAX: WINDOW SERVER [-sticky | -unsticky] <tag> */
|
2000-05-15 04:25:45 -04:00
|
|
|
static void cmd_window_server(const char *data)
|
|
|
|
{
|
2001-02-09 22:10:30 -05:00
|
|
|
GHashTable *optlist;
|
2000-05-15 04:25:45 -04:00
|
|
|
SERVER_REC *server;
|
2001-02-09 22:10:30 -05:00
|
|
|
char *tag;
|
|
|
|
void *free_arg;
|
2000-05-15 04:25:45 -04:00
|
|
|
|
2001-02-09 22:10:30 -05:00
|
|
|
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
|
|
|
|
"window server", &optlist, &tag))
|
|
|
|
return;
|
|
|
|
|
2001-06-11 19:12:43 -04:00
|
|
|
if (*tag == '\0' && active_win->active_server != NULL &&
|
2001-02-09 22:10:30 -05:00
|
|
|
(g_hash_table_lookup(optlist, "sticky") != NULL ||
|
|
|
|
g_hash_table_lookup(optlist, "unsticky") != NULL)) {
|
|
|
|
tag = active_win->active_server->tag;
|
|
|
|
}
|
2000-05-15 04:25:45 -04:00
|
|
|
|
2001-02-09 22:10:30 -05:00
|
|
|
if (*tag == '\0')
|
|
|
|
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
|
|
|
server = server_find_tag(tag);
|
|
|
|
|
|
|
|
if (g_hash_table_lookup(optlist, "unsticky") != NULL &&
|
|
|
|
active_win->servertag != NULL) {
|
|
|
|
g_free_and_null(active_win->servertag);
|
2001-01-27 22:52:29 -05:00
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
2001-02-09 22:10:30 -05:00
|
|
|
TXT_UNSET_SERVER_STICKY, server->tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (active_win->servertag != NULL &&
|
|
|
|
g_hash_table_lookup(optlist, "sticky") == NULL) {
|
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTERROR,
|
|
|
|
TXT_ERROR_SERVER_STICKY);
|
|
|
|
} else if (server == NULL) {
|
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_UNKNOWN_SERVER_TAG, tag);
|
2001-01-27 22:52:29 -05:00
|
|
|
} else if (active_win->active == NULL) {
|
2000-05-15 04:25:45 -04:00
|
|
|
window_change_server(active_win, server);
|
2001-02-09 22:10:30 -05:00
|
|
|
if (g_hash_table_lookup(optlist, "sticky") != NULL) {
|
|
|
|
g_free_not_null(active_win->servertag);
|
|
|
|
active_win->servertag = g_strdup(server->tag);
|
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_SET_SERVER_STICKY, server->tag);
|
|
|
|
}
|
2001-01-27 22:52:29 -05:00
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_SERVER_CHANGED,
|
|
|
|
server->tag, server->connrec->address,
|
|
|
|
server->connrec->chatnet == NULL ? "" :
|
|
|
|
server->connrec->chatnet);
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
2001-02-09 22:10:30 -05:00
|
|
|
|
|
|
|
cmd_params_free(free_arg);
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
static void cmd_window_item(const char *data, void *server, WI_ITEM_REC *item)
|
|
|
|
{
|
|
|
|
command_runsub("window item", data, server, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SYNTAX: WINDOW ITEM PREV */
|
2000-05-15 04:25:45 -04:00
|
|
|
static void cmd_window_item_prev(void)
|
|
|
|
{
|
|
|
|
window_item_prev(active_win);
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW ITEM NEXT */
|
2000-05-15 04:25:45 -04:00
|
|
|
static void cmd_window_item_next(void)
|
|
|
|
{
|
|
|
|
window_item_next(active_win);
|
|
|
|
}
|
|
|
|
|
2000-12-02 01:08:31 -05:00
|
|
|
/* SYNTAX: WINDOW ITEM GOTO <name> */
|
|
|
|
static void cmd_window_item_goto(const char *data, SERVER_REC *server)
|
|
|
|
{
|
|
|
|
WI_ITEM_REC *item;
|
|
|
|
|
|
|
|
item = window_item_find_window(active_win, server, data);
|
|
|
|
if (item != NULL)
|
|
|
|
window_item_set_active(active_win, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SYNTAX: WINDOW ITEM MOVE <number>|<name> */
|
|
|
|
static void cmd_window_item_move(const char *data, SERVER_REC *server,
|
|
|
|
WI_ITEM_REC *item)
|
|
|
|
{
|
|
|
|
WINDOW_REC *window;
|
|
|
|
|
|
|
|
if (is_numeric(data, '\0')) {
|
|
|
|
/* move current window item to specified window */
|
|
|
|
window = window_find_refnum(atoi(data));
|
|
|
|
} else {
|
|
|
|
/* move specified window item to current window */
|
|
|
|
item = window_item_find(server, data);
|
|
|
|
window = active_win;
|
|
|
|
}
|
|
|
|
if (window != NULL && item != NULL)
|
|
|
|
window_item_set_active(window, item);
|
|
|
|
}
|
|
|
|
|
2001-01-01 13:30:23 -05:00
|
|
|
/* SYNTAX: WINDOW NUMBER [-sticky] <number> */
|
2000-05-15 04:25:45 -04:00
|
|
|
static void cmd_window_number(const char *data)
|
|
|
|
{
|
2001-01-01 13:30:23 -05:00
|
|
|
GHashTable *optlist;
|
|
|
|
char *refnum;
|
|
|
|
void *free_arg;
|
|
|
|
int num;
|
2000-05-15 04:25:45 -04:00
|
|
|
|
2001-01-01 13:30:23 -05:00
|
|
|
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
|
|
|
|
"window number", &optlist, &refnum))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (*refnum == '\0')
|
|
|
|
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
|
|
|
|
|
|
|
num = atoi(refnum);
|
|
|
|
if (num < 1) {
|
2001-01-27 22:52:29 -05:00
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_REFNUM_TOO_LOW);
|
2001-01-01 13:30:23 -05:00
|
|
|
} else {
|
2000-05-15 04:25:45 -04:00
|
|
|
window_set_refnum(active_win, num);
|
2001-01-01 13:30:23 -05:00
|
|
|
active_win->sticky_refnum =
|
|
|
|
g_hash_table_lookup(optlist, "sticky") != NULL;
|
|
|
|
}
|
2001-01-04 03:35:33 -05:00
|
|
|
|
|
|
|
cmd_params_free(free_arg);
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW NAME <name> */
|
2000-05-15 04:25:45 -04:00
|
|
|
static void cmd_window_name(const char *data)
|
|
|
|
{
|
|
|
|
window_set_name(active_win, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we're moving the first window to last - move the first contiguous block
|
|
|
|
of refnums to left. Like if there's windows 1..5 and 7..10, move 1 to
|
2001-08-07 08:41:10 -04:00
|
|
|
11, 2..5 to 1..4 and leave 7..10 alone */
|
|
|
|
static void window_refnums_move_left(WINDOW_REC *move_window)
|
2000-05-15 04:25:45 -04:00
|
|
|
{
|
|
|
|
WINDOW_REC *window;
|
2001-08-07 08:41:10 -04:00
|
|
|
int refnum, new_refnum;
|
2000-05-15 04:25:45 -04:00
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
new_refnum = windows_refnum_last();
|
|
|
|
for (refnum = move_window->refnum+1; refnum <= new_refnum; refnum++) {
|
2000-05-15 04:25:45 -04:00
|
|
|
window = window_find_refnum(refnum);
|
2001-08-07 08:41:10 -04:00
|
|
|
if (window == NULL) {
|
|
|
|
new_refnum++;
|
|
|
|
break;
|
|
|
|
}
|
2000-05-15 04:25:45 -04:00
|
|
|
|
|
|
|
window_set_refnum(window, refnum-1);
|
|
|
|
}
|
2001-08-07 08:41:10 -04:00
|
|
|
|
|
|
|
window_set_refnum(move_window, new_refnum);
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we're moving the last window to first - make some space so we can use the
|
|
|
|
refnum 1 */
|
2001-08-07 08:41:10 -04:00
|
|
|
static void window_refnums_move_right(WINDOW_REC *move_window)
|
2000-05-15 04:25:45 -04:00
|
|
|
{
|
|
|
|
WINDOW_REC *window;
|
2001-08-07 08:41:10 -04:00
|
|
|
int refnum, new_refnum;
|
|
|
|
|
|
|
|
new_refnum = 1;
|
|
|
|
if (window_find_refnum(new_refnum) == NULL) {
|
|
|
|
window_set_refnum(move_window, new_refnum);
|
|
|
|
return;
|
|
|
|
}
|
2000-05-15 04:25:45 -04:00
|
|
|
|
|
|
|
/* find the first unused refnum, like if there's windows
|
|
|
|
1..5 and 7..10, we only need to move 1..5 to 2..6 */
|
2001-08-07 08:41:10 -04:00
|
|
|
refnum = new_refnum;
|
|
|
|
while (move_window->refnum == refnum ||
|
|
|
|
window_find_refnum(refnum) != NULL) refnum++;
|
2000-05-15 04:25:45 -04:00
|
|
|
refnum--;
|
2001-08-07 08:41:10 -04:00
|
|
|
|
|
|
|
while (refnum >= new_refnum) {
|
2000-05-15 04:25:45 -04:00
|
|
|
window = window_find_refnum(refnum);
|
2001-08-07 08:41:10 -04:00
|
|
|
window_set_refnum(window, refnum+1);
|
2000-05-15 04:25:45 -04:00
|
|
|
|
|
|
|
refnum--;
|
|
|
|
}
|
2001-08-07 08:41:10 -04:00
|
|
|
|
|
|
|
window_set_refnum(move_window, new_refnum);
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
/* SYNTAX: WINDOW MOVE PREV */
|
|
|
|
static void cmd_window_move_prev(void)
|
2000-05-15 04:25:45 -04:00
|
|
|
{
|
|
|
|
int refnum;
|
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
refnum = window_refnum_prev(active_win->refnum, FALSE);
|
2000-05-15 04:25:45 -04:00
|
|
|
if (refnum != -1) {
|
2000-06-12 18:57:53 -04:00
|
|
|
window_set_refnum(active_win, refnum);
|
2000-05-15 04:25:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
window_refnums_move_left(active_win);
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
/* SYNTAX: WINDOW MOVE NEXT */
|
|
|
|
static void cmd_window_move_next(void)
|
2000-05-15 04:25:45 -04:00
|
|
|
{
|
|
|
|
int refnum;
|
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
refnum = window_refnum_next(active_win->refnum, FALSE);
|
2000-05-15 04:25:45 -04:00
|
|
|
if (refnum != -1) {
|
2000-06-12 18:57:53 -04:00
|
|
|
window_set_refnum(active_win, refnum);
|
2000-05-15 04:25:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
window_refnums_move_right(active_win);
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
/* SYNTAX: WINDOW MOVE <number>|<direction> */
|
2000-05-15 04:25:45 -04:00
|
|
|
static void cmd_window_move(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
|
|
|
|
{
|
|
|
|
int new_refnum, refnum;
|
|
|
|
|
|
|
|
if (!is_numeric(data, 0)) {
|
|
|
|
command_runsub("window move", data, server, item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_refnum = atoi(data);
|
|
|
|
if (new_refnum > active_win->refnum) {
|
|
|
|
for (;;) {
|
2000-06-12 18:57:53 -04:00
|
|
|
refnum = window_refnum_next(active_win->refnum, FALSE);
|
2000-05-15 04:25:45 -04:00
|
|
|
if (refnum == -1 || refnum > new_refnum)
|
|
|
|
break;
|
|
|
|
|
|
|
|
window_set_refnum(active_win, refnum);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (;;) {
|
2000-06-12 18:57:53 -04:00
|
|
|
refnum = window_refnum_prev(active_win->refnum, FALSE);
|
2000-05-15 04:25:45 -04:00
|
|
|
if (refnum == -1 || refnum < new_refnum)
|
|
|
|
break;
|
|
|
|
|
|
|
|
window_set_refnum(active_win, refnum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW LIST */
|
2000-05-15 04:25:45 -04:00
|
|
|
static void cmd_window_list(void)
|
|
|
|
{
|
|
|
|
GSList *tmp, *sorted;
|
|
|
|
char *levelstr;
|
|
|
|
|
|
|
|
sorted = windows_get_sorted();
|
2001-01-07 14:42:59 -05:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_WINDOWLIST_HEADER);
|
2000-05-15 04:25:45 -04:00
|
|
|
for (tmp = sorted; tmp != NULL; tmp = tmp->next) {
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
levelstr = bits2level(rec->level);
|
2001-01-07 14:42:59 -05:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_WINDOWLIST_LINE,
|
2000-05-15 04:25:45 -04:00
|
|
|
rec->refnum, rec->name == NULL ? "" : rec->name,
|
|
|
|
rec->active == NULL ? "" : rec->active->name,
|
|
|
|
rec->active_server == NULL ? "" : ((SERVER_REC *) rec->active_server)->tag,
|
|
|
|
levelstr);
|
|
|
|
g_free(levelstr);
|
|
|
|
}
|
|
|
|
g_slist_free(sorted);
|
2001-01-07 14:42:59 -05:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_WINDOWLIST_FOOTER);
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
|
|
|
|
2001-06-27 17:16:43 -04:00
|
|
|
/* SYNTAX: WINDOW THEME [-delete] [<name>] */
|
2000-07-31 17:16:09 -04:00
|
|
|
static void cmd_window_theme(const char *data)
|
|
|
|
{
|
2001-02-19 20:12:47 -05:00
|
|
|
THEME_REC *theme;
|
2001-06-27 17:16:43 -04:00
|
|
|
GHashTable *optlist;
|
|
|
|
char *name;
|
|
|
|
void *free_arg;
|
|
|
|
|
|
|
|
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
|
|
|
|
"window theme", &optlist, &name))
|
|
|
|
return;
|
2001-02-19 20:12:47 -05:00
|
|
|
|
2001-06-27 17:16:43 -04:00
|
|
|
if (g_hash_table_lookup(optlist, "delete") != NULL) {
|
|
|
|
g_free_and_null(active_win->theme_name);
|
2000-07-31 21:02:46 -04:00
|
|
|
|
2001-01-27 22:52:29 -05:00
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
2001-06-27 17:16:43 -04:00
|
|
|
TXT_WINDOW_THEME_REMOVED);
|
|
|
|
} else if (*name == '\0') {
|
|
|
|
if (active_win->theme == NULL) {
|
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_WINDOW_THEME_DEFAULT);
|
|
|
|
} else {
|
|
|
|
theme = active_win->theme;
|
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_WINDOW_THEME,
|
|
|
|
theme->name, theme->path);
|
|
|
|
}
|
2000-07-31 17:16:09 -04:00
|
|
|
} else {
|
2001-06-27 17:16:43 -04:00
|
|
|
g_free_not_null(active_win->theme_name);
|
|
|
|
active_win->theme_name = g_strdup(data);
|
|
|
|
|
|
|
|
active_win->theme = theme = theme_load(data);
|
|
|
|
if (theme != NULL) {
|
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_WINDOW_THEME_CHANGED,
|
|
|
|
theme->name, theme->path);
|
|
|
|
} else {
|
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_THEME_NOT_FOUND, data);
|
|
|
|
}
|
2000-07-31 17:16:09 -04:00
|
|
|
}
|
2001-06-27 17:16:43 -04:00
|
|
|
|
|
|
|
cmd_params_free(free_arg);
|
2000-07-31 17:16:09 -04:00
|
|
|
}
|
|
|
|
|
2001-02-21 14:19:24 -05:00
|
|
|
static void cmd_layout(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
|
2000-07-31 21:02:46 -04:00
|
|
|
{
|
2001-02-21 14:19:24 -05:00
|
|
|
command_runsub("layout", data, server, item);
|
2000-07-31 21:02:46 -04:00
|
|
|
}
|
|
|
|
|
2001-02-21 13:41:45 -05:00
|
|
|
/* SYNTAX: FOREACH WINDOW <command> */
|
|
|
|
static void cmd_foreach_window(const char *data)
|
|
|
|
{
|
|
|
|
WINDOW_REC *old;
|
2001-07-15 14:21:44 -04:00
|
|
|
GSList *list;
|
2001-02-21 13:41:45 -05:00
|
|
|
|
|
|
|
old = active_win;
|
|
|
|
|
2001-07-15 14:21:44 -04:00
|
|
|
list = g_slist_copy(windows);
|
|
|
|
while (list != NULL) {
|
|
|
|
WINDOW_REC *rec = list->data;
|
|
|
|
|
|
|
|
active_win = rec;
|
2001-02-21 13:41:45 -05:00
|
|
|
signal_emit("send command", 3, data, rec->active_server,
|
|
|
|
rec->active);
|
2001-07-15 14:21:44 -04:00
|
|
|
list = g_slist_remove(list, list->data);
|
2001-02-21 13:41:45 -05:00
|
|
|
}
|
2001-07-15 14:21:44 -04:00
|
|
|
|
2001-02-21 13:41:45 -05:00
|
|
|
active_win = old;
|
|
|
|
}
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
void window_commands_init(void)
|
|
|
|
{
|
|
|
|
command_bind("window", NULL, (SIGNAL_FUNC) cmd_window);
|
|
|
|
command_bind("window new", NULL, (SIGNAL_FUNC) cmd_window_new);
|
|
|
|
command_bind("window close", NULL, (SIGNAL_FUNC) cmd_window_close);
|
|
|
|
command_bind("window kill", NULL, (SIGNAL_FUNC) cmd_window_close);
|
|
|
|
command_bind("window server", NULL, (SIGNAL_FUNC) cmd_window_server);
|
|
|
|
command_bind("window refnum", NULL, (SIGNAL_FUNC) cmd_window_refnum);
|
|
|
|
command_bind("window goto", NULL, (SIGNAL_FUNC) cmd_window_goto);
|
2001-02-27 03:39:04 -05:00
|
|
|
command_bind("window previous", NULL, (SIGNAL_FUNC) cmd_window_previous);
|
2000-05-15 04:25:45 -04:00
|
|
|
command_bind("window next", NULL, (SIGNAL_FUNC) cmd_window_next);
|
2000-07-22 13:07:27 -04:00
|
|
|
command_bind("window last", NULL, (SIGNAL_FUNC) cmd_window_last);
|
2000-05-15 04:25:45 -04:00
|
|
|
command_bind("window level", NULL, (SIGNAL_FUNC) cmd_window_level);
|
2000-07-23 19:19:22 -04:00
|
|
|
command_bind("window item", NULL, (SIGNAL_FUNC) cmd_window_item);
|
2000-05-15 04:25:45 -04:00
|
|
|
command_bind("window item prev", NULL, (SIGNAL_FUNC) cmd_window_item_prev);
|
|
|
|
command_bind("window item next", NULL, (SIGNAL_FUNC) cmd_window_item_next);
|
2000-12-02 01:08:31 -05:00
|
|
|
command_bind("window item goto", NULL, (SIGNAL_FUNC) cmd_window_item_goto);
|
|
|
|
command_bind("window item move", NULL, (SIGNAL_FUNC) cmd_window_item_move);
|
2000-05-15 04:25:45 -04:00
|
|
|
command_bind("window number", NULL, (SIGNAL_FUNC) cmd_window_number);
|
|
|
|
command_bind("window name", NULL, (SIGNAL_FUNC) cmd_window_name);
|
|
|
|
command_bind("window move", NULL, (SIGNAL_FUNC) cmd_window_move);
|
2001-08-07 08:41:10 -04:00
|
|
|
command_bind("window move prev", NULL, (SIGNAL_FUNC) cmd_window_move_prev);
|
|
|
|
command_bind("window move next", NULL, (SIGNAL_FUNC) cmd_window_move_next);
|
2000-05-15 04:25:45 -04:00
|
|
|
command_bind("window list", NULL, (SIGNAL_FUNC) cmd_window_list);
|
2000-07-31 17:16:09 -04:00
|
|
|
command_bind("window theme", NULL, (SIGNAL_FUNC) cmd_window_theme);
|
2001-02-21 14:19:24 -05:00
|
|
|
command_bind("layout", NULL, (SIGNAL_FUNC) cmd_layout);
|
|
|
|
/* SYNTAX: LAYOUT SAVE */
|
|
|
|
command_bind("layout save", NULL, (SIGNAL_FUNC) windows_layout_save);
|
|
|
|
/* SYNTAX: LAYOUT RESET */
|
|
|
|
command_bind("layout reset", NULL, (SIGNAL_FUNC) windows_layout_reset);
|
2001-02-21 13:41:45 -05:00
|
|
|
command_bind("foreach window", NULL, (SIGNAL_FUNC) cmd_foreach_window);
|
2001-01-01 13:30:23 -05:00
|
|
|
|
|
|
|
command_set_options("window number", "sticky");
|
2001-02-09 22:10:30 -05:00
|
|
|
command_set_options("window server", "sticky unsticky");
|
2001-06-27 17:16:43 -04:00
|
|
|
command_set_options("window theme", "delete");
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void window_commands_deinit(void)
|
|
|
|
{
|
|
|
|
command_unbind("window", (SIGNAL_FUNC) cmd_window);
|
|
|
|
command_unbind("window new", (SIGNAL_FUNC) cmd_window_new);
|
|
|
|
command_unbind("window close", (SIGNAL_FUNC) cmd_window_close);
|
|
|
|
command_unbind("window kill", (SIGNAL_FUNC) cmd_window_close);
|
|
|
|
command_unbind("window server", (SIGNAL_FUNC) cmd_window_server);
|
|
|
|
command_unbind("window refnum", (SIGNAL_FUNC) cmd_window_refnum);
|
|
|
|
command_unbind("window goto", (SIGNAL_FUNC) cmd_window_goto);
|
2001-02-27 03:39:04 -05:00
|
|
|
command_unbind("window previous", (SIGNAL_FUNC) cmd_window_previous);
|
2000-05-15 04:25:45 -04:00
|
|
|
command_unbind("window next", (SIGNAL_FUNC) cmd_window_next);
|
2000-07-22 13:07:27 -04:00
|
|
|
command_unbind("window last", (SIGNAL_FUNC) cmd_window_last);
|
2000-05-15 04:25:45 -04:00
|
|
|
command_unbind("window level", (SIGNAL_FUNC) cmd_window_level);
|
2000-07-23 19:19:22 -04:00
|
|
|
command_unbind("window item", (SIGNAL_FUNC) cmd_window_item);
|
2000-05-15 04:25:45 -04:00
|
|
|
command_unbind("window item prev", (SIGNAL_FUNC) cmd_window_item_prev);
|
|
|
|
command_unbind("window item next", (SIGNAL_FUNC) cmd_window_item_next);
|
2000-12-02 01:08:31 -05:00
|
|
|
command_unbind("window item goto", (SIGNAL_FUNC) cmd_window_item_goto);
|
|
|
|
command_unbind("window item move", (SIGNAL_FUNC) cmd_window_item_move);
|
2000-05-15 04:25:45 -04:00
|
|
|
command_unbind("window number", (SIGNAL_FUNC) cmd_window_number);
|
|
|
|
command_unbind("window name", (SIGNAL_FUNC) cmd_window_name);
|
|
|
|
command_unbind("window move", (SIGNAL_FUNC) cmd_window_move);
|
2001-08-07 08:41:10 -04:00
|
|
|
command_unbind("window move prev", (SIGNAL_FUNC) cmd_window_move_prev);
|
|
|
|
command_unbind("window move next", (SIGNAL_FUNC) cmd_window_move_next);
|
2000-05-15 04:25:45 -04:00
|
|
|
command_unbind("window list", (SIGNAL_FUNC) cmd_window_list);
|
2000-07-31 17:16:09 -04:00
|
|
|
command_unbind("window theme", (SIGNAL_FUNC) cmd_window_theme);
|
2001-02-21 14:19:24 -05:00
|
|
|
command_unbind("layout", (SIGNAL_FUNC) cmd_layout);
|
|
|
|
command_unbind("layout save", (SIGNAL_FUNC) windows_layout_save);
|
|
|
|
command_unbind("layout reset", (SIGNAL_FUNC) windows_layout_reset);
|
2001-02-21 13:41:45 -05:00
|
|
|
command_unbind("foreach window", (SIGNAL_FUNC) cmd_foreach_window);
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|