app/tools/gimptool.[ch] added boolean return value to

2004-06-24  Michael Natterer  <mitch@gimp.org>

	* app/tools/gimptool.[ch]
	* app/tools/tool_manager.[ch]: added boolean return value to
	GimpTool::key_press() which indicates if the event was handled.

	* app/tools/gimpcroptool.c
	* app/tools/gimpeditselectiontool.[ch]
	* app/tools/gimptransformtool.c
	* app/tools/gimpvectortool.c: return TRUE if the key event was handled.

	* app/tools/gimppainttool.c: removed key_press() implementation.

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimpcontrollerkeyboard.[ch]: new controller class
	which takes GdkEventKey and emits controller events for all
	combinations of modifiers and cursor keys.

	* app/widgets/gimpcontrollers.[ch]: added new function
	gimp_controllers_get_keyboard().

	* app/display/gimpdisplayshell-callbacks.c: if a key event was not
	handled by the active tool, dispatch it to the keyboard controller.

	* etc/controllerrc: add a keyboard controller which is configured
	to do the same as the removed gimp_paint_tool_key_press().
This commit is contained in:
Michael Natterer 2004-06-24 10:16:08 +00:00 committed by Michael Natterer
parent ffe9ac0772
commit 02b91f6628
20 changed files with 665 additions and 317 deletions

View File

@ -1,3 +1,31 @@
2004-06-24 Michael Natterer <mitch@gimp.org>
* app/tools/gimptool.[ch]
* app/tools/tool_manager.[ch]: added boolean return value to
GimpTool::key_press() which indicates if the event was handled.
* app/tools/gimpcroptool.c
* app/tools/gimpeditselectiontool.[ch]
* app/tools/gimptransformtool.c
* app/tools/gimpvectortool.c: return TRUE if the key event was handled.
* app/tools/gimppainttool.c: removed key_press() implementation.
* app/widgets/Makefile.am
* app/widgets/widgets-types.h
* app/widgets/gimpcontrollerkeyboard.[ch]: new controller class
which takes GdkEventKey and emits controller events for all
combinations of modifiers and cursor keys.
* app/widgets/gimpcontrollers.[ch]: added new function
gimp_controllers_get_keyboard().
* app/display/gimpdisplayshell-callbacks.c: if a key event was not
handled by the active tool, dispatch it to the keyboard controller.
* etc/controllerrc: add a keyboard controller which is configured
to do the same as the removed gimp_paint_tool_key_press().
2004-06-23 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* libgimp/gimpdrawable.c: added some documentation for

View File

@ -46,6 +46,7 @@
#include "widgets/gimpactiongroup.h"
#include "widgets/gimpcontrollers.h"
#include "widgets/gimpcontrollerkeyboard.h"
#include "widgets/gimpcontrollerwheel.h"
#include "widgets/gimpcursor.h"
#include "widgets/gimpdevices.h"
@ -1129,11 +1130,18 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
case GDK_Right:
case GDK_Up:
case GDK_Down:
if (! gimp_image_is_empty (gimage))
{
tool_manager_key_press_active (gimp,
if (gimp_image_is_empty (gimage) ||
! tool_manager_key_press_active (gimp,
kevent,
gdisp);
gdisp))
{
GimpController *keyboard;
keyboard = gimp_controllers_get_keyboard (gimp);
if (keyboard)
gimp_controller_keyboard_key_press (GIMP_CONTROLLER_KEYBOARD (keyboard),
kevent);
}
return_val = TRUE;

View File

@ -86,9 +86,6 @@ static void gimp_paint_tool_motion (GimpTool *tool,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_paint_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp);
static void gimp_paint_tool_modifier_key (GimpTool *tool,
GdkModifierType key,
gboolean press,
@ -169,7 +166,6 @@ gimp_paint_tool_class_init (GimpPaintToolClass *klass)
tool_class->button_press = gimp_paint_tool_button_press;
tool_class->button_release = gimp_paint_tool_button_release;
tool_class->motion = gimp_paint_tool_motion;
tool_class->key_press = gimp_paint_tool_key_press;
tool_class->modifier_key = gimp_paint_tool_modifier_key;
tool_class->oper_update = gimp_paint_tool_oper_update;
tool_class->cursor_update = gimp_paint_tool_cursor_update;
@ -548,40 +544,6 @@ gimp_paint_tool_motion (GimpTool *tool,
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
}
static void
gimp_paint_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp)
{
if (tool->gdisp)
{
GimpContext *context = GIMP_CONTEXT (tool->tool_info->tool_options);
gdouble opacity;
opacity = gimp_context_get_opacity (context);
switch (kevent->keyval)
{
case GDK_Left:
opacity = CLAMP (opacity - 0.01, 0, 1);
break;
case GDK_Right:
opacity = CLAMP (opacity + 0.01, 0, 1);
break;
case GDK_Up:
opacity = CLAMP (opacity + 0.1, 0, 1);
break;
case GDK_Down:
opacity = CLAMP (opacity - 0.1, 0, 1);
break;
default:
break;
}
gimp_context_set_opacity (context, opacity);
}
}
static void
gimp_paint_tool_modifier_key (GimpTool *tool,
GdkModifierType key,

View File

@ -93,7 +93,7 @@ static void gimp_crop_tool_motion (GimpTool *tool,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_crop_tool_key_press (GimpTool *tool,
static gboolean gimp_crop_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp);
static void gimp_crop_tool_modifier_key (GimpTool *tool,
@ -514,7 +514,7 @@ gimp_crop_tool_motion (GimpTool *tool,
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
}
static void
static gboolean
gimp_crop_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp)
@ -527,7 +527,7 @@ gimp_crop_tool_key_press (GimpTool *tool,
gint max_x, max_y;
if (gdisp != tool->gdisp)
return;
return FALSE;
inc_x = inc_y = 0;
@ -545,12 +545,14 @@ gimp_crop_tool_key_press (GimpTool *tool,
case GDK_Down:
inc_y = 1;
break;
case GDK_KP_Enter:
case GDK_Return:
crop_response (NULL, options->crop_mode, crop);
return;
return TRUE;
default:
return;
return FALSE;
}
/* If the shift key is down, move by an accelerated increment */
@ -606,6 +608,8 @@ gimp_crop_tool_key_press (GimpTool *tool,
crop_recalc (crop);
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
return TRUE;
}
static void

View File

@ -113,9 +113,6 @@ static void gimp_edit_selection_tool_motion (GimpTool *tool,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
void gimp_edit_selection_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp);
static void gimp_edit_selection_tool_draw (GimpDrawTool *tool);
@ -1051,7 +1048,7 @@ process_event_queue_keys (GdkEventKey *kevent,
#undef FILTER_MAX_KEYS
}
void
gboolean
gimp_edit_selection_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp)
@ -1071,7 +1068,7 @@ gimp_edit_selection_tool_key_press (GimpTool *tool,
kevent->keyval != GDK_Right &&
kevent->keyval != GDK_Up &&
kevent->keyval != GDK_Down)
return;
return FALSE;
/* check for mask translation first because the translate_layer
* modifiers match the translate_mask ones...
@ -1216,7 +1213,7 @@ gimp_edit_selection_tool_key_press (GimpTool *tool,
}
if (! item)
return;
return TRUE;
switch (edit_type)
{
@ -1297,4 +1294,6 @@ gimp_edit_selection_tool_key_press (GimpTool *tool,
gimp_undo_refresh_preview (undo);
gimp_image_flush (gdisp->gimage);
return TRUE;
}

View File

@ -39,7 +39,7 @@ void init_edit_selection (GimpTool *tool,
EditType edit_type);
void gimp_edit_selection_tool_key_press (GimpTool *tool,
gboolean gimp_edit_selection_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp);

View File

@ -86,9 +86,6 @@ static void gimp_paint_tool_motion (GimpTool *tool,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_paint_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp);
static void gimp_paint_tool_modifier_key (GimpTool *tool,
GdkModifierType key,
gboolean press,
@ -169,7 +166,6 @@ gimp_paint_tool_class_init (GimpPaintToolClass *klass)
tool_class->button_press = gimp_paint_tool_button_press;
tool_class->button_release = gimp_paint_tool_button_release;
tool_class->motion = gimp_paint_tool_motion;
tool_class->key_press = gimp_paint_tool_key_press;
tool_class->modifier_key = gimp_paint_tool_modifier_key;
tool_class->oper_update = gimp_paint_tool_oper_update;
tool_class->cursor_update = gimp_paint_tool_cursor_update;
@ -548,40 +544,6 @@ gimp_paint_tool_motion (GimpTool *tool,
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
}
static void
gimp_paint_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp)
{
if (tool->gdisp)
{
GimpContext *context = GIMP_CONTEXT (tool->tool_info->tool_options);
gdouble opacity;
opacity = gimp_context_get_opacity (context);
switch (kevent->keyval)
{
case GDK_Left:
opacity = CLAMP (opacity - 0.01, 0, 1);
break;
case GDK_Right:
opacity = CLAMP (opacity + 0.01, 0, 1);
break;
case GDK_Up:
opacity = CLAMP (opacity + 0.1, 0, 1);
break;
case GDK_Down:
opacity = CLAMP (opacity - 0.1, 0, 1);
break;
default:
break;
}
gimp_context_set_opacity (context, opacity);
}
}
static void
gimp_paint_tool_modifier_key (GimpTool *tool,
GdkModifierType key,

View File

@ -74,7 +74,7 @@ static void gimp_tool_real_motion (GimpTool *tool,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_tool_real_key_press (GimpTool *tool,
static gboolean gimp_tool_real_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp);
static void gimp_tool_real_modifier_key (GimpTool *tool,
@ -276,11 +276,12 @@ gimp_tool_real_motion (GimpTool *tool,
{
}
static void
static gboolean
gimp_tool_real_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp)
{
return FALSE;
}
static void
@ -442,16 +443,16 @@ gimp_tool_set_focus_display (GimpTool *tool,
}
}
void
gboolean
gimp_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp)
{
g_return_if_fail (GIMP_IS_TOOL (tool));
g_return_if_fail (GIMP_IS_DISPLAY (gdisp));
g_return_if_fail (gdisp == tool->focus_display);
g_return_val_if_fail (GIMP_IS_TOOL (tool), FALSE);
g_return_val_if_fail (GIMP_IS_DISPLAY (gdisp), FALSE);
g_return_val_if_fail (gdisp == tool->focus_display, FALSE);
GIMP_TOOL_GET_CLASS (tool)->key_press (tool, kevent, gdisp);
return GIMP_TOOL_GET_CLASS (tool)->key_press (tool, kevent, gdisp);
}
static void

View File

@ -82,7 +82,7 @@ struct _GimpToolClass
GdkModifierType state,
GimpDisplay *gdisp);
void (* key_press) (GimpTool *tool,
gboolean (* key_press) (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp);
void (* modifier_key) (GimpTool *tool,
@ -126,7 +126,7 @@ void gimp_tool_motion (GimpTool *tool,
GdkModifierType state,
GimpDisplay *gdisp);
void gimp_tool_key_press (GimpTool *tool,
gboolean gimp_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp);

View File

@ -100,7 +100,7 @@ static void gimp_transform_tool_motion (GimpTool *tool,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_transform_tool_key_press (GimpTool *tool,
static gboolean gimp_transform_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp);
static void gimp_transform_tool_modifier_key (GimpTool *tool,
@ -184,13 +184,9 @@ gimp_transform_tool_get_type (void)
static void
gimp_transform_tool_class_init (GimpTransformToolClass *klass)
{
GObjectClass *object_class;
GimpToolClass *tool_class;
GimpDrawToolClass *draw_class;
object_class = G_OBJECT_CLASS (klass);
tool_class = GIMP_TOOL_CLASS (klass);
draw_class = GIMP_DRAW_TOOL_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpDrawToolClass *draw_class = GIMP_DRAW_TOOL_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
@ -519,7 +515,7 @@ gimp_transform_tool_motion (GimpTool *tool,
#define RESPONSE_RESET 1
static void
static gboolean
gimp_transform_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp)
@ -534,17 +530,16 @@ gimp_transform_tool_key_press (GimpTool *tool,
case GDK_KP_Enter:
case GDK_Return:
gimp_transform_tool_response (NULL, GTK_RESPONSE_OK, trans_tool);
break;
return TRUE;
case GDK_Delete:
case GDK_BackSpace:
gimp_transform_tool_response (NULL, RESPONSE_RESET, trans_tool);
break;
return TRUE;
}
}
default:
break;
}
}
return FALSE;
}
static void

View File

@ -92,7 +92,7 @@ static void gimp_vector_tool_motion (GimpTool *tool,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_vector_tool_key_press (GimpTool *tool,
static gboolean gimp_vector_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp);
static void gimp_vector_tool_modifier_key (GimpTool *tool,
@ -783,7 +783,7 @@ gimp_vector_tool_motion (GimpTool *tool,
gimp_vectors_thaw (vector_tool->vectors);
}
static void
static gboolean
gimp_vector_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *gdisp)
@ -794,8 +794,8 @@ gimp_vector_tool_key_press (GimpTool *tool,
gdouble xdist, ydist;
gdouble pixels = 1.0;
if (!vector_tool->vectors)
return;
if (! vector_tool->vectors)
return TRUE;
shell = GIMP_DISPLAY_SHELL (draw_tool->gdisp->shell);
@ -811,9 +811,9 @@ gimp_vector_tool_key_press (GimpTool *tool,
{
case GDK_KP_Enter:
case GDK_Return:
gimp_vector_tool_to_selection_extended (vector_tool,
kevent->state);
gimp_vector_tool_to_selection_extended (vector_tool, kevent->state);
break;
case GDK_BackSpace:
case GDK_Delete:
gimp_vector_tool_delete_selected_anchors (vector_tool);
@ -833,21 +833,21 @@ gimp_vector_tool_key_press (GimpTool *tool,
switch (kevent->keyval)
{
case GDK_Left:
gimp_vector_tool_move_selected_anchors (vector_tool,
-xdist, 0);
gimp_vector_tool_move_selected_anchors (vector_tool, -xdist, 0);
break;
case GDK_Right:
gimp_vector_tool_move_selected_anchors (vector_tool,
xdist, 0);
gimp_vector_tool_move_selected_anchors (vector_tool, xdist, 0);
break;
case GDK_Up:
gimp_vector_tool_move_selected_anchors (vector_tool,
0, -ydist);
gimp_vector_tool_move_selected_anchors (vector_tool, 0, -ydist);
break;
case GDK_Down:
gimp_vector_tool_move_selected_anchors (vector_tool,
0, ydist);
gimp_vector_tool_move_selected_anchors (vector_tool, 0, ydist);
break;
default:
break;
}
@ -862,6 +862,8 @@ gimp_vector_tool_key_press (GimpTool *tool,
gimp_image_flush (gdisp->gimage);
}
return TRUE;
}
static void
@ -871,10 +873,9 @@ gimp_vector_tool_modifier_key (GimpTool *tool,
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpVectorTool *vector_tool;
GimpVectorTool *vector_tool = GIMP_VECTOR_TOOL (tool);
GimpVectorOptions *options;
vector_tool = GIMP_VECTOR_TOOL (tool);
options = GIMP_VECTOR_OPTIONS (tool->tool_info->tool_options);
if (key == TOGGLE_MASK)

View File

@ -328,23 +328,25 @@ tool_manager_motion_active (Gimp *gimp,
}
}
void
gboolean
tool_manager_key_press_active (Gimp *gimp,
GdkEventKey *kevent,
GimpDisplay *gdisp)
{
GimpToolManager *tool_manager;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
tool_manager = tool_manager_get (gimp);
if (tool_manager->active_tool)
{
gimp_tool_key_press (tool_manager->active_tool,
return gimp_tool_key_press (tool_manager->active_tool,
kevent,
gdisp);
}
return FALSE;
}
void

View File

@ -53,7 +53,7 @@ void tool_manager_motion_active (Gimp *gimp,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
void tool_manager_key_press_active (Gimp *gimp,
gboolean tool_manager_key_press_active (Gimp *gimp,
GdkEventKey *kevent,
GimpDisplay *gdisp);

View File

@ -75,6 +75,8 @@ libappwidgets_a_sources = \
gimpcontrollerinfo.h \
gimpcontrollers.c \
gimpcontrollers.h \
gimpcontrollerkeyboard.c \
gimpcontrollerkeyboard.h \
gimpcontrollerwheel.c \
gimpcontrollerwheel.h \
gimpcursor.c \

View File

@ -0,0 +1,293 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcontrollerkeyboard.c
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
*
* This library 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 of the License, or (at your option) any later version.
*
* This library 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "gimpcontrollerkeyboard.h"
#include "gimp-intl.h"
typedef struct _KeyboardEvent KeyboardEvent;
struct _KeyboardEvent
{
guint keyval;
GdkModifierType modifiers;
const gchar *name;
const gchar *blurb;
};
static void gimp_controller_keyboard_class_init (GimpControllerKeyboardClass *klass);
static void gimp_controller_keyboard_init (GimpControllerKeyboard *keyboard);
static GObject * gimp_controller_keyboard_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static gint gimp_controller_keyboard_get_n_events (GimpController *controller);
static const gchar * gimp_controller_keyboard_get_event_name (GimpController *controller,
gint event_id);
static const gchar * gimp_controller_keyboard_get_event_blurb (GimpController *controller,
gint event_id);
static GimpControllerClass *parent_class = NULL;
static const KeyboardEvent keyboard_events[] =
{
{ GDK_Up, GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"key-up-shift-control-alt",
N_("Key Up (Shift + Control + Alt)") },
{ GDK_Up, GDK_MOD1_MASK | GDK_CONTROL_MASK,
"key-up-control-alt",
N_("Key Up (Control + Alt)") },
{ GDK_Up, GDK_MOD1_MASK | GDK_SHIFT_MASK,
"key-up-shift-alt",
N_("Key Up (Shift + Alt)") },
{ GDK_Up, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"key-up-shift-control",
N_("Key Up (Shift + Control)") },
{ GDK_Up, GDK_MOD1_MASK,
"key-up-alt",
N_("Key Up (Alt)") },
{ GDK_Up, GDK_CONTROL_MASK,
"key-up-control",
N_("Key Up (Control)") },
{ GDK_Up, GDK_SHIFT_MASK,
"key-up-shift",
N_("Key Up (Shift)") },
{ GDK_Up, 0,
"key-up",
N_("Key Up") },
{ GDK_Down, GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"key-down-shift-control-alt",
N_("Key Down (Shift + Control + Alt)") },
{ GDK_Down, GDK_MOD1_MASK | GDK_CONTROL_MASK,
"key-down-control-alt",
N_("Key Down (Control + Alt)") },
{ GDK_Down, GDK_MOD1_MASK | GDK_SHIFT_MASK,
"key-down-shift-alt",
N_("Key Down (Shift + Alt)") },
{ GDK_Down, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"key-down-shift-control",
N_("Key Down (Shift + Control)") },
{ GDK_Down, GDK_MOD1_MASK,
"key-down-alt",
N_("Key Down (Alt)") },
{ GDK_Down, GDK_CONTROL_MASK,
"key-down-control",
N_("Key Down (Control)") },
{ GDK_Down, GDK_SHIFT_MASK,
"key-down-shift",
N_("Key Down (Shift)") },
{ GDK_Down, 0,
"key-down",
N_("Key Down") },
{ GDK_Left, GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"key-left-shift-control-alt",
N_("Key Left (Shift + Control + Alt)") },
{ GDK_Left, GDK_MOD1_MASK | GDK_CONTROL_MASK,
"key-left-control-alt",
N_("Key Left (Control + Alt)") },
{ GDK_Left, GDK_MOD1_MASK | GDK_SHIFT_MASK,
"key-left-shift-alt",
N_("Key Left (Shift + Alt)") },
{ GDK_Left, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"key-left-shift-control",
N_("Key Left (Shift + Control)") },
{ GDK_Left, GDK_MOD1_MASK,
"key-left-alt",
N_("Key Left (Alt)") },
{ GDK_Left, GDK_CONTROL_MASK,
"key-left-control",
N_("Key Left (Control)") },
{ GDK_Left, GDK_SHIFT_MASK,
"key-left-shift",
N_("Key Left (Shift)") },
{ GDK_Left, 0,
"key-left",
N_("Key Left") },
{ GDK_Right, GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"key-right-shift-control-alt",
N_("Key Right (Shift + Control + Alt)") },
{ GDK_Right, GDK_MOD1_MASK | GDK_CONTROL_MASK,
"key-right-control-alt",
N_("Key Right (Control + Alt)") },
{ GDK_Right, GDK_MOD1_MASK | GDK_SHIFT_MASK,
"key-right-shift-alt",
N_("Key Right (Shift + Alt)") },
{ GDK_Right, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"key-right-shift-control",
N_("Key Right (Shift + Control)") },
{ GDK_Right, GDK_MOD1_MASK,
"key-right-alt",
N_("Key Right (Alt)") },
{ GDK_Right, GDK_CONTROL_MASK,
"key-right-control",
N_("Key Right (Control)") },
{ GDK_Right, GDK_SHIFT_MASK,
"key-right-shift",
N_("Key Right (Shift)") },
{ GDK_Right, 0,
"key-right",
N_("Key Right") }
};
GType
gimp_controller_keyboard_get_type (void)
{
static GType controller_type = 0;
if (! controller_type)
{
static const GTypeInfo controller_info =
{
sizeof (GimpControllerKeyboardClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_controller_keyboard_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpControllerKeyboard),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_controller_keyboard_init,
};
controller_type = g_type_register_static (GIMP_TYPE_CONTROLLER,
"GimpControllerKeyboard",
&controller_info, 0);
}
return controller_type;
}
static void
gimp_controller_keyboard_class_init (GimpControllerKeyboardClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpControllerClass *controller_class = GIMP_CONTROLLER_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->constructor = gimp_controller_keyboard_constructor;
controller_class->name = _("Keyboard");
controller_class->get_n_events = gimp_controller_keyboard_get_n_events;
controller_class->get_event_name = gimp_controller_keyboard_get_event_name;
controller_class->get_event_blurb = gimp_controller_keyboard_get_event_blurb;
}
static void
gimp_controller_keyboard_init (GimpControllerKeyboard *keyboard)
{
}
static GObject *
gimp_controller_keyboard_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
g_object_set (object, "name", _("Main Keyboard"), NULL);
return object;
}
static gint
gimp_controller_keyboard_get_n_events (GimpController *controller)
{
return G_N_ELEMENTS (keyboard_events);
}
static const gchar *
gimp_controller_keyboard_get_event_name (GimpController *controller,
gint event_id)
{
if (event_id < 0 || event_id >= G_N_ELEMENTS (keyboard_events))
return NULL;
return keyboard_events[event_id].name;
}
static const gchar *
gimp_controller_keyboard_get_event_blurb (GimpController *controller,
gint event_id)
{
if (event_id < 0 || event_id >= G_N_ELEMENTS (keyboard_events))
return NULL;
return gettext (keyboard_events[event_id].blurb);
}
gboolean
gimp_controller_keyboard_key_press (GimpControllerKeyboard *keyboard,
const GdkEventKey *kevent)
{
gint i;
g_return_val_if_fail (GIMP_IS_CONTROLLER_KEYBOARD (keyboard), FALSE);
g_return_val_if_fail (kevent != NULL, FALSE);
for (i = 0; i < G_N_ELEMENTS (keyboard_events); i++)
{
if (keyboard_events[i].keyval == kevent->keyval)
{
if ((keyboard_events[i].modifiers & kevent->state) ==
keyboard_events[i].modifiers)
{
GimpControllerEvent controller_event;
GimpControllerEventTrigger *trigger;
trigger = (GimpControllerEventTrigger *) &controller_event;
trigger->type = GIMP_CONTROLLER_EVENT_TRIGGER;
trigger->source = GIMP_CONTROLLER (keyboard);
trigger->event_id = i;
if (gimp_controller_event (GIMP_CONTROLLER (keyboard),
&controller_event))
{
return TRUE;
}
}
}
}
return FALSE;
}

View File

@ -0,0 +1,57 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcontrollerkeyboard.h
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
*
* This library 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 of the License, or (at your option) any later version.
*
* This library 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_CONTROLLER_WHELL_H__
#define __GIMP_CONTROLLER_KEYBOARD_H__
#include "libgimpwidgets/gimpcontroller.h"
#define GIMP_TYPE_CONTROLLER_KEYBOARD (gimp_controller_keyboard_get_type ())
#define GIMP_CONTROLLER_KEYBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CONTROLLER_KEYBOARD, GimpControllerKeyboard))
#define GIMP_CONTROLLER_KEYBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CONTROLLER_KEYBOARD, GimpControllerKeyboardClass))
#define GIMP_IS_CONTROLLER_KEYBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CONTROLLER_KEYBOARD))
#define GIMP_IS_CONTROLLER_KEYBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CONTROLLER_KEYBOARD))
#define GIMP_CONTROLLER_KEYBOARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CONTROLLER_KEYBOARD, GimpControllerKeyboardClass))
typedef struct _GimpControllerKeyboardClass GimpControllerKeyboardClass;
struct _GimpControllerKeyboard
{
GimpController parent_instance;
};
struct _GimpControllerKeyboardClass
{
GimpControllerClass parent_class;
};
GType gimp_controller_keyboard_get_type (void) G_GNUC_CONST;
gboolean gimp_controller_keyboard_key_press (GimpControllerKeyboard *keyboard,
const GdkEventKey *kevent);
#endif /* __GIMP_CONTROLLER_KEYBOARD_H__ */

View File

@ -38,6 +38,7 @@
#include "gimpcontrollerinfo.h"
#include "gimpcontrollers.h"
#include "gimpcontrollerkeyboard.h"
#include "gimpcontrollerwheel.h"
#include "gimpenumaction.h"
#include "gimpuimanager.h"
@ -55,6 +56,7 @@ struct _GimpControllerManager
GimpContainer *controllers;
GQuark event_mapped_id;
GimpController *wheel;
GimpController *keyboard;
GimpUIManager *ui_manager;
};
@ -122,6 +124,7 @@ gimp_controllers_init (Gimp *gimp)
}
g_type_class_ref (GIMP_TYPE_CONTROLLER_WHEEL);
g_type_class_ref (GIMP_TYPE_CONTROLLER_KEYBOARD);
}
void
@ -133,6 +136,7 @@ gimp_controllers_exit (Gimp *gimp)
g_object_set_data (G_OBJECT (gimp), GIMP_CONTROLLER_MANAGER_DATA_KEY, NULL);
g_type_class_unref (g_type_class_peek (GIMP_TYPE_CONTROLLER_WHEEL));
g_type_class_unref (g_type_class_peek (GIMP_TYPE_CONTROLLER_KEYBOARD));
}
void
@ -247,6 +251,21 @@ gimp_controllers_get_wheel (Gimp *gimp)
return manager->wheel;
}
GimpController *
gimp_controllers_get_keyboard (Gimp *gimp)
{
GimpControllerManager *manager;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
manager = gimp_controller_manager_get (gimp);
g_return_val_if_fail (manager != NULL, NULL);
return manager->keyboard;
}
/* private functions */
static GimpControllerManager *
@ -274,6 +293,8 @@ gimp_controllers_add (GimpContainer *container,
{
if (GIMP_IS_CONTROLLER_WHEEL (info->controller))
manager->wheel = info->controller;
else if (GIMP_IS_CONTROLLER_KEYBOARD (info->controller))
manager->keyboard = info->controller;
}
static void
@ -283,6 +304,8 @@ gimp_controllers_remove (GimpContainer *container,
{
if (info->controller == manager->wheel)
manager->wheel = NULL;
else if (info->controller == manager->keyboard)
manager->keyboard = NULL;
}
static gboolean

View File

@ -32,6 +32,7 @@ void gimp_controllers_save (Gimp *gimp);
GimpContainer * gimp_controllers_get_list (Gimp *gimp);
GimpController * gimp_controllers_get_wheel (Gimp *gimp);
GimpController * gimp_controllers_get_keyboard (Gimp *gimp);
#endif /* __GIMP_CONTROLLERS_H__ */

View File

@ -57,6 +57,7 @@ typedef struct _GimpPreviewRendererImagefile GimpPreviewRendererImagefile;
typedef struct _GimpPreviewRendererVectors GimpPreviewRendererVectors;
typedef struct _GimpControllerInfo GimpControllerInfo;
typedef struct _GimpControllerKeyboard GimpControllerKeyboard;
typedef struct _GimpControllerWheel GimpControllerWheel;

View File

@ -15,6 +15,15 @@
(map "scroll-up-shift-control-alt" "context-font-next")))
(map "scroll-down-shift-control-alt" "context-font-previous")
(GimpControllerInfo "Main Keyboard"
(enabled yes)
(controller "GimpControllerKeyboard")
(mapping
(map "key-up" "context-opacity-increase-skip")
(map "key-down" "context-opacity-decrease-skip")
(map "key-left" "context-opacity-decrease")
(map "key-right" "context-opacity-increase")))
# (GimpControllerInfo "LinuxInput"
# (enabled yes)
# (controller "ControllerLinuxInput"