MPV: quick setup for load file menu action
Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
975e722a10
commit
3c9a597f7f
3 changed files with 60 additions and 2 deletions
|
|
@ -208,6 +208,15 @@ void EmbedWidget::hide()
|
||||||
pData->hide();
|
pData->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uintptr_t EmbedWidget::getNativeWindowId() const
|
||||||
|
{
|
||||||
|
#ifdef HAVE_X11
|
||||||
|
return pData->window;
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void EmbedWidget::step()
|
void EmbedWidget::step()
|
||||||
{
|
{
|
||||||
pData->step(getAbsoluteRect());
|
pData->step(getAbsoluteRect());
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ struct EmbedWidget : Widget {
|
||||||
void embedIntoRack(uintptr_t nativeWindowId);
|
void embedIntoRack(uintptr_t nativeWindowId);
|
||||||
void hide();
|
void hide();
|
||||||
|
|
||||||
|
uintptr_t getNativeWindowId() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void draw(const DrawArgs&) override {}
|
void draw(const DrawArgs&) override {}
|
||||||
void step() override;
|
void step() override;
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "plugincontext.hpp"
|
#include "plugincontext.hpp"
|
||||||
|
|
||||||
#ifndef HEADLESS
|
#ifndef HEADLESS
|
||||||
# include "EmbedWidget.hpp"
|
# include "EmbedWidget.hpp"
|
||||||
|
# include "extra/ExternalWindow.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
@ -54,7 +54,7 @@ struct CardinalEmbedModule : Module {
|
||||||
// --------------------------------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef HEADLESS
|
#ifndef HEADLESS
|
||||||
struct CardinalEmbedWidget : ModuleWidget {
|
struct CardinalEmbedWidget : ModuleWidget, ExternalWindow {
|
||||||
CardinalEmbedModule* const module;
|
CardinalEmbedModule* const module;
|
||||||
CardinalPluginContext* const pcontext;
|
CardinalPluginContext* const pcontext;
|
||||||
EmbedWidget* embedWidget = nullptr;
|
EmbedWidget* embedWidget = nullptr;
|
||||||
|
|
@ -62,6 +62,7 @@ struct CardinalEmbedWidget : ModuleWidget {
|
||||||
|
|
||||||
CardinalEmbedWidget(CardinalEmbedModule* const m)
|
CardinalEmbedWidget(CardinalEmbedModule* const m)
|
||||||
: ModuleWidget(),
|
: ModuleWidget(),
|
||||||
|
ExternalWindow(),
|
||||||
module(m),
|
module(m),
|
||||||
pcontext(m != nullptr ? m->pcontext : nullptr)
|
pcontext(m != nullptr ? m->pcontext : nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -75,6 +76,11 @@ struct CardinalEmbedWidget : ModuleWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~CardinalEmbedWidget()
|
||||||
|
{
|
||||||
|
terminateAndWaitForExternalProcess();
|
||||||
|
}
|
||||||
|
|
||||||
void onContextCreate(const ContextCreateEvent& e) override
|
void onContextCreate(const ContextCreateEvent& e) override
|
||||||
{
|
{
|
||||||
ModuleWidget::onContextCreate(e);
|
ModuleWidget::onContextCreate(e);
|
||||||
|
|
@ -121,6 +127,47 @@ struct CardinalEmbedWidget : ModuleWidget {
|
||||||
isEmbed = false;
|
isEmbed = false;
|
||||||
embedWidget->hide();
|
embedWidget->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void appendContextMenu(ui::Menu* const menu) override
|
||||||
|
{
|
||||||
|
menu->addChild(new ui::MenuSeparator);
|
||||||
|
|
||||||
|
struct LoadVideoFileItem : MenuItem {
|
||||||
|
CardinalEmbedWidget* const self;
|
||||||
|
|
||||||
|
LoadVideoFileItem(CardinalEmbedWidget* const s)
|
||||||
|
: self(s)
|
||||||
|
{
|
||||||
|
text = "Load video file...";
|
||||||
|
}
|
||||||
|
|
||||||
|
void onAction(const event::Action&) override
|
||||||
|
{
|
||||||
|
WeakPtr<CardinalEmbedWidget> const self = this->self;
|
||||||
|
async_dialog_filebrowser(false, nullptr, text.c_str(), [self](char* path)
|
||||||
|
{
|
||||||
|
if (path == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (self != nullptr)
|
||||||
|
{
|
||||||
|
char winIdStr[64];
|
||||||
|
std::snprintf(winIdStr, sizeof(winIdStr), "--wid=%lu",
|
||||||
|
static_cast<ulong>(self->embedWidget->getNativeWindowId()));
|
||||||
|
const char* args[] = {
|
||||||
|
"mpv", "--no-audio", winIdStr, path, nullptr
|
||||||
|
};
|
||||||
|
self->terminateAndWaitForExternalProcess();
|
||||||
|
self->startExternalProcess(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::free(path);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
menu->addChild(new LoadVideoFileItem(this));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
typedef ModuleWidget CardinalEmbedWidget;
|
typedef ModuleWidget CardinalEmbedWidget;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue