| 791 | // =========================================================================== |
| 792 | |
| 793 | bool PipeWireScreencap::pw_init() |
| 794 | { |
| 795 | // Create pw_thread_loop (standard event loop with integrated bg thread) |
| 796 | pw_thread_loop_ = pw_thread_loop_new("MaaScreencap", nullptr); |
| 797 | if (!pw_thread_loop_) { |
| 798 | LogError << "Failed to create PipeWire thread loop"; |
| 799 | return false; |
| 800 | } |
| 801 | |
| 802 | pw_loop_ = pw_thread_loop_get_loop(pw_thread_loop_); |
| 803 | |
| 804 | pw_context_ = pw_context_new(pw_loop_, nullptr, 0); |
| 805 | if (!pw_context_) { |
| 806 | LogError << "Failed to create PipeWire context"; |
| 807 | close_internal(); |
| 808 | return false; |
| 809 | } |
| 810 | |
| 811 | if (pipewire_fd_ < 0) { |
| 812 | LogError << "Invalid PipeWire FD (missing OpenPipeWireRemote?)"; |
| 813 | close_internal(); |
| 814 | return false; |
| 815 | } |
| 816 | |
| 817 | // Connect to KWin's private PipeWire instance via the portal FD |
| 818 | pw_core_ = pw_context_connect_fd(pw_context_, pipewire_fd_, nullptr, 0); |
| 819 | if (!pw_core_) { |
| 820 | LogError << "Failed to connect via portal PipeWire FD"; |
| 821 | close_internal(); |
| 822 | return false; |
| 823 | } |
| 824 | |
| 825 | // pw_context_connect_fd takes ownership of pipewire_fd_ |
| 826 | pipewire_fd_ = -1; |
| 827 | |
| 828 | // Register core event listener for error detection (e.g. EPIPE on disconnect). |
| 829 | static const struct pw_core_events core_events = { |
| 830 | .version = PW_VERSION_CORE_EVENTS, |
| 831 | .error = pw_on_core_error, |
| 832 | }; |
| 833 | pw_core_add_listener(pw_core_, &core_hook_, &core_events, this); |
| 834 | |
| 835 | return true; |
| 836 | } |
| 837 | |
| 838 | bool PipeWireScreencap::pw_create_stream() |
| 839 | { |
nothing calls this directly
no outgoing calls
no test coverage detected