QWidget / QWindow title bar: custom look, native feel (similar to Chrome) - c++

I know how to make a QWidget (in Qt4 or Qt5) / QWindow (since Qt5) borderless, draw a custom title bar and manually implement mouse dragging to move the window on the screen by simply tracking the mouse position with some mouseMoveEvent and updating the window position.
However, this movement behaves different than the native one as implemented by the window manager. For example, moving the window near the screen's border can be interpreted as "fullscreen" or "split screen"; or windows snap to each other's borders, depending on the system / window manager. These things don't work if you implement the window movement like above.
Google Chrome / Chromium is only one example for an application which implements a custom window title bar and border, while still adapting to the native behavior of the window manager. I'm wondering whether Chrome implements these by itself (and detects the window manager and its configuration) or if there is some functionality in most window managers (clearly, this is still highly platform-dependent) for telling "start native window movement" and "stop native window movement" or similar.
Is something like that possible in Qt? If not, maybe using some other libraries like Qxt?
FYI: I'm mainly targeting Windows and Linux, where I see the difficulty that the user can have any window manager installed.

Based on attempting the same with Qt4 recently, I fear the answer is, you need to tune this per-platform / per-window-manager. I expect patches to QWindow to improve the behaviour in this area would be accepted, but I'm not aware of any standard hook to tell the OS/window-manager what you're trying to achieve.
Equally Qt should be not be 'getting in the way' of solving this, it's simply an area where it can't do anything to help you in a generic way.

Related

Xlib (or gtk). C++. Highlight application's window

I've got application for applications sharing (over network). I need to highlight application's window when it is in sharing state. Currently I use GtkWidget to create border around the window to show that the window is shared. However there are a lot of problems with this approach (need to hide border when application is minimized, need to resize border when application has changed it's size, etc.).
So the question is there any way to show that the window is shared (highlight it somehow or make it flickering or something like that) using xlib (or gtk) API? I didn't find any useful info in the Internet, so I had to ask it here.
Thanks.

Colorizing the titlebar in macOS with multiple colors

I have a Qt app that runs on macOS. I found a way to change the color of the titlebar here, however I want to take it a step further. I want to mimic the titlebar that the Slack and Discord apps use. For example:
As you can see, the color of the controls in the window extend to the very top of the app's window. I figure there are two ways to accomplish what I want:
I can build on the code pasted above. Looking through some of the Apple developer documentation, I think I can create a couple NsWindows on top of the titlebar with whatever width I want and attach the titlebar as a parent for those windows. Once I do that I should be able to make the same backgroundColor() color call for each one. Of course, this will require me to keep track of when the controls or window are resized and adjust the NsWindows of the titlebar, and I am not sure what (if any) issues that could cause.
Maybe there is a way to essentially set the height of the titlebar to 0? I wonder if that's what the Discord app is doing because:
if you look closely, the edit box that says "Find or start a conversation" is vertically lined with the close, minimize and maximize buttons, as is the "Activity" label. But if the controls do extend to the top of the app's window then how are the standard app buttons getting painted?
I'd be curious to know how Slack and Discord accomplish this even though I know they're not using Qt.
I realize there is not a Qt solution since Qt does not paint the titlebar. I know this will be OS-specific, but since I do not have any real experience with Objective-C++ or working with Cocoa (all of my programming experience on macOS has been standard C++ with non-UI or Qt-based code) I'd appreciate any suggestions or guidance!
Natively this is done with fullSizeContentView and titlebarAppearsTransparent properties of NSWindow. Once you set them to true, you can draw or place controls beneath the title bar.

How to create a Qt Drop Shadow without using transparencies? (Because the window manager doesn't support it)

I'm building a UI in Qt 5.9 that needs to run on an X11 display. I'm trying to add drop shadows to my dialog windows - but they don't work over X11.
The approach I'm taking is from zeFree's answer in This Question. (Put everything in the window in one widget, set the window translucent, and create a dropshadow effect on the widget).
setAttribute(Qt::WA_TranslucentBackground); //enable Window to be transparent
QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect();
effect->setBlurRadius(5);
ui->widget->setGraphicsEffect(effect);
It works great in my redhat vm:
RedHat Dropshadow
But when I send to the X11 display I, it looks like the transparency isn't supported, and I get the shadow on black instead:
X11 Dropshadow
My question is: Is there a way to make my Dialogs project a drop shadow onto my main window instead of onto their own (transparent) background? My application will be full screen on the X11 display so I don't need to worry about shadow effects outside of the window.
Any answer that gives me a clean way to get a drop shadow effect on this X11 display will be accepted.
If your window manage doesn't support transparency you are out of luck IMO. At least with your current approach.
There is theoretically a way to fake it, provided you can grab the pixel values from the underlying window manager composite that is under your application, then draw those pixels from your application, filling the black void, with the shadow composed over that, and finally your GUI stuff.
There is also the more viable course of giving up on native windowed dialogs and fake the dialog using a regular floating widget. This has the disadvantage that it will only be able to move within the confines of your main window, but this way you will have complete control over the drawing and not fall victim to platform limitations.

How are opengl menus that go outside of the window implemented?

I was looking at how sometimes when you right click, the menu goes outside of the window.
Is this implemented with a separate window? If so, how can I get this functionality. I am trying to use GLFW, but I understand if it isn't possible.
Currently I am on windows, but I like keeping my options open, which is why GLFW would be preferable.
I noticed that GLUT has such a feature. If you are confused to what I am looking at then look at that.
Thanks for any help!!
Overlapping menus (in MS Windows) have to be implemented as a new top-level window, you would have a new OpenGL rendering context and draw the menu in that space - yes, it's a fair bit of work all for the edge-case of a menu overspilling the parent window,
However this isn't often a problem in OpenGL programming because if you're working on a full-screen game then the menu will always be displayed within the main window, and even if it isn't a full-screen a game your users really won't notice them as games tend to use different UI concepts like radial-menus which wouldn't overspill the parent window.
Or if you're working on a non-game title, chances are it isn't full-screen and is going to be an OpenGL rendering area within a larger application that is rendered using a native UI toolkit (e.g. 3ds Max, AutoCAD, etc), in which case no problem: just use native menus.
You can, of course, use native menus in an OpenGL application anyway, provided you do the necessary plumbing for native window messages.

How to create a GUI without a frame in X11?

I'm trying to figure out how to create a graphical interface, in X11, which exists outside of a window manager's/desktop environment's standard window frame. For example, when Thunderbird finds new mail, it shows a special alert in the lower right hand corner of the screen which is shown without any frame (no close/minimize buttons, etc.).
I'm specifically interested in doing this in QT with C++, but if someone knows a solution with a different graphical library, that would be helpful too.
For QT pass Qt::FramelessWindowHint as a window flag when you construct your top level widget.
See here for more info:
http://doc.qt.nokia.com/main-snapshot/qt.html#WindowType-enum
You can do this with X as well although I haven't done so in a long time.
http://www.xfree86.org/current/XCreateWindow.3.html
With GTK you would use gtk_window_set_decorated(), which would probably be Gtk::Widget->set_decorated() (I think, I don't use gtkmm).
http://developer.gnome.org/gtkmm/unstable/classGtk_1_1Window.html#a67adb1d8051a38e0e5272f141bb8778c