aboutsummaryrefslogtreecommitdiff
path: root/common/action.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/action.c')
-rw-r--r--common/action.c378
1 files changed, 68 insertions, 310 deletions
diff --git a/common/action.c b/common/action.c
index 07a3a64d6..065188744 100644
--- a/common/action.c
+++ b/common/action.c
@@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21#include "command.h" 21#include "command.h"
22#include "debug.h" 22#include "debug.h"
23#include "led.h" 23#include "led.h"
24#include "layer_switch.h" 24#include "action_layer.h"
25#include "action_tapping.h" 25#include "action_tapping.h"
26#include "action_oneshot.h" 26#include "action_oneshot.h"
27#include "action_macro.h" 27#include "action_macro.h"
@@ -50,15 +50,19 @@ void action_exec(keyevent_t event)
50void process_action(keyrecord_t *record) 50void process_action(keyrecord_t *record)
51{ 51{
52 keyevent_t event = record->event; 52 keyevent_t event = record->event;
53#ifndef NO_ACTION_TAPPING
53 uint8_t tap_count = record->tap.count; 54 uint8_t tap_count = record->tap.count;
55#endif
54 56
55 if (IS_NOEVENT(event)) { return; } 57 if (IS_NOEVENT(event)) { return; }
56 58
57 action_t action = layer_switch_get_action(event.key); 59 action_t action = layer_switch_get_action(event.key);
58 debug("ACTION: "); debug_action(action); 60 debug("ACTION: "); debug_action(action);
59 debug(" overlays: "); overlay_debug(); 61#ifndef NO_ACTION_LAYER
60 debug(" keymaps: "); keymap_debug(); 62 debug(" layer_state: "); layer_debug();
61 debug(" default_layer: "); debug_dec(default_layer); debug("\n"); 63 debug(" default_layer_state: "); default_layer_debug();
64#endif
65 debug("\n");
62 66
63 switch (action.kind.id) { 67 switch (action.kind.id) {
64 /* Key and Mods */ 68 /* Key and Mods */
@@ -68,22 +72,17 @@ void process_action(keyrecord_t *record)
68 uint8_t mods = (action.kind.id == ACT_LMODS) ? action.key.mods : 72 uint8_t mods = (action.kind.id == ACT_LMODS) ? action.key.mods :
69 action.key.mods<<4; 73 action.key.mods<<4;
70 if (event.pressed) { 74 if (event.pressed) {
71 uint8_t tmp_mods = host_get_mods();
72 if (mods) { 75 if (mods) {
73 host_add_mods(mods); 76 host_add_mods(mods);
74 host_send_keyboard_report(); 77 host_send_keyboard_report();
75 } 78 }
76 register_code(action.key.code); 79 register_code(action.key.code);
77 if (mods && action.key.code) {
78 host_set_mods(tmp_mods);
79 host_send_keyboard_report();
80 }
81 } else { 80 } else {
82 if (mods && !action.key.code) { 81 unregister_code(action.key.code);
82 if (mods) {
83 host_del_mods(mods); 83 host_del_mods(mods);
84 host_send_keyboard_report(); 84 host_send_keyboard_report();
85 } 85 }
86 unregister_code(action.key.code);
87 } 86 }
88 } 87 }
89 break; 88 break;
@@ -93,7 +92,7 @@ void process_action(keyrecord_t *record)
93 { 92 {
94 uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods : 93 uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods :
95 action.key.mods<<4; 94 action.key.mods<<4;
96 switch (action.layer.code) { 95 switch (action.layer_tap.code) {
97 #ifndef NO_ACTION_ONESHOT 96 #ifndef NO_ACTION_ONESHOT
98 case 0x00: 97 case 0x00:
99 // Oneshot modifier 98 // Oneshot modifier
@@ -199,323 +198,88 @@ void process_action(keyrecord_t *record)
199 } 198 }
200 break; 199 break;
201#endif 200#endif
202#ifndef NO_ACTION_KEYMAP 201#ifndef NO_ACTION_LAYER
203 case ACT_KEYMAP: 202 case ACT_LAYER:
204 switch (action.layer.code) { 203 if (action.layer_bitop.on == 0) {
205 /* Keymap clear */ 204 /* Default Layer Bitwise Operation */
206 case OP_RESET: 205 if (!event.pressed) {
207 switch (action.layer.val & 0x03) { 206 uint8_t shift = action.layer_bitop.part*4;
208 case 0: 207 uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift;
209 // NOTE: reserved 208 uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0;
210 overlay_clear(); 209 switch (action.layer_bitop.op) {
211 keymap_clear(); 210 case OP_BIT_AND: default_layer_and(bits | mask); break;
212 break; 211 case OP_BIT_OR: default_layer_or(bits | mask); break;
213 case ON_PRESS: 212 case OP_BIT_XOR: default_layer_xor(bits | mask); break;
214 if (event.pressed) { 213 case OP_BIT_SET: default_layer_and(mask); default_layer_or(bits); break;
215 overlay_clear();
216 keymap_clear();
217 }
218 break;
219 case ON_RELEASE:
220 if (!event.pressed) {
221 overlay_clear();
222 keymap_clear();
223 }
224 break;
225 case ON_BOTH:
226 overlay_clear();
227 keymap_clear();
228 break;
229 /* NOTE: 4-7 rserved */
230 } 214 }
231 break; 215 }
232 /* Keymap Reset default layer */ 216 } else {
233 case (OP_RESET | ON_PRESS): 217 /* Layer Bitwise Operation */
234 if (event.pressed) { 218 if (event.pressed ? (action.layer_bitop.on & ON_PRESS) :
235 default_layer_set(action.layer.val); 219 (action.layer_bitop.on & ON_RELEASE)) {
236 } 220 uint8_t shift = action.layer_bitop.part*4;
237 break; 221 uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift;
238 case (OP_RESET | ON_RELEASE): 222 uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0;
239 if (!event.pressed) { 223 switch (action.layer_bitop.op) {
240 default_layer_set(action.layer.val); 224 case OP_BIT_AND: layer_and(bits | mask); break;
225 case OP_BIT_OR: layer_or(bits | mask); break;
226 case OP_BIT_XOR: layer_xor(bits | mask); break;
227 case OP_BIT_SET: layer_and(mask); layer_or(bits); break;
241 } 228 }
242 break; 229 }
243 case (OP_RESET | ON_BOTH): 230 }
244 default_layer_set(action.layer.val); 231 break;
245 break; 232 #ifndef NO_ACTION_TAPPING
246 233 case ACT_LAYER_TAP:
247 /* Keymap Bit invert */ 234 case ACT_LAYER_TAP1:
248 case OP_INV: 235 switch (action.layer_tap.code) {
249 /* with tap toggle */ 236 case OP_TAP_TOGGLE:
237 /* tap toggle */
250 if (event.pressed) { 238 if (event.pressed) {
251 if (tap_count < TAPPING_TOGGLE) { 239 if (tap_count < TAPPING_TOGGLE) {
252 debug("KEYMAP_INV: tap toggle(press).\n"); 240 layer_invert(action.layer_tap.val);
253 keymap_invert(action.layer.val);
254 } 241 }
255 } else { 242 } else {
256 if (tap_count <= TAPPING_TOGGLE) { 243 if (tap_count <= TAPPING_TOGGLE) {
257 debug("KEYMAP_INV: tap toggle(release).\n"); 244 layer_invert(action.layer_tap.val);
258 keymap_invert(action.layer.val);
259 } 245 }
260 } 246 }
261 break; 247 break;
262 case (OP_INV | ON_PRESS): 248 case OP_ON_OFF:
263 if (event.pressed) { 249 event.pressed ? layer_on(action.layer_tap.val) :
264 keymap_invert(action.layer.val); 250 layer_off(action.layer_tap.val);
265 }
266 break;
267 case (OP_INV | ON_RELEASE):
268 if (!event.pressed) {
269 keymap_invert(action.layer.val);
270 }
271 break; 251 break;
272 case (OP_INV | ON_BOTH): 252 case OP_OFF_ON:
273 keymap_invert(action.layer.val); 253 event.pressed ? layer_off(action.layer_tap.val) :
254 layer_on(action.layer_tap.val);
274 break; 255 break;
275 256 case OP_SET_CLEAR:
276 /* Keymap Bit on */ 257 event.pressed ? layer_move(action.layer_tap.val) :
277 case OP_ON: 258 layer_clear();
278 if (event.pressed) {
279 keymap_on(action.layer.val);
280 } else {
281 keymap_off(action.layer.val);
282 }
283 break;
284 case (OP_ON | ON_PRESS):
285 if (event.pressed) {
286 keymap_on(action.layer.val);
287 }
288 break;
289 case (OP_ON | ON_RELEASE):
290 if (!event.pressed) {
291 keymap_on(action.layer.val);
292 }
293 break; 259 break;
294 case (OP_ON | ON_BOTH):
295 keymap_on(action.layer.val);
296 break;
297
298 /* Keymap Bit off */
299 case OP_OFF:
300 if (event.pressed) {
301 keymap_off(action.layer.val);
302 } else {
303 keymap_on(action.layer.val);
304 }
305 break;
306 case (OP_OFF | ON_PRESS):
307 if (event.pressed) {
308 keymap_off(action.layer.val);
309 }
310 break;
311 case (OP_OFF | ON_RELEASE):
312 if (!event.pressed) {
313 keymap_off(action.layer.val);
314 }
315 break;
316 case (OP_OFF | ON_BOTH):
317 keymap_off(action.layer.val);
318 break;
319
320 /* Keymap Bit set */
321 case OP_SET:
322 if (event.pressed) {
323 keymap_set(action.layer.val);
324 } else {
325 keymap_clear();
326 }
327 break;
328 case (OP_SET | ON_PRESS):
329 if (event.pressed) {
330 keymap_set(action.layer.val);
331 }
332 break;
333 case (OP_SET | ON_RELEASE):
334 if (!event.pressed) {
335 keymap_set(action.layer.val);
336 }
337 break;
338 case (OP_SET | ON_BOTH):
339 keymap_set(action.layer.val);
340 break;
341
342 /* Keymap Bit invert with tap key */
343 default: 260 default:
261 /* tap key */
344 if (event.pressed) { 262 if (event.pressed) {
345 if (tap_count > 0) { 263 if (tap_count > 0) {
346 debug("KEYMAP_TAP_KEY: Tap: register_code\n"); 264 debug("KEYMAP_TAP_KEY: Tap: register_code\n");
347 register_code(action.layer.code); 265 register_code(action.layer_tap.code);
348 } else { 266 } else {
349 debug("KEYMAP_TAP_KEY: No tap: On on press\n"); 267 debug("KEYMAP_TAP_KEY: No tap: On on press\n");
350 keymap_on(action.layer.val); 268 layer_on(action.layer_tap.val);
351 } 269 }
352 } else { 270 } else {
353 if (tap_count > 0) { 271 if (tap_count > 0) {
354 debug("KEYMAP_TAP_KEY: Tap: unregister_code\n"); 272 debug("KEYMAP_TAP_KEY: Tap: unregister_code\n");
355 unregister_code(action.layer.code); 273 unregister_code(action.layer_tap.code);
356 } else { 274 } else {
357 debug("KEYMAP_TAP_KEY: No tap: Off on release\n"); 275 debug("KEYMAP_TAP_KEY: No tap: Off on release\n");
358 keymap_off(action.layer.val); 276 layer_off(action.layer_tap.val);
359 }
360 }
361 break;
362 }
363 break;
364#endif
365#ifndef NO_ACTION_OVERLAY
366 case ACT_OVERLAY:
367 switch (action.layer.code) {
368 // Overlay Invert bit4
369 case OP_INV4 | 0:
370 if (action.layer.val == 0) {
371 // NOTE: reserved for future use
372 overlay_clear();
373 } else {
374 overlay_set(overlay_stat ^ action.layer.val);
375 }
376 break;
377 case OP_INV4 | 1:
378 if (action.layer.val == 0) {
379 // on pressed
380 if (event.pressed) overlay_clear();
381 } else {
382 overlay_set(overlay_stat ^ action.layer.val<<4);
383 }
384 break;
385 case OP_INV4 | 2:
386 if (action.layer.val == 0) {
387 // on released
388 if (!event.pressed) overlay_clear();
389 } else {
390 overlay_set(overlay_stat ^ action.layer.val<<8);
391 }
392 break;
393 case OP_INV4 | 3:
394 if (action.layer.val == 0) {
395 // on both
396 overlay_clear();
397 } else {
398 overlay_set(overlay_stat ^ action.layer.val<<12);
399 }
400 break;
401
402 /* Overlay Bit invert */
403 case OP_INV:
404 /* with tap toggle */
405 if (event.pressed) {
406 if (tap_count < TAPPING_TOGGLE) {
407 debug("OVERLAY_INV: tap toggle(press).\n");
408 overlay_invert(action.layer.val);
409 }
410 } else {
411 if (tap_count <= TAPPING_TOGGLE) {
412 debug("OVERLAY_INV: tap toggle(release).\n");
413 overlay_invert(action.layer.val);
414 }
415 }
416 break;
417 case (OP_INV | ON_PRESS):
418 if (event.pressed) {
419 overlay_invert(action.layer.val);
420 }
421 break;
422 case (OP_INV | ON_RELEASE):
423 if (!event.pressed) {
424 overlay_invert(action.layer.val);
425 }
426 break;
427 case (OP_INV | ON_BOTH):
428 overlay_invert(action.layer.val);
429 break;
430
431 /* Overlay Bit on */
432 case OP_ON:
433 if (event.pressed) {
434 overlay_on(action.layer.val);
435 } else {
436 overlay_off(action.layer.val);
437 }
438 break;
439 case (OP_ON | ON_PRESS):
440 if (event.pressed) {
441 overlay_on(action.layer.val);
442 }
443 break;
444 case (OP_ON | ON_RELEASE):
445 if (!event.pressed) {
446 overlay_on(action.layer.val);
447 }
448 break;
449 case (OP_ON | ON_BOTH):
450 overlay_on(action.layer.val);
451 break;
452
453 /* Overlay Bit off */
454 case OP_OFF:
455 if (event.pressed) {
456 overlay_off(action.layer.val);
457 } else {
458 overlay_on(action.layer.val);
459 }
460 break;
461 case (OP_OFF | ON_PRESS):
462 if (event.pressed) {
463 overlay_off(action.layer.val);
464 }
465 break;
466 case (OP_OFF | ON_RELEASE):
467 if (!event.pressed) {
468 overlay_off(action.layer.val);
469 }
470 break;
471 case (OP_OFF | ON_BOTH):
472 overlay_off(action.layer.val);
473 break;
474
475 /* Overlay Bit set */
476 case OP_SET:
477 if (event.pressed) {
478 overlay_move(action.layer.val);
479 } else {
480 overlay_clear();
481 }
482 break;
483 case (OP_SET | ON_PRESS):
484 if (event.pressed) {
485 overlay_move(action.layer.val);
486 }
487 break;
488 case (OP_SET | ON_RELEASE):
489 if (!event.pressed) {
490 overlay_move(action.layer.val);
491 }
492 break;
493 case (OP_SET | ON_BOTH):
494 overlay_move(action.layer.val);
495 break;
496
497 /* Overlay Bit invert with tap key */
498 default:
499 if (event.pressed) {
500 if (tap_count > 0) {
501 debug("OVERLAY_TAP_KEY: Tap: register_code\n");
502 register_code(action.layer.code);
503 } else {
504 debug("OVERLAY_TAP_KEY: No tap: On on press\n");
505 overlay_on(action.layer.val);
506 }
507 } else {
508 if (tap_count > 0) {
509 debug("OVERLAY_TAP_KEY: Tap: unregister_code\n");
510 unregister_code(action.layer.code);
511 } else {
512 debug("OVERLAY_TAP_KEY: No tap: Off on release\n");
513 overlay_off(action.layer.val);
514 } 277 }
515 } 278 }
516 break; 279 break;
517 } 280 }
518 break; 281 break;
282 #endif
519#endif 283#endif
520 /* Extentions */ 284 /* Extentions */
521#ifndef NO_ACTION_MACRO 285#ifndef NO_ACTION_MACRO
@@ -667,16 +431,9 @@ bool is_tap_key(key_t key)
667 switch (action.kind.id) { 431 switch (action.kind.id) {
668 case ACT_LMODS_TAP: 432 case ACT_LMODS_TAP:
669 case ACT_RMODS_TAP: 433 case ACT_RMODS_TAP:
434 case ACT_LAYER_TAP:
435 case ACT_LAYER_TAP1:
670 return true; 436 return true;
671 case ACT_KEYMAP:
672 case ACT_OVERLAY:
673 switch (action.layer.code) {
674 case 0x04 ... 0xEF: /* tap key */
675 case OP_INV:
676 return true;
677 default:
678 return false;
679 }
680 case ACT_MACRO: 437 case ACT_MACRO:
681 case ACT_FUNCTION: 438 case ACT_FUNCTION:
682 if (action.func.opt & FUNC_TAP) { return true; } 439 if (action.func.opt & FUNC_TAP) { return true; }
@@ -714,8 +471,9 @@ void debug_action(action_t action)
714 case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; 471 case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break;
715 case ACT_USAGE: debug("ACT_USAGE"); break; 472 case ACT_USAGE: debug("ACT_USAGE"); break;
716 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; 473 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break;
717 case ACT_KEYMAP: debug("ACT_KEYMAP"); break; 474 case ACT_LAYER: debug("ACT_LAYER"); break;
718 case ACT_OVERLAY: debug("ACT_OVERLAY"); break; 475 case ACT_LAYER_TAP: debug("ACT_LAYER_TAP"); break;
476 case ACT_LAYER_TAP1: debug("ACT_LAYER_TAP1"); break;
719 case ACT_MACRO: debug("ACT_MACRO"); break; 477 case ACT_MACRO: debug("ACT_MACRO"); break;
720 case ACT_COMMAND: debug("ACT_COMMAND"); break; 478 case ACT_COMMAND: debug("ACT_COMMAND"); break;
721 case ACT_FUNCTION: debug("ACT_FUNCTION"); break; 479 case ACT_FUNCTION: debug("ACT_FUNCTION"); break;