66#include <string.h>
77#include <strings.h>
88#include <systemd/sd-bus.h>
9+ #include <time.h>
910#include <wayland-server-core.h>
1011#include <wlr/types/wlr_keyboard.h>
1112#include <wlr/util/log.h>
@@ -604,8 +605,7 @@ void global_shortcuts_init(void) {
604605
605606 r = sd_bus_request_name (gs .bus , GS_BUS_NAME , 0 );
606607 if (r < 0 ) {
607- wlr_log (WLR_ERROR , "failed to request bus name '%s': %s" , GS_BUS_NAME ,
608- strerror (- r ));
608+ wlr_log (WLR_ERROR , "failed to request bus name '%s': %s" , GS_BUS_NAME , strerror (- r ));
609609 sd_bus_unref (gs .bus );
610610 gs .bus = NULL ;
611611 return ;
@@ -708,6 +708,65 @@ bool global_shortcuts_handle_key(uint32_t modifiers, uint32_t keycode, const xkb
708708 return false;
709709}
710710
711+ void global_shortcuts_send_by_app (const char * app_id , const char * shortcut_id , bool pressed ) {
712+ if (!gs .initialized || !gs .bus || !app_id || !shortcut_id )
713+ return ;
714+
715+ struct timespec tp ;
716+ clock_gettime (CLOCK_MONOTONIC , & tp );
717+ uint64_t timestamp = (uint64_t )tp .tv_sec * 1000 + (uint64_t )tp .tv_nsec / 1000000 ;
718+
719+ gs_session_t * sess ;
720+ wl_list_for_each (sess , & gs .sessions , link ) {
721+ if (sess -> destroyed )
722+ continue ;
723+ if (strcmp (sess -> app_id , app_id ) != 0 )
724+ continue ;
725+ gs_shortcut_t * sc ;
726+ wl_list_for_each (sc , & sess -> shortcuts , link ) {
727+ if (strcmp (sc -> id , shortcut_id ) == 0 ) {
728+ if (pressed )
729+ emit_activated (sess , sc , timestamp );
730+ else
731+ emit_deactivated (sess , sc , timestamp );
732+ return ;
733+ }
734+ }
735+ }
736+ }
737+
738+ void global_shortcuts_list (char * buf , size_t buf_size ) {
739+ if (!buf || buf_size == 0 )
740+ return ;
741+
742+ int offset = 0 ;
743+
744+ if (!gs .initialized || !gs .bus ) {
745+ snprintf (buf , buf_size , "not initialized\n" );
746+ return ;
747+ }
748+
749+ gs_session_t * sess ;
750+ wl_list_for_each (sess , & gs .sessions , link ) {
751+ if (sess -> destroyed )
752+ continue ;
753+ gs_shortcut_t * sc ;
754+ wl_list_for_each (sc , & sess -> shortcuts , link ) {
755+ int ret = snprintf (buf + offset , buf_size - offset , "%s:%s\t%s\n" ,
756+ sess -> app_id ? sess -> app_id : "?" , sc -> id ? sc -> id : "?" ,
757+ sc -> description ? sc -> description : "" );
758+ if (ret < 0 )
759+ return ;
760+ if ((size_t )ret >= buf_size - offset )
761+ return ;
762+ offset += ret ;
763+ }
764+ }
765+
766+ if (offset == 0 )
767+ snprintf (buf , buf_size , "none\n" );
768+ }
769+
711770
712771#else // !HAVE_SYSTEMD
713772
@@ -733,5 +792,16 @@ bool global_shortcuts_handle_key(uint32_t modifiers, uint32_t keycode, const xkb
733792 return false;
734793}
735794
795+ void global_shortcuts_send_by_app (const char * app_id , const char * shortcut_id , bool pressed ) {
796+ (void )app_id ;
797+ (void )shortcut_id ;
798+ (void )pressed ;
799+ }
800+
801+ void global_shortcuts_list (char * buf , size_t buf_size ) {
802+ if (buf && buf_size )
803+ snprintf (buf , buf_size , "not available (no systemd)\n" );
804+ }
805+
736806
737807#endif // HAVE_SYSTEMD
0 commit comments