e_actions: Add ability to switch Config Profiles via keybinding

This commit is contained in:
Christopher Michael 2021-01-20 14:12:51 -05:00
parent c0f9749906
commit 3f2ddb4d1e
1 changed files with 70 additions and 0 deletions

View File

@ -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;