[Cuis-dev] [DEFECT] Ctrl-W does not work in some situations

Gerald Klix cuis.01 at klix.ch
Mon Nov 29 05:44:52 PST 2021


Hi all, Hi Juan,

There is a defect in handling of Ctrl-W, which should
close the current window.

Ctrl-W is only handled when there is a morph that
is the keyboard focus. Morphs that do not handle
keyboard events, like PluggableButtonMorphs,
set the keyboard focus to nil.
With focusFollowsMouse enabled, Ctrl-W
ceases to work if the mouse hovers over a
button. Needless to say that Ctrl-W does not
work for Transcripts; their submorphs do not
handle keyboard events.

Please find enclosed a change set, that highlights
the title bar of the system window with the keyboard
focus, actually the system window that has a submorph
that is they keyboard focus.

Once filed in, the change-set shows the problem nicely.

The change-set might also be integrated into Cuis' core,
but I am not quite satisfied with the drawing of highlighted
title-bars, at least when the theme demands rounded corners.


Best Regards,

Gerald
-------------- next part --------------
'From Haver 5.0 [latest update: #4985] on 29 November 2021 at 2:24:00 pm'!

!Preferences class methodsFor: 'standard queries' stamp: 'KLG 11/29/2021 12:44:29'!
titlebarIndicatesKeyboardFocus
	"Answer true if the title bar should indicate the keyboard focus."

	^ self
		valueOfFlag: #titlebarIndicatesKeyboardFocus
		ifAbsent: [ true ].! !


!SystemWindow methodsFor: 'testing' stamp: 'KLG 11/29/2021 12:46:56'!
shouldIndicateKeyboardFocus
	"Answer true if the titlebar should indicate the keyboard focus."

	^ Preferences titlebarIndicatesKeyboardFocus and: [
		self submorphHasKeyboardFocus ]! !

!SystemWindow methodsFor: 'testing' stamp: 'KLG 11/29/2021 12:28:42'!
submorphHasKeyboardFocus
	"Answer true if one of my submoprhs have the keyboard focus."

	^ self runningWorld
		ifNotNil: [ :world |
			world activeHand keyboardFocus 
				ifNotNil: [ :morphInFocus |
					morphInFocus owningWindow == self ]
				ifNil: [ false ] ]
		ifNil: [ false ]! !


!Theme methodsFor: 'colors' stamp: 'KLG 11/29/2021 14:15:00'!
focusedTitlebarColorForm: aColor
	"Answer the titlebar color for windows with the keyboard focus."

	^ aColor mixed: 0.5 with: `Color orange`! !


!HandMorph methodsFor: 'focus handling' stamp: 'KLG 11/29/2021 12:59:33'!
newKeyboardFocus: aMorphOrNil
	"Make the given morph the new keyboard focus, canceling the previous keyboard focus if any. If the argument is nil, the current keyboard focus is cancelled."

	| oldFocus |
	oldFocus _ keyboardFocus.
	keyboardFocus _ aMorphOrNil.
	oldFocus ifNotNil: [
		oldFocus == aMorphOrNil ifFalse: [ oldFocus keyboardFocusChange: false ].
		Preferences titlebarIndicatesKeyboardFocus ifTrue: [
			oldFocus owningWindow ifNotNil: [ :window |
				window redrawNeeded ]]].
	aMorphOrNil ifNotNil: [
		aMorphOrNil keyboardFocusChange: true.
		Preferences titlebarIndicatesKeyboardFocus ifTrue: [
			aMorphOrNil owningWindow ifNotNil: [ :window |
				window redrawNeeded ]]].! !


!SystemWindow methodsFor: 'drawing' stamp: 'KLG 11/29/2021 14:15:47'!
drawClassicFrameOn: aCanvas color: windowFrameColor
	"Window border encompasses title area. No round corners. No title gradient."

	aCanvas
		fillRectangle: (self morphLocalBounds insetBy: 1.5)
		color: color
		borderWidth: borderWidth
		borderStyleSymbol: #simple
		baseColorForBorder: self widgetsColor.
	"A border was drawn at the left, top and right of the title area.
	The look is that the title area is inside the window"
	aCanvas
		fillRectangle: (borderWidth @ borderWidth extent: extent x - (2 * borderWidth) @ self labelHeight)
		color:
			(self submorphHasKeyboardFocus 
				ifTrue: [ Theme current focusedTitlebarColorForm: windowFrameColor ]
				ifFalse: [ windowFrameColor ]).! !

!SystemWindow methodsFor: 'drawing' stamp: 'KLG 11/29/2021 14:16:58'!
drawRoundedFrameOn: aCanvas color: widgetsColor

	aCanvas
		drawRoundedFrame: self morphLocalBounds
		border: borderWidth 
		color: widgetsColor
		insideColor: color
		labelHeight: self labelHeight.
	self shouldIndicateKeyboardFocus ifTrue: [
		aCanvas
			roundRect: (0 @ 0 extent: extent x - borderWidth @ self labelHeight + borderWidth)
			color: (Theme current focusedTitlebarColorForm: widgetsColor)
			radius: Theme current roundedWindowRadius ].! !



More information about the Cuis-dev mailing list