1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; either version 2 of the License, or
5  *  (at your option) any later version.
6  *
7  *  This program is distributed in the hope that it will be useful,
8  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *  GNU General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
15  *
16  *  Copyright (C) 2006-2016 XNeur Team
17  *
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23 
24 #include <stdlib.h>
25 
26 #ifdef WITH_XOSD
27 
28 #include <xosd.h>
29 #include <pthread.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdarg.h>
33 
34 #include "xnconfig.h"
35 
36 #include "debug.h"
37 #include "log.h"
38 #include "types.h"
39 
40 #include "osd.h"
41 
42 extern struct _xneur_config *xconfig;
43 
osd_show_thread(void * osd_text)44 static void osd_show_thread(void *osd_text)
45 {
46 	xosd *osd = xosd_create(1);
47 
48 	xosd_set_font(osd, xconfig->osd_font);
49 	xosd_set_colour(osd, "Red");
50 	xosd_set_timeout(osd, 2);
51 	xosd_set_shadow_offset(osd, 1);
52 	xosd_set_align(osd, XOSD_right);
53 
54 	xosd_display(osd, 0, XOSD_string, (char *) osd_text);
55 
56 	xosd_wait_until_no_display(osd);
57 	xosd_destroy(osd);
58 	free(osd_text);
59 }
60 
osd_show(int notify,char * command)61 void osd_show(int notify, char *command)
62 {
63 	if (!xconfig->show_osd)
64 		return;
65 
66 	if ((xconfig->osds[notify].file == NULL) && (command == NULL))
67 		return;
68 
69 	if (!xconfig->osds[notify].enabled)
70 		return;
71 
72 	pthread_attr_t osd_thread_attr;
73 	pthread_attr_init(&osd_thread_attr);
74 	pthread_attr_setdetachstate(&osd_thread_attr, PTHREAD_CREATE_DETACHED);
75 
76 	char *osd_text = malloc (sizeof(char));
77 	osd_text[0] = NULLSYM;
78 	if (xconfig->osds[notify].file != NULL)
79 	{
80 		char *tmp = realloc(osd_text, (strlen(osd_text) + strlen(xconfig->osds[notify].file) + 1) * sizeof(char));
81 		if (tmp != NULL)
82 		{
83 			osd_text = tmp;
84 			osd_text = strcat(osd_text, xconfig->osds[notify].file);
85 		}
86 	}
87 	if (command != NULL)
88 	{
89 		char *tmp = realloc(osd_text, (strlen(osd_text) + strlen(command) + 1) * sizeof(char));
90 		if (tmp != NULL)
91 		{
92 			osd_text = tmp;
93 			osd_text = strcat(osd_text, " ");
94 			osd_text = strcat(osd_text, command);
95 		}
96 	}
97 	//
98 	log_message(DEBUG, _("Show OSD \"%s\""), osd_text);
99 
100 	pthread_t osd_thread;
101 	pthread_create(&osd_thread, &osd_thread_attr, (void *) &osd_show_thread, osd_text);
102 
103 	pthread_attr_destroy(&osd_thread_attr);
104 	free(osd_text);
105 }
106 
107 #else /* WITH_XOSD */
108 
osd_show(int notify,char * command)109 void osd_show(int notify, char *command)
110 {
111 	if (notify || command) {};
112 	return;
113 }
114 
115 #endif /* WITH_XOSD */
116