X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Fsrc%2Fgtkmm%2Fdevicetracker.cpp;fp=synfig-studio%2Fsrc%2Fgtkmm%2Fdevicetracker.cpp;h=8bd9a4686a10786fe86a4b1781963a7ecc83bf1b;hb=a095981e18cc37a8ecc7cd237cc22b9c10329264;hp=0000000000000000000000000000000000000000;hpb=9459638ad6797b8139f1e9f0715c96076dbf0890;p=synfig.git diff --git a/synfig-studio/src/gtkmm/devicetracker.cpp b/synfig-studio/src/gtkmm/devicetracker.cpp new file mode 100644 index 0000000..8bd9a46 --- /dev/null +++ b/synfig-studio/src/gtkmm/devicetracker.cpp @@ -0,0 +1,141 @@ +/* === S Y N F I G ========================================================= */ +/*! \file devicetracker.cpp +** \brief Template File +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2009 Gerco Ballintijn +** +** 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. +** +** 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 +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "devicetracker.h" +#include +#include +#include + +#include "general.h" + +#endif + +/* === U S I N G =========================================================== */ + +using namespace std; +using namespace etl; +using namespace synfig; +using namespace synfigapp; +using namespace studio; + +/* === M A C R O S ========================================================= */ + +/* === G L O B A L S ======================================================= */ + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +DeviceTracker::DeviceTracker() +{ + 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); + + 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)); + } +}