From b037a22036993a3ac0bbe51e5fd79ad780814f65 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 27 Feb 2010 17:52:41 +0800 Subject: Latest rev --- window-decorator/gtk-window-decorator.c | 155 ++++++++++++++++++++++++++----- window-decorator/gtk-window-decorator.c~ | 148 ++++++++++++++++++++++++----- 2 files changed, 256 insertions(+), 47 deletions(-) diff --git a/window-decorator/gtk-window-decorator.c b/window-decorator/gtk-window-decorator.c index 2064d3a..dac14f0 100644 --- a/window-decorator/gtk-window-decorator.c +++ b/window-decorator/gtk-window-decorator.c @@ -31,6 +31,8 @@ #include #include + + #ifndef GDK_DISABLE_DEPRECATED #define GDK_DISABLE_DEPRECATED #endif @@ -82,10 +84,14 @@ #define _(x) gettext (x) #define N_(x) x +#undef USE_METACITY + #ifdef USE_METACITY #include #endif + + #define METACITY_GCONF_DIR "/apps/metacity/general" #define COMPIZ_USE_SYSTEM_FONT_KEY \ @@ -322,6 +328,8 @@ static Atom toolkit_action_force_quit_dialog_atom; static Time dm_sn_timestamp; +int file_inc = 0; + #define C(name) { 0, XC_ ## name } static struct _cursor { @@ -944,11 +952,50 @@ button_state_paint (cairo_t *cr, } } +/* Cut and paste from GDK */ +static GdkGC * +get_bg_gc (GdkWindow *window, int x_offset, int y_offset) +{ + GdkWindowObject *private = (GdkWindowObject *)window; + guint gc_mask = 0; + GdkGCValues gc_values; + + if (private->bg_pixmap == GDK_PARENT_RELATIVE_BG && private->parent) + { + return get_bg_gc (GDK_WINDOW (private->parent), + x_offset + private->x, + y_offset + private->y); + } + else if (private->bg_pixmap && + private->bg_pixmap != GDK_PARENT_RELATIVE_BG && + private->bg_pixmap != GDK_NO_BG) + { + gc_values.fill = GDK_TILED; + gc_values.tile = private->bg_pixmap; + gc_values.ts_x_origin = x_offset; + gc_values.ts_y_origin = y_offset; + + gc_mask = GDK_GC_FILL | GDK_GC_TILE | GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN; + + return gdk_gc_new_with_values (window, &gc_values, gc_mask); + } + else + { + GdkGC *gc = gdk_gc_new (window); + + gdk_gc_set_foreground (gc, &(private->bg_color)); + + return gc; + } +} + + static void draw_window_decoration (decor_t *d) { cairo_t *cr; GtkStyle *style; + GdkDrawable *drawable; decor_color_t color; double alpha; double x1, y1, x2, y2, x, y, h; @@ -985,12 +1032,15 @@ draw_window_decoration (decor_t *d) gdk_drawable_set_colormap (GDK_DRAWABLE (d->pixmap), cmap); gdk_drawable_set_colormap (GDK_DRAWABLE (d->buffer_pixmap), cmap); + + drawable = GDK_DRAWABLE (d->buffer_pixmap); } - - if (d->buffer_pixmap) - cr = gdk_cairo_create (GDK_DRAWABLE (d->buffer_pixmap)); + else if (d->buffer_pixmap) + drawable = GDK_DRAWABLE (d->buffer_pixmap); else - cr = gdk_cairo_create (GDK_DRAWABLE (d->pixmap)); + drawable = GDK_DRAWABLE (d->pixmap); + + cr = gdk_cairo_create (GDK_DRAWABLE (drawable)); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); @@ -1396,23 +1446,70 @@ draw_window_decoration (decor_t *d) d->width, d->height); - //GdkColor c = {.pixel = 24, .red = MAXSHORT, .blue = MAXSHORT, .green = 0 }; - - fprintf (stderr, "depths are %i %i\n", gdk_drawable_get_depth (GDK_DRAWABLE (d->frame_window)), - gdk_drawable_get_depth (GDK_DRAWABLE (d->pixmap))); - if (d->frame_window) { + //Pixmap pix = gdk_x11_drawable_get_id (d->pixmap);, + //XGCValues gcv; + //Window winner = GDK_WINDOW_XID (d->frame_window); + + //gcv.foreground = BlackPixelOfScreen (GDK_SCREEN (gdk_display_get_default_screen (gdk_display_get_default ()))); + + //GC wingc = XCreateGC (GDK_DISPLAY (), + // GDK_SCREEN (gdk_display_get_default_screen (gdk_display_get_default ())), + // GCForeground, &gcv)); + + //XDrawRectangle (GDK_DISPLAY (gdk_display_get_default ()), winner, wingc, 0, 0, d->width, d->height); + gdk_window_set_back_pixmap (d->frame_window, d->pixmap, FALSE); + //gdk_window_clear (d->frame_window); + //GdkPixmap *gpixmaptest; + //GError *error = NULL; + //char buf_p[256]; + //char buf_w[256]; + //char buf_tp[256]; + //file_inc++; + //sprintf (buf_p, "/home/smspillaz/test%i.png", file_inc); + //sprintf (buf_w, "/home/smspillaz/test_w%i.png", file_inc); + //cairo_surface_t *png = cairo_image_surface_create_from_png ("/home/smspillaz/test.png"); + //GdkPixbuf *pixbufImg = gdk_pixbuf_get_from_drawable (NULL, d->pixmap, NULL, 0, 0, 0, 0, d->width, d->height); + + //gdk_pixbuf_save (pixbufImg, buf_p, "png", &error, NULL); + //error = NULL; + //Pixmap pix; + //Pixmap mask_return; + //int alpha_threshold; + //gdk_pixbuf_xlib_render_pixmap_and_mask (pixbufImg, + // &pix, + // &mask_return, + // 1.0); + //sprintf (buf_tp, "/home/smspillaz/test%i.png", file_inc); + //gpixmaptest = gdk_pixmap_foreign_new_for_display (gdk_display_get_default (), + // pix); + //pixbufImg = gdk_pixbuf_get_from_drawable (NULL, gpixmaptest, NULL, 0, 0, 0, 0, d->width, d->height); + //gdk_pixbuf_save (pixbufImg, buf_tp, "png", &error, NULL); + //error = NULL; + // + //pixbufImg = gdk_pixbuf_get_from_drawable (NULL, d->frame_window, NULL, 0, 0, 0, 0, d->width, d->height); + //gdk_pixbuf_save (pixbufImg, buf_w, "png", &error, NULL); + //gdk_draw_pixbuf (GDK_DRAWABLE (d->frame_window), + // NULL, + // pixbufImg, + // 0, 0, + // 0, 0, + // d->width, + // d->height, + // GDK_RGB_DITHER_NONE, + // 0, + // 0); + //pixbufImg = gdk_pixbuf_get_from_drawable (NULL, d->frame_window, NULL, 0, 0, 0, 0, d->width, d->height); + //gdk_pixbuf_save (pixbufImg, buf_w, "png", &error, NULL); + //fprintf (stderr, "drawed deco\n"); //XClearWindow (xdisplay, GDK_WINDOW_XID (d->frame_window)); - gdk_draw_drawable (d->frame_window, - d->gc, - d->pixmap, - 0, - 0, - 0, - 0, - -1, - -1); + + //GdkGC *gc = get_bg_gc (d->frame_window, 0, 0); + + //gdk_window_set_back_pixmap (d->frame_window, d->pixmap, FALSE); + + } if (d->prop_xid) @@ -2629,6 +2726,13 @@ draw_decor_list (void *data) static void queue_decor_draw (decor_t *d) { + if (d->frame_window) + { + (*d->draw) (d); + gdk_window_clear (d->frame_window); + return; + } + if (g_slist_find (draw_list, d)) return; @@ -3453,7 +3557,7 @@ update_window_decoration_icon (WnckWindow *win) g_object_ref (G_OBJECT (d->icon_pixbuf)); d->icon_pixmap = pixmap_new_from_pixbuf (d->icon_pixbuf, - d->frame_window ? FALSE : TRUE); + TRUE); cr = gdk_cairo_create (GDK_DRAWABLE (d->icon_pixmap)); d->icon = cairo_pattern_create_for_surface (cairo_get_target (cr)); cairo_destroy (cr); @@ -4177,8 +4281,8 @@ window_geometry_changed (WnckWindow *win) update_window_decoration_size (win); update_event_windows (win); - if (d->frame_window) - queue_decor_draw (d); + //if (!d->frame_window) + //queue_decor_draw (d); } } } @@ -5422,14 +5526,17 @@ event_filter_func (GdkXEvent *gdkxevent, if (win) { fprintf (stderr, "found win\n"); + gdk_window_clear (win); + #if 0 WnckWindow *wnck_window = g_object_get_data (G_OBJECT (win), "client_wnck_window"); if (wnck_window) { fprintf (stderr, "found wnck_win\n"); - update_window_decoration_size (wnck_window); - } + //update_window_decoration_size (wnck_window); + } + #endif } } case EnterNotify: @@ -6663,7 +6770,7 @@ theme_changed (GConfClient *client) } } - if (use_meta_theme) + if (FALSE) { theme_draw_window_decoration = meta_draw_window_decoration; theme_calc_decoration_size = meta_calc_decoration_size; diff --git a/window-decorator/gtk-window-decorator.c~ b/window-decorator/gtk-window-decorator.c~ index c7d1f95..393fe95 100644 --- a/window-decorator/gtk-window-decorator.c~ +++ b/window-decorator/gtk-window-decorator.c~ @@ -322,6 +322,8 @@ static Atom toolkit_action_force_quit_dialog_atom; static Time dm_sn_timestamp; +int file_inc = 0; + #define C(name) { 0, XC_ ## name } static struct _cursor { @@ -944,11 +946,50 @@ button_state_paint (cairo_t *cr, } } +/* Cut and paste from GDK */ +static GdkGC * +get_bg_gc (GdkWindow *window, int x_offset, int y_offset) +{ + GdkWindowObject *private = (GdkWindowObject *)window; + guint gc_mask = 0; + GdkGCValues gc_values; + + if (private->bg_pixmap == GDK_PARENT_RELATIVE_BG && private->parent) + { + return get_bg_gc (GDK_WINDOW (private->parent), + x_offset + private->x, + y_offset + private->y); + } + else if (private->bg_pixmap && + private->bg_pixmap != GDK_PARENT_RELATIVE_BG && + private->bg_pixmap != GDK_NO_BG) + { + gc_values.fill = GDK_TILED; + gc_values.tile = private->bg_pixmap; + gc_values.ts_x_origin = x_offset; + gc_values.ts_y_origin = y_offset; + + gc_mask = GDK_GC_FILL | GDK_GC_TILE | GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN; + + return gdk_gc_new_with_values (window, &gc_values, gc_mask); + } + else + { + GdkGC *gc = gdk_gc_new (window); + + gdk_gc_set_foreground (gc, &(private->bg_color)); + + return gc; + } +} + + static void draw_window_decoration (decor_t *d) { cairo_t *cr; GtkStyle *style; + GdkDrawable *drawable; decor_color_t color; double alpha; double x1, y1, x2, y2, x, y, h; @@ -985,12 +1026,15 @@ draw_window_decoration (decor_t *d) gdk_drawable_set_colormap (GDK_DRAWABLE (d->pixmap), cmap); gdk_drawable_set_colormap (GDK_DRAWABLE (d->buffer_pixmap), cmap); + + drawable = GDK_DRAWABLE (d->buffer_pixmap); } - - if (d->buffer_pixmap) - cr = gdk_cairo_create (GDK_DRAWABLE (d->buffer_pixmap)); + else if (d->buffer_pixmap) + drawable = GDK_DRAWABLE (d->buffer_pixmap); else - cr = gdk_cairo_create (GDK_DRAWABLE (d->pixmap)); + drawable = GDK_DRAWABLE (d->pixmap); + + cr = gdk_cairo_create (GDK_DRAWABLE (drawable)); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); @@ -1396,23 +1440,70 @@ draw_window_decoration (decor_t *d) d->width, d->height); - //GdkColor c = {.pixel = 24, .red = MAXSHORT, .blue = MAXSHORT, .green = 0 }; - - fprintf (stderr, "depths are %i %i\n", gdk_drawable_get_depth (GDK_DRAWABLE (d->frame_window)), - gdk_drawable_get_depth (GDK_DRAWABLE (d->pixmap))); - if (d->frame_window) { + //Pixmap pix = gdk_x11_drawable_get_id (d->pixmap);, + //XGCValues gcv; + //Window winner = GDK_WINDOW_XID (d->frame_window); + + //gcv.foreground = BlackPixelOfScreen (GDK_SCREEN (gdk_display_get_default_screen (gdk_display_get_default ()))); + + //GC wingc = XCreateGC (GDK_DISPLAY (), + // GDK_SCREEN (gdk_display_get_default_screen (gdk_display_get_default ())), + // GCForeground, &gcv)); + + //XDrawRectangle (GDK_DISPLAY (gdk_display_get_default ()), winner, wingc, 0, 0, d->width, d->height); + gdk_window_set_back_pixmap (d->frame_window, d->pixmap, FALSE); + //gdk_window_clear (d->frame_window); + //GdkPixmap *gpixmaptest; + //GError *error = NULL; + //char buf_p[256]; + //char buf_w[256]; + //char buf_tp[256]; + //file_inc++; + //sprintf (buf_p, "/home/smspillaz/test%i.png", file_inc); + //sprintf (buf_w, "/home/smspillaz/test_w%i.png", file_inc); + //cairo_surface_t *png = cairo_image_surface_create_from_png ("/home/smspillaz/test.png"); + //GdkPixbuf *pixbufImg = gdk_pixbuf_get_from_drawable (NULL, d->pixmap, NULL, 0, 0, 0, 0, d->width, d->height); + + //gdk_pixbuf_save (pixbufImg, buf_p, "png", &error, NULL); + //error = NULL; + //Pixmap pix; + //Pixmap mask_return; + //int alpha_threshold; + //gdk_pixbuf_xlib_render_pixmap_and_mask (pixbufImg, + // &pix, + // &mask_return, + // 1.0); + //sprintf (buf_tp, "/home/smspillaz/test%i.png", file_inc); + //gpixmaptest = gdk_pixmap_foreign_new_for_display (gdk_display_get_default (), + // pix); + //pixbufImg = gdk_pixbuf_get_from_drawable (NULL, gpixmaptest, NULL, 0, 0, 0, 0, d->width, d->height); + //gdk_pixbuf_save (pixbufImg, buf_tp, "png", &error, NULL); + //error = NULL; + // + //pixbufImg = gdk_pixbuf_get_from_drawable (NULL, d->frame_window, NULL, 0, 0, 0, 0, d->width, d->height); + //gdk_pixbuf_save (pixbufImg, buf_w, "png", &error, NULL); + //gdk_draw_pixbuf (GDK_DRAWABLE (d->frame_window), + // NULL, + // pixbufImg, + // 0, 0, + // 0, 0, + // d->width, + // d->height, + // GDK_RGB_DITHER_NONE, + // 0, + // 0); + //pixbufImg = gdk_pixbuf_get_from_drawable (NULL, d->frame_window, NULL, 0, 0, 0, 0, d->width, d->height); + //gdk_pixbuf_save (pixbufImg, buf_w, "png", &error, NULL); + //fprintf (stderr, "drawed deco\n"); //XClearWindow (xdisplay, GDK_WINDOW_XID (d->frame_window)); - gdk_draw_drawable (d->frame_window, - d->gc, - d->pixmap, - 0, - 0, - 0, - 0, - -1, - -1); + + //GdkGC *gc = get_bg_gc (d->frame_window, 0, 0); + + //gdk_window_set_back_pixmap (d->frame_window, d->pixmap, FALSE); + + } if (d->prop_xid) @@ -2629,6 +2720,13 @@ draw_decor_list (void *data) static void queue_decor_draw (decor_t *d) { + if (d->frame_window) + { + (*d->draw) (d); + gdk_window_clear (d->frame_window); + return; + } + if (g_slist_find (draw_list, d)) return; @@ -3453,7 +3551,7 @@ update_window_decoration_icon (WnckWindow *win) g_object_ref (G_OBJECT (d->icon_pixbuf)); d->icon_pixmap = pixmap_new_from_pixbuf (d->icon_pixbuf, - d->frame_window ? FALSE : TRUE); + TRUE); cr = gdk_cairo_create (GDK_DRAWABLE (d->icon_pixmap)); d->icon = cairo_pattern_create_for_surface (cairo_get_target (cr)); cairo_destroy (cr); @@ -3669,6 +3767,7 @@ meta_calc_decoration_size (decor_t *d, return TRUE; } + } return FALSE; } @@ -4176,8 +4275,8 @@ window_geometry_changed (WnckWindow *win) update_window_decoration_size (win); update_event_windows (win); - if (d->frame_window) - queue_decor_draw (d); + //if (!d->frame_window) + //queue_decor_draw (d); } } } @@ -5421,14 +5520,17 @@ event_filter_func (GdkXEvent *gdkxevent, if (win) { fprintf (stderr, "found win\n"); + gdk_window_clear (win); + #if 0 WnckWindow *wnck_window = g_object_get_data (G_OBJECT (win), "client_wnck_window"); if (wnck_window) { fprintf (stderr, "found wnck_win\n"); - update_window_decoration_size (wnck_window); - } + //update_window_decoration_size (wnck_window); + } + #endif } } case EnterNotify: -- cgit v1.1