1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

Fix margins. This fixes annoying extra pixels at bottom.

This commit is contained in:
Qball Cow 2014-01-13 09:42:52 +01:00
parent 5a1f20ae52
commit 236b36d328
2 changed files with 26 additions and 10 deletions

View file

@ -63,6 +63,8 @@
#define OVERLAP(a,b,c,d) (((a)==(c) && (b)==(d)) || MIN((a)+(b), (c)+(d)) - MAX((a), (c)) > 0) #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 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 OPAQUE 0xffffffff
#define OPACITY "_NET_WM_WINDOW_OPACITY" #define OPACITY "_NET_WM_WINDOW_OPACITY"
#define I3_SOCKET_PATH_PROP "I3_SOCKET_PATH" #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 // search text input
textbox *text = textbox_create( box, TB_AUTOHEIGHT|TB_EDITABLE, 5, 5, w-10, 1, textbox *text = textbox_create( box, TB_AUTOHEIGHT|TB_EDITABLE, INNER_MARGIN, INNER_MARGIN,
config_menu_font, config_menu_fg, config_menu_bg, "", prompt ); w-(2*INNER_MARGIN), 1,
config_menu_font, config_menu_fg, config_menu_bg, "", prompt );
textbox_show( text ); textbox_show( text );
int line_height = text->font->ascent + text->font->descent; 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 // filtered list display
textbox **boxes = allocate_clear( sizeof( textbox* ) * max_lines ); textbox **boxes = allocate_clear( sizeof( textbox* ) * max_lines );
for ( i = 0; i < max_lines; i++ ) { for ( i = 0; i < max_lines; i++ ) {
boxes[i] = textbox_create( box, TB_AUTOHEIGHT, 5, ( i+1 ) * line_height + 5, w-10, 1, boxes[i] = textbox_create( box, TB_AUTOHEIGHT, INNER_MARGIN, ( i+1 ) * line_height +
config_menu_font, config_menu_fg, config_menu_bg, lines[i], NULL ); INNER_MARGIN, w-(2*INNER_MARGIN), 1,
config_menu_font, config_menu_fg, config_menu_bg, lines[i], NULL );
textbox_show( boxes[i] ); 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 // 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; int y = mon.y + ( mon.h - h )/2;
XMoveResizeWindow( display, box, x, y, w, h ); XMoveResizeWindow( display, box, x, y, w, h );
XMapRaised( display, box ); XMapRaised( display, box );

View file

@ -2,6 +2,7 @@
MIT/X11 License MIT/X11 License
Copyright (c) 2012 Sean Pringle <sean.pringle@gmail.com> Copyright (c) 2012 Sean Pringle <sean.pringle@gmail.com>
Modified (c) 2013-2014 Qball Cow <qball@gmpclient.org>
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the 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_AUTOHEIGHT 1<<0
#define TB_AUTOWIDTH 1<<1 #define TB_AUTOWIDTH 1<<1
#define TB_LEFT 1<<16 #define TB_LEFT 1<<16
@ -215,10 +217,16 @@ void textbox_draw( textbox *tb )
} }
// calc full input text width // calc full input text width
XftTextExtents8( display, tb->font, ( unsigned char* )line, length, &extents ); // Calculate the right size, so no characters are cut off.
line_width = extents.width; // 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; if ( tb->flags & TB_RIGHT ) x = tb->w - line_width;
@ -229,8 +237,9 @@ void textbox_draw( textbox *tb )
// draw the cursor // draw the cursor
if ( tb->flags & TB_EDITABLE ) 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 // flip canvas to window
XCopyArea( display, canvas, tb->window, context, 0, 0, tb->w, tb->h, 0, 0 ); XCopyArea( display, canvas, tb->window, context, 0, 0, tb->w, tb->h, 0, 0 );