Code

Pot and Dutch translation update
[inkscape.git] / src / desktop-events.cpp
1 /** @file
2  * @brief Event handlers for SPDesktop
3  */
4 /* Author:
5  *   Lauris Kaplinski <lauris@kaplinski.com>
6  *
7  * Copyright (C) 1999-2002 Lauris Kaplinski
8  * Copyright (C) 1999-2010 Others
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  */
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
16 #include <map>
17 #include <string>
18 #include <2geom/line.h>
19 #include <glibmm/i18n.h>
21 #include "desktop.h"
22 #include "desktop-handles.h"
23 #include "dialogs/dialog-events.h"
24 #include "display/canvas-axonomgrid.h"
25 #include "display/canvas-grid.h"
26 #include "display/guideline.h"
27 #include "display/snap-indicator.h"
28 #include "document.h"
29 #include "event-context.h"
30 #include "helper/action.h"
31 #include "helper/unit-menu.h"
32 #include "helper/units.h"
33 #include "message-context.h"
34 #include "preferences.h"
35 #include "snap.h"
36 #include "sp-guide.h"
37 #include "sp-metrics.h"
38 #include "sp-namedview.h"
39 #include "tools-switch.h"
40 #include "ui/dialog/guides.h"
41 #include "widgets/desktop-widget.h"
42 #include "xml/repr.h"
44 static void snoop_extended(GdkEvent* event, SPDesktop *desktop);
45 static void init_extended();
47 /* Root item handler */
49 int sp_desktop_root_handler(SPCanvasItem */*item*/, GdkEvent *event, SPDesktop *desktop)
50 {
51     static bool watch = false;
52     static bool first = true;
54     if ( first ) {
55         Inkscape::Preferences *prefs = Inkscape::Preferences::get();
56         if ( prefs->getBool("/options/useextinput/value", true)
57             && prefs->getBool("/options/switchonextinput/value") ) {
58             watch = true;
59             init_extended();
60         }
61         first = false;
62     }
63     if ( watch ) {
64         snoop_extended(event, desktop);
65     }
67     return sp_event_context_root_handler(desktop->event_context, event);
68 }
70 static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dtw, bool horiz)
71 {
72     static bool dragging = false;
73     static SPCanvasItem *guide = NULL;
74     static Geom::Point normal;
75     int wx, wy;
77     SPDesktop *desktop = dtw->desktop;
78     Inkscape::XML::Node *repr = SP_OBJECT_REPR(desktop->namedview);
80     gdk_window_get_pointer(GTK_WIDGET(dtw->canvas)->window, &wx, &wy, NULL);
81     Geom::Point const event_win(wx, wy);
83     gint width, height;
84     gdk_window_get_geometry(GTK_WIDGET(dtw->canvas)->window, NULL /*x*/, NULL /*y*/, &width, &height, NULL/*depth*/);
86     switch (event->type) {
87     case GDK_BUTTON_PRESS:
88             if (event->button.button == 1) {
89                 dragging = true;
91                 Geom::Point const event_w(sp_canvas_window_to_world(dtw->canvas, event_win));
92                 Geom::Point const event_dt(desktop->w2d(event_w));
94                 // explicitly show guidelines; if I draw a guide, I want them on
95                 sp_repr_set_boolean(repr, "showguides", TRUE);
96                 sp_repr_set_boolean(repr, "inkscape:guide-bbox", TRUE);
98                 // calculate the normal of the guidelines when dragged from the edges of rulers.
99                 Geom::Point normal_bl_to_tr(-1.,1.); //bottomleft to topright
100                 Geom::Point normal_tr_to_bl(1.,1.); //topright to bottomleft
101                 normal_bl_to_tr.normalize();
102                 normal_tr_to_bl.normalize();
103                 Inkscape::CanvasGrid * grid = sp_namedview_get_first_enabled_grid(desktop->namedview);
104                 if ( grid && grid->getGridType() == Inkscape::GRID_AXONOMETRIC ) {
105                     Inkscape::CanvasAxonomGrid *axonomgrid = dynamic_cast<Inkscape::CanvasAxonomGrid *>(grid);
106                     if (event->button.state & GDK_CONTROL_MASK) {
107                         // guidelines normal to gridlines
108                         normal_bl_to_tr = Geom::Point::polar(-axonomgrid->angle_rad[0], 1.0);
109                         normal_tr_to_bl = Geom::Point::polar(axonomgrid->angle_rad[2], 1.0);
110                     } else {
111                         normal_bl_to_tr = rot90(Geom::Point::polar(axonomgrid->angle_rad[2], 1.0));
112                         normal_tr_to_bl = rot90(Geom::Point::polar(-axonomgrid->angle_rad[0], 1.0));
113                     }
114                 }
115                 if (horiz) {
116                     if (wx < 50) {
117                         normal = normal_bl_to_tr;
118                     } else if (wx > width - 50) {
119                         normal = normal_tr_to_bl;
120                     } else {
121                         normal = Geom::Point(0.,1.);
122                     }
123                 } else {
124                     if (wy < 50) {
125                         normal = normal_bl_to_tr;
126                     } else if (wy > height - 50) {
127                         normal = normal_tr_to_bl;
128                     } else {
129                         normal = Geom::Point(1.,0.);
130                     }
131                 }
133                 guide = sp_guideline_new(desktop->guides, event_dt, normal);
134                 sp_guideline_set_color(SP_GUIDELINE(guide), desktop->namedview->guidehicolor);
135                 gdk_pointer_grab(widget->window, FALSE,
136                                  (GdkEventMask)(GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ),
137                                  NULL, NULL,
138                                  event->button.time);
139             }
140             break;
141     case GDK_MOTION_NOTIFY:
142             if (dragging) {
143                 Geom::Point const event_w(sp_canvas_window_to_world(dtw->canvas, event_win));
144                 Geom::Point event_dt(desktop->w2d(event_w));
146                 if (!(event->motion.state & GDK_SHIFT_MASK)) {
147                     SnapManager &m = desktop->namedview->snap_manager;
148                     m.setup(desktop);
149                     // We only have a temporary guide which is not stored in our document yet.
150                     // Because the guide snapper only looks in the document for guides to snap to,
151                     // we don't have to worry about a guide snapping to itself here
152                     m.guideFreeSnap(event_dt, normal, SP_DRAG_MOVE_ORIGIN);
153                     m.unSetup();
154                 }
156                 sp_guideline_set_position(SP_GUIDELINE(guide), from_2geom(event_dt));
157                 desktop->set_coordinate_status(to_2geom(event_dt));
158                 desktop->setPosition(to_2geom(event_dt));
159             }
160             break;
161     case GDK_BUTTON_RELEASE:
162             if (dragging && event->button.button == 1) {
163                 sp_event_context_discard_delayed_snap_event(desktop->event_context);
165                 gdk_pointer_ungrab(event->button.time);
166                 Geom::Point const event_w(sp_canvas_window_to_world(dtw->canvas, event_win));
167                 Geom::Point event_dt(desktop->w2d(event_w));
169                 if (!(event->button.state & GDK_SHIFT_MASK)) {
170                     SnapManager &m = desktop->namedview->snap_manager;
171                     m.setup(desktop);
172                     // We only have a temporary guide which is not stored in our document yet.
173                     // Because the guide snapper only looks in the document for guides to snap to,
174                     // we don't have to worry about a guide snapping to itself here
175                     m.guideFreeSnap(event_dt, normal, SP_DRAG_MOVE_ORIGIN);
176                     m.unSetup();
177                 }
179                 dragging = false;
181                 gtk_object_destroy(GTK_OBJECT(guide));
182                 guide = NULL;
183                 if ((horiz ? wy : wx) >= 0) {
184                     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
185                     Inkscape::XML::Node *repr = xml_doc->createElement("sodipodi:guide");
186                     sp_repr_set_point(repr, "orientation", normal);
187                     sp_repr_set_point(repr, "position", from_2geom(event_dt));
188                     SP_OBJECT_REPR(desktop->namedview)->appendChild(repr);
189                     Inkscape::GC::release(repr);
190                     sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE,
191                                      _("Create guide"));
192                 }
193                 desktop->set_coordinate_status(from_2geom(event_dt));
194             }
195     default:
196             break;
197     }
199     return FALSE;
202 int sp_dt_hruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dtw)
204     if (event->type == GDK_MOTION_NOTIFY) {
205         sp_event_context_snap_delay_handler(dtw->desktop->event_context, (gpointer) widget, (gpointer) dtw, (GdkEventMotion *)event, DelayedSnapEvent::GUIDE_HRULER);
206     }
207     return sp_dt_ruler_event(widget, event, dtw, true);
210 int sp_dt_vruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dtw)
212     if (event->type == GDK_MOTION_NOTIFY) {
213         sp_event_context_snap_delay_handler(dtw->desktop->event_context, (gpointer) widget, (gpointer) dtw, (GdkEventMotion *)event, DelayedSnapEvent::GUIDE_VRULER);
214     }
215     return sp_dt_ruler_event(widget, event, dtw, false);
218 static Geom::Point drag_origin;
219 static SPGuideDragType drag_type = SP_DRAG_NONE;
220 //static bool reset_drag_origin = false; // when Ctrl is pressed while dragging, this is used to trigger resetting of the
221 //                                       // drag origin to that location so that constrained movement is more intuitive
223 // Min distance from anchor to initiate rotation, measured in screenpixels
224 #define tol 40.0
226 gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
228     static bool moved = false;
229     gint ret = FALSE;
231     SPGuide *guide = SP_GUIDE(data);
232     SPDesktop *desktop = static_cast<SPDesktop*>(gtk_object_get_data(GTK_OBJECT(item->canvas), "SPDesktop"));
234     switch (event->type) {
235     case GDK_2BUTTON_PRESS:
236             if (event->button.button == 1) {
237                 drag_type = SP_DRAG_NONE;
238                 sp_event_context_discard_delayed_snap_event(desktop->event_context);
239                 sp_canvas_item_ungrab(item, event->button.time);
240                 Inkscape::UI::Dialogs::GuidelinePropertiesDialog::showDialog(guide, desktop);
241                 ret = TRUE;
242             }
243             break;
244     case GDK_BUTTON_PRESS:
245             if (event->button.button == 1) {
246                 Geom::Point const event_w(event->button.x, event->button.y);
247                 Geom::Point const event_dt(desktop->w2d(event_w));
249                 // Due to the tolerance allowed when grabbing a guide, event_dt will generally
250                 // be close to the guide but not just exactly on it. The drag origin calculated
251                 // here must be exactly on the guide line though, otherwise
252                 // small errors will occur once we snap, see
253                 // https://bugs.launchpad.net/inkscape/+bug/333762
254                 drag_origin = Geom::projection(event_dt, Geom::Line(guide->point_on_line, guide->angle()));
256                 if (event->button.state & GDK_SHIFT_MASK) {
257                     // with shift we rotate the guide
258                     drag_type = SP_DRAG_ROTATE;
259                 } else {
260                     if (event->button.state & GDK_CONTROL_MASK) {
261                         drag_type = SP_DRAG_MOVE_ORIGIN;
262                     } else {
263                         drag_type = SP_DRAG_TRANSLATE;
264                     }
265                 }
267                 if (drag_type == SP_DRAG_ROTATE || drag_type == SP_DRAG_TRANSLATE) {
268                     sp_canvas_item_grab(item,
269                                         ( GDK_BUTTON_RELEASE_MASK  |
270                                           GDK_BUTTON_PRESS_MASK    |
271                                           GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK ),
272                                         NULL,
273                                         event->button.time);
274                 }
275                 ret = TRUE;
276             }
277             break;
278         case GDK_MOTION_NOTIFY:
279             if (drag_type != SP_DRAG_NONE) {
280                 Geom::Point const motion_w(event->motion.x,
281                                            event->motion.y);
282                 Geom::Point motion_dt(desktop->w2d(motion_w));
284                 sp_event_context_snap_delay_handler(desktop->event_context, (gpointer) item, data, (GdkEventMotion *)event, DelayedSnapEvent::GUIDE_HANDLER);
286                 // This is for snapping while dragging existing guidelines. New guidelines,
287                 // which are dragged off the ruler, are being snapped in sp_dt_ruler_event
288                 SnapManager &m = desktop->namedview->snap_manager;
289                 m.setup(desktop, true, NULL, NULL, guide);
290                 if (drag_type == SP_DRAG_MOVE_ORIGIN) {
291                     // If we snap in guideConstrainedSnap() below, then motion_dt will
292                     // be forced to be on the guide. If we don't snap however, then
293                     // the origin should still be constrained to the guide. So let's do
294                     // that explicitly first:
295                     Geom::Line line(guide->point_on_line, guide->angle());
296                     Geom::Coord t = line.nearestPoint(motion_dt);
297                     motion_dt = line.pointAt(t);
298                     if (!(event->motion.state & GDK_SHIFT_MASK)) {
299                         m.guideConstrainedSnap(motion_dt, *guide);
300                     }
301                 } else if (!((drag_type == SP_DRAG_ROTATE) && (event->motion.state & GDK_CONTROL_MASK))) {
302                     // cannot use shift here to disable snapping, because we already use it for rotating the guide
303                     m.guideFreeSnap(motion_dt, guide->normal_to_line, drag_type);
304                 }
305                 m.unSetup();
307                 switch (drag_type) {
308                     case SP_DRAG_TRANSLATE:
309                     {
310                         sp_guide_moveto(*guide, motion_dt, false);
311                         break;
312                     }
313                     case SP_DRAG_ROTATE:
314                     {
315                         Geom::Point pt = motion_dt - guide->point_on_line;
316                         double angle = std::atan2(pt[Geom::Y], pt[Geom::X]);
317                         if (event->motion.state & GDK_CONTROL_MASK) {
318                             Inkscape::Preferences *prefs = Inkscape::Preferences::get();
319                             unsigned const snaps = abs(prefs->getInt("/options/rotationsnapsperpi/value", 12));
320                             if (snaps) {
321                                 double sections = floor(angle * snaps / M_PI + .5);
322                                 angle = (M_PI / snaps) * sections;
323                             }
324                         }
325                         sp_guide_set_normal(*guide, Geom::Point(1,0) * Geom::Rotate(angle + M_PI_2), false);
326                         break;
327                     }
328                     case SP_DRAG_MOVE_ORIGIN:
329                     {
330                         sp_guide_moveto(*guide, motion_dt, false);
331                         break;
332                     }
333                     case SP_DRAG_NONE:
334                         g_assert_not_reached();
335                         break;
336                 }
337                 moved = true;
338                 desktop->set_coordinate_status(from_2geom(motion_dt));
339                 desktop->setPosition(from_2geom(motion_dt));
341                 ret = TRUE;
342             }
343             break;
344     case GDK_BUTTON_RELEASE:
345             if (drag_type != SP_DRAG_NONE && event->button.button == 1) {
346                 sp_event_context_discard_delayed_snap_event(desktop->event_context);
348                 if (moved) {
349                     Geom::Point const event_w(event->button.x,
350                                               event->button.y);
351                     Geom::Point event_dt(desktop->w2d(event_w));
353                     SnapManager &m = desktop->namedview->snap_manager;
354                     m.setup(desktop, true, NULL, NULL, guide);
355                     if (drag_type == SP_DRAG_MOVE_ORIGIN) {
356                         // If we snap in guideConstrainedSnap() below, then motion_dt will
357                         // be forced to be on the guide. If we don't snap however, then
358                         // the origin should still be constrained to the guide. So let's
359                         // do that explicitly first:
360                         Geom::Line line(guide->point_on_line, guide->angle());
361                         Geom::Coord t = line.nearestPoint(event_dt);
362                         event_dt = line.pointAt(t);
363                         if (!(event->button.state & GDK_SHIFT_MASK)) {
364                             m.guideConstrainedSnap(event_dt, *guide);
365                         }
366                     } else if (!((drag_type == SP_DRAG_ROTATE) && (event->motion.state & GDK_CONTROL_MASK))) {
367                         // cannot use shift here to disable snapping, because we already use it for rotating the guide
368                         m.guideFreeSnap(event_dt, guide->normal_to_line, drag_type);
369                     }
370                     m.unSetup();
372                     if (sp_canvas_world_pt_inside_window(item->canvas, event_w)) {
373                         switch (drag_type) {
374                             case SP_DRAG_TRANSLATE:
375                             {
376                                 sp_guide_moveto(*guide, event_dt, true);
377                                 break;
378                             }
379                             case SP_DRAG_ROTATE:
380                             {
381                                 Geom::Point pt = event_dt - guide->point_on_line;
382                                 double angle = std::atan2(pt[Geom::Y], pt[Geom::X]);
383                                 if  (event->motion.state & GDK_CONTROL_MASK) {
384                                     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
385                                     unsigned const snaps = abs(prefs->getInt("/options/rotationsnapsperpi/value", 12));
386                                     if (snaps) {
387                                         double sections = floor(angle * snaps / M_PI + .5);
388                                         angle = (M_PI / snaps) * sections;
389                                     }
390                                 }
391                                 sp_guide_set_normal(*guide, Geom::Point(1,0) * Geom::Rotate(angle + M_PI_2), true);
392                                 break;
393                             }
394                             case SP_DRAG_MOVE_ORIGIN:
395                             {
396                                 sp_guide_moveto(*guide, event_dt, true);
397                                 break;
398                             }
399                             case SP_DRAG_NONE:
400                                 g_assert_not_reached();
401                                 break;
402                         }
403                         sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE,
404                                          _("Move guide"));
405                     } else {
406                         /* Undo movement of any attached shapes. */
407                         sp_guide_moveto(*guide, guide->point_on_line, false);
408                         sp_guide_set_normal(*guide, guide->normal_to_line, false);
409                         sp_guide_remove(guide);
410                         sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE,
411                                      _("Delete guide"));
412                     }
413                     moved = false;
414                     desktop->set_coordinate_status(from_2geom(event_dt));
415                     desktop->setPosition (from_2geom(event_dt));
416                 }
417                 drag_type = SP_DRAG_NONE;
418                 sp_canvas_item_ungrab(item, event->button.time);
419                 ret=TRUE;
420             }
421     case GDK_ENTER_NOTIFY:
422     {
423             sp_guideline_set_color(SP_GUIDELINE(item), guide->hicolor);
425             // set move or rotate cursor
426             Geom::Point const event_w(event->crossing.x, event->crossing.y);
427             Geom::Point const event_dt(desktop->w2d(event_w));
429             if ((event->crossing.state & GDK_SHIFT_MASK) && (drag_type != SP_DRAG_MOVE_ORIGIN)) {
430                 GdkCursor *guide_cursor;
431                 guide_cursor = gdk_cursor_new (GDK_EXCHANGE);
432                 gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, guide_cursor);
433                 gdk_cursor_unref(guide_cursor);
434             }
436             char *guide_description = sp_guide_description(guide);
437             desktop->guidesMessageContext()->setF(Inkscape::NORMAL_MESSAGE, _("<b>Guideline</b>: %s"), guide_description);
438             g_free(guide_description);
439             break;
440     }
441     case GDK_LEAVE_NOTIFY:
442             sp_guideline_set_color(SP_GUIDELINE(item), guide->color);
444             // restore event context's cursor
445             gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, desktop->event_context->cursor);
447             desktop->guidesMessageContext()->clear();
448             break;
449         case GDK_KEY_PRESS:
450             switch (get_group0_keyval (&event->key)) {
451                 case GDK_Delete:
452                 case GDK_KP_Delete:
453                 case GDK_BackSpace:
454                 {
455                     SPDocument *doc = SP_OBJECT_DOCUMENT(guide);
456                     sp_guide_remove(guide);
457                     sp_document_done(doc, SP_VERB_NONE, _("Delete guide"));
458                     ret = TRUE;
459                     sp_event_context_discard_delayed_snap_event(desktop->event_context);
460                     break;
461                 }
462                 case GDK_Shift_L:
463                 case GDK_Shift_R:
464                     if (drag_type != SP_DRAG_MOVE_ORIGIN) {
465                         GdkCursor *guide_cursor;
466                         guide_cursor = gdk_cursor_new (GDK_EXCHANGE);
467                         gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, guide_cursor);
468                         gdk_cursor_unref(guide_cursor);
469                         ret = TRUE;
470                         break;
471                     }
473                 default:
474                     // do nothing;
475                     break;
476             }
477             break;
478         case GDK_KEY_RELEASE:
479             switch (get_group0_keyval (&event->key)) {
480                 case GDK_Shift_L:
481                 case GDK_Shift_R:
482                     GdkCursor *guide_cursor;
483                     guide_cursor = gdk_cursor_new (GDK_EXCHANGE);
484                     gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, guide_cursor);
485                     gdk_cursor_unref(guide_cursor);
486                     break;
487                 default:
488                     // do nothing;
489                     break;
490             }
491     default:
492         break;
493     }
495     return ret;
498 //static std::map<GdkInputSource, std::string> switchMap;
499 static std::map<std::string, int> toolToUse;
500 static std::string lastName;
501 static GdkInputSource lastType = GDK_SOURCE_MOUSE;
503 static void init_extended()
505     std::string avoidName = "pad";
506     GList* devices = gdk_devices_list();
507     if ( devices ) {
508         for ( GList* curr = devices; curr; curr = g_list_next(curr) ) {
509             GdkDevice* dev = reinterpret_cast<GdkDevice*>(curr->data);
510             if ( dev->name
511                  && (avoidName != dev->name)
512                  && (dev->source != GDK_SOURCE_MOUSE) ) {
513 //                 g_message("Adding '%s' as [%d]", dev->name, dev->source);
515                 // Set the initial tool for the device
516                 switch ( dev->source ) {
517                     case GDK_SOURCE_PEN:
518                         toolToUse[dev->name] = TOOLS_CALLIGRAPHIC;
519                         break;
520                     case GDK_SOURCE_ERASER:
521                         toolToUse[dev->name] = TOOLS_ERASER;
522                         break;
523                     case GDK_SOURCE_CURSOR:
524                         toolToUse[dev->name] = TOOLS_SELECT;
525                         break;
526                     default:
527                         ; // do not add
528                 }
529 //            } else if (dev->name) {
530 //                 g_message("Skippn '%s' as [%s]", dev->name, dev->source);
531             }
532         }
533     }
537 void snoop_extended(GdkEvent* event, SPDesktop *desktop)
539     GdkInputSource source = GDK_SOURCE_MOUSE;
540     std::string name;
542     switch ( event->type ) {
543         case GDK_MOTION_NOTIFY:
544         {
545             GdkEventMotion* event2 = reinterpret_cast<GdkEventMotion*>(event);
546             if ( event2->device ) {
547                 source = event2->device->source;
548                 name = event2->device->name;
549             }
550         }
551         break;
553         case GDK_BUTTON_PRESS:
554         case GDK_2BUTTON_PRESS:
555         case GDK_3BUTTON_PRESS:
556         case GDK_BUTTON_RELEASE:
557         {
558             GdkEventButton* event2 = reinterpret_cast<GdkEventButton*>(event);
559             if ( event2->device ) {
560                 source = event2->device->source;
561                 name = event2->device->name;
562             }
563         }
564         break;
566         case GDK_SCROLL:
567         {
568             GdkEventScroll* event2 = reinterpret_cast<GdkEventScroll*>(event);
569             if ( event2->device ) {
570                 source = event2->device->source;
571                 name = event2->device->name;
572             }
573         }
574         break;
576         case GDK_PROXIMITY_IN:
577         case GDK_PROXIMITY_OUT:
578         {
579             GdkEventProximity* event2 = reinterpret_cast<GdkEventProximity*>(event);
580             if ( event2->device ) {
581                 source = event2->device->source;
582                 name = event2->device->name;
583             }
584         }
585         break;
587         default:
588             ;
589     }
591     if (!name.empty()) {
592         if ( lastType != source || lastName != name ) {
593             // The device switched. See if it is one we 'count'
594             //g_message("Changed device %s -> %s", lastName.c_str(), name.c_str());
595             std::map<std::string, int>::iterator it = toolToUse.find(lastName);
596             if (it != toolToUse.end()) {
597                 // Save the tool currently selected for next time the input
598                 // device shows up.
599                 it->second = tools_active(desktop);
600             }
602             it = toolToUse.find(name);
603             if (it != toolToUse.end() ) {
604                 tools_switch(desktop, it->second);
605             }
607             lastName = name;
608             lastType = source;
609         }
610     }
615 /*
616   Local Variables:
617   mode:c++
618   c-file-style:"stroustrup"
619   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
620   indent-tabs-mode:nil
621   fill-column:99
622   End:
623 */
624 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :