devdraw: automatic OS X label updating
This commit is contained in:
parent
a0899df665
commit
342866f89c
1 changed files with 20 additions and 24 deletions
|
|
@ -29,7 +29,6 @@ extern Rectangle mouserect;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
char *label;
|
char *label;
|
||||||
int newlabel;
|
|
||||||
char *winsize;
|
char *winsize;
|
||||||
QLock labellock;
|
QLock labellock;
|
||||||
|
|
||||||
|
|
@ -67,6 +66,11 @@ enum
|
||||||
kWindowFullZoomAttribute
|
kWindowFullZoomAttribute
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
P9PEventLabelUpdate = 1
|
||||||
|
};
|
||||||
|
|
||||||
static void screenproc(void*);
|
static void screenproc(void*);
|
||||||
static void eresized(int);
|
static void eresized(int);
|
||||||
static void fullscreen(int);
|
static void fullscreen(int);
|
||||||
|
|
@ -178,6 +182,7 @@ _screeninit(void)
|
||||||
{ kEventClassMouse, kEventMouseMoved },
|
{ kEventClassMouse, kEventMouseMoved },
|
||||||
{ kEventClassMouse, kEventMouseDragged },
|
{ kEventClassMouse, kEventMouseDragged },
|
||||||
{ kEventClassMouse, kEventMouseWheelMoved },
|
{ kEventClassMouse, kEventMouseWheelMoved },
|
||||||
|
{ 'P9PE', P9PEventLabelUpdate}
|
||||||
};
|
};
|
||||||
|
|
||||||
InstallApplicationEventHandler(
|
InstallApplicationEventHandler(
|
||||||
|
|
@ -246,17 +251,19 @@ eventhandler(EventHandlerCallRef next, EventRef event, void *arg)
|
||||||
{
|
{
|
||||||
OSStatus result;
|
OSStatus result;
|
||||||
|
|
||||||
if(osx.newlabel) {
|
|
||||||
// dummy message so we update the label
|
|
||||||
qlock(&osx.labellock);
|
|
||||||
setlabel(osx.label);
|
|
||||||
osx.newlabel = 0;
|
|
||||||
qunlock(&osx.labellock);
|
|
||||||
}
|
|
||||||
|
|
||||||
result = CallNextEventHandler(next, event);
|
result = CallNextEventHandler(next, event);
|
||||||
|
|
||||||
switch(GetEventClass(event)){
|
switch(GetEventClass(event)){
|
||||||
|
|
||||||
|
case 'P9PE':
|
||||||
|
if (GetEventKind(event) == P9PEventLabelUpdate) {
|
||||||
|
qlock(&osx.labellock);
|
||||||
|
setlabel(osx.label);
|
||||||
|
qunlock(&osx.labellock);
|
||||||
|
return noErr;
|
||||||
|
} else
|
||||||
|
return eventNotHandledErr;
|
||||||
|
|
||||||
case kEventClassApplication:;
|
case kEventClassApplication:;
|
||||||
Rectangle r = Rect(0, 0, Dx(osx.screenr), Dy(osx.screenr));
|
Rectangle r = Rect(0, 0, Dx(osx.screenr), Dy(osx.screenr));
|
||||||
_flushmemscreen(r);
|
_flushmemscreen(r);
|
||||||
|
|
@ -842,30 +849,19 @@ void
|
||||||
kicklabel(char *label)
|
kicklabel(char *label)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
EventRef e;
|
||||||
|
|
||||||
p = strdup(label);
|
p = strdup(label);
|
||||||
if(p == nil)
|
if(p == nil)
|
||||||
return;
|
return;
|
||||||
qlock(&osx.labellock);
|
qlock(&osx.labellock);
|
||||||
free(osx.label);
|
free(osx.label);
|
||||||
osx.newlabel = 1;
|
|
||||||
osx.label = p;
|
osx.label = p;
|
||||||
qunlock(&osx.labellock);
|
qunlock(&osx.labellock);
|
||||||
|
|
||||||
// TODO(rsc): It would be great to send an OS X event to the
|
CreateEvent(nil, 'P9PE', P9PEventLabelUpdate, 0, kEventAttributeUserEvent, &e);
|
||||||
// event handling loop to force the update of the label,
|
PostEventToQueue(GetMainEventQueue(), e, kEventPriorityStandard);
|
||||||
// but I cannot manage to do this.
|
|
||||||
// int i;
|
|
||||||
// EventRef ev;
|
|
||||||
/*
|
|
||||||
ev = 0;
|
|
||||||
i = CreateEvent(nil, kEventClassApplication, 0, 0, 0, &ev);
|
|
||||||
if(i != 0)
|
|
||||||
fprint(2, "CreateEvent: %d\n", i);
|
|
||||||
i = SendEventToEventTarget(ev, GetUserFocusEventTarget());
|
|
||||||
if(i != 0)
|
|
||||||
fprint(2, "SendEventToEventTarget %p: %d\n", ev, i);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue