2323#include <poll.h>
2424#include <unistd.h>
2525#include <string/stdstring.h>
26+ #include <dlfcn.h>
2627
2728#include "wayland_common.h"
2829#include "wayland_common_webos.h"
3435#include "../input_keymaps.h"
3536
3637#include "../../gfx/common/wayland/webos-shell.h"
38+
39+ #ifdef HAVE_WEBOS_EXTRA_PROTOS
3740#include "../../gfx/common/wayland/webos-foreign.h"
3841#include "../../gfx/common/wayland/webos-surface-group.h"
3942#include "../../gfx/common/wayland/webos-input-manager.h"
43+ #endif
4044
4145#ifdef HAVE_USERLAND
4246#include <webos-helpers/libhelpers.h>
@@ -88,7 +92,7 @@ bool LunaRequest(const char *uri,
8892#ifdef HAVE_USERLAND
8993static bool registerAppCallback (LSHandle * sh , LSMessage * msg , void * context )
9094{
91- RARCH_DBG ("[LunaRequest] registerAppCallback returned.\n" );
95+ RARCH_LOG ("[LunaRequest] registerAppCallback returned.\n" );
9296 return true;
9397}
9498
@@ -217,7 +221,7 @@ static void wl_registry_handle_global_webos(void *data,
217221{
218222 gfx_ctx_wayland_data_t * wl = (gfx_ctx_wayland_data_t * )data ;
219223
220- RARCH_DBG ("[Wayland/webOS] Registry: %s (id=%u, version=%u)\n" ,
224+ RARCH_LOG ("[Wayland/webOS] Registry: %s (id=%u, version=%u)\n" ,
221225 interface , id , version );
222226
223227 if (string_is_equal (interface , "wl_compositor" ))
@@ -260,6 +264,7 @@ static void wl_registry_handle_global_webos(void *data,
260264 wl -> webos_shell = (struct wl_webos_shell * )wl_registry_bind (reg ,
261265 id , & wl_webos_shell_interface , 1 );
262266 }
267+ #ifdef HAVE_WEBOS_EXTRA_PROTOS
263268 else if (string_is_equal (interface , "wl_webos_foreign "))
264269 {
265270 wl -> webos_foreign = (struct wl_webos_foreign * )wl_registry_bind (reg ,
@@ -276,6 +281,7 @@ static void wl_registry_handle_global_webos(void *data,
276281 wl -> webos_input_manager = (struct wl_webos_input_manager * )wl_registry_bind (reg ,
277282 id , & wl_webos_input_manager_interface , 1 );
278283 }
284+ #endif
279285}
280286
281287static void wl_registry_handle_global_remove_webos (void * data ,
@@ -385,12 +391,14 @@ void gfx_ctx_wl_destroy_resources_webos(gfx_ctx_wayland_data_t *wl)
385391 if (wl -> surface )
386392 wl_surface_destroy (wl -> surface );
387393
394+ #ifdef HAVE_WEBOS_EXTRA_PROTOS
388395 if (wl -> webos_input_manager )
389396 wl_webos_input_manager_destroy (wl -> webos_input_manager );
390397 if (wl -> webos_surface_group_compositor )
391398 wl_webos_surface_group_compositor_destroy (wl -> webos_surface_group_compositor );
392399 if (wl -> webos_foreign )
393400 wl_webos_foreign_destroy (wl -> webos_foreign );
401+ #endif
394402 if (wl -> seat )
395403 wl_seat_destroy (wl -> seat );
396404 if (wl -> webos_shell )
@@ -674,7 +682,7 @@ static bool screenSaverCallback(LSHandle* sh, LSMessage* reply, void* context)
674682 ? (const char * )((HContext * )context )-> userdata
675683 : "" ;
676684
677- RARCH_DBG ("[LunaRequest] screenSaverCallback: %s\n" , msg ? msg : "(null)" );
685+ RARCH_LOG ("[LunaRequest] screenSaverCallback: %s\n" , msg ? msg : "(null)" );
678686 if (!msg || !len )
679687 return true;
680688
@@ -721,8 +729,7 @@ static bool screenSaverCallback(LSHandle* sh, LSMessage* reply, void* context)
721729 rjsonwriter_raw (w , "}" , 1 );
722730
723731 char * resp = rjsonwriter_get_memory_buffer (w , NULL );
724- RARCH_DBG ("[LunaRequest] responseScreenSaverRequest payload: %s\n" , resp );
725-
732+ RARCH_LOG ("[LunaRequest] responseScreenSaverRequest payload: %s\n" , resp );
726733 HContext response_ctx ;
727734 memset (& response_ctx , 0 , sizeof (response_ctx ));
728735 response_ctx .multiple = false;
@@ -864,3 +871,100 @@ void shutdown_webos_contexts()
864871 }
865872#endif
866873}
874+
875+ /*
876+ Backwards compatibility for older versions of libwayland-client that
877+ do not have wl_proxy_marshal_constructor_versioned and
878+ wl_proxy_marshal_array_constructor_versioned.
879+ */
880+ static int parse_msg_signature (const char * signature , int * new_id_index )
881+ {
882+ int count = 0 ;
883+ if (new_id_index ) * new_id_index = -1 ;
884+ if (!signature ) return 0 ;
885+
886+ for (; * signature ; ++ signature ) {
887+ switch (* signature ) {
888+ case 'n' :
889+ if (new_id_index ) * new_id_index = count ;
890+ /* fallthrough */
891+ case 'i' : case 'u' : case 'f' :
892+ case 's' : case 'o' : case 'a' : case 'h' :
893+ ++ count ;
894+ break ;
895+ default :
896+ break ;
897+ }
898+ }
899+ return count ;
900+ }
901+
902+ static void wl_marshal_20 (struct wl_proxy * proxy , uint32_t opcode , void * * varargs )
903+ {
904+ wl_proxy_marshal (proxy , opcode ,
905+ varargs [0 ], varargs [1 ], varargs [2 ], varargs [3 ], varargs [4 ],
906+ varargs [5 ], varargs [6 ], varargs [7 ], varargs [8 ], varargs [9 ],
907+ varargs [10 ], varargs [11 ], varargs [12 ], varargs [13 ], varargs [14 ],
908+ varargs [15 ], varargs [16 ], varargs [17 ], varargs [18 ], varargs [19 ]);
909+ }
910+
911+ struct wl_proxy * wl_proxy_marshal_constructor (struct wl_proxy * proxy ,
912+ uint32_t opcode ,
913+ const struct wl_interface * interface , ...)
914+ {
915+ va_list ap ;
916+ void * varargs [WL_CLOSURE_MAX_ARGS ];
917+ int num_args , new_id_index = -1 ;
918+
919+ struct wl_proxy * id = wl_proxy_create (proxy , interface );
920+ if (!id ) return NULL ;
921+
922+ struct wl_interface * proxy_iface = (* (struct wl_interface * * )proxy );
923+ if (!proxy_iface ) return NULL ;
924+ if (opcode >= proxy_iface -> method_count ) return NULL ;
925+
926+ const char * sig = proxy_iface -> methods [opcode ].signature ;
927+ num_args = parse_msg_signature (sig , & new_id_index );
928+ if (new_id_index < 0 ) return NULL ;
929+
930+ memset (varargs , 0 , sizeof (varargs ));
931+ va_start (ap , interface );
932+ for (int i = 0 ; i < num_args ; i ++ )
933+ varargs [i ] = va_arg (ap , void * );
934+ va_end (ap );
935+
936+ varargs [new_id_index ] = id ;
937+ wl_marshal_20 (proxy , opcode , varargs );
938+ return id ;
939+ }
940+
941+ struct wl_proxy * wl_proxy_marshal_constructor_versioned (struct wl_proxy * proxy ,
942+ uint32_t opcode ,
943+ const struct wl_interface * interface ,
944+ uint32_t version , ...)
945+ {
946+ va_list ap ;
947+ void * varargs [WL_CLOSURE_MAX_ARGS ];
948+ int num_args , new_id_index = -1 ;
949+
950+ struct wl_proxy * id = wl_proxy_create (proxy , interface );
951+ if (!id ) return NULL ;
952+
953+ struct wl_interface * proxy_iface = (* (struct wl_interface * * )proxy );
954+ if (!proxy_iface ) return NULL ;
955+ if (opcode >= proxy_iface -> method_count ) return NULL ;
956+
957+ const char * sig = proxy_iface -> methods [opcode ].signature ;
958+ num_args = parse_msg_signature (sig , & new_id_index );
959+ if (new_id_index < 0 ) return NULL ;
960+
961+ memset (varargs , 0 , sizeof (varargs ));
962+ va_start (ap , version );
963+ for (int i = 0 ; i < num_args ; i ++ )
964+ varargs [i ] = va_arg (ap , void * );
965+ va_end (ap );
966+
967+ varargs [new_id_index ] = id ;
968+ wl_marshal_20 (proxy , opcode , varargs );
969+ return id ;
970+ }
0 commit comments