aboutsummaryrefslogtreecommitdiff
path: root/bin/arctica-browser-overlay
blob: 038ed920d5ceef197f60e145ba0ac49a85479312 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/perl -X -T

################################################################################
#          _____ _
#         |_   _| |_  ___
#           | | | ' \/ -_)
#           |_| |_||_\___|
#                   _   _             ____            _           _
#    / \   _ __ ___| |_(_) ___ __ _  |  _ \ _ __ ___ (_) ___  ___| |_
#   / _ \ | '__/ __| __| |/ __/ _` | | |_) | '__/ _ \| |/ _ \/ __| __|
#  / ___ \| | | (__| |_| | (_| (_| | |  __/| | | (_) | |  __/ (__| |_
# /_/   \_\_|  \___|\__|_|\___\__,_| |_|   |_|  \___// |\___|\___|\__|
#                                                  |__/
#          The Arctica Modular Remote Computing Framework
#
################################################################################
#
# Copyright (C) 2015-2016 The Arctica Project
# http://http://arctica-project.org/
#
# This code is dual licensed: strictly GPL-2 or AGPL-3+
#
# GPL-2
# -----
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
#
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
# AGPL-3+
# -------
# This programm is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This programm is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Copyright (C) 2015-2016 Guangzhou Nianguan Electronics Technology Co.Ltd.
#                         <opensource@gznianguan.com>
# Copyright (C) 2015-2016 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
#
################################################################################

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;
use Glib qw(TRUE FALSE);

use Arctica::Browser::ToolBar;
use Arctica::Browser::WebView;
use Arctica::Browser::Proxy;

Glib::Object::Introspection->setup(
	basename => "GdkX11",
	version => "3.0",
	package => "Gtk3::Gdk");

my $proxy = Arctica::Browser::Proxy->new;

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 + 5);

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;

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




my $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");},
	},
});

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


my $window = Gtk3::Window->new('popup');
$window->set_default_size(80, 60);
$window->set_title('Browser');
$window->signal_connect(destroy => sub { Gtk3->main_quit() });

my $toolbar = Arctica::Browser::ToolBar->new;
my $webview = Arctica::Browser::WebView->new($toolbar);

my $vbox = Gtk3::Box->new( 'vertical', 0);
$vbox->set_border_width(0);
$vbox->pack_start($toolbar->return_toolbar,FALSE,FALSE,0);
$vbox->pack_start($webview->return_webview,TRUE,TRUE,0);
$window->add($vbox);

$window->show_all();
$window->unmap();

system("/usr/bin/xdotool","windowreparent",$window->get_window->get_xid,$gnx_xid);


$ACO->{'Glib'}{'MainLoop'}->run;


sub chtargetstate {
	my $data = $_[0];
	$lastcontact = time();
	warn(Dumper($data));
	my $x = $data->{'apx'};
	my $y = $data->{'apy'};
#warn("CH:\t$x,$y\t$data->{'w'} * $data->{'h'}	[$data->{'alive'}]");

	if ($data->{'w'} and $data->{'h'}) {
		$window->resize($data->{'w'},$data->{'h'});

	}

	if ((defined $x) and (defined $y)) {
		$window->move($x,$y);
	}


	if ($data->{'visible'} eq 1) {
			$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;
}