<commit_before>#include "x_client_thumbnail_gl.hpp"

#include <cmath>
#include <xcb/composite.h>
#include "x_connection.hpp"

x_client_thumbnail::x_client_thumbnail(x_connection & c,
                                       x::xrm & xrm,
                                       const x::gl::config & config,
                                       const rectangle & rect,
                                       const xcb_window_t & window)
  : m_c(c), m_xrm(xrm), m_gl_api(config.api())
  , m_gl_ctx(config)
  , m_x_client(m_c, window)
  , m_x_client_icon(m_c, m_x_client)
  , m_x_client_name(m_c, m_xrm, m_x_client, config.visual_info(), config.colormap())
{
  load_config();
  update(rect);

  m_c.attach(0, m_c.damage_event_id(), this);

  m_xrm.attach(this);
  m_x_client.attach(this);
  m_x_client_name.attach(this);

  m_damage = xcb_generate_id(m_c());

  m_thumbnail_window = xcb_generate_id(m_c());

  uint32_t valuemask = XCB_CW_BACK_PIXEL
                     | XCB_CW_BORDER_PIXEL
                     | XCB_CW_OVERRIDE_REDIRECT
                     | XCB_CW_COLORMAP
                     ;

  uint32_t valuelist[] = { 0, 0, 1, (uint32_t)config.colormap() };

  xcb_create_window(m_c(),
                    config.visual_info()->depth,
                    m_thumbnail_window,
                    m_c.root_window(), 0, 0,
                    m_x_client.rect().width(), m_x_client.rect().height(),
                    0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
                    config.visual_info()->visualid,
                    valuemask, valuelist);

  m_x_client_name.make_title();

  m_gl_ctx.drawable(m_thumbnail_window);

  m_gl_ctx.run([this](x::gl::context &)
  {
    m_gl_ctx.load("focused",
                  m_shader_path + "/shader/position.vert",
                  m_shader_path + "/shader/focused.frag");

    m_gl_ctx.load("unfocused",
                  m_shader_path + "/shader/position.vert",
                  m_shader_path + "/shader/unfocused.frag");

    m_gl_ctx.load(0, m_x_client.name_window_pixmap(), GLX_TEXTURE_FORMAT_RGB_EXT);
    m_gl_ctx.load(1, m_x_client_name.title(), GLX_TEXTURE_FORMAT_RGBA_EXT);
    m_gl_ctx.load(2, m_x_client_icon.icon(), GLX_TEXTURE_FORMAT_RGBA_EXT);

    for (auto & t : { 0, 1, 2 }) {
      m_gl_ctx.active_texture(t);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
    }

    glEnable(GL_SCISSOR_TEST);
    update(0, 0, m_rectangle.width(), m_rectangle.height());
  });
}

x_client_thumbnail::~x_client_thumbnail(void)
{
  m_c.detach(m_c.damage_event_id(), this);
  m_xrm.detach(this);
  m_x_client.detach(this);
  m_x_client_name.detach(this);
  xcb_damage_destroy(m_c(), m_damage);
  xcb_destroy_window(m_c(), m_thumbnail_window);
}
<commit_msg>Use context parameter instead of captured this<commit_after>#include "x_client_thumbnail_gl.hpp"

#include <cmath>
#include <xcb/composite.h>
#include "x_connection.hpp"

x_client_thumbnail::x_client_thumbnail(x_connection & c,
                                       x::xrm & xrm,
                                       const x::gl::config & config,
                                       const rectangle & rect,
                                       const xcb_window_t & window)
  : m_c(c), m_xrm(xrm), m_gl_api(config.api())
  , m_gl_ctx(config)
  , m_x_client(m_c, window)
  , m_x_client_icon(m_c, m_x_client)
  , m_x_client_name(m_c, m_xrm, m_x_client, config.visual_info(), config.colormap())
{
  load_config();
  update(rect);

  m_c.attach(0, m_c.damage_event_id(), this);

  m_xrm.attach(this);
  m_x_client.attach(this);
  m_x_client_name.attach(this);

  m_damage = xcb_generate_id(m_c());

  m_thumbnail_window = xcb_generate_id(m_c());

  uint32_t valuemask = XCB_CW_BACK_PIXEL
                     | XCB_CW_BORDER_PIXEL
                     | XCB_CW_OVERRIDE_REDIRECT
                     | XCB_CW_COLORMAP
                     ;

  uint32_t valuelist[] = { 0, 0, 1, (uint32_t)config.colormap() };

  xcb_create_window(m_c(),
                    config.visual_info()->depth,
                    m_thumbnail_window,
                    m_c.root_window(), 0, 0,
                    m_x_client.rect().width(), m_x_client.rect().height(),
                    0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
                    config.visual_info()->visualid,
                    valuemask, valuelist);

  m_x_client_name.make_title();

  m_gl_ctx.drawable(m_thumbnail_window);
    // load("my_shader", read("/path/to/my_shader_src.txt"));

  m_gl_ctx.run([&](x::gl::context & ctx)
  {
    ctx.load("focused",
                  m_shader_path + "/shader/position.vert",
                  m_shader_path + "/shader/focused.frag");

    ctx.load("unfocused",
                  m_shader_path + "/shader/position.vert",
                  m_shader_path + "/shader/unfocused.frag");

    ctx.load(0, m_x_client.name_window_pixmap(), GLX_TEXTURE_FORMAT_RGB_EXT);
    ctx.load(1, m_x_client_name.title(), GLX_TEXTURE_FORMAT_RGBA_EXT);
    ctx.load(2, m_x_client_icon.icon(), GLX_TEXTURE_FORMAT_RGBA_EXT);

    for (auto & t : { 0, 1, 2 }) {
      ctx.active_texture(t);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
    }

    glEnable(GL_SCISSOR_TEST);
    update(0, 0, m_rectangle.width(), m_rectangle.height());
  });
}

x_client_thumbnail::~x_client_thumbnail(void)
{
  m_c.detach(m_c.damage_event_id(), this);
  m_xrm.detach(this);
  m_x_client.detach(this);
  m_x_client_name.detach(this);
  xcb_damage_destroy(m_c(), m_damage);
  xcb_destroy_window(m_c(), m_thumbnail_window);
}

{'fraction_non_alphanumeric': 0.12115641711229946, 'fraction_numerical': 0.008355614973262033, 'mean_word_length': 2.665033680342927, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1757791', 'n_tokens_mistral': 2355, 'n_tokens_neox': 2234, 'n_words': 263}