<commit_before>/*****************************************************************************
 *   Copyright 2013 - 2014 <NAME> <<EMAIL>>                     *
 *                                                                           *
 *   This program 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) version 3, or any later version accepted   *
 *   by the membership of KDE e.V. (or its successor approved by the         *
 *   membership of KDE e.V.), which shall act as a proxy defined in          *
 *   Section 6 of version 3 of the license.                                  *
 *                                                                           *
 *   This program 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,                                *
 *   see <http://www.gnu.org/licenses/>.                                     *
 *****************************************************************************/

#include "config.h"

#include "x11shadow_p.h"
#include "x11wmmove.h"
#include "x11blur.h"
#include "x11qtc.h"
#include "x11wrap.h"

#ifdef QTC_ENABLE_X11

#include "log.h"
#include "number.h"
#include "shadow_p.h"
#include "x11utils_p.h"
#include <X11/Xlib.h>
#include <X11/Xatom.h>

/**
 * shadow atom and property specification available at
 * http://community.kde.org/KWin/Shadow
 **/

static uint32_t shadow_xpixmaps[8];
static uint32_t shadow_data_xcb[8 + 4];
/**
 * Use XCB to set window property recieves BadWindow errors for menus in
 * Qt4 kpartsplugin here, probably because of the order of some pending
 * event/requests in Xlib. Calling #XFlush before #xcb_change_property
 * doesn't solve the problem for unknown reason but using #XChangeProperty
 * works.
 * NOTE: #XChangeProperty want `unsigned long` for format 32. So we need
 * two seperate data buffers.
 **/
static unsigned long shadow_data_xlib[8 + 4];

static xcb_pixmap_t
qtcX11ShadowCreatePixmap(const QtcImage *data)
{
    xcb_pixmap_t pixmap = qtcX11GenerateId();

    // create X11 pixmap
    qtcX11CallVoid(create_pixmap, 32, pixmap, qtc_root_window,
                   data->width, data->height);
    xcb_gcontext_t cid = qtcX11GenerateId();
    qtcX11CallVoid(create_gc, cid, pixmap, 0, (const uint32_t*)0);
    qtcX11CallVoid(put_image, XCB_IMAGE_FORMAT_Z_PIXMAP, pixmap, cid,
                   data->width, data->height, 0, 0, 0, 32, data->len,
                   (unsigned char*)data->data);
    qtcX11CallVoid(free_gc, cid);
    qtcX11Flush();
    return pixmap;
}

void
qtcX11ShadowInit()
{
    int shadow_size = 30;
    int shadow_radius = 4;
    QtcColor c1 = {0.5, 0.4, 0.4};
    QtcColor c2 = {0.2, 0.2, 0.2};
    QtcImage *shadow_images[8];
    qtcShadowCreate(shadow_size, &c1, &c2, shadow_radius, false,
                    QTC_PIXEL_XCB, shadow_images);
    for (int i = 0;i < 8;i++) {
        shadow_xpixmaps[i] = qtcX11ShadowCreatePixmap(shadow_images[i]);
        free(shadow_images[i]);
    }<commit_msg>[lib/utils/x11shadow] typo in shadow color .... #54<commit_after>/*****************************************************************************
 *   Copyright 2013 - 2014 <NAME> <<EMAIL>>                     *
 *                                                                           *
 *   This program 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) version 3, or any later version accepted   *
 *   by the membership of KDE e.V. (or its successor approved by the         *
 *   membership of KDE e.V.), which shall act as a proxy defined in          *
 *   Section 6 of version 3 of the license.                                  *
 *                                                                           *
 *   This program 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,                                *
 *   see <http://www.gnu.org/licenses/>.                                     *
 *****************************************************************************/

#include "config.h"

#include "x11shadow_p.h"
#include "x11wmmove.h"
#include "x11blur.h"
#include "x11qtc.h"
#include "x11wrap.h"

#ifdef QTC_ENABLE_X11

#include "log.h"
#include "number.h"
#include "shadow_p.h"
#include "x11utils_p.h"
#include <X11/Xlib.h>
#include <X11/Xatom.h>

/**
 * shadow atom and property specification available at
 * http://community.kde.org/KWin/Shadow
 **/

static uint32_t shadow_xpixmaps[8];
static uint32_t shadow_data_xcb[8 + 4];
/**
 * Use XCB to set window property recieves BadWindow errors for menus in
 * Qt4 kpartsplugin here, probably because of the order of some pending
 * event/requests in Xlib. Calling #XFlush before #xcb_change_property
 * doesn't solve the problem for unknown reason but using #XChangeProperty
 * works.
 * NOTE: #XChangeProperty want `unsigned long` for format 32. So we need
 * two seperate data buffers.
 **/
static unsigned long shadow_data_xlib[8 + 4];

static xcb_pixmap_t
qtcX11ShadowCreatePixmap(const QtcImage *data)
{
    xcb_pixmap_t pixmap = qtcX11GenerateId();

    // create X11 pixmap
    qtcX11CallVoid(create_pixmap, 32, pixmap, qtc_root_window,
                   data->width, data->height);
    xcb_gcontext_t cid = qtcX11GenerateId();
    qtcX11CallVoid(create_gc, cid, pixmap, 0, (const uint32_t*)0);
    qtcX11CallVoid(put_image, XCB_IMAGE_FORMAT_Z_PIXMAP, pixmap, cid,
                   data->width, data->height, 0, 0, 0, 32, data->len,
                   (unsigned char*)data->data);
    qtcX11CallVoid(free_gc, cid);
    qtcX11Flush();
    return pixmap;
}

void
qtcX11ShadowInit()
{
    int shadow_size = 30;
    int shadow_radius = 4;
    QtcColor c1 = {0.4, 0.4, 0.4};
    QtcColor c2 = {0.2, 0.2, 0.2};
    QtcImage *shadow_images[8];
    qtcShadowCreate(shadow_size, &c1, &c2, shadow_radius, false,
                    QTC_PIXEL_XCB, shadow_images);
    for (int i = 0;i < 8;i++) {
        shadow_xpixmaps[i] = qtcX11ShadowCreatePixmap(shadow_images[i]);
        free(shadow_images[i]);
    }
{'fraction_non_alphanumeric': 0.1319001386962552, 'fraction_numerical': 0.027739251040221916, 'mean_word_length': 2.2120267260579065, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4000854', 'n_tokens_mistral': 2266, 'n_tokens_neox': 2088, 'n_words': 655}