Plug dbus in the event loop.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
This commit is contained in:
parent
8b61bf5197
commit
38f8d2fdce
13
awesome.c
13
awesome.c
|
@ -36,6 +36,7 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <ev.h>
|
||||||
|
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
#include <xcb/shape.h>
|
#include <xcb/shape.h>
|
||||||
|
@ -261,7 +262,7 @@ main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
const char *confpath = NULL;
|
const char *confpath = NULL;
|
||||||
int r, xfd, csfd, dbusfd, i, screen_nbr, opt;
|
int r, xfd, csfd, i, screen_nbr, opt;
|
||||||
ssize_t cmdlen = 1;
|
ssize_t cmdlen = 1;
|
||||||
const xcb_query_extension_reply_t *shape_query, *randr_query;
|
const xcb_query_extension_reply_t *shape_query, *randr_query;
|
||||||
fd_set rd;
|
fd_set rd;
|
||||||
|
@ -474,8 +475,7 @@ main(int argc, char **argv)
|
||||||
warn("error binding UNIX domain socket: %s", strerror(errno));
|
warn("error binding UNIX domain socket: %s", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!a_dbus_init(&dbusfd))
|
a_dbus_init();
|
||||||
dbusfd = -1;
|
|
||||||
|
|
||||||
/* register function for signals */
|
/* register function for signals */
|
||||||
signal(SIGINT, &exit_on_signal);
|
signal(SIGINT, &exit_on_signal);
|
||||||
|
@ -492,8 +492,6 @@ main(int argc, char **argv)
|
||||||
FD_ZERO(&rd);
|
FD_ZERO(&rd);
|
||||||
if(csfd >= 0)
|
if(csfd >= 0)
|
||||||
FD_SET(csfd, &rd);
|
FD_SET(csfd, &rd);
|
||||||
if(dbusfd >= 0)
|
|
||||||
FD_SET(dbusfd, &rd);
|
|
||||||
FD_SET(xfd, &rd);
|
FD_SET(xfd, &rd);
|
||||||
if(timerisset(&globalconf.timer))
|
if(timerisset(&globalconf.timer))
|
||||||
{
|
{
|
||||||
|
@ -509,7 +507,7 @@ main(int argc, char **argv)
|
||||||
else
|
else
|
||||||
timersub(&hook_nextrun, &now, &select_timeout);
|
timersub(&hook_nextrun, &now, &select_timeout);
|
||||||
}
|
}
|
||||||
if(select(MAX(MAX(xfd, csfd), dbusfd) + 1, &rd,
|
if(select(MAX(xfd, csfd) + 1, &rd,
|
||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
timerisset(&globalconf.timer) ? &select_timeout : NULL) == -1)
|
timerisset(&globalconf.timer) ? &select_timeout : NULL) == -1)
|
||||||
{
|
{
|
||||||
|
@ -533,9 +531,6 @@ main(int argc, char **argv)
|
||||||
luaA_docmd(buf);
|
luaA_docmd(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dbusfd >= 0 && FD_ISSET(dbusfd, &rd))
|
|
||||||
a_dbus_process_requests(&dbusfd);
|
|
||||||
|
|
||||||
/* Two level polling:
|
/* Two level polling:
|
||||||
* We need to first check we have an event to handle
|
* We need to first check we have an event to handle
|
||||||
* and if so, we handle them all in a round.
|
* and if so, we handle them all in a round.
|
||||||
|
|
31
dbus.c
31
dbus.c
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#ifdef WITH_DBUS
|
#ifdef WITH_DBUS
|
||||||
|
|
||||||
|
#include <ev.h>
|
||||||
#include <dbus/dbus.h>
|
#include <dbus/dbus.h>
|
||||||
|
|
||||||
#include "dbus.h"
|
#include "dbus.h"
|
||||||
|
@ -32,6 +33,7 @@ extern awesome_t globalconf;
|
||||||
|
|
||||||
static DBusError err;
|
static DBusError err;
|
||||||
static DBusConnection *dbus_connection = NULL;
|
static DBusConnection *dbus_connection = NULL;
|
||||||
|
ev_io dbusio = { .fd = -1 };
|
||||||
|
|
||||||
/** Check a dbus object path format and its number of element.
|
/** Check a dbus object path format and its number of element.
|
||||||
* \param path The path.
|
* \param path The path.
|
||||||
|
@ -98,13 +100,13 @@ a_dbus_process_widget_set(DBusMessage *req)
|
||||||
p_delete(&path);
|
p_delete(&path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
a_dbus_process_requests(int *fd)
|
a_dbus_process_requests(EV_P_ ev_io *w, int revents)
|
||||||
{
|
{
|
||||||
DBusMessage *msg;
|
DBusMessage *msg;
|
||||||
int nmsg = 0;
|
int nmsg = 0;
|
||||||
|
|
||||||
if(!dbus_connection && !a_dbus_init(fd))
|
if(!dbus_connection && !a_dbus_init())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
|
@ -134,9 +136,10 @@ a_dbus_process_requests(int *fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
a_dbus_init(int *fd)
|
a_dbus_init(void)
|
||||||
{
|
{
|
||||||
bool ret;
|
bool ret;
|
||||||
|
int fd;
|
||||||
|
|
||||||
dbus_error_init(&err);
|
dbus_error_init(&err);
|
||||||
|
|
||||||
|
@ -167,13 +170,16 @@ a_dbus_init(int *fd)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!dbus_connection_get_unix_fd(dbus_connection, fd))
|
if(!dbus_connection_get_unix_fd(dbus_connection, &fd))
|
||||||
{
|
{
|
||||||
warn("cannot get DBus connection file descriptor");
|
warn("cannot get DBus connection file descriptor");
|
||||||
a_dbus_cleanup();
|
a_dbus_cleanup();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ev_io_init(&dbusio, a_dbus_process_requests, fd, EV_READ);
|
||||||
|
ev_io_start(EV_DEFAULT_UC_ &dbusio);
|
||||||
|
ev_unref(EV_DEFAULT_UC);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,6 +191,12 @@ a_dbus_cleanup(void)
|
||||||
|
|
||||||
dbus_error_free(&err);
|
dbus_error_free(&err);
|
||||||
|
|
||||||
|
if (dbusio.fd >= 0) {
|
||||||
|
ev_ref(EV_DEFAULT_UC);
|
||||||
|
ev_io_stop(EV_DEFAULT_UC_ &dbusio);
|
||||||
|
dbusio.fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* This is a shared connection owned by libdbus
|
/* This is a shared connection owned by libdbus
|
||||||
* Do not close it, only unref
|
* Do not close it, only unref
|
||||||
*/
|
*/
|
||||||
|
@ -196,16 +208,9 @@ a_dbus_cleanup(void)
|
||||||
|
|
||||||
#include "dbus.h"
|
#include "dbus.h"
|
||||||
|
|
||||||
void
|
|
||||||
a_dbus_process_requests(int *fd __attribute__((unused)))
|
|
||||||
{
|
|
||||||
/* empty */
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
a_dbus_init(int *fd)
|
a_dbus_init(void)
|
||||||
{
|
{
|
||||||
*fd = -1;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue