Re: Wrapped GdkWindow* resize issues



Ok, so this is really a pure Gtk issue.  I know this isn't necessarily the proper mailing list, but if anyone has any clues, I'd really appreciate the help.

 See below for test program to illustrate issue, just resize X-window and watch the debug output.

What can I do to get the GdkWindow to update its size bounds when the underlying XWindow changes size?

// Written by Ch. Tronche (http://tronche.lri.fr:8000/)
// Modified by C. Nygard to illustrate gdk_window resize issue
// Copyright by the author. This is unmaintained, no-warranty free software.
// Please use freely. It is appreciated (but by no means mandatory) to
// acknowledge the author's contribution. Thank you.
// Started on Thu Jun 26 23:29:03 1997

// gcc -o test test.c `pkg-config --libs --cflags gtk+-2.0 gtk+-x11-2.0`


#include <X11/Xlib.h>
#include <assert.h>
#include <unistd.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>

#define NIL (0)

main(int argc, char **argv)
{
      GdkWindow *gdk_win;

      gdk_init(&argc, &argv);

      // Open the display
      Display *dpy = XOpenDisplay(NIL);
      assert(dpy);

      // Get some colors
      int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
      int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));

      // Create the window
      Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,
                                     200, 100, 0, blackColor, blackColor);
      gdk_win = gdk_window_foreign_new((guint32)w);
      printf("gdk_win = %p\n", gdk_win);

      // We want to get MapNotify events
      XSelectInput(dpy, w, StructureNotifyMask);

      // "Map" the window (that is, make it appear on the screen)
      XMapWindow(dpy, w);

      // Create a "Graphics Context"
      GC gc = XCreateGC(dpy, w, 0, NIL);

      // Tell the GC we draw using the white color
      XSetForeground(dpy, gc, whiteColor);

      // Wait for the MapNotify event
      for(;;) {
            XEvent e;
            XNextEvent(dpy, &e);
            if (e.type == MapNotify)
                  break;
      }

      // Draw the line
      XDrawLine(dpy, w, gc, 10, 60, 180, 20);

      // Send the "DrawLine" request to the server
      XFlush(dpy);

      gdk_win = gdk_window_foreign_new((guint32)w);
      printf("gdk_win = %p\n", gdk_win);

      // Spit out window dimensions whenever we get an event.
      for(;;) {
            XEvent e;
            Window root;
            int x, y, xret, yret;
            unsigned int widthret,heightret,borderwidthret,depthret;

            XNextEvent(dpy, &e);
            XGetGeometry(dpy, w,
                         &root, &xret, &yret,
                         &widthret, &heightret, &borderwidthret, &depthret);
            printf("Window dims: (%d, %d) pos: (%d, %d)\n",
                   widthret, heightret, xret, yret);
            // Re-initializing gdk_win doesn't even help
            gdk_win = gdk_window_foreign_new((guint32)w);
            gdk_window_get_size(gdk_win, &x, &y);
            printf("GdkWindow dims: (%d, %d)\n", x, y);
      }

      // Wait for 10 seconds
      sleep(10);
}



On Sat, Mar 8, 2014 at 2:02 PM, Carl Nygard <cjnygard gmail com> wrote:
Hey all,

Hoping to get some help on an older version of Gtkmm (2.4).  I'm supporting some legacy code and as we migrate to newer versions of OS, we're running into issues with some drawing functionality.

To boil it down, we are creating a GdkWindow via gdk_window_foreign_new() from a drawable window, and then wrapping that in a Glib::RefPtr<Gdk::Drawable> via Glib::wrap().

void InitDrawable() {

Window win;  // local variable, assume initialized properly
Glib::RefPtr<Gdk::Drawable> drawable;
GdkWindow* w = gdk_window_foreign_new(win)
drawable = Glib::wrap(w);

}

The issue is that everything works fine the first time through.  But if we resize the window, the drawable->get_size() always returns whatever size the window was when the drawable was initialized.

I've tried a bunch of different ideas to try to get this to work:

- gdk_window_foreign_new_for_display(dpy, win) has no effect on behavior
- drawable.reset() to free up the GdkWindow and re-initialize whenever the Window resizes.
- XGetGeometry(dpy, win, ...) followed by drawable->resize() or gdk_window_resize(win,...)

Nothing seems to work.  Resize() has no effect on the GdkWindow.  Freeing the drawable and then calling gdk_window_foreign_new() actually returns the same value for the GdkWindow* every time.

I'm hoping someone has some clues as to what I'm doing wrong.  I'd be happy with any kind of workaround just to get this functional.  Suggestions to just upgrade to latest are not helpful, as this is legacy code.  However, we are in the middle of rewriting the front end in pure Gtkmm, so this issue will not last forever.  I just need to get the previous version stabilized for the porting period.

--carl




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