Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cube: make cube ipc-activatable #1952

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion metadata/cube.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<group>
<_short>Bindings</_short>
<_long>Sets the cube bindings.</_long>
<option name="activate" type="button">
<option name="activate" type="activator">
<_short>Activate</_short>
<_long>Activates the cube with the specified button.</_long>
<default>&lt;ctrl&gt; &lt;alt&gt; BTN_LEFT</default>
Expand Down
68 changes: 39 additions & 29 deletions plugins/cube/cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <wayfire/workspace-set.hpp>
#include <wayfire/scene-operations.hpp>
#include <wayfire/plugins/common/input-grab.hpp>
#include "plugins/ipc/ipc-activator.hpp"

#include <glm/gtc/matrix_transform.hpp>
#include <wayfire/img.hpp>
Expand Down Expand Up @@ -178,9 +179,6 @@ class wayfire_cube : public wf::per_output_plugin_instance_t, public wf::pointer
std::unique_ptr<wf::input_grab_t> input_grab;
std::shared_ptr<cube_render_node_t> render_node;

wf::button_callback activate_binding;
wf::activator_callback rotate_left, rotate_right;

wf::option_wrapper_t<double> XVelocity{"cube/speed_spin_horiz"},
YVelocity{"cube/speed_spin_vert"}, ZVelocity{"cube/speed_zoom"};
wf::option_wrapper_t<double> zoom_opt{"cube/zoom"};
Expand All @@ -195,10 +193,6 @@ class wayfire_cube : public wf::per_output_plugin_instance_t, public wf::pointer
wf::option_wrapper_t<bool> use_light{"cube/light"};
wf::option_wrapper_t<int> use_deform{"cube/deform"};

wf::option_wrapper_t<wf::buttonbinding_t> button{"cube/activate"};
wf::option_wrapper_t<wf::activatorbinding_t> key_left{"cube/rotate_left"};
wf::option_wrapper_t<wf::activatorbinding_t> key_right{"cube/rotate_right"};

std::string last_background_mode;
std::unique_ptr<wf_cube_background_base> background;

Expand Down Expand Up @@ -259,24 +253,6 @@ class wayfire_cube : public wf::per_output_plugin_instance_t, public wf::pointer

reload_background();

activate_binding = [=] (auto)
{
return input_grabbed();
};

rotate_left = [=] (auto)
{
return move_vp(-1);
};

rotate_right = [=] (auto)
{
return move_vp(1);
};

output->add_button(button, &activate_binding);
output->add_activator(key_left, &rotate_left);
output->add_activator(key_right, &rotate_right);
output->connect(&on_cube_control);

OpenGL::render_begin();
Expand Down Expand Up @@ -778,11 +754,45 @@ class wayfire_cube : public wf::per_output_plugin_instance_t, public wf::pointer
OpenGL::render_begin();
program.free_resources();
OpenGL::render_end();
}
};


class wayfire_cube_global : public wf::plugin_interface_t,
public wf::per_output_tracker_mixin_t<wayfire_cube>
{
wf::ipc_activator_t rotate_left{"cube/rotate_left"};
wf::ipc_activator_t rotate_right{"cube/rotate_right"};
wf::ipc_activator_t activate{"cube/activate"};

output->rem_binding(&activate_binding);
output->rem_binding(&rotate_left);
output->rem_binding(&rotate_right);
public:
void init() override
{
this->init_output_tracking();
rotate_left.set_handler(rotate_left_cb);
rotate_right.set_handler(rotate_right_cb);
activate.set_handler(activate_cb);
}

void fini() override
{
this->fini_output_tracking();
}

wf::ipc_activator_t::handler_t rotate_left_cb = [=] (wf::output_t *output, wayfire_view)
{
return this->output_instance[output]->move_vp(-1);
};

wf::ipc_activator_t::handler_t rotate_right_cb = [=] (wf::output_t *output, wayfire_view)
{
return this->output_instance[output]->move_vp(+1);
};

wf::ipc_activator_t::handler_t activate_cb = [=] (wf::output_t *output, wayfire_view)
{
return this->output_instance[output]->input_grabbed();
};
};

DECLARE_WAYFIRE_PLUGIN(wf::per_output_plugin_t<wayfire_cube>);
DECLARE_WAYFIRE_PLUGIN(wayfire_cube_global);
4 changes: 2 additions & 2 deletions plugins/cube/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
animiate = shared_module('cube',
['cube.cpp', 'cubemap.cpp', 'skydome.cpp', 'simple-background.cpp'],
include_directories: [wayfire_api_inc, wayfire_conf_inc, plugins_common_inc],
dependencies: [wlroots, pixman, wfconfig],
include_directories: [wayfire_api_inc, wayfire_conf_inc, plugins_common_inc, ipc_include_dirs],
dependencies: [wlroots, pixman, wfconfig, json],
install: true,
install_dir: join_paths(get_option('libdir'), 'wayfire'))
Loading