Cannot convert glib::objectbase back to gdk::Monitor
Inpsired from an python gtk4 method for getting screen geometry, I'm trying to get the geometries from the default display's monitor list in order to determine the screen width and height. When converting the one item in the list of objectbase back into a monitor, it fails. How can I overcome this with gtkmm? Thank you in advance.
make -B
g++ -c hscale_demo_window.cc -o hscale_demo_window.o `pkg-config gtkmm-4.0 --cflags --libs`
g++ -c sgi_app_window.cc -o sgi_app_window.o `pkg-config gtkmm-4.0 --cflags --libs`
sgi_app_window.cc: In member function ‘void SgiAppWindow::get_screen_height()’:
sgi_app_window.cc:120:88: error: no matching function for call to ‘std::shared_ptr<const Gdk::Monitor>::shared_ptr(Glib::RefPtr<const Glib::ObjectBase>&)’
120 | Glib::RefPtr<const Gdk::Monitor> theOneMonitor = (Glib::RefPtr<const Gdk::Monitor>)theOneObject;
| ^~~~~~~~~~~~
Here's the source
void SgiAppWindow::get_screen_height() {
std::vector<Gdk::Rectangle> m_vGeometryList;
Glib::RefPtr<Gdk::Display> theDisplay = Gdk::Display::get_default();
Glib::RefPtr<const Gio::ListModel> theMonitors = theDisplay->get_monitors();
for (int theMonCounter = 0; theMonCounter < theMonitors->get_n_items(); theMonCounter++) {
//Glib::RefPtr<Gdk::Monitor> theOneMonitor = (Glib::RefPtr<Gdk::Monitor>)theMonitors->get_object(theMonCounter);
//Glib::ObjectBase* theOneObject = (Glib::ObjectBase*)theMonitors->get_object(theMonCounter);
Glib::RefPtr<const Glib::ObjectBase> theOneObject = theMonitors->get_object(theMonCounter);
Glib::RefPtr<const Gdk::Monitor> theOneMonitor = (Glib::RefPtr<const Gdk::Monitor>)theOneObject;
//Glib::RefPtr<const Gdk::Monitor> theOneMonitor = Glib::RefPtr<const Gdk::Monitor>theOneObject;
//Gdk::Rectangle theRectangle = theOneObject->property_geometry();
//m_vGeometryList.push_back(theRectangle);
}
}
void SgiAppWindow::get_screen_width() {
}
//The recommended python way as a point of reference.
// def get_screen_size(display):
// mon_geoms = [
// display.get_monitor(i).get_geometry()
// for i in range(display.get_n_monitors())
// ]
// x0 = min(r.x for r in mon_geoms)
// y0 = min(r.y for r in mon_geoms)
// x1 = max(r.x + r.width for r in mon_geoms)
// y1 = max(r.y + r.height for r in mon_geoms)
// return x1 - x0, y1 - y0
// # example use
// print(get_screen_size(Gdk.Display.get_default()))