Skip to content

Commit d7d4459

Browse files
committed
tooltips: ensure tooltips are viewable.
At certain bottom panel heights, GtkTooltip positioning logic ends up causing tooltips appear on the wrong side of the panel, and unviewable. This reimplements d80c0dc.
1 parent 273a3a9 commit d7d4459

File tree

3 files changed

+88
-4
lines changed

3 files changed

+88
-4
lines changed

src/compositor/compositor.c

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,75 @@ meta_compositor_unmanage (MetaCompositor *compositor)
627627
META_COMPOSITOR_GET_CLASS (compositor)->unmanage (compositor);
628628
}
629629

630+
static void
631+
ensure_tooltip_visible (MetaWindow *window)
632+
{
633+
const MetaLogicalMonitor *monitor;
634+
MetaRectangle work_area, win_rect;
635+
gint new_x, new_y;
636+
637+
/* Why this is here:
638+
* As of gtk 3.24, tooltips for GtkStatusIcons began displaying their tool tip
639+
* off the screen in certain situations.
640+
*
641+
* See: https://github.com/GNOME/gtk/commit/14d22cb3233e
642+
*
643+
* If the status icon is too small relative to its panel (which has been assigned
644+
* as a strut to muffin), tooltip positioning fails both tests in gdkwindowimpl.c
645+
* (maybe_flip_position()) skipping repositioning of the tooltip inside the workarea.
646+
* This only occurs on bottom panels, and only begins happening when the status icon
647+
* becomes 10px or more smaller than the panel it's *centered* on.
648+
*
649+
* Since the calculations are based upon the monitor's workarea and the status icon
650+
* plug window's size, there's no way to compensate for or fool gtk into displaying it
651+
* correctly. So here, we do our own check and adjustment if a part of the tooltip
652+
* window falls outside the current monitor's work area. This is also useful since
653+
* muffin knows *exactly* the work area for each monitor, whereas gtk only has
654+
* _NET_WORKAREA to go by, which only keeps track of (primary monitor * n_workspaces),
655+
* so an odd monitor layout would trip this up anyhow.
656+
*
657+
* This may cause regressions - see: https://github.com/linuxmint/muffin/commit/050038690,
658+
* but without being able to reproduce the issue mentioned there, we'll just have to address
659+
* it if it appears again as a result of this change. */
660+
661+
monitor = window->monitor;
662+
663+
if (!monitor)
664+
return;
665+
666+
meta_workspace_get_work_area_for_monitor (meta_workspace_manager_get_active_workspace (window->display->workspace_manager),
667+
monitor->number,
668+
&work_area);
669+
670+
meta_window_get_buffer_rect (window, &win_rect);
671+
672+
new_x = win_rect.x;
673+
new_y = win_rect.y;
674+
675+
if (win_rect.y < work_area.y)
676+
{
677+
new_y = work_area.y;
678+
}
679+
else if (win_rect.y + win_rect.height > work_area.y + work_area.height)
680+
{
681+
new_y = (work_area.y + work_area.height - win_rect.height);
682+
}
683+
684+
if (win_rect.x < work_area.x)
685+
{
686+
new_x = work_area.x;
687+
}
688+
else if (win_rect.x + win_rect.width > work_area.x + work_area.width)
689+
{
690+
new_x = (work_area.x + work_area.width - win_rect.width);
691+
}
692+
693+
if (new_x != win_rect.x || new_y != win_rect.y)
694+
{
695+
meta_window_move_frame (window, FALSE, new_x, new_y);
696+
}
697+
}
698+
630699
void
631700
meta_compositor_add_window (MetaCompositor *compositor,
632701
MetaWindow *window)
@@ -659,7 +728,15 @@ meta_compositor_add_window (MetaCompositor *compositor,
659728
NULL);
660729

661730
if (window->layer == META_LAYER_OVERRIDE_REDIRECT)
662-
window_group = priv->top_window_group;
731+
{
732+
if (window->type == META_WINDOW_TOOLTIP)
733+
{
734+
ensure_tooltip_visible (window);
735+
}
736+
737+
window_group = priv->top_window_group;
738+
}
739+
663740
else if (window->type == META_WINDOW_DESKTOP)
664741
window_group = priv->bottom_window_group;
665742
else

src/core/window.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4361,7 +4361,10 @@ meta_window_move_resize_internal (MetaWindow *window,
43614361
gboolean moved_or_resized = FALSE;
43624362
MetaWindowUpdateMonitorFlags update_monitor_flags;
43634363

4364-
g_return_if_fail (!window->override_redirect);
4364+
if (window->type != META_WINDOW_TOOLTIP)
4365+
{
4366+
g_return_if_fail (!window->override_redirect);
4367+
}
43654368

43664369
/* The action has to be a move, a resize or the wayland client
43674370
* acking our choice of size.
@@ -4535,7 +4538,10 @@ meta_window_move_frame (MetaWindow *window,
45354538
MetaMoveResizeFlags flags;
45364539
MetaRectangle rect = { root_x_nw, root_y_nw, 0, 0 };
45374540

4538-
g_return_if_fail (!window->override_redirect);
4541+
if (window->type != META_WINDOW_TOOLTIP)
4542+
{
4543+
g_return_if_fail (!window->override_redirect);
4544+
}
45394545

45404546
flags = (user_op ? META_MOVE_RESIZE_USER_ACTION : 0) | META_MOVE_RESIZE_MOVE_ACTION;
45414547
meta_window_move_resize_internal (window, flags, META_GRAVITY_NORTH_WEST, rect);

src/x11/window-x11.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,8 @@ meta_window_x11_move_resize_internal (MetaWindow *window,
14401440
* the client window may not get a real event
14411441
*/
14421442
if ((need_move_client || need_move_frame) &&
1443-
!(need_resize_client || need_resize_frame))
1443+
!(need_resize_client || need_resize_frame) &&
1444+
window->type != META_WINDOW_TOOLTIP)
14441445
need_configure_notify = TRUE;
14451446

14461447
/* MapRequest events with a PPosition or UPosition hint with a frame

0 commit comments

Comments
 (0)