html/osd.pl


   1 use strict;
   2 use IO::Handle;
   3 use vars qw($VERSION %IRSSI);
   4 
   5 use Irssi;
   6 $VERSION = '0.3.3';
   7 %IRSSI = (
   8 	authors     => 'Jeroen Coekaerts, Koenraad Heijlen',
   9 	contact     => 'vipie@ulyssis.org, jeroen@coekaerts.be',
  10 	name        => 'osd',
  11 	description => 'An OnScreenDisplay (osd) it show\'s who is talking to you, on what IRC Network.',
  12 	license     => 'BSD',
  13 	url         => 'http://vipie.studentenweb.org/dev/irssi/',
  14 	changed     => '2004-01-09'
  15 );
  16 
  17 #--------------------------------------------------------------------
  18 # Changelog
  19 # 2004-01-09 
  20 #  - fix a typo in the help (M.G.Kishalmi)
  21 # TODO :
  22 #
  23 # * a setting that let's you display the text? (exploits?!)
  24 #
  25 #--------------------------------------------------------------------
  26 
  27 
  28 #--------------------------------------------------------------------
  29 # Public Variables
  30 #--------------------------------------------------------------------
  31 my %myHELP = ();
  32 
  33 #--------------------------------------------------------------------
  34 # Help function
  35 #--------------------------------------------------------------------
  36 sub cmd_help { 
  37 	my ($about) = @_;
  38 
  39 	%myHELP = (
  40 		osd_test => "
  41 osd_test
  42 
  43 Displays a small test message on screen
  44 ",
  45 
  46 		osd_reload => "
  47 osd_reload
  48 
  49 Restarts the osd_cat program, it's especially need when
  50 have CHANGED settings. They DO NOT take effect UNTIL you RELOAD.
  51 ",
  52 
  53 		osd => "
  54 OSD 
  55 
  56 You can display on screen who is paging/msg'ing you on IRC.
  57 
  58 When you CHANGE the settings you SHOULD use /osd_reload to let these changes
  59 take effect.
  60 
  61 Settings:
  62 ---------
  63 
  64 * osd_color  	(default: blue)
  65 Currently the setting is: " . Irssi::settings_get_str('osd_color') . "
  66 
  67 It should be a valid X color, the list in normally located in /etc/X11/rgb.txt.
  68 
  69 * osd_font  	(default: -*-helvetica-medium-r-\*-\*-\*-320-\*-\*-\*-\*-\*-\*)
  70 Currently the setting is: " . Irssi::settings_get_str('osd_font') . "
  71 
  72 These fonts are available when you installed the microsoft font pack :-)
  73 -microsoft-tahoma-bold-r-normal-*-\*-320-\*-\*-p-\*-\*-\*
  74 -microsoft-verdana-bold-r-normal-\*-\*-320-\*-\*-p-\*-\*-\*
  75 
  76 This font is available on every linux install with the adobe fonts. 
  77 -*-helvetica-medium-r-\*-\*-\*-320-\*-\*-\*-\*-\*-\*
  78 
  79 *  osd_align	(default: right)
  80 Currently the setting is: " . Irssi::settings_get_str('osd_align') . "
  81 
  82 left|right|center (horizontal alignment)
  83 
  84 * osd_place	(default: top)
  85 Currently the setting is: " . Irssi::settings_get_str('osd_place') . "
  86 
  87 top|bottom|middle (vertical alginment)
  88 
  89 * osd_offset	(default: 100)
  90 Currently the setting is: " . Irssi::settings_get_str('osd_offset') . "
  91 
  92 The vertical offset from the screen edge set in osd_place.
  93 
  94 * osd_indent	(default: 100)
  95 Currently the setting is: " . Irssi::settings_get_str('osd_indent') . "
  96 
  97 The horizontal offset from the screen edge set in osd_align.
  98 
  99 * osd_shadow	(default: 0)
 100 Currently the setting is: " . Irssi::settings_get_str('osd_shadow') . "
 101 
 102 Set the shadow offset, if the offset is 0, the shadow is disabled.
 103 
 104 * osd_delay	(default: 4)
 105 Currently the setting is: " . Irssi::settings_get_str('osd_delay') . "
 106 
 107 How many seconds should the message remain on screen.
 108 
 109 * osd_age	(default: 4)
 110 Currently the setting is: " . Irssi::settings_get_str('osd_age') . "
 111 
 112 Time in seconds before old scroll lines are discarded.
 113 
 114 * osd_lines	(default: 5)
 115 Currently the setting is: " . Irssi::settings_get_str('osd_lines') . "
 116 
 117 Number of lines to display on screen at one time.
 118 
 119 * osd_DISPLAY	(default: :0.0)
 120 Currently the setting is: " . Irssi::settings_get_str('osd_DISPLAY') . "
 121 
 122 On what \$DISPLAY should the osd connect. (this makes tunneling possible)
 123 
 124 * osd_showactivechannel	(default: yes)
 125 Currently the setting is: " . Irssi::settings_get_str('osd_showactivechannel') . "
 126 
 127 When set to yes, OSD will be triggered even if the channel is the active channel.
 128 When set to yes, OSD will be triggered if you send a message from your own nick.
 129 
 130 You can test the OSD settings with the 'osd_test' command!
 131 he 'osd_test' to test them.
 132 
 133 ",
 134 );
 135 
 136 	if ( $about =~ /(osd_reload|osd_test|osd)/i ) { 
 137 		Irssi::print($myHELP{lc($1)});
 138 	} 
 139 }
 140 
 141 #--------------------------------------------------------------------
 142 # Irssi::Settings
 143 #--------------------------------------------------------------------
 144 
 145 Irssi::settings_add_str('OSD', 'osd_color', "blue");
 146 
 147 #These fonts are available when you installed the microsoft font pack :-)
 148 #Irssi::settings_add_str('OSD', 'osd_font', "-microsoft-tahoma-bold-r-normal-\*-\*-320-\*-\*-p-\*-\*-\*");
 149 #Irssi::settings_add_str('OSD', 'osd_font', "-microsoft-verdana-bold-r-normal-\*-\*-320-\*-\*-p-\*-\*-\*");
 150 #This font is available on every linux install with the adobe fonts. 
 151 Irssi::settings_add_str('OSD', 'osd_font', "-*-helvetica-medium-r-\*-\*-\*-320-\*-\*-\*-\*-\*-\*");
 152 
 153 Irssi::settings_add_str('OSD', 'osd_age', "4");
 154 Irssi::settings_add_str('OSD', 'osd_align', "right");
 155 Irssi::settings_add_str('OSD', 'osd_delay', "4");
 156 Irssi::settings_add_str('OSD', 'osd_indent', "100");
 157 Irssi::settings_add_str('OSD', 'osd_lines', "5");
 158 Irssi::settings_add_str('OSD', 'osd_offset', "100");
 159 Irssi::settings_add_str('OSD', 'osd_place', "top");
 160 Irssi::settings_add_str('OSD', 'osd_shadow', "0");
 161 Irssi::settings_add_str('OSD', 'osd_DISPLAY', ":0.0");
 162 Irssi::settings_add_str('OSD', 'osd_showactivechannel', "yes");
 163 
 164 #--------------------------------------------------------------------
 165 # initialize the pipe, test it.
 166 #--------------------------------------------------------------------
 167 
 168 sub init {
 169 	pipe_open();
 170 	osdprint("OSD Loaded.");
 171 }
 172 
 173 #--------------------------------------------------------------------
 174 # open the OSD pipe
 175 #--------------------------------------------------------------------
 176 
 177 sub pipe_open {
 178 	my $place;		
 179 	my $version;
 180 	my $command;
 181 
 182 	$version = `osd_cat -h 2>&1` or die("The OSD program can't be started, check if you have osd_cat installed AND in your path.");
 183 	$version =~ /Version:\s*(.*)\s*/;
 184 	$version = $1;
 185 	#Irssi::print "Version: $version";
 186 
 187 	if ( $version =~ /^2.*/ ) { 
 188 		# the --pos argument seems to be broken on 2.0.X
 189 		if ( Irssi::settings_get_str('osd_place') eq "top" ) { 
 190 			$place = "-p top"; 
 191 		} elsif ( Irssi::settings_get_str('osd_place') eq "bottom") { 
 192 			$place = "-p bottom"; 
 193 		} else { 
 194 			$place = "-p middle"; 
 195 		}
 196 	} else {
 197 		if ( Irssi::settings_get_str('osd_place') eq "top" ) { 
 198 			$place = "--top"; 
 199 		} else { 
 200 			$place = "--bottom"; 
 201 		}
 202 	}
 203 	
 204 	$command = "|DISPLAY=".Irssi::settings_get_str('osd_display') .
 205 		" osd_cat $place " .
 206 		" --color=".Irssi::settings_get_str('osd_color').
 207 		" --delay=".Irssi::settings_get_str('osd_delay').
 208 		" --age=".Irssi::settings_get_str('osd_age').
 209 		" --font=".quotemeta(Irssi::settings_get_str('osd_font')).
 210 		" --offset=".Irssi::settings_get_str('osd_offset').
 211 		" --shadow=".Irssi::settings_get_str('osd_shadow'). 
 212 		" --lines=".Irssi::settings_get_str('osd_lines').
 213 		" --align=".Irssi::settings_get_str('osd_align');
 214 
 215 	if ( $version =~ /^2.*/ ) {
 216 		$command .= " --indent=".Irssi::settings_get_str('osd_indent');
 217 	}
 218 	open( OSDPIPE, $command ) 
 219 		or print "The OSD program can't be started, check if you have osd_cat installed AND in your path.";
 220 	OSDPIPE->autoflush(1);
 221 }
 222 
 223 #--------------------------------------------------------------------
 224 # Private message parsing
 225 #--------------------------------------------------------------------
 226 
 227 sub priv_msg {
 228 	my ($server,$msg,$nick,$address,$target) = @_;
 229 	if ((Irssi::settings_get_str('osd_showactivechannel') =~ /yes/) or
 230 	   not (Irssi::active_win()->get_active_name() eq "$nick") ) {
 231 			osdprint($server->{chatnet}.":$nick");
 232 	}
 233 }
 234 
 235 #--------------------------------------------------------------------
 236 # Public message parsing
 237 #--------------------------------------------------------------------
 238 
 239 sub pub_msg {
 240 	my ($server,$msg,$nick,$address, $channel) = @_;
 241 	my $show;
 242 
 243 	if (Irssi::settings_get_str('osd_showactivechannel') =~ /yes/) {
 244 		$show = 1;
 245 	} elsif(uc(Irssi::active_win()->get_active_name()) eq uc($channel)) {
 246 		$show = 0;
 247 	}
 248 
 249 	if ($show) {
 250 		my $onick= quotemeta "$server->{nick}";
 251 		my $pat ='(\:|\,|\s)'; # option...
 252 		if($msg =~ /^$onick\s*$pat/i){
 253 			osdprint("$channel".":$nick");
 254 		}
 255 	}
 256 }
 257 
 258 #--------------------------------------------------------------------
 259 # The actual printing
 260 #--------------------------------------------------------------------
 261 
 262 sub osdprint {
 263 	my ($text) = @_;
 264 	if (not (OSDPIPE->opened())) {pipe_open();}
 265 	print OSDPIPE "$text\n";
 266 	OSDPIPE->flush();
 267 }
 268 
 269 #--------------------------------------------------------------------
 270 # A test command.
 271 #--------------------------------------------------------------------
 272 
 273 sub cmd_osd_test {
 274 	osdprint("Testing OSD");
 275 }
 276 
 277 #--------------------------------------------------------------------
 278 # A command to close and reopen OSDPIPE
 279 #  so options take effect without needing to unload/reload the script
 280 #--------------------------------------------------------------------
 281 
 282 sub cmd_osd_reload {
 283 	close(OSDPIPE);
 284 	pipe_open();
 285 	osdprint("Reloaded OSD");
 286 }
 287 
 288 #--------------------------------------------------------------------
 289 # Irssi::signal_add_last / Irssi::command_bind
 290 #--------------------------------------------------------------------
 291 
 292 Irssi::signal_add_last("message public", "pub_msg");
 293 Irssi::signal_add_last("message private", "priv_msg");
 294 
 295 Irssi::command_bind("osd_reload","cmd_osd_reload", "OSD");
 296 Irssi::command_bind("osd_test","cmd_osd_test", "OSD");
 297 Irssi::command_bind("help","cmd_help", "Irssi commands");
 298 
 299 #--------------------------------------------------------------------
 300 # The command that's executed at load time.
 301 #--------------------------------------------------------------------
 302 
 303 init();
 304 
 305 #--------------------------------------------------------------------
 306 # This text is printed at Load time.
 307 #--------------------------------------------------------------------
 308 
 309 Irssi::print("Use /help osd for more information."); 
 310 
 311 
 312 #- end