<commit_before>/*
   (c) Copyright 2000  convergence integrated media GmbH.
   All rights reserved.

   Written by <NAME> <<EMAIL>> and
              <NAME> <<EMAIL>>.

   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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <pthread.h>
#include <errno.h>

#include "directfb.h"

#include "core.h"
#include "coredefs.h"
#include "coretypes.h"

#include "input.h"
#include "gfxcard.h"
#include "layers.h"
#include "reactor.h"
#include "state.h"
#include "windows.h"

#include "gfx/util.h"
#include "misc/util.h"


#define CURSORFILE     DATADIR"/cursor.dat"

static int layer_id_pool = 0;

DisplayLayer *layers = NULL;

DFBResult layer_create_cursor_window( DisplayLayer *layer,
                                      int width, int height );
DFBResult layer_cursor_load_default( DisplayLayer *layer );

/*
 * added to the cleanup stack
 */
void layers_remove_all()
{
     while (layers) {
          DisplayLayer *l = layers;

          if (l->deinit)
               l->deinit( l );

          layers = l->next;
          free( l );
     }
}

void layers_add( DisplayLayer *layer )
{
     layer->id = layer_id_pool++;

     /* init mutex */
     pthread_mutex_init( &layer->lock, NULL );

     /* add it to the list, if the list was empty add the cleanup function */
     if (layers) {
          DisplayLayer *last = layers;

          while (last->next)
               last = last->next;

          last->next = layer;
     }
     else {
          layers = layer;
          core_cleanup_push( layers_remove_all );
     }
}

DFBResult layers_suspend()
{
     DisplayLayer *l = layers;
     
     DEBUGMSG( "DirectFB/core/layers: suspending...\n" );
     
     while (l) {
          l->Disable( l );

          l = l->next;
     }

     DEBUGMSG( "DirectFB/core/layers: ...suspended\n" );
     
     return DFB_OK;
}

DFBResult layers_resume()
{
     DisplayLayer *l = layers;
     
     DEBUGMSG( "DirectFB/core/layers: resuming...\n" );
     
     while (l) {
          /* bad check if layer was enabled before */
          if (l->surface) {
               l->Enable( l );

               if (l->windowstack)
                    windowstack_repaint_all( l->windowstack );
          }

          l = l->next;
     }

     DEBUGMSG( "DirectFB/core/layers: ...resumed\n" );
     
     return DFB_OK;
}

DFBResult layer_lock( DisplayLayer *layer )
{
     if (pthread_mutex_trylock( &layer->lock ))
          return DFB_LOCKED;

     layer->exclusive = 1;

     return DFB_OK;
}

DFBResult layer_unlock( DisplayLayer *layer )
{
     pthread_mutex_unlock( &layer->lock );

     layer->exclusive = 0;
     
     windowstack_repaint_all( layer->windowstack );

     return DFB_OK;
}

DFBResult layer_cursor_enable( DisplayLayer *layer, int enable )
{
     DFBResult ret = DFB_OK;

     if (enable) {
          if (!layer->windowstack->cursor_window)        /* no cursor yet?      */
               ret = layer_cursor_load_default( layer ); /* install the default */

          if (ret == DFB_OK)
               ret = window_set_opacity( layer->windowstack->cursor_window, 
                                         layer->windowstack->cursor_opacity );
          if (ret == DFB_OK)
               layer->windowstack->cursor = 1;
     }
     else {
          ret = window_set_opacity( layer->windowstack->cursor_window, 0 );

          if (ret == DFB_OK)
               layer->windowstack->cursor = 0;          
     }
     return ret;
}

DFBResult layer_cursor_set_opacity( DisplayLayer *layer, __u8 opacity )
{
     DFBResult ret = DFB_OK;

     if (layer->windowstack->cursor) {
          if (!layer->windowstack->cursor_window)        /* no cursor yet?      */
               ret = layer_cursor_load_default( layer ); /* install the default */<commit_msg>don't try to set opacity on unexistant cursor_window<commit_after>/*
   (c) Copyright 2000  convergence integrated media GmbH.
   All rights reserved.

   Written by <NAME> <<EMAIL>> and
              <NAME> <<EMAIL>>.

   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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <pthread.h>
#include <errno.h>

#include "directfb.h"

#include "core.h"
#include "coredefs.h"
#include "coretypes.h"

#include "input.h"
#include "gfxcard.h"
#include "layers.h"
#include "reactor.h"
#include "state.h"
#include "windows.h"

#include "gfx/util.h"
#include "misc/util.h"


#define CURSORFILE     DATADIR"/cursor.dat"

static int layer_id_pool = 0;

DisplayLayer *layers = NULL;

DFBResult layer_create_cursor_window( DisplayLayer *layer,
                                      int width, int height );
DFBResult layer_cursor_load_default( DisplayLayer *layer );

/*
 * added to the cleanup stack
 */
void layers_remove_all()
{
     while (layers) {
          DisplayLayer *l = layers;

          if (l->deinit)
               l->deinit( l );

          layers = l->next;
          free( l );
     }
}

void layers_add( DisplayLayer *layer )
{
     layer->id = layer_id_pool++;

     /* init mutex */
     pthread_mutex_init( &layer->lock, NULL );

     /* add it to the list, if the list was empty add the cleanup function */
     if (layers) {
          DisplayLayer *last = layers;

          while (last->next)
               last = last->next;

          last->next = layer;
     }
     else {
          layers = layer;
          core_cleanup_push( layers_remove_all );
     }
}

DFBResult layers_suspend()
{
     DisplayLayer *l = layers;
     
     DEBUGMSG( "DirectFB/core/layers: suspending...\n" );
     
     while (l) {
          l->Disable( l );

          l = l->next;
     }

     DEBUGMSG( "DirectFB/core/layers: ...suspended\n" );
     
     return DFB_OK;
}

DFBResult layers_resume()
{
     DisplayLayer *l = layers;
     
     DEBUGMSG( "DirectFB/core/layers: resuming...\n" );
     
     while (l) {
          /* bad check if layer was enabled before */
          if (l->surface) {
               l->Enable( l );

               if (l->windowstack)
                    windowstack_repaint_all( l->windowstack );
          }

          l = l->next;
     }

     DEBUGMSG( "DirectFB/core/layers: ...resumed\n" );
     
     return DFB_OK;
}

DFBResult layer_lock( DisplayLayer *layer )
{
     if (pthread_mutex_trylock( &layer->lock ))
          return DFB_LOCKED;

     layer->exclusive = 1;

     return DFB_OK;
}

DFBResult layer_unlock( DisplayLayer *layer )
{
     pthread_mutex_unlock( &layer->lock );

     layer->exclusive = 0;
     
     windowstack_repaint_all( layer->windowstack );

     return DFB_OK;
}

DFBResult layer_cursor_enable( DisplayLayer *layer, int enable )
{
     DFBResult ret = DFB_OK;

     if (enable) {
          if (!layer->windowstack->cursor_window)        /* no cursor yet?      */
               ret = layer_cursor_load_default( layer ); /* install the default */

          if (ret == DFB_OK)
               ret = window_set_opacity( layer->windowstack->cursor_window, 
                                         layer->windowstack->cursor_opacity );
          if (ret == DFB_OK)
               layer->windowstack->cursor = 1;
     }
     else {
          if (layer->windowstack->cursor_window)
               ret = window_set_opacity( layer->windowstack->cursor_window, 0 );

          if (ret == DFB_OK)
               layer->windowstack->cursor = 0;          
     }
     return ret;
}

DFBResult layer_cursor_set_opacity( DisplayLayer *layer, __u8 opacity )
{
     DFBResult ret = DFB_OK;

     if (layer->windowstack->cursor) {
          if (!layer->windowstack->cursor_window)        /* no cursor yet?      */
               ret = layer_cursor_load_default( layer ); /* install the default */
{'fraction_non_alphanumeric': 0.10724892751072489, 'fraction_numerical': 0.0057199428005719945, 'mean_word_length': 2.1471097265489787, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 99, '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': '3466938', 'n_tokens_mistral': 2823, 'n_tokens_neox': 2717, 'n_words': 799}