No hover please

Ever watch videos online? Ha ha, of course you do. Now here's what bothers me. I set the video — for example eurosportplayer.com — in full-screen, on a desktop, but I don't really watch continuously, I let it play and come back to it every now and then. Whenever I switch back to that desktop, a gross overlay with the video controls shadows the media for like 5 seconds. Even the slightest mouse movement brings on that despicable thing.

If this is pissing you off too, and if you are using Linux + Xorg/X11, then I have a solution. It's called nohoverplease but feel free to name it whatever you like, like fuckyouroverlay or something. It's an empty and fully transparent window that does nothing at all, it just sits there, maximized, on top of the browser, and won't let it know it's visible or catch mouse movements, so the damn overlay won't show up. I do have bigger problems in life, but it feels good to solve at least the little ones.

I'm not starting a Github project for something so small. The code is below (thanks Google and Stack Overflow), paste it into a file and compile it with the commented line, to link it against X11. Then configure nohoverplease to run on a key binding, if you'd like to. Pass -m if you'd like it to send the mouse cursor to the bottom-right corner whenever it gets focused.

// gcc nohoverplease.c -o nohoverplease -lX11

#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv) {
  Display *d;
  Window w;
  XEvent e;
  int s;
  double alpha = 0;
  Window root_window;
  Screen *screen;
  Bool hide_mouse = argc >= 2 && strcmp(argv[1], "-m") == 0;
  XClassHint cls = { .res_name = "nohoverplease",
		     .res_class = "nohoverplease" };

  d = XOpenDisplay(NULL);
  if (d == NULL) {
    fprintf(stderr, "Cannot open display\n");
    exit(1);
  }

  s = DefaultScreen(d);
  screen = DefaultScreenOfDisplay(d);
  root_window = RootWindow(d, s);
  w = XCreateSimpleWindow(d, root_window, 0, 0,
			  WidthOfScreen(screen),
			  HeightOfScreen(screen),
			  1,
			  WhitePixel(d, s), BlackPixel(d, s));
  XSelectInput(d, w, ExposureMask | KeyPressMask | FocusChangeMask);
  XStoreName(d, w, "No Hover Please");
  XSetClassHint(d, w, &cls);

  unsigned long opacity = (unsigned long)(0xFFFFFFFFul * alpha);
  Atom XA_NET_WM_WINDOW_OPACITY = XInternAtom(d, "_NET_WM_WINDOW_OPACITY", False);
  XChangeProperty(d, w, XA_NET_WM_WINDOW_OPACITY, XA_CARDINAL, 32,
		  PropModeReplace, (unsigned char *)&opacity, 1L);

  XMapWindow(d, w);

  while (1) {
    XNextEvent(d, &e);
    if (hide_mouse && e.type == FocusIn) {
      // send mouse to the bottom-right corner.
      XWindowAttributes info;
      XGetWindowAttributes(d, w, &info);
      XWarpPointer(d, None, w, 0, 0, 0, 0, info.width - 2, info.height - 2);
    }
  }

  XCloseDisplay(d);
  return 0;
}
One comment. ONE! Gimme some more!

Add your comment

# Alex J Mueller
2021-07-06 14:18
Nice, sort of the inverse of https://xkcd.com/196 :)
Welcome! (login)
Jun
30
2021

No hover please

  • Published: 2021-06-30
  • Modified: 2021-06-30 20:09
  • By: Mishoo
  • Tags: linux, video, x11, xorg
  • Comments: 1 (add)