I'm trying to move the gtk window to a certain position on the screen under wayland. Here is the demo script, but it's not working. What should be changed to make it work, Can someone check this please? -
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gdk/gdkwayland.h>
#include <wayland-client.h>
//gcc `pkg-config --cflags gtk+-3.0` -o example-0 example-0.c `pkg-config --libs gtk+-3.0` -l wayland-client
struct wl_compositor *compositor;
struct wl_shell *shell;
struct wl_shm *shm;
void registry_global_handler
(
void *data,
struct wl_registry *registry,
uint32_t name,
const char *interface,
uint32_t version
) {
if (strcmp(interface, "wl_compositor") == 0) {
compositor = wl_registry_bind(registry, name,
&wl_compositor_interface, 3);
} else if (strcmp(interface, "wl_shm") == 0) {
shm = wl_registry_bind(registry, name,
&wl_shm_interface, 1);
} else if (strcmp(interface, "wl_shell") == 0) {
shell = wl_registry_bind(registry, name,
&wl_shell_interface, 1);
}
}
void registry_global_remove_handler
(
void *data,
struct wl_registry *registry,
uint32_t name
) {}
const struct wl_registry_listener registry_listener = {
.global = registry_global_handler,
.global_remove = registry_global_remove_handler
};
int move_Window (GtkWidget *widget)
{
GdkDisplay *gdk_display = gdk_display_get_default ();
if (GDK_IS_WAYLAND_DISPLAY (gdk_display))
{
struct wl_display *display = gdk_wayland_display_get_wl_display (gdk_display);
// display = gdk_wayland_display_get_wl_display (gdk_window_get_display (widget));
if (display) {
printf("wayland\n");
struct wl_registry *registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, ®istry_listener, NULL);
// wait for the "initial" set of globals to appear
wl_display_roundtrip(display);
struct wl_surface *surface = wl_compositor_create_surface(compositor);
GdkWindow *w = gtk_widget_get_window (GTK_WIDGET(widget));
struct wl_surface *w_surface = gdk_wayland_window_get_wl_surface (w);
struct wl_shell_surface *shell_surface = wl_shell_get_shell_surface(shell, surface);
wl_shell_surface_set_toplevel(shell_surface);
wl_shell_surface_set_transient(shell_surface, surface, 300, 200, 0);
while (1) {
//wl_display_dispatch(display);
}
}
}
if (GDK_IS_X11_DISPLAY(gdk_display)){
printf("x11\n");
}
}
static void
print_hello (GtkWidget *widget,
gpointer data)
{
g_print ("Hello World\n");
}
static void
activate (GtkApplication *app,
gpointer user_data)
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *button_box;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
gtk_container_add (GTK_CONTAINER (window), button_box);
button = gtk_button_new_with_label ("Hello World");
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
gtk_container_add (GTK_CONTAINER (button_box), button);
gtk_widget_show_all (window);
move_Window(window);
}
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;
}
Is it possible to do it via the new protocol? How can it be done if possible?
i want to move gtkwindow under waylan,