<commit_before>#include <errno.h>
#include <fcntl.h>
#include "events.h"
#include "errors.h"
#include "SDL.h"
#include "window.h"
#include "drawing.h"
#include "inputMethod.h"
#include "SDL_gpu.h"
#include "display.h"

int eventFds[2];
#define READ_EVENT_FD eventFds[0]
#define WRITE_EVENT_FD eventFds[1]
SDL_Event waitingEvent;
Bool eventWaiting = False;
Bool tmpVar = False;
Window keyboardFocus = NULL;

void updateWindowRenderTargets(Display* display);

#define ENQUEUE_EVENT_IN_PIPE(display) { char buffer = 'e'; write(WRITE_EVENT_FD, &buffer, sizeof(buffer)); (display)->qlen++; }
#define READ_EVENT_IN_PIPE(display) if ((display)->qlen > 0) { char buffer; read(READ_EVENT_FD, &buffer, sizeof(buffer)); (display)->qlen--; }

//TODO: Generate Enter & Leave events on MouseButton down and MouseMotion

void postExposeEvent(Display* display, Window window, SDL_Rect damagedArea) {
    static unsigned exposeEventsToFollow = 0;
    SDL_Rect childDamagedArea;
    size_t i;
    int width, height;
    GET_WINDOW_DIMS(window, width, height);
    if (damagedArea.x < 0 || damagedArea.x > width || damagedArea.y < 0
        || damagedArea.y > height || width < 0 || height < 0) return;
    exposeEventsToFollow++;
    Window* children = GET_CHILDREN(window);
    for (i = 0; i < GET_WINDOW_STRUCT(window)->childSpace; i++) {
        if (children[i] != NULL && !IS_INPUT_ONLY(children[0])
            && GET_WINDOW_STRUCT(children[i])->mapState == Mapped) {
            WindowStruct* childWindowStruct = GET_WINDOW_STRUCT(children[i]);
            childDamagedArea.x = damagedArea.x - childWindowStruct->x;
            childDamagedArea.y = damagedArea.y - childWindowStruct->y;
            childDamagedArea.w = childDamagedArea.x + damagedArea.w;
            childDamagedArea.h = childDamagedArea.y + damagedArea.h;
            childDamagedArea.x = MAX(0, childDamagedArea.x);
            childDamagedArea.y = MAX(0, childDamagedArea.y);
            postExposeEvent(display, children[i], childDamagedArea);
        }
    }<commit_msg>Rework expose area checking<commit_after>#include <errno.h>
#include <fcntl.h>
#include "events.h"
#include "errors.h"
#include "SDL.h"
#include "window.h"
#include "drawing.h"
#include "inputMethod.h"
#include "SDL_gpu.h"
#include "display.h"

int eventFds[2];
#define READ_EVENT_FD eventFds[0]
#define WRITE_EVENT_FD eventFds[1]
SDL_Event waitingEvent;
Bool eventWaiting = False;
Bool tmpVar = False;
Window keyboardFocus = NULL;

void updateWindowRenderTargets(Display* display);

#define ENQUEUE_EVENT_IN_PIPE(display) { char buffer = 'e'; write(WRITE_EVENT_FD, &buffer, sizeof(buffer)); (display)->qlen++; }
#define READ_EVENT_IN_PIPE(display) if ((display)->qlen > 0) { char buffer; read(READ_EVENT_FD, &buffer, sizeof(buffer)); (display)->qlen--; }

//TODO: Generate Enter & Leave events on MouseButton down and MouseMotion

void postExposeEvent(Display* display, Window window, SDL_Rect damagedArea) {
    static unsigned exposeEventsToFollow = 0;
    SDL_Rect childDamagedArea;
    size_t i;
    SDL_Rect windowRect;
    windowRect.x = 0;
    windowRect.y = 0;
    GET_WINDOW_DIMS(window, windowRect.w, windowRect.h);
    if (!SDL_HasIntersection(&damagedArea, &windowRect)) return;
    exposeEventsToFollow++;
    Window* children = GET_CHILDREN(window);
    for (i = 0; i < GET_WINDOW_STRUCT(window)->childSpace; i++) {
        if (children[i] != NULL && !IS_INPUT_ONLY(children[0])
            && GET_WINDOW_STRUCT(children[i])->mapState == Mapped) {
            WindowStruct* childWindowStruct = GET_WINDOW_STRUCT(children[i]);
            childDamagedArea.x = damagedArea.x - childWindowStruct->x;
            childDamagedArea.y = damagedArea.y - childWindowStruct->y;
            childDamagedArea.w = childDamagedArea.x + damagedArea.w;
            childDamagedArea.h = childDamagedArea.y + damagedArea.h;
            childDamagedArea.x = MAX(0, childDamagedArea.x);
            childDamagedArea.y = MAX(0, childDamagedArea.y);
            postExposeEvent(display, children[i], childDamagedArea);
        }
    }
{'fraction_non_alphanumeric': 0.1264169541646131, 'fraction_numerical': 0.005914243469689502, 'mean_word_length': 4.035980148883374, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, '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': '6383857', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1335, 'n_words': 290}