#include <math.h>
int PtrX = 0, PtrY = 0;
-static Monitor* pickmon(void);
+
+//static Monitor* pickmon(void);
//static Column* pickcol(Column* cols, int relx);
-static Workspace* pickws(Monitor* mon, int wsid);
-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 Workspace* pickws(Monitor* mon, int wsid);
+//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 void change_wspace(Monitor* mon, Workspace* wspace);
Monitor Monitors[MAX_MONITORS];
int mons_find(Window win, Location* loc)
{
- for (int m = 0; m < MAX_MONITORS; m++)
- {
- for (int i = 0; i < NUM_WORKSPACES; i++)
- {
- Workspace* wspace = &(Monitors[m].wspaces[i]);
- Column* column = NULL;
- Client* client = client_find(wspace->floating, win);
- if (!client)
- {
- for (int i =0; i < wspace->ncolumns; i++)
- {
- Column* column = &wspace->columns[i];
- if ( (client = client_find(column->clients, win)) )
- {
- break;
- }
- }
- }
- /* return the client location if we found it */
- if (client)
- {
- loc->monitor = &Monitors[m];
- loc->workspace = wspace;
- loc->column = column;
- loc->client = client;
- return 1;
- }
- }
- }
+// for (int m = 0; m < MAX_MONITORS; m++)
+// {
+// for (int i = 0; i < NUM_WORKSPACES; i++)
+// {
+// Workspace* wspace = &(Monitors[m].wspaces[i]);
+// Column* column = NULL;
+// Client* client = client_find(wspace->floating, win);
+// if (!client)
+// {
+// for (int i =0; i < wspace->ncolumns; i++)
+// {
+// Column* column = &wspace->columns[i];
+// if ( (client = client_find(column->clients, win)) )
+// {
+// break;
+// }
+// }
+// }
+// /* return the client location if we found it */
+// if (client)
+// {
+// loc->monitor = &Monitors[m];
+// loc->workspace = wspace;
+// loc->column = column;
+// loc->client = client;
+// return 1;
+// }
+// }
+// }
return 0;
}
/* 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);
+// 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);
+// 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_layer(Monitor* mon)
{
- int nwins = 0;
- Window* wins = NULL;
- Client* c;
- Column* col;
- LIST_FOR_EACH(c, mon->cspace->floating)
- {
- wins = realloc(wins, ++nwins * sizeof(Window));
- wins[nwins-1] = c->frame;
- }
-
- /* first lower all of the tiled windows */
- for (int i =0; i < mon->cspace->ncolumns; i++)
- {
- col = &mon->cspace->columns[i];
- LIST_FOR_EACH(c, col->clients)
- {
- wins = realloc(wins, ++nwins * sizeof(Window));
- wins[nwins-1] = c->frame;
- }
- }
- if (nwins)
- {
- XRestackWindows(X.disp, wins, nwins);
- }
- xfree(wins);
+// int nwins = 0;
+// Window* wins = NULL;
+// Client* c;
+// Column* col;
+// LIST_FOR_EACH(c, mon->cspace->floating)
+// {
+// wins = realloc(wins, ++nwins * sizeof(Window));
+// wins[nwins-1] = c->frame;
+// }
+//
+// /* first lower all of the tiled windows */
+// for (int i =0; i < mon->cspace->ncolumns; i++)
+// {
+// col = &mon->cspace->columns[i];
+// LIST_FOR_EACH(c, col->clients)
+// {
+// wins = realloc(wins, ++nwins * sizeof(Window));
+// wins[nwins-1] = c->frame;
+// }
+// }
+// if (nwins)
+// {
+// XRestackWindows(X.disp, wins, nwins);
+// }
+// xfree(wins);
}
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);
+// 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);
}
/* find the best monitor to own the window by calculating the overlap */
void mons_wspace(int wsid)
{
- Monitor* mon = pickmon();
- change_wspace(mon, pickws(mon, wsid));
+// Monitor* mon = pickmon();
+// change_wspace(mon, pickws(mon, wsid));
}
void mons_towspace(Client* c, int wsid)
{
- Location loc = {0};
- if (mons_find(c->win, &loc))
- {
- mouse_get(&PtrX, &PtrY);
- Workspace* wspace = pickws(loc.monitor, wsid);
- if (wspace != loc.workspace)
- {
- remove_client(&loc, c);
-// client_show(c, 0);
- Workspace* prev = loc.monitor->cspace;
- loc.monitor->cspace = wspace;
- add_client(loc.monitor, c, PtrX);
- loc.monitor->cspace = prev;
- }
- }
+// Location loc = {0};
+// if (mons_find(c->win, &loc))
+// {
+// mouse_get(&PtrX, &PtrY);
+// Workspace* wspace = pickws(loc.monitor, wsid);
+// if (wspace != loc.workspace)
+// {
+// remove_client(&loc, c);
+//// client_show(c, 0);
+// Workspace* prev = loc.monitor->cspace;
+// loc.monitor->cspace = wspace;
+// add_client(loc.monitor, c, PtrX);
+// loc.monitor->cspace = prev;
+// }
+// }
}
void mons_raise(Monitor* mon, Client* c)
{
- mon->cspace->floating = list_del(mon->cspace->floating, c);
- c->next = mon->cspace->floating;
- mon->cspace->floating = c;
- mons_layer(mon);
+// mon->cspace->floating = list_del(mon->cspace->floating, c);
+// c->next = mon->cspace->floating;
+// mon->cspace->floating = c;
+// mons_layer(mon);
}
void mons_lower(Monitor* mon, Client* c)
{
- mon->cspace->floating = list_del(mon->cspace->floating, c);
- c->next = NULL;
- if (mon->cspace->floating)
- {
- Client* curr = list_last(mon->cspace->floating);
- curr->next = c;
- }
- else
- {
- mon->cspace->floating = c;
- }
- mons_layer(mon);
+// mon->cspace->floating = list_del(mon->cspace->floating, c);
+// c->next = NULL;
+// if (mon->cspace->floating)
+// {
+// Client* curr = list_last(mon->cspace->floating);
+// curr->next = c;
+// }
+// else
+// {
+// mon->cspace->floating = c;
+// }
+// mons_layer(mon);
}
void mons_colsplit(void)
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);
- }
- }
+// 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);
- int m = 0;
- Monitor* mon;
- for (; m < MAX_MONITORS; m++)
- {
- mon = &Monitors[m];
- if ((mon->x <= PtrX && PtrX < mon->x+mon->w) &&
- (mon->y <= PtrY && PtrY < mon->y+mon->h))
- {
- break;
- }
- }
- mon = (m < MAX_MONITORS ? mon : &Monitors[0]);
- return mon;
-}
+//static Monitor* pickmon(void)
+//{
+// mouse_get(&PtrX, &PtrY);
+// int m = 0;
+// Monitor* mon;
+// for (; m < MAX_MONITORS; m++)
+// {
+// mon = &Monitors[m];
+// if ((mon->x <= PtrX && PtrX < mon->x+mon->w) &&
+// (mon->y <= PtrY && PtrY < mon->y+mon->h))
+// {
+// break;
+// }
+// }
+// mon = (m < MAX_MONITORS ? mon : &Monitors[0]);
+// return mon;
+//}
//static Column* pickcol(Column* cols, int relx)
//{
// return col;
//}
-static Workspace* pickws(Monitor* mon, int wsid)
-{
- return &(mon->wspaces[wsid]);
-}
-
-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->cspace->floating;
- mon->cspace->floating = c;
- c->x = mon->midx - c->w/2;
- c->y = mon->midy - c->h/2;
- Client_AdjustSize(c);
- }
- else
- {
- /* find first empty column, and fill that first, otherwise use the last column we find */
- Column* col = NULL;
- for (int i = 0; i < mon->cspace->ncolumns; i++)
- {
- col = &(mon->cspace->columns[i]);
- if (col->clients == NULL)
- {
- break;
- }
- }
- tile_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
- {
- tile_del(loc);
- }
-}
+//static Workspace* pickws(Monitor* mon, int wsid)
+//{
+// return &(mon->wspaces[wsid]);
+//}
+//
+//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->cspace->floating;
+// mon->cspace->floating = c;
+// c->x = mon->midx - c->w/2;
+// c->y = mon->midy - c->h/2;
+// Client_AdjustSize(c);
+// }
+// else
+// {
+// /* find first empty column, and fill that first, otherwise use the last column we find */
+// Column* col = NULL;
+// for (int i = 0; i < mon->cspace->ncolumns; i++)
+// {
+// col = &(mon->cspace->columns[i]);
+// if (col->clients == NULL)
+// {
+// break;
+// }
+// }
+// tile_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
+// {
+// tile_del(loc);
+// }
+//}
//static void adjust_all(Column* col, int xoff)
//{
// }
//}
-static void change_wspace(Monitor* mon, Workspace* wspace)
-{
- if (mon->cspace != wspace)
- {
- client_visibility(mon->cspace, 0);
- client_visibility(wspace, 1);
- mon->cspace = wspace;
- }
-}
+//static void change_wspace(Monitor* mon, Workspace* wspace)
+//{
+// if (mon->cspace != wspace)
+// {
+// client_visibility(mon->cspace, 0);
+// client_visibility(wspace, 1);
+// mon->cspace = wspace;
+// }
+//}
int mods;
int btn;
int type;
- void(*func)(Location* loc);
+ void(*func)(Client* client);
} MouseAct;
-static void resize_frame(Location* loc)
+static void resize_frame(Client* client)
{
if (Current->xbutton.y > MIN_HEIGHT)
{
X.mode = M_RESIZE;
- Mouse_ToCorner(loc->client);
+ Mouse_ToCorner(client);
}
}
-//static void toggle_float(Location* loc)
+//static void toggle_float(Client* client)
//{
-// mons_togglefloat(loc);
+// mons_togglefloat(cient);
//}
-static void close_client(Location* loc)
+static void close_client(Client* client)
{
- Client_Close(loc->client);
+ Client_Close(client);
}
-static void stack_clients(Location* loc)
+static void stack_clients(Client* client)
{
- tile_set(loc);
+// tile_set(loc);
}
-static void reposition_tile(Location* loc)
+static void reposition_tile(Client* client)
{
- (void)loc;
+ (void)client;
X.mode = (X.edge == E_TOP ? M_TILE_RESIZE : M_COL_RESIZE);
}
{ 0, Button2, ButtonPress, stack_clients },
};
-static void process(XButtonEvent* ev, Location* loc, MouseAct* actions, int nactions)
+static void process(XButtonEvent* ev, Client* client, MouseAct* actions, int nactions)
{
for (int i = 0; i < nactions; i++)
{
if (match)
{
Current = (XEvent*)ev;
- act->func(loc);
+ act->func(client);
break;
}
}
}
-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]));
- }
-}
-
-void mouse_up(XButtonEvent* ev, Location* loc)
-{
- if (X.mode == M_TILE_RESIZE)
- {
- mons_tilemove(loc, ev->y_root - X.start_y);
- }
- else if (X.mode == M_COL_RESIZE)
- {
- mons_coladjust(loc->monitor, loc->column, ev->x_root - X.start_x);
- }
- else
- {
- /* nothing to do here */
- }
- X.mode = M_IDLE;
-}
-
-void mouse_totitle(Client* c)
-{
- XWarpPointer(X.disp, None, X.root, 0, 0, 0, 0, (c->x + c->w/2), c->y + (MIN_HEIGHT/2));
-}
-
-void mouse_get(int* ptrx, int* ptry)
-{
- Window root = 0, child = 0;
- int winx = 0, winy = 0, mask = 0;
- XQueryPointer(X.disp, X.root, &root, &child, ptrx, ptry, &winx, &winy, (unsigned int*)&mask);
-}
+//void mouse_totitle(Client* c)
+//{
+// XWarpPointer(X.disp, None, X.root, 0, 0, 0, 0, (c->x + c->w/2), c->y + (MIN_HEIGHT/2));
+//}
+//
+//void mouse_get(int* ptrx, int* ptry)
+//{
+// Window root = 0, child = 0;
+// int winx = 0, winy = 0, mask = 0;
+// XQueryPointer(X.disp, X.root, &root, &child, ptrx, ptry, &winx, &winy, (unsigned int*)&mask);
+//}
void Mouse_ToCorner(Client* client)
{
void Mouse_Down(XButtonEvent* ev, Client* client)
{
+// if (!loc->column)
+// {
+// process(ev, loc, Floating, sizeof(Floating)/sizeof(Floating[0]));
+// }
+// else
+ {
+ process(ev, client, Stacked, sizeof(Stacked)/sizeof(Stacked[0]));
+ }
}
void Mouse_Up(XButtonEvent* ev, Client* client)
{
+// if (X.mode == M_TILE_RESIZE)
+// {
+// mons_tilemove(loc, ev->y_root - X.start_y);
+// }
+// else if (X.mode == M_COL_RESIZE)
+// {
+// mons_coladjust(loc->monitor, loc->column, ev->x_root - X.start_x);
+// }
+// else
+// {
+// /* nothing to do here */
+// }
+ X.mode = M_IDLE;
}
void Mouse_Drag(XMotionEvent* ev, Client* client)
static void xunmapnotify(XEvent* e)
{
XUnmapEvent* ev = &(e->xunmap);
- //printf("UNMAP(e: 0x%lx w: 0x%lx %d)\n", ev->event, ev->window, ev->from_configure);
+ printf("UNMAP(e: 0x%lx w: 0x%lx %d)\n", ev->event, ev->window, ev->from_configure);
Client* client = Client_Find(ev->window);
if (client)
static void xdestroynotify(XEvent* e)
{
XDestroyWindowEvent* ev = &(e->xdestroywindow);
- //printf("DESTROY(w: 0x%lx)\n", ev->window);
+ printf("DESTROY(w: 0x%lx)\n", ev->window);
Client* client = Client_Find(ev->window);
if (client)
static void xclientmsg(XEvent* e)
{
XClientMessageEvent* ev = &(e->xclient);
- //printf("CLIENT_MSG(w: 0x%lx a: '%s')\n", ev->window, XGetAtomName(X.disp, ev->message_type));
+ printf("CLIENT_MSG(w: 0x%lx a: '%s')\n", ev->window, XGetAtomName(X.disp, ev->message_type));
if (ev->message_type == atom("_NET_ACTIVE_WINDOW"))
{
static void xpropnotify(XEvent* e)
{
XPropertyEvent* ev = &(e->xproperty);
- //printf("PROP_NOTIFY(w: 0x%lx)\n", ev->window);
+ printf("PROP_NOTIFY(w: 0x%lx)\n", ev->window);
Client* client = Client_Find(ev->window);
if (client)
static void xenternotify(XEvent* e)
{
XCrossingEvent* ev = &(e->xcrossing);
- //printf("ENTER(w: 0x%lx s: %d m: %d d: %d)\n", ev->window, ev->state, ev->mode, ev->detail);
+ printf("ENTER(w: 0x%lx s: %d m: %d d: %d)\n", ev->window, ev->state, ev->mode, ev->detail);
Client* client = Client_Find(ev->window);
if (client)
XExposeEvent* ev = &(e->xexpose);
if (ev->count == 0)
{
- //printf("EXPOSE(w: 0x%lx)\n", ev->window);
+ printf("EXPOSE(w: 0x%lx)\n", ev->window);
Client* client = Client_Find(ev->window);
if (client)
{
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);
+ 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);
Client* client = Client_Find(ev->window);
if (client && (client->frame == ev->window))
{
/* make sure we get just the latest event */
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);
+ 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));
Client* client = Client_Find(ev->window);