1. Overview

The mouse cursor is a visual pointer that helps users interact with the graphical user interface (GUI) of a computer system. However, sometimes the mouse cursor can be distracting, especially when watching videos, playing games, or using applications that don’t require mouse input. In such cases, we may want to hide the mouse cursor temporarily or permanently.

In this tutorial, we’ll learn how to hide the mouse cursor using different methods.

2. Using unclutter Command

One of the most common ways to hide the mouse cursor in Linux is to use the unclutter command.

2.1. Installation

To install unclutter on Ubuntu, we can use the apt-get command:

$ sudo apt-get install unclutter

This command can also be used to install unclutter on other Debian-based distributions.

Thus, we should have access to the unclutter command.

2.2. Enable

The unclutter command hides the mouse cursor when it’s idle for a specified period of time.

To achieve this, we run unclutter in the terminal:

$ unclutter

While the application runs, the terminal is blocked, and cursor hiding is enabled. Naturally, we can run it in the background as well.

2.3. Options

Notably, the default idle period is five (5) seconds, but it can be changed using the -idle option:

$ unclutter -idle 10

This command hides the mouse cursor after 10 seconds of inactivity.

Further, the unclutter command has some other options that we can use to customize its behavior:

  • -root: hide the mouse cursor even if theoretically not obscuring any important elements
  • -reset: reset the timeline of idleness
  • -onescreen: hide the mouse cursor from its current screen, not on all screens
  • -jitter: specify the maximum distance the mouse cursor can move before unclutter considers it active

Let’s see an example of using the -jitter option:

$ unclutter -idle 10 -jitter 5

This way, we hide the cursor after 10 seconds of inactivity and consider any movement less than 5 pixels as inactivity.

Notably, unclutter is active until terminated. To stop the unclutter command, we can press Ctrl+C in the terminal or kill the application. Of course, we can restore the cursor by simply moving the mouse.

3. Using xbanish Command

Another option to hide the mouse cursor in Linux is to use a tool called xbanish. In particular, xbanish is a small program that runs in the background and makes the cursor disappear when we type. Then, it reappears when we move the mouse or click a mouse button.

Notably, xbanish works for the whole X11 session, which means that the tool is capable of affecting the mouse cursor’s visibility across all applications and windows within the graphical environment X11 provides.

3.1. Installation

We can install xbanish using the apt-get command:

$ sudo apt-get xbanish

Thus, xbanish command is ready to use.

3.2. Enable

We can simply type xbanish in the terminal to use it:

$ xbanish

By default, running this command makes the cursor vanish whenever we press a key.

3.3. Options

We can also use some flags to modify the behavior of xbanish:

  • -a: keep the cursor hidden all the time
  • -i: exclude keys with modifiers
  • -m: move the cursor to a corner of the screen or window when hiding it

Let’s see an example of using xbanish with some flags:

$ xbanish -a -i mod4 -m nw

Now, the cursor is hidden unless we press the Super key. Also, the cursor goes to the top-left corner when hiding.

Similar to unclutter, we can press Ctrl+C in the terminal to stop xbanish.

4. Using xsetroot Command

xsetroot is a program that enables us to change the background, cursor, and other attributes of the root window on a display running X.

Two of the attributes we can change with xsetroot are the cursor image and mask file. Therefore, if we use a blank or transparent image file for the cursor, we can effectively hide the mouse cursor from the screen.

First, let’s define the blank image file:

$ cat emptyCursor.xbm
#define emptyCursor_width 1
#define emptyCursor_height 1
#define emptyCursor_x_hot 0
#define emptyCursor_y_hot 0
static unsigned char emptyCursor_bits[] = {
0x00};

We can now run the code to hide the cursor:

$ xsetroot -cursor emptyCursor.xbm emptyCursor.xbm

To show the cursor again, we can use the -cursor_name option with xsetroot and specify a standard cursor name such as left_ptr:

$ xsetroot -cursor_name left_ptr

This shows the mouse cursor again. Notably, this only affects the root cursor. Also, it may not work well with some desktop environments or applications that have their own cursor or background settings. Moving a cursor over such an application may cause its cursor to be displayed if it redefines the cursor.

5. Conclusion

In this article, we’ve seen how to hide the mouse cursor in Linux using methods such as unclutterxbanish, and the xsetroot command.

In conclusion, the ability to hide the mouse cursor enables us to tailor our computing environment to our specific needs. Some desktop environments or applications may have their custom cursor settings which may cause some of these methods not to work effectively.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.