aboutsummaryrefslogtreecommitdiff
path: root/common/action.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-02-08 00:50:51 +0900
committertmk <nobody@nowhere>2013-02-10 16:11:07 +0900
commitb2aa142ee0a88ae6c38798f33cf5d833b0ae3864 (patch)
treead4d142929e102d3e18082df877704d81a1c0171 /common/action.c
parentaad91a30a34d61739e1261bb82a1cb1ace581afa (diff)
downloadqmk_firmware-b2aa142ee0a88ae6c38798f33cf5d833b0ae3864.tar.gz
qmk_firmware-b2aa142ee0a88ae6c38798f33cf5d833b0ae3864.zip
Clean layer actions.
Diffstat (limited to 'common/action.c')
-rw-r--r--common/action.c213
1 files changed, 46 insertions, 167 deletions
diff --git a/common/action.c b/common/action.c
index 301a9b6a0..f6e50032e 100644
--- a/common/action.c
+++ b/common/action.c
@@ -319,14 +319,14 @@ static void process_action(keyrecord_t *record)
319 case ACT_USAGE: 319 case ACT_USAGE:
320#ifdef EXTRAKEY_ENABLE 320#ifdef EXTRAKEY_ENABLE
321 switch (action.usage.page) { 321 switch (action.usage.page) {
322 case ACTION_USAGE_PAGE_SYSTEM: 322 case PAGE_SYSTEM:
323 if (event.pressed) { 323 if (event.pressed) {
324 host_system_send(action.usage.code); 324 host_system_send(action.usage.code);
325 } else { 325 } else {
326 host_system_send(0); 326 host_system_send(0);
327 } 327 }
328 break; 328 break;
329 case ACTION_USAGE_PAGE_CONSUMER: 329 case PAGE_CONSUMER:
330 if (event.pressed) { 330 if (event.pressed) {
331 host_consumer_send(action.usage.code); 331 host_consumer_send(action.usage.code);
332 } else { 332 } else {
@@ -351,20 +351,44 @@ static void process_action(keyrecord_t *record)
351 break; 351 break;
352 352
353 /* Layer key */ 353 /* Layer key */
354 case ACT_LAYER_PRESSED: 354 case ACT_LAYER:
355 // layer action when pressed
356 switch (action.layer.code) { 355 switch (action.layer.code) {
357 case 0x00: 356 case LAYER_MOMENTARY: /* momentary */
358 if (event.pressed) { 357 if (event.pressed) {
359 layer_switch(action.layer.val); 358 layer_switch(action.layer.val);
360 } 359 }
361//TODO: this is ok?
362 else { 360 else {
363 layer_switch(default_layer); 361 layer_switch(default_layer);
364 } 362 }
365 break; 363 break;
366 case 0xF0: 364 case LAYER_ON_PRESS:
367 // tap toggle 365 if (event.pressed) {
366 layer_switch(action.layer.val);
367 }
368 break;
369 case LAYER_ON_RELEASE:
370 if (!event.pressed) {
371 layer_switch(action.layer.val);
372 }
373 break;
374 case LAYER_DEFAULT: /* default layer */
375 switch (action.layer.val) {
376 case DEFAULT_ON_BOTH:
377 layer_switch(default_layer);
378 break;
379 case DEFAULT_ON_PRESS:
380 if (event.pressed) {
381 layer_switch(default_layer);
382 }
383 break;
384 case DEFAULT_ON_RELEASE:
385 if (!event.pressed) {
386 layer_switch(default_layer);
387 }
388 break;
389 }
390 break;
391 case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */
368 if (event.pressed) { 392 if (event.pressed) {
369 if (tap_count < TAPPING_TOGGLE) { 393 if (tap_count < TAPPING_TOGGLE) {
370 layer_switch(action.layer.val); 394 layer_switch(action.layer.val);
@@ -376,15 +400,13 @@ static void process_action(keyrecord_t *record)
376 } 400 }
377 } 401 }
378 break; 402 break;
379 case 0xFF: 403 case LAYER_CHANGE_DEFAULT: /* change default layer */
380 // change default layer
381 if (event.pressed) { 404 if (event.pressed) {
382 default_layer = action.layer.val; 405 default_layer = action.layer.val;
383 layer_switch(default_layer); 406 layer_switch(default_layer);
384 } 407 }
385 break; 408 break;
386 default: 409 default: /* switch layer on hold and key on tap*/
387 // with tap key
388 if (event.pressed) { 410 if (event.pressed) {
389 if (tap_count > 0) { 411 if (tap_count > 0) {
390 debug("LAYER_PRESSED: Tap: register_code\n"); 412 debug("LAYER_PRESSED: Tap: register_code\n");
@@ -407,65 +429,26 @@ static void process_action(keyrecord_t *record)
407 break; 429 break;
408 } 430 }
409 break; 431 break;
410 case ACT_LAYER_RELEASED: 432 case ACT_LAYER_BIT:
411 switch (action.layer.code) { 433 switch (action.layer.code) {
412 case 0x00: 434 case LAYER_MOMENTARY: /* momentary */
413 if (!event.pressed) {
414 layer_switch(action.layer.val);
415 }
416 break;
417 case 0xF0:
418 // tap toggle
419 if (event.pressed) { 435 if (event.pressed) {
420 if (tap_count >= TAPPING_TOGGLE) { 436 layer_switch(current_layer ^ action.layer.val);
421 debug("LAYER_RELEASED: tap toggle.\n");
422 layer_switch(action.layer.val);
423 }
424 } else { 437 } else {
425 if (tap_count < TAPPING_TOGGLE) { 438 layer_switch(current_layer ^ action.layer.val);
426 layer_switch(action.layer.val);
427 }
428 }
429 break;
430 case 0xFF:
431 // change default layer
432 if (!event.pressed) {
433 default_layer = action.layer.val;
434 layer_switch(default_layer);
435 } 439 }
436 break; 440 break;
437 default: 441 case LAYER_ON_PRESS:
438 // with tap key
439 if (event.pressed) { 442 if (event.pressed) {
440 if (tap_count > 0) { 443 layer_switch(current_layer ^ action.layer.val);
441 debug("LAYER_RELEASED: Tap: register_code\n");
442 register_code(action.layer.code);
443 } else {
444 debug("LAYER_RELEASED: No tap: NO ACTION\n");
445 }
446 } else {
447 if (tap_count > 0) {
448 debug("LAYER_RELEASED: Tap: unregister_code\n");
449 unregister_code(action.layer.code);
450 } else {
451 debug("LAYER_RELEASED: No tap: layer_switch\n");
452 layer_switch(action.layer.val);
453 }
454 } 444 }
455 break; 445 break;
456 } 446 case LAYER_ON_RELEASE:
457 break; 447 if (!event.pressed) {
458 case ACT_LAYER_BIT:
459 switch (action.layer.code) {
460 case 0x00:
461 if (event.pressed) {
462 layer_switch(current_layer ^ action.layer.val);
463 } else {
464 layer_switch(current_layer ^ action.layer.val); 448 layer_switch(current_layer ^ action.layer.val);
465 } 449 }
466 break; 450 break;
467 case 0xF0: 451 case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */
468 // tap toggle
469 if (event.pressed) { 452 if (event.pressed) {
470 if (tap_count < TAPPING_TOGGLE) { 453 if (tap_count < TAPPING_TOGGLE) {
471 debug("LAYER_BIT: tap toggle(press).\n"); 454 debug("LAYER_BIT: tap toggle(press).\n");
@@ -510,108 +493,6 @@ static void process_action(keyrecord_t *record)
510 break; 493 break;
511 } 494 }
512 break; 495 break;
513 case ACT_LAYER_EXT:
514 switch (action.layer.val) {
515 case 0x00:
516 // set default layer when pressed
517 switch (action.layer.code) {
518 case 0x00:
519 if (event.pressed) {
520 layer_switch(default_layer);
521 }
522 break;
523 case 0xF0:
524 // tap toggle
525 if (event.pressed) {
526 if (tap_count < TAPPING_TOGGLE) {
527 layer_switch(default_layer);
528 }
529 } else {
530 if (tap_count >= TAPPING_TOGGLE) {
531 debug("LAYER_EXT_PRESSED: tap toggle.\n");
532 layer_switch(default_layer);
533 }
534 }
535 break;
536 case 0xFF:
537 // change default layer
538 if (event.pressed) {
539 default_layer = current_layer;
540 layer_switch(default_layer);
541 }
542 break;
543 default:
544 // with tap key
545 if (event.pressed) {
546 if (tap_count > 0) {
547 debug("LAYER_EXT_PRESSED: Tap: register_code\n");
548 register_code(action.layer.code);
549 } else {
550 debug("LAYER_EXT_PRESSED: No tap: layer_switch\n");
551 layer_switch(default_layer);
552 }
553 } else {
554 if (tap_count > 0) {
555 debug("LAYER_EXT_PRESSED: Tap: unregister_code\n");
556 unregister_code(action.layer.code);
557 } else {
558 debug("LAYER_EXT_PRESSED: No tap: NO ACTION\n");
559 }
560 }
561 break;
562 }
563 break;
564 case 0x01:
565 // set default layer when released
566 switch (action.layer.code) {
567 case 0x00:
568 if (!event.pressed) {
569 layer_switch(default_layer);
570 }
571 break;
572 case 0xF0:
573 // tap toggle
574 if (event.pressed) {
575 if (tap_count >= TAPPING_TOGGLE) {
576 debug("LAYER_EXT_RELEASED: tap toggle.\n");
577 layer_switch(default_layer);
578 }
579 } else {
580 if (tap_count < TAPPING_TOGGLE) {
581 layer_switch(default_layer);
582 }
583 }
584 break;
585 case 0xFF:
586 // change default layer
587 if (!event.pressed) {
588 default_layer = current_layer;
589 layer_switch(default_layer);
590 }
591 break;
592 default:
593 // with tap key
594 if (event.pressed) {
595 if (tap_count > 0) {
596 debug("LAYER_EXT_RELEASED: Tap: register_code\n");
597 register_code(action.layer.code);
598 } else {
599 debug("LAYER_EXT_RELEASED: No tap: NO ACTION\n");
600 }
601 } else {
602 if (tap_count > 0) {
603 debug("LAYER_EXT_RELEASED: Tap: unregister_code\n");
604 unregister_code(action.layer.code);
605 } else {
606 debug("LAYER_EXT_RELEASED: No tap: layer_switch\n");
607 layer_switch(default_layer);
608 }
609 }
610 break;
611 }
612 break;
613 }
614 break;
615 496
616 /* Extentions */ 497 /* Extentions */
617 case ACT_MACRO: 498 case ACT_MACRO:
@@ -932,7 +813,7 @@ bool is_tap_key(key_t key)
932 case ACT_LMODS_TAP: 813 case ACT_LMODS_TAP:
933 case ACT_RMODS_TAP: 814 case ACT_RMODS_TAP:
934 return true; 815 return true;
935 case ACT_LAYER_PRESSED: 816 case ACT_LAYER:
936 case ACT_LAYER_BIT: 817 case ACT_LAYER_BIT:
937 switch (action.layer.code) { 818 switch (action.layer.code) {
938 case 0x00: 819 case 0x00:
@@ -944,7 +825,7 @@ bool is_tap_key(key_t key)
944 } 825 }
945 return false; 826 return false;
946 case ACT_FUNCTION: 827 case ACT_FUNCTION:
947 if (action.func.opt & O_TAP) { 828 if (action.func.opt & FUNC_TAP) {
948 return true; 829 return true;
949 } 830 }
950 return false; 831 return false;
@@ -975,10 +856,8 @@ static void debug_action(action_t action)
975 case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; 856 case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break;
976 case ACT_USAGE: debug("ACT_USAGE"); break; 857 case ACT_USAGE: debug("ACT_USAGE"); break;
977 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; 858 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break;
978 case ACT_LAYER_PRESSED: debug("ACT_LAYER_PRESSED"); break; 859 case ACT_LAYER: debug("ACT_LAYER"); break;
979 case ACT_LAYER_RELEASED: debug("ACT_LAYER_RELEASED"); break;
980 case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; 860 case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break;
981 case ACT_LAYER_EXT: debug("ACT_LAYER_EXT"); break;
982 case ACT_MACRO: debug("ACT_MACRO"); break; 861 case ACT_MACRO: debug("ACT_MACRO"); break;
983 case ACT_COMMAND: debug("ACT_COMMAND"); break; 862 case ACT_COMMAND: debug("ACT_COMMAND"); break;
984 case ACT_FUNCTION: debug("ACT_FUNCTION"); break; 863 case ACT_FUNCTION: debug("ACT_FUNCTION"); break;