Re: With set_event_compression, most recent motion event is held in waiting



Hi, thanks for taking the time. 

I have updated my test. Now you don't have to press a mouse button, but
you can press a keyboard key instead. The problem isn't that I am
seeing extra events, the problem is that the extra event seems to be
hiding, or stuck in a backend/library queue. With the latest code you
can do this:

Move the mouse around inside the DrawingArea. Let go of the mouse so no
further motion events occur. Observe the last event number to be
received.

Press a key on the keyboard. You will immediately see two events, going
by increasing event number. One new motion event, even though the mouse
should be perfectly stationary, and then the key press event.

If you comment out the set_event_compression and then retry the above
test, you will always only receive the key press event, no extra,
lingering motion event.

If this is a problem, I suspect it is in GTK+, but I haven't gotten
around to rewriting the code in C. Another thing I want to try is just
rebooting my computer (I know, crazy Windows concept) just in case that
causes the problem to go away.


Here are some updated files. First the basic .glade file:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
  <requires lib="gtk+" version="3.24"/>
  <object class="GtkWindow" id="Window">
    <property name="can-focus">False</property>
    <child>
              <object class="GtkDrawingArea" id="drawing">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="position">1</property>
              </packing>
            </child>
  </object>
</interface>

And here is an updated C++ file:

#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);
        bool on_key_press_event(GdkEventKey* event);

};

void drawingArea::on_realize(void)
{
    Gtk::DrawingArea::on_realize();
    get_window()->set_event_compression(false);
    grab_focus();
}

bool drawingArea::on_key_press_event(GdkEventKey* event)
{
    std::cout << eventNum++ << " key pressed\n";
    return true;
}

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);
    drawArea->set_can_focus(true);

    app->run(*mainWindow);
    delete mainWindow;
}


On Mon, 2022-05-23 at 16:21 +0200, Kjell Ahlstedt wrote:
I thought I'd run your program and see what happens, but that's
difficult without the drawarea.glade file.
What is it that you suspect is a bug? That you get an extra motion
event with set_event_compression(false)? Or that you don't get it
with set_event_compression(true)? It's hardly surprising that the
number of motion events differ with and without event compression.
Den 2022-05-21 kl. 03:43, skrev Jason M'Sadoques via gtkmm-list:
 
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

 

Attachment: signature.asc
Description: OpenPGP digital signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]