Please help with this beginner's program for fetching gdk screen attributes. I have a small C++ program to find out the connected display units. I am using c++ on Linux Debian. gdk_screen_get_default() doesn't return Screen object. If I don't check for screen object then the following error occurs.
Error (process:8023): Gdk-CRITICAL **: gdk_screen_get_monitor_geometry: assertion 'GDK_IS_SCREEN (screen)' failed
I went through related posts and referred to Programmatically determining individual screen widths/heights in Linux (w/Xinerama, TwinView, and/or BigDesktop) for the below code snippet.
Thanks for your help. Any pointers/guidelines to resolve this would be helpful.
I have one monitor connected and the display settings are
$ echo $XDG_CURRENT_DESKTOP
GNOME
$ echo $DISPLAY
:0
CODE
#include <gdk/gdk.h>
#include <iostream>
/*
GTK version 3.14.5
g++ getScreenInfo.cpp -o getScreenInfo `pkg-config gtk+-3.0 --cflags --libs`
*/
int main()
{
GdkScreen *screen;
screen = gdk_screen_get_default();
int num_monitors;
int i;
if (screen)
{
num_monitors = gdk_screen_get_n_monitors(screen);
for (i = 0; i < num_monitors; i++)
{
GdkRectangle rect;
gdk_screen_get_monitor_geometry (screen, i, &rect);
std::cout << "monitor " << i << ": coordinates (" << rect.x << ","
<< rect.y << ", size (" << rect.width << "," << rect.height << ")"
<< std::endl;
}
}else
{
std::cout << "Couldn't obtain default screen object" << std::endl;
}
}
Aucun commentaire:
Enregistrer un commentaire