internal.h 7.31 KB
Newer Older
1
/* SPDX-License-Identifier: Zlib */
2 3 4 5

#ifndef GIRARA_INTERNAL_H
#define GIRARA_INTERNAL_H

6 7 8
#include <glib.h>
#include <gtk/gtk.h>

Sebastian Ramacher's avatar
Sebastian Ramacher committed
9
#include "types.h"
10
#include "macros.h"
Sebastian Ramacher's avatar
Sebastian Ramacher committed
11

12 13 14
#define FORMAT_COMMAND "<b>%s</b>"
#define FORMAT_DESCRIPTION "<i>%s</i>"

15
#define UNUSED(x) GIRARA_UNUSED(x)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
16
#define HIDDEN GIRARA_HIDDEN
17

Sebastian Ramacher's avatar
Sebastian Ramacher committed
18 19
#define LENGTH(x) (sizeof(x)/sizeof((x)[0]))

20
/**
21
 * Free girara_setting_t struct
22 23 24
 *
 * @param setting The setting to free.
 */
25 26 27 28
HIDDEN void girara_setting_free(girara_setting_t* setting);

HIDDEN void girara_config_handle_free(girara_config_handle_t* handle);

29 30 31 32 33 34
HIDDEN void girara_shortcut_mapping_free(girara_shortcut_mapping_t* mapping);

HIDDEN void girara_shortcut_free(girara_shortcut_t* shortcut);

HIDDEN void girara_inputbar_shortcut_free(girara_inputbar_shortcut_t* shortcut);

35 36 37
HIDDEN void girara_mode_string_free(girara_mode_string_t* mode);

HIDDEN void girara_statusbar_item_free(girara_statusbar_item_t* statusbaritem);
38

Moritz Lipp's avatar
Moritz Lipp committed
39 40
HIDDEN void girara_argument_mapping_free(
    girara_argument_mapping_t* argument_mapping);
41

Moritz Lipp's avatar
Moritz Lipp committed
42 43
HIDDEN void girara_special_command_free(
    girara_special_command_t* special_command);
44 45 46 47 48

HIDDEN void girara_command_free(girara_command_t* command);

HIDDEN void girara_mouse_event_free(girara_mouse_event_t* mouse_event);

49 50
HIDDEN void girara_config_load_default(girara_session_t* session);

51 52
HIDDEN void update_state_by_keyval(int *state, int keyval);

53 54
HIDDEN void widget_add_class(GtkWidget* widget, const char* styleclass);

55 56
HIDDEN void widget_remove_class(GtkWidget* widget, const char* styleclass);

57 58 59 60
HIDDEN void scrolled_window_set_scrollbar_visibility(GtkScrolledWindow* window,
                                                     bool show_horizontal,
                                                     bool show_vertical);

Sebastian Ramacher's avatar
Sebastian Ramacher committed
61 62 63 64 65 66
/**
 * Default complection function for the settings
 *
 * @param session The used girara session
 * @param input The current input
 */
Moritz Lipp's avatar
Moritz Lipp committed
67 68
HIDDEN girara_completion_t* girara_cc_set(girara_session_t* session,
    const char* input);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
69

Sebastian Ramacher's avatar
Sebastian Ramacher committed
70
/**
Sebastian Ramacher's avatar
Sebastian Ramacher committed
71
 * Default command to map sortcuts
Sebastian Ramacher's avatar
Sebastian Ramacher committed
72 73
 *
 * @param session The used girara session
Sebastian Ramacher's avatar
Sebastian Ramacher committed
74
 * @param argument_list List of passed arguments
75 76
 * @return TRUE No error occurred
 * @return FALSE An error occurred
Sebastian Ramacher's avatar
Sebastian Ramacher committed
77
 */
Moritz Lipp's avatar
Moritz Lipp committed
78 79
HIDDEN bool girara_cmd_map(girara_session_t* session,
    girara_list_t* argument_list);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
80

Moritz Lipp's avatar
Moritz Lipp committed
81 82 83 84 85
/**
 * Default command to unmap sortcuts
 *
 * @param session The used girara session
 * @param argument_list List of passed arguments
86 87
 * @return TRUE No error occurred
 * @return FALSE An error occurred
Moritz Lipp's avatar
Moritz Lipp committed
88
 */
Moritz Lipp's avatar
Moritz Lipp committed
89 90
HIDDEN bool girara_cmd_unmap(girara_session_t* session,
    girara_list_t* argument_list);
Moritz Lipp's avatar
Moritz Lipp committed
91

Sebastian Ramacher's avatar
Sebastian Ramacher committed
92
/**
Sebastian Ramacher's avatar
Sebastian Ramacher committed
93
 * Default command to quit the application
Sebastian Ramacher's avatar
Sebastian Ramacher committed
94 95
 *
 * @param session The used girara session
Sebastian Ramacher's avatar
Sebastian Ramacher committed
96
 * @param argument_list List of passed arguments
97 98
 * @return TRUE No error occurred
 * @return FALSE An error occurred
Sebastian Ramacher's avatar
Sebastian Ramacher committed
99
 */
Moritz Lipp's avatar
Moritz Lipp committed
100 101
HIDDEN bool girara_cmd_quit(girara_session_t* session,
    girara_list_t* argument_list);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
102 103

/**
Sebastian Ramacher's avatar
Sebastian Ramacher committed
104
 * Default command to set the value of settings
Sebastian Ramacher's avatar
Sebastian Ramacher committed
105 106
 *
 * @param session The used girara session
Sebastian Ramacher's avatar
Sebastian Ramacher committed
107
 * @param argument_list List of passed arguments
108 109
 * @return TRUE No error occurred
 * @return FALSE An error occurred
Sebastian Ramacher's avatar
Sebastian Ramacher committed
110
 */
Moritz Lipp's avatar
Moritz Lipp committed
111 112
HIDDEN bool girara_cmd_set(girara_session_t* session,
    girara_list_t* argument_list);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
113

Sebastian Ramacher's avatar
Sebastian Ramacher committed
114 115
/**
 * Execute an external command
116 117
 *
 * @param session The used girara session
Sebastian Ramacher's avatar
Sebastian Ramacher committed
118
 * @param argument_list List of passed arguments
119 120
 * @return TRUE No error occurred
 * @return FALSE An error occurred
Sebastian Ramacher's avatar
Sebastian Ramacher committed
121
 */
Moritz Lipp's avatar
Moritz Lipp committed
122 123
HIDDEN bool girara_cmd_exec(girara_session_t* session,
    girara_list_t* argument_list);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
124

125 126 127 128 129 130
#ifdef WITH_JSON
/**
 * Dump current settings to a JSON file
 *
 * @param session The used girara session
 * @param argument_list List of passed arguments
131 132
 * @return TRUE No error occurred
 * @return FALSE An error occurred
133 134 135 136 137
 */
HIDDEN bool girara_cmd_dump_config(girara_session_t* session,
    girara_list_t* argument_list);
#endif

Moritz Lipp's avatar
Moritz Lipp committed
138 139 140 141 142 143 144
/**
 * Process argument as a sequence of keys that were typed by the user
 *
 * @param session The session
 * @param argument The argument
 * @param event Event type
 * @param t Number of times
145 146
 * @return true No error occurred
 * @return false An error occurred
Moritz Lipp's avatar
Moritz Lipp committed
147 148 149 150
 */
HIDDEN bool girara_sc_feedkeys(girara_session_t* session, girara_argument_t* argument,
    girara_event_t* event, unsigned int t);

151 152
HIDDEN void css_template_fill_font(GiraraTemplate* csstemplate, const char* font);

153 154
HIDDEN int list_strcmp(const void* data1, const void* data2);

Sebastian Ramacher's avatar
Sebastian Ramacher committed
155 156 157 158 159 160 161 162
/**
 * Structure of a command
 */
struct girara_command_s
{
  char* command; /**< Name of the command */
  char* abbr; /**< Abbreviation of the command */
  girara_command_function_t function; /**< Function */
Moritz Lipp's avatar
Moritz Lipp committed
163
  girara_completion_function_t completion; /**< Completion function */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
164 165 166
  char* description; /**< Description of the command */
};

167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
struct girara_mode_string_s
{
  girara_mode_t index; /**< Index */
  char* name; /**< Name of the mode object */
};

/**
 * Shortcut mapping
 */
struct girara_shortcut_mapping_s
{
  char* identifier; /**> Identifier string */
  girara_shortcut_function_t function; /** Shortcut function */
};

/**
 * Argument mapping
 */
struct girara_argument_mapping_s
{
  char* identifier; /**> Identifier string */
  int value; /**> Value */
};

/**
 * Structure of a shortcut
 */
struct girara_shortcut_s
{
  guint mask; /**< Mask */
  guint key; /**< Key */
198
  char* buffered_command; /**< Buffer command */
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
  girara_shortcut_function_t function; /**< The correspondending function */
  girara_mode_t mode; /**< Mode identifier */
  girara_argument_t argument; /**< Given argument */
};

/**
 * Structure of a inputbar shortcut
 */
struct girara_inputbar_shortcut_s
{
  guint mask; /**< Mask */
  guint key; /**< Key */
  girara_shortcut_function_t function; /**< Function */
  girara_argument_t argument; /**< Given argument */
};

/**
 * Structure of a special command
 */
struct girara_special_command_s
{
  char identifier; /**< Identifier */
  girara_inputbar_special_function_t function; /**< Function */
  bool always; /**< Evalute on every change of the input */
  girara_argument_t argument; /**< Argument */
};

/**
 * Structure of a mouse event
 */
struct girara_mouse_event_s
{
  guint mask; /**< Mask */
  guint button; /**< Button */
  girara_shortcut_function_t function; /**< Function */
  girara_mode_t mode; /**< Allowed modes */
Moritz Lipp's avatar
Moritz Lipp committed
235
  girara_event_type_t event_type; /**< Event type */
236 237 238 239 240 241 242 243 244 245 246
  girara_argument_t argument; /**< Given argument */
};

/**
 * Config handle
 */
struct girara_config_handle_s
{
  char* identifier;
  girara_command_function_t handle;
};
Sebastian Ramacher's avatar
Sebastian Ramacher committed
247

248 249 250 251 252 253
/**
 * Structure of a statusbar item
 */
struct girara_statusbar_item_s
{
  GtkWidget* box; /**< Event box */
254
  GtkLabel*  text; /**< Text label */
255 256
};

257 258 259 260 261
/**
 * Private data of the girara session
 */
struct girara_session_private_s
{
262 263 264 265 266
  /**
   * Used in session-specific paths
   */
  char* session_name;

267 268 269 270
  /**
   * List of all settings
   */
  girara_list_t* settings;
271

272 273 274 275 276
  /**
   * Template enginge for CSS.
   */
  GiraraTemplate* csstemplate;

277 278
  struct
  {
279 280
    GtkWidget* overlay; /**< So we can overlay bottom_box on top of view */
    GtkBox*    bottom_box; /**< Box grouping input, status and notification */
281
    GtkCssProvider* cssprovider;
282
  } gtk;
283

284 285 286 287 288
  struct
  {
    girara_list_t* statusbar_items; /**< List of statusbar items */
  } elements;

289 290 291 292 293
  struct
  {
    int n; /**< Numeric buffer */
    GString *command; /**< Command in buffer */
  } buffer;
294 295 296 297 298 299 300

  struct
  {
    girara_list_t* handles;
    girara_list_t* shortcut_mappings;
    girara_list_t* argument_mappings;
  } config;
301 302
};

303
#endif