From 353f0b6ad71b380ceba6f2454ea9884a544d7123 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sat, 16 May 2009 23:47:02 -0600 Subject: [PATCH] More work on imlib2 stuff. Seems to be some rendering corruption which I'm not sure the reason for, but other than that I think it works okay. --- doc/config_settings.xml | 7 +++ doc/variables.xml | 10 ++++ extras/nano/conky.nanorc | 2 +- extras/vim/syntax/conkyrc.vim | 2 +- src/conky.c | 18 ++---- src/imlib2.c | 108 +++++++++++++--------------------- src/imlib2.h | 4 +- 7 files changed, 67 insertions(+), 84 deletions(-) diff --git a/doc/config_settings.xml b/doc/config_settings.xml index 7a2f80de..62418741 100644 --- a/doc/config_settings.xml +++ b/doc/config_settings.xml @@ -176,6 +176,13 @@ + + + + IMLIB2 image cache size, in bytes. Defaults to 4MiB. Increase this value if you use $image lots. Set to 0 to disable the image cache. + + + diff --git a/doc/variables.xml b/doc/variables.xml index c2162935..0dbaa827 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -1042,6 +1042,16 @@ + + + + + + + Renders an image from the path specified using IMLIB2. Takes 2 optional arguments, one being a position, the other an size. Changing the x,y position will move the position of the image, and changing the WxH will scale the image. Example: ${image /home/brenden/cheeseburger.jpg -p 20,20 -s 200x200} will render 'cheeseburger.jpg' at (20,20) scaled to 200x200 pixels. + + + diff --git a/extras/nano/conky.nanorc b/extras/nano/conky.nanorc index de91922c..856ef6d8 100644 --- a/extras/nano/conky.nanorc +++ b/extras/nano/conky.nanorc @@ -5,7 +5,7 @@ syntax "conky" "(\.*conkyrc.*$|conky.conf)" ## Configuration items -color green "\<(alias|alignment|append_file|background|border_margin|border_width|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|colorN|cpu_avg_samples|default_bar_size|default_color|default_gauge_size|default_graph_size|default_outline_color|default_shade_color|diskio_avg_samples|display|double_buffer|draw_borders|draw_graph_borders|draw_outline|draw_shades|font|gap_x|gap_y|if_up_strictness|imap|mail_spool|max_port_monitor_connections|max_specials|max_user_text|maximum_width|minimum_size|mpd_host|mpd_password|mpd_port|music_player_interval|net_avg_samples|no_buffers|out_to_console|out_to_stderr|out_to_x|override_utf8_locale|overwrite_file|own_window|own_window_class|own_window_colour|own_window_hints|own_window_title|own_window_transparent|own_window_type|pad_percents|pop3|sensor_device|short_units|show_graph_range|show_graph_scale|stippled_borders|temperature_unit|template|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|text|text_buffer_size|top_cpu_separate|top_name_width|total_run_times|update_interval|uppercase|use_spacer|use_xft|xftalpha|xftfont)\>" +color green "\<(alias|alignment|append_file|background|border_margin|border_width|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|colorN|cpu_avg_samples|default_bar_size|default_color|default_gauge_size|default_graph_size|default_outline_color|default_shade_color|diskio_avg_samples|display|double_buffer|draw_borders|draw_graph_borders|draw_outline|draw_shades|font|gap_x|gap_y|if_up_strictness|imap|imlib_cache_size|mail_spool|max_port_monitor_connections|max_specials|max_user_text|maximum_width|minimum_size|mpd_host|mpd_password|mpd_port|music_player_interval|net_avg_samples|no_buffers|out_to_console|out_to_stderr|out_to_x|override_utf8_locale|overwrite_file|own_window|own_window_class|own_window_colour|own_window_hints|own_window_title|own_window_transparent|own_window_type|pad_percents|pop3|sensor_device|short_units|show_graph_range|show_graph_scale|stippled_borders|temperature_unit|template|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|text|text_buffer_size|top_cpu_separate|top_name_width|total_run_times|update_interval|uppercase|use_spacer|use_xft|xftalpha|xftfont)\>" ## Configuration item constants color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|undecorated|yes)\>" diff --git a/extras/vim/syntax/conkyrc.vim b/extras/vim/syntax/conkyrc.vim index b8886c42..d356d047 100644 --- a/extras/vim/syntax/conkyrc.vim +++ b/extras/vim/syntax/conkyrc.vim @@ -12,7 +12,7 @@ endif syn region ConkyrcComment start=/^\s*#/ end=/$/ -syn keyword ConkyrcSetting alias alignment append_file background border_margin border_width color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 colorN cpu_avg_samples default_bar_size default_color default_gauge_size default_graph_size default_outline_color default_shade_color diskio_avg_samples display double_buffer draw_borders draw_graph_borders draw_outline draw_shades font gap_x gap_y if_up_strictness imap mail_spool max_port_monitor_connections max_specials max_user_text maximum_width minimum_size mpd_host mpd_password mpd_port music_player_interval net_avg_samples no_buffers out_to_console out_to_stderr out_to_x override_utf8_locale overwrite_file own_window own_window_class own_window_colour own_window_hints own_window_title own_window_transparent own_window_type pad_percents pop3 sensor_device short_units show_graph_range show_graph_scale stippled_borders temperature_unit template template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 text text_buffer_size top_cpu_separate top_name_width total_run_times update_interval uppercase use_spacer use_xft xftalpha xftfont +syn keyword ConkyrcSetting alias alignment append_file background border_margin border_width color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 colorN cpu_avg_samples default_bar_size default_color default_gauge_size default_graph_size default_outline_color default_shade_color diskio_avg_samples display double_buffer draw_borders draw_graph_borders draw_outline draw_shades font gap_x gap_y if_up_strictness imap imlib_cache_size mail_spool max_port_monitor_connections max_specials max_user_text maximum_width minimum_size mpd_host mpd_password mpd_port music_player_interval net_avg_samples no_buffers out_to_console out_to_stderr out_to_x override_utf8_locale overwrite_file own_window own_window_class own_window_colour own_window_hints own_window_title own_window_transparent own_window_type pad_percents pop3 sensor_device short_units show_graph_range show_graph_scale stippled_borders temperature_unit template template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 text text_buffer_size top_cpu_separate top_name_width total_run_times update_interval uppercase use_spacer use_xft xftalpha xftfont syn keyword ConkyrcConstant \ above diff --git a/src/conky.c b/src/conky.c index b8b8cc6f..594b7d6a 100644 --- a/src/conky.c +++ b/src/conky.c @@ -3725,7 +3725,7 @@ static void generate_text_internal(char *p, int p_max_size, OBJ(image) { /* doesn't actually draw anything, just queues it omp. the * image will get drawn after the X event loop */ - cimlib_add_image(obj->data.s); + cimlib_add_image(obj->data.s); } #endif /* IMLIB2 */ OBJ(eval) { @@ -6263,10 +6263,6 @@ static void main_loop(void) if (output_methods & TO_X) { XFlush(display); -#ifdef IMLIB2 - cimlib_event_start(); -#endif /* IMLIB2 */ - /* wait for X event or timeout */ if (!XPending(display)) { @@ -6353,15 +6349,11 @@ static void main_loop(void) case Expose: { XRectangle r; - r.x = ev.xexpose.x; r.y = ev.xexpose.y; r.width = ev.xexpose.width; r.height = ev.xexpose.height; XUnionRectWithRegion(&r, region, region); -#ifdef IMLIB2 - cimlib_event_expose(&ev); -#endif /* IMLIB2 */ break; } @@ -6502,11 +6494,11 @@ static void main_loop(void) } #endif draw_stuff(); -#ifdef IMLIB2 - cimlib_event_end(/*window.x, window.y, */0, 0, window.width, window.height); -#endif /* IMLIB2 */ XDestroyRegion(region); region = XCreateRegion(); +#ifdef IMLIB2 + cimlib_event_end(text_start_x + border_margin, text_start_y + border_margin, window.width, window.height); +#endif /* IMLIB2 */ } } else { #endif /* X11 */ @@ -7512,11 +7504,13 @@ static void load_config_file(const char *f) stippled_borders = 4; } } +#ifdef IMLIB2 CONF("imlib_cache_size") { if (value) { cimlib_set_cache_size(atoi(value)); } } +#endif /* IMLIB2 */ #endif /* X11 */ CONF("update_interval") { if (value) { diff --git a/src/imlib2.c b/src/imlib2.c index 6e2e842c..4387b6d3 100644 --- a/src/imlib2.c +++ b/src/imlib2.c @@ -28,9 +28,13 @@ #include #include +#define NAME_SIZE 1024 + struct image_list_s { - const char *name; + char name[NAME_SIZE]; Imlib_Image image; + int x, y, w, h; + int wh_set; struct image_list_s *prev; struct image_list_s *next; }; @@ -46,9 +50,7 @@ Imlib_Image buffer, image; void cimlib_set_cache_size(long size) { - if (size > 0) { - imlib_set_cache_size(size); - } + imlib_set_cache_size(size); } void cimlib_cleanup(void) @@ -62,7 +64,7 @@ void cimlib_cleanup(void) image_list_start = image_list_end = NULL; } -void cimlib_init(Display *display, Window window, Visual *visual, Colormap colourmap) +void cimlib_init(Display *display, Window drawable, Visual *visual, Colormap colourmap) { image_list_start = image_list_end = NULL; cimlib_set_cache_size(DEFAULT_CACHE_SIZE); @@ -74,15 +76,34 @@ void cimlib_init(Display *display, Window window, Visual *visual, Colormap colou imlib_context_set_display(display); imlib_context_set_visual(visual); imlib_context_set_colormap(colourmap); - imlib_context_set_drawable(window); + imlib_context_set_drawable(drawable); } -void cimlib_add_image(const char *name) +void cimlib_add_image(const char *args) { struct image_list_s *cur = NULL; + char *tmp; + cur = malloc(sizeof(struct image_list_s)); memset(cur, 0, sizeof(struct image_list_s)); - cur->name = name; + + if (!sscanf(args, "%1024s", cur->name)) { + ERR("Invalid args for $image. Format is: ' (-p x,y) (-s WxH)' (got '%s')", args); + } + // now we check for optional args + tmp = strstr(args, "-p "); + if (tmp) { + tmp += 3; + sscanf(tmp, "%i,%i", &cur->x, &cur->y); + } + tmp = strstr(args, "-s "); + if (tmp) { + tmp += 3; + if (sscanf(tmp, "%ix%i", &cur->w, &cur->h)) { + cur->wh_set = 1; + } + } + if (image_list_end) { image_list_end->next = cur; cur->prev = image_list_end; @@ -102,8 +123,8 @@ static void cimlib_draw_image(struct image_list_s *cur) w = imlib_image_get_width(); h = imlib_image_get_height(); imlib_context_set_image(buffer); - imlib_blend_image_onto_image(image, 0, 0, 0, w, h, - 0, 0, w, h); + imlib_blend_image_onto_image(image, 1, 0, 0, h, w, + cur->x, cur->y, cur->w, cur->h); imlib_context_set_image(image); imlib_free_image(); } else { @@ -111,13 +132,6 @@ static void cimlib_draw_image(struct image_list_s *cur) } } -void cimlib_event_start(void) -{ - if (!image_list_start) return; /* are we actually drawing anything? */ - /* init our updates to empty */ - updates = imlib_updates_init(); -} - static void cimlib_draw_all(void) { struct image_list_s *cur = image_list_start; @@ -132,57 +146,17 @@ void cimlib_event_end(int x, int y, int width, int height) if (!image_list_start) return; /* are we actually drawing anything? */ /* take all the little rectangles to redraw and merge them into * something sane for rendering */ - updates = imlib_updates_merge_for_rendering(updates, width, height); - for (current_update = updates; current_update; current_update = imlib_updates_get_next(current_update)) { - int up_x, up_y, up_w, up_h; + buffer = imlib_create_image(width, height); + /* we can blend stuff now */ + imlib_context_set_blend(1); - /* find out where the first update is */ - imlib_updates_get_coordinates(current_update, - &up_x, &up_y, &up_w, &up_h); + cimlib_draw_all(); - /* create our buffer image for rendering this update */ - buffer = imlib_create_image(up_w, up_h); - - /* we can blend stuff now */ - imlib_context_set_blend(1); - - cimlib_draw_all(); - - /* set the buffer image as our current image */ - imlib_context_set_image(buffer); - /* render the image at 0, 0 */ - imlib_render_image_on_drawable(up_x, up_y); - /* don't need that temporary buffer image anymore */ - imlib_free_image(); - } - /* if we had updates - free them */ - if (updates) { - imlib_updates_free(updates); - } else { - /* was likely a timeout, redraw everything */ - - /* create our buffer image for rendering this update */ - buffer = imlib_create_image(width, height); - - /* we can blend stuff now */ - imlib_context_set_blend(1); - - cimlib_draw_all(); - - /* set the buffer image as our current image */ - imlib_context_set_image(buffer); - /* render the image at 0, 0 */ - imlib_render_image_on_drawable(x, y); - /* don't need that temporary buffer image anymore */ - imlib_free_image(); - } -} - -void cimlib_event_expose(XEvent *event) -{ - if (!image_list_start) return; /* are we actually drawing anything? */ - updates = imlib_update_append_rect(updates, - event->xexpose.x, event->xexpose.y, - event->xexpose.width, event->xexpose.height); + /* set the buffer image as our current image */ + imlib_context_set_image(buffer); + /* render the image at 0, 0 */ + imlib_render_image_on_drawable(x, y); + /* don't need that temporary buffer image anymore */ + imlib_free_image(); } diff --git a/src/imlib2.h b/src/imlib2.h index 53f98b13..a276dd82 100644 --- a/src/imlib2.h +++ b/src/imlib2.h @@ -26,10 +26,8 @@ void cimlib_add_image(const char *name); void cimlib_set_cache_size(long size); -void cimlib_init(Display *display, Window window, Visual *visual, Colormap colourmap); -void cimlib_event_start(void); +void cimlib_init(Display *display, Window drawable, Visual *visual, Colormap colourmap); void cimlib_event_end(int x, int y, int width, int height); -void cimlib_event_expose(XEvent *event); void cimlib_cleanup(void); #endif /* _CONKY_IMBLI2_H_ */