mirror of
https://github.com/profanity-im/profanity.git
synced 2024-09-22 19:45:54 -04:00
Merge pull request #1824 from H3rnand3zzz/feature/mouse-scroll
Smooth scrolling support (+mouse wheel scrolling in some terminals)
This commit is contained in:
commit
bd0aa3eb85
@ -71,6 +71,14 @@ Page the occupants or roster panel up.
|
|||||||
.BI ALT+PAGEDOWN
|
.BI ALT+PAGEDOWN
|
||||||
Page the occupants or roster panel down.
|
Page the occupants or roster panel down.
|
||||||
.TP
|
.TP
|
||||||
|
.BI ALT+UP " or " ALT+WHEEL UP
|
||||||
|
Scroll up. Note: limited support for scrolling with mouse wheel,
|
||||||
|
please, get in touch with devs if you know how to add support
|
||||||
|
for other terminals.
|
||||||
|
.TP
|
||||||
|
.BI ALT+DOWN " or " ALT+WHEEL DOWN
|
||||||
|
Scroll down. See note above.
|
||||||
|
.TP
|
||||||
.BI ALT+a
|
.BI ALT+a
|
||||||
Jump to the next unread window.
|
Jump to the next unread window.
|
||||||
.TP
|
.TP
|
||||||
|
@ -81,6 +81,7 @@
|
|||||||
#include "tools/bookmark_ignore.h"
|
#include "tools/bookmark_ignore.h"
|
||||||
#include "tools/editor.h"
|
#include "tools/editor.h"
|
||||||
#include "plugins/plugins.h"
|
#include "plugins/plugins.h"
|
||||||
|
#include "ui/inputwin.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
#include "ui/window_list.h"
|
#include "ui/window_list.h"
|
||||||
#include "xmpp/avatar.h"
|
#include "xmpp/avatar.h"
|
||||||
|
@ -136,6 +136,7 @@ static int _inp_rl_subwin_pageup_handler(int count, int key);
|
|||||||
static int _inp_rl_subwin_pagedown_handler(int count, int key);
|
static int _inp_rl_subwin_pagedown_handler(int count, int key);
|
||||||
static int _inp_rl_startup_hook(void);
|
static int _inp_rl_startup_hook(void);
|
||||||
static int _inp_rl_down_arrow_handler(int count, int key);
|
static int _inp_rl_down_arrow_handler(int count, int key);
|
||||||
|
static int _inp_rl_scroll_handler(int count, int key);
|
||||||
static int _inp_rl_send_to_editor(int count, int key);
|
static int _inp_rl_send_to_editor(int count, int key);
|
||||||
static int _inp_rl_print_newline_symbol(int count, int key);
|
static int _inp_rl_print_newline_symbol(int count, int key);
|
||||||
|
|
||||||
@ -555,6 +556,8 @@ _inp_rl_startup_hook(void)
|
|||||||
rl_bind_key('\t', _inp_rl_tab_handler);
|
rl_bind_key('\t', _inp_rl_tab_handler);
|
||||||
rl_bind_keyseq("\\e[Z", _inp_rl_shift_tab_handler);
|
rl_bind_keyseq("\\e[Z", _inp_rl_shift_tab_handler);
|
||||||
|
|
||||||
|
rl_bind_keyseq("\\e[1;3A", _inp_rl_scroll_handler); // alt + scroll/arrow up
|
||||||
|
rl_bind_keyseq("\\e[1;3B", _inp_rl_scroll_handler); // alt + scroll/arrow down
|
||||||
rl_bind_keyseq("\\e[1;5B", _inp_rl_down_arrow_handler); // ctrl+arrow down
|
rl_bind_keyseq("\\e[1;5B", _inp_rl_down_arrow_handler); // ctrl+arrow down
|
||||||
rl_bind_keyseq("\\eOb", _inp_rl_down_arrow_handler);
|
rl_bind_keyseq("\\eOb", _inp_rl_down_arrow_handler);
|
||||||
|
|
||||||
@ -907,7 +910,7 @@ static int
|
|||||||
_inp_rl_win_pageup_handler(int count, int key)
|
_inp_rl_win_pageup_handler(int count, int key)
|
||||||
{
|
{
|
||||||
ProfWin* current = wins_get_current();
|
ProfWin* current = wins_get_current();
|
||||||
win_page_up(current);
|
win_page_up(current, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -915,7 +918,7 @@ static int
|
|||||||
_inp_rl_win_pagedown_handler(int count, int key)
|
_inp_rl_win_pagedown_handler(int count, int key)
|
||||||
{
|
{
|
||||||
ProfWin* current = wins_get_current();
|
ProfWin* current = wins_get_current();
|
||||||
win_page_down(current);
|
win_page_down(current, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -935,6 +938,21 @@ _inp_rl_subwin_pagedown_handler(int count, int key)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_inp_rl_scroll_handler(int count, int key)
|
||||||
|
{
|
||||||
|
ProfWin* window = wins_get_current();
|
||||||
|
|
||||||
|
if (key == 'B') {
|
||||||
|
// mouse wheel down
|
||||||
|
win_page_down(window, 4);
|
||||||
|
} else if (key == 'A') {
|
||||||
|
// mouse wheel up
|
||||||
|
win_page_up(window, 4);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_inp_rl_down_arrow_handler(int count, int key)
|
_inp_rl_down_arrow_handler(int count, int key)
|
||||||
{
|
{
|
||||||
|
@ -623,17 +623,20 @@ win_free(ProfWin* window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
win_page_up(ProfWin* window)
|
win_page_up(ProfWin* window, int scroll_size)
|
||||||
{
|
{
|
||||||
_reached_bottom_of_database = FALSE;
|
_reached_bottom_of_database = FALSE;
|
||||||
int rows = getmaxy(stdscr);
|
int rows = getmaxy(stdscr);
|
||||||
int y = getcury(window->layout->win);
|
int total_rows = getcury(window->layout->win);
|
||||||
int page_space = rows - 4;
|
int page_space = rows - 4;
|
||||||
int* page_start = &(window->layout->y_pos);
|
int* page_start = &(window->layout->y_pos);
|
||||||
|
int page_start_initial = *page_start;
|
||||||
|
if (scroll_size == 0)
|
||||||
|
scroll_size = page_space;
|
||||||
|
|
||||||
*page_start -= page_space;
|
*page_start -= scroll_size;
|
||||||
|
|
||||||
if (*page_start == -page_space && window->type == WIN_CHAT) {
|
if (*page_start == -scroll_size && window->type == WIN_CHAT) {
|
||||||
ProfChatWin* chatwin = (ProfChatWin*)window;
|
ProfChatWin* chatwin = (ProfChatWin*)window;
|
||||||
ProfBuffEntry* first_entry = buffer_size(window->layout->buffer) != 0 ? buffer_get_entry(window->layout->buffer, 0) : NULL;
|
ProfBuffEntry* first_entry = buffer_size(window->layout->buffer) != 0 ? buffer_get_entry(window->layout->buffer, 0) : NULL;
|
||||||
|
|
||||||
@ -655,27 +658,33 @@ win_page_up(ProfWin* window)
|
|||||||
*page_start = 0;
|
*page_start = 0;
|
||||||
|
|
||||||
window->layout->paged = 1;
|
window->layout->paged = 1;
|
||||||
win_update_virtual(window);
|
// update only if position has changed
|
||||||
|
if (page_start_initial != *page_start) {
|
||||||
|
win_update_virtual(window);
|
||||||
|
}
|
||||||
|
|
||||||
// switch off page if last line and space line visible
|
// switch off page if last line and space line visible
|
||||||
if ((y) - *page_start == page_space) {
|
if ((total_rows) - *page_start == page_space) {
|
||||||
window->layout->paged = 0;
|
window->layout->paged = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
win_page_down(ProfWin* window)
|
win_page_down(ProfWin* window, int scroll_size)
|
||||||
{
|
{
|
||||||
_reached_top_of_database = FALSE;
|
_reached_top_of_database = FALSE;
|
||||||
int rows = getmaxy(stdscr);
|
int rows = getmaxy(stdscr);
|
||||||
int y = getcury(window->layout->win);
|
|
||||||
int page_space = rows - 4;
|
|
||||||
int* page_start = &(window->layout->y_pos);
|
int* page_start = &(window->layout->y_pos);
|
||||||
|
int total_rows = getcury(window->layout->win);
|
||||||
|
int page_space = rows - 4;
|
||||||
|
int page_start_initial = *page_start;
|
||||||
|
if (scroll_size == 0)
|
||||||
|
scroll_size = page_space;
|
||||||
|
|
||||||
*page_start += page_space;
|
*page_start += scroll_size;
|
||||||
|
|
||||||
// Scrolled down after reaching the bottom of the page
|
// Scrolled down after reaching the bottom of the page
|
||||||
if ((*page_start == y || (*page_start == page_space && *page_start >= y)) && window->type == WIN_CHAT) {
|
if ((*page_start == total_rows || (*page_start == page_space && *page_start >= total_rows)) && window->type == WIN_CHAT) {
|
||||||
int bf_size = buffer_size(window->layout->buffer);
|
int bf_size = buffer_size(window->layout->buffer);
|
||||||
if (bf_size > 0) {
|
if (bf_size > 0) {
|
||||||
auto_gchar gchar* start = g_date_time_format_iso8601(buffer_get_entry(window->layout->buffer, bf_size - 1)->time);
|
auto_gchar gchar* start = g_date_time_format_iso8601(buffer_get_entry(window->layout->buffer, bf_size - 1)->time);
|
||||||
@ -691,18 +700,21 @@ win_page_down(ProfWin* window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// only got half a screen, show full screen
|
// only got half a screen, show full screen
|
||||||
if ((y - (*page_start)) < page_space)
|
if ((total_rows - (*page_start)) < page_space)
|
||||||
*page_start = y - page_space;
|
*page_start = total_rows - page_space;
|
||||||
|
|
||||||
// went past end, show full screen
|
// went past end, show full screen
|
||||||
else if (*page_start >= y)
|
else if (*page_start >= total_rows)
|
||||||
*page_start = y - page_space - 1;
|
*page_start = total_rows - page_space - 1;
|
||||||
|
|
||||||
window->layout->paged = 1;
|
window->layout->paged = 1;
|
||||||
win_update_virtual(window);
|
// update only if position has changed
|
||||||
|
if (page_start_initial != *page_start) {
|
||||||
|
win_update_virtual(window);
|
||||||
|
}
|
||||||
|
|
||||||
// switch off page if last line and space line visible
|
// switch off page if last line and space line visible
|
||||||
if ((y) - *page_start == page_space) {
|
if ((total_rows) - *page_start == page_space) {
|
||||||
window->layout->paged = 0;
|
window->layout->paged = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,8 @@ void win_update_entry_message(ProfWin* window, const char* const id, const char*
|
|||||||
|
|
||||||
gboolean win_has_active_subwin(ProfWin* window);
|
gboolean win_has_active_subwin(ProfWin* window);
|
||||||
|
|
||||||
void win_page_up(ProfWin* window);
|
void win_page_up(ProfWin* window, int scroll_size);
|
||||||
void win_page_down(ProfWin* window);
|
void win_page_down(ProfWin* window, int scroll_size);
|
||||||
void win_sub_page_down(ProfWin* window);
|
void win_sub_page_down(ProfWin* window);
|
||||||
void win_sub_page_up(ProfWin* window);
|
void win_sub_page_up(ProfWin* window);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user