Ph_WM_RESIZE: looks like a bug (?)

Hi!
If I resize a PtWidget then I receive the new width and height in
Ph_EV_WM event (Ph_WM_RESIZE). If I set these values with PtSetResources
then I receive a new event with 1 pixel smaller width and height.

Is this a bug or not?



A short example follows:
Compile it, run it, then resize the window and see how it resize itself
to the minimum size.


#include <Pt.h>
#include <photon/PtWindow.h>

int EventHandler (PtWidget_t*,void*,PtCallbackInfo_t*);

int main() {
PtArg_t args[13];
PhArea_t size = {{10,10},{400,400}};
int render = Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER |
Ph_WM_RENDER_MIN | Ph_WM_RENDER_MAX | Ph_WM_RENDER_CLOSE |
Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MOVE |
Ph_WM_RENDER_ASAPP;
int manage = Ph_WM_CLOSE | Ph_WM_FOCUS | Ph_WM_MENU |
Ph_WM_TOFRONT | Ph_WM_TOBACK | Ph_WM_HIDE | Ph_WM_CONSWITCH |
Ph_WM_RESIZE | Ph_WM_MOVE | Ph_WM_ICON | Ph_WM_MAX |
Ph_WM_BACKDROP | Ph_WM_TASKBAR | Ph_WM_RESTORE | Ph_WM_FFRONT;
PtWidget_t * widget=NULL;

if (PtInit(NULL) == -1) {
PtExit(EXIT_FAILURE);
}

PtSetArg(&args[0],Pt_ARG_AREA,&size,0);
PtSetArg(&args[1],Pt_ARG_WINDOW_RENDER_FLAGS,render,~0);
PtSetArg(&args[2],Pt_ARG_WINDOW_MANAGED_FLAGS,manage,~0);
PtSetArg(&args[3],Pt_ARG_WINDOW_NOTIFY_FLAGS,Pt_TRUE,~0);
PtSetArg(&args[4],Pt_ARG_WINDOW_STATE,Pt_FALSE,Ph_WM_STATE_ISHIDDEN);
PtSetArg(&args[5],Pt_ARG_RESIZE_FLAGS,0,Pt_RESIZE_XY_BITS);
PtSetArg(&args[6],Pt_ARG_BEVEL_WIDTH,0,0);
PtSetArg(&args[7],Pt_ARG_CONTAINER_FLAGS,0,~0);
PtSetArg(&args[8],Pt_ARG_WINDOW_TITLE,“window”,0);
PtSetParentWidget(NULL);
widget = PtCreateWidget(PtWindow,NULL,9,args);

PtAddEventHandler(widget,Ph_EV_WM,(PtCallbackF_t*)EventHandler,NULL);

PtRealizeWidget(widget);

PtMainLoop();
return (EXIT_SUCCESS);
}

int EventHandler(PtWidget_t* widget,void* notused,PtCallbackInfo_t*
acbinfo){
static unsigned short prev_width=0;
static unsigned short prev_height=0;
PhWindowEvent_t* winevt;
PtArg_t args[1];
PhDim_t dim;

if (acbinfo->event->type == Ph_EV_WM) {
winevt=(PhWindowEvent_t *)PhGetData(acbinfo->event);
switch (winevt->event_f) {
case Ph_WM_RESIZE:
if (winevt->size.w != prev_width ||
winevt->size.h != prev_height) {
prev_width = winevt->size.w;
prev_height = winevt->size.h;

dim.w = prev_width;
dim.h = prev_height;
PtSetArg(&args[0],Pt_ARG_DIM,&dim,0);
PtSetResources(widget,1,args);
}
break;
}
}
notused=notused;
return(Pt_CONTINUE);
}

Hi Laszlo,

Its a bug. This bug has been fixed in 6.3 which is going into beta shortly.

In the interim, you can use Pt_CB_RESIZE instead OR look at your
widget’s dimensions via Pt_ARG_DIM in your callback rather than looking
at the dim in the message. Both of these will give you correct sizing info.


Laszlo Nagy wrote:

Hi!
If I resize a PtWidget then I receive the new width and height in
Ph_EV_WM event (Ph_WM_RESIZE). If I set these values with PtSetResources
then I receive a new event with 1 pixel smaller width and height.

Is this a bug or not?



A short example follows:
Compile it, run it, then resize the window and see how it resize itself
to the minimum size.


#include <Pt.h
#include <photon/PtWindow.h

int EventHandler (PtWidget_t*,void*,PtCallbackInfo_t*);

int main() {
PtArg_t args[13];
PhArea_t size = {{10,10},{400,400}};
int render = Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER |
Ph_WM_RENDER_MIN | Ph_WM_RENDER_MAX | Ph_WM_RENDER_CLOSE |
Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MOVE |
Ph_WM_RENDER_ASAPP;
int manage = Ph_WM_CLOSE | Ph_WM_FOCUS | Ph_WM_MENU |
Ph_WM_TOFRONT | Ph_WM_TOBACK | Ph_WM_HIDE | Ph_WM_CONSWITCH |
Ph_WM_RESIZE | Ph_WM_MOVE | Ph_WM_ICON | Ph_WM_MAX |
Ph_WM_BACKDROP | Ph_WM_TASKBAR | Ph_WM_RESTORE | Ph_WM_FFRONT;
PtWidget_t * widget=NULL;

if (PtInit(NULL) == -1) {
PtExit(EXIT_FAILURE);
}

PtSetArg(&args[0],Pt_ARG_AREA,&size,0);
PtSetArg(&args[1],Pt_ARG_WINDOW_RENDER_FLAGS,render,~0);
PtSetArg(&args[2],Pt_ARG_WINDOW_MANAGED_FLAGS,manage,~0);
PtSetArg(&args[3],Pt_ARG_WINDOW_NOTIFY_FLAGS,Pt_TRUE,~0);
PtSetArg(&args[4],Pt_ARG_WINDOW_STATE,Pt_FALSE,Ph_WM_STATE_ISHIDDEN);
PtSetArg(&args[5],Pt_ARG_RESIZE_FLAGS,0,Pt_RESIZE_XY_BITS);
PtSetArg(&args[6],Pt_ARG_BEVEL_WIDTH,0,0);
PtSetArg(&args[7],Pt_ARG_CONTAINER_FLAGS,0,~0);
PtSetArg(&args[8],Pt_ARG_WINDOW_TITLE,“window”,0);
PtSetParentWidget(NULL);
widget = PtCreateWidget(PtWindow,NULL,9,args);

PtAddEventHandler(widget,Ph_EV_WM,(PtCallbackF_t*)EventHandler,NULL);

PtRealizeWidget(widget);

PtMainLoop();
return (EXIT_SUCCESS);
}

int EventHandler(PtWidget_t* widget,void* notused,PtCallbackInfo_t*
acbinfo){
static unsigned short prev_width=0;
static unsigned short prev_height=0;
PhWindowEvent_t* winevt;
PtArg_t args[1];
PhDim_t dim;

if (acbinfo->event->type == Ph_EV_WM) {
winevt=(PhWindowEvent_t *)PhGetData(acbinfo->event);
switch (winevt->event_f) {
case Ph_WM_RESIZE:
if (winevt->size.w != prev_width ||
winevt->size.h != prev_height) {
prev_width = winevt->size.w;
prev_height = winevt->size.h;

dim.w = prev_width;
dim.h = prev_height;
PtSetArg(&args[0],Pt_ARG_DIM,&dim,0);
PtSetResources(widget,1,args);
}
break;
}
}
notused=notused;
return(Pt_CONTINUE);
}