… | |
… | |
119 | |
119 | |
120 | scale 0.5, 2, load "$HOME/mypic.png" |
120 | scale 0.5, 2, load "$HOME/mypic.png" |
121 | |
121 | |
122 | IF you try out these expressions, you might suffer from sluggishness, |
122 | IF you try out these expressions, you might suffer from sluggishness, |
123 | because each time the terminal is resized, it again loads the PNG image |
123 | because each time the terminal is resized, it again loads the PNG image |
124 | and scales it. Scaling is usually fats, but loading the image can be quite |
124 | and scales it. Scaling is usually fast, but loading the image can be quite |
125 | time consuming. This is where C<keep> comes in handy: |
125 | time consuming. This is where C<keep> comes in handy: |
126 | |
126 | |
127 | scale 0.5, 2, keep { load "$HOME/mypic.png" } |
127 | scale 0.5, 2, keep { load "$HOME/mypic.png" } |
128 | |
128 | |
129 | The C<keep> operator executes all the statements inside the braces only |
129 | The C<keep> operator executes all the statements inside the braces only |
130 | once, or when it thinks the outcome might change. In other cases it |
130 | once, or when it thinks the outcome might change. In other cases it |
131 | returns the last value computed by the brace block. |
131 | returns the last value computed by the brace block. |
132 | |
132 | |
133 | This means that the C<load> is only executed once, which makes it much |
133 | This means that the C<load> is only executed once, which makes it much |
134 | faster, but alos means that more memory is being used, because the loaded |
134 | faster, but also means that more memory is being used, because the loaded |
135 | image must be kept in memory at all times. In this expression, the |
135 | image must be kept in memory at all times. In this expression, the |
136 | trade-off is likely worth it. |
136 | trade-off is likely worth it. |
137 | |
137 | |
138 | But back to effects: Other effects than scaling are also readily |
138 | But back to effects: Other effects than scaling are also readily |
139 | available, for example, you can tile the image to fill the whole window, |
139 | available, for example, you can tile the image to fill the whole window, |
… | |
… | |
152 | Another common background expression is: |
152 | Another common background expression is: |
153 | |
153 | |
154 | rootalign root |
154 | rootalign root |
155 | |
155 | |
156 | This one first takes a snapshot of the screen background image, and then |
156 | This one first takes a snapshot of the screen background image, and then |
157 | moves it to the upper left corner of the screen (as opposed to the upepr |
157 | moves it to the upper left corner of the screen (as opposed to the upper |
158 | left corner of the terminal window)- the result is pseudo-transparency: |
158 | left corner of the terminal window)- the result is pseudo-transparency: |
159 | the image seems to be static while the window is moved around. |
159 | the image seems to be static while the window is moved around. |
160 | |
160 | |
161 | =head2 CACHING AND SENSITIVITY |
161 | =head2 CACHING AND SENSITIVITY |
162 | |
162 | |
… | |
… | |
171 | The most important way to cache expensive operations is to use C<keep { |
171 | The most important way to cache expensive operations is to use C<keep { |
172 | ... }>. The C<keep> operator takes a block of multiple statements enclosed |
172 | ... }>. The C<keep> operator takes a block of multiple statements enclosed |
173 | by C<{}> and keeps the return value in memory. |
173 | by C<{}> and keeps the return value in memory. |
174 | |
174 | |
175 | An expression can be "sensitive" to various external events, such as |
175 | An expression can be "sensitive" to various external events, such as |
176 | scaling or moving the window, root backgorund changes and timers. Simply |
176 | scaling or moving the window, root background changes and timers. Simply |
177 | using an expression (such as C<scale> without parameters) that depend on |
177 | using an expression (such as C<scale> without parameters) that depend on |
178 | certain changing values (called "variables"), or using those variables |
178 | certain changing values (called "variables"), or using those variables |
179 | directly, will make an expression sensitive to these events - for example, |
179 | directly, will make an expression sensitive to these events - for example, |
180 | using C<scale> or C<TW> will make the expression sensitive to the terminal |
180 | using C<scale> or C<TW> will make the expression sensitive to the terminal |
181 | size, and thus to resizing events. |
181 | size, and thus to resizing events. |
… | |
… | |
266 | =item load $path |
266 | =item load $path |
267 | |
267 | |
268 | Loads the image at the given C<$path>. The image is set to plane tiling |
268 | Loads the image at the given C<$path>. The image is set to plane tiling |
269 | mode. |
269 | mode. |
270 | |
270 | |
271 | If the image is already in memory (e.g. because another temrinal instance |
271 | If the image is already in memory (e.g. because another terminal instance |
272 | uses it), then the in-memory copy us returned instead. |
272 | uses it), then the in-memory copy us returned instead. |
273 | |
273 | |
274 | =item load_uc $path |
274 | =item load_uc $path |
275 | |
275 | |
276 | Load uncached - same as load, but does not cache the image, which means it |
276 | Load uncached - same as load, but does not cache the image, which means it |
… | |
… | |
340 | |
340 | |
341 | =item merge $img ... |
341 | =item merge $img ... |
342 | |
342 | |
343 | Takes any number of images and merges them together, creating a single |
343 | Takes any number of images and merges them together, creating a single |
344 | image containing them all. The tiling mode of the first image is used as |
344 | image containing them all. The tiling mode of the first image is used as |
345 | the tiling mdoe of the resulting image. |
345 | the tiling mode of the resulting image. |
346 | |
346 | |
347 | This function is called automatically when an expression returns multiple |
347 | This function is called automatically when an expression returns multiple |
348 | images. |
348 | images. |
349 | |
349 | |
350 | =cut |
350 | =cut |
… | |
… | |
845 | Anything that didn't fit any of the other categories, even after applying |
845 | Anything that didn't fit any of the other categories, even after applying |
846 | force and closing our eyes. |
846 | force and closing our eyes. |
847 | |
847 | |
848 | =over 4 |
848 | =over 4 |
849 | |
849 | |
850 | =item once { ... } |
850 | =item keep { ... } |
851 | |
851 | |
|
|
852 | #TODO# |
|
|
853 | |
852 | This function takes a code block as argument, that is, one or more |
854 | This operator takes a code block as argument, that is, one or more |
853 | statements enclosed by braces. |
855 | statements enclosed by braces. |
854 | |
856 | |
855 | The trick is that this code block is only evaluated once - future calls |
857 | The trick is that this code block is only evaluated once - future calls |
856 | will simply return the original image (yes, it should only be used with |
858 | will simply return the original image (yes, it should only be used with |
857 | images). |
859 | images). |
… | |
… | |
865 | C<once> block so it only is reevaluated as required. |
867 | C<once> block so it only is reevaluated as required. |
866 | |
868 | |
867 | Putting the blur into a C<once> block will make sure the blur is only done |
869 | Putting the blur into a C<once> block will make sure the blur is only done |
868 | once: |
870 | once: |
869 | |
871 | |
870 | rootlign once { blur 10, root } |
872 | rootlign keep { blur 10, root } |
871 | |
873 | |
872 | This leaves the question of how to force reevaluation of the block, |
874 | This leaves the question of how to force reevaluation of the block, |
873 | in case the root background changes: If expression inside the block |
875 | in case the root background changes: If expression inside the block |
874 | is sensitive to some event (root background changes, window geometry |
876 | is sensitive to some event (root background changes, window geometry |
875 | changes), then it will be reevaluated automatically as needed. |
877 | changes), then it will be reevaluated automatically as needed. |