From: Mike Lowis Date: Mon, 5 Aug 2024 20:25:52 +0000 (-0400) Subject: windows now track which workspace they are on and workspaces can be swapped between... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=65ab9484dca322a8fc7874ea32a6e74626fd48b3;p=proto%2Fanvil.git windows now track which workspace they are on and workspaces can be swapped between monitors. Need to handle the swapping better so centering all the floating windows is not the actual solution --- diff --git a/client.c b/client.c index 9aae909..4cd601d 100644 --- a/client.c +++ b/client.c @@ -1,5 +1,7 @@ #include "anvil.h" +#define HiddenState 2 + static void ReadProps(Client* c); static void Redraw(Client* c); static void LayerWindows(void); @@ -128,9 +130,49 @@ Client* Client_Create(Window win) return c; } +static int MonitorOverlap(Monitor* mon, Client* c) +{ + /* calculate client boundaries */ + 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); + + /* calculate monitor boundaries */ + 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); + + + /* return the overlapped area */ + int area = 0; + if (left < right && top < bot) + { + area = (right - left) * (bot - top); + } + return area; +} + + + void Client_Show(Client* c) { + /* + If window not overlapping workspace + center on configured workspace + end + */ + 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); + } + ReadProps(c); + SetWMState(c, NormalState); XMapWindow(X.disp, c->frame); XMapWindow(X.disp, c->win); Redraw(c); @@ -138,6 +180,7 @@ void Client_Show(Client* c) void Client_Hide(Client* c) { + SetWMState(c, HiddenState); XUnmapWindow(X.disp, c->frame); XUnmapWindow(X.disp, c->win); } @@ -196,8 +239,6 @@ void Client_Raise(Client* c) c->next = AllClients; AllClients = c; LayerWindows(); -// mons_layer(mon); - } void Client_Lower(Client* c) @@ -237,7 +278,8 @@ void Client_Close(Client* client) void Client_Place(Client* c) { - /* caclulate client boundaries */ + (void)c; + /* calculate client boundaries */ int cleft = (c->x - BORDER_WIDTH); int cright = (c->x + c->w + 2*BORDER_WIDTH); int ctop = (c->y - BORDER_WIDTH); @@ -443,17 +485,22 @@ void Client_UpdateAll(void) { wspace_mask |= (1 << Monitors[i].wspace); } + printf("0x%x\n", wspace_mask); Client* c; LIST_FOR_EACH(c, AllClients) { int wspace_active = ((wspace_mask & (1 << c->wspace)) != 0); + printf("(0x%x & 0x%x) != 0 == %d\n", wspace_mask, (1 << c->wspace), wspace_active); + if (wspace_active && (c->state != WithdrawnState)) { + printf("Show 0x%lx\n", c->win); Client_Show(c); } else { + printf("Hide 0x%lx\n", c->win); Client_Hide(c); } } @@ -464,54 +511,6 @@ void Client_UpdateAll(void) -//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; -// 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); -// Redraw(c); -// return c; -//} -// -// -// -//void client_move(Client* c, int xdiff, int ydiff) -//{ -// c->x += xdiff; -// c->y += ydiff; -// Client_MoveResize(c); -//} -// -//void client_resize(Client* c, int xdiff, int ydiff) -//{ -// c->w += xdiff; -// c->h += ydiff; -// Client_MoveResize(c); -//} -// -// //void client_shade(Client* c) //{ // client_setshade(c, ((c->flags & F_SHADED) ? 0 : 1)); diff --git a/monitors.c b/monitors.c index 83641fa..60d0f5e 100644 --- a/monitors.c +++ b/monitors.c @@ -23,6 +23,7 @@ void Monitors_Init(void) int nmons; XineramaScreenInfo* mons = XineramaQueryScreens(X.disp, &nmons); nmons = min(MAX_MONITOR_COUNT, nmons); + /* initialize the monitors */ for (int i = 0; i < nmons; i++) { Monitor* m = &Monitors[i]; @@ -37,6 +38,14 @@ void Monitors_Init(void) printf("x: %d y: %d w: %d h: %d ws: %d\n", m->x, m->y, m->w, m->h, m->wspace); } Num_Monitors = nmons; + + /* now initialize the unused monitors */ + for (int i = Num_Monitors; i < MAX_MONITOR_COUNT; i++) + { + memset(&Monitors[i], 0, sizeof(Monitor)); + Monitors[i].wspace = i; + Workspaces[i].monitor = i; + } if (mons) { XFree(mons); @@ -53,18 +62,21 @@ void Monitors_SetWorkspace(int ws_id) int mon_id = GetActiveMonitor(); int other_mon_id = Workspaces[ws_id].monitor; printf("MONITORS %d %d\n", mon_id, other_mon_id); - if (mon_id != other_mon_id) { int prev_ws = Monitors[mon_id].wspace; printf("SWAPPING %d %d\n", prev_ws, ws_id); + Monitors[mon_id].wspace = ws_id; - Monitors[other_mon_id].wspace = prev_ws; + Workspaces[ws_id].monitor = mon_id; + Monitors[other_mon_id].wspace = prev_ws; + Workspaces[prev_ws].monitor = other_mon_id; Client_UpdateAll(); } XUngrabServer(X.disp); + XSync(X.disp, False); } void Monitors_SendToWorkspace(Client* c, int id)