-- Leo's gemini proxy
-- Connecting to git.thebackupbox.net:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
repo: rxvt-unicode-sixel action: commit revision: path_from: revision_from: 5f76cd9b4c043c8da702dc1a08716f8cc2145a03: path_to: revision_to:
commit 5f76cd9b4c043c8da702dc1a08716f8cc2145a03 Author: Emanuele Giaquinta <emanuele.giaquinta@gmail.com> Date: Thu May 17 10:18:32 2012 +0000 Refactor code to manage images from files into a new rxvt_image object, so as to be able to load multiple images. diff --git a/src/background.C b/src/background.C
--- a/src/background.C +++ b/src/background.C @@ -60,11 +60,6 @@ create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_ void rxvt_term::bg_destroy () { -#ifdef HAVE_PIXBUF - if (pixbuf) - g_object_unref (pixbuf); -#endif - if (bg_pixmap) XFreePixmap (dpy, bg_pixmap); } @@ -92,9 +87,11 @@ rxvt_term::bg_window_size_sensitive () # endif # ifdef BG_IMAGE_FROM_FILE - if (bg_flags & BG_IS_FROM_FILE) + if (bg_image.flags & IM_IS_SET) { - if (bg_flags & BG_IS_SIZE_SENSITIVE) + if ((bg_image.flags & IM_IS_SIZE_SENSITIVE) + || bg_image.width () > szHint.width + || bg_image.height () > szHint.height) return true; } # endif @@ -111,9 +108,9 @@ rxvt_term::bg_window_position_sensitive () # endif # ifdef BG_IMAGE_FROM_FILE - if (bg_flags & BG_IS_FROM_FILE) + if (bg_image.flags & IM_IS_SET) { - if (bg_flags & BG_ROOT_ALIGN) + if (bg_image.flags & IM_ROOT_ALIGN) return true; } # endif @@ -151,7 +148,7 @@ make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_ } bool -rxvt_term::bg_set_geometry (const char *geom, bool update) +rxvt_image::set_geometry (const char *geom, bool update) { bool changed = false; int geom_flags = 0; @@ -172,14 +169,14 @@ rxvt_term::bg_set_geometry (const char *geom, bool update) { if (!strcasecmp (arr[i], "style=tiled")) { - new_flags = BG_TILE; + new_flags = IM_TILE; w = h = noScale; x = y = 0; geom_flags = WidthValue|HeightValue|XValue|YValue; } else if (!strcasecmp (arr[i], "style=aspect-stretched")) { - new_flags = BG_KEEP_ASPECT; + new_flags = IM_KEEP_ASPECT; w = h = windowScale; x = y = centerAlign; geom_flags = WidthValue|HeightValue|XValue|YValue; @@ -199,40 +196,40 @@ rxvt_term::bg_set_geometry (const char *geom, bool update) } else if (!strcasecmp (arr[i], "style=root-tiled")) { - new_flags = BG_TILE|BG_ROOT_ALIGN; + new_flags = IM_TILE|IM_ROOT_ALIGN; w = h = noScale; geom_flags = WidthValue|HeightValue; } else if (!strcasecmp (arr[i], "op=tile")) - new_flags |= BG_TILE; + new_flags |= IM_TILE; else if (!strcasecmp (arr[i], "op=keep-aspect")) - new_flags |= BG_KEEP_ASPECT; + new_flags |= IM_KEEP_ASPECT; else if (!strcasecmp (arr[i], "op=root-align")) - new_flags |= BG_ROOT_ALIGN; + new_flags |= IM_ROOT_ALIGN; // deprecated else if (!strcasecmp (arr[i], "tile")) { - new_flags |= BG_TILE; + new_flags |= IM_TILE; w = h = noScale; geom_flags |= WidthValue|HeightValue; } else if (!strcasecmp (arr[i], "propscale")) { - new_flags |= BG_KEEP_ASPECT; + new_flags |= IM_KEEP_ASPECT; w = h = windowScale; geom_flags |= WidthValue|HeightValue; } else if (!strcasecmp (arr[i], "hscale")) { - new_flags |= BG_TILE; + new_flags |= IM_TILE; w = windowScale; h = noScale; geom_flags |= WidthValue|HeightValue; } else if (!strcasecmp (arr[i], "vscale")) { - new_flags |= BG_TILE; + new_flags |= IM_TILE; h = windowScale; w = noScale; geom_flags |= WidthValue|HeightValue; @@ -250,7 +247,7 @@ rxvt_term::bg_set_geometry (const char *geom, bool update) } else if (!strcasecmp (arr[i], "root")) { - new_flags |= BG_TILE|BG_ROOT_ALIGN; + new_flags |= IM_TILE|IM_ROOT_ALIGN; w = h = noScale; geom_flags |= WidthValue|HeightValue; } @@ -262,7 +259,7 @@ rxvt_term::bg_set_geometry (const char *geom, bool update) rxvt_free_strsplit (arr); } - new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS; + new_flags |= flags & ~IM_GEOMETRY_FLAGS; if (!update) { @@ -284,13 +281,13 @@ rxvt_term::bg_set_geometry (const char *geom, bool update) clamp_it (x, -100, 200); clamp_it (y, -100, 200); - if (bg_flags != new_flags + if (flags != new_flags || h_scale != w || v_scale != h || h_align != x || v_align != y) { - bg_flags = new_flags; + flags = new_flags; h_scale = w; v_scale = h; h_align = x; @@ -298,19 +295,28 @@ rxvt_term::bg_set_geometry (const char *geom, bool update) changed = true; } + if (!(flags & IM_TILE) + || h_scale || v_scale + || (!(flags & IM_ROOT_ALIGN) && (h_align || v_align))) + flags |= IM_IS_SIZE_SENSITIVE; + else + flags &= ~IM_IS_SIZE_SENSITIVE; + return changed; } void -rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) +rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) { + int image_width = image.width (); + int image_height = image.height (); int target_width = szHint.width; int target_height = szHint.height; - w = h_scale * target_width / 100; - h = v_scale * target_height / 100; + w = image.h_scale * target_width / 100; + h = image.v_scale * target_height / 100; - if (bg_flags & BG_KEEP_ASPECT) + if (image.flags & IM_KEEP_ASPECT) { float scale = (float)w / image_width; min_it (scale, (float)h / image_height); @@ -321,24 +327,16 @@ rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h if (!w) w = image_width; if (!h) h = image_height; - if (bg_flags & BG_ROOT_ALIGN) + if (image.flags & IM_ROOT_ALIGN) { x = -target_x; y = -target_y; } else { - x = make_align_position (h_align, target_width, w); - y = make_align_position (v_align, target_height, h); + x = make_align_position (image.h_align, target_width, w); + y = make_align_position (image.v_align, target_height, h); } - - if (!(bg_flags & BG_TILE) - || h_scale || v_scale - || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) - || image_width > target_width || image_height > target_height) - bg_flags |= BG_IS_SIZE_SENSITIVE; - else - bg_flags &= ~BG_IS_SIZE_SENSITIVE; } # ifdef HAVE_PIXBUF @@ -456,8 +454,9 @@ rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, } bool -rxvt_term::render_image (bool transparent) +rxvt_term::render_image (rxvt_image &image, bool transparent) { + GdkPixbuf *pixbuf = image.pixbuf; if (!pixbuf) return false; @@ -480,9 +479,9 @@ rxvt_term::render_image (bool transparent) int w = 0; int h = 0; - get_image_geometry (image_width, image_height, w, h, x, y); + get_image_geometry (image, w, h, x, y); - if (!(bg_flags & BG_ROOT_ALIGN) + if (!(image.flags & IM_ROOT_ALIGN) && (x >= target_width || y >= target_height || x + w <= 0 @@ -518,7 +517,7 @@ rxvt_term::render_image (bool transparent) } else { - if (bg_flags & BG_TILE) + if (image.flags & IM_TILE) { new_pmap_width = min (image_width, target_width); new_pmap_height = min (image_height, target_height); @@ -541,7 +540,7 @@ rxvt_term::render_image (bool transparent) if (gc) { - if (bg_flags & BG_TILE) + if (image.flags & IM_TILE) { Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); pixbuf_to_pixmap (result, tile, gc, @@ -621,7 +620,7 @@ rxvt_term::render_image (bool transparent) # endif /* HAVE_PIXBUF */ bool -rxvt_term::bg_set_file (const char *file) +rxvt_image::set_file (const char *file) { if (!file || !*file) return false; @@ -645,7 +644,7 @@ rxvt_term::bg_set_file (const char *file) if (pixbuf) g_object_unref (pixbuf); pixbuf = image; - bg_flags |= BG_IS_FROM_FILE; + flags |= IM_IS_SET; ret = true; } # endif @@ -653,9 +652,9 @@ rxvt_term::bg_set_file (const char *file) if (ret) { if (p) - bg_set_geometry (p + 1); + set_geometry (p + 1); else - bg_set_default_geometry (); + set_default_geometry (); } return ret; @@ -1081,9 +1080,9 @@ rxvt_term::bg_render () # endif # ifdef BG_IMAGE_FROM_FILE - if (bg_flags & BG_IS_FROM_FILE) + if (bg_image.flags & IM_IS_SET) { - if (render_image (transparent)) + if (render_image (bg_image, transparent)) bg_flags |= BG_IS_VALID; } # endif diff --git a/src/command.C b/src/command.C
--- a/src/command.C +++ b/src/command.C @@ -3455,8 +3455,8 @@ rxvt_term::process_xterm_seq (int op, char *str, char resp) char str[256]; sprintf (str, "[%dx%d+%d+%d]", - min (h_scale, 32767), min (v_scale, 32767), - min (h_align, 32767), min (v_align, 32767)); + min (bg_image.h_scale, 32767), min (bg_image.v_scale, 32767), + min (bg_image.h_align, 32767), min (bg_image.v_align, 32767)); process_xterm_seq (XTerm_title, str, CHAR_ST); } else @@ -3465,13 +3465,13 @@ rxvt_term::process_xterm_seq (int op, char *str, char resp) if (*str != ';') { - if (bg_set_file (str)) /* change pixmap */ + if (bg_image.set_file (str)) /* change pixmap */ changed = true; } else { str++; - if (bg_set_geometry (str, true)) + if (bg_image.set_geometry (str, true)) changed = true; } diff --git a/src/init.C b/src/init.C
--- a/src/init.C +++ b/src/init.C @@ -836,7 +836,7 @@ rxvt_term::init2 (int argc, const char *const *argv) #ifdef BG_IMAGE_FROM_FILE if (rs[Rs_backgroundPixmap]) - if (bg_set_file (rs[Rs_backgroundPixmap])) + if (bg_image.set_file (rs[Rs_backgroundPixmap])) if (!bg_window_position_sensitive ()) update_background (); #endif diff --git a/src/rxvt.h b/src/rxvt.h
--- a/src/rxvt.h +++ b/src/rxvt.h @@ -210,6 +210,68 @@ struct localise_env } }; +#ifdef HAVE_BG_PIXMAP +# ifdef BG_IMAGE_FROM_FILE +enum { + IM_IS_SET = 1 << 0, + IM_IS_SIZE_SENSITIVE = 1 << 1, + IM_KEEP_ASPECT = 1 << 2, + IM_ROOT_ALIGN = 1 << 3, + IM_TILE = 1 << 4, + IM_GEOMETRY_FLAGS = IM_KEEP_ASPECT | IM_ROOT_ALIGN | IM_TILE, +}; + +enum { + noScale = 0, + windowScale = 100, + defaultScale = windowScale, + centerAlign = 50, + defaultAlign = centerAlign, +}; + +struct rxvt_image +{ + uint8_t flags; + unsigned int h_scale, v_scale; /* percents of the window size */ + int h_align, v_align; /* percents of the window size: + 0 - left align, 50 - center, 100 - right */ + +# ifdef HAVE_PIXBUF + GdkPixbuf *pixbuf; +# endif + + ~rxvt_image () + { +# ifdef HAVE_PIXBUF + if (pixbuf) + g_object_unref (pixbuf); +# endif + } + + int width () + { +# ifdef HAVE_PIXBUF + return gdk_pixbuf_get_width (pixbuf); +# endif + } + int height () + { +# ifdef HAVE_PIXBUF + return gdk_pixbuf_get_height (pixbuf); +# endif + } + bool set_file (const char *file); + bool set_geometry (const char *geom, bool update = false); + void set_default_geometry () + { + h_scale = v_scale = defaultScale; + h_align = v_align = defaultAlign; + flags |= IM_IS_SIZE_SENSITIVE; + } +}; +# endif +#endif + /* ***************************************************************************** * STRUCTURES AND TYPEDEFS @@ -1086,11 +1148,6 @@ struct rxvt_term : zero_initialized, rxvt_vars, rxvt_screen enum { BG_IS_VALID = 1 << 0, - BG_KEEP_ASPECT = 1 << 3, - BG_ROOT_ALIGN = 1 << 4, - BG_TILE = 1 << 14, - BG_GEOMETRY_FLAGS = BG_KEEP_ASPECT | BG_ROOT_ALIGN | BG_TILE, - BG_TINT_SET = 1 << 5, BG_TINT_BITAND = 1 << 6, @@ -1100,36 +1157,14 @@ struct rxvt_term : zero_initialized, rxvt_vars, rxvt_screen BG_IS_TRANSPARENT = 1 << 10, BG_NEEDS_REFRESH = 1 << 11, - BG_IS_SIZE_SENSITIVE = 1 << 12, - BG_IS_FROM_FILE = 1 << 13, }; unsigned int bg_flags; # ifdef BG_IMAGE_FROM_FILE - void get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y); - bool render_image (bool transparent); - - enum { - noScale = 0, - windowScale = 100, - defaultScale = windowScale, - centerAlign = 50, - defaultAlign = centerAlign, - }; - - unsigned int h_scale, v_scale; /* percents of the window size */ - int h_align, v_align; /* percents of the window size: - 0 - left align, 50 - center, 100 - right */ - - bool bg_set_geometry (const char *geom, bool update = false); - void bg_set_default_geometry () - { - h_scale = v_scale = defaultScale; - h_align = v_align = defaultAlign; - } - - bool bg_set_file (const char *file); + rxvt_image bg_image; + void get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y); + bool render_image (rxvt_image &image, bool transparent); # endif # ifdef ENABLE_TRANSPARENCY @@ -1171,7 +1206,6 @@ struct rxvt_term : zero_initialized, rxvt_vars, rxvt_screen } #endif #ifdef HAVE_PIXBUF - GdkPixbuf *pixbuf; bool pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, int src_x, int src_y, int dst_x, int dst_y, unsigned int width, unsigned int height);
-----END OF PAGE-----
-- Response ended
-- Page fetched on Sun Jun 2 10:03:08 2024