/* Anvil State */
int PtrX = 0, PtrY = 0;
-int Num_Monitors = 0;
-Monitor Monitors[10] = {0};
-Workspace Workspaces[10] = {0};
+//int Num_Monitors = 0;
+//Monitor Monitors[10] = {0};
+//Workspace Workspaces[10] = {0};
Client* Withdrawn = NULL;
Client* Focused = NULL;
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);
-// }
+ Mouse_Down(ev);
}
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);
-// }
+
+ Mouse_Up(ev);
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);
-// }
+
+ Mouse_Drag(ev);
X.last_x = ev->x_root, X.last_y = ev->y_root;
}
Visual visual;
} Client;
-typedef struct Column {
- int width;
- Client* clients;
-} Column;
-
-typedef struct Workspace {
- Client* floating;
- Column columns[MAX_COL_COUNT];
- int ncolumns;
-} Workspace;
-
-typedef struct Monitor {
- int x, y, w, h, midx, midy;
- Workspace* wspace;
-} Monitor;
-
-typedef struct Location {
- Monitor* monitor;
- Workspace* workspace;
- Column* column;
- Client* client;
-} Location;
+//typedef struct Column {
+// int width;
+// Client* clients;
+//} Column;
+//
+//typedef struct Workspace {
+// Client* floating;
+// Column columns[MAX_COL_COUNT];
+// int ncolumns;
+//} Workspace;
+//
+//typedef struct Monitor {
+// int x, y, w, h, midx, midy;
+// Workspace* wspace;
+//} Monitor;
+//
+//typedef struct Location {
+// Monitor* monitor;
+// Workspace* workspace;
+// Column* column;
+// Client* client;
+//} Location;
typedef union {
int i;
extern int PtrX;
extern int PtrY;
-extern int Num_Monitors;
-extern Monitor Monitors[10];
-extern Workspace Workspaces[10];
+//extern int Num_Monitors;
+//extern Monitor Monitors[10];
+//extern Workspace Workspaces[10];
extern Client* Withdrawn;
extern Client* Focused;
void Keys_Init(void);
void Keys_Process(XKeyEvent* ev);
-/* mons.c */
-void mons_init(void);
-void mons_layer(Monitor* mon);
-void mons_addclient(Client* c);
-void mons_delclient(Location* loc);
-void mons_togglefloat(Location* loc);
-int mons_find(Window win, Location* loc);
-void mons_place(Client* c);
-void mons_wspace(int i);
-void mons_towspace(Client* c, int i);
-void mons_raise(Monitor* mon, Client* c);
-void mons_lower(Monitor* mon, Client* c);
-void mons_colsplit(void);
-void mons_coljoin(void);
-void mons_coladjust(Monitor* mon, Column* col, int wdiff);
-void mons_tilemove(Location* loc, int hdiff);
-void mons_activate(Window win);
-
/* client.c */
void Client_InitAll(void);
void Client_Create(Window win);
void Client_Hide(Window win);
void Client_MoveResize(Client* c);
-Client* client_add(Window win, XWindowAttributes* attr);
-void client_draw(Client* c);
-void client_move(Client* c, int xdiff, int ydiff);
-void client_resize(Client* c, int xdiff, int ydiff);
-void client_close(Client* c);
-void client_focus(Client* c);
-void client_show(Client* c, int show);
-void client_readprops(Client* c);
-void client_shade(Client* c);
-void client_setshade(Client* c, int shade);
+//Client* client_add(Window win, XWindowAttributes* attr);
+//void client_draw(Client* c);
+//void client_move(Client* c, int xdiff, int ydiff);
+//void client_resize(Client* c, int xdiff, int ydiff);
+//void client_close(Client* c);
+//void client_focus(Client* c);
+//void client_show(Client* c, int show);
+//void client_readprops(Client* c);
+//void client_shade(Client* c);
+//void client_setshade(Client* c, int shade);
/* mouse.c */
-void mouse_down(XButtonEvent* ev, Location* loc);
-void mouse_up(XButtonEvent* ev, Location* loc);
-void mouse_drag(XMotionEvent* ev, Location* loc);
-void mouse_tocorner(Client* c);
-void mouse_totitle(Client* c);
-void mouse_get(int* ptrx, int* ptry);
-
-/* tile.c */
-void stacked_add(Location* loc);
-void stacked_del(Location* loc);
-void stacked_set(Location* loc);
-void stacked_addheight(Location* loc, int amount);
+void Mouse_Down(XButtonEvent* ev);
+void Mouse_Up(XButtonEvent* ev);
+void Mouse_Drag(XMotionEvent* ev);
+
+//void mouse_tocorner(Client* c);
+//void mouse_totitle(Client* c);
+//void mouse_get(int* ptrx, int* ptry);
/* error.c */
extern int (*error_default)(Display* disp, XErrorEvent* ev);
// }
}
-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_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)
-{
- client_setshade(c, ((c->flags & F_SHADED) ? 0 : 1));
- Client_MoveResize(c);
-}
-
-void client_setshade(Client* c, int shade)
-{
- if (!shade && (c->flags & F_SHADED))
- {
- c->flags &= ~F_SHADED;
- XMapWindow(X.disp, c->win);
- }
- else if (shade && !(c->flags & F_SHADED))
- {
- c->flags |= F_SHADED;
- XUnmapWindow(X.disp, c->win);
- }
-}
+//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_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)
+//{
+// client_setshade(c, ((c->flags & F_SHADED) ? 0 : 1));
+// Client_MoveResize(c);
+//}
+//
+//void client_setshade(Client* c, int shade)
+//{
+// if (!shade && (c->flags & F_SHADED))
+// {
+// c->flags &= ~F_SHADED;
+// XMapWindow(X.disp, c->win);
+// }
+// else if (shade && !(c->flags & F_SHADED))
+// {
+// c->flags |= F_SHADED;
+// XUnmapWindow(X.disp, c->win);
+// }
+//}
(void)arg;
if (Focused)
{
- client_close(Focused);
+// client_close(Focused);
}
}
#include "anvil.h"
-static inline int PRESSED(int mods, int btn)
-{
- return ((mods & (1 << (btn + 7))) == (1 << (btn + 7)));
-}
-
-static inline int FLAGS_SET(int state, int flags)
-{
- return ((!flags && !state) || ((state & flags) == flags));
-}
-
-typedef struct {
- int mods;
- int btn;
- int type;
- void(*func)(Location* loc);
-} MouseAct;
-
-static void resize_frame(Location* loc)
-{
- if (X.curr_ev->xbutton.y > MIN_HEIGHT)
- {
- X.mode = M_RESIZE;
- mouse_tocorner(loc->client);
- }
-}
-
-static void toggle_float(Location* loc)
-{
- (void)loc;
-// mons_togglefloat(loc);
-}
-
-static void close_client(Location* loc)
-{
- client_close(loc->client);
-}
-
-static void shade_client(Location* loc)
-{
- client_shade(loc->client);
-}
-
-static void lower_client(Location* loc)
-{
- (void)loc;
-// mons_lower(loc->monitor, loc->client);
-}
-
-static void raise_client(Location* loc)
-{
- (void)loc;
-// mons_raise(loc->monitor, loc->client);
-}
-
-static void stack_clients(Location* loc)
-{
- (void)loc;
-// stacked_set(loc);
-}
-
-static void reposition_tile(Location* loc)
-{
- (void)loc;
- X.mode = (X.edge == E_TOP ? M_TILE_RESIZE : M_COL_RESIZE);
-}
-
-MouseAct Floating[] = {
- { 0, Button1, ButtonPress, resize_frame },
- { MODKEY|ShiftMask, Button2, ButtonPress, toggle_float },
- { MODKEY, Button2, ButtonPress, close_client },
- { 0, Button3, ButtonPress, shade_client },
- { 0, Button4, ButtonPress, lower_client },
- { 0, Button5, ButtonPress, raise_client }
-};
-
-MouseAct Stacked[] = {
- { 0, Button1, ButtonPress, reposition_tile },
- { MODKEY|ShiftMask, Button2, ButtonPress, toggle_float },
- { MODKEY, Button2, ButtonPress, close_client },
- { 0, Button2, ButtonPress, stack_clients },
- { 0, Button3, ButtonPress, stack_clients },
-};
-
-static void process(XButtonEvent* ev, Location* loc, MouseAct* actions, int nactions)
-{
- for (int i = 0; i < nactions; i++)
- {
- MouseAct* act = &actions[i];
- int match = (
- (ev->type == act->type) &&
- ((int)ev->button == act->btn) &&
- FLAGS_SET(ev->state, act->mods)
- );
- if (match)
- {
- X.curr_ev = (XEvent*)ev;
- act->func(loc);
- 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]));
- }
-}
-
-static void float_drag(XMotionEvent* ev, Location* loc)
-{
- if (PRESSED(ev->state, Button1))
- {
- if (X.mode != M_RESIZE)
- {
- client_move(loc->client, ev->x_root - X.last_x, ev->y_root - X.last_y);
- }
- else
- {
- client_resize(loc->client, ev->x_root - X.last_x, ev->y_root - X.last_y);
- }
- }
-}
-
-void mouse_up(XButtonEvent* ev, Location* loc)
+//static inline int PRESSED(int mods, int btn)
+//{
+// return ((mods & (1 << (btn + 7))) == (1 << (btn + 7)));
+//}
+//
+//static inline int FLAGS_SET(int state, int flags)
+//{
+// return ((!flags && !state) || ((state & flags) == flags));
+//}
+//
+//typedef struct {
+// int mods;
+// int btn;
+// int type;
+// void(*func)(Location* loc);
+//} MouseAct;
+//
+//static void resize_frame(Location* loc)
+//{
+// if (X.curr_ev->xbutton.y > MIN_HEIGHT)
+// {
+// X.mode = M_RESIZE;
+// mouse_tocorner(loc->client);
+// }
+//}
+//
+//static void toggle_float(Location* loc)
+//{
+// (void)loc;
+//// mons_togglefloat(loc);
+//}
+//
+//static void close_client(Location* loc)
+//{
+// client_close(loc->client);
+//}
+//
+//static void shade_client(Location* loc)
+//{
+// client_shade(loc->client);
+//}
+//
+//static void lower_client(Location* loc)
+//{
+// (void)loc;
+//// mons_lower(loc->monitor, loc->client);
+//}
+//
+//static void raise_client(Location* loc)
+//{
+// (void)loc;
+//// mons_raise(loc->monitor, loc->client);
+//}
+//
+//static void stack_clients(Location* loc)
+//{
+// (void)loc;
+//// stacked_set(loc);
+//}
+//
+//static void reposition_tile(Location* loc)
+//{
+// (void)loc;
+// X.mode = (X.edge == E_TOP ? M_TILE_RESIZE : M_COL_RESIZE);
+//}
+//
+//MouseAct Floating[] = {
+// { 0, Button1, ButtonPress, resize_frame },
+// { MODKEY|ShiftMask, Button2, ButtonPress, toggle_float },
+// { MODKEY, Button2, ButtonPress, close_client },
+// { 0, Button3, ButtonPress, shade_client },
+// { 0, Button4, ButtonPress, lower_client },
+// { 0, Button5, ButtonPress, raise_client }
+//};
+//
+//MouseAct Stacked[] = {
+// { 0, Button1, ButtonPress, reposition_tile },
+// { MODKEY|ShiftMask, Button2, ButtonPress, toggle_float },
+// { MODKEY, Button2, ButtonPress, close_client },
+// { 0, Button2, ButtonPress, stack_clients },
+// { 0, Button3, ButtonPress, stack_clients },
+//};
+//
+//static void process(XButtonEvent* ev, Location* loc, MouseAct* actions, int nactions)
+//{
+// for (int i = 0; i < nactions; i++)
+// {
+// MouseAct* act = &actions[i];
+// int match = (
+// (ev->type == act->type) &&
+// ((int)ev->button == act->btn) &&
+// FLAGS_SET(ev->state, act->mods)
+// );
+// if (match)
+// {
+// X.curr_ev = (XEvent*)ev;
+// act->func(loc);
+// 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]));
+// }
+//}
+//
+//static void float_drag(XMotionEvent* ev, Location* loc)
+//{
+// if (PRESSED(ev->state, Button1))
+// {
+// if (X.mode != M_RESIZE)
+// {
+// client_move(loc->client, ev->x_root - X.last_x, ev->y_root - X.last_y);
+// }
+// else
+// {
+// client_resize(loc->client, ev->x_root - X.last_x, ev->y_root - X.last_y);
+// }
+// }
+//}
+//
+//void mouse_up(XButtonEvent* ev, Location* loc)
+//{
+// (void)ev;
+// (void)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_drag(XMotionEvent* ev, Location* loc)
+//{
+// if (!loc->column)
+// {
+// float_drag(ev, loc);
+// }
+//}
+//
+//void mouse_tocorner(Client* c)
+//{
+// int new_w = c->w - BORDER_WIDTH/2;
+// int new_h = c->h - BORDER_WIDTH/2;
+// XWarpPointer(X.disp, None, c->frame, 0, 0, 0, 0, new_w, new_h);
+// X.last_x = c->x + new_w;
+// X.last_y = c->y + new_h;
+//}
+//
+//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_Down(XButtonEvent* ev)
{
(void)ev;
- (void)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_drag(XMotionEvent* ev, Location* 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);
+// }
+
+}
+
+void Mouse_Up(XButtonEvent* ev)
{
- if (!loc->column)
- {
- float_drag(ev, loc);
- }
-}
-
-void mouse_tocorner(Client* c)
-{
- int new_w = c->w - BORDER_WIDTH/2;
- int new_h = c->h - BORDER_WIDTH/2;
- XWarpPointer(X.disp, None, c->frame, 0, 0, 0, 0, new_w, new_h);
- X.last_x = c->x + new_w;
- X.last_y = c->y + new_h;
-}
-
-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)ev;
+// Location loc = {0};
+// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window))
+// {
+// mouse_up(ev, &loc);
+// }
}
-void mouse_get(int* ptrx, int* ptry)
+void Mouse_Drag(XMotionEvent* ev)
{
- 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)ev;
+// Location loc = {0};
+// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window))
+// {
+// mouse_drag(ev, &loc);
+// }
}