diff --git a/simpleswitcher.c b/simpleswitcher.c index a0721a7c..4aa03404 100644 --- a/simpleswitcher.c +++ b/simpleswitcher.c @@ -63,6 +63,8 @@ #define OVERLAP(a,b,c,d) (((a)==(c) && (b)==(d)) || MIN((a)+(b), (c)+(d)) - MAX((a), (c)) > 0) #define INTERSECT(x,y,w,h,x1,y1,w1,h1) (OVERLAP((x),(w),(x1),(w1)) && OVERLAP((y),(h),(y1),(h1))) +#define INNER_MARGIN 5 + #define OPAQUE 0xffffffff #define OPACITY "_NET_WM_WINDOW_OPACITY" #define I3_SOCKET_PATH_PROP "I3_SOCKET_PATH" @@ -818,19 +820,23 @@ int menu( char **lines, char **input, char *prompt, int selected, Time *time ) } // search text input - textbox *text = textbox_create( box, TB_AUTOHEIGHT|TB_EDITABLE, 5, 5, w-10, 1, - config_menu_font, config_menu_fg, config_menu_bg, "", prompt ); + textbox *text = textbox_create( box, TB_AUTOHEIGHT|TB_EDITABLE, INNER_MARGIN, INNER_MARGIN, + w-(2*INNER_MARGIN), 1, + config_menu_font, config_menu_fg, config_menu_bg, "", prompt ); textbox_show( text ); int line_height = text->font->ascent + text->font->descent; - line_height += line_height/10; + //line_height += line_height/10; + int row_margin = line_height/10; + line_height+=row_margin; // filtered list display textbox **boxes = allocate_clear( sizeof( textbox* ) * max_lines ); for ( i = 0; i < max_lines; i++ ) { - boxes[i] = textbox_create( box, TB_AUTOHEIGHT, 5, ( i+1 ) * line_height + 5, w-10, 1, - config_menu_font, config_menu_fg, config_menu_bg, lines[i], NULL ); + boxes[i] = textbox_create( box, TB_AUTOHEIGHT, INNER_MARGIN, ( i+1 ) * line_height + + INNER_MARGIN, w-(2*INNER_MARGIN), 1, + config_menu_font, config_menu_fg, config_menu_bg, lines[i], NULL ); textbox_show( boxes[i] ); } @@ -849,7 +855,8 @@ int menu( char **lines, char **input, char *prompt, int selected, Time *time ) } // resize window vertically to suit - int h = line_height * ( max_lines+1 ) + 8; + // Subtract the margin of the last row. + int h = line_height * ( max_lines+1 ) + INNER_MARGIN*2 - row_margin; int y = mon.y + ( mon.h - h )/2; XMoveResizeWindow( display, box, x, y, w, h ); XMapRaised( display, box ); diff --git a/textbox.c b/textbox.c index 3f8557b9..95274985 100644 --- a/textbox.c +++ b/textbox.c @@ -2,6 +2,7 @@ MIT/X11 License Copyright (c) 2012 Sean Pringle +Modified (c) 2013-2014 Qball Cow Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -24,6 +25,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#define SIDE_MARGIN 3 #define TB_AUTOHEIGHT 1<<0 #define TB_AUTOWIDTH 1<<1 #define TB_LEFT 1<<16 @@ -215,10 +217,16 @@ void textbox_draw( textbox *tb ) } // calc full input text width - XftTextExtents8( display, tb->font, ( unsigned char* )line, length, &extents ); - line_width = extents.width; + // Calculate the right size, so no characters are cut off. + // TODO: Check performance of this. + while(1) { + XftTextExtents8( display, tb->font, ( unsigned char* )line, length, &extents ); + line_width = extents.width; + if(line_width < (tb->w-2*SIDE_MARGIN)) break; + length--; + } - int x = 2, y = tb->font->ascent; + int x = SIDE_MARGIN, y = tb->font->ascent; if ( tb->flags & TB_RIGHT ) x = tb->w - line_width; @@ -229,8 +237,9 @@ void textbox_draw( textbox *tb ) // draw the cursor if ( tb->flags & TB_EDITABLE ) - XftDrawRect( draw, &tb->color_fg, cursor_x, 2, cursor_width, line_height-4 ); + XftDrawRect( draw, &tb->color_fg, cursor_x+SIDE_MARGIN, 2, cursor_width, line_height-4 ); + XftDrawRect( draw, &tb->color_bg, tb->w-SIDE_MARGIN, 0, SIDE_MARGIN, tb->h ); // flip canvas to window XCopyArea( display, canvas, tb->window, context, 0, 0, tb->w, tb->h, 0, 0 );