aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Djärv2011-03-27 12:36:44 +0200
committerJan Djärv2011-03-27 12:36:44 +0200
commitf0a1382af3afa31708d3ce2f4c28bce61565aada (patch)
tree3496ce73efe0ae5a747377d5154265f10b64bed9
parent5c380ffb17f2fb6f22d9f24a7732b7e4a1e0cd52 (diff)
downloademacs-f0a1382af3afa31708d3ce2f4c28bce61565aada.tar.gz
emacs-f0a1382af3afa31708d3ce2f4c28bce61565aada.zip
Introduce ns-auto-hide-menu-bar to hide menubar for Emacs frames.
Code by Anders Lindgren. * nsterm.m (ns_menu_bar_is_hidden): New variable. (ns_constrain_all_frames, ns_menu_bar_should_be_hidden) (ns_update_auto_hide_menu_bar): New functions. (ns_update_begin): Call ns_update_auto_hide_menu_bar. (applicationDidBecomeActive): Call ns_update_auto_hide_menu_bar and ns_constrain_all_frames. (constrainFrameRect): Return at once if ns_menu_bar_should_be_hidden. (syms_of_nsterm): DEFVAR ns-auto-hide-menu-bar, init to Qnil.
-rw-r--r--src/ChangeLog11
-rw-r--r--src/nsterm.m130
2 files changed, 140 insertions, 1 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index eb03806b33a..96f60877fce 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
12011-03-27 Anders Lindgren <andlind@gmail.com>
2
3 * nsterm.m (ns_menu_bar_is_hidden): New variable.
4 (ns_constrain_all_frames, ns_menu_bar_should_be_hidden)
5 (ns_update_auto_hide_menu_bar): New functions.
6 (ns_update_begin): Call ns_update_auto_hide_menu_bar.
7 (applicationDidBecomeActive): Call ns_update_auto_hide_menu_bar and
8 ns_constrain_all_frames.
9 (constrainFrameRect): Return at once if ns_menu_bar_should_be_hidden.
10 (syms_of_nsterm): DEFVAR ns-auto-hide-menu-bar, init to Qnil.
11
12011-03-27 Jan Djärv <jan.h.d@swipnet.se> 122011-03-27 Jan Djärv <jan.h.d@swipnet.se>
2 13
3 * nsmenu.m (runDialogAt): Remove argument to timer_check. 14 * nsmenu.m (runDialogAt): Remove argument to timer_check.
diff --git a/src/nsterm.m b/src/nsterm.m
index c7cd411c614..ebfa875ae0e 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -170,6 +170,7 @@ BOOL ns_in_resize = NO;
170static BOOL ns_fake_keydown = NO; 170static BOOL ns_fake_keydown = NO;
171int ns_tmp_flags; /* FIXME */ 171int ns_tmp_flags; /* FIXME */
172struct nsfont_info *ns_tmp_font; /* FIXME */ 172struct nsfont_info *ns_tmp_font; /* FIXME */
173static BOOL ns_menu_bar_is_hidden = NO;
173/*static int debug_lock = 0; */ 174/*static int debug_lock = 0; */
174 175
175/* event loop */ 176/* event loop */
@@ -505,6 +506,118 @@ ns_resize_handle_rect (NSWindow *window)
505} 506}
506 507
507 508
509//
510// Window constraining
511// -------------------
512//
513// To ensure that the windows are not placed under the menu bar, they
514// are typically moved by the call-back constrainFrameRect. However,
515// by overriding it, it's possible to inhibit this, leaving the window
516// in it's original position.
517//
518// It's possible to hide the menu bar. However, technically, it's only
519// possible to hide it when the application is active. To ensure that
520// this work properly, the menu bar and window constraining are
521// deferred until the application becomes active.
522//
523// Even though it's not possible to manually move a window above the
524// top of the screen, it is allowed if it's done programmatically,
525// when the menu is hidden. This allows the editable area to cover the
526// full screen height.
527//
528// Test cases
529// ----------
530//
531// Use the following extra files:
532//
533// init.el:
534// ;; Hide menu and place frame slightly above the top of the screen.
535// (setq ns-auto-hide-menu-bar t)
536// (set-frame-position (selected-frame) 0 -20)
537//
538// Test 1:
539//
540// emacs -Q -l init.el
541//
542// Result: No menu bar, and the title bar should be above the screen.
543//
544// Test 2:
545//
546// emacs -Q
547//
548// Result: Menu bar visible, frame placed immediately below the menu.
549//
550
551static void
552ns_constrain_all_frames (void)
553{
554 Lisp_Object tail, frame;
555
556 FOR_EACH_FRAME (tail, frame)
557 {
558 struct frame *f = XFRAME (frame);
559 if (FRAME_NS_P (f))
560 {
561 NSView *view = FRAME_NS_VIEW (f);
562 /* This no-op will trigger the default window placing
563 * constriant system. */
564 f->output_data.ns->dont_constrain = 0;
565 [[view window] setFrameOrigin:[[view window] frame].origin];
566 }
567 }
568}
569
570
571/* True, if the menu bar should be hidden. */
572
573static BOOL
574ns_menu_bar_should_be_hidden (void)
575{
576 return !NILP (ns_auto_hide_menu_bar)
577 && [NSApp respondsToSelector:@selector(setPresentationOptions:)];
578}
579
580
581/* Show or hide the menu bar, based on user setting. */
582
583static void
584ns_update_auto_hide_menu_bar (void)
585{
586 BLOCK_INPUT;
587
588 NSTRACE (ns_update_auto_hide_menu_bar);
589
590 if (NSApp != nil
591 && [NSApp isActive]
592 && [NSApp respondsToSelector:@selector(setPresentationOptions:)])
593 {
594 // Note, "setPresentationOptions" triggers an error unless the
595 // application is active.
596 BOOL menu_bar_should_be_hidden = ns_menu_bar_should_be_hidden ();
597
598 if (menu_bar_should_be_hidden != ns_menu_bar_is_hidden)
599 {
600 NSApplicationPresentationOptions options
601 = NSApplicationPresentationAutoHideDock;
602
603 if (menu_bar_should_be_hidden)
604 options |= NSApplicationPresentationAutoHideMenuBar;
605
606 [NSApp setPresentationOptions: options];
607
608 ns_menu_bar_is_hidden = menu_bar_should_be_hidden;
609
610 if (!ns_menu_bar_is_hidden)
611 {
612 ns_constrain_all_frames ();
613 }
614 }
615 }
616
617 UNBLOCK_INPUT;
618}
619
620
508static void 621static void
509ns_update_begin (struct frame *f) 622ns_update_begin (struct frame *f)
510/* -------------------------------------------------------------------------- 623/* --------------------------------------------------------------------------
@@ -515,6 +628,8 @@ ns_update_begin (struct frame *f)
515 NSView *view = FRAME_NS_VIEW (f); 628 NSView *view = FRAME_NS_VIEW (f);
516 NSTRACE (ns_update_begin); 629 NSTRACE (ns_update_begin);
517 630
631 ns_update_auto_hide_menu_bar ();
632
518 ns_updating_frame = f; 633 ns_updating_frame = f;
519 [view lockFocus]; 634 [view lockFocus];
520 635
@@ -4205,7 +4320,13 @@ ns_term_shutdown (int sig)
4205} 4320}
4206- (void)applicationDidBecomeActive: (NSNotification *)notification 4321- (void)applicationDidBecomeActive: (NSNotification *)notification
4207{ 4322{
4323 NSTRACE (applicationDidBecomeActive);
4324
4208 //ns_app_active=YES; 4325 //ns_app_active=YES;
4326
4327 ns_update_auto_hide_menu_bar ();
4328 // No constrining takes place when the application is not active.
4329 ns_constrain_all_frames ();
4209} 4330}
4210- (void)applicationDidResignActive: (NSNotification *)notification 4331- (void)applicationDidResignActive: (NSNotification *)notification
4211{ 4332{
@@ -5689,7 +5810,10 @@ ns_term_shutdown (int sig)
5689 /* When making the frame visible for the first time, we want to 5810 /* When making the frame visible for the first time, we want to
5690 constrain. Other times not. */ 5811 constrain. Other times not. */
5691 struct frame *f = ((EmacsView *)[self delegate])->emacsframe; 5812 struct frame *f = ((EmacsView *)[self delegate])->emacsframe;
5692 if (f->output_data.ns->dont_constrain) 5813 NSTRACE (constrainFrameRect);
5814
5815 if (f->output_data.ns->dont_constrain
5816 || ns_menu_bar_should_be_hidden ())
5693 return frameRect; 5817 return frameRect;
5694 5818
5695 f->output_data.ns->dont_constrain = 1; 5819 f->output_data.ns->dont_constrain = 1;
@@ -6361,6 +6485,10 @@ allowing it to be used at a lower level for accented character entry.");
6361 staticpro (&last_mouse_motion_frame); 6485 staticpro (&last_mouse_motion_frame);
6362 last_mouse_motion_frame = Qnil; 6486 last_mouse_motion_frame = Qnil;
6363 6487
6488 DEFVAR_LISP ("ns-auto-hide-menu-bar", ns_auto_hide_menu_bar,
6489 "Non-nil means that the menu bar is hidden, but appears when the mouse is near. Only works on OSX 10.6 or later.");
6490 ns_auto_hide_menu_bar = Qnil;
6491
6364 /* TODO: move to common code */ 6492 /* TODO: move to common code */
6365 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars, 6493 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
6366 doc: /* If not nil, Emacs uses toolkit scroll bars. */); 6494 doc: /* If not nil, Emacs uses toolkit scroll bars. */);