summaryrefslogtreecommitdiffstats
path: root/users/ericgebhart/extensions/alt_shift.c
blob: 002adec2305fe10dab653c8e00c0e76b80dad45f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include USERSPACE_H
#include <stdbool.h>
#include <stdint.h>

bool shift_for_two(uint16_t keycode, keyrecord_t *record){
  uint16_t mod_state = get_mods();

  bool is_shifted = (get_mods() & MOD_MASK_SHIFT) ||
    (get_oneshot_mods() & MOD_MASK_SHIFT);

  if(record ->event.pressed) {
    // If shifted, double these common punctuation marks.
    if(is_shifted){
      // clear shift temporarily
      del_mods(MOD_MASK_SHIFT);
      del_oneshot_mods(MOD_MASK_SHIFT);

      tap_code16(keycode);
      tap_code16(keycode);

      // restore previous shift state
      set_mods(mod_state);
      return false;
    }
  }
  return true;
}

bool shift_for_three(uint16_t keycode, keyrecord_t *record){
  uint16_t mod_state = get_mods();

  bool is_shifted = (get_mods() & MOD_MASK_SHIFT) ||
    (get_oneshot_mods() & MOD_MASK_SHIFT);

  if(record ->event.pressed) {
    // If shifted, double these common punctuation marks.
    if(is_shifted){
      // clear shift temporarily
      del_mods(MOD_MASK_SHIFT);
      del_oneshot_mods(MOD_MASK_SHIFT);

      tap_code16(keycode);
      tap_code16(keycode);
      tap_code16(keycode);

      // restore previous shift state
      set_mods(mod_state);
      return false;
    }
  }
  return true;
  }

bool override_shift(uint16_t keycode,
                    uint16_t shift_keycode,
                    keyrecord_t *record
                    ) {

  bool is_shifted = (get_mods() & MOD_MASK_SHIFT) ||
    (get_oneshot_mods() & MOD_MASK_SHIFT);

  if (record->event.pressed) {
    if (is_shifted) {
      uint8_t mod_state = get_mods();
      del_mods(MOD_MASK_SHIFT);
      del_oneshot_mods(MOD_MASK_SHIFT);

      tap_code16(shift_keycode);

      set_mods(mod_state);
    } else {
      //tap_code16(keycode);
    }
  }
  return false;
}

// macros for use in alt_shift.defs.
#define ALT_SHIFT(KCKEY, KC01)            \
  case KCKEY:                                   \
  return override_shift(KCKEY, KC01, record);   \
  break;

#define SHIFT_FOR_2(KCKEY)                      \
  case KCKEY:                                   \
  return shift_for_two(KCKEY, record);          \
  break;

#define SHIFT_FOR_3(KCKEY)                \
  case KCKEY:                                   \
  return shift_for_three(KCKEY, record);        \
  break;

bool process_alt_shift_user(uint16_t keycode, keyrecord_t *record) {
  switch(keycode){
#include "alt_shift.def"
  }
  return true;
}