<commit_before>/*
 * panel-bindings.c: panel keybindings support module
 *
 * Copyright (C) 2003 Sun Microsystems, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *	<NAME> <<EMAIL>>
 */

#include <config.h>

#include "panel-bindings.h"

#include <string.h>
#include <glib/gi18n.h>

#include "panel-schemas.h"
#include "panel-toplevel.h"
#include "panel-xutils.h"

#define DEFAULT_MOUSE_MODIFIER GDK_MOD1_MASK

typedef struct {
	guint            keyval;
	GdkModifierType  modifiers;
} KeyBinding;

typedef struct {
	const gchar *key;
	const gchar *signal;
	GSList      *list;
} PanelBinding;

static gboolean initialised = FALSE;
static GSettings *preferences = NULL;
static GSettings *keybindings = NULL;

static PanelBinding bindings [] = {
	{ GNOME_DESKTOP_WM_KEYBINDINGS_ACTIVATE_WINDOW_MENU_KEY, "popup-panel-menu", NULL },
	{ GNOME_DESKTOP_WM_KEYBINDINGS_TOGGLE_MAXIMIZED_KEY,     "toggle-expand",    NULL },
	{ GNOME_DESKTOP_WM_KEYBINDINGS_MAXIMIZE_KEY,             "expand",           NULL },
	{ GNOME_DESKTOP_WM_KEYBINDINGS_UNMAXIMIZE_KEY,           "unexpand",         NULL },
	{ GNOME_DESKTOP_WM_KEYBINDINGS_TOGGLE_SHADED_KEY,        "toggle-hidden",    NULL },
	{ GNOME_DESKTOP_WM_KEYBINDINGS_BEGIN_MOVE_KEY,           "begin-move",       NULL },
	{ GNOME_DESKTOP_WM_KEYBINDINGS_BEGIN_RESIZE_KEY,         "begin-resize",     NULL },
};

static guint mouse_button_modifier_keymask = DEFAULT_MOUSE_MODIFIER;

static void
panel_binding_set_from_string (PanelBinding *binding, const char *str)
{
	KeyBinding *tmp;

	if (!str || !str [0] || !strcmp (str, "disabled")) {
		g_slist_foreach (binding->list, (GFunc)g_free, NULL);
		g_slist_free (binding->list);
		binding->list = NULL;
		return;
	}

	tmp = g_new(KeyBinding, 1);
	tmp->keyval = 0;
	tmp->modifiers = 0;

	gtk_accelerator_parse (str, &tmp->keyval, &tmp->modifiers);

	if (tmp->keyval == 0 && tmp->modifiers == 0) {
		g_free (tmp);
		g_warning ("Unable to parse binding '%s'\n", str);
		return;
	} else {
		binding->list = g_slist_append (binding->list, tmp);
	}
}

static inline GtkBindingSet *
get_binding_set (GtkBindingSet *binding_set)
{
	if (!binding_set) {
		PanelToplevelClass *toplevel_class;

		toplevel_class = g_type_class_peek (PANEL_TYPE_TOPLEVEL);
		if (!toplevel_class)
			return NULL;

		g_assert (PANEL_IS_TOPLEVEL_CLASS (toplevel_class));

		binding_set = gtk_binding_set_by_class (toplevel_class);
	}

	return binding_set;
}

static void
panel_binding_clear_entry (PanelBinding *binding, GtkBindingSet *binding_set)
{
	KeyBinding *b;
	GSList     *l;

	binding_set = get_binding_set (binding_set);

	for (l = binding->list; l != NULL; l = l->next) {
		b = l->data;
		gtk_binding_entry_remove (binding_set, b->keyval, b->modifiers);
	}

	g_slist_foreach (binding->list, (GFunc)g_free, NULL);
	g_slist_free (binding->list);
	binding->list = NULL;
}

static void
panel_binding_set_entry (PanelBinding *binding, GtkBindingSet *binding_set)
{
	KeyBinding *b;
	GSList     *l;

	binding_set = get_binding_set (binding_set);

	for (l = binding->list; l != NULL; l = l->next) {
		b = l->data;
		gtk_binding_entry_add_signal (binding_set, b->keyval, b->modifiers, binding->signal, 0);
	}
}

static void
panel_binding_changed (GSettings *settings, const gchar *key, PanelBinding *binding)
{
	gchar **array;
	gint    i;

	if (binding->list != NULL)
		panel_binding_clear_entry (binding, NULL);

	array = g_settings_get_strv (settings, key);

	if (array) {
		for (i = 0; array[i] != NULL; i++) {<commit_msg>bindings: use g_slist_free_full to free list<commit_after>/*
 * panel-bindings.c: panel keybindings support module
 *
 * Copyright (C) 2003 Sun Microsystems, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *	<NAME> <<EMAIL>>
 */

#include <config.h>

#include "panel-bindings.h"

#include <string.h>
#include <glib/gi18n.h>

#include "panel-schemas.h"
#include "panel-toplevel.h"
#include "panel-xutils.h"

#define DEFAULT_MOUSE_MODIFIER GDK_MOD1_MASK

typedef struct {
	guint            keyval;
	GdkModifierType  modifiers;
} KeyBinding;

typedef struct {
	const gchar *key;
	const gchar *signal;
	GSList      *list;
} PanelBinding;

static gboolean initialised = FALSE;
static GSettings *preferences = NULL;
static GSettings *keybindings = NULL;

static PanelBinding bindings [] = {
	{ GNOME_DESKTOP_WM_KEYBINDINGS_ACTIVATE_WINDOW_MENU_KEY, "popup-panel-menu", NULL },
	{ GNOME_DESKTOP_WM_KEYBINDINGS_TOGGLE_MAXIMIZED_KEY,     "toggle-expand",    NULL },
	{ GNOME_DESKTOP_WM_KEYBINDINGS_MAXIMIZE_KEY,             "expand",           NULL },
	{ GNOME_DESKTOP_WM_KEYBINDINGS_UNMAXIMIZE_KEY,           "unexpand",         NULL },
	{ GNOME_DESKTOP_WM_KEYBINDINGS_TOGGLE_SHADED_KEY,        "toggle-hidden",    NULL },
	{ GNOME_DESKTOP_WM_KEYBINDINGS_BEGIN_MOVE_KEY,           "begin-move",       NULL },
	{ GNOME_DESKTOP_WM_KEYBINDINGS_BEGIN_RESIZE_KEY,         "begin-resize",     NULL },
};

static guint mouse_button_modifier_keymask = DEFAULT_MOUSE_MODIFIER;

static void
panel_binding_set_from_string (PanelBinding *binding, const char *str)
{
	KeyBinding *tmp;

	if (!str || !str [0] || !strcmp (str, "disabled")) {
		g_slist_free_full (binding->list, g_free);
		binding->list = NULL;
		return;
	}

	tmp = g_new(KeyBinding, 1);
	tmp->keyval = 0;
	tmp->modifiers = 0;

	gtk_accelerator_parse (str, &tmp->keyval, &tmp->modifiers);

	if (tmp->keyval == 0 && tmp->modifiers == 0) {
		g_free (tmp);
		g_warning ("Unable to parse binding '%s'\n", str);
		return;
	} else {
		binding->list = g_slist_append (binding->list, tmp);
	}
}

static inline GtkBindingSet *
get_binding_set (GtkBindingSet *binding_set)
{
	if (!binding_set) {
		PanelToplevelClass *toplevel_class;

		toplevel_class = g_type_class_peek (PANEL_TYPE_TOPLEVEL);
		if (!toplevel_class)
			return NULL;

		g_assert (PANEL_IS_TOPLEVEL_CLASS (toplevel_class));

		binding_set = gtk_binding_set_by_class (toplevel_class);
	}

	return binding_set;
}

static void
panel_binding_clear_entry (PanelBinding *binding, GtkBindingSet *binding_set)
{
	KeyBinding *b;
	GSList     *l;

	binding_set = get_binding_set (binding_set);

	for (l = binding->list; l != NULL; l = l->next) {
		b = l->data;
		gtk_binding_entry_remove (binding_set, b->keyval, b->modifiers);
	}

	g_slist_free_full (binding->list, g_free);
	binding->list = NULL;
}

static void
panel_binding_set_entry (PanelBinding *binding, GtkBindingSet *binding_set)
{
	KeyBinding *b;
	GSList     *l;

	binding_set = get_binding_set (binding_set);

	for (l = binding->list; l != NULL; l = l->next) {
		b = l->data;
		gtk_binding_entry_add_signal (binding_set, b->keyval, b->modifiers, binding->signal, 0);
	}
}

static void
panel_binding_changed (GSettings *settings, const gchar *key, PanelBinding *binding)
{
	gchar **array;
	gint    i;

	if (binding->list != NULL)
		panel_binding_clear_entry (binding, NULL);

	array = g_settings_get_strv (settings, key);

	if (array) {
		for (i = 0; array[i] != NULL; i++) {
{'fraction_non_alphanumeric': 0.11358055009823183, 'fraction_numerical': 0.003929273084479371, 'mean_word_length': 4.285528877352369, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6691251', 'n_tokens_mistral': 3036, 'n_tokens_neox': 2896, 'n_words': 733}