mirror of
https://github.com/lbonn/rofi
synced 2024-11-15 08:37:17 +00:00
Small cleanups.
This commit is contained in:
parent
a3569079c9
commit
52a28ea494
4 changed files with 18 additions and 51 deletions
|
@ -79,9 +79,9 @@ static pid_t exec_cmd( const char *cmd, int run_in_term )
|
|||
char *path = allocate( strlen( cache_dir ) + strlen( RUN_CACHE_FILE )+3 );
|
||||
sprintf( path, "%s/%s", cache_dir, RUN_CACHE_FILE );
|
||||
FILE *fd = fopen ( path, "r" );
|
||||
char buffer[1024];
|
||||
|
||||
if ( fd != NULL ) {
|
||||
char buffer[1024];
|
||||
while ( fgets( buffer,1024,fd ) != NULL ) {
|
||||
retv = reallocate( retv, ( index+2 )*sizeof( char* ) );
|
||||
buffer[strlen( buffer )-1] = '\0';
|
||||
|
@ -142,9 +142,9 @@ static void delete_entry( const char *cmd )
|
|||
char *path = allocate( strlen( cache_dir ) + strlen( RUN_CACHE_FILE )+3 );
|
||||
sprintf( path, "%s/%s", cache_dir, RUN_CACHE_FILE );
|
||||
FILE *fd = fopen ( path, "r" );
|
||||
char buffer[1024];
|
||||
|
||||
if ( fd != NULL ) {
|
||||
char buffer[1024];
|
||||
while ( fgets( buffer,1024,fd ) != NULL ) {
|
||||
retv = reallocate( retv, ( index+2 )*sizeof( char* ) );
|
||||
buffer[strlen( buffer )-1] = '\0';
|
||||
|
@ -209,9 +209,9 @@ static char ** get_apps ( )
|
|||
path = allocate( strlen( cache_dir ) + strlen( RUN_CACHE_FILE )+3 );
|
||||
sprintf( path, "%s/%s", cache_dir, RUN_CACHE_FILE );
|
||||
FILE *fd = fopen ( path, "r" );
|
||||
char buffer[1024];
|
||||
|
||||
if ( fd != NULL ) {
|
||||
char buffer[1024];
|
||||
while ( fgets( buffer,1024,fd ) != NULL ) {
|
||||
retv = reallocate( retv, ( index+2 )*sizeof( char* ) );
|
||||
buffer[strlen( buffer )-1] = '\0';
|
||||
|
|
|
@ -220,8 +220,7 @@ static void focus_window_i3( const char *socket_path, int id )
|
|||
t = recv( s, &head, sizeof( head ),0 );
|
||||
|
||||
if ( t == sizeof( head ) ) {
|
||||
t= recv( s, command, head.size, 0 );
|
||||
command[t] = '\0';
|
||||
recv( s, command, head.size, 0 );
|
||||
}
|
||||
|
||||
close( s );
|
||||
|
@ -529,13 +528,6 @@ void window_set_atom_prop( Window w, Atom prop, Atom *atoms, int count )
|
|||
XChangeProperty( display, w, prop, XA_ATOM, 32, PropModeReplace, ( unsigned char* )atoms, count );
|
||||
}
|
||||
|
||||
int window_get_cardinal_prop( Window w, Atom atom, unsigned long *list, int count )
|
||||
{
|
||||
Atom type;
|
||||
int items;
|
||||
return window_get_prop( w, atom, &type, &items, list, count*sizeof( unsigned long ) ) && type == XA_CARDINAL ? items:0;
|
||||
}
|
||||
|
||||
// a ClientMessage
|
||||
int window_send_message( Window target, Window subject, Atom atom, unsigned long protocol, unsigned long mask, Time time )
|
||||
{
|
||||
|
@ -562,10 +554,11 @@ void monitor_dimensions( Screen *screen, int x, int y, workarea *mon )
|
|||
|
||||
// locate the current monitor
|
||||
if ( XineramaIsActive( display ) ) {
|
||||
int monitors, i;
|
||||
int monitors;
|
||||
XineramaScreenInfo *info = XineramaQueryScreens( display, &monitors );
|
||||
|
||||
if ( info ) for ( i = 0; i < monitors; i++ ) {
|
||||
if ( info ) {
|
||||
for ( int i = 0; i < monitors; i++ ) {
|
||||
if ( INTERSECT( x, y, 1, 1, info[i].x_org, info[i].y_org, info[i].width, info[i].height ) ) {
|
||||
mon->x = info[i].x_org;
|
||||
mon->y = info[i].y_org;
|
||||
|
@ -574,6 +567,7 @@ void monitor_dimensions( Screen *screen, int x, int y, workarea *mon )
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XFree( info );
|
||||
}
|
||||
|
@ -730,15 +724,16 @@ void menu_draw( textbox *text, textbox **boxes, int max_lines,int num_lines, int
|
|||
*/
|
||||
static int calculate_common_prefix( char **filtered, int max_lines )
|
||||
{
|
||||
int length_prefix = 0,j,found = 1;
|
||||
int length_prefix = 0;
|
||||
|
||||
if ( filtered[0] != NULL ) {
|
||||
int found = 1;
|
||||
char *p = filtered[0];
|
||||
|
||||
do {
|
||||
found = 1;
|
||||
|
||||
for ( j=0; j < max_lines && filtered[j] != NULL; j++ ) {
|
||||
for ( int j=0; j < max_lines && filtered[j] != NULL; j++ ) {
|
||||
if ( filtered[j][length_prefix] == '\0' || filtered[j][length_prefix] != *p ) {
|
||||
if ( found )
|
||||
found=0;
|
||||
|
@ -753,7 +748,7 @@ static int calculate_common_prefix( char **filtered, int max_lines )
|
|||
p++;
|
||||
} while ( found );
|
||||
// cut off to be valid utf8.
|
||||
for ( j = 0; j < length_prefix; ) {
|
||||
for ( int j = 0; j < length_prefix; ) {
|
||||
if((filtered[0][j]&0x80) == 0){j++;}
|
||||
else if ((filtered[0][j]&0xf0) == 0xc0) {
|
||||
// 2 bytes
|
||||
|
@ -898,8 +893,6 @@ MenuReturn menu( char **lines, char **input, char *prompt, Time *time, int *shif
|
|||
int *line_map = allocate_clear( sizeof( int ) * num_lines );
|
||||
unsigned int filtered_lines = 0;
|
||||
|
||||
int jin = 0;
|
||||
|
||||
if ( input && *input ) {
|
||||
char **tokens = tokenize( *input );
|
||||
|
||||
|
@ -917,6 +910,7 @@ MenuReturn menu( char **lines, char **input, char *prompt, Time *time, int *shif
|
|||
|
||||
tokenize_free( tokens );
|
||||
} else {
|
||||
int jin = 0;
|
||||
for ( i = 0; i < num_lines; i++ ) {
|
||||
filtered[jin] = lines[i];
|
||||
line_map[jin] = i;
|
||||
|
|
|
@ -76,9 +76,9 @@ static pid_t exec_ssh( const char *cmd )
|
|||
char *path = allocate( strlen( cache_dir ) + strlen( SSH_CACHE_FILE )+3 );
|
||||
sprintf( path, "%s/%s", cache_dir, SSH_CACHE_FILE );
|
||||
FILE *fd = fopen ( path, "r" );
|
||||
char buffer[1024];
|
||||
|
||||
if ( fd != NULL ) {
|
||||
char buffer[1024];
|
||||
while ( fgets( buffer,1024,fd ) != NULL ) {
|
||||
retv = reallocate( retv, ( index+2 )*sizeof( char* ) );
|
||||
buffer[strlen( buffer )-1] = '\0';
|
||||
|
@ -140,9 +140,9 @@ static void delete_ssh( const char *cmd )
|
|||
char *path = allocate( strlen( cache_dir ) + strlen( SSH_CACHE_FILE )+3 );
|
||||
sprintf( path, "%s/%s", cache_dir, SSH_CACHE_FILE );
|
||||
FILE *fd = fopen ( path, "r" );
|
||||
char buffer[1024];
|
||||
|
||||
if ( fd != NULL ) {
|
||||
char buffer[1024];
|
||||
while ( fgets( buffer,1024,fd ) != NULL ) {
|
||||
retv = reallocate( retv, ( index+2 )*sizeof( char* ) );
|
||||
buffer[strlen( buffer )-1] = '\0';
|
||||
|
|
|
@ -113,7 +113,7 @@ void textbox_font( textbox *tb, char *font, char *fg, char *bg )
|
|||
void textbox_extents( textbox *tb )
|
||||
{
|
||||
int length = strlen( tb->text ) + strlen( tb->prompt ) +1;
|
||||
char *line = alloca( length + 1 );
|
||||
char line[length + 1 ];
|
||||
sprintf( line, "%s %s", tb->prompt, tb->text );
|
||||
XftTextExtentsUtf8( display, tb->font, ( unsigned char* )line, length, &tb->extents );
|
||||
}
|
||||
|
@ -128,15 +128,6 @@ void textbox_text( textbox *tb, char *text )
|
|||
textbox_extents( tb );
|
||||
}
|
||||
|
||||
// set an input prompt for edit mode
|
||||
void textbox_prompt( textbox *tb, char *text )
|
||||
{
|
||||
if ( tb->prompt ) free( tb->prompt );
|
||||
|
||||
tb->prompt = strdup( text );
|
||||
textbox_extents( tb );
|
||||
}
|
||||
|
||||
// within the parent. handled auto width/height modes
|
||||
void textbox_moveresize( textbox *tb, int x, int y, int w, int h )
|
||||
{
|
||||
|
@ -160,10 +151,6 @@ void textbox_show( textbox *tb )
|
|||
XMapWindow( display, tb->window );
|
||||
}
|
||||
|
||||
void textbox_hide( textbox *tb )
|
||||
{
|
||||
XUnmapWindow( display, tb->window );
|
||||
}
|
||||
|
||||
// will also unmap the window if still displayed
|
||||
void textbox_free( textbox *tb )
|
||||
|
@ -196,7 +183,6 @@ void textbox_free( textbox *tb )
|
|||
|
||||
void textbox_draw( textbox *tb )
|
||||
{
|
||||
int i;
|
||||
XGlyphInfo extents;
|
||||
|
||||
GC context = XCreateGC( display, tb->window, 0, 0 );
|
||||
|
@ -216,10 +202,10 @@ void textbox_draw( textbox *tb )
|
|||
int line_width = 0;
|
||||
|
||||
int cursor_x = 0;
|
||||
int cursor_offset = 0;
|
||||
int cursor_width = MAX( 2, line_height/10 );
|
||||
|
||||
if ( tb->flags & TB_EDITABLE ) {
|
||||
int cursor_offset = 0;
|
||||
int prompt_len = strlen( prompt ) +1;
|
||||
length = text_len + prompt_len;
|
||||
cursor_offset = MIN( tb->cursor + prompt_len, length );
|
||||
|
@ -228,7 +214,7 @@ void textbox_draw( textbox *tb )
|
|||
sprintf( line, "%s %s", prompt, text );
|
||||
|
||||
// replace spaces so XftTextExtents8 includes their width
|
||||
for ( i = 0; i < length; i++ ) if ( isspace( line[i] ) ) line[i] = '_';
|
||||
for ( int i = 0; i < length; i++ ) if ( isspace( line[i] ) ) line[i] = '_';
|
||||
|
||||
// calc cursor position
|
||||
XftTextExtentsUtf8( display, tb->font, ( unsigned char* )line, cursor_offset, &extents );
|
||||
|
@ -298,11 +284,6 @@ void textbox_cursor_dec( textbox *tb )
|
|||
textbox_cursor( tb, nextrune(tb,-1) );
|
||||
}
|
||||
|
||||
// beginning of line
|
||||
void textbox_cursor_home( textbox *tb )
|
||||
{
|
||||
tb->cursor = 0;
|
||||
}
|
||||
|
||||
// end of line
|
||||
void textbox_cursor_end( textbox *tb )
|
||||
|
@ -336,14 +317,6 @@ void textbox_delete( textbox *tb, int pos, int dlen )
|
|||
textbox_extents( tb );
|
||||
}
|
||||
|
||||
// insert one character
|
||||
void textbox_cursor_ins( textbox *tb, char c )
|
||||
{
|
||||
char tmp[2] = { c, 0 };
|
||||
textbox_insert( tb, tb->cursor, tmp );
|
||||
textbox_cursor_inc( tb );
|
||||
}
|
||||
|
||||
// delete on character
|
||||
void textbox_cursor_del( textbox *tb )
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue