mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
save
This commit is contained in:
parent
9aec6bbed4
commit
61783aafaa
@ -3,6 +3,7 @@
|
|||||||
#include "AModule.hpp"
|
#include "AModule.hpp"
|
||||||
#include "bar.hpp"
|
#include "bar.hpp"
|
||||||
#include "client.hpp"
|
#include "client.hpp"
|
||||||
|
#include "giomm/desktopappinfo.h"
|
||||||
#include "util/json.hpp"
|
#include "util/json.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -61,6 +62,7 @@ class Task
|
|||||||
Gtk::Image icon_;
|
Gtk::Image icon_;
|
||||||
Gtk::Label text_before_;
|
Gtk::Label text_before_;
|
||||||
Gtk::Label text_after_;
|
Gtk::Label text_after_;
|
||||||
|
Glib::RefPtr<Gio::DesktopAppInfo> app_info_;
|
||||||
bool button_visible_;
|
bool button_visible_;
|
||||||
bool ignored_;
|
bool ignored_;
|
||||||
|
|
||||||
@ -70,6 +72,7 @@ class Task
|
|||||||
|
|
||||||
std::string format_tooltip_;
|
std::string format_tooltip_;
|
||||||
|
|
||||||
|
std::string name_;
|
||||||
std::string title_;
|
std::string title_;
|
||||||
std::string app_id_;
|
std::string app_id_;
|
||||||
uint32_t state_ = 0;
|
uint32_t state_ = 0;
|
||||||
@ -77,6 +80,7 @@ class Task
|
|||||||
private:
|
private:
|
||||||
std::string repr() const;
|
std::string repr() const;
|
||||||
std::string state_string(bool = false) const;
|
std::string state_string(bool = false) const;
|
||||||
|
void set_desktop_app_info(const std::string &app_id);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* Getter functions */
|
/* Getter functions */
|
||||||
|
@ -86,8 +86,7 @@ static Glib::RefPtr<Gdk::Pixbuf> load_icon_from_file(std::string icon_path, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Method 1 - get the correct icon name from the desktop file */
|
static Glib::RefPtr<GDesktopAppInfo> get_app_info_by_name(const std::string& app_id)
|
||||||
static std::string get_from_desktop_app_info(const std::string &app_id)
|
|
||||||
{
|
{
|
||||||
static std::vector<std::string> prefixes = search_prefix();
|
static std::vector<std::string> prefixes = search_prefix();
|
||||||
|
|
||||||
@ -103,33 +102,30 @@ static std::string get_from_desktop_app_info(const std::string &app_id)
|
|||||||
".desktop"
|
".desktop"
|
||||||
};
|
};
|
||||||
|
|
||||||
Glib::RefPtr<Gio::DesktopAppInfo> app_info;
|
for (auto& prefix : prefixes) {
|
||||||
|
for (auto& folder : app_folders) {
|
||||||
|
for (auto& suffix : suffixes) {
|
||||||
|
auto app_info_ = Gio::DesktopAppInfo::create_from_filename(prefix + folder + app_id + suffix);
|
||||||
|
if (!app_info_) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& prefix : prefixes)
|
return app_info_;
|
||||||
for (auto& folder : app_folders)
|
}
|
||||||
for (auto& suffix : suffixes)
|
}
|
||||||
if (!app_info)
|
}
|
||||||
app_info = Gio::DesktopAppInfo::create_from_filename(prefix + folder + app_id + suffix);
|
|
||||||
|
|
||||||
if (app_info && app_info->get_icon())
|
return {};
|
||||||
return app_info->get_icon()->to_string();
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Method 2 - use the app_id and check whether there is an icon with this name in the icon theme */
|
void Task::set_desktop_app_info(const std::string &app_id)
|
||||||
static std::string get_from_icon_theme(const Glib::RefPtr<Gtk::IconTheme>& icon_theme,
|
|
||||||
const std::string &app_id)
|
|
||||||
{
|
{
|
||||||
if (icon_theme->lookup_icon(app_id, 24))
|
auto app_info = get_app_info_by_name(app_id);
|
||||||
return app_id;
|
if (app_info) {
|
||||||
|
app_info_ = app_info;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Method 3 - as last resort perform a search for most appropriate desktop info file */
|
|
||||||
static std::string get_from_desktop_app_info_search(const std::string &app_id)
|
|
||||||
{
|
|
||||||
std::string desktop_file = "";
|
std::string desktop_file = "";
|
||||||
|
|
||||||
gchar*** desktop_list = g_desktop_app_info_search(app_id.c_str());
|
gchar*** desktop_list = g_desktop_app_info_search(app_id.c_str());
|
||||||
@ -137,6 +133,7 @@ static std::string get_from_desktop_app_info_search(const std::string &app_id)
|
|||||||
for (size_t i=0; desktop_list[0][i]; i++) {
|
for (size_t i=0; desktop_list[0][i]; i++) {
|
||||||
if (desktop_file == "") {
|
if (desktop_file == "") {
|
||||||
desktop_file = desktop_list[0][i];
|
desktop_file = desktop_list[0][i];
|
||||||
|
// TODO: debug. Possible error
|
||||||
} else {
|
} else {
|
||||||
auto tmp_info = Gio::DesktopAppInfo::create(desktop_list[0][i]);
|
auto tmp_info = Gio::DesktopAppInfo::create(desktop_list[0][i]);
|
||||||
auto startup_class = tmp_info->get_startup_wm_class();
|
auto startup_class = tmp_info->get_startup_wm_class();
|
||||||
@ -151,7 +148,18 @@ static std::string get_from_desktop_app_info_search(const std::string &app_id)
|
|||||||
}
|
}
|
||||||
g_free(desktop_list);
|
g_free(desktop_list);
|
||||||
|
|
||||||
return get_from_desktop_app_info(desktop_file);
|
app_info = get_app_info_by_name(desktop_file);
|
||||||
|
app_info_ = app_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Method 2 - use the app_id and check whether there is an icon with this name in the icon theme */
|
||||||
|
static std::string get_from_icon_theme(const Glib::RefPtr<Gtk::IconTheme>& icon_theme,
|
||||||
|
const std::string &app_id)
|
||||||
|
{
|
||||||
|
if (icon_theme->lookup_icon(app_id, 24))
|
||||||
|
return app_id;
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool image_load_icon(Gtk::Image& image, const Glib::RefPtr<Gtk::IconTheme>& icon_theme,
|
static bool image_load_icon(Gtk::Image& image, const Glib::RefPtr<Gtk::IconTheme>& icon_theme,
|
||||||
@ -560,14 +568,17 @@ void Task::update()
|
|||||||
{
|
{
|
||||||
bool markup = config_["markup"].isBool() ? config_["markup"].asBool() : false;
|
bool markup = config_["markup"].isBool() ? config_["markup"].asBool() : false;
|
||||||
std::string title = title_;
|
std::string title = title_;
|
||||||
|
std::string name = name_;
|
||||||
std::string app_id = app_id_;
|
std::string app_id = app_id_;
|
||||||
if (markup) {
|
if (markup) {
|
||||||
title = Glib::Markup::escape_text(title);
|
title = Glib::Markup::escape_text(title);
|
||||||
|
name = Glib::Markup::escape_text(name);
|
||||||
app_id = Glib::Markup::escape_text(app_id);
|
app_id = Glib::Markup::escape_text(app_id);
|
||||||
}
|
}
|
||||||
if (!format_before_.empty()) {
|
if (!format_before_.empty()) {
|
||||||
auto txt = fmt::format(format_before_,
|
auto txt = fmt::format(format_before_,
|
||||||
fmt::arg("title", title),
|
fmt::arg("title", title),
|
||||||
|
fmt::arg("name", name),
|
||||||
fmt::arg("app_id", app_id),
|
fmt::arg("app_id", app_id),
|
||||||
fmt::arg("state", state_string()),
|
fmt::arg("state", state_string()),
|
||||||
fmt::arg("short_state", state_string(true))
|
fmt::arg("short_state", state_string(true))
|
||||||
@ -581,6 +592,7 @@ void Task::update()
|
|||||||
if (!format_after_.empty()) {
|
if (!format_after_.empty()) {
|
||||||
auto txt = fmt::format(format_after_,
|
auto txt = fmt::format(format_after_,
|
||||||
fmt::arg("title", title),
|
fmt::arg("title", title),
|
||||||
|
fmt::arg("name", name),
|
||||||
fmt::arg("app_id", app_id),
|
fmt::arg("app_id", app_id),
|
||||||
fmt::arg("state", state_string()),
|
fmt::arg("state", state_string()),
|
||||||
fmt::arg("short_state", state_string(true))
|
fmt::arg("short_state", state_string(true))
|
||||||
@ -595,6 +607,7 @@ void Task::update()
|
|||||||
if (!format_tooltip_.empty()) {
|
if (!format_tooltip_.empty()) {
|
||||||
auto txt = fmt::format(format_tooltip_,
|
auto txt = fmt::format(format_tooltip_,
|
||||||
fmt::arg("title", title),
|
fmt::arg("title", title),
|
||||||
|
fmt::arg("name", name),
|
||||||
fmt::arg("app_id", app_id),
|
fmt::arg("app_id", app_id),
|
||||||
fmt::arg("state", state_string()),
|
fmt::arg("state", state_string()),
|
||||||
fmt::arg("short_state", state_string(true))
|
fmt::arg("short_state", state_string(true))
|
||||||
|
Loading…
Reference in New Issue
Block a user