2015-06-21 17:33:46 +02:00
/*
Simple DirectMedia Layer
2024-01-01 13:15:26 -08:00
Copyright ( C ) 1997 - 2024 Sam Lantinga < slouken @ libsdl . org >
2015-06-21 17:33:46 +02:00
This software is provided ' as - is ' , without any express or implied
warranty . In no event will the authors be held liable for any damages
arising from the use of this software .
Permission is granted to anyone to use this software for any purpose ,
including commercial applications , and to alter it and redistribute it
freely , subject to the following restrictions :
1. The origin of this software must not be misrepresented ; you must not
claim that you wrote the original software . If you use this software
in a product , an acknowledgment in the product documentation would be
appreciated but is not required .
2. Altered source versions must be plainly marked as such , and must not be
misrepresented as being the original software .
3. This notice may not be removed or altered from any source distribution .
*/
2022-11-29 18:34:15 -08:00
# include "SDL_internal.h"
2015-06-21 17:33:46 +02:00
# include "SDL_dbus.h"
2022-08-29 11:08:24 +02:00
# include "SDL_sandbox.h"
2022-05-06 10:51:55 -07:00
# include "../../stdlib/SDL_vacopy.h"
2015-06-21 17:33:46 +02:00
2023-03-29 21:49:01 +00:00
# ifdef SDL_USE_LIBDBUS
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// we never link directly to libdbus.
2015-06-21 17:33:46 +02:00
static const char * dbus_library = " libdbus-1.so.3 " ;
static void * dbus_handle = NULL ;
2022-08-29 11:08:24 +02:00
static char * inhibit_handle = NULL ;
2015-06-21 17:33:46 +02:00
static unsigned int screensaver_cookie = 0 ;
2016-10-14 08:20:40 -07:00
static SDL_DBusContext dbus ;
2015-06-21 17:33:46 +02:00
2024-08-22 17:33:49 -07:00
static bool LoadDBUSSyms ( void )
2015-06-21 17:33:46 +02:00
{
2023-06-20 13:22:55 +01:00
# define SDL_DBUS_SYM2_OPTIONAL(TYPE, x, y) \
dbus . x = ( TYPE ) SDL_LoadFunction ( dbus_handle , # y )
2023-01-09 14:55:12 -08:00
# define SDL_DBUS_SYM2(TYPE, x, y) \
if ( ! ( dbus . x = ( TYPE ) SDL_LoadFunction ( dbus_handle , # y ) ) ) \
2024-08-22 17:33:49 -07:00
return false
2022-11-30 12:51:59 -08:00
2023-06-20 13:22:55 +01:00
# define SDL_DBUS_SYM_OPTIONAL(TYPE, x) \
SDL_DBUS_SYM2_OPTIONAL ( TYPE , x , dbus_ # # x )
2023-01-09 14:55:12 -08:00
# define SDL_DBUS_SYM(TYPE, x) \
SDL_DBUS_SYM2 ( TYPE , x , dbus_ # # x )
2015-06-21 17:33:46 +02:00
2023-01-09 14:55:12 -08:00
SDL_DBUS_SYM ( DBusConnection * ( * ) ( DBusBusType , DBusError * ) , bus_get_private ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusConnection * , DBusError * ) , bus_register ) ;
SDL_DBUS_SYM ( void ( * ) ( DBusConnection * , const char * , DBusError * ) , bus_add_match ) ;
SDL_DBUS_SYM ( DBusConnection * ( * ) ( const char * , DBusError * ) , connection_open_private ) ;
SDL_DBUS_SYM ( void ( * ) ( DBusConnection * , dbus_bool_t ) , connection_set_exit_on_disconnect ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusConnection * ) , connection_get_is_connected ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusConnection * , DBusHandleMessageFunction , void * , DBusFreeFunction ) , connection_add_filter ) ;
2024-03-10 17:27:42 -04:00
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusConnection * , DBusHandleMessageFunction , void * ) , connection_remove_filter ) ;
2023-01-09 14:55:12 -08:00
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusConnection * , const char * , const DBusObjectPathVTable * , void * , DBusError * ) , connection_try_register_object_path ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusConnection * , DBusMessage * , dbus_uint32_t * ) , connection_send ) ;
SDL_DBUS_SYM ( DBusMessage * ( * ) ( DBusConnection * , DBusMessage * , int , DBusError * ) , connection_send_with_reply_and_block ) ;
SDL_DBUS_SYM ( void ( * ) ( DBusConnection * ) , connection_close ) ;
SDL_DBUS_SYM ( void ( * ) ( DBusConnection * ) , connection_ref ) ;
SDL_DBUS_SYM ( void ( * ) ( DBusConnection * ) , connection_unref ) ;
SDL_DBUS_SYM ( void ( * ) ( DBusConnection * ) , connection_flush ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusConnection * , int ) , connection_read_write ) ;
SDL_DBUS_SYM ( DBusDispatchStatus ( * ) ( DBusConnection * ) , connection_dispatch ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusMessage * , const char * , const char * ) , message_is_signal ) ;
2024-03-10 17:27:42 -04:00
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusMessage * , const char * ) , message_has_path ) ;
2023-01-09 14:55:12 -08:00
SDL_DBUS_SYM ( DBusMessage * ( * ) ( const char * , const char * , const char * , const char * ) , message_new_method_call ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusMessage * , int , . . . ) , message_append_args ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusMessage * , int , va_list ) , message_append_args_valist ) ;
SDL_DBUS_SYM ( void ( * ) ( DBusMessage * , DBusMessageIter * ) , message_iter_init_append ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusMessageIter * , int , const char * , DBusMessageIter * ) , message_iter_open_container ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusMessageIter * , int , const void * ) , message_iter_append_basic ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusMessageIter * , DBusMessageIter * ) , message_iter_close_container ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusMessage * , DBusError * , int , . . . ) , message_get_args ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusMessage * , DBusError * , int , va_list ) , message_get_args_valist ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusMessage * , DBusMessageIter * ) , message_iter_init ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( DBusMessageIter * ) , message_iter_next ) ;
SDL_DBUS_SYM ( void ( * ) ( DBusMessageIter * , void * ) , message_iter_get_basic ) ;
SDL_DBUS_SYM ( int ( * ) ( DBusMessageIter * ) , message_iter_get_arg_type ) ;
SDL_DBUS_SYM ( void ( * ) ( DBusMessageIter * , DBusMessageIter * ) , message_iter_recurse ) ;
SDL_DBUS_SYM ( void ( * ) ( DBusMessage * ) , message_unref ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( void ) , threads_init_default ) ;
SDL_DBUS_SYM ( void ( * ) ( DBusError * ) , error_init ) ;
SDL_DBUS_SYM ( dbus_bool_t ( * ) ( const DBusError * ) , error_is_set ) ;
SDL_DBUS_SYM ( void ( * ) ( DBusError * ) , error_free ) ;
SDL_DBUS_SYM ( char * ( * ) ( void ) , get_local_machine_id ) ;
2023-06-20 13:22:55 +01:00
SDL_DBUS_SYM_OPTIONAL ( char * ( * ) ( DBusError * ) , try_get_local_machine_id ) ;
2023-01-09 14:55:12 -08:00
SDL_DBUS_SYM ( void ( * ) ( void * ) , free ) ;
SDL_DBUS_SYM ( void ( * ) ( char * * ) , free_string_array ) ;
SDL_DBUS_SYM ( void ( * ) ( void ) , shutdown ) ;
2015-06-21 17:33:46 +02:00
2022-11-30 12:51:59 -08:00
# undef SDL_DBUS_SYM
# undef SDL_DBUS_SYM2
2015-06-21 17:33:46 +02:00
2024-08-22 17:33:49 -07:00
return true ;
2015-06-21 17:33:46 +02:00
}
2022-11-30 12:51:59 -08:00
static void UnloadDBUSLibrary ( void )
2015-06-21 17:33:46 +02:00
{
2023-11-09 22:29:15 +01:00
if ( dbus_handle ) {
2015-06-21 17:33:46 +02:00
SDL_UnloadObject ( dbus_handle ) ;
dbus_handle = NULL ;
}
}
2024-08-22 17:33:49 -07:00
static bool LoadDBUSLibrary ( void )
2015-06-21 17:33:46 +02:00
{
2024-08-22 17:33:49 -07:00
bool result = true ;
2023-11-09 22:29:15 +01:00
if ( ! dbus_handle ) {
2015-06-21 17:33:46 +02:00
dbus_handle = SDL_LoadObject ( dbus_library ) ;
2023-11-09 22:29:15 +01:00
if ( ! dbus_handle ) {
2024-08-22 17:33:49 -07:00
result = false ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Don't call SDL_SetError(): SDL_LoadObject already did.
2015-06-21 17:33:46 +02:00
} else {
2024-08-22 17:33:49 -07:00
result = LoadDBUSSyms ( ) ;
if ( ! result ) {
2015-06-21 17:33:46 +02:00
UnloadDBUSLibrary ( ) ;
}
}
}
2024-08-22 17:33:49 -07:00
return result ;
2015-06-21 17:33:46 +02:00
}
2021-08-04 13:30:12 -04:00
static SDL_SpinLock spinlock_dbus_init = 0 ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// you must hold spinlock_dbus_init before calling this!
2022-11-30 12:51:59 -08:00
static void SDL_DBus_Init_Spinlocked ( void )
2015-06-21 17:33:46 +02:00
{
2024-08-22 09:21:26 -07:00
static bool is_dbus_available = true ;
2019-10-09 19:38:16 -04:00
if ( ! is_dbus_available ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
return ; // don't keep trying if this fails.
2019-10-09 19:38:16 -04:00
}
if ( ! dbus . session_conn ) {
2015-06-21 17:33:46 +02:00
DBusError err ;
2019-10-09 19:38:16 -04:00
2024-08-22 17:33:49 -07:00
if ( ! LoadDBUSLibrary ( ) ) {
2024-08-22 09:21:26 -07:00
is_dbus_available = false ; // can't load at all? Don't keep trying.
2022-11-30 12:51:59 -08:00
return ;
2019-10-09 19:38:16 -04:00
}
2020-03-30 14:26:15 -07:00
if ( ! dbus . threads_init_default ( ) ) {
2024-08-22 09:21:26 -07:00
is_dbus_available = false ;
2020-03-30 14:26:15 -07:00
return ;
}
2015-06-21 17:33:46 +02:00
dbus . error_init ( & err ) ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// session bus is required
2020-03-26 20:28:04 -04:00
2015-06-21 17:33:46 +02:00
dbus . session_conn = dbus . bus_get_private ( DBUS_BUS_SESSION , & err ) ;
if ( dbus . error_is_set ( & err ) ) {
dbus . error_free ( & err ) ;
2017-05-28 07:08:10 -04:00
SDL_DBus_Quit ( ) ;
2024-08-22 09:21:26 -07:00
is_dbus_available = false ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
return ; // oh well
2015-06-21 17:33:46 +02:00
}
dbus . connection_set_exit_on_disconnect ( dbus . session_conn , 0 ) ;
2020-03-26 20:28:04 -04:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// system bus is optional
2020-03-26 20:28:04 -04:00
dbus . system_conn = dbus . bus_get_private ( DBUS_BUS_SYSTEM , & err ) ;
if ( ! dbus . error_is_set ( & err ) ) {
dbus . connection_set_exit_on_disconnect ( dbus . system_conn , 0 ) ;
}
dbus . error_free ( & err ) ;
2015-06-21 17:33:46 +02:00
}
}
2022-11-30 12:51:59 -08:00
void SDL_DBus_Init ( void )
2021-08-04 13:30:12 -04:00
{
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
SDL_LockSpinlock ( & spinlock_dbus_init ) ; // make sure two threads can't init at same time, since this can happen before SDL_Init.
2021-08-04 13:30:12 -04:00
SDL_DBus_Init_Spinlocked ( ) ;
2024-01-18 03:39:55 -08:00
SDL_UnlockSpinlock ( & spinlock_dbus_init ) ;
2021-08-04 13:30:12 -04:00
}
2022-11-30 12:51:59 -08:00
void SDL_DBus_Quit ( void )
2015-06-21 17:33:46 +02:00
{
2017-05-28 07:08:10 -04:00
if ( dbus . system_conn ) {
dbus . connection_close ( dbus . system_conn ) ;
dbus . connection_unref ( dbus . system_conn ) ;
}
2015-06-21 17:33:46 +02:00
if ( dbus . session_conn ) {
dbus . connection_close ( dbus . session_conn ) ;
dbus . connection_unref ( dbus . session_conn ) ;
2017-05-28 07:08:10 -04:00
}
2024-01-02 13:15:32 -05:00
2024-08-22 09:21:26 -07:00
if ( SDL_GetHintBoolean ( SDL_HINT_SHUTDOWN_DBUS_ON_QUIT , false ) ) {
2024-01-07 14:20:16 -08:00
if ( dbus . shutdown ) {
dbus . shutdown ( ) ;
}
2015-06-21 17:33:46 +02:00
}
2024-01-02 13:15:32 -05:00
2017-05-28 07:08:10 -04:00
SDL_zero ( dbus ) ;
2015-06-21 17:33:46 +02:00
UnloadDBUSLibrary ( ) ;
2022-08-29 11:08:24 +02:00
SDL_free ( inhibit_handle ) ;
inhibit_handle = NULL ;
2015-06-21 17:33:46 +02:00
}
2023-05-23 11:29:41 -07:00
SDL_DBusContext * SDL_DBus_GetContext ( void )
2015-06-21 17:33:46 +02:00
{
2023-11-09 22:29:15 +01:00
if ( ! dbus_handle | | ! dbus . session_conn ) {
2015-06-21 17:33:46 +02:00
SDL_DBus_Init ( ) ;
}
2022-11-30 12:51:59 -08:00
2019-10-09 19:38:16 -04:00
return ( dbus_handle & & dbus . session_conn ) ? & dbus : NULL ;
2015-06-21 17:33:46 +02:00
}
2024-08-22 09:21:26 -07:00
static bool SDL_DBus_CallMethodInternal ( DBusConnection * conn , const char * node , const char * path , const char * interface , const char * method , va_list ap )
2015-06-21 17:33:46 +02:00
{
2024-08-22 17:33:49 -07:00
bool result = false ;
2017-05-28 07:11:52 -04:00
if ( conn ) {
DBusMessage * msg = dbus . message_new_method_call ( node , path , interface , method ) ;
if ( msg ) {
2018-07-13 17:53:24 -04:00
int firstarg ;
va_list ap_reply ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
va_copy ( ap_reply , ap ) ; // copy the arg list so we don't compete with D-Bus for it
2018-07-13 17:53:24 -04:00
firstarg = va_arg ( ap , int ) ;
2017-05-28 07:11:52 -04:00
if ( ( firstarg = = DBUS_TYPE_INVALID ) | | dbus . message_append_args_valist ( msg , firstarg , ap ) ) {
DBusMessage * reply = dbus . connection_send_with_reply_and_block ( conn , msg , 300 , NULL ) ;
if ( reply ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// skip any input args, get to output args.
2018-07-13 17:53:24 -04:00
while ( ( firstarg = va_arg ( ap_reply , int ) ) ! = DBUS_TYPE_INVALID ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// we assume D-Bus already validated all this.
2022-11-30 12:51:59 -08:00
{
void * dumpptr = va_arg ( ap_reply , void * ) ;
( void ) dumpptr ;
}
2018-07-13 17:53:24 -04:00
if ( firstarg = = DBUS_TYPE_ARRAY ) {
2022-11-30 12:51:59 -08:00
{
const int dumpint = va_arg ( ap_reply , int ) ;
( void ) dumpint ;
}
2018-07-13 17:53:24 -04:00
}
}
firstarg = va_arg ( ap_reply , int ) ;
if ( ( firstarg = = DBUS_TYPE_INVALID ) | | dbus . message_get_args_valist ( reply , NULL , firstarg , ap_reply ) ) {
2024-08-22 17:33:49 -07:00
result = true ;
2017-05-28 07:11:52 -04:00
}
dbus . message_unref ( reply ) ;
}
2015-06-21 17:33:46 +02:00
}
2018-07-13 17:53:24 -04:00
va_end ( ap_reply ) ;
2015-06-21 17:33:46 +02:00
dbus . message_unref ( msg ) ;
}
}
2017-05-28 07:11:52 -04:00
2024-08-22 17:33:49 -07:00
return result ;
2015-06-21 17:33:46 +02:00
}
2024-08-22 09:21:26 -07:00
bool SDL_DBus_CallMethodOnConnection ( DBusConnection * conn , const char * node , const char * path , const char * interface , const char * method , . . . )
2015-06-21 17:33:46 +02:00
{
2024-08-22 17:33:49 -07:00
bool result ;
2017-05-28 07:11:52 -04:00
va_list ap ;
va_start ( ap , method ) ;
2024-08-22 17:33:49 -07:00
result = SDL_DBus_CallMethodInternal ( conn , node , path , interface , method , ap ) ;
2017-05-28 07:11:52 -04:00
va_end ( ap ) ;
2024-08-22 17:33:49 -07:00
return result ;
2017-05-28 07:11:52 -04:00
}
2015-06-21 17:33:46 +02:00
2024-08-22 09:21:26 -07:00
bool SDL_DBus_CallMethod ( const char * node , const char * path , const char * interface , const char * method , . . . )
2017-05-28 07:11:52 -04:00
{
2024-08-22 17:33:49 -07:00
bool result ;
2017-05-28 07:11:52 -04:00
va_list ap ;
va_start ( ap , method ) ;
2024-08-22 17:33:49 -07:00
result = SDL_DBus_CallMethodInternal ( dbus . session_conn , node , path , interface , method , ap ) ;
2017-05-28 07:11:52 -04:00
va_end ( ap ) ;
2024-08-22 17:33:49 -07:00
return result ;
2017-05-28 07:11:52 -04:00
}
2015-06-21 17:33:46 +02:00
2024-08-22 09:21:26 -07:00
static bool SDL_DBus_CallVoidMethodInternal ( DBusConnection * conn , const char * node , const char * path , const char * interface , const char * method , va_list ap )
2017-05-28 07:11:52 -04:00
{
2024-08-22 17:33:49 -07:00
bool result = false ;
2015-06-21 17:33:46 +02:00
2017-05-28 07:11:52 -04:00
if ( conn ) {
DBusMessage * msg = dbus . message_new_method_call ( node , path , interface , method ) ;
if ( msg ) {
int firstarg = va_arg ( ap , int ) ;
if ( ( firstarg = = DBUS_TYPE_INVALID ) | | dbus . message_append_args_valist ( msg , firstarg , ap ) ) {
if ( dbus . connection_send ( conn , msg , NULL ) ) {
dbus . connection_flush ( conn ) ;
2024-08-22 17:33:49 -07:00
result = true ;
2017-05-28 07:11:52 -04:00
}
}
dbus . message_unref ( msg ) ;
2015-06-21 17:33:46 +02:00
}
2017-05-28 07:11:52 -04:00
}
2015-06-21 17:33:46 +02:00
2024-08-22 17:33:49 -07:00
return result ;
2017-05-28 07:11:52 -04:00
}
2015-06-21 17:33:46 +02:00
2024-08-22 09:21:26 -07:00
static bool SDL_DBus_CallWithBasicReply ( DBusConnection * conn , DBusMessage * msg , const int expectedtype , void * result )
2022-08-25 16:18:45 +02:00
{
2024-08-22 09:21:26 -07:00
bool retval = false ;
2022-08-25 16:18:45 +02:00
DBusMessage * reply = dbus . connection_send_with_reply_and_block ( conn , msg , 300 , NULL ) ;
if ( reply ) {
DBusMessageIter iter , actual_iter ;
dbus . message_iter_init ( reply , & iter ) ;
if ( dbus . message_iter_get_arg_type ( & iter ) = = DBUS_TYPE_VARIANT ) {
dbus . message_iter_recurse ( & iter , & actual_iter ) ;
} else {
actual_iter = iter ;
}
if ( dbus . message_iter_get_arg_type ( & actual_iter ) = = expectedtype ) {
dbus . message_iter_get_basic ( & actual_iter , result ) ;
2024-08-22 09:21:26 -07:00
retval = true ;
2022-08-25 16:18:45 +02:00
}
dbus . message_unref ( reply ) ;
}
return retval ;
}
2024-08-22 09:21:26 -07:00
bool SDL_DBus_CallVoidMethodOnConnection ( DBusConnection * conn , const char * node , const char * path , const char * interface , const char * method , . . . )
2017-05-28 07:11:52 -04:00
{
2024-08-22 17:33:49 -07:00
bool result ;
2017-05-28 07:11:52 -04:00
va_list ap ;
va_start ( ap , method ) ;
2024-08-22 17:33:49 -07:00
result = SDL_DBus_CallVoidMethodInternal ( conn , node , path , interface , method , ap ) ;
2017-05-28 07:11:52 -04:00
va_end ( ap ) ;
2024-08-22 17:33:49 -07:00
return result ;
2017-05-28 07:11:52 -04:00
}
2024-08-22 09:21:26 -07:00
bool SDL_DBus_CallVoidMethod ( const char * node , const char * path , const char * interface , const char * method , . . . )
2017-05-28 07:11:52 -04:00
{
2024-08-22 17:33:49 -07:00
bool result ;
2017-05-28 07:11:52 -04:00
va_list ap ;
va_start ( ap , method ) ;
2024-08-22 17:33:49 -07:00
result = SDL_DBus_CallVoidMethodInternal ( dbus . session_conn , node , path , interface , method , ap ) ;
2017-05-28 07:11:52 -04:00
va_end ( ap ) ;
2024-08-22 17:33:49 -07:00
return result ;
2017-05-28 07:11:52 -04:00
}
2024-08-22 09:21:26 -07:00
bool SDL_DBus_QueryPropertyOnConnection ( DBusConnection * conn , const char * node , const char * path , const char * interface , const char * property , const int expectedtype , void * result )
2017-05-28 07:11:52 -04:00
{
2024-08-22 09:21:26 -07:00
bool retval = false ;
2015-06-21 17:33:46 +02:00
2017-05-28 07:11:52 -04:00
if ( conn ) {
DBusMessage * msg = dbus . message_new_method_call ( node , path , " org.freedesktop.DBus.Properties " , " Get " ) ;
if ( msg ) {
if ( dbus . message_append_args ( msg , DBUS_TYPE_STRING , & interface , DBUS_TYPE_STRING , & property , DBUS_TYPE_INVALID ) ) {
2022-08-25 16:18:45 +02:00
retval = SDL_DBus_CallWithBasicReply ( conn , msg , expectedtype , result ) ;
2017-05-28 07:11:52 -04:00
}
2015-06-21 17:33:46 +02:00
dbus . message_unref ( msg ) ;
}
2017-05-28 07:11:52 -04:00
}
2015-06-21 17:33:46 +02:00
2017-05-28 07:11:52 -04:00
return retval ;
}
2024-08-22 09:21:26 -07:00
bool SDL_DBus_QueryProperty ( const char * node , const char * path , const char * interface , const char * property , const int expectedtype , void * result )
2017-05-28 07:11:52 -04:00
{
return SDL_DBus_QueryPropertyOnConnection ( dbus . session_conn , node , path , interface , property , expectedtype , result ) ;
}
2022-11-30 12:51:59 -08:00
void SDL_DBus_ScreensaverTickle ( void )
2017-05-28 07:11:52 -04:00
{
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
if ( screensaver_cookie = = 0 & & ! inhibit_handle ) { // no need to tickle if we're inhibiting.
// org.gnome.ScreenSaver is the legacy interface, but it'll either do nothing or just be a second harmless tickle on newer systems, so we leave it for now.
2019-07-02 09:43:26 -04:00
SDL_DBus_CallVoidMethod ( " org.gnome.ScreenSaver " , " /org/gnome/ScreenSaver " , " org.gnome.ScreenSaver " , " SimulateUserActivity " , DBUS_TYPE_INVALID ) ;
SDL_DBus_CallVoidMethod ( " org.freedesktop.ScreenSaver " , " /org/freedesktop/ScreenSaver " , " org.freedesktop.ScreenSaver " , " SimulateUserActivity " , DBUS_TYPE_INVALID ) ;
}
2017-05-28 07:11:52 -04:00
}
2024-08-22 09:21:26 -07:00
static bool SDL_DBus_AppendDictWithKeysAndValues ( DBusMessageIter * iterInit , const char * * keys , const char * * values , int count )
2022-08-29 11:08:24 +02:00
{
2023-06-22 10:48:12 +02:00
DBusMessageIter iterDict ;
2022-08-29 11:08:24 +02:00
2022-11-27 17:38:43 +01:00
if ( ! dbus . message_iter_open_container ( iterInit , DBUS_TYPE_ARRAY , " {sv} " , & iterDict ) ) {
2022-08-29 11:08:24 +02:00
goto failed ;
2022-11-27 17:38:43 +01:00
}
2022-08-29 11:08:24 +02:00
2023-06-22 10:48:12 +02:00
for ( int i = 0 ; i < count ; i + + ) {
DBusMessageIter iterEntry , iterValue ;
const char * key = keys [ i ] ;
const char * value = values [ i ] ;
2022-08-29 11:08:24 +02:00
2023-06-22 10:48:12 +02:00
if ( ! dbus . message_iter_open_container ( & iterDict , DBUS_TYPE_DICT_ENTRY , NULL , & iterEntry ) ) {
goto failed ;
}
2022-08-29 11:08:24 +02:00
2023-06-22 10:48:12 +02:00
if ( ! dbus . message_iter_append_basic ( & iterEntry , DBUS_TYPE_STRING , & key ) ) {
goto failed ;
}
2022-08-29 11:08:24 +02:00
2023-06-22 10:48:12 +02:00
if ( ! dbus . message_iter_open_container ( & iterEntry , DBUS_TYPE_VARIANT , DBUS_TYPE_STRING_AS_STRING , & iterValue ) ) {
goto failed ;
}
if ( ! dbus . message_iter_append_basic ( & iterValue , DBUS_TYPE_STRING , & value ) ) {
goto failed ;
}
if ( ! dbus . message_iter_close_container ( & iterEntry , & iterValue ) | | ! dbus . message_iter_close_container ( & iterDict , & iterEntry ) ) {
goto failed ;
}
2022-11-27 17:38:43 +01:00
}
2022-08-29 11:08:24 +02:00
2023-06-22 10:48:12 +02:00
if ( ! dbus . message_iter_close_container ( iterInit , & iterDict ) ) {
2022-08-29 11:08:24 +02:00
goto failed ;
}
2024-08-22 09:21:26 -07:00
return true ;
2022-08-29 11:08:24 +02:00
failed :
/* message_iter_abandon_container_if_open() and message_iter_abandon_container() might be
* missing if libdbus is too old . Instead , we just return without cleaning up any eventual
* open container */
2024-08-22 09:21:26 -07:00
return false ;
2022-08-29 11:08:24 +02:00
}
2024-08-22 09:21:26 -07:00
static bool SDL_DBus_AppendDictWithKeyValue ( DBusMessageIter * iterInit , const char * key , const char * value )
2023-06-23 07:28:05 -07:00
{
const char * keys [ 1 ] ;
const char * values [ 1 ] ;
keys [ 0 ] = key ;
values [ 0 ] = value ;
return SDL_DBus_AppendDictWithKeysAndValues ( iterInit , keys , values , 1 ) ;
}
2024-08-22 09:21:26 -07:00
bool SDL_DBus_ScreensaverInhibit ( bool inhibit )
2017-05-28 07:11:52 -04:00
{
2022-08-29 11:08:24 +02:00
const char * default_inhibit_reason = " Playing a game " ;
2023-11-09 22:29:15 +01:00
if ( ( inhibit & & ( screensaver_cookie ! = 0 | | inhibit_handle ) ) | | ( ! inhibit & & ( screensaver_cookie = = 0 & & ! inhibit_handle ) ) ) {
2024-08-22 09:21:26 -07:00
return true ;
2022-08-29 11:08:24 +02:00
}
2022-09-28 10:25:24 +02:00
if ( ! dbus . session_conn ) {
/* We either lost connection to the session bus or were not able to
* load the D - Bus library at all . */
2024-08-22 09:21:26 -07:00
return false ;
2022-09-28 10:25:24 +02:00
}
2022-08-29 11:08:24 +02:00
if ( SDL_DetectSandbox ( ) ! = SDL_SANDBOX_NONE ) {
const char * bus_name = " org.freedesktop.portal.Desktop " ;
const char * path = " /org/freedesktop/portal/desktop " ;
const char * interface = " org.freedesktop.portal.Inhibit " ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
const char * window = " " ; // As a future improvement we could gather the X11 XID or Wayland surface identifier
static const unsigned int INHIBIT_IDLE = 8 ; // Taken from the portal API reference
2022-08-29 11:08:24 +02:00
DBusMessageIter iterInit ;
if ( inhibit ) {
DBusMessage * msg ;
2024-08-22 17:33:49 -07:00
bool result = false ;
2022-08-29 11:08:24 +02:00
const char * key = " reason " ;
const char * reply = NULL ;
const char * reason = SDL_GetHint ( SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME ) ;
2023-11-09 22:29:15 +01:00
if ( ! reason | | ! reason [ 0 ] ) {
2022-08-29 11:08:24 +02:00
reason = default_inhibit_reason ;
}
msg = dbus . message_new_method_call ( bus_name , path , interface , " Inhibit " ) ;
2023-11-09 22:29:15 +01:00
if ( ! msg ) {
2024-08-22 09:21:26 -07:00
return false ;
2022-08-29 11:08:24 +02:00
}
if ( ! dbus . message_append_args ( msg , DBUS_TYPE_STRING , & window , DBUS_TYPE_UINT32 , & INHIBIT_IDLE , DBUS_TYPE_INVALID ) ) {
dbus . message_unref ( msg ) ;
2024-08-22 09:21:26 -07:00
return false ;
2022-08-29 11:08:24 +02:00
}
dbus . message_iter_init_append ( msg , & iterInit ) ;
2023-06-22 10:48:12 +02:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// a{sv}
2023-06-23 07:28:05 -07:00
if ( ! SDL_DBus_AppendDictWithKeyValue ( & iterInit , key , reason ) ) {
dbus . message_unref ( msg ) ;
2024-08-22 09:21:26 -07:00
return false ;
2022-08-29 11:08:24 +02:00
}
if ( SDL_DBus_CallWithBasicReply ( dbus . session_conn , msg , DBUS_TYPE_OBJECT_PATH , & reply ) ) {
inhibit_handle = SDL_strdup ( reply ) ;
2024-08-22 17:33:49 -07:00
result = true ;
2022-08-29 11:08:24 +02:00
}
dbus . message_unref ( msg ) ;
2024-08-22 17:33:49 -07:00
return result ;
2022-08-29 11:08:24 +02:00
} else {
if ( ! SDL_DBus_CallVoidMethod ( bus_name , inhibit_handle , " org.freedesktop.portal.Request " , " Close " , DBUS_TYPE_INVALID ) ) {
2024-08-22 09:21:26 -07:00
return false ;
2022-08-29 11:08:24 +02:00
}
SDL_free ( inhibit_handle ) ;
inhibit_handle = NULL ;
}
2015-06-21 17:33:46 +02:00
} else {
2022-08-29 11:08:24 +02:00
const char * bus_name = " org.freedesktop.ScreenSaver " ;
2017-05-28 07:11:52 -04:00
const char * path = " /org/freedesktop/ScreenSaver " ;
const char * interface = " org.freedesktop.ScreenSaver " ;
if ( inhibit ) {
2024-07-28 07:22:46 -07:00
const char * app = SDL_GetAppMetadataProperty ( SDL_PROP_APP_METADATA_NAME_STRING ) ;
2021-08-28 22:52:13 +08:00
const char * reason = SDL_GetHint ( SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME ) ;
2023-11-09 22:29:15 +01:00
if ( ! reason | | ! reason [ 0 ] ) {
2022-08-29 11:08:24 +02:00
reason = default_inhibit_reason ;
2021-08-28 22:52:13 +08:00
}
2022-08-29 11:08:24 +02:00
if ( ! SDL_DBus_CallMethod ( bus_name , path , interface , " Inhibit " ,
2022-11-30 12:51:59 -08:00
DBUS_TYPE_STRING , & app , DBUS_TYPE_STRING , & reason , DBUS_TYPE_INVALID ,
DBUS_TYPE_UINT32 , & screensaver_cookie , DBUS_TYPE_INVALID ) ) {
2024-08-22 09:21:26 -07:00
return false ;
2015-06-21 17:33:46 +02:00
}
2023-11-03 09:27:29 -07:00
return ( screensaver_cookie ! = 0 ) ;
2017-05-28 07:11:52 -04:00
} else {
2022-08-29 11:08:24 +02:00
if ( ! SDL_DBus_CallVoidMethod ( bus_name , path , interface , " UnInhibit " , DBUS_TYPE_UINT32 , & screensaver_cookie , DBUS_TYPE_INVALID ) ) {
2024-08-22 09:21:26 -07:00
return false ;
2017-05-28 07:11:52 -04:00
}
screensaver_cookie = 0 ;
2015-06-21 17:33:46 +02:00
}
}
2017-05-28 07:11:52 -04:00
2024-08-22 09:21:26 -07:00
return true ;
2015-06-21 17:33:46 +02:00
}
2023-05-18 17:42:08 -04:00
void SDL_DBus_PumpEvents ( void )
{
if ( dbus . session_conn ) {
dbus . connection_read_write ( dbus . session_conn , 0 ) ;
while ( dbus . connection_dispatch ( dbus . session_conn ) = = DBUS_DISPATCH_DATA_REMAINS ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Do nothing, actual work happens in DBus_MessageFilter
2023-05-18 17:42:08 -04:00
SDL_DelayNS ( SDL_US_TO_NS ( 10 ) ) ;
}
}
}
2023-06-20 13:22:55 +01:00
/*
* Get the machine ID if possible . Result must be freed with dbus - > free ( ) .
*/
char * SDL_DBus_GetLocalMachineId ( void )
{
DBusError err ;
char * result ;
dbus . error_init ( & err ) ;
if ( dbus . try_get_local_machine_id ) {
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Available since dbus 1.12.0, has proper error-handling
2023-06-20 13:22:55 +01:00
result = dbus . try_get_local_machine_id ( & err ) ;
} else {
/* Available since time immemorial, but has no error-handling:
* if the machine ID can ' t be read , many versions of libdbus will
* treat that as a fatal mis - installation and abort ( ) */
result = dbus . get_local_machine_id ( ) ;
}
if ( result ) {
return result ;
}
if ( dbus . error_is_set ( & err ) ) {
SDL_SetError ( " %s: %s " , err . name , err . message ) ;
dbus . error_free ( & err ) ;
} else {
SDL_SetError ( " Error getting D-Bus machine ID " ) ;
}
return NULL ;
}
2023-09-20 16:13:31 +01:00
/*
* Convert file drops with mime type " application/vnd.portal.filetransfer " to file paths
* Result must be freed with dbus - > free_string_array ( ) .
* https : //flatpak.github.io/xdg-desktop-portal/#gdbus-method-org-freedesktop-portal-FileTransfer.RetrieveFiles
*/
char * * SDL_DBus_DocumentsPortalRetrieveFiles ( const char * key , int * path_count )
{
DBusError err ;
DBusMessageIter iter , iterDict ;
char * * paths = NULL ;
DBusMessage * reply = NULL ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
DBusMessage * msg = dbus . message_new_method_call ( " org.freedesktop.portal.Documents " , // Node
" /org/freedesktop/portal/documents " , // Path
" org.freedesktop.portal.FileTransfer " , // Interface
" RetrieveFiles " ) ; // Method
2023-09-20 16:13:31 +01:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// Make sure we have a connection to the dbus session bus
2023-09-20 16:13:31 +01:00
if ( ! SDL_DBus_GetContext ( ) | | ! dbus . session_conn ) {
/* We either cannot connect to the session bus or were unable to
* load the D - Bus library at all . */
return NULL ;
}
dbus . error_init ( & err ) ;
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
// First argument is a "application/vnd.portal.filetransfer" key from a DnD or clipboard event
2023-09-20 16:13:31 +01:00
if ( ! dbus . message_append_args ( msg , DBUS_TYPE_STRING , & key , DBUS_TYPE_INVALID ) ) {
SDL_OutOfMemory ( ) ;
dbus . message_unref ( msg ) ;
goto failed ;
}
/* Second argument is a variant dictionary for options.
* The spec doesn ' t define any entries yet so it ' s empty . */
dbus . message_iter_init_append ( msg , & iter ) ;
if ( ! dbus . message_iter_open_container ( & iter , DBUS_TYPE_ARRAY , " {sv} " , & iterDict ) | |
! dbus . message_iter_close_container ( & iter , & iterDict ) ) {
SDL_OutOfMemory ( ) ;
dbus . message_unref ( msg ) ;
goto failed ;
}
reply = dbus . connection_send_with_reply_and_block ( dbus . session_conn , msg , DBUS_TIMEOUT_USE_DEFAULT , & err ) ;
dbus . message_unref ( msg ) ;
if ( reply ) {
dbus . message_get_args ( reply , & err , DBUS_TYPE_ARRAY , DBUS_TYPE_STRING , & paths , path_count , DBUS_TYPE_INVALID ) ;
dbus . message_unref ( reply ) ;
}
if ( paths ) {
return paths ;
}
failed :
if ( dbus . error_is_set ( & err ) ) {
SDL_SetError ( " %s: %s " , err . name , err . message ) ;
dbus . error_free ( & err ) ;
} else {
SDL_SetError ( " Error retrieving paths for documents portal \" %s \" " , key ) ;
}
return NULL ;
}
2015-06-21 17:33:46 +02:00
# endif