static void x_session_check_input (int fd, void *data) { int ret; if (ice_fd == -1) return; /* Reset this so wo can check kind after callbacks have been called by IceProcessMessages. The smc_interact_CB sets the kind to SAVE_SESSION_EVENT, but we don't know beforehand if that callback will be called. */ emacs_event.kind = NO_EVENT; ret = IceProcessMessages (SmcGetIceConnection (smc_conn), 0, 0); if (ret != IceProcessMessagesSuccess) { /* Either IO error or Connection closed. */ if (ret == IceProcessMessagesIOError) IceCloseConnection (SmcGetIceConnection (smc_conn)); ice_connection_closed (); } /* Check if smc_interact_CB was called and we shall generate a SAVE_SESSION_EVENT. */ if (emacs_event.kind != NO_EVENT) kbd_buffer_store_event (&emacs_event); }
int x_session_check_input (struct input_event *bufp) { SELECT_TYPE read_fds; EMACS_TIME tmout; int ret; if (ice_fd == -1) return 0; FD_ZERO (&read_fds); FD_SET (ice_fd, &read_fds); tmout.tv_sec = 0; tmout.tv_usec = 0; /* Reset this so wo can check kind after callbacks have been called by IceProcessMessages. The smc_interact_CB sets the kind to SAVE_SESSION_EVENT, but we don't know beforehand if that callback will be called. */ emacs_event.kind = NO_EVENT; ret = select (ice_fd+1, &read_fds, (SELECT_TYPE *)0, (SELECT_TYPE *)0, &tmout); if (ret < 0) { ice_connection_closed (); } else if (ret > 0 && FD_ISSET (ice_fd, &read_fds)) { ret = IceProcessMessages (SmcGetIceConnection (smc_conn), (IceReplyWaitInfo *)0, (Bool *)0); if (ret != IceProcessMessagesSuccess) { /* Either IO error or Connection closed. */ if (ret == IceProcessMessagesIOError) IceCloseConnection (SmcGetIceConnection (smc_conn)); ice_connection_closed (); } } /* Check if smc_interact_CB was called and we shall generate a SAVE_SESSION_EVENT. */ if (emacs_event.kind != NO_EVENT) memcpy (bufp, &emacs_event, sizeof (struct input_event)); return emacs_event.kind != NO_EVENT ? 1 : 0; }
void KRequestShutdownHelper::processData() { #if HAVE_X11 if( conn != NULL ) IceProcessMessages( SmcGetIceConnection( conn ), 0, 0 ); #endif }
KRequestShutdownHelper::KRequestShutdownHelper() { #if HAVE_X11 SmcCallbacks calls; calls.save_yourself.callback = save_yourself_callback; calls.die.callback = dummy_callback; calls.save_complete.callback = dummy_callback; calls.shutdown_cancelled.callback = dummy_callback; char* id = NULL; char err[ 11 ]; conn = SmcOpenConnection( NULL, NULL, 1, 0, SmcSaveYourselfProcMask | SmcDieProcMask | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask, &calls, NULL, &id, 10, err ); if( id != NULL ) free( id ); if( conn == NULL ) return; // no SM // set the required properties, mostly dummy values SmPropValue propvalue[ 5 ]; SmProp props[ 5 ]; propvalue[ 0 ].length = sizeof( unsigned char ); unsigned char value0 = SmRestartNever; // so that this extra SM connection doesn't interfere propvalue[ 0 ].value = &value0; props[ 0 ].name = const_cast< char* >( SmRestartStyleHint ); props[ 0 ].type = const_cast< char* >( SmCARD8 ); props[ 0 ].num_vals = 1; props[ 0 ].vals = &propvalue[ 0 ]; struct passwd* entry = getpwuid( geteuid() ); propvalue[ 1 ].length = entry != NULL ? strlen( entry->pw_name ) : 0; propvalue[ 1 ].value = (SmPointer)( entry != NULL ? entry->pw_name : "" ); props[ 1 ].name = const_cast< char* >( SmUserID ); props[ 1 ].type = const_cast< char* >( SmARRAY8 ); props[ 1 ].num_vals = 1; props[ 1 ].vals = &propvalue[ 1 ]; propvalue[ 2 ].length = 0; propvalue[ 2 ].value = (SmPointer)( "" ); props[ 2 ].name = const_cast< char* >( SmRestartCommand ); props[ 2 ].type = const_cast< char* >( SmLISTofARRAY8 ); props[ 2 ].num_vals = 1; props[ 2 ].vals = &propvalue[ 2 ]; propvalue[ 3 ].length = strlen( "requestshutdownhelper" ); propvalue[ 3 ].value = (SmPointer)"requestshutdownhelper"; props[ 3 ].name = const_cast< char* >( SmProgram ); props[ 3 ].type = const_cast< char* >( SmARRAY8 ); props[ 3 ].num_vals = 1; props[ 3 ].vals = &propvalue[ 3 ]; propvalue[ 4 ].length = 0; propvalue[ 4 ].value = (SmPointer)( "" ); props[ 4 ].name = const_cast< char* >( SmCloneCommand ); props[ 4 ].type = const_cast< char* >( SmLISTofARRAY8 ); props[ 4 ].num_vals = 1; props[ 4 ].vals = &propvalue[ 4 ]; SmProp* p[ 5 ] = { &props[ 0 ], &props[ 1 ], &props[ 2 ], &props[ 3 ], &props[ 4 ] }; SmcSetProperties( conn, 5, p ); notifier = new QSocketNotifier( IceConnectionNumber( SmcGetIceConnection( conn )), QSocketNotifier::Read, this ); connect( notifier, SIGNAL(activated(int)), SLOT(processData())); #endif }
bool KRequestShutdownHelper::requestShutdown( ShutdownConfirm confirm ) { #if HAVE_X11 if( conn == NULL ) return false; SmcRequestSaveYourself( conn, SmSaveBoth, True, SmInteractStyleAny, confirm == ShutdownConfirmNo, True ); // flush the request IceFlush(SmcGetIceConnection(conn)); #endif return true; }
bool mod_sm_init_session() { char error_str[256]; char *new_client_id=NULL; SmcCallbacks smcall; if(getenv("SESSION_MANAGER")==0){ warn(TR("SESSION_MANAGER environment variable not set.")); return FALSE; } if(IceAddConnectionWatch(&sm_ice_watch_fd, NULL) == 0){ warn(TR("Session Manager: IceAddConnectionWatch failed.")); return FALSE; } memset(&smcall, 0, sizeof(smcall)); smcall.save_yourself.callback=&sm_save_yourself; smcall.save_yourself.client_data=NULL; smcall.die.callback=&sm_die; smcall.die.client_data=NULL; smcall.save_complete.callback=&sm_save_complete; smcall.save_complete.client_data=NULL; smcall.shutdown_cancelled.callback=&sm_shutdown_cancelled; smcall.shutdown_cancelled.client_data=NULL; if((sm_conn=SmcOpenConnection(NULL, /* network ids */ NULL, /* context */ 1, 0, /* protocol major, minor */ SmcSaveYourselfProcMask | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask | SmcDieProcMask, &smcall, sm_client_id, &new_client_id, sizeof(error_str), error_str)) == NULL) { warn(TR("Unable to connect to the session manager.")); return FALSE; } mod_sm_set_ion_id(new_client_id); free(new_client_id); ice_sm_conn=SmcGetIceConnection(sm_conn); return TRUE; }
static void ice_init(void) { static SmPointer context; SmcCallbacks callbacks; char error_string_ret[4096]; char *client_id; char style[2]; SmPropValue styleVal; SmProp styleProp; SmProp *props[1]; int sm_fd; if (!getenv("SESSION_MANAGER")) return; IceSetIOErrorHandler(ice_io_error_handler); callbacks.save_yourself.callback = callback_save_yourself; callbacks.die.callback = callback_die; callbacks.save_complete.callback = callback_save_complete; callbacks.shutdown_cancelled.callback = callback_shutdown_cancelled; callbacks.save_yourself.client_data = callbacks.die.client_data = callbacks.save_complete.client_data = callbacks.shutdown_cancelled.client_data = (SmPointer) NULL; client_id = Estrdup(sm_client_id); error_string_ret[0] = '\0'; sm_conn = SmcOpenConnection(NULL, &context, SmProtoMajor, SmProtoMinor, SmcSaveYourselfProcMask | SmcDieProcMask | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask, &callbacks, client_id, &sm_client_id, 4096, error_string_ret); Efree(client_id); if (error_string_ret[0]) Eprintf("While connecting to session manager: %s.", error_string_ret); if (!sm_conn) return; style[0] = SmRestartIfRunning; style[1] = 0; styleVal.length = 1; styleVal.value = style; styleProp.name = (char *)SmRestartStyleHint; styleProp.type = (char *)SmCARD8; styleProp.num_vals = 1; styleProp.vals = &styleVal; props[0] = &styleProp; ice_conn = SmcGetIceConnection(sm_conn); sm_fd = IceConnectionNumber(ice_conn); /* Just in case we are a copy of E created by a doExit("restart") */ SmcSetProperties(sm_conn, 1, props); fcntl(sm_fd, F_SETFD, fcntl(sm_fd, F_GETFD, 0) | FD_CLOEXEC); sm_efd = EventFdRegister(sm_fd, ice_msgs_process); }