Followup with code, Gdk/X integration




See attached code sample.  Compile with:

g++ -o resize resize.cxx -L/usr/X11R6/lib `pkg-config --libs --cflags
gtkmm-2.0` -lXm -lXt -lX11 -lm


Run resize:

[carl traveler raster]$ ./resize
//--------------hit button at startup
create new info
Straight X: XID(83886103) dims: width = 500 height = 300 pos: 0,25
X Via Gdk::Drawable: XID(83886103) dims: width = 500 height = 300 pos: 0,25
Gdk::Drawable: 500,300

//-------------resize in X direction, hit button
Straight X: XID(83886103) dims: width = 702 height = 300 pos: 0,25
X Via Gdk::Drawable: XID(83886103) dims: width = 702 height = 300 pos: 0,25
Gdk::Drawable: 500,300     //------------- note unchanged

//-------------resize in Y direction, hit button
Straight X: XID(83886103) dims: width = 702 height = 441 pos: 0,25
X Via Gdk::Drawable: XID(83886103) dims: width = 702 height = 441 pos: 0,25
Gdk::Drawable: 500,300     //------------- note unchanged


I don't know why the Gdk::Drawable still thinks it's the same old size
as when it was initialized, even though the underlying X window is
resized.

Help?

Regards,
Carl

#include <gdk/gdkx.h>
#include <Xm/Form.h>
#include <Xm/Frame.h>
#include <Xm/DrawingA.h>
#include <Xm/PushBG.h>

#undef DestroyNotify
#undef Status
#include <gtkmm/main.h>
#include <gtkmm/drawingarea.h>
#include <gdkmm/colormap.h>
#include <gdkmm/window.h>

#include <iostream>

#include <math.h>
#include <unistd.h>


Widget Ggraf;

struct GtkInfo {
    GtkInfo(Window win);

    Glib::RefPtr<Gdk::Drawable> _win;
};

GtkInfo* info = 0;
int width = 500, height = 300;

GtkInfo::GtkInfo(Window win) :
    _win(Glib::wrap(gdk_window_foreign_new(win)))
{
}

void PrintGeometry(Display* dsp, Window win)
{
    Window root;
    int xret, yret;
    unsigned int widthret,heightret,borderwidthret,depthret;

    XGetGeometry(dsp, win, &root, &xret, &yret, 
                 &widthret, &heightret, &borderwidthret, &depthret);
    std::cout << "XID(" << win << ") dims: width = "
              << widthret << " height = " << heightret
              << " pos: " << xret << "," << yret << std::endl;
}

void GbuttonPressed(Widget w, XtPointer client_data, XtPointer call_data)
{
    if(!info){
        std::cout << "create new info" << std::endl;
        info = new GtkInfo(XtWindow(Ggraf));
    }

    std::cout << "Straight X: ";
    PrintGeometry(XtDisplay(Ggraf), XtWindow(Ggraf));

    if(info /* 0 */){
        std::cout << "X Via Gdk::Drawable: ";
        PrintGeometry(GDK_WINDOW_XDISPLAY(info->_win->gobj()),
                      GDK_WINDOW_XID(info->_win->gobj()));

        int x, y;
        info->_win->get_size(x, y);
        std::cout << "Gdk::Drawable: " << x << "," << y << std::endl;
    }

    
}


int main(int argc, char** argv)
{
    Gtk::Main m(argc, argv);

    // Mandated by Gtk errors pointing to this function
    g_type_init();

    XtAppContext app_context;

	Widget GtopLevel = XtVaAppInitialize(&app_context,
                                         "RasterTest",
                                         NULL,0,
                                         &argc,argv,
                                         NULL,
                                         NULL);

    Widget Gwindow = XtVaCreateManagedWidget(
        "Gwindow",
        xmFormWidgetClass,
        GtopLevel,
        NULL);
  
    Widget Gbutton = XtVaCreateManagedWidget(
        "Gbutton",
        xmPushButtonGadgetClass,
        Gwindow,
        XmNtopAttachment,XmATTACH_FORM,
        XmNleftAttachment,XmATTACH_FORM,
        NULL);
  
    XtAddCallback(Gbutton,XmNactivateCallback,GbuttonPressed,0);

    Ggraf = XtVaCreateManagedWidget(
        "Ggraf",
        xmDrawingAreaWidgetClass,
        Gwindow,
        XmNtopAttachment,XmATTACH_WIDGET,
        XmNtopWidget, Gbutton,
        XmNleftAttachment,XmATTACH_FORM,
        XmNrightAttachment,XmATTACH_FORM,
        XmNbottomAttachment,XmATTACH_FORM,
        XmNwidth,500,
        XmNheight,300,
        NULL);

	XtRealizeWidget(GtopLevel);

    XtAppMainLoop(app_context);
    
}


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