Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/resize.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static void UpdateSize(ClientNode *np, const MouseContextType context,
const int x, const int y,
const int startx, const int starty,
const int oldx, const int oldy,
const int oldw, const int oldh);
const int oldw, const int oldh, MouseContextType *prevContext);
static void FixWidth(ClientNode *np);
static void FixHeight(ClientNode *np);

Expand All @@ -48,9 +48,19 @@ void UpdateSize(ClientNode *np, const MouseContextType context,
const int x, const int y,
const int startx, const int starty,
const int oldx, const int oldy,
const int oldw, const int oldh)
const int oldw, const int oldh, MouseContextType *prevContext)
{
if(context & MC_BORDER_N) {

// if previous context is unset, and context contains mask (not keyboard)
if (*prevContext == MC_NONE && context & MC_MASK) {
int xpos = x-oldx;
int ypos = y-oldy;
*prevContext |= MC_MASK; // make sure we don't run this twice
if (xpos < oldw/2) *prevContext |= MC_BORDER_W; // is left
if (ypos < oldh/2) *prevContext |= MC_BORDER_N; // is top
}

if(*prevContext & MC_BORDER_N || context & MC_BORDER_N) {
int delta = (y - starty) / np->yinc;
delta *= np->yinc;
if(oldh - delta >= np->minHeight
Expand All @@ -62,7 +72,7 @@ void UpdateSize(ClientNode *np, const MouseContextType context,
FixWidth(np);
}
}
if(context & MC_BORDER_S) {
if(!(*prevContext & MC_BORDER_N) && context & MC_BORDER_S) {
int delta = (y - starty) / np->yinc;
delta *= np->yinc;
np->height = oldh + delta;
Expand All @@ -72,7 +82,7 @@ void UpdateSize(ClientNode *np, const MouseContextType context,
FixWidth(np);
}
}
if(context & MC_BORDER_E) {
if(!(*prevContext & MC_BORDER_W) && context & MC_BORDER_E) {
int delta = (x - startx) / np->xinc;
delta *= np->xinc;
np->width = oldw + delta;
Expand All @@ -82,7 +92,7 @@ void UpdateSize(ClientNode *np, const MouseContextType context,
FixHeight(np);
}
}
if(context & MC_BORDER_W) {
if(*prevContext & MC_BORDER_W || context & MC_BORDER_W) {
int delta = (x - startx) / np->xinc;
delta *= np->xinc;
if(oldw - delta >= np->minWidth
Expand Down Expand Up @@ -170,6 +180,7 @@ void ResizeClient(ClientNode *np, MouseContextType context,
return;
}

MouseContextType prevContext = MC_NONE;
for(;;) {

WaitForEvent(&event);
Expand All @@ -194,7 +205,7 @@ void ResizeClient(ClientNode *np, MouseContextType context,
DiscardMotionEvents(&event, np->window);

UpdateSize(np, context, event.xmotion.x, event.xmotion.y,
startx, starty, oldx, oldy, oldw, oldh);
startx, starty, oldx, oldy, oldw, oldh, &prevContext);

lastgwidth = gwidth;
lastgheight = gheight;
Expand Down Expand Up @@ -371,7 +382,7 @@ void ResizeClientKeyboard(ClientNode *np, MouseContextType context)
DiscardMotionEvents(&event, np->window);

UpdateSize(np, context, event.xmotion.x, event.xmotion.y,
startx, starty, oldx, oldy, oldw, oldh);
startx, starty, oldx, oldy, oldw, oldh, 0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that either UpdateSize needs to check for the case that prevContext is NULL or this should pass a valid pointer into UpdateSize?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean passing something else instead of 0?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 turns into a null pointer dereference in UpdateSize, which leads to a seg fault for me when I select resize from the window menu. I think passing &context might give the desired effect.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. As I said, I'm definitely not an expert at C so feel free to modify the code as you see fit.


} else if(event.type == ButtonRelease) {

Expand Down