How to make a fixed position and size window in X11 - x11

So I wanna make my window not moveable and resizable, is there anyway to do it? Below is my current window creation code.
testbwidgetptr->basewin = XCreateWindow(BOTIFDisplay,
tmp->drawarea,
testbwidgetptr->bwidgetx,
testbwidgetptr->bwidgety,
testbwidgetptr->bwidgetwidth,
testbwidgetptr->bwidgetheight,
0, CopyFromParent, InputOutput,
CopyFromParent, valuemask, &winatt);
XSetWindowBackground(BOTIFDisplay, testbwidgetptr->basewin, WhiteDot);

I wanna make my window not moveable and resizable
In X11 window management, the client doesn't get to define what they want. They can ask the window manager to do this or that (or not to do that), but in the end it is always up to the window manager. In fact, the specifications state clearly that the client application must deal with any size the window manager assigns to it – so the answer is: no, you cannot do that if you want your window to be managed.
As pointed out in a comment, you can set override_redirect on your window. This tells the window manager not to manage your window, which means that the window manager will not interfere with it. However, in theory any client could still resize your window (though this is extremely unlikely to happen).
However, you should be careful about this. Bypassing the window manager also means that you lose a lot of things: window decorations, focus handling and the like will all be gone. In particular, focus handling must be done by you.
To summarize, you should really consider whether override_redirect is actually what you want to use. In most cases, you should instead just build a client that can deal with arbitrary window sizes and positions.

Related

how to define window stacking order?

I'm trying to write my own window manager. One issue I faced is that I don't understand how to define in which order windows should be displayed. The only means I found is to use xcb_configure_window. But it looks very limited to me: it only allows either to rise the window on top of all, or put it to the very bottom (no notion of layers or something). What a limited functionality :(.
What I really would like to do is to define the window order and tell X about it. Or to define multiple layers of windows (e.g, normal, above all, below all). So I could rise (or lower) the window with respect to its layer. So windows from lower layers will not ever cover windows from upper layers.
So, is there any other library function to define the order of windows apart from xcb_configure_window? Or I need to live with it? That would mean I have to track the order of windows in my window manager.
Link to relevant XCB documentation: https://www.x.org/releases/X11R7.6/doc/libxcb/tutorial/index.html#winstack
X11 only gives you the absolute minimum. There are no layers or always-over or always-under windows. You implement all the fancy stuff yourself, typically in the window manager, which is what you are writing.
There is no raw protocol request to change the stacking order of windows at once. Xlib has a function XRestackWindows which does that, but it uses one configure request per window. The pseudocode is just
for each window in the list except the first
change the stacking order to be under the previous window
That's it. Nothing more fancy than that.
You do need to track the stacking order in your WM in order to implement layers, so that when a program tries to restack a top level window, you intercept the request and only restack it within its layer.
Another possible way to implement layers is to have several transparent full-screen windows and reparent users' top-level windows to those, instead of to the root window. I'm not totally sure it will always work though, and you need to deal with transparency in one way or another, which requires transparency supporting hardware or the composite extension or possibly both.
It is the responsibility of the window manager to order the windows. A window gives hints about which type it is (popup dialog, menu window, splashscreen, toolbox, etc), the window manager then decides how to display this on the screen. This includes keeping track of the order and deciding which gets priority.
There is a X11 call to change the order (XRestackWindows), but I don't know the Xcb equivalent.

How to stop OpenGL from pausing when the window is out of focus or resizing?

I'm trying to prevent my rendering from stopping when my window is out of focus or resizing. In addition to the resizing, if I resize my window smaller, then bigger again anything that wasn't visible when it was smaller is now black. Is there any way to fix this?
There are really two distinct things going on here. The moving/resizing problem is caused by the windows DefWindowProc function which applications use to handle messages that aren't explicitly handled by the application itself. In the case of moving or resizing, it blocks, creating a new message queue to handle most messages, but there are a few that it will still dispatch to the application's main event queue, like WM_TIMER. You can find lots more information in this answer.
The second issue is that your program only "owns" the pixels inside your window, and only those that are not covered up by other windows. When you make the window smaller, the pixels at the edge need to be overwritten to show the window border or whatever's behind the window. When the window is made bigger, some drivers automatically set the newly acquired pixels to black, while others leave them at whatever they were before (usually part of the window border). The OS doesn't remember if those pixels had some specific color the last time the window was that size, because most of the time the program doesn't care. Instead, windows sends a WM_PAINT message to indicate that the application should redraw the window. Your program should either directly handle this, or use a library like GLFW that abstracts it. In addition, you need to handle resize events by calling glViewport with the new size of the window.

How to create an invisible X11 window for GPGPU?

Is it possible to create an invisible X window? For initialization of an OpenGL ES 2.0 context, one has to create a X window manually, but I can't find a way to make it invisible. Since I'm only doing GPGPU I don't need an output window. In fact, it is rather annoying in my case.
I'm aware of a solution from an earlier question, where it has been pointed out to use InputOnly in XCreateWindow(). This, however, leads to the X error GLXBadDrawable. Probably because EGL requires the window to respond to graphics request. Is there another way? Maybe create it minimized? But I can't find anything on that either. Also setting the window's size really small doesn't help, since it always occupies the whole screen on my device (Nokia N9).
When you create an X window, it is created unmapped, so what about creating an InputOutput window and leaving it unmapped? Another option would be (if the window must stay mapped), to move it out of the screen.

Updating the region behind a resized window

We have a fairly complex GUI, so when certain windows are resized their Redraw() is set to false till the operation is completed. The problem with this is that if the OS "Show window content while dragging" setting is checked, when decreasing the window's size the windows behind it are not repainted. This means I have to force the repaint myself so the remains of the resized window are deleted. I have no problem getting the dimensions of the region that was uncovered. What I'm looking for is best way to cause all windows within that region to repaint their part.
Not being much of a GUI programmer, I can traverse the uncovered region and list the windows in it. Then, I can ask each one of them to repaint its part. But I'm quite certain there has to be a better way to do this...
It is worth mentioning the app is written in PowerBuilder. This means I can call whatever Win32 function I'd like, but have limited control over the GUI behavior and the message handling. If there's a better way to prevent the window's content resize from being visible, or there's a way to make a non-redrawn window clean after itself, I'd love to hear it (just have the limitations above in mind).
I'm curious what version of PowerBuilder you are working in? I do resizing all the time and never run into issues like you are describing.
Maybe you can lay out some more detail on why you need to set your redraws to false within the PowerBuilder environment.
Hope I can help.

Can a window be always on top of just one other window?

In Windows, is it possible to set window A such that it is always on top of window B, yet allow other windows to work as normal and appear over the top of both, when active.
In other words, I want a parent-child relationship between two windows. Can this be done without making window A a child of window B, MDI-style? Window B isn't mine (Internet Explorer), and screws my dialog A's graphics up when I try to achieve this with SetParent.
I thought I'd cracked it with this idea from an MSDN forum post, but alas windows A is still always on top of everything, not just window B.
// Place window A on top
SetWindowPos(hWndWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
// Place window B underneath it
SetWindowPos(hWndParent, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
Is it possible?
Wouldn't creating an ownership relationship do the trick?
SetWindowLong(hwndChild, GWL_HWNDPARENT, hwndOwner)
The windows can be in different processes and you can call this from any process. This will ensure that the child window is always above the owner window. This is different than SetParent which actually creates a Parent / Child relationship. Read through this article (its from 1993 but still mostly correct) to see the distinction between ownership and parenting.
When your window's Z-order (or size or position) is changing, it should receive a WM_WINDOWPOSCHANGING message. If you process that message, you have an opportunity to modify the final Z-order (or size or position) to which the window is moved.
To illustrate, in hWndA's window procedure:
case WM_WINDOWPOSCHANGING:
DefWindowProc(hWnd, msg, wParam, lParam);
WINDOWPOS *p = (WINDOWPOS*)lParam;
p->hwndInsertAfter = hWndB;
p->flags &= ~SWP_NOZORDER;
return 0;
should insert hWndA after hWndB in the Z-order any time hWndA's position changes.
Until Vista, one way to do it would have been to use SetWindowsHookEx, and hook the WH_CBT or WH_CALLWNDPROC hook, and then take appropriate action when you detect the Z order changing. However this doesn't work with Vista (as far as I can tell from googling).
The only other solution I can think of is to set up a timer to fire every few seconds, and then when you receive a WM_TIMER, you interrogate the system using GetNextWindow to find out which window is behind yours. If it's not IE, then call SetWindowPos to position your window above IE (I assume you have a HWND for the IE window you care about - remember there can be multiple IE windows).
This will cause problems if people try to bring your window to the front - it will flip back to being just above IE. In this case, in your code you could handle WM_ACTIVATE and try to change the Z-order of IE's window so it's below your window (call SetWindowPos to move IE's window so it's above the window that is currently below your window). This solution may be fraught with problems as Windows may try to prevent you messing with the windows of another process, for security reasons. On the other hand, the MSDN docs for SetWindowPos don't explicitly mention that you can't manipulate the windows of another process. There may be obscure limitations though.
Even with this timer hack, you're going to effectively have a busy-waiting loop in your app (with the frequent WM_TIMER messages) and this is generally a bad thing to do, especially for battery life of laptops etc. (because you prevent the CPU from entering a sleep state, and so on).
I'd say there's no good way of doing this, and anything you're likely to get working will be brittle and cause problems. I strongly recommend not trying to do it. Is it possible to make your program into some kind of plug-in or toolbar for IE instead?
NB Be particularly aware that SetWindowsHookEx imposes a performance penalty at a system-wide level if you go down this route.
Maurice's answer is the best out of what's here but is missing an important step. When you call show on your window that you want as the overlay, you need to call the show method that has the parameter. You'll need to define a class that implements the IWin32Window interface and just make a new instance of that. The only thing that interface cares about is the Handle so just set that to the handle of the IE window and it should work pretty well
If the parent-child relationship is made by yourself with the SetWindowPos() function, your desire can be implemented.
Can you access the Z-order of the windows?
I cannot recall the default z-order of windows, but I think it is 1. You might be able to set IE to a -1 and your app to 0.
Try this:
// Place window A on top of window B
SetWindowPos(hWndA, hWndB, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
The second window handle parameter specifies the next window down in the Z order.
Note this doesn't actually change the window parent-child relationships - but you can simulate it.

Resources