Adds winprop preferredWidth to set default window width by wm_class (supports 'px' or '%' values)#453
Conversation
Updated README.md and added table with some Winprop descriptions. Added special case Winprop value for preferredWidthStep = 3 which maximises the window on creation.
Defining a ratio seems cleaner and is then independent of the useful width steps (which is user configurable).
|
@Gelbana @tadfisher @ccope @smichel17 - here's another quick fix to review when someone has time. We could even combine this functionality into one winprop Thoughts? |
There was a problem hiding this comment.
I think combining them into one setting is a good idea.
From the user's perspective, I think it's a simpler interface. I would suggest defining it as a string.
This way, we keep the flexibility to add different units of measurement in the future, without complicating the interface further. The numerical behavior could be allowed but should be undocumented/undefined, since it would likely change if we added a new unit.
For the internal representation, it's easier to reason about when the property either exists or doesn't vs also having to handle the 3rd case of when both exist (this gets worse with additional units). The code itself isn't more complicated, but it increases the chance of some other part of the code accidentally depending on the order of priority, or something like that.
-
For now, I think an internal representation as a number, with the fraction/pixel distinction you mentioned, is good. If more units are added, it would probably make sense to switch to an object with the shape
{ value: number, unit: string }. -
I would suggest parsing the user input to the internal representation as soon as it is defined (i.e. in the
defwinpropfunction).
|
@smichel17, yep, that makes a lot of sense. I hadn't considered other units, but yes that is a possibility. If we make it a string input then there's really no reason why we can't parse units as part of that - e.g. like css
Do you think that might cover current (and future perceicable) use cases for this? |
|
|
Nitpicking is fine! (since I don't really like nits!). I agree though - I'll update external to support One thing though - you'll note a few other PRs like #456 and #454 do use standard notation for ratios (0.5 as opposed to 50%)... my undergrad was mathematics so I prefer standard notation for ratios (but then again, I'm biased there); but I do like the fact that Not sure what you think about consistency for those other PRs. Thoughts? (edit: at this stage, I'll just implement the changes there and we can discuss those other PRs when needed). |
|
I agree that consistency is good. I personally like standard notation. The "software engineer" part of my brain screams ONLY ALLOW ONE WAY TO DO IT AND MAKE UNITS EXPLICIT. I'll sleep on it. As long as it's parsed to the internal representation right away, it's probably fine. |
with units "px" or "%" (e.g. "50%" or "500px" etc.)
|
Thanks @smichel17! See changes in latest commit in this PR. Yes, this is a much cleaner approach. Currently accepting Please re-review. P.S. I did end up going with an internal |
…ay (in extension settings) to percentage format (e.g. `30` instead of `0.3`).
…exists (avoids duplicates). Means if multiple for the same wm_class are defined (for some strange reason) then will take the last one. Updated comments and the WARNING for unvalid units. Lastly, being more strict on the units (previously was lowercasing them so 'PX', 'Px', 'pX' would still work...).
new `preferredWidth` window property. Left reference to not currently being able to set the window height.
doubling up each spec in array).
… settings (#454) * Added layout() call to show() - needed to readjust minimap position independent of MINIMAP_SCALE (preparation for setting scale to user option). Added "minimap-scale" to schema (and recompiled schema). Minimap.js now uses "prefs.minimap_scale" from schema. Added "Mini-map scale (size)" GtkSpinButton to settings.ui and implemented binding in prefs.js. * Removed period from tooltip description to align with gnome human interface guidelines. * Set right-side window preview's x position directly (using the used scale and clone.width instead of 'get_transformed_size()'). * Implemented fix for issue #457. Now uses user-defined mini-map scale value for StackOverlay window previews. * For consistency with other PRs (like #453) changed value display (in extension settings) to percentage format (e.g. `30` instead of `0.3`).
…463) Fixes #462, closes #453, closes #304. This PR adds a new tab to the PaperWM extensions settings ui that allows users to: - set default window properties for a window class (app etc.); - settings are immediately applied (no need to login/logout of gnome as is needed for the current approach); - set window (identified by `wm_class` or `title`) to open on scratch by default; - set a preferred window (identified by `wm_class` or `title`) width - supports both `%` and `px` input values; ### Notes: - the `preferredWidth` property is ignored if a window is set to `scratch_layer`; - Winprop entries that have no `wm_class` or `title` input will not be applied/persisted (they won't show when you open the preference settings next time); - this does not impact the current approach of setting winprops in `user.js` configuration (which you can still do); - modelled after keybinding settings ui (and fits in nicely with it); Feedback super welcome! ### See it in action in the video below (click the play button): https://user-images.githubusercontent.com/30424662/211422647-79e64d56-5dbb-4054-b9a6-32bf3194b636.mp4
Adds user configurable window property (settable in
user.jsfor example)preferredWidth. This property allows setting an initial window width. Accepts a String value with unitpxor%(e.g."50%","500px", etc).See
README.mdchanges in this PR for more details (under sectionWinprops).This approach builds on / extends (and relates to) #304.
I wouldn't say it fixes that PR(?) since it only addresses the width (and not the vertical height).I'm going to say this fixes #304 since the discussion in that issue focuses on width (with some comments re height being tricky). Can create another issue for setting
preferredHeightif there is appetite for that).Thoughts and feedback welcome!