<commit_before>/* gdkscreen-quartz.c
 *
 * Copyright (C) 2005 Imendio AB
 *
 * 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 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.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "config.h"
#include "gdk.h"
#include "gdkprivate-quartz.h"
 
/* FIXME: If we want to do it properly, this should be stored
 * in a proper GdkScreen subclass.
 */
static GdkColormap *default_colormap = NULL;
static int n_screens = 0;
static GdkRectangle *screen_rects = NULL;


static void
screen_rects_init (void)
{
  NSArray *array;
  NSRect largest_rect;
  int i;

  GDK_QUARTZ_ALLOC_POOL;

  array = [NSScreen screens];

  n_screens = [array count];
  screen_rects = g_new0 (GdkRectangle, n_screens);

  /* FIXME: as stated above the get_width() and get_height() functions
   * in this file, we only support horizontal screen layouts for now.
   */

  /* Find the monitor with the largest height.  All monitors should be
   * offset to this one in the GDK screen space instead of offset to
   * the screen with the menu bar.
   */
  largest_rect = [[array objectAtIndex:0] frame];
  for (i = 1; i < [array count]; i++)
    {
      NSRect rect = [[array objectAtIndex:i] frame];

      if (rect.size.height > largest_rect.size.height)
        largest_rect = [[array objectAtIndex:i] frame];
    }

  for (i = 0; i < n_screens; i++)
    {
      NSScreen *nsscreen;
      NSRect rect;

      nsscreen = [array objectAtIndex:i];
      rect = [nsscreen frame];

      screen_rects[i].x = rect.origin.x;
      screen_rects[i].width = rect.size.width;
      screen_rects[i].height = rect.size.height;

      if (largest_rect.size.height - rect.size.height == 0)
        screen_rects[i].y = 0;
      else
        screen_rects[i].y = largest_rect.size.height - rect.size.height + largest_rect.origin.y;
    }

  GDK_QUARTZ_RELEASE_POOL;
}

void
_gdk_quartz_screen_init (void)
{
  gdk_screen_set_default_colormap (_gdk_screen,
                                   gdk_screen_get_system_colormap (_gdk_screen));

  screen_rects_init ();
}

GdkDisplay *
gdk_screen_get_display (GdkScreen *screen)
{
  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);

  return _gdk_display;
}


GdkWindow *
gdk_screen_get_root_window (GdkScreen *screen)<commit_msg>Register and handle a display reconfiguration callback<commit_after>/* gdkscreen-quartz.c
 *
 * Copyright (C) 2005 Imendio AB
 *
 * 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 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.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "config.h"
#include "gdk.h"
#include "gdkprivate-quartz.h"
 
/* FIXME: If we want to do it properly, this should be stored
 * in a proper GdkScreen subclass.
 */
static GdkColormap *default_colormap = NULL;
static int n_screens = 0;
static GdkRectangle *screen_rects = NULL;

static guint screen_changed_id = 0;


static void
screen_rects_init (void)
{
  NSArray *array;
  NSRect largest_rect;
  int i;

  GDK_QUARTZ_ALLOC_POOL;

  array = [NSScreen screens];

  n_screens = [array count];
  screen_rects = g_new0 (GdkRectangle, n_screens);

  /* FIXME: as stated above the get_width() and get_height() functions
   * in this file, we only support horizontal screen layouts for now.
   */

  /* Find the monitor with the largest height.  All monitors should be
   * offset to this one in the GDK screen space instead of offset to
   * the screen with the menu bar.
   */
  largest_rect = [[array objectAtIndex:0] frame];
  for (i = 1; i < [array count]; i++)
    {
      NSRect rect = [[array objectAtIndex:i] frame];

      if (rect.size.height > largest_rect.size.height)
        largest_rect = [[array objectAtIndex:i] frame];
    }

  for (i = 0; i < n_screens; i++)
    {
      NSScreen *nsscreen;
      NSRect rect;

      nsscreen = [array objectAtIndex:i];
      rect = [nsscreen frame];

      screen_rects[i].x = rect.origin.x;
      screen_rects[i].width = rect.size.width;
      screen_rects[i].height = rect.size.height;

      if (largest_rect.size.height - rect.size.height == 0)
        screen_rects[i].y = 0;
      else
        screen_rects[i].y = largest_rect.size.height - rect.size.height + largest_rect.origin.y;
    }

  GDK_QUARTZ_RELEASE_POOL;
}

static void
screen_rects_free (void)
{
  n_screens = 0;

  g_free (screen_rects);
  screen_rects = NULL;
}


static void
process_display_reconfiguration (void)
{
  screen_rects_free ();
  screen_rects_init ();

  /* FIXME: We should only emit this when the size of screen really
   * has changed.  We need to start bookkeeping width, height once
   * we have a proper GdkScreen subclass.
   */
  g_signal_emit_by_name (_gdk_screen, "size-changed");
}

static gboolean
screen_changed_idle (gpointer data)
{
  process_display_reconfiguration ();

  screen_changed_id = 0;

  return FALSE;
}

static void
screen_changed (CGDirectDisplayID            display,
                CGDisplayChangeSummaryFlags  flags,
                void                        *userInfo)
{
  if (flags & kCGDisplayBeginConfigurationFlag)
    {
      /* Ignore the begin configuration signal. */

      /* FIXME: We can most probably use this flag to properly
       * emit monitors-changed.
       */
      return;
    }
  else
    {
      /* At this point Cocoa does not know about the new screen data
       * yet, so we delay our refresh into an idle handler.
       */

      if (!screen_changed_id)
        screen_changed_id = gdk_threads_add_idle (screen_changed_idle, NULL);
    }
}

void
_gdk_quartz_screen_init (void)
{
  gdk_screen_set_default_colormap (_gdk_screen,
                                   gdk_screen_get_system_colormap (_gdk_screen));

  screen_rects_init ();

  CGDisplayRegisterReconfigurationCallback (screen_changed,
                                            _gdk_screen);
}

GdkDisplay *
gdk_screen_get_display (GdkScreen *screen)
{
  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);

  return _gdk_display;
}


GdkWindow *
gdk_screen_get_root_window (GdkScreen *screen)
{'fraction_non_alphanumeric': 0.08623802249687543, 'fraction_numerical': 0.007637828079433412, 'mean_word_length': 3.1343283582089554, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2241895', 'n_tokens_mistral': 2368, 'n_tokens_neox': 2260, 'n_words': 744}