<commit_before>/* Rapicorn
 * Copyright (C) 2005-2006 <NAME>
 *
 * This library 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; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * A copy of the GNU Lesser General Public License should ship along
 * with this library; if not, see http://www.gnu.org/copyleft/.
 */
#include "viewport.hh"
#include <rcore/rapicornthread.hh>
#include <ui/utilities.hh>

#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>

#include <cstring>

#define DEBUG_EVENTS    0

namespace { // Anon
using namespace Rapicorn;

/* --- prototypes --- */
class ViewportGtk;
static gboolean     rapicorn_viewport_ancestor_event (GtkWidget  *ancestor,
                                                      GdkEvent   *event,
                                                      GtkWidget  *widget);
static bool         gdk_window_has_ancestor          (GdkWindow  *window,
                                                      GdkWindow  *ancestor);
static bool         gtk_widget_has_local_display     (GtkWidget  *widget);
typedef enum {
  BACKING_STORE_NOT_USEFUL,
  BACKING_STORE_WHEN_MAPPED,
  BACKING_STORE_ALWAYS
} BackingStore;
static BackingStore gdk_window_enable_backing        (GdkWindow  *window,
                                                      BackingStore bs_type);

/* --- GDK_THREADS_* / Mutex glue --- */
struct RapicronGdkSyncLock {
  void
  lock()
  {
    GDK_THREADS_ENTER();
    /* protect execution of any Gtk/Gdk functions */
  }
  void
  unlock()
  {
    /* X commands enqueued by any Gtk/Gdk functions so far
     * may still be queued and need to be flushed. also, any
     * X events that may have arrived already need to be
     * handled by the gtk_main() loop. waking up the default
     * main context will do exactly this, wake up gtk_main(),
     * and call XPending() which flushes any queued events.
     */
    g_main_context_wakeup (NULL);
    /* unprotect Gtk/Gdk */
    GDK_THREADS_LEAVE();
  }
};
static RapicronGdkSyncLock GTK_GDK_THREAD_SYNC;

/* --- RapicornViewport --- */<commit_msg>UI: reduce contention possibilities by wakeing Gtk+ up after global lock release<commit_after>/* Rapicorn
 * Copyright (C) 2005-2006 <NAME>
 *
 * This library 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; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * A copy of the GNU Lesser General Public License should ship along
 * with this library; if not, see http://www.gnu.org/copyleft/.
 */
#include "viewport.hh"
#include <rcore/rapicornthread.hh>
#include <ui/utilities.hh>

#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>

#include <cstring>

#define DEBUG_EVENTS    0

namespace { // Anon
using namespace Rapicorn;

/* --- prototypes --- */
class ViewportGtk;
static gboolean     rapicorn_viewport_ancestor_event (GtkWidget  *ancestor,
                                                      GdkEvent   *event,
                                                      GtkWidget  *widget);
static bool         gdk_window_has_ancestor          (GdkWindow  *window,
                                                      GdkWindow  *ancestor);
static bool         gtk_widget_has_local_display     (GtkWidget  *widget);
typedef enum {
  BACKING_STORE_NOT_USEFUL,
  BACKING_STORE_WHEN_MAPPED,
  BACKING_STORE_ALWAYS
} BackingStore;
static BackingStore gdk_window_enable_backing        (GdkWindow  *window,
                                                      BackingStore bs_type);

/* --- GDK_THREADS_* / Mutex glue --- */
struct RapicronGdkSyncLock {
  void
  lock()
  {
    GDK_THREADS_ENTER();
    /* protect execution of any Gtk/Gdk functions */
  }
  void
  unlock()
  {
    /* unprotect Gtk/Gdk */
    GDK_THREADS_LEAVE();
    /* X commands enqueued by any Gtk/Gdk functions so far
     * may still be queued and need to be flushed. also, any
     * X events that may have arrived already need to be
     * handled by the gtk_main() loop. waking up the default
     * main context will do exactly this, wake up gtk_main(),
     * and call XPending() which flushes any queued events.
     */
    g_main_context_wakeup (NULL);
  }
};
static RapicronGdkSyncLock GTK_GDK_THREAD_SYNC;

/* --- RapicornViewport --- */
{'fraction_non_alphanumeric': 0.07988815658078689, 'fraction_numerical': 0.00439384861194328, 'mean_word_length': 2.4254445964432283, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2313372', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1443, 'n_words': 503}