From 3f2ddb4d1e3d78596f72272f9c31867adbe16de4 Mon Sep 17 00:00:00 2001 From: Christopher Michael Date: Wed, 20 Jan 2021 14:12:51 -0500 Subject: [PATCH] e_actions: Add ability to switch Config Profiles via keybinding --- src/bin/e_actions.c | 70 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/bin/e_actions.c b/src/bin/e_actions.c index 1902ca7d9..7bcde40ef 100644 --- a/src/bin/e_actions.c +++ b/src/bin/e_actions.c @@ -3255,6 +3255,73 @@ _e_actions_post_init(void *d EINA_UNUSED) #endif } +ACT_FN_GO_KEY(profile_switch, , EINA_UNUSED) +{ + E_Action *a; + const char *cur_profile; + + if (!params) return; + + cur_profile = e_config_profile_get(); + + if (strcmp(cur_profile, params) == 0) return; + + e_config_save_flush(); + e_config_profile_set(params); + elm_config_profile_set(params); + e_config_profile_save(); + e_config_save_block_set(1); + + a = e_action_find("restart"); + if ((a) && (a->func.go)) a->func.go(NULL, NULL); +} + +static void +_e_actions_profiles_create(void) +{ + E_Action *act; + Eina_List *profiles, *l; + int i = 0; + + ACT_GO_KEY(profile_switch); + + profiles = e_config_profile_list(); + for (i = 0, l = profiles; l; l = l->next, i++) + { + Efreet_Desktop *desk = NULL; + char *prof, *pdir, buff[PATH_MAX]; + const char *label; + + prof = l->data; + + pdir = e_config_profile_dir_get(prof); + snprintf(buff, sizeof(buff), "%s/profile.desktop", pdir); + desk = efreet_desktop_new(buff); + if (!desk) + { + e_prefix_data_snprintf(buff, sizeof(buff), + "data/config/%s/", prof); + free(pdir); + pdir = strdup(buff); + if (pdir) + { + snprintf(buff, sizeof(buff), "%s/profile.desktop", pdir); + desk = efreet_desktop_new(buff); + } + } + + label = prof; + if ((desk) && (desk->name)) label = desk->name; + e_action_predef_name_set(N_("Profile: Switch"), label, + "profile_switch", prof, NULL, 0); + + free(prof); + free(pdir); + if (desk) efreet_desktop_free(desk); + } + if (profiles) eina_list_free(profiles); +} + /* externally accessible functions */ EINTERN int @@ -3840,6 +3907,9 @@ e_actions_init(void) N_("Previous keyboard layout"), "kbd_layout_prev", NULL, NULL, 0); + /* profiles */ + _e_actions_profiles_create(); + ecore_job_add(_e_actions_post_init, NULL); return 1;