1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 2002 Hans Breuer
3 * Copyright (C) 2003 Tor Lillqvist
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 #include "gdkprivate-win32.h"
24 typedef BOOL (WINAPI *t_EnumDisplayMonitors)(HDC, LPCRECT, MONITORENUMPROC, LPARAM);
25 typedef BOOL (WINAPI *t_GetMonitorInfoA)(HMONITOR, LPMONITORINFO);
27 static t_EnumDisplayMonitors p_EnumDisplayMonitors = NULL;
28 static t_GetMonitorInfoA p_GetMonitorInfoA = NULL;
31 _gdk_windowing_set_default_display (GdkDisplay *display)
33 g_assert (_gdk_display == display);
37 count_monitor (HMONITOR hmonitor,
42 gint *n = (gint *) data;
50 enum_monitor (HMONITOR hmonitor,
55 MONITORINFOEX monitor_info;
57 gint *index = (gint *) data;
58 GdkRectangle *monitor;
60 g_assert (*index < _gdk_num_monitors);
62 monitor = _gdk_monitors + *index;
64 monitor_info.cbSize = sizeof (MONITORINFOEX);
65 (*p_GetMonitorInfoA) (hmonitor, (MONITORINFO *) &monitor_info);
67 #ifndef MONITORINFOF_PRIMARY
68 #define MONITORINFOF_PRIMARY 1
71 if (monitor_info.dwFlags & MONITORINFOF_PRIMARY)
73 /* For the primary monitor, use SPI_GETWORKAREA */
76 SystemParametersInfo (SPI_GETWORKAREA, 0, &rect, 0);
77 monitor->x = rect.left;
78 monitor->y = rect.top;
79 monitor->width = rect.right - rect.left;
80 monitor->height = rect.bottom - rect.top;
82 /* Put primary monitor at index 0, just in case somebody needs
83 * to know which one is the primary.
87 GdkRectangle temp = *monitor;
88 *monitor = _gdk_monitors[0];
89 _gdk_monitors[0] = temp;
94 monitor->x = monitor_info.rcMonitor.left;
95 monitor->y = monitor_info.rcMonitor.top;
96 monitor->width = monitor_info.rcMonitor.right - monitor_info.rcMonitor.left;
97 monitor->height = monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top;
106 gdk_display_open (const gchar *display_name)
110 if (_gdk_display != NULL)
111 return NULL; /* single display only */
113 _gdk_display = g_object_new (GDK_TYPE_DISPLAY, NULL);
114 _gdk_screen = g_object_new (GDK_TYPE_SCREEN, NULL);
116 user32 = GetModuleHandle ("user32.dll");
117 g_assert (user32 != NULL);
119 p_EnumDisplayMonitors = (t_EnumDisplayMonitors) GetProcAddress (user32, "EnumDisplayMonitors");
120 p_GetMonitorInfoA = (t_GetMonitorInfoA) GetProcAddress (user32, "GetMonitorInfoA");
122 CloseHandle (user32);
124 if (p_EnumDisplayMonitors != NULL && p_GetMonitorInfoA != NULL)
128 _gdk_num_monitors = 0;
130 (*p_EnumDisplayMonitors) (NULL, NULL, count_monitor, (LPARAM) &_gdk_num_monitors);
132 _gdk_monitors = g_new (GdkRectangle, _gdk_num_monitors);
134 (*p_EnumDisplayMonitors) (NULL, NULL, enum_monitor, (LPARAM) &index);
136 _gdk_offset_x = G_MININT;
137 _gdk_offset_y = G_MININT;
139 /* Calculate offset */
140 for (i = 0; i < _gdk_num_monitors; i++)
142 _gdk_offset_x = MAX (_gdk_offset_x, -_gdk_monitors[i].x);
143 _gdk_offset_y = MAX (_gdk_offset_y, -_gdk_monitors[i].y);
145 GDK_NOTE (MISC, g_print ("Multi-monitor offset: (%d,%d)\n",
146 _gdk_offset_x, _gdk_offset_y));
148 /* Translate monitor coords into GDK coordinate space */
149 for (i = 0; i < _gdk_num_monitors; i++)
151 _gdk_monitors[i].x += _gdk_offset_x;
152 _gdk_monitors[i].y += _gdk_offset_y;
153 GDK_NOTE (MISC, g_print ("Monitor %d: %dx%d@+%d+%d\n",
154 i, _gdk_monitors[i].width,
155 _gdk_monitors[i].height,
156 _gdk_monitors[i].x, _gdk_monitors[i].y));
164 _gdk_num_monitors = 1;
165 _gdk_monitors = g_new (GdkRectangle, 1);
166 SystemParametersInfo (SPI_GETWORKAREA, 0, &rect, 0);
167 _gdk_monitors[0].x = rect.left;
168 _gdk_monitors[0].y = rect.top;
169 _gdk_monitors[0].width = rect.right - rect.left;
170 _gdk_monitors[0].height = rect.bottom - rect.top;
176 gdk_screen_set_default_colormap (_gdk_screen,
177 gdk_screen_get_system_colormap (_gdk_screen));
178 _gdk_windowing_window_init ();
179 _gdk_windowing_image_init ();
181 _gdk_input_init (_gdk_display);
184 g_signal_emit_by_name (gdk_display_manager_get (),
185 "display_opened", _gdk_display);
190 G_CONST_RETURN gchar *
191 gdk_display_get_name (GdkDisplay *display)
193 return gdk_get_display_arg_name ();
197 gdk_display_get_n_screens (GdkDisplay *display)
203 gdk_display_get_screen (GdkDisplay *display,
210 gdk_display_get_default_screen (GdkDisplay *display)