void mouse_click(XButtonEvent* ev, Location* loc);
void mouse_drag(XMotionEvent* ev, Location* loc);
+/* tile.c */
+void monocled_add(Monitor* mon, Column* col, Client* c);
+void monocled_del(Monitor* mon, Column* col, Client* c);
+void expanded_add(Monitor* mon, Column* col, Client* c);
+void expanded_del(Monitor* mon, Column* col, Client* c);
+void stacked_add(Monitor* mon, Column* col, Client* c);
+void stacked_del(Monitor* mon, Column* col, Client* c);
+
/* error.c */
extern int (*error_default)(Display* disp, XErrorEvent* ev);
int error_init(Display* disp, XErrorEvent* ev);
Atom atom(char* str);
void sendmsg(Window win, Atom proto, Atom type);
void warp_mouse(Client* c);
+Client* delclient(Client* list, Client* dead);
static Monitor* pickmon(int ptrx, int ptry);
static Column* pickcol(Column* cols, int relx);
static Workspace* pickws(Monitor* mon, int wsid);
-static Client* delclient(Client* list, Client* dead);
static void client_visibility(Workspace* wspace, int show);
static Client* client_find(Client* clients, Window win);
xfree(mons);
}
-static void coldims(Monitor* mon, Column* col, int *x, int *y, int *w, int *h)
-{
- *x = mon->x, *y = mon->y, *w = col->width-2, *h = mon->h-2;
-// printf("bef: %d %d %d %d\n", mon->x, mon->y, col->width, mon->h);
-// printf("mon: %d %d %d %d\n", mon->x, mon->y, mon->w, mon->h);
- for (Column* c = mon->cspace->columns; c != col; *x += c->width, c = c->next);
-// printf("%d %d %d %d\n", *x, *y, *w, *h);
-}
-
void mons_layer(Monitor* mon)
{
/* lower all of the floating windows first */
}
}
-static void add_monocle(Monitor* mon, Column* col, Client* c)
-{
- coldims(mon, col, &(c->x), &(c->y), &(c->w), &(c->h));
- client_adjust(c);
- c->next = col->clients;
- col->clients = c;
-}
-
-static void add_expand(Monitor* mon, Column* col, Client* client)
-{
- /*
- * stack all existing clients top to bottom only showing title bars
- * move+resize new client to fill remaining space or place its title bar at bottom of screen
- */
- (void)mon, (void)col;
- client->next = col->clients;
- col->clients = client;
-}
-
-static void add_stacked(Monitor* mon, Column* col, Client* client)
-{
- coldims(mon, col, &(client->x), &(client->y), &(client->w), &(client->h));
- if (col->clients)
- {
- Client* max = col->clients;
- for (Client* c = max; c; c = c->next)
- {
- if (c->h > max->h)
- {
- max = c;
- }
- }
- client->h = max->h/2;
- client->y = max->y + client->h;
- max->h -= max->h/2;
- client->next = max->next;
- max->next = client;
- client_adjust(max);
- client_adjust(client);
- }
- else
- {
- client->next = col->clients;
- col->clients = client;
- client_adjust(client);
- }
-}
-
/* adds a new client to the most appropriate monitor */
void mons_addclient(Client* c)
{
Column* col = pickcol(mon->cspace->columns, ptrx - mon->x);
if (col->mode == TILE_MONOCLE)
{
- add_monocle(mon, col, c);
+ monocled_add(mon, col, c);
}
else if (col->mode == TILE_EXPAND)
{
- add_expand(mon, col, c);
+ expanded_add(mon, col, c);
}
else if (col->mode == TILE_STACKED)
{
- add_stacked(mon, col, c);
+ stacked_add(mon, col, c);
}
}
mons_layer(mon);
Location loc = {0};
if (mons_find(c->win, &loc))
{
- if (loc.column)
+ if (!loc.column)
+ {
+ loc.workspace->floating = delclient(loc.workspace->floating, c);
+ }
+ else if (loc.column->mode == TILE_MONOCLE)
+ {
+ monocled_del(loc.monitor, loc.column, loc.client);
+ }
+ else if (loc.column->mode == TILE_EXPAND)
+ {
+ expanded_del(loc.monitor, loc.column, loc.client);
+ }
+ else if (loc.column->mode == TILE_STACKED)
{
- loc.column->clients = delclient(loc.column->clients, c);
+ stacked_del(loc.monitor, loc.column, loc.client);
}
else
{
- loc.workspace->floating = delclient(loc.workspace->floating, c);
+ assert(0);
}
xfree(c->name);
XDestroyWindow(X.disp, c->frame);
return wspace;
}
-static Client* delclient(Client* list, Client* dead)
-{
- if (!list)
- {
- return NULL;
- }
- else if (list == dead)
- {
- return list->next;
- }
- else
- {
- list->next = delclient(list->next, dead);
- return list;
- }
-}
-
static void client_visibility(Workspace* wspace, int show)
{
for (Client* client = wspace->floating; client; client = client->next)
{
client_show(client, show);
}
+ for (Column* col = wspace->columns; col; col = col->next)
+ {
+ for (Client* client = col->clients; client; client = client->next)
+ {
+ client_show(client, show);
+ }
+ }
XSync(X.disp, False);
}
--- /dev/null
+#include "anvil.h"
+
+static void coldims(Monitor* mon, Column* col, int *x, int *y, int *w, int *h)
+{
+ *x = mon->x, *y = mon->y, *w = col->width-2, *h = mon->h-2;
+ for (Column* c = mon->cspace->columns; c != col; *x += c->width, c = c->next);
+}
+
+void monocled_add(Monitor* mon, Column* col, Client* c)
+{
+ coldims(mon, col, &(c->x), &(c->y), &(c->w), &(c->h));
+ client_adjust(c);
+ c->next = col->clients;
+ col->clients = c;
+}
+
+void monocled_del(Monitor* mon, Column* col, Client* c)
+{
+ (void)mon;
+ col->clients = delclient(col->clients, c);
+}
+
+void expanded_add(Monitor* mon, Column* col, Client* c)
+{
+ /*
+ * stack all existing clients top to bottom only showing title bars
+ * move+resize new client to fill remaining space or place its title bar at bottom of screen
+ */
+ (void)mon;
+ c->next = col->clients;
+ col->clients = c;
+}
+
+void expanded_del(Monitor* mon, Column* col, Client* c)
+{
+ (void)mon;
+ col->clients = delclient(col->clients, c);
+}
+
+void stacked_add(Monitor* mon, Column* col, Client* c)
+{
+ coldims(mon, col, &(c->x), &(c->y), &(c->w), &(c->h));
+ if (col->clients)
+ {
+ Client* max = col->clients;
+ for (Client* c = max; c; c = c->next)
+ {
+ if (c->h > max->h)
+ {
+ max = c;
+ }
+ }
+ c->h = max->h/2;
+ c->y = max->y + c->h;
+ max->h -= max->h/2;
+ c->next = max->next;
+ max->next = c;
+ client_adjust(max);
+ client_adjust(c);
+ }
+ else
+ {
+ c->next = col->clients;
+ col->clients = c;
+ client_adjust(c);
+ }
+}
+
+void stacked_del(Monitor* mon, Column* col, Client* c)
+{
+ if (col->clients == c)
+ {
+ col->clients = c->next;
+ if (col->clients)
+ {
+ col->clients->h += col->clients->y - mon->y;
+ col->clients->y = mon->y;
+ client_adjust(col->clients);
+ }
+ }
+ else
+ {
+ Client* prev = col->clients;
+ for (; prev->next != c; prev = prev->next);
+ prev->next = c->next;
+ prev->h += c->h;
+ client_adjust(prev);
+ }
+}
+