1 /* SPDX-License-Identifier: Zlib */
2 
3 #ifndef GIRARA_INTERNAL_H
4 #define GIRARA_INTERNAL_H
5 
6 #include <glib.h>
7 #include <gtk/gtk.h>
8 
9 #include "types.h"
10 #include "macros.h"
11 
12 #define FORMAT_COMMAND "<b>%s</b>"
13 #define FORMAT_DESCRIPTION "<i>%s</i>"
14 
15 #define UNUSED(x) GIRARA_UNUSED(x)
16 #define HIDDEN GIRARA_HIDDEN
17 
18 #define LENGTH(x) (sizeof(x)/sizeof((x)[0]))
19 
20 /**
21  * Free girara_setting_t struct
22  *
23  * @param setting The setting to free.
24  */
25 HIDDEN void girara_setting_free(girara_setting_t* setting);
26 
27 HIDDEN void girara_config_handle_free(girara_config_handle_t* handle);
28 
29 HIDDEN void girara_shortcut_mapping_free(girara_shortcut_mapping_t* mapping);
30 
31 HIDDEN void girara_shortcut_free(girara_shortcut_t* shortcut);
32 
33 HIDDEN void girara_inputbar_shortcut_free(girara_inputbar_shortcut_t* shortcut);
34 
35 HIDDEN void girara_mode_string_free(girara_mode_string_t* mode);
36 
37 HIDDEN void girara_statusbar_item_free(girara_statusbar_item_t* statusbaritem);
38 
39 HIDDEN void girara_argument_mapping_free(
40     girara_argument_mapping_t* argument_mapping);
41 
42 HIDDEN void girara_special_command_free(
43     girara_special_command_t* special_command);
44 
45 HIDDEN void girara_command_free(girara_command_t* command);
46 
47 HIDDEN void girara_mouse_event_free(girara_mouse_event_t* mouse_event);
48 
49 HIDDEN void girara_config_load_default(girara_session_t* session);
50 
51 HIDDEN void widget_add_class(GtkWidget* widget, const char* styleclass);
52 
53 HIDDEN void widget_remove_class(GtkWidget* widget, const char* styleclass);
54 
55 HIDDEN void scrolled_window_set_scrollbar_visibility(GtkScrolledWindow* window,
56                                                      bool show_horizontal,
57                                                      bool show_vertical);
58 
59 /**
60  * Default complection function for the settings
61  *
62  * @param session The used girara session
63  * @param input The current input
64  */
65 HIDDEN girara_completion_t* girara_cc_set(girara_session_t* session,
66     const char* input);
67 
68 /**
69  * Default command to map sortcuts
70  *
71  * @param session The used girara session
72  * @param argument_list List of passed arguments
73  * @return TRUE No error occurred
74  * @return FALSE An error occurred
75  */
76 HIDDEN bool girara_cmd_map(girara_session_t* session,
77     girara_list_t* argument_list);
78 
79 /**
80  * Default command to unmap sortcuts
81  *
82  * @param session The used girara session
83  * @param argument_list List of passed arguments
84  * @return TRUE No error occurred
85  * @return FALSE An error occurred
86  */
87 HIDDEN bool girara_cmd_unmap(girara_session_t* session,
88     girara_list_t* argument_list);
89 
90 /**
91  * Default command to quit the application
92  *
93  * @param session The used girara session
94  * @param argument_list List of passed arguments
95  * @return TRUE No error occurred
96  * @return FALSE An error occurred
97  */
98 HIDDEN bool girara_cmd_quit(girara_session_t* session,
99     girara_list_t* argument_list);
100 
101 /**
102  * Default command to set the value of settings
103  *
104  * @param session The used girara session
105  * @param argument_list List of passed arguments
106  * @return TRUE No error occurred
107  * @return FALSE An error occurred
108  */
109 HIDDEN bool girara_cmd_set(girara_session_t* session,
110     girara_list_t* argument_list);
111 
112 /**
113  * Execute an external command
114  *
115  * @param session The used girara session
116  * @param argument_list List of passed arguments
117  * @return TRUE No error occurred
118  * @return FALSE An error occurred
119  */
120 HIDDEN bool girara_cmd_exec(girara_session_t* session,
121     girara_list_t* argument_list);
122 
123 #ifdef WITH_JSON
124 /**
125  * Dump current settings to a JSON file
126  *
127  * @param session The used girara session
128  * @param argument_list List of passed arguments
129  * @return TRUE No error occurred
130  * @return FALSE An error occurred
131  */
132 HIDDEN bool girara_cmd_dump_config(girara_session_t* session,
133     girara_list_t* argument_list);
134 #endif
135 
136 /**
137  * Process argument as a sequence of keys that were typed by the user
138  *
139  * @param session The session
140  * @param argument The argument
141  * @param event Event type
142  * @param t Number of times
143  * @return true No error occurred
144  * @return false An error occurred
145  */
146 HIDDEN bool girara_sc_feedkeys(girara_session_t* session, girara_argument_t* argument,
147     girara_event_t* event, unsigned int t);
148 
149 HIDDEN void css_template_fill_font(GiraraTemplate* csstemplate, const char* font);
150 
151 HIDDEN int list_strcmp(const void* data1, const void* data2);
152 
153 /**
154  * Structure of a command
155  */
156 struct girara_command_s
157 {
158   char* command; /**< Name of the command */
159   char* abbr; /**< Abbreviation of the command */
160   girara_command_function_t function; /**< Function */
161   girara_completion_function_t completion; /**< Completion function */
162   char* description; /**< Description of the command */
163 };
164 
165 struct girara_mode_string_s
166 {
167   girara_mode_t index; /**< Index */
168   char* name; /**< Name of the mode object */
169 };
170 
171 /**
172  * Shortcut mapping
173  */
174 struct girara_shortcut_mapping_s
175 {
176   char* identifier; /**> Identifier string */
177   girara_shortcut_function_t function; /** Shortcut function */
178 };
179 
180 /**
181  * Argument mapping
182  */
183 struct girara_argument_mapping_s
184 {
185   char* identifier; /**> Identifier string */
186   int value; /**> Value */
187 };
188 
189 /**
190  * Structure of a shortcut
191  */
192 struct girara_shortcut_s
193 {
194   guint mask; /**< Mask */
195   guint key; /**< Key */
196   char* buffered_command; /**< Buffer command */
197   girara_shortcut_function_t function; /**< The correspondending function */
198   girara_mode_t mode; /**< Mode identifier */
199   girara_argument_t argument; /**< Given argument */
200 };
201 
202 /**
203  * Structure of a inputbar shortcut
204  */
205 struct girara_inputbar_shortcut_s
206 {
207   guint mask; /**< Mask */
208   guint key; /**< Key */
209   girara_shortcut_function_t function; /**< Function */
210   girara_argument_t argument; /**< Given argument */
211 };
212 
213 /**
214  * Structure of a special command
215  */
216 struct girara_special_command_s
217 {
218   char identifier; /**< Identifier */
219   girara_inputbar_special_function_t function; /**< Function */
220   bool always; /**< Evalute on every change of the input */
221   girara_argument_t argument; /**< Argument */
222 };
223 
224 /**
225  * Structure of a mouse event
226  */
227 struct girara_mouse_event_s
228 {
229   guint mask; /**< Mask */
230   guint button; /**< Button */
231   girara_shortcut_function_t function; /**< Function */
232   girara_mode_t mode; /**< Allowed modes */
233   girara_event_type_t event_type; /**< Event type */
234   girara_argument_t argument; /**< Given argument */
235 };
236 
237 /**
238  * Config handle
239  */
240 struct girara_config_handle_s
241 {
242   char* identifier;
243   girara_command_function_t handle;
244 };
245 
246 /**
247  * Structure of a statusbar item
248  */
249 struct girara_statusbar_item_s
250 {
251   GtkWidget* box; /**< Event box */
252   GtkLabel*  text; /**< Text label */
253 };
254 
255 /**
256  * Private data of the girara session
257  */
258 struct girara_session_private_s
259 {
260   /**
261    * Used in session-specific paths
262    */
263   char* session_name;
264 
265   /**
266    * List of all settings
267    */
268   girara_list_t* settings;
269 
270   /**
271    * Template enginge for CSS.
272    */
273   GiraraTemplate* csstemplate;
274 
275   struct
276   {
277     GtkWidget* overlay; /**< So we can overlay bottom_box on top of view */
278     GtkBox*    bottom_box; /**< Box grouping input, status and notification */
279     GtkCssProvider* cssprovider;
280   } gtk;
281 
282   struct
283   {
284     girara_list_t* statusbar_items; /**< List of statusbar items */
285   } elements;
286 
287   struct
288   {
289     int n; /**< Numeric buffer */
290     GString *command; /**< Command in buffer */
291   } buffer;
292 
293   struct
294   {
295     girara_list_t* handles;
296     girara_list_t* shortcut_mappings;
297     girara_list_t* argument_mappings;
298   } config;
299 
300   GMutex feedkeys_mutex;
301 };
302 
303 #endif
304