Devab LLC
Devab LLC

Reputation: 115

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?

Upvotes: 3

Views: 1113

Answers (1)

hidefromkgb
hidefromkgb

Reputation: 5903

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;
}

Upvotes: 1

Related Questions