From b87be52b56c7f62294c49c40a49c766b958d0809 Mon Sep 17 00:00:00 2001 From: sabetts Date: Sun, 15 Apr 2001 21:25:10 +0000 Subject: * src/number.h (add_window_number): new prototype * src/number.c (add_window_number): renamed from add_to_list. Dependant code updated. * src/messages.h (MESSAGE_WINDOW_INFORMATION): new define * src/list.h (print_window_information): new prototype * src/list.c (print_window_information): new function * src/actions.h (cmd_number): new prototype --- src/actions.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- src/actions.h | 1 + src/list.c | 20 ++++++++++++++++++++ src/list.h | 2 ++ src/messages.h | 1 + src/number.c | 6 +++--- src/number.h | 1 + 7 files changed, 84 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/actions.c b/src/actions.c index f65c9f4..a9ed3d7 100644 --- a/src/actions.c +++ b/src/actions.c @@ -168,13 +168,13 @@ user_command user_commands[] = {"curframe", cmd_curframe, arg_VOID}, {"help", cmd_help, arg_VOID}, {"quit", cmd_quit, arg_VOID}, + {"number", cmd_number, arg_STRING}, /* the following screen commands may or may not be able to be implemented. See the screen documentation for what should be emulated with these commands */ {"stuff", cmd_unimplemented, arg_VOID}, - {"number", cmd_unimplemented, arg_VOID}, {"hardcopy", cmd_unimplemented, arg_VOID}, {"lastmsg", cmd_unimplemented, arg_VOID}, {"license", cmd_unimplemented, arg_VOID}, @@ -523,7 +523,7 @@ cmd_rename (void *data) current_window()->named = 1; /* Update the program bar. */ - update_window_names (current_window()->scr); + update_window_names (current_screen()); } free (winname); @@ -702,7 +702,7 @@ cmd_quit(void *data) /* Show the current time on the bar. Thanks to Martin Samuelsson for the patch. Thanks to Jonathan Walther - for making it pretty. */ + for making it pretty. */ void cmd_clock (void *data) { @@ -718,6 +718,59 @@ cmd_clock (void *data) free (msg); } +/* Assign a new number to a window ala screen's number command. Thanks + to Martin Samuelsson for the original + patch. */ +void +cmd_number (void *data) +{ + int old_number, new_number; + rp_window *other_win; + char *str; + + if (current_window() == NULL) return; + + if (data == NULL) + { + print_window_information (current_window()); + return; + } + else + { + str = strdup ((char *) data); + } + + if ((new_number = string_to_window_number (str)) >= 0) + { + /* Find other window with same number and give it old number. */ + other_win = find_window_number (new_number); + if (other_win != NULL) + { + old_number = current_window()->number; + other_win->number = old_number; + + /* Resort the the window in the list */ + remove_from_list (other_win); + insert_into_list (other_win, rp_mapped_window_sentinel); + } + else + { + return_window_number (current_window()->number); + } + + current_window()->number = new_number; + add_window_number (new_number); + + /* resort the the window in the list */ + remove_from_list (current_window()); + insert_into_list (current_window(), rp_mapped_window_sentinel); + + /* Update the window list. */ + update_window_names (current_screen()); + } + + free (str); +} /* Toggle the display of the program bar */ void diff --git a/src/actions.h b/src/actions.h index e0b2cb8..19b5c02 100644 --- a/src/actions.h +++ b/src/actions.h @@ -72,6 +72,7 @@ void cmd_banish (void *data); void cmd_curframe (void *data); void cmd_help (void *data); void cmd_quit(void *data); +void cmd_number (void *data); /* void cmd_xterm (void *data); */ diff --git a/src/list.c b/src/list.c index 34517b2..750221e 100644 --- a/src/list.c +++ b/src/list.c @@ -439,3 +439,23 @@ goto_window (rp_window *win) set_active_window (win); } } + +void +print_window_information (rp_window *win) +{ + char number[3]; + char *str; + + snprintf (number, 3, "%d", win->number); + + /* There is a bit of extra memory being allocated from the + formatting tags in MESSAGE_WINDOW_INFORMATION, but it is not a + couple bytes. */ + str = xmalloc (strlen (number) + strlen (win->name) + strlen (MESSAGE_WINDOW_INFORMATION) + 1); + + sprintf (str, MESSAGE_WINDOW_INFORMATION, number, win->name); + message (str); + free (str); + + return; +} diff --git a/src/list.h b/src/list.h index 2ad0b47..8a97f92 100644 --- a/src/list.h +++ b/src/list.h @@ -50,4 +50,6 @@ void append_to_list (rp_window *win, rp_window *sentinel); void insert_into_list (rp_window *win, rp_window *sentinel); void remove_from_list (rp_window *win); +void print_window_information (rp_window *win); + #endif /* ! _RATPOISON_LIST_H */ diff --git a/src/messages.h b/src/messages.h index 0d8cbe6..23ffe3d 100644 --- a/src/messages.h +++ b/src/messages.h @@ -27,6 +27,7 @@ #define MESSAGE_NO_OTHER_WINDOW " No other window " #define MESSAGE_NO_MANAGED_WINDOWS " No managed windows " #define MESSAGE_UNKNOWN_COMMAND ": unknown command " +#define MESSAGE_WINDOW_INFORMATION "This is window %s (%s)." #define MESSAGE_PROMPT_SWITCH_TO_WINDOW " Switch to window: " #define MESSAGE_PROMPT_NEW_WINDOW_NAME " Set window's title to: " diff --git a/src/number.c b/src/number.c index 0e33e21..8676d9d 100644 --- a/src/number.c +++ b/src/number.c @@ -69,8 +69,8 @@ find_empty_cell () return num_taken-1; } -static int -add_to_list (int n) +int +add_window_number (int n) { if (number_is_taken (n)) return 0; /* failed. */ @@ -88,7 +88,7 @@ get_unique_window_number () /* look for a unique number, and add it to the list of taken numbers. */ i = 0; - while (!add_to_list (i)) i++; + while (!add_window_number (i)) i++; return i; } diff --git a/src/number.h b/src/number.h index 1a489b1..aea0945 100644 --- a/src/number.h +++ b/src/number.h @@ -24,6 +24,7 @@ int get_unique_window_number (); void return_window_number (int n); +int add_window_number (int n); void init_numbers (); #endif /* ! _RATPOISON_NUMBER_H */ -- cgit v1.2.3