Commit a98adfd8 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

added API to set an event snooper which, if set, receives any controller

2005-05-11  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpcontrollerinfo.[ch]: added API to set an event
	snooper which, if set, receives any controller event first, even
	if event dispatching is disabled for the controller.

	* app/widgets/gimpcontrollereditor.[ch]: use the new API to
	implement a "Grab Event" button, which takes the next event from
	the controller and selects it in the event mapping tree view.
parent 66ce4f85
2005-05-11 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpcontrollerinfo.[ch]: added API to set an event
snooper which, if set, receives any controller event first, even
if event dispatching is disabled for the controller.
* app/widgets/gimpcontrollereditor.[ch]: use the new API to
implement a "Grab Event" button, which takes the next event from
the controller and selects it in the event mapping tree view.
2005-05-10 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpcontrollerlist.[ch]: some more stuff: up/down
......
......@@ -85,6 +85,8 @@ static void gimp_controller_editor_row_activated (GtkTreeView *tv,
GtkTreeViewColumn *column,
GimpControllerEditor *editor);
static void gimp_controller_editor_grab_toggled (GtkWidget *button,
GimpControllerEditor *editor);
static void gimp_controller_editor_edit_clicked (GtkWidget *button,
GimpControllerEditor *editor);
static void gimp_controller_editor_delete_clicked (GtkWidget *button,
......@@ -380,6 +382,15 @@ gimp_controller_editor_constructor (GType type,
gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
editor->grab_button = gtk_check_button_new_with_mnemonic (_("_Grab Event"));
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (editor->grab_button), FALSE);
gtk_box_pack_start (GTK_BOX (hbox), editor->grab_button, TRUE, TRUE, 0);
gtk_widget_show (editor->grab_button);
g_signal_connect (editor->grab_button, "toggled",
G_CALLBACK (gimp_controller_editor_grab_toggled),
editor);
editor->edit_button = gtk_button_new_from_stock (GIMP_STOCK_EDIT);
gtk_box_pack_start (GTK_BOX (hbox), editor->edit_button, TRUE, TRUE, 0);
gtk_widget_show (editor->edit_button);
......@@ -447,6 +458,8 @@ gimp_controller_editor_finalize (GObject *object)
if (editor->info)
{
gimp_controller_info_set_event_snooper (editor->info, NULL, NULL);
g_object_unref (editor->info);
editor->info = NULL;
}
......@@ -514,6 +527,8 @@ gimp_controller_editor_sel_changed (GtkTreeSelection *sel,
gtk_widget_set_sensitive (editor->edit_button, edit_sensitive);
gtk_widget_set_sensitive (editor->delete_button, delete_sensitive);
gimp_controller_info_set_event_snooper (editor->info, NULL, NULL);
}
static void
......@@ -526,6 +541,77 @@ gimp_controller_editor_row_activated (GtkTreeView *tv,
gtk_button_clicked (GTK_BUTTON (editor->edit_button));
}
static gboolean
gimp_controller_editor_snooper (GimpControllerInfo *info,
GimpController *controller,
const GimpControllerEvent *event,
gpointer user_data)
{
GimpControllerEditor *editor = GIMP_CONTROLLER_EDITOR (user_data);
GtkTreeModel *model;
GtkTreeIter iter;
gboolean iter_valid;
const gchar *event_name;
gtk_tree_selection_get_selected (editor->sel, &model, &iter);
event_name = gimp_controller_get_event_name (info->controller,
event->any.event_id);
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &iter))
{
gchar *list_name;
gtk_tree_model_get (model, &iter,
COLUMN_EVENT, &list_name,
-1);
if (! strcmp (list_name, event_name))
{
GtkTreeView *view;
GtkTreePath *path;
view = gtk_tree_selection_get_tree_view (editor->sel);
gtk_tree_selection_select_iter (editor->sel, &iter);
path = gtk_tree_model_get_path (model, &iter);
gtk_tree_view_scroll_to_cell (view, path, NULL, FALSE, 0.0, 0.0);
gtk_tree_view_set_cursor (view, path, NULL, FALSE);
gtk_tree_path_free (path);
gtk_widget_grab_focus (GTK_WIDGET (view));
g_free (list_name);
break;
}
g_free (list_name);
}
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->grab_button), FALSE);
return TRUE;
}
static void
gimp_controller_editor_grab_toggled (GtkWidget *button,
GimpControllerEditor *editor)
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
{
gimp_controller_info_set_event_snooper (editor->info,
gimp_controller_editor_snooper,
editor);
}
else
{
gimp_controller_info_set_event_snooper (editor->info, NULL, NULL);
}
}
static void
gimp_controller_editor_edit_clicked (GtkWidget *button,
GimpControllerEditor *editor)
......@@ -535,6 +621,8 @@ gimp_controller_editor_edit_clicked (GtkWidget *button,
gchar *event_name = NULL;
gchar *action_name = NULL;
gimp_controller_info_set_event_snooper (editor->info, NULL, NULL);
if (gtk_tree_selection_get_selected (editor->sel, &model, &iter))
gtk_tree_model_get (model, &iter,
COLUMN_EVENT, &event_name,
......@@ -611,6 +699,8 @@ gimp_controller_editor_delete_clicked (GtkWidget *button,
GtkTreeIter iter;
gchar *event_name = NULL;
gimp_controller_info_set_event_snooper (editor->info, NULL, NULL);
if (gtk_tree_selection_get_selected (editor->sel, &model, &iter))
gtk_tree_model_get (model, &iter,
COLUMN_EVENT, &event_name,
......
......@@ -44,6 +44,7 @@ struct _GimpControllerEditor
GtkTreeSelection *sel;
GtkWidget *grab_button;
GtkWidget *edit_button;
GtkWidget *delete_button;
......
......@@ -449,6 +449,17 @@ gimp_controller_info_get_enabled (GimpControllerInfo *info)
return info->enabled;
}
void
gimp_controller_info_set_event_snooper (GimpControllerInfo *info,
GimpControllerEventSnooper snooper,
gpointer snooper_data)
{
g_return_if_fail (GIMP_IS_CONTROLLER_INFO (info));
info->snooper = snooper;
info->snooper_data = snooper_data;
}
/* private functions */
......@@ -465,29 +476,38 @@ gimp_controller_info_event (GimpController *controller,
event_blurb = gimp_controller_get_event_blurb (controller, event->any.event_id);
if (info->debug_events)
g_print ("Received '%s' (class '%s')\n"
" controller event '%s (%s)'\n",
controller->name, GIMP_CONTROLLER_GET_CLASS (controller)->name,
event_name, event_blurb);
switch (event->any.type)
{
case GIMP_CONTROLLER_EVENT_TRIGGER:
if (info->debug_events)
g_print (" (trigger event)\n");
break;
g_print ("Received '%s' (class '%s')\n"
" controller event '%s (%s)'\n",
controller->name, GIMP_CONTROLLER_GET_CLASS (controller)->name,
event_name, event_blurb);
case GIMP_CONTROLLER_EVENT_VALUE:
if (info->debug_events)
switch (event->any.type)
{
case GIMP_CONTROLLER_EVENT_TRIGGER:
g_print (" (trigger event)\n");
break;
case GIMP_CONTROLLER_EVENT_VALUE:
if (G_VALUE_HOLDS_DOUBLE (&event->value.value))
g_print (" (value event, value = %f)\n",
g_value_get_double (&event->value.value));
else
g_print (" (value event, unhandled type '%s')\n",
g_type_name (event->value.value.g_type));
break;
}
}
if (info->snooper)
{
if (info->snooper (info, controller, event, info->snooper_data))
{
if (info->debug_events)
g_print (" intercepted by event snooper\n\n");
return TRUE;
}
break;
}
if (! info->enabled)
......
......@@ -20,13 +20,19 @@
* Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_CONTROLLER_WHELL_H__
#ifndef __GIMP_CONTROLLER_INFO_H__
#define __GIMP_CONTROLLER_INFO_H__
#include "core/gimpviewable.h"
typedef gboolean (* GimpControllerEventSnooper) (GimpControllerInfo *info,
GimpController *controller,
const GimpControllerEvent *event,
gpointer user_data);
#define GIMP_TYPE_CONTROLLER_INFO (gimp_controller_info_get_type ())
#define GIMP_CONTROLLER_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CONTROLLER_INFO, GimpControllerInfo))
#define GIMP_CONTROLLER_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CONTROLLER_INFO, GimpControllerInfoClass))
......@@ -39,13 +45,16 @@ typedef struct _GimpControllerInfoClass GimpControllerInfoClass;
struct _GimpControllerInfo
{
GimpViewable parent_instance;
GimpViewable parent_instance;
gboolean enabled;
gboolean debug_events;
gboolean enabled;
gboolean debug_events;
GimpController *controller;
GHashTable *mapping;
GimpController *controller;
GHashTable *mapping;
GimpControllerEventSnooper snooper;
gpointer snooper_data;
};
struct _GimpControllerInfoClass
......@@ -59,13 +68,17 @@ struct _GimpControllerInfoClass
};
GType gimp_controller_info_get_type (void) G_GNUC_CONST;
GType gimp_controller_info_get_type (void) G_GNUC_CONST;
GimpControllerInfo * gimp_controller_info_new (GType type);
GimpControllerInfo * gimp_controller_info_new (GType type);
void gimp_controller_info_set_enabled (GimpControllerInfo *info,
gboolean enabled);
gboolean gimp_controller_info_get_enabled (GimpControllerInfo *info);
void gimp_controller_info_set_enabled (GimpControllerInfo *info,
gboolean enabled);
gboolean gimp_controller_info_get_enabled (GimpControllerInfo *info);
void gimp_controller_info_set_event_snooper (GimpControllerInfo *info,
GimpControllerEventSnooper snooper,
gpointer snooper_data);
#endif /* __GIMP_CONTROLLER_INFO_H__ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment