Site: new messages about current critical problem with FontConfig
[adesklets.git] / scripting / perl / adesklets.pm
blob6e5fffff4ae83572742e9f987d8d9437b3c24fdf
1 package adesklets;
3 =for html <div class="Content">
5 =head1 NAME
7 adesklets.pm -- Perl bindings to the adesklets interpreter
9 =head1 COPYRIGHT
11 Copyright (C) 2006, Lucas Brutschy <lbrutschy@users.sourceforge.net>
13 Released under the GPL, version 2.
15 Permission is hereby granted, free of charge, to any person obtaining a copy
16 of this software and associated documentation files (the "Software"), to
17 deal in the Software without restriction, including without limitation the
18 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
19 sell copies of the Software, and to permit persons to whom the Software is
20 furnished to do so, subject to the following conditions:
22 The above copyright notice and this permission notice shall be included in
23 all copies of the Software and its documentation and acknowledgment shall be
24 given in the documentation and software packages that this Software was
25 used.
27 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30 THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
31 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 =head1 SYNOPSIS
36 # Simple desklet: draw red lines following the mouse
37 use adesklets;
38 adesklets::open_streams();
40 # These are just normal adesklet commands
41 adesklets::window_resize(100,100);
42 adesklets::window_reset(adesklets::WINDOW_UNMANAGED);
43 adesklets::window_set_transparency(1);
44 adesklets::context_set_color(255,255,255,64);
45 adesklets::image_fill_rectangle(5,5,90,90);
46 adesklets::window_show();
48 adesklets::event_loop(ButtonPress=>\&onbutton); # supply a hash of callbacks
49 adesklets::close_streams();
51 sub onbutton
53 my($x,$y) = @_;
54 adesklets::context_set_color(255,0,0,255);
55 adesklets::image_fill_rectangle($x,$y,3,3);
58 =head1 DESCRIPTION
60 =head2 Functions
62 time_gate: Set a time gate
63 help: Display short help about a command
64 ping: Ping the interpreter
65 pause: Freeze the interpreter for debugging
66 version: Get interpreter version
67 get_id: Get current applet identificator
68 history: List/save commands history
69 set: Set or unset a textual variable
70 unset_all: Unset all defined textual variables
71 echo: Echo a string
72 start_recording: Start recording a macro
73 stop_recording: Stop recording the macro
74 play_get_abort_on_events: Get replays interuptable status
75 play_set_abort_on_events: Set replays to be interuptable
76 play: Play a given macro
77 context_get_dither: Get context dither
78 context_get_anti_alias: Get context anti alias
79 context_get_blend: Get context blending
80 context_get_operation: Get context operation
81 context_get_cliprect: Get clipping rectange
82 context_get_image: Get context image
83 context_get_font: Get context font
84 context_get_color_range: Get context color range
85 context_get_color_modifier: Get context color modifier
86 context_get_filter: Get context filter
87 context_get_color: Get context color
88 context_get_angle: Get context angle
89 context_get_direction: Get context direction
90 context_set_dither: Set context dither
91 context_set_anti_alias: Set context anti-alias
92 context_set_blend: Set context blending
93 context_set_operation: Set context operation
94 context_set_cliprect: Set context clipping rectangle
95 context_set_image: Set context image
96 context_set_font: Set context font
97 context_set_color_range: Set context color range
98 context_set_color_modifier: Set context color modifier
99 context_set_filter: Set context filter
100 context_set_color: Set context RGBA color
101 context_set_angle: Set context angle
102 context_set_direction: Set context direction
103 add_color_to_color_range: Add a color to a color range
104 blend_image_onto_image: Blend images together
105 blend_image_onto_image_at_angle: Blend images together
106 blend_image_onto_image_skewed: Blend images together
107 apply_filter: Apply a dynamic filter
108 get_text_size: Get size of text
109 get_text_advance: Get advance of text
110 text_draw: Draw a text string
111 modify_color_modifier_gamma: Modify gamma correction
112 modify_color_modifier_brightness: Modify brightness
113 modify_color_modifier_contrast: Modify contrast
114 get_color_modifier_tables: Get tables for a color modifier
115 set_color_modifier_tables: Set tables for a color modifier
116 get_color_modifier_value: Get a value for a color modifier
117 set_color_modifier_value: Set a value for a color modifier
118 apply_color_modifier: Apply a color modifier
119 apply_color_modifier_to_rectangle: Apply a color modifier
120 load_image_without_cache: Load an image from disk bypassing the cache
121 load_image: Load an image from disk
122 save_image: Save an image to disk
123 create_image: Create an image
124 create_image_using_data: Create an image from data
125 clone_image: Create a copy of an image
126 free_image: Free an image
127 load_font: Load a font
128 free_font: Free a font
129 list_fonts: List all fonts
130 list_font_path: List all fonts path
131 add_path_to_font_path: Add a font path
132 remove_path_from_font_path: Remove a font path
133 create_color_range: Create a color range
134 free_color_range: Free a color range
135 create_filter: Create a filter
136 free_filter: Free a filter
137 create_color_modifier: Create a color modifier
138 free_color_modifier: Free a color modifier
139 polygon_new: Create a polygon
140 polygon_free: Free a polygon
141 polygon_add_point: Add point to a polygon
142 images_reset_all: Free all images and refresh foreground
143 images_info: Get information on all images
144 fonts_reset_all: Free all fonts
145 fonts_info: Get information on all fonts
146 color_ranges_reset_all: Free all color ranges
147 color_ranges_info: Get information on all color ranges
148 color_modifiers_reset_all: Free all color modifiers
149 color_modifiers_info: Get information on all color modifiers
150 filters_reset_all: Free all filters
151 filters_info: Get information on all filters
152 polygons_reset_all: Free all polygons
153 polygons_info: Get information on all polygons
154 image_has_alpha: Get alpha channel setting of an image
155 image_get_width: Get width of an image
156 image_get_height: Get height of an image
157 image_get_filename: Get filename of an image
158 image_get_data: Get the data of an image
159 image_query_pixel: Query a pixel value
160 image_set_has_alpha: Set alpha channel of an image
161 image_set_changes_on_disk: Set image load time behavior
162 image_set_format: Set image format
163 image_filter_recurse:
164 image_draw_line: Draw a line
165 image_draw_rectangle: Draw a rectangle
166 image_fill_rectangle: Draw a filled rectangle
167 image_fill_color_range_rectangle: Draw a gradian filled rectange
168 image_draw_ellipse: Draw an ellipse
169 image_fill_ellipse: Fill an ellipse
170 image_copy_alpha_to_image: Transfert alpha channel
171 image_copy_alpha_rectangle_to_image: Transfert alpha channel
172 image_draw_polygon: Draw a polygon onto image
173 image_fill_polygon: Fill a polygon onto image
174 image_flip_horizontal: Flip an image horizontally
175 image_flip_vertical: Flip an image vertically
176 image_flip_diagonal: Flip an image diagonally
177 image_orientate: Orientate an image
178 image_blur: Blur an image
179 image_sharpen: Sharpen an image
180 filter_set: Set filter
181 filter_set_red: Set filter red channel
182 filter_set_green: Set filter grean channel
183 filter_set_blue: Set filter blue channel
184 filter_set_alpha: Set filter alpha channel
185 filter_constants: Set filter constants
186 filter_divisors: Set filter divisors
187 menu_fire: Fire a given menu
188 menu_reset_all: Reset all menus to initial state
189 menu_add_menu: Add a new menu
190 menu_add_submenu: Add a submenu to current menu
191 menu_add_item: Add an item to current menu
192 menu_add_separator: Add a separator to current menu
193 menu_end_submenu: End a submenu construction
194 events_info: Get all caught events
195 events_get_echo: Get events echo status
196 events_get_send_sigusr1: Get sending of SIGUSR1 to parent on event
197 window_reset: Reset the window
198 window_show: Map the window on the screen
199 window_hide: Unmap the window from the screen
200 window_resize: Resize the window
201 window_get_transparency: Get automatic transparency
202 window_get_background_grab: Get automatic grab
203 window_get_background_image: Get background image
204 window_get_managed_status: Get managed status
205 window_set_transparency: Set automatic transparency
206 window_set_background_grab: Set automatic grab
207 window_set_background_image: Set background image
208 screen_get_width: Get screen width
209 screen_get_height: Get screen height
210 screen_get_depth: Get screen depth
211 get_charset: Get input charset
212 set_charset: Set input charset
213 charset_status: Get charset capabilities
214 x_status: Status of connection to X Window server
215 quit: Quit the program
217 =head2 Constants
219 TEXT_TO_RIGHT
220 TEXT_TO_LEFT
221 TEXT_TO_DOWN
222 TEXT_TO_UP
223 TEXT_TO_ANGLE
224 OP_COPY
225 OP_ADD
226 OP_SUBSTRACT
227 OP_RESHADE
228 CHANNEL_RED
229 CHANNEL_GREEN
230 CHANNEL_BLUE
231 CHANNEL_ALPHA
232 WINDOW_UNMANAGED
233 WINDOW_MANAGED
235 =head1 SEE ALSO
237 adesklets manual
239 =for html <div />
241 =cut
243 use strict;
244 use IPC::Open3;
245 use Cwd 'realpath';
246 my $pid = 0;
248 sub open_streams
250 my ($path) = realpath($0);
252 my %opthash = (
253 '-h',2,'--help',2,
254 '-f',1,'-k',1, '--killall',1,'-c',1, '--cleanup',1,
255 '-i',1, '--installer',1,'-v',1, '--version',1,
258 foreach (@ARGV) { if (defined $opthash{$_}) {
259 if ($opthash{$_}==2) {
260 open(HELP,"| adesklets --help") or die $!;
261 while(<HELP>) { print; }
262 close(HELP);
263 exit;
264 } else { die "unsupported '$_' option.\n"; }
267 if((!defined $ENV{ADESKLETS_ID})&&(-t STDIN))
269 print 'Do you want to (r)egister this desklet or to (t)est it? ';
270 if(getc() eq 't')
272 print "\nNow testing...\n".('='x60)."\n",
273 "If you do not see anything (or just an initial flicker\n".
274 "in the top left corner of your screen), try `--help',\n".
275 "and see the FAQ: `info adesklets'.\n".
276 ('='x60)."\n";
277 $path = ':';
281 $pid = open3(\*OUT,\*IN,\*ERR,"adesklets $path ".join(" ",@ARGV)) or die $!;
283 my $line = readline(ERR);
284 if($line ne "event: ready!\n") { die $line; }
286 if ((!defined $ENV{ADESKLETS_ID})&&($path ne ":"))
288 print "Registered. Run 'adesklets' to (re)start your desklets.\n".
289 "Look at 'adesklets --help' for special options.\n";
290 quit();
291 close_streams();
292 exit;
296 sub close_streams
298 close (OUT); close (IN); close (ERR);
299 if($pid) { waitpid($pid,0); }
302 sub send_command
304 my ($command,@args) = @_;
305 $command .= " ".join(' ',@args)."\n";
306 syswrite OUT,$command;
308 my $lines = "";
309 while(1)
311 $lines .= readline(IN);
312 if($lines =~ s/^(.*)command \d+ ok: ([^\n]*)\n//s)
314 my ($prereturn,$return) = ($1,$2);
315 if(($return."\n") ne $command)
317 my @integers;
318 while($return =~ s/(\d+)//) { push(@integers,$1);}
319 if($#integers == 0) { return $integers[0];}
320 elsif($#integers > 0) { return @integers; }
322 if($prereturn ne "") { return split(/\n/,$prereturn); }
323 return $return;
324 } elsif ($lines =~ s/^(.*)command \d+ error: ([^\n]*)\n//s) {
325 die $1.$2."\n";
330 sub event_loop
332 my %functionhash = @_;
333 foreach (keys %functionhash)
334 { adesklets::send_command("event_catch",$_); }
336 while(1)
338 my $line = readline(ERR);
339 if($line =~ s/\s*event: //)
341 $line =~ s/\s+$//;
342 my @event = split / /,$line;
343 my $name = shift @event;
344 foreach my $key (keys %functionhash)
346 if(($name eq lc($key)) && ($functionhash{$key}))
347 { $functionhash{$key}->(@event); last; }
353 # == prototypes == do not delete this comment and do not edit anything below
354 use constant TEXT_TO_RIGHT => 0;
355 use constant TEXT_TO_LEFT => 1;
356 use constant TEXT_TO_DOWN => 2;
357 use constant TEXT_TO_UP => 3;
358 use constant TEXT_TO_ANGLE => 4;
359 use constant OP_COPY => 0;
360 use constant OP_ADD => 1;
361 use constant OP_SUBSTRACT => 2;
362 use constant OP_RESHADE => 3;
363 use constant CHANNEL_RED => 0;
364 use constant CHANNEL_GREEN => 1;
365 use constant CHANNEL_BLUE => 2;
366 use constant CHANNEL_ALPHA => 3;
367 use constant WINDOW_UNMANAGED => 0;
368 use constant WINDOW_MANAGED => 1;
369 sub time_gate { return send_command('time_gate',@_); }
370 sub help { return send_command('help',@_); }
371 sub ping { return send_command('ping',@_); }
372 sub pause { return send_command('pause',@_); }
373 sub version { return send_command('version',@_); }
374 sub get_id { return send_command('get_id',@_); }
375 sub history { return send_command('history',@_); }
376 sub set { return send_command('set',@_); }
377 sub unset_all { return send_command('unset_all',@_); }
378 sub echo { return send_command('echo',@_); }
379 sub start_recording { return send_command('start_recording',@_); }
380 sub stop_recording { return send_command('stop_recording',@_); }
381 sub play_get_abort_on_events { return send_command('play_get_abort_on_events',@_); }
382 sub play_set_abort_on_events { return send_command('play_set_abort_on_events',@_); }
383 sub play { return send_command('play',@_); }
384 sub context_get_dither { return send_command('context_get_dither',@_); }
385 sub context_get_anti_alias { return send_command('context_get_anti_alias',@_); }
386 sub context_get_blend { return send_command('context_get_blend',@_); }
387 sub context_get_operation { return send_command('context_get_operation',@_); }
388 sub context_get_cliprect { return send_command('context_get_cliprect',@_); }
389 sub context_get_image { return send_command('context_get_image',@_); }
390 sub context_get_font { return send_command('context_get_font',@_); }
391 sub context_get_color_range { return send_command('context_get_color_range',@_); }
392 sub context_get_color_modifier { return send_command('context_get_color_modifier',@_); }
393 sub context_get_filter { return send_command('context_get_filter',@_); }
394 sub context_get_color { return send_command('context_get_color',@_); }
395 sub context_get_angle { return send_command('context_get_angle',@_); }
396 sub context_get_direction { return send_command('context_get_direction',@_); }
397 sub context_set_dither { return send_command('context_set_dither',@_); }
398 sub context_set_anti_alias { return send_command('context_set_anti_alias',@_); }
399 sub context_set_blend { return send_command('context_set_blend',@_); }
400 sub context_set_operation { return send_command('context_set_operation',@_); }
401 sub context_set_cliprect { return send_command('context_set_cliprect',@_); }
402 sub context_set_image { return send_command('context_set_image',@_); }
403 sub context_set_font { return send_command('context_set_font',@_); }
404 sub context_set_color_range { return send_command('context_set_color_range',@_); }
405 sub context_set_color_modifier { return send_command('context_set_color_modifier',@_); }
406 sub context_set_filter { return send_command('context_set_filter',@_); }
407 sub context_set_color { return send_command('context_set_color',@_); }
408 sub context_set_angle { return send_command('context_set_angle',@_); }
409 sub context_set_direction { return send_command('context_set_direction',@_); }
410 sub add_color_to_color_range { return send_command('add_color_to_color_range',@_); }
411 sub blend_image_onto_image { return send_command('blend_image_onto_image',@_); }
412 sub blend_image_onto_image_at_angle { return send_command('blend_image_onto_image_at_angle',@_); }
413 sub blend_image_onto_image_skewed { return send_command('blend_image_onto_image_skewed',@_); }
414 sub apply_filter { return send_command('apply_filter',@_); }
415 sub get_text_size { return send_command('get_text_size',@_); }
416 sub get_text_advance { return send_command('get_text_advance',@_); }
417 sub text_draw { return send_command('text_draw',@_); }
418 sub modify_color_modifier_gamma { return send_command('modify_color_modifier_gamma',@_); }
419 sub modify_color_modifier_brightness { return send_command('modify_color_modifier_brightness',@_); }
420 sub modify_color_modifier_contrast { return send_command('modify_color_modifier_contrast',@_); }
421 sub get_color_modifier_tables { return send_command('get_color_modifier_tables',@_); }
422 sub set_color_modifier_tables { return send_command('set_color_modifier_tables',@_); }
423 sub get_color_modifier_value { return send_command('get_color_modifier_value',@_); }
424 sub set_color_modifier_value { return send_command('set_color_modifier_value',@_); }
425 sub apply_color_modifier { return send_command('apply_color_modifier',@_); }
426 sub apply_color_modifier_to_rectangle { return send_command('apply_color_modifier_to_rectangle',@_); }
427 sub load_image_without_cache { return send_command('load_image_without_cache',@_); }
428 sub load_image { return send_command('load_image',@_); }
429 sub save_image { return send_command('save_image',@_); }
430 sub create_image { return send_command('create_image',@_); }
431 sub create_image_using_data { return send_command('create_image_using_data',@_); }
432 sub clone_image { return send_command('clone_image',@_); }
433 sub free_image { return send_command('free_image',@_); }
434 sub load_font { return send_command('load_font',@_); }
435 sub free_font { return send_command('free_font',@_); }
436 sub list_fonts { return send_command('list_fonts',@_); }
437 sub list_font_path { return send_command('list_font_path',@_); }
438 sub add_path_to_font_path { return send_command('add_path_to_font_path',@_); }
439 sub remove_path_from_font_path { return send_command('remove_path_from_font_path',@_); }
440 sub create_color_range { return send_command('create_color_range',@_); }
441 sub free_color_range { return send_command('free_color_range',@_); }
442 sub create_filter { return send_command('create_filter',@_); }
443 sub free_filter { return send_command('free_filter',@_); }
444 sub create_color_modifier { return send_command('create_color_modifier',@_); }
445 sub free_color_modifier { return send_command('free_color_modifier',@_); }
446 sub polygon_new { return send_command('polygon_new',@_); }
447 sub polygon_free { return send_command('polygon_free',@_); }
448 sub polygon_add_point { return send_command('polygon_add_point',@_); }
449 sub images_reset_all { return send_command('images_reset_all',@_); }
450 sub images_info { return send_command('images_info',@_); }
451 sub fonts_reset_all { return send_command('fonts_reset_all',@_); }
452 sub fonts_info { return send_command('fonts_info',@_); }
453 sub color_ranges_reset_all { return send_command('color_ranges_reset_all',@_); }
454 sub color_ranges_info { return send_command('color_ranges_info',@_); }
455 sub color_modifiers_reset_all { return send_command('color_modifiers_reset_all',@_); }
456 sub color_modifiers_info { return send_command('color_modifiers_info',@_); }
457 sub filters_reset_all { return send_command('filters_reset_all',@_); }
458 sub filters_info { return send_command('filters_info',@_); }
459 sub polygons_reset_all { return send_command('polygons_reset_all',@_); }
460 sub polygons_info { return send_command('polygons_info',@_); }
461 sub image_has_alpha { return send_command('image_has_alpha',@_); }
462 sub image_get_width { return send_command('image_get_width',@_); }
463 sub image_get_height { return send_command('image_get_height',@_); }
464 sub image_get_filename { return send_command('image_get_filename',@_); }
465 sub image_get_data { return send_command('image_get_data',@_); }
466 sub image_query_pixel { return send_command('image_query_pixel',@_); }
467 sub image_set_has_alpha { return send_command('image_set_has_alpha',@_); }
468 sub image_set_changes_on_disk { return send_command('image_set_changes_on_disk',@_); }
469 sub image_set_format { return send_command('image_set_format',@_); }
470 sub image_filter_recurse { return send_command('image_filter_recurse',@_); }
471 sub image_draw_line { return send_command('image_draw_line',@_); }
472 sub image_draw_rectangle { return send_command('image_draw_rectangle',@_); }
473 sub image_fill_rectangle { return send_command('image_fill_rectangle',@_); }
474 sub image_fill_color_range_rectangle { return send_command('image_fill_color_range_rectangle',@_); }
475 sub image_draw_ellipse { return send_command('image_draw_ellipse',@_); }
476 sub image_fill_ellipse { return send_command('image_fill_ellipse',@_); }
477 sub image_copy_alpha_to_image { return send_command('image_copy_alpha_to_image',@_); }
478 sub image_copy_alpha_rectangle_to_image { return send_command('image_copy_alpha_rectangle_to_image',@_); }
479 sub image_draw_polygon { return send_command('image_draw_polygon',@_); }
480 sub image_fill_polygon { return send_command('image_fill_polygon',@_); }
481 sub image_flip_horizontal { return send_command('image_flip_horizontal',@_); }
482 sub image_flip_vertical { return send_command('image_flip_vertical',@_); }
483 sub image_flip_diagonal { return send_command('image_flip_diagonal',@_); }
484 sub image_orientate { return send_command('image_orientate',@_); }
485 sub image_blur { return send_command('image_blur',@_); }
486 sub image_sharpen { return send_command('image_sharpen',@_); }
487 sub filter_set { return send_command('filter_set',@_); }
488 sub filter_set_red { return send_command('filter_set_red',@_); }
489 sub filter_set_green { return send_command('filter_set_green',@_); }
490 sub filter_set_blue { return send_command('filter_set_blue',@_); }
491 sub filter_set_alpha { return send_command('filter_set_alpha',@_); }
492 sub filter_constants { return send_command('filter_constants',@_); }
493 sub filter_divisors { return send_command('filter_divisors',@_); }
494 sub menu_fire { return send_command('menu_fire',@_); }
495 sub menu_reset_all { return send_command('menu_reset_all',@_); }
496 sub menu_add_menu { return send_command('menu_add_menu',@_); }
497 sub menu_add_submenu { return send_command('menu_add_submenu',@_); }
498 sub menu_add_item { return send_command('menu_add_item',@_); }
499 sub menu_add_separator { return send_command('menu_add_separator',@_); }
500 sub menu_end_submenu { return send_command('menu_end_submenu',@_); }
501 sub events_info { return send_command('events_info',@_); }
502 sub events_get_echo { return send_command('events_get_echo',@_); }
503 sub events_get_send_sigusr1 { return send_command('events_get_send_sigusr1',@_); }
504 sub window_reset { return send_command('window_reset',@_); }
505 sub window_show { return send_command('window_show',@_); }
506 sub window_hide { return send_command('window_hide',@_); }
507 sub window_resize { return send_command('window_resize',@_); }
508 sub window_get_transparency { return send_command('window_get_transparency',@_); }
509 sub window_get_background_grab { return send_command('window_get_background_grab',@_); }
510 sub window_get_background_image { return send_command('window_get_background_image',@_); }
511 sub window_get_managed_status { return send_command('window_get_managed_status',@_); }
512 sub window_set_transparency { return send_command('window_set_transparency',@_); }
513 sub window_set_background_grab { return send_command('window_set_background_grab',@_); }
514 sub window_set_background_image { return send_command('window_set_background_image',@_); }
515 sub screen_get_width { return send_command('screen_get_width',@_); }
516 sub screen_get_height { return send_command('screen_get_height',@_); }
517 sub screen_get_depth { return send_command('screen_get_depth',@_); }
518 sub get_charset { return send_command('get_charset',@_); }
519 sub set_charset { return send_command('set_charset',@_); }
520 sub charset_status { return send_command('charset_status',@_); }
521 sub x_status { return send_command('x_status',@_); }
522 sub quit { return send_command('quit',@_); }