opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
75.95k stars 55.62k forks source link

Can't use moveWindow() using Ubuntu 22.04 using WAYLAND but can using X11 for desktop environment #25478

Closed Digital1O1 closed 3 days ago

Digital1O1 commented 3 weeks ago

System Information

OpenCV version: 4.9.0 Operating System / Platform: Ubuntu 22.04 Linux Kernal: 6.5.0-28-generic Compiler & compiler version: G++/GCC : 11.4.0.

Detailed description

So........ There I was, writing a basic C++ program to make sure I understood how the moveWindow() command works for a project I'm working on.

After compiling the program, the generated window; in this case 'banana', wasn't moving as expected.

So a buddy of mine ran the same code on his Debian machine and the window moved as expected.

Below is the C++ code that was ran.

// g++ test.cpp -o cvTest `pkg-config --libs --cflags opencv4`

#include <stdlib.h>
#include <time.h>

#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>

int main()
{

    /* initialize random seed: */
    srand(time(NULL));

    /* generate secret number between 1 and 10: */
    cv::Mat test = cv::Mat::zeros(400, 300, CV_8UC3);

    cv::namedWindow("banana");

    int key, x, y;

    while (1)
    {

        cv::imshow("banana", test);
        key = cv::waitKey(500);

        if (key == 97)
        {
            break;
        }
        else if (key != 0)
        {

            x = rand() % 1000 + 1;
            y = rand() % 1000 + 1;

            cv::moveWindow("banana", x, y);
        }
    }
}

We both realized after Googling the issue for nearly an hour that I was using Wayland on my machine while my buddy was using X11 on his.

So after switching my machine from Wayland --> X11 I recompiled the code and ran it and observed that the window was moving as expected

Steps to reproduce

Steps to reproduce

  1. Ensure that you're using WAYLAND on your machine
  2. Compile the C++ program with the following G++ command : g++ test.cpp -o cvTest pkg-config --libs --cflags opencv4
  3. Run the C++ executable to verify that the window 'banana' isn't moving
  4. Switch over from WAYLAND to X11
  5. Re-run the C++ executable and verify that the window 'banana' is moving
// g++ test.cpp -o cvTest `pkg-config --libs --cflags opencv4`

#include <stdlib.h>
#include <time.h>

#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>

int main()
{

    /* initialize random seed: */
    srand(time(NULL));

    /* generate secret number between 1 and 10: */
    cv::Mat test = cv::Mat::zeros(400, 300, CV_8UC3);

    cv::namedWindow("banana");

    int key, x, y;

    while (1)
    {

        cv::imshow("banana", test);
        key = cv::waitKey(500);

        if (key == 97)
        {
            break;
        }
        else if (key != 0)
        {

            x = rand() % 1000 + 1;
            y = rand() % 1000 + 1;

            cv::moveWindow("banana", x, y);
        }
    }
}

Issue submission checklist

asmorkalov commented 3 weeks ago

@Digital1O1 Wailand backend for UI is experimental feature for now. Feel free to submit PR, if you have a solution.

Kumataro commented 3 days ago

Hello, I investigated about this issue.

At Wayland, each window positions are controlled under the compositor, not application side.

So I think this is Wayland protocol limitation, and it cannot be fixed by application( or client backend in OpenCV) side approach.

And this limitation is described at document on 4.x branch.

https://docs.opencv.org/4.x/d7/dfc/group__highgui.html#ga8d86b207f7211250dbe6e28f76307ffb

If OK, please could you close this issue ?