Linux window topmost

Hello

Is there any way to set a window topmost on linux¿

Regards

Hi

If i’ve understood correctly your question, then the answer depends from the desktop environment and (most important) the window manager in use. However, in general, right clicking on window title bar should provide you with this option.

If you mean “launch an application with window on top”, i think you have to create a launcher with the desired option. But in this case too, it really depends on your desktop environment/window manager.

HTH

Thank you, but i want it to do by code from the app.

In windows i used to do this:

HWND AppWindow = GetActiveWindow();
SetWindowPos(AppWindow, HWND_TOPMOST, NULL, NULL, NULL, NULL, SWP_NOMOVE | SWP_NOSIZE);

I basically want to be allways over any possible window, popup, notification… etc etc

i don’t think that’s possible in linux… As i said, you don’t have just one window manager, but really a lot (see https://en.wikipedia.org/wiki/X_window_manager), so implementing this function looks like a mess…
If you don’t find a solution, i suggest you to define window position and properties with a launcher.
See here for example: https://askubuntu.com/questions/613973/how-can-i-start-up-an-application-with-a-pre-defined-window-size-and-position

As i said, you don’t have just one window manager, but really a lot (see https://en.wikipedia.org/wiki/X_window_manager), so implementing this function looks like a mess…

True, but you don’t have to implement it for every windowmanager - fortunately most window managers support the EWMH spec: http://www.freedesktop.org/wiki/Specifications/wm-spec

The ‘Window Hint’ required here is _NET_WM_STATE_ABOVE
This stuff is not completely obvious, but I found this gist that packaged all needed mumbo jumbo into a nice function: https://gist.github.com/woodruffw/16af23d886e62fbb1526

/*	set_window_front
	On EWMH-compliant window managers, sets the _NET_WM_STATE of the given
	window to _NET_WM_STATE_ABOVE to make it stay on top of all others besides
	_NET_WM_STATE_FULLSCREEN. If the window manager is not EWMH-compliant, 
	nothing is done.

	Arguments:
	Display *disp - a pointer to the X display
	Window wind - the window being moved to the front
*/
void set_window_front(Display *disp, Window wind)
{
	Atom wm_state, wm_state_above;
	XEvent event;

	if ((wm_state = XInternAtom(disp, "_NET_WM_STATE", False)) != None)
	{
		if ((wm_state_above = XInternAtom(disp, "_NET_WM_STATE_ABOVE", False))
			!= None)
		{
			/* sending a ClientMessage */
			event.xclient.type = ClientMessage;

			/* value unimportant in this case */
			event.xclient.serial = 0;

			/* coming from a SendEvent request, so True */
			event.xclient.send_event = True;

			/* the event originates from disp */
			event.xclient.display = disp;

			/* the window whose state will be modified */
			event.xclient.window = wind;

			/* the component Atom being modified in the window */
			event.xclient.message_type = wm_state;

			/* specifies that data.l will be used */
			event.xclient.format = 32;

			/* 1 is _NET_WM_STATE_ADD */
			event.xclient.data.l[0] = 1;

			/* the atom being added */
			event.xclient.data.l[1] = wm_state_above;

			/* unused */
			event.xclient.data.l[2] = 0;
			event.xclient.data.l[3] = 0;
			event.xclient.data.l[4] = 0;

			/* actually send the event */
			XSendEvent(disp, DefaultRootWindow(disp), False,
				SubstructureRedirectMask | SubstructureNotifyMask, &event);
		}
	}
}

In your ofApp you would call this function like this (in the setup() , for example):

    set_window_front(ofGetX11Display(), ofGetX11Window());

(You’ll also need a #include <X11/Xlib.h> at the top of your ofApp to make the X11 functions available)

Hope this helps!

2 Likes

Super!!
I tried and it works, thank you, is a nice tip!

That’s good to hear - you’re welcome! :smiley: