hyprwm / Hyprland

Hyprland is an independent, highly customizable, dynamic tiling Wayland compositor that doesn't sacrifice on its looks.
https://hyprland.org
BSD 3-Clause "New" or "Revised" License
19.92k stars 849 forks source link

The qt program cannot reset the window size when it uses wayland #3167

Open CnsMaple opened 1 year ago

CnsMaple commented 1 year ago

Hyprland Version

Hyprland, built from branch main at commit 8fefb180b1f4bd62cd866f4c3d1d93ed3f019536 dirty (windowrules: Monitor rule fix (3157)). Tag: v0.29.1-2-g8fefb180 flags: (if any)

Bug or Regression?

Bug

Description

I have a QT program that can reset the window size. When I run it in xwayland, it can be reset normally, but it is not possible in wayland.But I'm not sure if it's a problem with hyprland or with wayland.

How to reproduce

This is demonstrated using the flameshot program.

  1. paru -S flameshot-git.
  2. Launching flameshot in different ways(wayland and xwayland).
  3. Scroll Mouse.

Crash reports, logs, images, videos

wayland:

https://github.com/hyprwm/Hyprland/assets/92523839/f8295df0-c79f-438c-b74a-e852cefd9750

xwayland:

https://github.com/hyprwm/Hyprland/assets/92523839/33e6cdbd-7a3b-43b7-ac65-05998d512a5c

vaxerski commented 1 year ago

hyprland will only resize the toplevel if you set min_width == max_width and min_height == max_height and then commit.

CnsMaple commented 1 year ago

@vaxerski Sorry, I haven't been using hypland for long, I don't quite understand what you mean. Can you tell me how to set it in the configuration file?

memchr commented 1 year ago

It's not about configuration file.

https://github.com/hyprwm/Hyprland/blob/c6c820d16d87c175719569e7ac8c5088ea63f0b2/src/events/Windows.cpp#L728-L732

However, this restriction seems rather superficial and does not correspond to how Xwayland behaves. Many applications do not change the maximum and minimum size when requesting a resize, and some don't set a maximum size (always 0), so most resize requests will always be ignored.

It applies to both GTK and QT.

Sample, press r to request a resize

#!/usr/bin/env python
from PyQt5.QtGui import QKeyEvent
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QApplication

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.resize(400, 400)
        self.setMinimumSize(200, 200)
        self.setMaximumSize(400, 400)
        self.setWindowTitle("test.app")
        self._size = 1

    def keyPressEvent(self, event: QKeyEvent) -> None:
        if event.key() == Qt.Key.Key_R:
            if self._size == 1:
                size = (200, 200)
                self._size = 0
            else:
                size = (400, 400)
                self._size = 1
            print(f"resize to {size}")
            self.resize(*size)

app = QApplication([])

w = Window()
w.show()

app.exec()
vaxerski commented 1 year ago

However, this restriction seems rather superficial and does not correspond to how Xwayland behaves.

xwayland windows change their size via .configure, this is only a mechanism for native wayland.

memchr commented 1 year ago

Considering that many applications do not set a maximum size, would it be better to just use wlr_xdg_surface_get_geometry here?

I haven't been able to find an example of an application that requests resize that also changes its maximum and minimum size.

vaxerski commented 1 year ago

Considering that many applications do not set a maximum size, would it be better to just use wlr_xdg_surface_get_geometry here?

nope

I haven't been able to find an example of an application that requests resize that also changes its maximum and minimum size.

I have, ulauncher for example.

CnsMaple commented 1 year ago

@vaxerski Thank you, I understand what you mean. I have already resolved this issue in my program. However, I have another question. When I am displaying a floating window, the move in the program does not work, and the window is always centered on my screen. Is there any way to make it appear in different specific positions (this move is not for hyprland, it is for qt program).

vaxerski commented 1 year ago

wayland does not allow toplevels to know, or change, their position.