Created
June 20, 2017 13:02
-
-
Save gicmo/0b2ae88379b3af7622eefe47efebc5b4 to your computer and use it in GitHub Desktop.
monitor info via gtk api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -*- mode: C; c-file-style: "stroustrup"; indent-tabs-mode: nil; -*- */ | |
#include <gdk/gdk.h> | |
#include <gtk/gtk.h> | |
#ifdef GDK_WINDOWING_WAYLAND | |
#include <gdk/gdkwayland.h> | |
#endif | |
#ifdef GDK_WINDOWING_X11 | |
#include <gdk/gdkx.h> | |
#endif | |
int | |
main (int argc, char **argv) | |
{ | |
GdkDisplay *display; | |
GdkRectangle geo; | |
int i, n; | |
gboolean is_wayland = FALSE; | |
#if GTK_CHECK_VERSION(4, 0, 0) | |
gboolean ok = gtk_init_check(); | |
#else | |
gboolean ok = gtk_init_check(&argc, &argv); | |
#endif | |
if (!ok) { | |
return -1; | |
} | |
g_print("Gtk+ version: %d.%d.%d\n", | |
gtk_get_major_version(), | |
gtk_get_minor_version(), | |
gtk_get_micro_version()); | |
display = gdk_display_get_default (); | |
if (display == NULL) { | |
return -1; | |
} | |
#ifdef GDK_WINDOWING_WAYLAND | |
if (GDK_IS_WAYLAND_DISPLAY(display)) { | |
g_print("Wayland\n"); | |
is_wayland = TRUE; | |
} | |
#endif | |
#ifdef GDK_WINDOWING_X11 | |
if (!is_wayland && GDK_IS_X11_DISPLAY (display)) { | |
g_print("X11\n"); | |
} | |
#endif | |
n = gdk_display_get_n_monitors(display); | |
for (i = 0; i < n; i++) { | |
GdkMonitor *moni = gdk_display_get_monitor(display, i); | |
const char *model = gdk_monitor_get_model(moni); | |
int w = gdk_monitor_get_width_mm(moni); | |
int h = gdk_monitor_get_height_mm(moni); | |
int sf = gdk_monitor_get_scale_factor(moni); | |
gdk_monitor_get_geometry(moni, &geo); | |
int x = geo.width; | |
int y = geo.height; | |
g_print("\n"); | |
g_print("Monitor: %s [%d]\n", model, i); | |
g_print(" %d x %d [mm x mm]\n", w, h); | |
g_print(" %d x %d [px]\n", x, y); | |
g_print(" scale: %d\n", sf); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment