Linux window topmost


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



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.


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

In windows i used to do this:

HWND AppWindow = GetActiveWindow();

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, 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:

As i said, you don’t have just one window manager, but really a lot (see, 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:

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:

/*	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.

	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 */[0] = 1;

			/* the atom being added */[1] = wm_state_above;

			/* unused */[2] = 0;[3] = 0;[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!


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

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