aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2021-10-23 19:51:31 +0800
committerAlan Third2021-11-06 12:59:18 +0000
commit75a264ed023fd407c279eabf4089bb0aa61bec8d (patch)
treea89fe5de1da61cbb5393ad4a52db17467cbb1ef3 /src
parent07715630ad9df9cb681cbadecbaf73fc9c698061 (diff)
downloademacs-75a264ed023fd407c279eabf4089bb0aa61bec8d.tar.gz
emacs-75a264ed023fd407c279eabf4089bb0aa61bec8d.zip
General improvements to NS port
* src/dispextern.h: Remove some !HAVE_NS conditionals around grab related code. * src/frame.c (gui_mouse_grabbed, gui_redo_mouse_highlight): Remove !HAVE_NS conditionals around code. * src/nsmenu.m (ns_update_menubar): Prevent recursive calls and enable shallow updates on GNUstep. (menuNeedsUpdate): Prevent recursive calls. (ns_menu_show): Fix mysterious GC-related bug. (update_frame_tool_bar_1): Work around mysterious toolbar sizing bug on GNUstep. * src/nsterm.h (struct ns_output): New field for tracking toolbar visibility changes. * src/nsterm.m (frame_set_mouse_pixel_position): Implement for GNUstep. (ns_redraw_scroll_bars): Enable for GNUstep. (ns_clear_frame): Redraw scrollbars on GNUstep. (ns_update_window_end): New function. (ns_redisplay_interface): Add ns_update_window_end on GNUstep. (- keyDown): Remove debug code that doesn't work on GNUstep. (- mouseDown): Enable grab tracking on NS port. (- resizeWithOldSuperviewSize): Fix build with NSTRACE. * src/xdisp.c (note_tab_bar_highlight): Enable some code for NS port.
Diffstat (limited to 'src')
-rw-r--r--src/dispextern.h2
-rw-r--r--src/frame.c4
-rw-r--r--src/nsmenu.m76
-rw-r--r--src/nsterm.h6
-rw-r--r--src/nsterm.m42
-rw-r--r--src/xdisp.c2
6 files changed, 102 insertions, 30 deletions
diff --git a/src/dispextern.h b/src/dispextern.h
index e03e21fddcf..5b28fe76664 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3722,10 +3722,8 @@ extern Lisp_Object gui_default_parameter (struct frame *, Lisp_Object,
3722 const char *, const char *, 3722 const char *, const char *,
3723 enum resource_types); 3723 enum resource_types);
3724 3724
3725#ifndef HAVE_NS /* These both used on W32 and X only. */
3726extern bool gui_mouse_grabbed (Display_Info *); 3725extern bool gui_mouse_grabbed (Display_Info *);
3727extern void gui_redo_mouse_highlight (Display_Info *); 3726extern void gui_redo_mouse_highlight (Display_Info *);
3728#endif /* HAVE_NS */
3729 3727
3730#endif /* HAVE_WINDOW_SYSTEM */ 3728#endif /* HAVE_WINDOW_SYSTEM */
3731 3729
diff --git a/src/frame.c b/src/frame.c
index 2b1cb452efd..79a7c89e0dd 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -5028,8 +5028,6 @@ gui_set_no_special_glyphs (struct frame *f, Lisp_Object new_value, Lisp_Object o
5028} 5028}
5029 5029
5030 5030
5031#ifndef HAVE_NS
5032
5033/* Non-zero if mouse is grabbed on DPYINFO 5031/* Non-zero if mouse is grabbed on DPYINFO
5034 and we know the frame where it is. */ 5032 and we know the frame where it is. */
5035 5033
@@ -5054,8 +5052,6 @@ gui_redo_mouse_highlight (Display_Info *dpyinfo)
5054 dpyinfo->last_mouse_motion_y); 5052 dpyinfo->last_mouse_motion_y);
5055} 5053}
5056 5054
5057#endif /* HAVE_NS */
5058
5059/* Subroutines of creating an X frame. */ 5055/* Subroutines of creating an X frame. */
5060 5056
5061/* Make sure that Vx_resource_name is set to a reasonable value. 5057/* Make sure that Vx_resource_name is set to a reasonable value.
diff --git a/src/nsmenu.m b/src/nsmenu.m
index 9b78643d56a..29201e69079 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -101,6 +101,15 @@ popup_activated (void)
101static void 101static void
102ns_update_menubar (struct frame *f, bool deep_p) 102ns_update_menubar (struct frame *f, bool deep_p)
103{ 103{
104#ifdef NS_IMPL_GNUSTEP
105 static int inside = 0;
106
107 if (inside)
108 return;
109
110 inside++;
111#endif
112
104 BOOL needsSet = NO; 113 BOOL needsSet = NO;
105 id menu = [NSApp mainMenu]; 114 id menu = [NSApp mainMenu];
106 bool owfi; 115 bool owfi;
@@ -120,7 +129,12 @@ ns_update_menubar (struct frame *f, bool deep_p)
120 NSTRACE ("ns_update_menubar"); 129 NSTRACE ("ns_update_menubar");
121 130
122 if (f != SELECTED_FRAME () || FRAME_EXTERNAL_MENU_BAR (f) == 0) 131 if (f != SELECTED_FRAME () || FRAME_EXTERNAL_MENU_BAR (f) == 0)
132 {
133#ifdef NS_IMPL_GNUSTEP
134 inside--;
135#endif
123 return; 136 return;
137 }
124 XSETFRAME (Vmenu_updating_frame, f); 138 XSETFRAME (Vmenu_updating_frame, f);
125/*fprintf (stderr, "ns_update_menubar: frame: %p\tdeep: %d\tsub: %p\n", f, deep_p, submenu); */ 139/*fprintf (stderr, "ns_update_menubar: frame: %p\tdeep: %d\tsub: %p\n", f, deep_p, submenu); */
126 140
@@ -144,10 +158,6 @@ ns_update_menubar (struct frame *f, bool deep_p)
144 t = -(1000*tb.time+tb.millitm); 158 t = -(1000*tb.time+tb.millitm);
145#endif 159#endif
146 160
147#ifdef NS_IMPL_GNUSTEP
148 deep_p = 1; /* See comment in menuNeedsUpdate. */
149#endif
150
151 if (deep_p) 161 if (deep_p)
152 { 162 {
153 /* Make a widget-value tree representing the entire menu trees. */ 163 /* Make a widget-value tree representing the entire menu trees. */
@@ -275,6 +285,9 @@ ns_update_menubar (struct frame *f, bool deep_p)
275 free_menubar_widget_value_tree (first_wv); 285 free_menubar_widget_value_tree (first_wv);
276 discard_menu_items (); 286 discard_menu_items ();
277 unbind_to (specpdl_count, Qnil); 287 unbind_to (specpdl_count, Qnil);
288#ifdef NS_IMPL_GNUSTEP
289 inside--;
290#endif
278 return; 291 return;
279 } 292 }
280 293
@@ -408,6 +421,10 @@ ns_update_menubar (struct frame *f, bool deep_p)
408 if (needsSet) 421 if (needsSet)
409 [NSApp setMainMenu: menu]; 422 [NSApp setMainMenu: menu];
410 423
424#ifdef NS_IMPL_GNUSTEP
425 inside--;
426#endif
427
411 unblock_input (); 428 unblock_input ();
412 429
413} 430}
@@ -452,17 +469,34 @@ set_frame_menubar (struct frame *f, bool deep_p)
452 call to ns_update_menubar. */ 469 call to ns_update_menubar. */
453- (void)menuNeedsUpdate: (NSMenu *)menu 470- (void)menuNeedsUpdate: (NSMenu *)menu
454{ 471{
472#ifdef NS_IMPL_GNUSTEP
473 static int inside = 0;
474#endif
475
455 if (!FRAME_LIVE_P (SELECTED_FRAME ())) 476 if (!FRAME_LIVE_P (SELECTED_FRAME ()))
456 return; 477 return;
457 478
458#ifdef NS_IMPL_COCOA 479#ifdef NS_IMPL_GNUSTEP
459/* TODO: GNUstep calls this method when the menu is still being built 480 /* GNUstep calls this method when the menu is still being built
460 which results in a recursive stack overflow. One possible solution 481 which results in a recursive stack overflow, which this variable
461 is to use menuWillOpen instead, but the Apple docs explicitly warn 482 prevents. */
462 against changing the contents of the menu in it. I don't know what 483
463 the right thing to do for GNUstep is. */ 484 if (!inside)
485 ++inside;
486 else
487 return;
488#endif
489
464 if (needsUpdate) 490 if (needsUpdate)
465 ns_update_menubar (SELECTED_FRAME (), true); 491 {
492#ifdef NS_IMPL_GNUSTEP
493 needsUpdate = NO;
494#endif
495 ns_update_menubar (SELECTED_FRAME (), true);
496 }
497
498#ifdef NS_IMPL_GNUSTEP
499 --inside;
466#endif 500#endif
467} 501}
468 502
@@ -789,6 +823,9 @@ ns_menu_show (struct frame *f, int x, int y, int menuflags,
789 823
790 p.x = x; p.y = y; 824 p.x = x; p.y = y;
791 825
826 /* Don't GC due to a mysterious bug. */
827 inhibit_garbage_collection ();
828
792 /* now parse stage 2 as in ns_update_menubar */ 829 /* now parse stage 2 as in ns_update_menubar */
793 wv = make_widget_value ("contextmenu", NULL, true, Qnil); 830 wv = make_widget_value ("contextmenu", NULL, true, Qnil);
794 wv->button_type = BUTTON_TYPE_NONE; 831 wv->button_type = BUTTON_TYPE_NONE;
@@ -960,15 +997,17 @@ ns_menu_show (struct frame *f, int x, int y, int menuflags,
960 997
961 pmenu = [[EmacsMenu alloc] initWithTitle: 998 pmenu = [[EmacsMenu alloc] initWithTitle:
962 NILP (title) ? @"" : [NSString stringWithLispString: title]]; 999 NILP (title) ? @"" : [NSString stringWithLispString: title]];
1000 /* On GNUstep, this call makes menu_items nil for whatever reason
1001 when displaying a context menu from `context-menu-mode'. */
1002 Lisp_Object items = menu_items;
963 [pmenu fillWithWidgetValue: first_wv->contents]; 1003 [pmenu fillWithWidgetValue: first_wv->contents];
1004 menu_items = items;
964 free_menubar_widget_value_tree (first_wv); 1005 free_menubar_widget_value_tree (first_wv);
965 unbind_to (specpdl_count, Qnil);
966
967 popup_activated_flag = 1; 1006 popup_activated_flag = 1;
968 tem = [pmenu runMenuAt: p forFrame: f keymaps: keymaps]; 1007 tem = [pmenu runMenuAt: p forFrame: f keymaps: keymaps];
969 popup_activated_flag = 0; 1008 popup_activated_flag = 0;
970 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow]; 1009 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
971 1010 unbind_to (specpdl_count, Qnil);
972 unblock_input (); 1011 unblock_input ();
973 return tem; 1012 return tem;
974} 1013}
@@ -1019,6 +1058,15 @@ update_frame_tool_bar_1 (struct frame *f, EmacsToolbar *toolbar)
1019 [toolbar clearActive]; 1058 [toolbar clearActive];
1020#else 1059#else
1021 [toolbar clearAll]; 1060 [toolbar clearAll];
1061 /* It takes at least 3 such adjustments to fix an issue where the
1062 tool bar is 2x too tall when a frame's tool bar is first shown.
1063 This is ugly, but I have no other solution for this problem. */
1064 if (FRAME_OUTPUT_DATA (f)->tool_bar_adjusted < 3)
1065 {
1066 [toolbar setVisible: NO];
1067 FRAME_OUTPUT_DATA (f)->tool_bar_adjusted++;
1068 [toolbar setVisible: YES];
1069 }
1022#endif 1070#endif
1023 1071
1024 /* Update EmacsToolbar as in GtkUtils, build items list. */ 1072 /* Update EmacsToolbar as in GtkUtils, build items list. */
diff --git a/src/nsterm.h b/src/nsterm.h
index 944dbd727cf..8175f996644 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -978,6 +978,12 @@ struct ns_output
978 978
979 /* Non-zero if we are doing an animation, e.g. toggling the tool bar. */ 979 /* Non-zero if we are doing an animation, e.g. toggling the tool bar. */
980 int in_animation; 980 int in_animation;
981
982#ifdef NS_IMPL_GNUSTEP
983 /* Zero if this is the first time a toolbar has been updated on this
984 frame. */
985 int tool_bar_adjusted;
986#endif
981}; 987};
982 988
983/* This dummy declaration needed to support TTYs. */ 989/* This dummy declaration needed to support TTYs. */
diff --git a/src/nsterm.m b/src/nsterm.m
index a00a58f7901..9409697b135 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -65,6 +65,7 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
65 65
66#ifdef NS_IMPL_GNUSTEP 66#ifdef NS_IMPL_GNUSTEP
67#include "process.h" 67#include "process.h"
68#import <GNUstepGUI/GSDisplayServer.h>
68#endif 69#endif
69 70
70#ifdef NS_IMPL_COCOA 71#ifdef NS_IMPL_COCOA
@@ -2256,13 +2257,19 @@ frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
2256{ 2257{
2257 NSTRACE ("frame_set_mouse_pixel_position"); 2258 NSTRACE ("frame_set_mouse_pixel_position");
2258 2259
2259 /* FIXME: what about GNUstep? */
2260#ifdef NS_IMPL_COCOA 2260#ifdef NS_IMPL_COCOA
2261 CGPoint mouse_pos = 2261 CGPoint mouse_pos =
2262 CGPointMake(f->left_pos + pix_x, 2262 CGPointMake(f->left_pos + pix_x,
2263 f->top_pos + pix_y + 2263 f->top_pos + pix_y +
2264 FRAME_NS_TITLEBAR_HEIGHT(f) + FRAME_TOOLBAR_HEIGHT(f)); 2264 FRAME_NS_TITLEBAR_HEIGHT(f) + FRAME_TOOLBAR_HEIGHT(f));
2265 CGWarpMouseCursorPosition (mouse_pos); 2265 CGWarpMouseCursorPosition (mouse_pos);
2266#else
2267 GSDisplayServer *server = GSServerForWindow ([FRAME_NS_VIEW (f) window]);
2268 [server setMouseLocation: NSMakePoint (f->left_pos + pix_x,
2269 f->top_pos + pix_y
2270 + FRAME_NS_TITLEBAR_HEIGHT(f)
2271 + FRAME_TOOLBAR_HEIGHT(f))
2272 onScreen: [[[FRAME_NS_VIEW (f) window] screen] screenNumber]];
2266#endif 2273#endif
2267} 2274}
2268 2275
@@ -2575,8 +2582,7 @@ ns_get_shifted_character (NSEvent *event)
2575 ========================================================================== */ 2582 ========================================================================== */
2576 2583
2577 2584
2578#if 0 2585#ifdef NS_IMPL_GNUSTEP
2579/* FIXME: Remove this function. */
2580static void 2586static void
2581ns_redraw_scroll_bars (struct frame *f) 2587ns_redraw_scroll_bars (struct frame *f)
2582{ 2588{
@@ -2621,10 +2627,9 @@ ns_clear_frame (struct frame *f)
2621 NSRectFill (r); 2627 NSRectFill (r);
2622 ns_unfocus (f); 2628 ns_unfocus (f);
2623 2629
2624 /* as of 2006/11 or so this is now needed */ 2630#ifdef NS_IMPL_GNUSTEP
2625 /* FIXME: I don't see any reason for this and removing it makes no 2631 ns_redraw_scroll_bars (f);
2626 difference here. Do we need it for GNUstep? */ 2632#endif
2627 //ns_redraw_scroll_bars (f);
2628 unblock_input (); 2633 unblock_input ();
2629} 2634}
2630 2635
@@ -4922,6 +4927,17 @@ ns_default_font_parameter (struct frame *f, Lisp_Object parms)
4922{ 4927{
4923} 4928}
4924 4929
4930#ifdef NS_IMPL_GNUSTEP
4931static void
4932ns_update_window_end (struct window *w, bool cursor_on_p,
4933 bool mouse_face_overwritten_p)
4934{
4935 NSTRACE ("ns_update_window_end (cursor_on_p = %d)", cursor_on_p);
4936
4937 ns_redraw_scroll_bars (WINDOW_XFRAME (w));
4938}
4939#endif
4940
4925/* This and next define (many of the) public functions in this file. */ 4941/* This and next define (many of the) public functions in this file. */
4926/* gui_* are generic versions in xdisp.c that we, and other terms, get away 4942/* gui_* are generic versions in xdisp.c that we, and other terms, get away
4927 with using despite presence in the "system dependent" redisplay 4943 with using despite presence in the "system dependent" redisplay
@@ -4938,7 +4954,11 @@ static struct redisplay_interface ns_redisplay_interface =
4938 ns_scroll_run, 4954 ns_scroll_run,
4939 ns_after_update_window_line, 4955 ns_after_update_window_line,
4940 NULL, /* update_window_begin */ 4956 NULL, /* update_window_begin */
4957#ifndef NS_IMPL_GNUSTEP
4941 NULL, /* update_window_end */ 4958 NULL, /* update_window_end */
4959#else
4960 ns_update_window_end,
4961#endif
4942 0, /* flush_display */ 4962 0, /* flush_display */
4943 gui_clear_window_mouse_face, 4963 gui_clear_window_mouse_face,
4944 gui_get_glyph_overhangs, 4964 gui_get_glyph_overhangs,
@@ -6165,9 +6185,11 @@ not_in_argv (NSString *arg)
6165 Lisp_Object kind = fnKeysym ? QCfunction : QCordinary; 6185 Lisp_Object kind = fnKeysym ? QCfunction : QCordinary;
6166 emacs_event->modifiers = EV_MODIFIERS2 (flags, kind); 6186 emacs_event->modifiers = EV_MODIFIERS2 (flags, kind);
6167 6187
6188#ifndef NS_IMPL_GNUSTEP
6168 if (NS_KEYLOG) 6189 if (NS_KEYLOG)
6169 fprintf (stderr, "keyDown: code =%x\tfnKey =%x\tflags = %x\tmods = %x\n", 6190 fprintf (stderr, "keyDown: code =%x\tfnKey =%x\tflags = %x\tmods = %x\n",
6170 code, fnKeysym, flags, emacs_event->modifiers); 6191 code, fnKeysym, flags, emacs_event->modifiers);
6192#endif
6171 6193
6172 /* If it was a function key or had control-like modifiers, pass 6194 /* If it was a function key or had control-like modifiers, pass
6173 it directly to Emacs. */ 6195 it directly to Emacs. */
@@ -6680,6 +6702,11 @@ not_in_argv (NSString *arg)
6680 emacs_event->code = EV_BUTTON (theEvent); 6702 emacs_event->code = EV_BUTTON (theEvent);
6681 emacs_event->modifiers = EV_MODIFIERS (theEvent) 6703 emacs_event->modifiers = EV_MODIFIERS (theEvent)
6682 | EV_UDMODIFIERS (theEvent); 6704 | EV_UDMODIFIERS (theEvent);
6705
6706 if (emacs_event->modifiers & down_modifier)
6707 FRAME_DISPLAY_INFO (emacsframe)->grabbed |= 1 << EV_BUTTON (theEvent);
6708 else
6709 FRAME_DISPLAY_INFO (emacsframe)->grabbed &= ~(1 << EV_BUTTON (theEvent));
6683 } 6710 }
6684 6711
6685 XSETINT (emacs_event->x, lrint (p.x)); 6712 XSETINT (emacs_event->x, lrint (p.x));
@@ -6980,7 +7007,6 @@ not_in_argv (NSString *arg)
6980 height = (int)NSHeight (frame); 7007 height = (int)NSHeight (frame);
6981 7008
6982 NSTRACE_SIZE ("New size", NSMakeSize (width, height)); 7009 NSTRACE_SIZE ("New size", NSMakeSize (width, height));
6983 NSTRACE_SIZE ("Original size", size);
6984 7010
6985 /* Reset the frame size to match the bounds of the superview (the 7011 /* Reset the frame size to match the bounds of the superview (the
6986 NSWindow's contentView). We need to do this as sometimes the 7012 NSWindow's contentView). We need to do this as sometimes the
diff --git a/src/xdisp.c b/src/xdisp.c
index 9814efd63c5..86c4e704d52 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -13894,7 +13894,6 @@ note_tab_bar_highlight (struct frame *f, int x, int y)
13894 clear_mouse_face (hlinfo); 13894 clear_mouse_face (hlinfo);
13895 13895
13896 bool mouse_down_p = false; 13896 bool mouse_down_p = false;
13897#ifndef HAVE_NS
13898 /* Mouse is down, but on different tab-bar item? Or alternatively, 13897 /* Mouse is down, but on different tab-bar item? Or alternatively,
13899 the mouse might've been pressed somewhere we don't know about, 13898 the mouse might've been pressed somewhere we don't know about,
13900 and then have moved onto the tab bar. In this case, 13899 and then have moved onto the tab bar. In this case,
@@ -13907,7 +13906,6 @@ note_tab_bar_highlight (struct frame *f, int x, int y)
13907 if (mouse_down_p && f->last_tab_bar_item != prop_idx 13906 if (mouse_down_p && f->last_tab_bar_item != prop_idx
13908 && f->last_tab_bar_item != -1) 13907 && f->last_tab_bar_item != -1)
13909 return; 13908 return;
13910#endif
13911 draw = mouse_down_p ? DRAW_IMAGE_SUNKEN : DRAW_IMAGE_RAISED; 13909 draw = mouse_down_p ? DRAW_IMAGE_SUNKEN : DRAW_IMAGE_RAISED;
13912 13910
13913 /* If tab-bar item is not enabled, don't highlight it. */ 13911 /* If tab-bar item is not enabled, don't highlight it. */