Add mac app agent and Terminal.app specific keybinds

This commit is contained in:
2026-03-18 07:59:46 -07:00
parent 025d33b739
commit 96d5a2b249
9 changed files with 195 additions and 3 deletions

View File

@@ -0,0 +1,51 @@
#include "raw_hid.h"
#include <string.h>
#include "app_focus.h"
#define CMD_SET_FOCUSED_APP 0x80
#define APP_NAME_BUF_SIZE 64
focused_app_t focused_app = APP_UNKNOWN;
static char app_name_buf[APP_NAME_BUF_SIZE];
typedef struct {
const char *name;
focused_app_t app;
} app_mapping_t;
static const app_mapping_t app_map[] = {
{ "Terminal", APP_TERMINAL },
{ "iTerm2", APP_TERMINAL },
{ "Xcode", APP_XCODE },
{ "Code", APP_VSCODE }, // "Code" is VSCode's localizedName
{ "Visual Studio Code", APP_VSCODE },
};
static focused_app_t resolve_app(const char *name) {
for (uint8_t i = 0; i < sizeof(app_map) / sizeof(app_map[0]); i++) {
if (strcmp(name, app_map[i].name) == 0) {
return app_map[i].app;
}
}
return APP_UNKNOWN;
}
// Called from system76_ec.c's raw_hid_receive (injected via sed at build time).
// Returns true if the command was handled.
bool app_focus_raw_hid_intercept(uint8_t *data, uint8_t length) {
if (data[0] == CMD_SET_FOCUSED_APP) {
uint8_t copy_len = length - 1;
if (copy_len >= APP_NAME_BUF_SIZE) {
copy_len = APP_NAME_BUF_SIZE - 1;
}
memcpy(app_name_buf, &data[1], copy_len);
app_name_buf[copy_len] = '\0';
focused_app = resolve_app(app_name_buf);
data[1] = 0; // success
raw_hid_send(data, length);
return true;
}
return false;
}