summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/gui-layout.c118
-rw-r--r--src/gui/gui-layout.h8
-rw-r--r--src/plugins/plugin-api.c29
3 files changed, 154 insertions, 1 deletions
diff --git a/src/gui/gui-layout.c b/src/gui/gui-layout.c
index a866393c9..c7d348685 100644
--- a/src/gui/gui-layout.c
+++ b/src/gui/gui-layout.c
@@ -24,12 +24,14 @@
#endif
#include <stdlib.h>
+#include <stddef.h>
#include <string.h>
#include "../core/weechat.h"
-#include "../core/wee-log.h"
#include "../core/wee-config.h"
+#include "../core/wee-hdata.h"
#include "../core/wee-infolist.h"
+#include "../core/wee-log.h"
#include "../core/wee-string.h"
#include "../plugins/plugin.h"
#include "gui-layout.h"
@@ -869,6 +871,89 @@ gui_layout_remove_all ()
}
/*
+ * Returns hdata for buffer layout.
+ */
+
+struct t_hdata *
+gui_layout_hdata_layout_buffer_cb (void *data, const char *hdata_name)
+{
+ struct t_hdata *hdata;
+
+ /* make C compiler happy */
+ (void) data;
+
+ hdata = hdata_new (NULL, hdata_name, "prev_layout", "next_layout",
+ 0, 0, NULL, NULL);
+ if (hdata)
+ {
+ HDATA_VAR(struct t_gui_layout_buffer, plugin_name, STRING, 0, NULL, NULL);
+ HDATA_VAR(struct t_gui_layout_buffer, buffer_name, STRING, 0, NULL, NULL);
+ HDATA_VAR(struct t_gui_layout_buffer, number, INTEGER, 0, NULL, NULL);
+ HDATA_VAR(struct t_gui_layout_buffer, prev_layout, POINTER, 0, NULL, hdata_name);
+ HDATA_VAR(struct t_gui_layout_buffer, next_layout, POINTER, 0, NULL, hdata_name);
+ }
+ return hdata;
+}
+
+/*
+ * Returns hdata for window layout.
+ */
+
+struct t_hdata *
+gui_layout_hdata_layout_window_cb (void *data, const char *hdata_name)
+{
+ struct t_hdata *hdata;
+
+ /* make C compiler happy */
+ (void) data;
+
+ hdata = hdata_new (NULL, hdata_name, NULL, NULL, 0, 0, NULL, NULL);
+ if (hdata)
+ {
+ HDATA_VAR(struct t_gui_layout_window, internal_id, INTEGER, 0, NULL, NULL);
+ HDATA_VAR(struct t_gui_layout_window, parent_node, POINTER, 0, NULL, hdata_name);
+ HDATA_VAR(struct t_gui_layout_window, split_pct, INTEGER, 0, NULL, NULL);
+ HDATA_VAR(struct t_gui_layout_window, split_horiz, INTEGER, 0, NULL, NULL);
+ HDATA_VAR(struct t_gui_layout_window, child1, POINTER, 0, NULL, hdata_name);
+ HDATA_VAR(struct t_gui_layout_window, child2, POINTER, 0, NULL, hdata_name);
+ HDATA_VAR(struct t_gui_layout_window, plugin_name, STRING, 0, NULL, NULL);
+ HDATA_VAR(struct t_gui_layout_window, buffer_name, STRING, 0, NULL, NULL);
+ }
+ return hdata;
+}
+
+/*
+ * Returns hdata for layout.
+ */
+
+struct t_hdata *
+gui_layout_hdata_layout_cb (void *data, const char *hdata_name)
+{
+ struct t_hdata *hdata;
+
+ /* make C compiler happy */
+ (void) data;
+
+ hdata = hdata_new (NULL, hdata_name, "prev_layout", "next_layout",
+ 0, 0, NULL, NULL);
+ if (hdata)
+ {
+ HDATA_VAR(struct t_gui_layout, name, STRING, 0, NULL, NULL);
+ HDATA_VAR(struct t_gui_layout, layout_buffers, POINTER, 0, NULL, "layout_buffer");
+ HDATA_VAR(struct t_gui_layout, last_layout_buffer, POINTER, 0, NULL, "layout_buffer");
+ HDATA_VAR(struct t_gui_layout, layout_windows, POINTER, 0, NULL, "layout_window");
+ HDATA_VAR(struct t_gui_layout, internal_id, INTEGER, 0, NULL, NULL);
+ HDATA_VAR(struct t_gui_layout, internal_id_current_window, INTEGER, 0, NULL, NULL);
+ HDATA_VAR(struct t_gui_layout, prev_layout, POINTER, 0, NULL, hdata_name);
+ HDATA_VAR(struct t_gui_layout, next_layout, POINTER, 0, NULL, hdata_name);
+ HDATA_LIST(gui_layouts);
+ HDATA_LIST(last_gui_layout);
+ HDATA_LIST(gui_layout_current);
+ }
+ return hdata;
+}
+
+/*
* Adds a buffer layout in an infolist.
*
* Returns:
@@ -945,6 +1030,37 @@ gui_layout_window_add_to_infolist (struct t_infolist *infolist,
}
/*
+ * Adds a layout in an infolist.
+ *
+ * Returns:
+ * 1: OK
+ * 0: error
+ */
+
+int
+gui_layout_add_to_infolist (struct t_infolist *infolist,
+ struct t_gui_layout *layout)
+{
+ struct t_infolist_item *ptr_item;
+
+ if (!infolist || !layout)
+ return 0;
+
+ ptr_item = infolist_new_item (infolist);
+ if (!ptr_item)
+ return 0;
+
+ if (!infolist_new_var_string (ptr_item, "name", layout->name))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "internal_id", layout->internal_id))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "internal_id_current_window", layout->internal_id_current_window))
+ return 0;
+
+ return 1;
+}
+
+/*
* Prints windows layout infos in WeeChat log file (usually for crash dump).
*/
diff --git a/src/gui/gui-layout.h b/src/gui/gui-layout.h
index 97bdcc00b..fc9b9c990 100644
--- a/src/gui/gui-layout.h
+++ b/src/gui/gui-layout.h
@@ -112,10 +112,18 @@ extern void gui_layout_save_on_exit ();
extern void gui_layout_free (struct t_gui_layout *layout);
extern void gui_layout_remove (struct t_gui_layout *layout);
extern void gui_layout_remove_all ();
+extern struct t_hdata *gui_layout_hdata_layout_buffer_cb (void *data,
+ const char *hdata_name);
+extern struct t_hdata *gui_layout_hdata_layout_window_cb (void *data,
+ const char *hdata_name);
+extern struct t_hdata *gui_layout_hdata_layout_cb (void *data,
+ const char *hdata_name);
extern int gui_layout_buffer_add_to_infolist (struct t_infolist *infolist,
struct t_gui_layout_buffer *layout_buffer);
extern int gui_layout_window_add_to_infolist (struct t_infolist *infolist,
struct t_gui_layout_window *layout_window);
+extern int gui_layout_add_to_infolist (struct t_infolist *infolist,
+ struct t_gui_layout *layout);
extern void gui_layout_print_log ();
extern void gui_layout_init ();
extern void gui_layout_end ();
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c
index 6d06d922f..ffed78bb0 100644
--- a/src/plugins/plugin-api.c
+++ b/src/plugins/plugin-api.c
@@ -56,6 +56,7 @@
#include "../gui/gui-history.h"
#include "../gui/gui-hotlist.h"
#include "../gui/gui-key.h"
+#include "../gui/gui-layout.h"
#include "../gui/gui-line.h"
#include "../gui/gui-nicklist.h"
#include "../gui/gui-window.h"
@@ -412,6 +413,7 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name,
struct t_gui_hotlist *ptr_hotlist;
struct t_gui_key *ptr_key;
struct t_weechat_plugin *ptr_plugin;
+ struct t_gui_layout *ptr_layout;
int context, number, i;
char *error;
@@ -713,6 +715,23 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name,
return ptr_infolist;
}
}
+ else if (string_strcasecmp (infolist_name, "layout") == 0)
+ {
+ ptr_infolist = infolist_new ();
+ if (ptr_infolist)
+ {
+ for (ptr_layout = gui_layouts; ptr_layout;
+ ptr_layout = ptr_layout->next_layout)
+ {
+ if (!gui_layout_add_to_infolist (ptr_infolist,ptr_layout))
+ {
+ infolist_free (ptr_infolist);
+ return NULL;
+ }
+ }
+ return ptr_infolist;
+ }
+ }
else if (string_strcasecmp (infolist_name, "nicklist") == 0)
{
/* invalid buffer pointer ? */
@@ -1108,6 +1127,10 @@ plugin_api_init ()
N_("context (\"default\", \"search\", \"cursor\" or "
"\"mouse\") (optional)"),
&plugin_api_infolist_get_internal, NULL);
+ hook_infolist (NULL, "layout", N_("list of layouts"),
+ NULL,
+ NULL,
+ &plugin_api_infolist_get_internal, NULL);
hook_infolist (NULL, "nicklist", N_("nicks in nicklist for a buffer"),
N_("buffer pointer"),
N_("nick_xxx or group_xxx to get only nick/group xxx "
@@ -1159,6 +1182,12 @@ plugin_api_init ()
&gui_buffer_hdata_input_undo_cb, NULL);
hook_hdata (NULL, "key", N_("a key (keyboard shortcut)"),
&gui_key_hdata_key_cb, NULL);
+ hook_hdata (NULL, "layout", N_("layout"),
+ &gui_layout_hdata_layout_cb, NULL);
+ hook_hdata (NULL, "layout_buffer", N_("buffer layout"),
+ &gui_layout_hdata_layout_buffer_cb, NULL);
+ hook_hdata (NULL, "layout_window", N_("window layout"),
+ &gui_layout_hdata_layout_window_cb, NULL);
hook_hdata (NULL, "lines", N_("structure with lines"),
&gui_line_hdata_lines_cb, NULL);
hook_hdata (NULL, "line", N_("structure with one line"),