mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-19 19:25:41 +02:00
module_mpris: Added 'query-timeout' option
This enables us to configure the communication timeout with the dbus daemon.
This commit is contained in:
parent
e68ed8d843
commit
e423776000
2 changed files with 28 additions and 13 deletions
|
@ -55,6 +55,11 @@ mpris - This module provides MPRIS status such as currently playing artist/album
|
||||||
: list of string
|
: list of string
|
||||||
: yes
|
: yes
|
||||||
: A list of MPRIS client identities
|
: A list of MPRIS client identities
|
||||||
|
| query_timeout
|
||||||
|
: int
|
||||||
|
: no
|
||||||
|
: Dbus/MPRIS client connection timeout in ms. Try setting/incrementing
|
||||||
|
this value if the module reports a timeout error. Defaults to 500.
|
||||||
|
|
||||||
# EXAMPLES
|
# EXAMPLES
|
||||||
|
|
||||||
|
@ -77,18 +82,19 @@ bar:
|
||||||
# NOTE
|
# NOTE
|
||||||
|
|
||||||
The 'identity' refers a part of your clients DBus bus name.
|
The 'identity' refers a part of your clients DBus bus name.
|
||||||
You can obtain a list of available bus names using:
|
You can obtain a list of active client names using:
|
||||||
|
|
||||||
```
|
```
|
||||||
Systemd: > busctl --user --list
|
Systemd: > busctl --user --list
|
||||||
Playerctl: > playerctl --list-all
|
Playerctl: > playerctl --list-all
|
||||||
Libdbus: > dbus-send --session --print-reply --type=method_call --dest='org.freedesktop.DBus' /org org.freedesktop.DBus.ListNames ... | grep 'org.mpris.MediaPlayer2'
|
Libdbus: > dbus-send --session --print-reply --type=method_call \
|
||||||
|
--dest='org.freedesktop.DBus' /org org.freedesktop.DBus.ListNames
|
||||||
```
|
```
|
||||||
|
|
||||||
The identity refers to the part after 'org.mpris.MediaPlayer2'.
|
MPRIS client bus names start with 'org.mpris.MediaPlayer2.<identity>'.
|
||||||
For example, firefox may use the bus name
|
For example, firefox may use the bus name:
|
||||||
'org.mpris.MediaPlayer2.firefox.instance_1_7' and its identity would be
|
'org.mpris.MediaPlayer2.firefox.instance_1_7' which
|
||||||
'firefox'
|
gives us the identity 'firefox'
|
||||||
|
|
||||||
# SEE ALSO
|
# SEE ALSO
|
||||||
|
|
||||||
|
|
|
@ -14,16 +14,17 @@
|
||||||
#include <sys/eventfd.h>
|
#include <sys/eventfd.h>
|
||||||
|
|
||||||
#include "dbus.h"
|
#include "dbus.h"
|
||||||
|
#include "yml.h"
|
||||||
|
|
||||||
#define LOG_MODULE "mpris"
|
#define LOG_MODULE "mpris"
|
||||||
#define LOG_ENABLE_DBG 1
|
#define LOG_ENABLE_DBG 0
|
||||||
#include "../bar/bar.h"
|
#include "../bar/bar.h"
|
||||||
#include "../config-verify.h"
|
#include "../config-verify.h"
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
#include "../log.h"
|
#include "../log.h"
|
||||||
#include "../plugin.h"
|
#include "../plugin.h"
|
||||||
|
|
||||||
#define QUERY_TIMEOUT 100
|
#define DEFAULT_QUERY_TIMEOUT 500
|
||||||
|
|
||||||
#define PATH "/org/mpris/MediaPlayer2"
|
#define PATH "/org/mpris/MediaPlayer2"
|
||||||
#define BUS_NAME "org.mpris.MediaPlayer2"
|
#define BUS_NAME "org.mpris.MediaPlayer2"
|
||||||
|
@ -99,6 +100,7 @@ struct private
|
||||||
int refresh_abort_fd;
|
int refresh_abort_fd;
|
||||||
|
|
||||||
size_t identities_count;
|
size_t identities_count;
|
||||||
|
size_t timeout_ms;
|
||||||
const char **identities;
|
const char **identities;
|
||||||
struct particle *label;
|
struct particle *label;
|
||||||
|
|
||||||
|
@ -649,10 +651,10 @@ context_new(struct private *m, struct context *context)
|
||||||
|
|
||||||
sd_bus_message *reply = NULL;
|
sd_bus_message *reply = NULL;
|
||||||
sd_bus_error error = {};
|
sd_bus_error error = {};
|
||||||
status = sd_bus_call(NULL, message, QUERY_TIMEOUT, &error, &reply);
|
status = sd_bus_call(NULL, message, m->timeout_ms, &error, &reply);
|
||||||
|
|
||||||
if (status < 0 && sd_bus_error_is_set(&error)) {
|
if (status < 0 && sd_bus_error_is_set(&error)) {
|
||||||
LOG_ERR("context_new: got error response with error: %s: %s (%d)", error.name, error.message,
|
LOG_ERR("context_new: got error response: %s: %s (%d)", error.name, error.message,
|
||||||
sd_bus_error_get_errno(&error));
|
sd_bus_error_get_errno(&error));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1035,7 +1037,7 @@ run(struct module *mod)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!context_process_events(context, QUERY_TIMEOUT)) {
|
if (!context_process_events(context, m->timeout_ms)) {
|
||||||
aborted = true;
|
aborted = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1068,10 +1070,11 @@ description(const struct module *mod)
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct module *
|
static struct module *
|
||||||
mpris_new(const char **ident, size_t ident_count, struct particle *label)
|
mpris_new(const char **ident, size_t ident_count, size_t timeout, struct particle *label)
|
||||||
{
|
{
|
||||||
struct private *priv = calloc(1, sizeof(*priv));
|
struct private *priv = calloc(1, sizeof(*priv));
|
||||||
priv->label = label;
|
priv->label = label;
|
||||||
|
priv->timeout_ms = timeout;
|
||||||
priv->identities = malloc(sizeof(*ident) * ident_count);
|
priv->identities = malloc(sizeof(*ident) * ident_count);
|
||||||
priv->identities_count = ident_count;
|
priv->identities_count = ident_count;
|
||||||
|
|
||||||
|
@ -1093,8 +1096,13 @@ static struct module *
|
||||||
from_conf(const struct yml_node *node, struct conf_inherit inherited)
|
from_conf(const struct yml_node *node, struct conf_inherit inherited)
|
||||||
{
|
{
|
||||||
const struct yml_node *ident_list = yml_get_value(node, "identities");
|
const struct yml_node *ident_list = yml_get_value(node, "identities");
|
||||||
|
const struct yml_node *query_timeout = yml_get_value(node, "query_timeout");
|
||||||
const struct yml_node *c = yml_get_value(node, "content");
|
const struct yml_node *c = yml_get_value(node, "content");
|
||||||
|
|
||||||
|
size_t timeout_ms = DEFAULT_QUERY_TIMEOUT * 1000;
|
||||||
|
if(query_timeout != NULL)
|
||||||
|
timeout_ms = yml_value_as_int(query_timeout) * 1000;
|
||||||
|
|
||||||
const size_t ident_count = yml_list_length(ident_list);
|
const size_t ident_count = yml_list_length(ident_list);
|
||||||
const char *ident[ident_count];
|
const char *ident[ident_count];
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
@ -1102,7 +1110,7 @@ from_conf(const struct yml_node *node, struct conf_inherit inherited)
|
||||||
ident[i] = yml_value_as_string(iter.node);
|
ident[i] = yml_value_as_string(iter.node);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mpris_new(ident, ident_count, conf_to_particle(c, inherited));
|
return mpris_new(ident, ident_count, timeout_ms, conf_to_particle(c, inherited));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -1116,6 +1124,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
{
|
{
|
||||||
static const struct attr_info attrs[] = {
|
static const struct attr_info attrs[] = {
|
||||||
{"identities", true, &conf_verify_indentities},
|
{"identities", true, &conf_verify_indentities},
|
||||||
|
{"query_timeout", false, &conf_verify_unsigned},
|
||||||
MODULE_COMMON_ATTRS,
|
MODULE_COMMON_ATTRS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue