From: Mike Lowis Date: Thu, 1 Aug 2024 16:00:25 +0000 (-0400) Subject: remove remnants of tiling and monitor management. let's get stacking working again... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=9927130713605ac9f20d1c2ef1c60ae2db5f29eb;p=proto%2Fanvil.git remove remnants of tiling and monitor management. let's get stacking working again. Then add tiling, workspaces and monitors --- diff --git a/anvil.c b/anvil.c index 236433b..58434db 100644 --- a/anvil.c +++ b/anvil.c @@ -87,43 +87,43 @@ static void xbtnpress(XEvent* e) printf("BTN_DN(w: 0x%lx s: %d x: %d y: %d rx: %d ry: %d)\n", ev->window, ev->state, ev->x, ev->y, ev->x_root, ev->y_root); X.start_x = ev->x_root, X.start_y = ev->y_root; X.last_x = ev->x_root, X.last_y = ev->y_root; - Location loc = {0}; - if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window)) - { - Client* c = loc.client; - if (ev->y < MIN_HEIGHT) - { - X.edge = E_TOP; - } - else if (ev->y_root > (c->y + c->h - BORDER_WIDTH)) - { - X.edge = E_BOTTOM; - } - else if (ev->x < BORDER_WIDTH) - { - X.edge = E_LEFT; - } - else if (ev->x_root > (c->x + c->w - BORDER_WIDTH)) - { - X.edge = E_RIGHT; - } - else - { - X.edge = E_NONE; - } - mouse_down(ev, &loc); - } +// Location loc = {0}; +// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window)) +// { +// Client* c = loc.client; +// if (ev->y < MIN_HEIGHT) +// { +// X.edge = E_TOP; +// } +// else if (ev->y_root > (c->y + c->h - BORDER_WIDTH)) +// { +// X.edge = E_BOTTOM; +// } +// else if (ev->x < BORDER_WIDTH) +// { +// X.edge = E_LEFT; +// } +// else if (ev->x_root > (c->x + c->w - BORDER_WIDTH)) +// { +// X.edge = E_RIGHT; +// } +// else +// { +// X.edge = E_NONE; +// } +// mouse_down(ev, &loc); +// } } static void xbtnrelease(XEvent* e) { XButtonEvent* ev = &(e->xbutton); printf("BTN_UP(w: 0x%lx x: %d y: %d rx: %d ry: %d)\n", ev->window, ev->x, ev->y, ev->x_root, ev->y_root); - Location loc = {0}; - if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window)) - { - mouse_up(ev, &loc); - } +// Location loc = {0}; +// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window)) +// { +// mouse_up(ev, &loc); +// } X.mode = M_IDLE; XUngrabPointer(X.disp, CurrentTime); } @@ -134,11 +134,11 @@ static void xbtnmotion(XEvent* e) XMotionEvent *ev = &e->xmotion; printf("BTN_MV(w: 0x%lx x: %d y: %d rx: %d ry: %d)\n", ev->window, ev->x, ev->y, ev->x_root, ev->y_root); while (XCheckTypedWindowEvent(X.disp, ev->window, ev->type, e)); - Location loc = {0}; - if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window)) - { - mouse_drag(ev, &loc); - } +// Location loc = {0}; +// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window)) +// { +// mouse_drag(ev, &loc); +// } X.last_x = ev->x_root, X.last_y = ev->y_root; } @@ -240,7 +240,7 @@ static void xkeypress(XEvent* e) { XKeyEvent* ev = &(e->xkey); printf("KEY_DN(w: 0x%lx)\n", ev->window); - keys_run(ev); + Keys_Process(ev); } static void init_cursors(void) @@ -307,9 +307,9 @@ int main(void) check_for_wm(); init_cursors(); init_font(); - mons_init(); - client_initall(); - keys_init(); +// mons_init(); + Client_InitAll(); + Keys_Init(); atoms_init(); /* setup window life-cycle management event handlers */ diff --git a/anvil.h b/anvil.h index c63df74..4675ce5 100644 --- a/anvil.h +++ b/anvil.h @@ -145,8 +145,8 @@ void* list_last(void* list); for (val = list; (val != NULL) && !(cond); val = val->next) /* keys.c */ -void keys_init(void); -void keys_run(XKeyEvent* ev); +void Keys_Init(void); +void Keys_Process(XKeyEvent* ev); /* mons.c */ void mons_init(void); @@ -167,15 +167,15 @@ void mons_tilemove(Location* loc, int hdiff); void mons_activate(Window win); /* client.c */ +void Client_InitAll(void); void Client_Create(Window win); void Client_Destroy(Window win); void Client_Show(Window win); void Client_Hide(Window win); +void Client_MoveResize(Client* c); -void client_initall(void); Client* client_add(Window win, XWindowAttributes* attr); void client_draw(Client* c); -void client_adjust(Client* c); void client_move(Client* c, int xdiff, int ydiff); void client_resize(Client* c, int xdiff, int ydiff); void client_close(Client* c); diff --git a/build.sh b/build.sh index 8e8f4a6..85cab23 100755 --- a/build.sh +++ b/build.sh @@ -4,7 +4,8 @@ incpath="-I/usr/X11R6/include -Itest/" libpath="-L/usr/X11R6/lib" libs="-lX11 -lXinerama -lm" -cc $cflags $incpath $libpath -o anvil ./*.c $libs && ./atf $incpath test/*.c +cc $cflags $incpath $libpath -o anvil ./*.c $libs \ + # && ./atf $incpath test/*.c error="$?" grep -n 'TODO' ./*.[ch]| sed -e 's/: \+/: /' -e 's/\/\* *//g' -e 's/ *\*\/$//' -e 's/TODO: *//' diff --git a/client.c b/client.c index 87882e0..50c76e3 100644 --- a/client.c +++ b/client.c @@ -277,7 +277,7 @@ static Client* FindClient(Window win) -void client_initall(void) +void Client_InitAll(void) { // /* TODO: Find all top-level windows and register them correctly // @@ -330,7 +330,7 @@ Client* client_add(Window win, XWindowAttributes* attr) /* Map the window and draw the frame */ XAddToSaveSet(X.disp, c->win); - mons_addclient(c); +// mons_addclient(c); client_show(c, 1); Redraw(c); return c; @@ -342,14 +342,14 @@ void client_move(Client* c, int xdiff, int ydiff) { c->x += xdiff; c->y += ydiff; - client_adjust(c); + Client_MoveResize(c); } void client_resize(Client* c, int xdiff, int ydiff) { c->w += xdiff; c->h += ydiff; - client_adjust(c); + Client_MoveResize(c); } void client_close(Client* c) @@ -387,7 +387,7 @@ void client_show(Client* c, int show) void client_shade(Client* c) { client_setshade(c, ((c->flags & F_SHADED) ? 0 : 1)); - client_adjust(c); + Client_MoveResize(c); } void client_setshade(Client* c, int shade) diff --git a/keys.c b/keys.c index 3a91299..709aa44 100644 --- a/keys.c +++ b/keys.c @@ -25,12 +25,14 @@ static void quit(Arg* arg) static void set_workspace(Arg* arg) { - mons_wspace(arg->i); + (void)arg; +// mons_wspace(arg->i); } static void to_workspace(Arg* arg) { - mons_towspace(Focused, arg->i); + (void)arg; +// mons_towspace(Focused, arg->i); } static void runcmd(Arg *arg) @@ -57,23 +59,23 @@ static void killwin(Arg *arg) static void coljoin(Arg *arg) { (void)arg; - mons_coljoin(); +// mons_coljoin(); } static void colsplit(Arg *arg) { (void)arg; - mons_colsplit(); +// mons_colsplit(); } static void togfloat(Arg *arg) { (void)arg; - Location loc; - if (Focused && mons_find(Focused->win, &loc)) - { - mons_togglefloat(&loc); - } +// Location loc; +// if (Focused && mons_find(Focused->win, &loc)) +// { +// mons_togglefloat(&loc); +// } } static Key keys[] = { @@ -110,7 +112,7 @@ static Key keys[] = { { MODKEY|ShiftMask, XK_0, to_workspace, { .i = 9 } }, }; -void keys_init(void) +void Keys_Init(void) { KeyCode code; for (unsigned int i = 0; i < sizeof(keys)/sizeof(keys[0]); i++) @@ -122,7 +124,7 @@ void keys_init(void) } } -void keys_run(XKeyEvent* ev) +void Keys_Process(XKeyEvent* ev) { KeySym keysym = XkbKeycodeToKeysym(X.disp, ev->keycode, 0, 0); for (unsigned int i = 0; i < sizeof(keys)/sizeof(keys[0]); i++) diff --git a/mons.c b/mons.c deleted file mode 100644 index 6e2dd6a..0000000 --- a/mons.c +++ /dev/null @@ -1,491 +0,0 @@ -#include "anvil.h" -#include - -static Monitor* pickmon(void); -static Column* pickcol(Workspace* wspace, int relx); -static void client_visibility(Workspace* wspace, int show); -static Client* client_find(Client* clients, Window win); -static void add_client(Monitor* mon, Client* c, int ptrx); -static void remove_client(Location* loc, Client* c); -//static void adjust_all(Column* col, int xoff); -static void change_wspace(Monitor* mon, Workspace* wspace); - -//static int min_col_width(Monitor* mon) -//{ -// return (int)(mon->w * MIN_COL_FACT); -//} - -void mons_init(void) -{ - int nmons; - check( XineramaIsActive(X.disp), "Xinerama extension is required"); - XineramaScreenInfo* mons = XineramaQueryScreens(X.disp, &nmons); - for (int i = 0; i < nmons; i++) - { - Monitor* m = &Monitors[i]; - m->x = mons[i].x_org; - m->y = mons[i].y_org; - m->w = mons[i].width; - m->h = mons[i].height; - m->midx = m->x + m->w/2; - m->midy = m->y + m->h/2; - m->wspace = &Workspaces[i]; - m->wspace->ncolumns = 1; - } - Num_Monitors = nmons; - xfree(mons); -} - -void mons_layer(Monitor* mon) -{ - int nwins = 0; - Window* wins = NULL; - Client* c; - Workspace* wspace = mon->wspace; - - /* add all of the floating windows */ - LIST_FOR_EACH(c, wspace->floating) - { - wins = realloc(wins, ++nwins * sizeof(Window)); - wins[nwins-1] = c->frame; - } - - /* now lower all of the tiled windows */ - for (int i = 0; i < wspace->ncolumns; i++) - { - LIST_FOR_EACH(c, wspace->columns[i].clients) - { - wins = realloc(wins, ++nwins * sizeof(Window)); - wins[nwins-1] = c->frame; - } - } - - /* restack them and free the array */ - if (nwins) - { - XRestackWindows(X.disp, wins, nwins); - } - xfree(wins); -} - -/* adds a new client to the most appropriate monitor */ -void mons_addclient(Client* c) -{ - Monitor* mon = pickmon(); - add_client(mon, c, PtrX); - mouse_totitle(c); -} - -void mons_delclient(Location* loc) -{ - if (Focused == loc->client) - { - Focused = NULL; - } - remove_client(loc, loc->client); - xfree(loc->client->name); - XDestroyWindow(X.disp, loc->client->frame); - free(loc->client); -} - -void mons_togglefloat(Location* loc) -{ - remove_client(loc, loc->client); - if (loc->client->flags & (F_FLOATING)) - { - loc->client->flags &= ~F_FLOATING; - } - else - { - loc->client->flags |= F_FLOATING; - } - mons_addclient(loc->client); -} - -int mons_find(Window win, Location* loc) -{ - Monitor* mon = NULL; - Workspace* wspace = NULL; - Column* column = NULL; - Client* client = NULL; - - /* check if the window is withdrawn */ - client = client_find(Withdrawn, win); - - /* otherwise, check if it is on a workspace */ - if (!client) - { - for (int i = 0; i < MAX_WSPACE_COUNT; i++) - { - wspace = &Workspaces[i]; - - /* check if the window is floating first */ - client = client_find(wspace->floating, win); - - /* if not found, find the window in the columns */ - if (!client) - { - for (int c = 0; c < wspace->ncolumns; c++) - { - Column* col = &(wspace->columns[c]); - if ( (client = client_find(col->clients, win)) ) - { - column = col; - break; - } - } - } - } - } - - /* return the client location if we found it */ - if (client) - { - loc->monitor = mon; - loc->workspace = wspace; - loc->column = column; - loc->client = client; - return 1; - } - - return 0; -} - -/* find the best monitor to own the window by calculating the overlap */ -void mons_place(Client* c) -{ - Location loc; - int cleft = (c->x - BORDER_WIDTH); - int cright = (c->x + c->w + 2*BORDER_WIDTH); - int ctop = (c->y - BORDER_WIDTH); - int cbot = (c->y + c->h + 2*BORDER_WIDTH + TITLE_HEIGHT); - if (mons_find(c->win, &loc) && !loc.column) - { - int maxarea = 0; - Monitor *mon = NULL, *closest = NULL; - for (int i =0; i < Num_Monitors; i++) - { - mon = &Monitors[i]; - int left = max(cleft, mon->x); - int right = min(cright, mon->x + mon->w); - int top = max(ctop, mon->y); - int bot = min(cbot, mon->y + mon->h); - if (left < right && top < bot) - { - int area = (right - left) * (bot - top); - if (area > maxarea) - { - maxarea = area; - closest = mon; - } - } - } - /* if we changed monitors, make sure we update accordingly */ - if (closest && loc.monitor != closest) - { - loc.workspace->floating = list_del(loc.workspace->floating, c); - c->next = closest->wspace->floating; - closest->wspace->floating = c; - } - } -} - -void mons_wspace(int wsid) -{ - Monitor* mon = pickmon(); - change_wspace(mon, &Workspaces[wsid]); -} - -void mons_towspace(Client* c, int wsid) -{ - (void)c; - (void)wsid; -// TODO: rework how towspace works -// Location loc = {0}; -// if (mons_find(c->win, &loc)) -// { -// mouse_get(&PtrX, &PtrY); -// Workspace* wspace = &Workspaces[wsid]; -// if (wspace != loc.workspace) -// { -// remove_client(&loc, c); -// client_show(c, 0); -// Workspace* prev = &Workspaces[loc.monitor->wspace]; -// loc.monitor->wspace = wspace; -// add_client(loc.monitor, c, PtrX); -// loc.monitor->wspace = prev; -// } -// } -} - -void mons_raise(Monitor* mon, Client* c) -{ - mon->wspace->floating = list_del(mon->wspace->floating, c); - c->next = mon->wspace->floating; - mon->wspace->floating = c; - mons_layer(mon); -} - -void mons_lower(Monitor* mon, Client* c) -{ - mon->wspace->floating = list_del(mon->wspace->floating, c); - c->next = NULL; - if (mon->wspace->floating) - { - Client* curr = list_last(mon->wspace->floating); - curr->next = c; - } - else - { - mon->wspace->floating = c; - } - mons_layer(mon); -} - -void mons_colsplit(void) -{ -// TODO: implement column splitting -// Monitor* mon = pickmon(); -// Column* col = pickcol(mon->wspace, PtrX - mon->x); -// int next_empty = (col->next && !col->next->clients); -// if (col->clients && !next_empty && col->width >= 2*min_col_width(mon)) -// { -// Column* newcol = ecalloc(1, sizeof(Column)); -// newcol->width = col->width/2; -// col->width -= newcol->width; -// newcol->next = col->next; -// col->next = newcol; -// adjust_all(col, 0); -// } -} - -void mons_coljoin(void) -{ -// TODO: implement column joining -// Monitor* mon = pickmon(); -// Column* dest = pickcol(mon->wspace, PtrX - mon->x); -// Column* dead = dest->next; -// if (!dead) -// { -// dead = dest; -// dest = list_prev(mon->wspace->columns, dead); -// } -// -// if (dest && dead) -// { -// /* add the clients to the current col */ -// for (Client* c = dead->clients; c;) -// { -// Client* next = c->next; -// stacked_add(&(Location){mon, NULL, dest, c}); -// c = next; -// } -// dest->next = dead->next; -// dest->width += dead->width; -// free(dead); -// adjust_all(dest, 0); -// } -} - -void mons_coladjust(Monitor* mon, Column* col, int wdiff) -{ - (void)mon; - (void)col; - (void)wdiff; -// TODO: implement column resizing -// Column* neighbor = col->next; -// int minwidth = min_col_width(mon); -// if (X.edge == E_LEFT && mon->wspace->columns != col) -// { -// for (neighbor = mon->wspace->columns; neighbor && neighbor->next != col; neighbor = neighbor->next); -// int minadj = -(neighbor->width - minwidth); -// int maxadj = (col->width - minwidth); -// wdiff = min(max(minadj, wdiff), maxadj); -// neighbor->width += wdiff; -// col->width -= wdiff; -// adjust_all(col, wdiff); -// adjust_all(neighbor, 0); -// } -// else if (X.edge == E_RIGHT && col->next) -// { -// int minadj = -(col->width - minwidth); -// int maxadj = (neighbor->width - minwidth); -// wdiff = min(max(minadj, wdiff), maxadj); -// col->width += wdiff; -// neighbor->width -= wdiff; -// adjust_all(col, 0); -// adjust_all(neighbor, wdiff); -// } -// else -// { -// /* invalid edge */ -// } -} - -void mons_tilemove(Location* loc, int hdiff) -{ - Monitor* mon = pickmon(); - Column* col = pickcol(mon->wspace, PtrX - mon->x); - if (loc->monitor != mon || loc->column != col) - { - remove_client(loc, loc->client); - client_setshade(loc->client, 0); - loc->monitor = mon; - loc->column = col; - stacked_add(loc); - } - else - { - stacked_addheight(loc, hdiff); - } - mouse_totitle(loc->client); -} - -void mons_activate(Window win) -{ - Location loc; - if (mons_find(win, &loc)) - { - change_wspace(loc.monitor, loc.workspace); - if (!loc.column) - { - mons_raise(loc.monitor, loc.client); - } - } -} - -static Monitor* pickmon(void) -{ - mouse_get(&PtrX, &PtrY); - Monitor* monitor = NULL; - for (int i = 0; i < Num_Monitors; i++) - { - Monitor* mon = &Monitors[i]; - if ((mon->x <= PtrX && PtrX < mon->x+mon->w) && - (mon->y <= PtrY && PtrY < mon->y+mon->h)) - { - monitor = mon; - break; - } - } - monitor = (monitor ? monitor : &Monitors[0]); - return monitor; -} - -static Column* pickcol(Workspace* wspace, int relx) -{ - Column* col; - int left = 0, right = 0; - for (int i = 0; i < wspace->ncolumns; i++) - { - left = right, right += wspace->columns[i].width; - if (left <= relx && relx < right) - { - col = &wspace->columns[i]; - break; /* we found the column holding the mouse */ - } - } - return col; -} - -static void client_visibility(Workspace* wspace, int show) -{ - Column* col; - Client* client; - LIST_FOR_EACH(client, wspace->floating) - { - client_show(client, show); - } - for (int i = 0; i < wspace->ncolumns; i++) - { - col = &(wspace->columns[i]); - LIST_FOR_EACH(client, col->clients) - { - client_show(client, show); - } - } -} - -static Client* client_find(Client* clients, Window win) -{ - Client* client; - LIST_FOR_EACH_UNTIL(client, clients, - (client->frame == win || client->win == win)); - return client; -} - -static void add_client(Monitor* mon, Client* c, int ptrx) -{ - if (X.mode == M_INIT || c->flags & (F_DIALOG|F_FLOATING)) - { - c->next = mon->wspace->floating; - mon->wspace->floating = c; - c->x = mon->midx - c->w/2; - c->y = mon->midy - c->h/2; - client_adjust(c); - } - else - { - Column* col = NULL; - /* find first empty column, and fill that first */ - for (int i = 0; i < mon->wspace->ncolumns; i++) - { - if (mon->wspace->columns[i].clients == NULL) - { - col = &mon->wspace->columns[i]; - break; - } - } - - /* otherwise pick the column to the right of the current column */ - if (!col) - { - Column* c = pickcol(mon->wspace, ptrx - mon->x); - int cid = (c - mon->wspace->columns); - if (cid < (mon->wspace->ncolumns - 1)) - { - cid++; - } - col = &mon->wspace->columns[cid]; - } - - /* add the client to the stack */ - stacked_add(&(Location){mon, NULL, col, c}); - } - mons_layer(mon); -} - -static void remove_client(Location* loc, Client* c) -{ - if (!loc->column) - { - loc->workspace->floating = list_del(loc->workspace->floating, c); - } - else - { - stacked_del(loc); - } -} - -//static void adjust_all(Column* col, int xoff) -//{ -// (void)col; -// (void)xoff; -//// Client* c; -//// LIST_FOR_EACH(c, col->clients) -//// { -//// c->x += xoff; -//// c->w = col->width; -//// client_adjust(c); -//// } -//} - -static void change_wspace(Monitor* mon, Workspace* wspace) -{ - if (mon->wspace != wspace) - { - client_visibility(mon->wspace, 0); - client_visibility(wspace, 1); - mon->wspace = wspace; - } -} diff --git a/mouse.c b/mouse.c index beb6e6d..6490815 100644 --- a/mouse.c +++ b/mouse.c @@ -28,7 +28,8 @@ static void resize_frame(Location* loc) static void toggle_float(Location* loc) { - mons_togglefloat(loc); + (void)loc; +// mons_togglefloat(loc); } static void close_client(Location* loc) @@ -43,17 +44,20 @@ static void shade_client(Location* loc) static void lower_client(Location* loc) { - mons_lower(loc->monitor, loc->client); + (void)loc; +// mons_lower(loc->monitor, loc->client); } static void raise_client(Location* loc) { - mons_raise(loc->monitor, loc->client); + (void)loc; +// mons_raise(loc->monitor, loc->client); } static void stack_clients(Location* loc) { - stacked_set(loc); + (void)loc; +// stacked_set(loc); } static void reposition_tile(Location* loc) @@ -127,13 +131,15 @@ static void float_drag(XMotionEvent* ev, Location* loc) void mouse_up(XButtonEvent* ev, Location* loc) { + (void)ev; + (void)loc; if (X.mode == M_TILE_RESIZE) { - mons_tilemove(loc, ev->y_root - X.start_y); +// mons_tilemove(loc, ev->y_root - X.start_y); } else if (X.mode == M_COL_RESIZE) { - mons_coladjust(loc->monitor, loc->column, ev->x_root - X.start_x); +// mons_coladjust(loc->monitor, loc->column, ev->x_root - X.start_x); } else { diff --git a/tile.c b/tile.c deleted file mode 100644 index 368d08b..0000000 --- a/tile.c +++ /dev/null @@ -1,139 +0,0 @@ -#include "anvil.h" - -static void coldims(Monitor *mon, Column *col, int *x, int *y, int *w, int *h) -{ - *x = mon->x, *y = mon->y, *w = col->width, *h = mon->h; - for (int i = 0 ; i < mon->wspace->ncolumns; i++) - { - if (col == &(mon->wspace->columns[i])) - { - break; - } - *x += mon->wspace->columns[i].width; - } -} - -void stacked_add(Location* loc) -{ - Client* c = loc->client; - coldims(loc->monitor, loc->column, &(c->x), &(c->y), &(c->w), &(c->h)); - if (loc->column->clients) - { - Client *cl, *max = loc->column->clients; - LIST_FOR_EACH(cl, max) - { - if (cl->h > max->h) - { - max = cl; - } - } - if (max->h < 3*MIN_HEIGHT) - { - int cid = (loc->column - loc->monitor->wspace->columns); - if ((cid + 1) < loc->monitor->wspace->ncolumns) - { - stacked_add(loc); - } - else - { - c->next = loc->monitor->wspace->floating; - loc->monitor->wspace->floating = c; - c->x = loc->monitor->midx - c->w/2; - c->y = loc->monitor->midy - c->h/2; - client_adjust(c); - } - } - else - { - c->h = max->h/2; - c->y = max->y + c->h; - c->w = max->w; - max->h -= max->h/2; - c->next = max->next; - max->next = c; - client_adjust(c); - client_adjust(max); - } - } - else - { - c->next = loc->column->clients; - loc->column->clients = c; - client_adjust(c); - } -} - -void stacked_del(Location* loc) -{ - Client* c = loc->client; - if (loc->column->clients == c) - { - loc->column->clients = c->next; - if (loc->column->clients) - { - loc->column->clients->h += loc->column->clients->y - loc->monitor->y; - loc->column->clients->y = loc->monitor->y; - client_setshade(loc->column->clients, 0); - client_adjust(loc->column->clients); - } - } - else - { - Client* prev = list_prev(loc->column->clients, c); - prev->next = c->next; - prev->h += c->h; - client_setshade(prev, 0); - client_adjust(prev); - } -} - -void stacked_set(Location* loc) -{ - Client *curr, *c = loc->client; - int starty = loc->monitor->y; - /* stack the windows before the target */ - LIST_FOR_EACH_UNTIL(curr, loc->column->clients, curr == c) - { - curr->y = starty; - curr->h = MIN_HEIGHT; - client_setshade(curr, 1); - client_adjust(curr); - starty += MIN_HEIGHT; - } - /* expand the target window */ - int nclients = list_length(curr->next); - curr->y = starty; - curr->h = (loc->monitor->h - starty) - (nclients * MIN_HEIGHT); - client_setshade(c, 0); - client_adjust(curr); - mouse_totitle(curr); - starty = (curr->y + curr->h - 1); - /* stack the windows after the target */ - LIST_FOR_EACH(curr, curr->next) - { - curr->y = starty; - curr->h = MIN_HEIGHT; - client_setshade(curr, 1); - client_adjust(curr); - starty += MIN_HEIGHT; - } -} - -void stacked_addheight(Location* loc, int amount) -{ - Client* c = loc->client; - Client* prev = list_prev(loc->column->clients, c); - if (prev) - { - amount = (abs(amount) < BORDER_WIDTH ? min((int)(-c->h * 0.25), -2*MIN_HEIGHT) : amount); - int miny = (prev->y + MIN_HEIGHT); - int maxy = min((loc->monitor->y + loc->monitor->h) , (c->y + c->h)) - MIN_HEIGHT; - c->y = max(miny, min(maxy, c->y + amount)); - prev->h = c->y - prev->y; - c->h = (c->next ? c->next->y : loc->monitor->y + loc->monitor->h) - c->y; - client_setshade(prev, (prev->h <= MIN_HEIGHT)); - client_setshade(c, (c->h <= MIN_HEIGHT)); - client_adjust(prev); - client_adjust(c); - } -}