summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <DaveDavenport@users.noreply.github.com>2017-11-02 21:05:07 +0100
committerGitHub <noreply@github.com>2017-11-02 21:05:07 +0100
commitf7d7fd4573178bd1e4de57287296c0992cefcb1e (patch)
treea1ff3c4ce5b91295b12f7ebef1762e468f41cd68
parentc3aa4fb5f3cc5ab7a65049b7c8ec48961969f09e (diff)
[DRun] Obey OnlyShowIn NotShowIn (#715)
* [DRun] Obey OnlyShowIn NotShowIn * Replace g_strv_contains.
-rw-r--r--source/dialogs/drun.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c
index 87efdd54..961b0e2f 100644
--- a/source/dialogs/drun.c
+++ b/source/dialogs/drun.c
@@ -127,6 +127,8 @@ typedef struct
// Theme
const gchar *icon_theme;
+ // DE
+ gchar **current_desktop_list;
} DRunModePrivateData;
struct RegexEvalArg
@@ -303,6 +305,42 @@ static gboolean read_desktop_file ( DRunModePrivateData *pd, const char *root, c
g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) );
return FALSE;
}
+ if ( pd->current_desktop_list ) {
+ gboolean show = TRUE;
+ // If the DE is set, check the keys.
+ if ( g_key_file_has_key ( kf, "Desktop Entry", "OnlyShowIn", NULL ) ) {
+ gsize llength = 0;
+ show = FALSE;
+ gchar **list = g_key_file_get_string_list ( kf, "Desktop Entry", "OnlyShowIn", &llength, NULL);
+ if ( list ) {
+ for ( gsize lcd = 0; !show && pd->current_desktop_list[lcd]; lcd++ ) {
+ for ( gsize lle = 0; !show && lle < llength; lle++ ) {
+ show = ( g_strcmp0 ( pd->current_desktop_list[lcd], list[lle] ) == 0 );
+ }
+ }
+ g_strfreev ( list );
+ }
+ }
+ if ( show && g_key_file_has_key ( kf, "Desktop Entry", "NotShowIn", NULL )) {
+ gsize llength = 0;
+ gchar **list = g_key_file_get_string_list ( kf, "Desktop Entry", "NotShowIn", &llength, NULL);
+ if ( list ) {
+ for ( gsize lcd = 0; show && pd->current_desktop_list[lcd]; lcd++ ) {
+ for ( gsize lle = 0; show && lle < llength; lle++ ) {
+ show = ! ( g_strcmp0 ( pd->current_desktop_list[lcd], list[lle] ) == 0 );
+ }
+ }
+ g_strfreev ( list );
+ }
+ }
+
+ if ( ! show ) {
+ g_debug ( "Adding desktop file: %s to disabled list because: OnlyShowIn/NotShowIn", path );
+ g_key_file_free ( kf );
+ g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) );
+ return FALSE;
+ }
+ }
// Skip entries that have NoDisplay set.
if ( g_key_file_get_boolean ( kf, "Desktop Entry", "NoDisplay", NULL ) ) {
g_debug ( "Adding desktop file: %s to disabled list because: NoDisplay", path );
@@ -628,6 +666,12 @@ static int drun_mode_init ( Mode *sw )
DRunModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
pd->disabled_entries = g_hash_table_new_full ( g_str_hash, g_str_equal, g_free, NULL );
mode_set_private_data ( sw, (void *) pd );
+ // current destkop
+ const char *current_desktop = g_getenv ( "XDG_CURRENT_DESKTOP" );
+ pd->current_desktop_list = current_desktop? g_strsplit(current_desktop, ":", 0) : NULL;
+
+
+ // Theme
pd->xdg_context = nk_xdg_theme_context_new ( drun_icon_fallback_themes, NULL );
nk_xdg_theme_preload_themes_icon ( pd->xdg_context, themes );
get_apps ( pd );
@@ -707,6 +751,8 @@ static void drun_mode_destroy ( Mode *sw )
g_hash_table_destroy ( rmpd->disabled_entries );
g_free ( rmpd->entry_list );
nk_xdg_theme_context_free ( rmpd->xdg_context );
+
+ g_strfreev ( rmpd->current_desktop_list );
g_free ( rmpd );
mode_set_private_data ( sw, NULL );
}