diff --git a/meson.build b/meson.build index 1937f23..0fcfe8b 100644 --- a/meson.build +++ b/meson.build @@ -1,22 +1,8 @@ -project('qt-video-wlr',['c','cpp']) +project('qt-video-wlr', ['cpp']) -wl_client=dependency('wayland-client') -wl_protocols=dependency('wayland-protocols') -scanner=find_program('wayland-scanner') -scanner_private_code=generator(scanner,output: '@BASENAME@-protocol.c',arguments: ['private-code','@INPUT@','@OUTPUT@']) -scanner_client_header=generator(scanner,output: '@BASENAME@-client-protocol.h',arguments: ['client-header','@INPUT@','@OUTPUT@']) - -protocols_src=[ - scanner_private_code.process('wlr-layer-shell-unstable-v1.xml'), - scanner_private_code.process(wl_protocols.get_pkgconfig_variable('pkgdatadir')+'/stable/xdg-shell/xdg-shell.xml') -] -protocols_headers=[ - scanner_client_header.process('wlr-layer-shell-unstable-v1.xml') -] -lib_protocols=static_library('protocols',protocols_src+protocols_headers,dependencies: wl_client) -protocols_dep=declare_dependency(link_with: lib_protocols,sources: protocols_headers) - -qt5=import('qt5') -qt5_dep=dependency('qt5',modules: ['Widgets','Core','Multimedia','MultimediaWidgets','Gui']) -qtgui=dependency('Qt5Gui') -executable('qt-video-wlr',['qt-video-wlr-bg.cpp'],dependencies: [qt5_dep,protocols_dep],cpp_args: '-I'+join_paths(qtgui.get_pkgconfig_variable('includedir'),'QtGui',qtgui.version(),'QtGui'),install: true) +qt5_dep = dependency('qt5', modules: ['Widgets', 'Core', 'Multimedia', 'MultimediaWidgets', 'Gui']) +layer_shell_qt_dep = dependency('LayerShellQt', modules: ['LayerShellQt::Interface']) +executable('qt-video-wlr', + ['qt-video-wlr-bg.cpp'], + dependencies: [qt5_dep, layer_shell_qt_dep], + install: true) diff --git a/qt-video-wlr-bg.cpp b/qt-video-wlr-bg.cpp index dcfd309..80d6894 100644 --- a/qt-video-wlr-bg.cpp +++ b/qt-video-wlr-bg.cpp @@ -1,35 +1,27 @@ -#include -#include -#include #include +#include +#include #include -#include #include -#include -#include -#include -#include "wlr-layer-shell-unstable-v1-client-protocol.h" +#include +#include +#include +#include +#include -struct qvw_state { - struct zwlr_layer_shell_v1 *layer_shell; - uint32_t width, height; - QApplication *app; - QWidget *root; - QVideoWidget *videoWidget; -}; +#include +#include int main(int argc,char *argv[]){ - struct wl_surface *wl_surface; - struct zwlr_layer_surface_v1 *layer_surface; - struct qvw_state state { - .app = new QApplication(argc, argv), - .root = new QWidget, - }; - - // hack: disable shell integration - setenv("QT_WAYLAND_SHELL_INTEGRATION","nonexistance",1); + LayerShellQt::Shell::useLayerShell(); QApplication::setApplicationName("qt-video-wlr"); QApplication::setApplicationVersion("dev"); + // XXX: hack to make QWidget::windowHandle available before show + // removed @ Qt6 + QApplication::setAttribute(Qt::AA_ImmediateWidgetCreation); + + QApplication app(argc, argv); + QWidget root; QCommandLineParser parser; parser.setApplicationDescription("Qt pip-mode-like video player " @@ -69,60 +61,66 @@ int main(int argc,char *argv[]){ volumeOption, positionOption, noLoopOption, marginOption, topMarginOption, rightMarginOption, bottomMarginOption, leftMarginOption }); - parser.process(*state.app); + parser.process(app); - uint32_t layer, anchor; - int32_t top_margin, right_margin, bottom_margin, left_margin; bool ok; + + uint32_t width, height; + width = parser.value(widthOption).toInt(&ok); + if (!ok) parser.showHelp(1); + height = parser.value(heightOption).toInt(&ok); + if (!ok) parser.showHelp(1); + + auto layerShell = LayerShellQt::Window::get(root.windowHandle()); + LayerShellQt::Window::Layer layer; QString layerStr = parser.value(layerOption); if (layerStr == "background") - layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND; + layer = LayerShellQt::Window::LayerBackground; else if (layerStr == "bottom") - layer = ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM; + layer = LayerShellQt::Window::LayerBottom; else if (layerStr == "top") - layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP; + layer = LayerShellQt::Window::LayerTop; else if (layerStr == "overlay") - layer = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY; + layer = LayerShellQt::Window::LayerOverlay; else parser.showHelp(1); + layerShell->setLayer(layer); - state.width = parser.value(widthOption).toInt(&ok); - if (!ok) parser.showHelp(1); - state.height = parser.value(heightOption).toInt(&ok); - if (!ok) parser.showHelp(1); - + LayerShellQt::Window::Anchors anchor; QString positionStr = parser.value(positionOption); if (positionStr == "center") - anchor = 0; + anchor = {}; else if (positionStr == "top") - anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP; + anchor = LayerShellQt::Window::Anchor::AnchorTop; else if (positionStr == "top-left") - anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | - ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT; + anchor = {LayerShellQt::Window::Anchor::AnchorTop, + LayerShellQt::Window::Anchor::AnchorLeft}; else if (positionStr == "top-right") - anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | - ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; + anchor = {LayerShellQt::Window::Anchor::AnchorTop, + LayerShellQt::Window::Anchor::AnchorRight}; else if (positionStr == "bottom") - anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; + anchor = LayerShellQt::Window::Anchor::AnchorBottom; else if (positionStr == "bottom-left") - anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | - ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT; + anchor = {LayerShellQt::Window::Anchor::AnchorBottom, + LayerShellQt::Window::Anchor::AnchorLeft}; else if (positionStr == "bottom-right") - anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | - ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; + anchor = {LayerShellQt::Window::Anchor::AnchorBottom, + LayerShellQt::Window::Anchor::AnchorRight}; else if (positionStr == "left") - anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT; + anchor = LayerShellQt::Window::Anchor::AnchorLeft; else if (positionStr == "right") - anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; + anchor = LayerShellQt::Window::Anchor::AnchorRight; else parser.showHelp(1); - if (state.width == 0) - anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | - ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT; - if (state.height == 0) - anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | - ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP; + if (width == 0) + anchor |= {LayerShellQt::Window::Anchor::AnchorLeft, + LayerShellQt::Window::Anchor::AnchorRight}; + if (height == 0) + anchor |= {LayerShellQt::Window::Anchor::AnchorTop, + LayerShellQt::Window::Anchor::AnchorBottom}; + layerShell->setAnchors(anchor); + int top_margin, right_margin, bottom_margin, left_margin; top_margin = right_margin = bottom_margin = left_margin = parser.value(marginOption).toInt(&ok); if (!ok) parser.showHelp(1); @@ -134,29 +132,17 @@ int main(int argc,char *argv[]){ if (!ok) parser.showHelp(1); left_margin = parser.value(leftMarginOption).toInt(&ok); if (!ok) parser.showHelp(1); + layerShell->setMargins({left_margin, top_margin, right_margin, bottom_margin}); - QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface(); - struct wl_display *display = (struct wl_display *) - native->nativeResourceForWindow("display", NULL); - struct wl_registry *registry = wl_display_get_registry(display); - const struct wl_registry_listener registry_listener = { - .global = [](void *data, struct wl_registry *registry, - uint32_t name, const char *interface, uint32_t version) { - struct qvw_state *state = static_cast(data); - if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { - state->layer_shell = (zwlr_layer_shell_v1*)wl_registry_bind( - registry, name, &zwlr_layer_shell_v1_interface, 1); - } - }, - .global_remove = [](void *data, struct wl_registry *registry, uint32_t name) {}, - }; - wl_registry_add_listener(registry, ®istry_listener, &state); - wl_display_roundtrip(display); - if (state.layer_shell == NULL) { - fprintf(stderr, "layer_shell not available\n"); - state.app->quit(); - return 1; - } + layerShell->setKeyboardInteractivity(LayerShellQt::Window::KeyboardInteractivityNone); + + QVBoxLayout layout; + QVideoWidget videoWidget; + layout.addWidget(&videoWidget); + layout.setContentsMargins({}); + root.setLayout(&layout); + root.resize(width ? width : 1, height ? height : 1); + root.show(); QMediaPlayer player; QMediaPlaylist playlist; @@ -174,63 +160,27 @@ int main(int argc,char *argv[]){ if (!ok) parser.showHelp(1); } - state.videoWidget = new QVideoWidget(state.root); - state.root->resize(state.width ? state.width : 1, state.height ? state.height : 1); - state.root->show(); - - wl_surface = static_cast( - native->nativeResourceForWindow("surface", state.root->windowHandle())); - layer_surface = zwlr_layer_shell_v1_get_layer_surface(state.layer_shell, - wl_surface, NULL, layer, "video-player"); - - const struct zwlr_layer_surface_v1_listener layer_surface_listener = { - .configure = [](void *data, - struct zwlr_layer_surface_v1 *surface, - uint32_t serial, uint32_t w, uint32_t h) { - struct qvw_state *state = static_cast(data); - printf("resize %d %d\n", w, h); - state->root->resize(w, h); - state->videoWidget->resize(w ,h); - zwlr_layer_surface_v1_ack_configure(surface, serial); - }, - .closed = [](void *data, - struct zwlr_layer_surface_v1 *surface) { - struct qvw_state *state = static_cast(data); - zwlr_layer_surface_v1_destroy(surface); - state->app->quit(); - }, - }; - zwlr_layer_surface_v1_set_margin(layer_surface, top_margin, right_margin, - bottom_margin, left_margin); - zwlr_layer_surface_v1_set_size(layer_surface, state.width, state.height); - zwlr_layer_surface_v1_set_anchor(layer_surface, anchor); - zwlr_layer_surface_v1_add_listener(layer_surface, &layer_surface_listener, &state); - wl_surface_commit(wl_surface); - wl_display_roundtrip(display); - - player.setVideoOutput(state.videoWidget); - state.videoWidget->setMinimumSize(state.width ? state.width : 1, state.height ? state.height : 1); + player.setVideoOutput(&videoWidget); if (parser.isSet(colorOption)) { QColor qcolor(parser.value(colorOption)); if(!qcolor.isValid()) parser.showHelp(1); QPalette pal; pal.setColor(QPalette::Window, qcolor); - state.videoWidget->setAutoFillBackground(true); - state.videoWidget->setPalette(pal); + videoWidget.setAutoFillBackground(true); + videoWidget.setPalette(pal); QPalette pal2; pal2.setColor(QPalette::Window, "#00000000"); - state.root->setAutoFillBackground(true); - state.root->setPalette(pal2); + root.setAutoFillBackground(true); + root.setPalette(pal2); } - state.videoWidget->show(); + videoWidget.show(); player.play(); QObject::connect(&player, &QMediaPlayer::stateChanged, - [&layer_surface, &state](QMediaPlayer::State playerState) { + [&app](QMediaPlayer::State playerState) { if(playerState == QMediaPlayer::StoppedState){ - zwlr_layer_surface_v1_destroy(layer_surface); - state.app->quit(); + app.quit(); } }); - return state.app->exec(); + return app.exec(); } diff --git a/wlr-layer-shell-unstable-v1.xml b/wlr-layer-shell-unstable-v1.xml deleted file mode 100644 index b7f3889..0000000 --- a/wlr-layer-shell-unstable-v1.xml +++ /dev/null @@ -1,285 +0,0 @@ - - - - Copyright © 2017 Drew DeVault - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that copyright notice and this permission - notice appear in supporting documentation, and that the name of - the copyright holders not be used in advertising or publicity - pertaining to distribution of the software without specific, - written prior permission. The copyright holders make no - representations about the suitability of this software for any - purpose. It is provided "as is" without express or implied - warranty. - - THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS - SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY - SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN - AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, - ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF - THIS SOFTWARE. - - - - - Clients can use this interface to assign the surface_layer role to - wl_surfaces. Such surfaces are assigned to a "layer" of the output and - rendered with a defined z-depth respective to each other. They may also be - anchored to the edges and corners of a screen and specify input handling - semantics. This interface should be suitable for the implementation of - many desktop shell components, and a broad number of other applications - that interact with the desktop. - - - - - Create a layer surface for an existing surface. This assigns the role of - layer_surface, or raises a protocol error if another role is already - assigned. - - Creating a layer surface from a wl_surface which has a buffer attached - or committed is a client error, and any attempts by a client to attach - or manipulate a buffer prior to the first layer_surface.configure call - must also be treated as errors. - - You may pass NULL for output to allow the compositor to decide which - output to use. Generally this will be the one that the user most - recently interacted with. - - Clients can specify a namespace that defines the purpose of the layer - surface. - - - - - - - - - - - - - - - - - These values indicate which layers a surface can be rendered in. They - are ordered by z depth, bottom-most first. Traditional shell surfaces - will typically be rendered between the bottom and top layers. - Fullscreen shell surfaces are typically rendered at the top layer. - Multiple surfaces can share a single layer, and ordering within a - single layer is undefined. - - - - - - - - - - - - An interface that may be implemented by a wl_surface, for surfaces that - are designed to be rendered as a layer of a stacked desktop-like - environment. - - Layer surface state (size, anchor, exclusive zone, margin, interactivity) - is double-buffered, and will be applied at the time wl_surface.commit of - the corresponding wl_surface is called. - - - - - Sets the size of the surface in surface-local coordinates. The - compositor will display the surface centered with respect to its - anchors. - - If you pass 0 for either value, the compositor will assign it and - inform you of the assignment in the configure event. You must set your - anchor to opposite edges in the dimensions you omit; not doing so is a - protocol error. Both values are 0 by default. - - Size is double-buffered, see wl_surface.commit. - - - - - - - - Requests that the compositor anchor the surface to the specified edges - and corners. If two orthoginal edges are specified (e.g. 'top' and - 'left'), then the anchor point will be the intersection of the edges - (e.g. the top left corner of the output); otherwise the anchor point - will be centered on that edge, or in the center if none is specified. - - Anchor is double-buffered, see wl_surface.commit. - - - - - - - Requests that the compositor avoids occluding an area of the surface - with other surfaces. The compositor's use of this information is - implementation-dependent - do not assume that this region will not - actually be occluded. - - A positive value is only meaningful if the surface is anchored to an - edge, rather than a corner. The zone is the number of surface-local - coordinates from the edge that are considered exclusive. - - Surfaces that do not wish to have an exclusive zone may instead specify - how they should interact with surfaces that do. If set to zero, the - surface indicates that it would like to be moved to avoid occluding - surfaces with a positive excluzive zone. If set to -1, the surface - indicates that it would not like to be moved to accommodate for other - surfaces, and the compositor should extend it all the way to the edges - it is anchored to. - - For example, a panel might set its exclusive zone to 10, so that - maximized shell surfaces are not shown on top of it. A notification - might set its exclusive zone to 0, so that it is moved to avoid - occluding the panel, but shell surfaces are shown underneath it. A - wallpaper or lock screen might set their exclusive zone to -1, so that - they stretch below or over the panel. - - The default value is 0. - - Exclusive zone is double-buffered, see wl_surface.commit. - - - - - - - Requests that the surface be placed some distance away from the anchor - point on the output, in surface-local coordinates. Setting this value - for edges you are not anchored to has no effect. - - The exclusive zone includes the margin. - - Margin is double-buffered, see wl_surface.commit. - - - - - - - - - - Set to 1 to request that the seat send keyboard events to this layer - surface. For layers below the shell surface layer, the seat will use - normal focus semantics. For layers above the shell surface layers, the - seat will always give exclusive keyboard focus to the top-most layer - which has keyboard interactivity set to true. - - Layer surfaces receive pointer, touch, and tablet events normally. If - you do not want to receive them, set the input region on your surface - to an empty region. - - Events is double-buffered, see wl_surface.commit. - - - - - - - This assigns an xdg_popup's parent to this layer_surface. This popup - should have been created via xdg_surface::get_popup with the parent set - to NULL, and this request must be invoked before committing the popup's - initial state. - - See the documentation of xdg_popup for more details about what an - xdg_popup is and how it is used. - - - - - - - When a configure event is received, if a client commits the - surface in response to the configure event, then the client - must make an ack_configure request sometime before the commit - request, passing along the serial of the configure event. - - If the client receives multiple configure events before it - can respond to one, it only has to ack the last configure event. - - A client is not required to commit immediately after sending - an ack_configure request - it may even ack_configure several times - before its next surface commit. - - A client may send multiple ack_configure requests before committing, but - only the last request sent before a commit indicates which configure - event the client really is responding to. - - - - - - - This request destroys the layer surface. - - - - - - The configure event asks the client to resize its surface. - - Clients should arrange their surface for the new states, and then send - an ack_configure request with the serial sent in this configure event at - some point before committing the new surface. - - The client is free to dismiss all but the last configure event it - received. - - The width and height arguments specify the size of the window in - surface-local coordinates. - - The size is a hint, in the sense that the client is free to ignore it if - it doesn't resize, pick a smaller size (to satisfy aspect ratio or - resize in steps of NxM pixels). If the client picks a smaller size and - is anchored to two opposite anchors (e.g. 'top' and 'bottom'), the - surface will be centered on this axis. - - If the width or height arguments are zero, it means the client should - decide its own window dimension. - - - - - - - - - The closed event is sent by the compositor when the surface will no - longer be shown. The output may have been destroyed or the user may - have asked for it to be removed. Further changes to the surface will be - ignored. The client should destroy the resource after receiving this - event, and create a new surface if they so choose. - - - - - - - - - - - - - - - - -