Position sub-window in top right corner

I have a window that I would like to put in the top right corner of the user’s browser, I’m having trouble getting at the correct positions. I assume that UI.getCurrent is not the correct width to be looking at, but I’m not sure what is correct.

The following snippet was based on another example I found in the forums, but it does not work as expected:

            CompareResultsWindow window = new CompareResultsWindow();
            UI.getCurrent().addWindow(window);
            int margin = 20;
            window.setPositionX((int) (UI.getCurrent().getWidth() - window.getWidth() - margin));
            window.setPositionY((margin));

The UI might return values like -1.
In Vaadin 7 use the method described here
https://vaadin.com/forum#!/thread/208232/2967510
instead.

Thanks, UI.getCurrent().getPage().getBrowserWindowWidth(); worked perfectly