<commit_before>// Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
// the Lawrence Livermore National Laboratory. LLNL-CODE-443271. All Rights
// reserved. See file COPYRIGHT for details.
//
// This file is part of the GLVis visualization tool and library. For more
// information and source code availability see http://glvis.org.
//
// GLVis is free software; you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License (as published by the Free
// Software Foundation) version 2.1 dated February 1999.

#ifndef GLVIS_SDL_X11_HPP
#define GLVIS_SDL_X11_HPP

#ifdef SDL_VIDEO_DRIVER_X11
#include "sdl_helper.hpp"
#include "gl/platform_gl.hpp"
#include "threads.hpp"
#include <poll.h>
#ifdef SDL_VIDEO_DRIVER_X11_XINPUT2
#include <X11/extensions/XInput2.h>
#endif // SDL_VIDEO_DRIVER_X11_XINPUT2

extern int visualize;

class SdlX11Platform final : public SdlNativePlatform
{
public:
   SdlX11Platform(Display* xdisplay, Window xwindow)
      : disp(xdisplay), wnd(xwindow)
   {
      // Disable XInput extension events since they are generated even outside
      // the GLVis window.
      Window root_win = DefaultRootWindow(disp);
      unsigned char mask[4] = {0,0,0,0};
      XIEventMask event_mask;
      event_mask.deviceid = XIAllMasterDevices;
      event_mask.mask_len = sizeof(mask);
      event_mask.mask = mask;
#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2
      typedef int (*XISelectEvents_ptr)(Display *, Window, XIEventMask *, int);
      static XISelectEvents_ptr XISelectEvents_ = NULL;
      if (XISelectEvents_ == NULL)
      {
         void *lib = SDL_LoadObject(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2);
         if (lib != NULL)
         {
            XISelectEvents_ =
               (XISelectEvents_ptr)SDL_LoadFunction(lib, "XISelectEvents");
         }
      }
      if (XISelectEvents_ == NULL)
      {
         cerr << "Error accessing XISelectEvents!" << endl;
         exit(EXIT_FAILURE);
      }
#else
#define XISelectEvents_ XISelectEvents
#endif
      if (XISelectEvents_(disp, root_win, &event_mask, 1) != Success)
      {
         cerr << "Failed to disable XInput on the default root window!" << endl;
      }
      if (XISelectEvents_(disp, wnd, &event_mask, 1) != Success)
      {
         cerr << "Failed to disable XInput on the current window!" << endl;
      }
   }
   void WaitEvent()
   {
      int nstr, nfd = 1;
      struct pollfd pfd[2];

      pfd[0].fd     = ConnectionNumber(disp);
      pfd[0].events = POLLIN;
      pfd[0].revents = 0;<commit_msg>Fix for a non-dynamic X11 build of SDL2, e.g. for Ubuntu.<commit_after>// Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
// the Lawrence Livermore National Laboratory. LLNL-CODE-443271. All Rights
// reserved. See file COPYRIGHT for details.
//
// This file is part of the GLVis visualization tool and library. For more
// information and source code availability see http://glvis.org.
//
// GLVis is free software; you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License (as published by the Free
// Software Foundation) version 2.1 dated February 1999.

#ifndef GLVIS_SDL_X11_HPP
#define GLVIS_SDL_X11_HPP

#ifdef SDL_VIDEO_DRIVER_X11
#include "sdl_helper.hpp"
#include "gl/platform_gl.hpp"
#include "threads.hpp"
#include <poll.h>
#ifdef SDL_VIDEO_DRIVER_X11_XINPUT2
#include <X11/extensions/XInput2.h>
#endif // SDL_VIDEO_DRIVER_X11_XINPUT2

extern int visualize;

class SdlX11Platform final : public SdlNativePlatform
{
public:
   SdlX11Platform(Display* xdisplay, Window xwindow)
      : disp(xdisplay), wnd(xwindow)
   {
      // Disable XInput extension events since they are generated even outside
      // the GLVis window.
      Window root_win = DefaultRootWindow(disp);
      unsigned char mask[4] = {0,0,0,0};
      XIEventMask event_mask;
      event_mask.deviceid = XIAllMasterDevices;
      event_mask.mask_len = sizeof(mask);
      event_mask.mask = mask;
#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2
      const char Xi_lib[] = SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2;
#else
      const char Xi_lib[] = "libXi.so";
#endif
      typedef int (*XISelectEvents_ptr)(Display *, Window, XIEventMask *, int);
      XISelectEvents_ptr XISelectEvents_ = NULL;
      void *lib = SDL_LoadObject(Xi_lib);
      if (lib != NULL)
      {
         XISelectEvents_ =
            (XISelectEvents_ptr)SDL_LoadFunction(lib, "XISelectEvents");
      }
      if (XISelectEvents_ == NULL)
      {
         cerr << "Error accessing XISelectEvents!" << endl;
         exit(EXIT_FAILURE);
      }
      if (XISelectEvents_(disp, root_win, &event_mask, 1) != Success)
      {
         cerr << "Failed to disable XInput on the default root window!" << endl;
      }
      if (XISelectEvents_(disp, wnd, &event_mask, 1) != Success)
      {
         cerr << "Failed to disable XInput on the current window!" << endl;
      }
#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2
      SDL_UnloadObject(lib);
#endif
   }
   void WaitEvent()
   {
      int nstr, nfd = 1;
      struct pollfd pfd[2];

      pfd[0].fd     = ConnectionNumber(disp);
      pfd[0].events = POLLIN;
      pfd[0].revents = 0;
{'fraction_non_alphanumeric': 0.09781357882623705, 'fraction_numerical': 0.02186421173762946, 'mean_word_length': 3.1586921850079746, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 7, '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': '1724954', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1682, 'n_words': 468}