Imported Upstream version 2.3.15

This commit is contained in:
Ari Pollak
2010-08-11 01:21:06 -04:00
parent aca02f7697
commit d694295a3e
819 changed files with 63117 additions and 44484 deletions

View File

@ -25,10 +25,19 @@ cdisplay_lcms_module = libcdisplay_lcms.la
cdisplay_proof_module = libcdisplay_proof.la
endif
if PLATFORM_WIN32
else
controller_midi_module = libcontroller_midi.la
endif
if HAVE_LINUX_INPUT
controller_linux_input_module = libcontroller_linux_input.la
endif
if HAVE_DX_DINPUT
controller_dx_dinput_module = libcontroller_dx_dinput.la
endif
lib_LTLIBRARIES = \
libcolorsel_cmyk.la \
libcolorsel_triangle.la \
@ -38,8 +47,9 @@ lib_LTLIBRARIES = \
libcdisplay_highcontrast.la \
$(cdisplay_lcms_module) \
$(cdisplay_proof_module) \
libcontroller_midi.la \
$(controller_linux_input_module)
$(controller_midi_module) \
$(controller_linux_input_module)\
$(controller_dx_dinput_module)
modules_libadd = $(libgimpmodule) $(libgimpwidgets) $(GTK_LIBS)
@ -86,9 +96,23 @@ libcdisplay_proof_la_SOURCES = cdisplay_proof.c
libcdisplay_proof_la_LDFLAGS = -avoid-version -module $(no_undefined)
libcdisplay_proof_la_LIBADD = $(cdisplay_libadd) $(LIBLCMS)
libcontroller_linux_input_la_SOURCES = controller_linux_input.c
libcontroller_linux_input_la_SOURCES = \
gimpinputdevicestore.c \
gimpinputdevicestore.h \
controller_linux_input.c
libcontroller_linux_input_la_CFLAGS = $(DBUS_GLIB_CFLAGS) $(HAL_CFLAGS)
libcontroller_linux_input_la_LDFLAGS = -avoid-version -module $(no_undefined)
libcontroller_linux_input_la_LIBADD = $(controller_libadd)
libcontroller_linux_input_la_LIBADD = \
$(controller_libadd) $(DBUS_GLIB_LIBS) $(HAL_LIBS)
libcontroller_dx_dinput_la_SOURCES = \
gimpinputdevicestore.c \
gimpinputdevicestore.h \
controller_dx_dinput.c
# Use -Wl to avoid libtool lossage
libcontroller_dx_dinput_la_LDFLAGS = -avoid-version -module $(no_undefined) -Wl,-ldinput8 -Wl,-ldxguid
libcontroller_dx_dinput_la_LIBADD = \
$(controller_libadd) -lrpcrt4
libcontroller_midi_la_SOURCES = controller_midi.c
libcontroller_midi_la_CFLAGS = $(ALSA_CFLAGS)

View File

@ -111,8 +111,18 @@ libcolorsel_water_la_DEPENDENCIES = $(am__DEPENDENCIES_9)
am_libcolorsel_water_la_OBJECTS = colorsel_water.lo
libcolorsel_water_la_OBJECTS = $(am_libcolorsel_water_la_OBJECTS)
am__DEPENDENCIES_10 = $(am__DEPENDENCIES_6)
libcontroller_linux_input_la_DEPENDENCIES = $(am__DEPENDENCIES_10)
am_libcontroller_linux_input_la_OBJECTS = controller_linux_input.lo
libcontroller_dx_dinput_la_DEPENDENCIES = $(am__DEPENDENCIES_10)
am_libcontroller_dx_dinput_la_OBJECTS = gimpinputdevicestore.lo \
controller_dx_dinput.lo
libcontroller_dx_dinput_la_OBJECTS = \
$(am_libcontroller_dx_dinput_la_OBJECTS)
@HAVE_DX_DINPUT_TRUE@am_libcontroller_dx_dinput_la_rpath = -rpath \
@HAVE_DX_DINPUT_TRUE@ $(libdir)
libcontroller_linux_input_la_DEPENDENCIES = $(am__DEPENDENCIES_10) \
$(am__DEPENDENCIES_5) $(am__DEPENDENCIES_5)
am_libcontroller_linux_input_la_OBJECTS = \
libcontroller_linux_input_la-gimpinputdevicestore.lo \
libcontroller_linux_input_la-controller_linux_input.lo
libcontroller_linux_input_la_OBJECTS = \
$(am_libcontroller_linux_input_la_OBJECTS)
@HAVE_LINUX_INPUT_TRUE@am_libcontroller_linux_input_la_rpath = -rpath \
@ -122,6 +132,8 @@ libcontroller_midi_la_DEPENDENCIES = $(am__DEPENDENCIES_10) \
am_libcontroller_midi_la_OBJECTS = \
libcontroller_midi_la-controller_midi.lo
libcontroller_midi_la_OBJECTS = $(am_libcontroller_midi_la_OBJECTS)
@PLATFORM_WIN32_FALSE@am_libcontroller_midi_la_rpath = -rpath \
@PLATFORM_WIN32_FALSE@ $(libdir)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
@ -140,6 +152,7 @@ SOURCES = $(libcdisplay_colorblind_la_SOURCES) \
$(libcolorsel_cmyk_la_SOURCES) \
$(libcolorsel_triangle_la_SOURCES) \
$(libcolorsel_water_la_SOURCES) \
$(libcontroller_dx_dinput_la_SOURCES) \
$(libcontroller_linux_input_la_SOURCES) \
$(libcontroller_midi_la_SOURCES)
DIST_SOURCES = $(libcdisplay_colorblind_la_SOURCES) \
@ -149,6 +162,7 @@ DIST_SOURCES = $(libcdisplay_colorblind_la_SOURCES) \
$(am__libcolorsel_cmyk_la_SOURCES_DIST) \
$(libcolorsel_triangle_la_SOURCES) \
$(libcolorsel_water_la_SOURCES) \
$(libcontroller_dx_dinput_la_SOURCES) \
$(libcontroller_linux_input_la_SOURCES) \
$(libcontroller_midi_la_SOURCES)
ETAGS = etags
@ -280,6 +294,10 @@ GTK_DOC_USE_LIBTOOL_FALSE = @GTK_DOC_USE_LIBTOOL_FALSE@
GTK_DOC_USE_LIBTOOL_TRUE = @GTK_DOC_USE_LIBTOOL_TRUE@
GTK_LIBS = @GTK_LIBS@
GTK_REQUIRED_VERSION = @GTK_REQUIRED_VERSION@
HAL_CFLAGS = @HAL_CFLAGS@
HAL_LIBS = @HAL_LIBS@
HAVE_DX_DINPUT_FALSE = @HAVE_DX_DINPUT_FALSE@
HAVE_DX_DINPUT_TRUE = @HAVE_DX_DINPUT_TRUE@
HAVE_FINITE = @HAVE_FINITE@
HAVE_GLIBC_REGEX = @HAVE_GLIBC_REGEX@
HAVE_GLIBC_REGEX_FALSE = @HAVE_GLIBC_REGEX_FALSE@
@ -533,7 +551,9 @@ EXTRA_DIST = \
@HAVE_LCMS_TRUE@cdisplay_lcms_module = libcdisplay_lcms.la
@HAVE_LCMS_TRUE@cdisplay_proof_module = libcdisplay_proof.la
@PLATFORM_WIN32_FALSE@controller_midi_module = libcontroller_midi.la
@HAVE_LINUX_INPUT_TRUE@controller_linux_input_module = libcontroller_linux_input.la
@HAVE_DX_DINPUT_TRUE@controller_dx_dinput_module = libcontroller_dx_dinput.la
lib_LTLIBRARIES = \
libcolorsel_cmyk.la \
libcolorsel_triangle.la \
@ -543,8 +563,9 @@ lib_LTLIBRARIES = \
libcdisplay_highcontrast.la \
$(cdisplay_lcms_module) \
$(cdisplay_proof_module) \
libcontroller_midi.la \
$(controller_linux_input_module)
$(controller_midi_module) \
$(controller_linux_input_module)\
$(controller_dx_dinput_module)
modules_libadd = $(libgimpmodule) $(libgimpwidgets) $(GTK_LIBS)
colorsel_libadd = $(libgimpcolor) $(modules_libadd)
@ -576,9 +597,26 @@ libcdisplay_lcms_la_LIBADD = $(cdisplay_libadd) $(LIBLCMS)
libcdisplay_proof_la_SOURCES = cdisplay_proof.c
libcdisplay_proof_la_LDFLAGS = -avoid-version -module $(no_undefined)
libcdisplay_proof_la_LIBADD = $(cdisplay_libadd) $(LIBLCMS)
libcontroller_linux_input_la_SOURCES = controller_linux_input.c
libcontroller_linux_input_la_SOURCES = \
gimpinputdevicestore.c \
gimpinputdevicestore.h \
controller_linux_input.c
libcontroller_linux_input_la_CFLAGS = $(DBUS_GLIB_CFLAGS) $(HAL_CFLAGS)
libcontroller_linux_input_la_LDFLAGS = -avoid-version -module $(no_undefined)
libcontroller_linux_input_la_LIBADD = $(controller_libadd)
libcontroller_linux_input_la_LIBADD = \
$(controller_libadd) $(DBUS_GLIB_LIBS) $(HAL_LIBS)
libcontroller_dx_dinput_la_SOURCES = \
gimpinputdevicestore.c \
gimpinputdevicestore.h \
controller_dx_dinput.c
# Use -Wl to avoid libtool lossage
libcontroller_dx_dinput_la_LDFLAGS = -avoid-version -module $(no_undefined) -Wl,-ldinput8 -Wl,-ldxguid
libcontroller_dx_dinput_la_LIBADD = \
$(controller_libadd) -lrpcrt4
libcontroller_midi_la_SOURCES = controller_midi.c
libcontroller_midi_la_CFLAGS = $(ALSA_CFLAGS)
libcontroller_midi_la_LDFLAGS = -avoid-version -module $(no_undefined)
@ -659,10 +697,12 @@ libcolorsel_triangle.la: $(libcolorsel_triangle_la_OBJECTS) $(libcolorsel_triang
$(LINK) -rpath $(libdir) $(libcolorsel_triangle_la_LDFLAGS) $(libcolorsel_triangle_la_OBJECTS) $(libcolorsel_triangle_la_LIBADD) $(LIBS)
libcolorsel_water.la: $(libcolorsel_water_la_OBJECTS) $(libcolorsel_water_la_DEPENDENCIES)
$(LINK) -rpath $(libdir) $(libcolorsel_water_la_LDFLAGS) $(libcolorsel_water_la_OBJECTS) $(libcolorsel_water_la_LIBADD) $(LIBS)
libcontroller_dx_dinput.la: $(libcontroller_dx_dinput_la_OBJECTS) $(libcontroller_dx_dinput_la_DEPENDENCIES)
$(LINK) $(am_libcontroller_dx_dinput_la_rpath) $(libcontroller_dx_dinput_la_LDFLAGS) $(libcontroller_dx_dinput_la_OBJECTS) $(libcontroller_dx_dinput_la_LIBADD) $(LIBS)
libcontroller_linux_input.la: $(libcontroller_linux_input_la_OBJECTS) $(libcontroller_linux_input_la_DEPENDENCIES)
$(LINK) $(am_libcontroller_linux_input_la_rpath) $(libcontroller_linux_input_la_LDFLAGS) $(libcontroller_linux_input_la_OBJECTS) $(libcontroller_linux_input_la_LIBADD) $(LIBS)
libcontroller_midi.la: $(libcontroller_midi_la_OBJECTS) $(libcontroller_midi_la_DEPENDENCIES)
$(LINK) -rpath $(libdir) $(libcontroller_midi_la_LDFLAGS) $(libcontroller_midi_la_OBJECTS) $(libcontroller_midi_la_LIBADD) $(LIBS)
$(LINK) $(am_libcontroller_midi_la_rpath) $(libcontroller_midi_la_LDFLAGS) $(libcontroller_midi_la_OBJECTS) $(libcontroller_midi_la_LIBADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@ -679,7 +719,10 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/colorsel_cmyk_lcms.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/colorsel_triangle.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/colorsel_water.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/controller_linux_input.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/controller_dx_dinput.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gimpinputdevicestore.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcontroller_linux_input_la-controller_linux_input.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcontroller_linux_input_la-gimpinputdevicestore.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcontroller_midi_la-controller_midi.Plo@am__quote@
.c.o:
@ -703,6 +746,20 @@ distclean-compile:
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
libcontroller_linux_input_la-gimpinputdevicestore.lo: gimpinputdevicestore.c
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcontroller_linux_input_la_CFLAGS) $(CFLAGS) -MT libcontroller_linux_input_la-gimpinputdevicestore.lo -MD -MP -MF "$(DEPDIR)/libcontroller_linux_input_la-gimpinputdevicestore.Tpo" -c -o libcontroller_linux_input_la-gimpinputdevicestore.lo `test -f 'gimpinputdevicestore.c' || echo '$(srcdir)/'`gimpinputdevicestore.c; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcontroller_linux_input_la-gimpinputdevicestore.Tpo" "$(DEPDIR)/libcontroller_linux_input_la-gimpinputdevicestore.Plo"; else rm -f "$(DEPDIR)/libcontroller_linux_input_la-gimpinputdevicestore.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='gimpinputdevicestore.c' object='libcontroller_linux_input_la-gimpinputdevicestore.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcontroller_linux_input_la_CFLAGS) $(CFLAGS) -c -o libcontroller_linux_input_la-gimpinputdevicestore.lo `test -f 'gimpinputdevicestore.c' || echo '$(srcdir)/'`gimpinputdevicestore.c
libcontroller_linux_input_la-controller_linux_input.lo: controller_linux_input.c
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcontroller_linux_input_la_CFLAGS) $(CFLAGS) -MT libcontroller_linux_input_la-controller_linux_input.lo -MD -MP -MF "$(DEPDIR)/libcontroller_linux_input_la-controller_linux_input.Tpo" -c -o libcontroller_linux_input_la-controller_linux_input.lo `test -f 'controller_linux_input.c' || echo '$(srcdir)/'`controller_linux_input.c; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcontroller_linux_input_la-controller_linux_input.Tpo" "$(DEPDIR)/libcontroller_linux_input_la-controller_linux_input.Plo"; else rm -f "$(DEPDIR)/libcontroller_linux_input_la-controller_linux_input.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='controller_linux_input.c' object='libcontroller_linux_input_la-controller_linux_input.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcontroller_linux_input_la_CFLAGS) $(CFLAGS) -c -o libcontroller_linux_input_la-controller_linux_input.lo `test -f 'controller_linux_input.c' || echo '$(srcdir)/'`controller_linux_input.c
libcontroller_midi_la-controller_midi.lo: controller_midi.c
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcontroller_midi_la_CFLAGS) $(CFLAGS) -MT libcontroller_midi_la-controller_midi.lo -MD -MP -MF "$(DEPDIR)/libcontroller_midi_la-controller_midi.Tpo" -c -o libcontroller_midi_la-controller_midi.lo `test -f 'controller_midi.c' || echo '$(srcdir)/'`controller_midi.c; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcontroller_midi_la-controller_midi.Tpo" "$(DEPDIR)/libcontroller_midi_la-controller_midi.Plo"; else rm -f "$(DEPDIR)/libcontroller_midi_la-controller_midi.Tpo"; exit 1; fi

View File

@ -263,6 +263,8 @@ cdisplay_colorblind_deficiency_get_type (GTypeModule *module)
g_type_module_register_enum (module, "CDisplayColorblindDeficiency",
enum_values);
gimp_type_set_translation_domain (cdisplay_colorblind_deficiency_type,
GETTEXT_PACKAGE "-libgimp");
gimp_enum_set_value_descriptions (cdisplay_colorblind_deficiency_type,
enum_descs);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +1,23 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* controller_linux_input.c
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
* Copyright (C) 2004-2007 Sven Neumann <sven@gimp.org>
* 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 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 library is distributed in the hope that it will be useful,
* 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.
* 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 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.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
@ -41,6 +41,8 @@
#define GIMP_ENABLE_CONTROLLER_UNDER_CONSTRUCTION
#include "libgimpwidgets/gimpcontroller.h"
#include "gimpinputdevicestore.h"
#include "libgimp/libgimp-intl.h"
@ -70,7 +72,8 @@ static const LinuxInputEvent key_events[] =
{ BTN_SIDE, "button-side", N_("Button Side") },
{ BTN_EXTRA, "button-extra", N_("Button Extra") },
{ BTN_FORWARD, "button-forward", N_("Button Forward") },
{ BTN_BACK, "button-back", N_("Button Forward") },
{ BTN_BACK, "button-back", N_("Button Back") },
{ BTN_TASK, "button-task", N_("Button Task") },
#ifdef BTN_WHEEL
{ BTN_WHEEL, "button-wheel", N_("Button Wheel") },
#endif
@ -110,7 +113,8 @@ static const LinuxInputEvent rel_events[] =
enum
{
PROP_0,
PROP_DEVICE
PROP_DEVICE,
PROP_DEVICE_STORE
};
@ -126,11 +130,12 @@ typedef struct _ControllerLinuxInputClass ControllerLinuxInputClass;
struct _ControllerLinuxInput
{
GimpController parent_instance;
GimpController parent_instance;
gchar *device;
GIOChannel *io;
guint io_id;
GimpInputDeviceStore *store;
gchar *device;
GIOChannel *io;
guint io_id;
};
struct _ControllerLinuxInputClass
@ -141,7 +146,9 @@ struct _ControllerLinuxInputClass
GType linux_input_get_type (GTypeModule *module);
static void linux_input_class_init (ControllerLinuxInputClass *klass);
static void linux_input_init (ControllerLinuxInput *controller);
static void linux_input_dispose (GObject *object);
static void linux_input_finalize (GObject *object);
static void linux_input_set_property (GObject *object,
guint property_id,
const GValue *value,
@ -157,21 +164,23 @@ static const gchar * linux_input_get_event_name (GimpController *controller,
static const gchar * linux_input_get_event_blurb (GimpController *controller,
gint event_id);
static gboolean linux_input_set_device (ControllerLinuxInput *controller,
const gchar *device);
static gboolean linux_input_read_event (GIOChannel *io,
GIOCondition cond,
gpointer data);
static void linux_input_device_changed (ControllerLinuxInput *controller,
const gchar *udi);
static gboolean linux_input_set_device (ControllerLinuxInput *controller,
const gchar *device);
static gboolean linux_input_read_event (GIOChannel *io,
GIOCondition cond,
gpointer data);
static const GimpModuleInfo linux_input_info =
{
GIMP_MODULE_ABI_VERSION,
N_("Linux input event controller"),
"Sven Neumann <sven@gimp.org>",
"v0.1",
"(c) 2004, released under the GPL",
"June 2004"
"Sven Neumann <sven@gimp.org>, Michael Natterer <mitch@gimp.org>",
"v0.2",
"(c) 2004-2007, released under the GPL",
"2004-2007"
};
@ -188,6 +197,7 @@ gimp_module_query (GTypeModule *module)
G_MODULE_EXPORT gboolean
gimp_module_register (GTypeModule *module)
{
gimp_input_device_store_get_type (module);
linux_input_get_type (module);
return TRUE;
@ -209,7 +219,7 @@ linux_input_get_type (GTypeModule *module)
NULL, /* class_data */
sizeof (ControllerLinuxInput),
0, /* n_preallocs */
NULL /* instance_init */
(GInstanceInitFunc) linux_input_init
};
controller_type = g_type_module_register_type (module,
@ -230,6 +240,7 @@ linux_input_class_init (ControllerLinuxInputClass *klass)
parent_class = g_type_class_peek_parent (klass);
object_class->dispose = linux_input_dispose;
object_class->finalize = linux_input_finalize;
object_class->get_property = linux_input_get_property;
object_class->set_property = linux_input_set_property;
@ -239,6 +250,13 @@ linux_input_class_init (ControllerLinuxInputClass *klass)
_("The name of the device to read Linux Input events from."),
NULL,
GIMP_CONFIG_PARAM_FLAGS));
#ifdef HAVE_LIBHAL
g_object_class_install_property (object_class, PROP_DEVICE_STORE,
g_param_spec_object ("device-values",
NULL, NULL,
GIMP_TYPE_INPUT_DEVICE_STORE,
G_PARAM_READABLE));
#endif
controller_class->name = _("Linux Input");
controller_class->help_id = "gimp-controller-linux-input";
@ -249,6 +267,22 @@ linux_input_class_init (ControllerLinuxInputClass *klass)
controller_class->get_event_blurb = linux_input_get_event_blurb;
}
static void
linux_input_init (ControllerLinuxInput *controller)
{
controller->store = gimp_input_device_store_new ();
if (controller->store)
{
g_signal_connect_swapped (controller->store, "device-added",
G_CALLBACK (linux_input_device_changed),
controller);
g_signal_connect_swapped (controller->store, "device-removed",
G_CALLBACK (linux_input_device_changed),
controller);
}
}
static void
linux_input_dispose (GObject *object)
{
@ -259,6 +293,20 @@ linux_input_dispose (GObject *object)
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
linux_input_finalize (GObject *object)
{
ControllerLinuxInput *controller = CONTROLLER_LINUX_INPUT (object);
if (controller->store)
{
g_object_unref (controller->store);
controller->store = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
linux_input_set_property (GObject *object,
guint property_id,
@ -291,6 +339,9 @@ linux_input_get_property (GObject *object,
case PROP_DEVICE:
g_value_set_string (value, controller->device);
break;
case PROP_DEVICE_STORE:
g_value_set_object (value, controller->store);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -347,10 +398,130 @@ linux_input_get_event_blurb (GimpController *controller,
}
}
#define BITS_PER_LONG (sizeof(long) * 8)
#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
#define OFF(x) ((x)%BITS_PER_LONG)
#define BIT(x) (1UL<<OFF(x))
#define LONG(x) ((x)/BITS_PER_LONG)
#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
static void
linux_input_get_device_info (ControllerLinuxInput *controller,
int fd)
{
unsigned long evbit[NBITS (EV_MAX)];
unsigned long keybit[NBITS (KEY_MAX)];
unsigned long relbit[NBITS (REL_MAX)];
unsigned long absbit[NBITS (ABS_MAX)];
gint num_keys = 0;
gint num_ext_keys = 0;
gint num_buttons = 0;
gint num_rels = 0;
gint num_abs = 0;
/* get event type bits */
ioctl (fd, EVIOCGBIT (0, EV_MAX), evbit);
if (test_bit (EV_KEY, evbit))
{
gint i;
/* get keyboard bits */
ioctl (fd, EVIOCGBIT (EV_KEY, KEY_MAX), keybit);
/** count typical keyboard keys only */
for (i = KEY_Q; i < KEY_M; i++)
if (test_bit (i, keybit))
{
num_keys++;
g_print ("%s: key 0x%02x present\n", G_STRFUNC, i);
}
g_print ("%s: #keys = %d\n", G_STRFUNC, num_keys);
for (i = KEY_OK; i < KEY_MAX; i++)
if (test_bit (i, keybit))
{
num_ext_keys++;
g_print ("%s: ext key 0x%02x present\n", G_STRFUNC, i);
}
g_print ("%s: #ext_keys = %d\n", G_STRFUNC, num_ext_keys);
for (i = BTN_MISC; i < KEY_OK; i++)
if (test_bit (i, keybit))
{
num_buttons++;
g_print ("%s: button 0x%02x present\n", G_STRFUNC, i);
}
g_print ("%s: #buttons = %d\n", G_STRFUNC, num_buttons);
}
if (test_bit (EV_REL, evbit))
{
gint i;
/* get bits for relative axes */
ioctl (fd, EVIOCGBIT (EV_REL, REL_MAX), relbit);
for (i = 0; i < REL_MAX; i++)
if (test_bit (i, relbit))
{
num_rels++;
g_print ("%s: rel 0x%02x present\n", G_STRFUNC, i);
}
g_print ("%s: #rels = %d\n", G_STRFUNC, num_rels);
}
if (test_bit (EV_ABS, evbit))
{
gint i;
/* get bits for absolute axes */
ioctl (fd, EVIOCGBIT (EV_ABS, ABS_MAX), absbit);
for (i = 0; i < ABS_MAX; i++)
if (test_bit (i, absbit))
{
struct input_absinfo absinfo;
num_abs++;
/* get info for the absolute axis */
ioctl (fd, EVIOCGABS (i), &absinfo);
g_print ("%s: abs 0x%02x present [%d..%d]\n", G_STRFUNC, i,
absinfo.minimum, absinfo.maximum);
}
g_print ("%s: #abs = %d\n", G_STRFUNC, num_abs);
}
}
static void
linux_input_device_changed (ControllerLinuxInput *controller,
const gchar *udi)
{
if (controller->device && strcmp (udi, controller->device) == 0)
{
linux_input_set_device (controller, udi);
g_object_notify (G_OBJECT (controller), "device");
}
}
static gboolean
linux_input_set_device (ControllerLinuxInput *controller,
const gchar *device)
{
gchar *filename;
if (controller->io)
{
g_source_remove (controller->io_id);
@ -368,11 +539,26 @@ linux_input_set_device (ControllerLinuxInput *controller,
g_object_set (controller, "name", _("Linux Input Events"), NULL);
if (controller->device && strlen (controller->device))
{
if (controller->store)
filename = gimp_input_device_store_get_device_file (controller->store,
controller->device);
else
filename = g_strdup (controller->device);
}
else
{
g_object_set (controller, "state", _("No device configured"), NULL);
return FALSE;
}
if (filename)
{
gchar *state;
gint fd;
fd = g_open (controller->device, O_RDONLY, 0);
fd = g_open (filename, O_RDONLY, 0);
if (fd >= 0)
{
@ -386,10 +572,14 @@ linux_input_set_device (ControllerLinuxInput *controller,
g_object_set (controller, "name", name, NULL);
}
state = g_strdup_printf (_("Reading from %s"), controller->device);
linux_input_get_device_info (controller, fd);
state = g_strdup_printf (_("Reading from %s"), filename);
g_object_set (controller, "state", state, NULL);
g_free (state);
g_free (filename);
controller->io = g_io_channel_unix_new (fd);
g_io_channel_set_close_on_unref (controller->io, TRUE);
g_io_channel_set_encoding (controller->io, NULL, NULL);
@ -407,10 +597,22 @@ linux_input_set_device (ControllerLinuxInput *controller,
g_object_set (controller, "state", state, NULL);
g_free (state);
}
g_free (filename);
}
else
else if (controller->store)
{
g_object_set (controller, "state", _("No device configured"), NULL);
GError *error = gimp_input_device_store_get_error (controller->store);
if (error)
{
g_object_set (controller, "state", error->message, NULL);
g_error_free (error);
}
else
{
g_object_set (controller, "state", _("Device not available"), NULL);
}
}
return FALSE;
@ -426,7 +628,6 @@ linux_input_read_event (GIOChannel *io,
GError *error = NULL;
struct input_event ev;
gsize n_bytes;
gint i;
status = g_io_channel_read_chars (io,
(gchar *) &ev,
@ -468,17 +669,20 @@ linux_input_read_event (GIOChannel *io,
if (n_bytes == sizeof (struct input_event))
{
GimpController *controller = GIMP_CONTROLLER (data);
GimpControllerEvent cevent = { 0, };
gint i;
switch (ev.type)
{
case EV_KEY:
g_print ("%s: EV_KEY code = 0x%02x\n", G_STRFUNC, ev.code);
for (i = 0; i < G_N_ELEMENTS (key_events); i++)
if (ev.code == key_events[i].code)
{
GimpController *controller = GIMP_CONTROLLER (data);
GimpControllerEvent cevent;
cevent.any.type = GIMP_CONTROLLER_EVENT_TRIGGER;
cevent.any.source = GIMP_CONTROLLER (data);
cevent.any.source = controller;
cevent.any.event_id = i;
gimp_controller_event (controller, &cevent);
@ -488,29 +692,42 @@ linux_input_read_event (GIOChannel *io,
break;
case EV_REL:
g_print ("%s: EV_REL code = 0x%02x (value = %d)\n", G_STRFUNC,
ev.code, ev.value);
for (i = 0; i < G_N_ELEMENTS (rel_events); i++)
if (ev.code == rel_events[i].code)
{
GimpController *controller = GIMP_CONTROLLER (data);
GimpControllerEvent cevent;
gint count;
cevent.any.type = GIMP_CONTROLLER_EVENT_TRIGGER;
cevent.any.type = GIMP_CONTROLLER_EVENT_VALUE;
cevent.any.source = controller;
cevent.any.event_id = G_N_ELEMENTS (key_events) + i;
for (count = ev.value; count < 0; count++)
gimp_controller_event (controller, &cevent);
g_value_init (&cevent.value.value, G_TYPE_DOUBLE);
cevent.any.event_id++;
if (ev.value < 0)
{
g_value_set_double (&cevent.value.value, -ev.value);
}
else
{
cevent.any.event_id++;
for (count = ev.value; count > 0; count--)
gimp_controller_event (controller, &cevent);
g_value_set_double (&cevent.value.value, ev.value);
}
break;
gimp_controller_event (controller, &cevent);
g_value_unset (&cevent.value.value);
break;
}
break;
case EV_ABS:
g_print ("%s: EV_ABS code = 0x%02x (value = %d)\n", G_STRFUNC,
ev.code, ev.value);
break;
default:
break;
}

View File

@ -1,23 +1,22 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* controller_midi.c
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
* Copyright (C) 2004-2007 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 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 library is distributed in the hope that it will be useful,
* 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.
* 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 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.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
@ -167,9 +166,9 @@ static const GimpModuleInfo midi_info =
GIMP_MODULE_ABI_VERSION,
N_("MIDI event controller"),
"Michael Natterer <mitch@gimp.org>",
"v0.1",
"(c) 2004, released under the GPL",
"June 2004"
"v0.2",
"(c) 2004-2007, released under the GPL",
"2004-2007"
};

View File

@ -0,0 +1,940 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpinputdevicestore.c
* Copyright (C) 2007 Sven Neumann <sven@gimp.org>
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#ifdef HAVE_LIBHAL
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <hal/libhal.h>
#endif
#ifdef HAVE_DX_DINPUT
#define _WIN32_WINNT 0x0501
#include <windows.h>
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#include <rpc.h>
#ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 0x00000004
#endif
#include <gdk/gdkwin32.h>
#endif
#include "gimpinputdevicestore.h"
#ifdef HAVE_LIBHAL
enum
{
COLUMN_UDI,
COLUMN_LABEL,
NUM_COLUMNS
};
enum
{
PROP_0,
PROP_CONSTRUCT_ERROR
};
enum
{
DEVICE_ADDED,
DEVICE_REMOVED,
LAST_SIGNAL
};
typedef struct _GimpInputDeviceStoreClass GimpInputDeviceStoreClass;
struct _GimpInputDeviceStore
{
GtkListStore parent_instance;
LibHalContext *context;
GError *error;
};
struct _GimpInputDeviceStoreClass
{
GtkListStoreClass parent_class;
void (*device_added) (GimpInputDeviceStore *store,
const gchar *udi);
void (*device_removed) (GimpInputDeviceStore *store,
const gchar *udi);
};
static void gimp_input_device_store_class_init (GimpInputDeviceStoreClass *klass);
static void gimp_input_device_store_init (GimpInputDeviceStore *store);
static void gimp_input_device_store_finalize (GObject *object);
static gboolean gimp_input_device_store_add (GimpInputDeviceStore *store,
const gchar *udi);
static gboolean gimp_input_device_store_remove (GimpInputDeviceStore *store,
const gchar *udi);
static void gimp_input_device_store_device_added (LibHalContext *ctx,
const char *udi);
static void gimp_input_device_store_device_removed (LibHalContext *ctx,
const char *udi);
GType gimp_input_device_store_type = 0;
static GtkListStoreClass *parent_class = NULL;
static guint store_signals[LAST_SIGNAL] = { 0 };
GType
gimp_input_device_store_get_type (GTypeModule *module)
{
if (! gimp_input_device_store_type)
{
const GTypeInfo info =
{
sizeof (GimpInputDeviceStoreClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_input_device_store_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpInputDeviceStore),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_input_device_store_init
};
gimp_input_device_store_type =
g_type_module_register_type (module, GTK_TYPE_LIST_STORE,
"GimpInputDeviceStore",
&info, 0);
}
return gimp_input_device_store_type;
}
static void
gimp_input_device_store_class_init (GimpInputDeviceStoreClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
store_signals[DEVICE_ADDED] =
g_signal_new ("device-added",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpInputDeviceStoreClass, device_added),
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_STRING);
store_signals[DEVICE_REMOVED] =
g_signal_new ("device-removed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpInputDeviceStoreClass, device_removed),
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_STRING);
object_class->finalize = gimp_input_device_store_finalize;
klass->device_added = NULL;
klass->device_removed = NULL;
}
static void
gimp_input_device_store_init (GimpInputDeviceStore *store)
{
GType types[] = { G_TYPE_STRING, G_TYPE_STRING };
DBusGConnection *connection;
DBusError dbus_error;
gtk_list_store_set_column_types (GTK_LIST_STORE (store),
G_N_ELEMENTS (types), types);
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &store->error);
if (! connection)
return;
store->context = libhal_ctx_new ();
libhal_ctx_set_dbus_connection (store->context,
dbus_g_connection_get_connection (connection));
dbus_g_connection_unref (connection);
dbus_error_init (&dbus_error);
if (libhal_ctx_init (store->context, &dbus_error))
{
char **devices;
int i, num_devices;
devices = libhal_find_device_by_capability (store->context, "input",
&num_devices, NULL);
for (i = 0; i < num_devices; i++)
gimp_input_device_store_add (store, devices[i]);
libhal_free_string_array (devices);
libhal_ctx_set_user_data (store->context, store);
libhal_ctx_set_device_added (store->context,
gimp_input_device_store_device_added);
libhal_ctx_set_device_removed (store->context,
gimp_input_device_store_device_removed);
}
else
{
if (dbus_error_is_set (&dbus_error))
{
dbus_set_g_error (&store->error, &dbus_error);
dbus_error_free (&dbus_error);
}
else
{
g_set_error (&store->error, 0, 0, "Unable to connect to hald");
}
libhal_ctx_free (store->context);
store->context = NULL;
}
}
static void
gimp_input_device_store_finalize (GObject *object)
{
GimpInputDeviceStore *store = GIMP_INPUT_DEVICE_STORE (object);
if (store->context)
{
libhal_ctx_shutdown (store->context, NULL);
libhal_ctx_free (store->context);
store->context = NULL;
}
if (store->error)
{
g_error_free (store->error);
store->error = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gboolean
gimp_input_device_store_lookup (GimpInputDeviceStore *store,
const gchar *udi,
GtkTreeIter *iter)
{
GtkTreeModel *model = GTK_TREE_MODEL (store);
GValue value = { 0, };
gboolean iter_valid;
for (iter_valid = gtk_tree_model_get_iter_first (model, iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, iter))
{
const gchar *str;
gtk_tree_model_get_value (model, iter, COLUMN_UDI, &value);
str = g_value_get_string (&value);
if (strcmp (str, udi) == 0)
{
g_value_unset (&value);
break;
}
g_value_unset (&value);
}
return iter_valid;
}
/* insert in alphabetic order */
static void
gimp_input_device_store_insert (GimpInputDeviceStore *store,
const gchar *udi,
const gchar *label)
{
GtkTreeModel *model = GTK_TREE_MODEL (store);
GtkTreeIter iter;
GValue value = { 0, };
gint pos = 0;
gboolean iter_valid;
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &iter), pos++)
{
const gchar *str;
gtk_tree_model_get_value (model, &iter, COLUMN_LABEL, &value);
str = g_value_get_string (&value);
if (g_utf8_collate (label, str) < 0)
{
g_value_unset (&value);
break;
}
g_value_unset (&value);
}
gtk_list_store_insert_with_values (GTK_LIST_STORE (store), &iter, pos,
COLUMN_UDI, udi,
COLUMN_LABEL, label,
-1);
}
static gboolean
gimp_input_device_store_add (GimpInputDeviceStore *store,
const gchar *udi)
{
gboolean added = FALSE;
char **caps;
gint i;
caps = libhal_device_get_property_strlist (store->context,
udi, "info.capabilities",
NULL);
for (i = 0; caps && caps[i] && !added; i++)
{
char *str;
if (strcmp (caps[i], "input") != 0)
continue;
/* skip "PC Speaker" (why is this an input device at all?) */
str = libhal_device_get_property_string (store->context,
udi, "input.physical_device",
NULL);
if (str)
{
gboolean speaker =
strcmp (str, "/org/freedesktop/Hal/devices/platform_pcspkr") == 0;
libhal_free_string (str);
if (speaker)
continue;
}
str = libhal_device_get_property_string (store->context,
udi, "input.product",
NULL);
if (str)
{
gimp_input_device_store_insert (store, udi, str);
libhal_free_string (str);
added = TRUE;
}
}
libhal_free_string_array (caps);
return added;
}
static gboolean
gimp_input_device_store_remove (GimpInputDeviceStore *store,
const gchar *udi)
{
GtkTreeIter iter;
if (gimp_input_device_store_lookup (store, udi, &iter))
{
gtk_list_store_remove (GTK_LIST_STORE (store), &iter);
return TRUE;
}
return FALSE;
}
static void
gimp_input_device_store_device_added (LibHalContext *ctx,
const char *udi)
{
GimpInputDeviceStore *store = libhal_ctx_get_user_data (ctx);
if (gimp_input_device_store_add (store, udi))
{
g_signal_emit (store, store_signals[DEVICE_ADDED], 0, udi);
}
}
static void
gimp_input_device_store_device_removed (LibHalContext *ctx,
const char *udi)
{
GimpInputDeviceStore *store = libhal_ctx_get_user_data (ctx);
if (gimp_input_device_store_remove (store, udi))
{
g_signal_emit (store, store_signals[DEVICE_REMOVED], 0, udi);
}
}
GimpInputDeviceStore *
gimp_input_device_store_new (void)
{
return g_object_new (GIMP_TYPE_INPUT_DEVICE_STORE, NULL);
}
gchar *
gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
const gchar *udi)
{
GtkTreeIter iter;
g_return_val_if_fail (GIMP_IS_INPUT_DEVICE_STORE (store), NULL);
g_return_val_if_fail (udi != NULL, NULL);
if (! store->context)
return NULL;
if (gimp_input_device_store_lookup (store, udi, &iter))
{
char *str = libhal_device_get_property_string (store->context,
udi, "input.device",
NULL);
if (str)
{
gchar *retval = g_strdup (str);
libhal_free_string (str);
return retval;
}
}
return NULL;
}
GError *
gimp_input_device_store_get_error (GimpInputDeviceStore *store)
{
g_return_val_if_fail (GIMP_IS_INPUT_DEVICE_STORE (store), NULL);
return store->error ? g_error_copy (store->error) : NULL;
}
#elif defined (HAVE_DX_DINPUT)
enum
{
COLUMN_GUID,
COLUMN_LABEL,
COLUMN_IDEVICE,
NUM_COLUMNS
};
enum
{
PROP_0,
PROP_CONSTRUCT_ERROR
};
enum
{
DEVICE_ADDED,
DEVICE_REMOVED,
LAST_SIGNAL
};
typedef struct _GimpInputDeviceStoreClass GimpInputDeviceStoreClass;
struct _GimpInputDeviceStore
{
GtkListStore parent_instance;
GdkWindow *window;
LPDIRECTINPUT8W directinput8;
GError *error;
};
struct _GimpInputDeviceStoreClass
{
GtkListStoreClass parent_class;
void (*device_added) (GimpInputDeviceStore *store,
const gchar *udi);
void (*device_removed) (GimpInputDeviceStore *store,
const gchar *udi);
};
static void gimp_input_device_store_class_init (GimpInputDeviceStoreClass *klass);
static void gimp_input_device_store_init (GimpInputDeviceStore *store);
static void gimp_input_device_store_finalize (GObject *object);
static gboolean gimp_input_device_store_add (GimpInputDeviceStore *store,
const GUID *guid);
static gboolean gimp_input_device_store_remove (GimpInputDeviceStore *store,
const gchar *udi);
#if 0
static void gimp_input_device_store_device_added (LibHalContext *ctx,
const char *udi);
static void gimp_input_device_store_device_removed (LibHalContext *ctx,
const char *udi);
#endif
GType gimp_input_device_store_type = 0;
static GtkListStoreClass *parent_class = NULL;
static guint store_signals[LAST_SIGNAL] = { 0 };
GType
gimp_input_device_store_get_type (GTypeModule *module)
{
if (! gimp_input_device_store_type)
{
const GTypeInfo info =
{
sizeof (GimpInputDeviceStoreClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_input_device_store_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpInputDeviceStore),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_input_device_store_init
};
gimp_input_device_store_type =
g_type_module_register_type (module, GTK_TYPE_LIST_STORE,
"GimpInputDeviceStore",
&info, 0);
}
return gimp_input_device_store_type;
}
static void
gimp_input_device_store_class_init (GimpInputDeviceStoreClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
store_signals[DEVICE_ADDED] =
g_signal_new ("device-added",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpInputDeviceStoreClass, device_added),
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_STRING);
store_signals[DEVICE_REMOVED] =
g_signal_new ("device-removed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpInputDeviceStoreClass, device_removed),
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_STRING);
object_class->finalize = gimp_input_device_store_finalize;
klass->device_added = NULL;
klass->device_removed = NULL;
}
static GdkFilterReturn
aux_window_filter (GdkXEvent *xevent,
GdkEvent *event,
gpointer data)
{
GimpInputDeviceStore *store = (GimpInputDeviceStore *) data;
const MSG *msg = (MSG *) xevent;
/* Look for deviced being added or removed */
switch (msg->message)
{
}
return GDK_FILTER_REMOVE;
}
static GdkWindow *
create_aux_window (GimpInputDeviceStore *store)
{
GdkWindowAttr wa;
GdkWindow *retval;
/* Create a dummy window to be associated with DirectInput devices */
wa.wclass = GDK_INPUT_OUTPUT;
wa.event_mask = GDK_ALL_EVENTS_MASK;
wa.width = 2;
wa.height = 2;
wa.x = -100;
wa.y = -100;
wa.window_type = GDK_WINDOW_TOPLEVEL;
if ((retval = gdk_window_new (NULL, &wa, GDK_WA_X|GDK_WA_Y)) == NULL)
return NULL;
g_object_ref (retval);
gdk_window_add_filter (retval, aux_window_filter, store);
return retval;
}
static BOOL CALLBACK
enum_devices (const DIDEVICEINSTANCEW *di,
void *user_data)
{
GimpInputDeviceStore *store = (GimpInputDeviceStore *) user_data;
gimp_input_device_store_add (store, &di->guidInstance);
return DIENUM_CONTINUE;
}
static void
gimp_input_device_store_init (GimpInputDeviceStore *store)
{
GType types[] = { G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER };
HRESULT hresult;
HMODULE thismodule;
HMODULE dinput8;
typedef HRESULT (WINAPI *t_DirectInput8Create) (HINSTANCE, DWORD, REFIID, LPVOID *, LPUNKNOWN);
t_DirectInput8Create p_DirectInput8Create;
g_assert (G_N_ELEMENTS (types) == NUM_COLUMNS);
gtk_list_store_set_column_types (GTK_LIST_STORE (store),
G_N_ELEMENTS (types), types);
if (!GetModuleHandleEx (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
(LPCTSTR) &gimp_input_device_store_init,
&thismodule))
return;
if ((store->window = create_aux_window (store)) == NULL)
{
g_set_error (&store->error, 0, 0, "Could not create aux window");
return;
}
if ((dinput8 = LoadLibrary ("dinput8.dll")) == NULL)
{
g_set_error (&store->error, 0, 0, "Could not load dinput8.dll");
return;
}
if ((p_DirectInput8Create = (t_DirectInput8Create) GetProcAddress (dinput8, "DirectInput8Create")) == NULL)
{
g_set_error (&store->error, 0, 0, "Could not find DirectInput8Create in dinput8.dll");
return;
}
if (FAILED ((hresult = (*p_DirectInput8Create) (thismodule,
DIRECTINPUT_VERSION,
&IID_IDirectInput8W,
(LPVOID *) &store->directinput8,
NULL))))
{
g_set_error (&store->error, 0, 0, "DirectInput8Create failed: %s", g_win32_error_message (hresult));
return;
}
if (FAILED ((hresult = IDirectInput8_EnumDevices (store->directinput8,
DI8DEVCLASS_GAMECTRL,
enum_devices,
store,
DIEDFL_ATTACHEDONLY))))
{
g_set_error (&store->error, 0, 0, "IDirectInput8::EnumDevices failed: %s", g_win32_error_message (hresult));
return;
}
}
static void
gimp_input_device_store_finalize (GObject *object)
{
GimpInputDeviceStore *store = GIMP_INPUT_DEVICE_STORE (object);
if (store->directinput8)
{
IDirectInput8_Release (store->directinput8);
store->directinput8 = NULL;
}
if (store->error)
{
g_error_free (store->error);
store->error = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gboolean
gimp_input_device_store_lookup (GimpInputDeviceStore *store,
const gchar *guid,
GtkTreeIter *iter)
{
GtkTreeModel *model = GTK_TREE_MODEL (store);
GValue value = { 0, };
gboolean iter_valid;
for (iter_valid = gtk_tree_model_get_iter_first (model, iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, iter))
{
const gchar *str;
gtk_tree_model_get_value (model, iter, COLUMN_GUID, &value);
str = g_value_get_string (&value);
if (strcmp (str, guid) == 0)
{
g_value_unset (&value);
break;
}
g_value_unset (&value);
}
return iter_valid;
}
/* insert in alphabetic order */
static void
gimp_input_device_store_insert (GimpInputDeviceStore *store,
const gchar *guid,
const gchar *label,
LPDIRECTINPUTDEVICE8W didevice8)
{
GtkTreeModel *model = GTK_TREE_MODEL (store);
GtkTreeIter iter;
GValue value = { 0, };
gint pos = 0;
gboolean iter_valid;
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &iter), pos++)
{
const gchar *str;
gtk_tree_model_get_value (model, &iter, COLUMN_LABEL, &value);
str = g_value_get_string (&value);
if (g_utf8_collate (label, str) < 0)
{
g_value_unset (&value);
break;
}
g_value_unset (&value);
}
gtk_list_store_insert_with_values (GTK_LIST_STORE (store), &iter, pos,
COLUMN_GUID, guid,
COLUMN_LABEL, label,
COLUMN_IDEVICE, didevice8,
-1);
}
static gboolean
gimp_input_device_store_add (GimpInputDeviceStore *store,
const GUID *guid)
{
HRESULT hresult;
LPDIRECTINPUTDEVICE8W didevice8;
DIDEVICEINSTANCEW di;
gboolean added = FALSE;
unsigned char *s;
gchar *guidstring;
gchar *name;
if (UuidToString (guid, &s) != S_OK)
return FALSE;
guidstring = g_strdup (s);
RpcStringFree (&s);
if (FAILED ((hresult = IDirectInput8_CreateDevice (store->directinput8,
guid,
&didevice8,
NULL))))
return FALSE;
if (FAILED ((hresult = IDirectInputDevice8_SetCooperativeLevel (didevice8,
(HWND) gdk_win32_drawable_get_handle (store->window),
DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))))
{
g_warning ("IDirectInputDevice8::SetCooperativeLevel failed: %s",
g_win32_error_message (hresult));
return FALSE;
}
di.dwSize = sizeof (DIDEVICEINSTANCEW);
if (FAILED ((hresult = IDirectInputDevice8_GetDeviceInfo (didevice8,
&di))))
{
g_warning ("IDirectInputDevice8::GetDeviceInfo failed: %s",
g_win32_error_message (hresult));
return FALSE;
}
name = g_utf16_to_utf8 (di.tszInstanceName, -1, NULL, NULL, NULL);
gimp_input_device_store_insert (store, guidstring, name, didevice8);
return added;
}
static gboolean
gimp_input_device_store_remove (GimpInputDeviceStore *store,
const gchar *guid)
{
GtkTreeIter iter;
if (gimp_input_device_store_lookup (store, guid, &iter))
{
gtk_list_store_remove (GTK_LIST_STORE (store), &iter);
return TRUE;
}
return FALSE;
}
#if 0
static void
gimp_input_device_store_device_added (LibHalContext *ctx,
const char *guid)
{
GimpInputDeviceStore *store = libhal_ctx_get_user_data (ctx);
if (gimp_input_device_store_add (store, udi))
{
g_signal_emit (store, store_signals[DEVICE_ADDED], 0, udi);
}
}
static void
gimp_input_device_store_device_removed (LibHalContext *ctx,
const char *udi)
{
GimpInputDeviceStore *store = libhal_ctx_get_user_data (ctx);
if (gimp_input_device_store_remove (store, udi))
{
g_signal_emit (store, store_signals[DEVICE_REMOVED], 0, udi);
}
}
#endif
GimpInputDeviceStore *
gimp_input_device_store_new (void)
{
return g_object_new (GIMP_TYPE_INPUT_DEVICE_STORE, NULL);
}
gchar *
gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
const gchar *udi)
{
GtkTreeIter iter;
GValue value = { 0, };
g_return_val_if_fail (GIMP_IS_INPUT_DEVICE_STORE (store), NULL);
g_return_val_if_fail (udi != NULL, NULL);
if (! store->directinput8)
return NULL;
if (gimp_input_device_store_lookup (store, udi, &iter))
{
gtk_tree_model_get_value (GTK_TREE_MODEL (store), &iter, COLUMN_IDEVICE, &value);
return g_value_get_pointer (&value);
}
return NULL;
}
GError *
gimp_input_device_store_get_error (GimpInputDeviceStore *store)
{
g_return_val_if_fail (GIMP_IS_INPUT_DEVICE_STORE (store), NULL);
return store->error ? g_error_copy (store->error) : NULL;
}
#else
GType gimp_input_device_store_type = G_TYPE_NONE;
GType
gimp_input_device_store_get_type (GTypeModule *module)
{
return G_TYPE_NONE;
}
GimpInputDeviceStore *
gimp_input_device_store_new (void)
{
return NULL;
}
gchar *
gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
const gchar *udi)
{
return NULL;
}
GError *
gimp_input_device_store_get_error (GimpInputDeviceStore *store)
{
return NULL;
}
#endif

View File

@ -0,0 +1,44 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpinputdevicestore.h
* Copyright (C) 2007 Sven Neumann <sven@gimp.org>
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_INPUT_DEVICE_STORE_H__
#define __GIMP_INPUT_DEVICE_STORE_H__
#define GIMP_TYPE_INPUT_DEVICE_STORE (gimp_input_device_store_type)
#define GIMP_INPUT_DEVICE_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_INPUT_DEVICE_STORE, GimpInputDeviceStore))
#define GIMP_IS_INPUT_DEVICE_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_INPUT_DEVICE_STORE))
typedef struct _GimpInputDeviceStore GimpInputDeviceStore;
extern GType gimp_input_device_store_type;
GType gimp_input_device_store_get_type (GTypeModule *module);
GimpInputDeviceStore * gimp_input_device_store_new (void);
gchar * gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
const gchar *udi);
GError * gimp_input_device_store_get_error (GimpInputDeviceStore *store);
#endif /* __GIMP_INPUT_DEVICE_STORE_H__ */