Skip to content

Commit 096dbb1

Browse files
vtyrtovTurboGit
authored andcommitted
colorlabels: strengthen Wayland popover anchoring (relative_to + pointing_to rect + extra debug)
1 parent 61ce83f commit 096dbb1

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/libs/tools/colorlabels.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "dtgtk/button.h"
2424
#include "gui/accelerators.h"
2525
#include "gui/gtk.h"
26+
#include "common/debug.h"
2627
#include "libs/lib.h"
2728
#include "libs/lib_api.h"
2829

@@ -34,6 +35,10 @@
3435
#include <gdk/gdkwayland.h>
3536
#endif
3637

38+
#ifdef GDK_WINDOWING_X11
39+
#include <gdk/gdkx.h>
40+
#endif
41+
3742
DT_MODULE(1)
3843

3944
typedef struct dt_lib_colorlabels_t
@@ -224,6 +229,20 @@ static void _lib_colorlabels_edit(dt_lib_module_t *self,
224229
use_popover = GDK_IS_WAYLAND_DISPLAY(gtk_widget_get_display(window));
225230
#endif
226231

232+
// Debug: backend and basic context
233+
const char *backend = "unknown";
234+
#ifdef GDK_WINDOWING_WAYLAND
235+
if(GDK_IS_WAYLAND_DISPLAY(gtk_widget_get_display(window))) backend = "wayland";
236+
#endif
237+
#ifdef GDK_WINDOWING_X11
238+
if(GDK_IS_X11_DISPLAY(gtk_widget_get_display(window))) backend = "x11";
239+
#endif
240+
dt_print(DT_DEBUG_ALWAYS,
241+
"[colorlabels] edit popup: backend=%s use_popover=%d colorlabel=%d event=(type=%d btn=%d x_root=%d y_root=%d)",
242+
backend, use_popover, d->colorlabel,
243+
event ? event->type : -1, event ? event->button : -1,
244+
event ? (int)event->x_root : -1, event ? (int)event->y_root : -1);
245+
227246
GtkWidget *entry = gtk_entry_new();
228247
gtk_widget_set_size_request(entry, FLOATING_ENTRY_WIDTH, -1);
229248
gtk_widget_add_events(entry, GDK_FOCUS_CHANGE_MASK);
@@ -236,7 +255,25 @@ static void _lib_colorlabels_edit(dt_lib_module_t *self,
236255
{
237256
// Wayland path: use GtkPopover anchored to the clicked color label button for proper xdg_popup semantics
238257
GtkWidget *button = d->buttons[d->colorlabel];
258+
// Debug: anchor widget info
259+
GtkAllocation alloc = {0};
260+
gtk_widget_get_allocation(button, &alloc);
261+
// Try to translate button coords to toplevel
262+
gint rx = -1, ry = -1;
263+
if(gtk_widget_get_toplevel(button))
264+
gtk_widget_translate_coordinates(button, window, 0, 0, &rx, &ry);
265+
dt_print(DT_DEBUG_ALWAYS,
266+
"[colorlabels] popover anchor: button=%p name=%s alloc=(%d,%d %dx%d) toplevel_xy=(%d,%d)",
267+
(void*)button, gtk_widget_get_name(button),
268+
alloc.x, alloc.y, alloc.width, alloc.height, rx, ry);
239269
d->floating_window = gtk_popover_new(button);
270+
// Be explicit about relative_to and pointing rect to avoid GTK quirks in some environments
271+
gtk_popover_set_relative_to(GTK_POPOVER(d->floating_window), button);
272+
GdkRectangle r = { 0, 0, alloc.width, alloc.height };
273+
gtk_popover_set_pointing_to(GTK_POPOVER(d->floating_window), &r);
274+
dt_print(DT_DEBUG_ALWAYS,
275+
"[colorlabels] popover pointing_to: rel_rect=(%d,%d %dx%d)",
276+
r.x, r.y, r.width, r.height);
240277
gtk_popover_set_modal(GTK_POPOVER(d->floating_window), TRUE);
241278
gtk_popover_set_position(GTK_POPOVER(d->floating_window), GTK_POS_TOP);
242279
gtk_container_add(GTK_CONTAINER(d->floating_window), entry);
@@ -248,6 +285,9 @@ static void _lib_colorlabels_edit(dt_lib_module_t *self,
248285
// Legacy/X11 path: keep undecorated popup GtkWindow
249286
const gint x = event->x_root;
250287
const gint y = event->y_root - DT_PIXEL_APPLY_DPI(50);
288+
dt_print(DT_DEBUG_ALWAYS,
289+
"[colorlabels] x11 popup window move: target=(%d,%d) entry_width=%d",
290+
(int)x, (int)y, (int)FLOATING_ENTRY_WIDTH);
251291

252292
d->floating_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
253293
#ifdef GDK_WINDOWING_QUARTZ

0 commit comments

Comments
 (0)