mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
Merge branch 'master' of github:DaveDavenport/rofi
This commit is contained in:
commit
fefd992c11
11 changed files with 139 additions and 39 deletions
|
@ -3,6 +3,10 @@
|
|||
- Have separate config file.
|
||||
Bug fixes:
|
||||
- Fix subpixel rendering. (#303)
|
||||
- Fix basic tests on OpenBSD (#272)
|
||||
- Fix wrong use of memcpy (thx to Jasperia).
|
||||
- Work around for sigwaitinfo on OpenBSD.
|
||||
|
||||
0.15.12:
|
||||
New features:
|
||||
- Initial `-dump` command for dmenu mode. (#216)
|
||||
|
|
10
Makefile.am
10
Makefile.am
|
@ -191,7 +191,7 @@ test-x: ${bin_PROGRAMS}
|
|||
echo "Test daemon"
|
||||
$(top_srcdir)/test/run_test.sh 211 $(top_srcdir)/test/run_daemon_test.sh $(top_builddir)
|
||||
echo "Test xr dump"
|
||||
$(top_srcdir)/test/run_test.sh 212 $(top_srcdir)/test/xr_dump_test.sh $(top_builddir) $(top_srcdir)
|
||||
$(top_srcdir)/test/run_test.sh 212 $(top_srcdir)/test/xr_dump_test.sh $(top_builddir) $(top_srcdir)
|
||||
echo "Test drun"
|
||||
$(top_srcdir)/test/run_test.sh 213 $(top_srcdir)/test/run_drun_test.sh $(top_builddir)
|
||||
echo "Test combi"
|
||||
|
@ -200,10 +200,14 @@ test-x: ${bin_PROGRAMS}
|
|||
$(top_srcdir)/test/run_test.sh 215 $(top_srcdir)/test/run_regex_test.sh $(top_builddir)
|
||||
echo "Test dmenu glob"
|
||||
$(top_srcdir)/test/run_test.sh 216 $(top_srcdir)/test/run_glob_test.sh $(top_builddir)
|
||||
echo "Test dmenu fuzzy"
|
||||
$(top_srcdir)/test/run_test.sh 217 $(top_srcdir)/test/run_fuzzy_test.sh $(top_builddir)
|
||||
echo "Test config dump"
|
||||
$(top_srcdir)/test/run_test.sh 217 $(top_srcdir)/test/xr_config_test.sh $(top_builddir) $(top_srcdir)
|
||||
$(top_srcdir)/test/run_test.sh 218 $(top_srcdir)/test/xr_config_test.sh $(top_builddir) $(top_srcdir)
|
||||
echo "Test dmenu-normal-window"
|
||||
$(top_srcdir)/test/run_test.sh 219 $(top_srcdir)/test/run_dmenu_normal_window_test.sh $(top_builddir)
|
||||
echo "Test window"
|
||||
$(top_srcdir)/test/run_test.sh 217 $(top_srcdir)/test/run_window_test.sh $(top_builddir) $(top_srcdir)
|
||||
$(top_srcdir)/test/run_test.sh 220 $(top_srcdir)/test/run_window_test.sh $(top_builddir) $(top_srcdir)
|
||||
echo "End tests"
|
||||
|
||||
|
||||
|
|
|
@ -154,4 +154,5 @@ void cmd_set_arguments ( int argc, char **argv );
|
|||
* @returns path
|
||||
*/
|
||||
char *rofi_expand_path ( const char *input );
|
||||
unsigned int levenshtein ( const char *needle, const char *haystack );
|
||||
#endif // ROFI_HELPER_H
|
||||
|
|
|
@ -32,14 +32,14 @@ typedef struct
|
|||
|
||||
typedef enum
|
||||
{
|
||||
TB_AUTOHEIGHT = 1 << 0,
|
||||
TB_AUTOWIDTH = 1 << 1,
|
||||
TB_LEFT = 1 << 16,
|
||||
TB_RIGHT = 1 << 17,
|
||||
TB_CENTER = 1 << 18,
|
||||
TB_EDITABLE = 1 << 19,
|
||||
TB_MARKUP = 1 << 20,
|
||||
TB_WRAP = 1 << 21,
|
||||
TB_AUTOHEIGHT = 1 << 0,
|
||||
TB_AUTOWIDTH = 1 << 1,
|
||||
TB_LEFT = 1 << 16,
|
||||
TB_RIGHT = 1 << 17,
|
||||
TB_CENTER = 1 << 18,
|
||||
TB_EDITABLE = 1 << 19,
|
||||
TB_MARKUP = 1 << 20,
|
||||
TB_WRAP = 1 << 21,
|
||||
} TextboxFlags;
|
||||
|
||||
typedef enum
|
||||
|
|
|
@ -38,6 +38,10 @@ void config_parse_cmd_options_dynamic ( void );
|
|||
void config_parse_xresource_options_dynamic ( Display *display );
|
||||
void config_parse_xresource_options_dynamic_file ( const char *filename );
|
||||
|
||||
/**
|
||||
* Initializes the Xresourced system.
|
||||
*/
|
||||
void config_parse_xresource_init ( void );
|
||||
/**
|
||||
* Free any allocated memory.
|
||||
*/
|
||||
|
|
|
@ -624,3 +624,36 @@ char *rofi_expand_path ( const char *input )
|
|||
g_strfreev ( str );
|
||||
return retv;
|
||||
}
|
||||
|
||||
#define MIN3( a, b, c ) ( ( a ) < ( b ) ? ( ( a ) < ( c ) ? ( a ) : ( c ) ) : ( ( b ) < ( c ) ? ( b ) : ( c ) ) )
|
||||
|
||||
unsigned int levenshtein ( const char *needle, const char *haystack )
|
||||
{
|
||||
unsigned int x, y, lastdiag, olddiag;
|
||||
size_t needlelen = g_utf8_strlen ( needle, -1 );
|
||||
size_t haystacklen = g_utf8_strlen ( haystack, -1 );
|
||||
unsigned int column[needlelen + 1];
|
||||
for ( y = 0; y <= needlelen; y++ ) {
|
||||
column[y] = y;
|
||||
}
|
||||
for ( x = 1; x <= haystacklen; x++ ) {
|
||||
const char *needles = needle;
|
||||
column[0] = x;
|
||||
gunichar haystackc = g_utf8_get_char ( haystack );
|
||||
if ( !config.case_sensitive ) {
|
||||
haystackc = g_unichar_tolower ( haystackc );
|
||||
}
|
||||
for ( y = 1, lastdiag = x - 1; y <= needlelen; y++ ) {
|
||||
gunichar needlec = g_utf8_get_char ( needles );
|
||||
if ( !config.case_sensitive ) {
|
||||
needlec = g_unichar_tolower ( needlec );
|
||||
}
|
||||
olddiag = column[y];
|
||||
column[y] = MIN3 ( column[y] + 1, column[y - 1] + 1, lastdiag + ( needlec == haystackc ? 0 : 1 ) );
|
||||
lastdiag = olddiag;
|
||||
needles = g_utf8_next_char ( needles );
|
||||
}
|
||||
haystack = g_utf8_next_char ( haystack );
|
||||
}
|
||||
return column[needlelen];
|
||||
}
|
||||
|
|
|
@ -173,28 +173,6 @@ static int lev_sort ( const void *p1, const void *p2, void *arg )
|
|||
return distances[*a] - distances[*b];
|
||||
}
|
||||
|
||||
#define MIN3( a, b, c ) ( ( a ) < ( b ) ? ( ( a ) < ( c ) ? ( a ) : ( c ) ) : ( ( b ) < ( c ) ? ( b ) : ( c ) ) )
|
||||
|
||||
static unsigned int levenshtein ( const char *s1, const char *s2 )
|
||||
{
|
||||
unsigned int x, y, lastdiag, olddiag;
|
||||
size_t s1len = strlen ( s1 );
|
||||
size_t s2len = strlen ( s2 );
|
||||
unsigned int column[s1len + 1];
|
||||
for ( y = 0; y <= s1len; y++ ) {
|
||||
column[y] = y;
|
||||
}
|
||||
for ( x = 1; x <= s2len; x++ ) {
|
||||
column[0] = x;
|
||||
for ( y = 1, lastdiag = x - 1; y <= s1len; y++ ) {
|
||||
olddiag = column[y];
|
||||
column[y] = MIN3 ( column[y] + 1, column[y - 1] + 1, lastdiag + ( s1[y - 1] == s2[x - 1] ? 0 : 1 ) );
|
||||
lastdiag = olddiag;
|
||||
}
|
||||
}
|
||||
return column[s1len];
|
||||
}
|
||||
|
||||
// State of the menu.
|
||||
|
||||
typedef struct MenuState
|
||||
|
@ -861,7 +839,13 @@ static void filter_elements ( thread_state *t, G_GNUC_UNUSED gpointer user_data
|
|||
t->state->line_map[t->start + t->count] = i;
|
||||
if ( config.levenshtein_sort ) {
|
||||
// This is inefficient, need to fix it.
|
||||
char * str = t->state->sw->mgrv ( t->state->sw, i, &st, TRUE );
|
||||
char * str = NULL;
|
||||
if ( t->state->sw->get_completion ) {
|
||||
str = t->state->sw->get_completion ( t->state->sw, i );
|
||||
}
|
||||
else{
|
||||
str = t->state->sw->mgrv ( t->state->sw, i, &st, TRUE );
|
||||
}
|
||||
t->state->distance[i] = levenshtein ( t->state->text->text, str );
|
||||
g_free ( str );
|
||||
}
|
||||
|
@ -2473,6 +2457,10 @@ int main ( int argc, char *argv[] )
|
|||
sncontext = sn_launchee_context_new_from_environment ( sndisplay, DefaultScreen ( display ) );
|
||||
}
|
||||
TICK_N ( "Startup Notification" );
|
||||
|
||||
// Initialize Xresources subsystem.
|
||||
config_parse_xresource_init ();
|
||||
TICK_N ( "Initialize Xresources system" );
|
||||
// Setup keybinding
|
||||
setup_abe ();
|
||||
TICK_N ( "Setup abe" );
|
||||
|
|
|
@ -221,7 +221,6 @@ void config_parse_xresource_options ( Display *display )
|
|||
{
|
||||
char *xRMS;
|
||||
// Map Xresource entries to rofi config options.
|
||||
XrmInitialize ();
|
||||
xRMS = XResourceManagerString ( display );
|
||||
|
||||
if ( xRMS == NULL ) {
|
||||
|
@ -237,7 +236,6 @@ void config_parse_xresource_options_file ( const char *filename )
|
|||
return;
|
||||
}
|
||||
// Map Xresource entries to rofi config options.
|
||||
XrmInitialize ();
|
||||
XrmDatabase xDB = XrmGetFileDatabase ( filename );
|
||||
if ( xDB == NULL ) {
|
||||
return;
|
||||
|
@ -331,7 +329,6 @@ void config_parse_xresource_options_dynamic ( Display *display )
|
|||
{
|
||||
char *xRMS;
|
||||
// Map Xresource entries to rofi config options.
|
||||
XrmInitialize ();
|
||||
xRMS = XResourceManagerString ( display );
|
||||
|
||||
if ( xRMS == NULL ) {
|
||||
|
@ -347,7 +344,6 @@ void config_parse_xresource_options_dynamic_file ( const char *filename )
|
|||
return;
|
||||
}
|
||||
// Map Xresource entries to rofi config options.
|
||||
XrmInitialize ();
|
||||
XrmDatabase xDB = XrmGetFileDatabase ( filename );
|
||||
if ( xDB == NULL ) {
|
||||
return;
|
||||
|
@ -568,3 +564,8 @@ void print_xresources_theme ( void )
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void config_parse_xresource_init ( void )
|
||||
{
|
||||
XrmInitialize ();
|
||||
}
|
||||
|
|
|
@ -7,10 +7,18 @@
|
|||
|
||||
static int test = 0;
|
||||
|
||||
#define TASSERT( a ) { \
|
||||
#define TASSERT( a ) { \
|
||||
assert ( a ); \
|
||||
printf ( "Test %i passed (%s)\n", ++test, # a ); \
|
||||
}
|
||||
#define TASSERTE( a, b ) { \
|
||||
if ( ( a ) == ( b ) ) { \
|
||||
printf ( "Test %i passed (%s == %s) (%u == %u)\n", ++test, # a, # b, a, b ); \
|
||||
}else { \
|
||||
printf ( "Test %i failed (%s == %s) (%u != %u)\n", ++test, # a, # b, a, b ); \
|
||||
abort ( ); \
|
||||
} \
|
||||
}
|
||||
|
||||
void error_dialog ( const char *msg, G_GNUC_UNUSED int markup )
|
||||
{
|
||||
|
@ -127,4 +135,13 @@ int main ( int argc, char ** argv )
|
|||
TASSERT ( retv[2] && strcmp ( retv[2], "bEp" ) == 0 );
|
||||
TASSERT ( retv[3] && strcmp ( retv[3], "bEE" ) == 0 );
|
||||
tokenize_free ( retv );
|
||||
|
||||
TASSERT ( levenshtein ( "aap", "aap" ) == 0 );
|
||||
TASSERT ( levenshtein ( "aap", "aap " ) == 1 );
|
||||
TASSERT ( levenshtein ( "aap ", "aap" ) == 1 );
|
||||
TASSERTE ( levenshtein ( "aap", "aap noot" ), 5 );
|
||||
TASSERTE ( levenshtein ( "aap", "noot aap" ), 5 );
|
||||
TASSERTE ( levenshtein ( "aap", "noot aap mies" ), 10 );
|
||||
TASSERTE ( levenshtein ( "noot aap mies", "aap" ), 10 );
|
||||
TASSERTE ( levenshtein ( "otp", "noot aap" ), 5 );
|
||||
}
|
||||
|
|
26
test/run_dmenu_normal_window_test.sh
Executable file
26
test/run_dmenu_normal_window_test.sh
Executable file
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# wait till it is up, run rofi with error message
|
||||
sleep 1;
|
||||
echo -e -n "aap\nnoot\nmies" | rofi -dmenu -normal-window > output.txt &
|
||||
RPID=$!
|
||||
sleep 4
|
||||
xdotool getactivewindow windowsize 100% 100%
|
||||
# send enter.
|
||||
sleep 1
|
||||
xdotool key 'Down'
|
||||
sleep 0.4
|
||||
xdotool key Shift+Return
|
||||
xdotool key Return
|
||||
|
||||
# Get result, kill xvfb
|
||||
wait ${RPID}
|
||||
RETV=$?
|
||||
OUTPUT=$(cat output.txt | tr '\n' ' ')
|
||||
if [ "${OUTPUT}" != 'noot mies ' ]
|
||||
then
|
||||
echo "Got: '${OUTPUT}' expected 'noot mies '"
|
||||
exit 1
|
||||
fi
|
||||
echo ${RETV}
|
||||
exit ${RETV}
|
22
test/run_fuzzy_test.sh
Executable file
22
test/run_fuzzy_test.sh
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
echo -en "nooty\naap\nnoot\nmies" | rofi -fuzzy -dmenu > output.txt &
|
||||
RPID=$!
|
||||
|
||||
# send enter.
|
||||
sleep 5;
|
||||
xdotool type 'nty'
|
||||
sleep 0.4
|
||||
xdotool key Return
|
||||
|
||||
# Get result, kill xvfb
|
||||
wait ${RPID}
|
||||
RETV=$?
|
||||
OUTPUT=$(cat output.txt)
|
||||
if [ "${OUTPUT}" != 'nooty' ]
|
||||
then
|
||||
echo "Got: '${OUTPUT}' expected 'nooty'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit ${RETV}
|
Loading…
Reference in a new issue