2019-12-04 01:48:55 +06:00
|
|
|
/* Copyright 2019 Jack Humbert
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "process_magic.h"
|
2023-07-11 13:07:24 +06:00
|
|
|
#include "keycode_config.h"
|
|
|
|
#include "keycodes.h"
|
|
|
|
#include "eeconfig.h"
|
2019-12-04 01:48:55 +06:00
|
|
|
|
|
|
|
#ifdef AUDIO_ENABLE
|
2023-07-11 13:07:24 +06:00
|
|
|
# include "audio.h"
|
|
|
|
|
2019-12-04 01:48:55 +06:00
|
|
|
# ifndef AG_NORM_SONG
|
|
|
|
# define AG_NORM_SONG SONG(AG_NORM_SOUND)
|
|
|
|
# endif
|
|
|
|
# ifndef AG_SWAP_SONG
|
|
|
|
# define AG_SWAP_SONG SONG(AG_SWAP_SOUND)
|
|
|
|
# endif
|
|
|
|
# ifndef CG_NORM_SONG
|
|
|
|
# define CG_NORM_SONG SONG(AG_NORM_SOUND)
|
|
|
|
# endif
|
|
|
|
# ifndef CG_SWAP_SONG
|
|
|
|
# define CG_SWAP_SONG SONG(AG_SWAP_SOUND)
|
|
|
|
# endif
|
|
|
|
float ag_norm_song[][2] = AG_NORM_SONG;
|
|
|
|
float ag_swap_song[][2] = AG_SWAP_SONG;
|
|
|
|
float cg_norm_song[][2] = CG_NORM_SONG;
|
|
|
|
float cg_swap_song[][2] = CG_SWAP_SONG;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MAGIC actions (BOOTMAGIC without the boot)
|
|
|
|
*/
|
|
|
|
bool process_magic(uint16_t keycode, keyrecord_t *record) {
|
|
|
|
// skip anything that isn't a keyup
|
2019-12-12 01:39:30 +06:00
|
|
|
if (record->event.pressed) {
|
2022-11-05 16:30:09 +06:00
|
|
|
if (IS_MAGIC_KEYCODE(keycode)) {
|
|
|
|
/* keymap config */
|
|
|
|
keymap_config.raw = eeconfig_read_keymap();
|
|
|
|
switch (keycode) {
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_SWAP_CONTROL_CAPS_LOCK:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_control_capslock = true;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_SWAP_ESCAPE_CAPS_LOCK:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_escape_capslock = true;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_CAPS_LOCK_AS_CONTROL_ON:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.capslock_to_control = true;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_SWAP_LALT_LGUI:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_lalt_lgui = true;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_SWAP_RALT_RGUI:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_ralt_rgui = true;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_SWAP_LCTL_LGUI:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_lctl_lgui = true;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_SWAP_RCTL_RGUI:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_rctl_rgui = true;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_GUI_OFF:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.no_gui = true;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_SWAP_GRAVE_ESC:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_grave_esc = true;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_SWAP_BACKSLASH_BACKSPACE:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_backslash_backspace = true;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_NKRO_ON:
|
2022-11-05 16:30:09 +06:00
|
|
|
clear_keyboard(); // clear first buffer to prevent stuck keys
|
|
|
|
keymap_config.nkro = true;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_SWAP_ALT_GUI:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = true;
|
2019-12-04 01:48:55 +06:00
|
|
|
#ifdef AUDIO_ENABLE
|
2022-11-05 16:30:09 +06:00
|
|
|
PLAY_SONG(ag_swap_song);
|
2019-12-04 01:48:55 +06:00
|
|
|
#endif
|
2022-11-05 16:30:09 +06:00
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_SWAP_CTL_GUI:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = true;
|
2019-12-04 01:48:55 +06:00
|
|
|
#ifdef AUDIO_ENABLE
|
2022-11-05 16:30:09 +06:00
|
|
|
PLAY_SONG(cg_swap_song);
|
2019-12-04 01:48:55 +06:00
|
|
|
#endif
|
2022-11-05 16:30:09 +06:00
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_UNSWAP_CONTROL_CAPS_LOCK:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_control_capslock = false;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_UNSWAP_ESCAPE_CAPS_LOCK:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_escape_capslock = false;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_CAPS_LOCK_AS_CONTROL_OFF:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.capslock_to_control = false;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_UNSWAP_LALT_LGUI:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_lalt_lgui = false;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_UNSWAP_RALT_RGUI:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_ralt_rgui = false;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_UNSWAP_LCTL_LGUI:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_lctl_lgui = false;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_UNSWAP_RCTL_RGUI:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_rctl_rgui = false;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_GUI_ON:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.no_gui = false;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_UNSWAP_GRAVE_ESC:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_grave_esc = false;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_UNSWAP_BACKSLASH_BACKSPACE:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_backslash_backspace = false;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_NKRO_OFF:
|
2022-11-05 16:30:09 +06:00
|
|
|
clear_keyboard(); // clear first buffer to prevent stuck keys
|
|
|
|
keymap_config.nkro = false;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_UNSWAP_ALT_GUI:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = false;
|
2019-12-04 01:48:55 +06:00
|
|
|
#ifdef AUDIO_ENABLE
|
2022-11-05 16:30:09 +06:00
|
|
|
PLAY_SONG(ag_norm_song);
|
2019-12-04 01:48:55 +06:00
|
|
|
#endif
|
2022-11-05 16:30:09 +06:00
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_UNSWAP_CTL_GUI:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = false;
|
2019-12-04 01:48:55 +06:00
|
|
|
#ifdef AUDIO_ENABLE
|
2022-11-05 16:30:09 +06:00
|
|
|
PLAY_SONG(cg_norm_song);
|
2019-12-04 01:48:55 +06:00
|
|
|
#endif
|
2022-11-05 16:30:09 +06:00
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_TOGGLE_ALT_GUI:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
|
|
|
|
keymap_config.swap_ralt_rgui = keymap_config.swap_lalt_lgui;
|
2019-12-04 01:48:55 +06:00
|
|
|
#ifdef AUDIO_ENABLE
|
2022-11-05 16:30:09 +06:00
|
|
|
if (keymap_config.swap_ralt_rgui) {
|
|
|
|
PLAY_SONG(ag_swap_song);
|
|
|
|
} else {
|
|
|
|
PLAY_SONG(ag_norm_song);
|
|
|
|
}
|
2019-12-04 01:48:55 +06:00
|
|
|
#endif
|
2022-11-05 16:30:09 +06:00
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_TOGGLE_CTL_GUI:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_lctl_lgui = !keymap_config.swap_lctl_lgui;
|
|
|
|
keymap_config.swap_rctl_rgui = keymap_config.swap_lctl_lgui;
|
2019-12-04 01:48:55 +06:00
|
|
|
#ifdef AUDIO_ENABLE
|
2022-11-05 16:30:09 +06:00
|
|
|
if (keymap_config.swap_rctl_rgui) {
|
|
|
|
PLAY_SONG(cg_swap_song);
|
|
|
|
} else {
|
|
|
|
PLAY_SONG(cg_norm_song);
|
|
|
|
}
|
2019-12-04 01:48:55 +06:00
|
|
|
#endif
|
2022-11-05 16:30:09 +06:00
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_TOGGLE_BACKSLASH_BACKSPACE:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_TOGGLE_NKRO:
|
2022-11-05 16:30:09 +06:00
|
|
|
clear_keyboard(); // clear first buffer to prevent stuck keys
|
|
|
|
keymap_config.nkro = !keymap_config.nkro;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_EE_HANDS_LEFT:
|
2022-11-05 16:30:09 +06:00
|
|
|
eeconfig_update_handedness(true);
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_EE_HANDS_RIGHT:
|
2022-11-05 16:30:09 +06:00
|
|
|
eeconfig_update_handedness(false);
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_TOGGLE_GUI:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.no_gui = !keymap_config.no_gui;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_TOGGLE_CONTROL_CAPS_LOCK:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
|
|
|
|
break;
|
2023-02-23 03:14:29 +06:00
|
|
|
case QK_MAGIC_TOGGLE_ESCAPE_CAPS_LOCK:
|
2022-11-05 16:30:09 +06:00
|
|
|
keymap_config.swap_escape_capslock = !keymap_config.swap_escape_capslock;
|
|
|
|
break;
|
|
|
|
}
|
2019-12-04 01:48:55 +06:00
|
|
|
|
2022-11-05 16:30:09 +06:00
|
|
|
eeconfig_update_keymap(keymap_config.raw);
|
|
|
|
clear_keyboard(); // clear to prevent stuck keys
|
2019-12-12 01:39:30 +06:00
|
|
|
|
2022-11-05 16:30:09 +06:00
|
|
|
return false;
|
2019-12-12 01:39:30 +06:00
|
|
|
}
|
|
|
|
}
|
2019-12-04 01:48:55 +06:00
|
|
|
|
2019-12-12 01:39:30 +06:00
|
|
|
// Not a magic keycode so continue processing
|
|
|
|
return true;
|
2019-12-04 01:48:55 +06:00
|
|
|
}
|