mirror of https://github.com/procxx/kepka.git
Get system icon theme on gtk-based DEs
This commit is contained in:
parent
47d7bd95ae
commit
1fb1d57a27
|
@ -40,8 +40,12 @@ Type Compute() {
|
|||
return Type::Gnome;
|
||||
}
|
||||
return Type::Unity;
|
||||
} else if (list.contains("xfce")) {
|
||||
return Type::XFCE;
|
||||
} else if (list.contains("gnome")) {
|
||||
return Type::Gnome;
|
||||
} else if (list.contains("x-cinnamon")) {
|
||||
return Type::Cinnamon;
|
||||
} else if (list.contains("kde")) {
|
||||
if (kdeSession == qstr("5")) {
|
||||
return Type::KDE5;
|
||||
|
@ -49,12 +53,16 @@ Type Compute() {
|
|||
return Type::KDE4;
|
||||
} else if (list.contains("mate")) {
|
||||
return Type::MATE;
|
||||
} else if (list.contains("lxde")) {
|
||||
return Type::LXDE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!desktopSession.isEmpty()) {
|
||||
if (desktopSession == qstr("gnome")) {
|
||||
return Type::Gnome;
|
||||
} else if (desktopSession == qstr("cinnamon")) {
|
||||
return Type::Cinnamon;
|
||||
} else if (desktopSession == qstr("kde4") || desktopSession == qstr("kde-plasma")) {
|
||||
return Type::KDE4;
|
||||
} else if (desktopSession == qstr("kde")) {
|
||||
|
@ -63,8 +71,12 @@ Type Compute() {
|
|||
return Type::KDE4;
|
||||
}
|
||||
return Type::KDE3;
|
||||
} else if (desktopSession == qstr("xfce")) {
|
||||
return Type::XFCE;
|
||||
} else if (desktopSession == qstr("mate")) {
|
||||
return Type::MATE;
|
||||
} else if (desktopSession == qstr("lxde")) {
|
||||
return Type::LXDE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,11 +100,14 @@ Type ComputeAndLog() {
|
|||
switch (result) {
|
||||
case Type::Other: return "Other";
|
||||
case Type::Gnome: return "Gnome";
|
||||
case Type::Cinnamon: return "Cinnamon";
|
||||
case Type::KDE3: return "KDE3";
|
||||
case Type::KDE4: return "KDE4";
|
||||
case Type::KDE5: return "KDE5";
|
||||
case Type::Unity: return "Unity";
|
||||
case Type::XFCE: return "XFCE";
|
||||
case Type::MATE: return "MATE";
|
||||
case Type::LXDE: return "LXDE";
|
||||
}
|
||||
return QString::number(static_cast<int>(result));
|
||||
};
|
||||
|
|
|
@ -13,11 +13,14 @@ namespace DesktopEnvironment {
|
|||
enum class Type {
|
||||
Other,
|
||||
Gnome,
|
||||
Cinnamon,
|
||||
KDE3,
|
||||
KDE4,
|
||||
KDE5,
|
||||
Unity,
|
||||
XFCE,
|
||||
MATE,
|
||||
LXDE,
|
||||
};
|
||||
|
||||
Type Get();
|
||||
|
@ -26,6 +29,10 @@ inline bool IsGnome() {
|
|||
return Get() == Type::Gnome;
|
||||
}
|
||||
|
||||
inline bool IsCinnamon() {
|
||||
return Get() == Type::Cinnamon;
|
||||
}
|
||||
|
||||
inline bool IsKDE3() {
|
||||
return Get() == Type::KDE3;
|
||||
}
|
||||
|
@ -46,9 +53,26 @@ inline bool IsUnity() {
|
|||
return Get() == Type::Unity;
|
||||
}
|
||||
|
||||
inline bool IsXFCE() {
|
||||
return Get() == Type::XFCE;
|
||||
}
|
||||
|
||||
inline bool IsMATE() {
|
||||
return Get() == Type::MATE;
|
||||
}
|
||||
|
||||
inline bool IsLXDE() {
|
||||
return Get() == Type::LXDE;
|
||||
}
|
||||
|
||||
inline bool IsGtkBased() {
|
||||
return IsGnome()
|
||||
|| IsCinnamon()
|
||||
|| IsUnity()
|
||||
|| IsMATE()
|
||||
|| IsXFCE()
|
||||
|| IsLXDE();
|
||||
}
|
||||
|
||||
} // namespace DesktopEnvironment
|
||||
} // namespace Platform
|
||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "platform/linux/linux_gdk_helper.h"
|
||||
#include "platform/linux/linux_desktop_environment.h"
|
||||
#include "platform/linux/specific_linux.h"
|
||||
|
||||
#include <QtGui/QGuiApplication>
|
||||
|
||||
|
@ -33,8 +34,26 @@ bool loadLibrary(QLibrary &lib, const char *name, int version) {
|
|||
}
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||
template <typename T>
|
||||
T gtkSetting(const gchar *propertyName)
|
||||
{
|
||||
GtkSettings *settings = Libs::gtk_settings_get_default();
|
||||
T value;
|
||||
Libs::g_object_get(settings, propertyName, &value, nullptr);
|
||||
return value;
|
||||
}
|
||||
|
||||
QString gtkSetting(const gchar *propertyName)
|
||||
{
|
||||
gchararray value = gtkSetting<gchararray>(propertyName);
|
||||
QString str = QString::fromUtf8(value);
|
||||
Libs::g_free(value);
|
||||
return str;
|
||||
}
|
||||
|
||||
bool setupGtkBase(QLibrary &lib_gtk) {
|
||||
if (!load(lib_gtk, "gtk_init_check", gtk_init_check)) return false;
|
||||
if (!load(lib_gtk, "gtk_settings_get_default", gtk_settings_get_default)) return false;
|
||||
if (!load(lib_gtk, "gtk_menu_new", gtk_menu_new)) return false;
|
||||
if (!load(lib_gtk, "gtk_menu_get_type", gtk_menu_get_type)) return false;
|
||||
|
||||
|
@ -90,6 +109,7 @@ bool setupGtkBase(QLibrary &lib_gtk) {
|
|||
if (!load(lib_gtk, "g_signal_connect_data", g_signal_connect_data)) return false;
|
||||
if (!load(lib_gtk, "g_signal_handler_disconnect", g_signal_handler_disconnect)) return false;
|
||||
|
||||
if (!load(lib_gtk, "g_object_get", g_object_get)) return false;
|
||||
if (!load(lib_gtk, "g_object_ref_sink", g_object_ref_sink)) return false;
|
||||
if (!load(lib_gtk, "g_object_unref", g_object_unref)) return false;
|
||||
if (!load(lib_gtk, "g_free", g_free)) return false;
|
||||
|
@ -132,6 +152,7 @@ bool setupGtkBase(QLibrary &lib_gtk) {
|
|||
|
||||
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||
f_gtk_init_check gtk_init_check = nullptr;
|
||||
f_gtk_settings_get_default gtk_settings_get_default = nullptr;
|
||||
f_gtk_menu_new gtk_menu_new = nullptr;
|
||||
f_gtk_menu_get_type gtk_menu_get_type = nullptr;
|
||||
f_gtk_menu_item_new_with_label gtk_menu_item_new_with_label = nullptr;
|
||||
|
@ -203,6 +224,7 @@ f_gtk_status_icon_get_geometry gtk_status_icon_get_geometry = nullptr;
|
|||
f_gtk_status_icon_position_menu gtk_status_icon_position_menu = nullptr;
|
||||
f_gtk_menu_popup gtk_menu_popup = nullptr;
|
||||
f_gtk_get_current_event_time gtk_get_current_event_time = nullptr;
|
||||
f_g_object_get g_object_get = nullptr;
|
||||
f_g_object_ref_sink g_object_ref_sink = nullptr;
|
||||
f_g_object_unref g_object_unref = nullptr;
|
||||
f_g_idle_add g_idle_add = nullptr;
|
||||
|
@ -215,8 +237,8 @@ f_g_slist_free g_slist_free = nullptr;
|
|||
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||
|
||||
void start() {
|
||||
DEBUG_LOG(("Loading libraries"));
|
||||
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||
DEBUG_LOG(("Loading libraries"));
|
||||
|
||||
bool gtkLoaded = false;
|
||||
bool isWayland = QGuiApplication::platformName().startsWith(qsl("wayland"), Qt::CaseInsensitive);
|
||||
|
@ -253,6 +275,19 @@ void start() {
|
|||
load(lib_gtk, "gtk_dialog_get_widget_for_response", gtk_dialog_get_widget_for_response);
|
||||
load(lib_gtk, "gtk_button_set_label", gtk_button_set_label);
|
||||
load(lib_gtk, "gtk_button_get_type", gtk_button_get_type);
|
||||
|
||||
// change the icon theme only if it isn't already set by a platformtheme plugin
|
||||
// if QT_QPA_PLATFORMTHEME=(gtk2|gtk3), then force-apply the icon theme
|
||||
if ((((QIcon::themeName() == qstr("hicolor") // QGenericUnixTheme
|
||||
&& QIcon::fallbackThemeName() == qstr("hicolor"))
|
||||
|| (QIcon::themeName() == qstr("Adwaita") // QGnomeTheme
|
||||
&& QIcon::fallbackThemeName() == qstr("gnome")))
|
||||
&& DesktopEnvironment::IsGtkBased())
|
||||
|| IsGtkIntegrationForced()) {
|
||||
DEBUG_LOG(("Set GTK icon theme"));
|
||||
QIcon::setThemeName(gtkSetting("gtk-icon-theme-name"));
|
||||
QIcon::setFallbackThemeName(gtkSetting("gtk-fallback-icon-theme"));
|
||||
}
|
||||
} else {
|
||||
LOG(("Could not load gtk-3 or gtk-x11-2.0!"));
|
||||
}
|
||||
|
|
|
@ -44,6 +44,9 @@ bool load(QLibrary &lib, const char *name, Function &func) {
|
|||
typedef gboolean (*f_gtk_init_check)(int *argc, char ***argv);
|
||||
extern f_gtk_init_check gtk_init_check;
|
||||
|
||||
typedef GtkSettings* (*f_gtk_settings_get_default)(void);
|
||||
extern f_gtk_settings_get_default gtk_settings_get_default;
|
||||
|
||||
typedef GtkWidget* (*f_gtk_menu_new)(void);
|
||||
extern f_gtk_menu_new gtk_menu_new;
|
||||
|
||||
|
@ -321,6 +324,9 @@ extern f_gtk_menu_popup gtk_menu_popup;
|
|||
typedef guint32 (*f_gtk_get_current_event_time)(void);
|
||||
extern f_gtk_get_current_event_time gtk_get_current_event_time;
|
||||
|
||||
typedef void (*f_g_object_get)(gpointer object, const gchar *first_property_name, ...) G_GNUC_NULL_TERMINATED;
|
||||
extern f_g_object_get g_object_get;
|
||||
|
||||
typedef gpointer (*f_g_object_ref_sink)(gpointer object);
|
||||
extern f_g_object_ref_sink g_object_ref_sink;
|
||||
|
||||
|
|
Loading…
Reference in New Issue