aboutsummaryrefslogtreecommitdiff
path: root/bin/arctica-mediaplayer-overlay
blob: 7e8266b2d044010d7ae7470732ceede960708939 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl -X -T -I /tekitest/perlmodules
use strict;
use Data::Dumper;
use Arctica::Core::eventInit qw(genARandom BugOUT);
use Arctica::Core::JABus::Socket;
use POSIX qw(mkfifo);
use Gtk3 -init;
use Glib;
use Glib::Object::Introspection;
Glib::Object::Introspection->setup(
	basename => "GdkX11",
	version => "3.0",
	package => "Gtk3::Gdk");

my $MPVO = "x11";
#my $MPVO = "gl";

my $gnx_xid = `/usr/bin/xwininfo -root -all|/bin/grep NXAgent`;
if ($gnx_xid =~ /^\s*(0x[0-9a-f]*)\s.*/) {
        $gnx_xid = $1;
} else {
        die;
}


my $lastcontact = time;

my $ACO = Arctica::Core::eventInit->new({
	app_name=>'forked-overlay-test',
	app_class =>'amoduletester',
	app_version=>'0.0.1.1'});

my $app_id = @ARGV[0];
my $ttid = @ARGV[1];
my $sock_id;
my $tmplnkid;

if (@ARGV[2] =~ /^([a-zA-Z0-9]*)$/) {
	$sock_id = $1;
	BugOUT(8,"SOC:\t$sock_id");
} else {die("YOU SOCK!");}

if (@ARGV[3] =~ /^([a-zA-Z0-9]*)$/) {
        $tmplnkid = $1;
        BugOUT(8,"TMPLNKID:\t$tmplnkid");
} else {die("YOU SOCK!");}
print "YAY WE GOT IT: $tmplnkid\n";

my $TeKi;
my $window = Gtk3::Window->new('popup');
$TeKi = Arctica::Core::JABus::Socket->new($ACO,{
	type	=>	"unix",
	destination =>	"local", # FIX ME (change to remote!!!)
	is_client => 1,
	connect_to => $sock_id,
	handle_in_dispatch => {
			chtstate => sub {\&chtargetstate(@_)},
#			srvcneg => sub {$TeKiClient->c2s_service_neg(@_)},
#			appctrl => \&teki_client2s_appctrl,
	},
	hooks => {
		on_ready => sub {my_ready($app_id,$ttid);},
		on_client_errhup => sub {die("\tLOST CONN!\n");},
	},
});

print "THEDUMP:\t\n",Dumper($TeKi);

my $timeout = Glib::Timeout->add(1000, sub {
print "\tTime:\t",time,"\n\tLast:\t$lastcontact\n";
	if ($lastcontact < (time-60)) {
		die("We're an orphan?");
	}
	return 1;
});

	

$window->set_title('OVERLAY');
$window->set_border_width(0);
$window->resize(600,300);
my $socket = new Gtk3::Socket;
$window->add($socket);
my $xid = $socket->get_id;
my $xid2 = $window->get_window->get_xid;
warn("WINXID:\t$xid2");
system("/usr/bin/xdotool","windowreparent",$xid2,$gnx_xid);
$window->show_all();
$window->unmap();
my $time = time();
my $SlaveFIFO = "/tmp/mpslave_$time.fifo";
if (-e $SlaveFIFO) {
	unlink($SlaveFIFO);
}
mkfifo($SlaveFIFO, 0700);
my  $pid =    open(my $mpFH,"-|",'/usr/bin/mplayer','-slave','-input' ,"file=$SlaveFIFO", '-vo',$MPVO,'-zoom','-framedrop','-fs','-wid',$xid,'-volume','100', '-identify','-idle','-nolirc','-ss','1', "http://username:password\@localhost:9199/thedir/$tmplnkid.lnk","2>&1");
my $TnW = Glib::IO->add_watch( $mpFH->fileno, 'in', sub {watch_mplayerOutput( $mpFH);});
#print "MP:$pid\n";
$ACO->{'Glib'}{'MainLoop'}->run;

sub watch_mplayerOutput {
	my ($fh,undef) = @_;
	my $buffer;
	sysread($fh, $buffer, 4096);
	print "YALLA:\t$buffer\n";
}

sub chtargetstate {
	my $data = $_[0];
	warn(Dumper($data));
	my $x = $data->{'apx'};
	my $y = $data->{'apy'};
	if ($x and $y) {
		$window->move($x,$y);
		$window->resize($data->{'w'},$data->{'h'});
	}
	
	if ($data->{'visible'} eq 1) {
		if ($x ne 0) {#remove this
			$window->map();
		}
	} else {
		$window->unmap();
	}
}

sub my_ready {
	BugOUT(8,"MY READY?");
	my $app_id = $_[0];
	my $ttid = $_[1];
	$TeKi->client_send('treg',{
				app_id => $app_id,
				ttid => $ttid,
	});
}

sub daemonize {
	fork and exit;
	POSIX::setsid();
	fork and exit;
	umask 0;
	chdir '/';
	close STDIN;
	close STDOUT;
	close STDERR;
}