-
Notifications
You must be signed in to change notification settings - Fork 10
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
Format unicode_common #13
Changes from 4 commits
ae25652
bcafc3b
e6d9692
871169a
415d12a
fdded5c
09dbc0c
3e22b6a
2c9cfc4
3f7cd36
b55f059
408ec5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,27 +21,6 @@ | |
|
||
unicode_config_t unicode_config; | ||
static uint8_t saved_mods; | ||
#ifdef AUDIO_ENABLE | ||
#ifdef UNICODE_SONG_OSX | ||
float osx_song[][2] = UNICODE_SONG_OSX; | ||
#endif | ||
#ifdef UNICODE_SONG_LNX | ||
float song_lnx[][2] = UNICODE_SONG_LNX; | ||
#endif | ||
#ifdef UNICODE_SONG_BSD | ||
float song_bsd[][2] = UNICODE_SONG_BSD; | ||
#endif | ||
#ifdef UNICODE_SONG_WINDOWS | ||
float windows_song[][2] = UNICODE_SONG_WINDOWS; | ||
#endif | ||
#ifdef UNICODE_SONG_WIN_COMPOSE | ||
float win_compose_song[][2] = UNICODE_SONG_WIN_COMPOSE; | ||
#endif | ||
#ifdef UNICODE_SONG_OSX_RALT | ||
float osx_ralt_song[][2] = UNICODE_SONG_OSX_RALT; | ||
#endif | ||
#endif | ||
|
||
|
||
void set_unicode_input_mode(uint8_t os_target) { | ||
unicode_config.input_mode = os_target; | ||
|
@@ -90,16 +69,16 @@ void unicode_input_start(void) { | |
__attribute__((weak)) | ||
void unicode_input_finish(void) { | ||
switch (unicode_config.input_mode) { | ||
case UC_OSX: | ||
case UC_WIN: | ||
case UC_OSX: | ||
case UC_WIN: | ||
unregister_code(KC_LALT); | ||
break; | ||
case UC_OSX_RALT: | ||
unregister_code(KC_RALT); | ||
break; | ||
case UC_LNX: | ||
tap_code(KC_SPC); | ||
break; | ||
break; | ||
case UC_OSX_RALT: | ||
unregister_code(KC_RALT); | ||
break; | ||
case UC_LNX: | ||
tap_code(KC_SPC); | ||
break; | ||
} | ||
|
||
set_mods(saved_mods); // Reregister previously set mods | ||
|
@@ -148,55 +127,60 @@ void send_unicode_hex_string(const char *str) { | |
} | ||
} | ||
|
||
bool process_record_unicode_common(uint16_t keycode, keyrecord_t *record) { | ||
bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { | ||
if (record->event.pressed) { | ||
switch (keycode) { | ||
case UNICODE_MODE_OSX: | ||
case UNICODE_MODE_OSX: | ||
set_unicode_input_mode(UC_OSX); | ||
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX) | ||
PLAY_SONG(osx_song); | ||
#endif | ||
break; | ||
case UNICODE_MODE_LNX: | ||
set_unicode_input_mode(UC_LNX); | ||
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_LNX) | ||
PLAY_SONG(song_lnx); | ||
#endif | ||
break; | ||
case UNICODE_MODE_BSD: | ||
set_unicode_input_mode(UC_BSD); | ||
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_BSD) | ||
PLAY_SONG(song_bsd); | ||
#endif | ||
break; | ||
case UNICODE_MODE_WIN: | ||
set_unicode_input_mode(UC_WIN); | ||
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINDOWS) | ||
PLAY_SONG(windows_song); | ||
#endif | ||
break; | ||
case UNICODE_MODE_WINC: | ||
set_unicode_input_mode(UC_WINC); | ||
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WIN_COMPOSE) | ||
PLAY_SONG(win_compose_song); | ||
#endif | ||
break; | ||
case UNICODE_MODE_OSX_RALT: | ||
set_unicode_input_mode(UC_OSX_RALT); | ||
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX_RALT) | ||
PLAY_SONG(osx_ralt_song); | ||
#endif | ||
break; | ||
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason why I prefer preprocessor ifs (and preprocessor directives in general) to have their own separate indentation levels is that they aren't part of the program logic. They just pick & choose which parts of the code get compiled and which don't; they aren't runtime checks. Therefore, they shouldn't affect the indentation of the actual code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I definitely understand that. However, .... I think we need a clear and concise rule about this, because you can see three different formats throughout the code. Also, this looks cleaner. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now the tally for preprocessor directives before code in core QMK is:
I agree that there should be a hard rule for it for any new code, as well as for the |
||
static float song_osx[][2] = UNICODE_SONG_OSX; | ||
PLAY_SONG(song_osx); | ||
#endif | ||
break; | ||
case UNICODE_MODE_LNX: | ||
set_unicode_input_mode(UC_LNX); | ||
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_LNX) | ||
static float song_lnx[][2] = UNICODE_SONG_LNX; | ||
PLAY_SONG(song_lnx); | ||
#endif | ||
break; | ||
case UNICODE_MODE_BSD: | ||
set_unicode_input_mode(UC_BSD); | ||
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_BSD) | ||
static float song_bsd[][2] = UNICODE_SONG_BSD; | ||
PLAY_SONG(song_bsd); | ||
#endif | ||
break; | ||
case UNICODE_MODE_WIN: | ||
set_unicode_input_mode(UC_WIN); | ||
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WIN) | ||
static float song_win[][2] = UNICODE_SONG_WIN; | ||
PLAY_SONG(song_win); | ||
#endif | ||
break; | ||
case UNICODE_MODE_WINC: | ||
set_unicode_input_mode(UC_WINC); | ||
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINC) | ||
static float song_winc[][2] = UNICODE_SONG_WINC; | ||
PLAY_SONG(song_winc); | ||
#endif | ||
break; | ||
case UNICODE_MODE_OSX_RALT: | ||
set_unicode_input_mode(UC_OSX_RALT); | ||
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX_RALT) | ||
static float song_osx_ralt[][2] = UNICODE_SONG_OSX_RALT; | ||
PLAY_SONG(song_osx_ralt); | ||
#endif | ||
break; | ||
} | ||
} | ||
#ifdef UNICODE_ENABLE | ||
return process_unicode(keycode, record); | ||
#endif | ||
#ifdef UCIS_ENABLE | ||
return process_ucis(keycode, record); | ||
#endif | ||
#ifdef UNICODEMAP_ENABLE | ||
return process_unicode_map(keycode, record); | ||
#endif | ||
#if defined(UNICODE_ENABLE) | ||
return process_unicode(keycode, record); | ||
#elif defined(UNICODEMAP_ENABLE) | ||
return process_unicode_map(keycode, record); | ||
#elif defined(UCIS_ENABLE) | ||
return process_ucis(keycode, record); | ||
#else | ||
return true; | ||
#endif | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is proper, but I hate it because of the readability (lack thereof)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Assuming you're referring to the
case
indentation) I actually disagree 😄 In QMK's case we have 2-space indents, but in projects where indentation is the standard 4 spaces or a tab, the extra indentation from cases (which bears no semantic meaning, as cases are just jump labels) can harm readability by adding another indentation level and shifting code horizontally.To quote Linus Torvalds: “If you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.”
And I'd rather not waste one of those levels on
case
labels 😄But regardless of what we agree to go with, we should make sure we're consistent with it across all Unicode files:
process_unicode_common.c
,process_unicode.c
,process_unicodemap.c
,process_ucis.c
.