Skip to content

Commit 9baed3b

Browse files
committed
Added check in linux for window change detection
1 parent 761014b commit 9baed3b

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

Example/Screen_Capture_Example.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,20 @@ void createwindowgrabber()
105105
auto s = std::to_string(r) + std::string("WINDIF_") + std::string(".jpg");
106106
auto size = RowStride(img) * Height(img);
107107

108-
/* auto imgbuffer(std::make_unique<unsigned char[]>(size));
108+
/* auto imgbuffer(std::make_unique<unsigned char[]>(size));
109109
ExtractAndConvertToRGBA(img, imgbuffer.get(), size);
110-
tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char*)imgbuffer.get());*/
110+
tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char*)imgbuffer.get());
111+
*/
111112
})->onNewFrame([&](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Window& window) {
112113

113114
auto r = realcounter.fetch_add(1);
114115
auto s = std::to_string(r) + std::string("WINNEW_") + std::string(".jpg");
115-
116-
auto size = RowStride(img) * Height(img);/*
117-
auto imgbuffer(std::make_unique<unsigned char[]>(size));
116+
auto size = RowStride(img) * Height(img);
117+
118+
/* auto imgbuffer(std::make_unique<unsigned char[]>(size));
118119
ExtractAndConvertToRGBA(img, imgbuffer.get(), size);
119-
tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char*)imgbuffer.get());*/
120+
tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char*)imgbuffer.get());
121+
*/
120122
if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - onNewFramestart).count() >= 1000) {
121123
std::cout << "onNewFrame fps" << onNewFramecounter << std::endl;
122124
onNewFramecounter = 0;

src/linux/X11FrameProcessor.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ namespace Screen_Capture
123123
ret.left = ret.top = 0;
124124
ret.right = selectedwindow.Size.x;
125125
ret.bottom = selectedwindow.Size.y;
126-
126+
XWindowAttributes wndattr;
127+
if(XGetWindowAttributes(SelectedDisplay, SelectedWindow, &wndattr) ==0){
128+
return DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED;//window might not be valid any more
129+
}
130+
if(wndattr.width != ret.right || wndattr.height != ret.bottom){
131+
return DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED;//window size changed. This will rebuild everything
132+
}
127133
if(!XShmGetImage(SelectedDisplay,
128134
selectedwindow.Handle,
129135
Image,

0 commit comments

Comments
 (0)