Compare commits
3 Commits
e318bb07fe
...
d54702b071
Author | SHA1 | Date |
---|---|---|
Kim Woelders | d54702b071 | |
Kim Woelders | cd517589b3 | |
Kim Woelders | d885dcc5b3 |
|
@ -377,8 +377,8 @@ fi
|
|||
AM_CONDITIONAL(ENABLE_ZOOM, test "x$enable_zoom" != "xno")
|
||||
|
||||
AC_ARG_ENABLE(dbus,
|
||||
AS_HELP_STRING([--enable-dbus], [compile with D-Bus support (experimental) @<:@default=no@:>@]),,
|
||||
enable_dbus=no)
|
||||
AS_HELP_STRING([--enable-dbus], [compile with D-Bus support @<:@default=yes@:>@]),,
|
||||
enable_dbus=yes)
|
||||
if test "x$enable_dbus" = "xyes"; then
|
||||
PKG_CHECK_MODULES(DBUS, dbus-1, AC_DEFINE(USE_DBUS, 1, [dbus support]), enable_dbus=no)
|
||||
fi
|
||||
|
@ -556,6 +556,7 @@ echo " Render ....................... $enable_xrender"
|
|||
echo " Sync ......................... $enable_xsync"
|
||||
echo " Composite .................... $enable_composite"
|
||||
echo " GNOME session support ........ $with_gnome"
|
||||
echo " D-Bus ........................ $enable_dbus"
|
||||
echo " Window mode helper library ... $enable_libhack"
|
||||
echo " Dialogs ...................... $enable_dialogs"
|
||||
echo
|
||||
|
@ -567,7 +568,6 @@ echo
|
|||
echo "Experimental options - DO NOT USE unless you know what you are doing"
|
||||
echo " GLX .......................... $enable_glx"
|
||||
echo " ScreenSaver .................. $enable_xscrnsaver"
|
||||
echo " D-Bus ........................ $enable_dbus"
|
||||
echo " XI2 .......................... $enable_xi2"
|
||||
echo " Present....................... $enable_xpresent"
|
||||
echo " Do not use container window .. $enable_containerless"
|
||||
|
|
92
src/edbus.c
92
src/edbus.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2021 Kim Woelders
|
||||
* Copyright (C) 2007-2024 Kim Woelders
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
|
@ -332,3 +332,93 @@ DbusExit(void)
|
|||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
_DbusSendCommand(DBusBusType bus, const char *dest, const char *path,
|
||||
const char *meth, const char *args)
|
||||
{
|
||||
int err;
|
||||
DBusError dberr;
|
||||
DBusConnection *conn;
|
||||
DBusMessage *msg, *rpl;
|
||||
DBusMessageIter iter;
|
||||
const char *iface = dest;
|
||||
|
||||
err = -1;
|
||||
msg = rpl = NULL;
|
||||
dbus_error_init(&dberr);
|
||||
|
||||
conn = dbus_bus_get(bus, &dberr);
|
||||
if (dbus_error_is_set(&dberr))
|
||||
goto quit;
|
||||
|
||||
msg = dbus_message_new_method_call(dest, path, iface, meth);
|
||||
|
||||
if (args)
|
||||
{
|
||||
const char *s = args;
|
||||
int nr, type, value;
|
||||
dbus_message_iter_init_append(msg, &iter);
|
||||
for (;;)
|
||||
{
|
||||
type = *s++;
|
||||
if (type == '\0')
|
||||
break;
|
||||
if (type == ';')
|
||||
continue;
|
||||
if (*s++ != '=')
|
||||
break;
|
||||
nr = -1;
|
||||
if (type == 'u')
|
||||
{
|
||||
sscanf(s, "%u%n", &value, &nr);
|
||||
if (nr <= 0)
|
||||
goto quit;
|
||||
s += nr;
|
||||
if (!dbus_message_iter_append_basic(&iter,
|
||||
DBUS_TYPE_UINT32, &value))
|
||||
goto quit;
|
||||
}
|
||||
else
|
||||
{
|
||||
goto quit; /* Unknown type */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rpl = dbus_connection_send_with_reply_and_block(conn, msg, 100, &dberr);
|
||||
if (!rpl)
|
||||
goto quit;
|
||||
|
||||
dbus_connection_flush(conn);
|
||||
|
||||
err = 0;
|
||||
|
||||
quit:
|
||||
if (dbus_error_is_set(&dberr))
|
||||
{
|
||||
Eprintf("*** Dbus error: %s\n", dberr.message);
|
||||
dbus_error_free(&dberr);
|
||||
}
|
||||
|
||||
if (msg)
|
||||
dbus_message_unref(msg);
|
||||
if (rpl)
|
||||
dbus_message_unref(rpl);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int
|
||||
DbusRequestLogout(void)
|
||||
{
|
||||
return _DbusSendCommand(DBUS_BUS_SESSION, "org.gnome.SessionManager",
|
||||
"/org/gnome/SessionManager", "Logout", "u=0");
|
||||
}
|
||||
|
||||
int
|
||||
DbusRequestShutdown(void)
|
||||
{
|
||||
return _DbusSendCommand(DBUS_BUS_SESSION, "org.gnome.SessionManager",
|
||||
"/org/gnome/SessionManager", "Shutdown", NULL);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2007 Kim Woelders
|
||||
* Copyright (C) 2007-2024 Kim Woelders
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
|
@ -26,4 +26,7 @@
|
|||
void DbusInit(void);
|
||||
void DbusExit(void);
|
||||
|
||||
int DbusRequestLogout(void);
|
||||
int DbusRequestShutdown(void);
|
||||
|
||||
#endif /* _EDBUS_H_ */
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
#include "snaps.h"
|
||||
#include "user.h"
|
||||
#include "xwin.h"
|
||||
#if USE_DBUS
|
||||
#include "edbus.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_EXT_INIT_WIN
|
||||
static EX_Window new_init_win_ext = NoXID;
|
||||
|
@ -533,6 +536,31 @@ doSMExit(int mode, const char *params)
|
|||
#define LOGOUT_SUSPEND 5
|
||||
#define LOGOUT_HIBERNATE 6
|
||||
|
||||
#if USE_DBUS
|
||||
static int
|
||||
_SessionExitDbus(int how)
|
||||
{
|
||||
if (Mode.wm.window)
|
||||
return -1;
|
||||
|
||||
switch (how)
|
||||
{
|
||||
default:
|
||||
case LOGOUT_LOCK:
|
||||
case LOGOUT_SUSPEND:
|
||||
case LOGOUT_HIBERNATE:
|
||||
return -1;
|
||||
|
||||
case LOGOUT_EXIT:
|
||||
return DbusRequestLogout();
|
||||
|
||||
case LOGOUT_REBOOT:
|
||||
case LOGOUT_HALT:
|
||||
return DbusRequestShutdown();
|
||||
}
|
||||
}
|
||||
#endif /* USE_DBUS */
|
||||
|
||||
static void
|
||||
_SessionLogout(int how)
|
||||
{
|
||||
|
@ -552,6 +580,11 @@ _SessionLogout(int how)
|
|||
|
||||
#endif /* USE_SM */
|
||||
|
||||
#if USE_DBUS
|
||||
if (_SessionExitDbus(how) == 0)
|
||||
return;
|
||||
#endif
|
||||
|
||||
switch (how)
|
||||
{
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue