GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[solved] GDK Window from GTK Window ?

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
Zarg
Familiar Face


Joined: 09 Mar 2008
Posts: 10

PostPosted: Sat Mar 22, 2008 10:41 pm    Post subject: [solved] GDK Window from GTK Window ? Reply with quote

Hello everybody!

Could anyone please tell me how I can get the GDK_WINDOW of my GTK_WINDOW?

Thanks a lot for helping me :)

Greetings
Zarg


Last edited by Zarg on Tue Mar 25, 2008 7:32 am; edited 1 time in total
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 420
Location: Portland, OR USA

PostPosted: Mon Mar 24, 2008 1:32 pm    Post subject: Reply with quote

Code: (C)
1
2
GtkWindow *my_window;
GdkWindow = *my_gdk_window = my_window->window;
Back to top
Zarg
Familiar Face


Joined: 09 Mar 2008
Posts: 10

PostPosted: Mon Mar 24, 2008 4:18 pm    Post subject: Reply with quote

Hello and thank you for this answer!

Unfortunately this doesn't seem to work for me ...

My very simple program compiles, but I get runtime errors:
- g_return_if_fail will abort my program because it fails "CRITICAL **: main: assertion `GDK_IS_WINDOW (gdk_window)' failed"
- if I remove g_return_if_fail (line 17) I get "Segmentation fault (core dumped)"

Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
int main (int argc, char *argv[])
{
    /* This is called in all GTK applications */
   
gtk_init (&argc, &argv);
   
    /* window creation --------------------------------------------------- */
    /* create a new toplevel window */
   
GtkWidget *xero;
    xero = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   
    /* TODO get xdisplay and xwindow --------------------------------- */
   
Display *display;
    Window   window;
   
    GdkWindow *gdk_window = xero->window;
   
    g_return_if_fail (GDK_IS_WINDOW (gdk_window));
   
    display = GDK_WINDOW_XDISPLAY (gdk_window);
    window  = GDK_WINDOW_XWINDOW (gdk_window);

    /* Finish ---------------------------------------------------------------- */
    /* Display the window */
   
gtk_widget_show (xero);
   
    /* All GTK applications must have a gtk_main() */
   
gtk_main ();
   
    return 0;
}


Any suggestions?
Or is there an easier way to do this?

Greetings
Zarg
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 420
Location: Portland, OR USA

PostPosted: Mon Mar 24, 2008 6:13 pm    Post subject: Reply with quote

The window does not yet have a GdkWindow. You have to show it and wait for it to be created. For example...

Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <gtk/gtk.h>

int main (int argc, char *argv[])
{
    GtkWidget *xero;
   
    /* This is called in all GTK applications */
   
gtk_init (&argc, &argv);
   
    /* window creation --------------------------------------------------- */
    /* create a new toplevel window */
   
   
xero = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    /* Finish ---------------------------------------------------------------- */
    /* Display the window */
   
gtk_widget_show (xero);
   
    /* TODO get xdisplay and xwindow --------------------------------- */
   
   
while (gtk_events_pending()) gtk_main_iteration();
    g_return_val_if_fail (GDK_IS_WINDOW (xero->window), 1);

   
    /* All GTK applications must have a gtk_main() */
   
gtk_main ();
   
    return 0;
}
Back to top
Zarg
Familiar Face


Joined: 09 Mar 2008
Posts: 10

PostPosted: Tue Mar 25, 2008 7:31 am    Post subject: Reply with quote

Sometimes the solution is just too obvious :D

Thank you for solving this Problem!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP