Add `media_player_order` to set media player metadata order

pull/237/head
jackun 4 years ago
parent db07081617
commit 5ec6519832
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -142,6 +142,7 @@ A partial list of parameters are below. See the config file for a complete list.
| `vsync`<br> `gl_vsync` | Set vsync for OpenGL or Vulkan | | `vsync`<br> `gl_vsync` | Set vsync for OpenGL or Vulkan |
| `media_player` | Show media player metadata | | `media_player` | Show media player metadata |
| `media_player_name` | Set main media player DBus service name without the `org.mpris.MediaPlayer2` part, like `spotify`, `vlc`, `audacious` or `cantata`. Defaults to `spotify`. | | `media_player_name` | Set main media player DBus service name without the `org.mpris.MediaPlayer2` part, like `spotify`, `vlc`, `audacious` or `cantata`. Defaults to `spotify`. |
| `media_player_order` | Media player metadata field order. Defaults to `title,artist,album`. |
| `font_scale_media_player` | Change size of media player text relative to font_size | | `font_scale_media_player` | Change size of media player text relative to font_size |
| `io_read`<br> `io_write` | Show non-cached IO read/write, in MiB/s | | `io_read`<br> `io_write` | Show non-cached IO read/write, in MiB/s |
| `pci_dev` | Select GPU device in multi-gpu setups | | `pci_dev` | Select GPU device in multi-gpu setups |

@ -97,6 +97,7 @@ background_alpha=0.5
### Show media player metadata ### Show media player metadata
# media_player # media_player
# media_player_name = spotify # media_player_name = spotify
# media_player_order = title,artist,album
### Specify gpu with pci bus id for amdgpu and NVML stats. ### Specify gpu with pci bus id for amdgpu and NVML stats.
### Set to 'domain:bus:slot.function' ### Set to 'domain:bus:slot.function'

@ -957,10 +957,11 @@ float get_ticker_limited_pos(float pos, float tw, float& left_limit, float& righ
} }
#ifdef HAVE_DBUS #ifdef HAVE_DBUS
void render_mpris_metadata(swapchain_stats& data, const ImVec4& color, metadata& meta, uint64_t frame_timing, bool is_main) static void render_mpris_metadata(struct overlay_params& params, metadata& meta, uint64_t frame_timing, bool is_main)
{ {
scoped_lock lk(meta.mutex); scoped_lock lk(meta.mutex);
if (meta.valid) { if (meta.valid) {
auto color = ImGui::ColorConvertU32ToFloat4(params.media_player_color);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(8,0)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(8,0));
ImGui::Dummy(ImVec2(0.0f, 20.0f)); ImGui::Dummy(ImVec2(0.0f, 20.0f));
//ImGui::PushFont(data.font1); //ImGui::PushFont(data.font1);
@ -989,18 +990,34 @@ void render_mpris_metadata(swapchain_stats& data, const ImVec4& color, metadata&
meta.ticker.pos -= .5f * (frame_timing / 16666.7f) * meta.ticker.dir; meta.ticker.pos -= .5f * (frame_timing / 16666.7f) * meta.ticker.dir;
new_pos = get_ticker_limited_pos(meta.ticker.pos, meta.ticker.tw0, left_limit, right_limit); for (auto order : params.media_player_order) {
ImGui::SetCursorPosX(new_pos); switch (order) {
ImGui::TextColored(color, "%s", meta.title.c_str()); case MP_ORDER_TITLE:
{
new_pos = get_ticker_limited_pos(meta.ticker.pos, meta.ticker.tw1, left_limit, right_limit); new_pos = get_ticker_limited_pos(meta.ticker.pos, meta.ticker.tw0, left_limit, right_limit);
ImGui::SetCursorPosX(new_pos); ImGui::SetCursorPosX(new_pos);
ImGui::TextColored(color, "%s", meta.artists.c_str()); ImGui::TextColored(color, "%s", meta.title.c_str());
//ImGui::NewLine(); }
if (!meta.album.empty()) { break;
new_pos = get_ticker_limited_pos(meta.ticker.pos, meta.ticker.tw2, left_limit, right_limit); case MP_ORDER_ARTIST:
ImGui::SetCursorPosX(new_pos); {
ImGui::TextColored(color, "%s", meta.album.c_str()); new_pos = get_ticker_limited_pos(meta.ticker.pos, meta.ticker.tw1, left_limit, right_limit);
ImGui::SetCursorPosX(new_pos);
ImGui::TextColored(color, "%s", meta.artists.c_str());
}
break;
case MP_ORDER_ALBUM:
{
//ImGui::NewLine();
if (!meta.album.empty()) {
new_pos = get_ticker_limited_pos(meta.ticker.pos, meta.ticker.tw2, left_limit, right_limit);
ImGui::SetCursorPosX(new_pos);
ImGui::TextColored(color, "%s", meta.album.c_str());
}
}
break;
default: break;
}
} }
if (is_main && main_metadata.valid && !main_metadata.playing) { if (is_main && main_metadata.valid && !main_metadata.playing) {
@ -1355,9 +1372,8 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2&
ImFont scaled_font; ImFont scaled_font;
scale_default_font(scaled_font, params.font_scale_media_player); scale_default_font(scaled_font, params.font_scale_media_player);
ImGui::PushFont(&scaled_font); ImGui::PushFont(&scaled_font);
auto media_color = ImGui::ColorConvertU32ToFloat4(params.media_player_color); render_mpris_metadata(params, main_metadata, frame_timing, true);
render_mpris_metadata(data, media_color, main_metadata, frame_timing, true); render_mpris_metadata(params, generic_mpris, frame_timing, false);
render_mpris_metadata(data, media_color, generic_mpris, frame_timing, false);
ImGui::PopFont(); ImGui::PopFont();
#endif #endif

@ -8,6 +8,8 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <algorithm>
#include <cctype>
#include "overlay_params.h" #include "overlay_params.h"
#include "overlay.h" #include "overlay.h"
@ -182,6 +184,25 @@ parse_path(const char *str)
return str; return str;
} }
static std::vector<media_player_order>
parse_media_player_order(const char *str)
{
std::vector<media_player_order> order;
std::stringstream ss(str);
std::string token;
while (std::getline(ss, token, ',')) {
trim(token);
std::transform(token.begin(), token.end(), token.begin(), ::tolower);
if (token == "title")
order.push_back(MP_ORDER_TITLE);
else if (token == "artist")
order.push_back(MP_ORDER_ARTIST);
else if (token == "album")
order.push_back(MP_ORDER_ALBUM);
}
return order;
}
#define parse_width(s) parse_unsigned(s) #define parse_width(s) parse_unsigned(s)
#define parse_height(s) parse_unsigned(s) #define parse_height(s) parse_unsigned(s)
#define parse_vsync(s) parse_unsigned(s) #define parse_vsync(s) parse_unsigned(s)
@ -367,6 +388,7 @@ parse_overlay_config(struct overlay_params *params,
params->media_player_name = "spotify"; params->media_player_name = "spotify";
params->font_scale_media_player = 0.55f; params->font_scale_media_player = 0.55f;
params->log_interval = 100; params->log_interval = 100;
params->media_player_order = { MP_ORDER_TITLE, MP_ORDER_ARTIST, MP_ORDER_ALBUM };
#ifdef HAVE_X11 #ifdef HAVE_X11
params->toggle_hud = { XK_Shift_R, XK_F12 }; params->toggle_hud = { XK_Shift_R, XK_F12 };

@ -84,6 +84,7 @@ typedef unsigned long KeySym;
OVERLAY_PARAM_CUSTOM(pci_dev) \ OVERLAY_PARAM_CUSTOM(pci_dev) \
OVERLAY_PARAM_CUSTOM(media_player_name) \ OVERLAY_PARAM_CUSTOM(media_player_name) \
OVERLAY_PARAM_CUSTOM(media_player_color) \ OVERLAY_PARAM_CUSTOM(media_player_color) \
OVERLAY_PARAM_CUSTOM(media_player_order) \
OVERLAY_PARAM_CUSTOM(cpu_text) \ OVERLAY_PARAM_CUSTOM(cpu_text) \
OVERLAY_PARAM_CUSTOM(gpu_text) \ OVERLAY_PARAM_CUSTOM(gpu_text) \
OVERLAY_PARAM_CUSTOM(log_interval) \ OVERLAY_PARAM_CUSTOM(log_interval) \
@ -102,6 +103,12 @@ enum overlay_plots {
OVERLAY_PLOTS_MAX, OVERLAY_PLOTS_MAX,
}; };
enum media_player_order {
MP_ORDER_TITLE,
MP_ORDER_ARTIST,
MP_ORDER_ALBUM,
};
enum overlay_param_enabled { enum overlay_param_enabled {
#define OVERLAY_PARAM_BOOL(name) OVERLAY_PARAM_ENABLED_##name, #define OVERLAY_PARAM_BOOL(name) OVERLAY_PARAM_ENABLED_##name,
#define OVERLAY_PARAM_CUSTOM(name) #define OVERLAY_PARAM_CUSTOM(name)
@ -141,6 +148,7 @@ struct overlay_params {
std::string media_player_name; std::string media_player_name;
std::string cpu_text, gpu_text; std::string cpu_text, gpu_text;
unsigned log_interval; unsigned log_interval;
std::vector<media_player_order> media_player_order;
std::string config_file_path; std::string config_file_path;
std::unordered_map<std::string,std::string> options; std::unordered_map<std::string,std::string> options;

Loading…
Cancel
Save