Re: [gtk-list] Re: more widget size problems/questions



Havoc Pennington wrote:

> Anyway, I'm sure your code will work most of the time for now,

yes, the "frame hack" works beautifully. of course all of the
child windows/widgets are non-user-resizable dialog...

> but you
> should know that from a design point of view it's the Wrong Thing and
> might not work quite right forever because you're relying on
> non-guaranteed behavior. If someone can suggest a reliable way of doing
> this that would be great, 

 (see below. i know its not perfect but it does work...)

> and we'll fix that Gnome function too, but I
> don't think there's any way around the fact the the window manager can
> (and in some cases should) resize the window as it's being mapped.


> Most likely the WM should be doing this centering; maybe we will add a
> hint to the KDE/Gnome window manager spec for that purpose.

i agree that the WM *should* do this work, since it knows the actual
size of the window before it is visible. i don't know much about
Xlib (or anything else for that matter), but i wonder if the WM knows
who the parent of the new window is. if so, it should be fairly
simple to constrain the position of the new window to within the
boundary of the parent window.

i don't know enough about gtk internals, but it _seems_ to me
that there must be some way to have gtk_widget_realize() 
make the appropriate requests for size that is being done
by gtk_widget_show()...


thanks again.
brent

==================================================

this works *really* nicely when the child widget
was built with the "frame hack"... maybe this is
just good policy for building a widget. it only 
ads four or five lines of code (in my limited
experience).

typedef enum { VW_POS_CENTER, VW_POS_MOUSE, VW_POS_TOP_CENTER } gui_win_pos;

void 
gui_gtk_position_in_parent( 
	GtkWidget *parent, 
	GtkWidget *child, 
	gui_win_pos where ) 
{
    GtkRequisition c_size;
    gint xPm, yPm;   /* mouse positions relative to window origin */
    gint xP, yP, wP, hP; /* origin and dimension of parent window */
    gint pos_x, pos_y;  /* eventual origin of child window */
    
    gtk_widget_size_request( child, &c_size );
    
    /* get origin and size of parent window */
    gdk_window_get_origin( (GdkWindow *)(parent->window), &xP, &yP );
    gdk_window_get_size( (GdkWindow *)(parent->window), &wP, &hP );

    if( c_size.width > wP || c_size.height > hP ){
	/* doh! maybe the user should consider giving
	 gVim a little more screen real estate */
	gtk_widget_set_uposition( child , xP + 2 , yP + 2 );
	return;
    }

    if( where == VW_POS_MOUSE ){
	/* position window at mouse pointer */
        gtk_widget_get_pointer( parent, &xPm, &yPm );
	pos_x = xP + xPm - (c_size.width)/2;
	pos_y = yP + yPm - (c_size.height)/2;
    }
    else{
	/* set child x origin so it is in center of Vim window */
        pos_x =  xP + ( wP - c_size.width )/2;
	
	if( where == VW_POS_TOP_CENTER )
	    pos_y = yP + 2;
        else
	/* where == VW_POS_CENTER */
	    pos_y = yP + ( hP - c_size.height )/2;
    }   
    
    /* now, make sure the window will be inside
       the parent window ... */
    if( pos_x < xP )
        pos_x = xP + 2;
    if( pos_y < yP )
        pos_y = yP + 2;
    if( (pos_x + c_size.width) > (wP + xP) )
        pos_x = xP + wP - c_size.width - 2;
    if( (pos_y + c_size.height) > (hP + yP) )
        pos_y = yP + hP - c_size.height - 2;
	
    gtk_widget_set_uposition( child , pos_x, pos_y);
}



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