CNJMC1
CNJMC1

Reputation: 509

XLIB How to make a window go fullscreen?

I'm using Xlib to write my own platform library (genius plays, I know), but I can't get fullscreen to work on GNOME based DE. It works on I3 and Xfce but not on GNOME or Unity. Here is what I have so far.

XSizeHints* size_hints;
long hints = 0;

size_hints = XAllocSizeHints();

if (XGetWMSizeHints(_platform.display, _window.window, size_hints, &hints,
    XInternAtom(_platform.display, "WM_SIZE_HINTS", False)) == 0) {
    puts("Failed.");
} 

XLowerWindow(_platform.display, _window.window);
XUnmapWindow(_platform.display, _window.window);
XSync(_platform.display, False);

printf("%ld\n", hints);

XFree(size_hints);

Atom atoms[2] = { XInternAtom(_platform.display, "_NET_WM_STATE_FULLSCREEN", False), None };

XChangeProperty(
    _platform.display,
    _window.window,
    XInternAtom(_platform.display, "_NET_WM_STATE", False),
    XA_ATOM, 32, PropModeReplace, (unsigned char*)atoms, 1);

XMapWindow(_platform.display, _window.window);
XRaiseWindow(_platform.display, _window.window);

Minus all of the XGetWMSizeHints code, this code works fine on other WMs and DEs. According to other Stack Overflow questions, the way to get fullscreen working on GNOME is to either change some WM-NORMAL_HINT values or remove them entirely (How to open a non-decorated fullscreen window on Ubuntu and Fullscreen window without Gnome Panel).

In order to do either I have to use XGetWMSizeHints, but the function is failing. Do I need to create the property for the window first, then use this function? What values should I set in XSizeHints?

Upvotes: 2

Views: 1759

Answers (1)

user12165692
user12165692

Reputation: 21

I've tried your solution in my environment, and it works.

What I noticed though is the return value from XGetWMSizehints is 0 on failure and nonzero on success, which means your example is incorrectly printing "Failed."

Upvotes: 2

Related Questions