Friday, July 30, 2010

#1 2004-07-17 08:19:17 am

bwDreams
Member
From: Japan
Registered: 2003-11-21
Posts: 62
Website

Full Screen Windows - Really Cool

After success working out the titleless windows (thanks to you all) I thought it would be neet to have a full screen window. After checking around the net I came across some code written by "kitzkikz" <http://www.macosxhints.com/article.php?story=20030804193518188> and after some very slight modifications I was able to get it to work.

To recap:
1)Start  with a basic applescript studio project and add the two Objective-C files Fullscreen.h and Fullscreen.m

Fullscreen.h
----------------
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <Cocoa/Cocoa.h>
@interface NSApplication (ASKAFullScreen)
- (NSWindow *)beginFullScreen;
- (void)endFullScreen;
@end

Fullscreen.m
----------------
#import "Fullscreen.h"
NSWindow *fsWindow;
@implementation NSApplication (ASKAFullScreen)
- (NSWindow *)beginFullScreen
{   fsWindow = [
      [NSWindow alloc]
      initWithContentRect:[[NSScreen mainScreen] frame]
      styleMask:NSBorderlessWindowMask
      backing:NSBackingStoreBuffered
      defer:NO];
    NSView *fsView=[[NSView alloc] initWithFrame:[fsWindow frame]];
    [fsWindow setContentView:fsView];
    NSImageView *fsImage = [[NSImageView alloc] initWithFrame:[fsView frame]];
    [fsView addSubview:fsImage];
    [fsWindow setBackgroundColor:[NSColor redColor]];
    [NSMenu setMenuBarVisible:0];
    [fsWindow makeKeyAndOrderFront:fsWindow];
    return fsWindow;
}
- (void)endFullScreen
{   [NSMenu setMenuBarVisible:1];
    [fsWindow close];
}
@end

2) Then add a button to a window and in your main script add:
---------------------------------------------------------------------------

on clicked theObject
    set theWindow to (call method "beginFullScreen")
    delay 5
    call method "endFullScreen"
end clicked

Note: I made the window color red instead of the original black. I couldn`t get a hold of "kitzkikz" to thank him but I imagine that for all you Object-C programmers this isn`t really anything special.

----------------------------------------------------------------------------

Anyway, my question is (you were probably wondering whether I even had one):

How do you get a window that you`ve already made (ex: a window that includes a photo) to go full screen? In this example we`ve made a new window programatically, but what if you already have a window? Is it possible to reference it somehow?

Any help/ideas would be Greatly appreciated.

Thank you all for your time and I look forward to hearing from you soon.

Bruce
Follow Your Dreams


Follow Your Dreams

Offline

 

#2 2004-07-17 09:48:41 am

jobu
Member
From: phxaz
Registered: 2004-01-17
Posts: 908
Website

Re: Full Screen Windows - Really Cool

There have been a couple threads covering this topic.  This one and this one discuss some possible ways of doing this.  Basically YES, you can make an existing window go full screen, but you need to know what the screen resolution is in order to do that. Because screen resolutions change, you can't hardcode a resolution as it will not always be correct for every user.  This is assuming it's a distribution app.  If you're writing it for yourself, you could hardcode it.  There is no pure applescript method of getting the screen res, so you'll have to try one of the obj-c methods provided by mooresan in the second thread above.  Once you get the resolution, you can easily use applescript to set the size of the window using the bounds property...

Applescript:

tell window "theWindow"
set bounds to {0,0,1024,768}
end tell

j


The saddest thing I ever did see was a woodpecker peckin' at a plastic tree.
- Shel Silverstein

Offline

 

#3 2004-07-17 10:03:38 am

Rob
Member
From: Ohio, USA
Registered: 2002-11-19
Posts: 1886

Re: Full Screen Windows - Really Cool

There is no pure applescript method of getting the screen res, so you'll have to try one of the obj-c methods provided by mooresan in the second thread above.

I haven't tested this extensively but it appears to get the correct screen resolution for me. FYI, the handler was snagged from one of Apple's scripts that resizes a Safari window to full screen. :-)

Applescript:

set resolution to desktop_size()

on desktop_size()
   tell application "System Events"
       tell process "Finder"
           repeat with i from 1 to the count of windows
               if the position of window i is {0, 0} then
                   return the size of window i
               end if
           end repeat
       end tell
   end tell
end desktop_size

-- Rob


Filed under: System

Offline

 

#4 2004-07-17 11:05:23 am

jobu
Member
From: phxaz
Registered: 2004-01-17
Posts: 908
Website

Re: Full Screen Windows - Really Cool

You're right, this does work.  I stand corrected.  I don't like that it requires 'enabled for assistive devices' turned on, though.  Having more interest in developing apps than scripts, I think there are a handful of reasons why other ways might be better.  If it's being used in a personal, predictable environment it would be OK.  But in this case, you could just hardcode the dimensions. smile

j


The saddest thing I ever did see was a woodpecker peckin' at a plastic tree.
- Shel Silverstein

Offline

 

#5 2004-07-17 12:14:34 pm

jonn8
Member
From: New York
Registered: 2003-05-01
Posts: 1763
Website

Re: Full Screen Windows - Really Cool

Since you're in AS Studio, it's even easier with a method call to the NSScreen class:

--Open this script in a new Script Editor window.

set mainScreen to call method "mainScreen" of class "NSScreen"

--full frame:
set {x1, y1, x2, y2} to call method "frame" of mainScreen

--frame without menubar and Dock:
set {x1, y1, x2, y2} to call method "visibleFrame" of mainScreen

set bounds of window "main" to {x1, y1, x2, y2}

Jon

-------------------------
[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Offline

 

#6 2004-07-21 06:44:59 am

bwDreams
Member
From: Japan
Registered: 2003-11-21
Posts: 62
Website

Re: Full Screen Windows - Really Cool

Thanks for the info. (I`ve been away for a few days and am late getting back into the discussion, sorry.)

Jon, you mentioned:

--------------------------------
--full frame:
set {x1, y1, x2, y2} to call method "frame" of mainScreen

--frame without menubar and Dock:
set {x1, y1, x2, y2} to call method "visibleFrame" of mainScreen
--------------------------------

I have no problem with the "full frame" version (By the way, thank you very much) but I can`t get the "frame without menubar and Dock" version to work. It just gives me a full frame window like the "full frame" version. Any ideas?

Something else I noticed is that if you take out the:
    [fsWindow makeKeyAndOrderFront:fsWindow];
from the Fullscreen.m file then you get the desktop showing with no TitleBar. Is that cool or is that stange?


Follow Your Dreams

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.176 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)