Skip to content

Preferred window size and position offsets#222

Open
csabag wants to merge 1 commit into
cxw42:mainfrom
csabag:preferred-window-position
Open

Preferred window size and position offsets#222
csabag wants to merge 1 commit into
cxw42:mainfrom
csabag:preferred-window-position

Conversation

@csabag

@csabag csabag commented Aug 6, 2020

Copy link
Copy Markdown

Adding preferred window size and position offsets settings.

Fixes #182.

@cxw42 cxw42 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@csabag Thanks for your good work on this! I have some specific questions and comments related to robustness and style. Please let me know your thoughts. Much appreciated!

Note: if we need to modify the settings library, I am happy to help.

Comment thread app/bg/background.js
// When a window is created
chrome.windows.onCreated.addListener(function(window){
// Leave TabFern window alone...
if (window.id === me.viewWindowID) return;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if viewWindowID will always exist when this function is called. E.g., I don't know if Chrome will give us window-creation messages for the first window that opens before the TF popup opens. Would you please add a check that viewWindowID is defined before using it?

Comment thread app/bg/background.js

if (S.getBool(S.FIXED_WINDOW_SIZE) && window.type === 'normal') {
let windowSize = S.getString(S.S_WINDOW_SIZE);
[windowWidth, windowHeight] = windowSize.split('x').map((value) => parseInt(value));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a string of WxH instead of separate width and height fields? (And the same throughout.)

E.g., what if the user types 800 x 600 (with spaces around the x) or 800 (forgetting the x H)? I personally would prefer two separate numeric fields.

However, I do see an advantage of a single field. With a single field, it's either set or it's not. Perhaps we could change settings.js to improve the validation.

What are your thoughts?

Comment thread app/bg/background.js
chrome.windows.update(window.id, {width: windowWidth, height: windowHeight});
}
if (S.getBool(S.PREFERRED_WINDOW_POSITION_OFFSET) && window.type === 'normal') {
let fixedOffsetFormat = RegExp(/^([0-9]+):([0-9]+)$/)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please change let to const here and elsewhere that we are creating regexes or other constants.

Also, same question about one field vs. two.

Comment thread app/bg/background.js
leftOffset = parseInt(fixedOffsetValues[2]);
chrome.windows.update(window.id, {top:topOffset, left:leftOffset});
}
let relativeOffsetFormat = RegExp(/^\+([0-9]+):\+([0-9]+)$/)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are allowing positive relative offsets, I would like to allow negative relative offsets as well!

_NAM.CFGS_WINDOW_SIZE = 'window-size';
_DEF[_NAM.CFGS_WINDOW_SIZE] = '800x600';
_VAL[_NAM.CFGS_WINDOW_SIZE] = (v)=>{
let regex = RegExp(/^[0-9]+[xX][0-9]+$/);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This validator does not match the parsing above (windowSize.split('x')). If we stay with the single-field approach, I would like to move the regex or other logic into an export from S so that we only have to make changes in one place.

Comment thread app/settings/manifest.js
"group": future_i18n("When I..."),
"type": "description",
"text": future_i18n(`If you change this value please refresh Settings
page (this page) to reveal preferred window size parameter`)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give me a bit more detail about this? We can update the settings page at load time (app/settings/settings.js. main()) if we need to populate a field or customize something.

Comment thread app/settings/manifest.js
"tab": future_i18n("Behaviour"),
"group": future_i18n("When I..."),
"type": "description",
"text": future_i18n(`The format of the window size parameter is <em>[width]x[height]</em>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this show up OK? I can't remember if it needs to be "html" instead of "text".

Comment thread app/settings/manifest.js
},
];

if(S.getBool(S.FIXED_WINDOW_SIZE)) setting_definitions.push(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: please add { } around the settings_definitions.push for consistency with in the codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add option to define position, size and offset of new windows (not specific to which window it is)

2 participants