X11 Fullscreen window (OpenGL)
Asked Answered
S

2

6

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?

Sastruga answered 31/1, 2012 at 16:38 Comment(0)
I
4

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.

Ionia answered 31/1, 2012 at 16:43 Comment(0)
R
9

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
  );
}
Reber answered 10/7, 2013 at 16:49 Comment(6)
Please explain why this work instead of just giving the answerHaldane
Um, gcc is complaining when I use this code snippet. According to the XChangeProperty manpage, shouldn't the second-to-last argument of the aforementioned function be a string, not an array of atoms?Burney
XChangeProperty perhaps misleadingly takes unsigned char* data but it is indeed meant to be a pointer to an array of atoms like in the snippet above. What is gcc's complaint? If you're trying to compile this as C++ code, you need to use an explicit cast like (unsigned char *)atoms.Reber
T @ArtB Havoc already explained why it works. Like it says on the first line: this is just the implementation, which I'm posting so that other people can copy+paste.Reber
@EmilMikulic it was flagged by the review system, and SO are supposed to be self-contained... but that does lead to corner casese where it seems silly too. In this case I'd've either edit his answer to include your code (which you might not have rights to, or copied his answer into your own). Mind you, in review mode we don't see the question or any other answer, we just see your answer in isolation.Haldane
@EmilMikulic It should really be a void* because a property can be of any type, not just an Atom. But X11 and this function in particular predate ANSI C and void.Adenovirus
I
4

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.

Ionia answered 31/1, 2012 at 16:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.