I have sfml window. I need to keep space on top (or bottom) of a screen for my window. Like this doing polybar, lemonbar and etc. How can I do this?
On this step, I just have a simple sfml window:
#include <SFML/Graphics.hpp>
using namespace sf;
int main()
{
unsigned int bar_x = 1920, bar_y = 20;
RenderWindow window(VideoMode(bar_x, bar_y), "bar", Style::None);
Vector2u bar_size(bar_x, bar_y);
Vector2i bar_position(0,0);
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
// Here should be blocking position function...
if (event.type == Event::Closed)
window.close();
if (event.type == Event::Resized)
window.setSize(bar_size);
if (event.type == Event::Resized)
window.setPosition(Vector2i(0,0));
}
window.clear();
// window.draw(shape);
window.display();
}
return 0;
}
I don't think there is a way to force WMs to reserve space but many WMs support and respect the _NET_WM_STRUT_PARTIAL
EWMH property to reserve space at the edge of the screen. This is also what both lemonbar and polybar do.
From the EWMH Spec:
_NET_WM_STRUT_PARTIAL
_NET_WM_STRUT_PARTIAL, left, right, top, bottom, left_start_y, left_end_y, right_start_y, right_end_y, top_start_x, top_end_x, bottom_start_x, bottom_end_x,CARDINAL[12]/32
This property MUST be set by the Client if the window is to reserve space at the edge of the screen. The property contains 4 cardinals specifying the width of the reserved area at each border of the screen, and an additional 8 cardinals specifying the beginning and end corresponding to each of the four struts. The order of the values is left, right, top, bottom, left_start_y, left_end_y, right_start_y, right_end_y, top_start_x, top_end_x, bottom_start_x, bottom_end_x. All coordinates are root window coordinates. The client MAY change this property at any time, therefore the Window Manager MUST watch for property notify events if the Window Manager uses this property to assign special semantics to the window.
[...]
For example, for a panel-style Client appearing at the bottom of the screen, 50 pixels tall, and occupying the space from 200-600 pixels from the left of the screen edge would set a bottom strut of 50, and set bottom_start_x to 200 and bottom_end_x to 600. [...]
Update: After digging around the SFML documentation a bit, I am not sure how to set EMWH properties via SFML or if it is even possible at all. You will need to figure this out yourself. If it isn't possible, one route would be to somehow get the window handle (xcb_window_t
) from SFML and use something like xcb_change_property
from libxcb to set the _NET_WM_STRUT_PARTIAL
property. See the lemonbar source for reference.
Update 2: I am not really familiar with Xlib but I often look at the stalonetray source code for reference. For example the ewmh_set_window_strut
function in the src/wmh.c
file shows how to set the _NET_WM_STRUT_PARTIAL
property:
/* Set data for _NET_WM_STRUT{,_PARTIAL} hints */
int ewmh_set_window_strut(Display *dpy, Window wnd, wm_strut_t wm_strut)
{
Atom prop_strut;
Atom prop_strut_partial;
prop_strut = XInternAtom(dpy, _NET_WM_STRUT, False);
prop_strut_partial = XInternAtom(dpy, _NET_WM_STRUT_PARTIAL, False);
XChangeProperty(dpy, wnd, prop_strut, XA_CARDINAL, 32, PropModeReplace,
(unsigned char *)wm_strut, _NET_WM_STRUT_SZ);
XChangeProperty(dpy, wnd, prop_strut_partial, XA_CARDINAL, 32, PropModeReplace,
(unsigned char *)wm_strut, _NET_WM_STRUT_PARTIAL_SZ);
return x11_ok();
}