summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2019-10-20 18:16:10 +0200
committerBoris Faure <billiob@gmail.com>2019-10-20 18:16:10 +0200
commit71ee21af324fa20720954c9e1a9330fc4fd4cdd1 (patch)
treea12fa9b99ba7efedec31d358a6cc3de1a9d06aad
parent984d7e07c629ff078c7a000f4a261674f365db51 (diff)
main: only one place to configure a running instance
-rw-r--r--src/bin/ipc.c10
-rw-r--r--src/bin/ipc.h3
-rw-r--r--src/bin/main.c279
3 files changed, 137 insertions, 155 deletions
diff --git a/src/bin/ipc.c b/src/bin/ipc.c
index 318d5a7..c848e4f 100644
--- a/src/bin/ipc.c
+++ b/src/bin/ipc.c
@@ -131,6 +131,16 @@ ipc_init(void)
131 "hold", hold, EET_T_INT); 131 "hold", hold, EET_T_INT);
132 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance, 132 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
133 "nowm", nowm, EET_T_INT); 133 "nowm", nowm, EET_T_INT);
134 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
135 "xterm_256color", xterm_256color, EET_T_INT);
136 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
137 "active_links", active_links, EET_T_INT);
138 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
139 "video_mute", active_links, EET_T_INT);
140 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
141 "cursor_blink", active_links, EET_T_INT);
142 EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
143 "visual_bell", active_links, EET_T_INT);
134} 144}
135 145
136Eina_Bool 146Eina_Bool
diff --git a/src/bin/ipc.h b/src/bin/ipc.h
index 2290703..0aa4775 100644
--- a/src/bin/ipc.h
+++ b/src/bin/ipc.h
@@ -29,7 +29,10 @@ struct _Ipc_Instance
29 Eina_Bool hold; 29 Eina_Bool hold;
30 Eina_Bool nowm; 30 Eina_Bool nowm;
31 Eina_Bool xterm_256color; 31 Eina_Bool xterm_256color;
32 Eina_Bool video_mute;
32 Eina_Bool active_links; 33 Eina_Bool active_links;
34 Eina_Bool cursor_blink;
35 Eina_Bool visual_bell;
33 Config *config; 36 Config *config;
34}; 37};
35 38
diff --git a/src/bin/main.c b/src/bin/main.c
index 8e0bcad..4aabc07 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -51,6 +51,105 @@ _set_instance_theme(Ipc_Instance *inst)
51} 51}
52 52
53static void 53static void
54_configure_instance(Ipc_Instance *inst)
55{
56 Config *config = inst->config;
57
58 _set_instance_theme(inst);
59
60 if (inst->background)
61 {
62 eina_stringshare_replace(&(config->background), inst->background);
63 config->temporary = EINA_TRUE;
64 }
65
66 if (inst->font)
67 {
68 char *p = strchr(inst->font, '/');
69 if (p)
70 {
71 int sz;
72 char *fname = alloca(p - inst->font + 1);
73
74 strncpy(fname, inst->font, p - inst->font);
75 fname[p - inst->font] = '\0';
76 sz = atoi(p+1);
77 if (sz > 0)
78 inst->config->font.size = sz;
79 eina_stringshare_replace(&(inst->config->font.name), fname);
80 inst->config->font.bitmap = EINA_FALSE;
81 }
82 else
83 {
84 char buf[4096], *file;
85 Eina_List *files;
86 int n = strlen(inst->font);
87 Eina_Bool found = EINA_FALSE;
88
89 snprintf(buf, sizeof(buf), "%s/fonts", elm_app_data_dir_get());
90 files = ecore_file_ls(buf);
91 EINA_LIST_FREE(files, file)
92 {
93 if (n > 0)
94 {
95 if (!strncasecmp(file, inst->font, n))
96 {
97 n = -1;
98 eina_stringshare_replace(&(inst->config->font.name), file);
99 inst->config->font.bitmap = EINA_TRUE;
100 found = EINA_TRUE;
101 }
102 }
103 free(file);
104 }
105 if (!found)
106 {
107 ERR("font '%s' not found in %s", inst->font, buf);
108 }
109 }
110 config->font_set = EINA_TRUE;
111 config->temporary = EINA_TRUE;
112 }
113
114 if (inst->login_shell)
115 {
116 inst->config->login_shell = inst->login_shell;
117 inst->config->temporary = EINA_TRUE;
118 }
119 inst->login_shell = inst->config->login_shell;
120
121 if (inst->xterm_256color)
122 {
123 inst->config->xterm_256color = EINA_TRUE;
124 inst->config->temporary = EINA_TRUE;
125 }
126 if (inst->video_mute != 0xff)
127 {
128 config->mute = inst->video_mute;
129 config->temporary = EINA_TRUE;
130 }
131 if (inst->cursor_blink != 0xff)
132 {
133 config->disable_cursor_blink = !inst->cursor_blink;
134 config->temporary = EINA_TRUE;
135 }
136 if (inst->visual_bell != 0xff)
137 {
138 config->disable_visual_bell = !inst->visual_bell;
139 config->temporary = EINA_TRUE;
140 }
141 if (inst->active_links != 0xff)
142 {
143 config->active_links = !!inst->active_links;
144 config->active_links_email = inst->config->active_links;
145 config->active_links_file = inst->config->active_links;
146 config->active_links_url = inst->config->active_links;
147 config->active_links_escape = inst->config->active_links;
148 config->temporary = EINA_TRUE;
149 }
150}
151
152static void
54_check_multisense(void) 153_check_multisense(void)
55{ 154{
56 int enabled; 155 int enabled;
@@ -117,6 +216,9 @@ main_ipc_new(Ipc_Instance *inst)
117 if (inst->nowm) nargc += 1; 216 if (inst->nowm) nargc += 1;
118 if (inst->xterm_256color) nargc += 1; 217 if (inst->xterm_256color) nargc += 1;
119 if (inst->active_links) nargc += 1; 218 if (inst->active_links) nargc += 1;
219 if (inst->video_mute) nargc += 1;
220 if (inst->cursor_blink) nargc += 1;
221 if (inst->visual_bell) nargc += 1;
120 if (inst->cmd) nargc += 2; 222 if (inst->cmd) nargc += 2;
121 if (inst->theme) nargc += 2; 223 if (inst->theme) nargc += 2;
122 224
@@ -262,6 +364,19 @@ main_ipc_new(Ipc_Instance *inst)
262 nargv[i++] = "-e"; 364 nargv[i++] = "-e";
263 nargv[i++] = (char *)inst->cmd; 365 nargv[i++] = (char *)inst->cmd;
264 } 366 }
367 if (inst->video_mute)
368 {
369 nargv[i++] = "-m";
370 }
371 if (inst->cursor_blink)
372 {
373 nargv[i++] = "-c";
374 }
375 if (inst->visual_bell)
376 {
377 nargv[i++] = "-G";
378 }
379
265 380
266 ecore_app_args_set(nargc, (const char **)nargv); 381 ecore_app_args_set(nargc, (const char **)nargv);
267 wn = win_new(inst->name, inst->role, inst->title, inst->icon_name, 382 wn = win_new(inst->name, inst->role, inst->title, inst->icon_name,
@@ -279,60 +394,7 @@ main_ipc_new(Ipc_Instance *inst)
279 config = win_config_get(wn); 394 config = win_config_get(wn);
280 inst->config = config; 395 inst->config = config;
281 396
282 _set_instance_theme(inst); 397 _configure_instance(inst);
283
284 if (inst->background)
285 {
286 eina_stringshare_replace(&(config->background), inst->background);
287 config->temporary = EINA_TRUE;
288 }
289
290 if (inst->font)
291 {
292 if (strchr(inst->font, '/'))
293 {
294 char *fname = alloca(strlen(inst->font) + 1);
295 char *p;
296
297 strcpy(fname, inst->font);
298 p = strrchr(fname, '/');
299 if (p)
300 {
301 int sz;
302
303 *p = 0;
304 p++;
305 sz = atoi(p);
306 if (sz > 0) config->font.size = sz;
307 eina_stringshare_replace(&(config->font.name), fname);
308 }
309 config->font.bitmap = 0;
310 }
311 else
312 {
313 char buf[4096], *file;
314 Eina_List *files;
315 int n = strlen(inst->font);
316
317 snprintf(buf, sizeof(buf), "%s/fonts", elm_app_data_dir_get());
318 files = ecore_file_ls(buf);
319 EINA_LIST_FREE(files, file)
320 {
321 if (n > 0)
322 {
323 if (!strncasecmp(file, inst->font, n))
324 {
325 n = -1;
326 eina_stringshare_replace(&(config->font.name), file);
327 config->font.bitmap = 1;
328 }
329 }
330 free(file);
331 }
332 }
333 config->font_set = EINA_TRUE;
334 config->temporary = EINA_TRUE;
335 }
336 398
337 if (inst->w <= 0) inst->w = 80; 399 if (inst->w <= 0) inst->w = 80;
338 if (inst->h <= 0) inst->h = 24; 400 if (inst->h <= 0) inst->h = 24;
@@ -732,16 +794,15 @@ elm_main(int argc, char **argv)
732{ 794{
733 char *geometry = NULL; 795 char *geometry = NULL;
734 char *video_module = NULL; 796 char *video_module = NULL;
735 Eina_Bool video_mute = 0xff; /* unset */
736 Eina_Bool cursor_blink = 0xff; /* unset */
737 Eina_Bool visual_bell = 0xff; /* unset */
738 Eina_Bool quit_option = EINA_FALSE; 797 Eina_Bool quit_option = EINA_FALSE;
739 Eina_Bool single = EINA_FALSE; 798 Eina_Bool single = EINA_FALSE;
740 Eina_Bool cmd_options = EINA_FALSE; 799 Eina_Bool cmd_options = EINA_FALSE;
741 Eina_Bool xterm_256color = EINA_FALSE;
742 Ipc_Instance instance = { 800 Ipc_Instance instance = {
743 .login_shell = 0xff, /* unset */ 801 .login_shell = 0xff, /* unset */
744 .active_links = 0xff, /* unset */ 802 .active_links = 0xff, /* unset */
803 .video_mute = 0xff, /* unset */
804 .cursor_blink = 0xff, /* unset */
805 .visual_bell = 0xff, /* unset */
745 .startup_id = getenv("DESKTOP_STARTUP_ID"), 806 .startup_id = getenv("DESKTOP_STARTUP_ID"),
746 .w = 1, 807 .w = 1,
747 .h = 1, 808 .h = 1,
@@ -761,9 +822,9 @@ elm_main(int argc, char **argv)
761 ECORE_GETOPT_VALUE_STR(video_module), 822 ECORE_GETOPT_VALUE_STR(video_module),
762 823
763 ECORE_GETOPT_VALUE_BOOL(instance.login_shell), 824 ECORE_GETOPT_VALUE_BOOL(instance.login_shell),
764 ECORE_GETOPT_VALUE_BOOL(video_mute), 825 ECORE_GETOPT_VALUE_BOOL(instance.video_mute),
765 ECORE_GETOPT_VALUE_BOOL(cursor_blink), 826 ECORE_GETOPT_VALUE_BOOL(instance.cursor_blink),
766 ECORE_GETOPT_VALUE_BOOL(visual_bell), 827 ECORE_GETOPT_VALUE_BOOL(instance.visual_bell),
767 ECORE_GETOPT_VALUE_BOOL(instance.fullscreen), 828 ECORE_GETOPT_VALUE_BOOL(instance.fullscreen),
768 ECORE_GETOPT_VALUE_BOOL(instance.iconic), 829 ECORE_GETOPT_VALUE_BOOL(instance.iconic),
769 ECORE_GETOPT_VALUE_BOOL(instance.borderless), 830 ECORE_GETOPT_VALUE_BOOL(instance.borderless),
@@ -772,7 +833,7 @@ elm_main(int argc, char **argv)
772 ECORE_GETOPT_VALUE_BOOL(instance.nowm), 833 ECORE_GETOPT_VALUE_BOOL(instance.nowm),
773 ECORE_GETOPT_VALUE_BOOL(instance.hold), 834 ECORE_GETOPT_VALUE_BOOL(instance.hold),
774 ECORE_GETOPT_VALUE_BOOL(single), 835 ECORE_GETOPT_VALUE_BOOL(single),
775 ECORE_GETOPT_VALUE_BOOL(xterm_256color), 836 ECORE_GETOPT_VALUE_BOOL(instance.xterm_256color),
776 ECORE_GETOPT_VALUE_BOOL(instance.active_links), 837 ECORE_GETOPT_VALUE_BOOL(instance.active_links),
777 838
778 ECORE_GETOPT_VALUE_BOOL(quit_option), 839 ECORE_GETOPT_VALUE_BOOL(quit_option),
@@ -881,63 +942,8 @@ elm_main(int argc, char **argv)
881 942
882 _check_multisense(); 943 _check_multisense();
883 944
884 _set_instance_theme(&instance); 945 _configure_instance(&instance);
885
886 if (instance.background)
887 {
888 eina_stringshare_replace(&(instance.config->background),
889 instance.background);
890 instance.config->temporary = EINA_TRUE;
891 }
892
893 if (instance.font)
894 {
895 char *p = strchr(instance.font, '/');
896 if (p)
897 {
898 int sz;
899 char *fname = alloca(p - instance.font + 1);
900
901 strncpy(fname, instance.font, p - instance.font);
902 fname[p - instance.font] = '\0';
903 sz = atoi(p+1);
904 if (sz > 0)
905 instance.config->font.size = sz;
906 eina_stringshare_replace(&(instance.config->font.name), fname);
907 instance.config->font.bitmap = 0;
908 instance.config->font_set = 1;
909 }
910 else
911 {
912 char buf[4096], *file;
913 Eina_List *files;
914 int n = strlen(instance.font);
915 Eina_Bool found = EINA_FALSE;
916 946
917 snprintf(buf, sizeof(buf), "%s/fonts", elm_app_data_dir_get());
918 files = ecore_file_ls(buf);
919 EINA_LIST_FREE(files, file)
920 {
921 if (n > 0)
922 {
923 if (!strncasecmp(file, instance.font, n))
924 {
925 n = -1;
926 eina_stringshare_replace(&(instance.config->font.name), file);
927 instance.config->font.bitmap = 1;
928 instance.config->font_set = 1;
929 found = EINA_TRUE;
930 }
931 }
932 free(file);
933 }
934 if (!found)
935 {
936 ERR("font '%s' not found in %s", instance.font, buf);
937 }
938 }
939 instance.config->temporary = EINA_TRUE;
940 }
941 947
942 if (video_module) 948 if (video_module)
943 { 949 {
@@ -954,36 +960,6 @@ elm_main(int argc, char **argv)
954 instance.config->temporary = EINA_TRUE; 960 instance.config->temporary = EINA_TRUE;
955 } 961 }
956 962
957 if (video_mute != 0xff)
958 {
959 instance.config->mute = video_mute;
960 instance.config->temporary = EINA_TRUE;
961 }
962 if (cursor_blink != 0xff)
963 {
964 instance.config->disable_cursor_blink = !cursor_blink;
965 instance.config->temporary = EINA_TRUE;
966 }
967 if (visual_bell != 0xff)
968 {
969 instance.config->disable_visual_bell = !visual_bell;
970 instance.config->temporary = EINA_TRUE;
971 }
972 if (instance.active_links != 0xff)
973 {
974 instance.config->active_links = !!instance.active_links;
975 instance.config->active_links_email = instance.config->active_links;
976 instance.config->active_links_file = instance.config->active_links;
977 instance.config->active_links_url = instance.config->active_links;
978 instance.config->active_links_escape = instance.config->active_links;
979 instance.config->temporary = EINA_TRUE;
980 }
981
982 if (xterm_256color)
983 {
984 instance.config->xterm_256color = EINA_TRUE;
985 instance.config->temporary = EINA_TRUE;
986 }
987 963
988 if (geometry) 964 if (geometry)
989 { 965 {
@@ -1055,13 +1031,6 @@ elm_main(int argc, char **argv)
1055 } 1031 }
1056 } 1032 }
1057 1033
1058 if (instance.login_shell != 0xff)
1059 {
1060 instance.config->login_shell = instance.login_shell;
1061 instance.config->temporary = EINA_TRUE;
1062 }
1063 instance.login_shell = instance.config->login_shell;
1064
1065 elm_theme_overlay_add(NULL, 1034 elm_theme_overlay_add(NULL,
1066 config_theme_path_default_get(instance.config)); 1035 config_theme_path_default_get(instance.config));
1067 elm_theme_overlay_add(NULL, config_theme_path_get(instance.config)); 1036 elm_theme_overlay_add(NULL, config_theme_path_get(instance.config));