summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fe-text/gui-readline.c14
-rw-r--r--src/fe-text/gui-windows.c48
-rw-r--r--src/fe-text/mainwindows.c206
-rw-r--r--src/fe-text/mainwindows.h1
-rw-r--r--src/fe-text/module-formats.c6
-rw-r--r--src/fe-text/module-formats.h8
6 files changed, 259 insertions, 24 deletions
diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c
index 56dee1c3..a51f8428 100644
--- a/src/fe-text/gui-readline.c
+++ b/src/fe-text/gui-readline.c
@@ -480,6 +480,16 @@ static void key_next_window(void)
signal_emit("command window next", 3, "", active_win->active_server, active_win->active);
}
+static void key_left_window(void)
+{
+ signal_emit("command window left", 3, "", active_win->active_server, active_win->active);
+}
+
+static void key_right_window(void)
+{
+ signal_emit("command window right", 3, "", active_win->active_server, active_win->active);
+}
+
static void key_upper_window(void)
{
signal_emit("command window up", 3, "", active_win->active_server, active_win->active);
@@ -602,9 +612,9 @@ void gui_readline_init(void)
key_bind("check_replaces", NULL, "Return", NULL, (SIGNAL_FUNC) key_check_replaces);
key_bind("previous_window", "Previous window", "CTRL-P", NULL, (SIGNAL_FUNC) key_previous_window);
- key_bind("previous_window", NULL, "ALT-Left", NULL, (SIGNAL_FUNC) key_previous_window);
+ key_bind("left_window", NULL, "ALT-Left", NULL, (SIGNAL_FUNC) key_left_window);
key_bind("next_window", "Next window", "CTRL-N", NULL, (SIGNAL_FUNC) key_next_window);
- key_bind("next_window", NULL, "ALT-Right", NULL, (SIGNAL_FUNC) key_next_window);
+ key_bind("right_window", NULL, "ALT-Right", NULL, (SIGNAL_FUNC) key_right_window);
key_bind("upper_window", "Upper window", "ALT-Up", NULL, (SIGNAL_FUNC) key_upper_window);
key_bind("lower_window", "Lower window", "ALT-Down", NULL, (SIGNAL_FUNC) key_lower_window);
key_bind("active_window", "Go to next window with the highest activity", "ALT-A", NULL, (SIGNAL_FUNC) key_active_window);
diff --git a/src/fe-text/gui-windows.c b/src/fe-text/gui-windows.c
index 42eebfa8..6dfaa084 100644
--- a/src/fe-text/gui-windows.c
+++ b/src/fe-text/gui-windows.c
@@ -729,29 +729,59 @@ void gui_window_reparent(WINDOW_REC *window, MAIN_WINDOW_REC *parent)
int ychange;
oldparent = WINDOW_GUI(window)->parent;
- ychange = parent->lines - oldparent->lines;
+ if (oldparent == parent)
+ return;
WINDOW_GUI(window)->parent = parent;
+
+ ychange = parent->lines - oldparent->lines;
if (ychange != 0) gui_window_resize(window, ychange, FALSE);
}
+static MAIN_WINDOW_REC *mainwindow_find_unsticky(void)
+{
+ GSList *tmp;
+
+ for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
+ MAIN_WINDOW_REC *rec = tmp->data;
+
+ if (rec->sticky_windows == NULL)
+ return rec;
+ }
+
+ /* all windows are sticky, fallback to active window */
+ return active_mainwin;
+}
+
static void signal_window_changed(WINDOW_REC *window)
{
+ MAIN_WINDOW_REC *parent;
+
g_return_if_fail(window != NULL);
if (quitting) return;
+ parent = WINDOW_GUI(window)->parent;
if (is_window_visible(window)) {
- /* already visible, great! */
- active_mainwin = WINDOW_GUI(window)->parent;
+ /* already visible */
+ active_mainwin = parent;
+ } else if (active_mainwin == NULL) {
+ /* no main window set yet */
+ active_mainwin = parent;
+ } else if (g_slist_find(parent->sticky_windows, window) != NULL) {
+ /* window is sticky, switch to correct main window */
+ if (parent != active_mainwin)
+ active_mainwin = parent;
} else {
- /* move it to active main window */
- if (active_mainwin == NULL)
- active_mainwin = WINDOW_GUI(window)->parent;
- else
- gui_window_reparent(window, active_mainwin);
- active_mainwin->active = window;
+ /* move window to active main window */
+ if (active_mainwin->sticky_windows != NULL) {
+ /* active mainwindow is sticky, we'll need to
+ set the window active somewhere else */
+ active_mainwin = mainwindow_find_unsticky();
+ }
+ gui_window_reparent(window, active_mainwin);
}
+ active_mainwin->active = window;
screen_refresh_freeze();
window_update_prompt();
diff --git a/src/fe-text/mainwindows.c b/src/fe-text/mainwindows.c
index 8984c120..1334e20b 100644
--- a/src/fe-text/mainwindows.c
+++ b/src/fe-text/mainwindows.c
@@ -478,7 +478,8 @@ static void cmd_window_grow(const char *data)
window->first_line -= count;
shrink_win->last_line -= count;
} else {
- printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_WINDOW_TOO_SMALL);
+ printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
+ TXT_WINDOW_TOO_SMALL);
return;
}
}
@@ -496,7 +497,8 @@ static void cmd_window_shrink(const char *data)
window = WINDOW_GUI(active_win)->parent;
if (window->lines-count < WINDOW_MIN_SIZE) {
- printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_WINDOW_TOO_SMALL);
+ printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
+ TXT_WINDOW_TOO_SMALL);
return;
}
@@ -579,19 +581,31 @@ static void cmd_window_hide(const char *data)
WINDOW_REC *window;
if (mainwindows->next == NULL) {
- printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CANT_HIDE_LAST);
+ printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
+ TXT_CANT_HIDE_LAST);
return;
}
if (*data == '\0')
window = active_win;
- else if (is_numeric(data, 0))
+ else if (is_numeric(data, 0)) {
window = window_find_refnum(atoi(data));
- else
+ if (window == NULL) {
+ printformat_window(active_win, MSGLEVEL_CLIENTERROR,
+ TXT_REFNUM_NOT_FOUND, data);
+ }
+ } else {
window = window_find_item(active_win->active_server, data);
+ }
- if (window == NULL) return;
- if (!is_window_visible(window)) return;
+ if (window == NULL || !is_window_visible(window))
+ return;
+
+ if (WINDOW_GUI(window)->parent->sticky_windows != NULL) {
+ printformat_window(active_win, MSGLEVEL_CLIENTERROR,
+ TXT_CANT_HIDE_STICKY_WINDOWS);
+ return;
+ }
mainwindow_destroy(WINDOW_GUI(window)->parent);
@@ -608,12 +622,24 @@ static void cmd_window_show(const char *data)
if (*data == '\0') cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
- window = is_numeric(data, 0) ?
- window_find_refnum(atoi(data)) :
- window_find_item(active_win->active_server, data);
+ if (is_numeric(data, '\0')) {
+ window = window_find_refnum(atoi(data));
+ if (window == NULL) {
+ printformat_window(active_win, MSGLEVEL_CLIENTERROR,
+ TXT_REFNUM_NOT_FOUND, data);
+ }
+ } else {
+ window = window_find_item(active_win->active_server, data);
+ }
+
+ if (window == NULL || is_window_visible(window))
+ return;
- if (window == NULL) return;
- if (is_window_visible(window)) return;
+ if (WINDOW_GUI(window)->parent->sticky_windows != NULL) {
+ printformat_window(active_win, MSGLEVEL_CLIENTERROR,
+ TXT_CANT_SHOW_STICKY_WINDOWS);
+ return;
+ }
WINDOW_GUI(window)->parent = mainwindow_create();
WINDOW_GUI(window)->parent->active = window;
@@ -642,6 +668,156 @@ static void cmd_window_down(void)
window_set_active(rec->active);
}
+/* SYNTAX: WINDOW LEFT */
+static void cmd_window_left(const char *data, SERVER_REC *server, void *item)
+{
+ MAIN_WINDOW_REC *parent;
+ WINDOW_REC *window;
+ int pos, num;
+
+ window = NULL;
+ if (active_mainwin->sticky_windows == NULL) {
+ /* no sticky windows, go to previous non-sticky window */
+ num = active_win->refnum;
+ do {
+ num = window_refnum_prev(num, TRUE);
+ if (num < 0) {
+ window = NULL;
+ break;
+ }
+ window = window_find_refnum(num);
+ parent = WINDOW_GUI(window)->parent;
+ } while (g_slist_find(parent->sticky_windows, window) != NULL);
+ } else {
+ pos = g_slist_index(active_mainwin->sticky_windows,
+ active_win);
+ if (pos > 0) {
+ window = g_slist_nth_data(
+ active_mainwin->sticky_windows, pos-1);
+ } else {
+ window = g_slist_last(
+ active_mainwin->sticky_windows)->data;
+ }
+ }
+
+ if (window != NULL)
+ window_set_active(window);
+}
+
+/* SYNTAX: WINDOW RIGHT */
+static void cmd_window_right(void)
+{
+ MAIN_WINDOW_REC *parent;
+ WINDOW_REC *window;
+ GSList *tmp;
+ int num;
+
+ window = NULL;
+ if (active_mainwin->sticky_windows == NULL) {
+ /* no sticky windows, go to next non-sticky window */
+ num = active_win->refnum;
+ do {
+ num = window_refnum_next(num, TRUE);
+ if (num < 0) {
+ window = NULL;
+ break;
+ }
+ window = window_find_refnum(num);
+ parent = WINDOW_GUI(window)->parent;
+ } while (g_slist_find(parent->sticky_windows, window) != NULL);
+ } else {
+ tmp = g_slist_find(active_mainwin->sticky_windows, active_win);
+ if (tmp != NULL) {
+ window = tmp->next != NULL ? tmp->next->data :
+ active_mainwin->sticky_windows->data;
+ }
+ }
+
+ if (window != NULL)
+ window_set_active(window);
+}
+
+static void mainwindow_change_window(MAIN_WINDOW_REC *mainwin,
+ WINDOW_REC *window)
+{
+ MAIN_WINDOW_REC *parent;
+ GSList *tmp;
+
+ if (mainwin->sticky_windows != NULL) {
+ /* sticky window */
+ window_set_active(mainwin->sticky_windows->data);
+ return;
+ }
+
+ for (tmp = windows; tmp != NULL; tmp = tmp->next) {
+ WINDOW_REC *rec = tmp->data;
+
+ parent = WINDOW_GUI(rec)->parent;
+ if (rec != window &&
+ g_slist_find(parent->sticky_windows, rec) == NULL) {
+ window_set_active(rec);
+ return;
+ }
+ }
+
+ /* no more non-sticky windows, remove main window */
+ mainwindow_destroy(mainwin);
+}
+
+/* SYNTAX: WINDOW STICK [ON|OFF|<ref#>] */
+static void cmd_window_stick(const char *data)
+{
+ MAIN_WINDOW_REC *window = active_mainwin;
+
+ if (is_numeric(data, '\0')) {
+ WINDOW_REC *win = window_find_refnum(atoi(data));
+ if (win == NULL) {
+ printformat_window(active_win, MSGLEVEL_CLIENTERROR,
+ TXT_REFNUM_NOT_FOUND, data);
+ return;
+ }
+ window = WINDOW_GUI(win)->parent;
+ }
+
+ if (g_strncasecmp(data, "OF", 2) == 0 || toupper(*data) == 'N') {
+ /* unset sticky */
+ if (g_slist_find(window->sticky_windows, active_win) == NULL) {
+ printformat_window(active_win, MSGLEVEL_CLIENTERROR,
+ TXT_WINDOW_NOT_STICKY);
+ } else {
+ window->sticky_windows =
+ g_slist_remove(window->sticky_windows,
+ active_win);
+ printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
+ TXT_WINDOW_UNSET_STICKY);
+ }
+ } else {
+ /* set sticky */
+ active_mainwin->sticky_windows =
+ g_slist_remove(active_mainwin->sticky_windows,
+ active_win);
+
+ if (g_slist_find(window->sticky_windows, active_win) == NULL) {
+ window->sticky_windows =
+ g_slist_append(window->sticky_windows,
+ active_win);
+ }
+ if (window != active_mainwin) {
+ WINDOW_REC *movewin;
+
+ movewin = active_win;
+ gui_window_reparent(movewin, window);
+ mainwindow_change_window(active_mainwin, movewin);
+
+ active_mainwin = window;
+ window_set_active(movewin);
+ }
+
+ printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
+ TXT_WINDOW_SET_STICKY);
+ }
+}
+
void mainwindows_init(void)
{
mainwindows = NULL;
@@ -659,6 +835,9 @@ void mainwindows_init(void)
command_bind("window show", NULL, (SIGNAL_FUNC) cmd_window_show);
command_bind("window up", NULL, (SIGNAL_FUNC) cmd_window_up);
command_bind("window down", NULL, (SIGNAL_FUNC) cmd_window_down);
+ command_bind("window left", NULL, (SIGNAL_FUNC) cmd_window_left);
+ command_bind("window right", NULL, (SIGNAL_FUNC) cmd_window_right);
+ command_bind("window stick", NULL, (SIGNAL_FUNC) cmd_window_stick);
}
void mainwindows_deinit(void)
@@ -674,4 +853,7 @@ void mainwindows_deinit(void)
command_unbind("window show", (SIGNAL_FUNC) cmd_window_show);
command_unbind("window up", (SIGNAL_FUNC) cmd_window_up);
command_unbind("window down", (SIGNAL_FUNC) cmd_window_down);
+ command_unbind("window left", (SIGNAL_FUNC) cmd_window_left);
+ command_unbind("window right", (SIGNAL_FUNC) cmd_window_right);
+ command_unbind("window stick", (SIGNAL_FUNC) cmd_window_stick);
}
diff --git a/src/fe-text/mainwindows.h b/src/fe-text/mainwindows.h
index 5d65247a..278e1b11 100644
--- a/src/fe-text/mainwindows.h
+++ b/src/fe-text/mainwindows.h
@@ -6,6 +6,7 @@
typedef struct {
WINDOW_REC *active;
+ GSList *sticky_windows; /* list of windows allowed to show only in this mainwindow */
#ifdef USE_CURSES_WINDOWS
WINDOW *curses_win;
diff --git a/src/fe-text/module-formats.c b/src/fe-text/module-formats.c
index 935e6eee..74e34d77 100644
--- a/src/fe-text/module-formats.c
+++ b/src/fe-text/module-formats.c
@@ -28,8 +28,14 @@ FORMAT_REC gui_text_formats[] =
{ "lastlog_start", "{hilight Lastlog}:", 0 },
{ "lastlog_end", "{hilight End of Lastlog}", 0 },
+ { "refnum_not_found", "Window number $0 not found", 1, { 0 } },
{ "window_too_small", "Not enough room to resize this window", 0 },
{ "cant_hide_last", "You can't hide the last window", 0 },
+ { "cant_hide_sticky_windows", "You can't hide sticky windows (use /WINDOW STICKY OFF)", 0 },
+ { "cant_show_sticky_windows", "You can't show sticky windows (use /WINDOW STICKY OFF)", 0 },
+ { "window_not_sticky", "Window is not sticky", 0 },
+ { "window_set_sticky", "Window set sticky", 0 },
+ { "window_unset_sticky", "Window is not sticky anymore", 0 },
{ NULL, NULL, 0 }
};
diff --git a/src/fe-text/module-formats.h b/src/fe-text/module-formats.h
index b8ac7cf6..9fe896d8 100644
--- a/src/fe-text/module-formats.h
+++ b/src/fe-text/module-formats.h
@@ -6,8 +6,14 @@ enum {
TXT_LASTLOG_START,
TXT_LASTLOG_END,
+ TXT_REFNUM_NOT_FOUND,
TXT_WINDOW_TOO_SMALL,
- TXT_CANT_HIDE_LAST
+ TXT_CANT_HIDE_LAST,
+ TXT_CANT_HIDE_STICKY_WINDOWS,
+ TXT_CANT_SHOW_STICKY_WINDOWS,
+ TXT_WINDOW_NOT_STICKY,
+ TXT_WINDOW_SET_STICKY,
+ TXT_WINDOW_UNSET_STICKY
};
extern FORMAT_REC gui_text_formats[];