#include "anvil.h"
+#define HiddenState 2
+
static void ReadProps(Client* c);
static void Redraw(Client* c);
static void LayerWindows(void);
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);
void Client_Hide(Client* c)
{
+ SetWMState(c, HiddenState);
XUnmapWindow(X.disp, c->frame);
XUnmapWindow(X.disp, c->win);
}
c->next = AllClients;
AllClients = c;
LayerWindows();
-// mons_layer(mon);
-
}
void Client_Lower(Client* c)
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);
{
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);
}
}
-//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));
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];
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);
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)