wc.border_width = ev->border_width;
wc.sibling = ev->above;
wc.stack_mode = ev->detail;
-// Location loc = {0};
-// if (mons_find(ev->window, &loc))
-// {
-// /* only allow floating clients to resize on their own */
-// if ((loc.client->win == ev->window) && !loc.column)
-// {
-// loc.client->w = wc.width + FRAME_WIDTH_SUM;
-// loc.client->h = wc.height + FRAME_HEIGHT_SUM;
-// client_adjust(loc.client);
-// if (X.mode == M_RESIZE && Focused == loc.client)
-// {
-// mouse_tocorner(loc.client);
-// }
-// }
-// }
-// else
+ Client* c = Client_Find(ev->window);
+ if (c)
+ {
+ c->w = wc.width + FRAME_WIDTH_SUM;
+ c->h = wc.height + FRAME_HEIGHT_SUM;
+ Client_MoveResize(c);
+ if (X.mode == M_RESIZE /* && Focused == c */)
+ {
+ Mouse_ToCorner(c);
+ }
+ }
+ else
{
XConfigureWindow(X.disp, ev->window, ev->value_mask, &wc);
}
{
XClientMessageEvent* ev = &(e->xclient);
printf("CLIENT_MSG(w: 0x%lx a: '%s')\n", ev->window, XGetAtomName(X.disp, ev->message_type));
- if (ev->message_type == _NET_ACTIVE_WINDOW)
- {
-// mons_activate(ev->window);
- }
+// if (ev->message_type == _NET_ACTIVE_WINDOW)
+// {
+//// mons_activate(ev->window);
+// }
}
static void xpropnotify(XEvent* e)
{
XPropertyEvent* ev = &(e->xproperty);
printf("PROP_NOTIFY(w: 0x%lx)\n", ev->window);
-// Location loc = {0};
-// if (mons_find(ev->window, &loc))
-// {
-// client_readprops(loc.client);
-// client_draw(loc.client);
-// }
+ Client* c = Client_Find(ev->window);
+ if (c)
+ {
+ Client_Update(c);
+ }
}
static void xenternotify(XEvent* e)
{
XCrossingEvent* ev = &(e->xcrossing);
-// Location loc = {0};
printf("ENTER(w: 0x%lx s: %d m: %d d: %d)\n", ev->window, ev->state, ev->mode, ev->detail);
-// if (mons_find(ev->window, &loc))
-// {
-// client_focus(loc.client);
-// }
+ Client* c = Client_Find(ev->window);
+ if (c)
+ {
+ Client_Focus(c);
+ }
}
static void xexpose(XEvent* e)
if (ev->count == 0)
{
printf("EXPOSE(w: 0x%lx)\n", ev->window);
-// Location loc = {0};
-// if (mons_find(ev->window, &loc))
-// {
-// client_draw(loc.client);
-// }
+ Client* c = Client_Find(ev->window);
+ if (c)
+ {
+ Client_Update(c);
+ }
}
}
{
XMapEvent* ev = &(e->xmap);
printf("MAP(e: 0x%lx w: 0x%lx)\n", ev->event, ev->window);
-// Location loc = {0};
-// if (mons_find(ev->window, &loc))// && loc.client->win == ev->window)
-// {
-// client_draw(loc.client);
-// }
+ Client* c = Client_Find(ev->window);
+ if (c)
+ {
+ Client_Update(c);
+ }
}
-
-
static void xkeypress(XEvent* e)
{
XKeyEvent* ev = &(e->xkey);
atoms_init();
/* setup window life-cycle management event handlers */
-// X.eventfns[CreateNotify] = xcreatenotify;
X.eventfns[MapRequest] = xmaprequest;
X.eventfns[UnmapNotify] = xunmapnotify;
X.eventfns[DestroyNotify] = xdestroynotify;
void Client_MoveResize(Client* c);
void Client_Move(Client* c, int xdiff, int ydiff);
void Client_Resize(Client* c, int xdiff, int ydiff);
+void Client_Raise(Client* c);
+void Client_Lower(Client* c);
+void Client_Update(Client* c);
+void Client_Focus(Client* client);
+void Client_Close(Client* client);
//Client* client_add(Window win, XWindowAttributes* attr);
//void client_draw(Client* c);
static void ReadProps(Client* c);
static void Redraw(Client* c);
+static void LayerWindows(void);
void SetWMState(Client *c, int state)
{
void Client_Destroy(Window win)
{
- (void)win;
+ Client* c = Client_Find(win);
+ if (c)
+ {
+ if (Focused == c)
+ {
+ Focused = NULL;
+ }
+ AllClients = list_del(AllClients, c);
+ xfree(c->name);
+ XDestroyWindow(X.disp, c->frame);
+ free(c);
+ }
}
void Client_MoveResize(Client* c)
{
int shaded = (c->flags & F_SHADED);
- int floating = (c->flags & (F_DIALOG|F_FLOATING));
+ int floating = 1; //(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;
Client_MoveResize(c);
}
+void Client_Raise(Client* c)
+{
+ AllClients = list_del(AllClients, c);
+ c->next = AllClients;
+ AllClients = c;
+ LayerWindows();
+// mons_layer(mon);
+
+}
+
+void Client_Lower(Client* c)
+{
+ (void)c;
+}
+
+void Client_Update(Client* c)
+{
+ ReadProps(c);
+ Redraw(c);
+}
+
+void Client_Focus(Client* client)
+{
+ Client* prev = Focused;
+ Focused = client;
+ XSetInputFocus(X.disp, client->win, RevertToPointerRoot, CurrentTime);
+ Redraw(client);
+ if (prev)
+ {
+ Redraw(prev);
+ }
+}
+
+void Client_Close(Client* client)
+{
+ if (client->flags & F_WM_DELETE)
+ {
+ sendmsg(client->win, WM_PROTOCOLS, WM_DELETE_WINDOW);
+ }
+ else
+ {
+ XKillClient(X.disp, client->win);
+ }
+}
+
static void ReadProps(Client* c)
{
Atom *protos = NULL, actual_type, *wintype;
}
/* tell the window to redraw itself */
-// XClearArea(X.disp, c->win, 0, 0, 0, 0, True);
+\
}
+void LayerWindows(void)
+{
+ int nwins = 0;
+ Window* wins = NULL;
+ Client* c;
+ LIST_FOR_EACH(c, AllClients)
+ {
+ wins = realloc(wins, ++nwins * sizeof(Window));
+ wins[nwins-1] = c->frame;
+ }
+// /* add in the monocled windows first */
+// LIST_FOR_EACH(col, mon->cspace->columns)
+// {
+// if (col->focused)
+// {
+// wins = realloc(wins, ++nwins * sizeof(Window));
+// wins[nwins-1] = col->focused->frame;
+// }
+// }
+// /* now lower all of the tiled windows */
+// LIST_FOR_EACH(col, mon->cspace->columns)
+// {
+// LIST_FOR_EACH(c, col->clients)
+// {
+// if (col->focused != c)
+// {
+// wins = realloc(wins, ++nwins * sizeof(Window));
+// wins[nwins-1] = c->frame;
+// }
+// }
+// }
+ if (nwins)
+ {
+ XRestackWindows(X.disp, wins, nwins);
+ }
+ xfree(wins);
+}
// Client_MoveResize(c);
//}
//
-//void client_close(Client* c)
-//{
-// if (c->flags & F_WM_DELETE)
-// {
-// sendmsg(c->win, WM_PROTOCOLS, WM_DELETE_WINDOW);
-// }
-// else
-// {
-// XKillClient(X.disp, c->win);
-// }
-//}
-//
-//void client_focus(Client* c)
-//{
-// Client* prev = Focused;
-// Focused = c;
-// XSetInputFocus(X.disp, c->win, RevertToPointerRoot, CurrentTime);
-// Redraw(Focused);
-// if (prev)
-// {
-// Redraw(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_shade(Client* c)
//{
(void)arg;
if (Focused)
{
-// client_close(Focused);
+ Client_Close(Focused);
}
}
{
(void)client;
// mons_lower(loc->monitor, loc->client);
+ Client_Lower(client);
}
static void raise_client(Client* client)
{
- (void)client;
+ Client_Raise(client);
// mons_raise(loc->monitor, loc->client);
}
}
}
}
-//
-//void mouse_down(XButtonEvent* ev, Location* loc)
-//{
-// if (!loc->column)
-// {
-// process(ev, loc, Floating, sizeof(Floating)/sizeof(Floating[0]));
-// }
-// else
-// {
-// process(ev, loc, Stacked, sizeof(Stacked)/sizeof(Stacked[0]));
-// }
-//}
-//
-//static void float_drag(XMotionEvent* ev, Location* loc)
-//{
-//}
-//
-//void mouse_up(XButtonEvent* ev, Location* loc)
-//{
-// (void)ev;
-// (void)loc;
-//}
-//
-//void mouse_drag(XMotionEvent* ev, Location* loc)
-//{
-// if (!loc->column)
-// {
-// float_drag(ev, loc);
-// }
-//}
-//
+
//
//void mouse_totitle(Client* c)
//{