dbus: export in Lua request_name()
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
a4254b195d
commit
79ae3ab72a
|
@ -397,6 +397,9 @@ main(int argc, char **argv)
|
||||||
if(xcb_connection_has_error(globalconf.connection))
|
if(xcb_connection_has_error(globalconf.connection))
|
||||||
fatal("cannot open display");
|
fatal("cannot open display");
|
||||||
|
|
||||||
|
/* initiliaze dbus */
|
||||||
|
a_dbus_init();
|
||||||
|
|
||||||
/* Grab server */
|
/* Grab server */
|
||||||
xcb_grab_server(globalconf.connection);
|
xcb_grab_server(globalconf.connection);
|
||||||
xcb_flush(globalconf.connection);
|
xcb_flush(globalconf.connection);
|
||||||
|
@ -498,13 +501,10 @@ main(int argc, char **argv)
|
||||||
a_xcb_set_event_handlers();
|
a_xcb_set_event_handlers();
|
||||||
a_xcb_set_property_handlers();
|
a_xcb_set_property_handlers();
|
||||||
|
|
||||||
/* Grab server */
|
/* we will receive events, stop grabbing server */
|
||||||
xcb_ungrab_server(globalconf.connection);
|
xcb_ungrab_server(globalconf.connection);
|
||||||
|
|
||||||
xcb_aux_sync(globalconf.connection);
|
|
||||||
|
|
||||||
luaA_cs_init();
|
luaA_cs_init();
|
||||||
a_dbus_init();
|
|
||||||
|
|
||||||
/* refresh everything before waiting events */
|
/* refresh everything before waiting events */
|
||||||
awesome_refresh(globalconf.connection);
|
awesome_refresh(globalconf.connection);
|
||||||
|
|
73
dbus.c
73
dbus.c
|
@ -261,10 +261,31 @@ a_dbus_process_requests(EV_P_ ev_io *w, int revents)
|
||||||
dbus_connection_flush(dbus_connection);
|
dbus_connection_flush(dbus_connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
a_dbus_request_name(const char *name)
|
||||||
|
{
|
||||||
|
int ret = dbus_bus_request_name(dbus_connection, name, 0, &err);
|
||||||
|
|
||||||
|
if(dbus_error_is_set(&err))
|
||||||
|
{
|
||||||
|
warn("failed to request D-Bus name: %s", err.message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(ret)
|
||||||
|
{
|
||||||
|
case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
|
||||||
|
return true;
|
||||||
|
case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
|
||||||
|
warn("already primary D-Bus name owner for %s", name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
a_dbus_init(void)
|
a_dbus_init(void)
|
||||||
{
|
{
|
||||||
bool ret;
|
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
dbus_error_init(&err);
|
dbus_error_init(&err);
|
||||||
|
@ -280,21 +301,7 @@ a_dbus_init(void)
|
||||||
|
|
||||||
dbus_connection_set_exit_on_disconnect(dbus_connection, FALSE);
|
dbus_connection_set_exit_on_disconnect(dbus_connection, FALSE);
|
||||||
|
|
||||||
ret = dbus_bus_request_name(dbus_connection, "org.awesome", 0, &err);
|
a_dbus_request_name("org.awesome");
|
||||||
|
|
||||||
if(dbus_error_is_set(&err))
|
|
||||||
{
|
|
||||||
warn("failed to request D-Bus name: %s", err.message);
|
|
||||||
a_dbus_cleanup();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
|
|
||||||
{
|
|
||||||
warn("not primary D-Bus name owner");
|
|
||||||
a_dbus_cleanup();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!dbus_connection_get_unix_fd(dbus_connection, &fd))
|
if(!dbus_connection_get_unix_fd(dbus_connection, &fd))
|
||||||
{
|
{
|
||||||
|
@ -332,6 +339,28 @@ a_dbus_cleanup(void)
|
||||||
dbus_connection = NULL;
|
dbus_connection = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Register a D-Bus name to receive message from.
|
||||||
|
* \param L The Lua VM state.
|
||||||
|
* \return The number of elements pushed on stack.
|
||||||
|
* \luastack
|
||||||
|
* \lparam A string with the name of the D-Bus name to register. Note that
|
||||||
|
* org.awesome is registered by default.
|
||||||
|
* \lreturn True if everything worked fine, false otherwise.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
luaA_dbus_request_name(lua_State *L)
|
||||||
|
{
|
||||||
|
const char *name = luaL_checkstring(L, 1);
|
||||||
|
lua_pushboolean(L, a_dbus_request_name(name));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct luaL_reg awesome_dbus_lib[] =
|
||||||
|
{
|
||||||
|
{ "request_name", luaA_dbus_request_name },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
#else /* HAVE_DBUS */
|
#else /* HAVE_DBUS */
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -346,5 +375,17 @@ a_dbus_cleanup(void)
|
||||||
/* empty */
|
/* empty */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
luaA_donothing(lua_State *L)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct luaL_reg awesome_dbus_lib[] =
|
||||||
|
{
|
||||||
|
{ "request_name", luaA_donothing },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||||
|
|
4
luaa.c
4
luaa.c
|
@ -55,6 +55,7 @@
|
||||||
extern awesome_t globalconf;
|
extern awesome_t globalconf;
|
||||||
|
|
||||||
extern const struct luaL_reg awesome_hooks_lib[];
|
extern const struct luaL_reg awesome_hooks_lib[];
|
||||||
|
extern const struct luaL_reg awesome_dbus_lib[];
|
||||||
extern const struct luaL_reg awesome_keygrabber_lib[];
|
extern const struct luaL_reg awesome_keygrabber_lib[];
|
||||||
extern const struct luaL_reg awesome_mousegrabber_lib[];
|
extern const struct luaL_reg awesome_mousegrabber_lib[];
|
||||||
extern const struct luaL_reg awesome_button_methods[];
|
extern const struct luaL_reg awesome_button_methods[];
|
||||||
|
@ -767,6 +768,9 @@ luaA_init(void)
|
||||||
/* Export hooks lib */
|
/* Export hooks lib */
|
||||||
luaL_register(L, "hooks", awesome_hooks_lib);
|
luaL_register(L, "hooks", awesome_hooks_lib);
|
||||||
|
|
||||||
|
/* Export D-Bus lib */
|
||||||
|
luaL_register(L, "dbus", awesome_dbus_lib);
|
||||||
|
|
||||||
/* Export keygrabber lib */
|
/* Export keygrabber lib */
|
||||||
luaL_register(L, "keygrabber", awesome_keygrabber_lib);
|
luaL_register(L, "keygrabber", awesome_keygrabber_lib);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue