3

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?

TrebledJ
  • 8,713
  • 7
  • 26
  • 48
Devab LLC
  • 115
  • 1
  • 8
  • Check out SO question: https://stackoverflow.com/questions/44595045/catch-mouse-motion-in-gtkmm – ZF007 Jan 12 '19 at 14:04
  • Possible duplicate of [catch mouse motion in gtkmm](https://stackoverflow.com/questions/44595045/catch-mouse-motion-in-gtkmm) – ZF007 Jan 12 '19 at 14:04
  • 2
    @ZF007 the duplicate you refer doesnt return an x and y coordinates – Devab LLC Jan 14 '19 at 07:32

1 Answers1

1

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;
}
hidefromkgb
  • 5,834
  • 1
  • 13
  • 44