English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System

 
 
Thread Tools
Old 19 November 2023, 08:30   #1
Steam Ranger
Registered User
 
Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide, South Australia, Australia
Posts: 208
Uninteruptable mouse movement events

How do I get the mouse position regardless of whether my window is selected or not? I want to get the same kind of coordinates that I get from the report mouse flag, but also get them if a window is selected other than mine.

The ideal solution would be if Intuition could report mouse events to my program, but it would be alright if I had to manually query the mouse position, as long as it always works even when my window is not selected.
Steam Ranger is offline  
Old 19 November 2023, 09:17   #2
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,043
Add your interrupt handler to input.device.
a/b is offline  
Old 19 November 2023, 09:25   #3
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,247
Quote:
Originally Posted by Steam Ranger View Post
How do I get the mouse position regardless of whether my window is selected or not? I want to get the same kind of coordinates that I get from the report mouse flag, but also get them if a window is selected other than mine.

The mouse position in your window is relative to the window, and thus not relative to all other windows. You can get a mouse position relative to the screen from the screen structure, but that is also only valid if the screen contains the active window. Thus, in a sense, what you request is not exactly possible as users may certainly open more screens, and select active windows on other screens. Since such other screens may be larger or smaller, mouse movement on them may be also scaled differently.


IOWs, while you can possibly get relative mouse movements, you do not get meaningful mouse coordinates without having a window and an input focus.
Thus, please rethink your design - what is it that you need data from the mouse without having the focus?
Thomas Richter is offline  
Old 19 November 2023, 09:51   #4
Olaf Barthel
Registered User
 
Join Date: Aug 2010
Location: Germany
Posts: 532
Quote:
Originally Posted by a/b View Post
Add your interrupt handler to input.device.
Tricky. The raw mouse events which pass through the input handler contain no mouse position information, just movement delta information.

This has to be translated into the respective screen position of where Intuition has currently placed the mouse pointer. You need to find the screen in which the currently active window resides and copy the Screen->MouseX and Screen->MouseY values. For that to work, you ought to use LockIBase() and UnLockIBase() while you are looking for the active screen. And eventually notify your program where the mouse is currently at.

All of this is doable, but easy to get wrong. Calling LockIBase() from within the input handler is strongly discouraged but works most of the time because Intuition was rewritten to allow for it, rather than to deadlock the Intuition state machine (this was easy enough in the Kickstart 1.x days).

Generally, I would not recommend this approach. I would recommend using the simplest possible approach the operating system offers you and adapt your program to make the best of it. This is a multitasking operating system after all. You could try polling your program's Screen->MouseX and Screen->MouseY values by using timer.device. 1/10s intervals should be a good start.
Olaf Barthel is offline  
Old 19 November 2023, 10:19   #5
Steam Ranger
Registered User
 
Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide, South Australia, Australia
Posts: 208
Quote:
Originally Posted by Olaf Barthel View Post
Tricky. The raw mouse events which pass through the input handler contain no mouse position information, just movement delta information.

This has to be translated into the respective screen position of where Intuition has currently placed the mouse pointer. You need to find the screen in which the currently active window resides and copy the Screen->MouseX and Screen->MouseY values. For that to work, you ought to use LockIBase() and UnLockIBase() while you are looking for the active screen. And eventually notify your program where the mouse is currently at.

All of this is doable, but easy to get wrong. Calling LockIBase() from within the input handler is strongly discouraged but works most of the time because Intuition was rewritten to allow for it, rather than to deadlock the Intuition state machine (this was easy enough in the Kickstart 1.x days).

Generally, I would not recommend this approach. I would recommend using the simplest possible approach the operating system offers you and adapt your program to make the best of it. This is a multitasking operating system after all. You could try polling your program's Screen->MouseX and Screen->MouseY values by using timer.device. 1/10s intervals should be a good start.
That sounds essentially like what I'm doing in Linux. I'm making my program for Linux and Amiga you see. Currently on Linux my program is informed by XInput whenever the mouse moves, and it manually asks Xlib where the pointer is.

That thing about the screens and active window sounds a bit troublesome though. I think the best way would just be to check MouseX and MouseY every time my library's processing loop is called, and notify the program if it has changed.
Steam Ranger is offline  
Old 19 November 2023, 10:52   #6
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,006
Quote:
Originally Posted by Steam Ranger View Post
regardless of whether my window is selected or not?
So you do have a window? All the other replyers seem to imply that you don't have a window. If you have a window you can read Window->MouseX and MouseY to get the same coordinates you would get from an IntuiMessage. They are kept up to date even if your window is not the active one.
thomas is offline  
Old 19 November 2023, 11:05   #7
Steam Ranger
Registered User
 
Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide, South Australia, Australia
Posts: 208
Quote:
Originally Posted by thomas View Post
So you do have a window? All the other replyers seem to imply that you don't have a window. If you have a window you can read Window->MouseX and MouseY to get the same coordinates you would get from an IntuiMessage. They are kept up to date even if your window is not the active one.
Are they kept up to date even if the pointer is not on the same screen as my window?
Steam Ranger is offline  
Old 19 November 2023, 11:21   #8
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,006
Yes.
thomas is offline  
Old 19 November 2023, 11:41   #9
Steam Ranger
Registered User
 
Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide, South Australia, Australia
Posts: 208
Nice. I'll have to implement a simple test using those to see if they work as I'm expecting.
Steam Ranger is offline  
Old 19 November 2023, 13:17   #10
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,247
Yes, but.... As stated earlier, this information is next to useless if a window on another screen has the focus, and intuition (unlike X) has the concept of screens, and multiple of them can be open at the same time, and the focus being somewhere on a different screen.

Thus, again, what makes you think that you need this information? Screen->MouseX,Y or Window->MouseX,Y may *not* be what you expect them to be, in particular if multiple screens are involved.
Thomas Richter is offline  
Old 19 November 2023, 13:38   #11
Steam Ranger
Registered User
 
Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide, South Australia, Australia
Posts: 208
Quote:
Originally Posted by Thomas Richter View Post
Yes, but.... As stated earlier, this information is next to useless if a window on another screen has the focus, and intuition (unlike X) has the concept of screens, and multiple of them can be open at the same time, and the focus being somewhere on a different screen.

Thus, again, what makes you think that you need this information? Screen->MouseX,Y or Window->MouseX,Y may *not* be what you expect them to be, in particular if multiple screens are involved.
What I expect is a way to get the same information provided by report mouse events, but constantly without any regard to the position of the pointer or the currently active window.

To simplify with an example, something you could use to make xeyes, where if follows your pointer constantly.
Steam Ranger is offline  
Old 19 November 2023, 17:32   #12
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,630
Amigas may have multiple screens visible at once, with different resolutions (unlike most other platforms), so I'm not sure that even makes sense - what would the pointer coordinates tell you in such a case?
hooverphonique is offline  
Old 19 November 2023, 21:44   #13
Steam Ranger
Registered User
 
Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide, South Australia, Australia
Posts: 208
Quote:
Originally Posted by hooverphonique View Post
Amigas may have multiple screens visible at once, with different resolutions (unlike most other platforms), so I'm not sure that even makes sense - what would the pointer coordinates tell you in such a case?
Well the pointer coordinates are relative to the window, so it should still work fine on other screens.
Steam Ranger is offline  
Old 19 November 2023, 22:10   #14
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,247
Quote:
Originally Posted by Steam Ranger View Post
Well the pointer coordinates are relative to the window, so it should still work fine on other screens.
No, it would not. Once again, mouse positions are scaled according to screen resolutions, and screens (in particular on RTG) have different resolutions. That means that a mouse position relative to a screen that is different from the screen your window is sitting on is next to meaningless. This may be quite irrelevant for toys like Xeyes, but if you use this as a design for more relevant software, things can go quite wrong. You can surely read window->MouseX,Y from your window while it is active, and even without receiving mouse movement events, but when your window is not active, these coordinates are not necessarily in a useful relation to where the mouse pointer actually is. It may be even on a completely different monitor for a two-monitor configuration.
Thomas Richter is offline  
Old 20 November 2023, 02:18   #15
Steam Ranger
Registered User
 
Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide, South Australia, Australia
Posts: 208
@thomas Thankyou for pointing me in this direction. MouseX and MouseY work perfectly for my use. Is there anything that modifies its function that I should be aware of?
Steam Ranger is offline  
Old 20 November 2023, 07:30   #16
Bruce Abbott
Registered User
 
Bruce Abbott's Avatar
 
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,652
Quote:
Originally Posted by Steam Ranger View Post
That sounds essentially like what I'm doing in Linux. I'm making my program for Linux and Amiga you see. Currently on Linux my program is informed by XInput whenever the mouse moves, and it manually asks Xlib where the pointer is.
What does your program do that requires knowing the pointer position when another program has the focus?
Bruce Abbott is offline  
Old 20 November 2023, 07:40   #17
Steam Ranger
Registered User
 
Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide, South Australia, Australia
Posts: 208
Quote:
Originally Posted by Bruce Abbott View Post
What does your program do that requires knowing the pointer position when another program has the focus?
I'm not making a program per-say, I'm making a library. This is a feature that's required as certain programs may make use of it (xeyes for example).
Steam Ranger is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Smoother mouse movement under WinUAE hexaae support.WinUAE 23 29 December 2019 13:37
custom input events / mouse click? E-Penguin support.WinUAE 2 24 November 2018 21:13
mouse wheel events meynaf Coders. System 1 26 August 2018 16:06
Reverse left/right on mouse movement musojon74 support.Hardware 7 14 February 2016 17:45
Jerky mouse movement andreas support.WinUAE 3 02 June 2002 19:14

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 18:45.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09307 seconds with 15 queries