mirror of
https://github.com/weechat/weechat.git
synced 2026-07-07 10:13:12 +02:00
gui: add gui_focus_info hashtable info (#1245)
This commit is contained in:
committed by
Sébastien Helleu
parent
5e5e1c0cd7
commit
3f0c6ac96b
@@ -76,6 +76,7 @@
|
||||
#include "../gui/gui-chat.h"
|
||||
#include "../gui/gui-color.h"
|
||||
#include "../gui/gui-completion.h"
|
||||
#include "../gui/gui-focus.h"
|
||||
#include "../gui/gui-key.h"
|
||||
#include "../gui/gui-layout.h"
|
||||
#include "../gui/gui-main.h"
|
||||
@@ -801,6 +802,7 @@ weechat_init (int argc, char *argv[], void (*gui_init_cb)())
|
||||
command_init (); /* initialize WeeChat commands */
|
||||
completion_init (); /* add core completion hooks */
|
||||
gui_key_init (); /* init keys */
|
||||
gui_focus_init (); /* initialize focus */
|
||||
network_init_gcrypt (); /* init gcrypt */
|
||||
if (!secure_init ()) /* init secured data */
|
||||
weechat_shutdown (EXIT_FAILURE, 0);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "../core/weechat.h"
|
||||
#include "../core/wee-hashtable.h"
|
||||
#include "../core/wee-hook.h"
|
||||
#include "../core/wee-string.h"
|
||||
#include "../plugins/plugin.h"
|
||||
#include "gui-bar.h"
|
||||
@@ -255,3 +256,80 @@ gui_focus_to_hashtable (struct t_gui_focus_info *focus_info, const char *key)
|
||||
|
||||
return hashtable;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns GUI focus info with hashtable "gui_focus_info".
|
||||
*/
|
||||
|
||||
struct t_hashtable *
|
||||
gui_focus_info_hashtable_gui_focus_info_cb (const void *pointer, void *data,
|
||||
const char *info_name,
|
||||
struct t_hashtable *hashtable)
|
||||
{
|
||||
char *error;
|
||||
const char *ptr_value;
|
||||
int x, y;
|
||||
struct t_gui_focus_info *focus_info;
|
||||
struct t_hashtable *focus_hashtable, *ret_hashtable;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) info_name;
|
||||
|
||||
if (!hashtable)
|
||||
return NULL;
|
||||
|
||||
/* parse coordinates */
|
||||
ptr_value = hashtable_get (hashtable, "x");
|
||||
if (!ptr_value)
|
||||
return NULL;
|
||||
error = NULL;
|
||||
x = (int)strtol (ptr_value, &error, 10);
|
||||
if (!error || error[0])
|
||||
return NULL;
|
||||
|
||||
ptr_value = hashtable_get (hashtable, "y");
|
||||
if (!ptr_value)
|
||||
return NULL;
|
||||
error = NULL;
|
||||
y = (int)strtol (ptr_value, &error, 10);
|
||||
if (!error || error[0])
|
||||
return NULL;
|
||||
|
||||
/* get focus info */
|
||||
focus_info = gui_focus_get_info (x, y);
|
||||
if (!focus_info)
|
||||
return NULL;
|
||||
|
||||
/* convert to hashtable */
|
||||
focus_hashtable = gui_focus_to_hashtable (focus_info, NULL); /* no key */
|
||||
gui_focus_free_info (focus_info);
|
||||
if (!focus_hashtable)
|
||||
return NULL;
|
||||
|
||||
hashtable_remove (focus_hashtable, "_key"); /* remove useless key */
|
||||
|
||||
/* run hook_focus callbacks that add extra data */
|
||||
ret_hashtable = hook_focus_get_data (focus_hashtable, NULL); /* no gesture */
|
||||
|
||||
free (focus_hashtable);
|
||||
|
||||
return ret_hashtable;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initializes focus hooks.
|
||||
*/
|
||||
|
||||
void
|
||||
gui_focus_init ()
|
||||
{
|
||||
hook_info_hashtable (NULL,
|
||||
"gui_focus_info",
|
||||
N_("get focus info"),
|
||||
/* TRANSLATORS: please do not translate key names (enclosed by quotes) */
|
||||
N_("\"x\": x coordinate, \"y\": y coordinate"),
|
||||
N_("see hook_focus"),
|
||||
&gui_focus_info_hashtable_gui_focus_info_cb, NULL, NULL);
|
||||
}
|
||||
@@ -45,5 +45,6 @@ extern struct t_gui_focus_info *gui_focus_get_info (int x, int y);
|
||||
extern void gui_focus_free_info (struct t_gui_focus_info *focus_info);
|
||||
extern struct t_hashtable *gui_focus_to_hashtable (struct t_gui_focus_info *focus_info,
|
||||
const char *key);
|
||||
extern void gui_focus_init ();
|
||||
|
||||
#endif /* WEECHAT_GUI_FOCUS_H */
|
||||
|
||||
Reference in New Issue
Block a user