1414 */
1515
1616public class WLProxy {
17+ public static boolean debug = false ;
18+
1719 private String real_socket_addr ;
1820 private UnixSocket real_socket ; //wayland-0
1921 private String proxy_socket_addr ;
2022 private UnixSocket proxy_socket ; //wayland-99
2123 private boolean active ;
2224 private Server server ;
2325
26+ private static int log = 99 ;
27+
2428 public boolean start (String real_wayland_display ) {
29+ if (debug ) {
30+ JFLog .init (log , System .getenv ("HOME" ) + "/wlproxy.log" , true );
31+ }
2532 String real_path = System .getenv ("XDG_RUNTIME_DIR" );
2633 if (real_path == null || real_wayland_display == null ) {
27- JFLog .log ("WLProxy:socket not found" );
34+ JFLog .log (log , "WLProxy:socket not found" );
2835 return false ;
2936 }
3037 if (!real_path .endsWith ("/" )) {
3138 real_path += "/" ;
3239 }
3340 String temp_path = real_path + "wayland-90" ;
3441 real_path += real_wayland_display ;
35- JFLog .log ("WLProxy:server.socket=" + real_path );
42+ JFLog .log (log , "WLProxy:server.socket=" + real_path );
3643
3744 try {
3845 real_socket_addr = real_path ;
@@ -41,7 +48,7 @@ public boolean start(String real_wayland_display) {
4148 real_socket .bind (temp_path ); //maybe not be necessary
4249 if (!real_socket .connect (real_path )) throw new Exception ("Unable to connect to real wayland socket" );
4350 } catch (Exception e ) {
44- JFLog .log (e );
51+ JFLog .log (log , e );
4552 if (real_socket != null ) {
4653 try {real_socket .close ();} catch (Exception e2 ) {}
4754 }
@@ -52,14 +59,14 @@ public boolean start(String real_wayland_display) {
5259 String proxy_path = System .getenv ("XDG_RUNTIME_DIR" );
5360 String proxy_wayland_display = "wayland-99" ;
5461 if (proxy_path == null || proxy_wayland_display == null ) {
55- JFLog .log ("WLProxy:socket not found" );
62+ JFLog .log (log , "WLProxy:socket not found" );
5663 return false ;
5764 }
5865 if (!proxy_path .endsWith ("/" )) {
5966 proxy_path += "/" ;
6067 }
6168 proxy_path += proxy_wayland_display ;
62- JFLog .log ("WLProxy:proxy.socket=" + proxy_path );
69+ JFLog .log (log , "WLProxy:proxy.socket=" + proxy_path );
6370
6471 try {
6572 proxy_socket_addr = proxy_path ;
@@ -68,7 +75,7 @@ public boolean start(String real_wayland_display) {
6875 if (!proxy_socket .bind (proxy_path )) throw new Exception ("Unable to bind to socket:" + proxy_path );
6976 if (!proxy_socket .listen ()) throw new Exception ("Unable to listen on unix socket" );
7077 } catch (Exception e ) {
71- JFLog .log (e );
78+ JFLog .log (log , e );
7279 if (proxy_socket != null ) {
7380 try {proxy_socket .close ();} catch (Exception e2 ) {}
7481 }
@@ -121,7 +128,7 @@ public void run() {
121128 session .proxy_client .start ();
122129 sessions .add (session );
123130 } catch (Exception e ) {
124- JFLog .log (e );
131+ JFLog .log (log , e );
125132 }
126133 }
127134 }
@@ -146,16 +153,22 @@ public void run() {
146153 data_len [0 ] = data .length ;
147154 fds_len [0 ] = fds .length ;
148155 src .read (data_len , data , fds_len , fds );
156+ if (debug ) {
157+ JFLog .log ((monitor ? ">" : "<" ) + ": read:" + data_len [0 ] + "," + fds_len [0 ]);
158+ }
149159 if (monitor ) {
150160 //TODO
151161 }
152162 dst .write (data_len , data , fds_len , fds );
163+ if (debug ) {
164+ JFLog .log ((monitor ? ">" : "<" ) + ":write:" + data_len [0 ] + "," + fds_len [0 ]);
165+ }
153166 if (fds_len [0 ] > 0 ) {
154167 //close fds received after they have been transferred
155168 src .close (fds_len [0 ], fds );
156169 }
157170 } catch (Exception e ) {
158- JFLog .log (e );
171+ JFLog .log (log , e );
159172 return ;
160173 }
161174 }
0 commit comments