session.h 7.56 KB
Newer Older
Sebastian Ramacher's avatar
Sebastian Ramacher committed
1 2 3 4 5
/* See LICENSE file for license and copyright information */

#ifndef GIRARA_SESSION_H
#define GIRARA_SESSION_H

Sebastian Ramacher's avatar
Sebastian Ramacher committed
6
#include "types.h"
7
#include "macros.h"
Moritz Lipp's avatar
Moritz Lipp committed
8
#include "callbacks.h"
Sebastian Ramacher's avatar
Sebastian Ramacher committed
9 10

#include <gtk/gtk.h>
Sebastian Ramacher's avatar
Sebastian Ramacher committed
11

12
#ifdef GDK_WINDOWING_X11
Sebastian Ramacher's avatar
Sebastian Ramacher committed
13
#include <gtk/gtkx.h>
Sebastian Ramacher's avatar
Sebastian Ramacher committed
14
#else
15 16 17
typedef int Window;
#endif

Sebastian Ramacher's avatar
Sebastian Ramacher committed
18 19 20 21 22 23 24 25 26 27 28 29
struct girara_session_s
{
  struct
  {
    GtkWidget       *window; /**< The main window of the application */
    GtkBox          *box; /**< A box that contains all widgets */
    GtkWidget       *view; /**< The view area of the applications widgets */
    GtkWidget       *viewport; /**< The viewport of view */
    GtkWidget       *statusbar; /**< The statusbar */
    GtkBox          *statusbar_entries; /**< Statusbar entry box */
    GtkWidget       *notification_area; /**< The notification area */
    GtkWidget       *notification_text; /**< The notification entry */
Moritz Lipp's avatar
Moritz Lipp committed
30 31 32 33
    GtkBox          *inputbar_box; /**< Inputbar box */
    GtkWidget       *inputbar; /**< Inputbar event box */
    GtkLabel        *inputbar_dialog; /**< Inputbar dialog */
    GtkEntry        *inputbar_entry; /**< Inputbar entry */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
34
    GtkBox          *results; /**< Completion results */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
35
    Window          embed; /**< Embedded window */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
36 37 38 39
  } gtk;

  struct
  {
40 41
    girara_list_t* mouse_events; /**< List of mouse events */
    girara_list_t* commands; /**< List of commands */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
42
    girara_list_t* shortcuts; /**< List of shortcuts */
43
    girara_list_t* special_commands; /**< List of special commands */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
44 45 46 47 48 49 50
    girara_list_t* inputbar_shortcuts; /**< List of inputbar shortcuts */
  } bindings;

  struct
  {
    int inputbar_activate; /**< Inputbar activation */
    int inputbar_key_pressed; /**< Pressed key in inputbar */
51
    int inputbar_changed; /**< Inputbar text changed */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
52
    int view_key_pressed; /**< Pressed key in view */
Moritz Lipp's avatar
Moritz Lipp committed
53 54 55
    int view_button_press_event; /**< Pressed button */
    int view_button_release_event; /**< Released button */
    int view_motion_notify_event; /**< Cursor movement event */
56
    int view_scroll_event; /**< Scroll event */
Moritz Lipp's avatar
Moritz Lipp committed
57 58
    girara_callback_inputbar_activate_t inputbar_custom_activate; /**< Custom handler */
    girara_callback_inputbar_key_press_event_t inputbar_custom_key_press_event; /**< Custom handler */
Moritz Lipp's avatar
Moritz Lipp committed
59
    void* inputbar_custom_data; /**< Data for custom handler */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
60 61 62 63
  } signals;

  struct
  {
Moritz Lipp's avatar
Moritz Lipp committed
64 65
    void (*buffer_changed)(girara_session_t* session); /**< Buffer changed */
    bool (*unknown_command)(girara_session_t* session, const char* input); /**< Unknown command */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
66 67 68 69 70 71
  } events;

  struct
  {
    GString *buffer; /**< Buffer */
    void* data; /**< User data */
Moritz Lipp's avatar
Moritz Lipp committed
72
    bool autohide_inputbar; /**< Auto-hide inputbar */
73
    bool hide_statusbar; /**< Hide statusbar */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
74 75 76 77 78 79 80
  } global;

  struct
  {
    girara_mode_t current_mode; /**< Current mode */
    girara_list_t *identifiers; /**< List of modes with its string identifiers */
    girara_mode_t normal; /**< The normal mode */
81
    girara_mode_t inputbar; /**< The inputbar mode */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
82 83
  } modes;

Sebastian Ramacher's avatar
Sebastian Ramacher committed
84
  GiraraInputHistory* command_history; /**< Command history */
85
  girara_session_private_t* private_data; /**< Private data of a girara session */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
86 87 88 89 90 91
};

/**
 * Creates a girara session
 *
 * @return A valid session object
92
 * @return NULL when an error occurred
Sebastian Ramacher's avatar
Sebastian Ramacher committed
93
 */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
94
girara_session_t* girara_session_create(void);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
95 96 97 98 99

/**
 * Initializes an girara session
 *
 * @param session The used girara session
100
 * @param appname Name of the session (can be NULL)
101 102
 * @return TRUE No error occurred
 * @return FALSE An error occurred
Sebastian Ramacher's avatar
Sebastian Ramacher committed
103
 */
104
bool girara_session_init(girara_session_t* session, const char* appname);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
105 106 107 108 109

/**
 * Destroys an girara session
 *
 * @param session The used girara session
110 111
 * @return TRUE No error occurred
 * @return FALSE An error occurred
Sebastian Ramacher's avatar
Sebastian Ramacher committed
112 113 114
 */
bool girara_session_destroy(girara_session_t* session);

115 116 117 118 119
/**
 * Sets the view widget of girara
 *
 * @param session The used girara session
 * @param widget The widget that should be displayed
120 121
 * @return TRUE No error occurred
 * @return FALSE An error occurred
122 123 124 125 126 127 128 129 130 131 132
 */
bool girara_set_view(girara_session_t* session, GtkWidget* widget);

/**
 * Returns a copy of the buffer
 *
 * @param session The used girara session
 * @return Copy of the current buffer
 */
char* girara_buffer_get(girara_session_t* session);

133
/**
134 135 136
 * Displays a notification popup for the user using libnotify. Basic styling
 * is allowed using Pango's markup format:
 * <https://developer.gnome.org/pango/stable/PangoMarkupFormat.html>
137 138 139 140 141 142 143 144
 *
 * @param session The girara session
 * @param summary The title
 * @param body The content
 */
void girara_libnotify(girara_session_t* session, const char *summary,
    const char *body);

Sebastian Ramacher's avatar
Sebastian Ramacher committed
145 146 147 148 149 150 151 152 153
/**
 * Displays a notification for the user. It is possible to pass GIRARA_INFO,
 * GIRARA_WARNING or GIRARA_ERROR as a notification level.
 *
 * @param session The girara session
 * @param level The level
 * @param format String format
 * @param ...
 */
Moritz Lipp's avatar
Moritz Lipp committed
154 155
void girara_notify(girara_session_t* session, int level,
    const char* format, ...) GIRARA_PRINTF(3, 4);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
156

Moritz Lipp's avatar
Moritz Lipp committed
157 158 159 160 161 162 163 164
/**
 * Creates a girara dialog
 *
 * @param session The girara session
 * @param dialog The dialog message
 * @param invisible Sets the input visibility
 * @param key_press_event Callback function to a custom key press event handler
 * @param activate_event Callback function to a custom activate event handler
Moritz Lipp's avatar
Moritz Lipp committed
165
 * @param data Custom data that is passed to the callback functions
Moritz Lipp's avatar
Moritz Lipp committed
166 167 168
 */
void girara_dialog(girara_session_t* session, const char* dialog, bool
    invisible, girara_callback_inputbar_key_press_event_t key_press_event,
Moritz Lipp's avatar
Moritz Lipp committed
169
    girara_callback_inputbar_activate_t activate_event, void* data);
Moritz Lipp's avatar
Moritz Lipp committed
170

Sebastian Ramacher's avatar
Sebastian Ramacher committed
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
/**
 * Adds a new mode by its string identifier
 *
 * @param session The used girara session
 * @param name The string identifier used in configs/inputbar etc to refer by
 * @return A newly defined girara_mode_t associated with name
 */
girara_mode_t girara_mode_add(girara_session_t* session, const char* name);

/**
 * Sets the current mode
 *
 * @param session The used girara session
 * @param mode The new mode
 */
void girara_mode_set(girara_session_t* session, girara_mode_t mode);

/**
 * Returns the current mode
 *
 * @param session The used girara session
 * @return The current mode
 */
girara_mode_t girara_mode_get(girara_session_t* session);

196 197 198 199 200
/**
 * Set name of the window title
 *
 * @param session The used girara session
 * @param name The new name of the session
201 202
 * @return true if no error occurred
 * @return false if an error occurred
203 204 205
 */
bool girara_set_window_title(girara_session_t* session, const char* name);

206 207 208 209 210
/**
 * Set icon of the window
 *
 * @param session The used girara session
 * @param name the name of the themed icon
211 212
 * @return true if no error occurred
 * @return false if an error occurred
213 214 215
 */
bool girara_set_window_icon(girara_session_t* session, const char* name);

Moritz Lipp's avatar
Moritz Lipp committed
216 217 218 219 220 221 222 223
/**
 * Returns the command history
 *
 * @param session The used girara session
 * @return The command history (list of strings) or NULL
 */
girara_list_t* girara_get_command_history(girara_session_t* session);

224 225 226 227 228 229 230 231
/**
 * Returns the internal template object to apply custom theming options
 *
 * @param session The girara session
 * @returns GiraraTemplate object
 */
GiraraTemplate* girara_session_get_template(girara_session_t* session);

232
/**
233
 * Replaces the internal template object, thus provides entirely user-defined styling.
234 235 236
 *
 * @param session The girara session
 * @param template The template to apply, @ref girara_template_new
237 238
 * @param init_variables Defines whether the default variables and current
 *    values should be added to the the template
239 240 241 242
 *
 * @note Using the template @c girara_template_new("") will use the default gtk style
 *
 */
243
void girara_session_set_template(girara_session_t* session, GiraraTemplate* template, bool init_variables);
244

Sebastian Ramacher's avatar
Sebastian Ramacher committed
245
#endif