Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get cursor position with Gtkmm?

Which Gtkmm functions can help me get the position(x,y) of the cursor. According to this, C# has

Gdk.Display.Default.WarpPointer(Gdk.Display.DefaultScreen, 20, 20);

Windows has

GetCursorPos

Qt has

QCursor::pos()

Gtkmm has what?

like image 455
Devab LLC Avatar asked Feb 03 '26 20:02

Devab LLC


1 Answers

Here you are.

#include <stdio.h>
#include <gtkmm.h>

int main(int argc, char* argv[]) {
    Gtk::Main gtkm(argc, argv);
    Glib::RefPtr<Gdk::Display> disp = Gdk::Display::get_default();
    Glib::RefPtr<Gdk::Screen> scrn = disp->get_default_screen();
    Gdk::ModifierType mods;
    int xpos, ypos;

    disp->get_pointer(scrn, xpos, ypos, mods);
    printf("xpos = %d, ypos = %d\n", xpos, ypos);
    return 0;
}
like image 137
hidefromkgb Avatar answered Feb 05 '26 09:02

hidefromkgb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!