1use strict; 2use IO::Handle; 3use vars qw($VERSION %IRSSI); 4 5use Irssi; 6$VERSION = '0.3.4'; 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 => '2017-06-12' 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#-------------------------------------------------------------------- 31my %myHELP = (); 32 33#-------------------------------------------------------------------- 34# Help function 35#-------------------------------------------------------------------- 36sub cmd_help { 37 my ($about) = @_; 38 39 %myHELP = ( 40 osd_test => " 41osd_test 42 43Displays a small test message on screen 44", 45 46 osd_reload => " 47osd_reload 48 49Restarts the osd_cat program, it's especially need when 50have CHANGED settings. They DO NOT take effect UNTIL you RELOAD. 51", 52 53 osd => " 54OSD 55 56You can display on screen who is paging/msg'ing you on IRC. 57 58When you CHANGE the settings you SHOULD use /osd_reload to let these changes 59take effect. 60 61Settings: 62--------- 63 64* osd_color (default: blue) 65Currently the setting is: " . Irssi::settings_get_str('osd_color') . " 66 67It 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-\*-\*-\*-\*-\*-\*) 70Currently the setting is: " . Irssi::settings_get_str('osd_font') . " 71 72These 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 76This font is available on every linux install with the adobe fonts. 77-*-helvetica-medium-r-\*-\*-\*-320-\*-\*-\*-\*-\*-\* 78 79* osd_align (default: right) 80Currently the setting is: " . Irssi::settings_get_str('osd_align') . " 81 82left|right|center (horizontal alignment) 83 84* osd_place (default: top) 85Currently the setting is: " . Irssi::settings_get_str('osd_place') . " 86 87top|bottom|middle (vertical alginment) 88 89* osd_offset (default: 100) 90Currently the setting is: " . Irssi::settings_get_str('osd_offset') . " 91 92The vertical offset from the screen edge set in osd_place. 93 94* osd_indent (default: 100) 95Currently the setting is: " . Irssi::settings_get_str('osd_indent') . " 96 97The horizontal offset from the screen edge set in osd_align. 98 99* osd_shadow (default: 0) 100Currently the setting is: " . Irssi::settings_get_str('osd_shadow') . " 101 102Set the shadow offset, if the offset is 0, the shadow is disabled. 103 104* osd_delay (default: 4) 105Currently the setting is: " . Irssi::settings_get_str('osd_delay') . " 106 107How many seconds should the message remain on screen. 108 109* osd_age (default: 4) 110Currently the setting is: " . Irssi::settings_get_str('osd_age') . " 111 112Time in seconds before old scroll lines are discarded. 113 114* osd_lines (default: 5) 115Currently the setting is: " . Irssi::settings_get_str('osd_lines') . " 116 117Number of lines to display on screen at one time. 118 119* osd_DISPLAY (default: :0.0) 120Currently the setting is: " . Irssi::settings_get_str('osd_DISPLAY') . " 121 122On what \$DISPLAY should the osd connect. (this makes tunneling possible) 123 124* osd_showactivechannel (default: yes) 125Currently the setting is: " . Irssi::settings_get_str('osd_showactivechannel') . " 126 127When set to yes, OSD will be triggered even if the channel is the active channel. 128When set to yes, OSD will be triggered if you send a message from your own nick. 129 130You can test the OSD settings with the 'osd_test' command! 131he '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 145Irssi::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. 151Irssi::settings_add_str('OSD', 'osd_font', "-*-helvetica-medium-r-\*-\*-\*-320-\*-\*-\*-\*-\*-\*"); 152 153Irssi::settings_add_str('OSD', 'osd_age', "4"); 154Irssi::settings_add_str('OSD', 'osd_align', "right"); 155Irssi::settings_add_str('OSD', 'osd_delay', "4"); 156Irssi::settings_add_str('OSD', 'osd_indent', "100"); 157Irssi::settings_add_str('OSD', 'osd_lines', "5"); 158Irssi::settings_add_str('OSD', 'osd_offset', "100"); 159Irssi::settings_add_str('OSD', 'osd_place', "top"); 160Irssi::settings_add_str('OSD', 'osd_shadow', "0"); 161Irssi::settings_add_str('OSD', 'osd_DISPLAY', ":0.0"); 162Irssi::settings_add_str('OSD', 'osd_showactivechannel', "yes"); 163 164#-------------------------------------------------------------------- 165# initialize the pipe, test it. 166#-------------------------------------------------------------------- 167 168sub init { 169 pipe_open(); 170 osdprint("OSD Loaded."); 171} 172 173#-------------------------------------------------------------------- 174# open the OSD pipe 175#-------------------------------------------------------------------- 176 177sub 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 = 205 "env DISPLAY=".Irssi::settings_get_str('osd_display') . 206 " osd_cat $place " . 207 " --color=".Irssi::settings_get_str('osd_color'). 208 " --delay=".Irssi::settings_get_str('osd_delay'). 209 " --age=".Irssi::settings_get_str('osd_age'). 210 " --font=".quotemeta(Irssi::settings_get_str('osd_font')). 211 " --offset=".Irssi::settings_get_str('osd_offset'). 212 " --shadow=".Irssi::settings_get_str('osd_shadow'). 213 " --lines=".Irssi::settings_get_str('osd_lines'). 214 " --align=".Irssi::settings_get_str('osd_align'); 215 216 if ( $version =~ /^2.*/ ) { 217 $command .= " --indent=".Irssi::settings_get_str('osd_indent'); 218 } 219 open( OSDPIPE, "|-", $command ) 220 or print "The OSD program can't be started, check if you have osd_cat installed AND in your path."; 221 OSDPIPE->autoflush(1); 222} 223 224#-------------------------------------------------------------------- 225# Private message parsing 226#-------------------------------------------------------------------- 227 228sub priv_msg { 229 my ($server,$msg,$nick,$address,$target) = @_; 230 if ((Irssi::settings_get_str('osd_showactivechannel') =~ /yes/) or 231 not (Irssi::active_win()->get_active_name() eq "$nick") ) { 232 osdprint($server->{chatnet}.":$nick"); 233 } 234} 235 236#-------------------------------------------------------------------- 237# Public message parsing 238#-------------------------------------------------------------------- 239 240sub pub_msg { 241 my ($server,$msg,$nick,$address, $channel) = @_; 242 my $show; 243 244 if (Irssi::settings_get_str('osd_showactivechannel') =~ /yes/) { 245 $show = 1; 246 } elsif(uc(Irssi::active_win()->get_active_name()) eq uc($channel)) { 247 $show = 0; 248 } 249 250 if ($show) { 251 my $onick= quotemeta "$server->{nick}"; 252 my $pat ='(\:|\,|\s)'; # option... 253 if($msg =~ /^$onick\s*$pat/i){ 254 osdprint("$channel".":$nick"); 255 } 256 } 257} 258 259#-------------------------------------------------------------------- 260# The actual printing 261#-------------------------------------------------------------------- 262 263sub osdprint { 264 my ($text) = @_; 265 if (not (OSDPIPE->opened())) {pipe_open();} 266 print OSDPIPE "$text\n"; 267 OSDPIPE->flush(); 268} 269 270#-------------------------------------------------------------------- 271# A test command. 272#-------------------------------------------------------------------- 273 274sub cmd_osd_test { 275 osdprint("Testing OSD"); 276} 277 278#-------------------------------------------------------------------- 279# A command to close and reopen OSDPIPE 280# so options take effect without needing to unload/reload the script 281#-------------------------------------------------------------------- 282 283sub cmd_osd_reload { 284 close(OSDPIPE); 285 pipe_open(); 286 osdprint("Reloaded OSD"); 287} 288 289#-------------------------------------------------------------------- 290# Irssi::signal_add_last / Irssi::command_bind 291#-------------------------------------------------------------------- 292 293Irssi::signal_add_last("message public", "pub_msg"); 294Irssi::signal_add_last("message private", "priv_msg"); 295 296Irssi::command_bind("osd_reload","cmd_osd_reload", "OSD"); 297Irssi::command_bind("osd_test","cmd_osd_test", "OSD"); 298Irssi::command_bind("help","cmd_help", "Irssi commands"); 299 300#-------------------------------------------------------------------- 301# The command that's executed at load time. 302#-------------------------------------------------------------------- 303 304init(); 305 306#-------------------------------------------------------------------- 307# This text is printed at Load time. 308#-------------------------------------------------------------------- 309 310Irssi::print("Use /help osd for more information."); 311 312 313#- end 314