mirror of
https://github.com/weechat/weechat.git
synced 2026-07-10 03:33:12 +02:00
core: add "/input grab_mouse" and "/input grab_mouse_area" (default: right click on input bar)
This commit is contained in:
+13
-4
@@ -2287,9 +2287,13 @@ COMMAND_CALLBACK(input)
|
||||
else if (string_strcasecmp (argv[1], "hotlist_clear") == 0)
|
||||
gui_input_hotlist_clear (buffer);
|
||||
else if (string_strcasecmp (argv[1], "grab_key") == 0)
|
||||
gui_input_grab_key (buffer, (argc > 2) ? argv[2] : NULL);
|
||||
gui_input_grab_key (buffer, 0, (argc > 2) ? argv[2] : NULL);
|
||||
else if (string_strcasecmp (argv[1], "grab_key_command") == 0)
|
||||
gui_input_grab_key_command (buffer, (argc > 2) ? argv[2] : NULL);
|
||||
gui_input_grab_key (buffer, 1, (argc > 2) ? argv[2] : NULL);
|
||||
else if (string_strcasecmp (argv[1], "grab_mouse") == 0)
|
||||
gui_input_grab_mouse (buffer, 0);
|
||||
else if (string_strcasecmp (argv[1], "grab_mouse_area") == 0)
|
||||
gui_input_grab_mouse (buffer, 1);
|
||||
else if (string_strcasecmp (argv[1], "scroll_unread") == 0)
|
||||
gui_input_scroll_unread (buffer);
|
||||
else if (string_strcasecmp (argv[1], "set_unread") == 0)
|
||||
@@ -3093,6 +3097,7 @@ COMMAND_CALLBACK(mouse)
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* enable mouse */
|
||||
if (string_strcasecmp (argv[1], "enable") == 0)
|
||||
{
|
||||
gui_mouse_enable ();
|
||||
@@ -3101,6 +3106,7 @@ COMMAND_CALLBACK(mouse)
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* disable mouse */
|
||||
if (string_strcasecmp (argv[1], "disable") == 0)
|
||||
{
|
||||
gui_mouse_disable ();
|
||||
@@ -3109,6 +3115,7 @@ COMMAND_CALLBACK(mouse)
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* toggle mouse */
|
||||
if (string_strcasecmp (argv[1], "toggle") == 0)
|
||||
{
|
||||
if (gui_mouse_enabled)
|
||||
@@ -5460,6 +5467,8 @@ command_init ()
|
||||
" grab_key_command: grab a key with its associated "
|
||||
"command (optional argument: delay for end of grab, "
|
||||
"default is 500 milliseconds)\n"
|
||||
" grab_mouse: grab mouse event code\n"
|
||||
" grab_mouse_area: grab mouse event code with area\n"
|
||||
" scroll_unread: scroll to unread marker\n"
|
||||
" set_unread: set unread marker for all buffers\n"
|
||||
" set_unread_current_buffer: set unread marker for "
|
||||
@@ -5481,8 +5490,8 @@ command_init ()
|
||||
"history_global_previous|history_global_next|"
|
||||
"jump_smart|jump_last_buffer|jump_previously_visited_buffer|"
|
||||
"jump_next_visited_buffer|hotlist_clear|grab_key|"
|
||||
"grab_key_command|scroll_unread|set_unread|"
|
||||
"set_unread_current_buffer|switch_active_buffer|"
|
||||
"grab_key_command|grab_mouse|grab_mouse_area|scroll_unread|"
|
||||
"set_unread|set_unread_current_buffer|switch_active_buffer|"
|
||||
"switch_active_buffer_previous|insert",
|
||||
&command_input, NULL);
|
||||
hook_command (NULL, "key",
|
||||
|
||||
@@ -263,6 +263,8 @@ gui_key_default_bindings (int context)
|
||||
BIND("@item(buffer_nicklist):button1-gesture-left", "/window ${_window_number};/kick ${nick}");
|
||||
BIND("@item(buffer_nicklist):button1-gesture-left-long", "/window ${_window_number};/kickban ${nick}");
|
||||
BIND("@item(buffer_nicklist):button2-gesture-left", "/window ${_window_number};/ban ${nick}");
|
||||
/* mouse events on input */
|
||||
BIND("@bar(input):button2", "/input grab_mouse_area");
|
||||
/* mouse wheel on any bar */
|
||||
BIND("@bar(*):wheelup", "/bar scroll ${_bar_name} ${_window_number} -10%");
|
||||
BIND("@bar(*):wheeldown", "/bar scroll ${_bar_name} ${_window_number} +10%");
|
||||
@@ -296,7 +298,7 @@ gui_key_flush ()
|
||||
|
||||
insert_ok = 1;
|
||||
|
||||
if (gui_mouse_grab)
|
||||
if (gui_mouse_event_pending)
|
||||
{
|
||||
insert_ok = 0;
|
||||
key_str[0] = (char) key;
|
||||
|
||||
@@ -34,9 +34,16 @@
|
||||
#include "../../core/wee-hook.h"
|
||||
#include "../../core/wee-utf8.h"
|
||||
#include "../../plugins/plugin.h"
|
||||
#include "../gui-bar.h"
|
||||
#include "../gui-bar-window.h"
|
||||
#include "../gui-buffer.h"
|
||||
#include "../gui-chat.h"
|
||||
#include "../gui-completion.h"
|
||||
#include "../gui-cursor.h"
|
||||
#include "../gui-input.h"
|
||||
#include "../gui-key.h"
|
||||
#include "../gui-mouse.h"
|
||||
#include "../gui-window.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -74,29 +81,116 @@ gui_mouse_display_state ()
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_grab_timer_cb: timer for grabbing mouse code
|
||||
* gui_mouse_grab_init: init "grab mode"
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_grab_init (int area)
|
||||
{
|
||||
gui_mouse_grab = (area) ? 2 : 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_grab_event2input: get area for input, according to (x,y) of mouse
|
||||
* event
|
||||
* for example: @item(buffer_nicklist)
|
||||
* @bar(title)
|
||||
* @chat
|
||||
* @*
|
||||
*/
|
||||
|
||||
char *
|
||||
gui_mouse_grab_event2input ()
|
||||
{
|
||||
struct t_gui_cursor_info cursor_info;
|
||||
static char area[256];
|
||||
|
||||
gui_cursor_get_info (gui_mouse_event_x[0],
|
||||
gui_mouse_event_y[0],
|
||||
&cursor_info);
|
||||
|
||||
if (cursor_info.bar_item)
|
||||
{
|
||||
snprintf (area, sizeof (area),
|
||||
"@item(%s)", cursor_info.bar_item);
|
||||
}
|
||||
else if (cursor_info.bar_window)
|
||||
{
|
||||
snprintf (area, sizeof (area),
|
||||
"@bar(%s)", ((cursor_info.bar_window)->bar)->name);
|
||||
}
|
||||
else if (cursor_info.chat)
|
||||
{
|
||||
snprintf (area, sizeof (area), "@chat");
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf (area, sizeof (area), "@*");
|
||||
}
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_grab_end: end "grab mode"
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_grab_end (const char *mouse_key)
|
||||
{
|
||||
char mouse_key_input[256];
|
||||
|
||||
/* insert mouse key in input */
|
||||
if (gui_current_window->buffer->input)
|
||||
{
|
||||
if (gui_mouse_grab == 2)
|
||||
{
|
||||
/* mouse key with area */
|
||||
snprintf (mouse_key_input, sizeof (mouse_key_input),
|
||||
"%s:%s",
|
||||
gui_mouse_grab_event2input (),
|
||||
mouse_key);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* mouse key without area */
|
||||
snprintf (mouse_key_input, sizeof (mouse_key_input),
|
||||
"%s", mouse_key);
|
||||
}
|
||||
gui_input_insert_string (gui_current_window->buffer,
|
||||
mouse_key_input, -1);
|
||||
if (gui_current_window->buffer->completion)
|
||||
gui_completion_stop (gui_current_window->buffer->completion, 1);
|
||||
gui_input_text_changed_modifier_and_signal (gui_current_window->buffer, 1);
|
||||
}
|
||||
|
||||
gui_mouse_grab = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_event_timer_cb: timer for grabbing mouse code
|
||||
*/
|
||||
|
||||
int
|
||||
gui_mouse_grab_timer_cb (void *data, int remaining_calls)
|
||||
gui_mouse_event_timer_cb (void *data, int remaining_calls)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) remaining_calls;
|
||||
|
||||
gui_mouse_grab_end ();
|
||||
gui_mouse_event_end ();
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_grab_init: init "grab mouse" mode
|
||||
* gui_mouse_event_init: init mouse event
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_grab_init ()
|
||||
gui_mouse_event_init ()
|
||||
{
|
||||
gui_mouse_grab = 1;
|
||||
gui_mouse_event_pending = 1;
|
||||
|
||||
if (gui_mouse_event_timer)
|
||||
unhook (gui_mouse_event_timer);
|
||||
@@ -104,18 +198,18 @@ gui_mouse_grab_init ()
|
||||
gui_mouse_event_timer = hook_timer (NULL,
|
||||
CONFIG_INTEGER(config_look_mouse_timer_delay),
|
||||
0, 1,
|
||||
&gui_mouse_grab_timer_cb, NULL);
|
||||
&gui_mouse_event_timer_cb, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_grab_code2key: get key name with a mouse code
|
||||
* *extra_chars is set with first char following the
|
||||
* end of mouse code (this can point to the '\0' or
|
||||
* other chars)
|
||||
* gui_mouse_event_code2key: get key name with a mouse code
|
||||
* *extra_chars is set with first char following the
|
||||
* end of mouse code (this can point to the '\0' or
|
||||
* other chars)
|
||||
*/
|
||||
|
||||
const char *
|
||||
gui_mouse_grab_code2key (const char *code, char **extra_chars)
|
||||
gui_mouse_event_code2key (const char *code, char **extra_chars)
|
||||
{
|
||||
int x, y, code_utf8, length;
|
||||
double diff_x, diff_y, distance, angle, pi4;
|
||||
@@ -288,17 +382,17 @@ gui_mouse_grab_code2key (const char *code, char **extra_chars)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_grab_end: end "grab mouse" mode
|
||||
* gui_mouse_event_end: end mouse event
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_grab_end ()
|
||||
gui_mouse_event_end ()
|
||||
{
|
||||
const char *mouse_key;
|
||||
char *extra_chars;
|
||||
int i;
|
||||
|
||||
gui_mouse_grab = 0;
|
||||
gui_mouse_event_pending = 0;
|
||||
|
||||
/* end mouse event timer */
|
||||
if (gui_mouse_event_timer)
|
||||
@@ -307,13 +401,21 @@ gui_mouse_grab_end ()
|
||||
gui_mouse_event_timer = NULL;
|
||||
}
|
||||
|
||||
/* get key from mouse code and execute command (if found) */
|
||||
mouse_key = gui_mouse_grab_code2key (gui_key_combo_buffer, &extra_chars);
|
||||
/* get key from mouse code */
|
||||
mouse_key = gui_mouse_event_code2key (gui_key_combo_buffer, &extra_chars);
|
||||
if (mouse_key && mouse_key[0])
|
||||
{
|
||||
(void) gui_key_focus (mouse_key,
|
||||
GUI_KEY_CONTEXT_MOUSE);
|
||||
gui_mouse_reset_event ();
|
||||
if (gui_mouse_grab)
|
||||
{
|
||||
gui_mouse_grab_end (mouse_key);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* execute command (if found) */
|
||||
(void) gui_key_focus (mouse_key,
|
||||
GUI_KEY_CONTEXT_MOUSE);
|
||||
}
|
||||
gui_mouse_event_reset ();
|
||||
}
|
||||
|
||||
gui_key_combo_buffer[0] = '\0';
|
||||
|
||||
@@ -60,21 +60,33 @@ gui_mouse_display_state ()
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_grab_init: init "grab mouse" mode
|
||||
* gui_mouse_grab_init: init "grab mode"
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_grab_init ()
|
||||
gui_mouse_grab_init (int area)
|
||||
{
|
||||
(void) area;
|
||||
|
||||
/* This function does nothing in Gtk GUI */
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_event_init: init mouse event
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_event_init ()
|
||||
{
|
||||
/* This function does nothing in Gtk GUI */
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_grab_code2key: get key name with a mouse code
|
||||
* gui_mouse_event_code2key: get key name with a mouse code
|
||||
*/
|
||||
|
||||
const char *
|
||||
gui_mouse_grab_code2key (const char *code)
|
||||
gui_mouse_event_code2key (const char *code)
|
||||
{
|
||||
(void) code;
|
||||
|
||||
@@ -84,11 +96,11 @@ gui_mouse_grab_code2key (const char *code)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_grab_end: end "grab mouse" mode
|
||||
* gui_mouse_event_end: end mouse event
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_grab_end ()
|
||||
gui_mouse_event_end ()
|
||||
{
|
||||
/* This function does nothing in Gtk GUI */
|
||||
}
|
||||
|
||||
+8
-6
@@ -43,6 +43,7 @@
|
||||
#include "gui-hotlist.h"
|
||||
#include "gui-key.h"
|
||||
#include "gui-line.h"
|
||||
#include "gui-mouse.h"
|
||||
#include "gui-window.h"
|
||||
|
||||
|
||||
@@ -1343,22 +1344,23 @@ gui_input_hotlist_clear (struct t_gui_buffer *buffer)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_grab_key (struct t_gui_buffer *buffer, const char *delay)
|
||||
gui_input_grab_key (struct t_gui_buffer *buffer, int command, const char *delay)
|
||||
{
|
||||
if (buffer->input)
|
||||
gui_key_grab_init (0, delay);
|
||||
gui_key_grab_init (command, delay);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_grab_key_command: init "grab key mode" (next key and command
|
||||
* bound will be inserted into input buffer)
|
||||
* gui_input_grab_mouse: init "grab mouse mode" (next mouse event will be
|
||||
* inserted into input buffer) (default key: button2 of
|
||||
* mouse in input bar)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_grab_key_command (struct t_gui_buffer *buffer, const char *delay)
|
||||
gui_input_grab_mouse (struct t_gui_buffer *buffer, int area)
|
||||
{
|
||||
if (buffer->input)
|
||||
gui_key_grab_init (1, delay);
|
||||
gui_mouse_grab_init (area);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+2
-3
@@ -70,10 +70,9 @@ 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 (struct t_gui_buffer *buffer, int command,
|
||||
const char *delay);
|
||||
extern void gui_input_grab_key_command (struct t_gui_buffer *buffer,
|
||||
const char *delay);
|
||||
extern void gui_input_grab_mouse (struct t_gui_buffer *buffer, int area);
|
||||
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);
|
||||
|
||||
+5
-5
@@ -820,15 +820,15 @@ gui_key_pressed (const char *key_str)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* mode "mouse grab" (mouse event pending) */
|
||||
if (gui_mouse_grab)
|
||||
/* mouse event pending */
|
||||
if (gui_mouse_event_pending)
|
||||
{
|
||||
pos = strstr (gui_key_combo_buffer, "\x1B[M");
|
||||
if (pos)
|
||||
{
|
||||
pos[0] = '\0';
|
||||
gui_mouse_grab_end ();
|
||||
gui_mouse_grab_init ();
|
||||
gui_mouse_event_end ();
|
||||
gui_mouse_event_init ();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -836,7 +836,7 @@ gui_key_pressed (const char *key_str)
|
||||
if (strcmp (gui_key_combo_buffer, "\x01[[M") == 0)
|
||||
{
|
||||
gui_key_combo_buffer[0] = '\0';
|
||||
gui_mouse_grab_init ();
|
||||
gui_mouse_event_init ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+6
-3
@@ -34,7 +34,10 @@
|
||||
|
||||
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_grab = 0; /* 1 if grab mode enabled */
|
||||
|
||||
/* mouse event */
|
||||
int gui_mouse_event_pending = 0; /* 1 if mouse event has started */
|
||||
struct t_hook *gui_mouse_event_timer = NULL; /* timer to detect entire */
|
||||
/* mouse event */
|
||||
int gui_mouse_event_index = 0; /* index for x/y in array (0 or 1) */
|
||||
@@ -61,11 +64,11 @@ gui_mouse_debug_toggle ()
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_mouse_reset_event: reset event values
|
||||
* gui_mouse_event_reset: reset event values
|
||||
*/
|
||||
|
||||
void
|
||||
gui_mouse_reset_event ()
|
||||
gui_mouse_event_reset ()
|
||||
{
|
||||
gui_mouse_event_index = 0;
|
||||
gui_mouse_event_x[0] = 0;
|
||||
|
||||
+5
-3
@@ -25,6 +25,7 @@
|
||||
extern int gui_mouse_enabled;
|
||||
extern int gui_mouse_debug;
|
||||
extern int gui_mouse_grab;
|
||||
extern int gui_mouse_event_pending;
|
||||
extern struct t_hook *gui_mouse_event_timer;
|
||||
extern int gui_mouse_event_index;
|
||||
extern int gui_mouse_event_x[2];
|
||||
@@ -34,14 +35,15 @@ extern char gui_mouse_event_button;
|
||||
/* mouse functions */
|
||||
|
||||
extern void gui_mouse_debug_toggle ();
|
||||
extern void gui_mouse_reset_event ();
|
||||
extern void gui_mouse_event_reset ();
|
||||
|
||||
/* 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 void gui_mouse_grab_end ();
|
||||
extern void gui_mouse_grab_init (int area);
|
||||
extern void gui_mouse_event_init ();
|
||||
extern void gui_mouse_event_end ();
|
||||
|
||||
#endif /* __WEECHAT_GUI_MOUSE_H */
|
||||
|
||||
Reference in New Issue
Block a user