How do I get the gdk window for a gtk window in C?
Asked Answered
M

2

15

I'm trying to set the cursor to a watch. The problem is that gdk_set_cursor() requires a gdk_window.

How do I get the gdk_window of a gtk_window in C? I've seen examples for gtkmm and pygtk but I can't find the corresponding C function.

Maxson answered 22/4, 2012 at 2:7 Comment(0)
B
29
GdkWindow *gdk_window = gtk_widget_get_window(GTK_WIDGET(gtk_window));

or, pre GTK 2.14, but now disallowed:

GdkWindow *gdk_window = gtk_window->window;
Brought answered 22/4, 2012 at 9:25 Comment(2)
Thanks that solved the problem of how to get the gdkwindow. Unfortunately the mouse pointer still stays the same. GdkWindow *gdkWindow = gtk_widget_get_window(window); GdkCursor *gdkCursor = gdk_cursor_new(GDK_WATCH); gdk_window_set_cursor(gdkWindow,gdkCursor);Maxson
while(gtk_events_pending ()) { gtk_main_iteration (); } often helps.Pastime
H
1

In my case gdk_window_set_cursor did not work because gtk_widget_get_window was returning an invalid handle because it was not already realized. Moving those lines after the window is made visible solved it for me.

From docs:

... For example, widget->window will be created when a widget is realized. Normally realization happens implicitly; if you show a widget and all its parent containers, then the widget will be realized and ...

Hypersonic answered 18/12, 2022 at 21:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.