TweetFollow Us on Twitter

Scrolling Menubar
Volume Number:5
Issue Number:4
Column Tag:Programmer's Workshop

April Fool's INIT: Scrolling the Menu Bar!?

By Mike Scanlin, San Diego, CA

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

Probably everyone who reads this magazine knows at least one person who owns a Mac that they’d like to play a joke on. This INIT resource might be just the thing you’re looking for. It is a patch to _GetNextEvent that will scroll the menu bar off the right side of the screen (leaving the menu bar blank) when the mouse is clicked in the very top pixel of the menu bar with an odd horizontal position. It does nothing if the mouse is clicked anywhere else on the screen, so it is possible to use the menus when this patch is installed, just so long as you don’t click in the very top pixel at an odd position. The menus will come back eventually (after a few sarcastic messages are displayed in the empty menu bar), so this is a pretty harmless patch (although extremely annoying according to my guinea pig roommate). Command key equivalents for current menus (like COMMAND-Q) will work even though no menus are shown. It is possible to remove the patch once it is installed by typing COMMAND-SHIFT-OPTION-TAB. The patch will beep to let you know it has been removed.


This patch to _GetNextEvent is an application of the technique I used in the Shift Mod patch (September 1987 issue of MacTutor). It is a tail patch on _GetNextEvent that looks at the event being returned and intercepts it if it is a mouseDown event with a vertical position of zero and an odd horizontal position. When it finds such an event the menu bar is scrolled off the screen and then _DrawMenuBar and _HiliteMenu are patched to do nothing. The reason those two traps are patched is because we don’t want anything drawn in the menu bar while we’re displaying our messages. The menu bar is restored by restoring those two traps and then calling _DrawMenuBar. Note that because we are patching _DrawMenuBar the user will not be able to get the menus back by quitting the current application and/or launching another application (because every application uses _DrawMenuBar to put their menus up).

Once we have scrolled the menus off, the patch to _GetNextEvent will intercept any mouseDown event anywhere in the menu bar area and display a message in the menu bar for 1 second or until the mouse button is let go, which ever is longer. After four such messages, the patches to _DrawMenuBar and _HiliteMenuBar are removed and _DrawMenuBar is called to draw the current menu bar (which may not necessarily be the one that was scrolled off since the user could have changed applications in the mean time).

To do the actual scrolling you would expect me to use _ScrollRect. That’s what I tried at first, but it was too slow (took about 10 seconds for the menu bar to get all the way off the screen). Then I tried scrolling by 3 or 4 pixels at a time, but it wasn’t smooth enough. The version you see here is scrolling by rotating bits in screen memory (via the 68000’s roxr instruction). Although somewhat unorthodox (Apple wouldn’t approve) it now only takes about 2 seconds to smoothly scroll the menu bar all the way off the screen.


There is a potential problem with this patch. There is a danger in patching and unpatching traps that may be patched by other applications. For applications that patch traps this isn’t normally a problem because they get a chance to restore the traps when they quit (before something else can patch them). But it is possible for our patches to be unpatched at a bad time. A “bad time” to unpatch would be after something else has patched on top of one of our patches. For instance, if we patch _GetNextEvent and then some other program patches it and then we unpatch ours, the second patch will be unpatched along with ours, but the application that made the second patch won’t know about it. To partially correct this from happening, I have the removePatch routine check if something has patched _GetNextEvent after we have patched it (by calling _GetTrapAddress and comparing it to ourself) and if it has, then ignore the request to unpatch ourself. I did not do this for _DrawMenuBar and _HiliteMenu, but it is unlikely that other applications would patch either of those two (besides, this is only a joke -- it’s not something you’re going to leave around in your System Folder forever).

One additional problem is that while this patch should work on any size monochrome monitor, it will not work on a Mac II color monitor. If anyone comes up with a simple fix, please send it in.

/* scrollMenuBarPatch.c     18 Nov 1987
 * by Mike Scanlin and Andy Voelker
 * This will install a patch to
 * _GetNextEvent that intercepts
 * mouseDown events if they occur in the
 * very top pixel-row of the screen. If
 * an event is intercepted, the menu bar
 * is scrolled off the right side of the
 * screen before the user can react.
 * After 4 more clicks in the menuBar
 * (with appropriately sarcastic messages 
 * displayed after each one) the origina
 * l menuBar is restored. The patch can
 * be removed by typing

#include “EventMgr.h”
#include “QuickDraw.h”
#include “asm.h”

/* low memory globals */
extern Handle    MenuList : 0x0A1C;
extern PtrScrnBase : 0x0824;
extern GrafPtr WMgrPort   : 0x09DE;

/* the traps we patch */
#define GetNextEventTrap  0xA970
#define DrawMenuBarTrap   0xA937
#define HiliteMenuTrap    0xA938

#define CLICKS_TO_MENU    4
#define MENU_BAR_HEIGHT   20
#define TAB_KEY  0x09
#define JMP_INSTRUCTION   0x4EF9

#define memFullErr -108
#define screenBits_bounds_right  -110
#define screenBits_bounds_left-114

void  main(void);

void main()
 asm {
/* This first section is the only part
 * that gets run initially. It gets some
 * space in the system heap and sets up a 
 * patch to _GetNextEvent. The patch
 * won’t do anything until the user
 * clicks in the very top pixel of the
 * menu bar (in which case it will scroll 
 * the menu bar off the screen to the
 * right). */
   move.l D3,-(SP)

/* get the old trap address */
 move   #GetNextEventTrap,D0

/* set the address for the JMP
 * instruction that calls the original
 * trap */
 lea    @origTrap,A1
 move.l A0,(A1)

/* get some space in the system heap for
 * our patch */
 lea    @last,A0
 lea    @first,A1
 suba.l A1,A0
/* D0 = length of patch */
 move.l A0,D0  
/* save length for _BlockMove */
 move.l D0,D3    
 cmpi   #memFullErr,D0
 beq.s  @noPatch
 lea    @saveLoc,A1
/* save for removePatch */
 move.l A0,(A1)
/* save for _BlockMove */ 
 move.l A0,-(SP) 

/* set the trap address to the space we
 * just got in the system heap. */
 move   #GetNextEventTrap,D0

/* now move our patch into place */
 lea    @first,A0
/* (SP)+ is the result from _NewPtr */
 move.l (SP)+,A1 
 move.l D3,D0

 move.l (SP)+,D3

/* this is the end of the installation
 * part, but we can’t do an RTS here
 * because LSC needs to clean up. So we
 * fall through to the end. */
 bra    @last

 * Here’s the new _GetNextEvent. It calls 
 * the existing _GetNextEvent and then
 * checks if a mouseDown or keyDown event 
 * is being reported. If not, the event
 * is passed to the application
 * unmodified. If we end up using the
 * event ourselves, a null event is
 * returned to the application.

/* pop the original return address and
 * save it */
 lea    @exitAddress,A0
 move.l (SP)+,(A0)
/* save ptr to event record so we can get 
 * at it later */
 lea    @eventRecPtr,A0
 move.l (SP),(A0)
/* set the return address to our patch */
 pea    @tailPatch

/* the nops get filled with the address
 * of the original _GetNextEvent */

/* this is where it comes after the
 * normal _GetNextEvent processing */
 lea    @eventRecPtr,A0
 move.l (A0),A0

/* check if it’s a keydown event that
 * says to remove ourself. This is the
 * only keyDown that we intercept. */
 cmpi   #keyDown,D0
 bne.s  @noKeyDown
/* the key to remove the patch is
 cmpi.b #TAB_KEY,D0
 bne.s  @noKeyDown
 beq.s  @removePatch
/* if it’s not a mousedown event, then
 * ignore it */
 cmpi   #mouseDown,D0
 bne.s  @patchExit

/* if we’ve already scrolled the menu
 * list, then don’t scroll it again */
 lea    @menus,A1
 tst    (A1)
 bne.s  @alreadyGone
/* if no menus exist, then leave */
 move.l MenuList,A1
 move.l (A1),A1
 tst    (A1)
 beq.s  @patchExit

/* if the mouse is not at an odd
 * location, then leave */
 andi   #1,D0
 beq.s  @patchExit
/* if the mouse is not at the very top
 * pixel of the menu bar, then leave */
/* put vertical coordinate in low word */
 swap   D0
 cmpi   #1,D0
 bge.s  @patchExit
/* now we’re set to scroll that puppy. */
 bsr    @scrollMenuBar

/* save the fact that the menu bar that
 * was just scrolled */
 lea    @menus,A0
 move   #1,(A0)
/* patch _DrawMenuBar and _HiliteMenu to
 * do nothing if and when they’re
 * called */
 bsr    @disableTraps

 lea    @clicks,A1
 move   #CLICKS_TO_MENU,(A1)
 bra.s  @returnNullEvent

/* if mouse is not in menu bar, then
 * leave */
/* put vertical coordinate in low word */
 swap   D0
 bge.s  @patchExit

/* print a message in the menu bar */
 bsr    @drawAMessage

 lea    @clicks,A0
 subi   #1,(A0)
 bne.s  @returnNullEvent

/* now that we’re finished playing,
 * restore _DrawMenuBar and 
 * _HiliteMenu */
 bsr    @restoreMenus
/* set the event to null */
 lea    @eventRecPtr,A0
 move.l (A0),A0
/* change _GetNextEvent’s return value to 
 * false. The 20 is for the 5 regs that
 * are saved on the stack at this point
 clr    20(SP)

/* JMP to the place that called
 * _GetNextEvent */

/* this is where it comes to remove the
 * _GetNextEvent patch */
/* if the menus aren’t shown, then
 * restore them before leaving */
 bsr    @restoreMenus
/* check if we are the most recent patch
 * to _GetNextEvent. If we’re not, then
 * don’t unpatch. */
   move #GetNextEventTrap,D0
 lea    @first,A1
 cmpa.l A1,A0
 bne.s  @returnNullEvent
/* set the trap address back to the
 * original trap. */
 lea    @origTrap,A0
 move.l (A0),A0
 move   #GetNextEventTrap,D0
/* beep to let them know it has been 
 * removed */
 move   #1,-(SP)
/* free up mem occupied by this patch */
 lea    @saveLoc,A0
 move.l A0),A0
 bra.s  @returnNullEvent

/* This routine will disable _DrawMenuBar 
 * and _HiliteMenu */
 move   #DrawMenuBarTrap,D0
 lea    @drawMenuBarAddr,A1
 move.l A0,(A1)
 lea    @doNothing,A0
 move   #DrawMenuBarTrap,D0
 move   #HiliteMenuTrap,D0
 lea    @hiliteMenuAddr,A1
 move.l A0,(A1)
 lea    @doNothingWithParam,A0
 move   #HiliteMenuTrap,D0
/* This routine will restore _DrawMenuBar 
 * and _HiliteMenu and then draw the 
 * current menu bar */
 lea    @menus,A0
 tst    (A0)
 beq.s  @doNothing
/* unpatch DrawMenuBar and then draw the
 * old menu bar */
 lea    @drawMenuBarAddr,A0
 move.l (A0),A0
 move   #DrawMenuBarTrap,D0
 lea    @hiliteMenuAddr,A0
 move.l (A0),A0
 move   #HiliteMenuTrap,D0
 lea    @menus,A0
 clr    (A0)

/* This is the _HiliteMenu routine that
 * does nothing. It gets rid of the
 * parameter passed to _HiliteMenu and
 * then returns. */
 move.l (SP)+,A0
 addq.l #2,SP
 jmp    (A0)

/* This is the routine that actually does 
 * the scrolling */
/* hide the cursor so we don’t get part
 * of the cursor scrolled with the
 * menuBar */

/* get the current screen width from the
 * Quickdraw global screenBits */
 move.l (A5),A0
/* D3 = # of columns (width) - 1 in the
 * current screen */
 move   D3,D2
 subq   #1,D3
/* D2 = # of bytes - 1 in one screen
 * row */ 
 asr    #3,D2
 subq   #1,D2

/* here’s the loop that actually scrolls
 * the menu bar all the way across the
 * screen */
 move   #MENU_BAR_HEIGHT - 2,D1

/* this outside loop will scroll all rows 
 * of the menu bar one pixel to the right 
 move   D2,D0
 addq   #1,D0
/* calc # of bytes from base addr to
 * start of current row */
 mulu   D1,D0    
 move.l ScrnBase,A0
 adda.l D0,A0
/* white-out the left edge of this row */
 clr.b  (A0)
/* D0 = number of words in one row */
 move   D2,D0    
 asr    #1,D0
/* set the X flag */
 andi.b #0xEF,CCR
/* this inner loop will scroll one row of 
 * the screen one pixel to the right */
 roxr   (A0)+
 dbra   D0,@inside

/* go and do the next row */
 dbra   D1,@outside

/* make the corners look like they used
 * to (i.e. rounded and black) */
 move   D2,D0
 move.l ScrnBase,A1
 ori.b  #0xF8,(A1)
 adda   D0,A1
 ori.b  #0x1F,(A1)+
 ori.b  #0xE0,(A1)
 adda   D0,A1
 ori.b  #0x07,(A1)+
 ori.b  #0xC0,(A1)
 adda   D0,A1
 ori.b  #0x03,(A1)+
 ori.b  #0x80,(A1)
 adda   D0,A1
 ori.b  #0x01,(A1)+
 ori.b  #0x80,(A1)
 adda   D0,A1
 ori.b  #0x01,(A1)
 dbra   D3,@wayOut


/* this routine will print a string in
 * the menu bar, wait a bit and then
 * erase it */
/* set the current port to the window
 * manager’s */
 move.l (A5),A0
 lea    @savePort,A1
 move.l (A0),(A1)
 move.l WMgrPort,(A0)

/* save the old clipRgn */
 lea    @saveClip,A0
 move.l WMgrPort,A1
/* set the clipRgn to be big enough for
 * the string we want to print */
 subq   #4,SP
 move.l WMgrPort,A1
 pea    @stringRect

/* the string we print depends on the
 * value of the clicks variable */
 lea    @clicks,A0
 move   (A0),D0
 cmpi   #4,D0
 bne.s  @1
 pea    @string1
 bra.s  @5
@1 cmpi #3,D0
 bne.s  @2
 pea    @string2
 bra.s  @5
@2 cmpi #2,D0
 bne.s  @3
 pea    @string3
 bra.s  @5
@3 cmpi #1,D0
 bne.s  @delay
 pea    @string4
@5 move #10,-(SP)
 move   #14,-(SP)
 lea    @downTime,A0
 move.l Ticks,(A0)

/* wait until the mouse is released or 60 
 * ticks, which ever is longer */
 subq.l #2,SP
 tst    (SP)+
 bne.s  @waitTilMouseUp
 lea    @downTime,A0
 move.l (A0),D0
 cmp.l  Ticks,D0
 bgt.s  @waitTilMouseUp

/* erase the string */
 pea    @stringRect

/* dispose of the clipRgn we created */
 move.l WMgrPort,A1
/* restore the old clip rgn */
 lea    @saveClip,A0
 move.l WMgrPort,A1
/* restore the old port */
 move.l (A5),A0
 lea    @savePort,A1
 move.l (A1),(A0)
@eventRecPtrdc.l 0
/* @menus is TRUE while menus that exist
 * are not being shown */
@menus  dc0 
@downTime dc.l   0
/* @clicks is the number of menus clicks
 * until menus return */
@clicks dc0 
/* @words is the number of 16 bit words
 * in one row of screen */
@words  dc0
/* @saveLoc is the address of our patch
 * in the system heap */  
@savePort dc.l   0
@saveClip dc.l   0
@drawMenuBarAddr dc.l0
@hiliteMenuAddr  dc.l0

/* this rect should be big enough to
 * enclose the longest of the strings. */
@stringRect dc

/* define the pascal strings. Does LSC
 * provide a better way than this? */
 ‘ ‘,’M’,’e’,’n’,’u’,’s’,’ ‘,’H’,’e’,
 ‘l’,’l’,’ ‘,’N’,’o’,’ ‘,’M’,’e’,’n’,
 ‘ ‘,’Y’,’e’,’t’
 ‘r’,’e’,’ ‘,’D’,’i’,’d’,’ ‘,’T’,’h’,
 ‘o’,’s’,’e’, ‘,’M’,’e’,’n’,’u’,’s’,
 ‘ ‘,’G’,’o’,’?’


Community Search:
MacTech Search:

Software Updates via MacUpdate

OmniOutliner Pro 4.2 - Pro version of th...
OmniOutliner Pro is a flexible program for creating, collecting, and organizing information. Give your creativity a kick start by using an application that's actually designed to help you think. It's... Read more
VLC Media Player 2.2.1 - Popular multime...
VLC Media Player is a highly portable multimedia player for various audio and video formats (MPEG-1, MPEG-2, MPEG-4, DivX, MP3, OGG, ...) as well as DVDs, VCDs, and various streaming protocols. It... Read more
Nisus Writer Pro 2.1.1 - Multilingual wo...
Nisus Writer Pro is a powerful multilingual word processor, similar to its entry level products, but brings new features such as table of contents, indexing, bookmarks, widow and orphan control,... Read more
Tinderbox 6.2.0 - Store and organize you...
Tinderbox is a personal content management assistant. It stores your notes, ideas, and plans. It can help you organize and understand them. And Tinderbox helps you share ideas through Web journals... Read more
OmniOutliner 4.2 - Organize your ideas,...
OmniOutliner is a flexible program for creating, collecting, and organizing information. Give your creativity a kick start by using an application that's actually designed to help you think. It's... Read more
Things 2.5.4 - Elegant personal task man...
Things is a task management solution that helps to organize your tasks in an elegant and intuitive way. Things combines powerful features with simplicity through the use of tags and its intelligent... Read more
NeoOffice 2014.10 - Mac-tailored, OpenOf...
NeoOffice is a complete office suite for OS X. With NeoOffice, users can view, edit, and save OpenOffice documents, PDF files, and most Microsoft Word, Excel, and PowerPoint documents. NeoOffice 3.x... Read more
iPhoto Library Manager 4.2 - Manage mult...
iPhoto Library Manager allows you to organize your photos among multiple iPhoto libraries, rather than having to store all of your photos in one giant library. You can browse the photos in all your... Read more
Web Snapper 3.3.8 - Capture entire Web p...
Web Snapper lets you capture Web pages exactly as they appear in your browser. You can send them to a file as images or vector-based, multi-page PDFs. It captures the whole Web page - eliminating the... Read more
TeamViewer 10.0.41404 - Establish remote...
TeamViewer gives you remote control of any computer or Mac over the Internet within seconds, or can be used for online meetings. Find out why more than 200 million users trust TeamViewer! Free for... Read more

Chainsaw Warrior: Lords of the Night has...
It's time to put the Darkness back in its place now that Chainsaw Warrior: Lords of the Night has officially made it to iOS. | Read more »
A World of Ice and Fire Lets You Stalk 2...
George R. R. Martin’s A World of Ice and Fire, by Random House, is a mobile guide to the epic series. The new update gives you the Journeys map feture that will let you track the movements of 25 different characters. But don't worry, you can protect... | Read more »
Gameloft Announces Battle Odyssey, a New...
Battle Odyssey, Gameloft's newest puzzle RPG, is coming to the App Store next week. Set in the world of Pondera, you will need to control the power of the elements to defend the world from evil. You'll be able to entlist over 500 allies to aid you... | Read more »
Fusion - HDR Camera (Photography)
Fusion - HDR Camera 1.0.0 Device: iOS Universal Category: Photography Price: $1.99, Version: 1.0.0 (iTunes) Description: Fusion creates HDR (high dynamic range) photos by capturing different exposures and then combining them into one... | Read more »
Sago Mini Toolbox (Education)
Sago Mini Toolbox 1.1 Device: iOS Universal Category: Education Price: $2.99, Version: 1.1 (iTunes) Description: Come build with the Sago Mini friends! Use a wrench, try a saw, or hammer some nails. From sewing hand puppets to... | Read more »
You Should Probably Grab Hitman GO While...
Hitman GO is a surprisingly cool (yet also incredibly drastic) departure from the Hitman series. It's well worth playing for any puzzle game fans out there, and at the moment you can get your hands - or garrotte if you will - on it for a mere $0.99... | Read more »
IFTTT is Bringing Do Button and Do Note...
IFTTT has announced Do Button and Do Note for the Apple Watch. Do Button lets you make your own personalized button that can connect to things like your Google Drive, control the temperature in your home with Nest Thermostat, or turn the lights on... | Read more »
How Many Days, Hours, and Minutes Are Le...
Countdown, by Yves Tscherry, is now available on the App Store. The app keeps track of countdowns to your favorite things such as someones birthday or days till the New Year. You can display the time in seconds, minutes, hours, days, weeks, months,... | Read more »
The All-New Misfit 2.0 App is Available...
Misfit has just given their app a complete overhaul. Misfit 2.0 now has a brand new interface with a sleek design and is easier to navigate. You'll be able to sync your Misfit device and look up health and fitness information faster than ever before... | Read more »
Halo: Spartan Strike (Games)
Halo: Spartan Strike 1.0 Device: iOS Universal Category: Games Price: $5.99, Version: 1.0 (iTunes) Description: Delve into 30 challenging missions through cities and jungles using a devastating arsenal of weapons, abilities and... | Read more »

Price Scanner via

TigerText Introduces First Secure Enterprise...
TigerText, a provider of secure, real-time messaging for the enterprise, has announced the launch of TigerText for the Apple Watch. TigerText for the Apple Watch enables users to securely send and... Read more
The Conservation Fund Partners with Apple To...
The Conservation Fund has announced that it will partner with Apple to help protect working forests in the United States. The Apple initiative will conserve more than 36,000 acres of working... Read more
Clearance 13-inch 2.6GHz Retina MacBook Pro a...
B&H Photo has clearance 2014 13″ 2.6GHz/128GB Retina MacBook Pros now available for $1099, or $200 off original MSRP. Shipping is free, and B&H charges NY sales tax only. Read more
Apple refurbished 2014 13-inch Retina MacBook...
The Apple Store has Apple Certified Refurbished 2014 13″ Retina MacBook Pros available for up to $400 off original MSRP, starting at $979. An Apple one-year warranty is included with each model, and... Read more
iMacs on sale for up to $205 off MSRP, NY tax...
B&H Photo has 21″ and 27″ iMacs on sale for up to $205 off MSRP including free shipping plus NY sales tax only: - 21″ 1.4GHz iMac: $1019 $80 off - 21″ 2.7GHz iMac: $1189 $110 off - 21″ 2.9GHz... Read more
Sale! 16GB iPhone 5S for $1 with service
Best Buy is offering 16GB iPhone 5Ss for $1.00 with 2-year activation at a participating cellular provider. Choose free home shipping and activation, or buy online and activate during in-store pickup... Read more
Apple refurbished 2014 MacBook Airs available...
The Apple Store has Apple Certified Refurbished 2014 MacBook Airs available starting at $679. An Apple one-year warranty is included with each MacBook, and shipping is free. These are currently the... Read more
27-inch 3.5GHz 5K iMac on sale for $2349, sav...
 Adorama has the 27″ 3.5GHz 5K iMac in stock today and on sale for $2349 including free shipping plus NY & NJ sales tax only. Their price is $150 off MSRP. For a limited time, Adorama will... Read more
Save up to $380 on an iMac with Apple refurbi...
The Apple Store has Apple Certified Refurbished iMacs available for up to $380 off the cost of new models. Apple’s one-year warranty is standard, and shipping is free: - 27″ 3.5GHz 5K iMac – $2119 $... Read more
iFixIt Teardown Awards 12-IInch Retina MacBoo...
iFixIt has posted its illustrated teardown of the new 12-inch MacBook Retina. They note that this new MacBook is less than half the thickness of the last Apple notebook called just “MacBook” back in... Read more

Jobs Board

*Apple* Solutions Consultant - Retail Sales...
**Job Summary** As an Apple Solutions Consultant (ASC) you are the link between our customers and our products. Your role is to drive the Apple business in a retail Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Technical Project Manager - *Apple* Pay - A...
**Job Summary** Apple Pay is seeking an experienced technical PM to…manage the on boarding of new merchants for the Apple Pay platform in the US Within this role you Read more
Senior Identity Architect - *Apple* Pay - A...
**Job Summary** Apple , Inc. is looking for a highly motivated, innovative and hands-on senior identity architect to join the Apple Pay Engineering team. You will Read more
Program Manager, *Apple* Retail Global Tale...
…for the worldwide creation and implementation of the key talent development initiatives within Apple Retail. He or she will work closely with our Retail Corporate team, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.