0x1B, 0x1B /* escape */
};
-
static Lisp_Object Qmodifier_value;
Lisp_Object Qalt, Qcontrol, Qhyper, Qmeta, Qsuper, Qnone;
extern Lisp_Object Qcursor_color, Qcursor_type, Qns, Qleft;
+static Lisp_Object QUTF8_STRING;
+
/* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold,
the maximum font size to NOT antialias. On GNUstep there is currently
no way to control this behavior. */
/* display update */
NSPoint last_mouse_motion_position;
static NSRect last_mouse_glyph;
-static unsigned long last_mouse_movement_time = 0;
+static Time last_mouse_movement_time = 0;
static Lisp_Object last_mouse_motion_frame;
static EmacsScroller *last_mouse_scroll_bar = nil;
static struct frame *ns_updating_frame;
static BOOL ns_fake_keydown = NO;
int ns_tmp_flags; /* FIXME */
struct nsfont_info *ns_tmp_font; /* FIXME */
+static BOOL ns_menu_bar_is_hidden = NO;
/*static int debug_lock = 0; */
/* event loop */
}
+//
+// Window constraining
+// -------------------
+//
+// To ensure that the windows are not placed under the menu bar, they
+// are typically moved by the call-back constrainFrameRect. However,
+// by overriding it, it's possible to inhibit this, leaving the window
+// in it's original position.
+//
+// It's possible to hide the menu bar. However, technically, it's only
+// possible to hide it when the application is active. To ensure that
+// this work properly, the menu bar and window constraining are
+// deferred until the application becomes active.
+//
+// Even though it's not possible to manually move a window above the
+// top of the screen, it is allowed if it's done programmatically,
+// when the menu is hidden. This allows the editable area to cover the
+// full screen height.
+//
+// Test cases
+// ----------
+//
+// Use the following extra files:
+//
+// init.el:
+// ;; Hide menu and place frame slightly above the top of the screen.
+// (setq ns-auto-hide-menu-bar t)
+// (set-frame-position (selected-frame) 0 -20)
+//
+// Test 1:
+//
+// emacs -Q -l init.el
+//
+// Result: No menu bar, and the title bar should be above the screen.
+//
+// Test 2:
+//
+// emacs -Q
+//
+// Result: Menu bar visible, frame placed immediately below the menu.
+//
+
+static void
+ns_constrain_all_frames (void)
+{
+ Lisp_Object tail, frame;
+
+ FOR_EACH_FRAME (tail, frame)
+ {
+ struct frame *f = XFRAME (frame);
+ if (FRAME_NS_P (f))
+ {
+ NSView *view = FRAME_NS_VIEW (f);
+ /* This no-op will trigger the default window placing
+ * constriant system. */
+ f->output_data.ns->dont_constrain = 0;
+ [[view window] setFrameOrigin:[[view window] frame].origin];
+ }
+ }
+}
+
+
+/* True, if the menu bar should be hidden. */
+
+static BOOL
+ns_menu_bar_should_be_hidden (void)
+{
+ return !NILP (ns_auto_hide_menu_bar)
+ && [NSApp respondsToSelector:@selector(setPresentationOptions:)];
+}
+
+
+/* Show or hide the menu bar, based on user setting. */
+
+static void
+ns_update_auto_hide_menu_bar (void)
+{
+#ifndef MAC_OS_X_VERSION_10_6
+#define MAC_OS_X_VERSION_10_6 1060
+#endif
+#ifdef NS_IMPL_COCOA
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
+ BLOCK_INPUT;
+
+ NSTRACE (ns_update_auto_hide_menu_bar);
+
+ if (NSApp != nil
+ && [NSApp isActive]
+ && [NSApp respondsToSelector:@selector(setPresentationOptions:)])
+ {
+ // Note, "setPresentationOptions" triggers an error unless the
+ // application is active.
+ BOOL menu_bar_should_be_hidden = ns_menu_bar_should_be_hidden ();
+
+ if (menu_bar_should_be_hidden != ns_menu_bar_is_hidden)
+ {
+ NSApplicationPresentationOptions options
+ = NSApplicationPresentationAutoHideDock;
+
+ if (menu_bar_should_be_hidden)
+ options |= NSApplicationPresentationAutoHideMenuBar;
+
+ [NSApp setPresentationOptions: options];
+
+ ns_menu_bar_is_hidden = menu_bar_should_be_hidden;
+
+ if (!ns_menu_bar_is_hidden)
+ {
+ ns_constrain_all_frames ();
+ }
+ }
+ }
+
+ UNBLOCK_INPUT;
+#endif
+#endif
+}
+
+
static void
ns_update_begin (struct frame *f)
/* --------------------------------------------------------------------------
NSView *view = FRAME_NS_VIEW (f);
NSTRACE (ns_update_begin);
+ ns_update_auto_hide_menu_bar ();
+
ns_updating_frame = f;
[view lockFocus];
static void
ns_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y,
- unsigned long *time)
+ Time *time)
/* --------------------------------------------------------------------------
External (hook): inform emacs about mouse position and hit parts.
If a scrollbar is being dragged, set bar_window, part, x, y, time.
void
ns_term_shutdown (int sig)
{
+ [[NSUserDefaults standardUserDefaults] synchronize];
+
/* code not reached in emacs.c after this is called by shut_down_emacs: */
if (STRINGP (Vauto_save_list_file_name))
unlink (SDATA (Vauto_save_list_file_name));
}
- (void)applicationDidBecomeActive: (NSNotification *)notification
{
+ NSTRACE (applicationDidBecomeActive);
+
//ns_app_active=YES;
+
+ ns_update_auto_hide_menu_bar ();
+ // No constrining takes place when the application is not active.
+ ns_constrain_all_frames ();
}
- (void)applicationDidResignActive: (NSNotification *)notification
{
unsigned fnKeysym = 0;
int flags;
static NSMutableArray *nsEvArray;
+#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
static BOOL firstTime = YES;
+#endif
int left_is_none;
NSTRACE (keyDown);
}
}
+
+#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
/* if we get here we should send the key for input manager processing */
if (firstTime && [[NSInputManager currentInputManager]
wantsToDelayTextChangeNotifications] == NO)
fprintf (stderr,
"Emacs: WARNING: TextInput mgr wants marked text to be permanent!\n");
firstTime = NO;
-
+#endif
if (NS_KEYLOG && !processingCompose)
fprintf (stderr, "keyDown: Begin compose sequence.\n");
[self allocateGState];
+ [NSApp registerServicesMenuSendTypes: ns_send_types
+ returnTypes: nil];
+
ns_window_num++;
return self;
}
}
-- validRequestorForSendType: (NSString *)typeSent
- returnType: (NSString *)typeReturned
+- (id) validRequestorForSendType: (NSString *)typeSent
+ returnType: (NSString *)typeReturned
{
NSTRACE (validRequestorForSendType);
- if ([ns_send_types indexOfObjectIdenticalTo: typeSent] != NSNotFound &&
- [ns_return_types indexOfObjectIdenticalTo: typeSent] != NSNotFound)
- return self;
+ if (typeSent != nil && [ns_send_types indexOfObject: typeSent] != NSNotFound
+ && typeReturned == nil)
+ {
+ if (! NILP (ns_get_local_selection (QPRIMARY, QUTF8_STRING)))
+ return self;
+ }
return [super validRequestorForSendType: typeSent
returnType: typeReturned];
- (BOOL) writeSelectionToPasteboard: (NSPasteboard *)pb types: (NSArray *)types
{
- /* supposed to write for as many of types as we are able */
- return NO;
+ NSArray *typesDeclared;
+ Lisp_Object val;
+
+ /* We only support NSStringPboardType */
+ if ([types containsObject:NSStringPboardType] == NO) {
+ return NO;
+ }
+
+ val = ns_get_local_selection (QPRIMARY, QUTF8_STRING);
+ if (CONSP (val) && SYMBOLP (XCAR (val)))
+ {
+ val = XCDR (val);
+ if (CONSP (val) && NILP (XCDR (val)))
+ val = XCAR (val);
+ }
+ if (! STRINGP (val))
+ return NO;
+
+ typesDeclared = [NSArray arrayWithObject:NSStringPboardType];
+ [pb declareTypes:typesDeclared owner:nil];
+ ns_string_to_pasteboard (pb, val);
+ return YES;
}
/* When making the frame visible for the first time, we want to
constrain. Other times not. */
struct frame *f = ((EmacsView *)[self delegate])->emacsframe;
- if (f->output_data.ns->dont_constrain)
+ NSTRACE (constrainFrameRect);
+
+ if (f->output_data.ns->dont_constrain
+ || ns_menu_bar_should_be_hidden ())
return frameRect;
f->output_data.ns->dont_constrain = 1;
em_whole = whole;
if (portion >= whole)
- [self setFloatValue: 0.0 knobProportion: 1.0];
+ {
+#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
+ [self setKnobProportion: 1.0];
+ [self setDoubleValue: 1.0];
+#else
+ [self setFloatValue: 0.0 knobProportion: 1.0];
+#endif
+ }
else
{
float pos, por;
portion = max ((float)whole*min_portion/pixel_height, portion);
pos = (float)position / (whole - portion);
por = (float)portion/whole;
+#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
+ [self setKnobProportion: por];
+ [self setDoubleValue: pos];
+#else
[self setFloatValue: pos knobProportion: por];
+#endif
}
return self;
}
DEFSYM (Qsuper, "super");
DEFSYM (Qcontrol, "control");
DEFSYM (Qnone, "none");
+ DEFSYM (QUTF8_STRING, "UTF8_STRING");
+
Fput (Qalt, Qmodifier_value, make_number (alt_modifier));
Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier));
Fput (Qmeta, Qmodifier_value, make_number (meta_modifier));
staticpro (&last_mouse_motion_frame);
last_mouse_motion_frame = Qnil;
+ DEFVAR_LISP ("ns-auto-hide-menu-bar", ns_auto_hide_menu_bar,
+ doc: /* Non-nil means that the menu bar is hidden, but appears when the mouse is near.
+Only works on OSX 10.6 or later. */);
+ ns_auto_hide_menu_bar = Qnil;
+
/* TODO: move to common code */
DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
doc: /* If not nil, Emacs uses toolkit scroll bars. */);
/* Tell emacs about this window system. */
Fprovide (intern ("ns"), Qnil);
}
-
-