From 8191a4a1f97deb72543d594ccc7e7632cab27519 Mon Sep 17 00:00:00 2001 From: kiirala Date: Sun, 11 Jan 2009 21:49:58 +0000 Subject: [PATCH] Switching tools based on tablet device now handles many devices of same type --- src/desktop-events.cpp | 45 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 4258d1980..e2c3ba40e 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -303,8 +303,8 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) return ret; } -static std::map switchMap; -static std::map toolToUse; +//static std::map switchMap; +static std::map toolToUse; static std::string lastName; static GdkInputSource lastType = GDK_SOURCE_MOUSE; @@ -317,27 +317,25 @@ static void init_extended() GdkDevice* dev = reinterpret_cast(curr->data); if ( dev->name && (avoidName != dev->name) - && (switchMap.find(dev->source) == switchMap.end()) && (dev->source != GDK_SOURCE_MOUSE) ) { - switchMap[dev->source] = dev->name; // g_message("Adding '%s' as [%d]", dev->name, dev->source); // Set the initial tool for the device switch ( dev->source ) { case GDK_SOURCE_PEN: - toolToUse[GDK_SOURCE_PEN] = TOOLS_CALLIGRAPHIC; + toolToUse[dev->name] = TOOLS_CALLIGRAPHIC; break; case GDK_SOURCE_ERASER: - toolToUse[GDK_SOURCE_ERASER] = TOOLS_ERASER; + toolToUse[dev->name] = TOOLS_ERASER; break; case GDK_SOURCE_CURSOR: - toolToUse[GDK_SOURCE_CURSOR] = TOOLS_SELECT; + toolToUse[dev->name] = TOOLS_SELECT; break; default: ; // do not add } -// } else { -// g_message("Skippn '%s' as [%s]", dev->name, namefor(dev->source)); +// } else if (dev->name) { +// g_message("Skippn '%s' as [%s]", dev->name, dev->source); } } } @@ -399,22 +397,23 @@ void snoop_extended(GdkEvent* event, SPDesktop *desktop) } if (!name.empty()) { - if ( lastName != name || lastType != source ) { + if ( lastType != source || lastName != name ) { // The device switched. See if it is one we 'count' - std::map::iterator it = switchMap.find(source); - if ( (it != switchMap.end()) && (name == it->second) ) { - std::map::iterator it2 = toolToUse.find(source); - if (it2 != toolToUse.end() ) { - // Save the tool currently selected for next time the input device shows up. - if ( (switchMap.find(lastType) != switchMap.end()) - && (lastName == switchMap.find(lastType)->second)) { - toolToUse[lastType] = tools_active(desktop); - } - tools_switch(desktop, it2->second); - } - lastName = name; - lastType = source; + //g_message("Changed device %s -> %s", lastName.c_str(), name.c_str()); + std::map::iterator it = toolToUse.find(lastName); + if (it != toolToUse.end()) { + // Save the tool currently selected for next time the input + // device shows up. + it->second = tools_active(desktop); } + + it = toolToUse.find(name); + if (it != toolToUse.end() ) { + tools_switch(desktop, it->second); + } + + lastName = name; + lastType = source; } } } -- 2.30.2