XSync(X.disp, False);
}
-static inline int PRESSED(int mods, int btn)
-{
- return ((mods & (1 << (btn + 7))) == (1 << (btn + 7)));
-}
-
-static void warp_mouse(Client* c)
-{
- XWarpPointer(X.disp, None, c->frame, 0, 0, 0, 0,
- c->w + 2*BORDER_WIDTH - BORDER_WIDTH/2,
- c->h + 2*BORDER_WIDTH + TITLE_HEIGHT - BORDER_WIDTH/2
- );
- X.start_x = c->x + c->w + 4;
- X.start_y = c->y + c->h + 4;
-}
-
static void xbtnpress(XEvent* e)
{
XButtonEvent* ev = &(e->xbutton);
Client* c = client_get(e->xbutton.window, &loc);
if (c && (ev->window == c->frame))
{
- if (loc.column)
- {
- puts("tiled mouse click");
- }
- else
- {
-// client_btnclick(c, ev->button, ev->x, ev->y);
- if (ev->button == Button1)
- {
- mons_raise(loc.monitor, c);
- if (ev->y > (TITLE_HEIGHT + BORDER_WIDTH))
- {
- X.mode = M_RESIZE;
- warp_mouse(c);
- }
- }
- else if (ev->button == Button2)
- {
- client_close(c);
- }
- else if (ev->button == Button3)
- {
- mons_lower(loc.monitor, c);
- }
- }
+ mouse_click(ev, &loc);
}
}
Client* c = client_get(ev->window, &loc);
if (c && (ev->window == c->frame))
{
- if (loc.column)
- {
- puts("tiled mouse drag");
- }
- else
- {
-// client_btnmove(c, ev->button, ev->x, ev->y);
- if (PRESSED(ev->state, Button1))
- {
- if (X.mode != M_RESIZE)
- {
- client_move(c, ev->x_root - X.start_x, ev->y_root - X.start_y);
- }
- else
- {
- client_resize(c, ev->x_root - X.start_x, ev->y_root - X.start_y);
- }
- XSync(X.disp, False);
- }
- }
+ mouse_drag(ev, &loc);
}
X.start_x = ev->x_root;
X.start_y = ev->y_root;
void client_show(Client* c, int show);
void client_readprops(Client* c);
+/* mouse.c */
+void mouse_click(XButtonEvent* ev, Location* loc);
+void mouse_drag(XMotionEvent* ev, Location* loc);
+
/* error.c */
extern int (*error_default)(Display* disp, XErrorEvent* ev);
int error_init(Display* disp, XErrorEvent* ev);
void xfree(void* p);
Atom atom(char* str);
void sendmsg(Window win, Atom proto, Atom type);
+void warp_mouse(Client* c);
client_readprops(c);
/* Reparent the window if applicable */
- c->frame = XCreateSimpleWindow(X.disp, X.root, c->x, c->y, c->w, c->h, 1, X.black, X.gray);
+ c->frame = XCreateSimpleWindow(X.disp, X.root, c->x, c->y, c->w, c->h, 1, X.black, X.black);
XSelectInput(X.disp, c->frame,
ExposureMask | EnterWindowMask |
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
for (int i = 0; i < 10; i++)
{
Column* col = ecalloc(1, sizeof(Column));
- col->mode = TILE_MONOCLE,
+ col->mode = TILE_STACKED,
col->width = m->w;
Workspace* wspace = ecalloc(1, sizeof(Workspace));
wspace->columns = col;
}
}
-static void tile_monocle(Monitor* mon, Column* col, Client* c)
+static void add_monocle(Monitor* mon, Column* col, Client* c)
{
coldims(mon, col, &(c->x), &(c->y), &(c->w), &(c->h));
client_adjust(c);
col->clients = c;
}
-static void tile_expand(Monitor* mon, Column* col, Client* client)
+static void add_expand(Monitor* mon, Column* col, Client* client)
{
/*
* stack all existing clients top to bottom only showing title bars
col->clients = client;
}
-static void tile_stacked(Monitor* mon, Column* col, Client* client)
+static void add_stacked(Monitor* mon, Column* col, Client* client)
{
- /*
- * find biggest client in stack
- * split that client in half
- * move+resize new client to fill the gap
- */
- (void)mon, (void)col;
- client->next = col->clients;
- col->clients = 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 */
Column* col = pickcol(mon->cspace->columns, ptrx - mon->x);
if (col->mode == TILE_MONOCLE)
{
- tile_monocle(mon, col, c);
+ add_monocle(mon, col, c);
}
else if (col->mode == TILE_EXPAND)
{
- tile_expand(mon, col, c);
+ add_expand(mon, col, c);
}
else if (col->mode == TILE_STACKED)
{
- tile_stacked(mon, col, c);
+ add_stacked(mon, col, c);
}
}
mons_layer(mon);
--- /dev/null
+#include "anvil.h"
+
+static inline int PRESSED(int mods, int btn)
+{
+ return ((mods & (1 << (btn + 7))) == (1 << (btn + 7)));
+}
+
+static void float_click(XButtonEvent* ev, Location* loc)
+{
+ if (ev->button == Button1)
+ {
+ mons_raise(loc->monitor, loc->client);
+ if (ev->y > (TITLE_HEIGHT + BORDER_WIDTH))
+ {
+ X.mode = M_RESIZE;
+ warp_mouse(loc->client);
+ }
+ }
+ else if (ev->button == Button2)
+ {
+ client_close(loc->client);
+ }
+ else if (ev->button == Button3)
+ {
+ mons_lower(loc->monitor, loc->client);
+ }
+}
+
+static void monocle_click(XButtonEvent* ev, Location* loc)
+{
+ if (ev->button == Button2)
+ {
+ client_close(loc->client);
+ }
+ else if (ev->button == Button3)
+ {
+ Client *tail, *client = loc->column->clients;
+ if (client->next)
+ {
+ loc->column->clients = client->next;
+ for (tail = loc->column->clients; tail && tail->next; tail = tail->next);
+ client->next = NULL;
+ tail->next = client;
+ }
+ }
+ mons_layer(loc->monitor);
+}
+
+void mouse_click(XButtonEvent* ev, Location* loc)
+{
+ if (!loc->column)
+ {
+ float_click(ev, loc);
+ }
+ else if (loc->column->mode == TILE_MONOCLE)
+ {
+ monocle_click(ev, loc);
+ }
+ else if (loc->column->mode == TILE_STACKED)
+ {
+ puts("tiled (S) mouse click");
+ }
+ else if (loc->column->mode == TILE_EXPAND)
+ {
+ puts("tiled (E) mouse click");
+ }
+}
+
+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.start_x, ev->y_root - X.start_y);
+ }
+ else
+ {
+ client_resize(loc->client, ev->x_root - X.start_x, ev->y_root - X.start_y);
+ }
+ XSync(X.disp, False);
+ }
+}
+
+void mouse_drag(XMotionEvent* ev, Location* loc)
+{
+ if (!loc->column)
+ {
+ float_drag(ev, loc);
+ }
+ else
+ {
+ puts("tiled mouse drag");
+ }
+}
+
XSync(X.disp, False);
}
+void warp_mouse(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.start_x = c->x + new_w;
+ X.start_y = c->y + new_h;
+}
+