mirror of
https://github.com/weechat/weechat.git
synced 2026-07-02 15:53:12 +02:00
core: add mouse support (task #5435), free cursor movement, hook_focus, fix bugs with key "^" (bug #32072, bug #21381), fix bugs with bar windows, completion and /buffer
New features and bugs fixed: - mouse support: new command /mouse, new option weechat.look.mouse, new key context "mouse" - free movement of cursor: new command /cursor, new key context "cursor" - new hook_focus (used by cursor and mouse) - info "cursor_mode" - bugs fixed with key "^" - allow plugin name in /buffer name - fix bugs with bar windows: do not create bar windows for hidden bars - fix completion bug when two words for completion are equal but with different case - automatic scroll direction in /bar scroll (x/y is now optional)
This commit is contained in:
@@ -24,6 +24,7 @@ gui-bar-window.c gui-bar-window.h
|
||||
gui-buffer.c gui-buffer.h
|
||||
gui-chat.c gui-chat.h
|
||||
gui-color.c gui-color.h
|
||||
gui-cursor.c gui-cursor.h
|
||||
gui-filter.c gui-filter.h
|
||||
gui-completion.c gui-completion.h
|
||||
gui-history.c gui-history.h
|
||||
@@ -33,6 +34,7 @@ gui-key.c gui-key.h
|
||||
gui-layout.c gui-layout.h
|
||||
gui-line.c gui-line.h
|
||||
gui-main.h
|
||||
gui-mouse.c gui-mouse.h
|
||||
gui-nicklist.c gui-nicklist.h
|
||||
gui-window.c gui-window.h)
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ lib_weechat_gui_common_a_SOURCES = gui-bar.c \
|
||||
gui-chat.h \
|
||||
gui-color.c \
|
||||
gui-color.h \
|
||||
gui-cursor.c \
|
||||
gui-cursor.h \
|
||||
gui-completion.c \
|
||||
gui-completion.h \
|
||||
gui-filter.c \
|
||||
@@ -50,6 +52,8 @@ lib_weechat_gui_common_a_SOURCES = gui-bar.c \
|
||||
gui-line.c \
|
||||
gui-line.h \
|
||||
gui-main.h \
|
||||
gui-mouse.c \
|
||||
gui-mouse.h \
|
||||
gui-nicklist.c \
|
||||
gui-nicklist.h \
|
||||
gui-window.c \
|
||||
|
||||
@@ -30,6 +30,7 @@ gui-curses-chat.c
|
||||
gui-curses-color.c
|
||||
gui-curses-key.c
|
||||
gui-curses-main.c
|
||||
gui-curses-mouse.c
|
||||
gui-curses-term.c
|
||||
gui-curses-window.c)
|
||||
|
||||
@@ -68,6 +69,8 @@ IF(LIBINTL_LIBRARY)
|
||||
LIST(APPEND EXTRA_LIBS ${LIBINTL_LIBRARY})
|
||||
ENDIF(LIBINTL_LIBRARY)
|
||||
|
||||
LIST(APPEND EXTRA_LIBS "m")
|
||||
|
||||
ADD_EXECUTABLE(${EXECUTABLE} ${WEECHAT_CURSES_SRC})
|
||||
|
||||
INCLUDE_DIRECTORIES(.. ../../core ../../plugins)
|
||||
|
||||
@@ -30,13 +30,15 @@ weechat_curses_LDADD = ./../../core/lib_weechat_core.a \
|
||||
$(PLUGINS_LFLAGS) \
|
||||
$(NCURSES_LFLAGS) \
|
||||
$(GCRYPT_LFLAGS) \
|
||||
$(GNUTLS_LFLAGS)
|
||||
$(GNUTLS_LFLAGS) \
|
||||
-lm
|
||||
|
||||
weechat_curses_SOURCES = gui-curses-bar-window.c \
|
||||
gui-curses-chat.c \
|
||||
gui-curses-color.c \
|
||||
gui-curses-key.c \
|
||||
gui-curses-main.c \
|
||||
gui-curses-mouse.c \
|
||||
gui-curses-term.c \
|
||||
gui-curses-window.c \
|
||||
gui-curses.h
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "../gui-bar-window.h"
|
||||
#include "../gui-chat.h"
|
||||
#include "../gui-color.h"
|
||||
#include "../gui-cursor.h"
|
||||
#include "../gui-window.h"
|
||||
#include "gui-curses.h"
|
||||
|
||||
@@ -89,6 +90,9 @@ gui_bar_window_objects_free (struct t_gui_bar_window *bar_window)
|
||||
void
|
||||
gui_bar_window_create_win (struct t_gui_bar_window *bar_window)
|
||||
{
|
||||
if (CONFIG_BOOLEAN(bar_window->bar->options[GUI_BAR_OPTION_HIDDEN]))
|
||||
return;
|
||||
|
||||
if (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar)
|
||||
{
|
||||
delwin (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
|
||||
@@ -152,14 +156,15 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
|
||||
int *x, int *y,
|
||||
const char *string,
|
||||
int reset_color_before_display,
|
||||
int hide_chars_if_scrolling)
|
||||
int hide_chars_if_scrolling,
|
||||
int *index_item, int *index_subitem, int *index_line)
|
||||
{
|
||||
int x_with_hidden, size_on_screen, low_char, hidden;
|
||||
char utf_char[16], *next_char, *output;
|
||||
|
||||
if (!string || !string[0])
|
||||
return 1;
|
||||
|
||||
|
||||
wmove (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, *y, *x);
|
||||
|
||||
if (reset_color_before_display)
|
||||
@@ -239,6 +244,40 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
|
||||
bar_window->cursor_x += bar_window->x;
|
||||
bar_window->cursor_y += bar_window->y;
|
||||
break;
|
||||
case GUI_COLOR_BAR_START_ITEM:
|
||||
string += 2;
|
||||
if (*index_item < 0)
|
||||
{
|
||||
*index_item = 0;
|
||||
*index_subitem = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
(*index_subitem)++;
|
||||
if (*index_subitem >= bar_window->items_subcount[*index_item])
|
||||
{
|
||||
(*index_item)++;
|
||||
*index_subitem = 0;
|
||||
}
|
||||
}
|
||||
*index_line = 0;
|
||||
gui_bar_window_coords_add (bar_window,
|
||||
(*index_item >= bar_window->items_count) ? -1 : *index_item,
|
||||
(*index_item >= bar_window->items_count) ? -1 : *index_subitem,
|
||||
*index_line,
|
||||
*x + bar_window->x,
|
||||
*y + bar_window->y);
|
||||
break;
|
||||
case GUI_COLOR_BAR_START_LINE_ITEM:
|
||||
string += 2;
|
||||
(*index_line)++;
|
||||
gui_bar_window_coords_add (bar_window,
|
||||
*index_item,
|
||||
*index_subitem,
|
||||
*index_line,
|
||||
*x + bar_window->x,
|
||||
*y + bar_window->y);
|
||||
break;
|
||||
default:
|
||||
string++;
|
||||
break;
|
||||
@@ -353,10 +392,11 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
|
||||
int length_screen_before_cursor, length_screen_after_cursor;
|
||||
int diff, max_length, optimal_number_of_lines;
|
||||
int some_data_not_displayed, separator_horizontal, separator_vertical;
|
||||
int index_item, index_subitem, index_line;
|
||||
|
||||
if (!gui_init_ok)
|
||||
return;
|
||||
|
||||
|
||||
if (!str_start_input[0])
|
||||
{
|
||||
snprintf (str_start_input, sizeof (str_start_input), "%c%c%c",
|
||||
@@ -384,6 +424,12 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
|
||||
bar_window->cursor_x = -1;
|
||||
bar_window->cursor_y = -1;
|
||||
|
||||
/* remove coords */
|
||||
gui_bar_window_coords_free (bar_window);
|
||||
index_item = -1;
|
||||
index_subitem = -1;
|
||||
index_line = 0;
|
||||
|
||||
filling = gui_bar_get_filling (bar_window->bar);
|
||||
|
||||
content = gui_bar_window_content_get_with_filling (bar_window, window);
|
||||
@@ -547,7 +593,10 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
|
||||
{
|
||||
if (!gui_bar_window_print_string (bar_window, filling,
|
||||
&x, &y,
|
||||
items[line], 1, 1))
|
||||
items[line], 1, 1,
|
||||
&index_item,
|
||||
&index_subitem,
|
||||
&index_line))
|
||||
{
|
||||
some_data_not_displayed = 1;
|
||||
}
|
||||
@@ -571,7 +620,10 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
|
||||
while (x < bar_window->width)
|
||||
{
|
||||
gui_bar_window_print_string (bar_window, filling,
|
||||
&x, &y, " ", 0, 0);
|
||||
&x, &y, " ", 0, 0,
|
||||
&index_item,
|
||||
&index_subitem,
|
||||
&index_line);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,7 +670,7 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
|
||||
CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]),
|
||||
CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* move cursor if it was asked in an item content (input_text does that
|
||||
* to move cursor in user input text)
|
||||
@@ -632,7 +684,12 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
|
||||
x = bar_window->width - 2;
|
||||
wmove (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, y, x);
|
||||
wrefresh (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
|
||||
move (bar_window->cursor_y, bar_window->cursor_x);
|
||||
if (!gui_cursor_mode)
|
||||
{
|
||||
gui_window_cursor_x = bar_window->cursor_x;
|
||||
gui_window_cursor_y = bar_window->cursor_y;
|
||||
move (bar_window->cursor_y, bar_window->cursor_x);
|
||||
}
|
||||
}
|
||||
else
|
||||
wnoutrefresh (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
|
||||
|
||||
@@ -209,6 +209,8 @@ gui_chat_string_next_char (struct t_gui_window *window,
|
||||
case GUI_COLOR_BAR_START_INPUT_CHAR:
|
||||
case GUI_COLOR_BAR_START_INPUT_HIDDEN_CHAR:
|
||||
case GUI_COLOR_BAR_MOVE_CURSOR_CHAR:
|
||||
case GUI_COLOR_BAR_START_ITEM:
|
||||
case GUI_COLOR_BAR_START_LINE_ITEM:
|
||||
string++;
|
||||
break;
|
||||
}
|
||||
|
||||
+200
-155
@@ -40,8 +40,10 @@
|
||||
#include "../gui-key.h"
|
||||
#include "../gui-buffer.h"
|
||||
#include "../gui-color.h"
|
||||
#include "../gui-input.h"
|
||||
#include "../gui-cursor.h"
|
||||
#include "../gui-completion.h"
|
||||
#include "../gui-input.h"
|
||||
#include "../gui-mouse.h"
|
||||
#include "../gui-window.h"
|
||||
#include "gui-curses.h"
|
||||
|
||||
@@ -79,145 +81,193 @@ gui_key_default_bindings (int context)
|
||||
int i;
|
||||
char key_str[32], command[32];
|
||||
|
||||
switch (context)
|
||||
if (context == GUI_KEY_CONTEXT_DEFAULT)
|
||||
{
|
||||
case GUI_KEY_CONTEXT_DEFAULT:
|
||||
BIND(/* RC */ "ctrl-M", "/input return");
|
||||
BIND(/* RC */ "ctrl-J", "/input return");
|
||||
BIND(/* tab */ "ctrl-I", "/input complete_next");
|
||||
BIND(/* s-tab */ "meta2-Z", "/input complete_previous");
|
||||
BIND(/* ^R */ "ctrl-R", "/input search_text");
|
||||
BIND(/* basckpace */ "ctrl-H", "/input delete_previous_char");
|
||||
BIND(/* basckpace */ "ctrl-?", "/input delete_previous_char");
|
||||
BIND(/* ^_ */ "ctrl-_", "/input undo");
|
||||
BIND(/* m-_ */ "meta-_", "/input redo");
|
||||
BIND(/* del */ "meta2-3~", "/input delete_next_char");
|
||||
BIND(/* ^D */ "ctrl-D", "/input delete_next_char");
|
||||
BIND(/* ^W */ "ctrl-W", "/input delete_previous_word");
|
||||
BIND(/* ^X */ "ctrl-X", "/input switch_active_buffer");
|
||||
BIND(/* m-d */ "meta-d", "/input delete_next_word");
|
||||
BIND(/* ^K */ "ctrl-K", "/input delete_end_of_line");
|
||||
BIND(/* m-r */ "meta-r", "/input delete_line");
|
||||
BIND(/* ^T */ "ctrl-T", "/input transpose_chars");
|
||||
BIND(/* ^U */ "ctrl-U", "/input delete_beginning_of_line");
|
||||
BIND(/* ^Y */ "ctrl-Y", "/input clipboard_paste");
|
||||
BIND(/* home */ "meta2-1~", "/input move_beginning_of_line");
|
||||
BIND(/* home */ "meta2-H", "/input move_beginning_of_line");
|
||||
BIND(/* home */ "meta2-7~", "/input move_beginning_of_line");
|
||||
BIND(/* home */ "meta-OH", "/input move_beginning_of_line");
|
||||
BIND(/* ^A */ "ctrl-A", "/input move_beginning_of_line");
|
||||
BIND(/* end */ "meta2-4~", "/input move_end_of_line");
|
||||
BIND(/* end */ "meta2-F", "/input move_end_of_line");
|
||||
BIND(/* end */ "meta2-8~", "/input move_end_of_line");
|
||||
BIND(/* end */ "meta-OF", "/input move_end_of_line");
|
||||
BIND(/* ^E */ "ctrl-E", "/input move_end_of_line");
|
||||
BIND(/* left */ "meta2-D", "/input move_previous_char");
|
||||
BIND(/* ^B */ "ctrl-B", "/input move_previous_char");
|
||||
BIND(/* right */ "meta2-C", "/input move_next_char");
|
||||
BIND(/* ^F */ "ctrl-F", "/input move_next_char");
|
||||
BIND(/* m-b */ "meta-b", "/input move_previous_word");
|
||||
BIND(/* ^left */ "meta-Od", "/input move_previous_word");
|
||||
BIND(/* ^left */ "meta-OD", "/input move_previous_word");
|
||||
BIND(/* m-f */ "meta-f", "/input move_next_word");
|
||||
BIND(/* ^right */ "meta-Oc", "/input move_next_word");
|
||||
BIND(/* ^right */ "meta-OC", "/input move_next_word");
|
||||
BIND(/* up */ "meta2-A", "/input history_previous");
|
||||
BIND(/* down */ "meta2-B", "/input history_next");
|
||||
BIND(/* ^up */ "meta-Oa", "/input history_global_previous");
|
||||
BIND(/* ^up */ "meta-OA", "/input history_global_previous");
|
||||
BIND(/* ^up */ "meta2-1;5A", "/input history_global_previous");
|
||||
BIND(/* ^down */ "meta-Ob", "/input history_global_next");
|
||||
BIND(/* ^down */ "meta-OB", "/input history_global_next");
|
||||
BIND(/* ^down */ "meta2-1;5B", "/input history_global_next");
|
||||
BIND(/* m-a */ "meta-a", "/input jump_smart");
|
||||
BIND(/* m-j,m-l */ "meta-jmeta-l", "/input jump_last_buffer");
|
||||
BIND(/* m-j,m-r */ "meta-jmeta-r", "/server raw");
|
||||
BIND(/* m-j,m-s */ "meta-jmeta-s", "/server jump");
|
||||
BIND(/* m-h */ "meta-h", "/input hotlist_clear");
|
||||
BIND(/* m-k */ "meta-k", "/input grab_key_command");
|
||||
BIND(/* m-u */ "meta-u", "/input scroll_unread");
|
||||
BIND(/* ^S^U */ "ctrl-Sctrl-U", "/input set_unread");
|
||||
BIND(/* ^Cb */ "ctrl-Cb", "/input insert \\x02");
|
||||
BIND(/* ^Cc */ "ctrl-Cc", "/input insert \\x03");
|
||||
BIND(/* ^Ci */ "ctrl-Ci", "/input insert \\x1D");
|
||||
BIND(/* ^Co */ "ctrl-Co", "/input insert \\x0F");
|
||||
BIND(/* ^Cr */ "ctrl-Cr", "/input insert \\x12");
|
||||
BIND(/* ^Cu */ "ctrl-Cu", "/input insert \\x15");
|
||||
BIND(/* m-right */ "meta-meta2-C", "/buffer +1");
|
||||
BIND(/* m-right */ "meta2-1;3C", "/buffer +1");
|
||||
BIND(/* m-down */ "meta-meta2-B", "/buffer +1");
|
||||
BIND(/* m-down */ "meta2-1;3B", "/buffer +1");
|
||||
BIND(/* F6 */ "meta2-17~", "/buffer +1");
|
||||
BIND(/* ^N */ "ctrl-N", "/buffer +1");
|
||||
BIND(/* m-left */ "meta-meta2-D", "/buffer -1");
|
||||
BIND(/* m-left */ "meta2-1;3D", "/buffer -1");
|
||||
BIND(/* m-up */ "meta-meta2-A", "/buffer -1");
|
||||
BIND(/* m-up */ "meta2-1;3A", "/buffer -1");
|
||||
BIND(/* F5 */ "meta2-15~", "/buffer -1");
|
||||
BIND(/* ^P */ "ctrl-P", "/buffer -1");
|
||||
BIND(/* pgup */ "meta2-5~", "/window page_up");
|
||||
BIND(/* pgup */ "meta2-I", "/window page_up");
|
||||
BIND(/* pgdn */ "meta2-6~", "/window page_down");
|
||||
BIND(/* pgdn */ "meta2-G", "/window page_down");
|
||||
BIND(/* m-pgup */ "meta-meta2-5~", "/window scroll_up");
|
||||
BIND(/* m-pgup */ "meta2-5;3~", "/window scroll_up");
|
||||
BIND(/* m-pgdn */ "meta-meta2-6~", "/window scroll_down");
|
||||
BIND(/* m-pgdn */ "meta2-6;3~", "/window scroll_down");
|
||||
BIND(/* m-home */ "meta-meta2-1~", "/window scroll_top");
|
||||
BIND(/* m-home */ "meta-meta2-7~", "/window scroll_top");
|
||||
BIND(/* m-end */ "meta-meta2-4~", "/window scroll_bottom");
|
||||
BIND(/* m-end */ "meta-meta2-8~", "/window scroll_bottom");
|
||||
BIND(/* m-n */ "meta-n", "/window scroll_next_highlight");
|
||||
BIND(/* m-p */ "meta-p", "/window scroll_previous_highlight");
|
||||
BIND(/* F9 */ "meta2-20~", "/bar scroll title * x-50%");
|
||||
BIND(/* F10 */ "meta2-21~", "/bar scroll title * x+50%");
|
||||
BIND(/* F11 */ "meta2-23~", "/bar scroll nicklist * y-100%");
|
||||
BIND(/* F12 */ "meta2-24~", "/bar scroll nicklist * y+100%");
|
||||
BIND(/* m-F11 */ "meta-meta2-23~", "/bar scroll nicklist * yb");
|
||||
BIND(/* m-F12 */ "meta-meta2-24~", "/bar scroll nicklist * ye");
|
||||
BIND(/* ^L */ "ctrl-L", "/window refresh");
|
||||
BIND(/* F7 */ "meta2-18~", "/window -1");
|
||||
BIND(/* F8 */ "meta2-19~", "/window +1");
|
||||
BIND(/* m-w,m-up */ "meta-wmeta-meta2-A", "/window up");
|
||||
BIND(/* m-w,m-up */ "meta-wmeta2-1;3A", "/window up");
|
||||
BIND(/* m-w,m-down */ "meta-wmeta-meta2-B", "/window down");
|
||||
BIND(/* m-w,m-down */ "meta-wmeta2-1;3B", "/window down");
|
||||
BIND(/* m-w,m-right */ "meta-wmeta-meta2-C", "/window right");
|
||||
BIND(/* m-w,m-right */ "meta-wmeta2-1;3C", "/window right");
|
||||
BIND(/* m-w,m-left */ "meta-wmeta-meta2-D", "/window left");
|
||||
BIND(/* m-w,m-left */ "meta-wmeta2-1;3D", "/window left");
|
||||
BIND(/* m-w,m-b */ "meta-wmeta-b", "/window balance");
|
||||
BIND(/* m-w,m-s */ "meta-wmeta-s", "/window swap");
|
||||
BIND(/* m-z */ "meta-z", "/window zoom");
|
||||
BIND(/* m-= */ "meta-=", "/filter toggle");
|
||||
BIND(/* m-0 */ "meta-0", "/buffer *10");
|
||||
BIND(/* m-1 */ "meta-1", "/buffer *1");
|
||||
BIND(/* m-2 */ "meta-2", "/buffer *2");
|
||||
BIND(/* m-3 */ "meta-3", "/buffer *3");
|
||||
BIND(/* m-4 */ "meta-4", "/buffer *4");
|
||||
BIND(/* m-5 */ "meta-5", "/buffer *5");
|
||||
BIND(/* m-6 */ "meta-6", "/buffer *6");
|
||||
BIND(/* m-7 */ "meta-7", "/buffer *7");
|
||||
BIND(/* m-8 */ "meta-8", "/buffer *8");
|
||||
BIND(/* m-9 */ "meta-9", "/buffer *9");
|
||||
BIND(/* m-< */ "meta-<", "/input jump_previously_visited_buffer");
|
||||
BIND(/* m-> */ "meta->", "/input jump_next_visited_buffer");
|
||||
|
||||
/* bind meta-j + {01..99} to switch to buffers # > 10 */
|
||||
for (i = 1; i < 100; i++)
|
||||
{
|
||||
sprintf (key_str, "meta-j%02d", i);
|
||||
sprintf (command, "/buffer %d", i);
|
||||
BIND(key_str, command);
|
||||
}
|
||||
break;
|
||||
case GUI_KEY_CONTEXT_SEARCH:
|
||||
BIND(/* RC */ "ctrl-M", "/input search_stop");
|
||||
BIND(/* RC */ "ctrl-J", "/input search_stop");
|
||||
BIND(/* ^R */ "ctrl-R", "/input search_switch_case");
|
||||
BIND(/* up */ "meta2-A", "/input search_previous");
|
||||
BIND(/* down */ "meta2-B", "/input search_next");
|
||||
break;
|
||||
BIND(/* Enter */ "ctrl-M", "/input return");
|
||||
BIND(/* Enter */ "ctrl-J", "/input return");
|
||||
BIND(/* tab */ "ctrl-I", "/input complete_next");
|
||||
BIND(/* s-tab */ "meta2-Z", "/input complete_previous");
|
||||
BIND(/* ^R */ "ctrl-R", "/input search_text");
|
||||
BIND(/* basckpace */ "ctrl-H", "/input delete_previous_char");
|
||||
BIND(/* basckpace */ "ctrl-?", "/input delete_previous_char");
|
||||
BIND(/* ^_ */ "ctrl-_", "/input undo");
|
||||
BIND(/* m-_ */ "meta-_", "/input redo");
|
||||
BIND(/* del */ "meta2-3~", "/input delete_next_char");
|
||||
BIND(/* ^D */ "ctrl-D", "/input delete_next_char");
|
||||
BIND(/* ^W */ "ctrl-W", "/input delete_previous_word");
|
||||
BIND(/* ^X */ "ctrl-X", "/input switch_active_buffer");
|
||||
BIND(/* m-d */ "meta-d", "/input delete_next_word");
|
||||
BIND(/* ^K */ "ctrl-K", "/input delete_end_of_line");
|
||||
BIND(/* m-r */ "meta-r", "/input delete_line");
|
||||
BIND(/* ^T */ "ctrl-T", "/input transpose_chars");
|
||||
BIND(/* ^U */ "ctrl-U", "/input delete_beginning_of_line");
|
||||
BIND(/* ^Y */ "ctrl-Y", "/input clipboard_paste");
|
||||
BIND(/* home */ "meta2-1~", "/input move_beginning_of_line");
|
||||
BIND(/* home */ "meta2-H", "/input move_beginning_of_line");
|
||||
BIND(/* home */ "meta2-7~", "/input move_beginning_of_line");
|
||||
BIND(/* home */ "meta-OH", "/input move_beginning_of_line");
|
||||
BIND(/* ^A */ "ctrl-A", "/input move_beginning_of_line");
|
||||
BIND(/* end */ "meta2-4~", "/input move_end_of_line");
|
||||
BIND(/* end */ "meta2-F", "/input move_end_of_line");
|
||||
BIND(/* end */ "meta2-8~", "/input move_end_of_line");
|
||||
BIND(/* end */ "meta-OF", "/input move_end_of_line");
|
||||
BIND(/* ^E */ "ctrl-E", "/input move_end_of_line");
|
||||
BIND(/* left */ "meta2-D", "/input move_previous_char");
|
||||
BIND(/* ^B */ "ctrl-B", "/input move_previous_char");
|
||||
BIND(/* right */ "meta2-C", "/input move_next_char");
|
||||
BIND(/* ^F */ "ctrl-F", "/input move_next_char");
|
||||
BIND(/* m-b */ "meta-b", "/input move_previous_word");
|
||||
BIND(/* ^left */ "meta-Od", "/input move_previous_word");
|
||||
BIND(/* ^left */ "meta-OD", "/input move_previous_word");
|
||||
BIND(/* m-f */ "meta-f", "/input move_next_word");
|
||||
BIND(/* ^right */ "meta-Oc", "/input move_next_word");
|
||||
BIND(/* ^right */ "meta-OC", "/input move_next_word");
|
||||
BIND(/* up */ "meta2-A", "/input history_previous");
|
||||
BIND(/* down */ "meta2-B", "/input history_next");
|
||||
BIND(/* ^up */ "meta-Oa", "/input history_global_previous");
|
||||
BIND(/* ^up */ "meta-OA", "/input history_global_previous");
|
||||
BIND(/* ^up */ "meta2-1;5A", "/input history_global_previous");
|
||||
BIND(/* ^down */ "meta-Ob", "/input history_global_next");
|
||||
BIND(/* ^down */ "meta-OB", "/input history_global_next");
|
||||
BIND(/* ^down */ "meta2-1;5B", "/input history_global_next");
|
||||
BIND(/* m-a */ "meta-a", "/input jump_smart");
|
||||
BIND(/* m-j,m-l */ "meta-jmeta-l", "/input jump_last_buffer");
|
||||
BIND(/* m-j,m-r */ "meta-jmeta-r", "/server raw");
|
||||
BIND(/* m-j,m-s */ "meta-jmeta-s", "/server jump");
|
||||
BIND(/* m-h */ "meta-h", "/input hotlist_clear");
|
||||
BIND(/* m-k */ "meta-k", "/input grab_key_command");
|
||||
BIND(/* m-u */ "meta-u", "/input scroll_unread");
|
||||
BIND(/* ^S^U */ "ctrl-Sctrl-U", "/input set_unread");
|
||||
BIND(/* ^Cb */ "ctrl-Cb", "/input insert \\x02");
|
||||
BIND(/* ^Cc */ "ctrl-Cc", "/input insert \\x03");
|
||||
BIND(/* ^Ci */ "ctrl-Ci", "/input insert \\x1D");
|
||||
BIND(/* ^Co */ "ctrl-Co", "/input insert \\x0F");
|
||||
BIND(/* ^Cr */ "ctrl-Cr", "/input insert \\x12");
|
||||
BIND(/* ^Cu */ "ctrl-Cu", "/input insert \\x15");
|
||||
BIND(/* m-right */ "meta-meta2-C", "/buffer +1");
|
||||
BIND(/* m-right */ "meta2-1;3C", "/buffer +1");
|
||||
BIND(/* m-down */ "meta-meta2-B", "/buffer +1");
|
||||
BIND(/* m-down */ "meta2-1;3B", "/buffer +1");
|
||||
BIND(/* F6 */ "meta2-17~", "/buffer +1");
|
||||
BIND(/* ^N */ "ctrl-N", "/buffer +1");
|
||||
BIND(/* m-left */ "meta-meta2-D", "/buffer -1");
|
||||
BIND(/* m-left */ "meta2-1;3D", "/buffer -1");
|
||||
BIND(/* m-up */ "meta-meta2-A", "/buffer -1");
|
||||
BIND(/* m-up */ "meta2-1;3A", "/buffer -1");
|
||||
BIND(/* F5 */ "meta2-15~", "/buffer -1");
|
||||
BIND(/* ^P */ "ctrl-P", "/buffer -1");
|
||||
BIND(/* pgup */ "meta2-5~", "/window page_up");
|
||||
BIND(/* pgup */ "meta2-I", "/window page_up");
|
||||
BIND(/* pgdn */ "meta2-6~", "/window page_down");
|
||||
BIND(/* pgdn */ "meta2-G", "/window page_down");
|
||||
BIND(/* m-pgup */ "meta-meta2-5~", "/window scroll_up");
|
||||
BIND(/* m-pgup */ "meta2-5;3~", "/window scroll_up");
|
||||
BIND(/* m-pgdn */ "meta-meta2-6~", "/window scroll_down");
|
||||
BIND(/* m-pgdn */ "meta2-6;3~", "/window scroll_down");
|
||||
BIND(/* m-home */ "meta-meta2-1~", "/window scroll_top");
|
||||
BIND(/* m-home */ "meta-meta2-7~", "/window scroll_top");
|
||||
BIND(/* m-end */ "meta-meta2-4~", "/window scroll_bottom");
|
||||
BIND(/* m-end */ "meta-meta2-8~", "/window scroll_bottom");
|
||||
BIND(/* m-n */ "meta-n", "/window scroll_next_highlight");
|
||||
BIND(/* m-p */ "meta-p", "/window scroll_previous_highlight");
|
||||
BIND(/* F9 */ "meta2-20~", "/bar scroll title * -30%");
|
||||
BIND(/* F10 */ "meta2-21~", "/bar scroll title * +30%");
|
||||
BIND(/* F11 */ "meta2-23~", "/bar scroll nicklist * -100%");
|
||||
BIND(/* F12 */ "meta2-24~", "/bar scroll nicklist * +100%");
|
||||
BIND(/* m-F11 */ "meta-meta2-23~", "/bar scroll nicklist * b");
|
||||
BIND(/* m-F12 */ "meta-meta2-24~", "/bar scroll nicklist * e");
|
||||
BIND(/* ^L */ "ctrl-L", "/window refresh");
|
||||
BIND(/* F7 */ "meta2-18~", "/window -1");
|
||||
BIND(/* F8 */ "meta2-19~", "/window +1");
|
||||
BIND(/* m-w,m-up */ "meta-wmeta-meta2-A", "/window up");
|
||||
BIND(/* m-w,m-up */ "meta-wmeta2-1;3A", "/window up");
|
||||
BIND(/* m-w,m-down */ "meta-wmeta-meta2-B", "/window down");
|
||||
BIND(/* m-w,m-down */ "meta-wmeta2-1;3B", "/window down");
|
||||
BIND(/* m-w,m-right */ "meta-wmeta-meta2-C", "/window right");
|
||||
BIND(/* m-w,m-right */ "meta-wmeta2-1;3C", "/window right");
|
||||
BIND(/* m-w,m-left */ "meta-wmeta-meta2-D", "/window left");
|
||||
BIND(/* m-w,m-left */ "meta-wmeta2-1;3D", "/window left");
|
||||
BIND(/* m-w,m-b */ "meta-wmeta-b", "/window balance");
|
||||
BIND(/* m-w,m-s */ "meta-wmeta-s", "/window swap");
|
||||
BIND(/* m-z */ "meta-z", "/window zoom");
|
||||
BIND(/* m-= */ "meta-=", "/filter toggle");
|
||||
BIND(/* m-0 */ "meta-0", "/buffer *10");
|
||||
BIND(/* m-1 */ "meta-1", "/buffer *1");
|
||||
BIND(/* m-2 */ "meta-2", "/buffer *2");
|
||||
BIND(/* m-3 */ "meta-3", "/buffer *3");
|
||||
BIND(/* m-4 */ "meta-4", "/buffer *4");
|
||||
BIND(/* m-5 */ "meta-5", "/buffer *5");
|
||||
BIND(/* m-6 */ "meta-6", "/buffer *6");
|
||||
BIND(/* m-7 */ "meta-7", "/buffer *7");
|
||||
BIND(/* m-8 */ "meta-8", "/buffer *8");
|
||||
BIND(/* m-9 */ "meta-9", "/buffer *9");
|
||||
BIND(/* m-< */ "meta-<", "/input jump_previously_visited_buffer");
|
||||
BIND(/* m-> */ "meta->", "/input jump_next_visited_buffer");
|
||||
BIND(/* mouse */ "meta2-M", "/mouse grab");
|
||||
BIND(/* m-m */ "meta-m", "/mouse toggle");
|
||||
|
||||
/* bind meta-j + {01..99} to switch to buffers # > 10 */
|
||||
for (i = 1; i < 100; i++)
|
||||
{
|
||||
sprintf (key_str, "meta-j%02d", i);
|
||||
sprintf (command, "/buffer %d", i);
|
||||
BIND(key_str, command);
|
||||
}
|
||||
}
|
||||
else if (context == GUI_KEY_CONTEXT_SEARCH)
|
||||
{
|
||||
BIND(/* Enter */ "ctrl-M", "/input search_stop");
|
||||
BIND(/* Enter */ "ctrl-J", "/input search_stop");
|
||||
BIND(/* ^R */ "ctrl-R", "/input search_switch_case");
|
||||
BIND(/* up */ "meta2-A", "/input search_previous");
|
||||
BIND(/* down */ "meta2-B", "/input search_next");
|
||||
}
|
||||
else if (context == GUI_KEY_CONTEXT_CURSOR)
|
||||
{
|
||||
BIND(/* Enter */ "ctrl-M", "/cursor stop");
|
||||
BIND(/* Enter */ "ctrl-J", "/cursor stop");
|
||||
BIND(/* up */ "meta2-A", "/cursor move up");
|
||||
BIND(/* down */ "meta2-B", "/cursor move down");
|
||||
BIND(/* left */ "meta2-D", "/cursor move left");
|
||||
BIND(/* right */ "meta2-C", "/cursor move right");
|
||||
BIND(/* m-up */ "meta-meta2-A", "/cursor move area_up");
|
||||
BIND(/* m-up */ "meta2-1;3A", "/cursor move area_up");
|
||||
BIND(/* m-down */ "meta-meta2-B", "/cursor move area_down");
|
||||
BIND(/* m-down */ "meta2-1;3B", "/cursor move area_down");
|
||||
BIND(/* m-left */ "meta-meta2-D", "/cursor move area_left");
|
||||
BIND(/* m-left */ "meta2-1;3D", "/cursor move area_left");
|
||||
BIND(/* m-right */ "meta-meta2-C", "/cursor move area_right");
|
||||
BIND(/* m-right */ "meta2-1;3C", "/cursor move area_right");
|
||||
BIND(/* b */ "@item(buffer_nicklist):b", "/ban ${nick}");
|
||||
BIND(/* k */ "@item(buffer_nicklist):k", "/kick ${nick}");
|
||||
BIND(/* K */ "@item(buffer_nicklist):K", "/kickban ${nick}");
|
||||
BIND(/* q */ "@item(buffer_nicklist):q", "/query ${nick};/cursor stop");
|
||||
BIND(/* w */ "@item(buffer_nicklist):w", "/whois ${nick}");
|
||||
}
|
||||
else if (context == GUI_KEY_CONTEXT_MOUSE)
|
||||
{
|
||||
/* mouse events on chat area */
|
||||
BIND("@chat:button1-gesture-left", "/buffer -1");
|
||||
BIND("@chat:button1-gesture-right", "/buffer +1");
|
||||
BIND("@chat:button1-gesture-left-long", "/buffer 1");
|
||||
BIND("@chat:button1-gesture-right-long", "/input jump_last_buffer");
|
||||
BIND("@chat:wheelup", "/window scroll_up");
|
||||
BIND("@chat:wheeldown", "/window scroll_down");
|
||||
/* mouse events on nicklist */
|
||||
BIND("@bar(nicklist):button1-gesture-up", "/bar scroll nicklist * -100%");
|
||||
BIND("@bar(nicklist):button1-gesture-down", "/bar scroll nicklist * +100%");
|
||||
BIND("@bar(nicklist):button1-gesture-up-long", "/bar scroll nicklist * b");
|
||||
BIND("@bar(nicklist):button1-gesture-down-long", "/bar scroll nicklist * e");
|
||||
BIND("@item(buffer_nicklist):button1", "/query ${nick}");
|
||||
BIND("@item(buffer_nicklist):button2", "/whois ${nick}");
|
||||
BIND("@item(buffer_nicklist):button1-gesture-left", "/kick ${nick}");
|
||||
BIND("@item(buffer_nicklist):button1-gesture-left-long", "/kickban ${nick}");
|
||||
BIND("@item(buffer_nicklist):button2-gesture-left", "/ban ${nick}");
|
||||
/* mouse wheel on any bar */
|
||||
BIND("@bar(*):wheelup", "/bar scroll ${_bar_name} * -10%");
|
||||
BIND("@bar(*):wheeldown", "/bar scroll ${_bar_name} * +10%");
|
||||
/* middle click to enable cursor mode at position */
|
||||
BIND("@*:button3", "/cursor go ${_x},${_y}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,16 +296,22 @@ gui_key_flush ()
|
||||
|
||||
insert_ok = 1;
|
||||
|
||||
if (key < 32)
|
||||
if (gui_mouse_grab)
|
||||
{
|
||||
insert_ok = 0;
|
||||
key_str[0] = '^';
|
||||
key_str[0] = (char) key;
|
||||
key_str[1] = '\0';
|
||||
}
|
||||
else if (key < 32)
|
||||
{
|
||||
insert_ok = 0;
|
||||
key_str[0] = '\x01';
|
||||
key_str[1] = (char) key + '@';
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
else if (key == 127)
|
||||
{
|
||||
key_str[0] = '^';
|
||||
key_str[0] = '\x01';
|
||||
key_str[1] = '?';
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
@@ -339,12 +395,6 @@ gui_key_flush ()
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp (key_str, "^") == 0)
|
||||
{
|
||||
key_str[1] = '^';
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
|
||||
hook_signal_send ("key_pressed",
|
||||
WEECHAT_HOOK_SIGNAL_STRING, key_str);
|
||||
|
||||
@@ -354,11 +404,9 @@ gui_key_flush ()
|
||||
else
|
||||
input_old = NULL;
|
||||
|
||||
if ((gui_key_pressed (key_str) != 0) && (insert_ok))
|
||||
if ((gui_key_pressed (key_str) != 0) && (insert_ok)
|
||||
&& (!gui_cursor_mode))
|
||||
{
|
||||
if (strcmp (key_str, "^^") == 0)
|
||||
key_str[1] = '\0';
|
||||
|
||||
gui_buffer_undo_snap (gui_current_window->buffer);
|
||||
gui_input_insert_string (gui_current_window->buffer,
|
||||
key_str, -1);
|
||||
@@ -405,9 +453,6 @@ gui_key_flush ()
|
||||
free (input_old);
|
||||
}
|
||||
|
||||
if (gui_key_grab && (gui_key_grab_count > 0))
|
||||
gui_key_grab_end ();
|
||||
|
||||
gui_key_buffer_reset ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,10 +48,12 @@
|
||||
#include "../gui-buffer.h"
|
||||
#include "../gui-chat.h"
|
||||
#include "../gui-color.h"
|
||||
#include "../gui-cursor.h"
|
||||
#include "../gui-filter.h"
|
||||
#include "../gui-input.h"
|
||||
#include "../gui-layout.h"
|
||||
#include "../gui-history.h"
|
||||
#include "../gui-mouse.h"
|
||||
#include "../gui-nicklist.h"
|
||||
#include "../gui-window.h"
|
||||
#include "gui-curses.h"
|
||||
@@ -149,7 +151,7 @@ gui_main_init ()
|
||||
|
||||
/*
|
||||
* create bar windows for root bars (they were read from config,
|
||||
* but no window was created (GUI was not initialized)
|
||||
* but no window was created, GUI was not initialized)
|
||||
*/
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
{
|
||||
@@ -166,6 +168,11 @@ gui_main_init ()
|
||||
gui_bar_window_create_win (ptr_bar_win);
|
||||
}
|
||||
}
|
||||
|
||||
if (CONFIG_BOOLEAN(config_look_mouse))
|
||||
gui_mouse_enable ();
|
||||
else
|
||||
gui_mouse_disable ();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -277,7 +284,6 @@ gui_main_refreshs ()
|
||||
}
|
||||
|
||||
/* refresh bars if needed */
|
||||
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
{
|
||||
if (ptr_bar->bar_refresh_needed)
|
||||
@@ -285,6 +291,10 @@ gui_main_refreshs ()
|
||||
gui_bar_draw (ptr_bar);
|
||||
}
|
||||
}
|
||||
|
||||
/* move cursor (for cursor mode) */
|
||||
if (gui_cursor_mode)
|
||||
gui_window_move_cursor ();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -387,6 +397,9 @@ gui_main_end (int clean_exit)
|
||||
gui_main_refreshs ();
|
||||
}
|
||||
|
||||
/* disable mouse */
|
||||
gui_mouse_disable ();
|
||||
|
||||
/* remove bar items and bars */
|
||||
gui_bar_item_end ();
|
||||
gui_bar_free_all ();
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Sebastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat 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 WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* gui-curses-mouse.c: mouse functions for Curses GUI
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "../../core/weechat.h"
|
||||
#include "../../core/wee-config.h"
|
||||
#include "../gui-chat.h"
|
||||
#include "../gui-mouse.h"
|
||||
|
||||
|
||||
/*
|
||||
* gui_mouse_enable: enable mouse
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_enable ()
|
||||
{
|
||||
gui_mouse_enabled = 1;
|
||||
fprintf (stderr, "\033[?1005h\033[?1000h\033[?1002h");
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_disable: disable mouse
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_disable ()
|
||||
{
|
||||
gui_mouse_enabled = 0;
|
||||
fprintf (stderr, "\033[?1002l\033[?1000l\033[?1005l");
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_display_state: display state of mouse
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_display_state ()
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
(CONFIG_BOOLEAN(config_look_mouse)) ?
|
||||
_("Mouse is enabled") : _("Mouse is disabled"));
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_grab_init: init "grab mouse" mode
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_grab_init ()
|
||||
{
|
||||
gui_mouse_grab = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_grab_code2key: get key name with a mouse code
|
||||
*/
|
||||
|
||||
const char *
|
||||
gui_mouse_grab_code2key (const char *code)
|
||||
{
|
||||
int x, y;
|
||||
double diff_x, diff_y, distance, angle, pi4;
|
||||
static char key[128];
|
||||
char button[2];
|
||||
|
||||
/* mouse code must have at least 3 chars */
|
||||
if (strlen (code) < 3)
|
||||
return NULL;
|
||||
|
||||
key[0] = '\0';
|
||||
|
||||
/* ignore code '#' (button released) if it's received as first event */
|
||||
if ((gui_mouse_event_index == 0) && (code[0] == '#'))
|
||||
return key;
|
||||
|
||||
/* get coordinates and button */
|
||||
x = ((unsigned char)code[1]) - 33;
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
y = ((unsigned char)code[2]) - 33;
|
||||
if (y < 0)
|
||||
y = 0;
|
||||
gui_mouse_event_x[gui_mouse_event_index] = x;
|
||||
gui_mouse_event_y[gui_mouse_event_index] = y;
|
||||
if (gui_mouse_event_index == 0)
|
||||
gui_mouse_event_button = code[0];
|
||||
|
||||
if (gui_mouse_event_index == 0)
|
||||
gui_mouse_event_index = 1;
|
||||
|
||||
if (code[0] == '`')
|
||||
{
|
||||
strcat (key, "wheelup");
|
||||
return key;
|
||||
}
|
||||
|
||||
if (code[0] == 'a')
|
||||
{
|
||||
strcat (key, "wheeldown");
|
||||
return key;
|
||||
}
|
||||
|
||||
if (code[0] != '#')
|
||||
return key;
|
||||
|
||||
/* add button/wheel */
|
||||
switch (gui_mouse_event_button)
|
||||
{
|
||||
case ' ': /* left button pressed */
|
||||
strcat (key, "button1");
|
||||
break;
|
||||
case '"': /* right button pressed */
|
||||
strcat (key, "button2");
|
||||
break;
|
||||
case '!': /* middle button pressed */
|
||||
strcat (key, "button3");
|
||||
break;
|
||||
default: /* extra buttons: button4..button9 */
|
||||
if ((gui_mouse_event_button >= 'b')
|
||||
&& (gui_mouse_event_button <= 'g'))
|
||||
{
|
||||
button[0] = gui_mouse_event_button - ('b' - '4');
|
||||
button[1] = '\0';
|
||||
strcat (key, "button");
|
||||
strcat (key, button);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Mouse gesture: if (x,y) on release is different from (x,y) on click,
|
||||
* compute distance and angle between 2 points.
|
||||
*
|
||||
* Distance: sqrt((x2-x1)²+(y2-y1)²)
|
||||
* Angle : atan2(x1-x1, y2-y1)
|
||||
*
|
||||
* Angle:
|
||||
*
|
||||
* 3.14 pi
|
||||
* /\
|
||||
* -2.35 || 2.35 3/4 * pi
|
||||
* ||
|
||||
* -1.57 /----++----\ 1.57 1/2 * pi
|
||||
* \----++----/
|
||||
* ||
|
||||
* -0.78 || 0.78 1/4 * pi
|
||||
* \/
|
||||
* 0.00 0
|
||||
*
|
||||
* Possible returned gestures are:
|
||||
*
|
||||
* key name | dist. | angle
|
||||
* ---------------------------+-------+--------------------------
|
||||
* buttonX-gesture-up | 3..19 | -2.35..-3.14 + 2.35..3.14
|
||||
* buttonX-gesture-up-long | >= 20 |
|
||||
* buttonX-gesture-down | 3..19 | -0.78..0.78
|
||||
* buttonX-gesture-down-long | >= 20 |
|
||||
* buttonX-gesture-left | 3..39 | -0.78..-2.35
|
||||
* buttonX-gesture-left-long | >= 40 |
|
||||
* buttonX-gesture-right | 3..39 | 0.78..2.35
|
||||
* buttonX-gesture-right-long | >= 40 |
|
||||
*/
|
||||
|
||||
distance = 0;
|
||||
if (key[0]
|
||||
&& ((gui_mouse_event_x[0] != gui_mouse_event_x[1])
|
||||
|| (gui_mouse_event_y[0] != gui_mouse_event_y[1])))
|
||||
{
|
||||
diff_x = gui_mouse_event_x[1] - gui_mouse_event_x[0];
|
||||
diff_y = gui_mouse_event_y[1] - gui_mouse_event_y[0];
|
||||
distance = sqrt ((diff_x * diff_x) + (diff_y * diff_y));
|
||||
if (distance >= 3)
|
||||
{
|
||||
angle = atan2 ((double)(gui_mouse_event_x[1] - gui_mouse_event_x[0]),
|
||||
(double)(gui_mouse_event_y[1] - gui_mouse_event_y[0]));
|
||||
pi4 = 3.14159265358979 / 4;
|
||||
if ((angle <= pi4 * (-3)) || (angle >= pi4 * 3))
|
||||
{
|
||||
strcat (key, "-gesture-up");
|
||||
if (distance >= 20)
|
||||
strcat (key, "-long");
|
||||
}
|
||||
else if ((angle >= pi4 * (-1)) && (angle <= pi4))
|
||||
{
|
||||
strcat (key, "-gesture-down");
|
||||
if (distance >= 20)
|
||||
strcat (key, "-long");
|
||||
}
|
||||
else if ((angle >= pi4 * (-3)) && (angle <= pi4 * (-1)))
|
||||
{
|
||||
strcat (key, "-gesture-left");
|
||||
if (distance >= 40)
|
||||
strcat (key, "-long");
|
||||
}
|
||||
else if ((angle >= pi4) && (angle <= pi4 * 3))
|
||||
{
|
||||
strcat (key, "-gesture-right");
|
||||
if (distance >= 40)
|
||||
strcat (key, "-long");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_grab_end: end "grab mouse" mode
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_grab_end ()
|
||||
{
|
||||
gui_mouse_grab = 0;
|
||||
}
|
||||
@@ -46,6 +46,7 @@
|
||||
#include "../gui-buffer.h"
|
||||
#include "../gui-chat.h"
|
||||
#include "../gui-color.h"
|
||||
#include "../gui-cursor.h"
|
||||
#include "../gui-hotlist.h"
|
||||
#include "../gui-input.h"
|
||||
#include "../gui-key.h"
|
||||
@@ -1514,7 +1515,8 @@ gui_window_refresh_windows ()
|
||||
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
{
|
||||
if (CONFIG_INTEGER(ptr_bar->options[GUI_BAR_OPTION_TYPE]) == GUI_BAR_TYPE_ROOT)
|
||||
if ((CONFIG_INTEGER(ptr_bar->options[GUI_BAR_OPTION_TYPE]) == GUI_BAR_TYPE_ROOT)
|
||||
&& !CONFIG_BOOLEAN(ptr_bar->options[GUI_BAR_OPTION_HIDDEN]))
|
||||
{
|
||||
gui_bar_window_calculate_pos_size (ptr_bar->bar_window, NULL);
|
||||
gui_bar_window_create_win (ptr_bar->bar_window);
|
||||
@@ -2196,6 +2198,20 @@ gui_window_set_title (const char *title)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_move_cursor: move cursor on screen (for cursor mode)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_move_cursor ()
|
||||
{
|
||||
if (gui_cursor_mode)
|
||||
{
|
||||
move (gui_cursor_y, gui_cursor_x);
|
||||
refresh ();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_term_display_infos: display some infos about terminal and colors
|
||||
*/
|
||||
|
||||
@@ -25,6 +25,7 @@ gui-gtk-chat.c
|
||||
gui-gtk-color.c
|
||||
gui-gtk-key.c
|
||||
gui-gtk-main.c
|
||||
gui-gtk-mouse.c
|
||||
gui-gtk-term.c
|
||||
gui-gtk-window.c)
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ weechat_gtk_SOURCES = gui-gtk-bar-window.c \
|
||||
gui-gtk-color.c \
|
||||
gui-gtk-key.c \
|
||||
gui-gtk-main.c \
|
||||
gui-gtk-mouse.c \
|
||||
gui-gtk-term.c \
|
||||
gui-gtk-window.c \
|
||||
gui-gtk.h
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Sebastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat 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 WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* gui-gtk-mouse.c: mouse functions for Gtk GUI
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "../../core/weechat.h"
|
||||
#include "../gui-mouse.h"
|
||||
|
||||
|
||||
/*
|
||||
* gui_mouse_enable: enable mouse
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_enable ()
|
||||
{
|
||||
/* This function does nothing in Gtk GUI */
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_disable: disable mouse
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_disable ()
|
||||
{
|
||||
/* This function does nothing in Gtk GUI */
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_display_state: display state of mouse
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_display_state ()
|
||||
{
|
||||
/* This function does nothing in Gtk GUI */
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_grab_init: init "grab mouse" mode
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_grab_init ()
|
||||
{
|
||||
/* This function does nothing in Gtk GUI */
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_grab_code2key: get key name with a mouse code
|
||||
*/
|
||||
|
||||
const char *
|
||||
gui_mouse_grab_code2key (const char *code)
|
||||
{
|
||||
(void) code;
|
||||
|
||||
/* This function does nothing in Gtk GUI */
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_grab_end: end "grab mouse" mode
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_grab_end ()
|
||||
{
|
||||
/* This function does nothing in Gtk GUI */
|
||||
}
|
||||
@@ -848,6 +848,16 @@ gui_window_set_title (const char *title)
|
||||
/* TODO: write this function for Gtk */
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_move_cursor: move cursor on screen (for cursor mode)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_move_cursor ()
|
||||
{
|
||||
/* TODO: write this function for Gtk */
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_term_display_infos: display some infos about terminal and colors
|
||||
*/
|
||||
|
||||
+195
-151
@@ -47,6 +47,7 @@
|
||||
#include "gui-chat.h"
|
||||
#include "gui-color.h"
|
||||
#include "gui-completion.h"
|
||||
#include "gui-cursor.h"
|
||||
#include "gui-filter.h"
|
||||
#include "gui-hotlist.h"
|
||||
#include "gui-key.h"
|
||||
@@ -130,70 +131,6 @@ gui_bar_item_search (const char *item_name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_valid_char_name: return 1 if char is valid for item name
|
||||
* (any letter, digit, "-" or "_")
|
||||
* return 0 otherwise
|
||||
*/
|
||||
|
||||
int
|
||||
gui_bar_item_valid_char_name (char c)
|
||||
{
|
||||
return (((c >= 'a') && (c <= 'z'))
|
||||
|| ((c >= 'A') && (c <= 'Z'))
|
||||
|| ((c >= '0') && (c <= '9'))
|
||||
|| (c == '-')
|
||||
|| (c == '_')) ?
|
||||
1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_string_get_item_start: return pointer to beginning of item name
|
||||
* (string may contain special delimiters
|
||||
* at beginning, which are ignored)
|
||||
*/
|
||||
|
||||
const char *
|
||||
gui_bar_item_string_get_item_start (const char *string)
|
||||
{
|
||||
while (string && string[0])
|
||||
{
|
||||
if (gui_bar_item_valid_char_name (string[0]))
|
||||
break;
|
||||
string++;
|
||||
}
|
||||
if (string && string[0])
|
||||
return string;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_string_is_item: return 1 if string is item (string may contain
|
||||
* special delimiters at beginning and end of
|
||||
* string, which are ignored)
|
||||
*/
|
||||
|
||||
int
|
||||
gui_bar_item_string_is_item (const char *string, const char *item_name)
|
||||
{
|
||||
const char *item_start;
|
||||
int length;
|
||||
|
||||
item_start = gui_bar_item_string_get_item_start (string);
|
||||
if (!item_start)
|
||||
return 0;
|
||||
|
||||
length = strlen (item_name);
|
||||
if (strncmp (item_start, item_name, length) == 0)
|
||||
{
|
||||
if (!gui_bar_item_valid_char_name (item_start[length]))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_search_with_plugin: search a bar item for a plugin
|
||||
* if exact_plugin == 1, then search only for
|
||||
@@ -249,7 +186,6 @@ gui_bar_item_used_in_a_bar (const char *item_name, int partial_name)
|
||||
{
|
||||
struct t_gui_bar *ptr_bar;
|
||||
int i, j, length;
|
||||
const char *ptr_start;
|
||||
|
||||
length = strlen (item_name);
|
||||
|
||||
@@ -259,13 +195,14 @@ gui_bar_item_used_in_a_bar (const char *item_name, int partial_name)
|
||||
{
|
||||
for (j = 0; j < ptr_bar->items_subcount[i]; j++)
|
||||
{
|
||||
ptr_start = gui_bar_item_string_get_item_start (ptr_bar->items_array[i][j]);
|
||||
if (ptr_start)
|
||||
if (ptr_bar->items_name[i][j])
|
||||
{
|
||||
if ((partial_name
|
||||
&& strncmp (ptr_start, item_name, length) == 0)
|
||||
&& strncmp (ptr_bar->items_name[i][j],
|
||||
item_name, length) == 0)
|
||||
|| (!partial_name
|
||||
&& strcmp (ptr_start, item_name) == 0))
|
||||
&& strcmp (ptr_bar->items_name[i][j],
|
||||
item_name) == 0))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@@ -279,40 +216,39 @@ gui_bar_item_used_in_a_bar (const char *item_name, int partial_name)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_get_value: return value of a bar item
|
||||
* first look for prefix/suffix in name, then run item
|
||||
* callback (if found) and concatene strings
|
||||
* for example: if name == "[time]"
|
||||
* return: color(delimiter) + "[" +
|
||||
* (value of item "time") + color(delimiter) +
|
||||
* "]"
|
||||
* gui_bar_item_set_prefix_name_suffix: get prefix, name and suffix for an item
|
||||
* for example, item name "[time]"
|
||||
* will return:
|
||||
* prefix: "["
|
||||
* name : "time"
|
||||
* suffix: "]"
|
||||
*/
|
||||
|
||||
char *
|
||||
gui_bar_item_get_value (const char *name, struct t_gui_bar *bar,
|
||||
struct t_gui_window *window)
|
||||
void
|
||||
gui_bar_item_set_prefix_name_suffix (const char *item_name,
|
||||
char **prefix, char **name, char **suffix)
|
||||
{
|
||||
const char *ptr, *start, *end;
|
||||
char *prefix, *item_name, *suffix;
|
||||
char *item_value, delimiter_color[32], bar_color[32];
|
||||
char *result, str_attr[8];
|
||||
int valid_char, length;
|
||||
struct t_gui_bar_item *ptr_item;
|
||||
struct t_weechat_plugin *ptr_plugin;
|
||||
int valid_char;
|
||||
|
||||
if (!name)
|
||||
return NULL;
|
||||
*prefix = NULL;
|
||||
*name = NULL;
|
||||
*suffix = NULL;
|
||||
|
||||
if (!item_name)
|
||||
return;
|
||||
|
||||
start = NULL;
|
||||
end = NULL;
|
||||
prefix = NULL;
|
||||
item_name = NULL;
|
||||
suffix = NULL;
|
||||
|
||||
ptr = name;
|
||||
ptr = item_name;
|
||||
while (ptr[0])
|
||||
{
|
||||
valid_char = gui_bar_item_valid_char_name (ptr[0]);
|
||||
valid_char = (((ptr[0] >= 'a') && (ptr[0] <= 'z'))
|
||||
|| ((ptr[0] >= 'A') && (ptr[0] <= 'Z'))
|
||||
|| ((ptr[0] >= '0') && (ptr[0] <= '9'))
|
||||
|| (ptr[0] == '-')
|
||||
|| (ptr[0] == '_')) ? 1 : 0;
|
||||
if (!start && valid_char)
|
||||
start = ptr;
|
||||
else if (start && !end && !valid_char)
|
||||
@@ -321,56 +257,70 @@ gui_bar_item_get_value (const char *name, struct t_gui_bar *bar,
|
||||
}
|
||||
if (start)
|
||||
{
|
||||
if (start > name)
|
||||
prefix = string_strndup (name, start - name);
|
||||
if (start > item_name)
|
||||
*prefix = string_strndup (item_name, start - item_name);
|
||||
}
|
||||
else
|
||||
prefix = strdup (name);
|
||||
*prefix = strdup (item_name);
|
||||
if (start)
|
||||
{
|
||||
item_name = (end) ?
|
||||
*name = (end) ?
|
||||
string_strndup (start, end - start + 1) : strdup (start);
|
||||
}
|
||||
if (end && end[0] && end[1])
|
||||
suffix = strdup (end + 1);
|
||||
*suffix = strdup (end + 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_get_value: return value of a bar item
|
||||
* run callback if a name exists, then concatenate
|
||||
* prefix + return of callback + suffix
|
||||
* for example: if item == "[time]"
|
||||
* return: color(delimiter) + "[" +
|
||||
* (value of item "time") + color(delimiter) +
|
||||
* "]"
|
||||
*/
|
||||
|
||||
char *
|
||||
gui_bar_item_get_value (struct t_gui_bar *bar, struct t_gui_window *window,
|
||||
int item, int subitem)
|
||||
{
|
||||
char *item_value, delimiter_color[32], bar_color[32];
|
||||
char *result, str_attr[8];
|
||||
int length;
|
||||
struct t_gui_bar_item *ptr_item;
|
||||
struct t_weechat_plugin *ptr_plugin;
|
||||
|
||||
if (!bar->items_array[item][subitem])
|
||||
return NULL;
|
||||
|
||||
item_value = NULL;
|
||||
if (item_name)
|
||||
if (bar->items_name[item][subitem])
|
||||
{
|
||||
ptr_plugin = NULL;
|
||||
if (window && window->buffer)
|
||||
ptr_plugin = window->buffer->plugin;
|
||||
else if (gui_current_window && gui_current_window->buffer)
|
||||
ptr_plugin = gui_current_window->buffer->plugin;
|
||||
ptr_item = gui_bar_item_search_with_plugin (ptr_plugin, 0, item_name);
|
||||
ptr_item = gui_bar_item_search_with_plugin (ptr_plugin, 0,
|
||||
bar->items_name[item][subitem]);
|
||||
if (ptr_item && ptr_item->build_callback)
|
||||
{
|
||||
item_value = (ptr_item->build_callback) (ptr_item->build_callback_data,
|
||||
ptr_item, window);
|
||||
}
|
||||
if (!item_value || !item_value[0])
|
||||
{
|
||||
if (prefix)
|
||||
{
|
||||
free (prefix);
|
||||
prefix = NULL;
|
||||
}
|
||||
if (suffix)
|
||||
{
|
||||
free (suffix);
|
||||
suffix = NULL;
|
||||
}
|
||||
}
|
||||
if (!item_value)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
length = 0;
|
||||
if (prefix)
|
||||
length += 64 + strlen (prefix) + 1; /* color + prefix + color */
|
||||
if (bar->items_prefix[item][subitem])
|
||||
length += 64 + strlen (bar->items_prefix[item][subitem]) + 1; /* color + prefix + color */
|
||||
if (item_value && item_value[0])
|
||||
length += strlen (item_value) + 16 + 1; /* length + "move cursor" id */
|
||||
if (suffix)
|
||||
length += 32 + strlen (suffix) + 1; /* color + suffix */
|
||||
|
||||
length += strlen (item_value) + 1;
|
||||
if (bar->items_suffix[item][subitem])
|
||||
length += 32 + strlen (bar->items_suffix[item][subitem]) + 1; /* color + suffix */
|
||||
|
||||
result = NULL;
|
||||
if (length > 0)
|
||||
{
|
||||
@@ -379,7 +329,8 @@ gui_bar_item_get_value (const char *name, struct t_gui_bar *bar,
|
||||
{
|
||||
delimiter_color[0] = '\0';
|
||||
bar_color[0] = '\0';
|
||||
if (prefix || suffix)
|
||||
if (bar->items_prefix[item][subitem]
|
||||
|| bar->items_suffix[item][subitem])
|
||||
{
|
||||
/* color for text in bar */
|
||||
gui_color_attr_build_string (CONFIG_COLOR(bar->options[GUI_BAR_OPTION_COLOR_FG]),
|
||||
@@ -429,27 +380,45 @@ gui_bar_item_get_value (const char *name, struct t_gui_bar *bar,
|
||||
}
|
||||
snprintf (result, length,
|
||||
"%s%s%s%s%s%s",
|
||||
(prefix) ? delimiter_color : "",
|
||||
(prefix) ? prefix : "",
|
||||
(prefix) ? bar_color : "",
|
||||
(bar->items_prefix[item][subitem]) ? delimiter_color : "",
|
||||
(bar->items_prefix[item][subitem]) ? bar->items_prefix[item][subitem] : "",
|
||||
(bar->items_prefix[item][subitem]) ? bar_color : "",
|
||||
(item_value) ? item_value : "",
|
||||
(suffix) ? delimiter_color : "",
|
||||
(suffix) ? suffix : "");
|
||||
(bar->items_suffix[item][subitem]) ? delimiter_color : "",
|
||||
(bar->items_suffix[item][subitem]) ? bar->items_suffix[item][subitem] : "");
|
||||
}
|
||||
}
|
||||
|
||||
if (prefix)
|
||||
free (prefix);
|
||||
if (item_name)
|
||||
free (item_name);
|
||||
if (suffix)
|
||||
free (suffix);
|
||||
if (item_value)
|
||||
free (item_value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_count_lines: count number of lines in item
|
||||
*/
|
||||
|
||||
int
|
||||
gui_bar_item_count_lines (char *string)
|
||||
{
|
||||
int count, i;
|
||||
|
||||
if (!string || !string[0])
|
||||
return 0;
|
||||
|
||||
count = 1;
|
||||
i = 0;
|
||||
while (string[i])
|
||||
{
|
||||
if ((string[i] == '\n') && string[i + 1])
|
||||
count++;
|
||||
i++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_new: create a new bar item
|
||||
*/
|
||||
@@ -505,22 +474,20 @@ gui_bar_item_update (const char *item_name)
|
||||
struct t_gui_bar *ptr_bar;
|
||||
struct t_gui_window *ptr_window;
|
||||
struct t_gui_bar_window *ptr_bar_window;
|
||||
int index_item, index_subitem;
|
||||
int i, j;
|
||||
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
{
|
||||
for (index_item = 0; index_item < ptr_bar->items_count; index_item++)
|
||||
for (i = 0; i < ptr_bar->items_count; i++)
|
||||
{
|
||||
for (index_subitem = 0;
|
||||
index_subitem < ptr_bar->items_subcount[index_item];
|
||||
index_subitem++)
|
||||
for (j = 0; j < ptr_bar->items_subcount[i]; j++)
|
||||
{
|
||||
if (gui_bar_item_string_is_item (ptr_bar->items_array[index_item][index_subitem],
|
||||
item_name))
|
||||
if (ptr_bar->items_name[i][j]
|
||||
&& (strcmp (ptr_bar->items_name[i][j], item_name) == 0))
|
||||
{
|
||||
if (ptr_bar->bar_window)
|
||||
{
|
||||
ptr_bar->bar_window->items_refresh_needed[index_item][index_subitem] = 1;
|
||||
ptr_bar->bar_window->items_refresh_needed[i][j] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -533,7 +500,7 @@ gui_bar_item_update (const char *item_name)
|
||||
{
|
||||
if (ptr_bar_window->bar == ptr_bar)
|
||||
{
|
||||
ptr_bar_window->items_refresh_needed[index_item][index_subitem] = 1;
|
||||
ptr_bar_window->items_refresh_needed[i][j] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -744,11 +711,15 @@ gui_bar_item_default_input_text (void *data, struct t_gui_bar_item *item,
|
||||
"0x%lx", (long unsigned int)(window->buffer));
|
||||
|
||||
/* execute modifier with basic string (without cursor tag) */
|
||||
ptr_input = hook_modifier_exec (NULL,
|
||||
"input_text_display",
|
||||
str_buffer,
|
||||
(window->buffer->input_buffer) ?
|
||||
window->buffer->input_buffer : "");
|
||||
ptr_input = NULL;
|
||||
if (!gui_cursor_mode)
|
||||
{
|
||||
ptr_input = hook_modifier_exec (NULL,
|
||||
"input_text_display",
|
||||
str_buffer,
|
||||
(window->buffer->input_buffer) ?
|
||||
window->buffer->input_buffer : "");
|
||||
}
|
||||
if (!ptr_input)
|
||||
{
|
||||
ptr_input = (window->buffer->input_buffer) ?
|
||||
@@ -791,13 +762,16 @@ gui_bar_item_default_input_text (void *data, struct t_gui_bar_item *item,
|
||||
}
|
||||
|
||||
/* execute modifier with cursor in string */
|
||||
ptr_input2 = hook_modifier_exec (NULL,
|
||||
"input_text_display_with_cursor",
|
||||
str_buffer,
|
||||
(ptr_input) ? ptr_input : "");
|
||||
if (ptr_input)
|
||||
free (ptr_input);
|
||||
ptr_input = ptr_input2;
|
||||
if (!gui_cursor_mode)
|
||||
{
|
||||
ptr_input2 = hook_modifier_exec (NULL,
|
||||
"input_text_display_with_cursor",
|
||||
str_buffer,
|
||||
(ptr_input) ? ptr_input : "");
|
||||
if (ptr_input)
|
||||
free (ptr_input);
|
||||
ptr_input = ptr_input2;
|
||||
}
|
||||
|
||||
/* insert "start input" at beginning of string */
|
||||
if (ptr_input)
|
||||
@@ -1447,6 +1421,74 @@ gui_bar_item_default_buffer_nicklist (void *data, struct t_gui_bar_item *item,
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_focus_buffer_nicklist: focus on nicklist
|
||||
*/
|
||||
|
||||
struct t_hashtable *
|
||||
gui_bar_item_focus_buffer_nicklist (void *data,
|
||||
struct t_hashtable *info)
|
||||
{
|
||||
struct t_gui_nick_group *ptr_group;
|
||||
struct t_gui_nick *ptr_nick;
|
||||
int i, rc, item_line;
|
||||
unsigned long int value;
|
||||
const char *str_window;
|
||||
struct t_gui_window *window;
|
||||
char *error;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
|
||||
str_window = hashtable_get (info, "_window");
|
||||
rc = sscanf (str_window, "%lx", &value);
|
||||
if ((rc == EOF) || (rc == 0))
|
||||
return NULL;
|
||||
|
||||
window = (struct t_gui_window *)value;
|
||||
if (!window)
|
||||
window = gui_current_window;
|
||||
|
||||
error = NULL;
|
||||
item_line = (int) strtol (hashtable_get (info, "_item_line"), &error, 10);
|
||||
if (!error || error[0])
|
||||
return NULL;
|
||||
|
||||
i = 0;
|
||||
ptr_group = NULL;
|
||||
ptr_nick = NULL;
|
||||
gui_nicklist_get_next_item (window->buffer, &ptr_group, &ptr_nick);
|
||||
while (ptr_group || ptr_nick)
|
||||
{
|
||||
if ((ptr_nick && ptr_nick->visible)
|
||||
|| (ptr_group && !ptr_nick
|
||||
&& window->buffer->nicklist_display_groups
|
||||
&& ptr_group->visible))
|
||||
{
|
||||
if (i == item_line)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
gui_nicklist_get_next_item (window->buffer, &ptr_group, &ptr_nick);
|
||||
}
|
||||
|
||||
if (i != item_line)
|
||||
return NULL;
|
||||
|
||||
if (ptr_nick)
|
||||
{
|
||||
hashtable_set (info, "nick", ptr_nick->name);
|
||||
hashtable_set (info, "prefix", ptr_nick->prefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
hashtable_set (info,
|
||||
"group",
|
||||
gui_nicklist_get_group_start (ptr_group->name));
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_timer_cb: timer callback
|
||||
*/
|
||||
@@ -1673,6 +1715,8 @@ gui_bar_item_init ()
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST]);
|
||||
gui_bar_item_hook_signal ("buffer_switch",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST]);
|
||||
hook_focus (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST],
|
||||
&gui_bar_item_focus_buffer_nicklist, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -74,13 +74,15 @@ extern char *gui_bar_items_default_for_bars[][2];
|
||||
|
||||
extern int gui_bar_item_valid (struct t_gui_bar_item *bar_item);
|
||||
extern struct t_gui_bar_item *gui_bar_item_search (const char *name);
|
||||
extern int gui_bar_item_string_is_item (const char *string,
|
||||
const char *item_name);
|
||||
extern int gui_bar_item_used_in_a_bar (const char *item_name,
|
||||
int partial_name);
|
||||
extern char *gui_bar_item_get_value (const char *name,
|
||||
struct t_gui_bar *bar,
|
||||
struct t_gui_window *window);
|
||||
extern void gui_bar_item_set_prefix_name_suffix (const char *item_name,
|
||||
char **prefix, char **name,
|
||||
char **suffix);
|
||||
extern char *gui_bar_item_get_value (struct t_gui_bar *bar,
|
||||
struct t_gui_window *window,
|
||||
int item, int subitem);
|
||||
extern int gui_bar_item_count_lines (char *string);
|
||||
extern struct t_gui_bar_item *gui_bar_item_new (struct t_weechat_plugin *plugin,
|
||||
const char *name,
|
||||
char *(*build_callback)(void *data,
|
||||
|
||||
+429
-80
@@ -26,14 +26,17 @@
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../core/weechat.h"
|
||||
#include "../core/wee-config.h"
|
||||
#include "../core/wee-hdata.h"
|
||||
#include "../core/wee-infolist.h"
|
||||
#include "../core/wee-log.h"
|
||||
#include "../core/wee-string.h"
|
||||
#include "../plugins/plugin.h"
|
||||
#include "gui-bar-window.h"
|
||||
#include "gui-bar.h"
|
||||
#include "gui-bar-item.h"
|
||||
@@ -101,6 +104,149 @@ gui_bar_window_search_bar (struct t_gui_window *window, struct t_gui_bar *bar)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_window_search_by_xy: get bar_window pointer displayed at (x,y)
|
||||
* if window is not NULL, search is done in
|
||||
* bar windows of window
|
||||
* if window is NULL, search is done in root
|
||||
* bar windows
|
||||
*/
|
||||
|
||||
void
|
||||
gui_bar_window_search_by_xy (struct t_gui_window *window, int x, int y,
|
||||
struct t_gui_bar_window **bar_window,
|
||||
char **bar_item, int *item_line, int *item_col)
|
||||
{
|
||||
struct t_gui_bar *ptr_bar;
|
||||
struct t_gui_bar_window *ptr_bar_window;
|
||||
int filling, num_cols, column, lines, lines_old, i, j, coord_x, coord_y;
|
||||
int item, subitem;
|
||||
|
||||
*bar_window = NULL;
|
||||
*bar_item = NULL;
|
||||
*item_line = -1;
|
||||
*item_col = -1;
|
||||
|
||||
if (window)
|
||||
{
|
||||
for (ptr_bar_window = window->bar_windows; ptr_bar_window;
|
||||
ptr_bar_window = ptr_bar_window->next_bar_window)
|
||||
{
|
||||
if ((x >= ptr_bar_window->x) && (y >= ptr_bar_window->y)
|
||||
&& (x <= ptr_bar_window->x + ptr_bar_window->width - 1)
|
||||
&& (y <= ptr_bar_window->y + ptr_bar_window->height - 1))
|
||||
{
|
||||
*bar_window = ptr_bar_window;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
{
|
||||
if (ptr_bar->bar_window
|
||||
&& (x >= ptr_bar->bar_window->x)
|
||||
&& (y >= ptr_bar->bar_window->y)
|
||||
&& (x <= ptr_bar->bar_window->x + ptr_bar->bar_window->width - 1)
|
||||
&& (y <= ptr_bar->bar_window->y + ptr_bar->bar_window->height - 1))
|
||||
{
|
||||
*bar_window = ptr_bar->bar_window;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (*bar_window)
|
||||
{
|
||||
filling = gui_bar_get_filling ((*bar_window)->bar);
|
||||
|
||||
*item_line = y - (*bar_window)->y + (*bar_window)->scroll_y;
|
||||
*item_col = x - (*bar_window)->x + (*bar_window)->scroll_x;
|
||||
|
||||
if ((filling == GUI_BAR_FILLING_COLUMNS_HORIZONTAL)
|
||||
&& ((*bar_window)->screen_col_size > 0))
|
||||
{
|
||||
num_cols = (*bar_window)->width / (*bar_window)->screen_col_size;
|
||||
column = *item_col / (*bar_window)->screen_col_size;
|
||||
*item_line = (*item_line * num_cols) + column;
|
||||
*item_col = *item_col - (column * ((*bar_window)->screen_col_size));
|
||||
}
|
||||
|
||||
if ((filling == GUI_BAR_FILLING_COLUMNS_VERTICAL)
|
||||
&& ((*bar_window)->screen_col_size > 0))
|
||||
{
|
||||
column = *item_col / (*bar_window)->screen_col_size;
|
||||
*item_line = (column * ((*bar_window)->height)) + *item_line;
|
||||
*item_col = *item_col % ((*bar_window)->screen_col_size);
|
||||
}
|
||||
|
||||
if (filling == GUI_BAR_FILLING_HORIZONTAL)
|
||||
{
|
||||
i = 0;
|
||||
while (i < (*bar_window)->coords_count)
|
||||
{
|
||||
coord_x = (*bar_window)->coords[i]->x;
|
||||
coord_y = (*bar_window)->coords[i]->y;
|
||||
while ((i < (*bar_window)->coords_count - 1)
|
||||
&& (coord_x == (*bar_window)->coords[i + 1]->x)
|
||||
&& (coord_y == (*bar_window)->coords[i + 1]->y))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
if (i == (*bar_window)->coords_count - 1)
|
||||
{
|
||||
item = (*bar_window)->coords[i]->item;
|
||||
subitem = (*bar_window)->coords[i]->subitem;
|
||||
if ((item >= 0) && (subitem >= 0))
|
||||
{
|
||||
*bar_item = (*bar_window)->bar->items_name[item][subitem];
|
||||
*item_line = (*bar_window)->coords[i]->line;
|
||||
*item_col = x - (*bar_window)->coords[i]->x;
|
||||
}
|
||||
break;
|
||||
}
|
||||
coord_x = (*bar_window)->coords[i + 1]->x;
|
||||
coord_y = (*bar_window)->coords[i + 1]->y;
|
||||
if ((y < coord_y) || ((y == coord_y) && (x < coord_x)))
|
||||
{
|
||||
item = (*bar_window)->coords[i]->item;
|
||||
subitem = (*bar_window)->coords[i]->subitem;
|
||||
*bar_item = (*bar_window)->bar->items_name[item][subitem];
|
||||
*item_line = (*bar_window)->coords[i]->line;
|
||||
*item_col = x - (*bar_window)->coords[i]->x;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
j = 0;
|
||||
lines = 0;
|
||||
lines_old = 0;
|
||||
while (i < (*bar_window)->items_count)
|
||||
{
|
||||
lines_old = lines;
|
||||
lines += (*bar_window)->items_num_lines[i][j];
|
||||
if (*item_line < lines)
|
||||
{
|
||||
*bar_item = (*bar_window)->bar->items_name[i][j];
|
||||
break;
|
||||
}
|
||||
j++;
|
||||
if (j >= (*bar_window)->items_subcount[i])
|
||||
{
|
||||
j = 0;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
*item_line -= lines_old;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_window_get_size: get total bar size (window bars) for a position
|
||||
* bar is optional, if not NULL, size is computed
|
||||
@@ -159,6 +305,9 @@ gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window,
|
||||
int x1, y1, x2, y2;
|
||||
int add_bottom, add_top, add_left, add_right;
|
||||
|
||||
if (CONFIG_BOOLEAN(bar_window->bar->options[GUI_BAR_OPTION_HIDDEN]))
|
||||
return;
|
||||
|
||||
if (window)
|
||||
{
|
||||
x1 = window->win_x;
|
||||
@@ -247,7 +396,9 @@ gui_bar_window_content_alloc (struct t_gui_bar_window *bar_window)
|
||||
bar_window->items_count = bar_window->bar->items_count;
|
||||
bar_window->items_subcount = NULL;
|
||||
bar_window->items_content = NULL;
|
||||
bar_window->items_num_lines = NULL;
|
||||
bar_window->items_refresh_needed = NULL;
|
||||
bar_window->screen_col_size = 0;
|
||||
bar_window->items_subcount = malloc (bar_window->items_count *
|
||||
sizeof (*bar_window->items_subcount));
|
||||
if (!bar_window->items_subcount)
|
||||
@@ -256,6 +407,10 @@ gui_bar_window_content_alloc (struct t_gui_bar_window *bar_window)
|
||||
sizeof (*bar_window->items_content));
|
||||
if (!bar_window->items_content)
|
||||
goto error;
|
||||
bar_window->items_num_lines = malloc ((bar_window->items_count) *
|
||||
sizeof (*bar_window->items_num_lines));
|
||||
if (!bar_window->items_num_lines)
|
||||
goto error;
|
||||
bar_window->items_refresh_needed = malloc (bar_window->items_count *
|
||||
sizeof (*bar_window->items_refresh_needed));
|
||||
if (!bar_window->items_refresh_needed)
|
||||
@@ -264,6 +419,7 @@ gui_bar_window_content_alloc (struct t_gui_bar_window *bar_window)
|
||||
for (i = 0; i < bar_window->items_count; i++)
|
||||
{
|
||||
bar_window->items_content[i] = NULL;
|
||||
bar_window->items_num_lines[i] = NULL;
|
||||
bar_window->items_refresh_needed[i] = NULL;
|
||||
}
|
||||
|
||||
@@ -274,6 +430,10 @@ gui_bar_window_content_alloc (struct t_gui_bar_window *bar_window)
|
||||
sizeof (**bar_window->items_content));
|
||||
if (!bar_window->items_content[i])
|
||||
goto error;
|
||||
bar_window->items_num_lines[i] = malloc (bar_window->items_subcount[i] *
|
||||
sizeof (**bar_window->items_num_lines));
|
||||
if (!bar_window->items_num_lines[i])
|
||||
goto error;
|
||||
bar_window->items_refresh_needed[i] = malloc (bar_window->items_subcount[i] *
|
||||
sizeof (**bar_window->items_refresh_needed));
|
||||
if (!bar_window->items_refresh_needed[i])
|
||||
@@ -282,6 +442,8 @@ gui_bar_window_content_alloc (struct t_gui_bar_window *bar_window)
|
||||
{
|
||||
if (bar_window->items_content[i])
|
||||
bar_window->items_content[i][j] = NULL;
|
||||
if (bar_window->items_num_lines[i])
|
||||
bar_window->items_num_lines[i][j] = 0;
|
||||
if (bar_window->items_refresh_needed[i])
|
||||
bar_window->items_refresh_needed[i][j] = 1;
|
||||
}
|
||||
@@ -304,6 +466,16 @@ error:
|
||||
free (bar_window->items_content);
|
||||
bar_window->items_content = NULL;
|
||||
}
|
||||
if (bar_window->items_num_lines)
|
||||
{
|
||||
for (i = 0; i < bar_window->items_count; i++)
|
||||
{
|
||||
if (bar_window->items_num_lines[i])
|
||||
free (bar_window->items_num_lines[i]);
|
||||
}
|
||||
free (bar_window->items_num_lines);
|
||||
bar_window->items_num_lines = NULL;
|
||||
}
|
||||
if (bar_window->items_refresh_needed)
|
||||
{
|
||||
for (i = 0; i < bar_window->items_count; i++)
|
||||
@@ -338,12 +510,15 @@ gui_bar_window_content_free (struct t_gui_bar_window *bar_window)
|
||||
}
|
||||
}
|
||||
free (bar_window->items_content[i]);
|
||||
free (bar_window->items_num_lines[i]);
|
||||
free (bar_window->items_refresh_needed[i]);
|
||||
}
|
||||
free (bar_window->items_subcount);
|
||||
bar_window->items_subcount = NULL;
|
||||
free (bar_window->items_content);
|
||||
bar_window->items_content = NULL;
|
||||
free (bar_window->items_num_lines);
|
||||
bar_window->items_num_lines = NULL;
|
||||
free (bar_window->items_refresh_needed);
|
||||
bar_window->items_refresh_needed = NULL;
|
||||
}
|
||||
@@ -368,14 +543,17 @@ gui_bar_window_content_build_item (struct t_gui_bar_window *bar_window,
|
||||
free (bar_window->items_content[index_item][index_subitem]);
|
||||
bar_window->items_content[index_item][index_subitem] = NULL;
|
||||
}
|
||||
bar_window->items_num_lines[index_item][index_subitem] = 0;
|
||||
|
||||
/* build item, but only if there's a buffer in window */
|
||||
if ((window && window->buffer)
|
||||
|| (gui_current_window && gui_current_window->buffer))
|
||||
{
|
||||
bar_window->items_content[index_item][index_subitem] =
|
||||
gui_bar_item_get_value (bar_window->bar->items_array[index_item][index_subitem],
|
||||
bar_window->bar, window);
|
||||
gui_bar_item_get_value (bar_window->bar, window,
|
||||
index_item, index_subitem);
|
||||
bar_window->items_num_lines[index_item][index_subitem] =
|
||||
gui_bar_item_count_lines (bar_window->items_content[index_item][index_subitem]);
|
||||
bar_window->items_refresh_needed[index_item][index_subitem] = 0;
|
||||
}
|
||||
}
|
||||
@@ -437,28 +615,50 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
|
||||
struct t_gui_window *window)
|
||||
{
|
||||
enum t_gui_bar_filling filling;
|
||||
char *ptr_content, *content, reinit_color[32], reinit_color_space[32];
|
||||
char *ptr_content, *content, str_reinit_color[32];
|
||||
char str_reinit_color_space[32], str_reinit_color_space_start_line[32];
|
||||
char str_start_item[32];
|
||||
char *item_value, *item_value2, ****split_items, **linear_items;
|
||||
int index_content, content_length, i, first_sub_item, sub, j, k, index;
|
||||
int length_reinit_color_space, length, max_length, max_length_screen;
|
||||
int index_content, content_length, i, j, k, sub, index;
|
||||
int at_least_one_item, first_sub_item;
|
||||
int length_reinit_color_space, length_start_item, length;
|
||||
int max_length, max_length_screen;
|
||||
int total_items, columns, lines;
|
||||
|
||||
if (!bar_window->items_subcount || !bar_window->items_content
|
||||
|| !bar_window->items_refresh_needed)
|
||||
|| !bar_window->items_num_lines || !bar_window->items_refresh_needed)
|
||||
return NULL;
|
||||
|
||||
snprintf (reinit_color, sizeof (reinit_color),
|
||||
snprintf (str_reinit_color, sizeof (str_reinit_color),
|
||||
"%c",
|
||||
GUI_COLOR_RESET_CHAR);
|
||||
|
||||
snprintf (reinit_color_space, sizeof (reinit_color_space),
|
||||
snprintf (str_reinit_color_space, sizeof (str_reinit_color_space),
|
||||
"%c ",
|
||||
GUI_COLOR_RESET_CHAR);
|
||||
length_reinit_color_space = strlen (reinit_color_space);
|
||||
length_reinit_color_space = strlen (str_reinit_color_space);
|
||||
|
||||
snprintf (str_reinit_color_space_start_line,
|
||||
sizeof (str_reinit_color_space_start_line),
|
||||
"%c %c%c%c",
|
||||
GUI_COLOR_RESET_CHAR,
|
||||
GUI_COLOR_COLOR_CHAR,
|
||||
GUI_COLOR_BAR_CHAR,
|
||||
GUI_COLOR_BAR_START_LINE_ITEM);
|
||||
|
||||
snprintf (str_start_item, sizeof (str_start_item),
|
||||
"%c%c%c",
|
||||
GUI_COLOR_COLOR_CHAR,
|
||||
GUI_COLOR_BAR_CHAR,
|
||||
GUI_COLOR_BAR_START_ITEM);
|
||||
length_start_item = strlen (str_start_item);
|
||||
|
||||
content = NULL;
|
||||
content_length = 1;
|
||||
content = malloc (content_length);
|
||||
if (content)
|
||||
content[0] = '\0';
|
||||
filling = gui_bar_get_filling (bar_window->bar);
|
||||
at_least_one_item = 0;
|
||||
switch (filling)
|
||||
{
|
||||
case GUI_BAR_FILLING_HORIZONTAL: /* items separated by space */
|
||||
@@ -472,10 +672,10 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
|
||||
i, sub);
|
||||
if (ptr_content && ptr_content[0])
|
||||
{
|
||||
if (gui_bar_get_filling (bar_window->bar) == GUI_BAR_FILLING_HORIZONTAL)
|
||||
if (filling == GUI_BAR_FILLING_HORIZONTAL)
|
||||
{
|
||||
item_value = string_replace (ptr_content, "\n",
|
||||
reinit_color_space);
|
||||
str_reinit_color_space_start_line);
|
||||
if (item_value)
|
||||
{
|
||||
item_value2 = string_replace (item_value,
|
||||
@@ -489,43 +689,55 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
|
||||
}
|
||||
else
|
||||
item_value = NULL;
|
||||
if (!content)
|
||||
|
||||
content_length += ((filling == GUI_BAR_FILLING_HORIZONTAL) ? length_start_item : 0) +
|
||||
length_reinit_color_space +
|
||||
strlen ((item_value) ? item_value : ptr_content);
|
||||
content = realloc (content, content_length);
|
||||
if (at_least_one_item && first_sub_item)
|
||||
{
|
||||
content_length += strlen ((item_value) ?
|
||||
item_value : ptr_content);
|
||||
content = strdup ((item_value) ? item_value : ptr_content);
|
||||
first_sub_item = 0;
|
||||
/* first sub item: insert space after last item */
|
||||
if (filling == GUI_BAR_FILLING_HORIZONTAL)
|
||||
strcat (content, str_reinit_color_space);
|
||||
else
|
||||
strcat (content, "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
content_length += length_reinit_color_space +
|
||||
strlen ((item_value) ? item_value : ptr_content);
|
||||
content = realloc (content, content_length);
|
||||
if (first_sub_item)
|
||||
{
|
||||
/* first sub item: insert space after last item */
|
||||
if (gui_bar_get_filling (bar_window->bar) == GUI_BAR_FILLING_HORIZONTAL)
|
||||
strcat (content, reinit_color_space);
|
||||
else
|
||||
strcat (content, "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
strcat (content, reinit_color);
|
||||
}
|
||||
strcat (content,
|
||||
(item_value) ? item_value : ptr_content);
|
||||
first_sub_item = 0;
|
||||
strcat (content, str_reinit_color);
|
||||
}
|
||||
if (filling == GUI_BAR_FILLING_HORIZONTAL)
|
||||
strcat (content, str_start_item);
|
||||
strcat (content,
|
||||
(item_value) ? item_value : ptr_content);
|
||||
first_sub_item = 0;
|
||||
|
||||
if (item_value)
|
||||
free (item_value);
|
||||
at_least_one_item = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (filling == GUI_BAR_FILLING_HORIZONTAL)
|
||||
{
|
||||
content_length += length_start_item;
|
||||
content = realloc (content, content_length);
|
||||
if (content)
|
||||
strcat (content, str_start_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (filling == GUI_BAR_FILLING_HORIZONTAL)
|
||||
{
|
||||
content_length += length_start_item;
|
||||
content = realloc (content, content_length);
|
||||
if (content)
|
||||
strcat (content, str_start_item);
|
||||
}
|
||||
break;
|
||||
case GUI_BAR_FILLING_COLUMNS_HORIZONTAL: /* items in columns, with horizontal filling */
|
||||
case GUI_BAR_FILLING_COLUMNS_VERTICAL: /* items in columns, with vertical filling */
|
||||
content = NULL;
|
||||
total_items = 0;
|
||||
max_length = 1;
|
||||
max_length_screen = 1;
|
||||
@@ -580,6 +792,7 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
|
||||
columns++;
|
||||
lines = bar_window->height;
|
||||
}
|
||||
bar_window->screen_col_size = max_length_screen + 1;
|
||||
|
||||
/* build array with pointers to split items */
|
||||
|
||||
@@ -605,9 +818,10 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
|
||||
}
|
||||
|
||||
/* build content with lines and columns */
|
||||
content = malloc (1 + (lines *
|
||||
((columns *
|
||||
(max_length + max_length_screen + length_reinit_color_space)) + 1)));
|
||||
content_length = 1 + (lines *
|
||||
((columns *
|
||||
(max_length + max_length_screen + length_reinit_color_space)) + 1));
|
||||
content = realloc (content, content_length);
|
||||
if (content)
|
||||
{
|
||||
content[0] = '\0';
|
||||
@@ -641,7 +855,8 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
|
||||
}
|
||||
if (j < columns - 1)
|
||||
{
|
||||
strcpy (content + index_content, reinit_color_space);
|
||||
strcpy (content + index_content,
|
||||
str_reinit_color_space);
|
||||
index_content += length_reinit_color_space;
|
||||
}
|
||||
}
|
||||
@@ -671,25 +886,126 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
|
||||
break;
|
||||
}
|
||||
|
||||
if (content_length == 1)
|
||||
{
|
||||
free (content);
|
||||
content = NULL;
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_window_coords_add: add coordinates (item index/subindex and x,y)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_bar_window_coords_add (struct t_gui_bar_window *bar_window,
|
||||
int index_item, int index_subitem, int index_line,
|
||||
int x, int y)
|
||||
{
|
||||
if (!bar_window->coords)
|
||||
{
|
||||
bar_window->coords_count = 1;
|
||||
bar_window->coords = malloc (sizeof (*(bar_window->coords)));
|
||||
}
|
||||
else
|
||||
{
|
||||
bar_window->coords_count++;
|
||||
bar_window->coords = realloc (bar_window->coords,
|
||||
bar_window->coords_count * sizeof (*(bar_window->coords)));
|
||||
}
|
||||
bar_window->coords[bar_window->coords_count - 1] = malloc (sizeof (*(bar_window->coords[bar_window->coords_count - 1])));
|
||||
bar_window->coords[bar_window->coords_count - 1]->item = index_item;
|
||||
bar_window->coords[bar_window->coords_count - 1]->subitem = index_subitem;
|
||||
bar_window->coords[bar_window->coords_count - 1]->line = index_line;
|
||||
bar_window->coords[bar_window->coords_count - 1]->x = x;
|
||||
bar_window->coords[bar_window->coords_count - 1]->y = y;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_window_coords_free: free coords of a bar window
|
||||
*/
|
||||
|
||||
void
|
||||
gui_bar_window_coords_free (struct t_gui_bar_window *bar_window)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (bar_window->coords)
|
||||
{
|
||||
for (i = 0; i < bar_window->coords_count; i++)
|
||||
{
|
||||
free (bar_window->coords[i]);
|
||||
}
|
||||
free (bar_window->coords);
|
||||
bar_window->coords = NULL;
|
||||
}
|
||||
bar_window->coords_count = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_window_insert: insert bar window in list of bar windows (at good
|
||||
* position, according to priority)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_bar_window_insert (struct t_gui_bar_window *bar_window,
|
||||
struct t_gui_window *window)
|
||||
{
|
||||
struct t_gui_bar_window *pos_bar_window;
|
||||
|
||||
if (window->bar_windows)
|
||||
{
|
||||
pos_bar_window = gui_bar_window_find_pos (bar_window->bar, window);
|
||||
if (pos_bar_window)
|
||||
{
|
||||
/* insert before bar window found */
|
||||
bar_window->prev_bar_window = pos_bar_window->prev_bar_window;
|
||||
bar_window->next_bar_window = pos_bar_window;
|
||||
if (pos_bar_window->prev_bar_window)
|
||||
(pos_bar_window->prev_bar_window)->next_bar_window = bar_window;
|
||||
else
|
||||
window->bar_windows = bar_window;
|
||||
pos_bar_window->prev_bar_window = bar_window;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* add to end of list for window */
|
||||
bar_window->prev_bar_window = window->last_bar_window;
|
||||
bar_window->next_bar_window = NULL;
|
||||
(window->last_bar_window)->next_bar_window = bar_window;
|
||||
window->last_bar_window = bar_window;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bar_window->prev_bar_window = NULL;
|
||||
bar_window->next_bar_window = NULL;
|
||||
window->bar_windows = bar_window;
|
||||
window->last_bar_window = bar_window;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_window_new: create a new "window bar" for a bar, in screen or a window
|
||||
* if window is not NULL, bar window will be in this window
|
||||
* return 1 if ok, 0 if error
|
||||
*/
|
||||
|
||||
int
|
||||
void
|
||||
gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
|
||||
{
|
||||
struct t_gui_bar_window *new_bar_window, *pos_bar_window;
|
||||
struct t_gui_bar_window *new_bar_window;
|
||||
|
||||
if (CONFIG_BOOLEAN(bar->options[GUI_BAR_OPTION_HIDDEN]))
|
||||
return;
|
||||
|
||||
if (window)
|
||||
{
|
||||
if ((CONFIG_INTEGER(bar->options[GUI_BAR_OPTION_TYPE]) == GUI_BAR_TYPE_WINDOW)
|
||||
&& (!gui_bar_check_conditions_for_window (bar, window)))
|
||||
return 1;
|
||||
return;
|
||||
}
|
||||
|
||||
new_bar_window = malloc (sizeof (*new_bar_window));
|
||||
@@ -699,36 +1015,7 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
|
||||
if (window)
|
||||
{
|
||||
bar->bar_window = NULL;
|
||||
if (window->bar_windows)
|
||||
{
|
||||
pos_bar_window = gui_bar_window_find_pos (bar, window);
|
||||
if (pos_bar_window)
|
||||
{
|
||||
/* insert before bar window found */
|
||||
new_bar_window->prev_bar_window = pos_bar_window->prev_bar_window;
|
||||
new_bar_window->next_bar_window = pos_bar_window;
|
||||
if (pos_bar_window->prev_bar_window)
|
||||
(pos_bar_window->prev_bar_window)->next_bar_window = new_bar_window;
|
||||
else
|
||||
window->bar_windows = new_bar_window;
|
||||
pos_bar_window->prev_bar_window = new_bar_window;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* add to end of list for window */
|
||||
new_bar_window->prev_bar_window = window->last_bar_window;
|
||||
new_bar_window->next_bar_window = NULL;
|
||||
(window->last_bar_window)->next_bar_window = new_bar_window;
|
||||
window->last_bar_window = new_bar_window;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
new_bar_window->prev_bar_window = NULL;
|
||||
new_bar_window->next_bar_window = NULL;
|
||||
window->bar_windows = new_bar_window;
|
||||
window->last_bar_window = new_bar_window;
|
||||
}
|
||||
gui_bar_window_insert (new_bar_window, window);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -750,7 +1037,11 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
|
||||
new_bar_window->items_count = 0;
|
||||
new_bar_window->items_subcount = NULL;
|
||||
new_bar_window->items_content = NULL;
|
||||
new_bar_window->items_num_lines = NULL;
|
||||
new_bar_window->items_refresh_needed = NULL;
|
||||
new_bar_window->screen_col_size = 0;
|
||||
new_bar_window->coords_count = 0;
|
||||
new_bar_window->coords = NULL;
|
||||
gui_bar_window_objects_init (new_bar_window);
|
||||
gui_bar_window_content_alloc (new_bar_window);
|
||||
|
||||
@@ -760,12 +1051,7 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
|
||||
gui_bar_window_create_win (new_bar_window);
|
||||
gui_window_ask_refresh (1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* failed to create bar window */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -916,6 +1202,7 @@ gui_bar_window_free (struct t_gui_bar_window *bar_window,
|
||||
|
||||
/* free data */
|
||||
gui_bar_window_content_free (bar_window);
|
||||
gui_bar_window_coords_free (bar_window);
|
||||
gui_bar_window_objects_free (bar_window);
|
||||
free (bar_window->gui_objects);
|
||||
|
||||
@@ -1059,6 +1346,46 @@ gui_bar_window_scroll (struct t_gui_bar_window *bar_window,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_window_hdata_bar_window_cb: return hdata for bar window
|
||||
*/
|
||||
|
||||
struct t_hdata *
|
||||
gui_bar_window_hdata_bar_window_cb (void *data, const char *hdata_name)
|
||||
{
|
||||
struct t_hdata *hdata;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
|
||||
hdata = hdata_new (NULL, hdata_name, "prev_bar_window", "next_bar_window");
|
||||
if (hdata)
|
||||
{
|
||||
HDATA_VAR(struct t_gui_bar_window, bar, POINTER, "bar");
|
||||
HDATA_VAR(struct t_gui_bar_window, x, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, y, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, width, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, height, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, scroll_x, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, scroll_y, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, cursor_x, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, cursor_y, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, current_size, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, items_count, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, items_subcount, POINTER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, items_content, POINTER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, items_num_lines, POINTER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, items_refresh_needed, POINTER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, screen_col_size, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, coords_count, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, coords, POINTER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, gui_objects, POINTER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar_window, prev_bar_window, POINTER, hdata_name);
|
||||
HDATA_VAR(struct t_gui_bar_window, next_bar_window, POINTER, hdata_name);
|
||||
}
|
||||
return hdata;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_window_add_to_infolist: add a bar window in an infolist
|
||||
* return 1 if ok, 0 if error
|
||||
@@ -1110,8 +1437,15 @@ gui_bar_window_add_to_infolist (struct t_infolist *infolist,
|
||||
if (!infolist_new_var_string (ptr_item, option_name,
|
||||
bar_window->items_content[i][j]))
|
||||
return 0;
|
||||
snprintf (option_name, sizeof (option_name),
|
||||
"items_num_lines_%05d_%05d", i + 1, j + 1);
|
||||
if (!infolist_new_var_integer (ptr_item, option_name,
|
||||
bar_window->items_num_lines[i][j]))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (!infolist_new_var_integer (ptr_item, "screen_col_size", bar_window->screen_col_size))
|
||||
return 0;
|
||||
if (!infolist_new_var_pointer (ptr_item, "gui_objects", bar_window->gui_objects))
|
||||
return 0;
|
||||
|
||||
@@ -1151,11 +1485,13 @@ gui_bar_window_print_log (struct t_gui_bar_window *bar_window)
|
||||
{
|
||||
for (j = 0; j < bar_window->items_subcount[i]; j++)
|
||||
{
|
||||
log_printf (" items_content[%03d][%03d]: '%s' (item: '%s')",
|
||||
log_printf (" items_content[%03d][%03d]: '%s' "
|
||||
"(item: '%s', num_lines: %d)",
|
||||
i, j,
|
||||
bar_window->items_content[i][j],
|
||||
(bar_window->items_count >= i + 1) ?
|
||||
bar_window->bar->items_array[i][j] : "?");
|
||||
bar_window->bar->items_array[i][j] : "?",
|
||||
bar_window->items_num_lines[i][j]);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1163,6 +1499,19 @@ gui_bar_window_print_log (struct t_gui_bar_window *bar_window)
|
||||
log_printf (" items_content. . . . . . : 0x%lx", bar_window->items_content);
|
||||
}
|
||||
}
|
||||
log_printf (" screen_col_size. . . . : %d", bar_window->screen_col_size);
|
||||
log_printf (" coords_count . . . . . : %d", bar_window->coords_count);
|
||||
for (i = 0; i < bar_window->coords_count; i++)
|
||||
{
|
||||
log_printf (" coords[%03d]. . . . . . : item=%d, subitem=%d, "
|
||||
"line=%d, x=%d, y=%d",
|
||||
i,
|
||||
bar_window->coords[i]->item,
|
||||
bar_window->coords[i]->subitem,
|
||||
bar_window->coords[i]->line,
|
||||
bar_window->coords[i]->x,
|
||||
bar_window->coords[i]->y);
|
||||
}
|
||||
log_printf (" gui_objects. . . . . . : 0x%lx", bar_window->gui_objects);
|
||||
gui_bar_window_objects_print_log (bar_window);
|
||||
log_printf (" prev_bar_window. . . . : 0x%lx", bar_window->prev_bar_window);
|
||||
|
||||
@@ -20,9 +20,19 @@
|
||||
#ifndef __WEECHAT_GUI_BAR_WINDOW_H
|
||||
#define __WEECHAT_GUI_BAR_WINDOW_H 1
|
||||
|
||||
struct t_infolist;
|
||||
struct t_gui_window;
|
||||
enum t_gui_bar_position;
|
||||
|
||||
struct t_gui_bar_window_coords
|
||||
{
|
||||
int item; /* index of item */
|
||||
int subitem; /* index of sub item */
|
||||
int line; /* line */
|
||||
int x; /* X on screen */
|
||||
int y; /* Y on screen */
|
||||
};
|
||||
|
||||
struct t_gui_bar_window
|
||||
{
|
||||
struct t_gui_bar *bar; /* pointer to bar */
|
||||
@@ -34,8 +44,14 @@ struct t_gui_bar_window
|
||||
int current_size; /* current size (width or height) */
|
||||
int items_count; /* number of bar items */
|
||||
int *items_subcount; /* number of sub items */
|
||||
char ***items_content; /* content for each item/sub item of bar*/
|
||||
char ***items_content; /* content for each (sub)item of bar */
|
||||
int **items_num_lines; /* number of lines for each (sub)item */
|
||||
int **items_refresh_needed; /* refresh needed for (sub)item? */
|
||||
int screen_col_size; /* size of columns on screen */
|
||||
/* (for filling with columns) */
|
||||
int coords_count; /* number of coords saved */
|
||||
struct t_gui_bar_window_coords **coords; /* coords for filling horiz. */
|
||||
/* (size is 5 * coords_count) */
|
||||
void *gui_objects; /* pointer to a GUI specific struct */
|
||||
struct t_gui_bar_window *prev_bar_window; /* link to previous bar win */
|
||||
/* (only for non-root bars) */
|
||||
@@ -46,6 +62,12 @@ struct t_gui_bar_window
|
||||
/* functions */
|
||||
|
||||
extern int gui_bar_window_valid (struct t_gui_bar_window *bar_window);
|
||||
extern void gui_bar_window_search_by_xy (struct t_gui_window *window,
|
||||
int x, int y,
|
||||
struct t_gui_bar_window **bar_window,
|
||||
char **bar_item,
|
||||
int *item_line,
|
||||
int *item_col);
|
||||
extern void gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window,
|
||||
struct t_gui_window *window);
|
||||
extern void gui_bar_window_content_build (struct t_gui_bar_window *bar_window,
|
||||
@@ -61,8 +83,15 @@ extern void gui_bar_window_set_current_size (struct t_gui_bar_window *bar_window
|
||||
extern int gui_bar_window_get_size (struct t_gui_bar *bar,
|
||||
struct t_gui_window *window,
|
||||
enum t_gui_bar_position position);
|
||||
extern int gui_bar_window_new (struct t_gui_bar *bar,
|
||||
struct t_gui_window *window);
|
||||
extern void gui_bar_window_coords_add (struct t_gui_bar_window *bar_window,
|
||||
int index_item, int index_subitem,
|
||||
int index_line,
|
||||
int x, int y);
|
||||
extern void gui_bar_window_coords_free (struct t_gui_bar_window *bar_window);
|
||||
extern void gui_bar_window_insert (struct t_gui_bar_window *bar_window,
|
||||
struct t_gui_window *window);
|
||||
extern void gui_bar_window_new (struct t_gui_bar *bar,
|
||||
struct t_gui_window *window);
|
||||
extern void gui_bar_window_free (struct t_gui_bar_window *bar_window,
|
||||
struct t_gui_window *window);
|
||||
extern int gui_bar_window_remove_unused_bars (struct t_gui_window *window);
|
||||
@@ -72,6 +101,8 @@ extern void gui_bar_window_scroll (struct t_gui_bar_window *bar_window,
|
||||
int add_x, int scroll_beginning,
|
||||
int scroll_end, int add, int percent,
|
||||
int value);
|
||||
extern struct t_hdata *gui_bar_window_hdata_bar_window_cb (void *data,
|
||||
const char *hdata_name);
|
||||
extern int gui_bar_window_add_to_infolist (struct t_infolist *infolist,
|
||||
struct t_gui_bar_window *bar_window);
|
||||
extern void gui_bar_window_print_log (struct t_gui_bar_window *bar_window);
|
||||
|
||||
+152
-46
@@ -637,24 +637,54 @@ gui_bar_apply_current_size (struct t_gui_bar *bar)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_free_items_array: free array with items for a bar
|
||||
* gui_bar_free_items_arrays: free arrays with items for a bar
|
||||
*/
|
||||
|
||||
void
|
||||
gui_bar_free_items_array (struct t_gui_bar *bar)
|
||||
gui_bar_free_items_arrays (struct t_gui_bar *bar)
|
||||
{
|
||||
int i;
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < bar->items_count; i++)
|
||||
{
|
||||
if (bar->items_array[i])
|
||||
string_free_split (bar->items_array[i]);
|
||||
for (j = 0; j < bar->items_subcount[i]; j++)
|
||||
{
|
||||
if (bar->items_prefix[i][j])
|
||||
free (bar->items_prefix[i][j]);
|
||||
if (bar->items_name[i][j])
|
||||
free (bar->items_name[i][j]);
|
||||
if (bar->items_suffix[i][j])
|
||||
free (bar->items_suffix[i][j]);
|
||||
}
|
||||
if (bar->items_prefix[i])
|
||||
free (bar->items_prefix[i]);
|
||||
if (bar->items_name[i])
|
||||
free (bar->items_name[i]);
|
||||
if (bar->items_suffix[i])
|
||||
free (bar->items_suffix[i]);
|
||||
}
|
||||
if (bar->items_array)
|
||||
{
|
||||
free (bar->items_array);
|
||||
bar->items_array = NULL;
|
||||
}
|
||||
if (bar->items_prefix)
|
||||
{
|
||||
free (bar->items_prefix);
|
||||
bar->items_prefix = NULL;
|
||||
}
|
||||
if (bar->items_name)
|
||||
{
|
||||
free (bar->items_name);
|
||||
bar->items_name = NULL;
|
||||
}
|
||||
if (bar->items_suffix)
|
||||
{
|
||||
free (bar->items_suffix);
|
||||
bar->items_suffix = NULL;
|
||||
}
|
||||
if (bar->items_subcount)
|
||||
{
|
||||
free (bar->items_subcount);
|
||||
@@ -670,10 +700,10 @@ gui_bar_free_items_array (struct t_gui_bar *bar)
|
||||
void
|
||||
gui_bar_set_items_array (struct t_gui_bar *bar, const char *items)
|
||||
{
|
||||
int i, count;
|
||||
int i, j, count;
|
||||
char **tmp_array;
|
||||
|
||||
gui_bar_free_items_array (bar);
|
||||
gui_bar_free_items_arrays (bar);
|
||||
|
||||
if (items && items[0])
|
||||
{
|
||||
@@ -683,10 +713,29 @@ gui_bar_set_items_array (struct t_gui_bar *bar, const char *items)
|
||||
bar->items_count = count;
|
||||
bar->items_subcount = malloc (count * sizeof (*bar->items_subcount));
|
||||
bar->items_array = malloc (count * sizeof (*bar->items_array));
|
||||
bar->items_prefix = malloc (count * sizeof (*bar->items_prefix));
|
||||
bar->items_name = malloc (count * sizeof (*bar->items_name));
|
||||
bar->items_suffix = malloc (count * sizeof (*bar->items_suffix));
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
bar->items_array[i] = string_split (tmp_array[i], "+", 0, 0,
|
||||
&(bar->items_subcount[i]));
|
||||
if (bar->items_subcount[i] > 0)
|
||||
{
|
||||
bar->items_prefix[i] = malloc (bar->items_subcount[i] *
|
||||
sizeof (*(bar->items_prefix[i])));
|
||||
bar->items_name[i] = malloc (bar->items_subcount[i] *
|
||||
sizeof (*(bar->items_name[i])));
|
||||
bar->items_suffix[i] = malloc (bar->items_subcount[i] *
|
||||
sizeof (*(bar->items_suffix[i])));
|
||||
for (j = 0; j < bar->items_subcount[i]; j++)
|
||||
{
|
||||
gui_bar_item_set_prefix_name_suffix (bar->items_array[i][j],
|
||||
&bar->items_prefix[i][j],
|
||||
&bar->items_name[i][j],
|
||||
&bar->items_suffix[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
string_free_split (tmp_array);
|
||||
@@ -722,6 +771,8 @@ gui_bar_config_change_hidden (void *data, struct t_config_option *option)
|
||||
{
|
||||
struct t_gui_bar *ptr_bar;
|
||||
struct t_gui_window *ptr_win;
|
||||
struct t_gui_bar_window *ptr_bar_win;
|
||||
int bar_window_exists;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -729,26 +780,43 @@ gui_bar_config_change_hidden (void *data, struct t_config_option *option)
|
||||
ptr_bar = gui_bar_search_with_option_name (option->name);
|
||||
if (ptr_bar)
|
||||
{
|
||||
/* free bar windows */
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
if (CONFIG_INTEGER(ptr_bar->options[GUI_BAR_OPTION_TYPE]) == GUI_BAR_TYPE_ROOT)
|
||||
{
|
||||
gui_bar_free_bar_windows (ptr_bar);
|
||||
}
|
||||
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
{
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
if (CONFIG_BOOLEAN(ptr_bar->options[GUI_BAR_OPTION_HIDDEN]))
|
||||
{
|
||||
if (!CONFIG_BOOLEAN(ptr_bar->options[GUI_BAR_OPTION_HIDDEN])
|
||||
&& (CONFIG_INTEGER(ptr_bar->options[GUI_BAR_OPTION_TYPE]) != GUI_BAR_TYPE_ROOT))
|
||||
gui_bar_window_free (ptr_bar->bar_window, NULL);
|
||||
ptr_bar->bar_window = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_bar_window_new (ptr_bar, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
{
|
||||
bar_window_exists = 0;
|
||||
for (ptr_bar_win = ptr_win->bar_windows; ptr_bar_win;
|
||||
ptr_bar_win = ptr_bar_win->next_bar_window)
|
||||
{
|
||||
if (ptr_bar_win->bar == ptr_bar)
|
||||
{
|
||||
if (CONFIG_BOOLEAN(ptr_bar->options[GUI_BAR_OPTION_HIDDEN]))
|
||||
gui_bar_window_free (ptr_bar_win, ptr_win);
|
||||
else
|
||||
bar_window_exists = 1;
|
||||
}
|
||||
}
|
||||
if (!bar_window_exists
|
||||
&& !CONFIG_BOOLEAN(ptr_bar->options[GUI_BAR_OPTION_HIDDEN]))
|
||||
{
|
||||
gui_bar_window_new (ptr_bar, ptr_win);
|
||||
}
|
||||
}
|
||||
}
|
||||
gui_window_ask_refresh (1);
|
||||
}
|
||||
|
||||
gui_window_ask_refresh (1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -760,6 +828,7 @@ gui_bar_config_change_priority (void *data, struct t_config_option *option)
|
||||
{
|
||||
struct t_gui_bar *ptr_bar;
|
||||
struct t_gui_window *ptr_win;
|
||||
struct t_gui_bar_window *bar_windows, *ptr_bar_win, *next_bar_win;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -785,26 +854,24 @@ gui_bar_config_change_priority (void *data, struct t_config_option *option)
|
||||
|
||||
gui_bar_insert (ptr_bar);
|
||||
|
||||
/* free bar windows */
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
{
|
||||
gui_bar_free_bar_windows (ptr_bar);
|
||||
}
|
||||
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
{
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
bar_windows = ptr_win->bar_windows;
|
||||
ptr_win->bar_windows = NULL;
|
||||
ptr_win->last_bar_window = NULL;
|
||||
ptr_bar_win = bar_windows;
|
||||
while (ptr_bar_win)
|
||||
{
|
||||
if (!CONFIG_BOOLEAN(ptr_bar->options[GUI_BAR_OPTION_HIDDEN])
|
||||
&& (CONFIG_INTEGER(ptr_bar->options[GUI_BAR_OPTION_TYPE]) != GUI_BAR_TYPE_ROOT))
|
||||
{
|
||||
gui_bar_window_new (ptr_bar, ptr_win);
|
||||
}
|
||||
next_bar_win = ptr_bar_win->next_bar_window;
|
||||
|
||||
gui_bar_window_insert (ptr_bar_win, ptr_win);
|
||||
|
||||
ptr_bar_win = next_bar_win;
|
||||
}
|
||||
}
|
||||
|
||||
gui_window_ask_refresh (1);
|
||||
}
|
||||
|
||||
gui_window_ask_refresh (1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1468,6 +1535,9 @@ gui_bar_alloc (const char *name)
|
||||
new_bar->conditions_array = NULL;
|
||||
new_bar->items_count = 0;
|
||||
new_bar->items_array = NULL;
|
||||
new_bar->items_prefix = NULL;
|
||||
new_bar->items_name = NULL;
|
||||
new_bar->items_suffix = NULL;
|
||||
new_bar->bar_window = NULL;
|
||||
new_bar->bar_refresh_needed = 0;
|
||||
new_bar->prev_bar = NULL;
|
||||
@@ -1533,6 +1603,9 @@ gui_bar_new_with_options (const char *name,
|
||||
new_bar->items_count = 0;
|
||||
new_bar->items_subcount = NULL;
|
||||
new_bar->items_array = NULL;
|
||||
new_bar->items_prefix = NULL;
|
||||
new_bar->items_name = NULL;
|
||||
new_bar->items_suffix = NULL;
|
||||
gui_bar_set_items_array (new_bar, CONFIG_STRING(items));
|
||||
new_bar->bar_window = NULL;
|
||||
new_bar->bar_refresh_needed = 1;
|
||||
@@ -1983,7 +2056,11 @@ gui_bar_scroll (struct t_gui_bar *bar, struct t_gui_buffer *buffer,
|
||||
scroll++;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
{
|
||||
/* auto-detect if we scroll X/Y, according to filling */
|
||||
if (gui_bar_get_filling (bar) == GUI_BAR_FILLING_HORIZONTAL)
|
||||
add_x = 1;
|
||||
}
|
||||
|
||||
if ((scroll[0] == 'b') || (scroll[0] == 'B'))
|
||||
{
|
||||
@@ -2032,9 +2109,11 @@ gui_bar_scroll (struct t_gui_bar *bar, struct t_gui_buffer *buffer,
|
||||
}
|
||||
|
||||
if (CONFIG_INTEGER(bar->options[GUI_BAR_OPTION_TYPE]) == GUI_BAR_TYPE_ROOT)
|
||||
{
|
||||
gui_bar_window_scroll (bar->bar_window, NULL,
|
||||
add_x, scroll_beginning, scroll_end,
|
||||
add, percent, number);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
@@ -2055,7 +2134,8 @@ gui_bar_scroll (struct t_gui_bar *bar, struct t_gui_buffer *buffer,
|
||||
}
|
||||
}
|
||||
|
||||
free (str);
|
||||
if (str)
|
||||
free (str);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -2101,7 +2181,7 @@ gui_bar_free (struct t_gui_bar *bar)
|
||||
}
|
||||
if (bar->conditions_array)
|
||||
string_free_split (bar->conditions_array);
|
||||
gui_bar_free_items_array (bar);
|
||||
gui_bar_free_items_arrays (bar);
|
||||
|
||||
free (bar);
|
||||
}
|
||||
@@ -2129,17 +2209,25 @@ gui_bar_free_bar_windows (struct t_gui_bar *bar)
|
||||
struct t_gui_window *ptr_win;
|
||||
struct t_gui_bar_window *ptr_bar_win, *next_bar_win;
|
||||
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
if (bar->bar_window)
|
||||
{
|
||||
ptr_bar_win = ptr_win->bar_windows;
|
||||
while (ptr_bar_win)
|
||||
gui_bar_window_free (bar->bar_window, NULL);
|
||||
bar->bar_window = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
{
|
||||
next_bar_win = ptr_bar_win->next_bar_window;
|
||||
|
||||
if (ptr_bar_win->bar == bar)
|
||||
gui_bar_window_free (ptr_bar_win, ptr_win);
|
||||
|
||||
ptr_bar_win = next_bar_win;
|
||||
ptr_bar_win = ptr_win->bar_windows;
|
||||
while (ptr_bar_win)
|
||||
{
|
||||
next_bar_win = ptr_bar_win->next_bar_window;
|
||||
|
||||
if (ptr_bar_win->bar == bar)
|
||||
gui_bar_window_free (ptr_bar_win, ptr_win);
|
||||
|
||||
ptr_bar_win = next_bar_win;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2166,7 +2254,10 @@ gui_bar_hdata_bar_cb (void *data, const char *hdata_name)
|
||||
HDATA_VAR(struct t_gui_bar, items_count, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar, items_subcount, POINTER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar, items_array, POINTER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar, bar_window, POINTER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar, items_prefix, POINTER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar, items_name, POINTER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar, items_suffix, POINTER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar, bar_window, POINTER, "bar_window");
|
||||
HDATA_VAR(struct t_gui_bar, bar_refresh_needed, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_bar, prev_bar, POINTER, hdata_name);
|
||||
HDATA_VAR(struct t_gui_bar, next_bar, POINTER, hdata_name);
|
||||
@@ -2247,6 +2338,16 @@ gui_bar_add_to_infolist (struct t_infolist *infolist,
|
||||
if (!infolist_new_var_string (ptr_item, option_name,
|
||||
bar->items_array[i][j]))
|
||||
return 0;
|
||||
snprintf (option_name, sizeof (option_name),
|
||||
"items_prefix_%05d_%05d", i + 1, j + 1);
|
||||
if (!infolist_new_var_string (ptr_item, option_name,
|
||||
bar->items_prefix[i][j]))
|
||||
return 0;
|
||||
snprintf (option_name, sizeof (option_name),
|
||||
"items_suffix_%05d_%05d", i + 1, j + 1);
|
||||
if (!infolist_new_var_string (ptr_item, option_name,
|
||||
bar->items_suffix[i][j]))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (!infolist_new_var_pointer (ptr_item, "bar_window", bar->bar_window))
|
||||
@@ -2307,8 +2408,13 @@ gui_bar_print_log ()
|
||||
i, ptr_bar->items_subcount[i]);
|
||||
for (j = 0; j < ptr_bar->items_subcount[i]; j++)
|
||||
{
|
||||
log_printf (" items_array[%03d][%03d]: '%s'",
|
||||
i, j, ptr_bar->items_array[i][j]);
|
||||
log_printf (" items_array[%03d][%03d]: '%s' "
|
||||
"(prefix: '%s', name: '%s', suffix: '%s')",
|
||||
i, j,
|
||||
ptr_bar->items_array[i][j],
|
||||
ptr_bar->items_prefix[i][j],
|
||||
ptr_bar->items_name[i][j],
|
||||
ptr_bar->items_suffix[i][j]);
|
||||
}
|
||||
}
|
||||
log_printf (" bar_window . . . . . . : 0x%lx", ptr_bar->bar_window);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#ifndef __WEECHAT_GUI_BAR_H
|
||||
#define __WEECHAT_GUI_BAR_H 1
|
||||
|
||||
struct t_infolist;
|
||||
struct t_weechat_plugin;
|
||||
struct t_gui_window;
|
||||
struct t_gui_buffer;
|
||||
@@ -89,6 +90,9 @@ struct t_gui_bar
|
||||
int items_count; /* number of bar items */
|
||||
int *items_subcount; /* number of sub items */
|
||||
char ***items_array; /* bar items (after split) */
|
||||
char ***items_prefix; /* prefix for each (sub)item */
|
||||
char ***items_name; /* name for each (sub)item */
|
||||
char ***items_suffix; /* suffix for each (sub)item */
|
||||
struct t_gui_bar_window *bar_window; /* pointer to bar window */
|
||||
/* (for type root only) */
|
||||
int bar_refresh_needed; /* refresh for bar is needed? */
|
||||
|
||||
@@ -515,6 +515,8 @@ gui_color_decode (const char *string, const char *replacement)
|
||||
case GUI_COLOR_BAR_START_INPUT_CHAR:
|
||||
case GUI_COLOR_BAR_START_INPUT_HIDDEN_CHAR:
|
||||
case GUI_COLOR_BAR_MOVE_CURSOR_CHAR:
|
||||
case GUI_COLOR_BAR_START_ITEM:
|
||||
case GUI_COLOR_BAR_START_LINE_ITEM:
|
||||
ptr_string++;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -104,6 +104,8 @@ enum t_gui_color_enum
|
||||
#define GUI_COLOR_BAR_START_INPUT_CHAR '_'
|
||||
#define GUI_COLOR_BAR_START_INPUT_HIDDEN_CHAR '-'
|
||||
#define GUI_COLOR_BAR_MOVE_CURSOR_CHAR '#'
|
||||
#define GUI_COLOR_BAR_START_ITEM 'i'
|
||||
#define GUI_COLOR_BAR_START_LINE_ITEM 'l'
|
||||
|
||||
#define GUI_COLOR_EXTENDED_FLAG 0x0100000
|
||||
#define GUI_COLOR_EXTENDED_BOLD_FLAG 0x0200000
|
||||
|
||||
@@ -1027,7 +1027,7 @@ gui_completion_complete (struct t_gui_completion *completion)
|
||||
other_completion++;
|
||||
}
|
||||
if (completion->word_found &&
|
||||
(string_strcasecmp (ptr_item->data, completion->word_found) == 0))
|
||||
(strcmp (ptr_item->data, completion->word_found) == 0))
|
||||
word_found_seen = 1;
|
||||
|
||||
if (completion->direction < 0)
|
||||
|
||||
@@ -0,0 +1,337 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Sebastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat 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 WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* gui-cursor.c: functions for free movement of cursor (used by all GUI)
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../core/weechat.h"
|
||||
#include "gui-cursor.h"
|
||||
#include "gui-bar.h"
|
||||
#include "gui-bar-window.h"
|
||||
#include "gui-buffer.h"
|
||||
#include "gui-chat.h"
|
||||
#include "gui-color.h"
|
||||
#include "gui-input.h"
|
||||
#include "gui-window.h"
|
||||
|
||||
|
||||
int gui_cursor_mode = 0; /* cursor mode? (free movement) */
|
||||
int gui_cursor_debug = 0; /* debug mode (show info in input) */
|
||||
int gui_cursor_x = 0; /* position of cursor in cursor mode */
|
||||
int gui_cursor_y = 0; /* position of cursor in cursor mode */
|
||||
|
||||
|
||||
/*
|
||||
* gui_cursor_mode_toggle: toggle cursor mode
|
||||
*/
|
||||
|
||||
void
|
||||
gui_cursor_mode_toggle ()
|
||||
{
|
||||
gui_cursor_mode ^= 1;
|
||||
|
||||
if (gui_cursor_mode)
|
||||
{
|
||||
if (gui_cursor_debug)
|
||||
gui_input_delete_line (gui_current_window->buffer);
|
||||
gui_cursor_x = gui_window_cursor_x;
|
||||
gui_cursor_y = gui_window_cursor_y;
|
||||
gui_cursor_move_xy (0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* restore input (and move cursor in input) */
|
||||
if (gui_cursor_debug)
|
||||
gui_input_delete_line (gui_current_window->buffer);
|
||||
gui_input_text_changed_modifier_and_signal (gui_current_window->buffer, 0);
|
||||
gui_buffer_ask_chat_refresh (gui_current_window->buffer, 2);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_cursor_debug_toggle: toggle debug for cursor mode
|
||||
*/
|
||||
|
||||
void
|
||||
gui_cursor_debug_toggle ()
|
||||
{
|
||||
gui_cursor_debug ^= 1;
|
||||
|
||||
if (gui_cursor_debug)
|
||||
gui_chat_printf (NULL, _("Debug enabled for cursor mode"));
|
||||
else
|
||||
gui_chat_printf (NULL, _("Debug disabled for cursor mode"));
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_cursor_get_info: get info about what is pointed by cursor at (x,y)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_cursor_get_info (int x, int y, struct t_gui_cursor_info *cursor_info)
|
||||
{
|
||||
cursor_info->x = x;
|
||||
cursor_info->y = y;
|
||||
|
||||
/* search window */
|
||||
cursor_info->window = gui_window_search_by_xy (x, y);
|
||||
|
||||
/* chat area in this window? */
|
||||
if (cursor_info->window
|
||||
&& (x >= (cursor_info->window)->win_chat_x)
|
||||
&& (y >= (cursor_info->window)->win_chat_y)
|
||||
&& (x <= (cursor_info->window)->win_chat_x + (cursor_info->window)->win_chat_width - 1)
|
||||
&& (y <= (cursor_info->window)->win_chat_y + (cursor_info->window)->win_chat_height - 1))
|
||||
{
|
||||
cursor_info->chat = 1;
|
||||
}
|
||||
else
|
||||
cursor_info->chat = 0;
|
||||
|
||||
/* search bar window, item, and line/col in item */
|
||||
gui_bar_window_search_by_xy (cursor_info->window, x, y,
|
||||
&cursor_info->bar_window,
|
||||
&cursor_info->bar_item,
|
||||
&cursor_info->item_line,
|
||||
&cursor_info->item_col);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_cursor_display_debug_info: display debug info about (x,y) in input
|
||||
*/
|
||||
|
||||
void
|
||||
gui_cursor_display_debug_info ()
|
||||
{
|
||||
struct t_gui_cursor_info cursor_info;
|
||||
char str_info[1024];
|
||||
|
||||
if (!gui_cursor_debug)
|
||||
return;
|
||||
|
||||
gui_cursor_get_info (gui_cursor_x, gui_cursor_y, &cursor_info);
|
||||
|
||||
snprintf (str_info, sizeof (str_info),
|
||||
"%s(%d,%d) window:0x%lx (buffer: %s), chat: %d, "
|
||||
"bar_window:0x%lx (bar: %s, item: %s, line: %d, col: %d)",
|
||||
gui_color_get_custom ("yellow,red"),
|
||||
cursor_info.x, cursor_info.y,
|
||||
(long unsigned int)cursor_info.window,
|
||||
(cursor_info.window) ? (cursor_info.window)->buffer->name : "-",
|
||||
cursor_info.chat,
|
||||
(long unsigned int)cursor_info.bar_window,
|
||||
(cursor_info.bar_window) ? (cursor_info.bar_window)->bar->name : "-",
|
||||
(cursor_info.bar_item) ? cursor_info.bar_item : "-",
|
||||
cursor_info.item_line,
|
||||
cursor_info.item_col);
|
||||
gui_input_delete_line (gui_current_window->buffer);
|
||||
gui_input_insert_string (gui_current_window->buffer, str_info, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_cursor_move_xy: set cursor at position (x,y)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_cursor_move_xy (int x, int y)
|
||||
{
|
||||
if (!gui_cursor_mode)
|
||||
gui_cursor_mode_toggle ();
|
||||
|
||||
gui_cursor_x = x;
|
||||
gui_cursor_y = y;
|
||||
|
||||
if (gui_cursor_x < 0)
|
||||
gui_cursor_x = 0;
|
||||
else if (gui_cursor_x > gui_window_get_width () - 1)
|
||||
gui_cursor_x = gui_window_get_width () - 1;
|
||||
|
||||
if (gui_cursor_y < 0)
|
||||
gui_cursor_y = 0;
|
||||
else if (gui_cursor_y > gui_window_get_height () - 1)
|
||||
gui_cursor_y = gui_window_get_height () - 1;
|
||||
|
||||
gui_cursor_display_debug_info ();
|
||||
gui_window_move_cursor ();
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_cursor_move_add_xy: move cursor by adding values to (x,y)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_cursor_move_add_xy (int add_x, int add_y)
|
||||
{
|
||||
if (!gui_cursor_mode)
|
||||
gui_cursor_mode_toggle ();
|
||||
|
||||
gui_cursor_x += add_x;
|
||||
gui_cursor_y += add_y;
|
||||
|
||||
if (gui_cursor_x < 0)
|
||||
gui_cursor_x = gui_window_get_width () - 1;
|
||||
else if (gui_cursor_x > gui_window_get_width () - 1)
|
||||
gui_cursor_x = 0;
|
||||
|
||||
if (gui_cursor_y < 0)
|
||||
gui_cursor_y = gui_window_get_height () - 1;
|
||||
else if (gui_cursor_y > gui_window_get_height () - 1)
|
||||
gui_cursor_y = 0;
|
||||
|
||||
gui_cursor_display_debug_info ();
|
||||
gui_window_move_cursor ();
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_cursor_move_area_add_xy: move cursor to another area by adding values to
|
||||
* (x,y)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_cursor_move_area_add_xy (int add_x, int add_y)
|
||||
{
|
||||
int x, y, width, height, area_found;
|
||||
struct t_gui_cursor_info cursor_info_old, cursor_info_new;
|
||||
|
||||
if (!gui_cursor_mode)
|
||||
gui_cursor_mode_toggle ();
|
||||
|
||||
area_found = 0;
|
||||
|
||||
x = gui_cursor_x;
|
||||
y = gui_cursor_y;
|
||||
width = gui_window_get_width ();
|
||||
height = gui_window_get_height ();
|
||||
|
||||
gui_cursor_get_info (x, y, &cursor_info_old);
|
||||
|
||||
if (add_x != 0)
|
||||
x += add_x;
|
||||
else
|
||||
y += add_y;
|
||||
|
||||
while ((x >= 0) && (x < width) && (y >= 0) && (y < height))
|
||||
{
|
||||
gui_cursor_get_info (x, y, &cursor_info_new);
|
||||
if (((cursor_info_new.window && cursor_info_new.chat)
|
||||
|| cursor_info_new.bar_window)
|
||||
&& ((cursor_info_old.window != cursor_info_new.window)
|
||||
|| (cursor_info_old.bar_window != cursor_info_new.bar_window)))
|
||||
{
|
||||
area_found = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (add_x != 0)
|
||||
x += add_x;
|
||||
else
|
||||
y += add_y;
|
||||
}
|
||||
|
||||
if (area_found)
|
||||
{
|
||||
if (cursor_info_new.window && cursor_info_new.chat)
|
||||
{
|
||||
x = (cursor_info_new.window)->win_chat_x;
|
||||
y = (cursor_info_new.window)->win_chat_y;
|
||||
}
|
||||
else if (cursor_info_new.bar_window)
|
||||
{
|
||||
x = (cursor_info_new.bar_window)->x;
|
||||
y = (cursor_info_new.bar_window)->y;
|
||||
}
|
||||
else
|
||||
area_found = 0;
|
||||
}
|
||||
|
||||
if (area_found)
|
||||
{
|
||||
gui_cursor_x = x;
|
||||
gui_cursor_y = y;
|
||||
gui_cursor_display_debug_info ();
|
||||
gui_window_move_cursor ();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_cursor_move_area: move cursor to another area by name
|
||||
*/
|
||||
|
||||
void
|
||||
gui_cursor_move_area (const char *area)
|
||||
{
|
||||
int area_found, x, y;
|
||||
struct t_gui_bar_window *ptr_bar_win;
|
||||
struct t_gui_bar *ptr_bar;
|
||||
|
||||
area_found = 0;
|
||||
x = 0;
|
||||
y = 0;
|
||||
|
||||
if (strcmp (area, "chat") == 0)
|
||||
{
|
||||
area_found = 1;
|
||||
x = gui_current_window->win_chat_x;
|
||||
y = gui_current_window->win_chat_y;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ptr_bar_win = gui_current_window->bar_windows; ptr_bar_win;
|
||||
ptr_bar_win = ptr_bar_win->next_bar_window)
|
||||
{
|
||||
if (strcmp (ptr_bar_win->bar->name, area) == 0)
|
||||
{
|
||||
area_found = 1;
|
||||
x = ptr_bar_win->x;
|
||||
y = ptr_bar_win->y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!area_found)
|
||||
{
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
{
|
||||
if (ptr_bar->bar_window && (strcmp (ptr_bar->name, area) == 0))
|
||||
{
|
||||
area_found = 1;
|
||||
x = ptr_bar->bar_window->x;
|
||||
y = ptr_bar->bar_window->y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (area_found)
|
||||
{
|
||||
if (!gui_cursor_mode)
|
||||
gui_cursor_mode_toggle ();
|
||||
gui_cursor_x = x;
|
||||
gui_cursor_y = y;
|
||||
gui_cursor_display_debug_info ();
|
||||
gui_window_move_cursor ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Sebastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat 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 WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __WEECHAT_GUI_CURSOR_H
|
||||
#define __WEECHAT_GUI_CURSOR_H 1
|
||||
|
||||
/* cursor structures */
|
||||
|
||||
struct t_gui_cursor_info
|
||||
{
|
||||
int x, y; /* (x,y) on screen */
|
||||
struct t_gui_window *window; /* window found */
|
||||
int chat; /* 1 for chat area, otherwise 0 */
|
||||
struct t_gui_bar_window *bar_window; /* bar window found */
|
||||
char *bar_item; /* bar item found */
|
||||
int item_line; /* line in bar item */
|
||||
int item_col; /* column in bar item */
|
||||
};
|
||||
|
||||
/* cursor variables */
|
||||
|
||||
extern int gui_cursor_mode;
|
||||
extern int gui_cursor_debug;
|
||||
extern int gui_cursor_x;
|
||||
extern int gui_cursor_y;
|
||||
|
||||
/* cursor functions */
|
||||
|
||||
extern void gui_cursor_mode_toggle ();
|
||||
extern void gui_cursor_debug_toggle ();
|
||||
extern void gui_cursor_get_info (int x, int y,
|
||||
struct t_gui_cursor_info *cursor_info);
|
||||
extern void gui_cursor_move_xy (int x, int y);
|
||||
extern void gui_cursor_move_add_xy (int add_x, int add_y);
|
||||
extern void gui_cursor_move_area_add_xy (int add_x, int add_y);
|
||||
extern void gui_cursor_move_area (const char *area);
|
||||
|
||||
#endif /* __WEECHAT_GUI_CURSOR_H */
|
||||
+25
-21
@@ -38,6 +38,7 @@
|
||||
#include "gui-input.h"
|
||||
#include "gui-buffer.h"
|
||||
#include "gui-completion.h"
|
||||
#include "gui-cursor.h"
|
||||
#include "gui-history.h"
|
||||
#include "gui-hotlist.h"
|
||||
#include "gui-key.h"
|
||||
@@ -117,26 +118,29 @@ gui_input_text_changed_modifier_and_signal (struct t_gui_buffer *buffer,
|
||||
{
|
||||
char str_buffer[128], *new_input;
|
||||
|
||||
if (save_undo)
|
||||
gui_buffer_undo_add (buffer);
|
||||
|
||||
/* send modifier, and change input if needed */
|
||||
snprintf (str_buffer, sizeof (str_buffer),
|
||||
"0x%lx", (long unsigned int)buffer);
|
||||
new_input = hook_modifier_exec (NULL,
|
||||
"input_text_content",
|
||||
str_buffer,
|
||||
(buffer->input_buffer) ?
|
||||
buffer->input_buffer : "");
|
||||
if (new_input)
|
||||
if (!gui_cursor_mode)
|
||||
{
|
||||
if (!buffer->input_buffer
|
||||
|| strcmp (new_input, buffer->input_buffer) != 0)
|
||||
if (save_undo)
|
||||
gui_buffer_undo_add (buffer);
|
||||
|
||||
/* send modifier, and change input if needed */
|
||||
snprintf (str_buffer, sizeof (str_buffer),
|
||||
"0x%lx", (long unsigned int)buffer);
|
||||
new_input = hook_modifier_exec (NULL,
|
||||
"input_text_content",
|
||||
str_buffer,
|
||||
(buffer->input_buffer) ?
|
||||
buffer->input_buffer : "");
|
||||
if (new_input)
|
||||
{
|
||||
/* input has been changed by modifier, use it */
|
||||
gui_input_replace_input (buffer, new_input);
|
||||
if (!buffer->input_buffer
|
||||
|| strcmp (new_input, buffer->input_buffer) != 0)
|
||||
{
|
||||
/* input has been changed by modifier, use it */
|
||||
gui_input_replace_input (buffer, new_input);
|
||||
}
|
||||
free (new_input);
|
||||
}
|
||||
free (new_input);
|
||||
}
|
||||
|
||||
/* send signal */
|
||||
@@ -1339,10 +1343,10 @@ gui_input_hotlist_clear (struct t_gui_buffer *buffer)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_grab_key (struct t_gui_buffer *buffer)
|
||||
gui_input_grab_key (struct t_gui_buffer *buffer, const char *delay)
|
||||
{
|
||||
if (buffer->input)
|
||||
gui_key_grab_init (0);
|
||||
gui_key_grab_init (0, delay);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1351,10 +1355,10 @@ gui_input_grab_key (struct t_gui_buffer *buffer)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_grab_key_command (struct t_gui_buffer *buffer)
|
||||
gui_input_grab_key_command (struct t_gui_buffer *buffer, const char *delay)
|
||||
{
|
||||
if (buffer->input)
|
||||
gui_key_grab_init (1);
|
||||
gui_key_grab_init (1, delay);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+4
-2
@@ -70,8 +70,10 @@ extern void gui_input_jump_last_buffer (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_jump_previously_visited_buffer (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_jump_next_visited_buffer (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_hotlist_clear (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_grab_key (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_grab_key_command (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_grab_key (struct t_gui_buffer *buffer,
|
||||
const char *delay);
|
||||
extern void gui_input_grab_key_command (struct t_gui_buffer *buffer,
|
||||
const char *delay);
|
||||
extern void gui_input_scroll_unread (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_set_unread ();
|
||||
extern void gui_input_set_unread_current (struct t_gui_buffer *buffer);
|
||||
|
||||
+303
-37
@@ -32,6 +32,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#include "../core/weechat.h"
|
||||
#include "../core/wee-hashtable.h"
|
||||
#include "../core/wee-hdata.h"
|
||||
#include "../core/wee-hook.h"
|
||||
#include "../core/wee-infolist.h"
|
||||
@@ -41,11 +42,15 @@
|
||||
#include "../core/wee-utf8.h"
|
||||
#include "../plugins/plugin.h"
|
||||
#include "gui-key.h"
|
||||
#include "gui-bar.h"
|
||||
#include "gui-bar-window.h"
|
||||
#include "gui-buffer.h"
|
||||
#include "gui-chat.h"
|
||||
#include "gui-color.h"
|
||||
#include "gui-completion.h"
|
||||
#include "gui-cursor.h"
|
||||
#include "gui-input.h"
|
||||
#include "gui-mouse.h"
|
||||
#include "gui-window.h"
|
||||
|
||||
|
||||
@@ -57,14 +62,15 @@ int gui_keys_count[GUI_KEY_NUM_CONTEXTS]; /* keys number */
|
||||
int gui_default_keys_count[GUI_KEY_NUM_CONTEXTS]; /* default keys number */
|
||||
|
||||
char *gui_key_context_string[GUI_KEY_NUM_CONTEXTS] =
|
||||
{ "default", "search" };
|
||||
{ "default", "search", "cursor", "mouse" };
|
||||
|
||||
int gui_key_verbose = 0; /* 1 to see some messages */
|
||||
|
||||
char gui_key_combo_buffer[128]; /* buffer used for combos */
|
||||
char gui_key_combo_buffer[256]; /* buffer used for combos */
|
||||
int gui_key_grab = 0; /* 1 if grab mode enabled (alt-k) */
|
||||
int gui_key_grab_count = 0; /* number of keys pressed in grab mode */
|
||||
int gui_key_grab_command = 0; /* grab command bound to key? */
|
||||
int gui_key_grab_delay = 0; /* delay for grab (default is 500) */
|
||||
|
||||
int *gui_key_buffer = NULL; /* input buffer (for paste detection) */
|
||||
int gui_key_buffer_alloc = 0; /* input buffer allocated size */
|
||||
@@ -136,6 +142,9 @@ gui_key_search_context (const char *context)
|
||||
int
|
||||
gui_key_get_current_context ()
|
||||
{
|
||||
if (gui_cursor_mode)
|
||||
return GUI_KEY_CONTEXT_CURSOR;
|
||||
|
||||
if (gui_current_window
|
||||
&& (gui_current_window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED))
|
||||
return GUI_KEY_CONTEXT_SEARCH;
|
||||
@@ -148,24 +157,44 @@ gui_key_get_current_context ()
|
||||
*/
|
||||
|
||||
void
|
||||
gui_key_grab_init (int grab_command)
|
||||
gui_key_grab_init (int grab_command, const char *delay)
|
||||
{
|
||||
long milliseconds;
|
||||
char *error;
|
||||
|
||||
gui_key_grab = 1;
|
||||
gui_key_grab_count = 0;
|
||||
gui_key_grab_command = grab_command;
|
||||
|
||||
gui_key_grab_delay = GUI_KEY_GRAB_DELAY_DEFAULT;
|
||||
if (delay != NULL)
|
||||
{
|
||||
error = NULL;
|
||||
milliseconds = strtol (delay, &error, 10);
|
||||
if (error && !error[0] && (milliseconds >= 0))
|
||||
{
|
||||
gui_key_grab_delay = milliseconds;
|
||||
if (gui_key_grab_delay == 0)
|
||||
gui_key_grab_delay = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_key_grab_end: insert grabbed key in input buffer
|
||||
* gui_key_grab_end_timer_cb: insert grabbed key in input buffer
|
||||
*/
|
||||
|
||||
void
|
||||
gui_key_grab_end ()
|
||||
int
|
||||
gui_key_grab_end_timer_cb (void *data, int remaining_calls)
|
||||
{
|
||||
char *expanded_key;
|
||||
struct t_gui_key *ptr_key;
|
||||
|
||||
/* get expanded name (for example: ^U => ctrl-u) */
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) remaining_calls;
|
||||
|
||||
/* get expanded name (for example: \x01+U => ctrl-u) */
|
||||
expanded_key = gui_key_get_expanded_name (gui_key_combo_buffer);
|
||||
|
||||
if (expanded_key)
|
||||
@@ -195,11 +224,13 @@ gui_key_grab_end ()
|
||||
gui_key_grab_count = 0;
|
||||
gui_key_grab_command = 0;
|
||||
gui_key_combo_buffer[0] = '\0';
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_key_get_internal_code: get internal code from user key name
|
||||
* for example: return "^R" for "ctrl-R"
|
||||
* for example: return "\x01+R" for "ctrl-R"
|
||||
*/
|
||||
|
||||
char *
|
||||
@@ -214,17 +245,17 @@ gui_key_get_internal_code (const char *key)
|
||||
{
|
||||
if (strncmp (key, "meta2-", 6) == 0)
|
||||
{
|
||||
strcat (result, "^[[");
|
||||
strcat (result, "\x01[[");
|
||||
key += 6;
|
||||
}
|
||||
if (strncmp (key, "meta-", 5) == 0)
|
||||
{
|
||||
strcat (result, "^[");
|
||||
strcat (result, "\x01[");
|
||||
key += 5;
|
||||
}
|
||||
else if (strncmp (key, "ctrl-", 5) == 0)
|
||||
{
|
||||
strcat (result, "^");
|
||||
strcat (result, "\x01");
|
||||
key += 5;
|
||||
}
|
||||
else
|
||||
@@ -242,7 +273,7 @@ gui_key_get_internal_code (const char *key)
|
||||
|
||||
/*
|
||||
* gui_key_get_expanded_name: get expanded name from internal key code
|
||||
* for example: return "ctrl-R" for "^R"
|
||||
* for example: return "ctrl-R" for "\x01+R"
|
||||
*/
|
||||
|
||||
char *
|
||||
@@ -259,17 +290,17 @@ gui_key_get_expanded_name (const char *key)
|
||||
result[0] = '\0';
|
||||
while (key[0])
|
||||
{
|
||||
if (strncmp (key, "^[[", 3) == 0)
|
||||
if (strncmp (key, "\x01[[", 3) == 0)
|
||||
{
|
||||
strcat (result, "meta2-");
|
||||
key += 3;
|
||||
}
|
||||
if (strncmp (key, "^[", 2) == 0)
|
||||
if (strncmp (key, "\x01[", 2) == 0)
|
||||
{
|
||||
strcat (result, "meta-");
|
||||
key += 2;
|
||||
}
|
||||
else if ((key[0] == '^') && (key[1]))
|
||||
else if ((key[0] == '\x01') && (key[1]))
|
||||
{
|
||||
strcat (result, "ctrl-");
|
||||
key++;
|
||||
@@ -403,8 +434,10 @@ gui_key_new (struct t_gui_buffer *buffer, int context, const char *key,
|
||||
|
||||
if (gui_key_verbose)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("New key binding: %s%s => %s%s"),
|
||||
gui_chat_printf (gui_current_window->buffer,
|
||||
_("New key binding (context \"%s\"): "
|
||||
"%s%s => %s%s"),
|
||||
gui_key_context_string[context],
|
||||
(expanded_name) ? expanded_name : new_key->key,
|
||||
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
|
||||
GUI_COLOR(GUI_COLOR_CHAT),
|
||||
@@ -443,10 +476,13 @@ gui_key_search (struct t_gui_key *keys, const char *key)
|
||||
*/
|
||||
|
||||
int
|
||||
gui_key_cmp (const char *key, const char *search)
|
||||
gui_key_cmp (const char *key, const char *search, int context)
|
||||
{
|
||||
int diff;
|
||||
|
||||
if (context == GUI_KEY_CONTEXT_MOUSE)
|
||||
return strcmp (key, search);
|
||||
|
||||
while (search[0])
|
||||
{
|
||||
diff = utf8_charcmp (key, search);
|
||||
@@ -472,8 +508,14 @@ gui_key_search_part (struct t_gui_buffer *buffer, int context,
|
||||
for (ptr_key = (buffer) ? buffer->keys : gui_keys[context]; ptr_key;
|
||||
ptr_key = ptr_key->next_key)
|
||||
{
|
||||
if (ptr_key->key && (gui_key_cmp (ptr_key->key, key) == 0))
|
||||
return ptr_key;
|
||||
if (ptr_key->key
|
||||
&& (((context != GUI_KEY_CONTEXT_CURSOR)
|
||||
&& (context != GUI_KEY_CONTEXT_MOUSE))
|
||||
|| (ptr_key->key[0] != '@')))
|
||||
{
|
||||
if (gui_key_cmp (ptr_key->key, key, context) == 0)
|
||||
return ptr_key;
|
||||
}
|
||||
}
|
||||
|
||||
/* key not found */
|
||||
@@ -551,6 +593,173 @@ gui_key_unbind (struct t_gui_buffer *buffer, int context, const char *key,
|
||||
return (ptr_key != NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_key_focus_matching: return 1 if area in key is matching focus area on
|
||||
* screen (cursor/mouse)
|
||||
*/
|
||||
|
||||
int
|
||||
gui_key_focus_matching (const char *key,
|
||||
struct t_gui_cursor_info *cursor_info)
|
||||
{
|
||||
int match, area_chat;
|
||||
char *area_bar, *area_item, *pos;
|
||||
|
||||
if (key[1] == '*')
|
||||
return 1;
|
||||
|
||||
match = 0;
|
||||
|
||||
pos = strchr (key, ':');
|
||||
if (pos)
|
||||
{
|
||||
area_chat = 0;
|
||||
area_bar = NULL;
|
||||
area_item = NULL;
|
||||
if (strncmp (key + 1, "chat:", 5) == 0)
|
||||
area_chat = 1;
|
||||
else if (strncmp (key + 1, "bar(", 4) == 0)
|
||||
{
|
||||
area_bar = string_strndup (key + 5, pos - key - 6);
|
||||
}
|
||||
else if (strncmp (key + 1, "item(", 5) == 0)
|
||||
{
|
||||
area_item = string_strndup (key + 6, pos - key - 7);
|
||||
}
|
||||
if (area_chat || area_bar || area_item)
|
||||
{
|
||||
if (area_chat && cursor_info->chat)
|
||||
{
|
||||
match = 1;
|
||||
}
|
||||
else if (area_bar && cursor_info->bar_window
|
||||
&& ((strcmp (area_bar, "*") == 0)
|
||||
|| (strcmp (area_bar, (cursor_info->bar_window)->bar->name) == 0)))
|
||||
{
|
||||
match = 1;
|
||||
}
|
||||
else if (area_item && cursor_info->bar_item
|
||||
&& ((strcmp (area_item, "*") == 0)
|
||||
|| (strcmp (area_item, cursor_info->bar_item) == 0)))
|
||||
{
|
||||
match = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (area_bar)
|
||||
free (area_bar);
|
||||
if (area_item)
|
||||
free (area_item);
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_key_focus_command: run command according to focus
|
||||
* return 1 if a command was executed, otherwise 0
|
||||
*/
|
||||
|
||||
int
|
||||
gui_key_focus_command (const char *key, int context,
|
||||
int focus_specific, int focus_any,
|
||||
struct t_gui_cursor_info *cursor_info)
|
||||
{
|
||||
struct t_gui_key *ptr_key;
|
||||
int i, errors;
|
||||
char *pos, *pos_joker, *command, **commands;
|
||||
struct t_hashtable *hashtable;
|
||||
|
||||
for (ptr_key = gui_keys[context]; ptr_key;
|
||||
ptr_key = ptr_key->next_key)
|
||||
{
|
||||
if (ptr_key->key && (ptr_key->key[0] == '@'))
|
||||
{
|
||||
pos = strchr (ptr_key->key, ':');
|
||||
if (pos)
|
||||
{
|
||||
pos_joker = strchr (ptr_key->key, '*');
|
||||
if (!focus_specific && (!pos_joker || (pos_joker > pos)))
|
||||
continue;
|
||||
if (!focus_any && pos_joker && (pos_joker < pos))
|
||||
continue;
|
||||
|
||||
pos++;
|
||||
if (gui_key_cmp (pos, key, context) == 0)
|
||||
{
|
||||
if (gui_key_focus_matching (ptr_key->key, cursor_info))
|
||||
{
|
||||
hashtable = hook_focus_get_data (cursor_info);
|
||||
if (gui_mouse_debug)
|
||||
{
|
||||
gui_chat_printf (NULL, "Hashtable focus: %s",
|
||||
hashtable_get_string (hashtable,
|
||||
"keys_values"));
|
||||
}
|
||||
command = string_replace_with_hashtable (ptr_key->command,
|
||||
hashtable,
|
||||
&errors);
|
||||
if (command)
|
||||
{
|
||||
if (errors == 0)
|
||||
{
|
||||
if ((context == GUI_KEY_CONTEXT_CURSOR)
|
||||
&& gui_cursor_debug)
|
||||
{
|
||||
gui_input_delete_line (gui_current_window->buffer);
|
||||
}
|
||||
commands = string_split_command (command,
|
||||
';');
|
||||
if (commands)
|
||||
{
|
||||
for (i = 0; commands[i]; i++)
|
||||
{
|
||||
input_data (gui_current_window->buffer, commands[i]);
|
||||
}
|
||||
string_free_split_command (commands);
|
||||
}
|
||||
}
|
||||
free (command);
|
||||
}
|
||||
if (hashtable)
|
||||
hashtable_free (hashtable);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_key_focus: treat key pressed in cursor or mouse mode,
|
||||
* looking for keys: "{area}key" in context "cursor" or "mouse"
|
||||
* return 1 if a command was executed, otherwise 0
|
||||
*/
|
||||
|
||||
int
|
||||
gui_key_focus (const char *key, int context)
|
||||
{
|
||||
struct t_gui_cursor_info cursor_info;
|
||||
|
||||
if (context == GUI_KEY_CONTEXT_MOUSE)
|
||||
{
|
||||
gui_cursor_get_info (gui_mouse_event_x[0], gui_mouse_event_y[0],
|
||||
&cursor_info);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_cursor_get_info (gui_cursor_x, gui_cursor_y, &cursor_info);
|
||||
}
|
||||
|
||||
if (gui_key_focus_command (key, context, 1, 0, &cursor_info))
|
||||
return 1;
|
||||
|
||||
return gui_key_focus_command (key, context, 0, 1, &cursor_info);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_key_pressed: treat new key pressed
|
||||
* return: 1 if key should be added to input buffer
|
||||
@@ -560,22 +769,52 @@ gui_key_unbind (struct t_gui_buffer *buffer, int context, const char *key,
|
||||
int
|
||||
gui_key_pressed (const char *key_str)
|
||||
{
|
||||
int first_key, context;
|
||||
int i, first_key, context, length, length_key;
|
||||
struct t_gui_key *ptr_key;
|
||||
char *buffer_before_key;
|
||||
char **commands, **ptr_cmd;
|
||||
char **commands;
|
||||
const char *mouse_key;
|
||||
|
||||
/* add key to buffer */
|
||||
first_key = (gui_key_combo_buffer[0] == '\0');
|
||||
strcat (gui_key_combo_buffer, key_str);
|
||||
length = strlen (gui_key_combo_buffer);
|
||||
length_key = strlen (key_str);
|
||||
if (length + length_key + 1 <= (int)sizeof (gui_key_combo_buffer))
|
||||
strcat (gui_key_combo_buffer, key_str);
|
||||
|
||||
/* if we are in "show mode", increase counter and return */
|
||||
if (gui_key_grab)
|
||||
{
|
||||
if (gui_key_grab_count == 0)
|
||||
{
|
||||
hook_timer (NULL, gui_key_grab_delay, 0, 1,
|
||||
&gui_key_grab_end_timer_cb, NULL);
|
||||
}
|
||||
gui_key_grab_count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* mode "mouse grab" (mouse event pending) */
|
||||
if (gui_mouse_grab)
|
||||
{
|
||||
mouse_key = gui_mouse_grab_code2key (gui_key_combo_buffer);
|
||||
if (mouse_key)
|
||||
{
|
||||
gui_key_combo_buffer[0] = '\0';
|
||||
strcat (gui_key_combo_buffer, mouse_key);
|
||||
gui_mouse_grab_end ();
|
||||
if (gui_key_combo_buffer[0])
|
||||
{
|
||||
(void) gui_key_focus (gui_key_combo_buffer,
|
||||
GUI_KEY_CONTEXT_MOUSE);
|
||||
gui_key_combo_buffer[0] = '\0';
|
||||
gui_mouse_reset_event ();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ptr_key = NULL;
|
||||
|
||||
context = gui_key_get_current_context ();
|
||||
switch (context)
|
||||
{
|
||||
@@ -601,6 +840,11 @@ gui_key_pressed (const char *key_str)
|
||||
gui_key_combo_buffer);
|
||||
}
|
||||
break;
|
||||
case GUI_KEY_CONTEXT_CURSOR:
|
||||
ptr_key = gui_key_search_part (NULL,
|
||||
GUI_KEY_CONTEXT_CURSOR,
|
||||
gui_key_combo_buffer);
|
||||
break;
|
||||
}
|
||||
|
||||
/* if key is found, then execute action */
|
||||
@@ -609,29 +853,30 @@ gui_key_pressed (const char *key_str)
|
||||
if (strcmp (ptr_key->key, gui_key_combo_buffer) == 0)
|
||||
{
|
||||
/* exact combo found => execute function or command */
|
||||
buffer_before_key =
|
||||
(gui_current_window->buffer->input_buffer) ?
|
||||
strdup (gui_current_window->buffer->input_buffer) : strdup ("");
|
||||
gui_key_combo_buffer[0] = '\0';
|
||||
if (ptr_key->command)
|
||||
{
|
||||
commands = string_split_command (ptr_key->command, ';');
|
||||
if (commands)
|
||||
{
|
||||
for (ptr_cmd = commands; *ptr_cmd; ptr_cmd++)
|
||||
for (i = 0; commands[i]; i++)
|
||||
{
|
||||
input_data (gui_current_window->buffer,
|
||||
*ptr_cmd);
|
||||
input_data (gui_current_window->buffer, commands[i]);
|
||||
}
|
||||
string_free_split_command (commands);
|
||||
}
|
||||
}
|
||||
|
||||
if (buffer_before_key)
|
||||
free (buffer_before_key);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else if (context == GUI_KEY_CONTEXT_CURSOR)
|
||||
{
|
||||
if (gui_key_focus (gui_key_combo_buffer, GUI_KEY_CONTEXT_CURSOR))
|
||||
{
|
||||
gui_key_combo_buffer[0] = '\0';
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
gui_key_combo_buffer[0] = '\0';
|
||||
|
||||
@@ -829,6 +1074,8 @@ struct t_hdata *
|
||||
gui_key_hdata_key_cb (void *data, const char *hdata_name)
|
||||
{
|
||||
struct t_hdata *hdata;
|
||||
int i;
|
||||
char str_list[128];
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -840,10 +1087,29 @@ gui_key_hdata_key_cb (void *data, const char *hdata_name)
|
||||
HDATA_VAR(struct t_gui_key, command, STRING, NULL);
|
||||
HDATA_VAR(struct t_gui_key, prev_key, POINTER, hdata_name);
|
||||
HDATA_VAR(struct t_gui_key, next_key, POINTER, hdata_name);
|
||||
HDATA_LIST(gui_keys);
|
||||
HDATA_LIST(last_gui_key);
|
||||
HDATA_LIST(gui_default_keys);
|
||||
HDATA_LIST(last_gui_default_key);
|
||||
for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
|
||||
{
|
||||
snprintf (str_list, sizeof (str_list),
|
||||
"gui_keys%s%s",
|
||||
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : "_",
|
||||
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : gui_key_context_string[i]);
|
||||
hdata_new_list(hdata, str_list, &gui_keys[i]);
|
||||
snprintf (str_list, sizeof (str_list),
|
||||
"last_gui_key%s%s",
|
||||
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : "_",
|
||||
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : gui_key_context_string[i]);
|
||||
hdata_new_list(hdata, str_list, &last_gui_key[i]);
|
||||
snprintf (str_list, sizeof (str_list),
|
||||
"gui_default_keys%s%s",
|
||||
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : "_",
|
||||
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : gui_key_context_string[i]);
|
||||
hdata_new_list(hdata, str_list, &gui_default_keys[i]);
|
||||
snprintf (str_list, sizeof (str_list),
|
||||
"last_gui_default_key%s%s",
|
||||
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : "_",
|
||||
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : gui_key_context_string[i]);
|
||||
hdata_new_list(hdata, str_list, &last_gui_default_key[i]);
|
||||
}
|
||||
}
|
||||
return hdata;
|
||||
}
|
||||
|
||||
+5
-2
@@ -22,10 +22,14 @@
|
||||
|
||||
#define GUI_KEY_BUFFER_BLOCK_SIZE 256
|
||||
|
||||
#define GUI_KEY_GRAB_DELAY_DEFAULT 500
|
||||
|
||||
enum t_gui_key_context
|
||||
{
|
||||
GUI_KEY_CONTEXT_DEFAULT = 0,
|
||||
GUI_KEY_CONTEXT_SEARCH,
|
||||
GUI_KEY_CONTEXT_CURSOR,
|
||||
GUI_KEY_CONTEXT_MOUSE,
|
||||
/* number of key contexts */
|
||||
GUI_KEY_NUM_CONTEXTS,
|
||||
};
|
||||
@@ -62,8 +66,7 @@ extern time_t gui_key_last_activity_time;
|
||||
|
||||
extern void gui_key_init ();
|
||||
extern int gui_key_search_context (const char *context);
|
||||
extern void gui_key_grab_init (int grab_command);
|
||||
extern void gui_key_grab_end ();
|
||||
extern void gui_key_grab_init (int grab_command, const char *delay);
|
||||
extern char *gui_key_get_internal_code (const char *key);
|
||||
extern char *gui_key_get_expanded_name (const char *key);
|
||||
extern struct t_gui_key *gui_key_new (struct t_gui_buffer *buffer,
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Sebastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat 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 WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* gui-mouse.c: functions for mouse (used by all GUI)
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../core/weechat.h"
|
||||
#include "gui-chat.h"
|
||||
|
||||
|
||||
int gui_mouse_enabled = 0; /* 1 if mouse support is enabled */
|
||||
int gui_mouse_debug = 0; /* debug mode for mouse */
|
||||
int gui_mouse_grab = 0; /* 1 if grab mouse code enabled */
|
||||
int gui_mouse_event_index = 0; /* index for x/y in array (0 or 1) */
|
||||
int gui_mouse_event_x[2] = { 0, 0 }; /* position of latest mouse event: */
|
||||
/* (on click, on release) */
|
||||
int gui_mouse_event_y[2] = { 0, 0 }; /* position of latest mouse event */
|
||||
/* (on click, on release) */
|
||||
char gui_mouse_event_button = '#'; /* button pressed (or wheel) */
|
||||
|
||||
|
||||
/*
|
||||
* gui_mouse_debug_toggle: toggle debug for mouse events
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_debug_toggle ()
|
||||
{
|
||||
gui_mouse_debug ^= 1;
|
||||
|
||||
if (gui_mouse_debug)
|
||||
gui_chat_printf (NULL, _("Debug enabled for mouse"));
|
||||
else
|
||||
gui_chat_printf (NULL, _("Debug disabled for mouse"));
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_reset_event: reset event values
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_reset_event ()
|
||||
{
|
||||
gui_mouse_event_index = 0;
|
||||
gui_mouse_event_x[0] = 0;
|
||||
gui_mouse_event_y[0] = 0;
|
||||
gui_mouse_event_x[1] = 0;
|
||||
gui_mouse_event_y[1] = 0;
|
||||
gui_mouse_event_button = '#';
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Sebastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat 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 WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __WEECHAT_GUI_MOUSE_H
|
||||
#define __WEECHAT_GUI_MOUSE_H 1
|
||||
|
||||
/* mouse variables */
|
||||
|
||||
extern int gui_mouse_enabled;
|
||||
extern int gui_mouse_debug;
|
||||
extern int gui_mouse_grab;
|
||||
extern int gui_mouse_event_index;
|
||||
extern int gui_mouse_event_x[2];
|
||||
extern int gui_mouse_event_y[2];
|
||||
extern char gui_mouse_event_button;
|
||||
|
||||
/* mouse functions */
|
||||
|
||||
extern void gui_mouse_debug_toggle ();
|
||||
extern void gui_mouse_reset_event ();
|
||||
|
||||
/* mouse functions (GUI dependent) */
|
||||
|
||||
extern void gui_mouse_enable ();
|
||||
extern void gui_mouse_disable ();
|
||||
extern void gui_mouse_display_state ();
|
||||
extern void gui_mouse_grab_init ();
|
||||
extern const char *gui_mouse_grab_code2key (const char *code);
|
||||
extern void gui_mouse_grab_end ();
|
||||
|
||||
#endif /* __WEECHAT_GUI_MOUSE_H */
|
||||
+29
-2
@@ -70,8 +70,35 @@ struct t_gui_layout_window *gui_window_layout_before_zoom = NULL;
|
||||
/* layout before zooming on a window */
|
||||
int gui_window_layout_id_current_window = -1;
|
||||
/* current window id before zoom */
|
||||
int gui_window_cursor_x = 0; /* cursor pos on screen */
|
||||
int gui_window_cursor_y = 0; /* cursor pos on screen */
|
||||
|
||||
|
||||
/*
|
||||
* gui_window_search_by_xy: get pointer of window displayed at (x,y)
|
||||
* return NULL if no window is found
|
||||
*/
|
||||
|
||||
struct t_gui_window *
|
||||
gui_window_search_by_xy (int x, int y)
|
||||
{
|
||||
struct t_gui_window *ptr_window;
|
||||
|
||||
for (ptr_window = gui_windows; ptr_window;
|
||||
ptr_window = ptr_window->next_window)
|
||||
{
|
||||
if ((x >= ptr_window->win_x) && (y >= ptr_window->win_y)
|
||||
&& (x <= ptr_window->win_x + ptr_window->win_width - 1)
|
||||
&& (y <= ptr_window->win_y + ptr_window->win_height - 1))
|
||||
{
|
||||
return ptr_window;
|
||||
}
|
||||
}
|
||||
|
||||
/* no window at this location */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_ask_refresh: set "gui_window_refresh_needed" flag
|
||||
*/
|
||||
@@ -1293,8 +1320,8 @@ gui_window_hdata_window_cb (void *data, const char *hdata_name)
|
||||
HDATA_VAR(struct t_gui_window, win_chat_height, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_window, win_chat_cursor_x, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_window, win_chat_cursor_y, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_window, bar_windows, POINTER, NULL);
|
||||
HDATA_VAR(struct t_gui_window, last_bar_window, POINTER, NULL);
|
||||
HDATA_VAR(struct t_gui_window, bar_windows, POINTER, "bar_window");
|
||||
HDATA_VAR(struct t_gui_window, last_bar_window, POINTER, "bar_window");
|
||||
HDATA_VAR(struct t_gui_window, refresh_needed, INTEGER, NULL);
|
||||
HDATA_VAR(struct t_gui_window, gui_objects, POINTER, NULL);
|
||||
HDATA_VAR(struct t_gui_window, buffer, POINTER, "buffer");
|
||||
|
||||
@@ -27,10 +27,12 @@
|
||||
#define GUI_WINDOW_CHAT_MIN_HEIGHT 2
|
||||
|
||||
struct t_infolist;
|
||||
struct t_gui_bar_window;
|
||||
|
||||
extern int gui_init_ok;
|
||||
extern int gui_ok;
|
||||
extern int gui_window_refresh_needed;
|
||||
extern int gui_window_cursor_x, gui_window_cursor_y;
|
||||
|
||||
/* window structures */
|
||||
|
||||
@@ -116,6 +118,8 @@ extern struct t_gui_window *gui_current_window;
|
||||
extern struct t_gui_window_tree *gui_windows_tree;
|
||||
|
||||
/* window functions */
|
||||
|
||||
extern struct t_gui_window *gui_window_search_by_xy (int x, int y);
|
||||
extern void gui_window_ask_refresh (int refresh);
|
||||
extern int gui_window_tree_init (struct t_gui_window *window);
|
||||
extern void gui_window_tree_node_to_leaf (struct t_gui_window_tree *node,
|
||||
@@ -200,6 +204,7 @@ extern int gui_window_balance (struct t_gui_window_tree *tree);
|
||||
extern void gui_window_swap (struct t_gui_window *window, int direction);
|
||||
extern void gui_window_refresh_screen (int full_refresh);
|
||||
extern void gui_window_set_title (const char *title);
|
||||
extern void gui_window_move_cursor ();
|
||||
extern void gui_window_term_display_infos ();
|
||||
extern void gui_window_objects_print_log (struct t_gui_window *window);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user