static gint monitor_number (GdkMonitor *monitor) { GdkDisplay *display = gdk_monitor_get_display (monitor); gint n_monitors = gdk_display_get_n_monitors (display); gint i; for (i = 0; i < n_monitors; i++) if (gdk_display_get_monitor (display, i) == monitor) return i; return 0; }
static int get_monitor_num (GdkMonitor *monitor) { GdkDisplay *display; int n_monitors, i; display = gdk_monitor_get_display (monitor); n_monitors = gdk_display_get_n_monitors (display); for (i = 0; i < n_monitors; i++) { if (gdk_display_get_monitor (display, i) == monitor) return i; } return -1; }
/** * gimp_monitor_get_color_profile: * @monitor: a #GdkMonitor * * This function returns the #GimpColorProfile of @monitor * or %NULL if there is no profile configured. * * Since: 3.0 * * Return value: the monitor's #GimpColorProfile, or %NULL. **/ GimpColorProfile * gimp_monitor_get_color_profile (GdkMonitor *monitor) { GdkDisplay *display; GdkScreen *screen; GimpColorProfile *profile = NULL; g_return_val_if_fail (GDK_IS_MONITOR (monitor), NULL); display = gdk_monitor_get_display (monitor); #if defined GDK_WINDOWING_X11 { GdkAtom type = GDK_NONE; gint format = 0; gint nitems = 0; gint number; gchar *atom_name; guchar *data = NULL; number = monitor_number (monitor); if (number > 0) atom_name = g_strdup_printf ("_ICC_PROFILE_%d", number); else atom_name = g_strdup ("_ICC_PROFILE"); screen = gdk_display_get_default_screen (display); if (gdk_property_get (gdk_screen_get_root_window (screen), gdk_atom_intern (atom_name, FALSE), GDK_NONE, 0, 64 * 1024 * 1024, FALSE, &type, &format, &nitems, &data) && nitems > 0) { profile = gimp_color_profile_new_from_icc_profile (data, nitems, NULL); g_free (data); } g_free (atom_name); } #elif defined GDK_WINDOWING_QUARTZ { CGColorSpaceRef space = NULL; space = CGDisplayCopyColorSpace (monitor_number (monitor)); if (space) { CFDataRef data; data = CGColorSpaceCopyICCData (space); if (data) { UInt8 *buffer = g_malloc (CFDataGetLength (data)); /* We cannot use CFDataGetBytesPtr(), because that returns * a const pointer where cmsOpenProfileFromMem wants a * non-const pointer. */ CFDataGetBytes (data, CFRangeMake (0, CFDataGetLength (data)), buffer); profile = gimp_color_profile_new_from_icc_profile (buffer, CFDataGetLength (data), NULL); g_free (buffer); CFRelease (data); } CFRelease (space); } } #elif defined G_OS_WIN32 { HDC hdc = GetDC (NULL); if (hdc) { gchar *path; gint32 len = 0; GetICMProfile (hdc, (LPDWORD) &len, NULL); path = g_new (gchar, len); if (GetICMProfile (hdc, (LPDWORD) &len, path)) { GFile *file = g_file_new_for_path (path); profile = gimp_color_profile_new_from_file (file, NULL); g_object_unref (file); } g_free (path); ReleaseDC (NULL, hdc); } } #endif return profile; }
/** * gimp_session_info_apply_geometry: * @info: * @monitor: * @current_monitor: * * Apply the geometry stored in the session info object to the * associated widget. **/ void gimp_session_info_apply_geometry (GimpSessionInfo *info, GdkMonitor *current_monitor, gboolean apply_stored_monitor) { GdkMonitor *monitor; GdkRectangle rect; GdkRectangle work_rect; GdkGravity gravity; GdkWindowHints hints; gint width; gint height; g_return_if_fail (GIMP_IS_SESSION_INFO (info)); g_return_if_fail (GTK_IS_WINDOW (info->p->widget)); g_return_if_fail (GDK_IS_MONITOR (current_monitor)); monitor = current_monitor; if (apply_stored_monitor) { GdkDisplay *display = gdk_monitor_get_display (current_monitor); gint n_monitors; n_monitors = gdk_display_get_n_monitors (display); if (info->p->monitor != DEFAULT_MONITOR && monitor_number (info->p->monitor) < n_monitors) { monitor = info->p->monitor; } else { monitor = gdk_display_get_primary_monitor (display); } } gdk_monitor_get_geometry (monitor, &rect); gdk_monitor_get_workarea (monitor, &work_rect); info->p->x += rect.x; info->p->y += rect.y; if (gimp_session_info_get_remember_size (info) && info->p->width > 0 && info->p->height > 0) { width = info->p->width; height = info->p->height; } else { GtkRequisition requisition; gtk_widget_get_preferred_size (info->p->widget, NULL, &requisition); width = requisition.width; height = requisition.height; } info->p->x = CLAMP (info->p->x, work_rect.x, work_rect.x + work_rect.width - width); info->p->y = CLAMP (info->p->y, work_rect.y, work_rect.y + work_rect.height - height); if (gimp_session_info_get_remember_size (info) && info->p->width > 0 && info->p->height > 0) { /* This used to call gtk_window_set_default_size() which worked * fine in gtk2 and should continue to work, but doesn't for * dock windows. gtk_window_resize() seems to work fine for all * windows. Leave this comment here until we figured what's * going on... * * XXX If we end up updating this code, also do the same to the * gtk_window_resize() call in gimp_session_info_dialog_show() * signal handler. */ #if 1 gtk_window_resize (GTK_WINDOW (info->p->widget), info->p->width, info->p->height); #else gtk_window_set_default_size (GTK_WINDOW (info->p->widget), info->p->width, info->p->height); #endif } gtk_window_get_size (GTK_WINDOW (info->p->widget), &width, &height); gravity = GDK_GRAVITY_NORTH_WEST; if (info->p->right_align && info->p->bottom_align) { gravity = GDK_GRAVITY_SOUTH_EAST; } else if (info->p->right_align) { gravity = GDK_GRAVITY_NORTH_EAST; } else if (info->p->bottom_align) { gravity = GDK_GRAVITY_SOUTH_WEST; } if (gravity == GDK_GRAVITY_SOUTH_EAST || gravity == GDK_GRAVITY_NORTH_EAST) info->p->x = work_rect.x + work_rect.width - width; if (gravity == GDK_GRAVITY_SOUTH_WEST || gravity == GDK_GRAVITY_SOUTH_EAST) info->p->y = work_rect.y + work_rect.height - height; gtk_window_set_gravity (GTK_WINDOW (info->p->widget), gravity); gtk_window_move (GTK_WINDOW (info->p->widget), info->p->x, info->p->y); hints = GDK_HINT_USER_POS; if (gimp_session_info_get_remember_size (info)) hints |= GDK_HINT_USER_SIZE; gtk_window_set_geometry_hints (GTK_WINDOW (info->p->widget), NULL, NULL, hints); /* Window managers and windowing systems suck. They have their own * ideas about WM standards and when it's appropriate to honor * user/application-set window positions and when not. Therefore, * use brute force and "manually" position dialogs whenever they * are shown. This is important especially for transient dialogs, * because window managers behave even "smarter" then... */ if (GTK_IS_WINDOW (info->p->widget)) g_signal_connect (info->p->widget, "show", G_CALLBACK (gimp_session_info_dialog_show), info); }