discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Touch panel keyboard in GNUstep app


From: Fred Kiefer
Subject: Re: Touch panel keyboard in GNUstep app
Date: Tue, 31 Mar 2020 16:33:50 +0200

The actual transfer happens in NSWindow makeFirstResponder. You should be able 
to log the current and the future first responder in that method to see who is 
requesting this. And if you run in a debugger and put a break point in this 
method you might be even able to see where this call comes from. But beware, 
this gets called quite a lot and debugging Guidebook applications may be 
difficult. The most likely caller is sendEvent: on NSWindow, but as Wolfgang 
noted this should ignore NSButton.

Fred 

> Am 31.03.2020 um 13:30 schrieb Andreas Höschler <ahoesch@smartsoft.de>:
> 
> Hi Fred,
> 
> in the meanwhile I was able to test the 
> 
> - (void)mouseDown:(NSEvent *)theEvent
> {    
>  NSLog(@"mouseDown ...");
>  [NSApp preventWindowOrdering];        
> 
>  [self highlight:YES];
> 
>  NSEvent *mouseUpEvent = [[self window] 
> nextEventMatchingMask:NSLeftMouseUpMask untilDate:[NSDate distantFuture] 
> inMode:NSEventTrackingRunLoopMode dequeue:YES];
>  NSPoint mouseLocation = [self convertPoint:[mouseUpEvent locationInWindow] 
> fromView:nil];
>  BOOL mouseUpInside = [self mouse:mouseLocation inRect:[self bounds]];
> 
>  if (mouseUpInside)
>    {
>     if ([self target]) [[self target] performSelector:[self action] 
> withObject:self]; 
>    }      
>  [self highlight:NO];                  
> }
> 
> code fragment (NSButton subclass) on GNUstep. And as expected it does not 
> work there. So I am still looking for a solution ...
> 
> Do you know which part in the GNustep source tree resigns fist responder from 
> a currently active control and transfers it to a clicked button? I got 
> somehow lost in the event handling code. 
> 
> Thanks a lot,
> 
>    Andreas
> 
> 
> 
>> The method preventWindowOrdering is a NOOP on GNUstep, so it won’t help you. 
>> Put if this is what helps you on MacOS then most likely your touch panel is 
>> stealing the focus. You should try to override canBecomeKeyWindow for that 
>> panel.
>> 
>> Hope this help,
>> Fred
>> 
>>> Am 30.03.2020 um 19:13 schrieb Andreas Höschler <ahoesch@smartsoft.de>:
>>> 
>>>> 
>>>>> Am 30.03.2020 um 15:19 schrieb Andreas Höschler <ahoesch@smartsoft.de>:
>>>>> 
>>>>> Hi Fred,
>>>>> 
>>>>>> in NSButton you find this code:
>>>>>> 
>>>>>> 
>>>>>> - (BOOL) acceptsFirstMouse: (NSEvent *)theEvent
>>>>>> {
>>>>>> return YES;
>>>>>> }
>>>>>> 
>>>>>> 
>>>>>> You will need to write a subclass to handle this different.
>>>>> 
>>>>> Thanks a lot for your response. I created a subclass KbButton and 
>>>>> overwrote this method like so
>>>>> 
>>>>> - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
>>>>> {
>>>>> NSLog(@"%@ returns acceptsFirstMouse NO", self);
>>>>> return NO;
>>>>> }
>>>>> 
>>>>> When I click on the button the currently active NSTextField looses first 
>>>>> responder and the action of the button is called 
>>>>> 
>>>>> 30/03/20 14:42:16,912 ScaleMaster[59798]: strike sender <KbButton: 
>>>>> 0x7b82ae50> stringValue A
>>>>> 
>>>>> The method acceptsFirstMouse: of KbButton is never called. So this 
>>>>> unfortunately does not work, at least not on MacOSX (dev machine for the 
>>>>> project). :-( I will port the code to GNUstep and see whether GNUstep 
>>>>> behaves differently. Will let you know ...
>>>> 
>>>> Well, yes. I'm afraid Fred's advice is wrong (even though . While the code 
>>>> in -[NSWindow sendEvent:] indeed requires  The method acceptsFirstMouse is 
>>>> supposed to serve a different purpose. When you activate window by 
>>>> clicking onto it, acceptsFirstMouse governs whether this click is passed 
>>>> to the control under the mouse (acceptsFirstMouse returns YES) or whether 
>>>> it is only for activating the window (acceptsFirstMouse returns NO). Your 
>>>> original approach calling setAcceptsFirstResponder: with NO looks right to 
>>>> me. It is just that the code in -[NSEvent sendEvent:] gets the logic 
>>>> wrong. Where it currently says
>>>> if ([v acceptsFirstResponder] && ![self makeFirstResponder: v])
>>>>  {
>>>>    return;
>>>>  }
>>>> it should really say
>>>> if (![v acceptsFirstResponder] || ![self makeFirstResponder: v])
>>>>  {
>>>>    return;
>>>>  }
>>> 
>>> I got this working on MacOSX by subclassing NSButton and doing 
>>> 
>>> - (void)mouseDown:(NSEvent *)theEvent
>>> {    
>>>  NSLog(@"mouseDown ...");
>>>  [NSApp preventWindowOrdering];        
>>> 
>>>  [self highlight:YES];
>>> 
>>>  NSEvent *mouseUpEvent = [[self window] 
>>> nextEventMatchingMask:NSLeftMouseUpMask
>>>  untilDate:[NSDate distantFuture] inMode:NSEventTrackingRunLoopMode 
>>> dequeue:YES];
>>>  NSPoint mouseLocation = [self convertPoint:[mouseUpEvent locationInWindow] 
>>> fromView:nil];
>>>  BOOL mouseUpInside = [self mouse:mouseLocation inRect:[self bounds]];
>>> 
>>>  if (mouseUpInside)
>>>    {
>>>     if ([self target])
>>>     [[self target] performSelector:[self action] withObject:self]; 
>>>    }      
>>>  [self highlight:NO];                  
>>> }
>>> 
>>> I haven't tested that on the GNUstep machine yet. But if it worked there as 
>>> well this would make my day.
>>> 
>>> Best wishes,
>>> 
>>> Andrea
>>> 
>> 
> 
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]