Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added non-sensitivity to keyboard layout #994

Open
wants to merge 8 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ SOURCES=\
include/dialogs/filebrowser.h\
include/dialogs/dmenuscriptshared.h\
resources/resources.c\
resources/resources.h
resources/resources.h\
source/keyb-layout.c

rofi_SOURCES=\
lexer/theme-parser.y\
Expand Down Expand Up @@ -355,7 +356,8 @@ helper_pidfile_SOURCES=\
include/helper-theme.h\
include/xrmoptions.h\
source/xrmoptions.c\
test/helper-pidfile.c
test/helper-pidfile.c\
source/keyb-layout.c

widget_test_LDADD=$(textbox_test_LDADD)
widget_test_CFLAGS=$(textbox_test_CFLAGS)
Expand All @@ -370,7 +372,8 @@ widget_test_SOURCES=\
config/config.c\
lexer/theme-parser.y\
lexer/theme-lexer.l\
test/widget-test.c
test/widget-test.c\
source/keyb-layout.c

box_test_LDADD=$(textbox_test_LDADD)
box_test_CFLAGS=$(textbox_test_CFLAGS)
Expand Down Expand Up @@ -426,7 +429,8 @@ textbox_test_SOURCES=\
include/xrmoptions.h\
include/helper.h\
include/helper-theme.h\
test/textbox-test.c
test/textbox-test.c\
source/keyb-layout.c

if USE_CHECK
theme_parser_test_CFLAGS=${helper_test_CFLAGS} $(check_CFLAGS)
Expand All @@ -450,7 +454,8 @@ theme_parser_test_SOURCES=\
source/rofi-types.c\
include/rofi-types.h\
source/css-colors.c\
test/theme-parser-test.c
test/theme-parser-test.c\
source/keyb-layout.c
endif

helper_test_SOURCES=\
Expand All @@ -465,7 +470,8 @@ helper_test_SOURCES=\
source/xrmoptions.c\
source/rofi-types.c\
include/rofi-types.h\
test/helper-test.c
test/helper-test.c\
source/keyb-layout.c


helper_test_CFLAGS=\
Expand Down Expand Up @@ -506,7 +512,8 @@ helper_expand_SOURCES=\
source/xrmoptions.c\
source/rofi-types.c\
include/rofi-types.h\
test/helper-expand.c
test/helper-expand.c\
source/keyb-layout.c

helper_expand_CFLAGS=${helper_test_CFLAGS}

Expand All @@ -527,7 +534,8 @@ helper_config_cmdline_parser_SOURCES=\
include/helper-theme.h\
include/xrmoptions.h\
source/xrmoptions.c\
test/helper-config-cmdline-parser.c
test/helper-config-cmdline-parser.c\
source/keyb-layout.c


if USE_CHECK
Expand All @@ -544,7 +552,8 @@ mode_test_SOURCES=\
source/xrmoptions.c\
source/keyb.c\
include/mode.h\
include/mode-private.h
include/mode-private.h\
source/keyb-layout.c
helper_tokenize_CFLAGS=$(textbox_test_CFLAGS) $(check_CFLAGS)
helper_tokenize_LDADD=$(textbox_test_LDADD) $(check_LIBS)
helper_tokenize_SOURCES=\
Expand All @@ -559,7 +568,8 @@ helper_tokenize_SOURCES=\
include/helper-theme.h\
include/xrmoptions.h\
source/xrmoptions.c\
test/helper-tokenize.c
test/helper-tokenize.c\
source/keyb-layout.c

endif

Expand Down
1 change: 1 addition & 0 deletions doc/rofi.1.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ Current the following methods are supported.
* **regex**: match a regex input
* **glob**: match a glob pattern
* **fuzzy**: do a fuzzy match
* **all_kb_layouts**: normal with non-sensitivity to keyboard layout

Default: *normal*

Expand Down
18 changes: 18 additions & 0 deletions include/keyb.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,23 @@ gboolean parse_keys_abe ( NkBindings *bindings );
*/
void setup_abe ( void );

/**
* Load the charmap from a keymap
*/
void kbl_charmap_load_from_keymap ( struct xkb_keymap *keymap );

/**
* Cleanup the charmap
*/
void kbl_charmap_cleanup ( void );

/**
* Allocate and initialize an input buffer state.
* @param chr character in utf8.
*
* @return the allocated string containing corresponding characters
*/
gchar *kbl_charmap_for_char ( const gchar *chr );

/**@}*/
#endif // ROFI_KEYB_H
9 changes: 5 additions & 4 deletions include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
*/
typedef enum
{
MM_NORMAL = 0,
MM_REGEX = 1,
MM_GLOB = 2,
MM_FUZZY = 3
MM_NORMAL = 0,
MM_REGEX = 1,
MM_GLOB = 2,
MM_FUZZY = 3,
MM_ALL_KB_LAYOUTS = 4
} MatchingMethod;

/**
Expand Down
10 changes: 10 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ rofi_sources = files(
'source/view.c',
'source/mode.c',
'source/keyb.c',
'source/keyb-layout.c',
'config/config.c',
'source/helper.c',
'source/timings.c',
Expand Down Expand Up @@ -299,6 +300,7 @@ test('helper_pidfile test', executable('helper_pidfile.test', [
'source/helper.c',
'source/xrmoptions.c',
'source/rofi-types.c',
'source/keyb-layout.c',
]),
dependencies: deps,
))
Expand All @@ -317,6 +319,7 @@ test('widget test', executable('widget.test', [
'source/css-colors.c',
'source/helper.c',
'config/config.c',
'source/keyb-layout.c',
]),
dependencies: deps,
))
Expand Down Expand Up @@ -366,6 +369,7 @@ test('textbox test', executable('textbox.test', [
'source/css-colors.c',
'source/helper.c',
'config/config.c',
'source/keyb-layout.c',
]),
dependencies: deps,
))
Expand All @@ -378,6 +382,7 @@ test('helper test', executable('helper.test', [
'source/helper.c',
'source/xrmoptions.c',
'source/rofi-types.c',
'source/keyb-layout.c',
]),
dependencies: deps,
))
Expand All @@ -390,6 +395,7 @@ test('helper_expand test', executable('helper_expand.test', [
'source/helper.c',
'source/xrmoptions.c',
'source/rofi-types.c',
'source/keyb-layout.c',
]),
dependencies: deps,
))
Expand All @@ -402,6 +408,7 @@ test('helper_config_cmdline_parser test', executable('helper_config_cmdline_pars
'source/helper.c',
'source/xrmoptions.c',
'source/rofi-types.c',
'source/keyb-layout.c',
]),
dependencies: deps,
))
Expand All @@ -421,6 +428,7 @@ if check.found()
'source/theme.c',
'source/rofi-types.c',
'source/css-colors.c',
'source/keyb-layout.c',
]),
dependencies: deps,
))
Expand All @@ -436,6 +444,7 @@ if check.found()
'source/xrmoptions.c',
'source/rofi-types.c',
'source/keyb.c',
'source/keyb-layout.c',
]),
dependencies: deps,
))
Expand All @@ -448,6 +457,7 @@ if check.found()
'source/helper.c',
'source/xrmoptions.c',
'source/rofi-types.c',
'source/keyb-layout.c',
]),
dependencies: deps,
))
Expand Down
28 changes: 27 additions & 1 deletion source/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "settings.h"
#include "rofi.h"
#include "view.h"
#include "keyb.h"

/**
* Textual description of positioning rofi.
Expand Down Expand Up @@ -178,6 +179,23 @@ static gchar *fuzzy_to_regex ( const char * input )
g_string_free ( str, FALSE );
return retv;
}
static gchar *all_kb_layouts_to_regex ( const char * input )
{
GString *str = g_string_new ( "" );
gchar *iter;
for ( iter = input; iter && *iter != '\0'; iter = g_utf8_next_char ( iter ) ) {
gchar *kblchs = kbl_charmap_for_char ( iter );
gchar *r = g_regex_escape_string ( kblchs, -1 );

g_string_append_printf ( str, "[%s]", r );
g_free ( kblchs );
g_free ( r );
}

gchar *retv = str->str;
g_string_free ( str, FALSE );
return retv;
}

static char *utf8_helper_simplify_string ( const char *s)
{
Expand Down Expand Up @@ -247,6 +265,11 @@ static rofi_int_matcher * create_regex ( const char *input, int case_sensitive )
retv = R ( r, case_sensitive );
g_free ( r );
break;
case MM_ALL_KB_LAYOUTS:
r = all_kb_layouts_to_regex ( input );
retv = R ( r, case_sensitive );
g_free ( r );
break;
default:
r = g_regex_escape_string ( input, -1 );
retv = R ( r, case_sensitive );
Expand Down Expand Up @@ -627,11 +650,14 @@ int config_sanity_check ( void )
else if ( g_strcmp0 ( config.matching, "fuzzy" ) == 0 ) {
config.matching_method = MM_FUZZY;
}
else if ( g_strcmp0 ( config.matching, "all_kb_layouts" ) == 0 ) {
config.matching_method = MM_ALL_KB_LAYOUTS;
}
else if ( g_strcmp0 ( config.matching, "normal" ) == 0 ) {
config.matching_method = MM_NORMAL;;
}
else {
g_string_append_printf ( msg, "\t<b>config.matching</b>=%s is not a valid matching strategy.\nValid options are: glob, regex, fuzzy or normal.\n",
g_string_append_printf ( msg, "\t<b>config.matching</b>=%s is not a valid matching strategy.\nValid options are: glob, regex, fuzzy, all_kb_layouts or normal.\n",
config.matching );
found_error = 1;
}
Expand Down
Loading