aboutsummaryrefslogtreecommitdiffstats
path: root/src/macterm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/macterm.c')
-rw-r--r--src/macterm.c212
1 files changed, 128 insertions, 84 deletions
diff --git a/src/macterm.c b/src/macterm.c
index 596d74cddd9..df0275fe22b 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -52,6 +52,7 @@ Boston, MA 02110-1301, USA. */
52#include <LowMem.h> 52#include <LowMem.h>
53#include <Controls.h> 53#include <Controls.h>
54#include <Windows.h> 54#include <Windows.h>
55#include <Displays.h>
55#if defined (__MRC__) || (__MSL__ >= 0x6000) 56#if defined (__MRC__) || (__MSL__ >= 0x6000)
56#include <ControlDefinitions.h> 57#include <ControlDefinitions.h>
57#endif 58#endif
@@ -8890,6 +8891,9 @@ int mac_pass_control_to_system;
8890 Carbon/Apple event handlers. */ 8891 Carbon/Apple event handlers. */
8891static struct input_event *read_socket_inev = NULL; 8892static struct input_event *read_socket_inev = NULL;
8892 8893
8894/* Whether or not the screen configuration has changed. */
8895static int mac_screen_config_changed = 0;
8896
8893Point saved_menu_event_location; 8897Point saved_menu_event_location;
8894 8898
8895/* Apple Events */ 8899/* Apple Events */
@@ -10420,6 +10424,87 @@ remove_window_handler (window)
10420} 10424}
10421 10425
10422 10426
10427static pascal void
10428mac_handle_dm_notification (event)
10429 AppleEvent *event;
10430{
10431 mac_screen_config_changed = 1;
10432}
10433
10434static OSErr
10435init_dm_notification_handler ()
10436{
10437 OSErr err;
10438 static DMNotificationUPP handle_dm_notificationUPP = NULL;
10439 ProcessSerialNumber psn;
10440
10441 if (handle_dm_notificationUPP == NULL)
10442 handle_dm_notificationUPP =
10443 NewDMNotificationUPP (mac_handle_dm_notification);
10444
10445 err = GetCurrentProcess (&psn);
10446 if (err == noErr)
10447 err = DMRegisterNotifyProc (handle_dm_notificationUPP, &psn);
10448
10449 return err;
10450}
10451
10452static void
10453mac_get_screen_info (dpyinfo)
10454 struct mac_display_info *dpyinfo;
10455{
10456#ifdef MAC_OSX
10457 /* HasDepth returns true if it is possible to have a 32 bit display,
10458 but this may not be what is actually used. Mac OSX can do better. */
10459 dpyinfo->color_p = CGDisplaySamplesPerPixel (kCGDirectMainDisplay) > 1;
10460 dpyinfo->n_planes = CGDisplayBitsPerPixel (kCGDirectMainDisplay);
10461 {
10462 CGDisplayErr err;
10463 CGDisplayCount ndisps;
10464 CGDirectDisplayID *displays;
10465
10466 err = CGGetActiveDisplayList (0, NULL, &ndisps);
10467 if (err == noErr)
10468 {
10469 displays = alloca (sizeof (CGDirectDisplayID) * ndisps);
10470 err = CGGetActiveDisplayList (ndisps, displays, &ndisps);
10471 }
10472 if (err == noErr)
10473 {
10474 CGRect bounds = CGRectZero;
10475
10476 while (ndisps-- > 0)
10477 bounds = CGRectUnion (bounds, CGDisplayBounds (displays[ndisps]));
10478 dpyinfo->height = CGRectGetHeight (bounds);
10479 dpyinfo->width = CGRectGetWidth (bounds);
10480 }
10481 else
10482 {
10483 dpyinfo->height = CGDisplayPixelsHigh (kCGDirectMainDisplay);
10484 dpyinfo->width = CGDisplayPixelsWide (kCGDirectMainDisplay);
10485 }
10486 }
10487#else /* !MAC_OSX */
10488 {
10489 GDHandle gdh = GetMainDevice ();
10490 Rect rect = (**gdh).gdRect;
10491
10492 dpyinfo->color_p = TestDeviceAttribute (gdh, gdDevType);
10493 for (dpyinfo->n_planes = 32; dpyinfo->n_planes > 0; dpyinfo->n_planes >>= 1)
10494 if (HasDepth (gdh, dpyinfo->n_planes, gdDevType, dpyinfo->color_p))
10495 break;
10496
10497 for (gdh = DMGetFirstScreenDevice (dmOnlyActiveDisplays); gdh;
10498 gdh = DMGetNextScreenDevice (gdh, dmOnlyActiveDisplays))
10499 UnionRect (&rect, &(**gdh).gdRect, &rect);
10500
10501 dpyinfo->height = rect.bottom - rect.top;
10502 dpyinfo->width = rect.right - rect.left;
10503 }
10504#endif /* !MAC_OSX */
10505}
10506
10507
10423#if __profile__ 10508#if __profile__
10424void 10509void
10425profiler_exit_proc () 10510profiler_exit_proc ()
@@ -10477,6 +10562,8 @@ main (void)
10477 10562
10478 init_apple_event_handler (); 10563 init_apple_event_handler ();
10479 10564
10565 init_dm_notification_handler ();
10566
10480 { 10567 {
10481 char **argv; 10568 char **argv;
10482 int argc = 0; 10569 int argc = 0;
@@ -10554,8 +10641,7 @@ mac_post_mouse_moved_event ()
10554 { 10641 {
10555 Point mouse_pos; 10642 Point mouse_pos;
10556 10643
10557 GetMouse (&mouse_pos); 10644 GetGlobalMouse (&mouse_pos);
10558 LocalToGlobal (&mouse_pos);
10559 err = SetEventParameter (event, kEventParamMouseLocation, typeQDPoint, 10645 err = SetEventParameter (event, kEventParamMouseLocation, typeQDPoint,
10560 sizeof (Point), &mouse_pos); 10646 sizeof (Point), &mouse_pos);
10561 } 10647 }
@@ -11375,6 +11461,12 @@ XTread_socket (sd, expected, hold_quit)
11375 pending_autoraise_frame = 0; 11461 pending_autoraise_frame = 0;
11376 } 11462 }
11377 11463
11464 if (mac_screen_config_changed)
11465 {
11466 mac_get_screen_info (dpyinfo);
11467 mac_screen_config_changed = 0;
11468 }
11469
11378#if !USE_CARBON_EVENTS 11470#if !USE_CARBON_EVENTS
11379 /* Check which frames are still visible. We do this here because 11471 /* Check which frames are still visible. We do this here because
11380 there doesn't seem to be any direct notification from the Window 11472 there doesn't seem to be any direct notification from the Window
@@ -11509,86 +11601,7 @@ make_mac_terminal_frame (struct frame *f)
11509 Initialization 11601 Initialization
11510 ***********************************************************************/ 11602 ***********************************************************************/
11511 11603
11512int mac_initialized = 0; 11604static int mac_initialized = 0;
11513
11514void
11515mac_initialize_display_info ()
11516{
11517 struct mac_display_info *dpyinfo = &one_mac_display_info;
11518
11519 bzero (dpyinfo, sizeof (*dpyinfo));
11520
11521#ifdef MAC_OSX
11522 dpyinfo->mac_id_name
11523 = (char *) xmalloc (SCHARS (Vinvocation_name)
11524 + SCHARS (Vsystem_name)
11525 + 2);
11526 sprintf (dpyinfo->mac_id_name, "%s@%s",
11527 SDATA (Vinvocation_name), SDATA (Vsystem_name));
11528#else
11529 dpyinfo->mac_id_name = (char *) xmalloc (strlen ("Mac Display") + 1);
11530 strcpy (dpyinfo->mac_id_name, "Mac Display");
11531#endif
11532
11533 dpyinfo->reference_count = 0;
11534 dpyinfo->resx = 72.0;
11535 dpyinfo->resy = 72.0;
11536#ifdef MAC_OSX
11537 /* HasDepth returns true if it is possible to have a 32 bit display,
11538 but this may not be what is actually used. Mac OSX can do better. */
11539 dpyinfo->color_p = CGDisplaySamplesPerPixel (kCGDirectMainDisplay) > 1;
11540 dpyinfo->n_planes = CGDisplayBitsPerPixel (kCGDirectMainDisplay);
11541 {
11542 CGDisplayErr err;
11543 CGDisplayCount ndisps;
11544 CGDirectDisplayID *displays;
11545
11546 err = CGGetActiveDisplayList (0, NULL, &ndisps);
11547 if (err == noErr)
11548 {
11549 displays = alloca (sizeof (CGDirectDisplayID) * ndisps);
11550 err = CGGetActiveDisplayList (ndisps, displays, &ndisps);
11551 }
11552 if (err == noErr)
11553 {
11554 CGRect bounds = CGRectMake (0, 0, 0, 0);
11555
11556 while (ndisps-- > 0)
11557 bounds = CGRectUnion (bounds, CGDisplayBounds (displays[ndisps]));
11558 dpyinfo->height = CGRectGetHeight (bounds);
11559 dpyinfo->width = CGRectGetWidth (bounds);
11560 }
11561 else
11562 {
11563 dpyinfo->height = CGDisplayPixelsHigh (kCGDirectMainDisplay);
11564 dpyinfo->width = CGDisplayPixelsWide (kCGDirectMainDisplay);
11565 }
11566 }
11567#else
11568 {
11569 GDHandle main_device_handle = LMGetMainDevice();
11570
11571 dpyinfo->color_p = TestDeviceAttribute (main_device_handle, gdDevType);
11572 for (dpyinfo->n_planes = 32; dpyinfo->n_planes > 0; dpyinfo->n_planes >>= 1)
11573 if (HasDepth (main_device_handle, dpyinfo->n_planes,
11574 gdDevType, dpyinfo->color_p))
11575 break;
11576 dpyinfo->height = (**main_device_handle).gdRect.bottom;
11577 dpyinfo->width = (**main_device_handle).gdRect.right;
11578 }
11579#endif
11580 dpyinfo->grabbed = 0;
11581 dpyinfo->root_window = NULL;
11582 dpyinfo->image_cache = make_image_cache ();
11583
11584 dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1;
11585 dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1;
11586 dpyinfo->mouse_face_face_id = DEFAULT_FACE_ID;
11587 dpyinfo->mouse_face_window = Qnil;
11588 dpyinfo->mouse_face_overlay = Qnil;
11589 dpyinfo->mouse_face_hidden = 0;
11590}
11591
11592 11605
11593static XrmDatabase 11606static XrmDatabase
11594mac_make_rdb (xrm_option) 11607mac_make_rdb (xrm_option)
@@ -11622,9 +11635,37 @@ mac_term_init (display_name, xrm_option, resource_name)
11622 if (x_display_list) 11635 if (x_display_list)
11623 error ("Sorry, this version can only handle one display"); 11636 error ("Sorry, this version can only handle one display");
11624 11637
11625 mac_initialize_display_info ();
11626
11627 dpyinfo = &one_mac_display_info; 11638 dpyinfo = &one_mac_display_info;
11639 bzero (dpyinfo, sizeof (*dpyinfo));
11640
11641#ifdef MAC_OSX
11642 dpyinfo->mac_id_name
11643 = (char *) xmalloc (SCHARS (Vinvocation_name)
11644 + SCHARS (Vsystem_name)
11645 + 2);
11646 sprintf (dpyinfo->mac_id_name, "%s@%s",
11647 SDATA (Vinvocation_name), SDATA (Vsystem_name));
11648#else
11649 dpyinfo->mac_id_name = (char *) xmalloc (strlen ("Mac Display") + 1);
11650 strcpy (dpyinfo->mac_id_name, "Mac Display");
11651#endif
11652
11653 dpyinfo->reference_count = 0;
11654 dpyinfo->resx = 72.0;
11655 dpyinfo->resy = 72.0;
11656
11657 mac_get_screen_info (dpyinfo);
11658
11659 dpyinfo->grabbed = 0;
11660 dpyinfo->root_window = NULL;
11661 dpyinfo->image_cache = make_image_cache ();
11662
11663 dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1;
11664 dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1;
11665 dpyinfo->mouse_face_face_id = DEFAULT_FACE_ID;
11666 dpyinfo->mouse_face_window = Qnil;
11667 dpyinfo->mouse_face_overlay = Qnil;
11668 dpyinfo->mouse_face_hidden = 0;
11628 11669
11629 dpyinfo->xrdb = mac_make_rdb (xrm_option); 11670 dpyinfo->xrdb = mac_make_rdb (xrm_option);
11630 11671
@@ -11642,6 +11683,7 @@ mac_term_init (display_name, xrm_option, resource_name)
11642 11683
11643 return dpyinfo; 11684 return dpyinfo;
11644} 11685}
11686
11645/* Get rid of display DPYINFO, assuming all frames are already gone. */ 11687/* Get rid of display DPYINFO, assuming all frames are already gone. */
11646 11688
11647void 11689void
@@ -11861,6 +11903,8 @@ mac_initialize ()
11861 11903
11862 init_apple_event_handler (); 11904 init_apple_event_handler ();
11863 11905
11906 init_dm_notification_handler ();
11907
11864 if (!inhibit_window_system) 11908 if (!inhibit_window_system)
11865 { 11909 {
11866 static const ProcessSerialNumber psn = {0, kCurrentProcess}; 11910 static const ProcessSerialNumber psn = {0, kCurrentProcess};