X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftrunk%2Fsrc%2Fgtkmm%2Fdevicetracker.cpp;h=8bd9a4686a10786fe86a4b1781963a7ecc83bf1b;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=6723e8f13cc49abbffa101cc803dd6d72959053c;hpb=3a3c4bca3a17137bec5d7960560934b91ef4146e;p=synfig.git diff --git a/synfig-studio/trunk/src/gtkmm/devicetracker.cpp b/synfig-studio/trunk/src/gtkmm/devicetracker.cpp index 6723e8f..8bd9a46 100644 --- a/synfig-studio/trunk/src/gtkmm/devicetracker.cpp +++ b/synfig-studio/trunk/src/gtkmm/devicetracker.cpp @@ -1,24 +1,30 @@ -/* === S I N F G =========================================================== */ +/* === S Y N F I G ========================================================= */ /*! \file devicetracker.cpp ** \brief Template File ** -** $Id: devicetracker.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $ +** $Id$ ** ** \legal -** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2009 Gerco Ballintijn ** -** This software and associated documentation -** are CONFIDENTIAL and PROPRIETARY property of -** the above-mentioned copyright holder. +** This package 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. ** -** You may not copy, print, publish, or in any -** other way distribute this software without -** a prior written agreement with -** the copyright holder. +** This package 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. ** \endlegal */ /* ========================================================================= */ +// FIXME: The code here doesn't use the GTKmm layer but uses GTK+ directly +// since the GTKmm wrapper for Gdk::Device is incomplete. When the wrapper +// gets fixed, this code should be updated accoordingly. + /* === H E A D E R S ======================================================= */ #ifdef USING_PCH @@ -29,8 +35,11 @@ #endif #include "devicetracker.h" -#include -#include +#include +#include +#include + +#include "general.h" #endif @@ -38,7 +47,8 @@ using namespace std; using namespace etl; -using namespace sinfg; +using namespace synfig; +using namespace synfigapp; using namespace studio; /* === M A C R O S ========================================================= */ @@ -51,26 +61,81 @@ using namespace studio; DeviceTracker::DeviceTracker() { - // By default, set the input mode on devices to - // GDK_MODE_SCREEN. + GList* device_list; + GList* iter; + device_list=gdk_devices_list(); + + for(iter=device_list;iter;iter=g_list_next(iter)) { - GList* device_list; - GList* iter; - device_list=gdk_devices_list(); - - for(iter=device_list;iter;iter=g_list_next(iter)) - { - GdkDevice* device=reinterpret_cast(iter->data); - gdk_device_set_mode(device,GDK_MODE_SCREEN); - - sinfgapp::InputDevice::Handle input_device; - input_device=sinfgapp::Main::add_input_device(device->name,sinfgapp::InputDevice::Type(device->source)); - if(input_device->get_type()==sinfgapp::InputDevice::TYPE_MOUSE) - sinfgapp::Main::select_input_device(input_device); - } + GdkDevice* device=reinterpret_cast(iter->data); + + synfigapp::InputDevice::Handle input_device; + input_device=synfigapp::Main::add_input_device(device->name,synfigapp::InputDevice::Type(device->source)); + if(input_device->get_type()==synfigapp::InputDevice::TYPE_MOUSE) { + input_device->set_mode(synfigapp::InputDevice::MODE_SCREEN); + synfigapp::Main::select_input_device(input_device); + } } } DeviceTracker::~DeviceTracker() { } + +void +DeviceTracker::save_preferences() +{ + GList * device_list = gdk_devices_list(); + for (GList * itr = device_list; itr; itr = g_list_next(itr)) + { + GdkDevice * gdk_device = reinterpret_cast(itr->data); + + InputDevice::Handle synfig_device = synfigapp::Main::find_input_device(gdk_device->name); + if (synfig_device == NULL) + continue; + + synfig_device->set_mode(InputDevice::Mode(gdk_device->mode)); + if (gdk_device->num_axes > 0) { + vector axes; + axes.resize(gdk_device->num_axes); + for (int i = 0; i < gdk_device->num_axes; i++) + axes[i] = InputDevice::AxisUse(gdk_device->axes[i].use); + synfig_device->set_axes(axes); + } + + if (gdk_device->num_keys > 0) { + vector keys; + keys.resize(gdk_device->num_keys); + for (int i = 0; i < gdk_device->num_keys; i++) { + keys[i].keyval = gdk_device->keys[i].keyval; + keys[i].modifiers = gdk_device->keys[i].modifiers; + } + synfig_device->set_keys(keys); + } + } +} + +void +DeviceTracker::load_preferences() +{ + GList * device_list = gdk_devices_list(); + for (GList * itr = device_list; itr; itr = g_list_next(itr)) + { + GdkDevice * gdk_device = reinterpret_cast(itr->data); + + InputDevice::Handle synfig_device = synfigapp::Main::find_input_device(gdk_device->name); + if (synfig_device == NULL) + continue; + + gdk_device_set_mode(gdk_device, GdkInputMode(synfig_device->get_mode())); + + const std::vector axes = synfig_device->get_axes(); + for (int axis = 0; axis < (int) axes.size(); axis++) + gdk_device_set_axis_use(gdk_device, axis, GdkAxisUse(axes[axis])); + + const std::vector keys = synfig_device->get_keys(); + for (int key = 0; key < (int) keys.size(); key++) + gdk_device_set_key(gdk_device, key, keys[key].keyval, + GdkModifierType(keys[key].modifiers)); + } +}