Implement SDL_SetWindowAlwaysOnTop for X11

This commit is contained in:
Cacodemon345 2021-04-21 11:41:08 +06:00 committed by Ryan C. Gordon
parent a5825576fb
commit 0838f53d5a
3 changed files with 32 additions and 0 deletions

View File

@ -222,6 +222,7 @@ X11_CreateDevice(int devindex)
device->RestoreWindow = X11_RestoreWindow; device->RestoreWindow = X11_RestoreWindow;
device->SetWindowBordered = X11_SetWindowBordered; device->SetWindowBordered = X11_SetWindowBordered;
device->SetWindowResizable = X11_SetWindowResizable; device->SetWindowResizable = X11_SetWindowResizable;
device->SetWindowAlwaysOnTop = X11_SetWindowAlwaysOnTop;
device->SetWindowFullscreen = X11_SetWindowFullscreen; device->SetWindowFullscreen = X11_SetWindowFullscreen;
device->SetWindowGammaRamp = X11_SetWindowGammaRamp; device->SetWindowGammaRamp = X11_SetWindowGammaRamp;
device->SetWindowMouseGrab = X11_SetWindowMouseGrab; device->SetWindowMouseGrab = X11_SetWindowMouseGrab;

View File

@ -1109,6 +1109,36 @@ X11_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
X11_XFlush(display); X11_XFlush(display);
} }
void
X11_SetWindowAlwaysOnTop(_THIS, SDL_Window * window, SDL_bool on_top)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
Display *display = data->videodata->display;
Atom _NET_WM_STATE = data->videodata->_NET_WM_STATE;
Atom _NET_WM_STATE_ABOVE = data->videodata->_NET_WM_STATE_ABOVE;
if (X11_IsWindowMapped(_this, window)) {
XEvent e;
SDL_zero(e);
e.xany.type = ClientMessage;
e.xclient.message_type = _NET_WM_STATE;
e.xclient.format = 32;
e.xclient.window = data->xwindow;
e.xclient.data.l[0] =
on_top ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
e.xclient.data.l[1] = _NET_WM_STATE_ABOVE;
e.xclient.data.l[3] = 0l;
X11_XSendEvent(display, RootWindow(display, displaydata->screen), 0,
SubstructureNotifyMask | SubstructureRedirectMask, &e);
} else {
X11_SetNetWMState(_this, data->xwindow, window->flags);
}
X11_XFlush(display);
}
void void
X11_ShowWindow(_THIS, SDL_Window * window) X11_ShowWindow(_THIS, SDL_Window * window)
{ {

View File

@ -97,6 +97,7 @@ extern void X11_MinimizeWindow(_THIS, SDL_Window * window);
extern void X11_RestoreWindow(_THIS, SDL_Window * window); extern void X11_RestoreWindow(_THIS, SDL_Window * window);
extern void X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered); extern void X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
extern void X11_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable); extern void X11_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
extern void X11_SetWindowAlwaysOnTop(_THIS, SDL_Window * window, SDL_bool on_top);
extern void X11_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen); extern void X11_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
extern int X11_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp); extern int X11_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
extern void X11_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed); extern void X11_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed);