Skip to content

Commit

Permalink
JXWindow: make it safe to call Refresh() from non-ui thread
Browse files Browse the repository at this point in the history
  • Loading branch information
jafl committed Jun 9, 2024
1 parent e992922 commit d6a9296
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions libjx/code/JXWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,11 @@ JXWindow::RefreshRect
)
const
{
itsUpdateRegionMutex.lock();
XRectangle xrect = JXJToXRect(rect);
XUnionRectWithRegion(&xrect, itsUpdateRegion, itsUpdateRegion);
itsUpdateRegionMutex.unlock();

itsDisplay->WindowNeedsUpdate(const_cast<JXWindow*>(this));
}

Expand All @@ -921,8 +924,10 @@ void
JXWindow::Redraw()
const
{
itsUpdateRegionMutex.lock();
Refresh();
const_cast<JXWindow*>(this)->Update();
itsUpdateRegionMutex.unlock();
}

/******************************************************************************
Expand All @@ -937,8 +942,10 @@ JXWindow::RedrawRect
)
const
{
itsUpdateRegionMutex.lock();
RefreshRect(rect);
const_cast<JXWindow*>(this)->Update();
itsUpdateRegionMutex.unlock();
}

/******************************************************************************
Expand Down Expand Up @@ -978,14 +985,18 @@ JXWindow::BufferDrawing
void
JXWindow::Update()
{
itsUpdateRegionMutex.lock();

if (XEmptyRegion(itsUpdateRegion))
{
itsUpdateRegionMutex.unlock();
return;
}
else if ((!itsIsMappedFlag || itsIsIconifiedFlag) && !itsUseBkgdPixmapFlag)
{
XDestroyRegion(itsUpdateRegion);
itsUpdateRegion = XCreateRegion();
itsUpdateRegionMutex.unlock();
return;
}

Expand All @@ -997,6 +1008,8 @@ JXWindow::Update()
XDestroyRegion(itsUpdateRegion);
itsUpdateRegion = XCreateRegion();

itsUpdateRegionMutex.unlock();

const Drawable drawable = PrepareForUpdate();
const JRect rect = JXGetRegionBounds(updateRegion);
JXWindowPainter p(itsGC, drawable, itsBounds, updateRegion);
Expand Down Expand Up @@ -4673,12 +4686,17 @@ JXWindow::CalledByHandleExpose
const XExposeEvent& exposeEvent
)
{
itsUpdateRegionMutex.lock();

XRectangle xrect;
xrect.x = exposeEvent.x;
xrect.y = exposeEvent.y;
xrect.width = exposeEvent.width;
xrect.height = exposeEvent.height;
XUnionRectWithRegion(&xrect, itsUpdateRegion, itsUpdateRegion);

itsUpdateRegionMutex.unlock();

itsDisplay->WindowNeedsUpdate(this);
}

Expand Down
3 changes: 3 additions & 0 deletions libjx/code/JXWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <jx-af/jcore/JString.h>
#include <mutex>

class JXDisplay;
class JXGC;
Expand Down Expand Up @@ -406,6 +407,8 @@ class JXWindow : public JXContainer

mutable Window itsRootChild; // ancestor which is direct child of root window

mutable std::recursive_mutex itsUpdateRegionMutex;

// multiple click detection

JXContainer* itsPrevMouseContainer;
Expand Down

0 comments on commit d6a9296

Please sign in to comment.