GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Nov 26, 2014 5:27 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: [solved] GDK Window from GTK Window ?
PostPosted: Sat Mar 22, 2008 10:41 pm 
Offline
Familiar Face

Joined: Sun Mar 09, 2008 2:16 pm
Posts: 14
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.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 1:32 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Code:
GtkWindow *my_window;
GdkWindow = *my_gdk_window = my_window->window;

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 4:18 pm 
Offline
Familiar Face

Joined: Sun Mar 09, 2008 2:16 pm
Posts: 14
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:
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 6:13 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
The window does not yet have a GdkWindow. You have to show it and wait for it to be created. For example...

Code:
#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;
}

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 7:31 am 
Offline
Familiar Face

Joined: Sun Mar 09, 2008 2:16 pm
Posts: 14
Sometimes the solution is just too obvious :D

Thank you for solving this Problem!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group