Shrink the Settings window

About programming and getting involved with Linux Mint development
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
Drugwash
Level 5
Level 5
Posts: 733
Joined: Fri Jun 07, 2019 6:40 am
Location: Ploieşti, RO
Contact:

Shrink the Settings window

Post by Drugwash »

For a long time the Settings window for x-lets has been annoying me to death opening so large for sometimes only one or two options. Finally I got to look into this issue and probably/hopefully found the solution. It does work here in Mint 19.2 Cinnamon and I think it also works in 20.2 (forgot whether I tested it there or not). No other higher version here for testing.

The change is simple enough if done carefully. The file is /usr/share/cinnamon/cinnamon-settings/xlet-settings.py so it has to be edited as root:
sudo xed /usr/share/cinnamon/cinnamon-settings/xlet-settings.py
or use whatever other text editor you prefer. But first of all create a backup copy of the original unmodified file, for safety.
Another thing very important as with any Python script: mind the indentation! A single missing or extra space (or other caracter) can and will screw up the whole thing.

First change is a one-liner, simple; see below where it says Added by...:

Code: Select all

    def build_window(self):
        self.window = XApp.GtkWindow()
        self.window.set_default_size(DEFWW, DEFWH)
        main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.window.add(main_box)

        toolbar = Gtk.Toolbar()
        toolbar.get_style_context().add_class("primary-toolbar")
        main_box.add(toolbar)
# Added by Drugwash, 2022.06.04
        self.tb = toolbar
# End addition
The self.tb object is required in the second block of added code; couldn't use the toolbar widget since it isn't declared as global.

Second change consists of six lines (the Added by... block) a little higher in the __init__ method of the MainWindow class:

Code: Select all

class MainWindow(object):
    def __init__(self, xlet_type, uuid, *instance_id):
        [...]
        self.window.show_all()
# Added by Drugwash, 2022.06.04
        m, n = self.instance_stack.get_preferred_size()
        tm, tn = self.tb.get_preferred_size()
        wm, wn = self.window.get_preferred_size()
        pw = m.width if m.height == n.height else n.width
        maxw = max(tn.width, pw)
        self.window.resize(maxw, m.height + tn.height + 10) # small hack since global.ui_scale pertains to js not Python
# End addition
        if instance_id and len(self.instance_info) > 1:
            for info in self.instance_info:
                if info["id"] == instance_id:
                    self.set_instance(info)
                    break
        [...]
That should be all. Save the file overwriting the existing one (have you created the backup copy first ?!)
Nice thing about these Python scripts is that they run right away, no need to restart Cinnamon or the x-let or whatever.
So now just open the Settings dialogs (right-click > Configure...) for your enabled x-lets and see if the windows are at their minimal size.
If no Settings window opens it means you typed/pasted something wrong so double-check and triple-check the added code.
If it still won't work then don't panic - just restore from the backup and forget about it.

If it works correctly for enough people maybe someone will post this as a pull request at GitHub. I can't work with that thing so don't expect me to do it.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Drugwash
Level 5
Level 5
Posts: 733
Joined: Fri Jun 07, 2019 6:40 am
Location: Ploieşti, RO
Contact:

Re: Shrink the Settings window

Post by Drugwash »

Ugh, just realized I had posted the wrong code above. Last line above # End addition in second code block should've been:
self.window.resize(maxw, m.height + tn.height + 10*global.ui_scale)
Fixed it above. Sorry for any inconvenience. :oops:
User avatar
Drugwash
Level 5
Level 5
Posts: 733
Joined: Fri Jun 07, 2019 6:40 am
Location: Ploieşti, RO
Contact:

Re: Shrink the Settings window

Post by Drugwash »

Edited again after finally realizing global.ui_scale is valid in JS not in Python, although there should be some equivalent there too (but this splitting headache won't let me dig properly now).
Locked

Return to “Programming & Development”