Updated workman layout, added layer toggle feature

f13
Jacob McIntosh 2015-07-14 15:50:36 -05:00
parent 9fffce4cb8
commit b4e431c49b
4 changed files with 662 additions and 566 deletions

File diff suppressed because it is too large Load Diff

View File

@ -51,6 +51,16 @@
void kbfun_layer_pop_8 (void); void kbfun_layer_pop_8 (void);
void kbfun_layer_pop_9 (void); void kbfun_layer_pop_9 (void);
void kbfun_layer_pop_10 (void); void kbfun_layer_pop_10 (void);
void kbfun_layer_toggle_1 (void);
void kbfun_layer_toggle_2 (void);
void kbfun_layer_toggle_3 (void);
void kbfun_layer_toggle_4 (void);
void kbfun_layer_toggle_5 (void);
void kbfun_layer_toggle_6 (void);
void kbfun_layer_toggle_7 (void);
void kbfun_layer_toggle_8 (void);
void kbfun_layer_toggle_9 (void);
void kbfun_layer_toggle_10 (void);
// --- // ---
// device // device

View File

@ -103,9 +103,17 @@ void kbfun_transparent(void) {
// layer 0 even if we will never have a push or pop function for it // layer 0 even if we will never have a push or pop function for it
static uint8_t layer_ids[1 + MAX_LAYER_PUSH_POP_FUNCTIONS]; static uint8_t layer_ids[1 + MAX_LAYER_PUSH_POP_FUNCTIONS];
static void layer_pop(uint8_t local_id) {
uint8_t id = layer_ids[local_id];
if (id != 0) {
main_layers_pop_id(id);
layer_ids[local_id] = 0;
}
}
static void layer_push(uint8_t local_id) { static void layer_push(uint8_t local_id) {
uint8_t keycode = kb_layout_get(LAYER, ROW, COL); uint8_t keycode = kb_layout_get(LAYER, ROW, COL);
main_layers_pop_id(layer_ids[local_id]); layer_pop(local_id);
// Only the topmost layer on the stack should be in sticky once state, pop // Only the topmost layer on the stack should be in sticky once state, pop
// the top layer if it is in sticky once state // the top layer if it is in sticky once state
uint8_t topSticky = main_layers_peek_sticky(0); uint8_t topSticky = main_layers_peek_sticky(0);
@ -120,7 +128,7 @@ static void layer_sticky(uint8_t local_id) {
if (IS_PRESSED) { if (IS_PRESSED) {
uint8_t topLayer = main_layers_peek(0); uint8_t topLayer = main_layers_peek(0);
uint8_t topSticky = main_layers_peek_sticky(0); uint8_t topSticky = main_layers_peek_sticky(0);
main_layers_pop_id(layer_ids[local_id]); layer_pop(local_id);
if (topLayer == local_id) { if (topLayer == local_id) {
if (topSticky == eStickyOnceUp) if (topSticky == eStickyOnceUp)
layer_ids[local_id] = main_layers_push(keycode, eStickyLock); layer_ids[local_id] = main_layers_push(keycode, eStickyLock);
@ -129,7 +137,7 @@ static void layer_sticky(uint8_t local_id) {
{ {
// only the topmost layer on the stack should be in sticky once state // only the topmost layer on the stack should be in sticky once state
if (topSticky == eStickyOnceDown || topSticky == eStickyOnceUp) { if (topSticky == eStickyOnceDown || topSticky == eStickyOnceUp) {
main_layers_pop_id(layer_ids[topLayer]); layer_pop(topLayer);
} }
layer_ids[local_id] = main_layers_push(keycode, eStickyOnceDown); layer_ids[local_id] = main_layers_push(keycode, eStickyOnceDown);
// this should be the only place we care about this flag being cleared // this should be the only place we care about this flag being cleared
@ -143,7 +151,7 @@ static void layer_sticky(uint8_t local_id) {
if (topLayer == local_id) { if (topLayer == local_id) {
if (topSticky == eStickyOnceDown) { if (topSticky == eStickyOnceDown) {
// When releasing this sticky key, pop the layer always // When releasing this sticky key, pop the layer always
main_layers_pop_id(layer_ids[local_id]); layer_pop(local_id);
if (!main_arg_any_non_trans_key_pressed) { if (!main_arg_any_non_trans_key_pressed) {
// If no key defined for this layer (a non-transparent key) // If no key defined for this layer (a non-transparent key)
// was pressed, push the layer again, but in the // was pressed, push the layer again, but in the
@ -155,9 +163,14 @@ static void layer_sticky(uint8_t local_id) {
} }
} }
static void layer_pop(uint8_t local_id) { static void layer_toggle(uint8_t local_id) {
main_layers_pop_id(layer_ids[local_id]); if (layer_ids[local_id] != 0) {
layer_ids[local_id] = 0; layer_pop(local_id);
}
else
{
layer_push(local_id);
}
} }
/* /*
@ -197,7 +210,7 @@ void kbfun_layer_push_1(void) {
* for each state: * for each state:
* 1) One time down (set on key press) - The layer was not active and the key * 1) One time down (set on key press) - The layer was not active and the key
* has been pressed but not yet released. The layer is pushed in the one * has been pressed but not yet released. The layer is pushed in the one
* time down state. * time down state.
* 2) One time up (set on key release) - The layer was active when the layer * 2) One time up (set on key release) - The layer was active when the layer
* sticky key was released. If a key on this layer (not set to * sticky key was released. If a key on this layer (not set to
* transparent) was pressed before the key was released, the layer will be * transparent) was pressed before the key was released, the layer will be
@ -224,13 +237,24 @@ void kbfun_layer_pop_1(void) {
layer_pop(1); layer_pop(1);
} }
/*
* [name]
* Layer toggle #1
*
* [description]
* If the layer element is already in the layer stack, pop it. Otherwise,
* push the layer element to the top of the stack.
*/
void kbfun_layer_toggle_1(void) {
layer_toggle(1);
}
/* /*
* [name] * [name]
* Layer push #2 * Layer push #2
* *
* [description] * [description]
* Push a layer element containing the layer value specified in the keymap to * See the description of kbfun_layer_push_1()
* the top of the stack, and record the id of that layer element
*/ */
void kbfun_layer_push_2(void) { void kbfun_layer_push_2(void) {
layer_push(2); layer_push(2);
@ -252,21 +276,29 @@ void kbfun_layer_sticky_2 (void) {
* Layer pop #2 * Layer pop #2
* *
* [description] * [description]
* Pop the layer element created by the corresponding "layer push" function * See the description of kbfun_layer_pop_1()
* out of the layer stack (no matter where it is in the stack, without
* touching any other elements)
*/ */
void kbfun_layer_pop_2(void) { void kbfun_layer_pop_2(void) {
layer_pop(2); layer_pop(2);
} }
/*
* [name]
* Layer toggle #2
*
* [description]
* See the description of kbfun_layer_toggle_1()
*/
void kbfun_layer_toggle_2(void) {
layer_toggle(2);
}
/* /*
* [name] * [name]
* Layer push #3 * Layer push #3
* *
* [description] * [description]
* Push a layer element containing the layer value specified in the keymap to * See the description of kbfun_layer_push_1()
* the top of the stack, and record the id of that layer element
*/ */
void kbfun_layer_push_3(void) { void kbfun_layer_push_3(void) {
layer_push(3); layer_push(3);
@ -288,21 +320,29 @@ void kbfun_layer_sticky_3 (void) {
* Layer pop #3 * Layer pop #3
* *
* [description] * [description]
* Pop the layer element created by the corresponding "layer push" function * See the description of kbfun_layer_pop_1()
* out of the layer stack (no matter where it is in the stack, without
* touching any other elements)
*/ */
void kbfun_layer_pop_3(void) { void kbfun_layer_pop_3(void) {
layer_pop(3); layer_pop(3);
} }
/*
* [name]
* Layer toggle #3
*
* [description]
* See the description of kbfun_layer_toggle_1()
*/
void kbfun_layer_toggle_3(void) {
layer_toggle(3);
}
/* /*
* [name] * [name]
* Layer push #4 * Layer push #4
* *
* [description] * [description]
* Push a layer element containing the layer value specified in the keymap to * See the description of kbfun_layer_push_1()
* the top of the stack, and record the id of that layer element
*/ */
void kbfun_layer_push_4(void) { void kbfun_layer_push_4(void) {
layer_push(4); layer_push(4);
@ -324,21 +364,29 @@ void kbfun_layer_sticky_4 (void) {
* Layer pop #4 * Layer pop #4
* *
* [description] * [description]
* Pop the layer element created by the corresponding "layer push" function * See the description of kbfun_layer_pop_1()
* out of the layer stack (no matter where it is in the stack, without
* touching any other elements)
*/ */
void kbfun_layer_pop_4(void) { void kbfun_layer_pop_4(void) {
layer_pop(4); layer_pop(4);
} }
/*
* [name]
* Layer toggle #4
*
* [description]
* See the description of kbfun_layer_toggle_1()
*/
void kbfun_layer_toggle_4(void) {
layer_toggle(4);
}
/* /*
* [name] * [name]
* Layer push #5 * Layer push #5
* *
* [description] * [description]
* Push a layer element containing the layer value specified in the keymap to * See the description of kbfun_layer_push_1()
* the top of the stack, and record the id of that layer element
*/ */
void kbfun_layer_push_5(void) { void kbfun_layer_push_5(void) {
layer_push(5); layer_push(5);
@ -360,21 +408,29 @@ void kbfun_layer_sticky_5 (void) {
* Layer pop #5 * Layer pop #5
* *
* [description] * [description]
* Pop the layer element created by the corresponding "layer push" function * See the description of kbfun_layer_pop_1()
* out of the layer stack (no matter where it is in the stack, without
* touching any other elements)
*/ */
void kbfun_layer_pop_5(void) { void kbfun_layer_pop_5(void) {
layer_pop(5); layer_pop(5);
} }
/*
* [name]
* Layer toggle #5
*
* [description]
* See the description of kbfun_layer_toggle_1()
*/
void kbfun_layer_toggle_5(void) {
layer_toggle(5);
}
/* /*
* [name] * [name]
* Layer push #6 * Layer push #6
* *
* [description] * [description]
* Push a layer element containing the layer value specified in the keymap to * See the description of kbfun_layer_push_1()
* the top of the stack, and record the id of that layer element
*/ */
void kbfun_layer_push_6(void) { void kbfun_layer_push_6(void) {
layer_push(6); layer_push(6);
@ -396,21 +452,29 @@ void kbfun_layer_sticky_6 (void) {
* Layer pop #6 * Layer pop #6
* *
* [description] * [description]
* Pop the layer element created by the corresponding "layer push" function * See the description of kbfun_layer_pop_1()
* out of the layer stack (no matter where it is in the stack, without
* touching any other elements)
*/ */
void kbfun_layer_pop_6(void) { void kbfun_layer_pop_6(void) {
layer_pop(6); layer_pop(6);
} }
/*
* [name]
* Layer toggle #6
*
* [description]
* See the description of kbfun_layer_toggle_1()
*/
void kbfun_layer_toggle_6(void) {
layer_toggle(6);
}
/* /*
* [name] * [name]
* Layer push #7 * Layer push #7
* *
* [description] * [description]
* Push a layer element containing the layer value specified in the keymap to * See the description of kbfun_layer_push_1()
* the top of the stack, and record the id of that layer element
*/ */
void kbfun_layer_push_7(void) { void kbfun_layer_push_7(void) {
layer_push(7); layer_push(7);
@ -432,21 +496,29 @@ void kbfun_layer_sticky_7 (void) {
* Layer pop #7 * Layer pop #7
* *
* [description] * [description]
* Pop the layer element created by the corresponding "layer push" function * See the description of kbfun_layer_pop_1()
* out of the layer stack (no matter where it is in the stack, without
* touching any other elements)
*/ */
void kbfun_layer_pop_7(void) { void kbfun_layer_pop_7(void) {
layer_pop(7); layer_pop(7);
} }
/*
* [name]
* Layer toggle #7
*
* [description]
* See the description of kbfun_layer_toggle_1()
*/
void kbfun_layer_toggle_7(void) {
layer_toggle(7);
}
/* /*
* [name] * [name]
* Layer push #8 * Layer push #8
* *
* [description] * [description]
* Push a layer element containing the layer value specified in the keymap to * See the description of kbfun_layer_push_1()
* the top of the stack, and record the id of that layer element
*/ */
void kbfun_layer_push_8(void) { void kbfun_layer_push_8(void) {
layer_push(8); layer_push(8);
@ -468,21 +540,29 @@ void kbfun_layer_sticky_8 (void) {
* Layer pop #8 * Layer pop #8
* *
* [description] * [description]
* Pop the layer element created by the corresponding "layer push" function * See the description of kbfun_layer_pop_1()
* out of the layer stack (no matter where it is in the stack, without
* touching any other elements)
*/ */
void kbfun_layer_pop_8(void) { void kbfun_layer_pop_8(void) {
layer_pop(8); layer_pop(8);
} }
/*
* [name]
* Layer toggle #8
*
* [description]
* See the description of kbfun_layer_toggle_1()
*/
void kbfun_layer_toggle_8(void) {
layer_toggle(8);
}
/* /*
* [name] * [name]
* Layer push #9 * Layer push #9
* *
* [description] * [description]
* Push a layer element containing the layer value specified in the keymap to * See the description of kbfun_layer_push_1()
* the top of the stack, and record the id of that layer element
*/ */
void kbfun_layer_push_9(void) { void kbfun_layer_push_9(void) {
layer_push(9); layer_push(9);
@ -504,21 +584,29 @@ void kbfun_layer_sticky_9 (void) {
* Layer pop #9 * Layer pop #9
* *
* [description] * [description]
* Pop the layer element created by the corresponding "layer push" function * See the description of kbfun_layer_pop_1()
* out of the layer stack (no matter where it is in the stack, without
* touching any other elements)
*/ */
void kbfun_layer_pop_9(void) { void kbfun_layer_pop_9(void) {
layer_pop(9); layer_pop(9);
} }
/*
* [name]
* Layer toggle #9
*
* [description]
* See the description of kbfun_layer_toggle_1()
*/
void kbfun_layer_toggle_9(void) {
layer_toggle(9);
}
/* /*
* [name] * [name]
* Layer push #10 * Layer push #10
* *
* [description] * [description]
* Push a layer element containing the layer value specified in the keymap to * See the description of kbfun_layer_push_1()
* the top of the stack, and record the id of that layer element
*/ */
void kbfun_layer_push_10(void) { void kbfun_layer_push_10(void) {
layer_push(10); layer_push(10);
@ -540,14 +628,23 @@ void kbfun_layer_sticky_10 (void) {
* Layer pop #10 * Layer pop #10
* *
* [description] * [description]
* Pop the layer element created by the corresponding "layer push" function * See the description of kbfun_layer_pop_1()
* out of the layer stack (no matter where it is in the stack, without
* touching any other elements)
*/ */
void kbfun_layer_pop_10(void) { void kbfun_layer_pop_10(void) {
layer_pop(10); layer_pop(10);
} }
/*
* [name]
* Layer toggle #10
*
* [description]
* See the description of kbfun_layer_toggle_1()
*/
void kbfun_layer_toggle_10(void) {
layer_toggle(10);
}
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */

View File

@ -250,43 +250,22 @@ uint8_t main_layers_push(uint8_t layer, uint8_t sticky) {
*/ */
void main_layers_pop_id(uint8_t id) { void main_layers_pop_id(uint8_t id) {
// look for the element with the id we want to pop // look for the element with the id we want to pop
for (uint8_t element=1; element<=layers_head; element++) for (uint8_t element=1; element<=layers_head; element++) {
// if we find it // if we find it
if (layers[element].id == id) { if (layers[element].id == id) {
// move all layers above it down one for(; element<layers_head; ++element) {
for (; element<layers_head; element++) { layers[element].layer = layers[element+1].layer;
layers[element].layer = layers[element+1].layer; layers[element].id = layers[element+1].id;
layers[element].id = layers[element+1].id; }
} // reinitialize the topmost (now unused) slot
// reinitialize the topmost (now unused) slot layers[layers_head].layer = 0;
layers[layers_head].layer = 0; layers[layers_head].id = 0;
layers[layers_head].id = 0; // record keeping
// record keeping layers_ids_in_use[id] = false;
layers_ids_in_use[id] = false; layers_head--;
layers_head--; return;
} }
} }
/*
* get_offset_id()
*
* Arguments
* - 'id': the id of the element you want the offset of
*
* Returns
* - success: the offset (down the stack from the head element) of the element
* with the given id
* - failure: 0 (default) (id unassigned)
*/
uint8_t main_layers_get_offset_id(uint8_t id) {
// look for the element with the id we want to get the offset of
for (uint8_t element=1; element<=layers_head; element++)
// if we find it
if (layers[element].id == id)
return (layers_head - element);
return 0; // default, or error
} }
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------