Re: Gtk problems with GNOME
- From: Matias Szeinfeld <matinger gmail com>
- To: desktop-devel-list gnome org
- Subject: Re: Gtk problems with GNOME
- Date: Wed, 19 Sep 2012 17:05:24 -0300
Send main.c
2012/9/19 Matias Szeinfeld <matinger gmail com>:
> Hi, i have a problem using gtk_window_move with gnome. There are two
> windows, and a function to move one window (not decorated) respect to
> the other window (decorated) using gtk_window_move. The problem is the
> result. Because not always is the expected. Sometimes the window
> (undecorated) position is wrong. I want to know why.
>
> This situation appear first when i use gtkwebkit with the undecorated
> parent. Then i try without gtkwebkit, and usually works but not
> always. So try more times if you choose the option without gtkwebkit.
> The problem is show better if you attach a gtkwebkit to the not
> decorated window (uncomment code in the main.c).
>
> This program works in Ubuntu 12.04 with XFCE and not in Ubuntu 12.04 with gnome.
> Can someone help me please?
> I send you the main.c.
> Compile: gcc -o main main.c `pkg-config --cflags --libs gtk+-2.0 webkit-1.0`
>
> RealPos: http://imageshack.us/a/img404/861/realpos.png
> BadPos: http://imageshack.us/a/img840/5949/badpos.png
> BadPos2: http://imageshack.us/a/img705/3136/badpos2.png
> BadPosWithWebKit: http://imageshack.us/a/img441/4392/badposwithwebkit.png
> RealPosWithWebKit: http://imageshack.us/a/img528/4655/realposwithwebkit.png
#include <gtk/gtk.h>
#include <webkit/webkit.h>
typedef struct Size {
int x;
int y;
int w;
int h;
} Size;
void move(GtkWidget *videoOverlay,GtkWidget *_main, int x, int y){
gint xOrigin,yOrigin,borderLeft,borderBottom;
GdkRectangle fRect;
GdkWindow *window = gtk_widget_get_window(_main); // Getting window
gdk_window_get_origin(window, &xOrigin,&yOrigin); // Parent's left-top screen coordinates
gdk_window_get_frame_extents( window, &fRect ); // Getting size and position including decorations
//Calculating borders
borderLeft = (fRect.width-720)/2;
borderBottom = fRect.height - (576 + (yOrigin-fRect.y));
gtk_window_move( GTK_WINDOW(videoOverlay), fRect.x+(fRect.width-720)+x-borderLeft, fRect.y+(fRect.height-576)+y-borderBottom );
}
void resize(GtkWidget *_overlay, int w, int h){
GdkGeometry hints;
hints.min_width = w;
hints.min_height = h;
hints.width_inc = w;
hints.height_inc = h;
GdkWindowHints mask = (GdkWindowHints) (GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE );
gtk_window_set_geometry_hints (GTK_WINDOW (_overlay),
_overlay,
&hints,
mask);
}
static void on_window_destroyed( GtkWidget * widget, gpointer user_data ) {
gtk_main_quit();
}
int main(int argc, char * argv[]){
GtkWidget *_window,*_overlay,*_view;
Size s;
gtk_init(NULL, NULL);
// Main window initialization
_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(_window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(_window), 720, 576);
gtk_window_set_title(GTK_WINDOW(_window), "Sample");
gtk_widget_set_double_buffered(_window, FALSE);
// Set background color
GdkColor color;
gdk_color_parse ("black", &color);
gtk_widget_modify_bg (_window, GTK_STATE_NORMAL, &color);
// Connect signals
g_signal_connect( GTK_OBJECT(_window), "destroy", G_CALLBACK (on_window_destroyed), NULL);
gtk_widget_show(_window);
// Create Overlay
_overlay = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_decorated (GTK_WINDOW (_overlay), FALSE);
gtk_window_set_resizable (GTK_WINDOW(_overlay), FALSE);
gtk_window_set_skip_taskbar_hint( GTK_WINDOW(_overlay), TRUE );
gtk_window_set_transient_for(GTK_WINDOW(_overlay),GTK_WINDOW(_window));
gtk_window_set_accept_focus( GTK_WINDOW(_overlay), FALSE );
gtk_window_set_destroy_with_parent( GTK_WINDOW(_overlay), TRUE );
gtk_widget_realize(_overlay);
// Set overlay position
s.y=s.x=0;
move(_overlay,_window, s.x, s.y);
// Set overlay size
s.w=720;
s.h=576;
resize(_overlay, s.w, s.h);
gdk_window_restack(
gtk_widget_get_window(_overlay),
gtk_widget_get_window(_window),
FALSE
);
gtk_widget_show(_overlay);
/*
// Create WebKit
_view = webkit_web_view_new ();
// Setup webkit
webkit_web_view_set_full_content_zoom( WEBKIT_WEB_VIEW (_view), TRUE );
webkit_web_view_set_transparent( WEBKIT_WEB_VIEW (_view), TRUE );
// Load url
webkit_web_view_load_uri (WEBKIT_WEB_VIEW (_view), "http://google.com.ar" );
//Show webkit
gtk_container_add(GTK_CONTAINER(_overlay),_view);
gtk_widget_show (_view);
*/
// Move and resize overlay
s.y=100;
s.x=100;
s.w=620;
s.h=476;
move(_overlay,_window, s.x, s.y);
resize(_overlay, s.w, s.h);
// Run loop
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]