Daniel Gessel
Posts: 117
Joined: Sun Dec 03, 2017 1:47 am
Location: Boston area, MA, US
Contact: Website Twitter

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 11:39 am

Brian Beuken wrote:
Tue Jan 21, 2020 11:31 am
Its my understanding, that Pi1,2,3 etc do not use X11 (I don't doubt that they can, I've just never tried it). The standard way to open a window on these systems is to use DispmanX. This is what I've been doing for a couple of years now.
If you are running the Raspian GUI, you are running X11.

What you are doing with dispmanx is creating a hardware overlay, which sits on top of the display and covers all or part of X windows (or the console, say, if X is not running). Technically speaking, your dispmanx code does not create a window, but that’s a bit of a semantic question.

If you want to find out what the GUI is doing with the cursor, you have to talk to X. So open a connection and use the default root window to query the pointer.

User avatar
PeterO
Posts: 5456
Joined: Sun Jul 22, 2012 4:14 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 11:43 am

Brian Beuken wrote:
Tue Jan 21, 2020 11:13 am
Thanks, but I really just need to get the Raspbian OS cursor, nothing else.
There is no such thing..... As far as I know the only cursor ever(*) generated on a PI is the X11 cursor.

What exactly do you mean by "open a window" because your definition of "window" seems different to the normal one.

PeterO

(*) Unless your own code has created one, in which case you would already know where it is on the screen!
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Brian Beuken
Posts: 210
Joined: Fri Jan 29, 2016 12:51 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 11:52 am

As I thought, can't open a display

Code: Select all

	
	Window root;
	Screen *screen;

	/*
	 * X11 native display initialization
	 */
	
	x_display = XOpenDisplay(NULL);
	if (x_display == NULL)
	{
		printf("Sorry to say we can't create an Xwindow and this will fail");
		exit(0);    // we need to trap this;
	}
	else
		printf("we got an xwindow\n");
	
	root = DefaultRootWindow(x_display);
	screen = ScreenOfDisplay(x_display, 0);
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

Brian Beuken
Posts: 210
Joined: Fri Jan 29, 2016 12:51 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 11:54 am

PeterO wrote:
Tue Jan 21, 2020 11:43 am
Brian Beuken wrote:
Tue Jan 21, 2020 11:13 am
Thanks, but I really just need to get the Raspbian OS cursor, nothing else.
There is no such thing..... As far as I know the only cursor ever(*) generated on a PI is the X11 cursor.

What exactly do you mean by "open a window" because your definition of "window" seems different to the normal one.

PeterO

(*) Unless your own code has created one, in which case you would already know where it is on the screen!
ok fine, but how then do i get the X11 cursor "position" i can comfortably intercept the event and use the delta values to move my own cursor/objects in project but I need in this very specific instance to get hold of the position of the cursor displayed by Raspbian.

(yes sorry Window/display/buffer I tend to get these things all mixed up, I'm a console coder and don't generally need to deal with this level of OS nomenclature)
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

Brian Beuken
Posts: 210
Joined: Fri Jan 29, 2016 12:51 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 12:08 pm

PeterO wrote:
Tue Jan 21, 2020 11:43 am


(*) Unless your own code has created one, in which case you would already know where it is on the screen!
Sadly I don't seem to be making myself clear, I'm sorry.


Once my own code creates render systems and sets up a cursor I can indeed place it anywhere on screen, and control it with the delta values provided by the mice event.. Once my code kicks linux out, Im happy as a pig in muck once my own code is in control.

I need, only, at a startup point, before my own code takes control of the mouse, to know the current positional x y coords of the Raspbian cursor, which will allow a simple DearImgGui setup screen to set up various paramacters with menus and check boxes. The Raspbian cursor is much more precise than my system since at that point i don't know screen res and other info until this screen has completed its setup and gathered info on the users system and requirements .

Now its clear from this thread, that Raspbian GUI is an X11 screen (thats cool i honestly didn't know that), so that cursor data should be accessable with XQueryPointer, but... I can't get access to an XDisplay in order to feed the correct paramaters to XQueryPointer.

Does anyone have a code snippet that gets the current cursor position.
Last edited by Brian Beuken on Tue Jan 21, 2020 12:12 pm, edited 2 times in total.
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

User avatar
PeterO
Posts: 5456
Joined: Sun Jul 22, 2012 4:14 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 12:10 pm

Brian Beuken wrote:
Tue Jan 21, 2020 11:52 am
As I thought, can't open a display

Code: Select all

	
	Window root;
	Screen *screen;

	/*
	 * X11 native display initialization
	 */
	
	x_display = XOpenDisplay(NULL);
	if (x_display == NULL)
	{
		printf("Sorry to say we can't create an Xwindow and this will fail");
		exit(0);    // we need to trap this;
	}
	else
		printf("we got an xwindow\n");
	
	root = DefaultRootWindow(x_display);
	screen = ScreenOfDisplay(x_display, 0);
Are you running that from a text mode console, or from a terminal window in a GUI ?
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Brian Beuken
Posts: 210
Joined: Fri Jan 29, 2016 12:51 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 12:11 pm

PeterO wrote:
Tue Jan 21, 2020 12:10 pm
Brian Beuken wrote:
Tue Jan 21, 2020 11:52 am
As I thought, can't open a display

Code: Select all

	
	Window root;
	Screen *screen;

	/*
	 * X11 native display initialization
	 */
	
	x_display = XOpenDisplay(NULL);
	if (x_display == NULL)
	{
		printf("Sorry to say we can't create an Xwindow and this will fail");
		exit(0);    // we need to trap this;
	}
	else
		printf("we got an xwindow\n");
	
	root = DefaultRootWindow(x_display);
	screen = ScreenOfDisplay(x_display, 0);
Are you running that from a text mode console, or from a terminal window in a GUI ?
PeterO
SSH from a PC using VisualGDB
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

User avatar
PeterO
Posts: 5456
Joined: Sun Jul 22, 2012 4:14 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 12:13 pm

Brian Beuken wrote:
Tue Jan 21, 2020 12:08 pm
. Once my code kicks linux out, Im happy as a pig in muck once my own code is in control.
So are you trying to move towards to a "bare metal" application without the Linux kernel ?
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Brian Beuken
Posts: 210
Joined: Fri Jan 29, 2016 12:51 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 12:15 pm

PeterO wrote:
Tue Jan 21, 2020 12:13 pm
Brian Beuken wrote:
Tue Jan 21, 2020 12:08 pm
. Once my code kicks linux out, Im happy as a pig in muck once my own code is in control.
So are you trying to move towards to a "bare metal" application without the Linux kernel ?
PeterO
Its always there, and I need it for some file handling and input events but other than that my code is selfcontained OpenGLES game engine code.
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

User avatar
PeterO
Posts: 5456
Joined: Sun Jul 22, 2012 4:14 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 12:19 pm

Brian Beuken wrote:
Tue Jan 21, 2020 12:11 pm
SSH from a PC using VisualGDB
I think you should have told us this much earlier.
my code is selfcontained OpenGLES
And that as well.....

We are onto page two and I've still got no idea what you are actually trying to do, or how you are running your code,
so I'll leave it to others .....
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Brian Beuken
Posts: 210
Joined: Fri Jan 29, 2016 12:51 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 12:22 pm

Im trying to get the cursor position from Raspbian... As I said right at the start that should be easy....I'm stumped as to why its so hard.
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

User avatar
PeterO
Posts: 5456
Joined: Sun Jul 22, 2012 4:14 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 12:24 pm

Brian Beuken wrote:
Tue Jan 21, 2020 12:22 pm
Im trying to get the cursor position from Raspbian... As I said right at the start that should be easy....I'm stumped as to why its so hard.
And as we keep telling you "Raspbian" doesn't have a cursor. The only cursor is the one managed by X11 if you are running an X server but it now seems you are running in text mode so it's not at all clear what "cursor" you are trying to locate.

Anyway, it's dinner time......

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Brian Beuken
Posts: 210
Joined: Fri Jan 29, 2016 12:51 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 12:31 pm

ok so PeterO's question about whether it was a GUI or Terminal, led me to check something on my SSH debug settings on Visual GDB, and I found a checkbox that was currently disabled for LinuxGUI(X11) with had 3 options, Forward to Windows (via XMing), Show on Target and Disable.

I changed it from Disable to Show on target and indeed now can open an XDisplay when I run the code on the Pi3

I'll continue my efforts after work, as lunch time play is over.
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 25002
Joined: Sat Jul 30, 2011 7:41 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 1:14 pm

Said multiple times above, but just to be absolutely clear.

ALL PI'S RUNNING RASPBIAN DESKTOP USE X/X11, and have done since launch.

There is NO hardware cursor support in dispmanx, it just draws what it is told - bitmaps. Sometimes, one of those bitmaps MIGHT be a cursor but dispmanx has no idea - it's just a bitmap it needs to display.

To get a list of bitmaps it's currently displaying...

vcgencmd dispmanx_list


I do not know why you are using dispmanx at all.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

User avatar
jojopi
Posts: 3141
Joined: Tue Oct 11, 2011 8:38 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 1:22 pm

Brian Beuken wrote:
Tue Jan 21, 2020 11:54 am
i can comfortably intercept the event and use the delta values to move my own cursor/objects in project but I need in this very specific instance to get hold of the position of the cursor displayed by Raspbian.
It sounds like your application is taking over the whole screen with 3d graphics, reading raw mouse events via the kernel interface, and drawing its own cursors when needed. I do not see why it matters where the desktop cursor was, if there even was one.

If you just plop your cursor in the middle of your own "window" will the user be upset or confused?

Brian Beuken
Posts: 210
Joined: Fri Jan 29, 2016 12:51 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 1:56 pm

I've made it clear earlier that I need to access the Raspbian mouse position...while I do various setups and info gathering... For that I need the accuracy and precision, under whatever resolution the display is in...

THEN I take it over and have my own control systems.
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

Brian Beuken
Posts: 210
Joined: Fri Jan 29, 2016 12:51 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 1:57 pm

jamesh wrote:
Tue Jan 21, 2020 1:14 pm
I do not know why you are using dispmanx at all.
Following systems on line to get an OpenGLES system up and running,
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

Daniel Gessel
Posts: 117
Joined: Sun Dec 03, 2017 1:47 am
Location: Boston area, MA, US
Contact: Website Twitter

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 2:02 pm

jamesh wrote:
Tue Jan 21, 2020 1:14 pm
There is NO hardware cursor support in dispmanx, it just draws what it is told - bitmaps. Sometimes, one of those bitmaps MIGHT be a cursor but dispmanx has no idea - it's just a bitmap it needs to display.
So we can expect no support for e.g, drmModeSetCursor but maybe we could use a small plane with drmModeSetPlane to “emulate” it? I admit, I don’t know the real difference between support for a small, positionable overlay and HW cursor support.

Anyway, enough hijacking the thread; for me attempting HW cursor support is a long way off with a lot of stuff in between...

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 25002
Joined: Sat Jul 30, 2011 7:41 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Tue Jan 21, 2020 2:40 pm

Daniel Gessel wrote:
Tue Jan 21, 2020 2:02 pm
jamesh wrote:
Tue Jan 21, 2020 1:14 pm
There is NO hardware cursor support in dispmanx, it just draws what it is told - bitmaps. Sometimes, one of those bitmaps MIGHT be a cursor but dispmanx has no idea - it's just a bitmap it needs to display.
So we can expect no support for e.g, drmModeSetCursor but maybe we could use a small plane with drmModeSetPlane to “emulate” it? I admit, I don’t know the real difference between support for a small, positionable overlay and HW cursor support.

Anyway, enough hijacking the thread; for me attempting HW cursor support is a long way off with a lot of stuff in between...
drmModeSetCursor. Hmm. I wonder if we need to implement that, or maybe it's already there. Will need to check. Certainly when running the desktop on the pi4, there is a dispmanx layer that appears to be a cursor - might be a result of that drm call.

EDIT: Cursor(y) look at the DRM code, I presume that the cursor you see on the desktop is actually generated from that DRM call. It creates a software cursor, which in FKMS will be generated as a dispmanx layer. Certainly, that API is present, and since we use DRM, is almost certainly what gets called to create the cursor you see on the desktop.

See drivers/gpu/drm/drm_plane.c for the implementation of the kernel side part of the code.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

Brian Beuken
Posts: 210
Joined: Fri Jan 29, 2016 12:51 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Wed Jan 22, 2020 9:49 am

Just as quick note to say thank you and sorry....

Thank you for pointing me in the right direction to (almost) solve my issue, and sorry, because I must have caused a lot of frustation. I've been proceeding for a very very long time on a totally false assumption which has clearly made me seem confused and a little mad.

Y'see, despite appearences I'm a very experienced and practical coder (no really), but I'm NOT an OS coder, I'm a console games coder; I code on hardware, specialised consoles and hardware/embedded systems, as such I seldom, if ever, have to deal with any kind of OS. I usually work with some kind of supplied framework that sets up draw/framebuffers for me to get straight to the system and work directly with CPU's/GPU's etc... Thats just how game systems work. Any access needed to files and input is usually done via an API that makes things simple. I don't code in Windows, Linux,SonyOS or anything else, I just code in C++. I never had any interest in writing tools/apps or anything else that was OS based. I've been working this way since ZX81 days, get into the box and take control.

So..it therefore goes without saying my knowledge of Linux, X11 and everything else for that matter is sketchy at best because, for my purposes all I care about is getting access to my hardware so I can get OpenGL(es) to do its thing, and I handle all my logic,rendering, thread/core management, input reponse and hardware needs, in my own code.

That means I nearly always work with a framework supplied by a hardware maker, and build on that. That framework, gets whatever it needs from the OS, sets up a framebuffer and leaves the OS behind.

But the Raspberry was different, I made a clear effort when I was considering writing about game coding, to choose a machine I knew nothing about, to emulate what my students must feel like when they start, and I picked the Raspberry because I didn't know squat about it, other than it had a solid set of specs that I could relate to, having worked on machines like the GameBoy Advance and DS, I knew ARM, so...should be easy right?

But I had no framework to get into the system, and after searching on line (here I'm pretty sure), I found an example of creating an EGL context that would then let me get OpenGLES up and running and voila I was off. It used DispmanX and I've built on that that last few years and comfortably written a lot of projects that happily work rendering to an EGL context displayed by DispmanX.

My error, and its a big one, compounded by my lack of understanding of Linux systems, was in thinking that DispmanX was some kind of replacement for X11, an assumption further compounded by my discovery that other SBC's I started to code on didn't have DispmanX and I had to cobble together a different framework using X11. I concluded that oh, Raspberry uses this, and Ubuntu uses that, but I got things working so I didn't dig too deep.

At no time did I ever twig that Raspbian is also using X11 (hell, I didn't even know X was X11) , I didn't even notice it was there, I maintained two seperate configs for SBC's one for Raspbian and 1 for every other Linux system thinking Raspberry was the exception to the X11 usage rule. That config to set up has hardly changed in 3 years of coding Raspberries, I didn't need to...it all worked fine, and then...I needed to get an OS cursor position and I thought that would be easy....

I'm happy and a little embarrassed to say my eyes are now a little more open, and I'm altering my systems to now make use of X11 to create my render systems and get cursor positions at my startup.

Can't say I won't have more stupid questions but I felt I should tell you all about the danger of assumptions, especially when you re-enforce them with an, it just works, mentality

Also, can I say, how much I really love coding on the Raspberry, despite strange things like this happening, when you work on machines like the PS4 and Switch, you more or less can do anything you want without having to think much about things, limits are seldom pushed. The Raspberry makes me think every time I try to do something and often leaves me befuddled about why I didn't know such and such. Its like learning all over again.
Last edited by Brian Beuken on Wed Jan 22, 2020 10:51 am, edited 2 times in total.
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

User avatar
PeterO
Posts: 5456
Joined: Sun Jul 22, 2012 4:14 pm

Re: Mouse position in C++ Not with X11 but DispmanX

Wed Jan 22, 2020 10:05 am

Well done Brian ! It's good to understand your "journey".

My "journey" was going from
Desktop PCs with full OpenGL 2 implementations integrated with X windows via EGL running on Radeon graphics cards
to
PIs with OpenGL ES 2 and no X integration
and now with the PI going to
OpenGLES 3 integrated with X windows via EGL.

Keep asking questions :-)

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Return to “C/C++”