VIS_CONSCURSOR
The VIS_CONSCURSOR
ioctl command
displays or hides a cursor. The vis_conscursor structure
is shown in the following code.
struct vis_conscursor { screen_pos_t row; /* Row to display cursor (in pixels) */ screen_pos_t col; /* Col to display cursor (in pixels) */ screen_size_t width; /* Width of cursor (in pixels) */ screen_size_t height; /* Height of cursor (in pixels) */ color_t fg_color; /* Foreground color */ color_t bg_color; /* Background color */ short action; /* Show or Hide cursor */ };
To implement the VIS_CONSCOPY
ioctl command in the console frame buffer driver, follow these general
steps:
Copy the vis_conscursor structure from the kernel terminal emulator.
Validate the display parameters. Return an error if any of the display parameters are out of range.
Invalidate any user context so that user applications cannot
simultaneously access the frame buffer hardware through user memory mappings.
This step is neither allowed nor necessary in polled I/O mode because user
applications are not running. Be sure to hold a lock so that users cannot
restore the mapping through a page fault until the VIS_CONSDISPLAY
ioctl completes.
The terminal emulator can call the VIS_CONSCOPY
ioctl with one of the following two actions: SHOW_CURSOR
and HIDE_CURSOR
.
The following steps describe how to implement this functionality by reading
and writing video memory. You might also be able to use the rendering engine
to do this work. Whether you can use the rendering engine depends on the frame
buffer hardware.
Take these steps to implement the SHOW_CURSOR
functionality:
Save the pixels within the rectangle where the cursor will be drawn. These saved pixels will be needed to hide the cursor.
Scan all the pixels on the screen bounded by the rectangle where the cursor will be drawn. Within this rectangle, replace the pixels that match the specified cursor foreground color (fg_color) with white pixels. Replace the pixels that match the specified cursor background color (bg_color) with black pixels. The visual effect is of a black cursor over white text. This method works with any foreground and background color of text. Attempting to invert colors based upon color map position is not feasible. More sophisticated strategies, such as attempting color inversion using HSB coloring (Hue, Saturation, Brightness), are not necessary.
To implement the HIDE_CURSOR
functionality,
replace the pixels beneath the cursor rectangle with the pixels saved from
the previous SHOW_CURSOR
action.