GUI use with Raspberry Pi + official 7" touch screen

I have a little project needing a GUI that I am writing for the Pi 2 with the official 7" ouchscreen. Although there are OF addons to get the touchscreen data out, these don’t integrate with any of the GUI addons I have seen, linking their mouse move & click events to the triggers for things like button presses and slider drags.

Does anyone have a favourite way around this? Currently I am manually trapping touchscreen events and categorising them (as I can’t see how to emulate mouse events and pass them directly to the GUI handlers) but if anyone could point me in a more sensible direction I would be most grateful!

if you are 100% sure that your driver does not touch interface with mouse events, then you can use this addons:

(some drivers for touch GPIO do not provide a bridge with mouse events of the operating system, but some yes)

https://github.com/kashimAstro/ofxTFTTouch

in combo with X11 events:

#include <linux/input.h>

struct input_event ie;

**check this function:**

Display *dpy = XOpenDisplay(NULL); <-- check this
XQueryPointer(dpy,DefaultRootWindow(dpy),&root,&child, &rootX,&rootY,&winX,&winY,&mask);
XSelectInput(dpy, root_window, KeyReleaseMask);
XWarpPointer(dpy, None, root_window, 0, 0, 0, 0, 100, 100);
....

Hi @kashim

It’s actually your addon that I am using already! As far as I can see, the official RPi display driver interfaces with X, but not directly to the OS itself - that is to say I can move the mouse pointer in Raspbian, but not when running an OF app.

I’m not sure I understand from your reply how to send an OS-level mouse event that will get picked up in an OF app. Would you mind elaborating a bit to help my slow brain out?

here a draft untested code:

#include "ofMain.h"
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "ofxTFTTouch.h"

Display *display;
Window root;
ofxTFTTouch touch;
int w,h;

void setup(){
    		w=ofGetScreenWidth();
    		h=ofGetScreenHeight();
    		touch.init("/dev/input/event0",w,h);
    		ofLog()<<touch.getName();
}

 void exit(){
                touch.exit();
}

void update(){
    		if(touch.getCoordTouch().z!=0){
                      if ((display = XOpenDisplay(NULL)) == NULL) {
                                ofLog()<<"Cannot open local X-display.\n";
                      }
                      root = DefaultRootWindow(display);
    		      XWarpPointer(display, None, None, 0, 0, 0, 0,touch.getCoordTouch().x,touch.getCoordTouch().y);
                      XCloseDisplay(display);

                }
}

but the way it should be,

for example using the pressure coordinates (touch.getCoordTouch().z) of addons ofxTFTTouch, you can activate the XWrapPointer event where the last two parameters (X, Y mouse) you pass here the coordinates taken by ofxTFTTouch “touch.getCoordTouch().x, touch.getCoordTouch().y”.

Thanks for this - looks good to me. I will give it a try this evening when I am back in front of the hardware.

@stefandz did you get the official 7" touch display working in you project? Unfortunately absolutely the same problem here …

No, never got it working - used @kashim’s method - that worked.

@stefandz Which exact method do you mean?

Do you have a working example maybe? That would be very helpful! : )

The project I was working on never went further than POC so I would have to dig it out and clean it up. The method I used was based off @kashim’s code 5 posts up from this one.