Skip to content

Commit

Permalink
fix: don't try to unmap a window that isn't mapped
Browse files Browse the repository at this point in the history
Closes: #389
  • Loading branch information
N-R-K committed Nov 10, 2024
1 parent 4976938 commit 373e3f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/scrot_selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct SelectionClassic {
};
struct SelectionEdge {
Window wndDraw;
bool isMapped;
};

struct Selection {
Expand Down
8 changes: 5 additions & 3 deletions src/selection_edge.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void selectionEdgeCreate(void)
pe->wndDraw = XCreateWindow(disp, root, 0, 0, WidthOfScreen(scr),
HeightOfScreen(scr), 0, CopyFromParent, InputOutput, CopyFromParent,
CWOverrideRedirect | CWBackPixel, &attr);
pe->isMapped = false;

unsigned long opacity = opt.lineOpacity * (0xFFFFFFFFu / 255);

Expand All @@ -79,8 +80,8 @@ void selectionEdgeCreate(void)

void selectionEdgeDraw(void)
{
const struct Selection *const sel = &selection;
const struct SelectionEdge *const pe = &sel->edge;
struct Selection *const sel = &selection;
struct SelectionEdge *const pe = &sel->edge;

XRectangle rects[4] = {
{ sel->rect.x, sel->rect.y, opt.lineWidth, sel->rect.h }, // left
Expand All @@ -95,6 +96,7 @@ void selectionEdgeDraw(void)
XShapeCombineRectangles(disp, pe->wndDraw, ShapeBounding, 0, 0, rects, 4,
ShapeSet, 0);
XMapWindow(disp, pe->wndDraw);
pe->isMapped = true;
}

void selectionEdgeMotionDraw(int x0, int y0, int x1, int y1)
Expand All @@ -118,7 +120,7 @@ void selectionEdgeDestroy(void)
if (pe->wndDraw != None) {
XSelectInput(disp, pe->wndDraw, StructureNotifyMask);
XDestroyWindow(disp, pe->wndDraw);
bool is_unmapped = false, is_destroyed = false;
bool is_unmapped = !pe->isMapped, is_destroyed = false;
for (XEvent ev; !(is_unmapped && is_destroyed);) {
XNextEvent(disp, &ev);
if (ev.type == DestroyNotify && ev.xdestroywindow.window == pe->wndDraw)
Expand Down

0 comments on commit 373e3f0

Please sign in to comment.