<commit_before>/* $Id$
 * This was written by <NAME> in 2001.
 * This code is in the public domain and the author disclaims all
 * copyright privileges.
 */
#include <stdlib.h>

#include "client.h"
#include "workspace.h"
#include "keyboard.h"

XContext window_context;
XContext frame_context;

client_t *client_create(Window w)
{
    client_t *client;
    XWMHints *xwmh;
    XWindowAttributes xwa;
    XSetWindowAttributes xswa;
    int mask;

    if (XGetWindowAttributes(dpy, w, &xwa) == 0) return NULL;
    if (xwa.override_redirect) {
        printf("\tWindow has override_redirect, not creating client\n");
        return NULL;
    }
    XSelectInput(dpy, w, EnterWindowMask | KeyPressMask);

    client = malloc(sizeof(client_t));
    if (client == NULL) {
        printf("\tMalloc failed\n");
        return NULL;
    }
    memset(client, 0, sizeof(client_t));
    
    client->window = w;
    client->transient_for = None;
    client->name = "???";
    client->workspace = workspace_current;
    client->xwmh = XGetWMHints(dpy, w);
    client->state = xwa.map_state == IsViewable ? MAPPED : UNMAPPED;
    client->x = xwa.x;
    client->y = xwa.y;
    client->width = xwa.width;
    client->height = xwa.height;

    if (focus_canfocus(client)) focus_add(client);

    if (XSaveContext(dpy, w, window_context, (void *)client) != 0) {
        printf("Could not save window context\n");
        free(client);
        return NULL;
    }
    printf("\tCreated an entry for window 0x%08X at 0x%08X\n", w, client);

    /* create frame and reparent */
    client->frame = None;
    if (1) {
        mask = CWBackPixmap | CWBackPixel | CWBorderPixel
               | CWCursor | CWEventMask | CWOverrideRedirect;
        xswa.cursor = cursor_normal;
        xswa.background_pixmap = None;
        xswa.background_pixel = black;
        xswa.event_mask = KeyPressMask | KeyReleaseMask
                          | SubstructureRedirectMask | ExposureMask
                          | EnterWindowMask | LeaveWindowMask;
        xswa.override_redirect = True;
        client->frame = XCreateWindow(dpy, root_window, client->x, client->y,
                                      client->width, client->height, 0,
                                      DefaultDepth(dpy, scr), CopyFromParent,
                                      DefaultVisual(dpy, scr),
                                      mask, &xswa);
        printf("\tReparenting client 0x%08X (window 0x%08X) to 0x%08X\n",
               client, w, client->frame);
        XClearWindow(dpy, client->frame);
        /* ignore the map and unmap events caused by the reparenting: */
        XSelectInput(dpy, w, xwa.your_event_mask & ~StructureNotifyMask);
        XReparentWindow(dpy, w, client->frame, 0, TITLE_HEIGHT);
        XSelectInput(dpy, w,
                     xwa.your_event_mask | EnterWindowMask | KeyPressMask
                    | StructureNotifyMask);
    }
    if (client->frame != None) {
        if (XSaveContext(dpy, client->frame,
                         frame_context, (void *)client) != 0) {
            XDeleteContext(dpy, client->window, window_context);
            free(client);
            printf("\tCould not save frame context\n");
            return NULL;
        }
    }

    return client;
}

client_t *client_find(Window w)
{
    client_t *client;

    if (XFindContext(dpy, w, window_context, (void *)&client) != 0)
        if (XFindContext(dpy, w, frame_context, (void *)&client) != 0)
            client = NULL;
    if (client == NULL)
        printf("\tCould not find client\n");
    else if (client->window == w)
        printf("\tFound client from window\n");
    else
        printf("\tFound client from frame\n");
    return client;
}

void client_destroy(client_t *client)
{
    if (client->frame != None)
        XUnmapWindow(dpy, client->frame);
    if (client->xwmh != NULL) XFree(client->xwmh);
    XDeleteContext(dpy, client->window, window_context);
    XDeleteContext(dpy, client->frame, frame_context);
    free(client);
}

void client_print(char *s, client_t *client)
{
    if (client == NULL) {
        printf("%-19s null client\n", s);
        return;
    }
    printf("%-19s client = 0x%08X, window = 0x%08X, frame = 0x%08X\n",
           s, client, client->window, client->frame);
}

<commit_msg>removed KeyPressMask, not needed with XGrabKey<commit_after>/* $Id$
 * This was written by <NAME> in 2001.
 * This code is in the public domain and the author disclaims all
 * copyright privileges.
 */
#include <stdlib.h>

#include "client.h"
#include "workspace.h"
#include "keyboard.h"

XContext window_context;
XContext frame_context;

client_t *client_create(Window w)
{
    client_t *client;
    XWMHints *xwmh;
    XWindowAttributes xwa;
    XSetWindowAttributes xswa;
    int mask;

    if (XGetWindowAttributes(dpy, w, &xwa) == 0) return NULL;
    if (xwa.override_redirect) {
        printf("\tWindow has override_redirect, not creating client\n");
        return NULL;
    }
    XSelectInput(dpy, w, EnterWindowMask);

    client = malloc(sizeof(client_t));
    if (client == NULL) {
        printf("\tMalloc failed\n");
        return NULL;
    }
    memset(client, 0, sizeof(client_t));
    
    client->window = w;
    client->transient_for = None;
    client->name = "???";
    client->workspace = workspace_current;
    client->xwmh = XGetWMHints(dpy, w);
    client->state = xwa.map_state == IsViewable ? MAPPED : UNMAPPED;
    client->x = xwa.x;
    client->y = xwa.y;
    client->width = xwa.width;
    client->height = xwa.height;

    if (focus_canfocus(client)) focus_add(client);

    if (XSaveContext(dpy, w, window_context, (void *)client) != 0) {
        printf("Could not save window context\n");
        free(client);
        return NULL;
    }
    printf("\tCreated an entry for window 0x%08X at 0x%08X\n", w, client);

    /* create frame and reparent */
    client->frame = None;
    if (1) {
        mask = CWBackPixmap | CWBackPixel | CWBorderPixel
               | CWCursor | CWEventMask | CWOverrideRedirect;
        xswa.cursor = cursor_normal;
        xswa.background_pixmap = None;
        xswa.background_pixel = black;
        xswa.event_mask = SubstructureRedirectMask | ExposureMask |
                          EnterWindowMask | LeaveWindowMask;
        xswa.override_redirect = True;
        client->frame = XCreateWindow(dpy, root_window, client->x, client->y,
                                      client->width, client->height, 0,
                                      DefaultDepth(dpy, scr), CopyFromParent,
                                      DefaultVisual(dpy, scr),
                                      mask, &xswa);
        printf("\tReparenting client 0x%08X (window 0x%08X) to 0x%08X\n",
               client, w, client->frame);
        XClearWindow(dpy, client->frame);
        /* ignore the map and unmap events caused by the reparenting: */
        XSelectInput(dpy, w, xwa.your_event_mask & ~StructureNotifyMask);
        XReparentWindow(dpy, w, client->frame, 0, TITLE_HEIGHT);
        XSelectInput(dpy, w,
                     xwa.your_event_mask | EnterWindowMask
                     | StructureNotifyMask);
    }
    if (client->frame != None) {
        if (XSaveContext(dpy, client->frame,
                         frame_context, (void *)client) != 0) {
            XDeleteContext(dpy, client->window, window_context);
            free(client);
            printf("\tCould not save frame context\n");
            return NULL;
        }
    }

    return client;
}

client_t *client_find(Window w)
{
    client_t *client;

    if (XFindContext(dpy, w, window_context, (void *)&client) != 0)
        if (XFindContext(dpy, w, frame_context, (void *)&client) != 0)
            client = NULL;
    if (client == NULL)
        printf("\tCould not find client\n");
    else if (client->window == w)
        printf("\tFound client from window\n");
    else
        printf("\tFound client from frame\n");
    return client;
}

void client_destroy(client_t *client)
{
    if (client->frame != None)
        XUnmapWindow(dpy, client->frame);
    if (client->xwmh != NULL) XFree(client->xwmh);
    XDeleteContext(dpy, client->window, window_context);
    XDeleteContext(dpy, client->frame, frame_context);
    free(client);
}

void client_print(char *s, client_t *client)
{
    if (client == NULL) {
        printf("%-19s null client\n", s);
        return;
    }
    printf("%-19s client = 0x%08X, window = 0x%08X, frame = 0x%08X\n",
           s, client, client->window, client->frame);
}


{'fraction_non_alphanumeric': 0.12347846441947566, 'fraction_numerical': 0.009597378277153557, 'mean_word_length': 2.315871168024835, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 69, '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': '5717715', 'n_tokens_mistral': 2781, 'n_tokens_neox': 2662, 'n_words': 647}