diff options
Diffstat (limited to '')
| -rw-r--r-- | dwl.c | 195 |
1 files changed, 165 insertions, 30 deletions
@@ -101,6 +101,7 @@ typedef struct { const Arg arg; } Button; +typedef struct Pertag Pertag; typedef struct Monitor Monitor; typedef struct { /* Must keep these three elements in this order */ @@ -198,6 +199,7 @@ struct Monitor { struct wlr_box w; /* window area, layout-relative */ struct wl_list layers[4]; /* LayerSurface.link */ const Layout *lt[2]; + Pertag *pertag; unsigned int seltags; unsigned int sellt; uint32_t tagset[2]; @@ -246,6 +248,7 @@ static void arrange(Monitor *m); static void arrangelayer(Monitor *m, struct wl_list *list, struct wlr_box *usable_area, int exclusive); static void arrangelayers(Monitor *m); +static void autostartexec(void); static void axisnotify(struct wl_listener *listener, void *data); static void buttonpress(struct wl_listener *listener, void *data); static void chvt(const Arg *arg); @@ -312,7 +315,7 @@ static void rendermon(struct wl_listener *listener, void *data); static void requestdecorationmode(struct wl_listener *listener, void *data); static void requeststartdrag(struct wl_listener *listener, void *data); static void requestmonstate(struct wl_listener *listener, void *data); -static void resize(Client *c, struct wlr_box geo, int interact); +static void resize(Client *c, struct wlr_box geo, int interact, int draw_borders); static void run(char *startup_cmd); static void setcursor(struct wl_listener *listener, void *data); static void setcursorshape(struct wl_listener *listener, void *data); @@ -424,6 +427,17 @@ static xcb_atom_t netatom[NetLast]; /* attempt to encapsulate suck into one file */ #include "client.h" +static pid_t *autostart_pids; +static size_t autostart_len; + +struct Pertag { + unsigned int curtag, prevtag; /* current and previous tag */ + int nmasters[TAGCOUNT + 1]; /* number of windows in master area */ + float mfacts[TAGCOUNT + 1]; /* mfacts per tag */ + unsigned int sellts[TAGCOUNT + 1]; /* selected layouts */ + const Layout *ltidxs[TAGCOUNT + 1][2]; /* matrix of tags and layouts indexes */ +}; + /* function implementations */ void applybounds(Client *c, struct wlr_box *bbox) @@ -470,6 +484,8 @@ applyrules(Client *c) } } } + c->geom.x = (mon->w.width - c->geom.width) / 2 + mon->m.x; + c->geom.y = (mon->w.height - c->geom.height) / 2 + mon->m.y; setmon(c, mon, newtags); } @@ -559,6 +575,27 @@ arrangelayers(Monitor *m) } void +autostartexec(void) { + const char *const *p; + size_t i = 0; + + /* count entries */ + for (p = autostart; *p; autostart_len++, p++) + while (*++p); + + autostart_pids = calloc(autostart_len, sizeof(pid_t)); + for (p = autostart; *p; i++, p++) { + if ((autostart_pids[i] = fork()) == 0) { + setsid(); + execvp(*p, (char *const *)p); + die("dwl: execvp %s:", *p); + } + /* skip arguments */ + while (*++p); + } +} + +void axisnotify(struct wl_listener *listener, void *data) { /* This event is forwarded by the cursor when a pointer emits an axis event, @@ -655,11 +692,21 @@ checkidleinhibitor(struct wlr_surface *exclude) void cleanup(void) { + size_t i; #ifdef XWAYLAND wlr_xwayland_destroy(xwayland); xwayland = NULL; #endif wl_display_destroy_clients(dpy); + + /* kill child processes */ + for (i = 0; i < autostart_len; i++) { + if (0 < autostart_pids[i]) { + kill(autostart_pids[i], SIGTERM); + waitpid(autostart_pids[i], NULL, 0); + } + } + if (child_pid > 0) { kill(child_pid, SIGTERM); waitpid(child_pid, NULL, 0); @@ -698,6 +745,7 @@ cleanupmon(struct wl_listener *listener, void *data) wlr_output_layout_remove(output_layout, m->wlr_output); wlr_scene_output_destroy(m->scene_output); + free(m->pertag); closemon(m); wlr_scene_node_destroy(&m->fullscreen_bg->node); free(m); @@ -721,7 +769,7 @@ closemon(Monitor *m) wl_list_for_each(c, &clients, link) { if (c->isfloating && c->geom.x > m->m.width) resize(c, (struct wlr_box){.x = c->geom.x - m->w.width, .y = c->geom.y, - .width = c->geom.width, .height = c->geom.height}, 0); + .width = c->geom.width, .height = c->geom.height}, 0, 1); if (c->mon == m) setmon(c, selmon, c->tags); } @@ -756,8 +804,12 @@ commitnotify(struct wl_listener *listener, void *data) { Client *c = wl_container_of(listener, c, commit); - if (client_surface(c)->mapped && c->mon) - resize(c, c->geom, (c->isfloating && !c->isfullscreen)); + if (client_surface(c)->mapped && c->mon) { + if (c->mon && c->mon->lt[c->mon->sellt]->arrange && !c->isfullscreen && !c->isfloating) + c->mon->lt[c->mon->sellt]->arrange(c->mon); + else + resize(c, c->geom, (c->isfloating && !c->isfullscreen), (c->isfloating && !c->isfullscreen)); + } /* mark a pending resize as completed */ if (c->resize && c->resize <= c->surface.xdg->current.configure_serial) @@ -915,6 +967,18 @@ createmon(struct wl_listener *listener, void *data) wl_list_insert(&mons, &m->link); printstatus(); + m->pertag = calloc(1, sizeof(Pertag)); + m->pertag->curtag = m->pertag->prevtag = 1; + + for (i = 0; i <= TAGCOUNT; i++) { + m->pertag->nmasters[i] = m->nmaster; + m->pertag->mfacts[i] = m->mfact; + + m->pertag->ltidxs[i][0] = m->lt[0]; + m->pertag->ltidxs[i][1] = m->lt[1]; + m->pertag->sellts[i] = m->sellt; + } + /* The xdg-protocol specifies: * * If the fullscreened surface is not opaque, the compositor must make @@ -1000,11 +1064,10 @@ createpointer(struct wlr_pointer *pointer) libinput_device_config_tap_set_drag_enabled(device, tap_and_drag); libinput_device_config_tap_set_drag_lock_enabled(device, drag_lock); libinput_device_config_tap_set_button_map(device, button_map); + if (libinput_device_config_scroll_has_natural_scroll(device)) + libinput_device_config_scroll_set_natural_scroll_enabled(device, natural_scrolling); } - if (libinput_device_config_scroll_has_natural_scroll(device)) - libinput_device_config_scroll_set_natural_scroll_enabled(device, natural_scrolling); - if (libinput_device_config_dwt_is_available(device)) libinput_device_config_dwt_set_enabled(device, disable_while_typing); @@ -1371,18 +1434,31 @@ void handlesig(int signo) { if (signo == SIGCHLD) { -#ifdef XWAYLAND siginfo_t in; /* wlroots expects to reap the XWayland process itself, so we * use WNOWAIT to keep the child waitable until we know it's not * XWayland. */ while (!waitid(P_ALL, 0, &in, WEXITED|WNOHANG|WNOWAIT) && in.si_pid - && (!xwayland || in.si_pid != xwayland->server->pid)) - waitpid(in.si_pid, NULL, 0); -#else - while (waitpid(-1, NULL, WNOHANG) > 0); +#ifdef XWAYLAND + && (!xwayland || in.si_pid != xwayland->server->pid) #endif + ) { + pid_t *p, *lim; + waitpid(in.si_pid, NULL, 0); + if (in.si_pid == child_pid) + child_pid = -1; + if (!(p = autostart_pids)) + continue; + lim = &p[autostart_len]; + + for (; p < lim; p++) { + if (*p == in.si_pid) { + *p = -1; + break; + } + } + } } else if (signo == SIGINT || signo == SIGTERM) { quit(NULL); } @@ -1393,7 +1469,7 @@ incnmaster(const Arg *arg) { if (!arg || !selmon) return; - selmon->nmaster = MAX(selmon->nmaster + arg->i, 0); + selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0); arrange(selmon); } @@ -1605,7 +1681,11 @@ mapnotify(struct wl_listener *listener, void *data) c->geom.height += 2 * c->bw; /* Insert this client into client lists. */ - wl_list_insert(&clients, &c->link); + if (clients.prev) + // tile at the bottom + wl_list_insert(clients.prev, &c->link); + else + wl_list_insert(&clients, &c->link); wl_list_insert(&fstack, &c->flink); /* Set initial monitor, tags, floating status, and focus: @@ -1654,7 +1734,7 @@ monocle(Monitor *m) wl_list_for_each(c, &clients, link) { if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen) continue; - resize(c, m->w, 0); + resize(c, m->w, 0, !smartborders); n++; } if (n) @@ -1734,11 +1814,11 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d if (cursor_mode == CurMove) { /* Move the grabbed client to the new position. */ resize(grabc, (struct wlr_box){.x = ROUND(cursor->x) - grabcx, .y = ROUND(cursor->y) - grabcy, - .width = grabc->geom.width, .height = grabc->geom.height}, 1); + .width = grabc->geom.width, .height = grabc->geom.height}, 1, 1); return; } else if (cursor_mode == CurResize) { resize(grabc, (struct wlr_box){.x = grabc->geom.x, .y = grabc->geom.y, - .width = ROUND(cursor->x) - grabc->geom.x, .height = ROUND(cursor->y) - grabc->geom.y}, 1); + .width = ROUND(cursor->x) - grabc->geom.x, .height = ROUND(cursor->y) - grabc->geom.y}, 1, 1); return; } @@ -2032,12 +2112,13 @@ requestmonstate(struct wl_listener *listener, void *data) } void -resize(Client *c, struct wlr_box geo, int interact) +resize(Client *c, struct wlr_box geo, int interact, int draw_borders) { struct wlr_box *bbox = interact ? &sgeom : &c->mon->w; struct wlr_box clip; client_set_bounds(c, geo.width, geo.height); c->geom = geo; + c->bw = draw_borders ? borderpx : 0; applybounds(c, bbox); /* Update scene-graph, including borders */ @@ -2073,6 +2154,7 @@ run(char *startup_cmd) die("startup: backend_start"); /* Now that the socket exists and the backend is started, run the startup command */ + autostartexec(); if (startup_cmd) { int piperw[2]; if (pipe(piperw) < 0) @@ -2154,6 +2236,8 @@ setfloating(Client *c, int floating) wlr_scene_node_reparent(&c->scene->node, layers[c->isfullscreen || (p && p->isfullscreen) ? LyrFS : c->isfloating ? LyrFloat : LyrTile]); + if (c->isfloating && !c->bw) + resize(c, c->mon->m, 0, 1); arrange(c->mon); printstatus(); } @@ -2171,11 +2255,11 @@ setfullscreen(Client *c, int fullscreen) if (fullscreen) { c->prev = c->geom; - resize(c, c->mon->m, 0); + resize(c, c->mon->m, 0, 0); } else { /* restore previous size instead of arrange for floating windows since * client positions are set by the user and cannot be recalculated */ - resize(c, c->prev, 0); + resize(c, c->prev, 0, 1); } arrange(c->mon); printstatus(); @@ -2198,10 +2282,16 @@ setlayout(const Arg *arg) if (!selmon) return; if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) - selmon->sellt ^= 1; + selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag] ^= 1; if (arg && arg->v) - selmon->lt[selmon->sellt] = (Layout *)arg->v; + selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v; strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, LENGTH(selmon->ltsymbol)); + if (!selmon->lt[selmon->sellt]->arrange) { + /* floating layout, draw borders around all clients */ + Client *c; + wl_list_for_each(c, &clients, link) + resize(c, c->mon->m, 0, 1); + } arrange(selmon); printstatus(); } @@ -2217,7 +2307,7 @@ setmfact(const Arg *arg) f = arg->f < 1.0f ? arg->f + selmon->mfact : arg->f - 1.0f; if (f < 0.1 || f > 0.9) return; - selmon->mfact = f; + selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f; arrange(selmon); } @@ -2236,7 +2326,7 @@ setmon(Client *c, Monitor *m, uint32_t newtags) arrange(oldmon); if (m) { /* Make sure window actually overlaps with the monitor */ - resize(c, c->geom, 0); + resize(c, c->geom, 0, 1); c->tags = newtags ? newtags : m->tagset[m->seltags]; /* assign tags of target monitor */ setfullscreen(c, c->isfullscreen); /* This will call arrange(c->mon) */ setfloating(c, c->isfloating); @@ -2573,7 +2663,7 @@ void tile(Monitor *m) { unsigned int mw, my, ty; - int i, n = 0; + int i, n = 0, draw_borders = 1; Client *c; wl_list_for_each(c, &clients, link) @@ -2582,6 +2672,9 @@ tile(Monitor *m) if (n == 0) return; + if (n == smartborders) + draw_borders = 0; + if (n > m->nmaster) mw = m->nmaster ? ROUND(m->w.width * m->mfact) : 0; else @@ -2592,11 +2685,11 @@ tile(Monitor *m) continue; if (i < m->nmaster) { resize(c, (struct wlr_box){.x = m->w.x, .y = m->w.y + my, .width = mw, - .height = (m->w.height - my) / (MIN(n, m->nmaster) - i)}, 0); + .height = (m->w.height - my) / (MIN(n, m->nmaster) - i)}, 0, draw_borders); my += c->geom.height; } else { resize(c, (struct wlr_box){.x = m->w.x + mw, .y = m->w.y + ty, - .width = m->w.width - mw, .height = (m->w.height - ty) / (n - i)}, 0); + .width = m->w.width - mw, .height = (m->w.height - ty) / (n - i)}, 0, draw_borders); ty += c->geom.height; } i++; @@ -2638,9 +2731,29 @@ void toggleview(const Arg *arg) { uint32_t newtagset; + size_t i; if (!(newtagset = selmon ? selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK) : 0)) return; + if (newtagset == ~0) { + selmon->pertag->prevtag = selmon->pertag->curtag; + selmon->pertag->curtag = 0; + } + + /* test if the user did not select the same tag */ + if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) { + selmon->pertag->prevtag = selmon->pertag->curtag; + for (i = 0; !(newtagset & 1 << i); i++) ; + selmon->pertag->curtag = i + 1; + } + + /* apply settings for this view */ + selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag]; + selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag]; + selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag]; + selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt]; + selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1]; + selmon->tagset[selmon->seltags] = newtagset; focusclient(focustop(selmon), 1); arrange(selmon); @@ -2765,7 +2878,7 @@ updatemons(struct wl_listener *listener, void *data) arrange(m); /* make sure fullscreen clients have the right size */ if ((c = focustop(m)) && c->isfullscreen) - resize(c, m->m, 0); + resize(c, m->m, 0, 0); /* Try to re-set the gamma LUT when updating monitors, * it's only really needed when enabling a disabled output, but meh. */ @@ -2825,11 +2938,33 @@ urgent(struct wl_listener *listener, void *data) void view(const Arg *arg) { + size_t i, tmptag; + if (!selmon || (arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) return; selmon->seltags ^= 1; /* toggle sel tagset */ - if (arg->ui & TAGMASK) + if (arg->ui & TAGMASK) { selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; + selmon->pertag->prevtag = selmon->pertag->curtag; + + if (arg->ui == ~0) + selmon->pertag->curtag = 0; + else { + for (i = 0; !(arg->ui & 1 << i); i++) ; + selmon->pertag->curtag = i + 1; + } + } else { + tmptag = selmon->pertag->prevtag; + selmon->pertag->prevtag = selmon->pertag->curtag; + selmon->pertag->curtag = tmptag; + } + + selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag]; + selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag]; + selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag]; + selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt]; + selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1]; + focusclient(focustop(selmon), 1); arrange(selmon); printstatus(); @@ -2962,7 +3097,7 @@ configurex11(struct wl_listener *listener, void *data) } if (c->isfloating || client_is_unmanaged(c)) resize(c, (struct wlr_box){.x = event->x, .y = event->y, - .width = event->width + c->bw * 2, .height = event->height + c->bw * 2}, 0); + .width = event->width + c->bw * 2, .height = event->height + c->bw * 2}, 0, 1); else arrange(c->mon); } |
