1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Added /mouse command for enabling/disabling mouse handling

Defaults to on.
This commit is contained in:
James Booth 2013-01-17 19:40:55 +00:00
parent 8aad45f9d3
commit b9ac008b80
4 changed files with 74 additions and 24 deletions

View File

@ -119,6 +119,7 @@ static gboolean _cmd_set_gone(gchar **args, struct cmd_help_t help);
static gboolean _cmd_set_autoping(gchar **args, struct cmd_help_t help);
static gboolean _cmd_set_titlebar(gchar **args, struct cmd_help_t help);
static gboolean _cmd_set_autoaway(gchar **args, struct cmd_help_t help);
static gboolean _cmd_set_mouse(gchar **args, struct cmd_help_t help);
static gboolean _cmd_vercheck(gchar **args, struct cmd_help_t help);
static gboolean _cmd_away(gchar **args, struct cmd_help_t help);
static gboolean _cmd_online(gchar **args, struct cmd_help_t help);
@ -438,6 +439,17 @@ static struct cmd_t setting_commands[] =
"Possible properties are 'version'.",
NULL } } },
{ "/mouse",
_cmd_set_mouse, parse_args, 1, 1,
{ "/mouse on|off", "Use profanity mouse handling.",
{ "/mouse on|off",
"-------------",
"If set to 'on', profanity will handle mouse actions, which enabled scrolling the main window with the mouse wheel.",
"To select text, use the shift key while selcting an area.",
"If set to 'off', profanity leaves mouse handling to the terminal implementation.",
"The default is 'on', if you have strange behaviour with mouse actions, set to 'off'.",
NULL } } },
{ "/chlog",
_cmd_set_chlog, parse_args, 1, 1,
{ "/chlog on|off", "Chat logging to file",
@ -911,6 +923,8 @@ _cmd_complete_parameters(char *input, int *size)
prefs_autocomplete_boolean_choice);
_parameter_autocomplete(input, size, "/chlog",
prefs_autocomplete_boolean_choice);
_parameter_autocomplete(input, size, "/mouse",
prefs_autocomplete_boolean_choice);
_parameter_autocomplete(input, size, "/history",
prefs_autocomplete_boolean_choice);
_parameter_autocomplete(input, size, "/vercheck",
@ -2089,6 +2103,13 @@ _cmd_set_chlog(gchar **args, struct cmd_help_t help)
"Chat logging", prefs_set_chlog);
}
static gboolean
_cmd_set_mouse(gchar **args, struct cmd_help_t help)
{
return _cmd_set_boolean_preference(args[0], help,
"Mouse handling", prefs_set_mouse);
}
static gboolean
_cmd_set_history(gchar **args, struct cmd_help_t help)
{

View File

@ -410,6 +410,23 @@ prefs_set_splash(gboolean value)
_save_prefs();
}
gboolean
prefs_get_mouse(void)
{
// default to true
if (!g_key_file_has_key(prefs, "ui", "mouse", NULL)) {
return TRUE;
} else {
return g_key_file_get_boolean(prefs, "ui", "mouse", NULL);
}
}
void
prefs_set_mouse(gboolean value)
{
g_key_file_set_boolean(prefs, "ui", "mouse", value);
_save_prefs();
}
static void
_save_prefs(void)
{

View File

@ -68,6 +68,8 @@ gint prefs_get_gone(void);
void prefs_set_gone(gint value);
gchar * prefs_get_theme(void);
void prefs_set_theme(gchar *value);
gboolean prefs_get_mouse(void);
void prefs_set_mouse(gboolean value);
void prefs_set_notify_message(gboolean value);
gboolean prefs_get_notify_message(void);

View File

@ -125,8 +125,10 @@ ui_init(void)
initscr();
raw();
keypad(stdscr, TRUE);
mousemask(ALL_MOUSE_EVENTS, NULL);
mouseinterval(5);
if (prefs_get_mouse()) {
mousemask(ALL_MOUSE_EVENTS, NULL);
mouseinterval(5);
}
ui_load_colours();
refresh();
create_title_bar();
@ -1251,6 +1253,11 @@ cons_show_ui_prefs(void)
cons_show("Version checking (/vercheck) : ON");
else
cons_show("Version checking (/vercheck) : OFF");
if (prefs_get_mouse())
cons_show("Mouse handling (/mouse) : ON");
else
cons_show("Mouse handling (/mouse) : OFF");
}
void
@ -2192,42 +2199,45 @@ _win_handle_page(const wint_t * const ch)
int page_space = rows - 4;
int *page_start = &(current->y_pos);
MEVENT mouse_event;
if (prefs_get_mouse()) {
MEVENT mouse_event;
if (*ch == KEY_MOUSE) {
if (getmouse(&mouse_event) == OK) {
if (*ch == KEY_MOUSE) {
if (getmouse(&mouse_event) == OK) {
#ifdef PLATFORM_CYGWIN
if (mouse_event.bstate & BUTTON5_PRESSED) { // mouse wheel down
if (mouse_event.bstate & BUTTON5_PRESSED) { // mouse wheel down
#else
if (mouse_event.bstate & BUTTON2_PRESSED) { // mouse wheel down
if (mouse_event.bstate & BUTTON2_PRESSED) { // mouse wheel down
#endif
*page_start += 4;
*page_start += 4;
// only got half a screen, show full screen
if ((y - (*page_start)) < page_space)
*page_start = y - page_space;
// only got half a screen, show full screen
if ((y - (*page_start)) < page_space)
*page_start = y - page_space;
// went past end, show full screen
else if (*page_start >= y)
*page_start = y - page_space;
// went past end, show full screen
else if (*page_start >= y)
*page_start = y - page_space;
current->paged = 1;
dirty = TRUE;
} else if (mouse_event.bstate & BUTTON4_PRESSED) { // mouse wheel up
*page_start -= 4;
current->paged = 1;
dirty = TRUE;
} else if (mouse_event.bstate & BUTTON4_PRESSED) { // mouse wheel up
*page_start -= 4;
// went past beginning, show first page
if (*page_start < 0)
*page_start = 0;
// went past beginning, show first page
if (*page_start < 0)
*page_start = 0;
current->paged = 1;
dirty = TRUE;
current->paged = 1;
dirty = TRUE;
}
}
}
}
// page up
} else if (*ch == KEY_PPAGE) {
if (*ch == KEY_PPAGE) {
*page_start -= page_space;
// went past beginning, show first page