I have a simple drawing area, and I have configured
set_event_compression(false). I am printing out motion and button
events, and I see while I move the mouse the motion events come out,
but then when I stop and press the mouse button, I get one more motion
event and then the button press event.
Now I can do this because I'm using a trackball, so it is easy to press
a button without incurring any further actual mouse motion.
When I comment out the line to set_event_compression, I do not see this
behavior. So instead when I press the mouse button, I just get a button
press, and the coordinates of that button press match exactly to the
last motion event.
I wonder if someone can either confirm it is a bug, or I really hope
that it is a problem I'm doing. I am using GTKMM 3.24.6.
Here is a simple example which I compiled with:
g++ -o drawtest $(pkg-config --cflags --libs gtkmm-3.0) drawtest.cpp
#include <gtkmm.h>
#include <iostream>
class drawingArea : public Gtk::DrawingArea
{
public:
drawingArea(GtkDrawingArea* cObject, const
Glib::RefPtr<Gtk::Builder>& builder) : Gtk::DrawingArea(cObject),
eventNum(0) { };
void on_realize(void) override;
int eventNum;
bool on_button_press_event(GdkEventButton* event);
bool on_button_release_event(GdkEventButton* event);
bool on_motion_notify_event(GdkEventMotion* event);
};
void drawingArea::on_realize(void)
{
Gtk::DrawingArea::on_realize();
get_window()->set_event_compression(false);
}
bool drawingArea::on_button_press_event(GdkEventButton* event)
{
std::cout << eventNum++ << " button pressed " << event->x << ":" <<
event->y << std::endl;
return true;
}
bool drawingArea::on_button_release_event(GdkEventButton* event)
{
std::cout << eventNum++ << " button released " << event->x << ":"
<< event->y << std::endl;
return true;
}
bool drawingArea::on_motion_notify_event(GdkEventMotion* event)
{
std::cout << eventNum++ << " motion " << event->x << ":" <<
event->y << std::endl;
return true;
}
int main (int argc, char **argv)
{
auto app = Gtk::Application::create(argc, argv, "org.drawarea");
Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create();
builder->add_from_file("drawarea.glade");
Gtk::Window* mainWindow = nullptr;
builder->get_widget("Window", mainWindow);
drawingArea* drawArea = nullptr;
builder->get_widget_derived("drawing", drawArea);
drawArea->add_events(Gdk::POINTER_MOTION_MASK |
Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
app->run(*mainWindow);
delete mainWindow;
}
Attachment:
signature.asc
Description: OpenPGP digital signature