mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-03-03 01:40:28 -05:00
feat: set dbus env auto
This commit is contained in:
parent
ebdfb14654
commit
a06774d494
8 changed files with 155 additions and 3 deletions
|
|
@ -92,3 +92,85 @@ uint32_t get_now_in_ms(void) {
|
|||
uint32_t timespec_to_ms(struct timespec *ts) {
|
||||
return (uint32_t)ts->tv_sec * 1000 + (uint32_t)ts->tv_nsec / 1000000;
|
||||
}
|
||||
|
||||
char *join_strings(char *arr[], const char *sep) {
|
||||
if (!arr || !arr[0]) {
|
||||
char *empty = malloc(1);
|
||||
if (empty)
|
||||
empty[0] = '\0';
|
||||
return empty;
|
||||
}
|
||||
|
||||
size_t total_len = 0;
|
||||
int count = 0;
|
||||
for (int i = 0; arr[i] != NULL; i++) {
|
||||
total_len += strlen(arr[i]);
|
||||
count++;
|
||||
}
|
||||
if (count > 0) {
|
||||
total_len += strlen(sep) * (count - 1);
|
||||
}
|
||||
|
||||
char *result = malloc(total_len + 1);
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
result[0] = '\0';
|
||||
for (int i = 0; arr[i] != NULL; i++) {
|
||||
if (i > 0)
|
||||
strcat(result, sep);
|
||||
strcat(result, arr[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
char *join_strings_with_suffix(char *arr[], const char *suffix,
|
||||
const char *sep) {
|
||||
if (!arr || !arr[0]) {
|
||||
char *empty = malloc(1);
|
||||
if (empty)
|
||||
empty[0] = '\0';
|
||||
return empty;
|
||||
}
|
||||
|
||||
size_t total_len = 0;
|
||||
int count = 0;
|
||||
for (int i = 0; arr[i] != NULL; i++) {
|
||||
total_len += strlen(arr[i]) + strlen(suffix);
|
||||
count++;
|
||||
}
|
||||
if (count > 0) {
|
||||
total_len += strlen(sep) * (count - 1);
|
||||
}
|
||||
|
||||
char *result = malloc(total_len + 1);
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
result[0] = '\0';
|
||||
for (int i = 0; arr[i] != NULL; i++) {
|
||||
if (i > 0)
|
||||
strcat(result, sep);
|
||||
strcat(result, arr[i]);
|
||||
strcat(result, suffix);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
char *string_printf(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int len = vsnprintf(NULL, 0, fmt, args);
|
||||
va_end(args);
|
||||
if (len < 0)
|
||||
return NULL;
|
||||
|
||||
char *str = malloc(len + 1);
|
||||
if (!str)
|
||||
return NULL;
|
||||
|
||||
va_start(args, fmt);
|
||||
vsnprintf(str, len + 1, fmt, args);
|
||||
va_end(args);
|
||||
return str;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,4 +7,8 @@ int32_t fd_set_nonblock(int32_t fd);
|
|||
int32_t regex_match(const char *pattern_mb, const char *str_mb);
|
||||
void wl_list_append(struct wl_list *list, struct wl_list *object);
|
||||
uint32_t get_now_in_ms(void);
|
||||
uint32_t timespec_to_ms(struct timespec *ts);
|
||||
uint32_t timespec_to_ms(struct timespec *ts);
|
||||
char *join_strings(char *arr[], const char *sep);
|
||||
char *join_strings_with_suffix(char *arr[], const char *suffix,
|
||||
const char *sep);
|
||||
char *string_printf(const char *fmt, ...);
|
||||
|
|
@ -3503,6 +3503,16 @@ void reapply_cursor_style(void) {
|
|||
|
||||
cursor_mgr = wlr_xcursor_manager_create(config.cursor_theme, cursor_size);
|
||||
|
||||
if(cursor_size > 0){
|
||||
char size_str[16];
|
||||
snprintf(size_str, sizeof(size_str), "%d", cursor_size);
|
||||
setenv("XCURSOR_SIZE", size_str, 1);
|
||||
}
|
||||
|
||||
if(config.cursor_theme){
|
||||
setenv("XCURSOR_THEME", config.cursor_theme, 1);
|
||||
}
|
||||
|
||||
Monitor *m = NULL;
|
||||
wl_list_for_each(m, &mons, link) {
|
||||
wlr_xcursor_manager_load(cursor_mgr, m->wlr_output->scale);
|
||||
|
|
|
|||
44
src/mango.c
44
src/mango.c
|
|
@ -915,6 +915,12 @@ static KeyMode keymode = {
|
|||
.mode = {'d', 'e', 'f', 'a', 'u', 'l', 't', '\0'},
|
||||
.isdefault = true,
|
||||
};
|
||||
|
||||
static char *env_vars[] = {"DISPLAY",
|
||||
"WAYLAND_DISPLAY",
|
||||
"XDG_CURRENT_DESKTOP",
|
||||
"XDG_SESSION_TYPE",
|
||||
NULL};
|
||||
static struct {
|
||||
enum wp_cursor_shape_device_v1_shape shape;
|
||||
struct wlr_surface *surface;
|
||||
|
|
@ -4725,6 +4731,41 @@ void exchange_two_client(Client *c1, Client *c2) {
|
|||
}
|
||||
}
|
||||
|
||||
void set_activation_env() {
|
||||
if (!getenv("DBUS_SESSION_BUS_ADDRESS")) {
|
||||
wlr_log(WLR_INFO, "Not updating dbus execution environment: "
|
||||
"DBUS_SESSION_BUS_ADDRESS not set");
|
||||
return;
|
||||
}
|
||||
|
||||
wlr_log(WLR_INFO, "Updating dbus execution environment");
|
||||
|
||||
char *env_keys = join_strings(env_vars, " ");
|
||||
|
||||
// first command: dbus-update-activation-environment
|
||||
const char *arg1 = env_keys;
|
||||
char *cmd1 = string_printf("dbus-update-activation-environment %s", arg1);
|
||||
if (!cmd1) {
|
||||
wlr_log(WLR_ERROR, "Failed to allocate command string");
|
||||
goto cleanup;
|
||||
}
|
||||
spawn(&(Arg){.v = cmd1});
|
||||
free(cmd1);
|
||||
|
||||
// second command: systemctl --user
|
||||
const char *action = "import-environment";
|
||||
char *cmd2 = string_printf("systemctl --user %s %s", action, env_keys);
|
||||
if (!cmd2) {
|
||||
wlr_log(WLR_ERROR, "Failed to allocate command string");
|
||||
goto cleanup;
|
||||
}
|
||||
spawn(&(Arg){.v = cmd2});
|
||||
free(cmd2);
|
||||
|
||||
cleanup:
|
||||
free(env_keys);
|
||||
}
|
||||
|
||||
void // 17
|
||||
run(char *startup_cmd) {
|
||||
|
||||
|
|
@ -4782,6 +4823,8 @@ run(char *startup_cmd) {
|
|||
wlr_cursor_set_xcursor(cursor, cursor_mgr, "left_ptr");
|
||||
handlecursoractivity();
|
||||
|
||||
set_activation_env();
|
||||
|
||||
run_exec();
|
||||
run_exec_once();
|
||||
|
||||
|
|
@ -5278,6 +5321,7 @@ void setup(void) {
|
|||
|
||||
setenv("XCURSOR_SIZE", "24", 1);
|
||||
setenv("XDG_CURRENT_DESKTOP", "mango", 1);
|
||||
|
||||
parse_config();
|
||||
init_baked_points();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue