#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)
+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)(Client* client);
+} MouseAct;
+
+static void resize_frame(Client* client)
+{
+ (void)client;
+ if (X.curr_ev->xbutton.y > MIN_HEIGHT)
+ {
+ X.mode = M_RESIZE;
+ Mouse_ToCorner(client);
+ }
+}
+
+static void toggle_float(Client* client)
+{
+ (void)client;
+// mons_togglefloat(loc);
+}
+
+static void close_client(Client* client)
+{
+ (void)client;
+// client_close(client);
+}
+
+static void shade_client(Client* client)
+{
+ (void)client;
+// client_shade(client);
+}
+
+static void lower_client(Client* client)
+{
+ (void)client;
+// mons_lower(loc->monitor, loc->client);
+}
+
+static void raise_client(Client* client)
+{
+ (void)client;
+// mons_raise(loc->monitor, loc->client);
+}
+
+//static void stack_clients(Client* client)
//{
-// (void)loc;
+// (void)client;
//// stacked_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);
//}
-//
-//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 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 },
// { 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;
-// }
-// }
-//}
+static void ProcessMouseEvent(XButtonEvent* ev, Client* client, 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(client);
+ break;
+ }
+ }
+}
//
//void mouse_down(XButtonEvent* ev, Location* loc)
//{
//
//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)
// }
//}
//
-//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)
//{
void Mouse_Down(XButtonEvent* ev)
{
- (void)ev;
-// 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);
-// }
+ Client* c = Client_Find(ev->window);
+ if (c && (c->frame = ev->window))
+ {
+ 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;
+ }
+ ProcessMouseEvent(ev, c, Floating, sizeof(Floating)/sizeof(Floating[0]));
+ }
}
void Mouse_Up(XButtonEvent* ev)
{
(void)ev;
-// Location loc = {0};
-// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window))
-// {
-// mouse_up(ev, &loc);
-// }
+ Client* c = Client_Find(ev->window);
+ if (c && (c->frame = ev->window))
+ {
+ 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)
{
(void)ev;
-// Location loc = {0};
-// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window))
-// {
-// mouse_drag(ev, &loc);
-// }
+ Client* c = Client_Find(ev->window);
+ if (c && (c->frame = ev->window))
+ {
+ if (PRESSED(ev->state, Button1))
+ {
+ if (X.mode != M_RESIZE)
+ {
+ Client_Move(c, ev->x_root - X.last_x, ev->y_root - X.last_y);
+ }
+ else
+ {
+ Client_Resize(c, ev->x_root - X.last_x, ev->y_root - X.last_y);
+ }
+ }
+ }
}
+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;
+}