Add tab interface to wivrnctl
This commit is contained in:
@@ -89,6 +89,22 @@ sd_bus_message_ptr get_property(const sd_bus_ptr & bus, const char * member, con
|
||||
return sd_bus_message_ptr(msg);
|
||||
}
|
||||
|
||||
std::string get_property_string(const sd_bus_ptr & bus, const char * member)
|
||||
{
|
||||
sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
char * val;
|
||||
int ret = sd_bus_get_property_string(bus.get(), destination, path, interface, member, &error, &val);
|
||||
if (ret < 0)
|
||||
{
|
||||
std::runtime_error e(std::string("read property ") + member + " failed: " + error.message);
|
||||
sd_bus_error_free(&error);
|
||||
throw e;
|
||||
}
|
||||
std::string res(val);
|
||||
free(val);
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void set_property(const sd_bus_ptr & bus, const char * member, const char * signature, Args &&... args)
|
||||
{
|
||||
@@ -218,6 +234,23 @@ void unpair(size_t headset_id)
|
||||
call_method(bus, "RevokeKey", "s", values.at(headset_id - 1).public_key.c_str());
|
||||
}
|
||||
|
||||
void tab(std::string tab_name)
|
||||
{
|
||||
auto bus = get_user_bus();
|
||||
if (tab_name.empty())
|
||||
{
|
||||
auto val = get_property_string(bus, "ClientTab");
|
||||
if (val.empty())
|
||||
std::cout << "<No tab>" << std::endl;
|
||||
else
|
||||
std::cout << val << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
call_method(bus, "SetClientTab", "s", tab_name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
auto member(T U::* x)
|
||||
{
|
||||
@@ -340,6 +373,11 @@ int main(int argc, char ** argv)
|
||||
app.add_subcommand("disconnect", "Disconnect headset")
|
||||
->callback(disconnect);
|
||||
|
||||
std::string tab_name;
|
||||
app.add_subcommand("tab", "Show or set current tab on headset")
|
||||
->callback([&]() { return tab(tab_name); })
|
||||
->add_option("[TAB]", tab_name, "Tab to select");
|
||||
|
||||
try
|
||||
{
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
Reference in New Issue
Block a user