Non-visible Window Title Bars

I`ve got a simple app that puts a couple of small "image view"windows in the corner of my desktop with a picture of my wife in one, kids in the other etc. (I could just use Konfabulator etc. but doing it yourself is more fun.)

For the sake of simplicity I would like to cut the title bars so that only the pictures show.
ie: A command like: “set visibility of titlebar of window… to 0” would do fine if only it existed!

Im sure its a simple one-step command but I can`t seem to find it in the documentation so can anyone help me out?

The question again:
What is the prodedure for making a window`s title bar disappear?

Any help would be greatly appreciated and thanks in advance.

This should do it:

tell window "windowName"
set titled to false
end tell

Supercow…did you just make that up, or did you test that and make sure it worked? Neither the applescript window object reference nor the cocoa NSWindow class have any mention of a “titled” property. All I get are evaluator errors and wierd window effects. What gives?

As far as I can tell, the title bar of a window is a complex topic that can only be handled by a call to the cocoa window class in obj-c. I have not the skills to figure it out, but it seems that the “titled” property of the window can not be changed once the window is instantiated, so issuing a call to just ‘get rid of it’ after it’s launched, is not possible. The cocoa method involves instantiating a new window with the “NSBorderlessWindowMask” style. Doing this defaults the visibility and responsiveness of the window to false, so you have to override them with more calls to methods which will undo these. You also must enable dragging, if desired, and possibly other tasks that I’m certainly not experienced enough to provide code for. Below are some links I found that are good starts, but you’ll have to find someone with the skills to translate this into usable call methods and then to help you implement it. Searching the internet for “borderless window” or “NSBorderlessWindowMask” will yield some relavent results, too. Post your code and a tutorial if you figure this one out. :smiley:

  1. oomori (japanese site, but has direct mention of the call methods)
  2. sourceforce page (has a complete cocoa implementation with good comments explaining each step… wish I new how to modify this to give you an easy answer)

If I might author an applescript suggestion, it would be this. If you’re not opposed to the textured window, it does not have the unattractive line beneath the title bar. You could set the window’s title to “”, and leave a thick border around the other sides of the images so it looks intentional. I know it’s not perfect, but it gets the job done without any extra code…especially for a personal desktop app.

Good luck,
j

jobu is correct, the “set title to false” will not cut it. You’ll have to dive into Obj-C and create a method that instantiates a window with a NSBorderlessWindowMask mask. You can do this fairly easily by getting the bounds of the frame of the window you want to display without the title, then tell the method to create a new window to that size with the NSBorderlessWindowMask mask then set the view of the new window to the view of the source window. Finally, show the new window. You’ll also have to do some coding to get the frame to respond to mouse clicks if you want the user to be able to easily move the window after you’ve displayed it. I’ll get around to posting some code one of these days. You can see that I’ve done this to a certain extent in my app Jon’s Phone Tool.

Jon

OK, here’s a quick demo project for making titleless windows (though again, you’ll need more code if you actually want to be able to move the window by click and dragging on them–you can move them programatically by setting their position):

http://homepage.mac.com/jonn8/as/dist/titlelessWindows.sit

This is also very helpful code for showing how to make your windows textured/non-textured on-the-fly without having to relaunch the application. Just create your windows and, if the user chooses a different preference (textured or not), delete the programatically generated windows, and then recreate them with the appropriate settings.

Enjoy.

Jon

Very nice (…and quick 8)) work Jon. Kudo’s…
j

Obviously while I was sleeping last night (Japan) you were all very busy working this out. Thanks so much.

Hey Jon, thanks for the project. Im truly impressed. Its exactly what I needed. For some reason though, when I input the code into my script I get the error message: “The variable customWindow is not defined. (-2753)”. I notice that in your project you`ve got two extra files:
customWindow.h & customWindow.m

I``ve seen these kind of files before in other projects and have always wondered how they were made. I tried the new file command but cant figure out which of the options to choose. Its obviously not just an AppleScript File. Im sure this is where Im going wrong and why the customWindow error is occuring.

So, could you please tell me how to make the customWindow.h & m files (and maybe add in why we need them)? Im assuming here that this is where Im going wrong.

Anyway, again a huge thank you and I look forward to hearing from you again soon.

Bruce
Follow Your Dreams

The .h/.m files are header and method files to an Objective-C class file I created (File > New File… > Objective-C class) to hold the Objective-C code I needed to create the titleless windows programmatically. Then, from the AppleScript code, I called that Objective-C by using a “call method” command to first allocate (alloc) the class (customWindow) then to call the specific method of the class with variable parameters. For more information, see this discussion:

http://bbs.applescript.net/viewtopic.php?t=8257

Jon

Here is a program, w/ source code, you might want to look at.

(“iTunes Overlay” by Devin Bayer, found at “Doug’s Applescript’s for iTunes”)

Thanks for all the advice. I`ve finally gotten my app up and running with no title bars as well as the satisfaction of making my first foray into Objective-C files.

I truly do appreciate the help. Thanks

Not that there’s anything wrong with applescript or objC, but I thought I would suggest an alternate route. You could use Geek Tool to do what you are trying to accomplish, as well as other things.

Edit: It seems you have already have a working app. I’m glad you were successful with objC. I’m going to wimp out for the time being and use Geek Tool.

After playing with “Non-visible Window Title Bar” windows for a few days Ive noticed that images, buttons etc. work fine. But I cant seem to get a text field to allow text to be entered. It seems to be locked to text input somehow. I`m assuming that, as opposed to buttons and images, the text field must be dealt with programmatically. Any ideas?

Also, thanks guardian34 for the info on Geek Tool. I`ll have to check it out.

I like the titleless thing. Real cool.

Got any tricks for creating a window with the sideways title bar?
(Like the zoomed out, or mini version, of the iTunes window)

I considered making a titleless bar and some custom buttons that would emulate it, but maybe there is an easier way…

THANKS!

Here’s a tutorial on how to create a custom class to make any IB window a titleless one. I’ve modified code from this page (mostly originally from apple’s RoundTransparentWindow sample project, which is not supplied with xcode). I found it difficult at first to know what to do with all the bit’s an pieces, so I hope this clarifies the parts and process of getting this type of obj-c job done. I’ve written this as I created a new project, so it does work.

  1. Create an applescript project.

  2. Open your mainMenu.nib file, and create the window you wish to be displayed without a title. This can be an existing window, too

  3. Click on your window, and then click on “Classes” in the “MainMenu.nib” window. You’ll see a hierarchical list of NS objects… NSWindow should be highlighted. If it isn’t, navigate through NSObject>NSResponder>NSWindow.

  4. Click on the “Classes” menu in the IB main menu, and select “Subclass NSWindow”. A new subclass will appear to the right of NSWindow. Name it “CustomWindow”. With the new ‘CustomWindow’ subclass highlighted, click on the “Classes” main menu again, and select “Create Files for CustomWindow”. Make sure it intends to save “CustomWindow.h” and “Custom Window.m”, and then click “Choose” to create the cocoa files.

  5. Select your window, and go to the “Custom Class” pane in the info window. You should see “CustomWindow” as an option. Select it, and save your interface.

  6. Determine whether you want the user to be able to move the window.

  7. Open “CustomWindow.h”. If you want to be able to position the window programatically and NOT allow the user to move it, do nothing. If you want to enable moving/dragging of the window, add the line:

NSPoint initialLocation;

… between the {} brackets. The file should look something like this…

[code]/* CustomWindow */

#import <Cocoa/Cocoa.h>

@interface CustomWindow : NSWindow
{
NSPoint initialLocation;
}
@end[/code]
8 ) Open “CustomWindow.m”. Read through the commends carefully for this file, as they state what each part does, and whether it’s necessary for making the window draggable.

[code]#import “CustomWindow.h”
#import <AppKit/AppKit.h>

@implementation CustomWindow

// This line initializes any window connected to the CustomWindow class as titleless…overriding the default AppKit init method.

  • (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag {

    // Call the NSWindow method to instantiate the window, but add the borderless mask to make it titleless
    // Sets ‘result’ as a variable reference to the new window object
    NSWindow* result = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];

    // Set the background color to clear so that (along with the setOpaque call below) we can see through the parts of the window that we’re not drawing into
    // If you want to have a window with a non-rectangular shape, un-comment the next line.
    //[result setBackgroundColor: [NSColor clearColor]];
    // Note: You’ll need to provide an image in an image view in the window that will server as your ‘window’, otherwise the window will just be invisible.

    // The next line makes the window float on top of all other windows. Uncomment it if you wish the window to remain on top of ALL other windows.
    //[result setLevel: NSStatusWindowLevel];
    // Note: this is useful for startup screens or other utility windows that only you should control

    // Control the transparency of the entire window. 0 is totally transparent… 1 is totally opaque.
    [result setAlphaValue:1.0];

    // Control Opaqueness. Leave “YES” to make it a “normal” window.
    // Set to “NO”, and use in conjunction with the ‘clearColor’ background color above to make a window with a custom graphic shape.
    [result setOpaque:YES];

    // Does the window has a shadow?
    [result setHasShadow: YES];

    // Automatically center the window? Position will be handled as any normal xcode window would be if this is not used.
    //[result center];

    return result;
    }

// Custom windows that use the NSBorderlessWindowMask can’t become key by default. Therefore, controls in such windows
// won’t ever be enabled by default. Thus, we override this method to change that.

  • (BOOL) canBecomeKeyWindow
    {
    return YES;
    }

// IMPORTANT //
// Everything below here (except the “@end” at the end :slight_smile: can be omitted if you are not allowing dragging of the window.
// Make sure the “CustomWindow.h” file has the single line mentioned above if you ARE going to implement dragging.

// This code implements dragging of the window manually, because borderless windows can not be dragged by default.

  • (void)mouseDragged:(NSEvent *)theEvent
    {
    NSPoint currentLocation;
    NSPoint newOrigin;
    NSRect screenFrame = [[NSScreen mainScreen] frame];
    NSRect windowFrame = [self frame];

    currentLocation = [self convertBaseToScreen:[self mouseLocationOutsideOfEventStream]];
    newOrigin.x = currentLocation.x - initialLocation.x;
    newOrigin.y = currentLocation.y - initialLocation.y;

    if( (newOrigin.y+windowFrame.size.height) > (screenFrame.origin.y+screenFrame.size.height) ){
    newOrigin.y=screenFrame.origin.y + (screenFrame.size.height-windowFrame.size.height);
    }

    [self setFrameOrigin:newOrigin];
    }

// Get the intital mouse location

  • (void)mouseDown:(NSEvent *)theEvent
    {
    NSRect windowFrame = [self frame];

    initialLocation = [self convertBaseToScreen:[theEvent locationInWindow]];
    initialLocation.x -= windowFrame.origin.x;
    initialLocation.y -= windowFrame.origin.y;
    }

// Don’t delete this last line by accident!!! //
@end[/code]
9) Build and run your application. You should have a titleless window.

The windows initialized using this setup respond to pretty much all normal applescript studio commands. The custom class just replaces the default values supplied by the appkit with the new ones making it conform to our needs. You obviously can’t click on the close button or other title bar buttons, so you must manually provide a mechanism for closing the window, etc. If enabled, the entire window is the draggable portion. You can drag the window from any part of the window as you would in the title bar of a normal window.

Good luck, and have fun…
j

Esqwuared… an easy way for you to acheive a side title-bar is to use a titleless window, and create an image to place on the side of the window that appears as the title bar. Lay a few buttons over that to add functionality, and you’re ready to rock.

j

Thank you VERY much for the detailed explanation. This style is much better than the method Ive been using. Its great. Thanks.

One quick question. In the code it has the [result center] property setting. This sets the window center horizontally but not vertically. (Is it just my monitor or does not the resulting position appear much higher vertically than center?) Is there any way we can get the window centered vertically as well? And if so, how would the code be written?

Thanks in advance.

Here’s what apple has to say about that…

This not-quite-centered vertical placement is where apple wants it, so you’ll have to come up with another method of making it “exactly” centered if you must override it. This is the method that apple implements automatically with all panels and similarly centered windows. To get around this you’d need to read the screen dimensions, do some math, and then set the window’s bounds/position automatically. There is a post here with a discussion of getting screen res, which you’d have to implement yourself…as I still haven’t had time to mess with it.

Good luck…
j

Well there you go. That explains it. Again, thanks.

Topic is old, but a good one.

If you uncomment [result setBackgroundColor: [NSColor clearColor]]; and set [result setOpaque:YES]; to [result setOpaque:NO]; and use a custom graphic shape, how then would you make it draggable? You can’t move the window by dragging anywhere on the shape. Any code that would allow dragging by dragging on the shape?

Hi,

I think the original code of Apple’s sample project “roundTransparentWindow” (http://developer.apple.com/samplecode/RoundTransparentWindow/index.html) is doing exactly what you want - just copy & paste the NSWindow subclass code and place your shape view on this window - the window will be dragable then whereever your view’s alpha value is high enough.

D.