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

a few fixes #2153

Merged
merged 2 commits into from
Feb 21, 2024
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
7 changes: 3 additions & 4 deletions plugins/single_plugins/vswipe-processing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
static inline double vswipe_process_delta(const double delta,
const double accumulated_dx,
const int vx, const int vw,
const double speed_cap = 0.5,
const double speed_factor = 256,
const bool free_movement = false)
const double speed_cap = 0.5,
const bool free_movement = false)
{
// The slowdown below must be applied differently for going out of bounds.
double sdx_offset = free_movement ?
Expand All @@ -31,7 +30,7 @@ static inline double vswipe_process_delta(const double delta,
const double slowdown = wf::clamp(ease,
std::signbit(delta) == std::signbit(sdx_offset) ? 0.005 : 0.2, 1.0);

return wf::clamp(delta / speed_factor, -speed_cap, speed_cap) * slowdown;
return wf::clamp(delta, -speed_cap, speed_cap) * slowdown;
}

static inline int vswipe_finish_target(const double accumulated_dx,
Expand Down
10 changes: 4 additions & 6 deletions plugins/single_plugins/vswipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <wayfire/util/duration.hpp>

#include <cmath>
#include <utility>

#include <wayfire/plugins/common/workspace-wall.hpp>
#include <wayfire/plugins/common/geometry-animation.hpp>
Expand Down Expand Up @@ -268,8 +267,8 @@ class vswipe : public wf::per_output_plugin_instance_t
state.delta_sum.y += ev->event->dy / speed_factor;
if (state.direction == UNKNOWN)
{
state.initial_deltas.x += std::abs(ev->event->dx) / speed_factor;
state.initial_deltas.y += std::abs(ev->event->dy) / speed_factor;
state.initial_deltas.x += std::abs(ev->event->dx / speed_factor);
state.initial_deltas.y += std::abs(ev->event->dy / speed_factor);
state.direction = calculate_direction(state.initial_deltas);
if (state.direction == UNKNOWN)
{
Expand All @@ -288,16 +287,15 @@ class vswipe : public wf::per_output_plugin_instance_t
}

const double cap = speed_cap;
const double fac = speed_factor;

state.delta_prev = state.delta_last;
double current_delta_processed;

const auto& process_delta =
[&] (double delta, wf::timed_transition_t& total_delta, int ws, int ws_max)
{
current_delta_processed = vswipe_process_delta(delta, total_delta,
ws, ws_max, cap, fac, enable_free_movement);
current_delta_processed = vswipe_process_delta(delta / speed_factor, total_delta,
ws, ws_max, cap, enable_free_movement);

double new_delta_end = total_delta.end + current_delta_processed;
double new_delta_start = smooth_transition ? total_delta : new_delta_end;
Expand Down
50 changes: 23 additions & 27 deletions plugins/wobbly/wobbly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,6 @@ void main()
)";
}

OpenGL::program_t program;
void load_program()
{
OpenGL::render_begin();
program.compile(vertex_source, frag_source);
OpenGL::render_end();
}

void destroy_program()
{
OpenGL::render_begin();
program.free_resources();
OpenGL::render_end();
}

/**
* Enumerate the needed triangles for rendering the model
*/
Expand Down Expand Up @@ -120,23 +105,23 @@ void prepare_geometry(wobbly_surface *model, wf::geometry_t src_box,
}

/* Requires bound opengl context */
void render_triangles(wf::texture_t tex, glm::mat4 mat, float *pos, float *uv,
void render_triangles(OpenGL::program_t *program, wf::texture_t tex, glm::mat4 mat, float *pos, float *uv,
int cnt)
{
program.use(tex.type);
program.set_active_texture(tex);
program->use(tex.type);
program->set_active_texture(tex);

program.attrib_pointer("position", 2, 0, pos);
program.attrib_pointer("uvPosition", 2, 0, uv);
program.uniformMatrix4f("MVP", mat);
program->attrib_pointer("position", 2, 0, pos);
program->attrib_pointer("uvPosition", 2, 0, uv);
program->uniformMatrix4f("MVP", mat);

GL_CALL(glEnable(GL_BLEND));
GL_CALL(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));

GL_CALL(glDrawArrays(GL_TRIANGLES, 0, 3 * cnt));
GL_CALL(glDisable(GL_BLEND));

program.deactivate();
program->deactivate();
}
}

Expand Down Expand Up @@ -548,9 +533,11 @@ class wobbly_state_free_t : public iwobbly_state_t
class wobbly_transformer_node_t : public wf::scene::floating_inner_node_t
{
public:
wobbly_transformer_node_t(wayfire_toplevel_view view) : floating_inner_node_t(false)
wobbly_transformer_node_t(wayfire_toplevel_view view,
OpenGL::program_t *wobbly_prog) : floating_inner_node_t(false)
{
this->view = view;
this->wobbly_program = wobbly_prog;
init_model();
last_frame = wf::get_current_time();
view->get_output()->connect(&on_workspace_changed);
Expand Down Expand Up @@ -600,6 +587,8 @@ class wobbly_transformer_node_t : public wf::scene::floating_inner_node_t
view->get_transformed_node()->rem_transformer("wobbly");
}

OpenGL::program_t *wobbly_program;

private:
wayfire_toplevel_view view;

Expand Down Expand Up @@ -896,7 +885,7 @@ class wobbly_render_instance_t :
for (auto& box : damage)
{
target_fb.logic_scissor(wlr_box_from_pixman_box(box));
wobbly_graphics::render_triangles(tex,
wobbly_graphics::render_triangles(self->wobbly_program, tex,
target_fb.get_orthographic_projection(),
vert.data(), uv.data(),
self->model->x_cells * self->model->y_cells * 2);
Expand Down Expand Up @@ -925,7 +914,9 @@ class wayfire_wobbly : public wf::plugin_interface_t
void init() override
{
wf::get_core().connect(&wobbly_changed);
wobbly_graphics::load_program();
OpenGL::render_begin();
program.compile(wobbly_graphics::vertex_source, wobbly_graphics::frag_source);
OpenGL::render_end();
}

void adjust_wobbly(wobbly_signal *data)
Expand All @@ -935,7 +926,7 @@ class wayfire_wobbly : public wf::plugin_interface_t
!tr_manager->get_transformer<wobbly_transformer_node_t>("wobbly"))
{
tr_manager->add_transformer(
std::make_shared<wobbly_transformer_node_t>(data->view),
std::make_shared<wobbly_transformer_node_t>(data->view, &program),
wf::TRANSFORMER_HIGHLEVEL, "wobbly");
}

Expand Down Expand Up @@ -998,8 +989,13 @@ class wayfire_wobbly : public wf::plugin_interface_t
}
}

wobbly_graphics::destroy_program();
OpenGL::render_begin();
program.free_resources();
OpenGL::render_end();
}

private:
OpenGL::program_t program;
};

DECLARE_WAYFIRE_PLUGIN(wayfire_wobbly);
Loading