2026-07-14 19:27:27 +02:00
|
|
|
|
/*
|
|
|
|
|
|
gtk-uring-app.hpp - simple GTK Host Application
|
|
|
|
|
|
|
|
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2025, Benny Lyons <benny.lyons@gmx.net>
|
|
|
|
|
|
2025,2026 Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
|
under the terms of the GNU GPL version 2+ See the LICENSE file for details.
|
|
|
|
|
|
|
|
|
|
|
|
* ************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef GTK_URING_APP_H
|
|
|
|
|
|
#define GTK_URING_APP_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "commons.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include <gtkmm/window.h>
|
|
|
|
|
|
#include <gtkmm/button.h>
|
|
|
|
|
|
#include <gtkmm/application.h>
|
|
|
|
|
|
#include <glibmm/dispatcher.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
|
|
using std::unique_ptr;
|
|
|
|
|
|
using Glib::ustring;
|
|
|
|
|
|
using std::move;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Minimalist GTK application, used as framework for a demo of reading and displaying video.
|
|
|
|
|
|
* @tparam CTX custom data context to allocate while periodic processing is active
|
|
|
|
|
|
* @remark The actual actions can be installed as functors / callbacks
|
|
|
|
|
|
* - onClick() installs a function to be invoked when the button is first clicked;
|
|
|
|
|
|
* this function must return a _context object,_ which represents "the process"
|
|
|
|
|
|
* and will be copied into heap storage; the further functors will receive context.
|
|
|
|
|
|
* - onClose(CTX&) will be invoked when the application is shut down
|
|
|
|
|
|
*/
|
|
|
|
|
|
template<class CTX>
|
|
|
|
|
|
class GtkUringApp
|
|
|
|
|
|
: public Gtk::Application
|
|
|
|
|
|
{
|
|
|
|
|
|
class DemoWindow
|
|
|
|
|
|
: public Gtk::Window
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
DemoWindow()
|
|
|
|
|
|
{
|
|
|
|
|
|
// set_default_size (CTX::VIDEO_WIDTH, CTX::VIDEO_HEIGHT);
|
|
|
|
|
|
set_resizable (false);
|
|
|
|
|
|
add (button_);
|
|
|
|
|
|
button_.show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Gtk::Button button_{"click to start video..."};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
DemoWindow demoWindow_;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
GtkUringApp (ustring appID)
|
|
|
|
|
|
: Gtk::Application{appID}
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using StartTask = std::function<unique_ptr<CTX>(Gtk::Window&)>;
|
|
|
|
|
|
using CloseTask = std::function<void(CTX&)>;
|
|
|
|
|
|
|
|
|
|
|
|
GtkUringApp&
|
|
|
|
|
|
onClick (StartTask task)
|
|
|
|
|
|
{
|
|
|
|
|
|
startTask_ = move(task);
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
|
|
|
|
|
GtkUringApp&
|
|
|
|
|
|
onClose (CloseTask task)
|
|
|
|
|
|
{
|
|
|
|
|
|
closeTask_ = move(task);
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
|
run()
|
|
|
|
|
|
{
|
|
|
|
|
|
demoWindow_.button_.signal_clicked().connect(
|
2026-07-15 18:56:37 +02:00
|
|
|
|
sigc::mem_fun (*this, &GtkUringApp::triggerProcessing));
|
2026-07-14 19:27:27 +02:00
|
|
|
|
|
|
|
|
|
|
return Gtk::Application::run (demoWindow_);
|
|
|
|
|
|
} // blocks while application is active
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
std::unique_ptr<CTX> processor_;
|
|
|
|
|
|
StartTask startTask_;
|
|
|
|
|
|
CloseTask closeTask_;
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
triggerProcessing()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (processor_) return;
|
|
|
|
|
|
|
|
|
|
|
|
if (startTask_)
|
|
|
|
|
|
{
|
|
|
|
|
|
processor_ = startTask_(demoWindow_);
|
|
|
|
|
|
|
|
|
|
|
|
demoWindow_.button_.set_sensitive(false); // disable the button
|
|
|
|
|
|
demoWindow_.button_.set_label("active");
|
2026-07-14 20:16:18 +02:00
|
|
|
|
|
2026-07-14 19:27:27 +02:00
|
|
|
|
auto closeHook = [this]{
|
|
|
|
|
|
if (closeTask_)
|
|
|
|
|
|
closeTask_(*processor_);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this->signal_shutdown().connect (closeHook);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /*GTK_URING_APP_H*/
|