Skip to content

Commit

Permalink
[OS Detection] Add callback support
Browse files Browse the repository at this point in the history
  • Loading branch information
drashna committed Jan 29, 2024
1 parent 42e6c57 commit 635fb20
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_GRV, _________________RAISE_L1__________________, _________________RAISE_R1__________________, _______,
_______, _________________RAISE_L2__________________, _________________RAISE_R2__________________, KC_BSLS,
_______, _________________RAISE_L3__________________, _________________RAISE_R3__________________, _______,
_______, _______, _______, _______,
STORE_SETUPS, PRINT_SETUPS, _______, _______,
OL_LOCK, _______, _______,
_______, _______, _______,
_______, _______, _______, _______
Expand Down
3 changes: 0 additions & 3 deletions users/drashna/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ void keyboard_post_init_user(void) {
#ifdef CUSTOM_DYNAMIC_MACROS_ENABLE
dynamic_macro_init();
#endif
#if defined(OS_DETECTION_ENABLE) && defined(DEFERRED_EXEC_ENABLE)
defer_exec(100, startup_exec, NULL);
#endif
#ifdef RTC_ENABLE
rtc_init();
#endif
Expand Down
2 changes: 2 additions & 0 deletions users/drashna/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,5 @@
#ifndef EECONFIG_USER_DATA_SIZE
# define EECONFIG_USER_DATA_SIZE 8
#endif

#define OS_DETECTION_DEBUG_ENABLE
80 changes: 36 additions & 44 deletions users/drashna/drashna.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,57 +211,49 @@ void format_layer_bitmap_string(char *buffer, layer_state_t state, layer_state_t
}

#if defined(OS_DETECTION_ENABLE) && defined(DEFERRED_EXEC_ENABLE)
os_variant_t os_type;

uint32_t startup_exec(uint32_t trigger_time, void *cb_arg) {
bool process_detected_host_os_user(os_variant_t detected_os) {
if (is_keyboard_master()) {
os_type = detected_host_os();
if (os_type) {
bool is_mac = (os_type == OS_MACOS) || (os_type == OS_IOS);
if (keymap_config.swap_lctl_lgui != is_mac) {
keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = is_mac;
eeconfig_update_keymap(keymap_config.raw);
}
bool is_mac = (detected_os == OS_MACOS) || (detected_os == OS_IOS);
if (keymap_config.swap_lctl_lgui != is_mac) {
keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = is_mac;
eeconfig_update_keymap(keymap_config.raw);
}
# ifdef UNICODE_COMMON_ENABLE
set_unicode_input_mode_soft(keymap_config.swap_lctl_lgui ? UNICODE_MODE_MACOS : UNICODE_MODE_WINCOMPOSE);
# endif
switch (os_type) {
case OS_UNSURE:
xprintf("unknown OS Detected\n");
break;
case OS_LINUX:
xprintf("Linux Detected\n");
break;
case OS_WINDOWS:
xprintf("Windows Detected\n");
break;
# if 0
case OS_WINDOWS_UNSURE:
xprintf("Windows? Detected\n");
break;
set_unicode_input_mode_soft(keymap_config.swap_lctl_lgui ? UNICODE_MODE_MACOS : UNICODE_MODE_WINCOMPOSE);
# endif
case OS_MACOS:
xprintf("MacOS Detected\n");
break;
case OS_IOS:
xprintf("iOS Detected\n");
break;
# if 0
case OS_PS5:
xprintf("PlayStation 5 Detected\n");
break;
case OS_HANDHELD:
xprintf("Nintend Switch/Quest 2 Detected\n");
break;
# endif
default:
xprintf("Unknown OS Detected\n");
break;
}
switch (detected_os) {
case OS_UNSURE:
xprintf("unknown OS Detected\n");
break;
case OS_LINUX:
xprintf("Linux Detected\n");
break;
case OS_WINDOWS:
xprintf("Windows Detected\n");
break;
case OS_WINDOWS_UNSURE:
xprintf("Windows? Detected\n");
break;
case OS_MACOS:
xprintf("MacOS Detected\n");
break;
case OS_IOS:
xprintf("iOS Detected\n");
break;
case OS_PS5:
xprintf("PlayStation 5 Detected\n");
break;
case OS_HANDHELD:
xprintf("Nintend Switch/Quest 2 Detected\n");
break;
default:
xprintf("Unknown OS Detected\n");
break;
}
}

return os_type ? 0 : 500;
return true;
}
#endif

Expand Down
2 changes: 0 additions & 2 deletions users/drashna/oled/oled_stuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,6 @@ void render_os(uint8_t col, uint8_t line) {
case OS_IOS:
oled_write_ln_P(PSTR("iOS"), false);
break;
# if 0
case OS_WINDOWS_UNSURE:
oled_write_ln_P(PSTR("Windows?"), false);
break;
Expand All @@ -961,7 +960,6 @@ void render_os(uint8_t col, uint8_t line) {
case OS_HANDHELD:
oled_write_ln_P(PSTR("Handheld"), false);
break;
# endif
case OS_UNSURE:
oled_write_ln_P(PSTR("Unsure"), false);
break;
Expand Down

0 comments on commit 635fb20

Please sign in to comment.