From 5e8aceb5cc92d95ba7275d8b43f0941eec484cef Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 5 Aug 2024 23:16:34 -0400 Subject: [PATCH] use relative positioning to keep windows in the right spot as workspaces move around and implement moving windows between workspaces --- anvil.h | 4 ++-- client.c | 19 ++++++++----------- monitors.c | 4 ++-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/anvil.h b/anvil.h index d097e2c..3f08f62 100644 --- a/anvil.h +++ b/anvil.h @@ -80,7 +80,7 @@ typedef struct Client { struct Client* next; char* name; Window frame, win; - int state, flags, wspace, x, y, w, h; + int state, flags, wspace, x, y, w, h, rel_x, rel_y; long hint_flags, wm_flags; XWMHints hints; XSizeHints size_hints; @@ -92,7 +92,7 @@ typedef struct Client { // int width; // Client* clients; //} Column; -// + typedef struct Workspace { int monitor; // Client* floating; diff --git a/client.c b/client.c index 89e3138..7451c01 100644 --- a/client.c +++ b/client.c @@ -127,6 +127,8 @@ Client* Client_Create(Window win) XFree(hints); } } + Client_Place(c); + } return c; } @@ -136,18 +138,11 @@ Client* Client_Create(Window win) void Client_Show(Client* c) { - /* - If window not overlapping workspace - center on configured workspace - end - */ + /* position it with relative coords */ Monitor* mon = &Monitors[Workspaces[c->wspace].monitor]; - if (MonitorOverlap(mon, c) == 0) - { - c->x = mon->midx - c->w/2; - c->y = mon->midy - c->h/2; - Client_MoveResize(c); - } + c->x = mon->x + c->rel_x; + c->y = mon->y + c->rel_y; + Client_MoveResize(c); ReadProps(c); SetWMState(c, NormalState); @@ -272,6 +267,8 @@ void Client_Place(Client* c) /* update the workspace this client is mapped to */ c->wspace = Monitors[monitor].wspace; + c->rel_x = c->x - Monitors[monitor].x; + c->rel_y = c->y - Monitors[monitor].y; } static void ReadProps(Client* c) diff --git a/monitors.c b/monitors.c index 60d0f5e..478b136 100644 --- a/monitors.c +++ b/monitors.c @@ -81,6 +81,6 @@ void Monitors_SetWorkspace(int ws_id) void Monitors_SendToWorkspace(Client* c, int id) { - (void)c; - (void)id; + c->wspace = id; + Client_UpdateAll(); // TODO: this is overkill... } -- 2.51.0