Files
plezy/windows/runner/mpv/mpv_core.h
T

64 lines
1.7 KiB
C++
Raw Normal View History

2025-12-01 15:30:28 +01:00
#ifndef MPV_CORE_H_
#define MPV_CORE_H_
#include <Windows.h>
#include <cmath>
#include <map>
#include <memory>
#include <optional>
namespace mpv {
// Core class for managing z-order and window positioning for mpv video window.
// Handles transparency, minimize/maximize animations, and position syncing.
class MpvCore {
public:
static constexpr auto kPositionAndShowDelay = 300;
2025-12-22 09:04:15 +01:00
static constexpr UINT_PTR kCompositionRestoreTimerId = 1001;
2025-12-01 15:30:28 +01:00
static MpvCore* GetInstance();
static void SetInstance(std::unique_ptr<MpvCore> instance);
2026-03-10 22:24:14 +01:00
explicit MpvCore(HWND flutter_window);
2025-12-01 15:30:28 +01:00
~MpvCore();
// Initializes transparency on the Flutter window.
void EnsureInitialized();
// Creates and positions the mpv video view.
void CreateMpvView(HWND mpv_hwnd, RECT rect, double device_pixel_ratio);
// Updates the mpv view position.
void ResizeMpvView(HWND mpv_hwnd, RECT rect);
// Disposes the mpv view.
void DisposeMpvView(HWND mpv_hwnd);
// Shows or hides the mpv view.
void SetVisible(bool visible);
// Window procedure handler for Flutter window messages.
2026-05-01 05:47:13 +02:00
std::optional<HRESULT> WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
2025-12-01 15:30:28 +01:00
private:
RECT GetGlobalRect(int32_t left, int32_t top, int32_t right, int32_t bottom);
2026-04-02 15:02:07 +02:00
void EnableComposition();
void DisableComposition();
2025-12-01 15:30:28 +01:00
HWND flutter_window_ = nullptr;
HWND container_ = nullptr;
double device_pixel_ratio_ = 1.0;
std::map<HWND, RECT> mpv_views_;
WPARAM last_wm_size_wparam_ = SIZE_RESTORED;
bool was_window_hidden_due_to_minimize_ = false;
bool visible_ = true;
2025-12-22 09:04:15 +01:00
bool composition_enabled_ = false;
2025-12-01 15:30:28 +01:00
static std::unique_ptr<MpvCore> instance_;
};
} // namespace mpv
#endif // MPV_CORE_H_