添加自动运行功能
This commit is contained in:
@@ -172,3 +172,8 @@ const uint32_t client_name_x_padding = 10;
|
|||||||
const uint32_t status_x_padding = 4;
|
const uint32_t status_x_padding = 4;
|
||||||
const uint32_t status_icon_padding = 2;
|
const uint32_t status_icon_padding = 2;
|
||||||
const uint32_t border_width = 1;
|
const uint32_t border_width = 1;
|
||||||
|
|
||||||
|
const char *autostart_list[] = {
|
||||||
|
"gentoo-pipewire-launcher restart",
|
||||||
|
"picom -b --backend xrender",
|
||||||
|
};
|
||||||
|
|||||||
33
src/main.c
33
src/main.c
@@ -40,6 +40,9 @@ static void get_xresource_config(void);
|
|||||||
static void update_status(status_t *status);
|
static void update_status(status_t *status);
|
||||||
static void draw_all_monitor_bars(void);
|
static void draw_all_monitor_bars(void);
|
||||||
static void draw_monitor_bar(monitor_t *monitor);
|
static void draw_monitor_bar(monitor_t *monitor);
|
||||||
|
static void run_autostart(void);
|
||||||
|
static void run_once(const char *command);
|
||||||
|
static bool command_already_running(const char *command);
|
||||||
static void init_xcb_event_loop(void);
|
static void init_xcb_event_loop(void);
|
||||||
static void xcb_event_handler(generic_event_t *event, void *user_data);
|
static void xcb_event_handler(generic_event_t *event, void *user_data);
|
||||||
static void key_press(key_press_event_t *event);
|
static void key_press(key_press_event_t *event);
|
||||||
@@ -720,6 +723,34 @@ void draw_monitor_bar(monitor_t *m) {
|
|||||||
flush_xcb_connection();
|
flush_xcb_connection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void run_autostart(void) {
|
||||||
|
for (int i = 0; i < LENGTH(autostart_list); i++) run_once(autostart_list[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void run_once(const char *command) {
|
||||||
|
if (command_already_running(command)) return;
|
||||||
|
|
||||||
|
g_spawn_command_line_async(command, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool command_already_running(const char *command) {
|
||||||
|
char shell_cmd[1024];
|
||||||
|
const char *user = g_getenv("USER");
|
||||||
|
snprintf(shell_cmd, sizeof(shell_cmd), "pgrep -u %s -fx '%s'", user, command);
|
||||||
|
|
||||||
|
char *output = NULL, *error = NULL;
|
||||||
|
g_spawn_command_line_sync(shell_cmd, &output, &error, NULL, NULL);
|
||||||
|
|
||||||
|
bool result = (error == NULL || !strlen(error)) && (output && strlen(output));
|
||||||
|
|
||||||
|
free(output);
|
||||||
|
free(error);
|
||||||
|
output = NULL;
|
||||||
|
error = NULL;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void init_xcb_event_loop(void) {
|
void init_xcb_event_loop(void) {
|
||||||
adapter = create_event_adapter();
|
adapter = create_event_adapter();
|
||||||
event_adapter_set_handler(adapter, xcb_event_handler, NULL);
|
event_adapter_set_handler(adapter, xcb_event_handler, NULL);
|
||||||
@@ -1460,6 +1491,8 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
init_xcb_event_loop();
|
init_xcb_event_loop();
|
||||||
|
|
||||||
|
run_autostart();
|
||||||
|
|
||||||
g_main_loop_run(loop);
|
g_main_loop_run(loop);
|
||||||
|
|
||||||
cleanup(need_restart);
|
cleanup(need_restart);
|
||||||
|
|||||||
Reference in New Issue
Block a user