|
|
@ -55,12 +55,17 @@ shift.KEY_SHIFT = shift.KEY_SHIFT or 11 |
|
|
|
shift.KEY_LAYOUT = shift.KEY_LAYOUT or 8 |
|
|
|
shift.KEY_BRIGHTNESS = shift.KEY_BRIGHTNESS or 5 |
|
|
|
|
|
|
|
shift.BRIGHTNESS_LEVELS = shift.BRIGHTNESS_LEVELS or { 70, 100, 40 } |
|
|
|
|
|
|
|
|
|
|
|
-- Internal flag for detecting SHIFT press-release sequences without any SHIFTed |
|
|
|
-- function. |
|
|
|
local shift_only = false |
|
|
|
local grabbed_key_count = 0 |
|
|
|
|
|
|
|
-- Activates the first brightness level... |
|
|
|
shift.brightnesses = table.pack(table.unpack(shift.BRIGHTNESS_LEVELS)) |
|
|
|
mb.cycle_brightness(shift.brightnesses) |
|
|
|
|
|
|
|
-- Switches to the next SHIFT layer within the currently active keyboard layout. |
|
|
|
-- SHIFT layer(s) are wired up as a circular list of keymaps, linked using their |
|
|
@ -72,7 +77,6 @@ function shift.shift_secondary_keymap() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
-- Remember how many grabbed keys are pressed, so we won't ungrab later until |
|
|
|
-- all keys have been released. |
|
|
|
function shift.any_press(keyno) |
|
|
@ -94,7 +98,6 @@ function shift.any_release(keyno) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
-- SHIFT press: switches into grabbed SHIFT mode, activating the in-SHIFT keys |
|
|
|
-- for brightness change, keymap cycling, et cetera. |
|
|
|
function shift.shift(key) |
|
|
@ -106,23 +109,27 @@ function shift.shift(key) |
|
|
|
mb.grab(shift.keymap_shifted.name) |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
-- Cycles to the next primary keyboard layout (keymap) |
|
|
|
function shift.cycle(key) |
|
|
|
shift_only = false |
|
|
|
mb.cycle_primary_keymaps() |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
-- Changes the Keybow LED brightness, by cycling through different brightness |
|
|
|
-- levels |
|
|
|
function shift.brightness(key) |
|
|
|
shift_only = false |
|
|
|
local b = mb.brightness + 0.3 |
|
|
|
if b > 1 then; b = 0.4; end |
|
|
|
mb.set_brightness(b) |
|
|
|
mb.cycle_brightness(shift.brightnesses) |
|
|
|
mb.led(key, shift.next_brightness_color()) |
|
|
|
end |
|
|
|
|
|
|
|
-- Returns the color for the BRIGHTNESS key LED: this is the next brightness |
|
|
|
-- level in the sequence of brightness levels as a color of gray/white. |
|
|
|
function shift.next_brightness_color() |
|
|
|
local br = shift.brightnesses[1] |
|
|
|
br = br > 1.0 and br / 100 or br |
|
|
|
return { r=br, g=br, b=br } |
|
|
|
end |
|
|
|
|
|
|
|
-- define and register our keymaps: the permanent SHIFT key-only keymap, as well |
|
|
|
-- as a temporary grabbing keymap while the SHIFT key is being pressed and held. |
|
|
@ -138,7 +145,7 @@ shift.keymap_shifted = { |
|
|
|
[shift.KEY_SHIFT] = {c={r=1, g=1, b=1}}, |
|
|
|
|
|
|
|
[shift.KEY_LAYOUT] = {c={r=0, g=1, b=1}, press=shift.cycle, release=shift.release_other}, |
|
|
|
[shift.KEY_BRIGHTNESS] = {c={r=0.5, g=0.5, b=0.5}, press=shift.brightness, release=shift.release_other} |
|
|
|
[shift.KEY_BRIGHTNESS] = {c=shift.next_brightness_color, press=shift.brightness, release=shift.release_other} |
|
|
|
} |
|
|
|
mb.register_keymap(shift.keymap) |
|
|
|
mb.register_keymap(shift.keymap_shifted) |
|
|
|