Skip to content

Commit

Permalink
Fix restart issue of X11 software screen grabber
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Dec 15, 2021
1 parent c8049f1 commit aa91277
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions libsrc/grabber/X11/X11Grabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ void X11Grabber::stop()
{
_uninitX11Display(_handle);
_handle = nullptr;
_initialized = false;
}
_semaphore.release();
Info(_log, "Stopped");
Expand Down
17 changes: 16 additions & 1 deletion libsrc/grabber/X11/smartX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct x11Displays* enumerateX11Displays()

auto dispCount = ScreenCount(myDisplay);

if (dispCount < 0)
if (dispCount <= 0)
{
XCloseDisplay(myDisplay);
return nullptr;
Expand Down Expand Up @@ -51,6 +51,13 @@ void releaseX11Displays(struct x11Displays* buffer)
free(buffer);
}

static int x11errorHandler(Display* d, XErrorEvent* e)
{
return 0;
}

static XErrorHandler oldHandler = nullptr;

x11Handle* initX11Display(int display)
{
Display* maindisplay = XOpenDisplay(NULL);
Expand All @@ -67,6 +74,8 @@ x11Handle* initX11Display(int display)
retVal->height = 0;
retVal->size = 0;

oldHandler = XSetErrorHandler(x11errorHandler);

return retVal;
}

Expand All @@ -83,6 +92,12 @@ void releaseFrame(x11Handle* retVal)

void uninitX11Display(x11Handle* retVal)
{
if (oldHandler != nullptr)
{
XSetErrorHandler(oldHandler);
oldHandler = nullptr;
}

if (retVal == nullptr)
return;

Expand Down

0 comments on commit aa91277

Please sign in to comment.