printf("BTN_DN(w: 0x%lx s: %d x: %d y: %d rx: %d ry: %d)\n", ev->window, ev->state, ev->x, ev->y, ev->x_root, ev->y_root);
X.start_x = ev->x_root, X.start_y = ev->y_root;
X.last_x = ev->x_root, X.last_y = ev->y_root;
- Location loc = {0};
- if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window))
- {
- Client* c = loc.client;
- if (ev->y < MIN_HEIGHT)
- {
- X.edge = E_TOP;
- }
- else if (ev->y_root > (c->y + c->h - BORDER_WIDTH))
- {
- X.edge = E_BOTTOM;
- }
- else if (ev->x < BORDER_WIDTH)
- {
- X.edge = E_LEFT;
- }
- else if (ev->x_root > (c->x + c->w - BORDER_WIDTH))
- {
- X.edge = E_RIGHT;
- }
- else
- {
- X.edge = E_NONE;
- }
- mouse_down(ev, &loc);
- }
+// Location loc = {0};
+// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window))
+// {
+// Client* c = loc.client;
+// if (ev->y < MIN_HEIGHT)
+// {
+// X.edge = E_TOP;
+// }
+// else if (ev->y_root > (c->y + c->h - BORDER_WIDTH))
+// {
+// X.edge = E_BOTTOM;
+// }
+// else if (ev->x < BORDER_WIDTH)
+// {
+// X.edge = E_LEFT;
+// }
+// else if (ev->x_root > (c->x + c->w - BORDER_WIDTH))
+// {
+// X.edge = E_RIGHT;
+// }
+// else
+// {
+// X.edge = E_NONE;
+// }
+// mouse_down(ev, &loc);
+// }
}
static void xbtnrelease(XEvent* e)
{
XButtonEvent* ev = &(e->xbutton);
printf("BTN_UP(w: 0x%lx x: %d y: %d rx: %d ry: %d)\n", ev->window, ev->x, ev->y, ev->x_root, ev->y_root);
- Location loc = {0};
- if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window))
- {
- mouse_up(ev, &loc);
- }
+// Location loc = {0};
+// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window))
+// {
+// mouse_up(ev, &loc);
+// }
X.mode = M_IDLE;
XUngrabPointer(X.disp, CurrentTime);
}
XMotionEvent *ev = &e->xmotion;
printf("BTN_MV(w: 0x%lx x: %d y: %d rx: %d ry: %d)\n", ev->window, ev->x, ev->y, ev->x_root, ev->y_root);
while (XCheckTypedWindowEvent(X.disp, ev->window, ev->type, e));
- Location loc = {0};
- if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window))
- {
- mouse_drag(ev, &loc);
- }
+// Location loc = {0};
+// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window))
+// {
+// mouse_drag(ev, &loc);
+// }
X.last_x = ev->x_root, X.last_y = ev->y_root;
}
{
XKeyEvent* ev = &(e->xkey);
printf("KEY_DN(w: 0x%lx)\n", ev->window);
- keys_run(ev);
+ Keys_Process(ev);
}
static void init_cursors(void)
check_for_wm();
init_cursors();
init_font();
- mons_init();
- client_initall();
- keys_init();
+// mons_init();
+ Client_InitAll();
+ Keys_Init();
atoms_init();
/* setup window life-cycle management event handlers */
+++ /dev/null
-#include "anvil.h"
-#include <math.h>
-
-static Monitor* pickmon(void);
-static Column* pickcol(Workspace* wspace, int relx);
-static void client_visibility(Workspace* wspace, int show);
-static Client* client_find(Client* clients, Window win);
-static void add_client(Monitor* mon, Client* c, int ptrx);
-static void remove_client(Location* loc, Client* c);
-//static void adjust_all(Column* col, int xoff);
-static void change_wspace(Monitor* mon, Workspace* wspace);
-
-//static int min_col_width(Monitor* mon)
-//{
-// return (int)(mon->w * MIN_COL_FACT);
-//}
-
-void mons_init(void)
-{
- int nmons;
- check( XineramaIsActive(X.disp), "Xinerama extension is required");
- XineramaScreenInfo* mons = XineramaQueryScreens(X.disp, &nmons);
- for (int i = 0; i < nmons; i++)
- {
- Monitor* m = &Monitors[i];
- m->x = mons[i].x_org;
- m->y = mons[i].y_org;
- m->w = mons[i].width;
- m->h = mons[i].height;
- m->midx = m->x + m->w/2;
- m->midy = m->y + m->h/2;
- m->wspace = &Workspaces[i];
- m->wspace->ncolumns = 1;
- }
- Num_Monitors = nmons;
- xfree(mons);
-}
-
-void mons_layer(Monitor* mon)
-{
- int nwins = 0;
- Window* wins = NULL;
- Client* c;
- Workspace* wspace = mon->wspace;
-
- /* add all of the floating windows */
- LIST_FOR_EACH(c, wspace->floating)
- {
- wins = realloc(wins, ++nwins * sizeof(Window));
- wins[nwins-1] = c->frame;
- }
-
- /* now lower all of the tiled windows */
- for (int i = 0; i < wspace->ncolumns; i++)
- {
- LIST_FOR_EACH(c, wspace->columns[i].clients)
- {
- wins = realloc(wins, ++nwins * sizeof(Window));
- wins[nwins-1] = c->frame;
- }
- }
-
- /* restack them and free the array */
- if (nwins)
- {
- XRestackWindows(X.disp, wins, nwins);
- }
- xfree(wins);
-}
-
-/* adds a new client to the most appropriate monitor */
-void mons_addclient(Client* c)
-{
- Monitor* mon = pickmon();
- add_client(mon, c, PtrX);
- mouse_totitle(c);
-}
-
-void mons_delclient(Location* loc)
-{
- if (Focused == loc->client)
- {
- Focused = NULL;
- }
- remove_client(loc, loc->client);
- xfree(loc->client->name);
- XDestroyWindow(X.disp, loc->client->frame);
- free(loc->client);
-}
-
-void mons_togglefloat(Location* loc)
-{
- remove_client(loc, loc->client);
- if (loc->client->flags & (F_FLOATING))
- {
- loc->client->flags &= ~F_FLOATING;
- }
- else
- {
- loc->client->flags |= F_FLOATING;
- }
- mons_addclient(loc->client);
-}
-
-int mons_find(Window win, Location* loc)
-{
- Monitor* mon = NULL;
- Workspace* wspace = NULL;
- Column* column = NULL;
- Client* client = NULL;
-
- /* check if the window is withdrawn */
- client = client_find(Withdrawn, win);
-
- /* otherwise, check if it is on a workspace */
- if (!client)
- {
- for (int i = 0; i < MAX_WSPACE_COUNT; i++)
- {
- wspace = &Workspaces[i];
-
- /* check if the window is floating first */
- client = client_find(wspace->floating, win);
-
- /* if not found, find the window in the columns */
- if (!client)
- {
- for (int c = 0; c < wspace->ncolumns; c++)
- {
- Column* col = &(wspace->columns[c]);
- if ( (client = client_find(col->clients, win)) )
- {
- column = col;
- break;
- }
- }
- }
- }
- }
-
- /* return the client location if we found it */
- if (client)
- {
- loc->monitor = mon;
- loc->workspace = wspace;
- loc->column = column;
- loc->client = client;
- return 1;
- }
-
- return 0;
-}
-
-/* find the best monitor to own the window by calculating the overlap */
-void mons_place(Client* c)
-{
- Location loc;
- 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);
- if (mons_find(c->win, &loc) && !loc.column)
- {
- int maxarea = 0;
- Monitor *mon = NULL, *closest = NULL;
- for (int i =0; i < Num_Monitors; i++)
- {
- mon = &Monitors[i];
- 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);
- if (left < right && top < bot)
- {
- int area = (right - left) * (bot - top);
- if (area > maxarea)
- {
- maxarea = area;
- closest = mon;
- }
- }
- }
- /* if we changed monitors, make sure we update accordingly */
- if (closest && loc.monitor != closest)
- {
- loc.workspace->floating = list_del(loc.workspace->floating, c);
- c->next = closest->wspace->floating;
- closest->wspace->floating = c;
- }
- }
-}
-
-void mons_wspace(int wsid)
-{
- Monitor* mon = pickmon();
- change_wspace(mon, &Workspaces[wsid]);
-}
-
-void mons_towspace(Client* c, int wsid)
-{
- (void)c;
- (void)wsid;
-// TODO: rework how towspace works
-// Location loc = {0};
-// if (mons_find(c->win, &loc))
-// {
-// mouse_get(&PtrX, &PtrY);
-// Workspace* wspace = &Workspaces[wsid];
-// if (wspace != loc.workspace)
-// {
-// remove_client(&loc, c);
-// client_show(c, 0);
-// Workspace* prev = &Workspaces[loc.monitor->wspace];
-// loc.monitor->wspace = wspace;
-// add_client(loc.monitor, c, PtrX);
-// loc.monitor->wspace = prev;
-// }
-// }
-}
-
-void mons_raise(Monitor* mon, Client* c)
-{
- mon->wspace->floating = list_del(mon->wspace->floating, c);
- c->next = mon->wspace->floating;
- mon->wspace->floating = c;
- mons_layer(mon);
-}
-
-void mons_lower(Monitor* mon, Client* c)
-{
- mon->wspace->floating = list_del(mon->wspace->floating, c);
- c->next = NULL;
- if (mon->wspace->floating)
- {
- Client* curr = list_last(mon->wspace->floating);
- curr->next = c;
- }
- else
- {
- mon->wspace->floating = c;
- }
- mons_layer(mon);
-}
-
-void mons_colsplit(void)
-{
-// TODO: implement column splitting
-// Monitor* mon = pickmon();
-// Column* col = pickcol(mon->wspace, PtrX - mon->x);
-// int next_empty = (col->next && !col->next->clients);
-// if (col->clients && !next_empty && col->width >= 2*min_col_width(mon))
-// {
-// Column* newcol = ecalloc(1, sizeof(Column));
-// newcol->width = col->width/2;
-// col->width -= newcol->width;
-// newcol->next = col->next;
-// col->next = newcol;
-// adjust_all(col, 0);
-// }
-}
-
-void mons_coljoin(void)
-{
-// TODO: implement column joining
-// Monitor* mon = pickmon();
-// Column* dest = pickcol(mon->wspace, PtrX - mon->x);
-// Column* dead = dest->next;
-// if (!dead)
-// {
-// dead = dest;
-// dest = list_prev(mon->wspace->columns, dead);
-// }
-//
-// if (dest && dead)
-// {
-// /* add the clients to the current col */
-// for (Client* c = dead->clients; c;)
-// {
-// Client* next = c->next;
-// stacked_add(&(Location){mon, NULL, dest, c});
-// c = next;
-// }
-// dest->next = dead->next;
-// dest->width += dead->width;
-// free(dead);
-// adjust_all(dest, 0);
-// }
-}
-
-void mons_coladjust(Monitor* mon, Column* col, int wdiff)
-{
- (void)mon;
- (void)col;
- (void)wdiff;
-// TODO: implement column resizing
-// Column* neighbor = col->next;
-// int minwidth = min_col_width(mon);
-// if (X.edge == E_LEFT && mon->wspace->columns != col)
-// {
-// for (neighbor = mon->wspace->columns; neighbor && neighbor->next != col; neighbor = neighbor->next);
-// int minadj = -(neighbor->width - minwidth);
-// int maxadj = (col->width - minwidth);
-// wdiff = min(max(minadj, wdiff), maxadj);
-// neighbor->width += wdiff;
-// col->width -= wdiff;
-// adjust_all(col, wdiff);
-// adjust_all(neighbor, 0);
-// }
-// else if (X.edge == E_RIGHT && col->next)
-// {
-// int minadj = -(col->width - minwidth);
-// int maxadj = (neighbor->width - minwidth);
-// wdiff = min(max(minadj, wdiff), maxadj);
-// col->width += wdiff;
-// neighbor->width -= wdiff;
-// adjust_all(col, 0);
-// adjust_all(neighbor, wdiff);
-// }
-// else
-// {
-// /* invalid edge */
-// }
-}
-
-void mons_tilemove(Location* loc, int hdiff)
-{
- Monitor* mon = pickmon();
- Column* col = pickcol(mon->wspace, PtrX - mon->x);
- if (loc->monitor != mon || loc->column != col)
- {
- remove_client(loc, loc->client);
- client_setshade(loc->client, 0);
- loc->monitor = mon;
- loc->column = col;
- stacked_add(loc);
- }
- else
- {
- stacked_addheight(loc, hdiff);
- }
- mouse_totitle(loc->client);
-}
-
-void mons_activate(Window win)
-{
- Location loc;
- if (mons_find(win, &loc))
- {
- change_wspace(loc.monitor, loc.workspace);
- if (!loc.column)
- {
- mons_raise(loc.monitor, loc.client);
- }
- }
-}
-
-static Monitor* pickmon(void)
-{
- mouse_get(&PtrX, &PtrY);
- Monitor* monitor = NULL;
- for (int i = 0; i < Num_Monitors; i++)
- {
- Monitor* mon = &Monitors[i];
- if ((mon->x <= PtrX && PtrX < mon->x+mon->w) &&
- (mon->y <= PtrY && PtrY < mon->y+mon->h))
- {
- monitor = mon;
- break;
- }
- }
- monitor = (monitor ? monitor : &Monitors[0]);
- return monitor;
-}
-
-static Column* pickcol(Workspace* wspace, int relx)
-{
- Column* col;
- int left = 0, right = 0;
- for (int i = 0; i < wspace->ncolumns; i++)
- {
- left = right, right += wspace->columns[i].width;
- if (left <= relx && relx < right)
- {
- col = &wspace->columns[i];
- break; /* we found the column holding the mouse */
- }
- }
- return col;
-}
-
-static void client_visibility(Workspace* wspace, int show)
-{
- Column* col;
- Client* client;
- LIST_FOR_EACH(client, wspace->floating)
- {
- client_show(client, show);
- }
- for (int i = 0; i < wspace->ncolumns; i++)
- {
- col = &(wspace->columns[i]);
- LIST_FOR_EACH(client, col->clients)
- {
- client_show(client, show);
- }
- }
-}
-
-static Client* client_find(Client* clients, Window win)
-{
- Client* client;
- LIST_FOR_EACH_UNTIL(client, clients,
- (client->frame == win || client->win == win));
- return client;
-}
-
-static void add_client(Monitor* mon, Client* c, int ptrx)
-{
- if (X.mode == M_INIT || c->flags & (F_DIALOG|F_FLOATING))
- {
- c->next = mon->wspace->floating;
- mon->wspace->floating = c;
- c->x = mon->midx - c->w/2;
- c->y = mon->midy - c->h/2;
- client_adjust(c);
- }
- else
- {
- Column* col = NULL;
- /* find first empty column, and fill that first */
- for (int i = 0; i < mon->wspace->ncolumns; i++)
- {
- if (mon->wspace->columns[i].clients == NULL)
- {
- col = &mon->wspace->columns[i];
- break;
- }
- }
-
- /* otherwise pick the column to the right of the current column */
- if (!col)
- {
- Column* c = pickcol(mon->wspace, ptrx - mon->x);
- int cid = (c - mon->wspace->columns);
- if (cid < (mon->wspace->ncolumns - 1))
- {
- cid++;
- }
- col = &mon->wspace->columns[cid];
- }
-
- /* add the client to the stack */
- stacked_add(&(Location){mon, NULL, col, c});
- }
- mons_layer(mon);
-}
-
-static void remove_client(Location* loc, Client* c)
-{
- if (!loc->column)
- {
- loc->workspace->floating = list_del(loc->workspace->floating, c);
- }
- else
- {
- stacked_del(loc);
- }
-}
-
-//static void adjust_all(Column* col, int xoff)
-//{
-// (void)col;
-// (void)xoff;
-//// Client* c;
-//// LIST_FOR_EACH(c, col->clients)
-//// {
-//// c->x += xoff;
-//// c->w = col->width;
-//// client_adjust(c);
-//// }
-//}
-
-static void change_wspace(Monitor* mon, Workspace* wspace)
-{
- if (mon->wspace != wspace)
- {
- client_visibility(mon->wspace, 0);
- client_visibility(wspace, 1);
- mon->wspace = wspace;
- }
-}
+++ /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, *h = mon->h;
- for (int i = 0 ; i < mon->wspace->ncolumns; i++)
- {
- if (col == &(mon->wspace->columns[i]))
- {
- break;
- }
- *x += mon->wspace->columns[i].width;
- }
-}
-
-void stacked_add(Location* loc)
-{
- Client* c = loc->client;
- coldims(loc->monitor, loc->column, &(c->x), &(c->y), &(c->w), &(c->h));
- if (loc->column->clients)
- {
- Client *cl, *max = loc->column->clients;
- LIST_FOR_EACH(cl, max)
- {
- if (cl->h > max->h)
- {
- max = cl;
- }
- }
- if (max->h < 3*MIN_HEIGHT)
- {
- int cid = (loc->column - loc->monitor->wspace->columns);
- if ((cid + 1) < loc->monitor->wspace->ncolumns)
- {
- stacked_add(loc);
- }
- else
- {
- c->next = loc->monitor->wspace->floating;
- loc->monitor->wspace->floating = c;
- c->x = loc->monitor->midx - c->w/2;
- c->y = loc->monitor->midy - c->h/2;
- client_adjust(c);
- }
- }
- else
- {
- c->h = max->h/2;
- c->y = max->y + c->h;
- c->w = max->w;
- max->h -= max->h/2;
- c->next = max->next;
- max->next = c;
- client_adjust(c);
- client_adjust(max);
- }
- }
- else
- {
- c->next = loc->column->clients;
- loc->column->clients = c;
- client_adjust(c);
- }
-}
-
-void stacked_del(Location* loc)
-{
- Client* c = loc->client;
- if (loc->column->clients == c)
- {
- loc->column->clients = c->next;
- if (loc->column->clients)
- {
- loc->column->clients->h += loc->column->clients->y - loc->monitor->y;
- loc->column->clients->y = loc->monitor->y;
- client_setshade(loc->column->clients, 0);
- client_adjust(loc->column->clients);
- }
- }
- else
- {
- Client* prev = list_prev(loc->column->clients, c);
- prev->next = c->next;
- prev->h += c->h;
- client_setshade(prev, 0);
- client_adjust(prev);
- }
-}
-
-void stacked_set(Location* loc)
-{
- Client *curr, *c = loc->client;
- int starty = loc->monitor->y;
- /* stack the windows before the target */
- LIST_FOR_EACH_UNTIL(curr, loc->column->clients, curr == c)
- {
- curr->y = starty;
- curr->h = MIN_HEIGHT;
- client_setshade(curr, 1);
- client_adjust(curr);
- starty += MIN_HEIGHT;
- }
- /* expand the target window */
- int nclients = list_length(curr->next);
- curr->y = starty;
- curr->h = (loc->monitor->h - starty) - (nclients * MIN_HEIGHT);
- client_setshade(c, 0);
- client_adjust(curr);
- mouse_totitle(curr);
- starty = (curr->y + curr->h - 1);
- /* stack the windows after the target */
- LIST_FOR_EACH(curr, curr->next)
- {
- curr->y = starty;
- curr->h = MIN_HEIGHT;
- client_setshade(curr, 1);
- client_adjust(curr);
- starty += MIN_HEIGHT;
- }
-}
-
-void stacked_addheight(Location* loc, int amount)
-{
- Client* c = loc->client;
- Client* prev = list_prev(loc->column->clients, c);
- if (prev)
- {
- amount = (abs(amount) < BORDER_WIDTH ? min((int)(-c->h * 0.25), -2*MIN_HEIGHT) : amount);
- int miny = (prev->y + MIN_HEIGHT);
- int maxy = min((loc->monitor->y + loc->monitor->h) , (c->y + c->h)) - MIN_HEIGHT;
- c->y = max(miny, min(maxy, c->y + amount));
- prev->h = c->y - prev->y;
- c->h = (c->next ? c->next->y : loc->monitor->y + loc->monitor->h) - c->y;
- client_setshade(prev, (prev->h <= MIN_HEIGHT));
- client_setshade(c, (c->h <= MIN_HEIGHT));
- client_adjust(prev);
- client_adjust(c);
- }
-}