Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X11 Fullscreen window (OpenGL)

I'm writing and OpenGL application on linux (Ubuntu 11.10) using Xlib (X11). What is the simplest way to implement toggle between windowed and fullscreen mode?

like image 887
runnydead Avatar asked Jan 31 '12 16:01

runnydead


People also ask

How do I make OpenGL render in X11 window?

Once we have a valid GL context and we’ve also created an X11 window, we can bind them so that OpenGL will render to the window, from this point onward. This is achieved by calling glXMakeCurrent. After creating and setting the GL context, we can start making OpenGL calls.

Does GLFW work with Fullscreen windows?

Don't know about GLFW, perhaps it's buggy, but X11 fullscreen windows don't work like that. Any window manager worth its salt will force the window to fit the (single, non-virtual) screen.

What is X11?

First just some general information about X11. X11 is a protocol for a windowing system created at MIT. Some implementations exists today in the form of XFree86 and the newer X.org. X11 is the latest draft of the specification and works on many platforms such as BSD-families, GNU\Linux, Windows NT 5.0+, Solaris and more.

What do I need to use OpenGL?

In order to use OpenGL we need to include the following headers: Before creating an OpenGL context we need to select a visual by calling glXChooseVisual . This function accepts the connection to the display, a screen number and a list of desired attributes and returns the visual that matches best with the specified attributes.


2 Answers

Here's an implementation of what Havoc P suggested, to save the next person the effort:

void fullscreen(Display* dpy, Window win) {
  Atom atoms[2] = { XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False), None };
  XChangeProperty(
      dpy, 
      win, 
      XInternAtom(dpy, "_NET_WM_STATE", False),
      XA_ATOM, 32, PropModeReplace, (unsigned char*)atoms, 1
  );
}
like image 170
Emil Mikulic Avatar answered Nov 26 '22 11:11

Emil Mikulic


on the protocol level, see the _NET_WM_STATE property with accompanying client message and the fullscreen state flag. this is specified in the EWMH spec. for bonus points you may want to manually implement fullscreen if the WM does not report support for the official hint, EWMH specs a way to check what is supported. You may also want to grab the mouse pointer and/or keyboard if you don't want people to accidentally leave fullscreen.

or, to avoid learning low level X gunge, just use SDL or GTK or Qt or something and they should all have a simple method call to toggle fullscreen.

like image 40
Havoc P Avatar answered Nov 26 '22 12:11

Havoc P