From 94c0bd7f16f525e3b812c43c6e30aa9e20132c9d Mon Sep 17 00:00:00 2001 From: Mike Lowis Date: Thu, 1 Aug 2024 11:45:46 -0400 Subject: [PATCH] got floating windows mostly working with WM_STATE. Redraws are not happining in an ideal manner though --- anvil.c | 36 ++++++++------------- anvil.h | 2 +- client.c | 99 +++++++++++++++++++++++++++++--------------------------- 3 files changed, 66 insertions(+), 71 deletions(-) diff --git a/anvil.c b/anvil.c index c976eae..236433b 100644 --- a/anvil.c +++ b/anvil.c @@ -5,37 +5,29 @@ X11 Client Window State Management: - CreateNotify ->Withdrawn: - Create window detached from any workspace (withdrawn list). - Place window in withdrawn list. - - MapRequest ->Normal: - Read the window properties - Reparent the window to a frame if applicable - Move window to current workspace tiled or floating - Send expose event to window + MapRequest ->Normal/Withdrawn: + If window already tracked + Show the window and frame + Send expose event to window + else + Create new client struct + Read the window properties + Reparent the window to a frame if applicable + Move window to current workspace tiled or floating + Send expose event to window UnmapNotify ->Withdrawn/Iconified: if shaded -> Iconified - Keep window where it is, show only titlebar + Iconified: Keep window where it is, show only titlebar else if unloaded - Keep window where it is but unmapped + Withdrawn: Keep window where it is but unmapped else - Remove window from workspace. - Place window in withdrawn list. + Withdrawn: Remove window from workspace. DestroyNotify ->Destroyed Window is destroyed. Free all resources. */ -static void xcreatenotify(XEvent* e) -{ - XCreateWindowEvent* ev = &(e->xcreatewindow); - printf("CREATE(w: 0x%lx)\n", ev->window); - - /* add the new window in the withdrawn state */ - Client_Create(ev->window); -} static void xmaprequest(XEvent* e) { @@ -321,7 +313,7 @@ int main(void) atoms_init(); /* setup window life-cycle management event handlers */ - X.eventfns[CreateNotify] = xcreatenotify; +// X.eventfns[CreateNotify] = xcreatenotify; X.eventfns[MapRequest] = xmaprequest; X.eventfns[UnmapNotify] = xunmapnotify; X.eventfns[DestroyNotify] = xdestroynotify; diff --git a/anvil.h b/anvil.h index 147a614..c63df74 100644 --- a/anvil.h +++ b/anvil.h @@ -78,7 +78,7 @@ typedef struct Client { struct Client* next; char* name; Window frame, win; - int flags, x, y, w, h; + int state, flags, x, y, w, h; long hint_flags, wm_flags; XWMHints hints; XSizeHints size_hints; diff --git a/client.c b/client.c index 6b7e8e9..87882e0 100644 --- a/client.c +++ b/client.c @@ -7,6 +7,7 @@ static void Redraw(Client* c); void SetWMState(Client *c, int state) { CARD32 data[2] = {state, None}; + c->state = state; XChangeProperty(X.disp, c->win, WM_STATE, WM_STATE, 32, PropModeReplace, (unsigned char *)data, 2); } @@ -32,14 +33,14 @@ void SetWMState(Client *c, int state) // return state; //} -void Client_Create(Window win) +static Client* Create(Window win) { - (void)win; + Client* c = NULL; XWindowAttributes attr; if (XGetWindowAttributes(X.disp, win, &attr) && !attr.override_redirect) { /* we care about it, let's add it to withdrawn */ - Client* c = ecalloc(1, sizeof(Client)); + c = ecalloc(1, sizeof(Client)); c->win = win; c->x = attr.x; c->y = attr.y; @@ -63,36 +64,31 @@ void Client_Create(Window win) XReparentWindow(X.disp, c->win, c->frame, BORDER_WIDTH, MIN_HEIGHT); SetWMState(c, WithdrawnState); -// /* set the state now based on attributes and hints */ -// if (attr.map_state == IsUnmapped) -// { -// SetWMState(c, WithdrawnState); -// } -// else -// { -// SetWMState(c, NormalState); -// XWMHints* hints = XGetWMHints(X.disp, c->win); -// if (hints) -// { -// if (hints->flags & StateHint) -// { -// SetWMState(c, hints->initial_state); -// } -// XFree(hints); -// } -// } + /* set the state now based on attributes and hints */ + if (attr.map_state != IsViewable) + { + SetWMState(c, NormalState); + XWMHints* hints = XGetWMHints(X.disp, c->win); + if (hints) + { + if (hints->flags & StateHint) + { + SetWMState(c, hints->initial_state); + } + XFree(hints); + } + } } -} - -void Client_Destroy(Window win) -{ - (void)win; + return c; } void Client_Show(Window win) { + /* find or create the client structure */ Client* c = FindClient(win); - printf("%p %p\n", Withdrawn, c); + if (!c) { c = Create(win); } + + /* if we have a calid client, show it */ if (c) { ReadProps(c); @@ -126,6 +122,34 @@ void Client_Hide(Window win) } +void Client_Destroy(Window win) +{ + (void)win; +} + +void Client_MoveResize(Client* c) +{ + 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) ) + { + 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); + } +// mons_place(c); + Redraw(c); +} + + static void ReadProps(Client* c) { Atom *protos = NULL, actual_type, *wintype; @@ -313,27 +337,6 @@ Client* client_add(Window win, XWindowAttributes* attr) } -void client_adjust(Client* c) -{ - 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) ) - { - 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); - } - mons_place(c); -// Redraw(c); -} void client_move(Client* c, int xdiff, int ydiff) { -- 2.51.0