GtkClipboard owner-change signal under wayland



I have a GTK application which listen for clipboard "owner-change" signal to detect clipboard changes.

Under x11 all is working fine, the signal is fired when, for example, you press CTRL+C inside gedit.

Under Wayland "owner-change" signal is emitted when my window is *focused* and *moved*. Not when the clipboard changes. And most of GdkEventOwnerChange struct fields are *null*, including timestamps.

Why ?

Here is the code, just run it under both wayland or x11 (or GDK_BACKEND=x11) and see the differencies.

#include <gtk/gtk.h>

static void cb(GtkClipboard *gtkClipboard, GdkEvent *event, void *d)
{
    GdkEventOwnerChange *oce;
    oce = (GdkEventOwnerChange *)event;

    printf("----------\ncallback:\n");

    if (oce->type == GDK_OWNER_CHANGE)
        printf("oce->type is GDK_OWNER_CHANGE\n");
    else
        printf("oce->type is BAD: %d\n", (int)oce->type);

    printf("oce->window = %p\n", oce->window);
    printf("oce->send_event = %u\n", (unsigned)oce->send_event);
    printf("oce->owner = %p\n", oce->owner);
    printf("oce->reason = %d\n", (int)oce->reason);
    printf("oce->selection = %s\n", gdk_atom_name(oce->selection));
    printf("oce->time = %u\n", (unsigned)oce->time);
    printf("oce->selection_time = %u\n", (unsigned)oce->selection_time);


}

static void
activate (GtkApplication* app,
          gpointer        user_data)
{
  GtkWidget *window;
  GtkClipboard *c;

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
  gtk_widget_show_all (window);

  c = gtk_widget_get_clipboard(window, GDK_SELECTION_CLIPBOARD);
  g_signal_connect(c, "owner-change", G_CALLBACK(cb), (void *)1);

}

int
main (int    argc,
      char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}

Tests have been done under Ubutu 17.10.

Thank you
Giovanni









[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]