2011-09-06 10:10:43 -04:00
|
|
|
/*
|
2011-10-12 13:40:35 -04:00
|
|
|
* Cocoa's event loop must be in main thread.
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
*
|
|
|
|
|
* Unless otherwise stated, all coordinate systems
|
|
|
|
|
* are bottom-left-based.
|
2011-09-06 10:10:43 -04:00
|
|
|
*/
|
|
|
|
|
|
2011-10-12 13:40:35 -04:00
|
|
|
#define Cursor OSXCursor
|
2011-09-06 10:10:43 -04:00
|
|
|
#define Point OSXPoint
|
|
|
|
|
#define Rect OSXRect
|
|
|
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
|
|
#undef Cursor
|
2011-10-12 13:40:35 -04:00
|
|
|
#undef Point
|
|
|
|
|
#undef Rect
|
2011-09-06 10:10:43 -04:00
|
|
|
|
|
|
|
|
#include <u.h>
|
|
|
|
|
#include <libc.h>
|
2011-10-12 13:40:35 -04:00
|
|
|
#include "cocoa-thread.h"
|
2011-09-06 10:10:43 -04:00
|
|
|
#include <draw.h>
|
|
|
|
|
#include <memdraw.h>
|
|
|
|
|
#include <keyboard.h>
|
|
|
|
|
#include <cursor.h>
|
|
|
|
|
#include "cocoa-screen.h"
|
|
|
|
|
#include "osx-keycodes.h"
|
|
|
|
|
#include "devdraw.h"
|
2011-12-09 22:21:09 -05:00
|
|
|
#include "bigarrow.h"
|
2011-09-06 10:10:43 -04:00
|
|
|
#include "glendapng.h"
|
|
|
|
|
|
|
|
|
|
AUTOFRAMEWORK(Cocoa)
|
|
|
|
|
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
#define LOG if(0)NSLog
|
|
|
|
|
#define panic sysfatal
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2011-10-12 13:40:35 -04:00
|
|
|
int usegestures = 0;
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
int useliveresizing = 0;
|
2011-09-19 08:58:59 -04:00
|
|
|
int useoldfullscreen = 0;
|
2011-10-23 18:47:29 -04:00
|
|
|
int usebigarrow = 0;
|
|
|
|
|
|
2013-08-06 23:44:06 -04:00
|
|
|
static void setprocname(const char*);
|
|
|
|
|
|
2012-10-16 13:55:44 -04:00
|
|
|
/*
|
2015-02-17 14:45:46 -05:00
|
|
|
* By default, devdraw uses retina displays.
|
|
|
|
|
* Set devdrawretina=0 in the environment to override.
|
2012-10-16 13:55:44 -04:00
|
|
|
*/
|
2015-02-17 14:45:46 -05:00
|
|
|
int devdrawretina = 1;
|
2012-10-16 13:55:44 -04:00
|
|
|
|
2011-09-06 10:10:43 -04:00
|
|
|
void
|
|
|
|
|
usage(void)
|
|
|
|
|
{
|
|
|
|
|
fprint(2, "usage: devdraw (don't run directly)\n");
|
2011-10-12 13:40:35 -04:00
|
|
|
threadexitsall("usage");
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
|
2011-12-09 22:21:09 -05:00
|
|
|
@interface appdelegate : NSObject @end
|
2011-09-19 08:58:59 -04:00
|
|
|
|
2011-09-06 10:10:43 -04:00
|
|
|
void
|
2011-10-12 13:40:35 -04:00
|
|
|
threadmain(int argc, char **argv)
|
2011-09-06 10:10:43 -04:00
|
|
|
{
|
2012-10-16 13:55:44 -04:00
|
|
|
char *envvar;
|
|
|
|
|
|
2011-09-06 10:10:43 -04:00
|
|
|
/*
|
|
|
|
|
* Move the protocol off stdin/stdout so that
|
|
|
|
|
* any inadvertent prints don't screw things up.
|
|
|
|
|
*/
|
|
|
|
|
dup(0,3);
|
|
|
|
|
dup(1,4);
|
|
|
|
|
close(0);
|
|
|
|
|
close(1);
|
|
|
|
|
open("/dev/null", OREAD);
|
|
|
|
|
open("/dev/null", OWRITE);
|
|
|
|
|
|
|
|
|
|
ARGBEGIN{
|
2011-10-12 13:40:35 -04:00
|
|
|
case 'D': /* for good ps -a listings */
|
|
|
|
|
break;
|
|
|
|
|
case 'f':
|
|
|
|
|
useoldfullscreen = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'g':
|
|
|
|
|
usegestures = 1;
|
2011-09-06 10:10:43 -04:00
|
|
|
break;
|
2011-10-23 18:47:29 -04:00
|
|
|
case 'b':
|
|
|
|
|
usebigarrow = 1;
|
|
|
|
|
break;
|
2011-09-06 10:10:43 -04:00
|
|
|
default:
|
|
|
|
|
usage();
|
|
|
|
|
}ARGEND
|
2013-08-06 23:44:06 -04:00
|
|
|
|
|
|
|
|
setprocname(argv0);
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2012-10-16 13:55:44 -04:00
|
|
|
if (envvar = getenv("devdrawretina"))
|
|
|
|
|
devdrawretina = atoi(envvar) > 0;
|
|
|
|
|
|
2011-10-03 18:16:09 -04:00
|
|
|
if(OSX_VERSION < 100700)
|
|
|
|
|
[NSAutoreleasePool new];
|
|
|
|
|
|
2011-09-06 10:10:43 -04:00
|
|
|
[NSApplication sharedApplication];
|
|
|
|
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
|
|
|
|
[NSApp setDelegate:[appdelegate new]];
|
|
|
|
|
[NSApp run];
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-12 13:40:35 -04:00
|
|
|
#define WIN win.ofs[win.isofs]
|
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
NSWindow *ofs[2]; /* ofs[1] for old fullscreen; ofs[0] else */
|
|
|
|
|
int isofs;
|
2011-11-08 13:23:55 -05:00
|
|
|
int isnfs;
|
2011-10-12 13:40:35 -04:00
|
|
|
NSView *content;
|
2012-08-03 13:26:46 -04:00
|
|
|
NSBitmapImageRep *img;
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
int needimg;
|
|
|
|
|
int deferflush;
|
2011-10-12 13:40:35 -04:00
|
|
|
NSCursor *cursor;
|
2012-10-16 13:55:44 -04:00
|
|
|
CGFloat topointscale;
|
|
|
|
|
CGFloat topixelscale;
|
2011-09-19 08:58:59 -04:00
|
|
|
} win;
|
|
|
|
|
|
2011-10-12 13:40:35 -04:00
|
|
|
struct
|
|
|
|
|
{
|
2011-12-09 22:21:09 -05:00
|
|
|
NSCursor *bigarrow;
|
2011-10-12 13:40:35 -04:00
|
|
|
int kbuttons;
|
|
|
|
|
int mbuttons;
|
2011-12-09 22:21:09 -05:00
|
|
|
NSPoint mpos;
|
2011-10-12 13:40:35 -04:00
|
|
|
int mscroll;
|
2012-01-16 17:04:28 -05:00
|
|
|
int willactivate;
|
2011-10-12 13:40:35 -04:00
|
|
|
} in;
|
|
|
|
|
|
2011-11-08 13:23:55 -05:00
|
|
|
static void hidebars(int);
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
static void flushimg(NSRect);
|
|
|
|
|
static void autoflushwin(int);
|
2011-09-19 08:58:59 -04:00
|
|
|
static void flushwin(void);
|
2011-10-12 13:40:35 -04:00
|
|
|
static void followzoombutton(NSRect);
|
2011-09-06 10:10:43 -04:00
|
|
|
static void getmousepos(void);
|
2011-09-19 08:58:59 -04:00
|
|
|
static void makeicon(void);
|
|
|
|
|
static void makemenu(void);
|
2011-12-09 22:21:09 -05:00
|
|
|
static void makewin(char*);
|
2011-10-03 18:16:09 -04:00
|
|
|
static void sendmouse(void);
|
2011-12-09 22:21:09 -05:00
|
|
|
static void setcursor0(Cursor*);
|
2011-09-26 08:19:56 -07:00
|
|
|
static void togglefs(void);
|
2012-01-19 15:14:17 -05:00
|
|
|
static void acceptresizing(int);
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2011-12-09 22:21:09 -05:00
|
|
|
static NSCursor* makecursor(Cursor*);
|
|
|
|
|
|
2012-10-16 13:55:44 -04:00
|
|
|
static NSSize winsizepixels();
|
|
|
|
|
static NSSize winsizepoints();
|
|
|
|
|
static NSRect scalerect(NSRect, CGFloat);
|
|
|
|
|
static NSPoint scalepoint(NSPoint, CGFloat);
|
|
|
|
|
static NSRect dilate(NSRect);
|
|
|
|
|
|
2011-09-06 10:10:43 -04:00
|
|
|
@implementation appdelegate
|
|
|
|
|
- (void)applicationDidFinishLaunching:(id)arg
|
|
|
|
|
{
|
2011-12-09 22:21:09 -05:00
|
|
|
in.bigarrow = makecursor(&bigarrow);
|
2011-09-19 08:58:59 -04:00
|
|
|
makeicon();
|
|
|
|
|
makemenu();
|
|
|
|
|
[NSApplication
|
|
|
|
|
detachDrawingThread:@selector(callservep9p:)
|
|
|
|
|
toTarget:[self class] withObject:nil];
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
2011-09-19 08:58:59 -04:00
|
|
|
- (void)windowDidBecomeKey:(id)arg
|
2011-09-06 10:10:43 -04:00
|
|
|
{
|
2011-09-19 08:58:59 -04:00
|
|
|
getmousepos();
|
2011-10-03 18:16:09 -04:00
|
|
|
sendmouse();
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
- (void)windowDidResize:(id)arg
|
|
|
|
|
{
|
2011-09-19 08:58:59 -04:00
|
|
|
getmousepos();
|
2011-10-03 18:16:09 -04:00
|
|
|
sendmouse();
|
2011-09-19 08:58:59 -04:00
|
|
|
}
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
- (void)windowWillStartLiveResize:(id)arg
|
|
|
|
|
{
|
|
|
|
|
if(useliveresizing == 0)
|
|
|
|
|
[win.content setHidden:YES];
|
|
|
|
|
}
|
2011-09-19 08:58:59 -04:00
|
|
|
- (void)windowDidEndLiveResize:(id)arg
|
|
|
|
|
{
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
if(useliveresizing == 0)
|
|
|
|
|
[win.content setHidden:NO];
|
2011-09-26 08:19:56 -07:00
|
|
|
}
|
|
|
|
|
- (void)windowDidChangeScreen:(id)arg
|
|
|
|
|
{
|
2011-11-08 13:23:55 -05:00
|
|
|
if(win.isnfs || win.isofs)
|
|
|
|
|
hidebars(1);
|
2011-10-12 13:40:35 -04:00
|
|
|
[win.ofs[1] setFrame:[[WIN screen] frame] display:YES];
|
|
|
|
|
}
|
|
|
|
|
- (BOOL)windowShouldZoom:(id)arg toFrame:(NSRect)r
|
|
|
|
|
{
|
|
|
|
|
followzoombutton(r);
|
|
|
|
|
return YES;
|
2011-09-26 08:19:56 -07:00
|
|
|
}
|
2011-09-06 10:10:43 -04:00
|
|
|
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(id)arg
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
2012-01-16 17:04:28 -05:00
|
|
|
- (void)applicationDidBecomeActive:(id)arg{ in.willactivate = 0;}
|
2012-01-19 15:14:17 -05:00
|
|
|
- (void)windowWillEnterFullScreen:(id)arg{ acceptresizing(1);}
|
2011-11-08 13:23:55 -05:00
|
|
|
- (void)windowDidEnterFullScreen:(id)arg{ win.isnfs = 1; hidebars(1);}
|
|
|
|
|
- (void)windowWillExitFullScreen:(id)arg{ win.isnfs = 0; hidebars(0);}
|
|
|
|
|
- (void)windowDidExitFullScreen:(id)arg
|
|
|
|
|
{
|
|
|
|
|
NSButton *b;
|
|
|
|
|
|
|
|
|
|
b = [WIN standardWindowButton:NSWindowMiniaturizeButton];
|
|
|
|
|
|
|
|
|
|
if([b isEnabled] == 0){
|
|
|
|
|
[b setEnabled:YES];
|
|
|
|
|
hidebars(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
- (void)windowWillClose:(id)arg
|
|
|
|
|
{
|
|
|
|
|
autoflushwin(0); /* can crash otherwise */
|
|
|
|
|
}
|
2011-11-08 13:23:55 -05:00
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
+ (void)callservep9p:(id)arg
|
2011-09-06 10:10:43 -04:00
|
|
|
{
|
|
|
|
|
servep9p();
|
|
|
|
|
[NSApp terminate:self];
|
|
|
|
|
}
|
2012-01-16 17:12:10 -05:00
|
|
|
- (void)plumbmanual:(id)arg
|
|
|
|
|
{
|
|
|
|
|
if(fork() != 0)
|
|
|
|
|
return;
|
|
|
|
|
execl("plumb", "plumb", "devdraw(1)", nil);
|
|
|
|
|
}
|
2011-09-19 08:58:59 -04:00
|
|
|
+ (void)callflushwin:(id)arg{ flushwin();}
|
2011-09-26 08:19:56 -07:00
|
|
|
- (void)calltogglefs:(id)arg{ togglefs();}
|
2011-12-09 22:21:09 -05:00
|
|
|
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
+ (void)callflushimg:(NSValue*)v{ flushimg([v rectValue]);}
|
2011-12-09 22:21:09 -05:00
|
|
|
+ (void)callmakewin:(NSValue*)v{ makewin([v pointerValue]);}
|
|
|
|
|
+ (void)callsetcursor0:(NSValue*)v{ setcursor0([v pointerValue]);}
|
2011-09-06 10:10:43 -04:00
|
|
|
@end
|
|
|
|
|
|
2011-10-12 13:40:35 -04:00
|
|
|
static Memimage* initimg(void);
|
2011-09-19 08:58:59 -04:00
|
|
|
|
2011-09-06 10:10:43 -04:00
|
|
|
Memimage*
|
|
|
|
|
attachscreen(char *label, char *winsize)
|
|
|
|
|
{
|
|
|
|
|
static int first = 1;
|
|
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
if(first)
|
|
|
|
|
first = 0;
|
|
|
|
|
else
|
2011-09-06 10:10:43 -04:00
|
|
|
panic("attachscreen called twice");
|
|
|
|
|
|
|
|
|
|
if(label == nil)
|
|
|
|
|
label = "gnot a label";
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
if(strcmp(label, "page") == 0)
|
|
|
|
|
useliveresizing = 1;
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2011-10-12 13:40:35 -04:00
|
|
|
/*
|
|
|
|
|
* Create window in main thread, else no cursor
|
|
|
|
|
* change while resizing.
|
|
|
|
|
*/
|
2011-09-06 10:10:43 -04:00
|
|
|
[appdelegate
|
|
|
|
|
performSelectorOnMainThread:@selector(callmakewin:)
|
2011-12-09 22:21:09 -05:00
|
|
|
withObject:[NSValue valueWithPointer:winsize]
|
2011-09-06 10:10:43 -04:00
|
|
|
waitUntilDone:YES];
|
2011-12-09 22:21:09 -05:00
|
|
|
// makewin(winsize);
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
kicklabel(label);
|
2011-10-12 13:40:35 -04:00
|
|
|
return initimg();
|
2011-09-19 08:58:59 -04:00
|
|
|
}
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2011-12-09 22:21:09 -05:00
|
|
|
@interface appwin : NSWindow @end
|
|
|
|
|
@interface contentview : NSView @end
|
2011-09-19 08:58:59 -04:00
|
|
|
|
|
|
|
|
@implementation appwin
|
|
|
|
|
- (NSTimeInterval)animationResizeTime:(NSRect)r
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
2011-09-26 08:19:56 -07:00
|
|
|
- (BOOL)canBecomeKeyWindow
|
|
|
|
|
{
|
2011-12-09 22:21:09 -05:00
|
|
|
return YES; /* else no keyboard for old fullscreen */
|
2011-09-26 08:19:56 -07:00
|
|
|
}
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
- (void)makeKeyAndOrderFront:(id)arg
|
|
|
|
|
{
|
|
|
|
|
LOG(@"makeKeyAndOrderFront");
|
|
|
|
|
|
|
|
|
|
autoflushwin(1);
|
|
|
|
|
[win.content setHidden:NO];
|
|
|
|
|
[super makeKeyAndOrderFront:arg];
|
|
|
|
|
}
|
|
|
|
|
- (void)miniaturize:(id)arg
|
|
|
|
|
{
|
|
|
|
|
[super miniaturize:arg];
|
|
|
|
|
[NSApp hide:nil];
|
|
|
|
|
|
|
|
|
|
[win.content setHidden:YES];
|
|
|
|
|
autoflushwin(0);
|
|
|
|
|
}
|
|
|
|
|
- (void)deminiaturize:(id)arg
|
|
|
|
|
{
|
|
|
|
|
autoflushwin(1);
|
|
|
|
|
[win.content setHidden:NO];
|
|
|
|
|
[super deminiaturize:arg];
|
|
|
|
|
}
|
2011-09-19 08:58:59 -04:00
|
|
|
@end
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2012-03-05 15:38:59 -05:00
|
|
|
double
|
|
|
|
|
min(double a, double b)
|
|
|
|
|
{
|
|
|
|
|
return a<b? a : b;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
Winstyle = NSTitledWindowMask
|
|
|
|
|
| NSClosableWindowMask
|
|
|
|
|
| NSMiniaturizableWindowMask
|
|
|
|
|
| NSResizableWindowMask
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
2011-12-09 22:21:09 -05:00
|
|
|
makewin(char *s)
|
2011-09-06 10:10:43 -04:00
|
|
|
{
|
|
|
|
|
NSRect r, sr;
|
2011-10-12 13:40:35 -04:00
|
|
|
NSWindow *w;
|
2011-09-06 10:10:43 -04:00
|
|
|
Rectangle wr;
|
2011-10-12 13:40:35 -04:00
|
|
|
int i, set;
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2011-09-26 08:19:56 -07:00
|
|
|
sr = [[NSScreen mainScreen] frame];
|
2012-03-05 15:38:59 -05:00
|
|
|
r = [[NSScreen mainScreen] visibleFrame];
|
2011-09-06 10:10:43 -04:00
|
|
|
|
|
|
|
|
if(s && *s){
|
2011-09-19 08:58:59 -04:00
|
|
|
if(parsewinsize(s, &wr, &set) < 0)
|
2011-09-06 10:10:43 -04:00
|
|
|
sysfatal("%r");
|
|
|
|
|
}else{
|
|
|
|
|
wr = Rect(0, 0, sr.size.width*2/3, sr.size.height*2/3);
|
2011-09-19 08:58:59 -04:00
|
|
|
set = 0;
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
|
2012-03-05 15:38:59 -05:00
|
|
|
r.origin.x = wr.min.x;
|
|
|
|
|
r.origin.y = sr.size.height-wr.max.y; /* winsize is top-left-based */
|
|
|
|
|
r.size.width = min(Dx(wr), r.size.width);
|
|
|
|
|
r.size.height = min(Dy(wr), r.size.height);
|
2011-10-12 13:40:35 -04:00
|
|
|
r = [NSWindow contentRectForFrameRect:r
|
|
|
|
|
styleMask:Winstyle];
|
|
|
|
|
|
|
|
|
|
w = [[appwin alloc]
|
2011-09-06 10:10:43 -04:00
|
|
|
initWithContentRect:r
|
2011-09-19 08:58:59 -04:00
|
|
|
styleMask:Winstyle
|
2011-09-26 08:19:56 -07:00
|
|
|
backing:NSBackingStoreBuffered defer:NO];
|
2014-11-16 01:02:57 +01:00
|
|
|
[w setTitle:@"devdraw"];
|
|
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
if(!set)
|
2011-10-12 13:40:35 -04:00
|
|
|
[w center];
|
2011-09-06 10:10:43 -04:00
|
|
|
#if OSX_VERSION >= 100700
|
2011-10-12 13:40:35 -04:00
|
|
|
[w setCollectionBehavior:
|
|
|
|
|
NSWindowCollectionBehaviorFullScreenPrimary];
|
2011-09-06 10:10:43 -04:00
|
|
|
#endif
|
2011-10-12 13:40:35 -04:00
|
|
|
[w setContentMinSize:NSMakeSize(128,128)];
|
2011-09-26 08:19:56 -07:00
|
|
|
|
2011-10-12 13:40:35 -04:00
|
|
|
win.ofs[0] = w;
|
|
|
|
|
win.ofs[1] = [[appwin alloc]
|
2011-09-26 08:19:56 -07:00
|
|
|
initWithContentRect:sr
|
|
|
|
|
styleMask:NSBorderlessWindowMask
|
2011-10-12 13:40:35 -04:00
|
|
|
backing:NSBackingStoreBuffered defer:YES];
|
|
|
|
|
for(i=0; i<2; i++){
|
|
|
|
|
[win.ofs[i] setAcceptsMouseMovedEvents:YES];
|
|
|
|
|
[win.ofs[i] setDelegate:[NSApp delegate]];
|
|
|
|
|
[win.ofs[i] setDisplaysWhenScreenProfileChanges:NO];
|
|
|
|
|
}
|
|
|
|
|
win.isofs = 0;
|
2011-12-09 22:21:09 -05:00
|
|
|
win.content = [contentview new];
|
2011-10-12 13:40:35 -04:00
|
|
|
[WIN setContentView:win.content];
|
2014-11-16 01:02:57 +01:00
|
|
|
|
|
|
|
|
topwin();
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
static Memimage*
|
2011-10-12 13:40:35 -04:00
|
|
|
initimg(void)
|
2011-09-06 10:10:43 -04:00
|
|
|
{
|
2012-08-03 13:26:46 -04:00
|
|
|
Memimage *i;
|
2012-10-16 13:55:44 -04:00
|
|
|
NSSize size, ptsize;
|
2011-09-06 10:10:43 -04:00
|
|
|
Rectangle r;
|
|
|
|
|
|
2012-10-16 13:55:44 -04:00
|
|
|
size = winsizepixels();
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
LOG(@"initimg %.0f %.0f", size.width, size.height);
|
2011-09-06 10:10:43 -04:00
|
|
|
|
|
|
|
|
r = Rect(0, 0, size.width, size.height);
|
2012-08-03 13:26:46 -04:00
|
|
|
i = allocmemimage(r, XBGR32);
|
|
|
|
|
if(i == nil)
|
2011-09-06 10:10:43 -04:00
|
|
|
panic("allocmemimage: %r");
|
2012-08-03 13:26:46 -04:00
|
|
|
if(i->data == nil)
|
2011-10-12 13:40:35 -04:00
|
|
|
panic("i->data == nil");
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2012-08-03 13:26:46 -04:00
|
|
|
win.img = [[NSBitmapImageRep alloc]
|
|
|
|
|
initWithBitmapDataPlanes:&i->data->bdata
|
|
|
|
|
pixelsWide:Dx(r)
|
|
|
|
|
pixelsHigh:Dy(r)
|
|
|
|
|
bitsPerSample:8
|
|
|
|
|
samplesPerPixel:3
|
|
|
|
|
hasAlpha:NO
|
|
|
|
|
isPlanar:NO
|
|
|
|
|
colorSpaceName:NSDeviceRGBColorSpace
|
|
|
|
|
bytesPerRow:bytesperline(r, 32)
|
|
|
|
|
bitsPerPixel:32];
|
2012-10-16 13:55:44 -04:00
|
|
|
ptsize = winsizepoints();
|
|
|
|
|
[win.img setSize: ptsize];
|
|
|
|
|
win.topixelscale = size.width / ptsize.width;
|
|
|
|
|
win.topointscale = 1.0f / win.topixelscale;
|
2012-11-25 23:55:27 -05:00
|
|
|
|
|
|
|
|
// NOTE: This is not really the display DPI.
|
|
|
|
|
// On retina, topixelscale is 2; otherwise it is 1.
|
|
|
|
|
// This formula gives us 220 for retina, 110 otherwise.
|
|
|
|
|
// That's not quite right but it's close to correct.
|
|
|
|
|
// http://en.wikipedia.org/wiki/List_of_displays_by_pixel_density#Apple
|
|
|
|
|
displaydpi = win.topixelscale * 110;
|
|
|
|
|
|
2012-08-03 13:26:46 -04:00
|
|
|
return i;
|
2011-09-19 08:58:59 -04:00
|
|
|
}
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2012-11-25 23:38:14 -05:00
|
|
|
void
|
|
|
|
|
resizeimg(void)
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
{
|
2012-08-03 13:26:46 -04:00
|
|
|
[win.img release];
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
_drawreplacescreenimage(initimg());
|
2012-08-03 13:26:46 -04:00
|
|
|
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
mouseresized = 1;
|
|
|
|
|
sendmouse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
waitimg(int msec)
|
|
|
|
|
{
|
|
|
|
|
NSDate *limit;
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
win.needimg = 1;
|
|
|
|
|
win.deferflush = 0;
|
|
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
|
limit = [NSDate dateWithTimeIntervalSinceNow:msec/1000.0];
|
|
|
|
|
do{
|
|
|
|
|
[[NSRunLoop currentRunLoop]
|
|
|
|
|
runMode:@"waiting image"
|
|
|
|
|
beforeDate:limit];
|
|
|
|
|
n++;
|
|
|
|
|
}while(win.needimg && [(NSDate*)[NSDate date] compare:limit]<0);
|
|
|
|
|
|
|
|
|
|
win.deferflush = win.needimg;
|
|
|
|
|
|
|
|
|
|
LOG(@"waitimg %s (%d loop)", win.needimg?"defer":"ok", n);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
void
|
|
|
|
|
_flushmemscreen(Rectangle r)
|
|
|
|
|
{
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
static int n;
|
2011-12-09 22:21:09 -05:00
|
|
|
NSRect rect;
|
|
|
|
|
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
LOG(@"_flushmemscreen");
|
|
|
|
|
|
|
|
|
|
if(n==0){
|
|
|
|
|
n++;
|
|
|
|
|
return; /* to skip useless white init rect */
|
|
|
|
|
}else
|
|
|
|
|
if(n==1){
|
|
|
|
|
[WIN performSelectorOnMainThread:
|
|
|
|
|
@selector(makeKeyAndOrderFront:)
|
|
|
|
|
withObject:nil
|
|
|
|
|
waitUntilDone:NO];
|
|
|
|
|
n++;
|
|
|
|
|
}else
|
|
|
|
|
if([win.content canDraw] == 0)
|
|
|
|
|
return;
|
2011-09-06 10:10:43 -04:00
|
|
|
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
rect = NSMakeRect(r.min.x, r.min.y, Dx(r), Dy(r));
|
2011-09-19 08:58:59 -04:00
|
|
|
[appdelegate
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
performSelectorOnMainThread:@selector(callflushimg:)
|
2011-12-09 22:21:09 -05:00
|
|
|
withObject:[NSValue valueWithRect:rect]
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
waitUntilDone:YES
|
|
|
|
|
modes:[NSArray arrayWithObjects:
|
|
|
|
|
NSRunLoopCommonModes,
|
|
|
|
|
@"waiting image", nil]];
|
2011-09-19 08:58:59 -04:00
|
|
|
}
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2012-08-03 13:26:46 -04:00
|
|
|
static void drawimg(NSRect, uint);
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
static void drawresizehandle(void);
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
Pixel = 1,
|
|
|
|
|
Barsize = 4*Pixel,
|
|
|
|
|
Cornersize = 3*Pixel,
|
|
|
|
|
Handlesize = 3*Barsize + 1*Pixel,
|
|
|
|
|
};
|
2011-10-03 18:16:09 -04:00
|
|
|
|
2012-10-16 13:55:44 -04:00
|
|
|
/*
|
|
|
|
|
* |rect| is in pixel coordinates.
|
|
|
|
|
*/
|
2011-09-19 08:58:59 -04:00
|
|
|
static void
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
flushimg(NSRect rect)
|
2011-09-19 08:58:59 -04:00
|
|
|
{
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
NSRect dr, r;
|
2011-09-19 08:58:59 -04:00
|
|
|
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
if([win.content lockFocusIfCanDraw] == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if(win.needimg){
|
2012-10-16 13:55:44 -04:00
|
|
|
if(!NSEqualSizes(scalerect(rect, win.topointscale).size, [win.img size])){
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
LOG(@"flushimg reject %.0f %.0f",
|
|
|
|
|
rect.size.width, rect.size.height);
|
|
|
|
|
[win.content unlockFocus];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
win.needimg = 0;
|
|
|
|
|
}else
|
|
|
|
|
win.deferflush = 1;
|
|
|
|
|
|
|
|
|
|
LOG(@"flushimg ok %.0f %.0f", rect.size.width, rect.size.height);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Unless we are inside "drawRect", we have to round
|
|
|
|
|
* the corners ourselves, if this is the custom.
|
|
|
|
|
* "NSCompositeSourceIn" can do that, but we don't
|
|
|
|
|
* apply it to the whole rectangle, because this
|
|
|
|
|
* slows down trackpad scrolling considerably in
|
|
|
|
|
* Acme.
|
|
|
|
|
*/
|
|
|
|
|
r = [win.content bounds];
|
2012-10-16 13:55:44 -04:00
|
|
|
rect = dilate(scalerect(rect, win.topointscale));
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
r.size.height -= Cornersize;
|
|
|
|
|
dr = NSIntersectionRect(r, rect);
|
2012-10-16 13:55:44 -04:00
|
|
|
LOG(@"r %.0f %.0f", r.origin.x, r.origin.y, rect.size.width, rect.size.height);
|
|
|
|
|
LOG(@"rect in points %f %f %.0f %.0f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
|
|
|
|
|
LOG(@"dr in points %f %f %.0f %.0f", dr.origin.x, dr.origin.y, dr.size.width, dr.size.height);
|
2012-08-03 13:26:46 -04:00
|
|
|
drawimg(dr, NSCompositeCopy);
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
|
|
|
|
|
r.origin.y = r.size.height;
|
|
|
|
|
r.size = NSMakeSize(Cornersize, Cornersize);
|
|
|
|
|
dr = NSIntersectionRect(r, rect);
|
2012-08-03 13:26:46 -04:00
|
|
|
drawimg(dr, NSCompositeSourceIn);
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
|
2012-08-03 13:26:46 -04:00
|
|
|
r.origin.x = [win.img size].width - Cornersize;
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
dr = NSIntersectionRect(r, rect);
|
2012-08-03 13:26:46 -04:00
|
|
|
drawimg(dr, NSCompositeSourceIn);
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
|
|
|
|
|
r.size.width = r.origin.x - Cornersize;
|
|
|
|
|
r.origin.x -= r.size.width;
|
|
|
|
|
dr = NSIntersectionRect(r, rect);
|
2012-08-03 13:26:46 -04:00
|
|
|
drawimg(dr, NSCompositeCopy);
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
|
|
|
|
|
if(OSX_VERSION<100700 && win.isofs==0){
|
2012-08-03 13:26:46 -04:00
|
|
|
r.origin.x = [win.img size].width - Handlesize;
|
|
|
|
|
r.origin.y = [win.img size].height - Handlesize;
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
r.size = NSMakeSize(Handlesize, Handlesize);
|
|
|
|
|
if(NSIntersectsRect(r, rect))
|
|
|
|
|
drawresizehandle();
|
2011-09-19 08:58:59 -04:00
|
|
|
}
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
[win.content unlockFocus];
|
|
|
|
|
}
|
2011-09-19 08:58:59 -04:00
|
|
|
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
static void
|
|
|
|
|
autoflushwin(int set)
|
|
|
|
|
{
|
|
|
|
|
static NSTimer *t;
|
2011-10-12 13:40:35 -04:00
|
|
|
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
if(set){
|
|
|
|
|
if(t)
|
|
|
|
|
return;
|
2011-10-12 13:40:35 -04:00
|
|
|
/*
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
* We need "NSRunLoopCommonModes", otherwise the
|
|
|
|
|
* timer will not fire during live resizing.
|
2011-10-12 13:40:35 -04:00
|
|
|
*/
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
t = [NSTimer
|
|
|
|
|
timerWithTimeInterval:0.033
|
|
|
|
|
target:[appdelegate class]
|
|
|
|
|
selector:@selector(callflushwin:) userInfo:nil
|
|
|
|
|
repeats:YES];
|
|
|
|
|
[[NSRunLoop currentRunLoop] addTimer:t
|
|
|
|
|
forMode:NSRunLoopCommonModes];
|
|
|
|
|
}else{
|
|
|
|
|
[t invalidate];
|
|
|
|
|
t = nil;
|
|
|
|
|
win.deferflush = 0;
|
2011-09-19 08:58:59 -04:00
|
|
|
}
|
|
|
|
|
}
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
static void
|
|
|
|
|
flushwin(void)
|
|
|
|
|
{
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
if(win.deferflush && win.needimg==0){
|
2011-10-12 13:40:35 -04:00
|
|
|
[WIN flushWindow];
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
win.deferflush = 0;
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-16 13:55:44 -04:00
|
|
|
/*
|
|
|
|
|
* |dr| is sized in points. What if I make it pixels?
|
|
|
|
|
*/
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
static void
|
2012-08-03 13:26:46 -04:00
|
|
|
drawimg(NSRect dr, uint op)
|
2011-10-03 18:16:09 -04:00
|
|
|
{
|
2012-08-03 13:26:46 -04:00
|
|
|
CGContextRef c;
|
|
|
|
|
CGImageRef i;
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
NSRect sr;
|
|
|
|
|
|
|
|
|
|
if(NSIsEmptyRect(dr))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
sr = [win.content convertRect:dr fromView:nil];
|
2012-10-16 13:55:44 -04:00
|
|
|
LOG(@"before dr: %f %f %f %f\n", dr.origin.x, dr.origin.y, dr.size.width, dr.size.height);
|
|
|
|
|
LOG(@"before sr: %f %f %f %f\n", sr.origin.x, sr.origin.y, sr.size.width, sr.size.height);
|
|
|
|
|
|
|
|
|
|
dr = scalerect(dr, win.topixelscale);
|
|
|
|
|
sr = scalerect(sr, win.topixelscale);
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
|
2012-10-16 13:55:44 -04:00
|
|
|
LOG(@"dr: %f %f %f %f\n", dr.origin.x, dr.origin.y, dr.size.width, dr.size.height);
|
|
|
|
|
LOG(@"sr: %f %f %f %f\n", sr.origin.x, sr.origin.y, sr.size.width, sr.size.height);
|
2012-08-03 13:26:46 -04:00
|
|
|
if(OSX_VERSION >= 100800){
|
|
|
|
|
i = CGImageCreateWithImageInRect([win.img CGImage], NSRectToCGRect(dr));
|
|
|
|
|
c = [[WIN graphicsContext] graphicsPort];
|
|
|
|
|
|
|
|
|
|
CGContextSaveGState(c);
|
|
|
|
|
if(op == NSCompositeSourceIn)
|
|
|
|
|
CGContextSetBlendMode(c, kCGBlendModeSourceIn);
|
2012-10-16 13:55:44 -04:00
|
|
|
LOG(@"wim.img size %f %f\n", [win.img size].width, [win.img size].height);
|
2012-08-03 13:26:46 -04:00
|
|
|
CGContextTranslateCTM(c, 0, [win.img size].height);
|
2012-10-16 13:55:44 -04:00
|
|
|
CGContextScaleCTM(c, win.topointscale, -win.topointscale);
|
2012-08-03 13:26:46 -04:00
|
|
|
CGContextDrawImage(c, NSRectToCGRect(sr), i);
|
|
|
|
|
CGContextRestoreGState(c);
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
|
2012-08-03 13:26:46 -04:00
|
|
|
CGImageRelease(i);
|
|
|
|
|
}else{
|
|
|
|
|
[win.img drawInRect:dr fromRect:sr
|
|
|
|
|
operation:op fraction:1
|
|
|
|
|
respectFlipped:YES hints:nil];
|
|
|
|
|
}
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
// NSFrameRect(dr);
|
|
|
|
|
}
|
2011-10-03 18:16:09 -04:00
|
|
|
|
|
|
|
|
static void
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
drawresizehandle(void)
|
2011-10-03 18:16:09 -04:00
|
|
|
{
|
2011-10-12 13:40:35 -04:00
|
|
|
NSColor *color[Barsize];
|
|
|
|
|
NSPoint a,b;
|
|
|
|
|
Point c;
|
|
|
|
|
int i,j;
|
2011-10-03 18:16:09 -04:00
|
|
|
|
2012-08-03 13:26:46 -04:00
|
|
|
c = Pt([win.img size].width, [win.img size].height);
|
2011-10-03 18:16:09 -04:00
|
|
|
|
2011-10-12 13:40:35 -04:00
|
|
|
[[WIN graphicsContext] setShouldAntialias:NO];
|
2011-10-03 18:16:09 -04:00
|
|
|
|
2011-10-12 13:40:35 -04:00
|
|
|
color[0] = [NSColor clearColor];
|
|
|
|
|
color[1] = [NSColor darkGrayColor];
|
|
|
|
|
color[2] = [NSColor lightGrayColor];
|
|
|
|
|
color[3] = [NSColor whiteColor];
|
2011-10-03 18:16:09 -04:00
|
|
|
|
2011-10-12 13:40:35 -04:00
|
|
|
for(i=1; i+Barsize <= Handlesize; )
|
|
|
|
|
for(j=0; j<Barsize; j++){
|
|
|
|
|
[color[j] setStroke];
|
|
|
|
|
i++;
|
|
|
|
|
a = NSMakePoint(c.x-i, c.y-1);
|
|
|
|
|
b = NSMakePoint(c.x-2, c.y+1-i);
|
|
|
|
|
[NSBezierPath strokeLineFromPoint:a toPoint:b];
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-03 18:16:09 -04:00
|
|
|
|
2011-09-06 10:10:43 -04:00
|
|
|
static void getgesture(NSEvent*);
|
|
|
|
|
static void getkeyboard(NSEvent*);
|
|
|
|
|
static void getmouse(NSEvent*);
|
2011-09-19 08:58:59 -04:00
|
|
|
static void gettouch(NSEvent*, int);
|
2011-12-09 22:21:09 -05:00
|
|
|
static void updatecursor(void);
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2011-12-09 22:21:09 -05:00
|
|
|
@implementation contentview
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
/*
|
|
|
|
|
* "drawRect" is called each time Cocoa needs an
|
|
|
|
|
* image, and each time we call "display". It is
|
|
|
|
|
* preceded by background painting, and followed by
|
|
|
|
|
* "flushWindow".
|
|
|
|
|
*/
|
2011-09-19 08:58:59 -04:00
|
|
|
- (void)drawRect:(NSRect)r
|
|
|
|
|
{
|
2011-10-12 13:40:35 -04:00
|
|
|
static int first = 1;
|
|
|
|
|
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
LOG(@"drawrect %.0f %.0f %.0f %.0f",
|
|
|
|
|
r.origin.x, r.origin.y, r.size.width, r.size.height);
|
2011-10-12 13:40:35 -04:00
|
|
|
|
|
|
|
|
if(first)
|
|
|
|
|
first = 0;
|
|
|
|
|
else
|
|
|
|
|
resizeimg();
|
|
|
|
|
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
if([WIN inLiveResize])
|
|
|
|
|
waitimg(100);
|
|
|
|
|
else
|
|
|
|
|
waitimg(500);
|
2011-10-12 13:40:35 -04:00
|
|
|
}
|
2011-09-19 08:58:59 -04:00
|
|
|
- (BOOL)isFlipped
|
|
|
|
|
{
|
2011-12-09 22:21:09 -05:00
|
|
|
return YES; /* to make the content's origin top left */
|
2011-09-19 08:58:59 -04:00
|
|
|
}
|
|
|
|
|
- (BOOL)acceptsFirstResponder
|
|
|
|
|
{
|
2011-12-09 22:21:09 -05:00
|
|
|
return YES; /* else no keyboard */
|
|
|
|
|
}
|
|
|
|
|
- (id)initWithFrame:(NSRect)r
|
|
|
|
|
{
|
|
|
|
|
[super initWithFrame:r];
|
|
|
|
|
[self setAcceptsTouchEvents:YES];
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
[self setHidden:YES]; /* to avoid early "drawRect" call */
|
2011-12-09 22:21:09 -05:00
|
|
|
return self;
|
|
|
|
|
}
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
- (void)setHidden:(BOOL)set
|
|
|
|
|
{
|
|
|
|
|
if(!set)
|
|
|
|
|
[WIN makeFirstResponder:self]; /* for keyboard focus */
|
|
|
|
|
[super setHidden:set];
|
|
|
|
|
}
|
2011-12-09 22:21:09 -05:00
|
|
|
- (void)cursorUpdate:(NSEvent*)e{ updatecursor();}
|
|
|
|
|
|
2011-09-06 10:10:43 -04:00
|
|
|
- (void)mouseMoved:(NSEvent*)e{ getmouse(e);}
|
|
|
|
|
- (void)mouseDown:(NSEvent*)e{ getmouse(e);}
|
|
|
|
|
- (void)mouseDragged:(NSEvent*)e{ getmouse(e);}
|
|
|
|
|
- (void)mouseUp:(NSEvent*)e{ getmouse(e);}
|
|
|
|
|
- (void)otherMouseDown:(NSEvent*)e{ getmouse(e);}
|
|
|
|
|
- (void)otherMouseDragged:(NSEvent*)e{ getmouse(e);}
|
|
|
|
|
- (void)otherMouseUp:(NSEvent*)e{ getmouse(e);}
|
|
|
|
|
- (void)rightMouseDown:(NSEvent*)e{ getmouse(e);}
|
|
|
|
|
- (void)rightMouseDragged:(NSEvent*)e{ getmouse(e);}
|
|
|
|
|
- (void)rightMouseUp:(NSEvent*)e{ getmouse(e);}
|
|
|
|
|
- (void)scrollWheel:(NSEvent*)e{ getmouse(e);}
|
|
|
|
|
|
|
|
|
|
- (void)keyDown:(NSEvent*)e{ getkeyboard(e);}
|
|
|
|
|
- (void)flagsChanged:(NSEvent*)e{ getkeyboard(e);}
|
|
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
- (void)magnifyWithEvent:(NSEvent*)e{ getgesture(e);}
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
- (void)touchesBeganWithEvent:(NSEvent*)e
|
2011-09-06 10:10:43 -04:00
|
|
|
{
|
2011-09-19 08:58:59 -04:00
|
|
|
gettouch(e, NSTouchPhaseBegan);
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
2011-09-19 08:58:59 -04:00
|
|
|
- (void)touchesMovedWithEvent:(NSEvent*)e
|
2011-09-06 10:10:43 -04:00
|
|
|
{
|
2011-09-19 08:58:59 -04:00
|
|
|
gettouch(e, NSTouchPhaseMoved);
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
2011-09-19 08:58:59 -04:00
|
|
|
- (void)touchesEndedWithEvent:(NSEvent*)e
|
|
|
|
|
{
|
|
|
|
|
gettouch(e, NSTouchPhaseEnded);
|
|
|
|
|
}
|
|
|
|
|
- (void)touchesCancelledWithEvent:(NSEvent*)e
|
|
|
|
|
{
|
|
|
|
|
gettouch(e, NSTouchPhaseCancelled);
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
2011-09-06 10:10:43 -04:00
|
|
|
static int keycvt[] =
|
|
|
|
|
{
|
|
|
|
|
[QZ_IBOOK_ENTER] '\n',
|
|
|
|
|
[QZ_RETURN] '\n',
|
|
|
|
|
[QZ_ESCAPE] 27,
|
|
|
|
|
[QZ_BACKSPACE] '\b',
|
|
|
|
|
[QZ_LALT] Kalt,
|
|
|
|
|
[QZ_LCTRL] Kctl,
|
|
|
|
|
[QZ_LSHIFT] Kshift,
|
|
|
|
|
[QZ_F1] KF+1,
|
|
|
|
|
[QZ_F2] KF+2,
|
|
|
|
|
[QZ_F3] KF+3,
|
|
|
|
|
[QZ_F4] KF+4,
|
|
|
|
|
[QZ_F5] KF+5,
|
|
|
|
|
[QZ_F6] KF+6,
|
|
|
|
|
[QZ_F7] KF+7,
|
|
|
|
|
[QZ_F8] KF+8,
|
|
|
|
|
[QZ_F9] KF+9,
|
|
|
|
|
[QZ_F10] KF+10,
|
|
|
|
|
[QZ_F11] KF+11,
|
|
|
|
|
[QZ_F12] KF+12,
|
|
|
|
|
[QZ_INSERT] Kins,
|
|
|
|
|
[QZ_DELETE] 0x7F,
|
|
|
|
|
[QZ_HOME] Khome,
|
|
|
|
|
[QZ_END] Kend,
|
|
|
|
|
[QZ_KP_PLUS] '+',
|
|
|
|
|
[QZ_KP_MINUS] '-',
|
|
|
|
|
[QZ_TAB] '\t',
|
|
|
|
|
[QZ_PAGEUP] Kpgup,
|
|
|
|
|
[QZ_PAGEDOWN] Kpgdown,
|
|
|
|
|
[QZ_UP] Kup,
|
|
|
|
|
[QZ_DOWN] Kdown,
|
|
|
|
|
[QZ_LEFT] Kleft,
|
|
|
|
|
[QZ_RIGHT] Kright,
|
|
|
|
|
[QZ_KP_MULTIPLY] '*',
|
|
|
|
|
[QZ_KP_DIVIDE] '/',
|
|
|
|
|
[QZ_KP_ENTER] '\n',
|
|
|
|
|
[QZ_KP_PERIOD] '.',
|
|
|
|
|
[QZ_KP0] '0',
|
|
|
|
|
[QZ_KP1] '1',
|
|
|
|
|
[QZ_KP2] '2',
|
|
|
|
|
[QZ_KP3] '3',
|
|
|
|
|
[QZ_KP4] '4',
|
|
|
|
|
[QZ_KP5] '5',
|
|
|
|
|
[QZ_KP6] '6',
|
|
|
|
|
[QZ_KP7] '7',
|
|
|
|
|
[QZ_KP8] '8',
|
|
|
|
|
[QZ_KP9] '9',
|
|
|
|
|
};
|
|
|
|
|
|
2012-01-16 17:02:06 -05:00
|
|
|
@interface apptext : NSTextView @end
|
|
|
|
|
|
|
|
|
|
@implementation apptext
|
|
|
|
|
- (void)doCommandBySelector:(SEL)s{} /* Esc key beeps otherwise */
|
|
|
|
|
- (void)insertText:(id)arg{} /* to avoid a latency after some time */
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
interpretdeadkey(NSEvent *e)
|
|
|
|
|
{
|
|
|
|
|
static apptext *t;
|
|
|
|
|
|
|
|
|
|
if(t == nil)
|
|
|
|
|
t = [apptext new];
|
|
|
|
|
[t interpretKeyEvents:[NSArray arrayWithObject:e]];
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 10:10:43 -04:00
|
|
|
static void
|
|
|
|
|
getkeyboard(NSEvent *e)
|
|
|
|
|
{
|
2012-01-16 17:08:31 -05:00
|
|
|
static int omod;
|
2011-10-12 13:40:35 -04:00
|
|
|
NSString *s;
|
2011-09-06 10:10:43 -04:00
|
|
|
char c;
|
2011-09-19 08:58:59 -04:00
|
|
|
int k, m;
|
|
|
|
|
uint code;
|
2011-09-06 10:10:43 -04:00
|
|
|
|
|
|
|
|
m = [e modifierFlags];
|
|
|
|
|
|
|
|
|
|
switch([e type]){
|
|
|
|
|
case NSKeyDown:
|
2011-10-12 13:40:35 -04:00
|
|
|
s = [e characters];
|
|
|
|
|
c = [s UTF8String][0];
|
|
|
|
|
|
2012-01-16 17:02:06 -05:00
|
|
|
interpretdeadkey(e);
|
|
|
|
|
|
2011-09-06 10:10:43 -04:00
|
|
|
if(m & NSCommandKeyMask){
|
2011-10-12 13:40:35 -04:00
|
|
|
if(' '<=c && c<='~')
|
2011-09-06 10:10:43 -04:00
|
|
|
keystroke(Kcmd+c);
|
2011-10-12 13:40:35 -04:00
|
|
|
break;
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
k = c;
|
|
|
|
|
code = [e keyCode];
|
2011-10-12 13:40:35 -04:00
|
|
|
if(code<nelem(keycvt) && keycvt[code])
|
2011-09-06 10:10:43 -04:00
|
|
|
k = keycvt[code];
|
2011-10-12 13:40:35 -04:00
|
|
|
if(k==0)
|
|
|
|
|
break;
|
|
|
|
|
if(k>0)
|
2011-09-06 10:10:43 -04:00
|
|
|
keystroke(k);
|
|
|
|
|
else
|
2011-10-12 13:40:35 -04:00
|
|
|
keystroke([s characterAtIndex:0]);
|
2011-09-06 10:10:43 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NSFlagsChanged:
|
2011-09-19 08:58:59 -04:00
|
|
|
if(in.mbuttons || in.kbuttons){
|
|
|
|
|
in.kbuttons = 0;
|
2011-09-06 10:10:43 -04:00
|
|
|
if(m & NSAlternateKeyMask)
|
2011-09-19 08:58:59 -04:00
|
|
|
in.kbuttons |= 2;
|
2011-09-06 10:10:43 -04:00
|
|
|
if(m & NSCommandKeyMask)
|
2011-09-19 08:58:59 -04:00
|
|
|
in.kbuttons |= 4;
|
2011-10-03 18:16:09 -04:00
|
|
|
sendmouse();
|
2011-09-06 10:10:43 -04:00
|
|
|
}else
|
2012-01-16 17:08:31 -05:00
|
|
|
if(m&NSAlternateKeyMask && (omod&NSAlternateKeyMask)==0)
|
2011-09-06 10:10:43 -04:00
|
|
|
keystroke(Kalt);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
panic("getkey: unexpected event type");
|
|
|
|
|
}
|
2012-01-16 17:08:31 -05:00
|
|
|
omod = m;
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
|
2011-12-09 22:21:09 -05:00
|
|
|
/*
|
|
|
|
|
* Devdraw does not use NSTrackingArea, that often
|
|
|
|
|
* forgets to update the cursor on entering and on
|
|
|
|
|
* leaving the area, and that sometimes stops sending
|
|
|
|
|
* us MouseMove events, at least on OS X Lion.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
updatecursor(void)
|
|
|
|
|
{
|
|
|
|
|
NSCursor *c;
|
|
|
|
|
int isdown, isinside;
|
|
|
|
|
|
|
|
|
|
isinside = NSPointInRect(in.mpos, [win.content bounds]);
|
|
|
|
|
isdown = (in.mbuttons || in.kbuttons);
|
|
|
|
|
|
|
|
|
|
if(win.cursor && (isinside || isdown))
|
|
|
|
|
c = win.cursor;
|
|
|
|
|
else if(isinside && usebigarrow)
|
|
|
|
|
c = in.bigarrow;
|
|
|
|
|
else
|
|
|
|
|
c = [NSCursor arrowCursor];
|
|
|
|
|
[c set];
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Without this trick, we can come back from the dock
|
|
|
|
|
* with a resize cursor.
|
|
|
|
|
*/
|
|
|
|
|
if(OSX_VERSION >= 100700)
|
|
|
|
|
[NSCursor unhide];
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-19 15:14:17 -05:00
|
|
|
static void
|
|
|
|
|
acceptresizing(int set)
|
|
|
|
|
{
|
|
|
|
|
uint old, style;
|
|
|
|
|
|
|
|
|
|
old = [WIN styleMask];
|
|
|
|
|
|
|
|
|
|
if((old | NSResizableWindowMask) != Winstyle)
|
|
|
|
|
return; /* when entering new fullscreen */
|
|
|
|
|
|
|
|
|
|
if(set)
|
|
|
|
|
style = Winstyle;
|
|
|
|
|
else
|
|
|
|
|
style = Winstyle & ~NSResizableWindowMask;
|
|
|
|
|
|
|
|
|
|
if(style != old)
|
|
|
|
|
[WIN setStyleMask:style];
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 10:10:43 -04:00
|
|
|
static void
|
|
|
|
|
getmousepos(void)
|
|
|
|
|
{
|
2012-01-19 15:14:17 -05:00
|
|
|
NSPoint p, q;
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2011-10-12 13:40:35 -04:00
|
|
|
p = [WIN mouseLocationOutsideOfEventStream];
|
2012-01-19 15:14:17 -05:00
|
|
|
q = [win.content convertPoint:p fromView:nil];
|
2012-10-16 13:55:44 -04:00
|
|
|
|
|
|
|
|
/* q is in point coordinates. in.mpos is in pixels. */
|
|
|
|
|
q = scalepoint(q, win.topixelscale);
|
|
|
|
|
|
2012-01-19 15:14:17 -05:00
|
|
|
in.mpos.x = round(q.x);
|
|
|
|
|
in.mpos.y = round(q.y);
|
2011-12-09 22:21:09 -05:00
|
|
|
|
|
|
|
|
updatecursor();
|
2012-01-16 17:11:36 -05:00
|
|
|
|
|
|
|
|
if(win.isnfs || win.isofs)
|
|
|
|
|
hidebars(1);
|
2012-01-19 15:14:17 -05:00
|
|
|
else if(OSX_VERSION>=100700 && [WIN inLiveResize]==0){
|
|
|
|
|
if(p.x<12 && p.y<12 && p.x>2 && p.y>2)
|
|
|
|
|
acceptresizing(0);
|
|
|
|
|
else
|
|
|
|
|
acceptresizing(1);
|
|
|
|
|
}
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
getmouse(NSEvent *e)
|
|
|
|
|
{
|
|
|
|
|
float d;
|
2011-09-19 08:58:59 -04:00
|
|
|
int b, m;
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2011-12-09 22:21:09 -05:00
|
|
|
if([WIN isKeyWindow] == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-09-06 10:10:43 -04:00
|
|
|
getmousepos();
|
|
|
|
|
|
|
|
|
|
switch([e type]){
|
|
|
|
|
case NSLeftMouseDown:
|
|
|
|
|
case NSLeftMouseUp:
|
|
|
|
|
case NSOtherMouseDown:
|
|
|
|
|
case NSOtherMouseUp:
|
|
|
|
|
case NSRightMouseDown:
|
|
|
|
|
case NSRightMouseUp:
|
|
|
|
|
b = [NSEvent pressedMouseButtons];
|
|
|
|
|
b = b&~6 | (b&4)>>1 | (b&2)<<1;
|
|
|
|
|
b = mouseswap(b);
|
|
|
|
|
|
|
|
|
|
if(b == 1){
|
|
|
|
|
m = [e modifierFlags];
|
2011-09-19 08:58:59 -04:00
|
|
|
if(m & NSAlternateKeyMask){
|
2012-01-16 17:08:31 -05:00
|
|
|
abortcompose();
|
2011-09-06 10:10:43 -04:00
|
|
|
b = 2;
|
|
|
|
|
}else
|
|
|
|
|
if(m & NSCommandKeyMask)
|
|
|
|
|
b = 4;
|
|
|
|
|
}
|
2011-09-19 08:58:59 -04:00
|
|
|
in.mbuttons = b;
|
2011-09-06 10:10:43 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NSScrollWheel:
|
|
|
|
|
#if OSX_VERSION >= 100700
|
|
|
|
|
d = [e scrollingDeltaY];
|
|
|
|
|
#else
|
|
|
|
|
d = [e deltaY];
|
|
|
|
|
#endif
|
|
|
|
|
if(d>0)
|
2011-09-19 08:58:59 -04:00
|
|
|
in.mscroll = 8;
|
|
|
|
|
else
|
|
|
|
|
if(d<0)
|
|
|
|
|
in.mscroll = 16;
|
2011-09-06 10:10:43 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NSMouseMoved:
|
|
|
|
|
case NSLeftMouseDragged:
|
|
|
|
|
case NSRightMouseDragged:
|
|
|
|
|
case NSOtherMouseDragged:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
panic("getmouse: unexpected event type");
|
|
|
|
|
}
|
2011-10-03 18:16:09 -04:00
|
|
|
sendmouse();
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
|
2012-01-20 22:31:00 -05:00
|
|
|
#define Minpinch 0.02
|
2011-09-06 10:10:43 -04:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
getgesture(NSEvent *e)
|
|
|
|
|
{
|
|
|
|
|
switch([e type]){
|
|
|
|
|
case NSEventTypeMagnify:
|
2012-01-20 22:31:00 -05:00
|
|
|
if(fabs([e magnification]) > Minpinch)
|
2011-09-26 08:19:56 -07:00
|
|
|
togglefs();
|
2011-09-06 10:10:43 -04:00
|
|
|
break;
|
2011-09-19 08:58:59 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void sendclick(int);
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
static uint
|
|
|
|
|
msec(void)
|
|
|
|
|
{
|
|
|
|
|
return nsec()/1000000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gettouch(NSEvent *e, int type)
|
|
|
|
|
{
|
2012-01-20 22:31:00 -05:00
|
|
|
static int tapping;
|
2011-09-19 08:58:59 -04:00
|
|
|
static uint taptime;
|
|
|
|
|
NSSet *set;
|
2012-01-20 22:31:00 -05:00
|
|
|
int p;
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
switch(type){
|
|
|
|
|
case NSTouchPhaseBegan:
|
|
|
|
|
p = NSTouchPhaseTouching;
|
|
|
|
|
set = [e touchesMatchingPhase:p inView:nil];
|
|
|
|
|
if(set.count == 3){
|
|
|
|
|
tapping = 1;
|
|
|
|
|
taptime = msec();
|
|
|
|
|
}else
|
|
|
|
|
if(set.count > 3)
|
|
|
|
|
tapping = 0;
|
2012-01-20 22:31:00 -05:00
|
|
|
break;
|
2011-09-19 08:58:59 -04:00
|
|
|
|
|
|
|
|
case NSTouchPhaseMoved:
|
2012-01-20 22:31:00 -05:00
|
|
|
tapping = 0;
|
|
|
|
|
break;
|
2011-09-19 08:58:59 -04:00
|
|
|
|
|
|
|
|
case NSTouchPhaseEnded:
|
|
|
|
|
p = NSTouchPhaseTouching;
|
|
|
|
|
set = [e touchesMatchingPhase:p inView:nil];
|
|
|
|
|
if(set.count == 0){
|
2012-01-20 22:31:00 -05:00
|
|
|
if(tapping && msec()-taptime<400)
|
2011-10-12 13:40:35 -04:00
|
|
|
sendclick(2);
|
2011-09-19 08:58:59 -04:00
|
|
|
tapping = 0;
|
|
|
|
|
}
|
2011-09-06 10:10:43 -04:00
|
|
|
break;
|
|
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
case NSTouchPhaseCancelled:
|
2011-09-06 10:10:43 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2011-10-12 13:40:35 -04:00
|
|
|
panic("gettouch: unexpected event type");
|
2011-09-19 08:58:59 -04:00
|
|
|
}
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-19 08:58:59 -04:00
|
|
|
sendclick(int b)
|
2011-09-06 10:10:43 -04:00
|
|
|
{
|
2011-09-19 08:58:59 -04:00
|
|
|
in.mbuttons = b;
|
2011-10-03 18:16:09 -04:00
|
|
|
sendmouse();
|
2011-09-19 08:58:59 -04:00
|
|
|
in.mbuttons = 0;
|
2011-10-03 18:16:09 -04:00
|
|
|
sendmouse();
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-10-03 18:16:09 -04:00
|
|
|
sendmouse(void)
|
2011-09-06 10:10:43 -04:00
|
|
|
{
|
2011-09-19 08:58:59 -04:00
|
|
|
NSSize size;
|
|
|
|
|
int b;
|
|
|
|
|
|
2012-10-16 13:55:44 -04:00
|
|
|
size = winsizepixels();
|
2011-09-19 08:58:59 -04:00
|
|
|
mouserect = Rect(0, 0, size.width, size.height);
|
|
|
|
|
|
|
|
|
|
b = in.kbuttons | in.mbuttons | in.mscroll;
|
|
|
|
|
mousetrack(in.mpos.x, in.mpos.y, b, msec());
|
|
|
|
|
in.mscroll = 0;
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
|
2012-10-16 13:55:44 -04:00
|
|
|
/*
|
|
|
|
|
* |p| is in pixels.
|
|
|
|
|
*/
|
2011-09-06 10:10:43 -04:00
|
|
|
void
|
|
|
|
|
setmouse(Point p)
|
|
|
|
|
{
|
2011-09-19 08:58:59 -04:00
|
|
|
static int first = 1;
|
2011-09-06 10:10:43 -04:00
|
|
|
NSPoint q;
|
|
|
|
|
NSRect r;
|
|
|
|
|
|
2012-01-16 17:04:28 -05:00
|
|
|
if([NSApp isActive]==0 && in.willactivate==0)
|
2011-12-09 22:21:09 -05:00
|
|
|
return;
|
|
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
if(first){
|
2011-10-12 13:40:35 -04:00
|
|
|
/* Try to move Acme's scrollbars without that! */
|
2011-09-19 08:58:59 -04:00
|
|
|
CGSetLocalEventsSuppressionInterval(0);
|
|
|
|
|
first = 0;
|
|
|
|
|
}
|
Devdraw now waits for the image: this means that
there is no more blank image when toggling
fullscreen, when unminimizing, or at startup; this
also means that we can live resize, but we only
enable live resizing with Page, because it seems
useless for other apps, and Acme and Sam bug with
it. The tradeoff is that bottom corners are
sometimes automatically rounded. There is a way to
prevent the rounding here:
http://parmanoir.com/Custom_NSThemeFrame
but this would obfuscate the code. Instead, we
make sure that the corners are always rounded.
Closing the window while its content is updated
causes an exception, without this patch. This
seems to happen regularly with stats(1).
This patch avoids a possible deadlock at startup,
which I never experienced. If I recollect right,
there is little chance that this happens on a
multi-core CPU.
Minimizing now activates next app in line, and
Devdraw now stops drawing while minimized.
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5499043
2012-03-05 15:54:26 -05:00
|
|
|
if([WIN inLiveResize])
|
|
|
|
|
return;
|
|
|
|
|
|
2012-10-16 13:55:44 -04:00
|
|
|
in.mpos = scalepoint(NSMakePoint(p.x, p.y), win.topointscale); // race condition
|
2011-12-09 22:21:09 -05:00
|
|
|
|
|
|
|
|
q = [win.content convertPoint:in.mpos toView:nil];
|
2011-10-12 13:40:35 -04:00
|
|
|
q = [WIN convertBaseToScreen:q];
|
2012-03-05 21:14:34 -05:00
|
|
|
|
|
|
|
|
r = [[[NSScreen screens] objectAtIndex:0] frame];
|
|
|
|
|
q.y = r.size.height - q.y; /* Quartz is top-left-based here */
|
2011-09-06 10:10:43 -04:00
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
CGWarpMouseCursorPosition(NSPointToCGPoint(q));
|
2011-10-12 13:40:35 -04:00
|
|
|
}
|
|
|
|
|
|
2012-10-16 13:55:44 -04:00
|
|
|
/*
|
|
|
|
|
* |r| is in points.
|
|
|
|
|
*/
|
2011-10-12 13:40:35 -04:00
|
|
|
static void
|
|
|
|
|
followzoombutton(NSRect r)
|
|
|
|
|
{
|
|
|
|
|
NSRect wr;
|
|
|
|
|
Point p;
|
2012-10-16 13:55:44 -04:00
|
|
|
NSPoint pt;
|
2011-10-12 13:40:35 -04:00
|
|
|
|
|
|
|
|
wr = [WIN frame];
|
|
|
|
|
wr.origin.y += wr.size.height;
|
|
|
|
|
r.origin.y += r.size.height;
|
|
|
|
|
|
2011-12-09 22:21:09 -05:00
|
|
|
getmousepos();
|
2012-10-16 13:55:44 -04:00
|
|
|
pt.x = in.mpos.x;
|
|
|
|
|
pt.y = in.mpos.y;
|
|
|
|
|
pt = scalepoint(pt, win.topointscale);
|
|
|
|
|
pt.x = (r.origin.x - wr.origin.x) + pt.x;
|
|
|
|
|
pt.y = -(r.origin.y - wr.origin.y) + pt.y;
|
|
|
|
|
pt = scalepoint(pt, win.topixelscale);
|
|
|
|
|
|
|
|
|
|
p.x = pt.x;
|
|
|
|
|
p.y = pt.y;
|
|
|
|
|
|
2011-10-12 13:40:35 -04:00
|
|
|
setmouse(p);
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-26 08:19:56 -07:00
|
|
|
togglefs(void)
|
2011-09-06 10:10:43 -04:00
|
|
|
{
|
2011-11-08 13:23:55 -05:00
|
|
|
uint opt, tmp;
|
|
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
#if OSX_VERSION >= 100700
|
2012-02-28 14:56:13 -05:00
|
|
|
NSScreen *s, *s0;
|
|
|
|
|
|
|
|
|
|
s = [WIN screen];
|
|
|
|
|
s0 = [[NSScreen screens] objectAtIndex:0];
|
|
|
|
|
|
|
|
|
|
if((s==s0 && useoldfullscreen==0) || win.isnfs) {
|
2011-10-12 13:40:35 -04:00
|
|
|
[WIN toggleFullScreen:nil];
|
2011-09-19 08:58:59 -04:00
|
|
|
return;
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
2011-09-19 08:58:59 -04:00
|
|
|
#endif
|
2011-09-26 08:19:56 -07:00
|
|
|
[win.content retain];
|
2011-10-12 13:40:35 -04:00
|
|
|
[WIN orderOut:nil];
|
|
|
|
|
[WIN setContentView:nil];
|
2011-10-03 18:16:09 -04:00
|
|
|
|
2011-11-08 13:23:55 -05:00
|
|
|
win.isofs = ! win.isofs;
|
|
|
|
|
hidebars(win.isofs);
|
2011-10-03 18:16:09 -04:00
|
|
|
|
2011-11-08 13:23:55 -05:00
|
|
|
/*
|
|
|
|
|
* If we move the window from one space to another,
|
|
|
|
|
* ofs[0] and ofs[1] can be on different spaces.
|
|
|
|
|
* This "setCollectionBehavior" trick moves the
|
|
|
|
|
* window to the active space.
|
|
|
|
|
*/
|
|
|
|
|
opt = [WIN collectionBehavior];
|
|
|
|
|
tmp = opt | NSWindowCollectionBehaviorCanJoinAllSpaces;
|
2011-10-12 13:40:35 -04:00
|
|
|
[WIN setContentView:win.content];
|
2011-11-08 13:23:55 -05:00
|
|
|
[WIN setCollectionBehavior:tmp];
|
2011-10-12 13:40:35 -04:00
|
|
|
[WIN makeKeyAndOrderFront:nil];
|
2011-11-08 13:23:55 -05:00
|
|
|
[WIN setCollectionBehavior:opt];
|
2011-09-26 08:19:56 -07:00
|
|
|
[win.content release];
|
2011-10-03 18:16:09 -04:00
|
|
|
}
|
2011-09-19 08:58:59 -04:00
|
|
|
|
2011-11-08 13:23:55 -05:00
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
Autohiddenbars = NSApplicationPresentationAutoHideDock
|
|
|
|
|
| NSApplicationPresentationAutoHideMenuBar,
|
|
|
|
|
|
|
|
|
|
Hiddenbars = NSApplicationPresentationHideDock
|
|
|
|
|
| NSApplicationPresentationHideMenuBar,
|
|
|
|
|
};
|
|
|
|
|
|
2011-10-03 18:16:09 -04:00
|
|
|
static void
|
2011-11-08 13:23:55 -05:00
|
|
|
hidebars(int set)
|
2011-10-03 18:16:09 -04:00
|
|
|
{
|
|
|
|
|
NSScreen *s,*s0;
|
2011-11-08 13:23:55 -05:00
|
|
|
uint old, opt;
|
2011-10-03 18:16:09 -04:00
|
|
|
|
2011-10-12 13:40:35 -04:00
|
|
|
s = [WIN screen];
|
2011-10-03 18:16:09 -04:00
|
|
|
s0 = [[NSScreen screens] objectAtIndex:0];
|
2011-11-08 13:23:55 -05:00
|
|
|
old = [NSApp presentationOptions];
|
2011-10-03 18:16:09 -04:00
|
|
|
|
2012-01-16 17:11:36 -05:00
|
|
|
#if OSX_VERSION >= 100700
|
|
|
|
|
/* This bit can get lost, resulting in dreadful bugs. */
|
|
|
|
|
if(win.isnfs)
|
|
|
|
|
old |= NSApplicationPresentationFullScreen;
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-10-03 18:16:09 -04:00
|
|
|
if(set && s==s0)
|
2011-11-08 13:23:55 -05:00
|
|
|
opt = (old & ~Autohiddenbars) | Hiddenbars;
|
2011-10-03 18:16:09 -04:00
|
|
|
else
|
2011-11-08 13:23:55 -05:00
|
|
|
opt = old & ~(Autohiddenbars | Hiddenbars);
|
2011-10-03 18:16:09 -04:00
|
|
|
|
2011-11-08 13:23:55 -05:00
|
|
|
if(opt != old)
|
|
|
|
|
[NSApp setPresentationOptions:opt];
|
2011-10-03 18:16:09 -04:00
|
|
|
}
|
2011-09-19 08:58:59 -04:00
|
|
|
|
2011-09-06 10:10:43 -04:00
|
|
|
static void
|
2011-09-19 08:58:59 -04:00
|
|
|
makemenu(void)
|
2011-09-06 10:10:43 -04:00
|
|
|
{
|
2011-10-12 13:40:35 -04:00
|
|
|
NSMenu *m;
|
2012-01-16 17:12:10 -05:00
|
|
|
NSMenuItem *i0,*i1;
|
2011-10-12 13:40:35 -04:00
|
|
|
|
|
|
|
|
m = [NSMenu new];
|
2012-01-16 17:12:10 -05:00
|
|
|
i0 = [m addItemWithTitle:@"app" action:NULL keyEquivalent:@""];
|
|
|
|
|
i1 = [m addItemWithTitle:@"help" action:NULL keyEquivalent:@""];
|
2011-10-12 13:40:35 -04:00
|
|
|
[NSApp setMainMenu:m];
|
|
|
|
|
[m release];
|
|
|
|
|
|
2012-01-16 17:12:10 -05:00
|
|
|
m = [[NSMenu alloc] initWithTitle:@"app"];
|
|
|
|
|
[m addItemWithTitle:@"Full Screen"
|
2011-10-12 13:40:35 -04:00
|
|
|
action:@selector(calltogglefs:)
|
|
|
|
|
keyEquivalent:@"f"];
|
2012-01-16 17:12:10 -05:00
|
|
|
[m addItemWithTitle:@"Hide"
|
|
|
|
|
action:@selector(hide:)
|
|
|
|
|
keyEquivalent:@"h"];
|
|
|
|
|
[m addItemWithTitle:@"Quit"
|
2011-10-12 13:40:35 -04:00
|
|
|
action:@selector(terminate:)
|
|
|
|
|
keyEquivalent:@"q"];
|
|
|
|
|
[i0 setSubmenu:m];
|
2012-01-16 17:12:10 -05:00
|
|
|
[m release];
|
|
|
|
|
|
|
|
|
|
m = [[NSMenu alloc] initWithTitle:@"help"];
|
|
|
|
|
[m addItemWithTitle:@"Plumb devdraw(1)"
|
|
|
|
|
action:@selector(plumbmanual:)
|
|
|
|
|
keyEquivalent:@""];
|
|
|
|
|
[i1 setSubmenu:m];
|
2011-10-12 13:40:35 -04:00
|
|
|
[m release];
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
|
2012-10-16 13:55:44 -04:00
|
|
|
// FIXME: Introduce a high-resolution Glenda image.
|
2011-09-19 08:58:59 -04:00
|
|
|
static void
|
|
|
|
|
makeicon(void)
|
|
|
|
|
{
|
|
|
|
|
NSData *d;
|
|
|
|
|
NSImage *i;
|
|
|
|
|
|
|
|
|
|
d = [[NSData alloc]
|
|
|
|
|
initWithBytes:glenda_png
|
|
|
|
|
length:(sizeof glenda_png)];
|
|
|
|
|
|
|
|
|
|
i = [[NSImage alloc] initWithData:d];
|
|
|
|
|
[NSApp setApplicationIconImage:i];
|
|
|
|
|
[[NSApp dockTile] display];
|
|
|
|
|
[i release];
|
|
|
|
|
[d release];
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 10:10:43 -04:00
|
|
|
QLock snarfl;
|
|
|
|
|
|
|
|
|
|
char*
|
|
|
|
|
getsnarf(void)
|
|
|
|
|
{
|
|
|
|
|
NSPasteboard *pb;
|
2011-09-19 08:58:59 -04:00
|
|
|
NSString *s;
|
2011-09-06 10:10:43 -04:00
|
|
|
|
|
|
|
|
pb = [NSPasteboard generalPasteboard];
|
|
|
|
|
|
|
|
|
|
qlock(&snarfl);
|
2011-10-03 18:16:09 -04:00
|
|
|
s = [pb stringForType:NSPasteboardTypeString];
|
2011-09-06 10:10:43 -04:00
|
|
|
qunlock(&snarfl);
|
|
|
|
|
|
|
|
|
|
if(s)
|
|
|
|
|
return strdup((char*)[s UTF8String]);
|
|
|
|
|
else
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
putsnarf(char *s)
|
|
|
|
|
{
|
|
|
|
|
NSArray *t;
|
|
|
|
|
NSPasteboard *pb;
|
2011-09-19 08:58:59 -04:00
|
|
|
NSString *str;
|
2011-09-06 10:10:43 -04:00
|
|
|
|
|
|
|
|
if(strlen(s) >= SnarfSize)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
t = [NSArray arrayWithObject:NSPasteboardTypeString];
|
|
|
|
|
pb = [NSPasteboard generalPasteboard];
|
|
|
|
|
str = [[NSString alloc] initWithUTF8String:s];
|
|
|
|
|
|
|
|
|
|
qlock(&snarfl);
|
|
|
|
|
[pb declareTypes:t owner:nil];
|
2011-10-03 18:16:09 -04:00
|
|
|
[pb setString:str forType:NSPasteboardTypeString];
|
2011-09-06 10:10:43 -04:00
|
|
|
qunlock(&snarfl);
|
|
|
|
|
|
2011-10-03 18:16:09 -04:00
|
|
|
[str release];
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-09-19 08:58:59 -04:00
|
|
|
kicklabel(char *label)
|
2011-09-06 10:10:43 -04:00
|
|
|
{
|
2011-10-03 18:16:09 -04:00
|
|
|
NSString *s;
|
|
|
|
|
|
2011-09-19 08:58:59 -04:00
|
|
|
if(label == nil)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-10-03 18:16:09 -04:00
|
|
|
s = [[NSString alloc] initWithUTF8String:label];
|
2011-10-12 13:40:35 -04:00
|
|
|
[win.ofs[0] setTitle:s];
|
|
|
|
|
[win.ofs[1] setTitle:s];
|
2011-10-03 18:16:09 -04:00
|
|
|
[[NSApp dockTile] setBadgeLabel:s];
|
|
|
|
|
[s release];
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-12-09 22:21:09 -05:00
|
|
|
setcursor(Cursor *c)
|
2011-10-23 18:47:29 -04:00
|
|
|
{
|
2011-12-09 22:21:09 -05:00
|
|
|
/*
|
|
|
|
|
* No cursor change unless in main thread.
|
|
|
|
|
*/
|
2011-10-23 18:47:29 -04:00
|
|
|
[appdelegate
|
|
|
|
|
performSelectorOnMainThread:@selector(callsetcursor0:)
|
2011-12-09 22:21:09 -05:00
|
|
|
withObject:[NSValue valueWithPointer:c]
|
2011-10-23 18:47:29 -04:00
|
|
|
waitUntilDone:YES];
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-09 22:21:09 -05:00
|
|
|
static void
|
2011-10-23 18:47:29 -04:00
|
|
|
setcursor0(Cursor *c)
|
2011-09-19 08:58:59 -04:00
|
|
|
{
|
2011-12-09 22:21:09 -05:00
|
|
|
NSCursor *d;
|
2011-09-19 08:58:59 -04:00
|
|
|
|
2011-12-09 22:21:09 -05:00
|
|
|
d = win.cursor;
|
2011-09-19 08:58:59 -04:00
|
|
|
|
2011-12-09 22:21:09 -05:00
|
|
|
if(c)
|
|
|
|
|
win.cursor = makecursor(c);
|
|
|
|
|
else
|
2011-10-12 13:40:35 -04:00
|
|
|
win.cursor = nil;
|
2011-10-23 18:47:29 -04:00
|
|
|
|
2011-12-09 22:21:09 -05:00
|
|
|
updatecursor();
|
|
|
|
|
|
|
|
|
|
if(d)
|
|
|
|
|
[d release];
|
|
|
|
|
}
|
2011-09-19 08:58:59 -04:00
|
|
|
|
2012-10-16 13:55:44 -04:00
|
|
|
/*
|
|
|
|
|
* Cursors will be scaled on retina display.
|
|
|
|
|
*/
|
2011-12-09 22:21:09 -05:00
|
|
|
static NSCursor*
|
|
|
|
|
makecursor(Cursor *c)
|
|
|
|
|
{
|
|
|
|
|
NSBitmapImageRep *r;
|
|
|
|
|
NSCursor *d;
|
|
|
|
|
NSImage *i;
|
|
|
|
|
NSPoint p;
|
|
|
|
|
int b;
|
|
|
|
|
uchar *plane[5];
|
2011-10-12 13:40:35 -04:00
|
|
|
|
2011-12-09 22:21:09 -05:00
|
|
|
r = [[NSBitmapImageRep alloc]
|
|
|
|
|
initWithBitmapDataPlanes:nil
|
|
|
|
|
pixelsWide:16
|
|
|
|
|
pixelsHigh:16
|
|
|
|
|
bitsPerSample:1
|
|
|
|
|
samplesPerPixel:2
|
|
|
|
|
hasAlpha:YES
|
|
|
|
|
isPlanar:YES
|
|
|
|
|
colorSpaceName:NSDeviceBlackColorSpace
|
|
|
|
|
bytesPerRow:2
|
|
|
|
|
bitsPerPixel:1];
|
|
|
|
|
|
|
|
|
|
[r getBitmapDataPlanes:plane];
|
|
|
|
|
|
|
|
|
|
for(b=0; b<2*16; b++){
|
|
|
|
|
plane[0][b] = c->set[b];
|
|
|
|
|
plane[1][b] = c->clr[b];
|
2011-10-12 13:40:35 -04:00
|
|
|
}
|
2011-12-09 22:21:09 -05:00
|
|
|
p = NSMakePoint(-c->offset.x, -c->offset.y);
|
|
|
|
|
i = [NSImage new];
|
|
|
|
|
[i addRepresentation:r];
|
|
|
|
|
[r release];
|
2011-10-23 18:47:29 -04:00
|
|
|
|
2011-12-09 22:21:09 -05:00
|
|
|
d = [[NSCursor alloc] initWithImage:i hotSpot:p];
|
|
|
|
|
[i release];
|
|
|
|
|
return d;
|
2011-09-06 10:10:43 -04:00
|
|
|
}
|
2012-01-16 17:04:28 -05:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
topwin(void)
|
|
|
|
|
{
|
|
|
|
|
[WIN performSelectorOnMainThread:
|
|
|
|
|
@selector(makeKeyAndOrderFront:)
|
|
|
|
|
withObject:nil
|
|
|
|
|
waitUntilDone:NO];
|
|
|
|
|
|
|
|
|
|
in.willactivate = 1;
|
|
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
|
|
|
|
}
|
2012-10-16 13:55:44 -04:00
|
|
|
|
|
|
|
|
static NSSize
|
|
|
|
|
winsizepoints()
|
|
|
|
|
{
|
|
|
|
|
return [win.content bounds].size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NSSize
|
|
|
|
|
winsizepixels()
|
|
|
|
|
{
|
2012-11-25 22:43:57 -05:00
|
|
|
#if OSX_VERSION >= 100700
|
2012-10-16 13:55:44 -04:00
|
|
|
if (OSX_VERSION >= 100700 && devdrawretina)
|
|
|
|
|
return [win.content convertSizeToBacking: winsizepoints()];
|
|
|
|
|
else
|
2012-11-25 21:20:18 -05:00
|
|
|
#endif
|
2012-10-16 13:55:44 -04:00
|
|
|
return winsizepoints();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NSRect
|
|
|
|
|
scalerect(NSRect r, CGFloat scale)
|
|
|
|
|
{
|
|
|
|
|
r.origin.x *= scale;
|
|
|
|
|
r.origin.y *= scale;
|
|
|
|
|
r.size.width *= scale;
|
|
|
|
|
r.size.height *= scale;
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Expands rectangle |r|'s bounds to more inclusive integer bounds to
|
|
|
|
|
* eliminate 1 pixel gaps.
|
|
|
|
|
*/
|
|
|
|
|
static NSRect
|
|
|
|
|
dilate(NSRect r)
|
|
|
|
|
{
|
|
|
|
|
if(win.topixelscale > 1.0f){
|
|
|
|
|
r.origin.x = floorf(r.origin.x);
|
|
|
|
|
r.origin.y = floorf(r.origin.y);
|
|
|
|
|
r.size.width = ceilf(r.size.width + 0.5);
|
|
|
|
|
r.size.height = ceilf(r.size.height + 0.5);
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NSPoint
|
|
|
|
|
scalepoint(NSPoint pt, CGFloat scale)
|
|
|
|
|
{
|
|
|
|
|
pt.x *= scale;
|
|
|
|
|
pt.y *= scale;
|
|
|
|
|
return pt;
|
|
|
|
|
}
|
2013-08-06 23:44:06 -04:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
setprocname(const char *s)
|
|
|
|
|
{
|
|
|
|
|
CFStringRef process_name;
|
|
|
|
|
|
|
|
|
|
process_name = CFStringCreateWithBytes(nil, (uchar*)s, strlen(s), kCFStringEncodingUTF8, false);
|
|
|
|
|
|
|
|
|
|
// Adapted from Chrome's mac_util.mm.
|
|
|
|
|
// http://src.chromium.org/viewvc/chrome/trunk/src/base/mac/mac_util.mm
|
|
|
|
|
//
|
|
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
|
// met:
|
|
|
|
|
//
|
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
|
// copyright notice, this list of conditions and the following disclaimer
|
|
|
|
|
// in the documentation and/or other materials provided with the
|
|
|
|
|
// distribution.
|
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
|
// contributors may be used to endorse or promote products derived from
|
|
|
|
|
// this software without specific prior written permission.
|
|
|
|
|
//
|
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
// Warning: here be dragons! This is SPI reverse-engineered from WebKit's
|
|
|
|
|
// plugin host, and could break at any time (although realistically it's only
|
|
|
|
|
// likely to break in a new major release).
|
|
|
|
|
// When 10.7 is available, check that this still works, and update this
|
|
|
|
|
// comment for 10.8.
|
|
|
|
|
|
|
|
|
|
// Private CFType used in these LaunchServices calls.
|
|
|
|
|
typedef CFTypeRef PrivateLSASN;
|
|
|
|
|
typedef PrivateLSASN (*LSGetCurrentApplicationASNType)();
|
|
|
|
|
typedef OSStatus (*LSSetApplicationInformationItemType)(int, PrivateLSASN,
|
|
|
|
|
CFStringRef,
|
|
|
|
|
CFStringRef,
|
|
|
|
|
CFDictionaryRef*);
|
|
|
|
|
|
|
|
|
|
static LSGetCurrentApplicationASNType ls_get_current_application_asn_func =
|
|
|
|
|
NULL;
|
|
|
|
|
static LSSetApplicationInformationItemType
|
|
|
|
|
ls_set_application_information_item_func = NULL;
|
|
|
|
|
static CFStringRef ls_display_name_key = NULL;
|
|
|
|
|
|
|
|
|
|
static bool did_symbol_lookup = false;
|
|
|
|
|
if (!did_symbol_lookup) {
|
|
|
|
|
did_symbol_lookup = true;
|
|
|
|
|
CFBundleRef launch_services_bundle =
|
|
|
|
|
CFBundleGetBundleWithIdentifier(CFSTR("com.apple.LaunchServices"));
|
|
|
|
|
if (!launch_services_bundle) {
|
|
|
|
|
fprint(2, "Failed to look up LaunchServices bundle\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ls_get_current_application_asn_func =
|
|
|
|
|
(LSGetCurrentApplicationASNType)(
|
|
|
|
|
CFBundleGetFunctionPointerForName(
|
|
|
|
|
launch_services_bundle, CFSTR("_LSGetCurrentApplicationASN")));
|
|
|
|
|
if (!ls_get_current_application_asn_func)
|
|
|
|
|
fprint(2, "Could not find _LSGetCurrentApplicationASN\n");
|
|
|
|
|
|
|
|
|
|
ls_set_application_information_item_func =
|
|
|
|
|
(LSSetApplicationInformationItemType)(
|
|
|
|
|
CFBundleGetFunctionPointerForName(
|
|
|
|
|
launch_services_bundle,
|
|
|
|
|
CFSTR("_LSSetApplicationInformationItem")));
|
|
|
|
|
if (!ls_set_application_information_item_func)
|
|
|
|
|
fprint(2, "Could not find _LSSetApplicationInformationItem\n");
|
|
|
|
|
|
|
|
|
|
CFStringRef* key_pointer = (CFStringRef*)(
|
|
|
|
|
CFBundleGetDataPointerForName(launch_services_bundle,
|
|
|
|
|
CFSTR("_kLSDisplayNameKey")));
|
|
|
|
|
ls_display_name_key = key_pointer ? *key_pointer : NULL;
|
|
|
|
|
if (!ls_display_name_key)
|
|
|
|
|
fprint(2, "Could not find _kLSDisplayNameKey\n");
|
|
|
|
|
|
|
|
|
|
// Internally, this call relies on the Mach ports that are started up by the
|
|
|
|
|
// Carbon Process Manager. In debug builds this usually happens due to how
|
|
|
|
|
// the logging layers are started up; but in release, it isn't started in as
|
|
|
|
|
// much of a defined order. So if the symbols had to be loaded, go ahead
|
|
|
|
|
// and force a call to make sure the manager has been initialized and hence
|
|
|
|
|
// the ports are opened.
|
|
|
|
|
ProcessSerialNumber psn;
|
|
|
|
|
GetCurrentProcess(&psn);
|
|
|
|
|
}
|
|
|
|
|
if (!ls_get_current_application_asn_func ||
|
|
|
|
|
!ls_set_application_information_item_func ||
|
|
|
|
|
!ls_display_name_key) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PrivateLSASN asn = ls_get_current_application_asn_func();
|
|
|
|
|
// Constant used by WebKit; what exactly it means is unknown.
|
|
|
|
|
const int magic_session_constant = -2;
|
|
|
|
|
OSErr err =
|
|
|
|
|
ls_set_application_information_item_func(magic_session_constant, asn,
|
|
|
|
|
ls_display_name_key,
|
|
|
|
|
process_name,
|
|
|
|
|
NULL /* optional out param */);
|
|
|
|
|
if(err != noErr)
|
|
|
|
|
fprint(2, "Call to set process name failed\n");
|
|
|
|
|
}
|