mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2025-10-29 05:40:21 -04:00
opt:support use MAOMAOCONFIG env to set config path and chvt as default keybind
This commit is contained in:
parent
ae865e67bd
commit
90c69a7fa1
5 changed files with 89 additions and 37 deletions
|
|
@ -86,8 +86,13 @@ mkdir -p ~/.config/maomao/
|
|||
|
||||
|
||||
# config
|
||||
the config file is `~/.config/maomao/config.conf`
|
||||
the autostart file is `~/.config/maomao/autostart.sh`
|
||||
you can use `MAOMAOCONFIG` env to set the config path
|
||||
|
||||
- the only default keybinds is ctrl+alt+[F1-F12] to change tty
|
||||
|
||||
- the default config path is `~/.config/maomao/config.conf`
|
||||
|
||||
- the default autostart path is `~/.config/maomao/autostart.sh`
|
||||
|
||||
|
||||
# my dotfile
|
||||
|
|
|
|||
14
config.conf
14
config.conf
|
|
@ -211,20 +211,6 @@ bind=ALT+SHIFT,X,incgaps,1
|
|||
bind=ALT+SHIFT,Z,incgaps,-1
|
||||
bind=ALT+SHIFT,R,togglegaps
|
||||
|
||||
# switch tty
|
||||
bind=Ctrl+Alt,F1,chvt,1
|
||||
bind=Ctrl+Alt,F2,chvt,2
|
||||
bind=Ctrl+Alt,F3,chvt,3
|
||||
bind=Ctrl+Alt,f4,chvt,4
|
||||
bind=Ctrl+Alt,F5,chvt,5
|
||||
bind=Ctrl+Alt,F6,chvt,6
|
||||
bind=Ctrl+Alt,F7,chvt,7
|
||||
bind=Ctrl+Alt,F8,chvt,8
|
||||
bind=Ctrl+Alt,F9,chvt,9
|
||||
bind=Ctrl+Alt,F10,chvt,10
|
||||
bind=Ctrl+Alt,F11,chvt,11
|
||||
bind=Ctrl+Alt,F12,chvt,12
|
||||
|
||||
#custom app bind example
|
||||
# bind=SUPER,Return,spawn,google-chrome
|
||||
# bind=CTRL+ALT,Return,spawn,st -e ~/tool/ter-multiplexer.sh
|
||||
|
|
|
|||
47
maomao.c
47
maomao.c
|
|
@ -1551,6 +1551,29 @@ void autostartexec(void) {
|
|||
const char *const *p;
|
||||
size_t i = 0;
|
||||
|
||||
const char *maomaoconfig = getenv("MAOMAOCONFIG");
|
||||
static const char *autostart[4]; // 声明一个全局数组,大小为 5(包括 NULL 结 尾)
|
||||
char autostart_path[1024]; // 用于存储脚本的完整路径
|
||||
|
||||
if (maomaoconfig && maomaoconfig[0] != '\0') {
|
||||
// 如果 MAOMAOCONFIG 存在且不为空,使用它作为配置文件夹
|
||||
snprintf(autostart_path, sizeof(autostart_path), "%s/autostart.sh", maomaoconfig);
|
||||
} else {
|
||||
// 否则使用 HOME 环境变量下的默认路径
|
||||
const char *homedir = getenv("HOME");
|
||||
if (!homedir) {
|
||||
// 如果 HOME 环境变量不存在,无法继续
|
||||
fprintf(stderr, "Error: HOME environment variable not set.\n");
|
||||
return;
|
||||
}
|
||||
snprintf(autostart_path, sizeof(autostart_path), "%s/.config/maomao/autostart.sh", homedir);
|
||||
}
|
||||
|
||||
autostart[0] = "/bin/sh"; // 使用 /bin/sh 执行脚本
|
||||
autostart[1] = "-c"; // -c 参数表示从命令行读取脚本
|
||||
autostart[2] = autostart_path; // 脚本的完整路径
|
||||
autostart[3] = NULL; // 数组以 NULL 结尾
|
||||
|
||||
/* count entries */
|
||||
for (p = autostart; *p; autostart_len++, p++)
|
||||
while (*++p)
|
||||
|
|
@ -4364,15 +4387,23 @@ void signalhandler(int signalnumber) {
|
|||
size_t i;
|
||||
char filename[1024];
|
||||
|
||||
// 获取当前用户家目录
|
||||
const char *homedir = getenv("HOME");
|
||||
if (!homedir) {
|
||||
// 如果获取失败,则无法继续
|
||||
return;
|
||||
}
|
||||
// 获取 MAOMAOCONFIG 环境变量
|
||||
const char *maomaoconfig = getenv("MAOMAOCONFIG");
|
||||
|
||||
// 构建日志文件路径
|
||||
snprintf(filename, sizeof(filename), "%s/.config/maomao/crash.log", homedir);
|
||||
// 如果 MAOMAOCONFIG 环境变量不存在或为空,则使用 HOME 环境变量
|
||||
if (!maomaoconfig || maomaoconfig[0] == '\0') {
|
||||
// 获取当前用户家目录
|
||||
const char *homedir = getenv("HOME");
|
||||
if (!homedir) {
|
||||
// 如果获取失败,则无法继续
|
||||
return;
|
||||
}
|
||||
// 构建日志文件路径
|
||||
snprintf(filename, sizeof(filename), "%s/.config/maomao/crash.log", homedir);
|
||||
} else {
|
||||
// 使用 MAOMAOCONFIG 环境变量作为配置文件夹路径
|
||||
snprintf(filename, sizeof(filename), "%s/crash.log", maomaoconfig);
|
||||
}
|
||||
|
||||
// 打开日志文件
|
||||
FILE *fp = fopen(filename, "a");
|
||||
|
|
|
|||
|
|
@ -34,6 +34,15 @@ typedef struct {
|
|||
Arg arg;
|
||||
} KeyBinding;
|
||||
|
||||
// 定义一个宏来简化默认按键绑定的添加
|
||||
#define CHVT(n) { WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT, XKB_KEY_XF86Switch_VT_##n, chvt, {.ui = (n)} }
|
||||
|
||||
// 默认的按键绑定数组
|
||||
KeyBinding default_key_bindings[] = {
|
||||
CHVT(1), CHVT(2), CHVT(3), CHVT(4), CHVT(5), CHVT(6),
|
||||
CHVT(7), CHVT(8), CHVT(9), CHVT(10), CHVT(11), CHVT(12)
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
unsigned int mod;
|
||||
unsigned int button;
|
||||
|
|
@ -711,6 +720,24 @@ void parse_config_line(Config *config, const char *line) {
|
|||
config->key_bindings_count++;
|
||||
}
|
||||
|
||||
// 计算默认按键绑定的数量
|
||||
size_t default_key_bindings_count = sizeof(default_key_bindings) / sizeof(KeyBinding);
|
||||
|
||||
// 重新分配内存以容纳新的默认按键绑定
|
||||
config->key_bindings = realloc(config->key_bindings,
|
||||
(config->key_bindings_count + default_key_bindings_count) * sizeof(KeyBinding));
|
||||
if (!config->key_bindings) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 将默认按键绑定复制到配置的按键绑定数组中
|
||||
for (size_t i = 0; i < default_key_bindings_count; i++) {
|
||||
config->key_bindings[config->key_bindings_count + i] = default_key_bindings[i];
|
||||
}
|
||||
|
||||
// 更新按键绑定的总数
|
||||
config->key_bindings_count += default_key_bindings_count;
|
||||
|
||||
} else if (strncmp(key, "mousebind", 9) == 0) {
|
||||
config->mouse_bindings =
|
||||
realloc(config->mouse_bindings,
|
||||
|
|
@ -963,16 +990,23 @@ void parse_config(void) {
|
|||
config.axis_bindings = NULL;
|
||||
config.axis_bindings_count = 0;
|
||||
|
||||
// 获取当前用户家目录
|
||||
const char *homedir = getenv("HOME");
|
||||
if (!homedir) {
|
||||
// 如果获取失败,则无法继续
|
||||
return;
|
||||
}
|
||||
// 获取 MAOMAOCONFIG 环境变量
|
||||
const char *maomaoconfig = getenv("MAOMAOCONFIG");
|
||||
|
||||
// 构建日志文件路径
|
||||
snprintf(filename, sizeof(filename), "%s/.config/maomao/config.conf",
|
||||
homedir);
|
||||
// 如果 MAOMAOCONFIG 环境变量不存在或为空,则使用 HOME 环境变量
|
||||
if (!maomaoconfig || maomaoconfig[0] == '\0') {
|
||||
// 获取当前用户家目录
|
||||
const char *homedir = getenv("HOME");
|
||||
if (!homedir) {
|
||||
// 如果获取失败,则无法继续
|
||||
return;
|
||||
}
|
||||
// 构建日志文件路径
|
||||
snprintf(filename, sizeof(filename), "%s/.config/maomao/config.conf", homedir);
|
||||
} else {
|
||||
// 使用 MAOMAOCONFIG 环境变量作为配置文件夹路径
|
||||
snprintf(filename, sizeof(filename), "%s/config.conf", maomaoconfig);
|
||||
}
|
||||
|
||||
set_value_default();
|
||||
parse_config_file(&config, filename);
|
||||
|
|
|
|||
|
|
@ -136,7 +136,3 @@ enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TAP_MAP_LRM;
|
|||
static const char *tags[] = {
|
||||
"1", "2", "3", "4", "5", "6", "7", "8", "9",
|
||||
};
|
||||
|
||||
static const char *const autostart[] = {
|
||||
"/bin/sh", "-c", "~/.config/maomao/autostart.sh", NULL, NULL,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue