-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi Marc,
thanks for all your great help and especially the pointer to AnyEvent::DBus. I've attached a working version of my plugin which is now thread free and really simple. There is one more issue though. After closing the terminal (by pressing C-d or typing exit/logout) the process will keep running. The terminal window vanishes but the process is still alive. I think that the AnyEvent Loop does not get shut down. I've played a bit and found out that this is not a problem with DBus or AnyEvent::DBus since this problem occurs also if i attach just a simple AnyEvent->signal() handler. I tried killing '$$' as a naive approach but this isn't to good for urxvtd. :) Any hints on that? Best Regards, Jochen On 31.08.2010 16:52, Marc Lehmann wrote: > On Tue, Aug 31, 2010 at 03:27:03PM +0200, Jochen Keil <[email protected]> wrote: >> Cmd_parse("\033[?5h") respectively cmd_parse("\033[?5l") do the >> trick for me. However i'm having a problem with $self->refresh(). >> It doesn't happen instantly. The terminal only gets refreshed if I >> hit a key (it is not necessary that the terminal is focused >> though). > > That's one of the problems you run into threads with. While you > might be able to hack around it, your plug-in is already prone to > crash as it is due to race conditions. > >> The plugin works so far (for me), but I don't know how it would >> behave without threads. > > It's broken with or without the windows process emulation > ("threads"). > >> Writing it without threads would be tedious though since I'd have >> to use pipes (would a pipe in /tmp be portable anyway?). > > I don't see why you would need to use a pipe - there are many > exmaples of using Net::DBus without any pipes. > > For example AnyEvent::DBus let's you integrate dbus into urxvt, but > you could also register your own I/O watcher for dbus (note that > Net::DBus uses libdbus, which can freeze urxvt for long amounts of > time). > >> hacker (honestly these are my first steps with perl..) but I have >> enough experience with other languages (e.g. tcl which is quite >> comparable). > > libdbus makes itself hard to use, unfortunately... > >>> windows process emulation code, so you have to fix the race >>> conditions that ensue somehow (e.g. by not calling urxvt >>> functions from any other "thread" than the urxvt one). >> My plugin now isn't dependant on locks anymore.. yet there is >> still the problem with refreshing. I could set a 1s timer but I'm >> not to fond of polling. > > *any* modification of global data you do from another thread (the > process emulation uses C-level-threads to emulate processes, hence > the name) is prone to crashes, unless you lock (which you can't, as > urxvt itself would have to look everywhere and everytime, which it > doesn't of course). > > you might get away with it because the chances are low, but calling > methods and adding timers etc. will sooner or later crash for > program. > - -- ? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAkyADSMACgkQtVwvsA+W4CCwTwCbBItyXjsKb7G1WG69tq0LkB9E dMUAoJHIMcIYvL0pszSaUsFsznX4o8b+ =2qTt -----END PGP SIGNATURE-----
#! perl
use AnyEvent;
use AnyEvent::DBus;
sub on_start {
my ($self) = @_;
my $bus = Net::DBus->session();
my $upower = $bus->get_service('org.gnome.PowerManager');
my $object = $upower->get_object(
'/org/gnome/PowerManager/Backlight',
'org.gnome.PowerManager.Backlight');
$object->connect_to_signal('BrightnessChanged', sub {
if ((shift) < 80) {
$self->cmd_parse("\033[?5h");
$self->want_refresh();
} else {
$self->cmd_parse("\033[?5l");
$self->want_refresh();
}
});
()
}
rvid-on-brightnesschange.sig
Description: PGP signature
_______________________________________________ rxvt-unicode mailing list [email protected] http://lists.schmorp.de/cgi-bin/mailman/listinfo/rxvt-unicode
