From de5187bb0148f5c68cfe8e0668887edf54d8a12b Mon Sep 17 00:00:00 2001 From: Qball Cow Date: Wed, 14 May 2014 19:51:48 +0200 Subject: [PATCH] Add small arrows indicating more pages. (to be updated later) --- include/textbox.h | 1 + source/rofi.c | 28 +++++++++++++++++++++++++++- source/run-dialog.c | 12 ------------ source/textbox.c | 27 +++++++++++++++++++++------ 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/include/textbox.h b/include/textbox.h index 7fbc3a0e..fcc64873 100644 --- a/include/textbox.h +++ b/include/textbox.h @@ -46,4 +46,5 @@ void textbox_draw ( textbox *tb ); int textbox_keypress ( textbox *tb, XEvent *ev ); void textbox_cursor_end ( textbox *tb ); +void textbox_move (textbox *tb, int x, int y); #endif //__TEXTBOX_H__ diff --git a/source/rofi.c b/source/rofi.c index 59c70bad..c489b0f6 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -808,6 +808,19 @@ Window main_window = None; GC gc = NULL; #include "textbox.h" +inline char *menu_set_arrow_text(int filtered_lines, int selected, int max_lines) +{ + int page = (filtered_lines > 0)? selected/max_lines:0; + int npages = (filtered_lines > 0)? ((filtered_lines+max_lines-1)/max_lines):1; + if( page != 0 && page != (npages-1)) { + return "⇵"; + } else if (page != 0) { + return "↑"; + } else if (page != (npages-1)) { + return "↓"; + } + return " "; +} void menu_draw ( textbox *text, textbox **boxes, @@ -1044,13 +1057,22 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi } // search text input + textbox *arrowbox = textbox_create ( box, TB_AUTOHEIGHT | TB_AUTOWIDTH, + (config.padding), + (config.padding), + 0, 0, + config.menu_font, config.menu_fg, config.menu_bg, + "W", NULL); + textbox *text = textbox_create ( box, TB_AUTOHEIGHT | TB_EDITABLE, ( config.padding ), ( config.padding ), - element_width, 1, + element_width-arrowbox->w, 1, config.menu_font, config.menu_fg, config.menu_bg, ( input != NULL ) ? *input : "", prompt ); + textbox_move ( arrowbox, w-config.padding-arrowbox->w, config.padding); textbox_show ( text ); + textbox_show ( arrowbox ); int line_height = text->font->ascent + text->font->descent; @@ -1184,6 +1206,8 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi } menu_draw ( text, boxes, max_lines, num_lines, &last_offset, selected, filtered ); + textbox_text( arrowbox, menu_set_arrow_text(filtered_lines, selected, max_lines)); + textbox_draw( arrowbox ); // Why do we need the specian -1? if ( config.wmode == VERTICAL && max_lines > 0) @@ -1396,6 +1420,8 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi } menu_draw ( text, boxes, max_lines, num_lines, &last_offset, selected, filtered ); + textbox_text( arrowbox, menu_set_arrow_text(filtered_lines, selected, max_lines)); + textbox_draw( arrowbox ); } } diff --git a/source/run-dialog.c b/source/run-dialog.c index 1fca28da..e28b307e 100644 --- a/source/run-dialog.c +++ b/source/run-dialog.c @@ -59,18 +59,6 @@ static inline int execsh ( const char *cmd, int run_in_term ) return execlp ( "/bin/sh", "sh", "-c", cmd, NULL ); } -#define RUN_DIALOG_NAME_LENGTH 256 -typedef struct _element -{ - long int index; - char name[RUN_DIALOG_NAME_LENGTH]; -}element; -static int element_sort_func ( const void *ea, const void *eb ) -{ - element *a = *(element * *) ea; - element *b = *(element * *) eb; - return b->index - a->index; -} // execute sub-process static pid_t exec_cmd ( const char *cmd, int run_in_term ) { diff --git a/source/textbox.c b/source/textbox.c index 00c4fe08..e1349377 100644 --- a/source/textbox.c +++ b/source/textbox.c @@ -39,7 +39,7 @@ #include "rofi.h" #include "textbox.h" -#define SIDE_MARGIN 3 +#define SIDE_MARGIN 2 extern Display *display; @@ -133,6 +133,15 @@ void textbox_text ( textbox *tb, char *text ) textbox_extents ( tb ); } +void textbox_move (textbox *tb, int x, int y) +{ + if ( x != tb->x || y != tb->y ) + { + tb->x = x; + tb->y = y; + XMoveResizeWindow ( display, tb->window, tb->x, tb->y, tb->w, tb->h ); + } +} // within the parent. handled auto width/height modes void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ) { @@ -143,7 +152,14 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ) if ( tb->flags & TB_AUTOWIDTH ) { - w = tb->extents.width; + if(w > 1) + { + w = MIN(w, tb->extents.width+2*SIDE_MARGIN); + } + else + { + w = tb->extents.width+2*SIDE_MARGIN; + } } if ( x != tb->x || y != tb->y || w != tb->w || h != tb->h ) @@ -259,12 +275,10 @@ void textbox_draw ( textbox *tb ) // calc full input text width // Calculate the right size, so no characters are cut off. // TODO: Check performance of this. - while ( 1 ) - { + do{ XftTextExtentsUtf8 ( display, tb->font, ( unsigned char * ) line, length, &extents ); line_width = extents.width; - - if ( line_width < ( tb->w - 2 * SIDE_MARGIN ) ) + if ( line_width <= ( tb->w - 2 * SIDE_MARGIN ) ) { break; } @@ -274,6 +288,7 @@ void textbox_draw ( textbox *tb ) ; } } + while ( line_width >0 ); int x = SIDE_MARGIN, y = tb->font->ascent;