-
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remember window size #449
Comments
Been looking into this recently for KDE applications, they typically store geometry. However on Wayland restoring window position is a bit funky with Qr and instead of defaulting to centered it can default to what appears to be 0,0. It would be possible to store geometry though. We'd just have to be careful. If we maximise a window and store that geometry, then un-maximizing on load would set that maximised geometry. But not storing geometry on close when the window is maximised results in a problem where if you resize, maximise, close, then re-open, the resized geometry is not remembered. And storing on each resize event is a bit costly with performance. One option is to use a timer, I think that's what KDE's new And we may also want to store if the window was maximised, maybe not applying geometry if a window was opened maximised (we could store a flag for this). |
It makes the most sense to store the geometry once the applications exits. The signal
I think storing whether a window was maximized or not is the most interesting part. We could store whether it was maximized before closing and ignore the size on startup if that is the case and just maximize the window. |
Hey, many thanks for the interest! If you're going to implement this feature, would be good to target Wayland first, as X11 will be deprecated at some point. Implementing for both would be the ideal solution, but if we have to choose between one of them then Wayland would be the priority and future-proof. |
There shouldn't be any need to prioritize either or, Qt should handle that. However, Wayland itself does not offer a protocol for setting window positions to my understanding, positioning is handled by the compositor. If Wayland itself doesn't offer a protocol for it, then toolkits like Qt can't offer it, and so ProtonUp-Qt can't do it. @DavidoTek If you're interested, this is how KDE handle it on their side:
We wouldn't need to separate it like this per-se, some KDE apps before this like PlasmaTube had a |
We can use
I wonder how much effort it is to implement it for common compositors like KDE KWin and GNOME Mutter. At least in the Flatpak, all KDE libraries should be included, I'm not sure about GNOME stuff. (I think if we decide to implement it, the code should go into a separate file like I guess the first steps are implementing storing the width, height, and maximized state for Wayland/X11 and the position for X11. We can then concentrate on (re-)storing the position on Wayland. |
I agree, we can use this to write the window information out to a config file, one standard seems to be to end the filename with Before it recently switched to using PlasmaTube had a QTimer set up in QML to save the sizing after a fixed time interval. This avoids writing to a file constantly, as the comment in the linked file explains. We would have to set this up ourselves. We could use
I think currently it is not possible at all for applications to specify their positioning to a compositor. To my understanding it is the compositor alone that makes this decision (which I assume is how KWin/Mutter can center windows, place them on the display under the cursor, etc, but why applications cannot restore their positions/last displays on re-open). If this is correct then I assume if support for this is ever accepted into Wayland, Qt would implement support for it under |
I wasn't aware of this, is there a standard of how the content of this file would look? Which program does use that "rc" file? Yeah, I think we would need
Ah, I see. We could add something like # windowutil.py - PSEUDO CODE
def restore_window_geometry(window: QWindow):
window_name: str = window.getSomeUuidOrClassName() # some unique value to identify the window class
# window_name alternative: supply window_name as function parameter of restore_window_geometry()
cfg: dict = some_config_load_fn(CONFIG_FILE_LOCATION) # or parameter with config file ?
if win_cfg := cfg.get(window_name):
window.setGeometry(
win_cfg.get("posx", 0), win_cfg.get("posy", 0),
win_cfg.get("width", 400), win_cfg.get("height", 500)
)
If feel like the BUT: I'm not sure if it possible to determine the geometry of the window after the user clicked the close button. If that is not possible, we can do the timer approach as you suggested.
I see. Apparently there are a few drafts/discussions, but nothing production ready yet.
|
I am not sure if there is a standard, but I checked about ten (there are almost 300 in my Most Qt-based applications seem to use it, KDE applications which are Qt-based will use it, and the Strawberry Music Player also stores an But on further inspection, these may be auto-generated by Plasma, as there is also a For ProtonUp-Qt, the file looks like this on my system. Note that the key is
Perhaps there is a way we can write into these files, and set our own key? Plasma applications typically use
You should be able to, at least in C++ this is possible. Discover used to do this, when it got the import sys
from PySide6.QtCore import Qt, QEvent
from PySide6.QtWidgets import QApplication, QLabel, QWidget, QVBoxLayout
class HelloWorld(QWidget):
def __init__(self):
super().__init__()
self.setup_ui()
def setup_ui(self):
self.setWindowTitle('Hello, World!')
self.show()
def event(self, event):
if event.type() == QEvent.Close:
print(f'Geometry is: {self.geometry()}')
app = QApplication(sys.argv)
ex = HelloWorld()
sys.exit(app.exec()) But this alone is not enough, we still need the timer approach. Otherwise we end up with the problem Discover had, where if a window is maximized and we query the geometry on close, we store the maximized geometry. If we don't store on close if maximized, we will lose window geometry. Therefore we have to store geometry on close if not maximized, and on resize (with a I think you mentioned this earlier, it might be good to see if something like this is already written for PySide6 that we could use as a library, or a code snippet we could drop-in. |
I wonder if that file is created by Plasma itself or by the application (Qt/KDE framework in the case of QSettings supports an ini-like format. We can use that to read/write the *rc file.
The restoring is also handled by the WindowStateSaver, right? If the
Aah, right. What we could do is to only set the
There is this example: https://doc.qt.io/qtforpython-6/overviews/restoring-geometry.html If we create our own code, we could do something like this and handle the type checks using |
When the app is closed, it does not remember neither previous window size nor maximized state. Would be cool if the app remembered it.
The text was updated successfully, but these errors were encountered: