[squeak-dev] Merge Request: hostWindowFocus.2.cs

Marcel Taeumel marcel.taeumel at hpi.de
Wed Dec 1 14:56:15 UTC 2021


Yet, I don't think we need such a "hostMorph". "anEvent hand newKeyboardFocus: nil" works fine. Having a keyboard focus is the special case, from the event-dispatching point of view. Without such a focus, the (keyboard) events will be delivered to the mouse position.

Am 07.11.2021 22:20:05 schrieb christoph.thiede at student.hpi.uni-potsdam.de <christoph.thiede at student.hpi.uni-potsdam.de>:
=============== Summary ===============

Change Set:        hostWindowFocus
Date:            7 November 2021
Author:            Christoph Thiede

Proposal: When the host window loses the keyboard focus of the host system, remove the focus from the current focus holder morph in Squeak as well. This is done by initializing a temporary windowHostFocusMorph in the world which takes the keyboard focus while the host window is inactive and restores it afterward.

Some more explanation of this feature: When you activate a different window than Squeak in your operating system, Squeak did not know as of today and still might indicate a keyboard focus for any text morph or similar in the image. I have experienced a lot of confusion by this incorrect display when I was assuming a particular Squeak window would still be focused, started to type something, but actually was typing into a different window! With this patch, this situation cannot occur any longer.

This change won't become effective before opensmalltalk-vm#593 is merged which provides the #windowActivated and #windowDeactivated events to the image [1]; however, loading the patch into an older VM does not do any harm.

On the event type #windowChangedScreen: This has already been implemented in the VM last year [2] but was forgotten to mention on the image side until now.

[1] https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/593
[2] https://github.com/OpenSmalltalk/opensmalltalk-vm/commit/0361fc33d5f72b153b098f6400bad9b664a2625f

=============== Diff ===============

HandMorph>>generateWindowEvent: {private events} · ct 9/7/2021 18:44 (changed)
generateWindowEvent: evtBuf
    "Generate the appropriate window event for the given raw event buffer"

    | evt |
    evt := WindowEvent new.
+     evt setHand: self.
    evt setTimeStamp: evtBuf second.
    evt timeStamp = 0 ifTrue: [evt setTimeStamp: Sensor eventTimeNow].
    evt action: evtBuf third.
    evt rectangle: (Rectangle origin: evtBuf fourth @ evtBuf fifth corner: evtBuf sixth @ evtBuf seventh ).

PasteUpMorph>>windowEvent: {event handling} · ct 9/7/2021 19:20 (changed)
windowEvent: anEvent
    self windowEventHandler
        ifNotNil: [^self windowEventHandler windowEvent: anEvent].

-     anEvent type == #windowClose
-         ifTrue: [
-             ^Preferences eToyFriendly
-                 ifTrue: [ProjectNavigationMorph basicNew quitSqueak]
-                 ifFalse: [TheWorldMenu basicNew quitSession]].
+     anEvent type
+         caseOf: {
+             [#windowClose] -> [
+                 Preferences eToyFriendly
+                     ifTrue: [ProjectNavigationMorph basicNew quitSqueak]
+                     ifFalse: [TheWorldMenu basicNew quitSession]].
+             [#windowDeactivated]    -> [
+                 "The host window has been deactivated. Until it regains the focus, honor the fact that we will not receive keyboard events again by changing the current keyboard focus morph. windowHostFocusMorph represents the host system which now holds the keyboard focus instead of the previousFocus. If enabled, disable #mouseOverForKeyboardFocus temporarily because when inactive, we *can't* set the keyboard focus."
+                 (self valueOfProperty: #windowHostFocusMorph ifAbsentPut: [
+                     Morph new
+                         name: #windowHostFocusMorph;
+                         yourself]) in: [:hostFocus |
+                     hostFocus setProperty: #previousFocus toValue: anEvent hand keyboardFocus.
+                     anEvent hand newKeyboardFocus: hostFocus.
+                     Preferences mouseOverForKeyboardFocus ifTrue: [
+                         hostFocus setProperty: #previousMouseOverForKeyboardFocus toValue: true.
+                         Preferences setPreference: #mouseOverForKeyboardFocus toValue: false]]].
+             [#windowActivated] -> [
+                 "Alright, the spook is over! We have back control over the keyboard focus, delete the windowHostFocusMorph and restore the previous focus holder and the #mouseOverForKeyboardFocus preference."
+                 self valueOfProperty: #windowHostFocusMorph ifPresentDo: [:hostFocus |
+                     hostFocus abandon.
+                     (hostFocus valueOfProperty: #previousFocus) ifNotNil: [:previousFocus |
+                         anEvent hand newKeyboardFocus: previousFocus].
+                     (hostFocus valueOfProperty: #previousMouseOverForKeyboardFocus) ifNotNil: [:value |
+                         Preferences setPreference: #mouseOverForKeyboardFocus toValue: value].
+                     self removeProperty: #windowHostFocusMorph]]. }
+         otherwise: []

WindowEvent>>type {accessing} · ct 9/7/2021 18:38 (changed)
    "This should match the definitions in sq.h"
+         windowChangedScreen
+         windowDeactivated
    ) at: action ifAbsent: [#windowEventUnknown]

Sent from Squeak Inbox Talk [https://github.com/hpi-swa-lab/squeak-inbox-talk]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20211201/957c5402/attachment.html>

More information about the Squeak-dev mailing list