MultiMonitor.h

Go to the documentation of this file.
00001 #ifndef _GTKUTIL_MULTIMON_H_
00002 #define _GTKUTIL_MULTIMON_H_
00003 
00004 #include <gtk/gtkwindow.h>
00005 #include <gdk/gdkscreen.h>
00006 #include <gdk/gdkdisplay.h>
00007 #include "itextstream.h"
00008 
00009 namespace gtkutil
00010 {
00011 
00017     class MultiMonitor
00018     {
00019         public:
00023             static int getNumMonitors ()
00024             {
00025                 // Acquire the default screen reference
00026                 GdkScreen* screen = gdk_display_get_default_screen(gdk_display_get_default());
00027 
00028                 // Get and return the number of monitors
00029                 return gdk_screen_get_n_monitors(screen);
00030             }
00031 
00036             static GdkRectangle getMonitor (int monitorNum)
00037             {
00038                 GdkScreen* screen = gdk_display_get_default_screen(gdk_display_get_default());
00039 
00040                 GdkRectangle geom;
00041                 gdk_screen_get_monitor_geometry(screen, monitorNum, &geom);
00042 
00043                 return geom;
00044             }
00045 
00050             static GdkRectangle getMonitorForWindow (GtkWindow* window)
00051             {
00052                 // Retrieve the screen
00053                 GdkScreen* scr = gtk_window_get_screen(GTK_WINDOW(window));
00054 
00055                 // Get the monitor which the GtkWindow is displayed on
00056                 gint monitorNum = gdk_screen_get_monitor_at_window(scr, GTK_WIDGET(window)->window);
00057 
00058                 return getMonitor(monitorNum);
00059             }
00060 
00061             static void printMonitorInfo ()
00062             {
00063                 globalOutputStream() << "Default screen has " << getNumMonitors() << " monitors.\n";
00064 
00065                 // detect multiple monitors
00066                 for (int j = 0; j < getNumMonitors(); j++) {
00067                     GdkRectangle geom = getMonitor(j);
00068 
00069                     globalOutputStream() << "Monitor " << j << " geometry: " << geom.width << "x" << geom.height
00070                             << " at " << geom.x << ", " << geom.y << "\n";
00071                 }
00072             }
00073     };
00074 
00075 } // namespace gtkutil
00076 
00077 #endif /* _GTKUTIL_MULTIMON_H_ */

Generated by  doxygen 1.6.2