mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
[TextBox] fix alignment issue with cursor.
This commit is contained in:
parent
d393a5ff2e
commit
59ee49a557
3 changed files with 31 additions and 19 deletions
|
@ -86,9 +86,6 @@ indent: ${rofi_SOURCES}
|
|||
update-manpage: ${top_srcdir}/doc/rofi-manpage.markdown
|
||||
md2man-roff $^ > ${top_srcdir}/doc/rofi.1
|
||||
|
||||
.PHONY: test
|
||||
test: rofi
|
||||
make -C test/ test
|
||||
##
|
||||
# Rofi test program
|
||||
##
|
||||
|
|
|
@ -98,8 +98,14 @@ unsigned int curr_switcher = 0;
|
|||
|
||||
void window_set_opacity ( Display *display, Window box, unsigned int opacity );
|
||||
|
||||
|
||||
int switcher_get ( const char *name )
|
||||
/**
|
||||
* @param name Name of the switcher to lookup.
|
||||
*
|
||||
* Find the index of the switcher with name.
|
||||
*
|
||||
* @returns index of the switcher in switchers, -1 if not found.
|
||||
*/
|
||||
static int switcher_get ( const char *name )
|
||||
{
|
||||
for ( unsigned int i = 0; i < num_switchers; i++ ) {
|
||||
if ( strcmp ( switchers[i].name, name ) == 0 ) {
|
||||
|
@ -1659,7 +1665,7 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom
|
|||
state.retv = MENU_OK;
|
||||
}
|
||||
}
|
||||
else if ( strlen( state.text->text) > 0 ) {
|
||||
else if ( strlen ( state.text->text ) > 0 ) {
|
||||
state.retv = MENU_CUSTOM_INPUT;
|
||||
}
|
||||
else{
|
||||
|
@ -2275,10 +2281,6 @@ static void cleanup ()
|
|||
*/
|
||||
static void config_sanity_check ( void )
|
||||
{
|
||||
// if ( config.menu_lines == 0 ) {
|
||||
// fprintf ( stderr, "config.menu_lines is invalid. You need at least one visible line.\n" );
|
||||
// exit ( 1 );
|
||||
// }
|
||||
if ( config.element_height < 1 ) {
|
||||
fprintf ( stderr, "config.element_height is invalid. It needs to be atleast 1 line high.\n" );
|
||||
exit ( 1 );
|
||||
|
@ -2314,24 +2316,31 @@ static void setup_switchers ( void )
|
|||
char *savept;
|
||||
char *switcher_str = g_strdup ( config.switchers );
|
||||
char *token;
|
||||
// Split token on ','. This modifies switcher_str.
|
||||
for ( token = strtok_r ( switcher_str, ",", &savept );
|
||||
token != NULL;
|
||||
token = strtok_r ( NULL, ",", &savept ) ) {
|
||||
// Window switcher.
|
||||
if ( strcasecmp ( token, "window" ) == 0 ) {
|
||||
// Resize and add entry.
|
||||
switchers = (Switcher *) g_realloc ( switchers, sizeof ( Switcher ) * ( num_switchers + 1 ) );
|
||||
g_strlcpy ( switchers[num_switchers].name, "window", 32 );
|
||||
switchers[num_switchers].cb = run_switcher_window;
|
||||
switchers[num_switchers].cb_data = NULL;
|
||||
num_switchers++;
|
||||
}
|
||||
// SSh dialog
|
||||
else if ( strcasecmp ( token, "ssh" ) == 0 ) {
|
||||
// Resize and add entry.
|
||||
switchers = (Switcher *) g_realloc ( switchers, sizeof ( Switcher ) * ( num_switchers + 1 ) );
|
||||
g_strlcpy ( switchers[num_switchers].name, "ssh", 32 );
|
||||
switchers[num_switchers].cb = ssh_switcher_dialog;
|
||||
switchers[num_switchers].cb_data = NULL;
|
||||
num_switchers++;
|
||||
}
|
||||
// Run dialog
|
||||
else if ( strcasecmp ( token, "run" ) == 0 ) {
|
||||
// Resize and add entry.
|
||||
switchers = (Switcher *) g_realloc ( switchers, sizeof ( Switcher ) * ( num_switchers + 1 ) );
|
||||
g_strlcpy ( switchers[num_switchers].name, "run", 32 );
|
||||
switchers[num_switchers].cb = run_switcher_dialog;
|
||||
|
@ -2339,8 +2348,10 @@ static void setup_switchers ( void )
|
|||
num_switchers++;
|
||||
}
|
||||
else {
|
||||
// If not build in, use custom switchers.
|
||||
ScriptOptions *sw = script_switcher_parse_setup ( token );
|
||||
if ( sw != NULL ) {
|
||||
// Resize and add entry.
|
||||
switchers = (Switcher *) g_realloc ( switchers, sizeof ( Switcher ) * ( num_switchers + 1 ) );
|
||||
g_strlcpy ( switchers[num_switchers].name, sw->name, 32 );
|
||||
switchers[num_switchers].cb = script_switcher_dialog;
|
||||
|
@ -2348,12 +2359,13 @@ static void setup_switchers ( void )
|
|||
num_switchers++;
|
||||
}
|
||||
else{
|
||||
// Report error, don't continue.
|
||||
fprintf ( stderr, "Invalid script switcher: %s\n", token );
|
||||
token = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Free string that was modified by strtok_r
|
||||
g_free ( switcher_str );
|
||||
}
|
||||
|
||||
|
|
|
@ -228,7 +228,6 @@ void textbox_draw ( textbox *tb )
|
|||
char *text = tb->text ? tb->text : "";
|
||||
int text_len = strlen ( text );
|
||||
int font_height = textbox_get_font_height ( tb );
|
||||
int line_width = 0;
|
||||
|
||||
int cursor_x = 0;
|
||||
int cursor_width = MAX ( 2, font_height / 10 );
|
||||
|
@ -246,26 +245,30 @@ void textbox_draw ( textbox *tb )
|
|||
|
||||
pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tb->w - 2 * SIDE_MARGIN ) );
|
||||
|
||||
int x = PANGO_SCALE * SIDE_MARGIN, y = 0;
|
||||
|
||||
// Skip the side MARGIN on the X axis.
|
||||
int x = PANGO_SCALE * SIDE_MARGIN;
|
||||
int y = 0;
|
||||
|
||||
if ( tb->flags & TB_RIGHT ) {
|
||||
x = ( tb->w - line_width ) * PANGO_SCALE;
|
||||
int line_width = 0;
|
||||
// Get actual width.
|
||||
pango_layout_get_pixel_size ( tb->layout, &line_width, NULL );
|
||||
x = ( tb->w - line_width - SIDE_MARGIN ) * PANGO_SCALE;
|
||||
}
|
||||
else if ( tb->flags & TB_CENTER ) {
|
||||
int tw = textbox_get_font_width ( tb );
|
||||
x = ( PANGO_SCALE * ( tb->w - tw ) ) / 2;
|
||||
x = ( PANGO_SCALE * ( tb->w - tw - 2 * SIDE_MARGIN ) ) / 2;
|
||||
}
|
||||
y = ( PANGO_SCALE * ( textbox_get_width ( tb ) - textbox_get_font_width ( tb ) ) ) / 2;
|
||||
// Render the layout.
|
||||
pango_xft_render_layout ( draw, &( tb->color_fg ), tb->layout,
|
||||
x, y );
|
||||
pango_xft_render_layout ( draw, &( tb->color_fg ), tb->layout, x, y );
|
||||
|
||||
// draw the cursor
|
||||
if ( tb->flags & TB_EDITABLE ) {
|
||||
XftDrawRect ( draw, &tb->color_fg, x / PANGO_SCALE + cursor_x + SIDE_MARGIN, SIDE_MARGIN, cursor_width, font_height );
|
||||
XftDrawRect ( draw, &tb->color_fg, x / PANGO_SCALE + cursor_x, SIDE_MARGIN, cursor_width, font_height );
|
||||
}
|
||||
|
||||
XftDrawRect ( draw, &tb->color_bg, tb->w, 0, 0, tb->h );
|
||||
// flip canvas to window
|
||||
XCopyArea ( display, canvas, tb->window, context, 0, 0, tb->w, tb->h, 0, 0 );
|
||||
|
||||
|
|
Loading…
Reference in a new issue