Compare commits

..

2 Commits

3 changed files with 46 additions and 0 deletions

View File

@@ -96,3 +96,10 @@ static const layout_t layout_list[] = {
{.symbol = "[M]", .arrange = monocle}, {.symbol = "[M]", .arrange = monocle},
{.symbol = "><=", .arrange = nullptr}, {.symbol = "><=", .arrange = nullptr},
}; };
static const char *const autostart_list[] = {
"gentoo-pipewire-launcher restart",
"picom -b --backend xrender",
"fcitx5 -d",
nullptr,
};

View File

@@ -175,12 +175,15 @@ static void property_notify(xcb_property_notify_event_t *ev) {
if (ev->atom == WM_NAME) { if (ev->atom == WM_NAME) {
xwindow_get_text_property(ev->window, ev->atom, &client->name); xwindow_get_text_property(ev->window, ev->atom, &client->name);
monitor_draw_bar(client->monitor); monitor_draw_bar(client->monitor);
xcb_flush(wm.xcb_conn);
} else if (ev->atom == _NET_WM_NAME) { } else if (ev->atom == _NET_WM_NAME) {
xwindow_get_text_property(ev->window, ev->atom, &client->net_name); xwindow_get_text_property(ev->window, ev->atom, &client->net_name);
monitor_draw_bar(client->monitor); monitor_draw_bar(client->monitor);
xcb_flush(wm.xcb_conn);
} else if (ev->atom == XCB_ATOM_WM_HINTS) { } else if (ev->atom == XCB_ATOM_WM_HINTS) {
client_update_wm_hints(client); client_update_wm_hints(client);
monitor_draw_bar(client->monitor); monitor_draw_bar(client->monitor);
xcb_flush(wm.xcb_conn);
} }
} }

View File

@@ -5,6 +5,7 @@
#include <glibconfig.h> #include <glibconfig.h>
#include <signal.h> #include <signal.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@@ -46,6 +47,9 @@ static void wm_setup(void);
static void wm_get_xres_config(void); static void wm_get_xres_config(void);
static void wm_init_color_set(void); static void wm_init_color_set(void);
static void wm_setup_keybindings(void); static void wm_setup_keybindings(void);
static void wm_run_autostart(const char *const commands[]);
static void run_once(const char *command);
static bool command_already_running(const char *command);
wm_t wm; wm_t wm;
@@ -429,6 +433,36 @@ void wm_setup_keybindings(void) {
xwindow_grab_keys(wm.screen->root, key_list, countof(key_list)); xwindow_grab_keys(wm.screen->root, key_list, countof(key_list));
} }
/**
* @brief 允许自启动程序
* @param commands 命令字符串数组(以 nullptr 结尾)
*/
void wm_run_autostart(const char *const commands[]) {
for (int i = 0; commands[i]; i++) run_once(commands[i]);
}
void run_once(const char *command) {
if (command_already_running(command)) return;
g_spawn_command_line_async(command, nullptr);
}
bool command_already_running(const char *command) {
char shell_cmd[1024];
const char *user = getenv("USER");
snprintf(shell_cmd, sizeof(shell_cmd), "pgrep -u %s -fx '%s'", user, command);
char *output = nullptr;
char *error = nullptr;
g_spawn_command_line_sync(shell_cmd, &output, &error, nullptr, nullptr);
bool result =
(error == nullptr || !strlen(error)) && (output && strlen(output));
p_delete(&output);
p_delete(&error);
return result;
}
void wm_restart(void) { void wm_restart(void) {
wm.need_restart = true; wm.need_restart = true;
if (g_main_loop_is_running(wm.loop)) { if (g_main_loop_is_running(wm.loop)) {
@@ -552,6 +586,8 @@ int main(int argc, char *argv[]) {
debug_show_monitor_list(); debug_show_monitor_list();
wm_run_autostart(autostart_list);
if (wm.loop == nullptr) { if (wm.loop == nullptr) {
wm.loop = g_main_loop_new(nullptr, FALSE); wm.loop = g_main_loop_new(nullptr, FALSE);
g_main_loop_run(wm.loop); g_main_loop_run(wm.loop);