From 19ee09cc776bc4db41ea272d092960cd4f2167f8 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Mitsuharu Date: Fri, 13 Apr 2007 08:14:23 +0000 Subject: [PATCH] [!TARGET_API_MAC_CARBON] Include Displays.h. (mac_screen_config_changed): New variable. (mac_handle_dm_notification, init_dm_notification_handler) (mac_get_screen_info): New functions. [MAC_OS8] (main): Call init_dm_notification_handler. (mac_initialize) [MAC_OSX]: Likewise. (XTread_socket): Call mac_get_screen_info if screen config changed. (mac_initialized): Make static. (mac_initialize_display_info): Remove function. (mac_term_init): Call mac_get_screen_info. Add partial contents of mac_initialize_display_info. --- src/ChangeLog | 14 ++++ src/macterm.c | 215 ++++++++++++++++++++++++++++++++++------------------------ 2 files changed, 141 insertions(+), 88 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 44e4f873223..edb648e7e40 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +2007-04-13 YAMAMOTO Mitsuharu + + * macterm.c [!TARGET_API_MAC_CARBON]: Include Displays.h. + (mac_screen_config_changed): New variable. + (mac_handle_dm_notification, init_dm_notification_handler) + (mac_get_screen_info): New functions. + [MAC_OS8] (main): Call init_dm_notification_handler. + (mac_initialize) [MAC_OSX]: Likewise. + (XTread_socket): Call mac_get_screen_info if screen config changed. + (mac_initialized): Make static. + (mac_initialize_display_info): Remove function. + (mac_term_init): Call mac_get_screen_info. Add partial contents of + mac_initialize_display_info. + 2007-04-12 YAMAMOTO Mitsuharu * mac.c (xrm_get_preference_database, Fmac_get_preference) diff --git a/src/macterm.c b/src/macterm.c index 9d190a3e4f6..bee1af5ab71 100644 --- a/src/macterm.c +++ b/src/macterm.c @@ -52,6 +52,7 @@ Boston, MA 02110-1301, USA. */ #include #include #include +#include #if defined (__MRC__) || (__MSL__ >= 0x6000) #include #endif @@ -8869,6 +8870,9 @@ int mac_pass_control_to_system; Carbon/Apple event handlers. */ static struct input_event *read_socket_inev = NULL; +/* Whether or not the screen configuration has changed. */ +static int mac_screen_config_changed = 0; + Point saved_menu_event_location; /* Apple Events */ @@ -10399,6 +10403,87 @@ remove_window_handler (window) } +static pascal void +mac_handle_dm_notification (event) + AppleEvent *event; +{ + mac_screen_config_changed = 1; +} + +static OSErr +init_dm_notification_handler () +{ + OSErr err; + static DMNotificationUPP handle_dm_notificationUPP = NULL; + ProcessSerialNumber psn; + + if (handle_dm_notificationUPP == NULL) + handle_dm_notificationUPP = + NewDMNotificationUPP (mac_handle_dm_notification); + + err = GetCurrentProcess (&psn); + if (err == noErr) + err = DMRegisterNotifyProc (handle_dm_notificationUPP, &psn); + + return err; +} + +static void +mac_get_screen_info (dpyinfo) + struct mac_display_info *dpyinfo; +{ +#ifdef MAC_OSX + /* HasDepth returns true if it is possible to have a 32 bit display, + but this may not be what is actually used. Mac OSX can do better. */ + dpyinfo->color_p = CGDisplaySamplesPerPixel (kCGDirectMainDisplay) > 1; + dpyinfo->n_planes = CGDisplayBitsPerPixel (kCGDirectMainDisplay); + { + CGDisplayErr err; + CGDisplayCount ndisps; + CGDirectDisplayID *displays; + + err = CGGetActiveDisplayList (0, NULL, &ndisps); + if (err == noErr) + { + displays = alloca (sizeof (CGDirectDisplayID) * ndisps); + err = CGGetActiveDisplayList (ndisps, displays, &ndisps); + } + if (err == noErr) + { + CGRect bounds = CGRectZero; + + while (ndisps-- > 0) + bounds = CGRectUnion (bounds, CGDisplayBounds (displays[ndisps])); + dpyinfo->height = CGRectGetHeight (bounds); + dpyinfo->width = CGRectGetWidth (bounds); + } + else + { + dpyinfo->height = CGDisplayPixelsHigh (kCGDirectMainDisplay); + dpyinfo->width = CGDisplayPixelsWide (kCGDirectMainDisplay); + } + } +#else /* !MAC_OSX */ + { + GDHandle gdh = GetMainDevice (); + Rect rect = (**gdh).gdRect; + + dpyinfo->color_p = TestDeviceAttribute (gdh, gdDevType); + for (dpyinfo->n_planes = 32; dpyinfo->n_planes > 0; dpyinfo->n_planes >>= 1) + if (HasDepth (gdh, dpyinfo->n_planes, gdDevType, dpyinfo->color_p)) + break; + + for (gdh = DMGetFirstScreenDevice (dmOnlyActiveDisplays); gdh; + gdh = DMGetNextScreenDevice (gdh, dmOnlyActiveDisplays)) + UnionRect (&rect, &(**gdh).gdRect, &rect); + + dpyinfo->height = rect.bottom - rect.top; + dpyinfo->width = rect.right - rect.left; + } +#endif /* !MAC_OSX */ +} + + #if __profile__ void profiler_exit_proc () @@ -10456,6 +10541,8 @@ main (void) init_apple_event_handler (); + init_dm_notification_handler (); + { char **argv; int argc = 0; @@ -11377,6 +11464,12 @@ XTread_socket (sd, expected, hold_quit) pending_autoraise_frame = 0; } + if (mac_screen_config_changed) + { + mac_get_screen_info (dpyinfo); + mac_screen_config_changed = 0; + } + #if !USE_CARBON_EVENTS /* Check which frames are still visible. We do this here because there doesn't seem to be any direct notification from the Window @@ -11511,92 +11604,7 @@ make_mac_terminal_frame (struct frame *f) Initialization ***********************************************************************/ -int mac_initialized = 0; - -void -mac_initialize_display_info () -{ - struct mac_display_info *dpyinfo = &one_mac_display_info; - - bzero (dpyinfo, sizeof (*dpyinfo)); - -#ifdef MAC_OSX - dpyinfo->mac_id_name - = (char *) xmalloc (SCHARS (Vinvocation_name) - + SCHARS (Vsystem_name) - + 2); - sprintf (dpyinfo->mac_id_name, "%s@%s", - SDATA (Vinvocation_name), SDATA (Vsystem_name)); -#else - dpyinfo->mac_id_name = (char *) xmalloc (strlen ("Mac Display") + 1); - strcpy (dpyinfo->mac_id_name, "Mac Display"); -#endif - - dpyinfo->reference_count = 0; - dpyinfo->resx = 72.0; - dpyinfo->resy = 72.0; -#ifdef MAC_OSX - /* HasDepth returns true if it is possible to have a 32 bit display, - but this may not be what is actually used. Mac OSX can do better. */ - dpyinfo->color_p = CGDisplaySamplesPerPixel (kCGDirectMainDisplay) > 1; - dpyinfo->n_planes = CGDisplayBitsPerPixel (kCGDirectMainDisplay); - { - CGDisplayErr err; - CGDisplayCount ndisps; - CGDirectDisplayID *displays; - - err = CGGetActiveDisplayList (0, NULL, &ndisps); - if (err == noErr) - { - displays = alloca (sizeof (CGDirectDisplayID) * ndisps); - err = CGGetActiveDisplayList (ndisps, displays, &ndisps); - } - if (err == noErr) - { - CGRect bounds = CGRectZero; - - while (ndisps-- > 0) - bounds = CGRectUnion (bounds, CGDisplayBounds (displays[ndisps])); - dpyinfo->height = CGRectGetHeight (bounds); - dpyinfo->width = CGRectGetWidth (bounds); - } - else - { - dpyinfo->height = CGDisplayPixelsHigh (kCGDirectMainDisplay); - dpyinfo->width = CGDisplayPixelsWide (kCGDirectMainDisplay); - } - } -#else - { - GDHandle gdh = GetMainDevice (); - Rect rect = (**gdh).gdRect; - - dpyinfo->color_p = TestDeviceAttribute (gdh, gdDevType); - for (dpyinfo->n_planes = 32; dpyinfo->n_planes > 0; dpyinfo->n_planes >>= 1) - if (HasDepth (gdh, dpyinfo->n_planes, gdDevType, dpyinfo->color_p)) - break; - - for (gdh = GetDeviceList (); gdh; gdh = GetNextDevice (gdh)) - if (TestDeviceAttribute (gdh, screenDevice) - && TestDeviceAttribute (gdh, screenActive)) - UnionRect (&rect, &(**gdh).gdRect, &rect); - - dpyinfo->height = rect.bottom - rect.top; - dpyinfo->width = rect.right - rect.left; - } -#endif - dpyinfo->grabbed = 0; - dpyinfo->root_window = NULL; - dpyinfo->image_cache = make_image_cache (); - - dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; - dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; - dpyinfo->mouse_face_face_id = DEFAULT_FACE_ID; - dpyinfo->mouse_face_window = Qnil; - dpyinfo->mouse_face_overlay = Qnil; - dpyinfo->mouse_face_hidden = 0; -} - +static int mac_initialized = 0; static XrmDatabase mac_make_rdb (xrm_option) @@ -11630,9 +11638,37 @@ mac_term_init (display_name, xrm_option, resource_name) if (x_display_list) error ("Sorry, this version can only handle one display"); - mac_initialize_display_info (); - dpyinfo = &one_mac_display_info; + bzero (dpyinfo, sizeof (*dpyinfo)); + +#ifdef MAC_OSX + dpyinfo->mac_id_name + = (char *) xmalloc (SCHARS (Vinvocation_name) + + SCHARS (Vsystem_name) + + 2); + sprintf (dpyinfo->mac_id_name, "%s@%s", + SDATA (Vinvocation_name), SDATA (Vsystem_name)); +#else + dpyinfo->mac_id_name = (char *) xmalloc (strlen ("Mac Display") + 1); + strcpy (dpyinfo->mac_id_name, "Mac Display"); +#endif + + dpyinfo->reference_count = 0; + dpyinfo->resx = 72.0; + dpyinfo->resy = 72.0; + + mac_get_screen_info (dpyinfo); + + dpyinfo->grabbed = 0; + dpyinfo->root_window = NULL; + dpyinfo->image_cache = make_image_cache (); + + dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; + dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; + dpyinfo->mouse_face_face_id = DEFAULT_FACE_ID; + dpyinfo->mouse_face_window = Qnil; + dpyinfo->mouse_face_overlay = Qnil; + dpyinfo->mouse_face_hidden = 0; dpyinfo->xrdb = mac_make_rdb (xrm_option); @@ -11650,6 +11686,7 @@ mac_term_init (display_name, xrm_option, resource_name) return dpyinfo; } + /* Get rid of display DPYINFO, assuming all frames are already gone. */ void @@ -11869,6 +11906,8 @@ mac_initialize () init_apple_event_handler (); + init_dm_notification_handler (); + if (!inhibit_window_system) { static const ProcessSerialNumber psn = {0, kCurrentProcess}; -- 2.11.4.GIT