<commit_before>/* main.c
 *
 * Copyright (c) 2009 <NAME>
 * Copyright (c) 2011 <NAME>
 *
 * See LICENSE for licensing information
 */

#include <stdlib.h>
#include <string.h>

#include <gtk/gtk.h>
#include <panel-applet.h>
#include <dbus/dbus-glib.h>

/* AW: I pulled this code off the interwebs. It makes background 
 * transparency actually work
 */
static void change_bg(
    PanelApplet *applet, PanelAppletBackgroundType type,
    GdkColor *color, GdkPixmap *pixmap)
{
    GtkRcStyle *rc_style;
    GtkStyle *style;

    /* reset style */
    gtk_widget_set_style(GTK_WIDGET(applet), NULL);
    rc_style = gtk_rc_style_new();
    gtk_widget_modify_style(GTK_WIDGET(applet), rc_style);
    gtk_rc_style_unref(rc_style);

    switch(type) {
    case PANEL_NO_BACKGROUND:
        break;
    case PANEL_COLOR_BACKGROUND:
        gtk_widget_modify_bg(GTK_WIDGET(applet), GTK_STATE_NORMAL, color);
        break;
    case PANEL_PIXMAP_BACKGROUND:
        style = gtk_style_copy(GTK_WIDGET(applet)->style);

        if(style->bg_pixmap[GTK_STATE_NORMAL])
            g_object_unref(style->bg_pixmap[GTK_STATE_NORMAL]);

        style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref(pixmap);
        gtk_widget_set_style(GTK_WIDGET(applet), style);
        g_object_unref(style);
        break;
    }
}

static void signal_handler(DBusGProxy *obj, const char *msg, GtkWidget *widget)
{
    gtk_label_set_markup(GTK_LABEL(widget), msg);
}

static void set_up_dbus_transfer(GtkWidget *buf)
{
    DBusGConnection *connection;
    DBusGProxy *proxy;
    GError *error= NULL;

    connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
    if(connection == NULL) {
        g_printerr("Failed to open connection: %s\n", error->message);
        g_error_free(error);
        exit(1);
    }

    proxy = dbus_g_proxy_new_for_name(
        connection, "org.xmonad.Log", "/org/xmonad/Log", "org.xmonad.Log");
    error = NULL;

    dbus_g_proxy_add_signal(proxy, "Update", G_TYPE_STRING, G_TYPE_INVALID);
    dbus_g_proxy_connect_signal(
        proxy, "Update", (GCallback)signal_handler, buf, NULL);
}

static gboolean xmonad_log_applet_fill(PanelApplet *applet)
{
	panel_applet_set_flags(
        applet,
        PANEL_APPLET_EXPAND_MAJOR |
        PANEL_APPLET_EXPAND_MINOR |
        PANEL_APPLET_HAS_HANDLE);

    GtkWidget *label = gtk_label_new("Waiting for Xmonad...");
    gtk_label_set_ellipsize(label, PANGO_ELLIPSIZE_END);

    gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
    gtk_misc_set_alignment((GtkMisc *)label, 0.0, 0.5);
    set_up_dbus_transfer(label);

    gtk_container_add(GTK_CONTAINER(applet), label);
    gtk_widget_show_all(GTK_WIDGET(applet));

    return TRUE;
}

static gboolean xmonad_log_applet_factory(
    PanelApplet *applet, const gchar *iid, gpointer data)
{
    gboolean retval = FALSE;

    if(!strcmp(iid, "XmonadLogApplet"))
        retval = xmonad_log_applet_fill(applet);

    if(retval == FALSE) {
        printf("Wrong applet!\n");
        exit(-1);
    }

    return retval;
}

PANEL_APPLET_OUT_PROCESS_FACTORY(
    "XmonadLogAppletFactory",
    PANEL_TYPE_APPLET,
    "XmonadLogApplet",
    xmonad_log_applet_factory,
    NULL);
<commit_msg>Properly set the background<commit_after>/* main.c
 *
 * Copyright (c) 2009 <NAME>
 * Copyright (c) 2011 <NAME>
 *
 * See LICENSE for licensing information
 */

#include <stdlib.h>
#include <string.h>

#include <gtk/gtk.h>
#include <panel-applet.h>
#include <dbus/dbus-glib.h>

static void signal_handler(DBusGProxy *obj, const char *msg, GtkWidget *widget)
{
    gtk_label_set_markup(GTK_LABEL(widget), msg);
}

static void set_up_dbus_transfer(GtkWidget *buf)
{
    DBusGConnection *connection;
    DBusGProxy *proxy;
    GError *error= NULL;

    connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
    if(connection == NULL) {
        g_printerr("Failed to open connection: %s\n", error->message);
        g_error_free(error);
        exit(1);
    }

    proxy = dbus_g_proxy_new_for_name(
        connection, "org.xmonad.Log", "/org/xmonad/Log", "org.xmonad.Log");
    error = NULL;

    dbus_g_proxy_add_signal(proxy, "Update", G_TYPE_STRING, G_TYPE_INVALID);
    dbus_g_proxy_connect_signal(
        proxy, "Update", (GCallback)signal_handler, buf, NULL);
}

static gboolean xmonad_log_applet_fill(PanelApplet *applet)
{
	panel_applet_set_flags(
        applet,
        PANEL_APPLET_EXPAND_MAJOR |
        PANEL_APPLET_EXPAND_MINOR |
        PANEL_APPLET_HAS_HANDLE);

    panel_applet_set_background_widget(applet, GTK_WIDGET(applet));

    GtkWidget *label = gtk_label_new("Waiting for Xmonad...");
    gtk_label_set_ellipsize(label, PANGO_ELLIPSIZE_END);

    gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
    gtk_misc_set_alignment((GtkMisc *)label, 0.0, 0.5);
    set_up_dbus_transfer(label);

    gtk_container_add(GTK_CONTAINER(applet), label);
    gtk_widget_show_all(GTK_WIDGET(applet));

    return TRUE;
}

static gboolean xmonad_log_applet_factory(
    PanelApplet *applet, const gchar *iid, gpointer data)
{
    gboolean retval = FALSE;

    if(!strcmp(iid, "XmonadLogApplet"))
        retval = xmonad_log_applet_fill(applet);

    if(retval == FALSE) {
        printf("Wrong applet!\n");
        exit(-1);
    }

    return retval;
}

PANEL_APPLET_OUT_PROCESS_FACTORY(
    "XmonadLogAppletFactory",
    PANEL_TYPE_APPLET,
    "XmonadLogApplet",
    xmonad_log_applet_factory,
    NULL);

{'fraction_non_alphanumeric': 0.11183234421364985, 'fraction_numerical': 0.0051928783382789315, 'mean_word_length': 3.884963768115942, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, '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': '5050303', 'n_tokens_mistral': 2115, 'n_tokens_neox': 2051, 'n_words': 337}