commit b272bcc81a273944272480275d5806d0f4f92153
parent 97764ce75c9b512dadf95d3be83a45485f0bd342
Author: Lucas de Sena <lucas@seninha.org>
Date: Wed, 19 Jul 2023 20:29:26 -0300
fix maximization with mouse
Diffstat:
3 files changed, 33 insertions(+), 23 deletions(-)
diff --git a/shod.h b/shod.h
@@ -719,7 +719,7 @@ void containerdecorate(struct Container *c, struct Column *cdiv, struct Row *rdi
void containerredecorate(struct Container *c, struct Column *cdiv, struct Row *rdiv, enum Octant o);
void containercalccols(struct Container *c);
void containersetstate(struct Tab *, Atom *, unsigned long);
-void containerincrmove(struct Container *c, int x, int y);
+void containermove(struct Container *c, int x, int y, int relative);
void containerraise(struct Container *c, int isfullscreen, int layer);
void containerconfigure(struct Container *c, unsigned int valuemask, XWindowChanges *wc);
void containersendtodeskandfocus(struct Container *c, struct Monitor *mon, unsigned long desk);
diff --git a/xcontainer.c b/xcontainer.c
@@ -1165,7 +1165,7 @@ containersendtodeskandfocus(struct Container *c, struct Monitor *mon, unsigned l
/* move container x pixels to the right and y pixels down */
void
-containerincrmove(struct Container *c, int x, int y)
+containermove(struct Container *c, int x, int y, int relative)
{
struct Monitor *monto;
struct Object *t;
@@ -1173,8 +1173,13 @@ containerincrmove(struct Container *c, int x, int y)
if (c == NULL || c->isminimized || c->ismaximized || c->isfullscreen)
return;
- c->nx += x;
- c->ny += y;
+ if (relative) {
+ c->nx += x;
+ c->ny += y;
+ } else {
+ c->nx = x;
+ c->ny = y;
+ }
c->x = c->nx;
c->y = c->ny;
snaptoedge(&c->x, &c->y, c->w, c->h);
diff --git a/xevents.c b/xevents.c
@@ -1046,8 +1046,10 @@ mousemove(Window win, int type, void *p, int xroot, int yroot, enum Octant o)
Window frame;
XEvent ev;
Time lasttime;
- int x, y, maximize;
+ int x, y, unmaximize, origyroot;
+ origyroot = yroot;
+ unmaximize = 0;
if (type == FLOAT_MENU) {
menu = (struct Menu *)p;
menudecorate(menu, o);
@@ -1062,7 +1064,6 @@ mousemove(Window win, int type, void *p, int xroot, int yroot, enum Octant o)
XDefineCursor(dpy, win, wm.cursors[CURSOR_MOVE]);
else if (XGrabPointer(dpy, frame, False, ButtonReleaseMask | PointerMotionMask, GrabModeAsync, GrabModeAsync, None, wm.cursors[CURSOR_MOVE], CurrentTime) != GrabSuccess)
goto done;
- maximize = 0;
while (!XMaskEvent(dpy, MOUSEEVENTMASK, &ev)) {
switch (ev.type) {
case ButtonRelease:
@@ -1075,31 +1076,35 @@ mousemove(Window win, int type, void *p, int xroot, int yroot, enum Octant o)
y = ev.xmotion.y_root - yroot;
if (type == FLOAT_MENU)
menuincrmove(menu, x, y);
- else if (maximize < 0)
- containerincrmove(c, 0, 0);
- else
- containerincrmove(c, x, y);
- lasttime = ev.xmotion.time;
- xroot = ev.xmotion.x_root;
- yroot = ev.xmotion.y_root;
- if (type == FLOAT_MENU)
- break;
- if ((maximize > 0 && ev.xmotion.y_root <= 0) ||
- (maximize < 0 && ev.xmotion.y_root > 0) ||
- maximize == 0) {
+ else if (c->ismaximized && ev.xmotion.y_root > 0 && unmaximize) {
containersetstate(
c->selcol->selrow->seltab,
(Atom []){
atoms[_NET_WM_STATE_MAXIMIZED_VERT],
atoms[_NET_WM_STATE_MAXIMIZED_HORZ],
},
- ev.xmotion.y_root <= 0 ? ADD : REMOVE
+ REMOVE
);
+ containermove(c, c->nx, 0, 0);
+ } else if (!c->ismaximized && ev.xmotion.y_root <= 0) {
+ containersetstate(
+ c->selcol->selrow->seltab,
+ (Atom []){
+ atoms[_NET_WM_STATE_MAXIMIZED_VERT],
+ atoms[_NET_WM_STATE_MAXIMIZED_HORZ],
+ },
+ ADD
+ );
+ } else if (!c->ismaximized) {
+ containermove(c, x, y, 1);
}
- if (ev.xmotion.y_root <= 0)
- maximize = -1;
- else
- maximize = 1;
+ if (ev.xmotion.y_root < origyroot - config.titlewidth)
+ unmaximize = 1;
+ if (ev.xmotion.y_root > origyroot + config.titlewidth)
+ unmaximize = 1;
+ lasttime = ev.xmotion.time;
+ xroot = ev.xmotion.x_root;
+ yroot = ev.xmotion.y_root;
break;
}
}