3131#include " oshot_png.h"
3232#include " screen_capture.hpp"
3333#include " screenshot_tool.hpp"
34- #include " socket.hpp"
3534#include " spdlog/sinks/basic_file_sink.h"
3635#include " spdlog/sinks/stdout_color_sinks.h"
3736#include " switch_fnv1a.hpp"
@@ -51,12 +50,6 @@ struct GLFWwindow;
5150# pragma comment(lib, "legacy_stdio_definitions")
5251#endif
5352
54- #if (!__has_include("version.h"))
55- # error "version.h not found, please generate it with ./scripts/generateVersion.sh"
56- #else
57- # include " version.h"
58- #endif
59-
6053// clang-format off
6154// https://cfengine.com/blog/2021/optional-arguments-with-getopt-long/
6255// because "--opt-arg arg" won't work
@@ -357,11 +350,6 @@ int main(int argc, char* argv[])
357350 setenv (" LD_LIBRARY_PATH" , orig, 1 );
358351 else
359352 unsetenv (" LD_LIBRARY_PATH" ); // not running from AppImage, clear any stale value
360-
361- // Xlib is not thread-safe by default. We call it from both the render thread
362- // and the IPC/clipboard thread; this enables Xlib's internal locking.
363- // Must be called before glfwInit(), which opens a Display* immediately.
364- XInitThreads ();
365353#endif
366354
367355 atexit (exit_handler_nc);
@@ -403,7 +391,6 @@ int main(int argc, char* argv[])
403391 const std::string& imgui_ini_path = configDir + " /imgui.ini" ;
404392
405393 g_clipboard = std::make_unique<Clipboard>(get_session_type ());
406- g_sender = std::make_unique<SocketSender>();
407394 g_config = std::make_unique<Config>(configFile, configDir);
408395 if (!parseargs (argc, argv, configFile))
409396 return EXIT_FAILURE;
@@ -443,107 +430,6 @@ int main(int argc, char* argv[])
443430 // AppKit), so capture_worker must not run, because it would call run_main_tool
444431 // from a background thread and crash with NSInternalInconsistencyException.
445432 std::thread worker (capture_worker, imgui_ini_path);
446-
447- std::thread ipc ([&] {
448- while (!quit.load ())
449- {
450- const int client = ::accept (g_sock, nullptr , nullptr );
451- if (client < 0 )
452- {
453- if (quit.load ())
454- break ;
455- continue ;
456- }
457-
458- // Set receive timeout
459- struct timeval tv;
460- tv.tv_sec = 2 ;
461- tv.tv_usec = 0 ;
462- setsockopt (client, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof (tv));
463-
464- auto recv_all = [](int fd, void * dst, size_t n) {
465- uint8_t * p = static_cast <uint8_t *>(dst);
466- size_t remaining = n;
467- while (remaining > 0 )
468- {
469- const ssize_t r = ::recv (fd, p, remaining, 0 );
470- if (r <= 0 )
471- {
472- if (r == 0 )
473- spdlog::debug (" Connection closed by peer" );
474- else
475- spdlog::debug (" recv error: {}" , strerror (errno));
476- return false ;
477- }
478- p += static_cast <size_t >(r);
479- remaining -= static_cast <size_t >(r);
480- }
481- return true ;
482- };
483-
484- char type = 0 ;
485- uint32_t len = 0 ;
486-
487- bool ok = recv_all (client, &type, 1 ) && recv_all (client, &len, sizeof (len));
488-
489- if (ok)
490- spdlog::debug (" IPC received type={}, len={}" , type, len);
491-
492- std::vector<uint8_t > payload;
493- if (ok && len > 0 && len < 100 * 1024 * 1024 ) // Sanity check: max 100MB
494- {
495- payload.resize (len);
496- ok = recv_all (client, payload.data (), payload.size ());
497- }
498-
499- close (client);
500-
501- if (!ok)
502- continue ;
503-
504- if (type == ' T' )
505- {
506- std::string text (payload.begin (), payload.end ());
507- g_clipboard->CopyText (text);
508- }
509- else if (type == ' I' )
510- {
511- if (payload.size () < 8 )
512- {
513- spdlog::debug (" IPC image payload too small: {}" , payload.size ());
514- continue ;
515- }
516-
517- int w = 0 , h = 0 ;
518- std::memcpy (&w, payload.data () + 0 , 4 );
519- std::memcpy (&h, payload.data () + 4 , 4 );
520-
521- spdlog::debug (" IPC received image: {}x{}" , w, h);
522-
523- if (w <= 0 || h <= 0 )
524- continue ;
525-
526- const size_t expected = static_cast <size_t >(w) * h * 4 ;
527- if (payload.size () != expected + 8 )
528- {
529- spdlog::debug (" IPC image size mismatch: got {}, expected {}" , payload.size (), expected + 8 );
530- continue ;
531- }
532-
533- // Strip the 8-byte header
534- payload.erase (payload.begin (), payload.begin () + 8 );
535- capture_result_t cap{ std::move (payload), w, h };
536- {
537- std::lock_guard lk (mtx);
538- pending_image = std::move (cap);
539- do_copy_image = true ;
540- cv.notify_all ();
541- }
542- }
543- }
544- close (g_sock);
545- unlink (g_sock_path);
546- });
547433#endif
548434
549435 std::vector<TrayMenu*> menu;
@@ -596,8 +482,6 @@ int main(int argc, char* argv[])
596482 // Quitted the tray
597483#if !OSHOT_TOOL_ON_MAIN_THREAD
598484 worker.join ();
599- if (ipc.joinable ())
600- ipc.join ();
601485#endif
602486
603487 return EXIT_SUCCESS;
0 commit comments