Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fromDev #460

Merged
merged 11 commits into from
Mar 5, 2024
Prev Previous commit
Next Next commit
BlOSWindowEventHandler clean up
* mousePosition instvar was not used
* access time directly
* send #now to "time" collaborator, not to DateAndTime
* use yourself to end cascade
* remove some pragma
  • Loading branch information
tinchodias committed Feb 29, 2024
commit 66cd0198d325a7f10f15c6073f3cf52b0b20056c
74 changes: 41 additions & 33 deletions src/BlocHost-OSWindow/BlOSWindowEventHandler.class.st
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"
I am a OSWindow event handler for Bloc host spaces.
"
Class {
#name : #BlOSWindowEventHandler,
#superclass : #OSWindowGestureHandler,
#instVars : [
'window',
'time',
'mousePosition',
'keyboardKeyTable'
],
#pools : [
Expand All @@ -15,11 +17,13 @@ Class {

{ #category : #'instance creation' }
BlOSWindowEventHandler class >> new [

self error: 'Use #window: instead'
]

{ #category : #'instance creation' }
BlOSWindowEventHandler class >> window: anOSWindow [

^ self basicNew
initialize;
window: anOSWindow;
Expand Down Expand Up @@ -67,13 +71,13 @@ BlOSWindowEventHandler >> handleEvent: anEvent [

{ #category : #initialization }
BlOSWindowEventHandler >> initialize [

super initialize.

time := BlTime real.
mousePosition := 0@0.

self registerGesture: OSTouchTwoFingersScrollDetector new.
self registerGesture: OSTouchTwoFingersPinchDetector new.
self registerGesture: OSTouchTwoFingersPinchDetector new
]

{ #category : #'api - accessing' }
Expand All @@ -88,38 +92,40 @@ BlOSWindowEventHandler >> keyboardKeyTable: aKeyboardKeyTable [

{ #category : #'api - accessing' }
BlOSWindowEventHandler >> time [
<return: #BlTime>


^ time
]

{ #category : #'api - accessing' }
BlOSWindowEventHandler >> time: aTime [
time := aTime
BlOSWindowEventHandler >> time: aBlTime [

time := aBlTime
]

{ #category : #'visiting - keyboard' }
BlOSWindowEventHandler >> visitKeyDownEvent: anEvent [
| aBlEvent |

| aBlEvent |
aBlEvent := BlKeyDownEvent new
key: (self convertKeyFromEvent: anEvent);
scanCode: anEvent scanCode;
modifiers: (self convertKeyModifiers: anEvent modifiers);
timestamp: self time now.
timestamp: time now;
yourself.

self enqueue: aBlEvent
]

{ #category : #'visiting - keyboard' }
BlOSWindowEventHandler >> visitKeyUpEvent: anEvent [
| aBlEvent |

| aBlEvent |
aBlEvent := BlKeyUpEvent new
key: (self convertKeyFromEvent: anEvent);
scanCode: anEvent scanCode;
modifiers: (self convertKeyModifiers: anEvent modifiers);
timestamp: self time now.
timestamp: time now;
yourself.

self enqueue: aBlEvent
]
Expand All @@ -135,8 +141,8 @@ BlOSWindowEventHandler >> visitMainEventsCleared: anEvent [

{ #category : #'visiting - mouse' }
BlOSWindowEventHandler >> visitMouseButtonPressEvent: anEvent [
| aBlocEvent button |

| aBlocEvent button |
"we handle touch events separately, therefore ignore `touch` based mouse events"
"anEvent isTouch
ifTrue: [ ^ self ]."
Expand All @@ -147,15 +153,16 @@ BlOSWindowEventHandler >> visitMouseButtonPressEvent: anEvent [
delta: anEvent delta;
button: button;
modifiers: (self convertKeyModifiers: anEvent modifiers);
timestamp: self time now.
timestamp: time now;
yourself.

self enqueue: aBlocEvent
]

{ #category : #'visiting - mouse' }
BlOSWindowEventHandler >> visitMouseButtonReleaseEvent: anEvent [

| aBlocEvent button |

"we handle touch events separately, therefore ignore `touch` based mouse events"
"anEvent isTouch
ifTrue: [ ^ self ]."
Expand All @@ -166,32 +173,31 @@ BlOSWindowEventHandler >> visitMouseButtonReleaseEvent: anEvent [
delta: anEvent delta;
button: button;
modifiers: (self convertKeyModifiers: anEvent modifiers);
timestamp: self time now.
timestamp: time now;
yourself.

self enqueue: aBlocEvent
]

{ #category : #'visiting - mouse' }
BlOSWindowEventHandler >> visitMouseMoveEvent: anEvent [
| aBlocEvent |

mousePosition := anEvent position.

| aBlocEvent |
aBlocEvent := BlMouseMoveEvent new
position: anEvent position;
screenPosition: window position + anEvent position;
delta: anEvent delta;
modifiers: (self convertKeyModifiers: anEvent modifiers);
timestamp: self time now;
timestamp: time now;
yourself.

self enqueue: aBlocEvent
]

{ #category : #'visiting - mouse' }
BlOSWindowEventHandler >> visitMouseWheelEvent: anEvent [
| vertical horizontal aBlocEvent |

| vertical horizontal aBlocEvent |
horizontal := anEvent scrollHorizontal.
vertical := anEvent scrollVertical.

Expand All @@ -204,22 +210,23 @@ BlOSWindowEventHandler >> visitMouseWheelEvent: anEvent [
position: anEvent position;
screenPosition: window position + anEvent position;
modifiers: (self convertKeyModifiers: anEvent modifiers);
timestamp: self time now.

timestamp: time now;
yourself.

self enqueue: aBlocEvent
]

{ #category : #'visiting - keyboard' }
BlOSWindowEventHandler >> visitTextInputEvent: anEvent [

| aBlocEvent |

anEvent text
ifNil: [ ^ self ].
anEvent text ifNil: [ ^ self ].

aBlocEvent := BlTextInputEvent new
modifiers: (self convertKeyModifiers: anEvent modifiers);
text: anEvent text;
timestamp: self time now.
timestamp: time now;
yourself.

self enqueue: aBlocEvent
]
Expand Down Expand Up @@ -268,11 +275,12 @@ BlOSWindowEventHandler >> visitUnknownEvent: anEvent [

{ #category : #'visiting - window' }
BlOSWindowEventHandler >> visitWindowCloseEvent: anEvent [

| aBlocEvent |
anEvent suppressDefaultAction.

aBlocEvent := BlSpaceCloseRequest new
timestamp: self time now;
timestamp: time now;
yourself.

self enqueue: aBlocEvent
Expand All @@ -286,21 +294,21 @@ BlOSWindowEventHandler >> visitWindowExposeEvent: anEvent [

{ #category : #'visiting - window' }
BlOSWindowEventHandler >> visitWindowFocusInEvent: anEvent [
| aBlocEvent |

| aBlocEvent |
aBlocEvent := BlSpaceFocusInEvent new
timestamp: self time now;
timestamp: time now;
yourself.

self enqueue: aBlocEvent
]

{ #category : #'visiting - window' }
BlOSWindowEventHandler >> visitWindowFocusOutEvent: anEvent [

| aBlocEvent |

aBlocEvent := BlSpaceFocusOutEvent new
timestamp: self time now;
timestamp: time now;
yourself.

self enqueue: aBlocEvent
Expand Down Expand Up @@ -370,11 +378,11 @@ BlOSWindowEventHandler >> window: aBlOSWindowSpace [

{ #category : #'visiting - window' }
BlOSWindowEventHandler >> windowResized: aPoint [
| aBlocEvent |

| aBlocEvent |
aBlocEvent := BlSpaceResizedEvent new
extent: aPoint;
timestamp: DateAndTime now;
timestamp: time now;
yourself.

self enqueue: aBlocEvent
Expand Down