Skip to content

Commit

Permalink
animate: allow 3rd party plugins to provide additional animations
Browse files Browse the repository at this point in the history
  • Loading branch information
ammen99 committed Nov 27, 2024
1 parent f66f23c commit dad310e
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 302 deletions.
337 changes: 108 additions & 229 deletions plugins/animate/animate.cpp

Large diffs are not rendered by default.

80 changes: 60 additions & 20 deletions plugins/animate/animate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,73 @@
#include <wayfire/util/duration.hpp>
#include <wayfire/option-wrapper.hpp>

#define HIDING_ANIMATION (1 << 0)
#define SHOWING_ANIMATION (1 << 1)
#define MAP_STATE_ANIMATION (1 << 2)
#define MINIMIZE_STATE_ANIMATION (1 << 3)
#define WF_ANIMATE_HIDING_ANIMATION (1 << 0)
#define WF_ANIMATE_SHOWING_ANIMATION (1 << 1)
#define WF_ANIMATE_MAP_STATE_ANIMATION (1 << 2)
#define WF_ANIMATE_MINIMIZE_STATE_ANIMATION (1 << 3)

enum wf_animation_type
namespace wf
{
ANIMATION_TYPE_MAP = SHOWING_ANIMATION | MAP_STATE_ANIMATION,
ANIMATION_TYPE_UNMAP = HIDING_ANIMATION | MAP_STATE_ANIMATION,
ANIMATION_TYPE_MINIMIZE = HIDING_ANIMATION | MINIMIZE_STATE_ANIMATION,
ANIMATION_TYPE_RESTORE = SHOWING_ANIMATION | MINIMIZE_STATE_ANIMATION,
namespace animate
{
enum animation_type
{
ANIMATION_TYPE_MAP = WF_ANIMATE_SHOWING_ANIMATION | WF_ANIMATE_MAP_STATE_ANIMATION,
ANIMATION_TYPE_UNMAP = WF_ANIMATE_HIDING_ANIMATION | WF_ANIMATE_MAP_STATE_ANIMATION,
ANIMATION_TYPE_MINIMIZE = WF_ANIMATE_HIDING_ANIMATION | WF_ANIMATE_MINIMIZE_STATE_ANIMATION,
ANIMATION_TYPE_RESTORE = WF_ANIMATE_SHOWING_ANIMATION | WF_ANIMATE_MINIMIZE_STATE_ANIMATION,
};

class animation_base
{
public:
virtual void init(wayfire_view view, wf::animation_description_t duration, wf_animation_type type);
virtual bool step(); /* return true if continue, false otherwise */
virtual void reverse(); /* reverse the animation */
virtual int get_direction();

animation_base() = default;
virtual ~animation_base();
animation_base(const animation_base &) = default;
animation_base(animation_base &&) = default;
animation_base& operator =(const animation_base&) = default;
animation_base& operator =(animation_base&&) = default;
virtual void init(wayfire_view view, wf::animation_description_t duration, animation_type type)
{}

/**
* @return True if the animation should continue for at least one more frame.
*/
virtual bool step()
{
return false;
}

/**
* Reverse the animation direction (hiding -> showing, showing -> hiding)
*/
virtual void reverse()
{}

virtual ~animation_base() = default;
};

struct effect_description_t
{
std::function<std::unique_ptr<animation_base>()> generator;
std::function<std::optional<wf::animation_description_t>()> default_duration;
};

/**
* The effects registry holds a list of all available animation effects.
* Plugins can access the effects registry via ref_ptr_t helper in wayfire/plugins/common/shared-core-data.hpp
* They may add/remove their own effects.
*/
class animate_effects_registry_t
{
public:
void register_effect(std::string name, effect_description_t effect)
{
effects[name] = effect;
}

void unregister_effect(std::string name)
{
effects.erase(name);
}

std::map<std::string, effect_description_t> effects;
};
}
}

#endif
20 changes: 7 additions & 13 deletions plugins/animate/basic_animations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <wayfire/view-transform.hpp>
#include <wayfire/output.hpp>

class fade_animation : public animation_base
class fade_animation : public wf::animate::animation_base
{
wayfire_view view;

Expand All @@ -16,15 +16,15 @@ class fade_animation : public animation_base

public:

void init(wayfire_view view, wf::animation_description_t dur, wf_animation_type type) override
void init(wayfire_view view, wf::animation_description_t dur, wf::animate::animation_type type) override
{
this->view = view;
this->progression =
wf::animation::simple_animation_t(wf::create_option<wf::animation_description_t>(dur));

this->progression.animate(start, end);

if (type & HIDING_ANIMATION)
if (type & WF_ANIMATE_HIDING_ANIMATION)
{
this->progression.flip();
}
Expand All @@ -50,11 +50,6 @@ class fade_animation : public animation_base
this->progression.reverse();
}

int get_direction() override
{
return this->progression.get_direction();
}

~fade_animation()
{
view->get_transformed_node()->rem_transformer(name);
Expand All @@ -73,15 +68,14 @@ class zoom_animation_t : public duration_t
timed_transition_t offset_y{*this};
};

class zoom_animation : public animation_base
class zoom_animation : public fade_animation::animation_base
{
wayfire_view view;
zoom_animation_t progression;
std::string name;

public:

void init(wayfire_view view, wf::animation_description_t dur, wf_animation_type type) override
void init(wayfire_view view, wf::animation_description_t dur, wf::animate::animation_type type) override
{
this->view = view;
this->progression = zoom_animation_t(wf::create_option<wf::animation_description_t>(dur));
Expand All @@ -95,7 +89,7 @@ class zoom_animation : public animation_base
this->progression, 0, 0);
this->progression.start();

if (type & MINIMIZE_STATE_ANIMATION)
if (type & WF_ANIMATE_MINIMIZE_STATE_ANIMATION)
{
auto toplevel = wf::toplevel_cast(view);
wf::dassert(toplevel != nullptr, "We cannot minimize non-toplevel views!");
Expand All @@ -121,7 +115,7 @@ class zoom_animation : public animation_base
}
}

if (type & HIDING_ANIMATION)
if (type & WF_ANIMATE_HIDING_ANIMATION)
{
progression.alpha.flip();
progression.zoom.flip();
Expand Down
4 changes: 2 additions & 2 deletions plugins/animate/fire/fire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ static float fire_duration_mod_for_height(int height)
return std::min(height / 400.0, 3.0);
}

void FireAnimation::init(wayfire_view view, wf::animation_description_t dur, wf_animation_type type)
void FireAnimation::init(wayfire_view view, wf::animation_description_t dur, wf::animate::animation_type type)
{
this->view = view;

Expand All @@ -242,7 +242,7 @@ void FireAnimation::init(wayfire_view view, wf::animation_description_t dur, wf_
wf::create_option<wf::animation_description_t>(dur));
this->progression.animate(0, 1);

if (type & HIDING_ANIMATION)
if (type & WF_ANIMATE_HIDING_ANIMATION)
{
this->progression.flip();
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/animate/fire/fire.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class FireTransformer;
class ParticleSystem;

class FireAnimation : public animation_base
class FireAnimation : public wf::animate::animation_base
{
std::string name; // the name of the transformer in the view's table
wayfire_view view;
Expand All @@ -17,7 +17,7 @@ class FireAnimation : public animation_base
public:

~FireAnimation();
void init(wayfire_view view, wf::animation_description_t, wf_animation_type type) override;
void init(wayfire_view view, wf::animation_description_t, wf::animate::animation_type type) override;
bool step() override; /* return true if continue, false otherwise */
void reverse() override; /* reverse the animation */
};
Expand Down
2 changes: 2 additions & 0 deletions plugins/animate/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ animiate = shared_module('animate',
dependencies: dependencies,
install: true,
install_dir: join_paths(get_option('libdir'), 'wayfire'))

install_headers(['animate.hpp'], subdir: 'wayfire/plugins/animate')
18 changes: 5 additions & 13 deletions plugins/animate/spin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
*/

#include "animate.hpp"
#include "wayfire/toplevel-view.hpp"
#include <memory>
#include <wayfire/plugin.hpp>
#include <wayfire/opengl.hpp>
#include <wayfire/view-transform.hpp>
#include <wayfire/output.hpp>


wf::option_wrapper_t<wf::animation_description_t> spin_duration{"animate/spin_duration"};
wf::option_wrapper_t<int> spin_rotations{"animate/spin_rotations"};

namespace wf
Expand All @@ -45,22 +43,21 @@ class spin_animation_t : public duration_t
public:
using duration_t::duration_t;
};
class spin_animation : public animation_base
class spin_animation : public animate::animation_base
{
wayfire_view view;
wf_animation_type type;
animate::animation_type type;
wf::spin::spin_animation_t progression;

public:

void init(wayfire_view view, wf::animation_description_t dur, wf_animation_type type) override
void init(wayfire_view view, wf::animation_description_t dur, animate::animation_type type) override
{
this->view = view;
this->type = type;
this->progression =
wf::spin::spin_animation_t(wf::create_option<wf::animation_description_t>(spin_duration));
this->progression = wf::spin::spin_animation_t(wf::create_option<wf::animation_description_t>(dur));

if (type & HIDING_ANIMATION)
if (type & WF_ANIMATE_HIDING_ANIMATION)
{
this->progression.reverse();
}
Expand Down Expand Up @@ -90,11 +87,6 @@ class spin_animation : public animation_base
this->progression.reverse();
}

int get_direction() override
{
return this->progression.get_direction();
}

~spin_animation()
{
view->get_transformed_node()->rem_transformer(spin_transformer_name);
Expand Down
15 changes: 7 additions & 8 deletions plugins/animate/squeezimize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
#include "animate.hpp"


wf::option_wrapper_t<wf::animation_description_t> squeezimize_duration{"animate/squeezimize_duration"};

static const char *squeeze_vert_source =
R"(
#version 100
Expand Down Expand Up @@ -132,7 +130,7 @@ class squeezimize_transformer : public wf::scene::view_2d_transformer_t
OpenGL::program_t program;
wf::geometry_t minimize_target;
wf::geometry_t animation_geometry;
squeezimize_animation_t progression{squeezimize_duration};
squeezimize_animation_t progression;

class simple_node_render_instance_t : public wf::scene::transformer_render_instance_t<squeezimize_transformer>
{
Expand Down Expand Up @@ -251,9 +249,10 @@ class squeezimize_transformer : public wf::scene::view_2d_transformer_t
}
};

squeezimize_transformer(wayfire_view view,
squeezimize_transformer(wayfire_view view, wf::animation_description_t duration,
wf::geometry_t minimize_target, wf::geometry_t bbox) : wf::scene::view_2d_transformer_t(view)
{
this->progression = squeezimize_animation_t{wf::create_option<>(duration)};
this->minimize_target = minimize_target;
/* If there is no minimize target set, minimize to the bottom center of the output */
if ((this->minimize_target.width <= 0) || (this->minimize_target.height <= 0))
Expand Down Expand Up @@ -313,12 +312,12 @@ class squeezimize_transformer : public wf::scene::view_2d_transformer_t
}
};

class squeezimize_animation : public animation_base
class squeezimize_animation : public animate::animation_base
{
wayfire_view view;

public:
void init(wayfire_view view, wf::animation_description_t dur, wf_animation_type type) override
void init(wayfire_view view, wf::animation_description_t dur, animate::animation_type type) override
{
this->view = view;
pop_transformer(view);
Expand All @@ -327,9 +326,9 @@ class squeezimize_animation : public animation_base
wf::dassert(toplevel != nullptr, "We cannot minimize non-toplevel views!");
auto hint = toplevel->get_minimize_hint();
auto tmgr = view->get_transformed_node();
auto node = std::make_shared<wf::squeezimize::squeezimize_transformer>(view, hint, bbox);
auto node = std::make_shared<wf::squeezimize::squeezimize_transformer>(view, dur, hint, bbox);
tmgr->add_transformer(node, wf::TRANSFORMER_HIGHLEVEL + 1, squeezimize_transformer_name);
node->init_animation(type & HIDING_ANIMATION);
node->init_animation(type & WF_ANIMATE_HIDING_ANIMATION);
}

void pop_transformer(wayfire_view view)
Expand Down
5 changes: 5 additions & 0 deletions plugins/animate/unmapped-view-node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class unmapped_view_snapshot_node : public wf::scene::node_t
instances.push_back(std::make_unique<rinstance_t>(this, push_damage, shown_on));
}

std::string stringify() const override
{
return "unmapped-view-snapshot-node " + this->stringify_flags();
}

private:
class rinstance_t : public wf::scene::simple_render_instance_t<unmapped_view_snapshot_node>
{
Expand Down
20 changes: 5 additions & 15 deletions plugins/animate/zap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@
*/

#include "animate.hpp"
#include "wayfire/toplevel-view.hpp"
#include <memory>
#include <wayfire/plugin.hpp>
#include <wayfire/opengl.hpp>
#include <wayfire/view-transform.hpp>
#include <wayfire/output.hpp>


wf::option_wrapper_t<wf::animation_description_t> zap_duration{"animate/zap_duration"};

namespace wf
{
namespace zap
Expand All @@ -44,22 +40,21 @@ class zap_animation_t : public duration_t
public:
using duration_t::duration_t;
};
class zap_animation : public animation_base
class zap_animation : public animate::animation_base
{
wayfire_view view;
wf_animation_type type;
animate::animation_type type;
wf::zap::zap_animation_t progression;

public:

void init(wayfire_view view, wf::animation_description_t dur, wf_animation_type type) override
void init(wayfire_view view, wf::animation_description_t dur, animate::animation_type type) override
{
this->view = view;
this->type = type;
this->progression =
wf::zap::zap_animation_t(wf::create_option<wf::animation_description_t>(zap_duration));
this->progression = wf::zap::zap_animation_t(wf::create_option<wf::animation_description_t>(dur));

if (type & HIDING_ANIMATION)
if (type & WF_ANIMATE_HIDING_ANIMATION)
{
this->progression.reverse();
}
Expand Down Expand Up @@ -91,11 +86,6 @@ class zap_animation : public animation_base
this->progression.reverse();
}

int get_direction() override
{
return this->progression.get_direction();
}

~zap_animation()
{
view->get_transformed_node()->rem_transformer(zap_transformer_name);
Expand Down

0 comments on commit dad310e

Please sign in to comment.