Skip to content
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

Any way to set per wmclass preferences for default size #304

Closed
markk opened this issue May 13, 2020 · 4 comments · Fixed by #463
Closed

Any way to set per wmclass preferences for default size #304

markk opened this issue May 13, 2020 · 4 comments · Fixed by #463
Labels
enhancement Adds a new feature or extends scope

Comments

@markk
Copy link

markk commented May 13, 2020

It would be great to be able to set desired widths for new windows based on wmclass. I tried this in user.js but it had no effect.

Tiling.defwinprop({ wm_class: "Emacs", _targetWidth: 1536 });

Heights too, in case the window is vertically tiled after creation, if this is possible.

@hedning
Copy link
Member

hedning commented May 13, 2020

Not at the moment, but yeah, it's something we'd like to do, and should be fairly easy implement.

Due to how wayland handles resizing (starting several at the same time doesn't work) the resizing will probably need to be handled by the layout code. Eg. by adding a preferredWidth property which takes precedent here: https://github.com/paperwm/PaperWM/blob/clutter-dnd/tiling.js#L327

@olejorgenb olejorgenb added the enhancement Adds a new feature or extends scope label May 15, 2020
@markk
Copy link
Author

markk commented May 16, 2020

As a rough hack, I added the below to tiling.js and it seems to work.

First I tried setting these values in user.js and using let mwprop = Settings.find_winprop(mw); but this results in JS ERROR: TypeError: mwprop is undefined

var mwprop = { preferredWidth: 1152, preferredHeight: 1421 };
if (mw.wm_class == "Emacs") {
  mwprop = { wm_class: "Emacs", preferredWidth: 1536, preferredHeight: 2132 };
} else if (mw.wm_class == "tilix") {
  mwprop = { wm_class: "tilix", preferredWidth: 1152, preferredHeight: 711 };
}

if (mwprop.preferredWidth) {
  targetWidth = mwprop.preferredWidth;
}
if (mwprop.preferredHeight) {
  targetHeight = mwprop.preferredHeight;
}
// Update targets (NB: must happen before resize request)
mw._targetWidth = targetWidth;
mw._targetHeight = targetHeight;

@hedning
Copy link
Member

hedning commented May 16, 2020

Right, the winprop is looked up when new windows are created:

PaperWM/tiling.js

Lines 2426 to 2438 in b33f2d8

let winprop = Settings.find_winprop(metaWindow);
if (winprop) {
if (winprop.oneshot) {
Settings.winprops.splice(Settings.winprops.indexOf(winprop), 1);
}
if (winprop.scratch_layer) {
debug("#winprops", `Move ${metaWindow.title} to scratch`);
addToScratch = true;
}
if (winprop.focus) {
Main.activateWindow(metaWindow);
}
}

So you'll probably want something like this:

@@ -2441,6 +2450,8 @@ function insertWindow(metaWindow, {existing}) {
             if (winprop.focus) {
                 Main.activateWindow(metaWindow);
             }
+            metaWindow.preferredWidth = winprop.preferredWidth;
+            metaWindow.preferredHeight = winprop.preferredHeight;
         }
 
         if (addToScratch) {

And then apply the preferredWidth in eg. layoutColumnSimple:

@@ -319,6 +319,15 @@ class Space extends Array {
             let resizable = !mw.fullscreen &&
                 mw.get_maximized() !== Meta.MaximizeFlags.BOTH;
 
+            if (mw.preferredWidth) {
+                targetWidth = mw.preferredWidth;
+                delete mw.preferredWidth
+            }
+            if (mw.preferredHeight) {
+                targetHeight = mw.preferredHeight;
+                delete mw.preferredHeight
+            }
+
             if (resizable) {
                 const hasNewTarget = mw._targetWidth !== targetWidth || mw._targetHeight !== targetHeight;
                 const targetReached = f.width === targetWidth && f.height === targetHeight;

To correctly handle vertical tiling, getting the preferred width might be better done here (you'll still want to delete the preferredWidth property so its only applied once though):

@@ -413,9 +422,9 @@ class Space extends Array {
 
             let targetWidth;
             if (i === selectedIndex) {
-                targetWidth = selectedInColumn.get_frame_rect().width;
+                targetWidth = w.preferredWidth || selectedInColumn.get_frame_rect().width;
             } else {
-                targetWidth = Math.max(...column.map(w => w.get_frame_rect().width));
+                targetWidth = Math.max(...column.map(w => w.preferredWidth || w.get_frame_rect().width));
             }
             targetWidth = Math.min(targetWidth, workArea.width - 2*minimumMargin());

While heights might need some more handling if we want the whole column to take up all the available height (there's a use-case to freely resize the height though: #189).

@markk
Copy link
Author

markk commented May 20, 2020

Thanks, this is working well for width.

Height is a more complicated problem though... ideally we'd perhaps want the window to be created full height, but the its preferredHeight to be consulted when it is first pulled into a column. There seems to be a lot going on in layoutGrabColumn - I'll have a go at doing something in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adds a new feature or extends scope
Projects
None yet
3 participants