@@ -142,33 +142,44 @@ class Terminal::Widgets::HScrollBar
142142 # XXXX: Handle drag events
143143 multi method handle-event (Terminal::Widgets::Events::MouseEvent: D
144144 $ event where !*. mouse. pressed, AtTarget) {
145- # Determine relative click location and bounds
146- my $ layout = $ . layout . computed;
147- my $ x = 0 max $ event . relative-to(self )[0 ] - $ layout . left-correction;
148- my $ end = 0 max $ . w - 1 - $ layout . right-correction;
149-
150- # Handle end arrows if any
151- if $ . show-end-arrows {
152- if $ x == 0 {
153- self . arrow-left-scroll;
154- $ . scroll-target . refresh-for-scroll;
155- return ;
156- }
157- elsif $ x == $ end {
158- self . arrow-right-scroll;
145+ # Take focus even if clicked on framing instead of content area
146+ self . toplevel. focus-on(self );
147+
148+ # If enabled and within content area, process click
149+ if $ . enabled {
150+ my ($ x , $ y , $ w , $ h ) = $ event . relative-to-content-area(self );
151+
152+ if 0 <= $ x < $ w && 0 <= $ y < $ h {
153+ my $ end = $ w - 1 ;
154+
155+ # Handle end arrows if any
156+ if $ . show-end-arrows {
157+ if $ x == 0 {
158+ self . arrow-left-scroll;
159+ $ . scroll-target . refresh-for-scroll;
160+ return ;
161+ }
162+ elsif $ x == $ end {
163+ self . arrow-right-scroll;
164+ $ . scroll-target . refresh-for-scroll;
165+ return ;
166+ }
167+ else {
168+ $ end -= 2 ;
169+ $ x -- ;
170+ }
171+ }
172+
173+ # Handle bar events
174+ my $ scroll = floor ($ . scroll-target . x-max * $ x / ($ end max 1 ));
175+ $ . scroll-target . set-x-scroll($ scroll );
159176 $ . scroll-target . refresh-for-scroll;
160177 return ;
161178 }
162- else {
163- $ end -= 2 ;
164- $ x -- ;
165- }
166179 }
167180
168- # Handle bar events
169- my $ scroll = floor ($ . scroll-target . x-max * $ x / ($ end max 1 ));
170- $ . scroll-target . set-x-scroll($ scroll );
171- $ . scroll-target . refresh-for-scroll;
181+ # Refresh even if outside content area because of focus state change
182+ self . full-refresh;
172183 }
173184}
174185
@@ -260,32 +271,43 @@ class Terminal::Widgets::VScrollBar
260271 # XXXX: Handle drag events
261272 multi method handle-event (Terminal::Widgets::Events::MouseEvent: D
262273 $ event where !*. mouse. pressed, AtTarget) {
263- # Determine relative click location and bounds
264- my $ layout = $ . layout . computed;
265- my $ y = 0 max $ event . relative-to(self )[1 ] - $ layout . top-correction;
266- my $ end = 0 max $ . h - 1 - $ layout . bottom-correction;
267-
268- # Handle end arrows if any
269- if $ . show-end-arrows {
270- if $ y == 0 {
271- self . arrow-up-scroll;
272- $ . scroll-target . refresh-for-scroll;
273- return ;
274- }
275- elsif $ y == $ end {
276- self . arrow-down-scroll;
274+ # Take focus even if clicked on framing instead of content area
275+ self . toplevel. focus-on(self );
276+
277+ # If enabled and within content area, process click
278+ if $ . enabled {
279+ my ($ x , $ y , $ w , $ h ) = $ event . relative-to-content-area(self );
280+
281+ if 0 <= $ x < $ w && 0 <= $ y < $ h {
282+ my $ end = $ h - 1 ;
283+
284+ # Handle end arrows if any
285+ if $ . show-end-arrows {
286+ if $ y == 0 {
287+ self . arrow-up-scroll;
288+ $ . scroll-target . refresh-for-scroll;
289+ return ;
290+ }
291+ elsif $ y == $ end {
292+ self . arrow-down-scroll;
293+ $ . scroll-target . refresh-for-scroll;
294+ return ;
295+ }
296+ else {
297+ $ end -= 2 ;
298+ $ y -- ;
299+ }
300+ }
301+
302+ # Handle bar events
303+ my $ scroll = floor ($ . scroll-target . y-max * $ y / ($ end max 1 ));
304+ $ . scroll-target . set-y-scroll($ scroll );
277305 $ . scroll-target . refresh-for-scroll;
278306 return ;
279307 }
280- else {
281- $ end -= 2 ;
282- $ y -- ;
283- }
284308 }
285309
286- # Handle bar events
287- my $ scroll = floor ($ . scroll-target . y-max * $ y / ($ end max 1 ));
288- $ . scroll-target . set-y-scroll($ scroll );
289- $ . scroll-target . refresh-for-scroll;
310+ # Refresh even if outside content area because of focus state change
311+ self . full-refresh;
290312 }
291313}
0 commit comments