From dd4497dc1725ae27810b6bf368731eed110ccbc8 Mon Sep 17 00:00:00 2001 From: Steven Tamm Date: Sun, 15 Feb 2004 17:16:18 +0000 Subject: [PATCH] (Vmac_emulate_three_button_mouse): New variable for controlling emulation of a three button mouse with option and command keys. (Qreverse, mac_get_enumlated_btn): Handle the emulation (mac_event_to_emacs_modifiers, XTread_socket): Ditto --- src/ChangeLog | 8 ++++++++ src/macterm.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 727dc366bec..44d64dbb964 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2004-02-15 Steven Tamm + + * macterm.c (Vmac_emulate_three_button_mouse): New variable for + controlling emulation of a three button mouse with option and + command keys. + (Qreverse, mac_get_enumlated_btn): Handle the emulation + (mac_event_to_emacs_modifiers, XTread_socket): Ditto + 2004-02-15 Kim F. Storm * fringe.c (init_fringe_bitmap) [MAC_OS, WORDS_BIG_ENDIAN]: diff --git a/src/macterm.c b/src/macterm.c index 3c1b33fa6dd..f6e5414c299 100644 --- a/src/macterm.c +++ b/src/macterm.c @@ -6463,12 +6463,19 @@ static long app_sleep_time = WNE_SLEEP_AT_RESUME; Boolean terminate_flag = false; +/* Contains the string "reverse", which is a constant for mouse button emu.*/ +Lisp_Object Qreverse; + /* True if using command key as meta key. */ Lisp_Object Vmac_command_key_is_meta; /* True if the ctrl and meta keys should be reversed. */ Lisp_Object Vmac_reverse_ctrl_meta; +/* True if the option and command modifiers should be used to emulate + a three button mouse */ +Lisp_Object Vmac_emulate_three_button_mouse; + #if USE_CARBON_EVENTS /* True if the mouse wheel button (i.e. button 4) should map to mouse-2, instead of mouse-3. */ @@ -6541,6 +6548,20 @@ mac_to_emacs_modifiers (EventModifiers mods) return result; } +static int +mac_get_emulated_btn ( UInt32 modifiers ) +{ + int result = 0; + if (Vmac_emulate_three_button_mouse != Qnil) { + int cmdIs3 = (Vmac_emulate_three_button_mouse != Qreverse); + if (modifiers & controlKey) + result = cmdIs3 ? 2 : 1; + else if (modifiers & optionKey) + result = cmdIs3 ? 1 : 2; + } + return result; +} + #if USE_CARBON_EVENTS /* Obtains the event modifiers from the event ref and then calls mac_to_emacs_modifiers. */ @@ -6550,6 +6571,11 @@ mac_event_to_emacs_modifiers (EventRef eventRef) UInt32 mods = 0; GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL, sizeof (UInt32), NULL, &mods); + if (Vmac_emulate_three_button_mouse != Qnil && + GetEventClass(eventRef) == kEventClassMouse) + { + mods &= ~(optionKey & cmdKey); + } return mac_to_emacs_modifiers (mods); } @@ -6564,7 +6590,14 @@ mac_get_mouse_btn (EventRef ref) switch (result) { case kEventMouseButtonPrimary: - return 0; + if (Vmac_emulate_three_button_mouse == Qnil) + return 0; + else { + UInt32 mods = 0; + GetEventParameter (ref, kEventParamKeyModifiers, typeUInt32, NULL, + sizeof (UInt32), NULL, &mods); + return mac_get_emulated_btn(mods); + } case kEventMouseButtonSecondary: return NILP (Vmac_wheel_button_is_mouse_2) ? 1 : 2; case kEventMouseButtonTertiary: @@ -7700,7 +7733,7 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected) #if USE_CARBON_EVENTS bufp->code = mac_get_mouse_btn (eventRef); #else - bufp->code = 0; /* only one mouse button */ + bufp_.code = mac_get_emulate_btn (er.modifiers); #endif bufp->kind = SCROLL_BAR_CLICK_EVENT; bufp->frame_or_window = tracked_scroll_bar->window; @@ -7768,7 +7801,7 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected) #if USE_CARBON_EVENTS bufp->code = mac_get_mouse_btn (eventRef); #else - bufp->code = 0; /* only one mouse button */ + bufp_.code = mac_get_emulate_btn (er.modifiers); #endif XSETINT (bufp->x, mouse_loc.h); XSETINT (bufp->y, mouse_loc.v); @@ -8645,6 +8678,9 @@ syms_of_macterm () Fprovide (intern ("mac-carbon"), Qnil); + staticpro (&Qreverse); + Qreverse = intern ("reverse"); + staticpro (&x_display_name_list); x_display_name_list = Qnil; @@ -8689,6 +8725,17 @@ Otherwise the option key is used. */); useful for non-standard keyboard layouts. */); Vmac_reverse_ctrl_meta = Qnil; + DEFVAR_LISP ("mac-emulate-three-button-mouse", + &Vmac_emulate_three_button_mouse, + doc: /* t means that when the option-key is held down while pressing the + mouse button, the click will register as mouse-2 and while the + command-key is held down, the click will register as mouse-3. + 'reverse means that the the option-key will register for mouse-3 + and the command-key will register for mouse-2. nil means that + not emulation should be done and the modifiers should be placed + on the mouse-1 event. */); + Vmac_emulate_three_button_mouse = Qnil; + #if USE_CARBON_EVENTS DEFVAR_LISP ("mac-wheel-button-is-mouse-2", &Vmac_wheel_button_is_mouse_2, doc: /* Non-nil means that the wheel button will be treated as mouse-2 and -- 2.39.2