2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-06-16 06:59:26 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-06-16 06:59:26 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-06-16 06:59:26 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-06-16 06:59:26 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-04-22 03:41:36 +08:00
|
|
|
#include <gegl.h>
|
2004-06-16 06:59:26 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2004-06-16 06:59:26 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2004-11-24 10:17:12 +08:00
|
|
|
|
|
|
|
#define GIMP_ENABLE_CONTROLLER_UNDER_CONSTRUCTION
|
2004-06-17 02:14:44 +08:00
|
|
|
#include "libgimpwidgets/gimpcontroller.h"
|
2004-06-16 06:59:26 +08:00
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
2004-06-17 02:14:44 +08:00
|
|
|
#include "core/gimplist.h"
|
2004-06-16 06:59:26 +08:00
|
|
|
|
2004-06-16 19:11:32 +08:00
|
|
|
#include "gimpcontrollerinfo.h"
|
2004-06-16 06:59:26 +08:00
|
|
|
#include "gimpcontrollers.h"
|
2004-06-24 18:16:08 +08:00
|
|
|
#include "gimpcontrollerkeyboard.h"
|
2011-04-07 05:12:32 +08:00
|
|
|
#include "gimpcontrollermouse.h"
|
2004-06-16 06:59:26 +08:00
|
|
|
#include "gimpcontrollerwheel.h"
|
2004-06-19 08:31:08 +08:00
|
|
|
#include "gimpenumaction.h"
|
2004-06-16 06:59:26 +08:00
|
|
|
#include "gimpuimanager.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define GIMP_CONTROLLER_MANAGER_DATA_KEY "gimp-controller-manager"
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _GimpControllerManager GimpControllerManager;
|
|
|
|
|
|
|
|
struct _GimpControllerManager
|
|
|
|
{
|
2004-06-17 02:14:44 +08:00
|
|
|
GimpContainer *controllers;
|
|
|
|
GQuark event_mapped_id;
|
2011-04-07 05:12:32 +08:00
|
|
|
GimpController *mouse;
|
2004-06-16 06:59:26 +08:00
|
|
|
GimpController *wheel;
|
2004-06-24 18:16:08 +08:00
|
|
|
GimpController *keyboard;
|
2004-06-16 06:59:26 +08:00
|
|
|
GimpUIManager *ui_manager;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
|
|
|
static GimpControllerManager * gimp_controller_manager_get (Gimp *gimp);
|
|
|
|
static void gimp_controller_manager_free (GimpControllerManager *manager);
|
|
|
|
|
2004-06-18 00:25:36 +08:00
|
|
|
static void gimp_controllers_add (GimpContainer *container,
|
|
|
|
GimpControllerInfo *info,
|
|
|
|
GimpControllerManager *manager);
|
|
|
|
static void gimp_controllers_remove (GimpContainer *container,
|
|
|
|
GimpControllerInfo *info,
|
|
|
|
GimpControllerManager *manager);
|
|
|
|
|
2004-06-17 02:14:44 +08:00
|
|
|
static gboolean gimp_controllers_event_mapped (GimpControllerInfo *info,
|
|
|
|
GimpController *controller,
|
|
|
|
const GimpControllerEvent *event,
|
|
|
|
const gchar *action_name,
|
|
|
|
GimpControllerManager *manager);
|
2004-06-16 06:59:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_controllers_init (Gimp *gimp)
|
|
|
|
{
|
|
|
|
GimpControllerManager *manager;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
g_return_if_fail (gimp_controller_manager_get (gimp) == NULL);
|
|
|
|
|
2007-05-23 00:18:32 +08:00
|
|
|
manager = g_slice_new0 (GimpControllerManager);
|
2004-06-16 06:59:26 +08:00
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (gimp),
|
|
|
|
GIMP_CONTROLLER_MANAGER_DATA_KEY, manager,
|
|
|
|
(GDestroyNotify) gimp_controller_manager_free);
|
|
|
|
|
2004-06-17 02:14:44 +08:00
|
|
|
manager->controllers = gimp_list_new (GIMP_TYPE_CONTROLLER_INFO, TRUE);
|
|
|
|
|
2004-06-18 00:25:36 +08:00
|
|
|
g_signal_connect (manager->controllers, "add",
|
|
|
|
G_CALLBACK (gimp_controllers_add),
|
|
|
|
manager);
|
|
|
|
g_signal_connect (manager->controllers, "remove",
|
|
|
|
G_CALLBACK (gimp_controllers_remove),
|
|
|
|
manager);
|
|
|
|
|
2004-06-17 02:14:44 +08:00
|
|
|
manager->event_mapped_id =
|
|
|
|
gimp_container_add_handler (manager->controllers, "event-mapped",
|
|
|
|
G_CALLBACK (gimp_controllers_event_mapped),
|
|
|
|
manager);
|
|
|
|
|
2011-04-07 05:12:32 +08:00
|
|
|
g_type_class_ref (GIMP_TYPE_CONTROLLER_MOUSE);
|
2004-06-16 06:59:26 +08:00
|
|
|
g_type_class_ref (GIMP_TYPE_CONTROLLER_WHEEL);
|
2004-06-24 18:16:08 +08:00
|
|
|
g_type_class_ref (GIMP_TYPE_CONTROLLER_KEYBOARD);
|
2004-06-16 06:59:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_controllers_exit (Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
g_return_if_fail (gimp_controller_manager_get (gimp) != NULL);
|
|
|
|
|
|
|
|
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));
|
2004-06-24 18:16:08 +08:00
|
|
|
g_type_class_unref (g_type_class_peek (GIMP_TYPE_CONTROLLER_KEYBOARD));
|
2004-06-16 06:59:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_controllers_restore (Gimp *gimp,
|
|
|
|
GimpUIManager *ui_manager)
|
|
|
|
{
|
|
|
|
GimpControllerManager *manager;
|
2014-07-02 01:54:50 +08:00
|
|
|
GFile *file;
|
2004-06-16 06:59:26 +08:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
g_return_if_fail (GIMP_IS_UI_MANAGER (ui_manager));
|
|
|
|
|
|
|
|
manager = gimp_controller_manager_get (gimp);
|
|
|
|
|
|
|
|
g_return_if_fail (manager != NULL);
|
|
|
|
g_return_if_fail (manager->ui_manager == NULL);
|
|
|
|
|
|
|
|
manager->ui_manager = g_object_ref (ui_manager);
|
|
|
|
|
2014-07-28 08:04:01 +08:00
|
|
|
file = gimp_directory_file ("controllerrc", NULL);
|
2004-06-16 06:59:26 +08:00
|
|
|
|
2005-11-07 06:01:25 +08:00
|
|
|
if (gimp->be_verbose)
|
2014-07-02 01:54:50 +08:00
|
|
|
g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
|
2005-11-07 06:01:25 +08:00
|
|
|
|
2014-07-02 01:54:50 +08:00
|
|
|
if (! gimp_config_deserialize_gfile (GIMP_CONFIG (manager->controllers),
|
|
|
|
file, NULL, &error))
|
2004-06-16 06:59:26 +08:00
|
|
|
{
|
2004-06-17 02:14:44 +08:00
|
|
|
if (error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT)
|
2004-06-16 06:59:26 +08:00
|
|
|
{
|
2004-06-17 02:14:44 +08:00
|
|
|
g_clear_error (&error);
|
2014-07-02 01:54:50 +08:00
|
|
|
g_object_unref (file);
|
2004-06-16 06:59:26 +08:00
|
|
|
|
2014-07-28 08:04:01 +08:00
|
|
|
file = gimp_sysconf_directory_file ("controllerrc", NULL);
|
2004-06-16 06:59:26 +08:00
|
|
|
|
2014-07-02 01:54:50 +08:00
|
|
|
if (! gimp_config_deserialize_gfile (GIMP_CONFIG (manager->controllers),
|
|
|
|
file, NULL, &error))
|
2004-06-17 02:14:44 +08:00
|
|
|
{
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR,
|
2013-09-15 00:59:20 +08:00
|
|
|
error->message);
|
2004-06-16 06:59:26 +08:00
|
|
|
}
|
|
|
|
}
|
2004-06-17 02:14:44 +08:00
|
|
|
else
|
|
|
|
{
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
|
2004-06-17 02:14:44 +08:00
|
|
|
}
|
2004-06-16 06:59:26 +08:00
|
|
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
|
2004-06-17 02:14:44 +08:00
|
|
|
gimp_list_reverse (GIMP_LIST (manager->controllers));
|
2004-06-16 06:59:26 +08:00
|
|
|
|
2014-07-02 01:54:50 +08:00
|
|
|
g_object_unref (file);
|
2004-06-16 06:59:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_controllers_save (Gimp *gimp)
|
|
|
|
{
|
2004-06-17 02:14:44 +08:00
|
|
|
const gchar *header =
|
|
|
|
"GIMP controllerrc\n"
|
|
|
|
"\n"
|
2006-12-22 18:09:09 +08:00
|
|
|
"This file will be entirely rewritten each time you exit.";
|
2004-06-17 02:14:44 +08:00
|
|
|
const gchar *footer =
|
|
|
|
"end of controllerrc";
|
|
|
|
|
2004-06-16 06:59:26 +08:00
|
|
|
GimpControllerManager *manager;
|
2014-07-02 01:54:50 +08:00
|
|
|
GFile *file;
|
2004-06-16 06:59:26 +08:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
|
|
|
|
manager = gimp_controller_manager_get (gimp);
|
|
|
|
|
|
|
|
g_return_if_fail (manager != NULL);
|
|
|
|
|
2014-07-28 08:04:01 +08:00
|
|
|
file = gimp_directory_file ("controllerrc", NULL);
|
2004-06-17 02:14:44 +08:00
|
|
|
|
2005-11-07 06:01:25 +08:00
|
|
|
if (gimp->be_verbose)
|
2014-07-02 01:54:50 +08:00
|
|
|
g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
|
2005-11-07 06:01:25 +08:00
|
|
|
|
2014-07-02 01:54:50 +08:00
|
|
|
if (! gimp_config_serialize_to_gfile (GIMP_CONFIG (manager->controllers),
|
|
|
|
file,
|
|
|
|
header, footer, NULL,
|
|
|
|
&error))
|
2004-06-17 02:14:44 +08:00
|
|
|
{
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
|
2004-06-17 02:14:44 +08:00
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
2014-07-02 01:54:50 +08:00
|
|
|
g_object_unref (file);
|
2004-06-16 06:59:26 +08:00
|
|
|
}
|
|
|
|
|
2004-06-17 22:07:05 +08:00
|
|
|
GimpContainer *
|
|
|
|
gimp_controllers_get_list (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->controllers;
|
|
|
|
}
|
|
|
|
|
2004-07-21 02:50:20 +08:00
|
|
|
GimpUIManager *
|
|
|
|
gimp_controllers_get_ui_manager (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->ui_manager;
|
|
|
|
}
|
|
|
|
|
2011-04-07 05:12:32 +08:00
|
|
|
GimpController *
|
|
|
|
gimp_controllers_get_mouse (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->mouse;
|
|
|
|
}
|
|
|
|
|
2004-06-16 06:59:26 +08:00
|
|
|
GimpController *
|
|
|
|
gimp_controllers_get_wheel (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->wheel;
|
|
|
|
}
|
|
|
|
|
2004-06-24 18:16:08 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-16 06:59:26 +08:00
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static GimpControllerManager *
|
|
|
|
gimp_controller_manager_get (Gimp *gimp)
|
|
|
|
{
|
|
|
|
return g_object_get_data (G_OBJECT (gimp), GIMP_CONTROLLER_MANAGER_DATA_KEY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_controller_manager_free (GimpControllerManager *manager)
|
|
|
|
{
|
2004-06-17 02:14:44 +08:00
|
|
|
gimp_container_remove_handler (manager->controllers,
|
|
|
|
manager->event_mapped_id);
|
2004-06-16 06:59:26 +08:00
|
|
|
|
2004-06-17 02:14:44 +08:00
|
|
|
g_object_unref (manager->controllers);
|
2004-06-16 06:59:26 +08:00
|
|
|
g_object_unref (manager->ui_manager);
|
|
|
|
|
2007-05-23 00:18:32 +08:00
|
|
|
g_slice_free (GimpControllerManager, manager);
|
2004-06-16 06:59:26 +08:00
|
|
|
}
|
|
|
|
|
2004-06-18 00:25:36 +08:00
|
|
|
static void
|
|
|
|
gimp_controllers_add (GimpContainer *container,
|
|
|
|
GimpControllerInfo *info,
|
|
|
|
GimpControllerManager *manager)
|
|
|
|
{
|
|
|
|
if (GIMP_IS_CONTROLLER_WHEEL (info->controller))
|
|
|
|
manager->wheel = info->controller;
|
2004-06-24 18:16:08 +08:00
|
|
|
else if (GIMP_IS_CONTROLLER_KEYBOARD (info->controller))
|
|
|
|
manager->keyboard = info->controller;
|
2011-04-07 05:12:32 +08:00
|
|
|
else if (GIMP_IS_CONTROLLER_MOUSE (info->controller))
|
|
|
|
manager->mouse = info->controller;
|
2004-06-18 00:25:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_controllers_remove (GimpContainer *container,
|
|
|
|
GimpControllerInfo *info,
|
|
|
|
GimpControllerManager *manager)
|
|
|
|
{
|
|
|
|
if (info->controller == manager->wheel)
|
|
|
|
manager->wheel = NULL;
|
2004-06-24 18:16:08 +08:00
|
|
|
else if (info->controller == manager->keyboard)
|
|
|
|
manager->keyboard = NULL;
|
2004-06-18 00:25:36 +08:00
|
|
|
}
|
|
|
|
|
2004-06-17 02:14:44 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_controllers_event_mapped (GimpControllerInfo *info,
|
|
|
|
GimpController *controller,
|
|
|
|
const GimpControllerEvent *event,
|
|
|
|
const gchar *action_name,
|
|
|
|
GimpControllerManager *manager)
|
2004-06-16 06:59:26 +08:00
|
|
|
{
|
2007-10-10 13:52:45 +08:00
|
|
|
GtkUIManager *ui_manager = GTK_UI_MANAGER (manager->ui_manager);
|
|
|
|
GList *list;
|
2004-06-16 06:59:26 +08:00
|
|
|
|
2007-10-10 13:52:45 +08:00
|
|
|
for (list = gtk_ui_manager_get_action_groups (ui_manager);
|
2004-06-17 02:14:44 +08:00
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
2004-06-16 06:59:26 +08:00
|
|
|
{
|
2004-06-17 02:14:44 +08:00
|
|
|
GtkActionGroup *group = list->data;
|
|
|
|
GtkAction *action;
|
2004-06-16 06:59:26 +08:00
|
|
|
|
2004-06-17 02:14:44 +08:00
|
|
|
action = gtk_action_group_get_action (group, action_name);
|
2004-06-16 06:59:26 +08:00
|
|
|
|
2004-06-17 02:14:44 +08:00
|
|
|
if (action)
|
2004-06-16 06:59:26 +08:00
|
|
|
{
|
2004-06-19 08:31:08 +08:00
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case GIMP_CONTROLLER_EVENT_VALUE:
|
|
|
|
if (G_VALUE_HOLDS_DOUBLE (&event->value.value) &&
|
2004-11-19 00:04:41 +08:00
|
|
|
GIMP_IS_ENUM_ACTION (action) &&
|
|
|
|
GIMP_ENUM_ACTION (action)->value_variable)
|
2004-06-19 08:31:08 +08:00
|
|
|
{
|
2004-06-23 22:39:48 +08:00
|
|
|
gdouble value = g_value_get_double (&event->value.value);
|
2004-06-19 08:31:08 +08:00
|
|
|
|
2004-06-23 22:39:48 +08:00
|
|
|
gimp_enum_action_selected (GIMP_ENUM_ACTION (action),
|
|
|
|
value * 1000);
|
2004-06-19 08:31:08 +08:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2004-06-23 22:39:48 +08:00
|
|
|
/* else fallthru */
|
2004-06-19 08:31:08 +08:00
|
|
|
|
|
|
|
case GIMP_CONTROLLER_EVENT_TRIGGER:
|
|
|
|
default:
|
|
|
|
gtk_action_activate (action);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-06-17 02:14:44 +08:00
|
|
|
return TRUE;
|
2004-06-16 06:59:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|