aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-03-04 23:26:20 +0100
committerdec05eba <dec05eba@protonmail.com>2022-03-04 23:26:20 +0100
commit3214251ec07a17b961d81d2fc28b47690ac3e65e (patch)
treedf8179b5ce3fd964b7ad2081dba4f08c2596ffc5 /src
parent7b5caa47fe764573828a0d9e1d1b100ed9d19e9b (diff)
Add window icon and launcher icon
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index b788e0b..8d6e4a2 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -197,6 +197,35 @@ static std::string base64_url_decode(const std::string &data) {
return cppcodec::base64_url::decode<std::string>(data);
}
+static void set_window_icon(Display *display, Window window, const std::string &icon_filepath) {
+ mgl::Image image;
+ if(!image.load_from_file(icon_filepath.c_str()) || image.get_num_channels() != 4) {
+ fprintf(stderr, "Warning: failed to load window icon: %s\n", icon_filepath.c_str());
+ return;
+ }
+
+ const size_t icon_buffer_size = 2 + image.get_size().x * image.get_size().y;
+ unsigned long *icon_buffer = new unsigned long[icon_buffer_size];
+ icon_buffer[0] = image.get_size().x;
+ icon_buffer[1] = image.get_size().y;
+
+ const unsigned char *image_data = image.data();
+ for(size_t i = 0; i < (size_t)image.get_size().x * (size_t)image.get_size().y; ++i) {
+ const size_t image_data_index = i * 4;
+ icon_buffer[2 + i] =
+ (long)image_data[image_data_index + 0] << 16
+ | (long)image_data[image_data_index + 1] << 8
+ | (long)image_data[image_data_index + 2] << 0
+ | (long)image_data[image_data_index + 3] << 24;
+ }
+
+ Atom net_wm_icon = XInternAtom(display, "_NET_WM_ICON", False);
+ XChangeProperty(display, window, net_wm_icon, XA_CARDINAL, 32, PropModeReplace, (const unsigned char*)icon_buffer, icon_buffer_size);
+ XFlush(display);
+
+ delete []icon_buffer;
+}
+
namespace QuickMedia {
static Json::Value load_recommended_json(const char *plugin_name);
static void fill_recommended_items_from_json(const char *plugin_name, const Json::Value &recommended_json, BodyItems &body_items);
@@ -668,6 +697,8 @@ namespace QuickMedia {
set_use_system_fonts(get_config().use_system_fonts);
init_body_themes();
+ set_window_icon(disp, window.get_system_handle(), resources_root + "icons/qm_logo.png");
+
if(!is_touch_enabled()) {
if(!circle_mask_shader.load_from_file((resources_root + "shaders/circle_mask.glsl").c_str(), mgl::Shader::Type::Fragment)) {
show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/circle_mask.glsl", Urgency::CRITICAL);