diff options
| author | Abhinav <abhinav.prsai@gmail.com> | 2025-07-17 18:49:59 +0100 |
|---|---|---|
| committer | Abhinav <abhinav.prsai@gmail.com> | 2025-07-17 18:49:59 +0100 |
| commit | 26a1b7926a73592192e98f7238f14adee1758ccf (patch) | |
| tree | d3d31898bedd97d6fc72e5a7c55e1dea2746df40 /src | |
| parent | 13ba153eb9c602d2e4e0641fafd7945810fe5997 (diff) | |
add start_fullscreen
now windows specifed can by default start fullscreened.
Diffstat (limited to 'src')
| -rw-r--r-- | src/defs.h | 1 | ||||
| -rw-r--r-- | src/parser.c | 54 | ||||
| -rw-r--r-- | src/sxwm.c | 42 |
3 files changed, 97 insertions, 0 deletions
@@ -104,6 +104,7 @@ typedef struct { Bool new_win_master; Binding binds[256]; char **should_float[256]; + char **start_fullscreen[256]; char **can_swallow[256]; char **can_be_swallowed[256]; char **scratchpads[32]; diff --git a/src/parser.c b/src/parser.c index 9e82c08..86d24a9 100644 --- a/src/parser.c +++ b/src/parser.c @@ -529,6 +529,60 @@ found: } } } + else if (!strcmp(key, "start_fullscreen")) { + char *comment = strchr(rest, '#'); + size_t len = comment ? (size_t)(comment - rest) : strlen(rest); + if (len >= sizeof(line)) { + len = sizeof(line) - 1; + } + + char win[sizeof(line)]; + snprintf(win, sizeof(win), "%.*s", (int)len, rest); + + char *final = strip(win); + char *comma_ptr; + char *comma = strtok_r(final, ",", &comma_ptr); + + int start_fullscreen_idx = 0; + /* find first empty slot */ + for (int i = 0; i < 256; i++) { + if (!cfg->start_fullscreen[i]) { + start_fullscreen_idx = i; + break; + } + } + + /* store each comma separated value in a separate row */ + while (comma && start_fullscreen_idx < 256) { + comma = strip(comma); + if (*comma == '"') { + comma++; + } + char *end = comma + strlen(comma) - 1; + if (*end == '"') { + *end = '\0'; + } + + char *dup = strdup(comma); + if (!dup) { + fprintf(stderr, "sxwmrc:%d: failed to allocate memory\n", lineno); + goto cleanup_file; + } + + cfg->start_fullscreen[start_fullscreen_idx] = malloc(2 * sizeof(char *)); + if (!cfg->start_fullscreen[start_fullscreen_idx]) { + free(dup); + fprintf(stderr, "sxwmrc:%d: failed to allocate memory\n", lineno); + goto cleanup_file; + } + + /* store each program's name in its own row at index 0 */ + cfg->start_fullscreen[start_fullscreen_idx][0] = dup; + cfg->start_fullscreen[start_fullscreen_idx][1] = NULL; + start_fullscreen_idx++; + comma = strtok_r(NULL, ",", &comma_ptr); + } + } else { fprintf(stderr, "sxwmrc:%d: unknown option '%s'\n", lineno, key); } @@ -104,6 +104,7 @@ void update_struts(void); void update_workarea(void); void warp_cursor(Client *c); Bool window_should_float(Window w); +Bool window_should_start_fullscreen(Window w); int xerr(Display *dpy, XErrorEvent *ee); void xev_case(XEvent *xev); #include "config.h" @@ -1176,6 +1177,11 @@ void hdl_map_req(XEvent *xev) c->floating = True; } + if (window_should_start_fullscreen(w)) { + c->fullscreen = True; + c->floating = False; + } + /* center floating windows & set border */ if (c->floating && !c->fullscreen) { int w_ = MAX(c->w, 64), h_ = MAX(c->h, 64); @@ -1267,6 +1273,11 @@ void hdl_map_req(XEvent *xev) XMapWindow(dpy, w); c->mapped = True; + if (c->fullscreen) { + int m = c->mon; + XSetWindowBorderWidth(dpy, w, 0); + XMoveResizeWindow(dpy, w, mons[m].x, mons[m].y, mons[m].w, mons[m].h); + } set_frame_extents(w); if (user_config.new_win_focus) { @@ -1526,6 +1537,7 @@ void init_defaults(void) default_config.can_be_swallowed[i] = NULL; default_config.can_swallow[i] = NULL; default_config.open_in_workspace[i] = NULL; + default_config.start_fullscreen[i] = NULL; } default_config.motion_throttle = 60; @@ -1783,6 +1795,13 @@ void reload_config(void) free(user_config.open_in_workspace[i]); user_config.open_in_workspace[i] = NULL; } + if (user_config.start_fullscreen[i]) { + if (user_config.start_fullscreen[i][0]) { + free(user_config.start_fullscreen[i][0]); + } + free(user_config.start_fullscreen[i]); + user_config.start_fullscreen[i] = NULL; + } } /* free should_float arrays */ @@ -2693,6 +2712,29 @@ void warp_cursor(Client *c) XSync(dpy, False); } +Bool window_should_start_fullscreen(Window w) +{ + XClassHint ch; + if (XGetClassHint(dpy, w, &ch)) { + for (int i = 0; i < 256; i++) { + if (!user_config.start_fullscreen[i] || !user_config.start_fullscreen[i][0]) { + break; + } + + if ((ch.res_class && !strcmp(ch.res_class, user_config.start_fullscreen[i][0])) || + (ch.res_name && !strcmp(ch.res_name, user_config.start_fullscreen[i][0]))) { + XFree(ch.res_class); + XFree(ch.res_name); + return True; + } + } + XFree(ch.res_class); + XFree(ch.res_name); + } + + return False; +} + int xerr(Display *dpy, XErrorEvent *ee) { /* ignore noise & non fatal errors */ |
