Pixel size of primary monitor?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Pixel size of primary monitor?

Gtkmm mailing list
Hello!

I want to know the pixel dimensions of the primary monitor. The reason for this is that I want adapt the initial size of the application window relative to the monitor size. I don't know if their is another pleasant way, but I consider getting the pixel dimensions is generally a useful functionality.

What I use now, before the application window is shown with "Gtk::Application::run()":

Glib::RefPtr<Gdk::Monitor> primary_monitor = window->get_screen()->get_display()->get_primary_monitor();
if (primary_monitor) {
    Gdk::Rectangle monitor_size;
    primary_monitor->get_geometry(monitor_size);
    // adapt size
    width = monitor_size.get_width() / 1.8;
    height = monitor_size.get_height() / 2;
}

This works on X11 and Windows, but not on Wayland! I've get a nullptr and the defaults for width/height are used instead.

As far as I understand:
Gdk::Display // a workstation or seat with I/O interfaces: key, mouse, screen
  Gdk::Screen  // one or more physical screens, a screen could be merged from multiple monitors, probably like a wall of monitors?
    Gdk::Monitor // actually one physical screen!

Gdk::Screen already provides the member functions I need:
  int Gdk::Screen::get_width() const
But it is deprecated and does tell me to use something from Gdk::Monitor:
  Deprecated:
  > Use per-monitor information instead.

First and foremost Gdk::Screen doesn't offer get_width()! And this approach doesn't work either:
Glib::RefPtr<Gdk::Display> display = Gdk::Display::get_default();
if (display) {
    Glib::RefPtr<const Gdk::Monitor> primary_monitor = display->get_primary_monitor();
    if (primary_monitor) {
        Gdk::Rectangle rectangle;
        primary_monitor->get_geometry(rectangle);
        cout << rectangle.get_width() << "\n";
        cout << rectangle.get_height() << "\n";
    }
}

The variable primary_monitor is also nullptr on Wayland.
Can someone tell me what is the standard way to get the pixel dimensions of the primary monitor?

Thank you
Peter
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Pixel size of primary monitor?

Gtkmm mailing list

On Wed, 13 Feb 2019 at 14:55, Peter Weber via gtkmm-list <[hidden email]> wrote:
Glib::RefPtr<Gdk::Monitor> primary_monitor = window->get_screen()->get_display()->get_primary_monitor();
if (primary_monitor) {
    Gdk::Rectangle monitor_size;
    primary_monitor->get_geometry(monitor_size);
    // adapt size
    width = monitor_size.get_width() / 1.8;
    height = monitor_size.get_height() / 2;
}

This works on X11 and Windows, but not on Wayland! I've get a nullptr and the defaults for width/height are used instead.


See https://gitlab.gnome.org/GNOME/gtk/issues/1028 "No monitor reported as primary by GDK under Wayland"


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list