Using QWidget as QWindow for layer-shell-qt
-
I am trying to use a QWidget application as my desktop panel on Wayland. To that end, I am using layer-shell-qt. However, the LayerShellQt::Window::get(window) works on QWindow only. So, I have used windowHandle() to get the associated QWindow. The windowHandle() doesn't work if I don't show() the QWidget first. But if I show() the widget first, the size of the widget is not respected by the layer shell. (The widget covers the entire screen.) The show() has to come after the LayerShellQt commands for everything to work. The code below shows the hacky way I am doing it right now (show > hide > show).
Is there a better way to do this? Is it necessary to show() a widget to get the window? Am I using LayerShellQt the wrong way?
#include <LayerShellQt/Shell> #include <LayerShellQt/Window> #include <QApplication> #include <QWidget> #include <QWindow> #include <QDebug> int main(int argc, char *argv[]) { uint barWidth = 30; LayerShellQt::Shell::useLayerShell(); QApplication a(argc, argv); QWidget w; w.setStyleSheet("QWidget { background-color: teal; }"); w.resize(barWidth, 600); w.show(); w.hide(); QWindow *lwin = w.windowHandle(); qDebug() << lwin; if (LayerShellQt::Window *lsh = LayerShellQt::Window::get(lwin)) { qDebug() << lsh; lsh->setScope("atombar"); lsh->setLayer(LayerShellQt::Window::LayerBottom); lsh->setExclusiveZone(barWidth); lsh->setAnchors(LayerShellQt::Window::AnchorRight); } w.show(); return a.exec(); }
-
Hi and welcome to devnet,
That's a good question. I would recommend checking with the KDE folks that are handling that module.
Out of curiosity, why do you need a QWidget ?
-
I want to make a panel/bar that displays workspace-specific taskbars. I need it as a visual indicator of where the opened programs are. In X11, I have tint2 that does it. I don't have a similar panel setup in wayland. To implement such a panel, my options were gtk-layer-shell and layer-shell-qt. I went with Qt.
I built a prototype with QWidget that works with Hyprland. In the prototype, I used a QWidget filled with QVBoxLayouts. Each QVBoxLayout shows icons of the opened programs in the associated workspace. In the future, I want to implement "click to focus" and "drag to move" features as well.
I am new to Qt, so I am not sure if this is the best way to do it. What do you suggest?
-
You could use QtQuick to build your GUI, that would make you avoid the use of QWidget and thus fit directly with the shell.
Just from the top of my head but you could have a model with the icons of the applications and use something like a ListView to show them.