diff --git a/examples/config b/examples/config index 94edab5..15baf31 100644 --- a/examples/config +++ b/examples/config @@ -10,6 +10,9 @@ background 0.25 0.21 0.2 # Gap between windows (in pixels) gap 10 +# Smart gaps: disable gaps when there's only one window +smart_gaps enable + escape A-space bind s hsplit diff --git a/keybinding.c b/keybinding.c index f3bdef7..6b11fda 100644 --- a/keybinding.c +++ b/keybinding.c @@ -1636,6 +1636,33 @@ keybinding_set_gap(struct nedm_server *server, int gap_size) { old_gap, server->gap_size); } +void +keybinding_set_smart_gaps(struct nedm_server *server, int enable) { + bool old_smart_gaps = server->smart_gaps; + server->smart_gaps = enable ? true : false; + + // Re-position all windows with new smart gaps settings + struct nedm_output *output; + wl_list_for_each(output, &server->outputs, link) { + for(unsigned int i = 0; i < server->nws; ++i) { + struct nedm_tile *tile = output->workspaces[i]->focused_tile; + if(tile) { + struct nedm_tile *curr_tile = tile; + do { + if(curr_tile->view) { + view_maximize(curr_tile->view, curr_tile); + } + curr_tile = curr_tile->next; + } while(curr_tile != tile); + } + } + } + + ipc_send_event(server, + "{\"event_name\":\"set_smart_gaps\",\"old_smart_gaps\":%s,\"new_smart_gaps\":%s}", + old_smart_gaps ? "true" : "false", server->smart_gaps ? "true" : "false"); +} + void keybinding_definemode(struct nedm_server *server, char *mode) { int length = 0; @@ -1921,6 +1948,21 @@ keybinding_configure_message(struct nedm_server *server, ipc_send_event(server, "{\"event_name\":\"configure_message\"}"); } +void +keybinding_configure_wallpaper(struct nedm_server *server, + struct nedm_wallpaper_config *config) { + if(config->image_path != NULL) { + free(server->wallpaper_config.image_path); + server->wallpaper_config.image_path = strdup(config->image_path); + } + server->wallpaper_config.mode = config->mode; + server->wallpaper_config.bg_color[0] = config->bg_color[0]; + server->wallpaper_config.bg_color[1] = config->bg_color[1]; + server->wallpaper_config.bg_color[2] = config->bg_color[2]; + server->wallpaper_config.bg_color[3] = config->bg_color[3]; + ipc_send_event(server, "{\"event_name\":\"configure_wallpaper\"}"); +} + void set_cursor(bool enabled, struct nedm_seat *seat) { if(enabled == true) { @@ -2209,6 +2251,9 @@ run_action(enum keybinding_action action, struct nedm_server *server, case KEYBINDING_GAP: keybinding_set_gap(server, data.i); break; + case KEYBINDING_SMART_GAPS: + keybinding_set_smart_gaps(server, data.i); + break; case KEYBINDING_CONFIGURE_OUTPUT: keybinding_configure_output(server, data.o_cfg); break; @@ -2218,6 +2263,9 @@ run_action(enum keybinding_action action, struct nedm_server *server, case KEYBINDING_CONFIGURE_INPUT: keybinding_configure_input(server, data.i_cfg); break; + case KEYBINDING_CONFIGURE_WALLPAPER: + keybinding_configure_wallpaper(server, data.wp_cfg); + break; case KEYBINDING_CLOSE_VIEW: keybinding_close_view( server->curr_output->workspaces[server->curr_output->curr_workspace] diff --git a/keybinding.h b/keybinding.h index c72f8e5..6429426 100644 --- a/keybinding.h +++ b/keybinding.h @@ -116,7 +116,9 @@ struct nedm_server; KEYBINDING(KEYBINDING_WORKSPACES, \ workspaces) /* data.i is the number of workspaces */ \ KEYBINDING(KEYBINDING_GAP, \ - gap) /* data.i is the gap size in pixels */ + gap) /* data.i is the gap size in pixels */ \ + KEYBINDING(KEYBINDING_SMART_GAPS, \ + smart_gaps) /* data.i is 1 for enable, 0 for disable */ #define GENERATE_ENUM(ENUM, NAME) ENUM, #define GENERATE_STRING(STRING, NAME) #NAME, @@ -180,5 +182,7 @@ void keybinding_free(struct keybinding *keybinding, bool recursive); void keybinding_set_gap(struct nedm_server *server, int gap_size); +void +keybinding_set_smart_gaps(struct nedm_server *server, int enable); #endif /* end of include guard NEDM_KEYBINDING_H */ diff --git a/nedm.c b/nedm.c index 0441ed5..3420d35 100644 --- a/nedm.c +++ b/nedm.c @@ -394,6 +394,8 @@ main(int argc, char *argv[]) { server.nws = 1; server.views_curr_id = 1; server.tiles_curr_id = 1; + server.gap_size = 0; + server.smart_gaps = true; server.message_config.fg_color[0] = 0.0; server.message_config.fg_color[1] = 0.0; server.message_config.fg_color[2] = 0.0; @@ -756,6 +758,9 @@ main(int argc, char *argv[]) { } } + // Initialize wallpaper subsystem + nedm_wallpaper_init(&server); + { struct wl_list tmp_list; wl_list_init(&tmp_list); diff --git a/parse.c b/parse.c index c21ae98..1bf44be 100644 --- a/parse.c +++ b/parse.c @@ -821,8 +821,13 @@ parse_wallpaper_config(char **saveptr, char **errstr) { } if(strcmp(setting, "image_path") == 0) { + char *path = strtok_r(NULL, " ", saveptr); + if(path == NULL) { + *errstr = log_error("Expected image path for wallpaper configuration, got none"); + goto error; + } free(cfg->image_path); - cfg->image_path = strdup(*saveptr); + cfg->image_path = strdup(path); if(cfg->image_path == NULL) { *errstr = log_error("Unable to allocate memory for image path in wallpaper config"); goto error; @@ -1755,6 +1760,21 @@ parse_command(struct nedm_server *server, struct keybinding *keybinding, *errstr = log_error("Error parsing gap size, expected positive integer"); return -1; } + } else if(strcmp(action, "smart_gaps") == 0) { + keybinding->action = KEYBINDING_SMART_GAPS; + char *value = strtok_r(NULL, " ", &saveptr); + if(value == NULL) { + *errstr = log_error("Expected argument for \"smart_gaps\", got none"); + return -1; + } + if(strcmp(value, "enable") == 0 || strcmp(value, "on") == 0) { + keybinding->data.i = 1; + } else if(strcmp(value, "disable") == 0 || strcmp(value, "off") == 0) { + keybinding->data.i = 0; + } else { + *errstr = log_error("Invalid option \"%s\" for \"smart_gaps\". Expected \"enable\", \"disable\", \"on\", or \"off\"", value); + return -1; + } } else if(strcmp(action, "output") == 0) { keybinding->action = KEYBINDING_CONFIGURE_OUTPUT; keybinding->data.o_cfg = parse_output_config(&saveptr, errstr); diff --git a/server.h b/server.h index b2ede85..8ffd74b 100644 --- a/server.h +++ b/server.h @@ -84,6 +84,7 @@ struct nedm_server { uint32_t tiles_curr_id; uint32_t xcursor_size; uint32_t gap_size; + bool smart_gaps; }; void diff --git a/view.c b/view.c index ed68d67..446521b 100644 --- a/view.c +++ b/view.c @@ -80,10 +80,12 @@ void view_maximize(struct nedm_view *view, struct nedm_tile *tile) { uint32_t gap = view->workspace->output->server->gap_size; - // Smart gaps: only apply gaps if there are multiple views in the workspace - uint32_t view_count = wl_list_length(&view->workspace->views); - if (view_count <= 1) { - gap = 0; + // Smart gaps: only apply gaps if there are multiple views in the workspace (when enabled) + if (view->workspace->output->server->smart_gaps) { + uint32_t view_count = wl_list_length(&view->workspace->views); + if (view_count <= 1) { + gap = 0; + } } // Apply gap offset to position