MozillaZine

[Thunderbird] Center dialog in the middle of main window

Talk about add-ons and extension development.
metju312
 
Posts: 10
Joined: September 6th, 2017, 1:25 am

Post Posted September 15th, 2017, 2:39 am

Hi,

How to center dialog in the middle of main TB window?

I already done:
Code: Select all
window.openDialog("chrome://myext/content/prompt.xul", "dialogname",
      "chrome,centerscreen,resizable=no");


But this center my dialog in the middle of the whole screen.

Thanks for help.

morat
 
Posts: 2366
Joined: February 3rd, 2009, 6:29 pm

Post Posted September 15th, 2017, 8:38 am

Try this:

Code: Select all
// center window on 3pane window and ensure window is fully onscreen
var mail3PaneWindow = Services.wm.getMostRecentWindow("mail:3pane");
var xOffset = mail3PaneWindow.outerWidth / 2 - window.outerWidth / 2;
var yOffset = mail3PaneWindow.outerHeight / 2 - window.outerHeight / 2;
var newX = mail3PaneWindow.screenX + xOffset;
var newY = mail3PaneWindow.screenY + yOffset;
if (newX < screen.availLeft) newX = screen.availLeft + 20;
if ((newX + window.outerWidth) > (screen.availLeft + screen.availWidth))
  newX = (screen.availLeft + screen.availWidth) - window.outerWidth - 20;
if (newY < screen.availTop) newY = screen.availTop + 20;
if ((newY + window.outerHeight) > (screen.availTop + screen.availHeight))
  newY = (screen.availTop + screen.availHeight) - window.outerHeight - 20;
window.moveTo(newX, newY);

Reference
http://dxr.mozilla.org/mozilla-release/ ... rtPosition

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 1 guest