Skip to content

Commit

Permalink
Create Autocorrect Indicator
Browse files Browse the repository at this point in the history
Clear some crap code into seperate c files
  • Loading branch information
plodah committed Aug 14, 2024
1 parent 64b14c5 commit 4e18a72
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 126 deletions.
31 changes: 31 additions & 0 deletions users/plodah/functions/alttab_enhancements.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
bool is_alt_tab_active = false;
uint16_t alt_tab_timer = 0;

#ifndef PLODAH_ALT_TAB_DELAY
# define PLODAH_ALT_TAB_DELAY 1000
#endif //PLODAH_ALT_TAB_DELAY

void alt_tab_fw(void) {
if (!is_alt_tab_active) {
is_alt_tab_active = true;
register_code(KC_LALT);
}
alt_tab_timer = timer_read();
tap_code16(KC_TAB);
}
void alt_tab_bk(void) {
if (!is_alt_tab_active) {
is_alt_tab_active = true;
register_code(KC_LALT);
}
alt_tab_timer = timer_read();
tap_code16(S(KC_TAB));
}
void plodah_alttab_check(void) {
if (is_alt_tab_active) {
if (timer_elapsed(alt_tab_timer) > PLODAH_ALT_TAB_DELAY) {
unregister_code(KC_LALT);
is_alt_tab_active = false;
}
}
}
30 changes: 30 additions & 0 deletions users/plodah/functions/autocorrect_indicator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
bool is_autocorrect_indicator_active = false;
uint16_t autocorrect_indicator_timer = 0;

#ifndef PLODAH_AUTOCORRECT_INDICATOR_DURATION
# define PLODAH_AUTOCORRECT_INDICATOR_DURATION 600
#endif //PLODAH_AUTOCORRECT_INDICATOR_DURATION

#ifndef PLODAH_AUTOCORRECT_INDICATOR_COLOUR
# define PLODAH_AUTOCORRECT_INDICATOR_COLOUR HSV_RED
#endif //PLODAH_AUTOCORRECT_INDICATOR_COLOUR

void plodah_autocorrect_indicator_start(void) {
if (!is_autocorrect_indicator_active) {
is_autocorrect_indicator_active = true;
HSV curhsv = rgb_matrix_get_hsv();
HSV indhsv = { PLODAH_AUTOCORRECT_INDICATOR_COLOUR };
rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_COLOR);
rgb_matrix_sethsv_noeeprom(indhsv.h, indhsv.s, curhsv.v);
}
autocorrect_indicator_timer = timer_read();
}

void plodah_autocorrect_indicator_check(void) {
if (is_autocorrect_indicator_active) {
if (timer_elapsed(autocorrect_indicator_timer) > PLODAH_AUTOCORRECT_INDICATOR_DURATION) {
rgb_matrix_reload_from_eeprom();
is_autocorrect_indicator_active = false;
}
}
}
4 changes: 4 additions & 0 deletions users/plodah/functions/indicators.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#ifndef PLODAH_MODS_INDIC_RGB
# define PLODAH_MODS_INDIC_RGB RGB_RED
#endif

bool plodah_indicator_handler(void) {
# ifdef CAPS_LOCK_LED_INDEX
if (host_keyboard_led_state().caps_lock) {
Expand Down
43 changes: 22 additions & 21 deletions users/plodah/functions/ragequit.c
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
#pragma once

void rage_quit_fin_act(int count){
if (count >= 5) {
if(IS_LAYER_ON(PLODAH_BORING_LAYER)) {
SEND_STRING("Cool.");
layer_move(0);
}
else {
SEND_STRING("I'm sorry!");
layer_move(PLODAH_BORING_LAYER);
}
void rage_quit_fin(tap_dance_state_t *state, void *user_data){
if(state->count >= 5){
if(IS_LAYER_ON(PLODAH_BORING_LAYER)){
SEND_STRING("Cool.");
layer_move(0);
}
else{
if(count >= 3) {
SEND_STRING("Nearies");
}
else{
register_code(KC_ESC);
}
SEND_STRING("I'm sorry!");
layer_move(PLODAH_BORING_LAYER);
}
}
void rage_quit_rst_act(int count){
if(count < 3) {
unregister_code(KC_ESC);
}
else{
if(state->count >= 3){
SEND_STRING("Nearies");
}
}
else{
register_code(KC_ESC);
}
}
};

void rage_quit_rst(tap_dance_state_t *state, void *user_data){
if(state->count < 3){
unregister_code(KC_ESC);
}
};
195 changes: 90 additions & 105 deletions users/plodah/plodah.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,146 +2,131 @@
#include "plodah.h"
#include "quantum.h"

#if defined(PLODAH_KNOB_ENHANCEMENTS_ENABLE) && (! defined(PLODAH_ALTTAB_ENHANCEMENTS_ENABLE))
# define PLODAH_ALTTAB_ENHANCEMENTS_ENABLE
#endif // PLODAH_ALTTAB_ENHANCEMENTS_ENABLE

#if defined(PLODAH_ALTTAB_ENHANCEMENTS_ENABLE)
bool is_alt_tab_active = false;
uint16_t alt_tab_timer = 0;
#endif // PLODAH_ALTTAB_ENHANCEMENTS_ENABLE

//====================//
// MOD VARS //
//====================//
#if defined(PLODAH_KNOB_ENHANCEMENTS_ENABLE) || defined(PLODAH_MODS_INDIC_LALT_INDEX) || defined(PLODAH_MODS_INDIC_RALT_INDEX)
bool alt_pressed = false;
bool alt_pressed = false;
#endif // PLODAH_KNOB_ENHANCEMENTS_ENABLE
#if defined(PLODAH_KNOB_ENHANCEMENTS_ENABLE) || defined(PLODAH_MODS_INDIC_LCTL_INDEX) || defined(PLODAH_MODS_INDIC_RCTL_INDEX)
bool ctl_pressed = false;
bool ctl_pressed = false;
#endif // PLODAH_KNOB_ENHANCEMENTS_ENABLE
#if defined(PLODAH_KNOB_ENHANCEMENTS_ENABLE) || defined(PLODAH_MODS_INDIC_LSHIFT_INDEX) || defined(PLODAH_MODS_INDIC_RSHIFT_INDEX)
bool sft_pressed = false;
bool sft_pressed = false;
#endif // PLODAH_KNOB_ENHANCEMENTS_ENABLE
#if defined CAPS_WORD_ENABLE
bool sft_held = false;
#endif
bool sft_held = false;
#endif // CAPS_WORD_ENABLE

//===========================//
// TAPDANCE //
//===========================//
#if ! defined(PLODAH_BORING_LAYER)
# define PLODAH_BORING_LAYER (-1)
#endif
//===================//
// ALT TAB //
//===================//
#if defined(PLODAH_KNOB_ENHANCEMENTS_ENABLE) && (! defined(PLODAH_ALTTAB_ENHANCEMENTS_ENABLE))
# define PLODAH_ALTTAB_ENHANCEMENTS_ENABLE
#endif // PLODAH_ALTTAB_ENHANCEMENTS_ENABLE
#if defined(PLODAH_ALTTAB_ENHANCEMENTS_ENABLE)
# include "functions/alttab_enhancements.c"
#endif // PLODAH_ALTTAB_ENHANCEMENTS_ENABLE

//=======================//
// AUTOCORRECT //
//=======================//
#if defined(AUTOCORRECT_ENABLE)
# include "functions/autocorrect_indicator.c"
#endif // AUTOCORRECT_ENABLE

#if PLODAH_BORING_LAYER > 0 && defined(TAP_DANCE_ENABLE)
#include "functions/ragequit.c"
void rage_quit_fin(tap_dance_state_t *state, void *user_data) {
rage_quit_fin_act(state->count);
};
void rage_quit_rst(tap_dance_state_t *state, void *user_data) {
rage_quit_rst_act(state->count);
};
tap_dance_action_t tap_dance_actions[] = {
//====================//
// TAPDANCE //
//====================//
#if defined(PLODAH_BORING_LAYER) && defined(TAP_DANCE_ENABLE)
# include "functions/ragequit.c"
tap_dance_action_t tap_dance_actions[] = {
[TD_ESC_RAGEQUIT] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, rage_quit_fin, rage_quit_rst)
};
};
#endif

//===========================//
// ALT TAB //
//===========================//
#if defined(PLODAH_ALTTAB_ENHANCEMENTS_ENABLE)
void alt_tab_fw(void) {
if (!is_alt_tab_active) {
is_alt_tab_active = true;
register_code(KC_LALT);
}
alt_tab_timer = timer_read();
tap_code16(KC_TAB);
}
void alt_tab_bk(void) {
if (!is_alt_tab_active) {
is_alt_tab_active = true;
register_code(KC_LALT);
}
alt_tab_timer = timer_read();
tap_code16(S(KC_TAB));
}
#endif // PLODAH_ALTTAB_ENHANCEMENTS_ENABLE

//===========================//
// CUSTOM KEYCODES //
// CUSTOM KEYCODES //
//===========================//
#if defined PLODAH_KNOB_ENHANCEMENTS_ENABLE
#include "functions/mods_on_knob.c"
# include "functions/mods_on_knob.c"
#endif // PLODAH_KNOB_ENHANCEMENTS_ENABLE
#include "functions/kc_handler.c"
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return kc_handler(keycode, record);
return kc_handler(keycode, record);
}

//===========================//
// ALT TAB //
//===========================//
#if defined(PLODAH_ALTTAB_ENHANCEMENTS_ENABLE)
# ifndef PLODAH_ALT_TAB_DELAY
# define PLODAH_ALT_TAB_DELAY 1000
# endif
void matrix_scan_user(void) { // The very important timer.
if (is_alt_tab_active) {
if (timer_elapsed(alt_tab_timer) > PLODAH_ALT_TAB_DELAY) {
unregister_code(KC_LALT);
is_alt_tab_active = false;
}
}
}
#endif // PLODAH_ALTTAB_ENHANCEMENTS_ENABLE

//===========================//
// COMBOS //
//===========================//
//==================//
// COMBOS //
//==================//
#if defined(COMBO_ENABLE)
#include "functions/combos.c"
# include "functions/combos.c"
#endif // COMBO_ENABLE

//===========================//
// KEYCHRON DIPSWITCH //
//===========================//
//==============================//
// KEYCHRON DIPSWITCH //
//==============================//
#if PLODAH_BORING_LAYER > 0 && defined(DIP_SWITCH_ENABLE)
bool dip_switch_update_user(uint8_t index, bool active) {
bool dip_switch_update_user(uint8_t index, bool active) {
if (index == 0) {
//default_layer_set(active ? PLODAH_BORING_LAYER : 0);
layer_move(active ? PLODAH_BORING_LAYER : 0);
//default_layer_set(active ? PLODAH_BORING_LAYER : 0);
layer_move(active ? PLODAH_BORING_LAYER : 0);
}
return true;
}
}
#endif // DIP_SWITCH_ENABLE

//==================//
// CAPS INDICATOR //
//==================//
//=======================//
// MATRIX SCAN //
//=======================//
void matrix_scan_user(void) {
# if defined(PLODAH_ALTTAB_ENHANCEMENTS_ENABLE)
plodah_alttab_check();
# endif //PLODAH_ALTTAB_ENHANCEMENTS_ENABLE
# if defined(AUTOCORRECT_ENABLE)
plodah_autocorrect_indicator_check();
# endif //AUTOCORRECT_ENABLE
}

//==========================//
// CAPS INDICATOR //
//==========================//
#if defined(RGB_MATRIX_ENABLE)
# ifndef PLODAH_MODS_INDIC_RGB
# define PLODAH_MODS_INDIC_RGB RGB_RED
# endif
#include "functions/indicators.c"
bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
if (!rgb_matrix_indicators_user( )) {
return false;
}
return true;
}
bool rgb_matrix_indicators_user( ) {
return plodah_indicator_handler( );
# include "functions/indicators.c"
bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
if (!rgb_matrix_indicators_user()) {
return false;
}
return true;
}
bool rgb_matrix_indicators_user() {
return plodah_indicator_handler();
}
#endif // RGB_MATRIX_ENABLE

//==================//
// CAPS_WORD //
//==================//
#if defined( CAPS_WORD_ENABLE )
void caps_word_set_user(bool active) {
if (active) {
sft_held = true;
} else {
sft_held = false;
}
#if defined(CAPS_WORD_ENABLE)
void caps_word_set_user(bool active) {
if (active) {
sft_held = true;
} else {
sft_held = false;
}
}
#endif // CAPS_WORD_ENABLE

//=======================//
// AUTOCORRECT //
//=======================//
#if defined(AUTOCORRECT_ENABLE) && defined(RGB_MATRIX_ENABLE)
bool apply_autocorrect(uint8_t backspaces, const char *str, char *typo, char *correct) {
for (uint8_t i = 0; i < backspaces; ++i) {
tap_code(KC_BSPC);
}
send_string_P(str);
plodah_autocorrect_indicator_start();
return false;
}
#endif // AUTOCORRECT_ENABLE && RGB_MATRIX_ENABLE

0 comments on commit 4e18a72

Please sign in to comment.