<commit_before>#include <plugin.hpp>
#include <output.hpp>
#include <opengl.hpp>
#include <debug.hpp>
#include <render-manager.hpp>

static const char* vertex_shader =
R"(
#version 100

attribute mediump vec2 position;
attribute highp vec2 uvPosition;

varying highp vec2 uvpos;

void main() {

    gl_Position = vec4(position.xy, 0.0, 1.0);
    uvpos = uvPosition;
}
)";

static const char* fragment_shader =
R"(
#version 100

varying highp vec2 uvpos;
uniform sampler2D smp;

void main()
{
    mediump vec4 tex_color = texture2D(smp, uvpos);
    gl_FragColor = vec4(1.0 - tex_color.r, 1.0 - tex_color.g, 1.0 - tex_color.b, 1.0f);
}
)";

class wayfire_invert_screen : public wayfire_plugin_t
{

    post_hook_t hook;
    effect_hook_t wait_for_render;

    GLuint program, posID, uvID;

    public:
        void init(wayfire_config *config)
        {
            hook = [=] (uint32_t fb, uint32_t tex, uint32_t target)
            {
                render(fb, tex, target);
            };

            wait_for_render = [=] () {
                output->render->add_post(&hook);
                output->render->rem_effect(&wait_for_render, WF_OUTPUT_EFFECT_POST);

                auto vs = OpenGL::compile_shader(vertex_shader, GL_VERTEX_SHADER);
                auto fs = OpenGL::compile_shader(fragment_shader, GL_FRAGMENT_SHADER);

                program = GL_CALL(glCreateProgram());
                GL_CALL(glAttachShader(program, vs));
                GL_CALL(glAttachShader(program, fs));
                GL_CALL(glLinkProgram(program));

                posID = GL_CALL(glGetAttribLocation(program, "position"));
                uvID  = GL_CALL(glGetAttribLocation(program, "uvPosition"));
            };

            output->render->add_effect(&wait_for_render, WF_OUTPUT_EFFECT_POST);
        }

        void render(uint32_t fb, uint32_t tex, uint32_t target)
        {
            log_info("invert gets %u %u", fb, target);
            GL_CALL(glUseProgram(program));
            GL_CALL(glBindTexture(GL_TEXTURE_2D, tex));<commit_msg>invert: implement a toggle option<commit_after>#include <plugin.hpp>
#include <output.hpp>
#include <opengl.hpp>
#include <debug.hpp>
#include <render-manager.hpp>

static const char* vertex_shader =
R"(
#version 100

attribute mediump vec2 position;
attribute highp vec2 uvPosition;

varying highp vec2 uvpos;

void main() {

    gl_Position = vec4(position.xy, 0.0, 1.0);
    uvpos = uvPosition;
}
)";

static const char* fragment_shader =
R"(
#version 100

varying highp vec2 uvpos;
uniform sampler2D smp;

void main()
{
    mediump vec4 tex_color = texture2D(smp, uvpos);
    gl_FragColor = vec4(1.0 - tex_color.r, 1.0 - tex_color.g, 1.0 - tex_color.b, 1.0f);
}
)";

class wayfire_invert_screen : public wayfire_plugin_t
{

    post_hook_t hook;
    key_callback toggle_cb;

    bool active = false;
    GLuint program, posID, uvID;

    public:
        void init(wayfire_config *config)
        {
            auto section = config->get_section("invert");
            auto toggle_key = section->get_option("toggle", "<super> KEY_I");

            if (!toggle_key->as_key().valid())
                return;

            hook = [=] (uint32_t fb, uint32_t tex, uint32_t target)
            {
                render(fb, tex, target);
            };


            toggle_cb = [=] (uint32_t key) {
                if (active)
                {
                    output->render->rem_post(&hook);
                } else
                {
                    output->render->add_post(&hook);
                }

                active = !active;
            };

            auto vs = OpenGL::compile_shader(vertex_shader, GL_VERTEX_SHADER);
            auto fs = OpenGL::compile_shader(fragment_shader, GL_FRAGMENT_SHADER);

            program = GL_CALL(glCreateProgram());
            GL_CALL(glAttachShader(program, vs));
            GL_CALL(glAttachShader(program, fs));
            GL_CALL(glLinkProgram(program));

            posID = GL_CALL(glGetAttribLocation(program, "position"));
            uvID  = GL_CALL(glGetAttribLocation(program, "uvPosition"));

            output->add_key(toggle_key, &toggle_cb);
        }

        void render(uint32_t fb, uint32_t tex, uint32_t target)
        {
            log_info("invert gets %u %u", fb, target);
            GL_CALL(glUseProgram(program));
            GL_CALL(glBindTexture(GL_TEXTURE_2D, tex));
{'fraction_non_alphanumeric': 0.11381190368014539, 'fraction_numerical': 0.0186278964107224, 'mean_word_length': 2.3791250959324635, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2743066', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1428, 'n_words': 293}