1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Fix issue #104: Scrolling action.

This commit is contained in:
QC 2015-01-14 22:14:15 +01:00
parent 3a4c1f1f3f
commit 2d18aea928
2 changed files with 65 additions and 30 deletions

View file

@ -1025,6 +1025,44 @@ static void menu_calculate_window_and_element_width ( MenuState *state, workarea
}
}
/**
* Nav helper functions, to avoid duplicate code.
*/
inline static void menu_nav_right ( MenuState *state )
{
state->selected += state->max_rows;
if ( state->selected >= state->filtered_lines ) {
state->selected = state->filtered_lines - 1;
}
state->update = TRUE;
}
inline static void menu_nav_left ( MenuState *state )
{
if ( state->selected < state->max_rows ) {
state->selected = 0;
}
else{
state->selected -= state->max_rows;
}
state->update = TRUE;
}
inline static void menu_nav_up ( MenuState *state )
{
if ( state->selected == 0 ) {
state->selected = state->filtered_lines;
}
if ( state->selected > 0 ) {
state->selected--;
}
state->update = TRUE;
}
inline static void menu_nav_down ( MenuState *state )
{
state->selected = state->selected < state->filtered_lines - 1 ? MIN (
state->filtered_lines - 1, state->selected + 1 ) : 0;
state->update = TRUE;
}
/**
* @param state Internal state of the menu.
* @param key the Key being pressed.
@ -1046,14 +1084,7 @@ static void menu_keyboard_navigation ( MenuState *state, KeySym key, unsigned in
// Up, Ctrl-p or Shift-Tab
else if ( key == XK_Up || ( key == XK_Tab && modstate & ShiftMask ) ||
( key == XK_p && modstate & ControlMask ) ) {
if ( state->selected == 0 ) {
state->selected = state->filtered_lines;
}
if ( state->selected > 0 ) {
state->selected--;
}
state->update = TRUE;
menu_nav_up ( state );
}
else if ( key == XK_Tab ) {
if ( state->filtered_lines == 1 ) {
@ -1084,25 +1115,13 @@ static void menu_keyboard_navigation ( MenuState *state, KeySym key, unsigned in
// Down, Ctrl-n
else if ( key == XK_Down ||
( key == XK_n && ( modstate & ControlMask ) ) ) {
state->selected = state->selected < state->filtered_lines - 1 ? MIN (
state->filtered_lines - 1, state->selected + 1 ) : 0;
state->update = TRUE;
menu_nav_down ( state );
}
else if ( key == XK_Page_Up && ( modstate & ControlMask ) ) {
if ( state->selected < state->max_rows ) {
state->selected = 0;
}
else{
state->selected -= state->max_rows;
}
state->update = TRUE;
menu_nav_left ( state );
}
else if ( key == XK_Page_Down && ( modstate & ControlMask ) ) {
state->selected += state->max_rows;
if ( state->selected >= state->filtered_lines ) {
state->selected = state->filtered_lines - 1;
}
state->update = TRUE;
menu_nav_right ( state );
}
else if ( key == XK_Page_Up ) {
if ( state->selected < state->max_elements ) {
@ -1150,6 +1169,22 @@ static void menu_keyboard_navigation ( MenuState *state, KeySym key, unsigned in
*/
static void menu_mouse_navigation ( MenuState *state, XButtonEvent *xbe )
{
// Scroll event
if ( xbe->button > 3 ) {
if ( xbe->button == 4 ) {
menu_nav_up ( state );
}
else if ( xbe->button == 5 ) {
menu_nav_down ( state );
}
else if ( xbe->button == 6 ) {
menu_nav_left ( state );
}
else if ( xbe->button == 7 ) {
menu_nav_right ( state );
}
return;
}
if ( xbe->window == state->arrowbox_top->window ) {
// Page up.
if ( state->selected < state->max_rows ) {

View file

@ -51,7 +51,7 @@
// Used in get_ssh() when splitting lines from the user's
// SSH config file into tokens.
#define SSH_TOKEN_DELIM "= \t\r\n"
#define SSH_TOKEN_DELIM "= \t\r\n"
static inline int execshssh ( const char *host )
{
@ -141,17 +141,17 @@ static char ** get_ssh ( unsigned int *length )
if ( fd != NULL ) {
char buffer[1024];
while ( fgets ( buffer, sizeof( buffer ), fd ) ) {
while ( fgets ( buffer, sizeof ( buffer ), fd ) ) {
// Each line is either empty, a comment line starting with a '#'
// character or of the form "keyword [=] arguments", where there may
// be multiple (possibly quoted) arguments separated by whitespace.
// The keyword is separated from its arguments by whitespace OR by
// optional whitespace and a '=' character.
char *token = strtok( buffer, SSH_TOKEN_DELIM );
char *token = strtok ( buffer, SSH_TOKEN_DELIM );
// Skip empty lines and comment lines. Also skip lines where the
// keyword is not "Host".
if ( ! token || *token == '#' || g_ascii_strcasecmp( token, "Host" ) ) {
if ( !token || *token == '#' || g_ascii_strcasecmp ( token, "Host" ) ) {
continue;
}
@ -160,9 +160,9 @@ static char ** get_ssh ( unsigned int *length )
// by whitespace; while host names may be quoted with double quotes
// to represent host names containing spaces, we don't support this
// (how many host names contain spaces?).
while ( ( token = strtok( NULL, SSH_TOKEN_DELIM ) ) ) {
while ( ( token = strtok ( NULL, SSH_TOKEN_DELIM ) ) ) {
// We do not want to show wildcard entries, as you cannot ssh to them.
if ( *token == '!' || strpbrk( token, "*?" ) ) {
if ( *token == '!' || strpbrk ( token, "*?" ) ) {
continue;
}
@ -171,7 +171,7 @@ static char ** get_ssh ( unsigned int *length )
// given num_favorites is max 25.
int found = 0;
for ( unsigned int j = 0; j < num_favorites; j++ ) {
if ( ! g_ascii_strcasecmp ( token, retv[j] ) ) {
if ( !g_ascii_strcasecmp ( token, retv[j] ) ) {
found = 1;
break;
}