99#include < string>
1010#include < thread>
1111#include < vector>
12+ #if defined(__linux__) || defined(__APPLE__)
13+ // qt includes
14+ #include < QImage>
15+ #include < QString>
16+ #endif
1217#ifdef _WIN32
1318 #ifndef NOMINMAX
1419 #define NOMINMAX
2126// clang-format on
2227#endif
2328
29+ // lib includes
30+ #include < lizardbyte/common/env.h>
31+
2432namespace {
33+ bool capture_full_screen () {
34+ return lizardbyte::common::is_github_actions () && lizardbyte::common::get_env (" RUNNER_DEBUG" ) == " 1" ;
35+ }
36+
2537#if defined(__linux__) || defined(__APPLE__)
2638 std::string quote_shell_path (const std::filesystem::path &path) {
2739 const std::string input = path.string ();
@@ -38,6 +50,24 @@ namespace {
3850 output.push_back (' "' );
3951 return output;
4052 }
53+
54+ bool crop_to_top_right_quadrant (const std::filesystem::path &file) {
55+ const QString imagePath = QString::fromUtf8 (file.u8string ().c_str ());
56+ const QImage image (imagePath);
57+ if (image.isNull () || image.width () < 2 || image.height () < 2 ) {
58+ std::cerr << " Screenshot dimensions invalid" << std::endl;
59+ return false ;
60+ }
61+
62+ const int width = image.width () / 2 ;
63+ const int height = image.height () / 2 ;
64+ const QImage quadrant = image.copy (image.width () - width, 0 , width, height);
65+ if (!quadrant.save (imagePath, " PNG" )) {
66+ std::cerr << " Failed to crop " << file << std::endl;
67+ return false ;
68+ }
69+ return true ;
70+ }
4171#endif
4272
4373#ifdef _WIN32
@@ -108,7 +138,10 @@ namespace screenshot {
108138#ifdef __APPLE__
109139 static bool capture_macos (const std::filesystem::path &file, const Options &) {
110140 std::string cmd = " screencapture -x " + quote_shell_path (file);
111- return std::system (cmd.c_str ()) == 0 ;
141+ if (std::system (cmd.c_str ()) != 0 ) {
142+ return false ;
143+ }
144+ return capture_full_screen () || crop_to_top_right_quadrant (file);
112145 }
113146#endif
114147
@@ -118,17 +151,20 @@ namespace screenshot {
118151 if (std::system (" which import > /dev/null 2>&1" ) == 0 ) {
119152 std::string cmd = " import -window root " + target;
120153 if (std::system (cmd.c_str ()) == 0 ) {
121- return true ;
154+ return capture_full_screen () || crop_to_top_right_quadrant (file) ;
122155 }
123156 }
124157 if (std::system (" which spectacle > /dev/null 2>&1" ) == 0 ) {
125158 std::string cmd = " spectacle -f -b -n -o " + target;
126159 if (std::system (cmd.c_str ()) == 0 ) {
127- return true ;
160+ return capture_full_screen () || crop_to_top_right_quadrant (file) ;
128161 }
129162 }
130163 std::string cmd = " gnome-screenshot -f " + target;
131- return std::system (cmd.c_str ()) == 0 ;
164+ if (std::system (cmd.c_str ()) != 0 ) {
165+ return false ;
166+ }
167+ return capture_full_screen () || crop_to_top_right_quadrant (file);
132168 }
133169#endif
134170
@@ -162,6 +198,15 @@ namespace screenshot {
162198 return false ;
163199 }
164200
201+ if (!capture_full_screen ()) {
202+ const int fullWidth = width;
203+ const int fullHeight = height;
204+ width = fullWidth / 2 ;
205+ height = fullHeight / 2 ;
206+ left += fullWidth - width;
207+ top += fullHeight - height;
208+ }
209+
165210 HDC hdcScreen = GetDC (nullptr );
166211 if (hdcScreen == nullptr ) {
167212 std::cerr << " GetDC(nullptr) failed" << std::endl;
0 commit comments