I'm on Ubuntu 22.04 LTS using GNOME Shell 42.9. I've writen an extension that will position and resize a window based on its title, but I want to position the window in the horizontal center of the display (currently using hard-coded coordinates). I therefore need to know the dimensions of the display/workspace where the window lives.
I've looked through the available libraries listed in docs/reference/shell/urlmap.js (GNOME Shell source), and with its references to display, Meta seems to be where I want to be, but I'm not seeing an obvious function/class that would provide this information.
Can any Extension-knowledgeable soul out there point me in the right direction?
1 Answer 1
I'm going to answer my question using the approach I discovered (there are likely others)...
By using the window-created callback:
global.display.connect('window-created', this._onWindowCreated.bind(this));
A display argument is provided to the specified callback function. This display argument provides a method for retrieving the geometry of a given monitor:
display.get_monitor_geometry(0);
Using this, I'm able to retrieve the width and height of the specified monitor where the new window exists, and this let's me get it centered on the screen. \o/
Comments
Explore related questions
See similar questions with these tags.