diff --git a/libs/canvas/canvas.cc b/libs/canvas/canvas.cc index fe42fd4b07..27ad1f4964 100644 --- a/libs/canvas/canvas.cc +++ b/libs/canvas/canvas.cc @@ -767,6 +767,28 @@ GtkCanvas::on_button_release_event (GdkEventButton* ev) return deliver_event (reinterpret_cast(©)); } +bool +GtkCanvas::get_mouse_position (Duple& winpos) const +{ + int x; + int y; + Gdk::ModifierType mask; + Glib::RefPtr self = Glib::RefPtr::cast_const (get_window ()); + + if (!self) { + std::cerr << " no self window\n"; + winpos = Duple (0, 0); + return false; + } + + Glib::RefPtr win = self->get_pointer (x, y, mask); + + winpos.x = x; + winpos.y = y; + + return true; +} + /** Handler for GDK motion events. * @param ev Event. * @return true if the event was handled. @@ -788,6 +810,8 @@ GtkCanvas::on_motion_notify_event (GdkEventMotion* ev) DEBUG_TRACE (PBD::DEBUG::CanvasEvents, string_compose ("canvas motion @ %1, %2 canvas @ %3, %4\n", ev->x, ev->y, copy.motion.x, copy.motion.y)); + MouseMotion (point); /* EMIT SIGNAL */ + pick_current_item (point, ev->state); /* Now deliver the motion event. It may seem a little inefficient diff --git a/libs/canvas/canvas/canvas.h b/libs/canvas/canvas/canvas.h index 9b35f0e5f8..e084d18566 100644 --- a/libs/canvas/canvas/canvas.h +++ b/libs/canvas/canvas/canvas.h @@ -113,6 +113,23 @@ public: virtual Coord width () const = 0; virtual Coord height () const = 0; + /** Store the coordinates of the mouse pointer in window coordinates in + @param winpos. Return true if the position was within the window, + false otherwise. + */ + virtual bool get_mouse_position (Duple& winpos) const = 0; + + /** Signal to be used by items that need to track the mouse position + within the window. + */ + sigc::signal MouseMotion; + + /** Ensures that the position given by @param winpos (in window + coordinates) is within the current window area, possibly reduced by + @param border. + */ + Duple clamp_to_window (Duple const& winpos, Duple border = Duple()); + void zoomed(); std::string indent() const; @@ -150,6 +167,8 @@ public: Coord width() const; Coord height() const; + bool get_mouse_position (Duple& winpos) const; + protected: bool on_scroll_event (GdkEventScroll *); bool on_expose_event (GdkEventExpose *);