Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 120 additions & 52 deletions src/daemon/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ const key keymap_bragi[N_KEYS_BRAGI_PATCH] = {
{ "lbrace", 47, KEY_LEFTBRACE },
{ "rbrace", 48, KEY_RIGHTBRACE },
{ "bslash", 49, KEY_BACKSLASH },
{ "hash", 50, KEY_BACKSLASH_ISO },
{ "hash", 50, KEY_BACKSLASH_ISO },
{ "colon", 51, KEY_SEMICOLON },
{ "quote", 52, KEY_APOSTROPHE },
{ "grave", 53, KEY_GRAVE },
Expand Down Expand Up @@ -439,23 +439,23 @@ const key keymap_bragi[N_KEYS_BRAGI_PATCH] = {
{ "ralt", 111, KEY_RIGHTALT },
{ "rwin", 112, KEY_RIGHTMETA },
{ "light", 113, KEY_CORSAIR },
{ "lock", 1, KEY_CORSAIR },
{ "lock", 1, KEY_CORSAIR },
{ "ro", 115, KEY_RO },
{ 0, -1, KEY_NONE },
{ 0, -1, KEY_NONE },
{ 0, -1, KEY_NONE },
{ 0, -1, KEY_NONE },
{ 0, -1, KEY_NONE },
{ 0, -1, KEY_NONE },
{ 0, -1, KEY_NONE },
{ 0, -1, KEY_NONE },
{ 0, -1, KEY_NONE },
{ 0, -1, KEY_NONE },
{ 0, -1, KEY_NONE },
{ 0, -1, KEY_NONE },
{ "fn", 122, KEY_FN },
{ "stop", 123, KEY_STOPCD },
{ "play", 124, KEY_PLAYPAUSE },
{ "next", 125, KEY_NEXTSONG },
{ "prev", 126, KEY_PREVIOUSSONG },
{ "mr", -1, KEY_CORSAIR },
{ "mr", -1, KEY_CORSAIR },
{ "profswitch", 128, KEY_CORSAIR },
{ 0, -1, KEY_NONE },
{ 0, -1, KEY_NONE },
{ 0, -1, KEY_NONE },
{ 0, -1, KEY_NONE },
{ "g1", 131, KEY_CORSAIR },
{ "g2", 132, KEY_CORSAIR },
{ "g3", 133, KEY_CORSAIR },
Expand Down Expand Up @@ -601,7 +601,7 @@ static inline void handle_bragi_key_input(unsigned char* kbinput, const unsigned
} else {
ckb_warn("Unhandled NKRO_KEY_IN length %d in handle_bragi_key_input(), international keys will not function", length);
}
} else if(urbinput[0] == NKRO_MEDIA_IN && length == 3) {
} else if(urbinput[0] == NKRO_MEDIA_IN && (length == 3 || length == 5)) {
// This section is similar to handle_nkro_media_keys(), but with different indices due to the different keymap
// This works because these keys can not be pressed at the same time
CLEAR_KEYBIT(kbinput, 125); // next
Expand Down Expand Up @@ -636,12 +636,102 @@ static inline void handle_bragi_key_input(unsigned char* kbinput, const unsigned
case 234:
SET_KEYBIT(kbinput, 104); // voldn
break;
case 0:
break; // key up
default:
ckb_err("Unhandled NKRO_MEDIA_IN length %d first:0x%hhx in handle_bragi_key_input()", length, urbinput[1]);
break;
}
} else {
ckb_err("Invalid length %d and header 0x%hhx combination in handle_bragi_key_input()", length, urbinput[0]);
}
}

static inline void handle_bragi_media_keys(usbdevice* targetkb){
if(BRAGI_HAS_MEDIA_MACRO(targetkb)){
if(IS_K60PRORGB(targetkb)){
// if Fn is pressed
if(ISSET_KEYBIT(targetkb->input.keys, 122)){
// As awful as this hack
bool matched = true;
if(ISSET_KEYBIT(targetkb->input.keys, 62)) { // F5 -> mute
CLEAR_KEYBIT(targetkb->input.keys, 62);
SET_KEYBIT(targetkb->input.keys, 102);
} else if (ISSET_KEYBIT(targetkb->input.keys, 64)) { // F7 -> voldn
CLEAR_KEYBIT(targetkb->input.keys, 64);
SET_KEYBIT(targetkb->input.keys, 104);
} else if (ISSET_KEYBIT(targetkb->input.keys, 65)) { // F8 -> volup
CLEAR_KEYBIT(targetkb->input.keys, 65);
SET_KEYBIT(targetkb->input.keys, 103);
} else if (ISSET_KEYBIT(targetkb->input.keys, 66)) { // F9 -> stop
CLEAR_KEYBIT(targetkb->input.keys, 66);
SET_KEYBIT(targetkb->input.keys, 123);
} else if (ISSET_KEYBIT(targetkb->input.keys, 67)) { // F10 -> prev
CLEAR_KEYBIT(targetkb->input.keys, 67);
SET_KEYBIT(targetkb->input.keys, 126);
} else if (ISSET_KEYBIT(targetkb->input.keys, 68)) { // F11 -> playpause
CLEAR_KEYBIT(targetkb->input.keys, 68);
SET_KEYBIT(targetkb->input.keys, 124);
} else if (ISSET_KEYBIT(targetkb->input.keys, 69)) { // F12 -> next
CLEAR_KEYBIT(targetkb->input.keys, 69);
SET_KEYBIT(targetkb->input.keys, 125);
} else if (ISSET_KEYBIT(targetkb->input.keys, 58)) { // F1 -> winlock
CLEAR_KEYBIT(targetkb->input.keys, 58);
SET_KEYBIT(targetkb->input.keys, 114);
} else if (ISSET_KEYBIT(targetkb->input.keys, 60)) { // F3 -> brightnessdn (not supported, map to generic "light")
CLEAR_KEYBIT(targetkb->input.keys, 60);
SET_KEYBIT(targetkb->input.keys, 113);
} else if (ISSET_KEYBIT(targetkb->input.keys, 61)) { // F4 -> brightnessup (not supported, map to generic "light")
CLEAR_KEYBIT(targetkb->input.keys, 61);
SET_KEYBIT(targetkb->input.keys, 113);
} else {
matched = false;
}
if(matched)
CLEAR_KEYBIT(targetkb->input.keys, 122);
}
}else if(IS_K70CORERGB(targetkb)){
// if Fn is pressed
if(ISSET_KEYBIT(targetkb->input.keys, 122)){
// As awful as this hack
bool matched = true;
if(ISSET_KEYBIT(targetkb->input.keys, 62)) { // F5 -> stop
CLEAR_KEYBIT(targetkb->input.keys, 62);
SET_KEYBIT(targetkb->input.keys, 123);
} if(ISSET_KEYBIT(targetkb->input.keys, 63)) { // F6 -> prev
CLEAR_KEYBIT(targetkb->input.keys, 63);
SET_KEYBIT(targetkb->input.keys, 126);
} else if (ISSET_KEYBIT(targetkb->input.keys, 64)) { // F7 -> play/pause
CLEAR_KEYBIT(targetkb->input.keys, 64);
SET_KEYBIT(targetkb->input.keys, 124);
} else if (ISSET_KEYBIT(targetkb->input.keys, 65)) { // F8 -> next
CLEAR_KEYBIT(targetkb->input.keys, 65);
SET_KEYBIT(targetkb->input.keys, 125);
} else if (ISSET_KEYBIT(targetkb->input.keys, 69)) { // F12 -> supposed to switch knob function (map to ctrlwheelb)
CLEAR_KEYBIT(targetkb->input.keys, 69);
SET_KEYBIT(targetkb->input.keys, 137);
} else if (ISSET_KEYBIT(targetkb->input.keys, 58)) { // F1 -> winlock
CLEAR_KEYBIT(targetkb->input.keys, 58);
SET_KEYBIT(targetkb->input.keys, 114);
} else if (ISSET_KEYBIT(targetkb->input.keys, 59)) { // F2 -> profile switch
CLEAR_KEYBIT(targetkb->input.keys, 59);
SET_KEYBIT(targetkb->input.keys, 128);
} else if (ISSET_KEYBIT(targetkb->input.keys, 60)) { // F3 -> brightnessdn (not supported, map to generic "light")
CLEAR_KEYBIT(targetkb->input.keys, 60);
SET_KEYBIT(targetkb->input.keys, 113);
} else if (ISSET_KEYBIT(targetkb->input.keys, 61)) { // F4 -> brightnessup (not supported, map to generic "light")
CLEAR_KEYBIT(targetkb->input.keys, 61);
SET_KEYBIT(targetkb->input.keys, 113);
} else {
matched = false;
}
if(matched)
CLEAR_KEYBIT(targetkb->input.keys, 122);
}
}
}
}

// We just need the first few buttons only, so realistically it doesn't matter
#define BUTTON_BLD_COUNT 5

Expand Down Expand Up @@ -790,46 +880,21 @@ void process_input_urb(void* context, unsigned char* buffer, int urblen, ushort
if(buffer[1] == BRAGI_INPUT_HID) {
corsair_kbcopy(targetkb->input.keys, buffer + 2);
// Check if we need to apply an awful hack to get media keys working
if(BRAGI_HAS_MEDIA_MACRO(targetkb)){
// if Fn is pressed
if(ISSET_KEYBIT(targetkb->input.keys, 122)){
// As awful as this hack
bool matched = true;
if(ISSET_KEYBIT(targetkb->input.keys, 62)) { // F5 -> mute
CLEAR_KEYBIT(targetkb->input.keys, 62);
SET_KEYBIT(targetkb->input.keys, 102);
} else if (ISSET_KEYBIT(targetkb->input.keys, 64)) { // F7 -> voldn
CLEAR_KEYBIT(targetkb->input.keys, 64);
SET_KEYBIT(targetkb->input.keys, 104);
} else if (ISSET_KEYBIT(targetkb->input.keys, 65)) { // F8 -> volup
CLEAR_KEYBIT(targetkb->input.keys, 65);
SET_KEYBIT(targetkb->input.keys, 103);
} else if (ISSET_KEYBIT(targetkb->input.keys, 66)) { // F9 -> stop
CLEAR_KEYBIT(targetkb->input.keys, 66);
SET_KEYBIT(targetkb->input.keys, 123);
} else if (ISSET_KEYBIT(targetkb->input.keys, 67)) { // F10 -> prev
CLEAR_KEYBIT(targetkb->input.keys, 67);
SET_KEYBIT(targetkb->input.keys, 126);
} else if (ISSET_KEYBIT(targetkb->input.keys, 68)) { // F11 -> playpause
CLEAR_KEYBIT(targetkb->input.keys, 68);
SET_KEYBIT(targetkb->input.keys, 124);
} else if (ISSET_KEYBIT(targetkb->input.keys, 69)) { // F12 -> next
CLEAR_KEYBIT(targetkb->input.keys, 69);
SET_KEYBIT(targetkb->input.keys, 125);
} else if (ISSET_KEYBIT(targetkb->input.keys, 58)) { // F1 -> winlock
CLEAR_KEYBIT(targetkb->input.keys, 58);
SET_KEYBIT(targetkb->input.keys, 114);
} else if (ISSET_KEYBIT(targetkb->input.keys, 60)) { // F3 -> brightnessdn (not supported, map to generic "light")
CLEAR_KEYBIT(targetkb->input.keys, 60);
SET_KEYBIT(targetkb->input.keys, 113);
} else if (ISSET_KEYBIT(targetkb->input.keys, 61)) { // F4 -> brightnessup (not supported, map to generic "light")
CLEAR_KEYBIT(targetkb->input.keys, 61);
SET_KEYBIT(targetkb->input.keys, 113);
} else {
matched = false;
}
if(matched)
CLEAR_KEYBIT(targetkb->input.keys, 122);

handle_bragi_media_keys(targetkb);
} else if(buffer[1] == BRAGI_INPUT_DIAL) {
#define MEDIA_MASK 0x60
if(buffer[1] == BRAGI_INPUT_DIAL && buffer[2] == MEDIA_MASK) {
// This is a packet from the volume dial
// We need to handle it appropriately then clear the keys so we stop getting garbage
int32_t wheel;
memcpy(&wheel, buffer + 4, sizeof(int32_t));
if(wheel > 0) {
// Apply fresh key data
SET_KEYBIT(targetkb->input.keys, 103); // volup
} else {
// Apply fresh key data
SET_KEYBIT(targetkb->input.keys, 104); // voldn
}
}
} else {
Expand Down Expand Up @@ -944,6 +1009,9 @@ void handle_nkro_media_keys(unsigned char* kbinput, const unsigned char* urbinpu
case 234:
SET_KEYBIT(kbinput, 131); // voldn
break;
default:
ckb_err("Unhandled NKRO_MEDIA_IN length %d first:0x%hhx in handle_nkro_media_keys()", length, urbinput[1]);
break;
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/daemon/keymap_patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ keypatch k70propatch[] = {
{ 138, "logo", 138, KEY_NONE },
};

keypatch k70corergbpatch[] = {
{ 124, "mr", -1, KEY_CORSAIR },
{ 127, "play", -1, KEY_PLAY },
{ 129, "mute", -1, KEY_MUTE },
};

#define ADD_PATCH(vendor, product, patch) \
{ (vendor), (product), (patch), sizeof(patch)/sizeof(*patch) }
Expand All @@ -120,7 +125,10 @@ static const keypatches mappatches[] = {
ADD_PATCH(V_CORSAIR, P_K70_TKL, k70tklpatch),
ADD_PATCH(V_CORSAIR, P_K70_TKL_CHAMP_OPTIC, k70tklpatch),
ADD_PATCH(V_CORSAIR, P_K70_PRO, k70propatch),
ADD_PATCH(V_CORSAIR, P_K70_PRO_OPTIC, k70propatch)
ADD_PATCH(V_CORSAIR, P_K70_PRO_OPTIC, k70propatch),
ADD_PATCH(V_CORSAIR, P_K70_CORE_RGB, k70corergbpatch),
ADD_PATCH(V_CORSAIR, P_K70_CORE_RGB_2, k70corergbpatch),
ADD_PATCH(V_CORSAIR, P_K70_CORE_RGB_3, k70corergbpatch),
};

#define KEYPATCHES_LEN sizeof(mappatches)/sizeof(*mappatches)
Expand Down
4 changes: 4 additions & 0 deletions src/daemon/led_bragi.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ static inline size_t bragi_led_count(usbdevice* kb){
LED_CASE_K(P_MM700, 3);
LED_CASE_K(P_K70_PRO, 193);
LED_CASE_K(P_K70_PRO_OPTIC, 193);
LED_CASE_K(P_K70_CORE_RGB, 123);
LED_CASE_K(P_K70_CORE_RGB_2, 123);
LED_CASE_K(P_K70_CORE_RGB_3, 123);

default:
ckb_err("Unknown product 0x%hx", kb->product);
return 0;
Expand Down
5 changes: 5 additions & 0 deletions src/daemon/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ const device_desc models[] = {
{ V_CORSAIR, P_K70_TKL_CHAMP_OPTIC, },
{ V_CORSAIR, P_K70_PRO, },
{ V_CORSAIR, P_K70_PRO_OPTIC, },
{ V_CORSAIR, P_K70_CORE_RGB, },
{ V_CORSAIR, P_K70_CORE_RGB_2, },
{ V_CORSAIR, P_K70_CORE_RGB_3, },
{ V_CORSAIR, P_K90_LEGACY, },
{ V_CORSAIR, P_K95, },
{ V_CORSAIR, P_K95_LEGACY, },
Expand Down Expand Up @@ -211,6 +214,8 @@ const char* product_str(ushort product){
return "k70tkl";
if(product == P_K70_PRO || product == P_K70_PRO_OPTIC)
return "k70pro";
if(product == P_K70_CORE_RGB || product == P_K70_CORE_RGB_2 || product == P_K70_CORE_RGB_3)
return "k70_core_rgb";
if(product == P_K68 || product == P_K68_NRGB)
return "k68";
if(product == P_K65 || product == P_K65_LEGACY || product == P_K65_LUX || product == P_K65_RFIRE)
Expand Down
Loading