From: Mike Lowis Date: Wed, 31 Jul 2024 18:26:21 +0000 (-0400) Subject: refactore to have 10 workspaces overall instead of 10 per monitor. Monitors and works... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=2ec4e0df47043fd50882112626ad697edc99fada;p=proto%2Fanvil.git refactore to have 10 workspaces overall instead of 10 per monitor. Monitors and workspaces both switch to arrays instead of linked 'lists. --- diff --git a/anvil.c b/anvil.c index 9a6455a..93b4ada 100644 --- a/anvil.c +++ b/anvil.c @@ -3,6 +3,14 @@ XConf X = {0}; +/* Anvil State */ +int PtrX = 0, PtrY = 0; +int Num_Monitors = 0; +Monitor Monitors[10] = {0}; +Workspace Workspaces[10] = {0}; +Client* Withdrawn = NULL; +Client* Focused = NULL; + static void check_for_wm(void) { error_default = XSetErrorHandler(error_init); @@ -76,15 +84,6 @@ static void xbtnmotion(XEvent* e) X.last_x = ev->x_root, X.last_y = ev->y_root; } -static void xconfignotify(XEvent* e) -{ - XConfigureEvent* ev = &(e->xconfigure); - if (ev->window == X.root) - { - puts("root window resized"); - } -} - static void xconfigrequest(XEvent* e) { XConfigureRequestEvent* ev = &(e->xconfigurerequest); @@ -302,7 +301,6 @@ int main(void) X.eventfns[ButtonRelease] = xbtnrelease; X.eventfns[MotionNotify] = xbtnmotion; X.eventfns[KeyPress] = xkeypress; - X.eventfns[ConfigureNotify] = xconfignotify; X.eventfns[ConfigureRequest] = xconfigrequest; X.eventfns[MapRequest] = xmaprequest; X.eventfns[MapNotify] = xmapnotify; diff --git a/anvil.h b/anvil.h index 247943f..73b5cbb 100644 --- a/anvil.h +++ b/anvil.h @@ -20,6 +20,17 @@ #define min(a,b) (a < b ? a : b) #define max(a,b) (a > b ? a : b) +#define BORDER_WIDTH 5 +#define TITLE_HEIGHT (X.font_ext->max_logical_extent.height) +#define MIN_HEIGHT (TITLE_HEIGHT+BORDER_WIDTH) +#define MIN_COL_FACT 0.20 +#define MAX_COL_COUNT 5 +#define FONT_NAME "-*-lucida-bold-r-normal-sans-14-*-*-*-p-*-iso10646-1" +#define MODKEY Mod4Mask +#define FRAME_HEIGHT_SUM (2*BORDER_WIDTH + TITLE_HEIGHT) +#define FRAME_WIDTH_SUM (2*BORDER_WIDTH) +#define MAX_WSPACE_COUNT 10 + /* TODO: Add shortcuts to transfer windows between monitors */ /* TODO: add floating addclient function */ @@ -48,6 +59,7 @@ typedef struct { XFontSet font; XFontSetExtents *font_ext; Visual* visual; + XEvent* curr_ev; void (*eventfns[LASTEvent])(XEvent*); } XConf; @@ -68,29 +80,26 @@ typedef struct Client { Window frame, win; int flags, x, y, w, h; long hint_flags, wm_flags; - XSizeHints hints; + XWMHints hints; + XSizeHints size_hints; Pixmap pixmap; Visual visual; } Client; typedef struct Column { - struct Column* next; int width; - Client* focused; Client* clients; } Column; typedef struct Workspace { - struct Workspace* next; Client* floating; - Column* columns; + Column columns[MAX_COL_COUNT]; + int ncolumns; } Workspace; typedef struct Monitor { - struct Monitor* next; int x, y, w, h, midx, midy; - Workspace* wspaces; - Workspace* cspace; + Workspace* wspace; } Monitor; typedef struct Location { @@ -112,18 +121,19 @@ typedef struct { Arg arg; } Key; -#define BORDER_WIDTH 5 -#define TITLE_HEIGHT (X.font_ext->max_logical_extent.height) -#define MIN_HEIGHT (TITLE_HEIGHT+BORDER_WIDTH) -#define MIN_COL_FACT 0.20 -#define FONT_NAME "-*-lucida-bold-r-normal-sans-14-*-*-*-p-*-iso10646-1" -#define MODKEY Mod4Mask -#define FRAME_HEIGHT_SUM (2*BORDER_WIDTH + TITLE_HEIGHT) -#define FRAME_WIDTH_SUM (2*BORDER_WIDTH) /* anvil.c */ extern XConf X; +extern int PtrX; +extern int PtrY; +extern int Num_Monitors; +extern Monitor Monitors[10]; +extern Workspace Workspaces[10]; +extern Client* Withdrawn; +extern Client* Focused; + + /* list.c */ int list_length(void* list); void* list_del(void* list, void* node); @@ -139,7 +149,6 @@ void keys_init(void); void keys_run(XKeyEvent* ev); /* mons.c */ -extern Monitor* Monitors; void mons_init(void); void mons_layer(Monitor* mon); void mons_addclient(Client* c); @@ -158,7 +167,6 @@ void mons_tilemove(Location* loc, int hdiff); void mons_activate(Window win); /* client.c */ -extern Client* Focused; void client_initall(void); Client* client_add(Window win, XWindowAttributes* attr); void client_draw(Client* c); diff --git a/client.c b/client.c index 23342e8..a443733 100644 --- a/client.c +++ b/client.c @@ -1,9 +1,16 @@ #include "anvil.h" -Client* Focused = NULL; - void client_initall(void) { + /* TODO: Find all top-level windows and register them correctly + + * Find all root children with override_redirect set False + * Add them to withdrawn list if WM_STATE = withdrawn + * Add them as floating and unshaded if WM_STATE = Normal + * Add them as floating ad shaded if WM_STATE = Iconic + + */ + unsigned int nwins; Window d1, d2, *wins = NULL; XWindowAttributes attr; @@ -11,7 +18,7 @@ void client_initall(void) { for (unsigned int i = 0; i < nwins; i++) { - if (XGetWindowAttributes(X.disp, wins[i], &attr) && !attr.override_redirect) + if (XGetWindowAttributes(X.disp, wins[i], &attr) && (attr.override_redirect == False)) { Client* c = client_add(wins[i], &attr); c->flags |= F_FLOATING; @@ -175,23 +182,26 @@ void client_readprops(Client* c) int format, nprotos = 0; unsigned long n, extra; - /* get window title */ + /* WM_NAME - window title */ xfree(c->name); c->name = NULL; XGetWindowProperty( X.disp, c->win, XA_WM_NAME, 0, -1, False, AnyPropertyType, &actual_type, &format, &n, &extra, (unsigned char **)&c->name); - /* check if the window is a dialog */ - XGetWindowProperty( - X.disp, c->win, _NET_WM_WINDOW_TYPE, 0L, -1, False, XA_ATOM, &actual_type, &format, &n, &extra, (unsigned char **)&wintype); - if (wintype && *wintype == _NET_WM_WINDOW_TYPE_DIALOG) + /* WM_HINTS - other non-dimensional attributes of the window */ + XWMHints* hints = XGetWMHints(X.disp, c->win); + if (hints) { - c->flags |= F_DIALOG|F_FLOATING; + int ignored = (Focused == c ? XUrgencyHint : 0); + c->wm_flags = (hints->flags & ~ignored); + c->hints = *hints; } - xfree(wintype); + xfree(hints); + + /* WM_NORMAL_HINTS - desired dimensional attributes of the window */ + XGetWMNormalHints(X.disp, c->win, &(c->size_hints), &(c->hint_flags)); - /* get the other hints and protocols */ - XGetWMNormalHints(X.disp, c->win, &(c->hints), &(c->hint_flags)); + /* WM_PROTOCOLS - list of client message protocols this window responds to */ XGetWMProtocols(X.disp, c->win, &protos, &nprotos); for (int i = 0; i < nprotos; i++) { @@ -199,17 +209,32 @@ void client_readprops(Client* c) { c->flags |= F_WM_DELETE; } + + // TODO: handle WM_TAKE_FOCUS } xfree(protos); + /* WM_CLASS - instance and class names of the window. informs WM about behavior of window */ + // TODO: Read the class and instance of the window - XWMHints* hints = XGetWMHints(X.disp, c->win); - if (hints) + /* WM_TRANSIENT_FOR - marks the window as a pop-up for another window */ + // TODO: read the transient_for property and use ti to handle pop-ups better + + /* WM_CLIENT_MACHINE - */ + // TODO: read client machine property + + /* check if the window is a dialog */ + XGetWindowProperty( + X.disp, c->win, _NET_WM_WINDOW_TYPE, 0L, -1, False, XA_ATOM, &actual_type, &format, &n, &extra, (unsigned char **)&wintype); + if (wintype && *wintype == _NET_WM_WINDOW_TYPE_DIALOG) { - int ignored = (Focused == c ? XUrgencyHint : 0); - c->wm_flags = (hints->flags & ~ignored); + c->flags |= F_DIALOG|F_FLOATING; } - xfree(hints); + xfree(wintype); + + /* The following properties are unused currently */ + /* WM_ICON_NAME - window title when iconified */ + /* WM_COLORMAP_WINDOWS - */ } void client_shade(Client* c) diff --git a/mons.c b/mons.c index 033859f..6e2dd6a 100644 --- a/mons.c +++ b/mons.c @@ -1,23 +1,19 @@ #include "anvil.h" #include -int PtrX = 0, PtrY = 0; static Monitor* pickmon(void); -static Column* pickcol(Column* cols, int relx); -static Workspace* pickws(Monitor* mon, int wsid); +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 adjust_all(Column* col, int xoff); static void change_wspace(Monitor* mon, Workspace* wspace); -Monitor* Monitors = NULL; - -static int min_col_width(Monitor* mon) -{ - return (int)(mon->w * MIN_COL_FACT); -} +//static int min_col_width(Monitor* mon) +//{ +// return (int)(mon->w * MIN_COL_FACT); +//} void mons_init(void) { @@ -26,47 +22,18 @@ void mons_init(void) XineramaScreenInfo* mons = XineramaQueryScreens(X.disp, &nmons); for (int i = 0; i < nmons; i++) { - Monitor* m = ecalloc(1, sizeof(Monitor)); + 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->next = Monitors; - Monitors = m; - for (int i = 0; i < 10; i++) - { - Column* col = ecalloc(1, sizeof(Column)); - col->width = m->w; - Workspace* wspace = ecalloc(1, sizeof(Workspace)); - wspace->columns = col; - wspace->next = m->wspaces; - m->wspaces = wspace; - } - m->cspace = m->wspaces; + m->wspace = &Workspaces[i]; + m->wspace->ncolumns = 1; } + Num_Monitors = nmons; xfree(mons); - - Monitor* m = Monitors; - while (m) - { - printf("x: %d y: %d w: %d h: %d\n", m->x, m->y, m->w, m->h); - Workspace* w = m->wspaces; - while (w) - { - printf(" wspace %p\n", (void*)w); - Column* c = w->columns; - while (c) - { - printf(" col %p %d\n", (void*)c, c->width); - c = c->next; - } - w = w->next; - } - m = m->next; - } - } void mons_layer(Monitor* mon) @@ -74,24 +41,26 @@ void mons_layer(Monitor* mon) int nwins = 0; Window* wins = NULL; Client* c; - Column* col; - LIST_FOR_EACH(c, mon->cspace->floating) + 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 */ - LIST_FOR_EACH(col, mon->cspace->columns) + for (int i = 0; i < wspace->ncolumns; i++) { - LIST_FOR_EACH(c, col->clients) + LIST_FOR_EACH(c, wspace->columns[i].clients) { - if (col->focused != c) - { - wins = realloc(wins, ++nwins * sizeof(Window)); - wins[nwins-1] = c->frame; - } + wins = realloc(wins, ++nwins * sizeof(Window)); + wins[nwins-1] = c->frame; } } + + /* restack them and free the array */ if (nwins) { XRestackWindows(X.disp, wins, nwins); @@ -135,35 +104,50 @@ void mons_togglefloat(Location* loc) int mons_find(Window win, Location* loc) { - Monitor* mon; - Workspace* wspace; - LIST_FOR_EACH(mon, Monitors) + 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) { - LIST_FOR_EACH(wspace, mon->wspaces) + for (int i = 0; i < MAX_WSPACE_COUNT; i++) { - Column* column = NULL; - Client* client = client_find(wspace->floating, win); + 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) { - LIST_FOR_EACH(column, wspace->columns) + for (int c = 0; c < wspace->ncolumns; c++) { - if ( (client = client_find(column->clients, win)) ) + 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 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; } @@ -179,8 +163,9 @@ void mons_place(Client* c) { int maxarea = 0; Monitor *mon = NULL, *closest = NULL; - LIST_FOR_EACH(mon, Monitors) + 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); @@ -199,8 +184,8 @@ void mons_place(Client* c) if (closest && loc.monitor != closest) { loc.workspace->floating = list_del(loc.workspace->floating, c); - c->next = closest->cspace->floating; - closest->cspace->floating = c; + c->next = closest->wspace->floating; + closest->wspace->floating = c; } } } @@ -208,130 +193,139 @@ void mons_place(Client* c) void mons_wspace(int wsid) { Monitor* mon = pickmon(); - change_wspace(mon, pickws(mon, wsid)); + change_wspace(mon, &Workspaces[wsid]); } void mons_towspace(Client* c, int wsid) { - Location loc = {0}; - if (mons_find(c->win, &loc)) - { - mouse_get(&PtrX, &PtrY); - Workspace* wspace = pickws(loc.monitor, wsid); - if (wspace != loc.workspace) - { - remove_client(&loc, c); - client_show(c, 0); - Workspace* prev = loc.monitor->cspace; - loc.monitor->cspace = wspace; - add_client(loc.monitor, c, PtrX); - loc.monitor->cspace = prev; - } - } + (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->cspace->floating = list_del(mon->cspace->floating, c); - c->next = mon->cspace->floating; - mon->cspace->floating = 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->cspace->floating = list_del(mon->cspace->floating, c); + mon->wspace->floating = list_del(mon->wspace->floating, c); c->next = NULL; - if (mon->cspace->floating) + if (mon->wspace->floating) { - Client* curr = list_last(mon->cspace->floating); + Client* curr = list_last(mon->wspace->floating); curr->next = c; } else { - mon->cspace->floating = c; + mon->wspace->floating = c; } mons_layer(mon); } void mons_colsplit(void) { - Monitor* mon = pickmon(); - Column* col = pickcol(mon->cspace->columns, 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); - } +// 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) { - Monitor* mon = pickmon(); - Column* dest = pickcol(mon->cspace->columns, PtrX - mon->x); - Column* dead = dest->next; - if (!dead) - { - dead = dest; - dest = list_prev(mon->cspace->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); - } +// 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) { - Column* neighbor = col->next; - int minwidth = min_col_width(mon); - if (X.edge == E_LEFT && mon->cspace->columns != col) - { - for (neighbor = mon->cspace->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)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->cspace->columns, PtrX - mon->x); + Column* col = pickcol(mon->wspace, PtrX - mon->x); if (loc->monitor != mon || loc->column != col) { remove_client(loc, loc->client); @@ -363,43 +357,37 @@ void mons_activate(Window win) static Monitor* pickmon(void) { mouse_get(&PtrX, &PtrY); - Monitor* mon; - LIST_FOR_EACH_UNTIL(mon, Monitors, - (mon->x <= PtrX && PtrX < mon->x+mon->w) && - (mon->y <= PtrY && PtrY < mon->y+mon->h) - ); - mon = (mon ? mon : Monitors); - return mon; + 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(Column* cols, int relx) +static Column* pickcol(Workspace* wspace, int relx) { Column* col; int left = 0, right = 0; - printf("cols %p\n", cols); - LIST_FOR_EACH(col, cols) + for (int i = 0; i < wspace->ncolumns; i++) { - printf("curr = %p\n", col); - left = right, right += col->width; - printf("%d <= %d < %d\n", left, relx, right); + left = right, right += wspace->columns[i].width; if (left <= relx && relx < right) { + col = &wspace->columns[i]; break; /* we found the column holding the mouse */ } } - printf("%p\n", (void*)col); -// if (!col) col = cols; return col; } -static Workspace* pickws(Monitor* mon, int wsid) -{ - Workspace* wspace; - int i = 0; - LIST_FOR_EACH_UNTIL(wspace, mon->wspaces, (i++ == wsid)); - return wspace; -} - static void client_visibility(Workspace* wspace, int show) { Column* col; @@ -408,8 +396,9 @@ static void client_visibility(Workspace* wspace, int show) { client_show(client, show); } - LIST_FOR_EACH(col, wspace->columns) + for (int i = 0; i < wspace->ncolumns; i++) { + col = &(wspace->columns[i]); LIST_FOR_EACH(client, col->clients) { client_show(client, show); @@ -429,27 +418,38 @@ static void add_client(Monitor* mon, Client* c, int ptrx) { if (X.mode == M_INIT || c->flags & (F_DIALOG|F_FLOATING)) { - c->next = mon->cspace->floating; - mon->cspace->floating = c; + 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 { - /* find first empty column, and fill that first */ Column* col = NULL; - LIST_FOR_EACH_UNTIL(col, mon->cspace->columns, col->clients == 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) { - /* otherwise pick the column to the right or the current column */ - col = pickcol(mon->cspace->columns, ptrx - mon->x); - if (col->next) + Column* c = pickcol(mon->wspace, ptrx - mon->x); + int cid = (c - mon->wspace->columns); + if (cid < (mon->wspace->ncolumns - 1)) { - col = col->next; + cid++; } + col = &mon->wspace->columns[cid]; } - /* add in monocled or stacked mode */ + + /* add the client to the stack */ stacked_add(&(Location){mon, NULL, col, c}); } mons_layer(mon); @@ -467,23 +467,25 @@ static void remove_client(Location* loc, Client* c) } } -static void adjust_all(Column* col, int xoff) -{ - Client* c; - LIST_FOR_EACH(c, col->clients) - { - c->x += xoff; - c->w = col->width; - client_adjust(c); - } -} +//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->cspace != wspace) + if (mon->wspace != wspace) { - client_visibility(mon->cspace, 0); + client_visibility(mon->wspace, 0); client_visibility(wspace, 1); - mon->cspace = wspace; + mon->wspace = wspace; } } diff --git a/mouse.c b/mouse.c index 22d2cfd..beb6e6d 100644 --- a/mouse.c +++ b/mouse.c @@ -1,7 +1,5 @@ #include "anvil.h" -static XEvent* Current = NULL; - static inline int PRESSED(int mods, int btn) { return ((mods & (1 << (btn + 7))) == (1 << (btn + 7))); @@ -21,7 +19,7 @@ typedef struct { static void resize_frame(Location* loc) { - if (Current->xbutton.y > MIN_HEIGHT) + if (X.curr_ev->xbutton.y > MIN_HEIGHT) { X.mode = M_RESIZE; mouse_tocorner(loc->client); @@ -93,7 +91,7 @@ static void process(XButtonEvent* ev, Location* loc, MouseAct* actions, int nact ); if (match) { - Current = (XEvent*)ev; + X.curr_ev = (XEvent*)ev; act->func(loc); break; } diff --git a/test/tile.c b/test/tile.c index 6597ac0..8cdd65b 100644 --- a/test/tile.c +++ b/test/tile.c @@ -30,22 +30,22 @@ void mouse_totitle(Client* c) Location* setup(void) { Location* loc = calloc(1, sizeof(Location)); - Monitor* mon = calloc(1, sizeof(Monitor)); - mon->w = 100, mon->h = 100; - mon->midx = 50, mon->midy = 50; - Column* col1 = calloc(1, sizeof(Column)); - col1->width = 50; - Column* col2 = calloc(1, sizeof(Column)); - col2->width = 50; - col1->next = col2; - Workspace* wspace = calloc(1, sizeof(Workspace)); - wspace->columns = col1; - mon->wspaces = wspace; - mon->cspace = wspace; - loc->monitor = mon; - loc->workspace = wspace; - loc->column = col1; - loc->client = calloc(1, sizeof(Client)); +// Monitor* mon = calloc(1, sizeof(Monitor)); +// mon->w = 100, mon->h = 100; +// mon->midx = 50, mon->midy = 50; +// Column* col1 = calloc(1, sizeof(Column)); +// col1->width = 50; +// Column* col2 = calloc(1, sizeof(Column)); +// col2->width = 50; +// col1->next = col2; +// Workspace* wspace = calloc(1, sizeof(Workspace)); +// wspace->columns = col1; +// mon->wspaces = wspace; +// mon->cspace = wspace; +// loc->monitor = mon; +// loc->workspace = wspace; +// loc->column = col1; +// loc->client = calloc(1, sizeof(Client)); return loc; } diff --git a/tile.c b/tile.c index 2dffe2a..368d08b 100644 --- a/tile.c +++ b/tile.c @@ -2,11 +2,14 @@ static void coldims(Monitor *mon, Column *col, int *x, int *y, int *w, int *h) { - Column* c; *x = mon->x, *y = mon->y, *w = col->width, *h = mon->h; - LIST_FOR_EACH_UNTIL(c, mon->cspace->columns, (c == col)) + for (int i = 0 ; i < mon->wspace->ncolumns; i++) { - *x += c->width; + if (col == &(mon->wspace->columns[i])) + { + break; + } + *x += mon->wspace->columns[i].width; } } @@ -26,14 +29,15 @@ void stacked_add(Location* loc) } if (max->h < 3*MIN_HEIGHT) { - if (loc->column->next) + int cid = (loc->column - loc->monitor->wspace->columns); + if ((cid + 1) < loc->monitor->wspace->ncolumns) { stacked_add(loc); } else { - c->next = loc->monitor->cspace->floating; - loc->monitor->cspace->floating = c; + 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); @@ -86,7 +90,6 @@ void stacked_del(Location* loc) void stacked_set(Location* loc) { Client *curr, *c = loc->client; - loc->column->focused = NULL; int starty = loc->monitor->y; /* stack the windows before the target */ LIST_FOR_EACH_UNTIL(curr, loc->column->clients, curr == c)