From 5ce511e07e15a191a1c43b90aa26d03192c6022f Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 28 Sep 2016 13:37:31 +0300 Subject: [PATCH] Implement uniq widget ID for each widget. Signed-off-by: Andrew Borodin --- lib/widget/group.c | 1 - lib/widget/group.h | 1 - lib/widget/widget-common.c | 23 +++++++++++++++++++++++ lib/widget/widget-common.h | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/widget/group.c b/lib/widget/group.c index 58f257bf1..c9a40a138 100644 --- a/lib/widget/group.c +++ b/lib/widget/group.c @@ -174,7 +174,6 @@ group_add_widget_autopos (WGroup * g, void *w, widget_pos_flags_t pos_flags, con ww->owner = g; ww->pos_flags = pos_flags; - ww->id = g->widget_id++; if (g->widgets == NULL || before == NULL) { diff --git a/lib/widget/group.h b/lib/widget/group.h index 17f6135c7..7da7849ed 100644 --- a/lib/widget/group.h +++ b/lib/widget/group.h @@ -30,7 +30,6 @@ struct WGroup GList *widgets; /* widgets list */ GList *current; /* Currently active widget */ - unsigned long widget_id; /* maximum id of all widgets */ gboolean winch_pending; /* SIGWINCH signal has been got. Resize group after rise */ }; diff --git a/lib/widget/widget-common.c b/lib/widget/widget-common.c index e1d167ff7..942aebcda 100644 --- a/lib/widget/widget-common.c +++ b/lib/widget/widget-common.c @@ -53,10 +53,32 @@ /*** file scope variables ************************************************************************/ +/* maximum value of used widget ID */ +static unsigned long widget_id = 0; + /* --------------------------------------------------------------------------------------------- */ /*** file scope functions ************************************************************************/ /* --------------------------------------------------------------------------------------------- */ +/** + * Calc widget ID, + * Widget ID is uniq for each widget created during MC session (like PID in OS). + * + * @return widget ID. + */ +static unsigned long +widget_set_id (void) +{ + unsigned long id; + + id = widget_id++; + /* TODO IF NEEDED: if id is already used, find next free id. */ + + return id; +} + +/* --------------------------------------------------------------------------------------------- */ + static void widget_do_focus (Widget * w, gboolean enable) { @@ -252,6 +274,7 @@ void widget_init (Widget * w, int y, int x, int lines, int cols, widget_cb_fn callback, widget_mouse_cb_fn mouse_callback) { + w->id = widget_set_id (); w->x = x; w->y = y; w->cols = cols; diff --git a/lib/widget/widget-common.h b/lib/widget/widget-common.h index c5d6b5456..02112a9ad 100644 --- a/lib/widget/widget-common.h +++ b/lib/widget/widget-common.h @@ -131,7 +131,7 @@ struct Widget widget_pos_flags_t pos_flags; /* repositioning flags */ widget_options_t options; widget_state_t state; - unsigned int id; /* Number of the widget, starting with 0 */ + unsigned long id; /* uniq widget ID */ widget_cb_fn callback; widget_mouse_cb_fn mouse_callback; WGroup *owner;