Linux mouse question

22 views
Skip to first unread message

Carlo Hogeveen

unread,
May 27, 2024, 7:58:31 AMMay 27
to Semware @ GoogleGroups

Sammy,

Now that I got the Linux mouse "working" in text, I have a choice to make regarding if and how I want to make it work for menus,
prompts, lists, etc.

A Linux mouse event tells me at which coordinates it happened.

Unfortunately I cannot do something like:
Set(MouseX, 10)
Set(MouseY, 11)
PressKey(<LeftBtn>)
This either goes to the macro menu or makes Linux TSE hang.
Not too surprising; this probably just means that mouse functions are not implemented in Linux TSE.

Before I create a complex work-around or decide that that is not cost-beneficial, it makes sense to ask you the following.

Given that Linux TSE understands mouse key names, and given that mouse functions are already implemented in Windows TSE, would it be
doable for you to make the above example (or a new function) work for menus, etc. throughout Linux TSE?

Carlo

Aside, irrelevant for the above question, v1 of this promised test macro is now published:
https://ecarlo.nl/tse/DemosAndTests.html#LinuxMouseTest



S.E. Mitchell

unread,
May 27, 2024, 12:09:54 PMMay 27
to sem...@googlegroups.com
So it looks like set(mousex, ...) and set(mousey, ...) work.
The problem is what does the editor do with LeftBtn in the Linux
version. And I'm having a hard time figuring that out :( I'll
continue to look.
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/semware/000401dab02d%242ed50420%248c7f0c60%24%40ecarlo.nl.

S.E. Mitchell

unread,
May 27, 2024, 12:21:31 PMMay 27
to sem...@googlegroups.com
I may have found the problem.
There is a routine, loInitMouse() that returns
"GetSystemMetrics(SM_MOUSEPRESENT) != 0;" in the Windows version(s),
but simply FALSE in the Linux version.
I'm going change it to return TRUE. I'll make a test version available.

Carlo Hogeveen

unread,
May 27, 2024, 12:28:39 PMMay 27
to sem...@googlegroups.com

Looking forward to it.
I will gladly test it.

Carlo



knud van eeden

unread,
May 27, 2024, 12:33:49 PMMay 27
to sem...@googlegroups.com

FYIO

It sounds like you have identified a discrepancy between the Windows and Linux versions of the `loInitMouse()` function. 

Specifically, the Windows version checks if a mouse is present using the `GetSystemMetrics(SM_MOUSEPRESENT)` function, while the Linux version simply returns `FALSE`.

Here is a more detailed breakdown of your approach:

1. **Understanding `GetSystemMetrics(SM_MOUSEPRESENT)`**:

   - In Windows, `GetSystemMetrics(SM_MOUSEPRESENT)` is a system call that returns a non-zero value if a mouse is present.

   - Returning `TRUE` for the Linux version would make the behavior consistent across both platforms, assuming that you are 
confident that a mouse will always be present or that this simplification is acceptable for your application's needs.

2. **Modifying the Linux Version**:

   - Instead of returning `FALSE`, you will modify the `loInitMouse()` function to return `TRUE`.

3. **Testing**:

   - After making this change, you plan to create a test version of your application to verify that the modification works as expected.

Here is a sample of how you might adjust the `loInitMouse()` function in your Linux code:


// Original code in Linux version
bool loInitMouse() {
    return FALSE;
}

// Modified code in Linux version
bool loInitMouse() {
    return TRUE;
}


### Testing Your Change
Make sure to test the following aspects:

1. **Mouse Detection**:
   - Ensure that the application behaves correctly when a mouse is present.
   - Verify that there are no regressions or unexpected behavior when the mouse is used.

2. **Cross-Platform Consistency**:
   - Confirm that the application behaves consistently on both Windows and Linux platforms with the new change.

3. **Edge Cases**:
   - Test edge cases where the mouse might be disconnected or reconnected during the application's runtime, if applicable.

### Making a Test Version Available
Once you have made the change and built the test version, share it with your team or users who can help validate the fix. This will help ensure that the modification achieves the desired outcome without introducing new issues.

If you encounter any further issues or need more assistance, feel free to provide more details, and I can offer additional guidance.

with friendly greetings
Knud van Eeden

knud van eeden

unread,
May 27, 2024, 12:36:44 PMMay 27
to sem...@googlegroups.com
> What is the Linux equivalent of GetSystemMetrics(SM_MOUSEPRESENT)?

In Linux, there is not a direct equivalent of `GetSystemMetrics(SM_MOUSEPRESENT)` as found in Windows. However, you can determine if a mouse is present by checking for mouse devices in the `/dev/input` directory. One common approach is to look for event devices related to the mouse, such as `/dev/input/mice` or `/dev/input/mouseX`.

Here is a sample function that checks for the presence of a mouse in Linux:

```c
#include <stdbool.h>
#include <unistd.h>
#include <fcntl.h>

// Function to check if a mouse device is present
bool isMousePresent() {
    // Try to open a typical mouse device file
    int fd = open("/dev/input/mice", O_RDONLY);
    if (fd == -1) {
        // If opening the device file fails, the mouse is not present
        return false;
    } else {
        // If opening succeeds, close the file and return true
        close(fd);
        return true;
    }
}

bool loInitMouse() {
    return isMousePresent();
}
```

### Explanation:
- **Opening the Device File**: The function attempts to open `/dev/input/mice`, which is a general mouse device file that usually exists if a mouse is present.
- **Error Handling**: If the file can not be opened (returns `-1`), it indicates that the mouse is not present, and the function returns `false`.
- **Success Case**: If the file can be opened, it closes the file and returns `true`, indicating that a mouse is present.

This approach relies on the presence of the `/dev/input/mice` file. For a more robust solution, you might want to check other potential mouse device files or use higher-level libraries such as `libudev` to query input devices more comprehensively.

Here is an example using `libudev` to find mouse devices:

```c
#include <libudev.h>
#include <stdbool.h>

bool isMousePresent() {
    struct udev *udev = udev_new();
    if (!udev) {
        return false;
    }

    struct udev_enumerate *enumerate = udev_enumerate_new(udev);
    udev_enumerate_add_match_subsystem(enumerate, "input");
    udev_enumerate_scan_devices(enumerate);

    struct udev_list_entry *devices = udev_enumerate_get_list_entry(enumerate);
    struct udev_list_entry *entry;
    bool mouseFound = false;

    udev_list_entry_foreach(entry, devices) {
        const char *path = udev_list_entry_get_name(entry);
        struct udev_device *device = udev_device_new_from_syspath(udev, path);
        const char *devtype = udev_device_get_devtype(device);

        if (devtype && strcmp(devtype, "mouse") == 0) {
            mouseFound = true;
            udev_device_unref(device);
            break;
        }
        udev_device_unref(device);
    }

    udev_enumerate_unref(enumerate);
    udev_unref(udev);

    return mouseFound;
}

bool loInitMouse() {
    return isMousePresent();
}
```

### Explanation:
- **Using `libudev`**: This code uses the `libudev` library to enumerate input devices and check for any device with the type "mouse".
- **Initialization and Cleanup**: It initializes the `udev` context and enumerates devices in the "input" subsystem.
- **Device Checking**: It iterates over the devices and checks their type. If a mouse device is found, it sets `mouseFound` to `true` and breaks the loop.
- **Cleanup**: It unrefs the enumerate and udev structures before returning the result.

This method is more flexible and robust, suitable for complex environments where multiple input devices might be present.


knud van eeden

unread,
May 27, 2024, 12:42:13 PMMay 27
to sem...@googlegroups.com
So I guess the choice of always 'true' in Linux is a good enough solution.

It does not harm I guess to always assume there is a mouse present,
so additional tests are in the case of a text editor like TSE
not necessary, so just returning true.


S.E. Mitchell

unread,
May 28, 2024, 7:06:43 AMMay 28
to sem...@googlegroups.com
This:
Set(MouseX, 10)
Set(MouseY, 11)
PressKey(<LeftBtn>)

No longer causes the Linux version to hang.

On Mon, May 27, 2024 at 7:58 AM Carlo Hogeveen <t...@ecarlo.nl> wrote:
>
>

Carlo Hogeveen

unread,
May 28, 2024, 2:36:23 PMMay 28
to sem...@googlegroups.com

Sammy,

LinuxMouse v0.2 (a beta) now sometimes works for menus too!
https://ecarlo.nl/tse/InDevelopment.html#LinuxMouse
Only for Linux TSE v4.50rc24 upwards of course.
I have some debugging to do.
Thanks!

Carlo

knud van eeden

unread,
May 28, 2024, 3:50:25 PMMay 28
to sem...@googlegroups.com
FYIO:

===

A. Tested very quickly with WSL 2 > Linux Ubuntu > TSE version 4.50 RC24

1. Clicking in the text with the mouse moves to that position, as expected, business as usual.

2. The middle scrollwheel scrolls the text up or alternatively down, as expected, business as usual.

This does not work in UBUNTU:
3. Clicking on the menu options does not open the menu options, but scrolls the text upwards instead. Expected is of course that it
should open the menu options.

===

A. Tested very quickly with WSL 2 > Linux Debian > TSE version 4.50 RC24

1. Clicking in the text with the mouse moves to that position, as expected, business as usual.

2. The middle scrollwheel scrolls the text up or alternatively down, as expected, business as usual.

This works in DEBIAN:

3. Clicking on the menu options does open the menu options, as expected

===

A. Tested very quickly with WSL 2 > Linux Red Hat > TSE version 4.50 RC24

1. Clicking in the text with the mouse moves to that position, as expected, business as usual.

2. The middle scrollwheel scrolls the text up or alternatively down, as expected, business as usual.

This works in RED HAT:

3. Clicking on the menu options does open the menu options, as expected.

===

A. Tested very quickly with WSL 2 > Linux SUSE > TSE version 4.50 RC24

1. Clicking in the text with the mouse moves to that position, as expected, business as usual.

2. The middle scrollwheel scrolls the text up or alternatively down, as expected, business as usual.

This works in SUSE:

3. Clicking on the menu options does open the menu options, as expected.

===

WSL 2 on Microsoft Windows 10 Professional

with friendly greetings
Knud van Eeden

--

---
You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.

knud van eeden

unread,
May 28, 2024, 4:02:06 PMMay 28
to sem...@googlegroups.com
1. Double checking and trying to reproduce again: 

    => Ubuntu works also as expected and menu options open as expected. So no issue thus.

2. Further some menu options in general on the 4 Linux operating system after clicking work, but others not
and open and close very quickly not being able to see the content.



Carlo Hogeveen

unread,
May 28, 2024, 4:47:17 PMMay 28
to sem...@googlegroups.com

And now LinuxMouse v0.3 works consistently well for menus, and fixes that for some menu options random characters leaked into the text.

https://ecarlo.nl/tse/InDevelopment.html#LinuxMouse

Still only for Linux TSE v4.50rc24 upwards and the other requirements of course.

Again Sammy, thanks for the new Linux TSE work-around,
Carlo



knud van eeden

unread,
May 28, 2024, 5:48:59 PMMay 28
to sem...@googlegroups.com

After doing a very quick test of the menu options opened with the mouse:

currently only TSE menu > 'File' > 'Show File Info' 

does not work via the mouse 

(the window does not stay open)

But it does via the keyboard.



Carlo



--

---
You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.

H P

unread,
May 29, 2024, 8:27:27 AMMay 29
to sem...@googlegroups.com
Carlo, 

As I stated I'm using Ubuntu as a OS on a laptop.
Scrolling with the mousewheel was already working but with linuxmouse 0.3 it now longer works.
Point and click with the mouse does work but not on the menu (top line) and not in the menu-options.

Met vriendelijke groet,
With kind regards,
Muy atentamente,
Mit Freundliche Gruß,
Sinceramente,


H. Pikaar

Henri...@gmail.com



Op di 28 mei 2024 om 22:47 schreef Carlo Hogeveen <t...@ecarlo.nl>:
--

---
You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.

knud van eeden

unread,
May 29, 2024, 8:30:20 AMMay 29
to sem...@googlegroups.com
Just FYIO:

> From the latest LinuxMouse.s file information:

> It does not distinguish between mouse buttons yet.
> <F1> is disabled: You need to define an alternative key for TSE's Help.

---

As far as I can tell when testing does LinuxMouse.s version latest 
disable 4 function keys:

 <F1>
 <F2>
 <F3>
 <F4>

Steps to reproduce:

1. Execute macro LinuxMouse

2. Run ShowKey() in the Potpourri

3. Press <F1>, then <F2>, then <F3>, then <F4>

4. Result:

       255     255    ffff   65535   <CtrlAltShift  > 
       255     255    ffff   65535   <CtrlAltShift  > 
       255     255    ffff   65535   <CtrlAltShift  > 
       255     255    ffff   65535   <CtrlAltShift  > 

5. But expected was:

  p     112      16    1070    4208   <F1>   
  q     113      16    1071    4209   <F2>   
  r     114      16    1072    4210   <F3>   
  s     115      16    1073    4211   <F4>   

6. If one purges the LinuxMouse.mac macro the usual
behavior as seen in 5. is seen again. 

So therefore root cause assumed to be the LinuxMouse.s macro.

Running TSE Linux version 4.50 RC24 
on Microsoft Windows 10 Professional
within WSL 2 running Ubuntu

with friendly greetings
Knud van Eeden

knud van eeden

unread,
May 29, 2024, 8:35:21 AMMay 29
to sem...@googlegroups.com
Note:

The outcome as seen in 4. below is only when pressing the <F1>, <F2>, <F3>, <F4> key the FIRST time.

If one presses those keys a SECOND or more times it will show again the usual expected behavior as seen in step 5.

Note:

Also the first version of LinuxMouse.s shows this same behavior above.


Carlo Hogeveen

unread,
May 29, 2024, 6:16:30 PMMay 29
to sem...@googlegroups.com

HP,

You wrote:

>As I stated I'm using Ubuntu as a OS on a laptop.
I reproduced this by installing Ubuntu Desktop in a virtual machine.
During installation I enabled the Ubuntu's mouse setting.

> Scrolling with the mousewheel was already working
I could reproduce this!

> but with linuxmouse 0.3 it now longer works.
I could not reproduce this. The mouse still works, but scrolls slower.

> Point and click with the mouse does work
I could reproduce this: LinuxMouse enabled it.

> but not on the menu (top line) and not in the menu-options.
These do work for me in my Ubuntu Desktop virtual machine.

Especially based on that last difference I have to verify:
Did you upgrade Linux TSE to v4.50rc24?
LinuxMouse needs Linux TSE v4.50rc24 to work for TSE menus.

Carlo




H P

unread,
May 30, 2024, 7:07:35 AMMay 30
to sem...@googlegroups.com
HP,

You wrote:

>As I stated I'm using Ubuntu as a OS on a laptop.
I reproduced this by installing Ubuntu Desktop in a virtual machine.
During installation I enabled the Ubuntu's mouse setting.

> Scrolling with the mousewheel was already working
I could reproduce this!

> but with linuxmouse 0.3 it now longer works.
I could not reproduce this. The mouse still works, but scrolls slower.
Only with the cursor on line 1 it scrolls 1 line down and that's it.

> Point and click with the mouse does work
I could reproduce this: LinuxMouse enabled it.
Confirmed.


> but not on the menu (top line) and not in the menu-options.
These do work for me in my Ubuntu Desktop virtual machine.
They do work only when for example menu, macro, load macro: when empty double click under windows acts as enter but under linux nothing happens you have to click the enter key.

Especially based on that last difference I have to verify:
Did you upgrade Linux TSE to v4.50rc24?
LinuxMouse needs Linux TSE v4.50rc24 to work for TSE menus.
Yes.

Met vriendelijke groet,
With kind regards,
Muy atentamente,
Mit Freundliche Gruß,
Sinceramente,


H. Pikaar

Henri...@gmail.com



Op do 30 mei 2024 om 00:16 schreef Carlo Hogeveen <t...@ecarlo.nl>:
--

---
You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.

Carlo Hogeveen

unread,
May 30, 2024, 7:57:03 AMMay 30
to sem...@googlegroups.com

HP,

>>> but with linuxmouse 0.3 it now longer works.
>> I could not reproduce this. The mouse still works, but scrolls slower.
> Only with the cursor on line 1 it scrolls 1 line down and that's it.

I cannot explain that difference.
It might be relevant that I run TSE in the default "Terminal" that comes with Ubuntu Desktop.

>>> but not on the menu (top line) and not in the menu-options.
>> These do work for me in my Ubuntu Desktop virtual machine.
> They do work only when for example menu, macro, load macro: when empty double click under windows acts as enter but under linux nothing happens you have to click the enter key.

“Only”? 😢

I have to get technical and nitpicky here.
As I see it, almost all menus work, but prompts (and lists and whatnot) do not (yet).
So yes, the mouse will not work in the "Load macro:" prompt, but will in the menus leading up to it.

Aside:
Ubuntu Desktop is the most user-friendly Linux desktop I have seen to date.
The rumors about the company behind it scare me away from using it IRL.
Then again, similar rumors exist about Windows.

Carlo



H P

unread,
May 30, 2024, 8:29:27 AMMay 30
to sem...@googlegroups.com
Carlo, 
>>> but with linuxmouse 0.3 it now longer works.
>> I could not reproduce this. The mouse still works, but scrolls slower.
> Only with the cursor on line 1 it scrolls 1 line down and that's it.

I cannot explain that difference.
It might be relevant that I run TSE in the default "Terminal" that comes with Ubuntu Desktop.
I also use TSE in Terminal.


>>> but not on the menu (top line) and not in the menu-options.
>> These do work for me in my Ubuntu Desktop virtual machine.
> They do work only when for example menu, macro, load macro: when empty double click under windows acts as enter but under linux nothing happens you have to click the enter key.
Sorry my english is a little dumb. It does work in the menu but don't in the above option menu, macro, load macro: when empty double click under windows acts as enter but under linux nothing happens you have to click the enter key.
Which is a bit strange because it makes a difference between clicking on an other option and the above example which seems to implie that the enter which is generated by clicking is a different one.

“Only”? 😢

I have to get technical and nitpicky here.
As I see it, almost all menus work, but prompts (and lists and whatnot) do not (yet).
So yes, the mouse will not work in the "Load macro:" prompt, but will in the menus leading up to it.

Aside:
Ubuntu Desktop is the most user-friendly Linux desktop I have seen to date.
The rumors about the company behind it scare me away from using it IRL.
Then again, similar rumors exist about Windows.
I was a Suse fan but because Sammy uses ubuntu I installed this to be compatible.

Met vriendelijke groet,
With kind regards,
Muy atentamente,
Mit Freundliche Gruß,
Sinceramente,


H. Pikaar

Henri...@gmail.com



Op do 30 mei 2024 om 13:57 schreef Carlo Hogeveen <t...@ecarlo.nl>:
--

---
You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages