Getting mouse cursor position

2011-05-06 Thread eveningnick eveningnick
Hello
I am searching for the way to find a cursor's position on the screen.

I tried to use method -hotSpot of NSCursor, but it returns
> sc x=-2057825613, y=0


-(IBAction)timeHandler:(id)timer {
//NSCursor *sc = [NSCursor currentSystemCursor];
NSCursor *sc = [NSCursor currentCursor];
NSLog(@"sc x=%d, y=%d", [sc hotSpot].x, [sc hotSpot].y);
}

What may be wrong here?
I can successfully retrieve cursor's image though. But not the position. Why?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: drawing onto CVPixelBuffer

2011-05-06 Thread eveningnick eveningnick
the pixel format of the CVPixelBufferRef is k32BGRAPixelFormat
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Threading synchronization: does a primitive exists?

2011-05-06 Thread eveningnick eveningnick
I do call setNeedsDisplay, but the buffer of the picture that is
queued to be drawn is being reused right after the function of this
'supplying thread' is finished. This is ok as soon as i save/encode
the image in this function - i don't need this buffer anymore. But i
wanted to display it (temporarily for debugging purposes).. Anyway, i
solved the issue with NSCondition :-)
Thanks

2011/5/6 David Duncan :
> Why not use the production of a frame from your secondary thread to drive 
> calling -setNeedsDisplay on your view? Then you don't need to block any 
> thread (and you really really do not want to block the main thread anyway).
>
> On May 6, 2011, at 1:10 PM, eveningnick eveningnick wrote:
>
>> I need to wait, while the image is drawn (drawRect method is actually
>> called by the framework) from a different thread that supplies frames.
>> I am drawing images just to see that the output is correct, in the
>> final application i don't need them to be drawn on the screen but
>> saved into a file
>>
>> 2011/5/6 Graham Cox :
>>>
>>> On 05/05/2011, at 11:51 PM, eveningnick eveningnick wrote:
>>>
>>>> What i need - is to stop the thread A immediately after the thread B
>>>> has been spawned by a thread A.
>>>
>>> Hang on. Why use a thread at all? If Thread A simply calls the process B 
>>> synchronously, it will achieve exactly what you have stated you want - that 
>>> A will stop when B starts, and will continue when B finishes.
>>>
>>> --Graham
>>>
>>>
>>>
>> ___
>>
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
>>
>> This email sent to david.dun...@apple.com
>
> --
> David Duncan
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


drawing onto CVPixelBuffer

2011-05-06 Thread eveningnick eveningnick
Hi
I have a CVPixelBuffer with some background picture.
I need to draw on this background some foreground image. I don't need
to preserve the initial CVPixelBuffer's content - i just need to add a
small foreground watermark onto that buffer.

CIImage does allow to create an image from CVPixelBuffer and paint
something on top of it (using Core Image filters), but CIImage is
"read only" - it takes a source image and generates a brand new image
in a new buffer.
I can't afford one more copying, that greatly slows things down,
because the CVPixelBuffer itself is kind of big. And there are a lot
of them per second (they are generated as frames from a movie).

Is there any way i could draw without such a copy? Maybe there is any
other imaging framework that allows me to work with CVPixelBufferRef?
Or should i just 'CVPixelBufferLock' the buffer, and copy raw bytes
onto the buffer from my source NSImage (that contains the foreground
image) directly using a loop? This doesn't seem the right way though.
Could you please help me, what is better to do here?

Thanks
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Threading synchronization: does a primitive exists?

2011-05-06 Thread eveningnick eveningnick
I need to wait, while the image is drawn (drawRect method is actually
called by the framework) from a different thread that supplies frames.
I am drawing images just to see that the output is correct, in the
final application i don't need them to be drawn on the screen but
saved into a file

2011/5/6 Graham Cox :
>
> On 05/05/2011, at 11:51 PM, eveningnick eveningnick wrote:
>
>> What i need - is to stop the thread A immediately after the thread B
>> has been spawned by a thread A.
>
> Hang on. Why use a thread at all? If Thread A simply calls the process B 
> synchronously, it will achieve exactly what you have stated you want - that A 
> will stop when B starts, and will continue when B finishes.
>
> --Graham
>
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Threading synchronization: does a primitive exists?

2011-05-05 Thread eveningnick eveningnick
Ken,
Thanks for a detailed response
Still not sure how would it be possible to do using NSConditionLock,
but i managed to do it using NSCondition :)


2011/5/5 Ken Thomases :
> On May 5, 2011, at 8:51 AM, eveningnick eveningnick wrote:
>
>> 2011/5/5 Heath Borders :
>>> Try NSConditionLock. Its documentation should be pretty self-explanatory.
>>>
>>
>> Health,
>> thanks for the response.
>> However, i can't see how can i use NSConditionLock in my situation.
>> For every lock (or mutex/semaphore - which essentially is the same) i
>> need to acquire it 1 time at least to stop the the thread when a
>> second attempt to acquire it from a different thread is made.
>> What i need - is to stop the thread A immediately after the thread B
>> has been spawned by a thread A. I am afraid if i acquire the lock from
>> A, and then acquire it as soon as B starts (in B routine), the thread
>> A may even finish before the thread B _actually_ starts (or rather B's
>> threadfunction starts executing).
>> Am i wrong somewhere here?
>
> NSConditionLock allows one to lock waiting for specific conditions.  The lock 
> can be created in an initial condition, say THREAD_B_NOT_RUNNING.  Then, 
> Thread A can spawn B and lock waiting for condition THREAD_B_RUNNING.  Thread 
> B can take the lock unconditionally and, when it's ready, unlock it with 
> condition THREAD_B_RUNNING.  Or whatever.
>
> Other possible techniques include using a pipe to send a signal byte from one 
> thread to the other.  So, thread A would do a blocking read from the pipe.  
> Thread B would write a single byte to the pipe to signal whatever condition.
>
> There are all sorts of other approaches.
>
> Regards,
> Ken
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Threading synchronization: does a primitive exists?

2011-05-05 Thread eveningnick eveningnick
2011/5/5 Heath Borders :
> Try NSConditionLock. Its documentation should be pretty self-explanatory.
>

Health,
thanks for the response.
However, i can't see how can i use NSConditionLock in my situation.
For every lock (or mutex/semaphore - which essentially is the same) i
need to acquire it 1 time at least to stop the the thread when a
second attempt to acquire it from a different thread is made.
What i need - is to stop the thread A immediately after the thread B
has been spawned by a thread A. I am afraid if i acquire the lock from
A, and then acquire it as soon as B starts (in B routine), the thread
A may even finish before the thread B _actually_ starts (or rather B's
threadfunction starts executing).
Am i wrong somewhere here?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Threading synchronization: does a primitive exists?

2011-05-05 Thread eveningnick eveningnick
Hello
I have a thread A that spawns a thread B, and should stop, waiting
before the thread B allows thread A to continue.

In Windows, in a thread A, before spawning a thread B, i would create
a synchronization "Event" primitive in the "non signaled" mode, the
spawn a thread B, and call WaitForSingleObject(), waiting for thread B
to switch the "Event" into the "signaled" mode, which would release
the WaitForSingleObject() and allow the thread A to continue to
operate.

(WaitForSingleObject() freezes the thread, until the object that it is
waiting for - e.g., an "Event" primitive - is switched into a
"signaled" mode).

In OS X i have no idea how to do that :S I guess it is impossible to
do the same job using mutexes? Maybe some other primitives exist?

I need this _only_ for debugging, it would greatly simplify my life. I
am well aware that this is approach is deadlock-prone.

Thanks for the response if i get one
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


what kind of pictures am i allowed to draw onto NSOpenGLView?

2011-05-01 Thread eveningnick eveningnick
Hi

I am trying to find a way to display a set of images serially on
window. As far as i understood reading Apple programming guides (Core
image, OpenGL) and samples,  NSOpenGLView is the optimal choice for
the task, since it offers asynchrony and delegates anything possible
to the GPU.

According to the samples, to render some picture onto NSOpenGLView, i
need to subclass it, and do all the painting job into -drawRect
method. All the job - is calling CIContext's -drawImage method.
Previously i have to have a CIImage object, that contains an image.
The problem is that almost nothing i rendered. Almost - because
sometimes i get some "artifacts" for certain JPEG image files, but
most often i get a blank black view. It seems, like only special kind
of CIImage objects can be rendered.

An ordinary NSView's subclass does the same job perfectly. But i also
need to play a movie and display it in a view, and according to
samples NSOpenGLView is the preferred way.

Could you give me an advice what am i doing wrong?
Thanks!

Here's the implementation of my NSOpenGLView's subclass:

@implementation RenderingView
CIContext *ciContext;

-(void)awakeFromNib {
NSLog(@"init");
[super awakeFromNib];
CGColorSpaceRef displayColorSpace = CGColorSpaceCreateDeviceRGB();
ciContext = [[CIContext contextWithCGLContext:[[self openGLContext]
CGLContextObj]
  
pixelFormat:[[self pixelFormat] CGLPixelFormatObj]

  options:[NSDictionary dictionaryWithObjectsAndKeys:

   displayColorSpace, kCIContextOutputColorSpace,

   displayColorSpace, kCIContextWorkingColorSpace, nil] ] 
retain];
CGColorSpaceRelease(displayColorSpace);
}

-(void)drawRect:(NSRect)dirtyRect {
NSLog(@"-drawRect");
[[self openGLContext] makeCurrentContext];
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);

CIImage *ciImage = [CIImage imageWithContentsOfURL:[NSURL
fileURLWithPath:@"/Users/testuser/Downloads/x_80722192.jpg"]];
if(!ciImage)
NSLog(@"ciImage loading error");
NSRect viewFrame = [self frame];
CGRect imageFrame = [ciImage extent];

[ciContext drawImage:ciImage
 inRect:CGRectMake(10, 10, 100, 100)

// inRect:CGRectMake(0, 0, viewFrame.size.width, viewFrame.size.height)
// 
atPoint:CGPointMake((int)((viewFrame.size.width -
imageFrame.size.width)*0.5), (int)((viewFrame.size.height -
imageFrame.size.height)*0.5))
fromRect:/*imageFrame*/CGRectMake(10, 10, 100, 
100)];
glBegin(GL_LINES);
glVertex2f(-0.5,-0.5);
glVertex2f(0.5,0.5);
glEnd();
glFlush();
}

-(void)dealloc {
[ciContext release];
}
@end
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Multithreading and memory management question

2011-04-21 Thread eveningnick eveningnick
Hi Ken,
> How are you spawning your threads?
> If you use Cocoa methods, then they automatically retain the object which is 
> the target of the selector and the argument object for the life of the 
> thread.  So, you may be getting this automatically without realizing it.  If 
> not, then it should be easy to arrange.

thanks, i used cocoa methods but didn't know the object is being
retained. That simplifies the code how it looks :)

> If you're using some other technique to spawn your threads, you can just 
> retain the object before spawning the thread and then have the thread work 
> function or method release it before exiting.  The retain and the release 
> don't have to occur on the same thread.

The problem i still have  - is the display link. It is a system
thread, that calls a method periodically. When i stop display link
(while the method is being executed)  - this execution of the method
will be the last, it won't be called anymore. As i described in the
first post, the object is being used from the display link callback. I
can't pass an object that comfortable, as i did with cocoa methods
(unfortunately). I can't retain an object before starting display link
as you suggested here - because i can't know when this "before
exiting" time happens - display link's thread is a CoreVideo
framework's thread, and it just calls my function repeatedly. I was
thinking about using some custom flag (like, BOOL
thisIsTheLastTimeTheDisplayLinkMethodIsBeingCalled) protected by a
critical section, and which is set when i stop "System high-priority
display link thread". But the solution would look very ad-hoc and
hardly readable, hardly maintainable when the amount of code grows. I
am wondering maybe there's a prettier way to do it.

Thanks
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Multithreading and memory management question

2011-04-21 Thread eveningnick eveningnick
Hello

I have an application that has a shared object (which is a custom
container for elements - arrays, and which is protected by critical
sections in my code). I need to control it's lifetime - it should be
alive until the last thread finishes working. Let me try to explain it
using an example from my code.

I have a display link (a method, that is periodically called by a
CoreVideo framework-spawned "high priority thread"):

-(void)displayLinkCallbackMethod {
   do_something_with_the_object(myObject);
   spawn_thread_for_selector(mythreadfunction);
   do_something_with_the_object(myObject);
   spawn_thread_for_selector(mythreadfunction);
   do_something_with_the_object(myObject);
}


-(void)mythreadfunction() {
  do_something_with_the_object(myObject);
}

-(IBAction)button1_clicked {
  myObject = [[MyObject alloc] init];
  DisplayLinkStartThread(displayLinkCallbackMethod);
}

-(IBAction)button2_clicked {
  DisplayLinkStopThread();
  //[myObject release]; //can't do it here, it's wrong
}


The main thread of my application starts the Display Link thread
(which starts calling displayLinkCallbackMethod as fast as possible).
Now, when i stop Display Link thread, the unfinished part of
"displayLinkCallbackMethod" is being finished, and the method is never
called again. The threads, spawned by this callbackmethod, finish
executing too. And of course, these "mythreadfunction" threads need
myObject to be alive for some time, i can't deallocate the object
right after i stop display link thread. However, i need to deallocate
it sooner or later, as long as it consumes a big chunk of memory.

Reference counters would come very handy here, but i am not sure if
this is thread safe: yes, i can retain myObject when i enter
displayLinkCallbackMethod() and mythreadfunction() (and release this
object when i quit these functions). Then i just release the object
right after stopping displaylink, and the object is either deallocated
immediately (if its refcount was 1), or it is deallocated when the
last thread that was using it finishes.
It would look somehow like the following (very schematically):

-(void)displayLinkCallbackMethod {
   [myObject retain];
   do_something_with_the_object(myObject);
   spawn_thread_for_selector(mythreadfunction);
   do_something_with_the_object(myObject);
   spawn_thread_for_selector(mythreadfunction);
   do_something_with_the_object(myObject);
   [myObject release];
}


-(void)mythreadfunction() {
  [myObject retain];
  do_something_with_the_object(myObject);
  [myObject release];
}

-(IBAction)button1_clicked {
  myObject = [[MyObject alloc] init];
  DisplayLinkStartThread(displayLinkCallbackMethod);
}

-(IBAction)button2_clicked {
  DisplayLinkStopThread();
  [myObject release]; //kind of safe now
}

The problem arises when i stop display link, and the display link at
the moment when displaylinkcallback() just started, but haven't
actually executed my first [myObject retain] - here the myObject is
deallocated, and displayLinkcallback() works with "nil". I haven't
faced this on 2CPUd mac, but i can't be sure it never happens.

Could you please suggest me how to achieve the removal of the object
when i need it? In the most "pretty" way, if one exists.
Thanks for reading this long post :)
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: A very customized window

2011-04-19 Thread eveningnick eveningnick
Thanks a lot for detailed response!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: A very customized window

2011-04-16 Thread eveningnick eveningnick
Hi Ken,
first thank you for answering this question and previous times. I am
just very unfamiliar about what can i do and what i can't drowning in
documentation that's why i'm asking so many times. I managed to
display the "funky window", but the events were my problem. Thanks a
lot for the links.

May i bother you once again with my questions?. :-)
Could you give me a hint how did QuickTime Player developers manage to
display a window the way it looks now? Specifically i can't
understand, how they made the "Movie control" toolbar, that floats
only within the "movie window"?

Reading through NSOpenGLView documentation, i found the note that this
view can't contain subviews. Though i am pretty sure the "movie view"
is NSOpenGLView (am i wrong here?). Do they display an another
"control" window somehow in an "always on top of the NSOpenGLView"
manner?

And one more question. Maybe i should ask that in OpenGL mailing list?
Although i guess it sounds so "basic" that developers there won't even
answer it...
I am wondering, why is NSOpenGLView considered to be the preferred way
to display a set of images? Why is every image operation revolving
around OpenGL? I understand that eventually it all comes through the
videoadapter, but what if i just display an RGB picture that i have in
an RGB buffer (CVImageBufferRef). Will OpenGL give me some benefits
just for rendering it on the view against drawing image onto something
like "NSImageView"?

Sorry if the questions seem like i haven't read anything. I have, just
now trying to put it all together in one big picture.

Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: A very customized window

2011-04-16 Thread eveningnick eveningnick
>While what you are asking for does not sound patently unreasonable, this last 
>sentence should >almost never be the reason to make a particular design 
>decision, especially when it comes to >deciding to implement non-standard 
>controls, etc.

Your statement made me think about redesigning some elements. Surely i
will try to make it the less irritating possible for the Mac users :-)
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


A very customized window

2011-04-16 Thread eveningnick eveningnick
Hi
Is it possible to resize a "custom" title-less window using any of
it's 4 corners?

I want to display a window with a hole inside (A window which looks
like a frame), and let the user to resize this frame using any of the
4 boundaries of such a frame.

Also i am wondering, if i could let the user drag such a "title-less"
window clicking on the 'fake' title bar?

When the user clicks "in the hole" of the window - inside the frame,
the click "goes" to the desktop or another window which happened to be
below?

How could i do it, if it's possible at all? And if not, maybe i could
implement something very close using Cocoa facilities?
Basically i need this, to make my application look as similar as
possible to my Windows version.
Thanks a lot!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Display a "Red frame" on the screen

2011-04-08 Thread eveningnick eveningnick
thanks andreas, i'll look at that
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Display a "Red frame" on the screen

2011-04-08 Thread eveningnick eveningnick
Hi David,
thanks for the answer

I was thinking about the window. But then it has to be something with
a big hole inside. This hole ought to be transparent for mouse clicks
(so if there's something below my "window", that 'something' has to be
clickable and focused, and receive keyboard input)? Is it possible to
do somehow? Borderless is a window without a title (as i understand).
What kind of properties should i specify to make a window as that "Red
frame"? I mean, i really want it to be just a mark for the user,
without any "windowing" behaviour (well, the user can drag it, if he
clicks on the 'red frame' with mouse, but that is the only relation to
a real window it should have).

In OS Windows i would probably use "Regions" API, but i have no idea
what to do in Mac OS. Could you give me a clue?
thanks

2011/4/8 David Duncan :
> You can use NSScreen to get a list of available screens and then just create 
> an NSWindow on whatever screens you want. You probably want a borderless 
> window (which is a flag you can pass when you create the window) so that the 
> window doesn't have content by default.
> --
> David Duncan
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Display a "Red frame" on the screen

2011-04-08 Thread eveningnick eveningnick
Hello
I have two monitors attached to the computer, and when i click in
"System Preferences/Displays Preferences" on the "display" image
(Display arrangement tab), the screen of the clicked "scematic
monitor's image" monitor is being surrounded by a red frame.

How could i do something like this from my application? I don't need
the red frame around the whole screen, but i would like to have some
area on the screen. Is it possible to do using some kind of API?
Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Retrieve camera's parameters

2011-04-02 Thread eveningnick eveningnick
Hi
I am developing a QTKit application for capturing the camera's output,
and i need to tell the user about what color modes and resolutions the
camera supports natively. QTKit itself does not provide such a
functionality - it sets up resolution automatically.

I am wondering, if there is any way to retrieve such an information,
bypassing QTKit iteslf?

Maybe some QuickTime low level APIs exist? Even obsolete ones (i.e.,
only 32 bit) will also work for me.

Maybe i could ask some driver for that info?

I really need this.
Is it really impossible, on any level of the system  APIs in OS X system?

Thank you
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


What to play a series of images on, to make it look like a movie [the fastest way]?

2011-03-17 Thread eveningnick eveningnick
Hello
I have a set of pictures, stored in RAM in RGB-32-bits-per-pixel
format (allocated via malloc).
What is nowadays the most efficient way to "play" this "video" - i.e.
a set of frames - in a window, avoiding unnecessary data recopying?

Should i just build CGImage's for every frame that i have in memory,
and render that to an ordinary NSImage visual component on ? Or onto
NSView? Or, maybe, QTKit's QTMoviePreview?
I am planning to use CoreVideo display link to display every new
frame. Maybe it is more optimal to use NSOpenGLView (since, perhaps,
data would go "directly" to OpenGL driver)?
This is a model task, where im trying to understand how to do things :)
Right now the only my concern is performance - the faster the better.
And what would be the "right way" - that adds the less code 'mess'
possible, but which maybe is not that fast?

Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: "Highlight" a window of another application

2011-02-24 Thread eveningnick eveningnick
> I need to somehow "impact" a particular window for the user, make it bold,
> change it's shadow color or add some kind of a frame around it - to remind
> the user that only this particular window is being 'grabbed'.
> Does WindowServer allow to perform such kind of operations on any level?
> What APIs should i look at?

Thanks Uli,
but how could i impact windows? Is there a way to decorate another
applications' windows, like drawing a little frame around. or changing the
color of the shadow? Maybe there is no direct way, but i am wondering if
some low level features available? As a user of my own application, i would
appreciate when i know for sure which window is being "recorded". Or Window
server does not expose any APIs for manipulating other applications' windows
(except accessibility APIs)?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Fast way to grab the screen

2011-02-24 Thread eveningnick eveningnick
Thank you for the answer
So i guess OpenGL is a way to go.

And with it, i have two problems:
1) how to select only a particular window to grab? Since im getting a
framebuffer contents, i am having the whole screen picture.  I need to cut
out only a particular region of it - that contains a particular window only.
For that, i need to know the location of this "particular window" and its
size.
I am wondering, if WindowServer exposes any API for getting this information
for other windows? Or, otherwise, maybe, i could combine somehow CGWindow
API and OpenGL (the first for finding "edges" of the window, and the latter
for taking the whole screen and trimming in to these edges)?

2) how to grab a mouse pointer too? Like Skype, or ManyCam do, for example?
They allow to save an image (or video) together with the cursor. How did
they do that?

Could you point me out?
Thank you!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


"Highlight" a window of another application

2011-02-24 Thread eveningnick eveningnick
hi
i am writing a small screen video grabber and i would like to have an option
there to grab only a particular window. This window may belong to another
application, of course.
I need to somehow "impact" a particular window for the user, make it bold,
change it's shadow color or add some kind of a frame around it - to remind
the user that only this particular window is being 'grabbed'.
Does WindowServer allow to perform such kind of operations on any level?
What APIs should i look at?

Also i am wondering if there is a way to create a "transparent window" - a
window, that has a frame and a title bar, but whose insides are transparent
- you can click with a mouse button on it and your click will "go" to the
other window, that is below this one, and you can see the contents of the
window below through this "transparent window". Is there any way?
And, if not, maybe you could suggest some other way to let user know what's
being grabbed?
The system is Snow Leopard (and higher) only

Thanks for the answer!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Fast way to grab the screen

2011-02-23 Thread eveningnick eveningnick
Hello
Which way is faster to get the picture of the desktop (or some of its
windows): using CGWindow API or OpenGL?
i am trying to write a video grabber, CGWindow API seems pretty convenient
(because it allows to select which window to "grab"), but i am worried about
the speed, because i need to record the grabbed frames to the video file.

Also i am wondering, if it is possible to "grab" the mouse cursor picture
together with the window picture?
Thanks for any answer!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Reliable way to determine bitness of the kernel

2011-02-22 Thread eveningnick eveningnick
thanks for detailed description of the solution
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Reliable way to determine bitness of the kernel

2011-02-22 Thread eveningnick eveningnick
hello
i have a kext (or, rather, 2 kexts - one built with -arch i386, another one
with -arch x86_64). They should work on both OS X 10.5 and 10.6.
i have an installing script, which looks like
if [ `uname -a | grep x86_64 | wc -l` ge 1 ]; then
   cp -R "64bit.kext" "/Library/Extensions/"
else
   cp -R "32bit.kext" "/Library/Extensions/"

this goes into production code.
But unfortunately, it seems like it does not work well on all systems.
What caveats may this method of determining the bitness of the system have?
It works fine on my Leopard and Snow Leopard (even though my Snow Leo runs
in 32 bit mode), but other people complain that the driver is not being
installed.
Maybe some instances of the system are missing any of the command line
utilities i used?
Could you suggest a better way of determining the bitness of the kernel?
Thanks for any advice!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Execute a pre-starting script first, when the App bundle is launched, then the main executable

2011-01-08 Thread eveningnick eveningnick
> The one that comes to my mind immediately, is that if the user is 
> double-clicking a document in the Finder to open it, or trying to print from 
> the Finder, then the event for that goes to your script, not the real 
> application. So the script would need to pass that on.
>
> Assuming your app even deals with documents, which based on some of your 
> prior posts re pref panes, seems like it may not.

Thanks Scott for the answer

My Main Application DOES deal with documents and even URLs, so i guess
i will have to pass on requests which need to be processed according
to CFBundleDocumentTypes and CFBundleURLTypes.
I guess i could implement in a script (or, rather, a "thin"
application)  interceptor of odoc, pdoc and GURL apple events. and
execute Launch Services functions on the final bundle of Main
Application (which has a role of a helper tool), but are these all the
caveats i need to follow?

As far as i understand, this "drag to dock" issue is basically sending
"odoc" apple event as well?
Are there any possible pitfalls?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Change the NSPreferencePane window size programmatically

2011-01-07 Thread eveningnick eveningnick
Kyle,
thanks for the warning, i understand the problems it may cause.
but what if i was doing that, how should have i sent a message to an
object of the host application?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Change the NSPreferencePane window size programmatically

2011-01-07 Thread eveningnick eveningnick
Hello
is it possible to set up the System Preferences height programmatically?
I have 3 possible NSViews of different height (but the same width),
which are displayed depending on what current settings does the user
have.

I am aware that System Preferences automatically changes the size of
its window when it "activates" (loads) a Preference Pane, depending on
that Pane's window height which is loaded from nib.

But is there a way to change that height after the panel has been activated?

I was thinking that my pane is operating in the address space of
System Preferences, which means i can send messages to objects of this
application. Can i somehow retrieve the object of main window and send
it something like "-setFrame" ?

Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Execute a pre-starting script first, when the App bundle is launched, then the main executable

2011-01-06 Thread eveningnick eveningnick
> You can't do this. The Info.plist needs to refer to the main app's
> binary. Instead, put your checks into the main app's startup code.
> -[ applicationDidFinishLaunching:] would be a
> good place.
>
> This will require changes to the main app.

What if i rename the Main Application's executable from
   /Applications/MainApp.app/Contents/MacOS/MainApp
to
   /Applications/MainApp.app/Contents/MacOS/MainApp1

and rename my pre-startup script to MainApp (and place it in
/Applications/MainApp.app/Contents/MacOS/MainApp)?

The problem may occur if this is LaunchServices who is responsible for
delivering info (like main nib filename, or principal class name) from
the plist to the application, but as far as i know this information is
retrieved by the application itself, which means that if my script
launches this renamed Main Application's binary
(/Applications/MainApp.app/Contents/MacOS/MainApp1) the main
application should act as usual - read its plist, etc.

i know It looks like a dirty hack, but is it possible to do this way,
without modifying the main application (except simple renaming of its
binary)? What pitfalls could i run into, doing that?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Execute a pre-starting script first, when the App bundle is launched, then the main executable

2011-01-06 Thread eveningnick eveningnick
Hi
I have an application, which is located in a bundle (like any other
cocoa app) and can be installed in a mac-way: by dragging its bundle
to /Applications (or elsewhere).

I have been asked to create an "addition" to this application, that
adds some functionality, but needs to be installed using an installer
(or a script, that requires superuser) - in short, it can't be simply
dragged.

I came up with the following, which seems reasonable to me:
i will copy the pkg installer of my Addin-application into the Main
application's bundle. The user will be able to drag the bundle to
/Applications as usual, but after he doubleclicks this application,
instead of a binary executable from
/Applications/MyMainApp.app/Contents/MacOS/MyMainApp, a script will be
launched, which will first detect if my Addin-application has been
already installed (and if not, launches an installer), or just
launches the executable from
/Applications/MyMainApp.app/Contents/MacOS/MyMainApp.

This approach would require very few changes from the MyMainApp
developers, which is my goal.
I am wondering, what changes have i to make to the bundle's plist - i
want my script to be launched first, but the Main application should
find its definitions of Principal Class, Main nib file, etc.

How can it be done?

Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: execute system("some script") on behalf of root from non-root app

2011-01-06 Thread eveningnick eveningnick
> Executing arbitrary scripts as root is also a potentially major security 
> hole.  Your goal should be to do as little as possible as root (or other 
> elevated privileges), and with as little flexibility as possible.
>
> Security is hard, and if you don't understand the issues, you should take a 
> step back and learn them before attempting to work them.  If you get them 
> wrong, you've just exposed your customers to having their machine attacked.

Yes, this kind of applications should be thought throughoutly.
The biggest problem is the replacement of the helper tool - if it is
replaced, or an alias is created with the same name in the directory
of the calling application for ex, which is pointing to a malicious
app, that malicious process will be executed with root privileges
instead of a real helper tool which can do anything on the system,
remaining invisible. For conspiracy it can launch a genuine "helper
tool" after doing bad things. So when your application gets popular
(and bad guys find this security hole), it can be and most likely will
be exploited.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: execute system("some script") on behalf of root from non-root app

2011-01-06 Thread eveningnick eveningnick
>Search google is not an answer, although a good suggestion. Could you please 
>post the solution you came up with to the >list. There are many ways to skin 
>this cat, I think we would all benefit from your experience.

Every process that is running on a system has two user id numbers -
effective UID and real UID. The first identifies what a process can do
(privileges), the latter says, who had launched this process. they are
often the same for a usual process, but may differ in the case when
the executable has suid bit set (then the real UID will be the one of
the  user who launched the process, and effective UID will be the one
of the owner of this file, thus a process can do things that the owner
of the file would be able to do, even though its launched by a
different user), or if a process has been launched via
AuthorizationExecuteWithPrivileges.
When one is calling launchctl, it checks real UID and, depending on if
it is 0 or not, it talks either to system-wide instance of launchd or
to session-wide.
having an effective UID of root means that you can do root-like
operations, for ex. execute setuid(0) which would change your real UID
to 0 - i.e. to root. After that your helper process can talk to
system-wide instance of launchd.

I tried sudo before, it didn't work for me - in System Console i kept
getting password requests.

2011/1/5 Shawn Bakhtiar :
>
>
> Search google is not an answer, although a good suggestion. Could you please 
> post the solution you came up with to the list. There are many ways to skin 
> this cat, I think we would all benefit from your experience.
>
> Correct. You are NOT running them as root, but you can easily tell the script 
> to "sudo su" and go from there, which in effect will make you root.
>
> Also have you looked at making the uninstaller be an apple script?
>
> Also does any one know if there is a setup program like there use to be on 
> Windows (IE Nullsoft)?
>
>
>> Date: Wed, 5 Jan 2011 21:40:09 +0200
>> From: eveningn...@gmail.com
>> To: n...@chronosnet.com
>> CC: cocoa-dev@lists.apple.com
>> Subject: Re: execute system("some script") on behalf of root from non-root   
>>  app
>>
>> Thanks Nick, i really should've googled before asking.
>> ___
>>
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/cocoa-dev/shashaness%40hotmail.com
>>
>> This email sent to shashan...@hotmail.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: execute system("some script") on behalf of root from non-root app

2011-01-05 Thread eveningnick eveningnick
Thanks Nick, i really should've googled before asking.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


execute system("some script") on behalf of root from non-root app

2011-01-05 Thread eveningnick eveningnick
Hello
I am trying to write a simple uninstaller, that has to call few
root-demanding actions - stopping/unloading daemon and unloading kext.
I can do that from a script-uninstaller, like this:

#!/bin/sh
launchctl stop my.agent
launctctl -w unload /Library/LaunchAgents/my.agent.plist
sudo launchctl stop my.daemon
sudo launchctl -w unload /Library/LaunchDaemons/my.daemon.plist
sudo kextunload /Library/Extensions/mykext.kext

when i run this script, it requests password for the first encountered
sudo command (if the sudo's timeout had expired).

I want to do all these operations from within a GUI
application-uninstaller for the convenience of the user.

What i did - is created a helper tool, which executes system() for
every line of the script above. This tool is launched when "Uninstall"
button is clicked in my GUI application. I do it this way:

- (IBAction)uninstallButtonClicked:(id)sender {
AuthorizationRef authref;
const char *uninstallHelperPath = "/Library/Application
Support/MyApplication/UninstallHelper";
AuthorizationItem item = {
kAuthorizationRightExecute, //name
strlen(uninstallHelperPath),  //value length
uninstallHelperPath,  //value
0 //flags
};
AuthorizationRights requestedRights = {
1,  //count
&item   //array of authorization items
};
OSStatus result;
result = AuthorizationCreate(&requestedRights, 
kAuthorizationEmptyEnvironment,
kAuthorizationFlagExtendRights 
| kAuthorizationFlagInteractionAllowed,
&authref);
if(result != errAuthorizationSuccess)
return;
AuthorizationExecuteWithPrivileges(authref, uninstallHelperPath,
kAuthorizationFlagDefaults, /*arguments*/ NULL, NULL);
AuthorizationFree(authref, kAuthorizationFlagDestroyRights);
}

Having clicked on a button, it requests admin's password and launches
the helper tool. But in System Console i see messages like "to unload
kext you need to be root", "unable to stop the daemon". Only agent can
be stopped.
Why does this happen? Isn't my helper application works already on
behalf of root already? Then why does it ask me to switch to root once
again if it is lauched as root already?

Thanks
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Close System Preferences programmatically

2011-01-04 Thread eveningnick eveningnick
> - If you really want System Preferences to quit, you could use NSAppleScript
> and do something like:
> tell application "System Preferences" to quit
> You can do the same using AppleEvents.

Peter, could you hint me on how to do it using AppleEvents?

Googling, i have found some references to OmniAppKit:
"There's a working example of using Apple Events to do this in the
published Omni frameworks --- let's see, it's OAOpenSystemPreferences
(), in OAPreferenceController.m, in OmniAppKit."

I havent found this kit though, it is quite outdated.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Close System Preferences programmatically

2011-01-04 Thread eveningnick eveningnick
Hi Nick
Thank you
I've an unusual application that is mainly located in System
Preferences (its gui part), and which can be uninstalled by clicking a
button "Uninstall" in that prefpane

better solution would be to programmatically press "Show All" button
("back" in System Preferences), but that seems impossible because
PrefPane reference doesnt mention have to do that.

if someone knows there is a way to click "Show All" from a preference
pane programmatically, i'd be thankful
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Close System Preferences programmatically

2011-01-04 Thread eveningnick eveningnick
Is it possible to close System  Preferences programmatically from
within a custom preference pane? What would be the correct way?
Is it possible to programmatically press button "Show all"?
Thanks
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Application that uninstalls itself

2011-01-04 Thread eveningnick eveningnick
Thanks everyone for advices!

2011/1/4 James Bucanek :
> In my application, I have a special "Uninstall and Quit" menu item. I
> shutdown and delete launchd configuration files and them move the active
> components (plug-ins, helpers, ...) to the trash. I find this avoid the
> problem of deleting files that are part of a bundle (for the plug-ins) that
> is still in use, and my customers like the transparency of seeing what was
> removed and being given the control over when they're ultimately deleted.

James, how do you delete launchd conf files? Did you delegate all such
operations to a helper tool, and launch that tool using
AuthorizationExecuteWithPrivileges ?

I have written an uninstaller script, and now looking for a way to
"integrate" it in my non root application with "Quit and uninstall"
button. (This non root app is not writable by anyone but root).

What i have thought so far, is to create a helper tool, with a
system("here is the content of my uninstalling script file") call,
then i am going to launch it using AuthorizationExecuteWithPrivileges.
I don't know if it's the right way though.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Communicating to a process started by root from non-root app

2011-01-03 Thread eveningnick eveningnick
> Unless I'm forgetting something basic, you should be able to connect to your 
> daemon's socket from a non-root process if you first change the permissions 
> on the socket (using chmod, as if it were a file). The man page for the 
> unix-domain protocol family alludes to this briefly:
>
>> All addresses are absolute- or relative-pathnames of other UNIX-domain 
>> sockets.  Normal >filesystem access-control mechanisms are also applied when 
>> referencing pathnames; e.g., the >destination of a connect(2) or sendto(2) 
>> must be writable.

I dont want everyone to be able to write to that socket, the point is
to let only System Preferences (for example, by displaying
"Autorization dialog box" - like "User Accounts" preference pane, for
example.
I am wondering if that is possible to achieve using Authorization Server and how

Thank you
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Communicating to a process started by root from non-root app

2011-01-03 Thread eveningnick eveningnick
Hello
i have a daemon whose owner is wheel:root and which provides a Unix
Domain Socket where i can send/receive datagrams from my custom
Preference Pane.
The problem i have is that a socket, installed by a root-process can't
be "sent" by a non-root application, like System Preferences.

I guess i can deal with the problem the following way: i create one
more helper executable, which is "suid'ed", and "chown'ed" to root,
thus i can launch this helper tool simply for fork/exec'ing from my
non-root Preference Pane. This way i should establish two
"communication channels":
MyPrefPane (pipe or UnDomSock)--> HelperTool
---(UnDomSocket)--> Daemon

I am wondering if i could somehow increase System Preference's
privileges for a while, write to Daemon's socket directly, and
decrease privileges. Is that possble?

I have read AuthorizationServices reference, but still feel a little
misty about what can and can't be possibly done.

How do all other preference panes work? do they all load helper tools,
and there's no detour?
Thanks
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Application that uninstalls itself

2011-01-03 Thread eveningnick eveningnick
Hello
I am writing an application that for users convenience has a button "Uninstall".
Inside, this "uninstaller" stops several launchd services,
"kextunloads" a driver, deletes this driver and services and finally
is supposed to delete itself.
In any sane operating system it is impossible (at least, directly) for
an application to remove a file that is running.
Hence i am searching for a detour.

The uninstaller is a helper tool, which has a suid bit set. I am
fork/exec'ing this helper tool when a user clicks "Uninstall" button
in System Preferences custom preference pane.

The only way i am seeing how to completely remove everything my
installer had installed, and to remove the preference pane (that
contains settings and this "Uninstall" button) itself, is to delegate
"unlinking" of files to some external tool - like AppleScript
(fork/exec the "osascript" and terminate the parent process). But
then, i am unsure about privileges issue.
Should i be calling osascript with AuthorizationExecuteWithPrivileges?
But the what happens if my uninstaller application terminates right
after it calls this function? (i need to terminate it, to let the
script delete uninstaller's executable).

Could you give me some hints on where to look and what would be the
best approach?
Thank you!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Deleting root:wheel-owned file and stopping root daemon

2010-12-28 Thread eveningnick eveningnick
Hello
How do these operation can be performed from a cocoa application?
I have read through Security server, credentials and rights documents,
but to be honest got lost in tons of information. what kind of rights
should i acquire from security server to delete root-owned file and to
stop root daemon? Maybe someone could write few basic steps i need to
do? Id be very thankful

Thanks for the response
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: PreferencePane: To use xxx System Preferences must quit and reopen (Snow Leo 10.6.3)

2010-12-13 Thread eveningnick eveningnick
Thanks for the answers,
i enabled Garbage collection,
The problem was that i had "Build for active platform" checkbox
checked, i unchecked it and it started working fine
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: PreferencePane: To use xxx System Preferences must quit and reopen (Snow Leo 10.6.3)

2010-12-11 Thread eveningnick eveningnick
interesting thing is that it works, if the project is created as a
Preference Pane, while the "Bundle" project (there is a recipe for
creating preference panes using "Bundle" xcode template) doesn't work
as needed. I matched two projects - one created as "Bundle" manually,
and another one generated automatically as "Preference Pane" xcode
template - the first one keeps asking to switch System Preferences
into 32 bit mode - but i couldn't find any differences.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


PreferencePane: To use xxx System Preferences must quit and reopen (Snow Leo 10.6.3)

2010-12-11 Thread eveningnick eveningnick
Hello
I am creating a system preferences applet (according to apple's
guide), but after installing (copying) its bundle into
/Library/PreferencePanes/, and clicking it (or selecting its icon in
System Preferences app), i always get the message from the subj.
My OS is running in 32 bit mode:
$ arch
i386

I tried to select in project settings "32-bit universal", "64-bit
Intel", "Standard 32/64-bit universal" - the first and the last still
are causing the message "System preferences need to quit and reopen",
while the second doesn't work displaying error message (which is
natural).

I am wondering why does that subj message appear?

By default System Preferences runs in 64-bit mode (on 64 bit machines,
if the OS X is started in 64 bit mode). I am starting the system as a
32-bit one. I assume, in this case System Preferences should run as 32
bit as well. Why does it ask me to relaunch into 32 bit mode?
After clicking Ok, and System Preferences "quits and reopens", there's
a text "32-bit" in its title, and i can click on any icon including my
"applet" without this subj message appearence - unless i quit System
Preferences and open it again.

What am i doing wrong, and how can i get rid of that message for my
preference pane?
Thanks
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


What is Mac's "custom" for an agent to display its GUI?

2010-11-16 Thread eveningnick eveningnick
Hello!
I have to write an application, that should run on the background.
When the user needs, it should display some control panel. On Windows
system i would have used System tray, and an icon there - when the
user clicks on that icon, it displays some GUI. but what is the Mac's
usual practice? I am thinking that the analog to that tray application
is an agent, launched by launchd. On what event it is considered to be
good to trigger that "control panel"?
All i could think of - is installing a global event tap (but i need
accessibility Enabled then all the time - it is neither a good idea)
and watch some Shortcut pressed on a keyboard.
Another idea was to create an item in "System preferences" (but, could
it be done? And how?).

And where should I install that application? Installing in
/Applications doesn't seem to be nice, because it's not really a
full-gui applicatlion, It's rather some kind of background system
helper.

Thanks for the hints,
George
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Get current caret position

2010-11-16 Thread eveningnick eveningnick
> Hi George,
> What you want to do would is within another's application.
> Any public hooks/APIs could be used...
> In this case VB and AppleScript.
> For deeper, Cocoa-based integration, you would probably need to work with 
> Microsoft.
> Couldn't hurt to try contacting them...
>
> The means mentioned earlier are from within your own application.
>
> You might also look into building an app/tool as a Service...

Hi John
Thanks for the answer
The problem is that AppleScript allows to discover the caret's
position only relatively to the page's left-top corner, while there is
no way to determine that "page's left-top corner" absolute position.
Thus, i can't place my popup window where the caret is located. I am
pretty sure, Visual Basic doesn't give much more possibilities (AFAIK,
VB and AS operate on the same core API, which is closed to public).

And about "For deeper, Cocoa-based integration, you would probably
need to work with Microsoft".
What do you mean by working with Microsoft? I am not sure, but as far
as i know, they don't give out this low level API to 3d party
developers? And how could i contact them?
Perhaps some of Microsoft Office developers are looking through this
mailing list. Is there a place where i could find information about
who and on what conditions could get that mac:Office Word SDK APIs?

>You might also look into building an app/tool as a Service...
but what advantages does building as service has comparing to an
ordinary external Cocoa application?

Thanks,
George
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Get current caret position

2010-11-16 Thread eveningnick eveningnick
> The text caret doesn't have a single, global position. It is really the 
> position of the text selection within an active text view when the selection 
> length is zero. If you want to know which logical characters the insertion 
> point is at in a given text view, that's easy to find - just get the 
> selection range and the location field is the position of interest. The text 
> system has methods to convert the logical character position to a view 
> position and from there to a screen position, but why do you want that? In 
> other words, what are you really trying to do?
>

Hello, Graham
Basically i want to get the text caret position in Word 2011 active
document window. I want to place a popup window on that location.
Microsoft Word 2011 SDK is not available to public (i am not even sure
if this SDK includes such a GetCaretPosition() function, most likely
that the answer is No).
Thus i was thinking that as long as Word 2011 is a cocoa application,
its document is most likely something like a modified text field (not
sure though) and i could get that position (at least, relatively to
the main window's pos).
(there's a built in Visual Basic function called "Get text selection
position relatively to page", but that there is no way to determine
that page's location)
Would that be possible to achive using cocoa framework's means?
Thanks,
George
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Get current caret position

2010-11-16 Thread eveningnick eveningnick
Hello
I a wondering, if it is possible to get the current screen position of
a text cursor (text caret) using Cocoa? It is possible to do that in
Windows system (GetCaretPos), maybe Mac allows some similar
functionality?
Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Launchd and terminal process launch - is there any difference from that process' viewpoint?

2010-11-08 Thread eveningnick eveningnick
Hi Ken, thanks for the answer

> > Does the first one has some restrictions when it calls Accessibility
> > functions?
> It may, depending on the session type.  Have you set LimitLoadToSessionType 
> in your agent's launchd plist?
>

no, i haven't specified that

>
> > This Launch Agent is supposed to be started everytime, when the system
> > starts.
>
> When the system starts, or when a user logs in to a GUI session?

it is a "Session-start" agent. But: i can start this agent by writing
"launchctl load ~/Library/LaunchAgents/com.my.agent.label.plist"
"launchctl start com.my.agent.label"
in terminal, and i will get the same behavior - in MacOS 10.5 i
experience troubles. If i start it via terminal, it works great.

>What's the point of your agent running for a given user when that user is not 
>logged in?  You may be configuring your agent to be always running at the cost 
>of full access to the Window Server and its services.
Is "session-kind" agent loaded when the user isnt logged in? Well i
didnt delve much into that, i only specify it's a "session-type" and
was glad it worked on Mac OS 10.6.

Maybe i should try some special options in plist? I only specified
there "Start On load", "Not On Demand", working directory and a path
to the binary.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Understanding the Run loop idea and the updating of controls during long operations

2010-11-08 Thread eveningnick eveningnick
Hello Fritz

> You are understood: You want to learn how the high-level application and
> event API works by trying to recreate (or at least explain) it using
> lower-level API.
>
> You can't do it. At least not in general.
>
> To provide the high-level functionality, Apple uses the published low-level
> API, but it also uses unpublished API, and adds functionality that isn't in
> any API, and the whole thing relies upon undocumented interactions between
> all the APIs it uses. Apple can do this because every time it revises the
> high-level calls, its engineers know what the low-level and private calls in
> the same OS release will do.
>
> You don't know what Apple knows, and the whole idea of a high-level
> framework is that you do not have to know, and you should not know. You can
> rely on what the documentation says the high-level API does, but you can't
> rely on (or, usually, accurately reproduce) how it does it. Anything you
> try, to duplicate the high-level functionality, is only a partial guess.
>
> The way to understand Cocoa is to use Cocoa as it comes to you. Using Cocoa
> means trusting it to do its job even though you can't see inside it. That is
> in the nature of any modern application framework.
>
> I programmed for the original Mac, in C. It had an API that could be fully
> documented in well under a thousand pages. It was implemented in code that
> was easy to disassemble and read. I could explain what was going on inside
> every call I made. I wrote my own event loop, and handled my own interrupts.
> Those days are gone, and it is horrible to think of going back to them.
>
> Thank you, that's really the topic i am interested in :). I am wondering,
if any kind of "Mac OS Internals" books exist,
except "Mac OS Internals: A system Approach" by Amit Singh? Maybe you know
some blogs of the developers, or something else to read? Or is this kind of
info "a top secret"?


> For your more-specific question, I found many promising leads by googling
> "cocoa application modal progress bar".
>
Yes, i should've typed that in search bar myself before asking the question.
I have found the answer.


> PS: Yes, you can — when necessary — substitute notionally lower-level API
> (ex: Core Foundation, Application Services, BSD) for many things that are in
> Cocoa. (I say "notionally lower-level," because that API is sometimes
> implemented in terms of Cocoa, and not the other way around.) In this
> particular context of learning Cocoa and duplicating the core of
> NSApplication, that's a bad approach.
>
>
That is nothing more than having a good feeling about understanding how
things work in real under the hood. Of course, these things may and will
change with every new version/patch/whatever, but still there are people who
hardly can write any highlevel line of code, without knowing what is really
going on inside the system. And of course, this is insane to put such adhocs
into production.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Understanding the Run loop idea and the updating of controls during long operations

2010-11-08 Thread eveningnick eveningnick
>
> On >10.6 you can safely execute Apple scripts from a secondary thread (see
> previous thread on this matter).
>
> Well, I just checked this using an NSOperation object which executes a
> script. The operation can be alternatively executed on the main thread
> scheduled by the global queue [NSOperation mainQueue] or it can be executed
> on a secondary thread scheduled by any queue which you get via
> [[NSOperationQueue alloc] init]. There is no noticeable difference in the
> execution time of the script, which takes about 15 seconds. (As a contrived
> example, the script launches TextEdit which itself opens a text file of
> about several kByte. The script counts the words, builds a list of words and
> an internal sort routine sorts these words and returns the sorted list.)
>
> The Cocoa app is just a few lines - and it doesn't require any thoughts on
> how to handle the run loop -- there is simply no need for this. There is no
> need for synchronization as well, unless you schedule a number of operations
> concurrently which modify the same object (say a file, or whatever).
>
> I should note however, that a script is not "cancelable" -- it performs
> "atomically" regarding the NSOperation's main method. So, in order to make
> the NSOperation's main method interruptible, you need to partition your work
> in a sequence of smaller actions executed by one or more scripts. Then call
> them in sequence -- preferable in a loop. Before you execute the next script
> you check the cancellation state of the NSOperation. Just return from -main
> when someone had cancelled the operation. The operation can send messages
> about the progress to its delegate (note: custom NSOperation, which defines
> also an appropriate delegate protocol) in every loop as well, and may return
> a result when it eventually finished.
>
> When the NSOperation executes on a secondary thread, the app's main thread
> isn't blocked and receives and processes input without any noticeable delay.
>
> The most challenging task is probably to partition a given script, so that
> the task becomes interruptible when executed in a NSOperation.
>

Thank you Andreas, i really appreciate your work. I dont really know, why
did it slow down in my case.
Well now we know it should work without any slowdown :)
My application has to be able to be launched in Leopard as well, therefore
i've left this multithreading approach and i just run the runloop
periodically inbetween "applescript chunks" during that long operation.
Fortunately, it works fine so far, updating all the controls "in time".
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Launchd and terminal process launch - is there any difference from that process' viewpoint?

2010-11-08 Thread eveningnick eveningnick
what is the difference between a process that was started by launchd and the
same process, started via terminal (without sudo command) in Mac OS 10.5?
Does the first one has some restrictions when it calls Accessibility
functions?

Here is the Preface to my problem. (i apologize that it is a little
complicated and long but i didnt know which parts of the story are
insignificant)

I have three applications: A terminal application written in C (let's call
it a Launch Agent), a cocoa application (let's call it PlugIn) and some
third party GUI app (Master Application).
This Launch Agent, being launched, watches for all other process being
launched, and when it detects that third party Master Application has been
started, it launches PlugIn app.

This Launch Agent is supposed to be started everytime, when the system
starts. That is why i have created a launchd plist file, and i can
start/stop this agent using launchctl command. But of course, I still can
start Launch Agent by opening Terminal, changing directory to the folder
where is located and just typing its binarie's filename instead.

Thus, there are two way to start PlugIn Application:
1) LaunchD starts Launch Agent, which starts PlugIN when Master App is
started
2) a user from terminal starts Launch Agent, which starts PlugIN when Master
App is started

The PlugIn app installs "accessibility application state observers" into now
launched Master Application, using AXObserverAddNotification(myObserver,
thirdAppElement, kAXApplicationDeactivatedNotification, NULL); (actually, it
installs kAXApplicationDeactivatedNotification,
kAXApplicationActivatedNotification, kAXApplicationShownNotification,
kAXApplicationHiddenNotification).

Now the problem i am faced to:
In Mac OS 10.6 it all works great and i get error code 0 (NoError) after
calling AXObserverAddNotification, and my callbacks are called when the
status of Master Application changes (like activated/deactivated). No
matter, by whom the PlugIn app had been started - by started from a Terminal
manually Launch Agent, or by Launch Agent started using launchctl.

In Mac OS 10.5 i get a problem: the application still works flawlessly if i
Launch Agent is started from a Terminal, but  the function
 AXObserverAddNotification constantly returns kAXErrorCannotComplete. The
Master Application is already launched, it has displayed all its windows,
but i still can't register a callback. (interesting fact that i still can
successfully install EventTaps into that Master application though).

What can cause such a behaviour? The only sane explanation for me is
that in Leopard the process, started by launchd and by a user (via
terminal)  -- and therefore the processes (like, my PlugIN), spawned by such
a process, do not have equal privileges to call accessiblity functions. What
could i do to deal with this problem?

If what i described isn't clear enough, i can write a "model" of this
situation - two simple applications - to show "on a real example".

Thanks for any answer!
George
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Understanding the Run loop idea and the updating of controls during long operations

2010-11-07 Thread eveningnick eveningnick
Hello Scott


> You seem to be trying to find ways to use the frameworks in ways that are
> not intended. Why are you not using NSApplicationMain in the normal way?
>
Just for the sake of my own understanding. There's nothing extraordinary i
am doing there, but for example, i need to "delay" the launch of my
application and registering all the observers/event taps before the "master
application" starts


> Two reasonable choices are:
>
> - A single thread, where your processing is implemented as a finite state
> machine that can yield after a bit of work and return to the run loop, but
> sets an NSTimer to fire in 0 seconds just before it returns.
>
I will try that, thank you, but just wondering if i could do the same using
[NSRunLoop mainLoop], by calling -runMode:beforeDate:? Is it the same as
scheduling a timer? If i could use that, what should i have specified in
date? Current date? Current date+some time? what would be instead of that
time?
I am asking just to get the idea of that thing...

>
> - Multiple threads, figure out your bug with synchronization around
> AppleScripts (there is no reason the library would run slower just because
> you add a new thread).
>
I am not doing no synchronization at all, nor i need any for my application.
I was thinking this is done by the framework, only because i was reading
that NSAppleScript wasn't thread safe, and became so only lately. But as
long as "we shouldn't care how is it built inside", i only assumed this
thread safety had been provided in exchange of performance (when the apple
events - this is how NSAppleScript allows the application to retrieve result
value from applescript - are still received in the main thread, which
suspends both threads or something). Well actially i get a general
performance slowdown.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Understanding the Run loop idea and the updating of controls during long operations

2010-11-07 Thread eveningnick eveningnick
Hello Ken

If you don't have a handle on the basics, it's foolhardy to get into
> advanced techniques.

I am  trying to  understand these techniques step by step, it is really
difficult for me when everything is hidden :(

>
> > I assume i should call a one run through the runloop manually, but how?
> I recommend that you not attempt to "invert" the event loop or build one
> yourself.  The "modal session" methods of NSApplication
> (-beginModalSessionForWindow:, -runModalSession:, and -endModalSession:)
> seem like a good fit for your requirements.  It does entail implementing
> your long operation as a bunch of short work units.
>
Could you please explain what will happen when i call these methods? Why is
it better than just calling "update label text and go through the runloop"?
Why is it "the right way" and why does it trigger running through the run
loop? I would never guess i need to call it - reading apple docs it would
only lead me to use it only to display a modal window (the one, that makes
the runloop "receive" only those events that are sent to that window and
switches the runloop into another mode with another set of sources).

>
>

> > Here's what CoreFoundation reference suggest to do:
> >
> > CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false)
> >
> > this is supposed to call only one run through the runloop. But, according
> to
> > the documentation "If multiple sources or timers are ready to fire
> > immediately, only one (possibly two if one is a version 0 source) will be
> > fired, regardless of the value of returnAfterSourceHandled.". I have more
> > than one source: it is a label update (well, GUI events, i am not sure
> how
> > to call it - something like redraw i guess), event tap source (that is
> > installed into another app), and i am also observing another
> application's
> > state changes (when it becomes active/showed/hidden/inactive). Therefore
> i
> > can't specify 0 is the second parameter? Then what number should i
> specify?
> > 0.1? 0.5? 1? 10? how can i know how long it needs to be executed? And i
> dont
> > still want to slow down the processing waiting 1 second on every label
> > update. (i call these updates several times during processing the "big
> > file")
>
> All of these questions indicate that 1) you're deep in the weeds and over
> your head, and 2) you're caring about irrelevant minutiae of implementation
> details, exactly what you should avoid paying any attention to.
>
Perhaps, but let me explain a little more what my task is: It can be a
really huge file to process (it may take 1,5,10,20, 30 minutes to process).
Therefore, after every lets say 1 second i want to display the progress (i
want to look it smooth, not to give the feeling of freezing of the app -
thus 1 sec - it's like copying a file, but involving a lot of
Applescripting). Waiting for another one second  would result in twice than
needed processing time (40-60 minutes). Is it the "price of [indication of]
a progress"? And i really have no understanding in what do these methods do,
why there is this "time idea" and how is it supposed to be used (how a
developer can have any idea of what time does it take to process a set of
events while preemtive scheduling is enabled? I try to notice similarities
with window's timeout idea, but in windows that thing was created for long
input output operations, to make application "more responsive" - for
example, after 10 secs passed, windows will ask a user that the app is not
responding and if he or she wants to wait more, or to kill the task. Sorry
for windows analogy, but that's what i've been working with for a long time
before). You didn't answer on that question, i guess because you didnt want
to repeat some reference, but which one then?

>
> > o Why isn't label updated immediately on OS X 10.5, when i call
> > -setTextWithMnemonics? Does it require passing the event loop to  update?
>
> First, you're going to have to explain what -setTextWithMnemonics: is.  I
> don't find any method by that name in Apple's docs.
>
I am sorry, it was -setTitleWithMnemonic method of NSTextField, i wrote that
by memory


> Typically, when you set a control's value, it merely marks itself as
> needing display.  It does not display immediately.  Then, the framework
> takes care of displaying all views and windows needing display at an
> appropriate time (where the framework defines what's appropriate).
>
But when is it appropriate then? The only option left for me is
multithreading? But then this AppleScript "slowdown" appear.

>
> More questions you shouldn't care about.  -[NSApplication run] is built on
> NSRunLoop, which is built on CFRunLoop.  Beyond that, you are not entitled
> to know.  If you did know, you'd rely on it, which would constrain Apple's
> future flexibility in changing the frameworks.
>
Of course, but if i don't care, i won't be able to implement what i want and
to make it work right and fast at least on two systems - Leopard and Snow
Leopard :( Apple can

Understanding the Run loop idea and the updating of controls during long operations

2010-11-06 Thread eveningnick eveningnick
Hello
I am trying to understand how does Run loop work.
Here is my story
(i am sorry, it is a little long, but to avoid questions "why do you need
that" and others i thought better to write it down
here). I also read the CFRunLoop documentation, and event processing guide
in Cocoa, but I couldn't put it all into one big picture.

Basically the problem i need to solve is like the following:
I have a Cocoa application, which is a little "adhoc" - for better
understanding of the "internals" of my app i do not use application
delegates, and i do not call NSApplicationMain:

NSApplication *app = [NSApplication sharedApplication];
...some manual init code that loads nib...
[NSApp run];

I have a button on my window, and a text label. My application installs an
event tap into another application (CGEventTap).
When a user clicks on the button, a "long action" begins executing - this is
something like a processing of a big file.
I want a user to see the percentage of the operation displayed on the label,
and i want when my application's runloop receives Keyboard tap event (ESC
key pressed) from another application to interrupt processing of that file.

I've been asking similar question before, and i was suggested to use an
NSOperation for that - I should delegate the processing code to NSOperation
instance, and add that instance to NSOperationQueue. Then, having called
something like "run", my process creates a new thread, while my current
thread continues to run its runloop - which allows my application to react
to these "Event Tap"'s Events and to display the results normally.
An another option (which is almost the same as previous) - is to instantiate
NSThread.

Here is what i did instead:
when a user clicks the button, i simply call the "long processing" routine,
and inside that routine i call methods to modify the label's status (to let
the user know that my application does something useful, instead of just
"hanging"), and i periodically (after processing next chunk of that Big
file) i am checking a "cancellation variable" (that is set in EventTap
callback-handler function when ESC keypress received). And it worked!! (Snow
Leopard). Worked till the moment i tried my application on OS X 10.5, where
no updates were displayed on the label and no "event tap"'s events were
received untill the contiguous processing of the file was finished.

One of the reasons of using this approach (at least on Snow Leopard, where
it worked great) was a wide use of Apple Script calls during that
processing. Trying to implement the idea with another thread greatly
decreased performance (it's like the second thread tried to self-synchronize
with the main one, to perform apple script calls). I dont really know what
happened and why was it happening. Unfortunately my understanding of this is
very superficial. I only heard that before NSAppleScript had some issues
with multithreading, and it was adviced to perform -executeAndReturnError
only in main (GUI) thread.

here are my questions:
o Why does label update and why is event tap callback function called on Mac
OS X 10.6, but nothing is updated or called on OS X 10.5 during the
executiong of a "big file processing"? I assume, that when i'm calling
[mylabel setTextTitleMnemonics:@"Hey, we are not hanging yet, the file is
still being processed (10% done!)"] the run loop is being run through all
the runloop sources (including EventTap RunLoopSource). But, again, why
doesnt it happen on Leopard?
I assume i should call a one run through the runloop manually, but how?
Here's what CoreFoundation reference suggest to do:

CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false)

this is supposed to call only one run through the runloop. But, according to
the documentation "If multiple sources or timers are ready to fire
immediately, only one (possibly two if one is a version 0 source) will be
fired, regardless of the value of returnAfterSourceHandled.". I have more
than one source: it is a label update (well, GUI events, i am not sure how
to call it - something like redraw i guess), event tap source (that is
installed into another app), and i am also observing another application's
state changes (when it becomes active/showed/hidden/inactive). Therefore i
can't specify 0 is the second parameter? Then what number should i specify?
0.1? 0.5? 1? 10? how can i know how long it needs to be executed? And i dont
still want to slow down the processing waiting 1 second on every label
update. (i call these updates several times during processing the "big
file")

o Why isn't label updated immediately on OS X 10.5, when i call
-setTextWithMnemonics? Does it require passing the event loop to  update?

o What is the relation between [NSApp run] and a core foundation runloop?
What is the relation between NSRunLoop and core foundation runloop? Is
NSRunLoop an another while loop (in terms of programming language) that
"includes" core foundation while-loop? Then manual calling
of CFRunLoopRunInMode is not wise - i 

Re: Determine current mouse cursor position

2010-10-31 Thread eveningnick eveningnick
> If you want the *current* mouse location at the time you decide to display
> the window, use +[NSEvent mouseLocation] or -[NSWindow
> mouseLocationOutsideOfEventStream].
>
> However, it's more than possible that you should be using the mouse
> location *synchronized with the application's event stream*. AFAIK there's
> no way to do that directly, or 100% reliably. The best way I know of is to
> monitor the mouse location in every mouse event as your application
> processes it. In 10.6, you can use
> +[addLocalMonitorForEventsMatchingMask:handler:] to do this. In 10.5, you
> have to subclass NSApplication and override 'sendEvent:'. In both cases, you
> won't see any events consumed by modal event loops -- at least, those
> consumed in frameworks -- but it doesn't sound like this would matter for
> you.
>
> Why would you want to do the second (harder) thing? Consider what would
> happen, assuming for example that the window pops up where you right click,
> if the mouse is moving fast away from the window. If there's a slight delay
> between the click and the display of the window, the mouse might have
> already moved a long way from the click site before the window position is
> calculated.
>

Hi Quincey
Thank you  for the answer. You were right, i don't want to get the mouse
location as a snapshot.
Basically what i need to do - is to monitor system-widely, because i need to
watch that mouse not only when the mouse is over my app's window, but even
if it is over the Dock. And to monitor those events even if my application
is not active at the moment. I guess sendEvent works only when the
application is active and when the mouse is on top of the window? (and, as i
remember, some flag should be set to allow mousemove events me dispatched)?
Thanks again, George
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Determine current mouse cursor position

2010-10-31 Thread eveningnick eveningnick
Hello
I need to implement a functionality like Microsoft Word does for popup
windows - display a semi transparent popup window with the alpha value
calculated by the distance from the mouse cursor to the edge of the window.
It is a requirement for me, not just a decoration to look in a neat mac
style :)

How can it be done? Is it possible to do that without installing a system
wide even tap that watches mouse movements (i believe such a tap can
decrease the overall system performance)?

Thanks for the answer
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Operating with a file /Library/LaunchAgents/my.application.plist from a non-root application

2010-10-31 Thread eveningnick eveningnick
Hello
How, using an ordinary application (started by "doubleclicking" from
/Applications), i could create/modify/delete that file?
Is it possible at all, according to OS X current security model?
(Leopard and Snow Leopard)
Maybe i could display a "User login" inbox somehow then, to let user
authorise to perform that operation? What API should i use then?

My application - is an ordinary Cocoa app, created using XCode, if it matters
Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Writing an Uninstaller

2010-10-31 Thread eveningnick eveningnick
Thank you guys, i have written an Applescript for all that. That is
easy, and flexible :) And it can delete its own bundle, which is
important for me
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Writing an Uninstaller

2010-10-28 Thread eveningnick eveningnick
Thank you guys for answer, but the problem still remains for me

> HI ,
>   launch an applescript / shell script when uninstall button is clicked . 
> This should first quit  the App and wait for it to terminate and then delete 
> the bundle and plist
> Rajendran P

I'm sorry for asking such a primitive question but could you point me
how can that be done? How can i schedule a script to be executed after
my process is terminated? AppleScript call like

NSAppleScript alloc] initWithSource:@"tell finder to delete
something"] executeAndReturnError:nil];
[NSApp terminate];

can't do the job, because that -executeAndReturnError doesn't return
unless the launched script has returned. It looks like a deadlock -
the script should wait for my app to terminate, while my app is
waiting for script to terminate

Should i write an another *.plist to "program" launchd to execute a
script? What will it look like then? (by the way, is there a way to
make launchd execute some script without writing and saving a plist to
disk?)
Or what is the right way? What did you mean?

And, deleting my bundle requires Administrator privileges, which my
adhoc uninstaller doesn't have. Should i provide some kind of form to
ask for username and password then, like it is done in
PackageMaker/Installer? Or maybe the system provides some
interface/API for displaying that window? How can i escalate my
uninstaller privilege to be able to delete its own bundle, and its
stuff, that Installer has placed to ~/Library/Application
Support/MyApplication?

Angus, about
>Have you considered just killing the background process and then automatically 
>moving your app to the trash before quitting?

i do kill the daemon, and delete its plist, but how can i delete my
own bundle? the system just doesn't let me, i think because
Uninstaller is an Application from MyBundle.app/Contents/MacOS. Any
other launched binary (for example that background daemon) can be
deleted together with its bundle, but not an Application - it seems to
be protected by Finder or something

Thanks again!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Writing an Uninstaller

2010-10-27 Thread eveningnick eveningnick
Hello
I have an application that creats, when installed, a bundle in
"Applications" and registers a .plist file for launchd in
~/Library/LaunchAgents (the agent is located in that bundle, and its
process is launched everytime the OS starts).
Thus, i can't let a user just to move bundle to the Trash bin, when he
wants to get rid of it. Thats why, in a "control panel" of my
application, i placed a button "Uninstall", which
1) stops the Agent
2) deletes the plist file
3) [should delete the bundle]

This control panel is located in this bundle, that has to be deleted.
And in Mac OS 10.6 a bundle whose application is running can't be
deleted.
What could i do here to delete the bundle? What is usually done in such cases?
o) After "uninstalling", ask user to manually move bundle to a trash
bin, and then terminate control panel application? Seems pathetic,
especially when user already pressed "Uninstall".
o) Copy a "bundle-deleting script" to the "autorun once", that will
launch next time with the next system boot? It seems like a good idea,
but could it be done somehow without leaving traces afterwards?
o) Copy to some "autocleanined" (like temp or something) folder a
script, launch it and terminate control application. That script will
wait, till the control app is terminated , and then remove the bundle.
But does such a folder exist in MacOS? and how could it possibly be
done?

I don't want to rubbish  the user's Mac, if he/she doesn't like my App :)

Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Few binaries in one application's Bundle

2010-10-25 Thread eveningnick eveningnick
Thanks Uli, it worked!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Few binaries in one application's Bundle

2010-10-25 Thread eveningnick eveningnick
Hello
My project consists of few binaries, and i wanted to put them into one
application Bundle (thus, i placed them into ./Contents/MacOS/).
Only one of these binaries is launched when the bundle is
doubleclicked in finder (i have specified it in ExecutableFile in
bundle's Info.plist file). Other binary files - one is an agent that
is started with launchd, and one auxilary GUI application (that is
launched either by the agent, or by main binary).

The problem is, when either one of binaries is started, no one else
from this bundle can be launched. The bundle itself is
"LSUIElement=TRUE".
I was wondering, if i could use some technique/non-evil hack to keep
my appliations in a neat one bundle (counting that the user should be
able to start only one main binary, while other binaries are started
automatically by agent or by the main application).

I'm thinking that this would be convenient for the user - if he is
annoyed by my app, he just moves my bundle to a trash bin, and the job
is done :)
Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: fork/exec vs NSTask

2010-10-24 Thread eveningnick eveningnick
>
> Are you sure about that?
No, but by reading all the topics of people, who tried to launch a
simple (non bundled) binary with it, i left that idea - according to
gossips Launch Services act like Finder's doubleclick - if you
doubleclick on a binary file, it just won't work. And unfortunately on
the Apple website i couldn't find any info about those functions..

> Not great but should work.
> Better would be to use LaunchServices, if not possible I would use 
> SMJobSubmit() (ServicesManagement framework).
Could you please explain why? What steps do i omit, if using fork/exec?

And, perhaps, there are some other possible ways to launch a binary?
Just for better understanding and better choice :)

George
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


What alhorithm does the launcher follow while processing bundle?

2010-10-24 Thread eveningnick eveningnick
Hello!
What operations does the "application launcher" (or launch services?
who's responsible for launching bundles) when i doubleclick on a
bundle? What happens when i open a terminal and go (CD) straight
through MyApp.app/Contents/MacOS and launch the binary? Is there some
source to read about these steps?
(I would like to manually do all the steps that "Bundle Launcher"
does, to understand the process - launching a process using low level
posix calls, for better understanding :) )
Thank you
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


fork/exec vs NSTask

2010-10-24 Thread eveningnick eveningnick
Hello!
I am wondering, if  NSTask can be replaced with low-level fork/exec
calls. Looking through forums, i often met statements that launching a
process with "fork/exec" is not an "OS X way", especially if i am
using Cocoa framework (and i am using Cocoa!).
What i want to do - is to launch an application and just leave it
running (i don't want to wait until it terminates, and i don't need
its exitcode - my app spawns it and forgets about it, doing other
jobs). Another condition - this application should be launched by
executing its binary, rather than through emulation of a doubleclick
on its *.app bundle (my bundle has several executables - maybe this
also not Mac-way, but it is done for modularity and safety of the
application, when one part crashes, the rest shouldn't crash - anyway,
the visible behavior of my app is what user expects) - and I read that
Launch Services doesn't support launching separate binaries - only
bundles are supported.
What could be the pitfalls with using fork/exec method? I have found
it's the most appropriate solution for me, though i don't have a lot
of experience with Mac programming.

To avoid "Zombie processes" i am using double-forking
(Parent->TemporaryProcess->Child, where TemporaryProcess exits right
after its own forking, and Parent "waitpid"s for TemporaryPS to finish
- as long as TemporaryProcess terminates, Child's parent becomes the
root process).
Basically this is the question about using fork in MacOS. But if there
are other ways to launch a process, i'd appreciate if someone shared
:)

Thanks for the answer!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


What causes CGEventTap to be automatically disabled?

2010-10-21 Thread eveningnick eveningnick
Hello
i have an application that installs several active event taps (active
- those that can modify and filter events) into another application. I
activate them (CGEventTapEnable) and deactivate them only when my app
quits.

In some moments i find out (using application ET Testbench) that my
active event tap is disabled (when i have not called CGDisableEventTap
nowhere!).  I am pretty sure, i am not calling
CGEventTapEnable(myactivetap, NO) nowhere else, except when my app
finishes.

What could cause that behavior?
Can another application "spit out" and disable my installed tap? What
could be the other reasons? I feel like i'm completely lost, i don't
know from what side to approach to this problem. what are the
conditions for OS X to automatically disable event tap? (like, calling
CGRelease, or quitting the process that had installed that tap)?
Thanks for any hint!
George
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to create secondary Thread that listens to event taps?

2010-10-19 Thread eveningnick eveningnick
> You create the secondary thread, install the event tap in it as usual - that 
> is, create a run loop source for the tap and add the source to the current 
> run loop returned by CFRunLoopGetCurrent() - and then, erhm, run the run loop 
> in a loop :-)
>
> Something like (warning: typed in Eudora):
>        while (someCondition) {
>                NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
>                SInt32 result =  
> CFRunLoopRunInMode(kCFRunLoopDefaultMode,0.5,YES);
>                [pool drain];
>                if (result==kCFRunLoopRunStopped)) {
>                        return;
>                }
>        }
> should work.
>
> HTH,
> --

Hello Rainer
Thanks for the tip
Why did you give 0.5 as the second param of CFRunLoopRunInMode? Is it
the optimal value?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


How to create secondary Thread that listens to event taps?

2010-10-17 Thread eveningnick eveningnick
I have an application that has to perform a long action and while
performing it, be able to react to pressing "Esc" and cancel that long
operation.
That "long action" is a series of Applescript calls. If i perform
these calls in NSOperation's -main function the speed significantly
decreases - i guess this is because of NSAppleScript's implementation
that operates with main runloop.
So, i decided to do the following - i will execute the "long action"
in a main thread, and create an "Esc-listening thread" that will
install a system-wide keyboard EventTap (which watches ESC presses,
and if it gets any, it rises the cancellation flag - this flag is
periodically checked in the main thread's "long alhorithm").

The thing i can't understand - is how to make that secondary thread to
have a run loop, and how to make it not to finish as soon as i have
created it - but to watch its own run loop for "event taps"'s events.
Most tutorials are about putting "long operations" into the secondary
thread, but what i am trying to achieve - is to put the "run loop" in
it.
How could it be done?

P.S. i need a system wide hook, because the idea of the application is
to react on keypresses in several applications, so this is the best
idea for me
Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Let the runloop process its queue during a long operation

2010-10-07 Thread eveningnick eveningnick
Actually, by "processing" i mean a lot of AppleScript calls, some of
which return NSAppleEventDescriptors.
I am not sure how it is happening under the hood (if someone could
explain me...), but what i see is: i call
NSAppleEventDescriptor *resultFromScript = [myapplescript
executeAndReturnError];
and then this call returns _only after_ the result is available (i.e.,
the "return" operator in applescript has been called).
Does my application register some "event listeners", that wait for
AppleScripting server application (it is Microsoft Word) to post this
event?
Does that mean i will need the run loop? Maybe it's better and easier
to create the thread manually instead of using NSOperation?
Thank you

> It will be much easier to use a custom subclass of NSOperation for this kind 
> of problem.
> The operation's -main method should perform the transformation in a 
> peace-wise manner and thereby repeatedly checking its cancelation state 
> (-isCancelled method), like:
>
> - (void) main {
>    // runs on a secondary thread
>    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
>    ...
>    while (![self isCancelled] && !done) {
>        // transform a peace of data
>        ...
>    }
>
>    [delegate fileTransformOperationDidFinish:self];
>
>    [pool release];
> }
>
> You add the operation to a NSOperationQueue instance which schedules its 
> operations onto a secondary thread. From your main thread you may then cancel 
> the operation by sending it the -cancel message.
>
> There are several ways to notify the application (or some object) when the 
> task is finished. Using a delegate is safe and easy. You may consider to 
> define a protocol for the delegate. The delegate method may also schedule its 
> actual work to the main thread (via 
> -performSelectorOnMainThread:withObject:waitUntilDone:) if this is necessary.
>
> Just be careful when your task requires itself a runloop (e.g. using 
> asynchronous NSURLConnection) - since there exists no (implicit) one when 
> invoking an NSOperation's -main method on a secondary thread. Properly 
> implementing this will require more elaborated code, though.
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Let the runloop process its queue during a long operation

2010-10-07 Thread eveningnick eveningnick
2010/10/6 Dave Keck :
>> Can i make a runloop run only one time through the queue, and then
>> return back to processing of that big file?
>
> See CFRunLoopRunInMode(), specifically the returnAfterSourceHandled argument.
>

But this is for Carbon application, isn't it? I have a cocoa one...
Does this call operate with the core foundation run loop, bypassing
cocoa's one?
And if it's allowed to use it in cocoa app, what should i specify as
the second parameter (timeInterval)? 0 doesn't seem to work at all
(the run lop is not relaunched at all), 1 sec gives big delays, if
nothing has been pressed - it seems that "sourceHandled" means "at
least one event in queue is handled, if the queue is empty - just wait
that timeinterval". But then, setting any interval>0, i force my
application to wait, instead of processing that big file.
Or maybe i'm understanding something wrong?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


How does Popup menu receive keyboard events?

2010-10-07 Thread eveningnick eveningnick
Hello
I have some application active (for example, finder) and its window is
a keyWindow that receives keyboard events
After i click on a "free from windows" part of a desktop with right
mouse button, i have a popup menu dropped down, and somehow this menu
now gets keyboard events (for example, when i press up, and down keys,
the menu cursor moves up and down). The Finder application is still
active, and i presume its window is still key window. But desktop menu
- it is a different process, a different application and a different
window. How come it receives keyDowns and how come Finder doesn't
receive them anymore, unless i click on Finder's window with left
mouse button?
What is the mechanism that is used and what is the route the key
events go till they reach that menu? I was trying to find out this
info in event programming guide, but without any luck :(
Do i correctly understand that popup menu is an ordinary cocoa window,
which is only made topmost by calling
[setLevel:NSPopupMenuWindowLevel]?
Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Help to understand how do events work

2010-10-06 Thread eveningnick eveningnick
I'm sorry, i guess i have posted the messages privately before,
thinking they are posted to a mailing list. I have used before only
forums and don't have enough experience with mailing lists :) Hope
this time the message will come to the right destination

Hi Jonathan
Unfortunately this doesn't work.. sendEvent is called only when i
click with the mouse on the window. Keydowns are not dispatched to
this method.
I am just wondering, what path does the event take to get to the
destination control, bypassing somehow the window. I am sure this
happens because of the styles i have specified ( 1) when you click on
a window, the application doesn't become active; 2) the window is
floating on top of all other windows, even if it's not active -
NSPopupMenuWindowLevel), but i haven't found any details about event
routing in this case..

maybe i could do that by reimplementing the main event loop? Or maybe
cocoa framework doesn't send keydowns to my application at all?
What is the general conditional for the application to receive keydown
events? What if the application doesnt have ordinary key windows? is
there still a chance to process such keyDown events on some low level?


> Is you window the key window? call NSWindow - makeKeyWindow
> Regards

yes, for displaying that window i am calling makeKeyAndOrderFront,
making it key window. I am not sure if it becomes key though. As i
have described, my window is "special" - it doesn't behave like most
other cocoa windows. It is situated on the "menu level" (it behaves
like menu?)

>most events coming into an application make their way to a window in a 
>sendEvent: message
unfortunately, keyDown doesn't come (maybe because the window is not
really a "key" one, despite i'm calling makeKeyAndOrderFront).
I am only trying to understand where can i (and whether can i) catch
the key event. According to that "events programming guide", all
events directed to my application come through Main event loop.  Thus
i could inject some code into my app's runloop and try to extract the
events from there (if they, as we see, don't reach the window's
-sendEvent)? I don't know how to do that though. What comes on my mind
- is installing eventTap to my own application... But that looks a
little like an overhead.

Do keyDowns come only to those applications which have a keyWindow
displayed on a screen? What if my application is active (i clicked its
icon on dock), but its window is not a key one? The application's
runloop won't get any key down messages? How do popup menus usually
process keydown events? are they also "key windows" in cocoa
terminology?

Thanks again
George
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


what are the scenarios for an app to be terminated?

2010-10-06 Thread eveningnick eveningnick
Hello!
What are all the scenarios for terminating the Cocoa application, and
can i catch the moment of quitting and do some "before quit" actions?
I am writing a "naked" cocoa application (basically for myself, to
understand what happens under the hood). So, instead of calling
NsApplicationMain, i do the following:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSApplication *app = [NSApplication sharedApplication];

MyClass *myobject = [[[MyClass alloc] init] autorelease];

[app run];
[pool drain]; //or release
return 0;

Now i am wondering, how can i correctly "release" myobject (i.e. make
its -dealloc called) in as more "quitting scenarios" as possible - for
example, by clicking "with the right mouse button" app's icon on dock
and selecting "quit" there, by pressing Ctrl+C in terminal, by sending
kill signal...
I guess i should intercept some events from the main event loop, but
my superficial knowledge of "under-the-hood-things" don't let me to
understand what exactly should i do :)
How is it done in Cocoa framework by NSApplicationMain?
And what is the right way to terminate application, so it would
release all its allocated objects? Maybe it's a wrong way to use
-dealloc also as a destructor (like i did in C++) - where i save
config file? what is the right way?
Thanks for the answers
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Let the runloop process its queue during a long operation

2010-10-06 Thread eveningnick eveningnick
Hello
I have an application that transforms a very big file, and during that
operation i want to give a chance to user to press Esc and cancel this
transformation. Therefore i need to make mainRunLoop run inbetween
some "phases" of the file transformation.
There's an idea to create a separate "fileprocessing" thread that will
do onmly one job - transformation of that file, while the main thread
(that has the mainRunLoop) will only watch keypresses and when it
detects Esc, it kills that "fileprocessing" thread (or something like
that).

I am wondering if i could do that "in one thread", i.e. inbetween
transformation phases (for example, each phase - is a transformation
of 1 Kb of text) i call [mainRunLoop run], and the mainRunLoop
processes the event queue, and then gets back to work - continues
processing, if no Esc has been detected.
Here's what i can't understand: a call of [mainRunLoop run] will never
return, because what i do - is launch of infinite loop.
I've been adviced to use [runUntilDate], but i can't know how much
time will it be needed to process the whole event queue. If i specify
a little (say, [NSDate dateWithTimeIntervalSinceNow:0.001]), it may
not be sufficient. If i specify a lot (like, 1 sec) - it's just a
waste of processing time. If i specify [NSDate date] it seems like the
queue isn't processed at all...
Can i make a runloop run only one time through the queue, and then
return back to processing of that big file?
Thanks
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Help to understand how do events work

2010-10-06 Thread eveningnick eveningnick
Hello!
I have created a cocoa application that has unusual behavior: it has a
window (NSPanel), which does not activate the application, when it's
clicked. This window is ordered always on top of the other windows. So
it's like a "tooltip" window (basically it is a popup thing, that
drops down when a user types some combination of symols in another
application - which is a texteditor).
Anyway, i did it as following:
NSPanel *popupWindow = [[NSPanel alloc]
initWithContentRect:NSMakeRect(100,100,300,100)
styleMask:NSNonactivatingPanelMask | NSTitledWindowMask
backing:NSBackingStoreBuffered defer:NO];
[popupWindow setLevel:NSPopupMenuWindowLevel];

then i am showing it:
[popupWindow makeKeyAndOrderFront:nil];

This "window" behaves as expected: it is displayed on top of all
others, even if it's Application (in Dock, for ex) is not active. It
also dispatches all the clicks on controls (like NSPushButton's) to
these controls.

The problem for me is that i want to receive keyDown events with it.
But i am not sure if it is possible: in Apple documentation i found
that NSWindow (and NSPanel therefore) have keyDown method (that i
tried to override, having created a child class from NSPanel). But in
vain - this method is never called.
Neither is called mouseDown. How do buttons on this "panel"
successfully receive mouseDowns then, for example? Or, after i placed
on this panel an NSPushButton, i have seen that its dropdown list's
cursor is positioned according to the key pressed on a keyboard - this
means it processes keyDowns as well. But how? Could i process these
events (keyDown) too? Maybe i should make a child class of
NSApplication and rewrite -run method, watching for keydowns? What is
the "route" that events go in my case?
Thanks for the help
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Is there any other way of enumerating windows and getting their positions except Accessibility API?

2010-09-30 Thread eveningnick eveningnick
Hello
Is there a way in MacOS X to determine the position of the control on
a screen, if the application doesnt provide Accessibility object for
that control?

What am I trying to do - is to get the position of the topleft corner
of Mac:Word Page (it seems to be a View or something like that).
Word does provide Accessibility API, but only as deep as the window
which is called Document Pane that contains pages (and this document
pane may contain several pages, or the page can be scrolled while that
Document Pane doesnt change its location).

I am wondering, if this page can be interpreted as a control and then,
maybe using some Windowing APIs i could retrieve that position.
I am sorry about the terminology, before i've been coding only for
Windows, thus i hardly imagine how windowing system works in MacOS.

Thanks for any help
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Get an absolute screen pos of a text cursor in another Carbon application from Cocoa app

2010-09-26 Thread eveningnick eveningnick
Hello!
Is it possible to somehow determine the text caret's absolute screen
position of a Carbon application?
(I've sent it to carbon mailing list, but seems like no one is
interested in carbon development anymore)

What am i trying to do is to display a popup list window near the text
cursor in Microsoft Word (from my own process) - like it is done in
XCode (or Visual studio, or Delphi) as a dropdown code suggestion
menu.
I can't do it by the means provided by Word (Word supports only
getting cursor position relatively to the left-top page corner (it can
be done using AppleScript command), but i've no possibility to
determine where that page corner is located - unfortunately page is
not a separate accessibility object). Maybe it can be done somehow
using "under-the-hood" API?

Or perhaps someone knows how could I get that current page's left-top
corner coordinates? That would solve problem (though i doubt there's
such a possibility)
Thanks a lot for any suggestion!

George
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


To make an application start everytime when another program starts

2010-09-23 Thread eveningnick eveningnick
Hello!
I have written an application, that interacts with another
"stranger"-program by Applescript. The problem is that i need my
application to look like a plugin for "stranger program"- to display a
panel, and to be launched automatically when the Master-program starts
(and to finish, when the master program is terminated - this is solved
already using NSWorkspace's events [cocoa framework]).
I have submitted this to installer mailing list, but haven't got any
response, so decided to try my luck here :)
How could I make my application be automatically launched, when the
MasterApp process is started? Does MacOS provide any means for such
activity?
I was thinking about installing a daemon, that would watch application
start events (not sure how to do that, but i read somewhere that
Linux/BSD kernels support such a feature - when a process registers
its callback functions on processStart event). - And, if it's the only
way, could you point me where to read about these capabilities of the
kernel?
But a daemon, that is launched with the system start, and which
remains in memory all the time is not a good idea for a good
application (though, if there's no better way, i'd try to implement
it).
What could be the best way to perform this autolaunch? I would be very
thankful for any advice :)

PS: Why do i need it. I am writing a "plugin" for mac:Word, that
simplifies writing of big texts, but unfortunately Microsoft didn't
publish mac:Office Plugin SDK. Luckily for me, Word supports external
Applescipt commands. Everything is done by me, except this autolaunch,
which is a real problem. I had an idea to replace MicrosoftWord binary
in a bundle with mine (and rename original executable binary into
something like MicrosoftWord111), so when a user doubleclicks on
Word's, first my plugin starts, which launches Word. But i think it
can cause problems with license agreement, and major problems with
Autoupdates.

Thank you, George
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Applescript: force garbage collection? (NSAppleScript call from Cocoa app)

2010-09-14 Thread eveningnick eveningnick
Hello
I am trying to call applescript functions (from my cocoa application - using
NSAppleScript's -executeAndReturnError), to automate some operations in
Microsoft Word.
The problem is that after every Applescript call, the Word operates slower
and slower (and i guess finally it won't respond at all). I am calling
operations, like "set myvar to all words of current document whose some
conditional" or "set myvar to all fields of current document whose some
conditional" (which are memory consuming - on each call Word enumerates all
the words of a long document, searches there some matches, etc), and i think
that after each call of NSAppleScript's -executeAndReturnError, Word doesn't
clean its previous "results", which slows it down with every next call. I
wanted to try to do an explicit call of Applescript's garbage collector
after each -executeAndReturnError from my Cocoa app, maybe that could
eliminate the problem i have.
But i didn't find any info on how to do that. Java, ActionScript - most
garbage collectors have System.gc() functions (that launch Garbage
collection if it's needed right here and right now). If theres no way to
force garbage collecting in AppleScript, maybe someone knows "implicit
ways", when AppleScript engine calls it? Like the next iteration of a loop,
or some other conditions? Or some timespan, after passing which the GC is
called?

What could cause that slowness of Mac:Word? Is it a mistake of Microsoft, or
am i forgetting to do something? If someone could advice readings about how
applications usually implement Applescript interface "from the inside" (and
who is responsible for cleaning the results of each call), i'd be very
thankful.
Thanks for any advice!
George
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com