Skip to content

Commit e43b62d

Browse files
committed
rewrite hint positioning to respect multimonitor boundaries
1 parent fd6c89c commit e43b62d

File tree

2 files changed

+75
-53
lines changed

2 files changed

+75
-53
lines changed

Prima/Classes.pm

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,8 +2370,8 @@ sub profile_default
23702370
sub max_extents
23712371
{
23722372
shift;
2373-
my @pos = @_ || $::application-> pointerPos;
2374-
my @sz = $::application->size;
2373+
my @pos = @_ ? @_ : $::application-> pointerPos;
2374+
my @sz = $::application->size;
23752375
for my $r ( @{$::application->get_monitor_rects} ) {
23762376
next unless
23772377
$r->[0] <= $pos[0] && $r->[2] > $pos[0] &&
@@ -2407,6 +2407,60 @@ sub on_change
24072407
$self-> size(@sz);
24082408
}
24092409

2410+
sub on_hint
2411+
{
2412+
my ( $self, $widget, @around) = @_;
2413+
2414+
my (@pos, @size);
2415+
if ( 4 == (grep { $_ == -1 } @around)) {
2416+
@size = $widget->size;
2417+
@pos = $widget->client_to_screen(0,0);
2418+
} else {
2419+
@pos = @around[0,1];
2420+
$size[0] = $around[2] - $pos[0];
2421+
$size[1] = $around[3] - $pos[1];
2422+
}
2423+
2424+
$self->set(
2425+
text => $widget->hint,
2426+
color => $widget->hintColor,
2427+
backColor => $widget->hintBackColor,
2428+
);
2429+
2430+
my @psize = map { $::application->get_system_value($_) } (
2431+
sv::XPointer, sv::YPointer
2432+
);
2433+
my @mouse = $::application->pointerPos;
2434+
my @monitor = $::application->point_to_monitor(@mouse);
2435+
my @hsize = $self->size;
2436+
my @fin = ($mouse[0] - $psize[0]/2, $pos[1] - $hsize[1] - 1);
2437+
$fin[1] = $mouse[1] - $hsize[1] - $psize[1]
2438+
if $fin[1] > $mouse[1] - $hsize[1] - $psize[1];
2439+
$fin[0] = $pos[0] - $hsize[0]
2440+
if $fin[0] + $hsize[0] > $monitor[2];
2441+
$fin[0] = $monitor[0]
2442+
if $fin[0] < $monitor[0];
2443+
$fin[1] = $pos[1] - $hsize[1]
2444+
if $fin[1] + $hsize[1] >= $monitor[3];
2445+
$fin[1] = $pos[1] + $size[1] + $psize[1]/2
2446+
if $fin[1] < $monitor[1];
2447+
$fin[1] = $monitor[2] - $hsize[1]
2448+
if $fin[1] + $hsize[1] >= $monitor[3];
2449+
$fin[1] = $monitor[1]
2450+
if $fin[1] < $monitor[1];
2451+
if (
2452+
$fin[0] <= $mouse[0] && $fin[0] + $hsize[0] >= $mouse[0] + $psize[0] &&
2453+
$fin[1] <= $mouse[1] && $fin[1] + $hsize[1] >= $mouse[1] + $psize[1]
2454+
) {
2455+
$fin[0] = $mouse[0] + $psize[0];
2456+
$fin[1] = $mouse[1] - $psize[1] - $hsize[1];
2457+
}
2458+
2459+
$self->origin(@fin);
2460+
$self->show;
2461+
$self->bring_to_front;
2462+
}
2463+
24102464
sub on_paint
24112465
{
24122466
my ($self,$canvas) = @_;
@@ -2646,6 +2700,20 @@ sub open_help
26462700
return $self-> {HelpClass}-> open($link);
26472701
}
26482702

2703+
sub point_to_monitor
2704+
{
2705+
shift;
2706+
my @pos = @_ ? @_ : $::application-> pointerPos;
2707+
for my $r ( @{$::application->get_monitor_rects} ) {
2708+
next unless
2709+
$r->[0] <= $pos[0] && $r->[2] > $pos[0] &&
2710+
$r->[1] <= $pos[1] && $r->[3] > $pos[1]
2711+
;
2712+
return @$r;
2713+
}
2714+
return (0,0,$::application->size);
2715+
}
2716+
26492717
sub on_die
26502718
{
26512719
my ($self, $err, $stack) = @_;

class/Application.c

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -762,57 +762,11 @@ Application_get_scroll_rate( Handle self)
762762
static void
763763
hshow( Handle self)
764764
{
765-
PWidget_vmt hintUnder = CWidget( var-> hintUnder);
766-
SV * text = hintUnder-> get_hint( var-> hintUnder);
767-
Point size;
768-
Point s = my-> get_size( self);
769-
Point fin = {0,0};
770-
Point pos = fin;
771-
Point mouse = my-> get_pointerPos( self);
772-
Point hintSize;
773-
PWidget_vmt hintWidget = CWidget( var-> hintWidget);
774-
775-
if (
776-
var-> hintAround.left == -1 &&
777-
var-> hintAround.bottom == -1 &&
778-
var-> hintAround.right == -1 &&
779-
var-> hintAround.top == -1
780-
) {
781-
size = hintUnder-> get_size( var-> hintUnder);
782-
apc_widget_map_points( var-> hintUnder, true, 1, &pos);
783-
} else {
784-
pos.x = var->hintAround.left;
785-
pos.y = var->hintAround.bottom;
786-
size.x = var->hintAround.right - pos.x;
787-
size.y = var->hintAround.top - pos.y;
788-
}
789-
790-
hintWidget-> set_text( var-> hintWidget, text);
791-
hintWidget-> set_color( var-> hintWidget, PWidget(var-> hintUnder)-> hintColor);
792-
hintWidget-> set_backColor( var-> hintWidget, PWidget(var-> hintUnder)-> hintBackColor);
793-
hintSize = hintWidget-> get_size( var-> hintWidget);
794-
795-
fin. x = mouse. x - 16;
796-
fin. y = pos. y - hintSize. y - 1;
797-
if ( fin. y > mouse. y - hintSize. y - 32) fin. y = mouse. y - hintSize. y - 32;
798-
799-
if ( fin. x + hintSize. x >= s. x) fin. x = pos. x - hintSize. x;
800-
if ( fin. x < 0) fin. x = 0;
801-
if ( fin. y + hintSize. y >= s. y) fin. y = pos. y - hintSize. y;
802-
if ( fin. y < 0) fin. y = pos. y + size. y + 16;
803-
if ( fin. y + hintSize. y >= s. y) fin. y = s. y - hintSize. y;
804-
if ( fin. y < 0) fin. y = 0;
805-
if (
806-
fin. x <= mouse.x && fin.x + hintSize.x >= mouse.x + 32 &&
807-
fin. y <= mouse.y && fin.y + hintSize.y >= mouse.y + 32
808-
) {
809-
fin. x = mouse.x + 32;
810-
fin. y = mouse.y - 32 - hintSize.y;
811-
}
812-
813-
hintWidget-> set_origin( var-> hintWidget, fin);
814-
hintWidget-> show( var-> hintWidget);
815-
hintWidget-> bring_to_front( var-> hintWidget);
765+
CWidget(var->hintWidget)->notify(
766+
var->hintWidget,
767+
"sHR", "Hint",
768+
var->hintUnder, var->hintAround
769+
);
816770
}
817771

818772
void

0 commit comments

Comments
 (0)