From 5f9d2237b0fbc47f9f5627ea46ff88f961a58111 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 13 Mar 2023 07:59:33 -0400 Subject: [PATCH] started rebuilding floating window management. Still buggy but the frames and windows show up again --- bin/winmgr/anvil.h | 8 + bin/winmgr/client.c | 347 +++++++++++++++++++++----------------------- bin/winmgr/keys.c | 2 +- bin/winmgr/mons.c | 160 ++++++++++---------- bin/winmgr/mouse.c | 84 ++++------- bin/winmgr/tile.c | 226 ++++++++++++++--------------- bin/winmgr/winmgr.c | 7 +- 7 files changed, 398 insertions(+), 436 deletions(-) diff --git a/bin/winmgr/anvil.h b/bin/winmgr/anvil.h index 2b46b27..e8726bc 100644 --- a/bin/winmgr/anvil.h +++ b/bin/winmgr/anvil.h @@ -148,6 +148,7 @@ typedef struct { extern XConf X; +void Client_InitExistingWindows(void); Client* Client_Find(Window win); Client* Client_Add(Window win, XWindowAttributes* attr); void Client_Del(Client* client); @@ -156,6 +157,13 @@ void Client_SetActive(Window win); void Client_ReadProps(Client* client); void Client_Draw(Client* client); void Client_Focus(Client* client); +void Client_Move(Client* c, int xdiff, int ydiff); +void Client_Resize(Client* c, int xdiff, int ydiff); +void Client_Show(Client* c, int show); +void Client_Close(Client* c); + + +void Monitors_Place(Client* c); void Mouse_ToCorner(Client* client); void Mouse_Down(XButtonEvent* ev, Client* client); diff --git a/bin/winmgr/client.c b/bin/winmgr/client.c index a9170a3..a0e9c70 100644 --- a/bin/winmgr/client.c +++ b/bin/winmgr/client.c @@ -12,6 +12,25 @@ static Client Client_Buffer[MAX_CLIENTS]; /* The currently focused client */ Client* Focused = NULL; +void Client_InitExistingWindows(void) +{ + unsigned int nwins; + Window d1, d2, *wins = NULL; + XWindowAttributes attr; + if (XQueryTree(X.disp, X.root, &d1, &d2, &wins, &nwins)) + { + for (unsigned int i = 0; i < nwins; i++) + { + if (XGetWindowAttributes(X.disp, wins[i], &attr) && !attr.override_redirect) + { + Client* c = Client_Add(wins[i], &attr); + c->flags |= F_FLOATING; + } + } + xfree(wins); + } +} + Client* Client_Find(Window win) { Client* client = NULL; @@ -33,7 +52,7 @@ Client* Client_Find(Window win) Client* Client_Add(Window win, XWindowAttributes* attr) { - Client* client = NULL; + Client* c = NULL; for (int i = 0; i < NUM_BITMAP_CELLS; i++) { @@ -41,18 +60,45 @@ Client* Client_Add(Window win, XWindowAttributes* attr) { unsigned long bit_index = __builtin_ctz(~Client_Bitmap[i]); Client_Bitmap[i] |= (1 << bit_index); - client = &Client_Buffer[i + bit_index]; + c = &Client_Buffer[i + bit_index]; break; } } + assert(c); - return client; + c->win = win; + c->x = attr->x; + c->y = attr->y; + c->w = attr->width + FRAME_WIDTH_SUM; + c->h = attr->height + FRAME_HEIGHT_SUM; + Client_ReadProps(c); + + /* Reparent the window if applicable */ + c->frame = XCreateSimpleWindow(X.disp, X.root, c->x, c->y, c->w, c->h, 1, X.clr_bdr, X.clr_bg); + XSelectInput(X.disp, c->frame, + ExposureMask | EnterWindowMask | + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | + SubstructureRedirectMask | SubstructureNotifyMask + ); + XSetWindowAttributes wa; + wa.event_mask = EnterWindowMask | PropertyChangeMask | FocusChangeMask; + wa.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask; + XChangeWindowAttributes(X.disp, c->win, CWEventMask | CWDontPropagate, &wa); + XReparentWindow(X.disp, c->win, c->frame, BORDER_WIDTH, MIN_HEIGHT); + + /* Map the window and draw the frame */ + XAddToSaveSet(X.disp, c->win); +// mons_addclient(c); + Client_Show(c, 1); + Client_Draw(c); + + return c; } void Client_Del(Client* client) { /* cleanup stuff here... */ - + memset(client, 0, sizeof(Client)); /* now deallocate it */ unsigned long client_index = (client - &Client_Buffer[0]) / sizeof(Client); unsigned long cell = client_index / sizeof(unsigned long); @@ -62,6 +108,23 @@ void Client_Del(Client* client) void Client_AdjustSize(Client* client) { + int shaded = (client->flags & F_SHADED); + int floating = (client->flags & (F_DIALOG|F_FLOATING)); + int minheight = (shaded || !floating ? MIN_HEIGHT : 3*MIN_HEIGHT); + if (client->w < minheight) client->w = minheight; + if (client->h < minheight) client->h = minheight; + printf("XMoveResize(0x%lx, %d, %d, %d, %d)\n", client->frame, client->x, client->y, client->w, client->h); + XMoveResizeWindow(X.disp, client->frame, client->x, client->y, client->w, (shaded ? minheight : client->h)); + if ( !(client->flags & F_SHADED) ) + { + int child_w = client->w - FRAME_WIDTH_SUM; + int child_h = client->h - FRAME_HEIGHT_SUM; + if (child_w < 1) client->w = 1; + if (child_h < 1) client->h = 1; + printf("XResize(0x%lx, %d, %d)\n", client->win, client->w, client->h); + XResizeWindow(X.disp, client->win, child_w, child_h); + } + Monitors_Place(client); } void Client_SetActive(Window win) @@ -70,165 +133,128 @@ void Client_SetActive(Window win) void Client_ReadProps(Client* client) { -} - -void Client_Draw(Client* client) -{ -} - -void Client_Focus(Client* client) -{ -} - - - - - - - - - - - - - - + Atom *protos = NULL, actual_type, *wintype; + int format, nprotos = 0; + unsigned long n, extra; + /* get window title */ + xfree(client->name); + client->name = NULL; + XGetWindowProperty( + X.disp, client->win, XA_WM_NAME, 0, -1, False, AnyPropertyType, &actual_type, &format, &n, &extra, (unsigned char **)&client->name); + /* check if the window is a dialog */ + XGetWindowProperty( + X.disp, client->win, atom("_NET_WM_WINDOW_TYPE"), 0L, -1, False, XA_ATOM, &actual_type, &format, &n, &extra, (unsigned char **)&wintype); + if (wintype && *wintype == atom("_NET_WM_WINDOW_TYPE_DIALOG")) + { + client->flags |= F_DIALOG|F_FLOATING; + } + xfree(wintype); -void client_initall(void) -{ - unsigned int nwins; - Window d1, d2, *wins = NULL; - XWindowAttributes attr; - if (XQueryTree(X.disp, X.root, &d1, &d2, &wins, &nwins)) + /* get the other hints and protocols */ + XGetWMNormalHints(X.disp, client->win, &(client->hints), &(client->hint_flags)); + XGetWMProtocols(X.disp, client->win, &protos, &nprotos); + for (int i = 0; i < nprotos; i++) { - for (unsigned int i = 0; i < nwins; i++) + if (protos[i] == atom("WM_DELETE_WINDOW")) { - if (XGetWindowAttributes(X.disp, wins[i], &attr) && !attr.override_redirect) - { - Client* c = client_add(wins[i], &attr); - c->flags |= F_FLOATING; - } + client->flags |= F_WM_DELETE; } - xfree(wins); } -} + xfree(protos); -Client* client_add(Window win, XWindowAttributes* attr) -{ - Client* c = ecalloc(1, sizeof(Client)); - c->win = win; - c->x = attr->x; - c->y = attr->y; - c->w = attr->width + FRAME_WIDTH_SUM; - c->h = attr->height + FRAME_HEIGHT_SUM; - client_readprops(c); - /* Reparent the window if applicable */ - c->frame = XCreateSimpleWindow(X.disp, X.root, c->x, c->y, c->w, c->h, 1, X.clr_bdr, X.clr_bg); - XSelectInput(X.disp, c->frame, - ExposureMask | EnterWindowMask | - ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | - SubstructureRedirectMask | SubstructureNotifyMask - ); - XSetWindowAttributes wa; - wa.event_mask = EnterWindowMask | PropertyChangeMask | FocusChangeMask; - wa.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask; - XChangeWindowAttributes(X.disp, c->win, CWEventMask | CWDontPropagate, &wa); - XReparentWindow(X.disp, c->win, c->frame, BORDER_WIDTH, MIN_HEIGHT); - - /* Map the window and draw the frame */ - XAddToSaveSet(X.disp, c->win); - mons_addclient(c); - client_show(c, 1); - client_draw(c); - return c; + XWMHints* hints = XGetWMHints(X.disp, client->win); + if (hints) + { + int ignored = (Focused == client ? XUrgencyHint : 0); + client->wm_flags = (hints->flags & ~ignored); + } + xfree(hints); } -void client_draw(Client* c) +void Client_Draw(Client* client) { - if (c->frame) + if (client->frame) { - XSetWindowBackground(X.disp, c->frame, ((c->wm_flags & XUrgencyHint) ? X.clr_urgent : X.clr_bg)); - XSetWindowBorderWidth(X.disp, c->frame, 0); - XSetWindowBorderWidth(X.disp, c->win, 0); - XDefineCursor(X.disp, c->frame, X.csr_point); - XClearWindow(X.disp, c->frame); + XSetWindowBackground(X.disp, client->frame, ((client->wm_flags & XUrgencyHint) ? X.clr_urgent : X.clr_bg)); + XSetWindowBorderWidth(X.disp, client->frame, 0); + XSetWindowBorderWidth(X.disp, client->win, 0); + XDefineCursor(X.disp, client->frame, X.csr_point); + XClearWindow(X.disp, client->frame); /* set border color */ XSetForeground(X.disp, DefaultGC(X.disp, X.screen), BlackPixel(X.disp, X.screen)); XSetFillStyle(X.disp, DefaultGC(X.disp, X.screen), FillSolid); /* draw outer border */ - XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen), 0, 0, c->w, 0); - XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen), 0, c->h-1, c->w, c->h-1); - XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen), 0, 0, 0, c->h); - XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen), c->w-1, 0, c->w-1, c->h); + XDrawLine(X.disp, client->frame, DefaultGC(X.disp, X.screen), 0, 0, client->w, 0); + XDrawLine(X.disp, client->frame, DefaultGC(X.disp, X.screen), 0, client->h-1, client->w, client->h-1); + XDrawLine(X.disp, client->frame, DefaultGC(X.disp, X.screen), 0, 0, 0, client->h); + XDrawLine(X.disp, client->frame, DefaultGC(X.disp, X.screen), client->w-1, 0, client->w-1, client->h); /* draw inner border */ - if (!(c->flags & F_SHADED)) + if (!(client->flags & F_SHADED)) { int bw = BORDER_WIDTH; int mh = MIN_HEIGHT; - XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen), - bw-1, mh-1, c->w-bw, mh-1); - XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen), - bw-1, c->h-bw, c->w-bw, c->h-bw); - XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen), - bw-1, mh-1, bw-1, c->h-bw); - XDrawLine(X.disp, c->frame, DefaultGC(X.disp, X.screen), - c->w-bw, mh-1, c->w-bw, c->h-bw); + XDrawLine(X.disp, client->frame, DefaultGC(X.disp, X.screen), + bw-1, mh-1, client->w-bw, mh-1); + XDrawLine(X.disp, client->frame, DefaultGC(X.disp, X.screen), + bw-1, client->h-bw, client->w-bw, client->h-bw); + XDrawLine(X.disp, client->frame, DefaultGC(X.disp, X.screen), + bw-1, mh-1, bw-1, client->h-bw); + XDrawLine(X.disp, client->frame, DefaultGC(X.disp, X.screen), + client->w-bw, mh-1, client->w-bw, client->h-bw); } /* draw title text */ - if (c->name) { + if (client->name) { int ascent = abs(X.font_ext->max_logical_extent.y); - Xutf8DrawString(X.disp, c->frame, X.font, + Xutf8DrawString(X.disp, client->frame, X.font, DefaultGC(X.disp, X.screen), BORDER_WIDTH, 2 + ascent, - c->name, strlen(c->name)); + client->name, strlen(client->name)); } } } -void client_adjust(Client* c) +void Client_Focus(Client* client) { - int shaded = (c->flags & F_SHADED); - int floating = (c->flags & (F_DIALOG|F_FLOATING)); - int minheight = (shaded || !floating ? MIN_HEIGHT : 3*MIN_HEIGHT); - if (c->w < minheight) c->w = minheight; - if (c->h < minheight) c->h = minheight; -printf("XMoveResize(0x%lx, %d, %d, %d, %d)\n", c->frame, c->x, c->y, c->w, c->h); - XMoveResizeWindow(X.disp, c->frame, c->x, c->y, c->w, (shaded ? minheight : c->h)); - if ( !(c->flags & F_SHADED) ) + Client* prev = Focused; + Focused = client; + XSetInputFocus(X.disp, client->win, RevertToPointerRoot, CurrentTime); + Client_Draw(Focused); + if (prev) { - int child_w = c->w - FRAME_WIDTH_SUM; - int child_h = c->h - FRAME_HEIGHT_SUM; - if (child_w < 1) c->w = 1; - if (child_h < 1) c->h = 1; -printf("XResize(0x%lx, %d, %d)\n", c->win, c->w, c->h); - XResizeWindow(X.disp, c->win, child_w, child_h); + Client_Draw(prev); } - mons_place(c); } -void client_move(Client* c, int xdiff, int ydiff) +void Client_Move(Client* c, int xdiff, int ydiff) { c->x += xdiff; c->y += ydiff; - client_adjust(c); + Client_AdjustSize(c); } -void client_resize(Client* c, int xdiff, int ydiff) +void Client_Resize(Client* c, int xdiff, int ydiff) { c->w += xdiff; c->h += ydiff; - client_adjust(c); + Client_AdjustSize(c); } -void client_close(Client* c) +void Client_Show(Client* c, int show) +{ + int (*mapfn)(Display*,Window) = (show ? XMapWindow : XUnmapWindow); + mapfn(X.disp, c->frame); + mapfn(X.disp, c->win); +} + +void Client_Close(Client* c) { if (c->flags & F_WM_DELETE) { @@ -240,84 +266,35 @@ void client_close(Client* c) } } -void client_focus(Client* c) -{ - Client* prev = Focused; - Focused = c; - XSetInputFocus(X.disp, c->win, RevertToPointerRoot, CurrentTime); - client_draw(Focused); - if (prev) - { - client_draw(prev); - } -} -void client_show(Client* c, int show) -{ - int (*mapfn)(Display*,Window) = (show ? XMapWindow : XUnmapWindow); - mapfn(X.disp, c->frame); - mapfn(X.disp, c->win); -} -void client_readprops(Client* c) -{ - Atom *protos = NULL, actual_type, *wintype; - int format, nprotos = 0; - unsigned long n, extra; - /* get 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, atom("_NET_WM_WINDOW_TYPE"), 0L, -1, False, XA_ATOM, &actual_type, &format, &n, &extra, (unsigned char **)&wintype); - if (wintype && *wintype == atom("_NET_WM_WINDOW_TYPE_DIALOG")) - { - c->flags |= F_DIALOG|F_FLOATING; - } - xfree(wintype); - /* get the other hints and protocols */ - XGetWMNormalHints(X.disp, c->win, &(c->hints), &(c->hint_flags)); - XGetWMProtocols(X.disp, c->win, &protos, &nprotos); - for (int i = 0; i < nprotos; i++) - { - if (protos[i] == atom("WM_DELETE_WINDOW")) - { - c->flags |= F_WM_DELETE; - } - } - xfree(protos); - XWMHints* hints = XGetWMHints(X.disp, c->win); - if (hints) - { - int ignored = (Focused == c ? XUrgencyHint : 0); - c->wm_flags = (hints->flags & ~ignored); - } - xfree(hints); -} -void client_shade(Client* c) -{ - client_setshade(c, ((c->flags & F_SHADED) ? 0 : 1)); - client_adjust(c); -} -void client_setshade(Client* c, int shade) -{ - if (!shade && (c->flags & F_SHADED)) - { - c->flags &= ~F_SHADED; - XMapWindow(X.disp, c->win); - } - else if (shade && !(c->flags & F_SHADED)) - { - c->flags |= F_SHADED; - XUnmapWindow(X.disp, c->win); - } -} + + + +// +//void client_shade(Client* c) +//{ +// client_setshade(c, ((c->flags & F_SHADED) ? 0 : 1)); +// Client_AdjustSize(c); +//} +// +//void client_setshade(Client* c, int shade) +//{ +// if (!shade && (c->flags & F_SHADED)) +// { +// c->flags &= ~F_SHADED; +// XMapWindow(X.disp, c->win); +// } +// else if (shade && !(c->flags & F_SHADED)) +// { +// c->flags |= F_SHADED; +// XUnmapWindow(X.disp, c->win); +// } +//} diff --git a/bin/winmgr/keys.c b/bin/winmgr/keys.c index f0b4089..67bb215 100644 --- a/bin/winmgr/keys.c +++ b/bin/winmgr/keys.c @@ -54,7 +54,7 @@ static void killwin(Arg *arg) (void)arg; if (Focused) { - client_close(Focused); + Client_Close(Focused); } } diff --git a/bin/winmgr/mons.c b/bin/winmgr/mons.c index 2ee1eb6..3c3543e 100644 --- a/bin/winmgr/mons.c +++ b/bin/winmgr/mons.c @@ -3,7 +3,7 @@ int PtrX = 0, PtrY = 0; static Monitor* pickmon(void); -static Column* pickcol(Column* cols, int relx); +//static Column* pickcol(Column* cols, int relx); static Workspace* pickws(Monitor* mon, int wsid); static void client_visibility(Workspace* wspace, int show); static Client* client_find(Client* clients, Window win); @@ -14,6 +14,51 @@ static void change_wspace(Monitor* mon, Workspace* wspace); Monitor Monitors[MAX_MONITORS]; +void Monitors_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 m = 0; m < MAX_MONITORS; m++) +// { +// mon = &Monitors[m]; +// 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->cspace->floating; +// closest->cspace->floating = c; +// } +// } +} + + + + + + + + //static int min_col_width(Monitor* mon) //{ // return (int)(mon->w * MIN_COL_FACT); @@ -143,40 +188,7 @@ void mons_togglefloat(Location* loc) /* 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 m = 0; m < MAX_MONITORS; m++) - { - mon = &Monitors[m]; - 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->cspace->floating; - closest->cspace->floating = c; - } - } + (void)c; } void mons_wspace(int wsid) @@ -195,7 +207,7 @@ void mons_towspace(Client* c, int wsid) if (wspace != loc.workspace) { remove_client(&loc, c); - client_show(c, 0); +// client_show(c, 0); Workspace* prev = loc.monitor->cspace; loc.monitor->cspace = wspace; add_client(loc.monitor, c, PtrX); @@ -304,21 +316,21 @@ void mons_coladjust(Monitor* mon, Column* col, int wdiff) void mons_tilemove(Location* loc, int hdiff) { - Monitor* mon = pickmon(); - Column* col = pickcol(mon->cspace->columns, 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; - tile_add(loc); - } - else - { - tile_addheight(loc, hdiff); - } - mouse_totitle(loc->client); +// Monitor* mon = pickmon(); +// Column* col = pickcol(mon->cspace->columns, 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; +// tile_add(loc); +// } +// else +// { +// tile_addheight(loc, hdiff); +// } +// mouse_totitle(loc->client); } void mons_activate(Window win) @@ -352,26 +364,26 @@ static Monitor* pickmon(void) return mon; } -static Column* pickcol(Column* cols, int relx) -{ - Column* col; - int left = 0, right = 0; - printf("cols %p\n", (void*)cols); - for (int i = 0; i < MAX_COLUMNS; i++) - { - col = &(cols[i]); - printf("curr = %p\n", (void*)col); - left = right, right += col->width; - printf("%d <= %d < %d\n", left, relx, right); - if (left <= relx && relx < right) - { - break; /* we found the column holding the mouse */ - } - } - printf("%p\n", (void*)col); -// if (!col) col = cols; - return col; -} +//static Column* pickcol(Column* cols, int relx) +//{ +// Column* col; +// int left = 0, right = 0; +// printf("cols %p\n", (void*)cols); +// for (int i = 0; i < MAX_COLUMNS; i++) +// { +// col = &(cols[i]); +// printf("curr = %p\n", (void*)col); +// left = right, right += col->width; +// printf("%d <= %d < %d\n", left, relx, right); +// if (left <= relx && relx < right) +// { +// 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) { @@ -384,14 +396,14 @@ static void client_visibility(Workspace* wspace, int show) Client* client; LIST_FOR_EACH(client, wspace->floating) { - client_show(client, show); +// 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); +// client_show(client, show); } } } @@ -412,7 +424,7 @@ static void add_client(Monitor* mon, Client* c, int ptrx) mon->cspace->floating = c; c->x = mon->midx - c->w/2; c->y = mon->midy - c->h/2; - client_adjust(c); + Client_AdjustSize(c); } else { diff --git a/bin/winmgr/mouse.c b/bin/winmgr/mouse.c index 1f1e8de..3f55f4c 100644 --- a/bin/winmgr/mouse.c +++ b/bin/winmgr/mouse.c @@ -24,33 +24,18 @@ static void resize_frame(Location* loc) if (Current->xbutton.y > MIN_HEIGHT) { X.mode = M_RESIZE; - mouse_tocorner(loc->client); + Mouse_ToCorner(loc->client); } } -static void toggle_float(Location* loc) -{ - mons_togglefloat(loc); -} +//static void toggle_float(Location* loc) +//{ +// mons_togglefloat(loc); +//} static void close_client(Location* loc) { - client_close(loc->client); -} - -static void shade_client(Location* loc) -{ - client_shade(loc->client); -} - -static void lower_client(Location* loc) -{ - mons_lower(loc->monitor, loc->client); -} - -static void raise_client(Location* loc) -{ - mons_raise(loc->monitor, loc->client); + Client_Close(loc->client); } static void stack_clients(Location* loc) @@ -66,16 +51,13 @@ static void reposition_tile(Location* loc) MouseAct Floating[] = { { 0, Button1, ButtonPress, resize_frame }, - { MODKEY|ShiftMask, Button2, ButtonPress, toggle_float }, - { MODKEY, Button2, ButtonPress, close_client }, - { 0, Button3, ButtonPress, shade_client }, - { 0, Button4, ButtonPress, lower_client }, - { 0, Button5, ButtonPress, raise_client } +// { MODKEY|ShiftMask, Button2, ButtonPress, toggle_float }, +// { MODKEY, Button2, ButtonPress, close_client }, }; MouseAct Stacked[] = { { 0, Button1, ButtonPress, reposition_tile }, - { MODKEY|ShiftMask, Button2, ButtonPress, toggle_float }, +// { MODKEY|ShiftMask, Button2, ButtonPress, toggle_float }, { MODKEY, Button2, ButtonPress, close_client }, { 0, Button2, ButtonPress, stack_clients }, }; @@ -111,21 +93,6 @@ void mouse_down(XButtonEvent* ev, Location* loc) } } -static void float_drag(XMotionEvent* ev, Location* loc) -{ - if (PRESSED(ev->state, Button1)) - { - if (X.mode != M_RESIZE) - { - client_move(loc->client, ev->x_root - X.last_x, ev->y_root - X.last_y); - } - else - { - client_resize(loc->client, ev->x_root - X.last_x, ev->y_root - X.last_y); - } - } -} - void mouse_up(XButtonEvent* ev, Location* loc) { if (X.mode == M_TILE_RESIZE) @@ -143,23 +110,6 @@ void mouse_up(XButtonEvent* ev, Location* loc) X.mode = M_IDLE; } -void mouse_drag(XMotionEvent* ev, Location* loc) -{ - if (!loc->column) - { - float_drag(ev, loc); - } -} - -void mouse_tocorner(Client* c) -{ - int new_w = c->w - BORDER_WIDTH/2; - int new_h = c->h - BORDER_WIDTH/2; - XWarpPointer(X.disp, None, c->frame, 0, 0, 0, 0, new_w, new_h); - X.last_x = c->x + new_w; - X.last_y = c->y + new_h; -} - void mouse_totitle(Client* c) { XWarpPointer(X.disp, None, X.root, 0, 0, 0, 0, (c->x + c->w/2), c->y + (MIN_HEIGHT/2)); @@ -174,6 +124,11 @@ void mouse_get(int* ptrx, int* ptry) void Mouse_ToCorner(Client* client) { + int new_w = client->w - BORDER_WIDTH/2; + int new_h = client->h - BORDER_WIDTH/2; + XWarpPointer(X.disp, None, client->frame, 0, 0, 0, 0, new_w, new_h); + X.last_x = client->x + new_w; + X.last_y = client->y + new_h; } void Mouse_Down(XButtonEvent* ev, Client* client) @@ -186,5 +141,16 @@ void Mouse_Up(XButtonEvent* ev, Client* client) void Mouse_Drag(XMotionEvent* ev, Client* client) { + if (PRESSED(ev->state, Button1)) + { + if (X.mode != M_RESIZE) + { + Client_Move(client, ev->x_root - X.last_x, ev->y_root - X.last_y); + } + else + { + Client_Resize(client, ev->x_root - X.last_x, ev->y_root - X.last_y); + } + } } diff --git a/bin/winmgr/tile.c b/bin/winmgr/tile.c index a78c645..823edcc 100644 --- a/bin/winmgr/tile.c +++ b/bin/winmgr/tile.c @@ -1,131 +1,131 @@ #include "anvil.h" -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; - - int curr = (col - &mon->cspace->columns[0]) / sizeof(Column); - for (int i = 0; i < curr; i++) - { - c = &mon->cspace->columns[i]; - *x += c->width; - } -} +//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; +// +// int curr = (col - &mon->cspace->columns[0]) / sizeof(Column); +// for (int i = 0; i < curr; i++) +// { +// c = &mon->cspace->columns[i]; +// *x += c->width; +// } +//} void tile_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) - { - c->next = loc->monitor->cspace->floating; - loc->monitor->cspace->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); - } +// 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) +// { +// c->next = loc->monitor->cspace->floating; +// loc->monitor->cspace->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 tile_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); - } +// 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 tile_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; - } +// 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 tile_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); - } +// 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); +// } } diff --git a/bin/winmgr/winmgr.c b/bin/winmgr/winmgr.c index bb68e1e..a3018d4 100644 --- a/bin/winmgr/winmgr.c +++ b/bin/winmgr/winmgr.c @@ -17,7 +17,7 @@ static void check_for_wm(void) static void xmaprequest(XEvent* e) { XMapRequestEvent* ev = &(e->xmaprequest); - //printf("MAP(w: 0x%lx)\n", ev->window); + printf("MAP(w: 0x%lx)\n", ev->window); XWindowAttributes attr; /* if no record of this window exists, add it to our managed list */ @@ -92,10 +92,9 @@ static void xconfigrequest(XEvent* e) Client_AdjustSize(client); if (X.mode == M_RESIZE && Focused == client) { - mouse_tocorner(client); + Mouse_ToCorner(client); } } - } else { @@ -289,7 +288,7 @@ int main(void) init_cursors(); init_font(); mons_init(); - client_initall(); + Client_InitExistingWindows(); keys_init(); /* setup event handlers */ -- 2.54.0