/dev/sysmouse - Inappropriate ioctl for device

Hi everyone. This is my first post here, and here's my issue. I'm trying to read the mouse from the virtual console thru /dev/sysmouse. I can successfully open the mouse, but when I try to query the mouse through ioctl(), I get Inappropriate ioctl for device. I recently upgraded to 13.2. The code outputs the following.


Code:
Mouse opened successfully.  File descriptor: 3.
ioctl() failed. Error: 25 - Inappropriate ioctl for device


C:
#include        <errno.h>
#include        <stdio.h>
#include        <stdlib.h>
#include        <string.h>
#include        <unistd.h>
#include        <fcntl.h>
#include        <sys/mouse.h>
#include        <sys/consio.h>

int main(void) {
    int        mouse_fd;                                                                                                                            /* mouse file descriptor */

    static    mouse_info_t    mouse_info;                                                                                               /* BSD mouse info */


    mouse_fd = open("/dev/sysmouse", O_RDONLY);


    if (mouse_fd < 0) {
        fprintf(stdout, "Mouse could not be opened. Error: %d - %s\n", errno, strerror(errno));
    } else {
        fprintf(stdout, "Mouse opened successfully.  File descriptor: %d.\n", mouse_fd);

        mouse_info.operation = MOUSE_GETINFO;
        if (ioctl(mouse_fd, CONS_MOUSECTL, &mouse_info) < 0) {
            fprintf(stdout, "ioctl() failed. Error: %d - %s\n", errno, strerror(errno));
        } else {
            fprintf(stdout, "Mouse read successfully.\n");
        }

        close(mouse_fd);
    }

    return(0);
}
 
I might be misreading sysmouse(4) but MOUSE_GETINFO should be directed at the console, not the mouse driver.

Code:
		MOUSE_GETINFO  Returns current mouse position in the current
			       virtual console and button status in u.data.
That's under the section Console and Consolectl Ioctls
 
I might be misreading sysmouse(4) but MOUSE_GETINFO should be directed at the console, not the mouse driver.

Code:
        MOUSE_GETINFO  Returns current mouse position in the current
                   virtual console and button status in u.data.
That's under the section Console and Consolectl Ioctls
Thanks, it looks like I misread it. It is directed at /dev/consolectl for those ioctls and not /dev/sysmouse. It works now, but I'm getting another weird behavior. I can set the console mouse position with mouse_info.operation = MOUSE_MOVEABS, and successfully read back what I just set, but I can't track the mouse as it moves with mouse_info.operation = MOUSE_GETINFO. I'm looking to poll the location of the mouse in my main loop, so I always know where the mouse is and if it's currently over any particular area of the screen (so as to implement "rollovers"). I can only seem to get the mouse location when I click a button.

But it looks like I'm pointed in the right direction now. Thanks again!
 
Thanks, it looks like I misread it. It is directed at /dev/consolectl for those ioctls and not /dev/sysmouse. It works now, but I'm getting another weird behavior. I can set the console mouse position with mouse_info.operation = MOUSE_MOVEABS, and successfully read back what I just set, but I can't track the mouse as it moves with mouse_info.operation = MOUSE_GETINFO. I'm looking to poll the location of the mouse in my main loop, so I always know where the mouse is and if it's currently over any particular area of the screen (so as to implement "rollovers"). I can only seem to get the mouse location when I click a button.

But it looks like I'm pointed in the right direction now. Thanks again!
UPDATE: I think I know why this is happening. The mouse daemon isn't talking to the virtual terminal, so I'm simply writing a value to a struct and reading it back. I fixed the "Inappropriate ioctl for device" for the mouse, but when I try to turn on the mouse in the console with vidcontrol -m on, I get...
vidcontrol -m on
vidcontrol: getting active vty: Inappropriate ioctl for device
So now I have to fix this for the virtual terminal.

My /boot/loader.conf contains:
kern.vty=vt
hw.vga.textmode=1

i915kms_load="YES"

Still plugging away at it. I think if I can get rid of the "Inappropriate ioctl for device" for the terminal, and get vidcontrol -m on to work, and the mouse can pass data to the virtual terminal, I'll be good to go.

Getting the mouse location when I click a button is coming from curses, but curses has no way of polling the mouse.
 
Back
Top