Remove tab limit: growable apps array (drop MAX_APPS and dead MAX_WIN defines)
This commit is contained in:
parent
18653c9031
commit
49db6e9834
1 changed files with 30 additions and 6 deletions
|
|
@ -67,9 +67,7 @@
|
|||
#include <wlr/types/wlr_xdg_shell.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
||||
#define MAX_APPS 8
|
||||
#define MAX_WIN_W 2560
|
||||
#define MAX_WIN_H 1600
|
||||
/* server.apps grows as needed; there is no tab limit. */
|
||||
|
||||
/* ===================== Server-side (wlroots) state ===================== */
|
||||
|
||||
|
|
@ -109,8 +107,9 @@ struct tabbed_server {
|
|||
struct wl_listener frame;
|
||||
|
||||
struct wlr_xdg_toplevel *active;
|
||||
struct tabbed_app *apps[MAX_APPS];
|
||||
struct tabbed_app **apps;
|
||||
int num_apps;
|
||||
int apps_cap;
|
||||
|
||||
struct xkb_context *xkb_ctx;
|
||||
struct xkb_keymap *xkb_keymap;
|
||||
|
|
@ -261,6 +260,18 @@ static void remove_socket_file(void) {
|
|||
unlink(lock_path);
|
||||
}
|
||||
|
||||
/* Grow server.apps to hold at least n entries. Returns 0 on success, -1 on
|
||||
allocation failure. The buffer is freed in shutdown_cleanup(). */
|
||||
static int apps_ensure_cap(int n) {
|
||||
if (n <= server.apps_cap) return 0;
|
||||
struct tabbed_app **grown =
|
||||
realloc(server.apps, (size_t)n * sizeof(*grown));
|
||||
if (!grown) return -1;
|
||||
server.apps = grown;
|
||||
server.apps_cap = n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Full shutdown of the nested session: take down the clients first, then
|
||||
free our own allocations and exit. Guarded so the various close paths
|
||||
(host window close, last tab closed) only run once. */
|
||||
|
|
@ -272,6 +283,8 @@ static void shutdown_cleanup(void) {
|
|||
free(server.apps[i]->cmd);
|
||||
free(server.apps[i]);
|
||||
}
|
||||
free(server.apps);
|
||||
server.apps = NULL;
|
||||
if (server.xkb_keymap) xkb_keymap_unref(server.xkb_keymap);
|
||||
if (server.xkb_ctx) xkb_context_unref(server.xkb_ctx);
|
||||
remove_socket_file();
|
||||
|
|
@ -731,7 +744,7 @@ static void handle_new_toplevel(struct wl_listener *listener, void *data) {
|
|||
top and stays reachable via tab cycling. Place the new tab right
|
||||
after the tab that created it (protocol parent, else the active
|
||||
tab); fall back to the far right if neither can be identified. */
|
||||
if (server.num_apps >= MAX_APPS) return;
|
||||
if (apps_ensure_cap(server.num_apps + 1) != 0) return;
|
||||
app = calloc(1, sizeof(*app));
|
||||
if (!app) return;
|
||||
app->pid = -1;
|
||||
|
|
@ -2129,10 +2142,21 @@ int main(int argc, char *argv[]) {
|
|||
remove_socket_file();
|
||||
return 1;
|
||||
}
|
||||
if (total_apps > MAX_APPS) total_apps = MAX_APPS;
|
||||
server.apps = calloc((size_t)total_apps, sizeof(*server.apps));
|
||||
if (!server.apps) {
|
||||
fprintf(stderr, "tabbed-wlroots: out of memory for %d apps\n",
|
||||
total_apps);
|
||||
remove_socket_file();
|
||||
return 1;
|
||||
}
|
||||
server.apps_cap = total_apps;
|
||||
|
||||
for (int i = 0; i < total_apps; i++) {
|
||||
struct tabbed_app *app = calloc(1, sizeof(*app));
|
||||
if (!app) {
|
||||
remove_socket_file();
|
||||
return 1;
|
||||
}
|
||||
app->cmd = strdup(argv[i + 1]);
|
||||
app->pid = -1;
|
||||
server.apps[i] = app;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue