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

Update charatlas when monitor DPI changes #1172

Merged
merged 5 commits into from
Jan 5, 2018

Conversation

Tyriar
Copy link
Member

@Tyriar Tyriar commented Dec 29, 2017

Fixes #1118

@Tyriar Tyriar added this to the 3.1.0 milestone Dec 29, 2017
@Tyriar Tyriar self-assigned this Dec 29, 2017
src/Terminal.ts Outdated
// Listen for window zoom
window.addEventListener('resize', () => rendererResizeListener);
// Listen for monitor DPI change
window.matchMedia('screen and (-webkit-min-device-pixel-ratio: 1.5)').addListener(rendererResizeListener);
Copy link
Contributor

Choose a reason for hiding this comment

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

Having a look at the -webkit-min-device-pixel-ratio media query, we should be able to replace it with the more standardised min-resolution clause as mentioned in the examples section here: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/-webkit-device-pixel-ratio. I have not tested it yet, but I think it's worth to give it a try as it would also make it work for other browsers.

screen and (-webkit-min-device-pixel-ratio: 1.5)
vs.
screen and (min-resolution: 1.5dppx)

Btw, do you know if using any other value than 1.5 does make a difference?

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated this to use a more robust solution that fixes the 1.5 problem 😃

Can try min/max-resolution as well

}
// Add listeners for new DPR
this._currentDevicePixelRatio = window.devicePixelRatio;
this._minMediaMatchList = window.matchMedia(`screen and (-webkit-min-device-pixel-ratio: ${window.devicePixelRatio})`);
Copy link
Contributor

Choose a reason for hiding this comment

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

I've just tested using this code:

window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`).addListener(() => {
  console.log('dpi changed')
});

It fires whenever that media query match becomes either true or false (good to test by changing the browser zoom level). This means we can listen for the resolution change without having to listen for min and max separately.

Copy link
Member Author

Choose a reason for hiding this comment

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

Way better! 😃

mofux
mofux previously requested changes Jan 3, 2018
}
this._listener = listener;
this._outerListener = () => {
console.log('change!');
Copy link
Contributor

Choose a reason for hiding this comment

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

Look what I've found 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

That should be changed!

@mofux
Copy link
Contributor

mofux commented Jan 3, 2018

In general, what do you think about initialising the dpr monitor from within the xterm constructor and then have it emit an event on the terminal instance whenever the screen size changes? The renderer would then listen for that event on the terminal instance instead. This would give the advantage that external addons could also listen for screen size changes without having to create a separate ScreenDprMonitor instance.

@Tyriar
Copy link
Member Author

Tyriar commented Jan 3, 2018

I'll refactor as necessary when it's needed. The screen reader support PR needs to listen to this as well so I'll fiddle with it pretty fast #1182. Definitely don't want multiple of them

@Tyriar Tyriar changed the base branch from v3 to master January 5, 2018 16:26
@Tyriar
Copy link
Member Author

Tyriar commented Jan 5, 2018

Pushing this in as tests pass locally and review requests are done. I need to build upon ScreenDprMonitor in other PRs so merging this in will make that much easier to manage.

@Tyriar Tyriar merged commit be18507 into xtermjs:master Jan 5, 2018
@Tyriar Tyriar deleted the 1118_dpi_change branch January 5, 2018 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants